Context
stringlengths
285
157k
file_name
stringlengths
21
79
start
int64
14
3.67k
end
int64
18
3.69k
theorem
stringlengths
25
2.71k
proof
stringlengths
5
10.6k
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Limits.HasLimits import Mathlib.CategoryTheory.Products.Basic import Mathlib.CategoryTheory.Functor.Currying import Mathlib.CategoryTheory.Products.Bifunctor #align_import category_theory.limits.fubini from "leanprover-community/mathlib"@"59382264386afdbaf1727e617f5fdda511992eb9" /-! # A Fubini theorem for categorical (co)limits We prove that $lim_{J × K} G = lim_J (lim_K G(j, -))$ for a functor `G : J × K ⥤ C`, when all the appropriate limits exist. We begin working with a functor `F : J ⥤ K ⥤ C`. We'll write `G : J × K ⥤ C` for the associated "uncurried" functor. In the first part, given a coherent family `D` of limit cones over the functors `F.obj j`, and a cone `c` over `G`, we construct a cone over the cone points of `D`. We then show that if `c` is a limit cone, the constructed cone is also a limit cone. In the second part, we state the Fubini theorem in the setting where limits are provided by suitable `HasLimit` classes. We construct `limitUncurryIsoLimitCompLim F : limit (uncurry.obj F) ≅ limit (F ⋙ lim)` and give simp lemmas characterising it. For convenience, we also provide `limitIsoLimitCurryCompLim G : limit G ≅ limit ((curry.obj G) ⋙ lim)` in terms of the uncurried functor. All statements have their counterpart for colimits. -/ universe v u open CategoryTheory namespace CategoryTheory.Limits variable {J K : Type v} [SmallCategory J] [SmallCategory K] variable {C : Type u} [Category.{v} C] variable (F : J ⥤ K ⥤ C) -- We could try introducing a "dependent functor type" to handle this? /-- A structure carrying a diagram of cones over the functors `F.obj j`. -/ structure DiagramOfCones where /-- For each object, a cone. -/ obj : ∀ j : J, Cone (F.obj j) /-- For each map, a map of cones. -/ map : ∀ {j j' : J} (f : j ⟶ j'), (Cones.postcompose (F.map f)).obj (obj j) ⟶ obj j' id : ∀ j : J, (map (𝟙 j)).hom = 𝟙 _ := by aesop_cat comp : ∀ {j₁ j₂ j₃ : J} (f : j₁ ⟶ j₂) (g : j₂ ⟶ j₃), (map (f ≫ g)).hom = (map f).hom ≫ (map g).hom := by aesop_cat #align category_theory.limits.diagram_of_cones CategoryTheory.Limits.DiagramOfCones /-- A structure carrying a diagram of cocones over the functors `F.obj j`. -/ structure DiagramOfCocones where /-- For each object, a cocone. -/ obj : ∀ j : J, Cocone (F.obj j) /-- For each map, a map of cocones. -/ map : ∀ {j j' : J} (f : j ⟶ j'), (obj j) ⟶ (Cocones.precompose (F.map f)).obj (obj j') id : ∀ j : J, (map (𝟙 j)).hom = 𝟙 _ := by aesop_cat comp : ∀ {j₁ j₂ j₃ : J} (f : j₁ ⟶ j₂) (g : j₂ ⟶ j₃), (map (f ≫ g)).hom = (map f).hom ≫ (map g).hom := by aesop_cat variable {F} /-- Extract the functor `J ⥤ C` consisting of the cone points and the maps between them, from a `DiagramOfCones`. -/ @[simps] def DiagramOfCones.conePoints (D : DiagramOfCones F) : J ⥤ C where obj j := (D.obj j).pt map f := (D.map f).hom map_id j := D.id j map_comp f g := D.comp f g #align category_theory.limits.diagram_of_cones.cone_points CategoryTheory.Limits.DiagramOfCones.conePoints /-- Extract the functor `J ⥤ C` consisting of the cocone points and the maps between them, from a `DiagramOfCocones`. -/ @[simps] def DiagramOfCocones.coconePoints (D : DiagramOfCocones F) : J ⥤ C where obj j := (D.obj j).pt map f := (D.map f).hom map_id j := D.id j map_comp f g := D.comp f g /-- Given a diagram `D` of limit cones over the `F.obj j`, and a cone over `uncurry.obj F`, we can construct a cone over the diagram consisting of the cone points from `D`. -/ @[simps] def coneOfConeUncurry {D : DiagramOfCones F} (Q : ∀ j, IsLimit (D.obj j)) (c : Cone (uncurry.obj F)) : Cone D.conePoints where pt := c.pt π := { app := fun j => (Q j).lift { pt := c.pt π := { app := fun k => c.π.app (j, k) naturality := fun k k' f => by dsimp; simp only [Category.id_comp] have := @NatTrans.naturality _ _ _ _ _ _ c.π (j, k) (j, k') (𝟙 j, f) dsimp at this simp? at this says simp only [Category.id_comp, Functor.map_id, NatTrans.id_app] at this exact this } } naturality := fun j j' f => (Q j').hom_ext (by dsimp intro k simp only [Limits.ConeMorphism.w, Limits.Cones.postcompose_obj_π, Limits.IsLimit.fac_assoc, Limits.IsLimit.fac, NatTrans.comp_app, Category.id_comp, Category.assoc] have := @NatTrans.naturality _ _ _ _ _ _ c.π (j, k) (j', k) (f, 𝟙 k) dsimp at this simp only [Category.id_comp, Category.comp_id, CategoryTheory.Functor.map_id, NatTrans.id_app] at this exact this) } #align category_theory.limits.cone_of_cone_uncurry CategoryTheory.Limits.coneOfConeUncurry /-- Given a diagram `D` of colimit cocones over the `F.obj j`, and a cocone over `uncurry.obj F`, we can construct a cocone over the diagram consisting of the cocone points from `D`. -/ @[simps] def coconeOfCoconeUncurry {D : DiagramOfCocones F} (Q : ∀ j, IsColimit (D.obj j)) (c : Cocone (uncurry.obj F)) : Cocone D.coconePoints where pt := c.pt ι := { app := fun j => (Q j).desc { pt := c.pt ι := { app := fun k => c.ι.app (j, k) naturality := fun k k' f => by dsimp; simp only [Category.comp_id] conv_lhs => arg 1; equals (F.map (𝟙 _)).app _ ≫ (F.obj j).map f => simp; conv_lhs => arg 1; rw [← uncurry_obj_map F ((𝟙 j,f) : (j,k) ⟶ (j,k'))] rw [c.w] } } naturality := fun j j' f => (Q j).hom_ext (by dsimp intro k simp only [Limits.CoconeMorphism.w_assoc, Limits.Cocones.precompose_obj_ι, Limits.IsColimit.fac_assoc, Limits.IsColimit.fac, NatTrans.comp_app, Category.comp_id, Category.assoc] have := @NatTrans.naturality _ _ _ _ _ _ c.ι (j, k) (j', k) (f, 𝟙 k) dsimp at this simp only [Category.id_comp, Category.comp_id, CategoryTheory.Functor.map_id, NatTrans.id_app] at this exact this) } /-- `coneOfConeUncurry Q c` is a limit cone when `c` is a limit cone. -/ def coneOfConeUncurryIsLimit {D : DiagramOfCones F} (Q : ∀ j, IsLimit (D.obj j)) {c : Cone (uncurry.obj F)} (P : IsLimit c) : IsLimit (coneOfConeUncurry Q c) where lift s := P.lift { pt := s.pt π := { app := fun p => s.π.app p.1 ≫ (D.obj p.1).π.app p.2 naturality := fun p p' f => by dsimp; simp only [Category.id_comp, Category.assoc] rcases p with ⟨j, k⟩ rcases p' with ⟨j', k'⟩ rcases f with ⟨fj, fk⟩ dsimp slice_rhs 3 4 => rw [← NatTrans.naturality] slice_rhs 2 3 => rw [← (D.obj j).π.naturality] simp only [Functor.const_obj_map, Category.id_comp, Category.assoc] have w := (D.map fj).w k' dsimp at w rw [← w] have n := s.π.naturality fj dsimp at n simp only [Category.id_comp] at n rw [n] simp } } fac s j := by apply (Q j).hom_ext intro k simp uniq s m w := by refine P.uniq { pt := s.pt π := _ } m ?_ rintro ⟨j, k⟩ dsimp rw [← w j] simp #align category_theory.limits.cone_of_cone_uncurry_is_limit CategoryTheory.Limits.coneOfConeUncurryIsLimit /-- `coconeOfCoconeUncurry Q c` is a colimit cocone when `c` is a colimit cocone. -/ def coconeOfCoconeUncurryIsColimit {D : DiagramOfCocones F} (Q : ∀ j, IsColimit (D.obj j)) {c : Cocone (uncurry.obj F)} (P : IsColimit c) : IsColimit (coconeOfCoconeUncurry Q c) where desc s := P.desc { pt := s.pt ι := { app := fun p => (D.obj p.1).ι.app p.2 ≫ s.ι.app p.1 naturality := fun p p' f => by dsimp; simp only [Category.id_comp, Category.assoc] rcases p with ⟨j, k⟩ rcases p' with ⟨j', k'⟩ rcases f with ⟨fj, fk⟩ dsimp slice_lhs 2 3 => rw [(D.obj j').ι.naturality] simp only [Functor.const_obj_map, Category.id_comp, Category.assoc] have w := (D.map fj).w k dsimp at w slice_lhs 1 2 => rw [← w] have n := s.ι.naturality fj dsimp at n simp only [Category.comp_id] at n rw [← n] simp } } fac s j := by apply (Q j).hom_ext intro k simp uniq s m w := by refine P.uniq { pt := s.pt ι := _ } m ?_ rintro ⟨j, k⟩ dsimp rw [← w j] simp section variable (F) variable [HasLimitsOfShape K C] /-- Given a functor `F : J ⥤ K ⥤ C`, with all needed limits, we can construct a diagram consisting of the limit cone over each functor `F.obj j`, and the universal cone morphisms between these. -/ @[simps] noncomputable def DiagramOfCones.mkOfHasLimits : DiagramOfCones F where obj j := limit.cone (F.obj j) map f := { hom := lim.map (F.map f) } #align category_theory.limits.diagram_of_cones.mk_of_has_limits CategoryTheory.Limits.DiagramOfCones.mkOfHasLimits -- Satisfying the inhabited linter. noncomputable instance diagramOfConesInhabited : Inhabited (DiagramOfCones F) := ⟨DiagramOfCones.mkOfHasLimits F⟩ #align category_theory.limits.diagram_of_cones_inhabited CategoryTheory.Limits.diagramOfConesInhabited @[simp] theorem DiagramOfCones.mkOfHasLimits_conePoints : (DiagramOfCones.mkOfHasLimits F).conePoints = F ⋙ lim := rfl #align category_theory.limits.diagram_of_cones.mk_of_has_limits_cone_points CategoryTheory.Limits.DiagramOfCones.mkOfHasLimits_conePoints variable [HasLimit (uncurry.obj F)] variable [HasLimit (F ⋙ lim)] /-- The Fubini theorem for a functor `F : J ⥤ K ⥤ C`, showing that the limit of `uncurry.obj F` can be computed as the limit of the limits of the functors `F.obj j`. -/ noncomputable def limitUncurryIsoLimitCompLim : limit (uncurry.obj F) ≅ limit (F ⋙ lim) := by let c := limit.cone (uncurry.obj F) let P : IsLimit c := limit.isLimit _ let G := DiagramOfCones.mkOfHasLimits F let Q : ∀ j, IsLimit (G.obj j) := fun j => limit.isLimit _ have Q' := coneOfConeUncurryIsLimit Q P have Q'' := limit.isLimit (F ⋙ lim) exact IsLimit.conePointUniqueUpToIso Q' Q'' #align category_theory.limits.limit_uncurry_iso_limit_comp_lim CategoryTheory.Limits.limitUncurryIsoLimitCompLim @[simp, reassoc] theorem limitUncurryIsoLimitCompLim_hom_π_π {j} {k} : (limitUncurryIsoLimitCompLim F).hom ≫ limit.π _ j ≫ limit.π _ k = limit.π _ (j, k) := by dsimp [limitUncurryIsoLimitCompLim, IsLimit.conePointUniqueUpToIso, IsLimit.uniqueUpToIso] simp #align category_theory.limits.limit_uncurry_iso_limit_comp_lim_hom_π_π CategoryTheory.Limits.limitUncurryIsoLimitCompLim_hom_π_π -- Porting note: Added type annotation `limit (_ ⋙ lim) ⟶ _` @[simp, reassoc]
Mathlib/CategoryTheory/Limits/Fubini.lean
296
300
theorem limitUncurryIsoLimitCompLim_inv_π {j} {k} : (limitUncurryIsoLimitCompLim F).inv ≫ limit.π _ (j, k) = (limit.π _ j ≫ limit.π _ k : limit (_ ⋙ lim) ⟶ _) := by
rw [← cancel_epi (limitUncurryIsoLimitCompLim F).hom] simp
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Mario Carneiro, Scott Morrison, Floris van Doorn -/ import Mathlib.CategoryTheory.Adjunction.Basic import Mathlib.CategoryTheory.Limits.Cones #align_import category_theory.limits.is_limit from "leanprover-community/mathlib"@"740acc0e6f9adf4423f92a485d0456fc271482da" /-! # Limits and colimits We set up the general theory of limits and colimits in a category. In this introduction we only describe the setup for limits; it is repeated, with slightly different names, for colimits. The main structures defined in this file is * `IsLimit c`, for `c : Cone F`, `F : J ⥤ C`, expressing that `c` is a limit cone, See also `CategoryTheory.Limits.HasLimits` which further builds: * `LimitCone F`, which consists of a choice of cone for `F` and the fact it is a limit cone, and * `HasLimit F`, asserting the mere existence of some limit cone for `F`. ## Implementation At present we simply say everything twice, in order to handle both limits and colimits. It would be highly desirable to have some automation support, e.g. a `@[dualize]` attribute that behaves similarly to `@[to_additive]`. ## References * [Stacks: Limits and colimits](https://stacks.math.columbia.edu/tag/002D) -/ noncomputable section open CategoryTheory CategoryTheory.Category CategoryTheory.Functor Opposite namespace CategoryTheory.Limits -- declare the `v`'s first; see `CategoryTheory.Category` for an explanation universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ variable {J : Type u₁} [Category.{v₁} J] {K : Type u₂} [Category.{v₂} K] variable {C : Type u₃} [Category.{v₃} C] variable {F : J ⥤ C} /-- A cone `t` on `F` is a limit cone if each cone on `F` admits a unique cone morphism to `t`. See <https://stacks.math.columbia.edu/tag/002E>. -/ -- porting note (#5171): removed @[nolint has_nonempty_instance] structure IsLimit (t : Cone F) where /-- There is a morphism from any cone point to `t.pt` -/ lift : ∀ s : Cone F, s.pt ⟶ t.pt /-- The map makes the triangle with the two natural transformations commute -/ fac : ∀ (s : Cone F) (j : J), lift s ≫ t.π.app j = s.π.app j := by aesop_cat /-- It is the unique such map to do this -/ uniq : ∀ (s : Cone F) (m : s.pt ⟶ t.pt) (_ : ∀ j : J, m ≫ t.π.app j = s.π.app j), m = lift s := by aesop_cat #align category_theory.limits.is_limit CategoryTheory.Limits.IsLimit #align category_theory.limits.is_limit.fac' CategoryTheory.Limits.IsLimit.fac #align category_theory.limits.is_limit.uniq' CategoryTheory.Limits.IsLimit.uniq -- Porting note (#10618): simp can prove this. Linter complains it still exists attribute [-simp, nolint simpNF] IsLimit.mk.injEq attribute [reassoc (attr := simp)] IsLimit.fac namespace IsLimit instance subsingleton {t : Cone F} : Subsingleton (IsLimit t) := ⟨by intro P Q; cases P; cases Q; congr; aesop_cat⟩ #align category_theory.limits.is_limit.subsingleton CategoryTheory.Limits.IsLimit.subsingleton /-- Given a natural transformation `α : F ⟶ G`, we give a morphism from the cone point of any cone over `F` to the cone point of a limit cone over `G`. -/ def map {F G : J ⥤ C} (s : Cone F) {t : Cone G} (P : IsLimit t) (α : F ⟶ G) : s.pt ⟶ t.pt := P.lift ((Cones.postcompose α).obj s) #align category_theory.limits.is_limit.map CategoryTheory.Limits.IsLimit.map @[reassoc (attr := simp)] theorem map_π {F G : J ⥤ C} (c : Cone F) {d : Cone G} (hd : IsLimit d) (α : F ⟶ G) (j : J) : hd.map c α ≫ d.π.app j = c.π.app j ≫ α.app j := fac _ _ _ #align category_theory.limits.is_limit.map_π CategoryTheory.Limits.IsLimit.map_π @[simp] theorem lift_self {c : Cone F} (t : IsLimit c) : t.lift c = 𝟙 c.pt := (t.uniq _ _ fun _ => id_comp _).symm #align category_theory.limits.is_limit.lift_self CategoryTheory.Limits.IsLimit.lift_self -- Repackaging the definition in terms of cone morphisms. /-- The universal morphism from any other cone to a limit cone. -/ @[simps] def liftConeMorphism {t : Cone F} (h : IsLimit t) (s : Cone F) : s ⟶ t where hom := h.lift s #align category_theory.limits.is_limit.lift_cone_morphism CategoryTheory.Limits.IsLimit.liftConeMorphism
Mathlib/CategoryTheory/Limits/IsLimit.lean
101
104
theorem uniq_cone_morphism {s t : Cone F} (h : IsLimit t) {f f' : s ⟶ t} : f = f' := have : ∀ {g : s ⟶ t}, g = h.liftConeMorphism s := by
intro g; apply ConeMorphism.ext; exact h.uniq _ _ g.w this.trans this.symm
/- 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, Jeremy Avigad -/ import Mathlib.Algebra.Order.Ring.Defs import Mathlib.Data.Set.Finite #align_import order.filter.basic from "leanprover-community/mathlib"@"d4f691b9e5f94cfc64639973f3544c95f8d5d494" /-! # Theory of filters on sets ## Main definitions * `Filter` : filters on a set; * `Filter.principal` : filter of all sets containing a given set; * `Filter.map`, `Filter.comap` : operations on filters; * `Filter.Tendsto` : limit with respect to filters; * `Filter.Eventually` : `f.eventually p` means `{x | p x} ∈ f`; * `Filter.Frequently` : `f.frequently p` means `{x | ¬p x} ∉ f`; * `filter_upwards [h₁, ..., hₙ]` : a tactic that takes a list of proofs `hᵢ : sᵢ ∈ f`, and replaces a goal `s ∈ f` with `∀ x, x ∈ s₁ → ... → x ∈ sₙ → x ∈ s`; * `Filter.NeBot f` : a utility class stating that `f` is a non-trivial filter. Filters on a type `X` are sets of sets of `X` satisfying three conditions. They are mostly used to abstract two related kinds of ideas: * *limits*, including finite or infinite limits of sequences, finite or infinite limits of functions at a point or at infinity, etc... * *things happening eventually*, including things happening for large enough `n : ℕ`, or near enough a point `x`, or for close enough pairs of points, or things happening almost everywhere in the sense of measure theory. Dually, filters can also express the idea of *things happening often*: for arbitrarily large `n`, or at a point in any neighborhood of given a point etc... In this file, we define the type `Filter X` of filters on `X`, and endow it with a complete lattice structure. This structure is lifted from the lattice structure on `Set (Set X)` using the Galois insertion which maps a filter to its elements in one direction, and an arbitrary set of sets to the smallest filter containing it in the other direction. We also prove `Filter` is a monadic functor, with a push-forward operation `Filter.map` and a pull-back operation `Filter.comap` that form a Galois connections for the order on filters. The examples of filters appearing in the description of the two motivating ideas are: * `(Filter.atTop : Filter ℕ)` : made of sets of `ℕ` containing `{n | n ≥ N}` for some `N` * `𝓝 x` : made of neighborhoods of `x` in a topological space (defined in topology.basic) * `𝓤 X` : made of entourages of a uniform space (those space are generalizations of metric spaces defined in `Mathlib/Topology/UniformSpace/Basic.lean`) * `MeasureTheory.ae` : made of sets whose complement has zero measure with respect to `μ` (defined in `Mathlib/MeasureTheory/OuterMeasure/AE`) The general notion of limit of a map with respect to filters on the source and target types is `Filter.Tendsto`. It is defined in terms of the order and the push-forward operation. The predicate "happening eventually" is `Filter.Eventually`, and "happening often" is `Filter.Frequently`, whose definitions are immediate after `Filter` is defined (but they come rather late in this file in order to immediately relate them to the lattice structure). For instance, anticipating on Topology.Basic, the statement: "if a sequence `u` converges to some `x` and `u n` belongs to a set `M` for `n` large enough then `x` is in the closure of `M`" is formalized as: `Tendsto u atTop (𝓝 x) → (∀ᶠ n in atTop, u n ∈ M) → x ∈ closure M`, which is a special case of `mem_closure_of_tendsto` from Topology.Basic. ## Notations * `∀ᶠ x in f, p x` : `f.Eventually p`; * `∃ᶠ x in f, p x` : `f.Frequently p`; * `f =ᶠ[l] g` : `∀ᶠ x in l, f x = g x`; * `f ≤ᶠ[l] g` : `∀ᶠ x in l, f x ≤ g x`; * `𝓟 s` : `Filter.Principal s`, localized in `Filter`. ## References * [N. Bourbaki, *General Topology*][bourbaki1966] Important note: Bourbaki requires that a filter on `X` cannot contain all sets of `X`, which we do *not* require. This gives `Filter X` better formal properties, in particular a bottom element `⊥` for its lattice structure, at the cost of including the assumption `[NeBot f]` in a number of lemmas and definitions. -/ set_option autoImplicit true open Function Set Order open scoped Classical universe u v w x y /-- A filter `F` on a type `α` is a collection of sets of `α` which contains the whole `α`, is upwards-closed, and is stable under intersection. We do not forbid this collection to be all sets of `α`. -/ structure Filter (α : Type*) where /-- The set of sets that belong to the filter. -/ sets : Set (Set α) /-- The set `Set.univ` belongs to any filter. -/ univ_sets : Set.univ ∈ sets /-- If a set belongs to a filter, then its superset belongs to the filter as well. -/ sets_of_superset {x y} : x ∈ sets → x ⊆ y → y ∈ sets /-- If two sets belong to a filter, then their intersection belongs to the filter as well. -/ inter_sets {x y} : x ∈ sets → y ∈ sets → x ∩ y ∈ sets #align filter Filter /-- If `F` is a filter on `α`, and `U` a subset of `α` then we can write `U ∈ F` as on paper. -/ instance {α : Type*} : Membership (Set α) (Filter α) := ⟨fun U F => U ∈ F.sets⟩ namespace Filter variable {α : Type u} {f g : Filter α} {s t : Set α} @[simp] protected theorem mem_mk {t : Set (Set α)} {h₁ h₂ h₃} : s ∈ mk t h₁ h₂ h₃ ↔ s ∈ t := Iff.rfl #align filter.mem_mk Filter.mem_mk @[simp] protected theorem mem_sets : s ∈ f.sets ↔ s ∈ f := Iff.rfl #align filter.mem_sets Filter.mem_sets instance inhabitedMem : Inhabited { s : Set α // s ∈ f } := ⟨⟨univ, f.univ_sets⟩⟩ #align filter.inhabited_mem Filter.inhabitedMem theorem filter_eq : ∀ {f g : Filter α}, f.sets = g.sets → f = g | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl #align filter.filter_eq Filter.filter_eq theorem filter_eq_iff : f = g ↔ f.sets = g.sets := ⟨congr_arg _, filter_eq⟩ #align filter.filter_eq_iff Filter.filter_eq_iff protected theorem ext_iff : f = g ↔ ∀ s, s ∈ f ↔ s ∈ g := by simp only [filter_eq_iff, ext_iff, Filter.mem_sets] #align filter.ext_iff Filter.ext_iff @[ext] protected theorem ext : (∀ s, s ∈ f ↔ s ∈ g) → f = g := Filter.ext_iff.2 #align filter.ext Filter.ext /-- An extensionality lemma that is useful for filters with good lemmas about `sᶜ ∈ f` (e.g., `Filter.comap`, `Filter.coprod`, `Filter.Coprod`, `Filter.cofinite`). -/ protected theorem coext (h : ∀ s, sᶜ ∈ f ↔ sᶜ ∈ g) : f = g := Filter.ext <| compl_surjective.forall.2 h #align filter.coext Filter.coext @[simp] theorem univ_mem : univ ∈ f := f.univ_sets #align filter.univ_mem Filter.univ_mem theorem mem_of_superset {x y : Set α} (hx : x ∈ f) (hxy : x ⊆ y) : y ∈ f := f.sets_of_superset hx hxy #align filter.mem_of_superset Filter.mem_of_superset instance : Trans (· ⊇ ·) ((· ∈ ·) : Set α → Filter α → Prop) (· ∈ ·) where trans h₁ h₂ := mem_of_superset h₂ h₁ theorem inter_mem {s t : Set α} (hs : s ∈ f) (ht : t ∈ f) : s ∩ t ∈ f := f.inter_sets hs ht #align filter.inter_mem Filter.inter_mem @[simp] theorem inter_mem_iff {s t : Set α} : s ∩ t ∈ f ↔ s ∈ f ∧ t ∈ f := ⟨fun h => ⟨mem_of_superset h inter_subset_left, mem_of_superset h inter_subset_right⟩, and_imp.2 inter_mem⟩ #align filter.inter_mem_iff Filter.inter_mem_iff theorem diff_mem {s t : Set α} (hs : s ∈ f) (ht : tᶜ ∈ f) : s \ t ∈ f := inter_mem hs ht #align filter.diff_mem Filter.diff_mem theorem univ_mem' (h : ∀ a, a ∈ s) : s ∈ f := mem_of_superset univ_mem fun x _ => h x #align filter.univ_mem' Filter.univ_mem' theorem mp_mem (hs : s ∈ f) (h : { x | x ∈ s → x ∈ t } ∈ f) : t ∈ f := mem_of_superset (inter_mem hs h) fun _ ⟨h₁, h₂⟩ => h₂ h₁ #align filter.mp_mem Filter.mp_mem theorem congr_sets (h : { x | x ∈ s ↔ x ∈ t } ∈ f) : s ∈ f ↔ t ∈ f := ⟨fun hs => mp_mem hs (mem_of_superset h fun _ => Iff.mp), fun hs => mp_mem hs (mem_of_superset h fun _ => Iff.mpr)⟩ #align filter.congr_sets Filter.congr_sets /-- Override `sets` field of a filter to provide better definitional equality. -/ protected def copy (f : Filter α) (S : Set (Set α)) (hmem : ∀ s, s ∈ S ↔ s ∈ f) : Filter α where sets := S univ_sets := (hmem _).2 univ_mem sets_of_superset h hsub := (hmem _).2 <| mem_of_superset ((hmem _).1 h) hsub inter_sets h₁ h₂ := (hmem _).2 <| inter_mem ((hmem _).1 h₁) ((hmem _).1 h₂) lemma copy_eq {S} (hmem : ∀ s, s ∈ S ↔ s ∈ f) : f.copy S hmem = f := Filter.ext hmem @[simp] lemma mem_copy {S hmem} : s ∈ f.copy S hmem ↔ s ∈ S := Iff.rfl @[simp] theorem biInter_mem {β : Type v} {s : β → Set α} {is : Set β} (hf : is.Finite) : (⋂ i ∈ is, s i) ∈ f ↔ ∀ i ∈ is, s i ∈ f := Finite.induction_on hf (by simp) fun _ _ hs => by simp [hs] #align filter.bInter_mem Filter.biInter_mem @[simp] theorem biInter_finset_mem {β : Type v} {s : β → Set α} (is : Finset β) : (⋂ i ∈ is, s i) ∈ f ↔ ∀ i ∈ is, s i ∈ f := biInter_mem is.finite_toSet #align filter.bInter_finset_mem Filter.biInter_finset_mem alias _root_.Finset.iInter_mem_sets := biInter_finset_mem #align finset.Inter_mem_sets Finset.iInter_mem_sets -- attribute [protected] Finset.iInter_mem_sets porting note: doesn't work @[simp] theorem sInter_mem {s : Set (Set α)} (hfin : s.Finite) : ⋂₀ s ∈ f ↔ ∀ U ∈ s, U ∈ f := by rw [sInter_eq_biInter, biInter_mem hfin] #align filter.sInter_mem Filter.sInter_mem @[simp] theorem iInter_mem {β : Sort v} {s : β → Set α} [Finite β] : (⋂ i, s i) ∈ f ↔ ∀ i, s i ∈ f := (sInter_mem (finite_range _)).trans forall_mem_range #align filter.Inter_mem Filter.iInter_mem theorem exists_mem_subset_iff : (∃ t ∈ f, t ⊆ s) ↔ s ∈ f := ⟨fun ⟨_, ht, ts⟩ => mem_of_superset ht ts, fun hs => ⟨s, hs, Subset.rfl⟩⟩ #align filter.exists_mem_subset_iff Filter.exists_mem_subset_iff theorem monotone_mem {f : Filter α} : Monotone fun s => s ∈ f := fun _ _ hst h => mem_of_superset h hst #align filter.monotone_mem Filter.monotone_mem theorem exists_mem_and_iff {P : Set α → Prop} {Q : Set α → Prop} (hP : Antitone P) (hQ : Antitone Q) : ((∃ u ∈ f, P u) ∧ ∃ u ∈ f, Q u) ↔ ∃ u ∈ f, P u ∧ Q u := by constructor · rintro ⟨⟨u, huf, hPu⟩, v, hvf, hQv⟩ exact ⟨u ∩ v, inter_mem huf hvf, hP inter_subset_left hPu, hQ inter_subset_right hQv⟩ · rintro ⟨u, huf, hPu, hQu⟩ exact ⟨⟨u, huf, hPu⟩, u, huf, hQu⟩ #align filter.exists_mem_and_iff Filter.exists_mem_and_iff theorem forall_in_swap {β : Type*} {p : Set α → β → Prop} : (∀ a ∈ f, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ f, p a b := Set.forall_in_swap #align filter.forall_in_swap Filter.forall_in_swap end Filter namespace Mathlib.Tactic open Lean Meta Elab Tactic /-- `filter_upwards [h₁, ⋯, hₙ]` replaces a goal of the form `s ∈ f` and terms `h₁ : t₁ ∈ f, ⋯, hₙ : tₙ ∈ f` with `∀ x, x ∈ t₁ → ⋯ → x ∈ tₙ → x ∈ s`. The list is an optional parameter, `[]` being its default value. `filter_upwards [h₁, ⋯, hₙ] with a₁ a₂ ⋯ aₖ` is a short form for `{ filter_upwards [h₁, ⋯, hₙ], intros a₁ a₂ ⋯ aₖ }`. `filter_upwards [h₁, ⋯, hₙ] using e` is a short form for `{ filter_upwards [h1, ⋯, hn], exact e }`. Combining both shortcuts is done by writing `filter_upwards [h₁, ⋯, hₙ] with a₁ a₂ ⋯ aₖ using e`. Note that in this case, the `aᵢ` terms can be used in `e`. -/ syntax (name := filterUpwards) "filter_upwards" (" [" term,* "]")? (" with" (ppSpace colGt term:max)*)? (" using " term)? : tactic elab_rules : tactic | `(tactic| filter_upwards $[[$[$args],*]]? $[with $wth*]? $[using $usingArg]?) => do let config : ApplyConfig := {newGoals := ApplyNewGoals.nonDependentOnly} for e in args.getD #[] |>.reverse do let goal ← getMainGoal replaceMainGoal <| ← goal.withContext <| runTermElab do let m ← mkFreshExprMVar none let lem ← Term.elabTermEnsuringType (← ``(Filter.mp_mem $e $(← Term.exprToSyntax m))) (← goal.getType) goal.assign lem return [m.mvarId!] liftMetaTactic fun goal => do goal.apply (← mkConstWithFreshMVarLevels ``Filter.univ_mem') config evalTactic <|← `(tactic| dsimp (config := {zeta := false}) only [Set.mem_setOf_eq]) if let some l := wth then evalTactic <|← `(tactic| intro $[$l]*) if let some e := usingArg then evalTactic <|← `(tactic| exact $e) end Mathlib.Tactic namespace Filter variable {α : Type u} {β : Type v} {γ : Type w} {δ : Type*} {ι : Sort x} section Principal /-- The principal filter of `s` is the collection of all supersets of `s`. -/ def principal (s : Set α) : Filter α where sets := { t | s ⊆ t } univ_sets := subset_univ s sets_of_superset hx := Subset.trans hx inter_sets := subset_inter #align filter.principal Filter.principal @[inherit_doc] scoped notation "𝓟" => Filter.principal @[simp] theorem mem_principal {s t : Set α} : s ∈ 𝓟 t ↔ t ⊆ s := Iff.rfl #align filter.mem_principal Filter.mem_principal theorem mem_principal_self (s : Set α) : s ∈ 𝓟 s := Subset.rfl #align filter.mem_principal_self Filter.mem_principal_self end Principal open Filter section Join /-- The join of a filter of filters is defined by the relation `s ∈ join f ↔ {t | s ∈ t} ∈ f`. -/ def join (f : Filter (Filter α)) : Filter α where sets := { s | { t : Filter α | s ∈ t } ∈ f } univ_sets := by simp only [mem_setOf_eq, univ_sets, ← Filter.mem_sets, setOf_true] sets_of_superset hx xy := mem_of_superset hx fun f h => mem_of_superset h xy inter_sets hx hy := mem_of_superset (inter_mem hx hy) fun f ⟨h₁, h₂⟩ => inter_mem h₁ h₂ #align filter.join Filter.join @[simp] theorem mem_join {s : Set α} {f : Filter (Filter α)} : s ∈ join f ↔ { t | s ∈ t } ∈ f := Iff.rfl #align filter.mem_join Filter.mem_join end Join section Lattice variable {f g : Filter α} {s t : Set α} instance : PartialOrder (Filter α) where le f g := ∀ ⦃U : Set α⦄, U ∈ g → U ∈ f le_antisymm a b h₁ h₂ := filter_eq <| Subset.antisymm h₂ h₁ le_refl a := Subset.rfl le_trans a b c h₁ h₂ := Subset.trans h₂ h₁ theorem le_def : f ≤ g ↔ ∀ x ∈ g, x ∈ f := Iff.rfl #align filter.le_def Filter.le_def protected theorem not_le : ¬f ≤ g ↔ ∃ s ∈ g, s ∉ f := by simp_rw [le_def, not_forall, exists_prop] #align filter.not_le Filter.not_le /-- `GenerateSets g s`: `s` is in the filter closure of `g`. -/ inductive GenerateSets (g : Set (Set α)) : Set α → Prop | basic {s : Set α} : s ∈ g → GenerateSets g s | univ : GenerateSets g univ | superset {s t : Set α} : GenerateSets g s → s ⊆ t → GenerateSets g t | inter {s t : Set α} : GenerateSets g s → GenerateSets g t → GenerateSets g (s ∩ t) #align filter.generate_sets Filter.GenerateSets /-- `generate g` is the largest filter containing the sets `g`. -/ def generate (g : Set (Set α)) : Filter α where sets := {s | GenerateSets g s} univ_sets := GenerateSets.univ sets_of_superset := GenerateSets.superset inter_sets := GenerateSets.inter #align filter.generate Filter.generate lemma mem_generate_of_mem {s : Set <| Set α} {U : Set α} (h : U ∈ s) : U ∈ generate s := GenerateSets.basic h theorem le_generate_iff {s : Set (Set α)} {f : Filter α} : f ≤ generate s ↔ s ⊆ f.sets := Iff.intro (fun h _ hu => h <| GenerateSets.basic <| hu) fun h _ hu => hu.recOn (fun h' => h h') univ_mem (fun _ hxy hx => mem_of_superset hx hxy) fun _ _ hx hy => inter_mem hx hy #align filter.sets_iff_generate Filter.le_generate_iff theorem mem_generate_iff {s : Set <| Set α} {U : Set α} : U ∈ generate s ↔ ∃ t ⊆ s, Set.Finite t ∧ ⋂₀ t ⊆ U := by constructor <;> intro h · induction h with | @basic V V_in => exact ⟨{V}, singleton_subset_iff.2 V_in, finite_singleton _, (sInter_singleton _).subset⟩ | univ => exact ⟨∅, empty_subset _, finite_empty, subset_univ _⟩ | superset _ hVW hV => rcases hV with ⟨t, hts, ht, htV⟩ exact ⟨t, hts, ht, htV.trans hVW⟩ | inter _ _ hV hW => rcases hV, hW with ⟨⟨t, hts, ht, htV⟩, u, hus, hu, huW⟩ exact ⟨t ∪ u, union_subset hts hus, ht.union hu, (sInter_union _ _).subset.trans <| inter_subset_inter htV huW⟩ · rcases h with ⟨t, hts, tfin, h⟩ exact mem_of_superset ((sInter_mem tfin).2 fun V hV => GenerateSets.basic <| hts hV) h #align filter.mem_generate_iff Filter.mem_generate_iff @[simp] lemma generate_singleton (s : Set α) : generate {s} = 𝓟 s := le_antisymm (fun _t ht ↦ mem_of_superset (mem_generate_of_mem <| mem_singleton _) ht) <| le_generate_iff.2 <| singleton_subset_iff.2 Subset.rfl /-- `mkOfClosure s hs` constructs a filter on `α` whose elements set is exactly `s : Set (Set α)`, provided one gives the assumption `hs : (generate s).sets = s`. -/ protected def mkOfClosure (s : Set (Set α)) (hs : (generate s).sets = s) : Filter α where sets := s univ_sets := hs ▸ univ_mem sets_of_superset := hs ▸ mem_of_superset inter_sets := hs ▸ inter_mem #align filter.mk_of_closure Filter.mkOfClosure theorem mkOfClosure_sets {s : Set (Set α)} {hs : (generate s).sets = s} : Filter.mkOfClosure s hs = generate s := Filter.ext fun u => show u ∈ (Filter.mkOfClosure s hs).sets ↔ u ∈ (generate s).sets from hs.symm ▸ Iff.rfl #align filter.mk_of_closure_sets Filter.mkOfClosure_sets /-- Galois insertion from sets of sets into filters. -/ def giGenerate (α : Type*) : @GaloisInsertion (Set (Set α)) (Filter α)ᵒᵈ _ _ Filter.generate Filter.sets where gc _ _ := le_generate_iff le_l_u _ _ h := GenerateSets.basic h choice s hs := Filter.mkOfClosure s (le_antisymm hs <| le_generate_iff.1 <| le_rfl) choice_eq _ _ := mkOfClosure_sets #align filter.gi_generate Filter.giGenerate /-- The infimum of filters is the filter generated by intersections of elements of the two filters. -/ instance : Inf (Filter α) := ⟨fun f g : Filter α => { sets := { s | ∃ a ∈ f, ∃ b ∈ g, s = a ∩ b } univ_sets := ⟨_, univ_mem, _, univ_mem, by simp⟩ sets_of_superset := by rintro x y ⟨a, ha, b, hb, rfl⟩ xy refine ⟨a ∪ y, mem_of_superset ha subset_union_left, b ∪ y, mem_of_superset hb subset_union_left, ?_⟩ rw [← inter_union_distrib_right, union_eq_self_of_subset_left xy] inter_sets := by rintro x y ⟨a, ha, b, hb, rfl⟩ ⟨c, hc, d, hd, rfl⟩ refine ⟨a ∩ c, inter_mem ha hc, b ∩ d, inter_mem hb hd, ?_⟩ ac_rfl }⟩ theorem mem_inf_iff {f g : Filter α} {s : Set α} : s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, s = t₁ ∩ t₂ := Iff.rfl #align filter.mem_inf_iff Filter.mem_inf_iff theorem mem_inf_of_left {f g : Filter α} {s : Set α} (h : s ∈ f) : s ∈ f ⊓ g := ⟨s, h, univ, univ_mem, (inter_univ s).symm⟩ #align filter.mem_inf_of_left Filter.mem_inf_of_left theorem mem_inf_of_right {f g : Filter α} {s : Set α} (h : s ∈ g) : s ∈ f ⊓ g := ⟨univ, univ_mem, s, h, (univ_inter s).symm⟩ #align filter.mem_inf_of_right Filter.mem_inf_of_right theorem inter_mem_inf {α : Type u} {f g : Filter α} {s t : Set α} (hs : s ∈ f) (ht : t ∈ g) : s ∩ t ∈ f ⊓ g := ⟨s, hs, t, ht, rfl⟩ #align filter.inter_mem_inf Filter.inter_mem_inf theorem mem_inf_of_inter {f g : Filter α} {s t u : Set α} (hs : s ∈ f) (ht : t ∈ g) (h : s ∩ t ⊆ u) : u ∈ f ⊓ g := mem_of_superset (inter_mem_inf hs ht) h #align filter.mem_inf_of_inter Filter.mem_inf_of_inter theorem mem_inf_iff_superset {f g : Filter α} {s : Set α} : s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ ∩ t₂ ⊆ s := ⟨fun ⟨t₁, h₁, t₂, h₂, Eq⟩ => ⟨t₁, h₁, t₂, h₂, Eq ▸ Subset.rfl⟩, fun ⟨_, h₁, _, h₂, sub⟩ => mem_inf_of_inter h₁ h₂ sub⟩ #align filter.mem_inf_iff_superset Filter.mem_inf_iff_superset instance : Top (Filter α) := ⟨{ sets := { s | ∀ x, x ∈ s } univ_sets := fun x => mem_univ x sets_of_superset := fun hx hxy a => hxy (hx a) inter_sets := fun hx hy _ => mem_inter (hx _) (hy _) }⟩ theorem mem_top_iff_forall {s : Set α} : s ∈ (⊤ : Filter α) ↔ ∀ x, x ∈ s := Iff.rfl #align filter.mem_top_iff_forall Filter.mem_top_iff_forall @[simp] theorem mem_top {s : Set α} : s ∈ (⊤ : Filter α) ↔ s = univ := by rw [mem_top_iff_forall, eq_univ_iff_forall] #align filter.mem_top Filter.mem_top section CompleteLattice /- We lift the complete lattice along the Galois connection `generate` / `sets`. Unfortunately, we want to have different definitional equalities for some lattice operations. So we define them upfront and change the lattice operations for the complete lattice instance. -/ instance instCompleteLatticeFilter : CompleteLattice (Filter α) := { @OrderDual.instCompleteLattice _ (giGenerate α).liftCompleteLattice with le := (· ≤ ·) top := ⊤ le_top := fun _ _s hs => (mem_top.1 hs).symm ▸ univ_mem inf := (· ⊓ ·) inf_le_left := fun _ _ _ => mem_inf_of_left inf_le_right := fun _ _ _ => mem_inf_of_right le_inf := fun _ _ _ h₁ h₂ _s ⟨_a, ha, _b, hb, hs⟩ => hs.symm ▸ inter_mem (h₁ ha) (h₂ hb) sSup := join ∘ 𝓟 le_sSup := fun _ _f hf _s hs => hs hf sSup_le := fun _ _f hf _s hs _g hg => hf _ hg hs } instance : Inhabited (Filter α) := ⟨⊥⟩ end CompleteLattice /-- A filter is `NeBot` if it is not equal to `⊥`, or equivalently the empty set does not belong to the filter. Bourbaki include this assumption in the definition of a filter but we prefer to have a `CompleteLattice` structure on `Filter _`, so we use a typeclass argument in lemmas instead. -/ class NeBot (f : Filter α) : Prop where /-- The filter is nontrivial: `f ≠ ⊥` or equivalently, `∅ ∉ f`. -/ ne' : f ≠ ⊥ #align filter.ne_bot Filter.NeBot theorem neBot_iff {f : Filter α} : NeBot f ↔ f ≠ ⊥ := ⟨fun h => h.1, fun h => ⟨h⟩⟩ #align filter.ne_bot_iff Filter.neBot_iff theorem NeBot.ne {f : Filter α} (hf : NeBot f) : f ≠ ⊥ := hf.ne' #align filter.ne_bot.ne Filter.NeBot.ne @[simp] theorem not_neBot {f : Filter α} : ¬f.NeBot ↔ f = ⊥ := neBot_iff.not_left #align filter.not_ne_bot Filter.not_neBot theorem NeBot.mono {f g : Filter α} (hf : NeBot f) (hg : f ≤ g) : NeBot g := ⟨ne_bot_of_le_ne_bot hf.1 hg⟩ #align filter.ne_bot.mono Filter.NeBot.mono theorem neBot_of_le {f g : Filter α} [hf : NeBot f] (hg : f ≤ g) : NeBot g := hf.mono hg #align filter.ne_bot_of_le Filter.neBot_of_le @[simp] theorem sup_neBot {f g : Filter α} : NeBot (f ⊔ g) ↔ NeBot f ∨ NeBot g := by simp only [neBot_iff, not_and_or, Ne, sup_eq_bot_iff] #align filter.sup_ne_bot Filter.sup_neBot theorem not_disjoint_self_iff : ¬Disjoint f f ↔ f.NeBot := by rw [disjoint_self, neBot_iff] #align filter.not_disjoint_self_iff Filter.not_disjoint_self_iff theorem bot_sets_eq : (⊥ : Filter α).sets = univ := rfl #align filter.bot_sets_eq Filter.bot_sets_eq /-- Either `f = ⊥` or `Filter.NeBot f`. This is a version of `eq_or_ne` that uses `Filter.NeBot` as the second alternative, to be used as an instance. -/ theorem eq_or_neBot (f : Filter α) : f = ⊥ ∨ NeBot f := (eq_or_ne f ⊥).imp_right NeBot.mk theorem sup_sets_eq {f g : Filter α} : (f ⊔ g).sets = f.sets ∩ g.sets := (giGenerate α).gc.u_inf #align filter.sup_sets_eq Filter.sup_sets_eq theorem sSup_sets_eq {s : Set (Filter α)} : (sSup s).sets = ⋂ f ∈ s, (f : Filter α).sets := (giGenerate α).gc.u_sInf #align filter.Sup_sets_eq Filter.sSup_sets_eq theorem iSup_sets_eq {f : ι → Filter α} : (iSup f).sets = ⋂ i, (f i).sets := (giGenerate α).gc.u_iInf #align filter.supr_sets_eq Filter.iSup_sets_eq theorem generate_empty : Filter.generate ∅ = (⊤ : Filter α) := (giGenerate α).gc.l_bot #align filter.generate_empty Filter.generate_empty theorem generate_univ : Filter.generate univ = (⊥ : Filter α) := bot_unique fun _ _ => GenerateSets.basic (mem_univ _) #align filter.generate_univ Filter.generate_univ theorem generate_union {s t : Set (Set α)} : Filter.generate (s ∪ t) = Filter.generate s ⊓ Filter.generate t := (giGenerate α).gc.l_sup #align filter.generate_union Filter.generate_union theorem generate_iUnion {s : ι → Set (Set α)} : Filter.generate (⋃ i, s i) = ⨅ i, Filter.generate (s i) := (giGenerate α).gc.l_iSup #align filter.generate_Union Filter.generate_iUnion @[simp] theorem mem_bot {s : Set α} : s ∈ (⊥ : Filter α) := trivial #align filter.mem_bot Filter.mem_bot @[simp] theorem mem_sup {f g : Filter α} {s : Set α} : s ∈ f ⊔ g ↔ s ∈ f ∧ s ∈ g := Iff.rfl #align filter.mem_sup Filter.mem_sup theorem union_mem_sup {f g : Filter α} {s t : Set α} (hs : s ∈ f) (ht : t ∈ g) : s ∪ t ∈ f ⊔ g := ⟨mem_of_superset hs subset_union_left, mem_of_superset ht subset_union_right⟩ #align filter.union_mem_sup Filter.union_mem_sup @[simp] theorem mem_sSup {x : Set α} {s : Set (Filter α)} : x ∈ sSup s ↔ ∀ f ∈ s, x ∈ (f : Filter α) := Iff.rfl #align filter.mem_Sup Filter.mem_sSup @[simp] theorem mem_iSup {x : Set α} {f : ι → Filter α} : x ∈ iSup f ↔ ∀ i, x ∈ f i := by simp only [← Filter.mem_sets, iSup_sets_eq, iff_self_iff, mem_iInter] #align filter.mem_supr Filter.mem_iSup @[simp] theorem iSup_neBot {f : ι → Filter α} : (⨆ i, f i).NeBot ↔ ∃ i, (f i).NeBot := by simp [neBot_iff] #align filter.supr_ne_bot Filter.iSup_neBot theorem iInf_eq_generate (s : ι → Filter α) : iInf s = generate (⋃ i, (s i).sets) := show generate _ = generate _ from congr_arg _ <| congr_arg sSup <| (range_comp _ _).symm #align filter.infi_eq_generate Filter.iInf_eq_generate theorem mem_iInf_of_mem {f : ι → Filter α} (i : ι) {s} (hs : s ∈ f i) : s ∈ ⨅ i, f i := iInf_le f i hs #align filter.mem_infi_of_mem Filter.mem_iInf_of_mem theorem mem_iInf_of_iInter {ι} {s : ι → Filter α} {U : Set α} {I : Set ι} (I_fin : I.Finite) {V : I → Set α} (hV : ∀ i, V i ∈ s i) (hU : ⋂ i, V i ⊆ U) : U ∈ ⨅ i, s i := by haveI := I_fin.fintype refine mem_of_superset (iInter_mem.2 fun i => ?_) hU exact mem_iInf_of_mem (i : ι) (hV _) #align filter.mem_infi_of_Inter Filter.mem_iInf_of_iInter theorem mem_iInf {ι} {s : ι → Filter α} {U : Set α} : (U ∈ ⨅ i, s i) ↔ ∃ I : Set ι, I.Finite ∧ ∃ V : I → Set α, (∀ i, V i ∈ s i) ∧ U = ⋂ i, V i := by constructor · rw [iInf_eq_generate, mem_generate_iff] rintro ⟨t, tsub, tfin, tinter⟩ rcases eq_finite_iUnion_of_finite_subset_iUnion tfin tsub with ⟨I, Ifin, σ, σfin, σsub, rfl⟩ rw [sInter_iUnion] at tinter set V := fun i => U ∪ ⋂₀ σ i with hV have V_in : ∀ i, V i ∈ s i := by rintro i have : ⋂₀ σ i ∈ s i := by rw [sInter_mem (σfin _)] apply σsub exact mem_of_superset this subset_union_right refine ⟨I, Ifin, V, V_in, ?_⟩ rwa [hV, ← union_iInter, union_eq_self_of_subset_right] · rintro ⟨I, Ifin, V, V_in, rfl⟩ exact mem_iInf_of_iInter Ifin V_in Subset.rfl #align filter.mem_infi Filter.mem_iInf theorem mem_iInf' {ι} {s : ι → Filter α} {U : Set α} : (U ∈ ⨅ i, s i) ↔ ∃ I : Set ι, I.Finite ∧ ∃ V : ι → Set α, (∀ i, V i ∈ s i) ∧ (∀ i ∉ I, V i = univ) ∧ (U = ⋂ i ∈ I, V i) ∧ U = ⋂ i, V i := by simp only [mem_iInf, SetCoe.forall', biInter_eq_iInter] refine ⟨?_, fun ⟨I, If, V, hVs, _, hVU, _⟩ => ⟨I, If, fun i => V i, fun i => hVs i, hVU⟩⟩ rintro ⟨I, If, V, hV, rfl⟩ refine ⟨I, If, fun i => if hi : i ∈ I then V ⟨i, hi⟩ else univ, fun i => ?_, fun i hi => ?_, ?_⟩ · dsimp only split_ifs exacts [hV _, univ_mem] · exact dif_neg hi · simp only [iInter_dite, biInter_eq_iInter, dif_pos (Subtype.coe_prop _), Subtype.coe_eta, iInter_univ, inter_univ, eq_self_iff_true, true_and_iff] #align filter.mem_infi' Filter.mem_iInf' theorem exists_iInter_of_mem_iInf {ι : Type*} {α : Type*} {f : ι → Filter α} {s} (hs : s ∈ ⨅ i, f i) : ∃ t : ι → Set α, (∀ i, t i ∈ f i) ∧ s = ⋂ i, t i := let ⟨_, _, V, hVs, _, _, hVU'⟩ := mem_iInf'.1 hs; ⟨V, hVs, hVU'⟩ #align filter.exists_Inter_of_mem_infi Filter.exists_iInter_of_mem_iInf theorem mem_iInf_of_finite {ι : Type*} [Finite ι] {α : Type*} {f : ι → Filter α} (s) : (s ∈ ⨅ i, f i) ↔ ∃ t : ι → Set α, (∀ i, t i ∈ f i) ∧ s = ⋂ i, t i := by refine ⟨exists_iInter_of_mem_iInf, ?_⟩ rintro ⟨t, ht, rfl⟩ exact iInter_mem.2 fun i => mem_iInf_of_mem i (ht i) #align filter.mem_infi_of_finite Filter.mem_iInf_of_finite @[simp] theorem le_principal_iff {s : Set α} {f : Filter α} : f ≤ 𝓟 s ↔ s ∈ f := ⟨fun h => h Subset.rfl, fun hs _ ht => mem_of_superset hs ht⟩ #align filter.le_principal_iff Filter.le_principal_iff theorem Iic_principal (s : Set α) : Iic (𝓟 s) = { l | s ∈ l } := Set.ext fun _ => le_principal_iff #align filter.Iic_principal Filter.Iic_principal theorem principal_mono {s t : Set α} : 𝓟 s ≤ 𝓟 t ↔ s ⊆ t := by simp only [le_principal_iff, iff_self_iff, mem_principal] #align filter.principal_mono Filter.principal_mono @[gcongr] alias ⟨_, _root_.GCongr.filter_principal_mono⟩ := principal_mono @[mono] theorem monotone_principal : Monotone (𝓟 : Set α → Filter α) := fun _ _ => principal_mono.2 #align filter.monotone_principal Filter.monotone_principal @[simp] theorem principal_eq_iff_eq {s t : Set α} : 𝓟 s = 𝓟 t ↔ s = t := by simp only [le_antisymm_iff, le_principal_iff, mem_principal]; rfl #align filter.principal_eq_iff_eq Filter.principal_eq_iff_eq @[simp] theorem join_principal_eq_sSup {s : Set (Filter α)} : join (𝓟 s) = sSup s := rfl #align filter.join_principal_eq_Sup Filter.join_principal_eq_sSup @[simp] theorem principal_univ : 𝓟 (univ : Set α) = ⊤ := top_unique <| by simp only [le_principal_iff, mem_top, eq_self_iff_true] #align filter.principal_univ Filter.principal_univ @[simp] theorem principal_empty : 𝓟 (∅ : Set α) = ⊥ := bot_unique fun _ _ => empty_subset _ #align filter.principal_empty Filter.principal_empty theorem generate_eq_biInf (S : Set (Set α)) : generate S = ⨅ s ∈ S, 𝓟 s := eq_of_forall_le_iff fun f => by simp [le_generate_iff, le_principal_iff, subset_def] #align filter.generate_eq_binfi Filter.generate_eq_biInf /-! ### Lattice equations -/ theorem empty_mem_iff_bot {f : Filter α} : ∅ ∈ f ↔ f = ⊥ := ⟨fun h => bot_unique fun s _ => mem_of_superset h (empty_subset s), fun h => h.symm ▸ mem_bot⟩ #align filter.empty_mem_iff_bot Filter.empty_mem_iff_bot theorem nonempty_of_mem {f : Filter α} [hf : NeBot f] {s : Set α} (hs : s ∈ f) : s.Nonempty := s.eq_empty_or_nonempty.elim (fun h => absurd hs (h.symm ▸ mt empty_mem_iff_bot.mp hf.1)) id #align filter.nonempty_of_mem Filter.nonempty_of_mem theorem NeBot.nonempty_of_mem {f : Filter α} (hf : NeBot f) {s : Set α} (hs : s ∈ f) : s.Nonempty := @Filter.nonempty_of_mem α f hf s hs #align filter.ne_bot.nonempty_of_mem Filter.NeBot.nonempty_of_mem @[simp] theorem empty_not_mem (f : Filter α) [NeBot f] : ¬∅ ∈ f := fun h => (nonempty_of_mem h).ne_empty rfl #align filter.empty_not_mem Filter.empty_not_mem theorem nonempty_of_neBot (f : Filter α) [NeBot f] : Nonempty α := nonempty_of_exists <| nonempty_of_mem (univ_mem : univ ∈ f) #align filter.nonempty_of_ne_bot Filter.nonempty_of_neBot theorem compl_not_mem {f : Filter α} {s : Set α} [NeBot f] (h : s ∈ f) : sᶜ ∉ f := fun hsc => (nonempty_of_mem (inter_mem h hsc)).ne_empty <| inter_compl_self s #align filter.compl_not_mem Filter.compl_not_mem theorem filter_eq_bot_of_isEmpty [IsEmpty α] (f : Filter α) : f = ⊥ := empty_mem_iff_bot.mp <| univ_mem' isEmptyElim #align filter.filter_eq_bot_of_is_empty Filter.filter_eq_bot_of_isEmpty protected lemma disjoint_iff {f g : Filter α} : Disjoint f g ↔ ∃ s ∈ f, ∃ t ∈ g, Disjoint s t := by simp only [disjoint_iff, ← empty_mem_iff_bot, mem_inf_iff, inf_eq_inter, bot_eq_empty, @eq_comm _ ∅] #align filter.disjoint_iff Filter.disjoint_iff theorem disjoint_of_disjoint_of_mem {f g : Filter α} {s t : Set α} (h : Disjoint s t) (hs : s ∈ f) (ht : t ∈ g) : Disjoint f g := Filter.disjoint_iff.mpr ⟨s, hs, t, ht, h⟩ #align filter.disjoint_of_disjoint_of_mem Filter.disjoint_of_disjoint_of_mem theorem NeBot.not_disjoint (hf : f.NeBot) (hs : s ∈ f) (ht : t ∈ f) : ¬Disjoint s t := fun h => not_disjoint_self_iff.2 hf <| Filter.disjoint_iff.2 ⟨s, hs, t, ht, h⟩ #align filter.ne_bot.not_disjoint Filter.NeBot.not_disjoint theorem inf_eq_bot_iff {f g : Filter α} : f ⊓ g = ⊥ ↔ ∃ U ∈ f, ∃ V ∈ g, U ∩ V = ∅ := by simp only [← disjoint_iff, Filter.disjoint_iff, Set.disjoint_iff_inter_eq_empty] #align filter.inf_eq_bot_iff Filter.inf_eq_bot_iff theorem _root_.Pairwise.exists_mem_filter_of_disjoint {ι : Type*} [Finite ι] {l : ι → Filter α} (hd : Pairwise (Disjoint on l)) : ∃ s : ι → Set α, (∀ i, s i ∈ l i) ∧ Pairwise (Disjoint on s) := by have : Pairwise fun i j => ∃ (s : {s // s ∈ l i}) (t : {t // t ∈ l j}), Disjoint s.1 t.1 := by simpa only [Pairwise, Function.onFun, Filter.disjoint_iff, exists_prop, Subtype.exists] using hd choose! s t hst using this refine ⟨fun i => ⋂ j, @s i j ∩ @t j i, fun i => ?_, fun i j hij => ?_⟩ exacts [iInter_mem.2 fun j => inter_mem (@s i j).2 (@t j i).2, (hst hij).mono ((iInter_subset _ j).trans inter_subset_left) ((iInter_subset _ i).trans inter_subset_right)] #align pairwise.exists_mem_filter_of_disjoint Pairwise.exists_mem_filter_of_disjoint theorem _root_.Set.PairwiseDisjoint.exists_mem_filter {ι : Type*} {l : ι → Filter α} {t : Set ι} (hd : t.PairwiseDisjoint l) (ht : t.Finite) : ∃ s : ι → Set α, (∀ i, s i ∈ l i) ∧ t.PairwiseDisjoint s := by haveI := ht.to_subtype rcases (hd.subtype _ _).exists_mem_filter_of_disjoint with ⟨s, hsl, hsd⟩ lift s to (i : t) → {s // s ∈ l i} using hsl rcases @Subtype.exists_pi_extension ι (fun i => { s // s ∈ l i }) _ _ s with ⟨s, rfl⟩ exact ⟨fun i => s i, fun i => (s i).2, hsd.set_of_subtype _ _⟩ #align set.pairwise_disjoint.exists_mem_filter Set.PairwiseDisjoint.exists_mem_filter /-- There is exactly one filter on an empty type. -/ instance unique [IsEmpty α] : Unique (Filter α) where default := ⊥ uniq := filter_eq_bot_of_isEmpty #align filter.unique Filter.unique theorem NeBot.nonempty (f : Filter α) [hf : f.NeBot] : Nonempty α := not_isEmpty_iff.mp fun _ ↦ hf.ne (Subsingleton.elim _ _) /-- There are only two filters on a `Subsingleton`: `⊥` and `⊤`. If the type is empty, then they are equal. -/ theorem eq_top_of_neBot [Subsingleton α] (l : Filter α) [NeBot l] : l = ⊤ := by refine top_unique fun s hs => ?_ obtain rfl : s = univ := Subsingleton.eq_univ_of_nonempty (nonempty_of_mem hs) exact univ_mem #align filter.eq_top_of_ne_bot Filter.eq_top_of_neBot theorem forall_mem_nonempty_iff_neBot {f : Filter α} : (∀ s : Set α, s ∈ f → s.Nonempty) ↔ NeBot f := ⟨fun h => ⟨fun hf => not_nonempty_empty (h ∅ <| hf.symm ▸ mem_bot)⟩, @nonempty_of_mem _ _⟩ #align filter.forall_mem_nonempty_iff_ne_bot Filter.forall_mem_nonempty_iff_neBot instance instNontrivialFilter [Nonempty α] : Nontrivial (Filter α) := ⟨⟨⊤, ⊥, NeBot.ne <| forall_mem_nonempty_iff_neBot.1 fun s hs => by rwa [mem_top.1 hs, ← nonempty_iff_univ_nonempty]⟩⟩ theorem nontrivial_iff_nonempty : Nontrivial (Filter α) ↔ Nonempty α := ⟨fun _ => by_contra fun h' => haveI := not_nonempty_iff.1 h' not_subsingleton (Filter α) inferInstance, @Filter.instNontrivialFilter α⟩ #align filter.nontrivial_iff_nonempty Filter.nontrivial_iff_nonempty theorem eq_sInf_of_mem_iff_exists_mem {S : Set (Filter α)} {l : Filter α} (h : ∀ {s}, s ∈ l ↔ ∃ f ∈ S, s ∈ f) : l = sInf S := le_antisymm (le_sInf fun f hf _ hs => h.2 ⟨f, hf, hs⟩) fun _ hs => let ⟨_, hf, hs⟩ := h.1 hs; (sInf_le hf) hs #align filter.eq_Inf_of_mem_iff_exists_mem Filter.eq_sInf_of_mem_iff_exists_mem theorem eq_iInf_of_mem_iff_exists_mem {f : ι → Filter α} {l : Filter α} (h : ∀ {s}, s ∈ l ↔ ∃ i, s ∈ f i) : l = iInf f := eq_sInf_of_mem_iff_exists_mem <| h.trans exists_range_iff.symm #align filter.eq_infi_of_mem_iff_exists_mem Filter.eq_iInf_of_mem_iff_exists_mem theorem eq_biInf_of_mem_iff_exists_mem {f : ι → Filter α} {p : ι → Prop} {l : Filter α} (h : ∀ {s}, s ∈ l ↔ ∃ i, p i ∧ s ∈ f i) : l = ⨅ (i) (_ : p i), f i := by rw [iInf_subtype'] exact eq_iInf_of_mem_iff_exists_mem fun {_} => by simp only [Subtype.exists, h, exists_prop] #align filter.eq_binfi_of_mem_iff_exists_mem Filter.eq_biInf_of_mem_iff_exists_memₓ theorem iInf_sets_eq {f : ι → Filter α} (h : Directed (· ≥ ·) f) [ne : Nonempty ι] : (iInf f).sets = ⋃ i, (f i).sets := let ⟨i⟩ := ne let u := { sets := ⋃ i, (f i).sets univ_sets := mem_iUnion.2 ⟨i, univ_mem⟩ sets_of_superset := by simp only [mem_iUnion, exists_imp] exact fun i hx hxy => ⟨i, mem_of_superset hx hxy⟩ inter_sets := by simp only [mem_iUnion, exists_imp] intro x y a hx b hy rcases h a b with ⟨c, ha, hb⟩ exact ⟨c, inter_mem (ha hx) (hb hy)⟩ } have : u = iInf f := eq_iInf_of_mem_iff_exists_mem mem_iUnion -- Porting note: it was just `congr_arg filter.sets this.symm` (congr_arg Filter.sets this.symm).trans <| by simp only #align filter.infi_sets_eq Filter.iInf_sets_eq theorem mem_iInf_of_directed {f : ι → Filter α} (h : Directed (· ≥ ·) f) [Nonempty ι] (s) : s ∈ iInf f ↔ ∃ i, s ∈ f i := by simp only [← Filter.mem_sets, iInf_sets_eq h, mem_iUnion] #align filter.mem_infi_of_directed Filter.mem_iInf_of_directed theorem mem_biInf_of_directed {f : β → Filter α} {s : Set β} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) s) (ne : s.Nonempty) {t : Set α} : (t ∈ ⨅ i ∈ s, f i) ↔ ∃ i ∈ s, t ∈ f i := by haveI := ne.to_subtype simp_rw [iInf_subtype', mem_iInf_of_directed h.directed_val, Subtype.exists, exists_prop] #align filter.mem_binfi_of_directed Filter.mem_biInf_of_directed theorem biInf_sets_eq {f : β → Filter α} {s : Set β} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) s) (ne : s.Nonempty) : (⨅ i ∈ s, f i).sets = ⋃ i ∈ s, (f i).sets := ext fun t => by simp [mem_biInf_of_directed h ne] #align filter.binfi_sets_eq Filter.biInf_sets_eq theorem iInf_sets_eq_finite {ι : Type*} (f : ι → Filter α) : (⨅ i, f i).sets = ⋃ t : Finset ι, (⨅ i ∈ t, f i).sets := by rw [iInf_eq_iInf_finset, iInf_sets_eq] exact directed_of_isDirected_le fun _ _ => biInf_mono #align filter.infi_sets_eq_finite Filter.iInf_sets_eq_finite theorem iInf_sets_eq_finite' (f : ι → Filter α) : (⨅ i, f i).sets = ⋃ t : Finset (PLift ι), (⨅ i ∈ t, f (PLift.down i)).sets := by rw [← iInf_sets_eq_finite, ← Equiv.plift.surjective.iInf_comp, Equiv.plift_apply] #align filter.infi_sets_eq_finite' Filter.iInf_sets_eq_finite' theorem mem_iInf_finite {ι : Type*} {f : ι → Filter α} (s) : s ∈ iInf f ↔ ∃ t : Finset ι, s ∈ ⨅ i ∈ t, f i := (Set.ext_iff.1 (iInf_sets_eq_finite f) s).trans mem_iUnion #align filter.mem_infi_finite Filter.mem_iInf_finite theorem mem_iInf_finite' {f : ι → Filter α} (s) : s ∈ iInf f ↔ ∃ t : Finset (PLift ι), s ∈ ⨅ i ∈ t, f (PLift.down i) := (Set.ext_iff.1 (iInf_sets_eq_finite' f) s).trans mem_iUnion #align filter.mem_infi_finite' Filter.mem_iInf_finite' @[simp] theorem sup_join {f₁ f₂ : Filter (Filter α)} : join f₁ ⊔ join f₂ = join (f₁ ⊔ f₂) := Filter.ext fun x => by simp only [mem_sup, mem_join] #align filter.sup_join Filter.sup_join @[simp] theorem iSup_join {ι : Sort w} {f : ι → Filter (Filter α)} : ⨆ x, join (f x) = join (⨆ x, f x) := Filter.ext fun x => by simp only [mem_iSup, mem_join] #align filter.supr_join Filter.iSup_join instance : DistribLattice (Filter α) := { Filter.instCompleteLatticeFilter with le_sup_inf := by intro x y z s simp only [and_assoc, mem_inf_iff, mem_sup, exists_prop, exists_imp, and_imp] rintro hs t₁ ht₁ t₂ ht₂ rfl exact ⟨t₁, x.sets_of_superset hs inter_subset_left, ht₁, t₂, x.sets_of_superset hs inter_subset_right, ht₂, rfl⟩ } -- The dual version does not hold! `Filter α` is not a `CompleteDistribLattice`. -/ instance : Coframe (Filter α) := { Filter.instCompleteLatticeFilter with iInf_sup_le_sup_sInf := fun f s t ⟨h₁, h₂⟩ => by rw [iInf_subtype'] rw [sInf_eq_iInf', iInf_sets_eq_finite, mem_iUnion] at h₂ obtain ⟨u, hu⟩ := h₂ rw [← Finset.inf_eq_iInf] at hu suffices ⨅ i : s, f ⊔ ↑i ≤ f ⊔ u.inf fun i => ↑i from this ⟨h₁, hu⟩ refine Finset.induction_on u (le_sup_of_le_right le_top) ?_ rintro ⟨i⟩ u _ ih rw [Finset.inf_insert, sup_inf_left] exact le_inf (iInf_le _ _) ih } theorem mem_iInf_finset {s : Finset α} {f : α → Filter β} {t : Set β} : (t ∈ ⨅ a ∈ s, f a) ↔ ∃ p : α → Set β, (∀ a ∈ s, p a ∈ f a) ∧ t = ⋂ a ∈ s, p a := by simp only [← Finset.set_biInter_coe, biInter_eq_iInter, iInf_subtype'] refine ⟨fun h => ?_, ?_⟩ · rcases (mem_iInf_of_finite _).1 h with ⟨p, hp, rfl⟩ refine ⟨fun a => if h : a ∈ s then p ⟨a, h⟩ else univ, fun a ha => by simpa [ha] using hp ⟨a, ha⟩, ?_⟩ refine iInter_congr_of_surjective id surjective_id ?_ rintro ⟨a, ha⟩ simp [ha] · rintro ⟨p, hpf, rfl⟩ exact iInter_mem.2 fun a => mem_iInf_of_mem a (hpf a a.2) #align filter.mem_infi_finset Filter.mem_iInf_finset /-- If `f : ι → Filter α` is directed, `ι` is not empty, and `∀ i, f i ≠ ⊥`, then `iInf f ≠ ⊥`. See also `iInf_neBot_of_directed` for a version assuming `Nonempty α` instead of `Nonempty ι`. -/ theorem iInf_neBot_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) : (∀ i, NeBot (f i)) → NeBot (iInf f) := not_imp_not.1 <| by simpa only [not_forall, not_neBot, ← empty_mem_iff_bot, mem_iInf_of_directed hd] using id #align filter.infi_ne_bot_of_directed' Filter.iInf_neBot_of_directed' /-- If `f : ι → Filter α` is directed, `α` is not empty, and `∀ i, f i ≠ ⊥`, then `iInf f ≠ ⊥`. See also `iInf_neBot_of_directed'` for a version assuming `Nonempty ι` instead of `Nonempty α`. -/ theorem iInf_neBot_of_directed {f : ι → Filter α} [hn : Nonempty α] (hd : Directed (· ≥ ·) f) (hb : ∀ i, NeBot (f i)) : NeBot (iInf f) := by cases isEmpty_or_nonempty ι · constructor simp [iInf_of_empty f, top_ne_bot] · exact iInf_neBot_of_directed' hd hb #align filter.infi_ne_bot_of_directed Filter.iInf_neBot_of_directed theorem sInf_neBot_of_directed' {s : Set (Filter α)} (hne : s.Nonempty) (hd : DirectedOn (· ≥ ·) s) (hbot : ⊥ ∉ s) : NeBot (sInf s) := (sInf_eq_iInf' s).symm ▸ @iInf_neBot_of_directed' _ _ _ hne.to_subtype hd.directed_val fun ⟨_, hf⟩ => ⟨ne_of_mem_of_not_mem hf hbot⟩ #align filter.Inf_ne_bot_of_directed' Filter.sInf_neBot_of_directed' theorem sInf_neBot_of_directed [Nonempty α] {s : Set (Filter α)} (hd : DirectedOn (· ≥ ·) s) (hbot : ⊥ ∉ s) : NeBot (sInf s) := (sInf_eq_iInf' s).symm ▸ iInf_neBot_of_directed hd.directed_val fun ⟨_, hf⟩ => ⟨ne_of_mem_of_not_mem hf hbot⟩ #align filter.Inf_ne_bot_of_directed Filter.sInf_neBot_of_directed theorem iInf_neBot_iff_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) : NeBot (iInf f) ↔ ∀ i, NeBot (f i) := ⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed' hd⟩ #align filter.infi_ne_bot_iff_of_directed' Filter.iInf_neBot_iff_of_directed' theorem iInf_neBot_iff_of_directed {f : ι → Filter α} [Nonempty α] (hd : Directed (· ≥ ·) f) : NeBot (iInf f) ↔ ∀ i, NeBot (f i) := ⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed hd⟩ #align filter.infi_ne_bot_iff_of_directed Filter.iInf_neBot_iff_of_directed @[elab_as_elim] theorem iInf_sets_induct {f : ι → Filter α} {s : Set α} (hs : s ∈ iInf f) {p : Set α → Prop} (uni : p univ) (ins : ∀ {i s₁ s₂}, s₁ ∈ f i → p s₂ → p (s₁ ∩ s₂)) : p s := by rw [mem_iInf_finite'] at hs simp only [← Finset.inf_eq_iInf] at hs rcases hs with ⟨is, his⟩ induction is using Finset.induction_on generalizing s with | empty => rwa [mem_top.1 his] | insert _ ih => rw [Finset.inf_insert, mem_inf_iff] at his rcases his with ⟨s₁, hs₁, s₂, hs₂, rfl⟩ exact ins hs₁ (ih hs₂) #align filter.infi_sets_induct Filter.iInf_sets_induct /-! #### `principal` equations -/ @[simp] theorem inf_principal {s t : Set α} : 𝓟 s ⊓ 𝓟 t = 𝓟 (s ∩ t) := le_antisymm (by simp only [le_principal_iff, mem_inf_iff]; exact ⟨s, Subset.rfl, t, Subset.rfl, rfl⟩) (by simp [le_inf_iff, inter_subset_left, inter_subset_right]) #align filter.inf_principal Filter.inf_principal @[simp] theorem sup_principal {s t : Set α} : 𝓟 s ⊔ 𝓟 t = 𝓟 (s ∪ t) := Filter.ext fun u => by simp only [union_subset_iff, mem_sup, mem_principal] #align filter.sup_principal Filter.sup_principal @[simp] theorem iSup_principal {ι : Sort w} {s : ι → Set α} : ⨆ x, 𝓟 (s x) = 𝓟 (⋃ i, s i) := Filter.ext fun x => by simp only [mem_iSup, mem_principal, iUnion_subset_iff] #align filter.supr_principal Filter.iSup_principal @[simp] theorem principal_eq_bot_iff {s : Set α} : 𝓟 s = ⊥ ↔ s = ∅ := empty_mem_iff_bot.symm.trans <| mem_principal.trans subset_empty_iff #align filter.principal_eq_bot_iff Filter.principal_eq_bot_iff @[simp] theorem principal_neBot_iff {s : Set α} : NeBot (𝓟 s) ↔ s.Nonempty := neBot_iff.trans <| (not_congr principal_eq_bot_iff).trans nonempty_iff_ne_empty.symm #align filter.principal_ne_bot_iff Filter.principal_neBot_iff alias ⟨_, _root_.Set.Nonempty.principal_neBot⟩ := principal_neBot_iff #align set.nonempty.principal_ne_bot Set.Nonempty.principal_neBot theorem isCompl_principal (s : Set α) : IsCompl (𝓟 s) (𝓟 sᶜ) := IsCompl.of_eq (by rw [inf_principal, inter_compl_self, principal_empty]) <| by rw [sup_principal, union_compl_self, principal_univ] #align filter.is_compl_principal Filter.isCompl_principal theorem mem_inf_principal' {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ tᶜ ∪ s ∈ f := by simp only [← le_principal_iff, (isCompl_principal s).le_left_iff, disjoint_assoc, inf_principal, ← (isCompl_principal (t ∩ sᶜ)).le_right_iff, compl_inter, compl_compl] #align filter.mem_inf_principal' Filter.mem_inf_principal' lemma mem_inf_principal {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ { x | x ∈ t → x ∈ s } ∈ f := by simp only [mem_inf_principal', imp_iff_not_or, setOf_or, compl_def, setOf_mem_eq] #align filter.mem_inf_principal Filter.mem_inf_principal lemma iSup_inf_principal (f : ι → Filter α) (s : Set α) : ⨆ i, f i ⊓ 𝓟 s = (⨆ i, f i) ⊓ 𝓟 s := by ext simp only [mem_iSup, mem_inf_principal] #align filter.supr_inf_principal Filter.iSup_inf_principal theorem inf_principal_eq_bot {f : Filter α} {s : Set α} : f ⊓ 𝓟 s = ⊥ ↔ sᶜ ∈ f := by rw [← empty_mem_iff_bot, mem_inf_principal] simp only [mem_empty_iff_false, imp_false, compl_def] #align filter.inf_principal_eq_bot Filter.inf_principal_eq_bot theorem mem_of_eq_bot {f : Filter α} {s : Set α} (h : f ⊓ 𝓟 sᶜ = ⊥) : s ∈ f := by rwa [inf_principal_eq_bot, compl_compl] at h #align filter.mem_of_eq_bot Filter.mem_of_eq_bot theorem diff_mem_inf_principal_compl {f : Filter α} {s : Set α} (hs : s ∈ f) (t : Set α) : s \ t ∈ f ⊓ 𝓟 tᶜ := inter_mem_inf hs <| mem_principal_self tᶜ #align filter.diff_mem_inf_principal_compl Filter.diff_mem_inf_principal_compl theorem principal_le_iff {s : Set α} {f : Filter α} : 𝓟 s ≤ f ↔ ∀ V ∈ f, s ⊆ V := by simp_rw [le_def, mem_principal] #align filter.principal_le_iff Filter.principal_le_iff @[simp] theorem iInf_principal_finset {ι : Type w} (s : Finset ι) (f : ι → Set α) : ⨅ i ∈ s, 𝓟 (f i) = 𝓟 (⋂ i ∈ s, f i) := by induction' s using Finset.induction_on with i s _ hs · simp · rw [Finset.iInf_insert, Finset.set_biInter_insert, hs, inf_principal] #align filter.infi_principal_finset Filter.iInf_principal_finset theorem iInf_principal {ι : Sort w} [Finite ι] (f : ι → Set α) : ⨅ i, 𝓟 (f i) = 𝓟 (⋂ i, f i) := by cases nonempty_fintype (PLift ι) rw [← iInf_plift_down, ← iInter_plift_down] simpa using iInf_principal_finset Finset.univ (f <| PLift.down ·) /-- A special case of `iInf_principal` that is safe to mark `simp`. -/ @[simp] theorem iInf_principal' {ι : Type w} [Finite ι] (f : ι → Set α) : ⨅ i, 𝓟 (f i) = 𝓟 (⋂ i, f i) := iInf_principal _ #align filter.infi_principal Filter.iInf_principal theorem iInf_principal_finite {ι : Type w} {s : Set ι} (hs : s.Finite) (f : ι → Set α) : ⨅ i ∈ s, 𝓟 (f i) = 𝓟 (⋂ i ∈ s, f i) := by lift s to Finset ι using hs exact mod_cast iInf_principal_finset s f #align filter.infi_principal_finite Filter.iInf_principal_finite end Lattice @[mono, gcongr] theorem join_mono {f₁ f₂ : Filter (Filter α)} (h : f₁ ≤ f₂) : join f₁ ≤ join f₂ := fun _ hs => h hs #align filter.join_mono Filter.join_mono /-! ### Eventually -/ /-- `f.Eventually p` or `∀ᶠ x in f, p x` mean that `{x | p x} ∈ f`. E.g., `∀ᶠ x in atTop, p x` means that `p` holds true for sufficiently large `x`. -/ protected def Eventually (p : α → Prop) (f : Filter α) : Prop := { x | p x } ∈ f #align filter.eventually Filter.Eventually @[inherit_doc Filter.Eventually] notation3 "∀ᶠ "(...)" in "f", "r:(scoped p => Filter.Eventually p f) => r theorem eventually_iff {f : Filter α} {P : α → Prop} : (∀ᶠ x in f, P x) ↔ { x | P x } ∈ f := Iff.rfl #align filter.eventually_iff Filter.eventually_iff @[simp] theorem eventually_mem_set {s : Set α} {l : Filter α} : (∀ᶠ x in l, x ∈ s) ↔ s ∈ l := Iff.rfl #align filter.eventually_mem_set Filter.eventually_mem_set protected theorem ext' {f₁ f₂ : Filter α} (h : ∀ p : α → Prop, (∀ᶠ x in f₁, p x) ↔ ∀ᶠ x in f₂, p x) : f₁ = f₂ := Filter.ext h #align filter.ext' Filter.ext' theorem Eventually.filter_mono {f₁ f₂ : Filter α} (h : f₁ ≤ f₂) {p : α → Prop} (hp : ∀ᶠ x in f₂, p x) : ∀ᶠ x in f₁, p x := h hp #align filter.eventually.filter_mono Filter.Eventually.filter_mono theorem eventually_of_mem {f : Filter α} {P : α → Prop} {U : Set α} (hU : U ∈ f) (h : ∀ x ∈ U, P x) : ∀ᶠ x in f, P x := mem_of_superset hU h #align filter.eventually_of_mem Filter.eventually_of_mem protected theorem Eventually.and {p q : α → Prop} {f : Filter α} : f.Eventually p → f.Eventually q → ∀ᶠ x in f, p x ∧ q x := inter_mem #align filter.eventually.and Filter.Eventually.and @[simp] theorem eventually_true (f : Filter α) : ∀ᶠ _ in f, True := univ_mem #align filter.eventually_true Filter.eventually_true theorem eventually_of_forall {p : α → Prop} {f : Filter α} (hp : ∀ x, p x) : ∀ᶠ x in f, p x := univ_mem' hp #align filter.eventually_of_forall Filter.eventually_of_forall @[simp] theorem eventually_false_iff_eq_bot {f : Filter α} : (∀ᶠ _ in f, False) ↔ f = ⊥ := empty_mem_iff_bot #align filter.eventually_false_iff_eq_bot Filter.eventually_false_iff_eq_bot @[simp] theorem eventually_const {f : Filter α} [t : NeBot f] {p : Prop} : (∀ᶠ _ in f, p) ↔ p := by by_cases h : p <;> simp [h, t.ne] #align filter.eventually_const Filter.eventually_const theorem eventually_iff_exists_mem {p : α → Prop} {f : Filter α} : (∀ᶠ x in f, p x) ↔ ∃ v ∈ f, ∀ y ∈ v, p y := exists_mem_subset_iff.symm #align filter.eventually_iff_exists_mem Filter.eventually_iff_exists_mem theorem Eventually.exists_mem {p : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) : ∃ v ∈ f, ∀ y ∈ v, p y := eventually_iff_exists_mem.1 hp #align filter.eventually.exists_mem Filter.Eventually.exists_mem theorem Eventually.mp {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) (hq : ∀ᶠ x in f, p x → q x) : ∀ᶠ x in f, q x := mp_mem hp hq #align filter.eventually.mp Filter.Eventually.mp theorem Eventually.mono {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) (hq : ∀ x, p x → q x) : ∀ᶠ x in f, q x := hp.mp (eventually_of_forall hq) #align filter.eventually.mono Filter.Eventually.mono theorem forall_eventually_of_eventually_forall {f : Filter α} {p : α → β → Prop} (h : ∀ᶠ x in f, ∀ y, p x y) : ∀ y, ∀ᶠ x in f, p x y := fun y => h.mono fun _ h => h y #align filter.forall_eventually_of_eventually_forall Filter.forall_eventually_of_eventually_forall @[simp] theorem eventually_and {p q : α → Prop} {f : Filter α} : (∀ᶠ x in f, p x ∧ q x) ↔ (∀ᶠ x in f, p x) ∧ ∀ᶠ x in f, q x := inter_mem_iff #align filter.eventually_and Filter.eventually_and theorem Eventually.congr {f : Filter α} {p q : α → Prop} (h' : ∀ᶠ x in f, p x) (h : ∀ᶠ x in f, p x ↔ q x) : ∀ᶠ x in f, q x := h'.mp (h.mono fun _ hx => hx.mp) #align filter.eventually.congr Filter.Eventually.congr theorem eventually_congr {f : Filter α} {p q : α → Prop} (h : ∀ᶠ x in f, p x ↔ q x) : (∀ᶠ x in f, p x) ↔ ∀ᶠ x in f, q x := ⟨fun hp => hp.congr h, fun hq => hq.congr <| by simpa only [Iff.comm] using h⟩ #align filter.eventually_congr Filter.eventually_congr @[simp] theorem eventually_all {ι : Sort*} [Finite ι] {l} {p : ι → α → Prop} : (∀ᶠ x in l, ∀ i, p i x) ↔ ∀ i, ∀ᶠ x in l, p i x := by simpa only [Filter.Eventually, setOf_forall] using iInter_mem #align filter.eventually_all Filter.eventually_all @[simp] theorem eventually_all_finite {ι} {I : Set ι} (hI : I.Finite) {l} {p : ι → α → Prop} : (∀ᶠ x in l, ∀ i ∈ I, p i x) ↔ ∀ i ∈ I, ∀ᶠ x in l, p i x := by simpa only [Filter.Eventually, setOf_forall] using biInter_mem hI #align filter.eventually_all_finite Filter.eventually_all_finite alias _root_.Set.Finite.eventually_all := eventually_all_finite #align set.finite.eventually_all Set.Finite.eventually_all -- attribute [protected] Set.Finite.eventually_all @[simp] theorem eventually_all_finset {ι} (I : Finset ι) {l} {p : ι → α → Prop} : (∀ᶠ x in l, ∀ i ∈ I, p i x) ↔ ∀ i ∈ I, ∀ᶠ x in l, p i x := I.finite_toSet.eventually_all #align filter.eventually_all_finset Filter.eventually_all_finset alias _root_.Finset.eventually_all := eventually_all_finset #align finset.eventually_all Finset.eventually_all -- attribute [protected] Finset.eventually_all @[simp] theorem eventually_or_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} : (∀ᶠ x in f, p ∨ q x) ↔ p ∨ ∀ᶠ x in f, q x := by_cases (fun h : p => by simp [h]) fun h => by simp [h] #align filter.eventually_or_distrib_left Filter.eventually_or_distrib_left @[simp] theorem eventually_or_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} : (∀ᶠ x in f, p x ∨ q) ↔ (∀ᶠ x in f, p x) ∨ q := by simp only [@or_comm _ q, eventually_or_distrib_left] #align filter.eventually_or_distrib_right Filter.eventually_or_distrib_right theorem eventually_imp_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} : (∀ᶠ x in f, p → q x) ↔ p → ∀ᶠ x in f, q x := eventually_all #align filter.eventually_imp_distrib_left Filter.eventually_imp_distrib_left @[simp] theorem eventually_bot {p : α → Prop} : ∀ᶠ x in ⊥, p x := ⟨⟩ #align filter.eventually_bot Filter.eventually_bot @[simp] theorem eventually_top {p : α → Prop} : (∀ᶠ x in ⊤, p x) ↔ ∀ x, p x := Iff.rfl #align filter.eventually_top Filter.eventually_top @[simp] theorem eventually_sup {p : α → Prop} {f g : Filter α} : (∀ᶠ x in f ⊔ g, p x) ↔ (∀ᶠ x in f, p x) ∧ ∀ᶠ x in g, p x := Iff.rfl #align filter.eventually_sup Filter.eventually_sup @[simp] theorem eventually_sSup {p : α → Prop} {fs : Set (Filter α)} : (∀ᶠ x in sSup fs, p x) ↔ ∀ f ∈ fs, ∀ᶠ x in f, p x := Iff.rfl #align filter.eventually_Sup Filter.eventually_sSup @[simp] theorem eventually_iSup {p : α → Prop} {fs : ι → Filter α} : (∀ᶠ x in ⨆ b, fs b, p x) ↔ ∀ b, ∀ᶠ x in fs b, p x := mem_iSup #align filter.eventually_supr Filter.eventually_iSup @[simp] theorem eventually_principal {a : Set α} {p : α → Prop} : (∀ᶠ x in 𝓟 a, p x) ↔ ∀ x ∈ a, p x := Iff.rfl #align filter.eventually_principal Filter.eventually_principal theorem Eventually.forall_mem {α : Type*} {f : Filter α} {s : Set α} {P : α → Prop} (hP : ∀ᶠ x in f, P x) (hf : 𝓟 s ≤ f) : ∀ x ∈ s, P x := Filter.eventually_principal.mp (hP.filter_mono hf) theorem eventually_inf {f g : Filter α} {p : α → Prop} : (∀ᶠ x in f ⊓ g, p x) ↔ ∃ s ∈ f, ∃ t ∈ g, ∀ x ∈ s ∩ t, p x := mem_inf_iff_superset #align filter.eventually_inf Filter.eventually_inf theorem eventually_inf_principal {f : Filter α} {p : α → Prop} {s : Set α} : (∀ᶠ x in f ⊓ 𝓟 s, p x) ↔ ∀ᶠ x in f, x ∈ s → p x := mem_inf_principal #align filter.eventually_inf_principal Filter.eventually_inf_principal /-! ### Frequently -/ /-- `f.Frequently p` or `∃ᶠ x in f, p x` mean that `{x | ¬p x} ∉ f`. E.g., `∃ᶠ x in atTop, p x` means that there exist arbitrarily large `x` for which `p` holds true. -/ protected def Frequently (p : α → Prop) (f : Filter α) : Prop := ¬∀ᶠ x in f, ¬p x #align filter.frequently Filter.Frequently @[inherit_doc Filter.Frequently] notation3 "∃ᶠ "(...)" in "f", "r:(scoped p => Filter.Frequently p f) => r theorem Eventually.frequently {f : Filter α} [NeBot f] {p : α → Prop} (h : ∀ᶠ x in f, p x) : ∃ᶠ x in f, p x := compl_not_mem h #align filter.eventually.frequently Filter.Eventually.frequently theorem frequently_of_forall {f : Filter α} [NeBot f] {p : α → Prop} (h : ∀ x, p x) : ∃ᶠ x in f, p x := Eventually.frequently (eventually_of_forall h) #align filter.frequently_of_forall Filter.frequently_of_forall theorem Frequently.mp {p q : α → Prop} {f : Filter α} (h : ∃ᶠ x in f, p x) (hpq : ∀ᶠ x in f, p x → q x) : ∃ᶠ x in f, q x := mt (fun hq => hq.mp <| hpq.mono fun _ => mt) h #align filter.frequently.mp Filter.Frequently.mp theorem Frequently.filter_mono {p : α → Prop} {f g : Filter α} (h : ∃ᶠ x in f, p x) (hle : f ≤ g) : ∃ᶠ x in g, p x := mt (fun h' => h'.filter_mono hle) h #align filter.frequently.filter_mono Filter.Frequently.filter_mono theorem Frequently.mono {p q : α → Prop} {f : Filter α} (h : ∃ᶠ x in f, p x) (hpq : ∀ x, p x → q x) : ∃ᶠ x in f, q x := h.mp (eventually_of_forall hpq) #align filter.frequently.mono Filter.Frequently.mono theorem Frequently.and_eventually {p q : α → Prop} {f : Filter α} (hp : ∃ᶠ x in f, p x) (hq : ∀ᶠ x in f, q x) : ∃ᶠ x in f, p x ∧ q x := by refine mt (fun h => hq.mp <| h.mono ?_) hp exact fun x hpq hq hp => hpq ⟨hp, hq⟩ #align filter.frequently.and_eventually Filter.Frequently.and_eventually theorem Eventually.and_frequently {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) (hq : ∃ᶠ x in f, q x) : ∃ᶠ x in f, p x ∧ q x := by simpa only [and_comm] using hq.and_eventually hp #align filter.eventually.and_frequently Filter.Eventually.and_frequently theorem Frequently.exists {p : α → Prop} {f : Filter α} (hp : ∃ᶠ x in f, p x) : ∃ x, p x := by by_contra H replace H : ∀ᶠ x in f, ¬p x := eventually_of_forall (not_exists.1 H) exact hp H #align filter.frequently.exists Filter.Frequently.exists theorem Eventually.exists {p : α → Prop} {f : Filter α} [NeBot f] (hp : ∀ᶠ x in f, p x) : ∃ x, p x := hp.frequently.exists #align filter.eventually.exists Filter.Eventually.exists lemma frequently_iff_neBot {p : α → Prop} : (∃ᶠ x in l, p x) ↔ NeBot (l ⊓ 𝓟 {x | p x}) := by rw [neBot_iff, Ne, inf_principal_eq_bot]; rfl lemma frequently_mem_iff_neBot {s : Set α} : (∃ᶠ x in l, x ∈ s) ↔ NeBot (l ⊓ 𝓟 s) := frequently_iff_neBot theorem frequently_iff_forall_eventually_exists_and {p : α → Prop} {f : Filter α} : (∃ᶠ x in f, p x) ↔ ∀ {q : α → Prop}, (∀ᶠ x in f, q x) → ∃ x, p x ∧ q x := ⟨fun hp q hq => (hp.and_eventually hq).exists, fun H hp => by simpa only [and_not_self_iff, exists_false] using H hp⟩ #align filter.frequently_iff_forall_eventually_exists_and Filter.frequently_iff_forall_eventually_exists_and theorem frequently_iff {f : Filter α} {P : α → Prop} : (∃ᶠ x in f, P x) ↔ ∀ {U}, U ∈ f → ∃ x ∈ U, P x := by simp only [frequently_iff_forall_eventually_exists_and, @and_comm (P _)] rfl #align filter.frequently_iff Filter.frequently_iff @[simp] theorem not_eventually {p : α → Prop} {f : Filter α} : (¬∀ᶠ x in f, p x) ↔ ∃ᶠ x in f, ¬p x := by simp [Filter.Frequently] #align filter.not_eventually Filter.not_eventually @[simp] theorem not_frequently {p : α → Prop} {f : Filter α} : (¬∃ᶠ x in f, p x) ↔ ∀ᶠ x in f, ¬p x := by simp only [Filter.Frequently, not_not] #align filter.not_frequently Filter.not_frequently @[simp] theorem frequently_true_iff_neBot (f : Filter α) : (∃ᶠ _ in f, True) ↔ NeBot f := by simp [frequently_iff_neBot] #align filter.frequently_true_iff_ne_bot Filter.frequently_true_iff_neBot @[simp] theorem frequently_false (f : Filter α) : ¬∃ᶠ _ in f, False := by simp #align filter.frequently_false Filter.frequently_false @[simp] theorem frequently_const {f : Filter α} [NeBot f] {p : Prop} : (∃ᶠ _ in f, p) ↔ p := by by_cases p <;> simp [*] #align filter.frequently_const Filter.frequently_const @[simp] theorem frequently_or_distrib {f : Filter α} {p q : α → Prop} : (∃ᶠ x in f, p x ∨ q x) ↔ (∃ᶠ x in f, p x) ∨ ∃ᶠ x in f, q x := by simp only [Filter.Frequently, ← not_and_or, not_or, eventually_and] #align filter.frequently_or_distrib Filter.frequently_or_distrib theorem frequently_or_distrib_left {f : Filter α} [NeBot f] {p : Prop} {q : α → Prop} : (∃ᶠ x in f, p ∨ q x) ↔ p ∨ ∃ᶠ x in f, q x := by simp #align filter.frequently_or_distrib_left Filter.frequently_or_distrib_left theorem frequently_or_distrib_right {f : Filter α} [NeBot f] {p : α → Prop} {q : Prop} : (∃ᶠ x in f, p x ∨ q) ↔ (∃ᶠ x in f, p x) ∨ q := by simp #align filter.frequently_or_distrib_right Filter.frequently_or_distrib_right theorem frequently_imp_distrib {f : Filter α} {p q : α → Prop} : (∃ᶠ x in f, p x → q x) ↔ (∀ᶠ x in f, p x) → ∃ᶠ x in f, q x := by simp [imp_iff_not_or] #align filter.frequently_imp_distrib Filter.frequently_imp_distrib theorem frequently_imp_distrib_left {f : Filter α} [NeBot f] {p : Prop} {q : α → Prop} : (∃ᶠ x in f, p → q x) ↔ p → ∃ᶠ x in f, q x := by simp [frequently_imp_distrib] #align filter.frequently_imp_distrib_left Filter.frequently_imp_distrib_left theorem frequently_imp_distrib_right {f : Filter α} [NeBot f] {p : α → Prop} {q : Prop} : (∃ᶠ x in f, p x → q) ↔ (∀ᶠ x in f, p x) → q := by set_option tactic.skipAssignedInstances false in simp [frequently_imp_distrib] #align filter.frequently_imp_distrib_right Filter.frequently_imp_distrib_right theorem eventually_imp_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} : (∀ᶠ x in f, p x → q) ↔ (∃ᶠ x in f, p x) → q := by simp only [imp_iff_not_or, eventually_or_distrib_right, not_frequently] #align filter.eventually_imp_distrib_right Filter.eventually_imp_distrib_right @[simp] theorem frequently_and_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} : (∃ᶠ x in f, p ∧ q x) ↔ p ∧ ∃ᶠ x in f, q x := by simp only [Filter.Frequently, not_and, eventually_imp_distrib_left, Classical.not_imp] #align filter.frequently_and_distrib_left Filter.frequently_and_distrib_left @[simp] theorem frequently_and_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} : (∃ᶠ x in f, p x ∧ q) ↔ (∃ᶠ x in f, p x) ∧ q := by simp only [@and_comm _ q, frequently_and_distrib_left] #align filter.frequently_and_distrib_right Filter.frequently_and_distrib_right @[simp] theorem frequently_bot {p : α → Prop} : ¬∃ᶠ x in ⊥, p x := by simp #align filter.frequently_bot Filter.frequently_bot @[simp] theorem frequently_top {p : α → Prop} : (∃ᶠ x in ⊤, p x) ↔ ∃ x, p x := by simp [Filter.Frequently] #align filter.frequently_top Filter.frequently_top @[simp] theorem frequently_principal {a : Set α} {p : α → Prop} : (∃ᶠ x in 𝓟 a, p x) ↔ ∃ x ∈ a, p x := by simp [Filter.Frequently, not_forall] #align filter.frequently_principal Filter.frequently_principal theorem frequently_inf_principal {f : Filter α} {s : Set α} {p : α → Prop} : (∃ᶠ x in f ⊓ 𝓟 s, p x) ↔ ∃ᶠ x in f, x ∈ s ∧ p x := by simp only [Filter.Frequently, eventually_inf_principal, not_and] alias ⟨Frequently.of_inf_principal, Frequently.inf_principal⟩ := frequently_inf_principal theorem frequently_sup {p : α → Prop} {f g : Filter α} : (∃ᶠ x in f ⊔ g, p x) ↔ (∃ᶠ x in f, p x) ∨ ∃ᶠ x in g, p x := by simp only [Filter.Frequently, eventually_sup, not_and_or] #align filter.frequently_sup Filter.frequently_sup @[simp] theorem frequently_sSup {p : α → Prop} {fs : Set (Filter α)} : (∃ᶠ x in sSup fs, p x) ↔ ∃ f ∈ fs, ∃ᶠ x in f, p x := by simp only [Filter.Frequently, not_forall, eventually_sSup, exists_prop] #align filter.frequently_Sup Filter.frequently_sSup @[simp] theorem frequently_iSup {p : α → Prop} {fs : β → Filter α} : (∃ᶠ x in ⨆ b, fs b, p x) ↔ ∃ b, ∃ᶠ x in fs b, p x := by simp only [Filter.Frequently, eventually_iSup, not_forall] #align filter.frequently_supr Filter.frequently_iSup theorem Eventually.choice {r : α → β → Prop} {l : Filter α} [l.NeBot] (h : ∀ᶠ x in l, ∃ y, r x y) : ∃ f : α → β, ∀ᶠ x in l, r x (f x) := by haveI : Nonempty β := let ⟨_, hx⟩ := h.exists; hx.nonempty choose! f hf using fun x (hx : ∃ y, r x y) => hx exact ⟨f, h.mono hf⟩ #align filter.eventually.choice Filter.Eventually.choice /-! ### Relation “eventually equal” -/ /-- Two functions `f` and `g` are *eventually equal* along a filter `l` if the set of `x` such that `f x = g x` belongs to `l`. -/ def EventuallyEq (l : Filter α) (f g : α → β) : Prop := ∀ᶠ x in l, f x = g x #align filter.eventually_eq Filter.EventuallyEq @[inherit_doc] notation:50 f " =ᶠ[" l:50 "] " g:50 => EventuallyEq l f g theorem EventuallyEq.eventually {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) : ∀ᶠ x in l, f x = g x := h #align filter.eventually_eq.eventually Filter.EventuallyEq.eventually theorem EventuallyEq.rw {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) (p : α → β → Prop) (hf : ∀ᶠ x in l, p x (f x)) : ∀ᶠ x in l, p x (g x) := hf.congr <| h.mono fun _ hx => hx ▸ Iff.rfl #align filter.eventually_eq.rw Filter.EventuallyEq.rw theorem eventuallyEq_set {s t : Set α} {l : Filter α} : s =ᶠ[l] t ↔ ∀ᶠ x in l, x ∈ s ↔ x ∈ t := eventually_congr <| eventually_of_forall fun _ ↦ eq_iff_iff #align filter.eventually_eq_set Filter.eventuallyEq_set alias ⟨EventuallyEq.mem_iff, Eventually.set_eq⟩ := eventuallyEq_set #align filter.eventually_eq.mem_iff Filter.EventuallyEq.mem_iff #align filter.eventually.set_eq Filter.Eventually.set_eq @[simp] theorem eventuallyEq_univ {s : Set α} {l : Filter α} : s =ᶠ[l] univ ↔ s ∈ l := by simp [eventuallyEq_set] #align filter.eventually_eq_univ Filter.eventuallyEq_univ theorem EventuallyEq.exists_mem {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) : ∃ s ∈ l, EqOn f g s := Eventually.exists_mem h #align filter.eventually_eq.exists_mem Filter.EventuallyEq.exists_mem theorem eventuallyEq_of_mem {l : Filter α} {f g : α → β} {s : Set α} (hs : s ∈ l) (h : EqOn f g s) : f =ᶠ[l] g := eventually_of_mem hs h #align filter.eventually_eq_of_mem Filter.eventuallyEq_of_mem theorem eventuallyEq_iff_exists_mem {l : Filter α} {f g : α → β} : f =ᶠ[l] g ↔ ∃ s ∈ l, EqOn f g s := eventually_iff_exists_mem #align filter.eventually_eq_iff_exists_mem Filter.eventuallyEq_iff_exists_mem theorem EventuallyEq.filter_mono {l l' : Filter α} {f g : α → β} (h₁ : f =ᶠ[l] g) (h₂ : l' ≤ l) : f =ᶠ[l'] g := h₂ h₁ #align filter.eventually_eq.filter_mono Filter.EventuallyEq.filter_mono @[refl, simp] theorem EventuallyEq.refl (l : Filter α) (f : α → β) : f =ᶠ[l] f := eventually_of_forall fun _ => rfl #align filter.eventually_eq.refl Filter.EventuallyEq.refl protected theorem EventuallyEq.rfl {l : Filter α} {f : α → β} : f =ᶠ[l] f := EventuallyEq.refl l f #align filter.eventually_eq.rfl Filter.EventuallyEq.rfl @[symm] theorem EventuallyEq.symm {f g : α → β} {l : Filter α} (H : f =ᶠ[l] g) : g =ᶠ[l] f := H.mono fun _ => Eq.symm #align filter.eventually_eq.symm Filter.EventuallyEq.symm @[trans] theorem EventuallyEq.trans {l : Filter α} {f g h : α → β} (H₁ : f =ᶠ[l] g) (H₂ : g =ᶠ[l] h) : f =ᶠ[l] h := H₂.rw (fun x y => f x = y) H₁ #align filter.eventually_eq.trans Filter.EventuallyEq.trans instance : Trans ((· =ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· =ᶠ[l] ·) (· =ᶠ[l] ·) where trans := EventuallyEq.trans theorem EventuallyEq.prod_mk {l} {f f' : α → β} (hf : f =ᶠ[l] f') {g g' : α → γ} (hg : g =ᶠ[l] g') : (fun x => (f x, g x)) =ᶠ[l] fun x => (f' x, g' x) := hf.mp <| hg.mono <| by intros simp only [*] #align filter.eventually_eq.prod_mk Filter.EventuallyEq.prod_mk -- See `EventuallyEq.comp_tendsto` further below for a similar statement w.r.t. -- composition on the right. theorem EventuallyEq.fun_comp {f g : α → β} {l : Filter α} (H : f =ᶠ[l] g) (h : β → γ) : h ∘ f =ᶠ[l] h ∘ g := H.mono fun _ hx => congr_arg h hx #align filter.eventually_eq.fun_comp Filter.EventuallyEq.fun_comp theorem EventuallyEq.comp₂ {δ} {f f' : α → β} {g g' : α → γ} {l} (Hf : f =ᶠ[l] f') (h : β → γ → δ) (Hg : g =ᶠ[l] g') : (fun x => h (f x) (g x)) =ᶠ[l] fun x => h (f' x) (g' x) := (Hf.prod_mk Hg).fun_comp (uncurry h) #align filter.eventually_eq.comp₂ Filter.EventuallyEq.comp₂ @[to_additive] theorem EventuallyEq.mul [Mul β] {f f' g g' : α → β} {l : Filter α} (h : f =ᶠ[l] g) (h' : f' =ᶠ[l] g') : (fun x => f x * f' x) =ᶠ[l] fun x => g x * g' x := h.comp₂ (· * ·) h' #align filter.eventually_eq.mul Filter.EventuallyEq.mul #align filter.eventually_eq.add Filter.EventuallyEq.add @[to_additive const_smul] theorem EventuallyEq.pow_const {γ} [Pow β γ] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) (c : γ): (fun x => f x ^ c) =ᶠ[l] fun x => g x ^ c := h.fun_comp (· ^ c) #align filter.eventually_eq.const_smul Filter.EventuallyEq.const_smul @[to_additive] theorem EventuallyEq.inv [Inv β] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) : (fun x => (f x)⁻¹) =ᶠ[l] fun x => (g x)⁻¹ := h.fun_comp Inv.inv #align filter.eventually_eq.inv Filter.EventuallyEq.inv #align filter.eventually_eq.neg Filter.EventuallyEq.neg @[to_additive] theorem EventuallyEq.div [Div β] {f f' g g' : α → β} {l : Filter α} (h : f =ᶠ[l] g) (h' : f' =ᶠ[l] g') : (fun x => f x / f' x) =ᶠ[l] fun x => g x / g' x := h.comp₂ (· / ·) h' #align filter.eventually_eq.div Filter.EventuallyEq.div #align filter.eventually_eq.sub Filter.EventuallyEq.sub attribute [to_additive] EventuallyEq.const_smul #align filter.eventually_eq.const_vadd Filter.EventuallyEq.const_vadd @[to_additive] theorem EventuallyEq.smul {𝕜} [SMul 𝕜 β] {l : Filter α} {f f' : α → 𝕜} {g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : (fun x => f x • g x) =ᶠ[l] fun x => f' x • g' x := hf.comp₂ (· • ·) hg #align filter.eventually_eq.smul Filter.EventuallyEq.smul #align filter.eventually_eq.vadd Filter.EventuallyEq.vadd theorem EventuallyEq.sup [Sup β] {l : Filter α} {f f' g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : (fun x => f x ⊔ g x) =ᶠ[l] fun x => f' x ⊔ g' x := hf.comp₂ (· ⊔ ·) hg #align filter.eventually_eq.sup Filter.EventuallyEq.sup theorem EventuallyEq.inf [Inf β] {l : Filter α} {f f' g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : (fun x => f x ⊓ g x) =ᶠ[l] fun x => f' x ⊓ g' x := hf.comp₂ (· ⊓ ·) hg #align filter.eventually_eq.inf Filter.EventuallyEq.inf theorem EventuallyEq.preimage {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) (s : Set β) : f ⁻¹' s =ᶠ[l] g ⁻¹' s := h.fun_comp s #align filter.eventually_eq.preimage Filter.EventuallyEq.preimage theorem EventuallyEq.inter {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') : (s ∩ s' : Set α) =ᶠ[l] (t ∩ t' : Set α) := h.comp₂ (· ∧ ·) h' #align filter.eventually_eq.inter Filter.EventuallyEq.inter theorem EventuallyEq.union {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') : (s ∪ s' : Set α) =ᶠ[l] (t ∪ t' : Set α) := h.comp₂ (· ∨ ·) h' #align filter.eventually_eq.union Filter.EventuallyEq.union theorem EventuallyEq.compl {s t : Set α} {l : Filter α} (h : s =ᶠ[l] t) : (sᶜ : Set α) =ᶠ[l] (tᶜ : Set α) := h.fun_comp Not #align filter.eventually_eq.compl Filter.EventuallyEq.compl theorem EventuallyEq.diff {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') : (s \ s' : Set α) =ᶠ[l] (t \ t' : Set α) := h.inter h'.compl #align filter.eventually_eq.diff Filter.EventuallyEq.diff theorem eventuallyEq_empty {s : Set α} {l : Filter α} : s =ᶠ[l] (∅ : Set α) ↔ ∀ᶠ x in l, x ∉ s := eventuallyEq_set.trans <| by simp #align filter.eventually_eq_empty Filter.eventuallyEq_empty theorem inter_eventuallyEq_left {s t : Set α} {l : Filter α} : (s ∩ t : Set α) =ᶠ[l] s ↔ ∀ᶠ x in l, x ∈ s → x ∈ t := by simp only [eventuallyEq_set, mem_inter_iff, and_iff_left_iff_imp] #align filter.inter_eventually_eq_left Filter.inter_eventuallyEq_left theorem inter_eventuallyEq_right {s t : Set α} {l : Filter α} : (s ∩ t : Set α) =ᶠ[l] t ↔ ∀ᶠ x in l, x ∈ t → x ∈ s := by rw [inter_comm, inter_eventuallyEq_left] #align filter.inter_eventually_eq_right Filter.inter_eventuallyEq_right @[simp] theorem eventuallyEq_principal {s : Set α} {f g : α → β} : f =ᶠ[𝓟 s] g ↔ EqOn f g s := Iff.rfl #align filter.eventually_eq_principal Filter.eventuallyEq_principal theorem eventuallyEq_inf_principal_iff {F : Filter α} {s : Set α} {f g : α → β} : f =ᶠ[F ⊓ 𝓟 s] g ↔ ∀ᶠ x in F, x ∈ s → f x = g x := eventually_inf_principal #align filter.eventually_eq_inf_principal_iff Filter.eventuallyEq_inf_principal_iff theorem EventuallyEq.sub_eq [AddGroup β] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) : f - g =ᶠ[l] 0 := by simpa using ((EventuallyEq.refl l f).sub h).symm #align filter.eventually_eq.sub_eq Filter.EventuallyEq.sub_eq theorem eventuallyEq_iff_sub [AddGroup β] {f g : α → β} {l : Filter α} : f =ᶠ[l] g ↔ f - g =ᶠ[l] 0 := ⟨fun h => h.sub_eq, fun h => by simpa using h.add (EventuallyEq.refl l g)⟩ #align filter.eventually_eq_iff_sub Filter.eventuallyEq_iff_sub section LE variable [LE β] {l : Filter α} /-- A function `f` is eventually less than or equal to a function `g` at a filter `l`. -/ def EventuallyLE (l : Filter α) (f g : α → β) : Prop := ∀ᶠ x in l, f x ≤ g x #align filter.eventually_le Filter.EventuallyLE @[inherit_doc] notation:50 f " ≤ᶠ[" l:50 "] " g:50 => EventuallyLE l f g theorem EventuallyLE.congr {f f' g g' : α → β} (H : f ≤ᶠ[l] g) (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : f' ≤ᶠ[l] g' := H.mp <| hg.mp <| hf.mono fun x hf hg H => by rwa [hf, hg] at H #align filter.eventually_le.congr Filter.EventuallyLE.congr theorem eventuallyLE_congr {f f' g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : f ≤ᶠ[l] g ↔ f' ≤ᶠ[l] g' := ⟨fun H => H.congr hf hg, fun H => H.congr hf.symm hg.symm⟩ #align filter.eventually_le_congr Filter.eventuallyLE_congr end LE section Preorder variable [Preorder β] {l : Filter α} {f g h : α → β} theorem EventuallyEq.le (h : f =ᶠ[l] g) : f ≤ᶠ[l] g := h.mono fun _ => le_of_eq #align filter.eventually_eq.le Filter.EventuallyEq.le @[refl] theorem EventuallyLE.refl (l : Filter α) (f : α → β) : f ≤ᶠ[l] f := EventuallyEq.rfl.le #align filter.eventually_le.refl Filter.EventuallyLE.refl theorem EventuallyLE.rfl : f ≤ᶠ[l] f := EventuallyLE.refl l f #align filter.eventually_le.rfl Filter.EventuallyLE.rfl @[trans] theorem EventuallyLE.trans (H₁ : f ≤ᶠ[l] g) (H₂ : g ≤ᶠ[l] h) : f ≤ᶠ[l] h := H₂.mp <| H₁.mono fun _ => le_trans #align filter.eventually_le.trans Filter.EventuallyLE.trans instance : Trans ((· ≤ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· ≤ᶠ[l] ·) (· ≤ᶠ[l] ·) where trans := EventuallyLE.trans @[trans] theorem EventuallyEq.trans_le (H₁ : f =ᶠ[l] g) (H₂ : g ≤ᶠ[l] h) : f ≤ᶠ[l] h := H₁.le.trans H₂ #align filter.eventually_eq.trans_le Filter.EventuallyEq.trans_le instance : Trans ((· =ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· ≤ᶠ[l] ·) (· ≤ᶠ[l] ·) where trans := EventuallyEq.trans_le @[trans] theorem EventuallyLE.trans_eq (H₁ : f ≤ᶠ[l] g) (H₂ : g =ᶠ[l] h) : f ≤ᶠ[l] h := H₁.trans H₂.le #align filter.eventually_le.trans_eq Filter.EventuallyLE.trans_eq instance : Trans ((· ≤ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· =ᶠ[l] ·) (· ≤ᶠ[l] ·) where trans := EventuallyLE.trans_eq end Preorder theorem EventuallyLE.antisymm [PartialOrder β] {l : Filter α} {f g : α → β} (h₁ : f ≤ᶠ[l] g) (h₂ : g ≤ᶠ[l] f) : f =ᶠ[l] g := h₂.mp <| h₁.mono fun _ => le_antisymm #align filter.eventually_le.antisymm Filter.EventuallyLE.antisymm theorem eventuallyLE_antisymm_iff [PartialOrder β] {l : Filter α} {f g : α → β} : f =ᶠ[l] g ↔ f ≤ᶠ[l] g ∧ g ≤ᶠ[l] f := by simp only [EventuallyEq, EventuallyLE, le_antisymm_iff, eventually_and] #align filter.eventually_le_antisymm_iff Filter.eventuallyLE_antisymm_iff theorem EventuallyLE.le_iff_eq [PartialOrder β] {l : Filter α} {f g : α → β} (h : f ≤ᶠ[l] g) : g ≤ᶠ[l] f ↔ g =ᶠ[l] f := ⟨fun h' => h'.antisymm h, EventuallyEq.le⟩ #align filter.eventually_le.le_iff_eq Filter.EventuallyLE.le_iff_eq theorem Eventually.ne_of_lt [Preorder β] {l : Filter α} {f g : α → β} (h : ∀ᶠ x in l, f x < g x) : ∀ᶠ x in l, f x ≠ g x := h.mono fun _ hx => hx.ne #align filter.eventually.ne_of_lt Filter.Eventually.ne_of_lt theorem Eventually.ne_top_of_lt [PartialOrder β] [OrderTop β] {l : Filter α} {f g : α → β} (h : ∀ᶠ x in l, f x < g x) : ∀ᶠ x in l, f x ≠ ⊤ := h.mono fun _ hx => hx.ne_top #align filter.eventually.ne_top_of_lt Filter.Eventually.ne_top_of_lt theorem Eventually.lt_top_of_ne [PartialOrder β] [OrderTop β] {l : Filter α} {f : α → β} (h : ∀ᶠ x in l, f x ≠ ⊤) : ∀ᶠ x in l, f x < ⊤ := h.mono fun _ hx => hx.lt_top #align filter.eventually.lt_top_of_ne Filter.Eventually.lt_top_of_ne theorem Eventually.lt_top_iff_ne_top [PartialOrder β] [OrderTop β] {l : Filter α} {f : α → β} : (∀ᶠ x in l, f x < ⊤) ↔ ∀ᶠ x in l, f x ≠ ⊤ := ⟨Eventually.ne_of_lt, Eventually.lt_top_of_ne⟩ #align filter.eventually.lt_top_iff_ne_top Filter.Eventually.lt_top_iff_ne_top @[mono] theorem EventuallyLE.inter {s t s' t' : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) (h' : s' ≤ᶠ[l] t') : (s ∩ s' : Set α) ≤ᶠ[l] (t ∩ t' : Set α) := h'.mp <| h.mono fun _ => And.imp #align filter.eventually_le.inter Filter.EventuallyLE.inter @[mono] theorem EventuallyLE.union {s t s' t' : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) (h' : s' ≤ᶠ[l] t') : (s ∪ s' : Set α) ≤ᶠ[l] (t ∪ t' : Set α) := h'.mp <| h.mono fun _ => Or.imp #align filter.eventually_le.union Filter.EventuallyLE.union protected lemma EventuallyLE.iUnion [Finite ι] {s t : ι → Set α} (h : ∀ i, s i ≤ᶠ[l] t i) : (⋃ i, s i) ≤ᶠ[l] ⋃ i, t i := (eventually_all.2 h).mono fun _x hx hx' ↦ let ⟨i, hi⟩ := mem_iUnion.1 hx'; mem_iUnion.2 ⟨i, hx i hi⟩ protected lemma EventuallyEq.iUnion [Finite ι] {s t : ι → Set α} (h : ∀ i, s i =ᶠ[l] t i) : (⋃ i, s i) =ᶠ[l] ⋃ i, t i := (EventuallyLE.iUnion fun i ↦ (h i).le).antisymm <| .iUnion fun i ↦ (h i).symm.le protected lemma EventuallyLE.iInter [Finite ι] {s t : ι → Set α} (h : ∀ i, s i ≤ᶠ[l] t i) : (⋂ i, s i) ≤ᶠ[l] ⋂ i, t i := (eventually_all.2 h).mono fun _x hx hx' ↦ mem_iInter.2 fun i ↦ hx i (mem_iInter.1 hx' i) protected lemma EventuallyEq.iInter [Finite ι] {s t : ι → Set α} (h : ∀ i, s i =ᶠ[l] t i) : (⋂ i, s i) =ᶠ[l] ⋂ i, t i := (EventuallyLE.iInter fun i ↦ (h i).le).antisymm <| .iInter fun i ↦ (h i).symm.le lemma _root_.Set.Finite.eventuallyLE_iUnion {ι : Type*} {s : Set ι} (hs : s.Finite) {f g : ι → Set α} (hle : ∀ i ∈ s, f i ≤ᶠ[l] g i) : (⋃ i ∈ s, f i) ≤ᶠ[l] (⋃ i ∈ s, g i) := by have := hs.to_subtype rw [biUnion_eq_iUnion, biUnion_eq_iUnion] exact .iUnion fun i ↦ hle i.1 i.2 alias EventuallyLE.biUnion := Set.Finite.eventuallyLE_iUnion lemma _root_.Set.Finite.eventuallyEq_iUnion {ι : Type*} {s : Set ι} (hs : s.Finite) {f g : ι → Set α} (heq : ∀ i ∈ s, f i =ᶠ[l] g i) : (⋃ i ∈ s, f i) =ᶠ[l] (⋃ i ∈ s, g i) := (EventuallyLE.biUnion hs fun i hi ↦ (heq i hi).le).antisymm <| .biUnion hs fun i hi ↦ (heq i hi).symm.le alias EventuallyEq.biUnion := Set.Finite.eventuallyEq_iUnion lemma _root_.Set.Finite.eventuallyLE_iInter {ι : Type*} {s : Set ι} (hs : s.Finite) {f g : ι → Set α} (hle : ∀ i ∈ s, f i ≤ᶠ[l] g i) : (⋂ i ∈ s, f i) ≤ᶠ[l] (⋂ i ∈ s, g i) := by have := hs.to_subtype rw [biInter_eq_iInter, biInter_eq_iInter] exact .iInter fun i ↦ hle i.1 i.2 alias EventuallyLE.biInter := Set.Finite.eventuallyLE_iInter lemma _root_.Set.Finite.eventuallyEq_iInter {ι : Type*} {s : Set ι} (hs : s.Finite) {f g : ι → Set α} (heq : ∀ i ∈ s, f i =ᶠ[l] g i) : (⋂ i ∈ s, f i) =ᶠ[l] (⋂ i ∈ s, g i) := (EventuallyLE.biInter hs fun i hi ↦ (heq i hi).le).antisymm <| .biInter hs fun i hi ↦ (heq i hi).symm.le alias EventuallyEq.biInter := Set.Finite.eventuallyEq_iInter lemma _root_.Finset.eventuallyLE_iUnion {ι : Type*} (s : Finset ι) {f g : ι → Set α} (hle : ∀ i ∈ s, f i ≤ᶠ[l] g i) : (⋃ i ∈ s, f i) ≤ᶠ[l] (⋃ i ∈ s, g i) := .biUnion s.finite_toSet hle lemma _root_.Finset.eventuallyEq_iUnion {ι : Type*} (s : Finset ι) {f g : ι → Set α} (heq : ∀ i ∈ s, f i =ᶠ[l] g i) : (⋃ i ∈ s, f i) =ᶠ[l] (⋃ i ∈ s, g i) := .biUnion s.finite_toSet heq lemma _root_.Finset.eventuallyLE_iInter {ι : Type*} (s : Finset ι) {f g : ι → Set α} (hle : ∀ i ∈ s, f i ≤ᶠ[l] g i) : (⋂ i ∈ s, f i) ≤ᶠ[l] (⋂ i ∈ s, g i) := .biInter s.finite_toSet hle lemma _root_.Finset.eventuallyEq_iInter {ι : Type*} (s : Finset ι) {f g : ι → Set α} (heq : ∀ i ∈ s, f i =ᶠ[l] g i) : (⋂ i ∈ s, f i) =ᶠ[l] (⋂ i ∈ s, g i) := .biInter s.finite_toSet heq @[mono] theorem EventuallyLE.compl {s t : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) : (tᶜ : Set α) ≤ᶠ[l] (sᶜ : Set α) := h.mono fun _ => mt #align filter.eventually_le.compl Filter.EventuallyLE.compl @[mono] theorem EventuallyLE.diff {s t s' t' : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) (h' : t' ≤ᶠ[l] s') : (s \ s' : Set α) ≤ᶠ[l] (t \ t' : Set α) := h.inter h'.compl #align filter.eventually_le.diff Filter.EventuallyLE.diff theorem set_eventuallyLE_iff_mem_inf_principal {s t : Set α} {l : Filter α} : s ≤ᶠ[l] t ↔ t ∈ l ⊓ 𝓟 s := eventually_inf_principal.symm #align filter.set_eventually_le_iff_mem_inf_principal Filter.set_eventuallyLE_iff_mem_inf_principal theorem set_eventuallyLE_iff_inf_principal_le {s t : Set α} {l : Filter α} : s ≤ᶠ[l] t ↔ l ⊓ 𝓟 s ≤ l ⊓ 𝓟 t := set_eventuallyLE_iff_mem_inf_principal.trans <| by simp only [le_inf_iff, inf_le_left, true_and_iff, le_principal_iff] #align filter.set_eventually_le_iff_inf_principal_le Filter.set_eventuallyLE_iff_inf_principal_le theorem set_eventuallyEq_iff_inf_principal {s t : Set α} {l : Filter α} : s =ᶠ[l] t ↔ l ⊓ 𝓟 s = l ⊓ 𝓟 t := by simp only [eventuallyLE_antisymm_iff, le_antisymm_iff, set_eventuallyLE_iff_inf_principal_le] #align filter.set_eventually_eq_iff_inf_principal Filter.set_eventuallyEq_iff_inf_principal theorem EventuallyLE.mul_le_mul [MulZeroClass β] [PartialOrder β] [PosMulMono β] [MulPosMono β] {l : Filter α} {f₁ f₂ g₁ g₂ : α → β} (hf : f₁ ≤ᶠ[l] f₂) (hg : g₁ ≤ᶠ[l] g₂) (hg₀ : 0 ≤ᶠ[l] g₁) (hf₀ : 0 ≤ᶠ[l] f₂) : f₁ * g₁ ≤ᶠ[l] f₂ * g₂ := by filter_upwards [hf, hg, hg₀, hf₀] with x using _root_.mul_le_mul #align filter.eventually_le.mul_le_mul Filter.EventuallyLE.mul_le_mul @[to_additive EventuallyLE.add_le_add] theorem EventuallyLE.mul_le_mul' [Mul β] [Preorder β] [CovariantClass β β (· * ·) (· ≤ ·)] [CovariantClass β β (swap (· * ·)) (· ≤ ·)] {l : Filter α} {f₁ f₂ g₁ g₂ : α → β} (hf : f₁ ≤ᶠ[l] f₂) (hg : g₁ ≤ᶠ[l] g₂) : f₁ * g₁ ≤ᶠ[l] f₂ * g₂ := by filter_upwards [hf, hg] with x hfx hgx using _root_.mul_le_mul' hfx hgx #align filter.eventually_le.mul_le_mul' Filter.EventuallyLE.mul_le_mul' #align filter.eventually_le.add_le_add Filter.EventuallyLE.add_le_add theorem EventuallyLE.mul_nonneg [OrderedSemiring β] {l : Filter α} {f g : α → β} (hf : 0 ≤ᶠ[l] f) (hg : 0 ≤ᶠ[l] g) : 0 ≤ᶠ[l] f * g := by filter_upwards [hf, hg] with x using _root_.mul_nonneg #align filter.eventually_le.mul_nonneg Filter.EventuallyLE.mul_nonneg theorem eventually_sub_nonneg [OrderedRing β] {l : Filter α} {f g : α → β} : 0 ≤ᶠ[l] g - f ↔ f ≤ᶠ[l] g := eventually_congr <| eventually_of_forall fun _ => sub_nonneg #align filter.eventually_sub_nonneg Filter.eventually_sub_nonneg theorem EventuallyLE.sup [SemilatticeSup β] {l : Filter α} {f₁ f₂ g₁ g₂ : α → β} (hf : f₁ ≤ᶠ[l] f₂) (hg : g₁ ≤ᶠ[l] g₂) : f₁ ⊔ g₁ ≤ᶠ[l] f₂ ⊔ g₂ := by filter_upwards [hf, hg] with x hfx hgx using sup_le_sup hfx hgx #align filter.eventually_le.sup Filter.EventuallyLE.sup theorem EventuallyLE.sup_le [SemilatticeSup β] {l : Filter α} {f g h : α → β} (hf : f ≤ᶠ[l] h) (hg : g ≤ᶠ[l] h) : f ⊔ g ≤ᶠ[l] h := by filter_upwards [hf, hg] with x hfx hgx using _root_.sup_le hfx hgx #align filter.eventually_le.sup_le Filter.EventuallyLE.sup_le theorem EventuallyLE.le_sup_of_le_left [SemilatticeSup β] {l : Filter α} {f g h : α → β} (hf : h ≤ᶠ[l] f) : h ≤ᶠ[l] f ⊔ g := hf.mono fun _ => _root_.le_sup_of_le_left #align filter.eventually_le.le_sup_of_le_left Filter.EventuallyLE.le_sup_of_le_left theorem EventuallyLE.le_sup_of_le_right [SemilatticeSup β] {l : Filter α} {f g h : α → β} (hg : h ≤ᶠ[l] g) : h ≤ᶠ[l] f ⊔ g := hg.mono fun _ => _root_.le_sup_of_le_right #align filter.eventually_le.le_sup_of_le_right Filter.EventuallyLE.le_sup_of_le_right theorem join_le {f : Filter (Filter α)} {l : Filter α} (h : ∀ᶠ m in f, m ≤ l) : join f ≤ l := fun _ hs => h.mono fun _ hm => hm hs #align filter.join_le Filter.join_le /-! ### Push-forwards, pull-backs, and the monad structure -/ section Map /-- The forward map of a filter -/ def map (m : α → β) (f : Filter α) : Filter β where sets := preimage m ⁻¹' f.sets univ_sets := univ_mem sets_of_superset hs st := mem_of_superset hs <| preimage_mono st inter_sets hs ht := inter_mem hs ht #align filter.map Filter.map @[simp] theorem map_principal {s : Set α} {f : α → β} : map f (𝓟 s) = 𝓟 (Set.image f s) := Filter.ext fun _ => image_subset_iff.symm #align filter.map_principal Filter.map_principal variable {f : Filter α} {m : α → β} {m' : β → γ} {s : Set α} {t : Set β} @[simp] theorem eventually_map {P : β → Prop} : (∀ᶠ b in map m f, P b) ↔ ∀ᶠ a in f, P (m a) := Iff.rfl #align filter.eventually_map Filter.eventually_map @[simp] theorem frequently_map {P : β → Prop} : (∃ᶠ b in map m f, P b) ↔ ∃ᶠ a in f, P (m a) := Iff.rfl #align filter.frequently_map Filter.frequently_map @[simp] theorem mem_map : t ∈ map m f ↔ m ⁻¹' t ∈ f := Iff.rfl #align filter.mem_map Filter.mem_map theorem mem_map' : t ∈ map m f ↔ { x | m x ∈ t } ∈ f := Iff.rfl #align filter.mem_map' Filter.mem_map' theorem image_mem_map (hs : s ∈ f) : m '' s ∈ map m f := f.sets_of_superset hs <| subset_preimage_image m s #align filter.image_mem_map Filter.image_mem_map -- The simpNF linter says that the LHS can be simplified via `Filter.mem_map`. -- However this is a higher priority lemma. -- https://github.com/leanprover/std4/issues/207 @[simp 1100, nolint simpNF] theorem image_mem_map_iff (hf : Injective m) : m '' s ∈ map m f ↔ s ∈ f := ⟨fun h => by rwa [← preimage_image_eq s hf], image_mem_map⟩ #align filter.image_mem_map_iff Filter.image_mem_map_iff theorem range_mem_map : range m ∈ map m f := by rw [← image_univ] exact image_mem_map univ_mem #align filter.range_mem_map Filter.range_mem_map theorem mem_map_iff_exists_image : t ∈ map m f ↔ ∃ s ∈ f, m '' s ⊆ t := ⟨fun ht => ⟨m ⁻¹' t, ht, image_preimage_subset _ _⟩, fun ⟨_, hs, ht⟩ => mem_of_superset (image_mem_map hs) ht⟩ #align filter.mem_map_iff_exists_image Filter.mem_map_iff_exists_image @[simp] theorem map_id : Filter.map id f = f := filter_eq <| rfl #align filter.map_id Filter.map_id @[simp] theorem map_id' : Filter.map (fun x => x) f = f := map_id #align filter.map_id' Filter.map_id' @[simp] theorem map_compose : Filter.map m' ∘ Filter.map m = Filter.map (m' ∘ m) := funext fun _ => filter_eq <| rfl #align filter.map_compose Filter.map_compose @[simp] theorem map_map : Filter.map m' (Filter.map m f) = Filter.map (m' ∘ m) f := congr_fun Filter.map_compose f #align filter.map_map Filter.map_map /-- If functions `m₁` and `m₂` are eventually equal at a filter `f`, then they map this filter to the same filter. -/ theorem map_congr {m₁ m₂ : α → β} {f : Filter α} (h : m₁ =ᶠ[f] m₂) : map m₁ f = map m₂ f := Filter.ext' fun _ => eventually_congr (h.mono fun _ hx => hx ▸ Iff.rfl) #align filter.map_congr Filter.map_congr end Map section Comap /-- The inverse map of a filter. A set `s` belongs to `Filter.comap m f` if either of the following equivalent conditions hold. 1. There exists a set `t ∈ f` such that `m ⁻¹' t ⊆ s`. This is used as a definition. 2. The set `kernImage m s = {y | ∀ x, m x = y → x ∈ s}` belongs to `f`, see `Filter.mem_comap'`. 3. The set `(m '' sᶜ)ᶜ` belongs to `f`, see `Filter.mem_comap_iff_compl` and `Filter.compl_mem_comap`. -/ def comap (m : α → β) (f : Filter β) : Filter α where sets := { s | ∃ t ∈ f, m ⁻¹' t ⊆ s } univ_sets := ⟨univ, univ_mem, by simp only [subset_univ, preimage_univ]⟩ sets_of_superset := fun ⟨a', ha', ma'a⟩ ab => ⟨a', ha', ma'a.trans ab⟩ inter_sets := fun ⟨a', ha₁, ha₂⟩ ⟨b', hb₁, hb₂⟩ => ⟨a' ∩ b', inter_mem ha₁ hb₁, inter_subset_inter ha₂ hb₂⟩ #align filter.comap Filter.comap variable {f : α → β} {l : Filter β} {p : α → Prop} {s : Set α} theorem mem_comap' : s ∈ comap f l ↔ { y | ∀ ⦃x⦄, f x = y → x ∈ s } ∈ l := ⟨fun ⟨t, ht, hts⟩ => mem_of_superset ht fun y hy x hx => hts <| mem_preimage.2 <| by rwa [hx], fun h => ⟨_, h, fun x hx => hx rfl⟩⟩ #align filter.mem_comap' Filter.mem_comap' -- TODO: it would be nice to use `kernImage` much more to take advantage of common name and API, -- and then this would become `mem_comap'` theorem mem_comap'' : s ∈ comap f l ↔ kernImage f s ∈ l := mem_comap' /-- RHS form is used, e.g., in the definition of `UniformSpace`. -/ lemma mem_comap_prod_mk {x : α} {s : Set β} {F : Filter (α × β)} : s ∈ comap (Prod.mk x) F ↔ {p : α × β | p.fst = x → p.snd ∈ s} ∈ F := by simp_rw [mem_comap', Prod.ext_iff, and_imp, @forall_swap β (_ = _), forall_eq, eq_comm] #align filter.mem_comap_prod_mk Filter.mem_comap_prod_mk @[simp] theorem eventually_comap : (∀ᶠ a in comap f l, p a) ↔ ∀ᶠ b in l, ∀ a, f a = b → p a := mem_comap' #align filter.eventually_comap Filter.eventually_comap @[simp] theorem frequently_comap : (∃ᶠ a in comap f l, p a) ↔ ∃ᶠ b in l, ∃ a, f a = b ∧ p a := by simp only [Filter.Frequently, eventually_comap, not_exists, _root_.not_and] #align filter.frequently_comap Filter.frequently_comap theorem mem_comap_iff_compl : s ∈ comap f l ↔ (f '' sᶜ)ᶜ ∈ l := by simp only [mem_comap'', kernImage_eq_compl] #align filter.mem_comap_iff_compl Filter.mem_comap_iff_compl theorem compl_mem_comap : sᶜ ∈ comap f l ↔ (f '' s)ᶜ ∈ l := by rw [mem_comap_iff_compl, compl_compl] #align filter.compl_mem_comap Filter.compl_mem_comap end Comap section KernMap /-- The analog of `kernImage` for filters. A set `s` belongs to `Filter.kernMap m f` if either of the following equivalent conditions hold. 1. There exists a set `t ∈ f` such that `s = kernImage m t`. This is used as a definition. 2. There exists a set `t` such that `tᶜ ∈ f` and `sᶜ = m '' t`, see `Filter.mem_kernMap_iff_compl` and `Filter.compl_mem_kernMap`. This definition because it gives a right adjoint to `Filter.comap`, and because it has a nice interpretation when working with `co-` filters (`Filter.cocompact`, `Filter.cofinite`, ...). For example, `kernMap m (cocompact α)` is the filter generated by the complements of the sets `m '' K` where `K` is a compact subset of `α`. -/ def kernMap (m : α → β) (f : Filter α) : Filter β where sets := (kernImage m) '' f.sets univ_sets := ⟨univ, f.univ_sets, by simp [kernImage_eq_compl]⟩ sets_of_superset := by rintro _ t ⟨s, hs, rfl⟩ hst refine ⟨s ∪ m ⁻¹' t, mem_of_superset hs subset_union_left, ?_⟩ rw [kernImage_union_preimage, union_eq_right.mpr hst] inter_sets := by rintro _ _ ⟨s₁, h₁, rfl⟩ ⟨s₂, h₂, rfl⟩ exact ⟨s₁ ∩ s₂, f.inter_sets h₁ h₂, Set.preimage_kernImage.u_inf⟩ variable {m : α → β} {f : Filter α} theorem mem_kernMap {s : Set β} : s ∈ kernMap m f ↔ ∃ t ∈ f, kernImage m t = s := Iff.rfl theorem mem_kernMap_iff_compl {s : Set β} : s ∈ kernMap m f ↔ ∃ t, tᶜ ∈ f ∧ m '' t = sᶜ := by rw [mem_kernMap, compl_surjective.exists] refine exists_congr (fun x ↦ and_congr_right fun _ ↦ ?_) rw [kernImage_compl, compl_eq_comm, eq_comm] theorem compl_mem_kernMap {s : Set β} : sᶜ ∈ kernMap m f ↔ ∃ t, tᶜ ∈ f ∧ m '' t = s := by simp_rw [mem_kernMap_iff_compl, compl_compl] end KernMap /-- The monadic bind operation on filter is defined the usual way in terms of `map` and `join`. Unfortunately, this `bind` does not result in the expected applicative. See `Filter.seq` for the applicative instance. -/ def bind (f : Filter α) (m : α → Filter β) : Filter β := join (map m f) #align filter.bind Filter.bind /-- The applicative sequentiation operation. This is not induced by the bind operation. -/ def seq (f : Filter (α → β)) (g : Filter α) : Filter β where sets := { s | ∃ u ∈ f, ∃ t ∈ g, ∀ m ∈ u, ∀ x ∈ t, (m : α → β) x ∈ s } univ_sets := ⟨univ, univ_mem, univ, univ_mem, fun _ _ _ _ => trivial⟩ sets_of_superset := fun ⟨t₀, t₁, h₀, h₁, h⟩ hst => ⟨t₀, t₁, h₀, h₁, fun _ hx _ hy => hst <| h _ hx _ hy⟩ inter_sets := fun ⟨t₀, ht₀, t₁, ht₁, ht⟩ ⟨u₀, hu₀, u₁, hu₁, hu⟩ => ⟨t₀ ∩ u₀, inter_mem ht₀ hu₀, t₁ ∩ u₁, inter_mem ht₁ hu₁, fun _ ⟨hx₀, hx₁⟩ _ ⟨hy₀, hy₁⟩ => ⟨ht _ hx₀ _ hy₀, hu _ hx₁ _ hy₁⟩⟩ #align filter.seq Filter.seq /-- `pure x` is the set of sets that contain `x`. It is equal to `𝓟 {x}` but with this definition we have `s ∈ pure a` defeq `a ∈ s`. -/ instance : Pure Filter := ⟨fun x => { sets := { s | x ∈ s } inter_sets := And.intro sets_of_superset := fun hs hst => hst hs univ_sets := trivial }⟩ instance : Bind Filter := ⟨@Filter.bind⟩ instance : Functor Filter where map := @Filter.map instance : LawfulFunctor (Filter : Type u → Type u) where id_map _ := map_id comp_map _ _ _ := map_map.symm map_const := rfl theorem pure_sets (a : α) : (pure a : Filter α).sets = { s | a ∈ s } := rfl #align filter.pure_sets Filter.pure_sets @[simp] theorem mem_pure {a : α} {s : Set α} : s ∈ (pure a : Filter α) ↔ a ∈ s := Iff.rfl #align filter.mem_pure Filter.mem_pure @[simp] theorem eventually_pure {a : α} {p : α → Prop} : (∀ᶠ x in pure a, p x) ↔ p a := Iff.rfl #align filter.eventually_pure Filter.eventually_pure @[simp] theorem principal_singleton (a : α) : 𝓟 {a} = pure a := Filter.ext fun s => by simp only [mem_pure, mem_principal, singleton_subset_iff] #align filter.principal_singleton Filter.principal_singleton @[simp] theorem map_pure (f : α → β) (a : α) : map f (pure a) = pure (f a) := rfl #align filter.map_pure Filter.map_pure theorem pure_le_principal (a : α) : pure a ≤ 𝓟 s ↔ a ∈ s := by simp @[simp] theorem join_pure (f : Filter α) : join (pure f) = f := rfl #align filter.join_pure Filter.join_pure @[simp] theorem pure_bind (a : α) (m : α → Filter β) : bind (pure a) m = m a := by simp only [Bind.bind, bind, map_pure, join_pure] #align filter.pure_bind Filter.pure_bind theorem map_bind {α β} (m : β → γ) (f : Filter α) (g : α → Filter β) : map m (bind f g) = bind f (map m ∘ g) := rfl theorem bind_map {α β} (m : α → β) (f : Filter α) (g : β → Filter γ) : (bind (map m f) g) = bind f (g ∘ m) := rfl /-! ### `Filter` as a `Monad` In this section we define `Filter.monad`, a `Monad` structure on `Filter`s. This definition is not an instance because its `Seq` projection is not equal to the `Filter.seq` function we use in the `Applicative` instance on `Filter`. -/ section /-- The monad structure on filters. -/ protected def monad : Monad Filter where map := @Filter.map #align filter.monad Filter.monad attribute [local instance] Filter.monad protected theorem lawfulMonad : LawfulMonad Filter where map_const := rfl id_map _ := rfl seqLeft_eq _ _ := rfl seqRight_eq _ _ := rfl pure_seq _ _ := rfl bind_pure_comp _ _ := rfl bind_map _ _ := rfl pure_bind _ _ := rfl bind_assoc _ _ _ := rfl #align filter.is_lawful_monad Filter.lawfulMonad end instance : Alternative Filter where seq := fun x y => x.seq (y ()) failure := ⊥ orElse x y := x ⊔ y () @[simp] theorem map_def {α β} (m : α → β) (f : Filter α) : m <$> f = map m f := rfl #align filter.map_def Filter.map_def @[simp] theorem bind_def {α β} (f : Filter α) (m : α → Filter β) : f >>= m = bind f m := rfl #align filter.bind_def Filter.bind_def /-! #### `map` and `comap` equations -/ section Map variable {f f₁ f₂ : Filter α} {g g₁ g₂ : Filter β} {m : α → β} {m' : β → γ} {s : Set α} {t : Set β} @[simp] theorem mem_comap : s ∈ comap m g ↔ ∃ t ∈ g, m ⁻¹' t ⊆ s := Iff.rfl #align filter.mem_comap Filter.mem_comap theorem preimage_mem_comap (ht : t ∈ g) : m ⁻¹' t ∈ comap m g := ⟨t, ht, Subset.rfl⟩ #align filter.preimage_mem_comap Filter.preimage_mem_comap theorem Eventually.comap {p : β → Prop} (hf : ∀ᶠ b in g, p b) (f : α → β) : ∀ᶠ a in comap f g, p (f a) := preimage_mem_comap hf #align filter.eventually.comap Filter.Eventually.comap theorem comap_id : comap id f = f := le_antisymm (fun _ => preimage_mem_comap) fun _ ⟨_, ht, hst⟩ => mem_of_superset ht hst #align filter.comap_id Filter.comap_id theorem comap_id' : comap (fun x => x) f = f := comap_id #align filter.comap_id' Filter.comap_id' theorem comap_const_of_not_mem {x : β} (ht : t ∈ g) (hx : x ∉ t) : comap (fun _ : α => x) g = ⊥ := empty_mem_iff_bot.1 <| mem_comap'.2 <| mem_of_superset ht fun _ hx' _ h => hx <| h.symm ▸ hx' #align filter.comap_const_of_not_mem Filter.comap_const_of_not_mem theorem comap_const_of_mem {x : β} (h : ∀ t ∈ g, x ∈ t) : comap (fun _ : α => x) g = ⊤ := top_unique fun _ hs => univ_mem' fun _ => h _ (mem_comap'.1 hs) rfl #align filter.comap_const_of_mem Filter.comap_const_of_mem theorem map_const [NeBot f] {c : β} : (f.map fun _ => c) = pure c := by ext s by_cases h : c ∈ s <;> simp [h] #align filter.map_const Filter.map_const theorem comap_comap {m : γ → β} {n : β → α} : comap m (comap n f) = comap (n ∘ m) f := Filter.coext fun s => by simp only [compl_mem_comap, image_image, (· ∘ ·)] #align filter.comap_comap Filter.comap_comap section comm /-! The variables in the following lemmas are used as in this diagram: ``` φ α → β θ ↓ ↓ ψ γ → δ ρ ``` -/ variable {φ : α → β} {θ : α → γ} {ψ : β → δ} {ρ : γ → δ} (H : ψ ∘ φ = ρ ∘ θ) theorem map_comm (F : Filter α) : map ψ (map φ F) = map ρ (map θ F) := by rw [Filter.map_map, H, ← Filter.map_map] #align filter.map_comm Filter.map_comm theorem comap_comm (G : Filter δ) : comap φ (comap ψ G) = comap θ (comap ρ G) := by rw [Filter.comap_comap, H, ← Filter.comap_comap] #align filter.comap_comm Filter.comap_comm end comm theorem _root_.Function.Semiconj.filter_map {f : α → β} {ga : α → α} {gb : β → β} (h : Function.Semiconj f ga gb) : Function.Semiconj (map f) (map ga) (map gb) := map_comm h.comp_eq #align function.semiconj.filter_map Function.Semiconj.filter_map theorem _root_.Function.Commute.filter_map {f g : α → α} (h : Function.Commute f g) : Function.Commute (map f) (map g) := h.semiconj.filter_map #align function.commute.filter_map Function.Commute.filter_map theorem _root_.Function.Semiconj.filter_comap {f : α → β} {ga : α → α} {gb : β → β} (h : Function.Semiconj f ga gb) : Function.Semiconj (comap f) (comap gb) (comap ga) := comap_comm h.comp_eq.symm #align function.semiconj.filter_comap Function.Semiconj.filter_comap theorem _root_.Function.Commute.filter_comap {f g : α → α} (h : Function.Commute f g) : Function.Commute (comap f) (comap g) := h.semiconj.filter_comap #align function.commute.filter_comap Function.Commute.filter_comap section open Filter theorem _root_.Function.LeftInverse.filter_map {f : α → β} {g : β → α} (hfg : LeftInverse g f) : LeftInverse (map g) (map f) := fun F ↦ by rw [map_map, hfg.comp_eq_id, map_id] theorem _root_.Function.LeftInverse.filter_comap {f : α → β} {g : β → α} (hfg : LeftInverse g f) : RightInverse (comap g) (comap f) := fun F ↦ by rw [comap_comap, hfg.comp_eq_id, comap_id] nonrec theorem _root_.Function.RightInverse.filter_map {f : α → β} {g : β → α} (hfg : RightInverse g f) : RightInverse (map g) (map f) := hfg.filter_map nonrec theorem _root_.Function.RightInverse.filter_comap {f : α → β} {g : β → α} (hfg : RightInverse g f) : LeftInverse (comap g) (comap f) := hfg.filter_comap theorem _root_.Set.LeftInvOn.filter_map_Iic {f : α → β} {g : β → α} (hfg : LeftInvOn g f s) : LeftInvOn (map g) (map f) (Iic <| 𝓟 s) := fun F (hF : F ≤ 𝓟 s) ↦ by have : (g ∘ f) =ᶠ[𝓟 s] id := by simpa only [eventuallyEq_principal] using hfg rw [map_map, map_congr (this.filter_mono hF), map_id] nonrec theorem _root_.Set.RightInvOn.filter_map_Iic {f : α → β} {g : β → α} (hfg : RightInvOn g f t) : RightInvOn (map g) (map f) (Iic <| 𝓟 t) := hfg.filter_map_Iic end @[simp] theorem comap_principal {t : Set β} : comap m (𝓟 t) = 𝓟 (m ⁻¹' t) := Filter.ext fun _ => ⟨fun ⟨_u, hu, b⟩ => (preimage_mono hu).trans b, fun h => ⟨t, Subset.rfl, h⟩⟩ #align filter.comap_principal Filter.comap_principal theorem principal_subtype {α : Type*} (s : Set α) (t : Set s) : 𝓟 t = comap (↑) (𝓟 (((↑) : s → α) '' t)) := by rw [comap_principal, preimage_image_eq _ Subtype.coe_injective] #align principal_subtype Filter.principal_subtype @[simp] theorem comap_pure {b : β} : comap m (pure b) = 𝓟 (m ⁻¹' {b}) := by rw [← principal_singleton, comap_principal] #align filter.comap_pure Filter.comap_pure theorem map_le_iff_le_comap : map m f ≤ g ↔ f ≤ comap m g := ⟨fun h _ ⟨_, ht, hts⟩ => mem_of_superset (h ht) hts, fun h _ ht => h ⟨_, ht, Subset.rfl⟩⟩ #align filter.map_le_iff_le_comap Filter.map_le_iff_le_comap theorem gc_map_comap (m : α → β) : GaloisConnection (map m) (comap m) := fun _ _ => map_le_iff_le_comap #align filter.gc_map_comap Filter.gc_map_comap theorem comap_le_iff_le_kernMap : comap m g ≤ f ↔ g ≤ kernMap m f := by simp [Filter.le_def, mem_comap'', mem_kernMap, -mem_comap] theorem gc_comap_kernMap (m : α → β) : GaloisConnection (comap m) (kernMap m) := fun _ _ ↦ comap_le_iff_le_kernMap theorem kernMap_principal {s : Set α} : kernMap m (𝓟 s) = 𝓟 (kernImage m s) := by refine eq_of_forall_le_iff (fun g ↦ ?_) rw [← comap_le_iff_le_kernMap, le_principal_iff, le_principal_iff, mem_comap''] @[mono] theorem map_mono : Monotone (map m) := (gc_map_comap m).monotone_l #align filter.map_mono Filter.map_mono @[mono] theorem comap_mono : Monotone (comap m) := (gc_map_comap m).monotone_u #align filter.comap_mono Filter.comap_mono /-- Temporary lemma that we can tag with `gcongr` -/ @[gcongr, deprecated] theorem map_le_map (h : F ≤ G) : map m F ≤ map m G := map_mono h /-- Temporary lemma that we can tag with `gcongr` -/ @[gcongr, deprecated] theorem comap_le_comap (h : F ≤ G) : comap m F ≤ comap m G := comap_mono h @[simp] theorem map_bot : map m ⊥ = ⊥ := (gc_map_comap m).l_bot #align filter.map_bot Filter.map_bot @[simp] theorem map_sup : map m (f₁ ⊔ f₂) = map m f₁ ⊔ map m f₂ := (gc_map_comap m).l_sup #align filter.map_sup Filter.map_sup @[simp] theorem map_iSup {f : ι → Filter α} : map m (⨆ i, f i) = ⨆ i, map m (f i) := (gc_map_comap m).l_iSup #align filter.map_supr Filter.map_iSup @[simp] theorem map_top (f : α → β) : map f ⊤ = 𝓟 (range f) := by rw [← principal_univ, map_principal, image_univ] #align filter.map_top Filter.map_top @[simp] theorem comap_top : comap m ⊤ = ⊤ := (gc_map_comap m).u_top #align filter.comap_top Filter.comap_top @[simp] theorem comap_inf : comap m (g₁ ⊓ g₂) = comap m g₁ ⊓ comap m g₂ := (gc_map_comap m).u_inf #align filter.comap_inf Filter.comap_inf @[simp] theorem comap_iInf {f : ι → Filter β} : comap m (⨅ i, f i) = ⨅ i, comap m (f i) := (gc_map_comap m).u_iInf #align filter.comap_infi Filter.comap_iInf theorem le_comap_top (f : α → β) (l : Filter α) : l ≤ comap f ⊤ := by rw [comap_top] exact le_top #align filter.le_comap_top Filter.le_comap_top theorem map_comap_le : map m (comap m g) ≤ g := (gc_map_comap m).l_u_le _ #align filter.map_comap_le Filter.map_comap_le theorem le_comap_map : f ≤ comap m (map m f) := (gc_map_comap m).le_u_l _ #align filter.le_comap_map Filter.le_comap_map @[simp] theorem comap_bot : comap m ⊥ = ⊥ := bot_unique fun s _ => ⟨∅, mem_bot, by simp only [empty_subset, preimage_empty]⟩ #align filter.comap_bot Filter.comap_bot theorem neBot_of_comap (h : (comap m g).NeBot) : g.NeBot := by rw [neBot_iff] at * contrapose! h rw [h] exact comap_bot #align filter.ne_bot_of_comap Filter.neBot_of_comap theorem comap_inf_principal_range : comap m (g ⊓ 𝓟 (range m)) = comap m g := by simp #align filter.comap_inf_principal_range Filter.comap_inf_principal_range theorem disjoint_comap (h : Disjoint g₁ g₂) : Disjoint (comap m g₁) (comap m g₂) := by simp only [disjoint_iff, ← comap_inf, h.eq_bot, comap_bot] #align filter.disjoint_comap Filter.disjoint_comap theorem comap_iSup {ι} {f : ι → Filter β} {m : α → β} : comap m (iSup f) = ⨆ i, comap m (f i) := (gc_comap_kernMap m).l_iSup #align filter.comap_supr Filter.comap_iSup theorem comap_sSup {s : Set (Filter β)} {m : α → β} : comap m (sSup s) = ⨆ f ∈ s, comap m f := by simp only [sSup_eq_iSup, comap_iSup, eq_self_iff_true] #align filter.comap_Sup Filter.comap_sSup theorem comap_sup : comap m (g₁ ⊔ g₂) = comap m g₁ ⊔ comap m g₂ := by rw [sup_eq_iSup, comap_iSup, iSup_bool_eq, Bool.cond_true, Bool.cond_false] #align filter.comap_sup Filter.comap_sup theorem map_comap (f : Filter β) (m : α → β) : (f.comap m).map m = f ⊓ 𝓟 (range m) := by refine le_antisymm (le_inf map_comap_le <| le_principal_iff.2 range_mem_map) ?_ rintro t' ⟨t, ht, sub⟩ refine mem_inf_principal.2 (mem_of_superset ht ?_) rintro _ hxt ⟨x, rfl⟩ exact sub hxt #align filter.map_comap Filter.map_comap theorem map_comap_setCoe_val (f : Filter β) (s : Set β) : (f.comap ((↑) : s → β)).map (↑) = f ⊓ 𝓟 s := by rw [map_comap, Subtype.range_val] theorem map_comap_of_mem {f : Filter β} {m : α → β} (hf : range m ∈ f) : (f.comap m).map m = f := by rw [map_comap, inf_eq_left.2 (le_principal_iff.2 hf)] #align filter.map_comap_of_mem Filter.map_comap_of_mem instance canLift (c) (p) [CanLift α β c p] : CanLift (Filter α) (Filter β) (map c) fun f => ∀ᶠ x : α in f, p x where prf f hf := ⟨comap c f, map_comap_of_mem <| hf.mono CanLift.prf⟩ #align filter.can_lift Filter.canLift theorem comap_le_comap_iff {f g : Filter β} {m : α → β} (hf : range m ∈ f) : comap m f ≤ comap m g ↔ f ≤ g := ⟨fun h => map_comap_of_mem hf ▸ (map_mono h).trans map_comap_le, fun h => comap_mono h⟩ #align filter.comap_le_comap_iff Filter.comap_le_comap_iff theorem map_comap_of_surjective {f : α → β} (hf : Surjective f) (l : Filter β) : map f (comap f l) = l := map_comap_of_mem <| by simp only [hf.range_eq, univ_mem] #align filter.map_comap_of_surjective Filter.map_comap_of_surjective theorem comap_injective {f : α → β} (hf : Surjective f) : Injective (comap f) := LeftInverse.injective <| map_comap_of_surjective hf theorem _root_.Function.Surjective.filter_map_top {f : α → β} (hf : Surjective f) : map f ⊤ = ⊤ := (congr_arg _ comap_top).symm.trans <| map_comap_of_surjective hf ⊤ #align function.surjective.filter_map_top Function.Surjective.filter_map_top theorem subtype_coe_map_comap (s : Set α) (f : Filter α) : map ((↑) : s → α) (comap ((↑) : s → α) f) = f ⊓ 𝓟 s := by rw [map_comap, Subtype.range_coe] #align filter.subtype_coe_map_comap Filter.subtype_coe_map_comap theorem image_mem_of_mem_comap {f : Filter α} {c : β → α} (h : range c ∈ f) {W : Set β} (W_in : W ∈ comap c f) : c '' W ∈ f := by rw [← map_comap_of_mem h] exact image_mem_map W_in #align filter.image_mem_of_mem_comap Filter.image_mem_of_mem_comap theorem image_coe_mem_of_mem_comap {f : Filter α} {U : Set α} (h : U ∈ f) {W : Set U} (W_in : W ∈ comap ((↑) : U → α) f) : (↑) '' W ∈ f := image_mem_of_mem_comap (by simp [h]) W_in #align filter.image_coe_mem_of_mem_comap Filter.image_coe_mem_of_mem_comap theorem comap_map {f : Filter α} {m : α → β} (h : Injective m) : comap m (map m f) = f := le_antisymm (fun s hs => mem_of_superset (preimage_mem_comap <| image_mem_map hs) <| by simp only [preimage_image_eq s h, Subset.rfl]) le_comap_map #align filter.comap_map Filter.comap_map theorem mem_comap_iff {f : Filter β} {m : α → β} (inj : Injective m) (large : Set.range m ∈ f) {S : Set α} : S ∈ comap m f ↔ m '' S ∈ f := by rw [← image_mem_map_iff inj, map_comap_of_mem large] #align filter.mem_comap_iff Filter.mem_comap_iff theorem map_le_map_iff_of_injOn {l₁ l₂ : Filter α} {f : α → β} {s : Set α} (h₁ : s ∈ l₁) (h₂ : s ∈ l₂) (hinj : InjOn f s) : map f l₁ ≤ map f l₂ ↔ l₁ ≤ l₂ := ⟨fun h _t ht => mp_mem h₁ <| mem_of_superset (h <| image_mem_map (inter_mem h₂ ht)) fun _y ⟨_x, ⟨hxs, hxt⟩, hxy⟩ hys => hinj hxs hys hxy ▸ hxt, fun h => map_mono h⟩ #align filter.map_le_map_iff_of_inj_on Filter.map_le_map_iff_of_injOn theorem map_le_map_iff {f g : Filter α} {m : α → β} (hm : Injective m) : map m f ≤ map m g ↔ f ≤ g := by rw [map_le_iff_le_comap, comap_map hm] #align filter.map_le_map_iff Filter.map_le_map_iff theorem map_eq_map_iff_of_injOn {f g : Filter α} {m : α → β} {s : Set α} (hsf : s ∈ f) (hsg : s ∈ g) (hm : InjOn m s) : map m f = map m g ↔ f = g := by simp only [le_antisymm_iff, map_le_map_iff_of_injOn hsf hsg hm, map_le_map_iff_of_injOn hsg hsf hm] #align filter.map_eq_map_iff_of_inj_on Filter.map_eq_map_iff_of_injOn theorem map_inj {f g : Filter α} {m : α → β} (hm : Injective m) : map m f = map m g ↔ f = g := map_eq_map_iff_of_injOn univ_mem univ_mem hm.injOn #align filter.map_inj Filter.map_inj theorem map_injective {m : α → β} (hm : Injective m) : Injective (map m) := fun _ _ => (map_inj hm).1 #align filter.map_injective Filter.map_injective theorem comap_neBot_iff {f : Filter β} {m : α → β} : NeBot (comap m f) ↔ ∀ t ∈ f, ∃ a, m a ∈ t := by simp only [← forall_mem_nonempty_iff_neBot, mem_comap, forall_exists_index, and_imp] exact ⟨fun h t t_in => h (m ⁻¹' t) t t_in Subset.rfl, fun h s t ht hst => (h t ht).imp hst⟩ #align filter.comap_ne_bot_iff Filter.comap_neBot_iff theorem comap_neBot {f : Filter β} {m : α → β} (hm : ∀ t ∈ f, ∃ a, m a ∈ t) : NeBot (comap m f) := comap_neBot_iff.mpr hm #align filter.comap_ne_bot Filter.comap_neBot theorem comap_neBot_iff_frequently {f : Filter β} {m : α → β} : NeBot (comap m f) ↔ ∃ᶠ y in f, y ∈ range m := by simp only [comap_neBot_iff, frequently_iff, mem_range, @and_comm (_ ∈ _), exists_exists_eq_and] #align filter.comap_ne_bot_iff_frequently Filter.comap_neBot_iff_frequently theorem comap_neBot_iff_compl_range {f : Filter β} {m : α → β} : NeBot (comap m f) ↔ (range m)ᶜ ∉ f := comap_neBot_iff_frequently #align filter.comap_ne_bot_iff_compl_range Filter.comap_neBot_iff_compl_range theorem comap_eq_bot_iff_compl_range {f : Filter β} {m : α → β} : comap m f = ⊥ ↔ (range m)ᶜ ∈ f := not_iff_not.mp <| neBot_iff.symm.trans comap_neBot_iff_compl_range #align filter.comap_eq_bot_iff_compl_range Filter.comap_eq_bot_iff_compl_range theorem comap_surjective_eq_bot {f : Filter β} {m : α → β} (hm : Surjective m) : comap m f = ⊥ ↔ f = ⊥ := by rw [comap_eq_bot_iff_compl_range, hm.range_eq, compl_univ, empty_mem_iff_bot] #align filter.comap_surjective_eq_bot Filter.comap_surjective_eq_bot theorem disjoint_comap_iff (h : Surjective m) : Disjoint (comap m g₁) (comap m g₂) ↔ Disjoint g₁ g₂ := by rw [disjoint_iff, disjoint_iff, ← comap_inf, comap_surjective_eq_bot h] #align filter.disjoint_comap_iff Filter.disjoint_comap_iff theorem NeBot.comap_of_range_mem {f : Filter β} {m : α → β} (_ : NeBot f) (hm : range m ∈ f) : NeBot (comap m f) := comap_neBot_iff_frequently.2 <| Eventually.frequently hm #align filter.ne_bot.comap_of_range_mem Filter.NeBot.comap_of_range_mem @[simp] theorem comap_fst_neBot_iff {f : Filter α} : (f.comap (Prod.fst : α × β → α)).NeBot ↔ f.NeBot ∧ Nonempty β := by cases isEmpty_or_nonempty β · rw [filter_eq_bot_of_isEmpty (f.comap _), ← not_iff_not]; simp [*] · simp [comap_neBot_iff_frequently, *] #align filter.comap_fst_ne_bot_iff Filter.comap_fst_neBot_iff @[instance] theorem comap_fst_neBot [Nonempty β] {f : Filter α} [NeBot f] : (f.comap (Prod.fst : α × β → α)).NeBot := comap_fst_neBot_iff.2 ⟨‹_›, ‹_›⟩ #align filter.comap_fst_ne_bot Filter.comap_fst_neBot @[simp] theorem comap_snd_neBot_iff {f : Filter β} : (f.comap (Prod.snd : α × β → β)).NeBot ↔ Nonempty α ∧ f.NeBot := by cases' isEmpty_or_nonempty α with hα hα · rw [filter_eq_bot_of_isEmpty (f.comap _), ← not_iff_not]; simp · simp [comap_neBot_iff_frequently, hα] #align filter.comap_snd_ne_bot_iff Filter.comap_snd_neBot_iff @[instance] theorem comap_snd_neBot [Nonempty α] {f : Filter β} [NeBot f] : (f.comap (Prod.snd : α × β → β)).NeBot := comap_snd_neBot_iff.2 ⟨‹_›, ‹_›⟩ #align filter.comap_snd_ne_bot Filter.comap_snd_neBot theorem comap_eval_neBot_iff' {ι : Type*} {α : ι → Type*} {i : ι} {f : Filter (α i)} : (comap (eval i) f).NeBot ↔ (∀ j, Nonempty (α j)) ∧ NeBot f := by cases' isEmpty_or_nonempty (∀ j, α j) with H H · rw [filter_eq_bot_of_isEmpty (f.comap _), ← not_iff_not] simp [← Classical.nonempty_pi] · have : ∀ j, Nonempty (α j) := Classical.nonempty_pi.1 H simp [comap_neBot_iff_frequently, *] #align filter.comap_eval_ne_bot_iff' Filter.comap_eval_neBot_iff' @[simp] theorem comap_eval_neBot_iff {ι : Type*} {α : ι → Type*} [∀ j, Nonempty (α j)] {i : ι} {f : Filter (α i)} : (comap (eval i) f).NeBot ↔ NeBot f := by simp [comap_eval_neBot_iff', *] #align filter.comap_eval_ne_bot_iff Filter.comap_eval_neBot_iff @[instance] theorem comap_eval_neBot {ι : Type*} {α : ι → Type*} [∀ j, Nonempty (α j)] (i : ι) (f : Filter (α i)) [NeBot f] : (comap (eval i) f).NeBot := comap_eval_neBot_iff.2 ‹_› #align filter.comap_eval_ne_bot Filter.comap_eval_neBot theorem comap_inf_principal_neBot_of_image_mem {f : Filter β} {m : α → β} (hf : NeBot f) {s : Set α} (hs : m '' s ∈ f) : NeBot (comap m f ⊓ 𝓟 s) := by refine ⟨compl_compl s ▸ mt mem_of_eq_bot ?_⟩ rintro ⟨t, ht, hts⟩ rcases hf.nonempty_of_mem (inter_mem hs ht) with ⟨_, ⟨x, hxs, rfl⟩, hxt⟩ exact absurd hxs (hts hxt) #align filter.comap_inf_principal_ne_bot_of_image_mem Filter.comap_inf_principal_neBot_of_image_mem theorem comap_coe_neBot_of_le_principal {s : Set γ} {l : Filter γ} [h : NeBot l] (h' : l ≤ 𝓟 s) : NeBot (comap ((↑) : s → γ) l) := h.comap_of_range_mem <| (@Subtype.range_coe γ s).symm ▸ h' (mem_principal_self s) #align filter.comap_coe_ne_bot_of_le_principal Filter.comap_coe_neBot_of_le_principal theorem NeBot.comap_of_surj {f : Filter β} {m : α → β} (hf : NeBot f) (hm : Surjective m) : NeBot (comap m f) := hf.comap_of_range_mem <| univ_mem' hm #align filter.ne_bot.comap_of_surj Filter.NeBot.comap_of_surj theorem NeBot.comap_of_image_mem {f : Filter β} {m : α → β} (hf : NeBot f) {s : Set α} (hs : m '' s ∈ f) : NeBot (comap m f) := hf.comap_of_range_mem <| mem_of_superset hs (image_subset_range _ _) #align filter.ne_bot.comap_of_image_mem Filter.NeBot.comap_of_image_mem @[simp] theorem map_eq_bot_iff : map m f = ⊥ ↔ f = ⊥ := ⟨by rw [← empty_mem_iff_bot, ← empty_mem_iff_bot] exact id, fun h => by simp only [h, map_bot]⟩ #align filter.map_eq_bot_iff Filter.map_eq_bot_iff theorem map_neBot_iff (f : α → β) {F : Filter α} : NeBot (map f F) ↔ NeBot F := by simp only [neBot_iff, Ne, map_eq_bot_iff] #align filter.map_ne_bot_iff Filter.map_neBot_iff theorem NeBot.map (hf : NeBot f) (m : α → β) : NeBot (map m f) := (map_neBot_iff m).2 hf #align filter.ne_bot.map Filter.NeBot.map theorem NeBot.of_map : NeBot (f.map m) → NeBot f := (map_neBot_iff m).1 #align filter.ne_bot.of_map Filter.NeBot.of_map instance map_neBot [hf : NeBot f] : NeBot (f.map m) := hf.map m #align filter.map_ne_bot Filter.map_neBot theorem sInter_comap_sets (f : α → β) (F : Filter β) : ⋂₀ (comap f F).sets = ⋂ U ∈ F, f ⁻¹' U := by ext x suffices (∀ (A : Set α) (B : Set β), B ∈ F → f ⁻¹' B ⊆ A → x ∈ A) ↔ ∀ B : Set β, B ∈ F → f x ∈ B by simp only [mem_sInter, mem_iInter, Filter.mem_sets, mem_comap, this, and_imp, exists_prop, mem_preimage, exists_imp] constructor · intro h U U_in simpa only [Subset.rfl, forall_prop_of_true, mem_preimage] using h (f ⁻¹' U) U U_in · intro h V U U_in f_U_V exact f_U_V (h U U_in) #align filter.sInter_comap_sets Filter.sInter_comap_sets end Map -- this is a generic rule for monotone functions: theorem map_iInf_le {f : ι → Filter α} {m : α → β} : map m (iInf f) ≤ ⨅ i, map m (f i) := le_iInf fun _ => map_mono <| iInf_le _ _ #align filter.map_infi_le Filter.map_iInf_le theorem map_iInf_eq {f : ι → Filter α} {m : α → β} (hf : Directed (· ≥ ·) f) [Nonempty ι] : map m (iInf f) = ⨅ i, map m (f i) := map_iInf_le.antisymm fun s (hs : m ⁻¹' s ∈ iInf f) => let ⟨i, hi⟩ := (mem_iInf_of_directed hf _).1 hs have : ⨅ i, map m (f i) ≤ 𝓟 s := iInf_le_of_le i <| by simpa only [le_principal_iff, mem_map] Filter.le_principal_iff.1 this #align filter.map_infi_eq Filter.map_iInf_eq theorem map_biInf_eq {ι : Type w} {f : ι → Filter α} {m : α → β} {p : ι → Prop} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) { x | p x }) (ne : ∃ i, p i) : map m (⨅ (i) (_ : p i), f i) = ⨅ (i) (_ : p i), map m (f i) := by haveI := nonempty_subtype.2 ne simp only [iInf_subtype'] exact map_iInf_eq h.directed_val #align filter.map_binfi_eq Filter.map_biInf_eq theorem map_inf_le {f g : Filter α} {m : α → β} : map m (f ⊓ g) ≤ map m f ⊓ map m g := (@map_mono _ _ m).map_inf_le f g #align filter.map_inf_le Filter.map_inf_le theorem map_inf {f g : Filter α} {m : α → β} (h : Injective m) : map m (f ⊓ g) = map m f ⊓ map m g := by refine map_inf_le.antisymm ?_ rintro t ⟨s₁, hs₁, s₂, hs₂, ht : m ⁻¹' t = s₁ ∩ s₂⟩ refine mem_inf_of_inter (image_mem_map hs₁) (image_mem_map hs₂) ?_ rw [← image_inter h, image_subset_iff, ht] #align filter.map_inf Filter.map_inf theorem map_inf' {f g : Filter α} {m : α → β} {t : Set α} (htf : t ∈ f) (htg : t ∈ g) (h : InjOn m t) : map m (f ⊓ g) = map m f ⊓ map m g := by lift f to Filter t using htf; lift g to Filter t using htg replace h : Injective (m ∘ ((↑) : t → α)) := h.injective simp only [map_map, ← map_inf Subtype.coe_injective, map_inf h] #align filter.map_inf' Filter.map_inf' lemma disjoint_of_map {α β : Type*} {F G : Filter α} {f : α → β} (h : Disjoint (map f F) (map f G)) : Disjoint F G := disjoint_iff.mpr <| map_eq_bot_iff.mp <| le_bot_iff.mp <| trans map_inf_le (disjoint_iff.mp h) theorem disjoint_map {m : α → β} (hm : Injective m) {f₁ f₂ : Filter α} : Disjoint (map m f₁) (map m f₂) ↔ Disjoint f₁ f₂ := by simp only [disjoint_iff, ← map_inf hm, map_eq_bot_iff] #align filter.disjoint_map Filter.disjoint_map theorem map_equiv_symm (e : α ≃ β) (f : Filter β) : map e.symm f = comap e f := map_injective e.injective <| by rw [map_map, e.self_comp_symm, map_id, map_comap_of_surjective e.surjective] #align filter.map_equiv_symm Filter.map_equiv_symm theorem map_eq_comap_of_inverse {f : Filter α} {m : α → β} {n : β → α} (h₁ : m ∘ n = id) (h₂ : n ∘ m = id) : map m f = comap n f := map_equiv_symm ⟨n, m, congr_fun h₁, congr_fun h₂⟩ f #align filter.map_eq_comap_of_inverse Filter.map_eq_comap_of_inverse theorem comap_equiv_symm (e : α ≃ β) (f : Filter α) : comap e.symm f = map e f := (map_eq_comap_of_inverse e.self_comp_symm e.symm_comp_self).symm #align filter.comap_equiv_symm Filter.comap_equiv_symm theorem map_swap_eq_comap_swap {f : Filter (α × β)} : Prod.swap <$> f = comap Prod.swap f := map_eq_comap_of_inverse Prod.swap_swap_eq Prod.swap_swap_eq #align filter.map_swap_eq_comap_swap Filter.map_swap_eq_comap_swap /-- A useful lemma when dealing with uniformities. -/ theorem map_swap4_eq_comap {f : Filter ((α × β) × γ × δ)} : map (fun p : (α × β) × γ × δ => ((p.1.1, p.2.1), (p.1.2, p.2.2))) f = comap (fun p : (α × γ) × β × δ => ((p.1.1, p.2.1), (p.1.2, p.2.2))) f := map_eq_comap_of_inverse (funext fun ⟨⟨_, _⟩, ⟨_, _⟩⟩ => rfl) (funext fun ⟨⟨_, _⟩, ⟨_, _⟩⟩ => rfl) #align filter.map_swap4_eq_comap Filter.map_swap4_eq_comap theorem le_map {f : Filter α} {m : α → β} {g : Filter β} (h : ∀ s ∈ f, m '' s ∈ g) : g ≤ f.map m := fun _ hs => mem_of_superset (h _ hs) <| image_preimage_subset _ _ #align filter.le_map Filter.le_map theorem le_map_iff {f : Filter α} {m : α → β} {g : Filter β} : g ≤ f.map m ↔ ∀ s ∈ f, m '' s ∈ g := ⟨fun h _ hs => h (image_mem_map hs), le_map⟩ #align filter.le_map_iff Filter.le_map_iff protected theorem push_pull (f : α → β) (F : Filter α) (G : Filter β) : map f (F ⊓ comap f G) = map f F ⊓ G := by apply le_antisymm · calc map f (F ⊓ comap f G) ≤ map f F ⊓ (map f <| comap f G) := map_inf_le _ ≤ map f F ⊓ G := inf_le_inf_left (map f F) map_comap_le · rintro U ⟨V, V_in, W, ⟨Z, Z_in, hZ⟩, h⟩ apply mem_inf_of_inter (image_mem_map V_in) Z_in calc f '' V ∩ Z = f '' (V ∩ f ⁻¹' Z) := by rw [image_inter_preimage] _ ⊆ f '' (V ∩ W) := image_subset _ (inter_subset_inter_right _ ‹_›) _ = f '' (f ⁻¹' U) := by rw [h] _ ⊆ U := image_preimage_subset f U #align filter.push_pull Filter.push_pull protected theorem push_pull' (f : α → β) (F : Filter α) (G : Filter β) : map f (comap f G ⊓ F) = G ⊓ map f F := by simp only [Filter.push_pull, inf_comm] #align filter.push_pull' Filter.push_pull' theorem principal_eq_map_coe_top (s : Set α) : 𝓟 s = map ((↑) : s → α) ⊤ := by simp #align filter.principal_eq_map_coe_top Filter.principal_eq_map_coe_top theorem inf_principal_eq_bot_iff_comap {F : Filter α} {s : Set α} : F ⊓ 𝓟 s = ⊥ ↔ comap ((↑) : s → α) F = ⊥ := by rw [principal_eq_map_coe_top s, ← Filter.push_pull', inf_top_eq, map_eq_bot_iff] #align filter.inf_principal_eq_bot_iff_comap Filter.inf_principal_eq_bot_iff_comap section Applicative theorem singleton_mem_pure {a : α} : {a} ∈ (pure a : Filter α) := mem_singleton a #align filter.singleton_mem_pure Filter.singleton_mem_pure theorem pure_injective : Injective (pure : α → Filter α) := fun a _ hab => (Filter.ext_iff.1 hab { x | a = x }).1 rfl #align filter.pure_injective Filter.pure_injective instance pure_neBot {α : Type u} {a : α} : NeBot (pure a) := ⟨mt empty_mem_iff_bot.2 <| not_mem_empty a⟩ #align filter.pure_ne_bot Filter.pure_neBot @[simp] theorem le_pure_iff {f : Filter α} {a : α} : f ≤ pure a ↔ {a} ∈ f := by rw [← principal_singleton, le_principal_iff] #align filter.le_pure_iff Filter.le_pure_iff theorem mem_seq_def {f : Filter (α → β)} {g : Filter α} {s : Set β} : s ∈ f.seq g ↔ ∃ u ∈ f, ∃ t ∈ g, ∀ x ∈ u, ∀ y ∈ t, (x : α → β) y ∈ s := Iff.rfl #align filter.mem_seq_def Filter.mem_seq_def theorem mem_seq_iff {f : Filter (α → β)} {g : Filter α} {s : Set β} : s ∈ f.seq g ↔ ∃ u ∈ f, ∃ t ∈ g, Set.seq u t ⊆ s := by simp only [mem_seq_def, seq_subset, exists_prop, iff_self_iff] #align filter.mem_seq_iff Filter.mem_seq_iff theorem mem_map_seq_iff {f : Filter α} {g : Filter β} {m : α → β → γ} {s : Set γ} : s ∈ (f.map m).seq g ↔ ∃ t u, t ∈ g ∧ u ∈ f ∧ ∀ x ∈ u, ∀ y ∈ t, m x y ∈ s := Iff.intro (fun ⟨t, ht, s, hs, hts⟩ => ⟨s, m ⁻¹' t, hs, ht, fun _ => hts _⟩) fun ⟨t, s, ht, hs, hts⟩ => ⟨m '' s, image_mem_map hs, t, ht, fun _ ⟨_, has, Eq⟩ => Eq ▸ hts _ has⟩ #align filter.mem_map_seq_iff Filter.mem_map_seq_iff theorem seq_mem_seq {f : Filter (α → β)} {g : Filter α} {s : Set (α → β)} {t : Set α} (hs : s ∈ f) (ht : t ∈ g) : s.seq t ∈ f.seq g := ⟨s, hs, t, ht, fun f hf a ha => ⟨f, hf, a, ha, rfl⟩⟩ #align filter.seq_mem_seq Filter.seq_mem_seq theorem le_seq {f : Filter (α → β)} {g : Filter α} {h : Filter β} (hh : ∀ t ∈ f, ∀ u ∈ g, Set.seq t u ∈ h) : h ≤ seq f g := fun _ ⟨_, ht, _, hu, hs⟩ => mem_of_superset (hh _ ht _ hu) fun _ ⟨_, hm, _, ha, eq⟩ => eq ▸ hs _ hm _ ha #align filter.le_seq Filter.le_seq @[mono] theorem seq_mono {f₁ f₂ : Filter (α → β)} {g₁ g₂ : Filter α} (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : f₁.seq g₁ ≤ f₂.seq g₂ := le_seq fun _ hs _ ht => seq_mem_seq (hf hs) (hg ht) #align filter.seq_mono Filter.seq_mono @[simp] theorem pure_seq_eq_map (g : α → β) (f : Filter α) : seq (pure g) f = f.map g := by refine le_antisymm (le_map fun s hs => ?_) (le_seq fun s hs t ht => ?_) · rw [← singleton_seq] apply seq_mem_seq _ hs exact singleton_mem_pure · refine sets_of_superset (map g f) (image_mem_map ht) ?_ rintro b ⟨a, ha, rfl⟩ exact ⟨g, hs, a, ha, rfl⟩ #align filter.pure_seq_eq_map Filter.pure_seq_eq_map @[simp] theorem seq_pure (f : Filter (α → β)) (a : α) : seq f (pure a) = map (fun g : α → β => g a) f := by refine le_antisymm (le_map fun s hs => ?_) (le_seq fun s hs t ht => ?_) · rw [← seq_singleton] exact seq_mem_seq hs singleton_mem_pure · refine sets_of_superset (map (fun g : α → β => g a) f) (image_mem_map hs) ?_ rintro b ⟨g, hg, rfl⟩ exact ⟨g, hg, a, ht, rfl⟩ #align filter.seq_pure Filter.seq_pure @[simp] theorem seq_assoc (x : Filter α) (g : Filter (α → β)) (h : Filter (β → γ)) : seq h (seq g x) = seq (seq (map (· ∘ ·) h) g) x := by refine le_antisymm (le_seq fun s hs t ht => ?_) (le_seq fun s hs t ht => ?_) · rcases mem_seq_iff.1 hs with ⟨u, hu, v, hv, hs⟩ rcases mem_map_iff_exists_image.1 hu with ⟨w, hw, hu⟩ refine mem_of_superset ?_ (Set.seq_mono ((Set.seq_mono hu Subset.rfl).trans hs) Subset.rfl) rw [← Set.seq_seq] exact seq_mem_seq hw (seq_mem_seq hv ht) · rcases mem_seq_iff.1 ht with ⟨u, hu, v, hv, ht⟩ refine mem_of_superset ?_ (Set.seq_mono Subset.rfl ht) rw [Set.seq_seq] exact seq_mem_seq (seq_mem_seq (image_mem_map hs) hu) hv #align filter.seq_assoc Filter.seq_assoc theorem prod_map_seq_comm (f : Filter α) (g : Filter β) : (map Prod.mk f).seq g = seq (map (fun b a => (a, b)) g) f := by refine le_antisymm (le_seq fun s hs t ht => ?_) (le_seq fun s hs t ht => ?_) · rcases mem_map_iff_exists_image.1 hs with ⟨u, hu, hs⟩ refine mem_of_superset ?_ (Set.seq_mono hs Subset.rfl) rw [← Set.prod_image_seq_comm] exact seq_mem_seq (image_mem_map ht) hu · rcases mem_map_iff_exists_image.1 hs with ⟨u, hu, hs⟩ refine mem_of_superset ?_ (Set.seq_mono hs Subset.rfl) rw [Set.prod_image_seq_comm] exact seq_mem_seq (image_mem_map ht) hu #align filter.prod_map_seq_comm Filter.prod_map_seq_comm theorem seq_eq_filter_seq {α β : Type u} (f : Filter (α → β)) (g : Filter α) : f <*> g = seq f g := rfl #align filter.seq_eq_filter_seq Filter.seq_eq_filter_seq instance : LawfulApplicative (Filter : Type u → Type u) where map_pure := map_pure seqLeft_eq _ _ := rfl seqRight_eq _ _ := rfl seq_pure := seq_pure pure_seq := pure_seq_eq_map seq_assoc := seq_assoc instance : CommApplicative (Filter : Type u → Type u) := ⟨fun f g => prod_map_seq_comm f g⟩ end Applicative /-! #### `bind` equations -/ section Bind @[simp] theorem eventually_bind {f : Filter α} {m : α → Filter β} {p : β → Prop} : (∀ᶠ y in bind f m, p y) ↔ ∀ᶠ x in f, ∀ᶠ y in m x, p y := Iff.rfl #align filter.eventually_bind Filter.eventually_bind @[simp] theorem eventuallyEq_bind {f : Filter α} {m : α → Filter β} {g₁ g₂ : β → γ} : g₁ =ᶠ[bind f m] g₂ ↔ ∀ᶠ x in f, g₁ =ᶠ[m x] g₂ := Iff.rfl #align filter.eventually_eq_bind Filter.eventuallyEq_bind @[simp] theorem eventuallyLE_bind [LE γ] {f : Filter α} {m : α → Filter β} {g₁ g₂ : β → γ} : g₁ ≤ᶠ[bind f m] g₂ ↔ ∀ᶠ x in f, g₁ ≤ᶠ[m x] g₂ := Iff.rfl #align filter.eventually_le_bind Filter.eventuallyLE_bind theorem mem_bind' {s : Set β} {f : Filter α} {m : α → Filter β} : s ∈ bind f m ↔ { a | s ∈ m a } ∈ f := Iff.rfl #align filter.mem_bind' Filter.mem_bind' @[simp] theorem mem_bind {s : Set β} {f : Filter α} {m : α → Filter β} : s ∈ bind f m ↔ ∃ t ∈ f, ∀ x ∈ t, s ∈ m x := calc s ∈ bind f m ↔ { a | s ∈ m a } ∈ f := Iff.rfl _ ↔ ∃ t ∈ f, t ⊆ { a | s ∈ m a } := exists_mem_subset_iff.symm _ ↔ ∃ t ∈ f, ∀ x ∈ t, s ∈ m x := Iff.rfl #align filter.mem_bind Filter.mem_bind theorem bind_le {f : Filter α} {g : α → Filter β} {l : Filter β} (h : ∀ᶠ x in f, g x ≤ l) : f.bind g ≤ l := join_le <| eventually_map.2 h #align filter.bind_le Filter.bind_le @[mono]
Mathlib/Order/Filter/Basic.lean
2,982
2,986
theorem bind_mono {f₁ f₂ : Filter α} {g₁ g₂ : α → Filter β} (hf : f₁ ≤ f₂) (hg : g₁ ≤ᶠ[f₁] g₂) : bind f₁ g₁ ≤ bind f₂ g₂ := by
refine le_trans (fun s hs => ?_) (join_mono <| map_mono hf) simp only [mem_join, mem_bind', mem_map] at hs ⊢ filter_upwards [hg, hs] with _ hx hs using hx hs
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Johannes Hölzl, Mario Carneiro, Patrick Massot -/ import Mathlib.Data.Prod.PProd import Mathlib.Data.Set.Countable import Mathlib.Order.Filter.Prod import Mathlib.Order.Filter.Ker #align_import order.filter.bases from "leanprover-community/mathlib"@"996b0ff959da753a555053a480f36e5f264d4207" /-! # Filter bases A filter basis `B : FilterBasis α` on a type `α` is a nonempty collection of sets of `α` such that the intersection of two elements of this collection contains some element of the collection. Compared to filters, filter bases do not require that any set containing an element of `B` belongs to `B`. A filter basis `B` can be used to construct `B.filter : Filter α` such that a set belongs to `B.filter` if and only if it contains an element of `B`. Given an indexing type `ι`, a predicate `p : ι → Prop`, and a map `s : ι → Set α`, the proposition `h : Filter.IsBasis p s` makes sure the range of `s` bounded by `p` (ie. `s '' setOf p`) defines a filter basis `h.filterBasis`. If one already has a filter `l` on `α`, `Filter.HasBasis l p s` (where `p : ι → Prop` and `s : ι → Set α` as above) means that a set belongs to `l` if and only if it contains some `s i` with `p i`. It implies `h : Filter.IsBasis p s`, and `l = h.filterBasis.filter`. The point of this definition is that checking statements involving elements of `l` often reduces to checking them on the basis elements. We define a function `HasBasis.index (h : Filter.HasBasis l p s) (t) (ht : t ∈ l)` that returns some index `i` such that `p i` and `s i ⊆ t`. This function can be useful to avoid manual destruction of `h.mem_iff.mpr ht` using `cases` or `let`. This file also introduces more restricted classes of bases, involving monotonicity or countability. In particular, for `l : Filter α`, `l.IsCountablyGenerated` means there is a countable set of sets which generates `s`. This is reformulated in term of bases, and consequences are derived. ## Main statements * `Filter.HasBasis.mem_iff`, `HasBasis.mem_of_superset`, `HasBasis.mem_of_mem` : restate `t ∈ f` in terms of a basis; * `Filter.basis_sets` : all sets of a filter form a basis; * `Filter.HasBasis.inf`, `Filter.HasBasis.inf_principal`, `Filter.HasBasis.prod`, `Filter.HasBasis.prod_self`, `Filter.HasBasis.map`, `Filter.HasBasis.comap` : combinators to construct filters of `l ⊓ l'`, `l ⊓ 𝓟 t`, `l ×ˢ l'`, `l ×ˢ l`, `l.map f`, `l.comap f` respectively; * `Filter.HasBasis.le_iff`, `Filter.HasBasis.ge_iff`, `Filter.HasBasis.le_basis_iff` : restate `l ≤ l'` in terms of bases. * `Filter.HasBasis.tendsto_right_iff`, `Filter.HasBasis.tendsto_left_iff`, `Filter.HasBasis.tendsto_iff` : restate `Tendsto f l l'` in terms of bases. * `isCountablyGenerated_iff_exists_antitone_basis` : proves a filter is countably generated if and only if it admits a basis parametrized by a decreasing sequence of sets indexed by `ℕ`. * `tendsto_iff_seq_tendsto` : an abstract version of "sequentially continuous implies continuous". ## Implementation notes As with `Set.iUnion`/`biUnion`/`Set.sUnion`, there are three different approaches to filter bases: * `Filter.HasBasis l s`, `s : Set (Set α)`; * `Filter.HasBasis l s`, `s : ι → Set α`; * `Filter.HasBasis l p s`, `p : ι → Prop`, `s : ι → Set α`. We use the latter one because, e.g., `𝓝 x` in an `EMetricSpace` or in a `MetricSpace` has a basis of this form. The other two can be emulated using `s = id` or `p = fun _ ↦ True`. With this approach sometimes one needs to `simp` the statement provided by the `Filter.HasBasis` machinery, e.g., `simp only [true_and]` or `simp only [forall_const]` can help with the case `p = fun _ ↦ True`. -/ set_option autoImplicit true open Set Filter open scoped Classical open Filter section sort variable {α β γ : Type*} {ι ι' : Sort*} /-- A filter basis `B` on a type `α` is a nonempty collection of sets of `α` such that the intersection of two elements of this collection contains some element of the collection. -/ structure FilterBasis (α : Type*) where /-- Sets of a filter basis. -/ sets : Set (Set α) /-- The set of filter basis sets is nonempty. -/ nonempty : sets.Nonempty /-- The set of filter basis sets is directed downwards. -/ inter_sets {x y} : x ∈ sets → y ∈ sets → ∃ z ∈ sets, z ⊆ x ∩ y #align filter_basis FilterBasis instance FilterBasis.nonempty_sets (B : FilterBasis α) : Nonempty B.sets := B.nonempty.to_subtype #align filter_basis.nonempty_sets FilterBasis.nonempty_sets -- Porting note: this instance was reducible but it doesn't work the same way in Lean 4 /-- If `B` is a filter basis on `α`, and `U` a subset of `α` then we can write `U ∈ B` as on paper. -/ instance {α : Type*} : Membership (Set α) (FilterBasis α) := ⟨fun U B => U ∈ B.sets⟩ @[simp] theorem FilterBasis.mem_sets {s : Set α} {B : FilterBasis α} : s ∈ B.sets ↔ s ∈ B := Iff.rfl -- For illustration purposes, the filter basis defining `(atTop : Filter ℕ)` instance : Inhabited (FilterBasis ℕ) := ⟨{ sets := range Ici nonempty := ⟨Ici 0, mem_range_self 0⟩ inter_sets := by rintro _ _ ⟨n, rfl⟩ ⟨m, rfl⟩ exact ⟨Ici (max n m), mem_range_self _, Ici_inter_Ici.symm.subset⟩ }⟩ /-- View a filter as a filter basis. -/ def Filter.asBasis (f : Filter α) : FilterBasis α := ⟨f.sets, ⟨univ, univ_mem⟩, fun {x y} hx hy => ⟨x ∩ y, inter_mem hx hy, subset_rfl⟩⟩ #align filter.as_basis Filter.asBasis -- Porting note: was `protected` in Lean 3 but `protected` didn't work; removed /-- `is_basis p s` means the image of `s` bounded by `p` is a filter basis. -/ structure Filter.IsBasis (p : ι → Prop) (s : ι → Set α) : Prop where /-- There exists at least one `i` that satisfies `p`. -/ nonempty : ∃ i, p i /-- `s` is directed downwards on `i` such that `p i`. -/ inter : ∀ {i j}, p i → p j → ∃ k, p k ∧ s k ⊆ s i ∩ s j #align filter.is_basis Filter.IsBasis namespace Filter namespace IsBasis /-- Constructs a filter basis from an indexed family of sets satisfying `IsBasis`. -/ protected def filterBasis {p : ι → Prop} {s : ι → Set α} (h : IsBasis p s) : FilterBasis α where sets := { t | ∃ i, p i ∧ s i = t } nonempty := let ⟨i, hi⟩ := h.nonempty ⟨s i, ⟨i, hi, rfl⟩⟩ inter_sets := by rintro _ _ ⟨i, hi, rfl⟩ ⟨j, hj, rfl⟩ rcases h.inter hi hj with ⟨k, hk, hk'⟩ exact ⟨_, ⟨k, hk, rfl⟩, hk'⟩ #align filter.is_basis.filter_basis Filter.IsBasis.filterBasis variable {p : ι → Prop} {s : ι → Set α} (h : IsBasis p s) theorem mem_filterBasis_iff {U : Set α} : U ∈ h.filterBasis ↔ ∃ i, p i ∧ s i = U := Iff.rfl #align filter.is_basis.mem_filter_basis_iff Filter.IsBasis.mem_filterBasis_iff end IsBasis end Filter namespace FilterBasis /-- The filter associated to a filter basis. -/ protected def filter (B : FilterBasis α) : Filter α where sets := { s | ∃ t ∈ B, t ⊆ s } univ_sets := B.nonempty.imp fun s s_in => ⟨s_in, s.subset_univ⟩ sets_of_superset := fun ⟨s, s_in, h⟩ hxy => ⟨s, s_in, Set.Subset.trans h hxy⟩ inter_sets := fun ⟨_s, s_in, hs⟩ ⟨_t, t_in, ht⟩ => let ⟨u, u_in, u_sub⟩ := B.inter_sets s_in t_in ⟨u, u_in, u_sub.trans (inter_subset_inter hs ht)⟩ #align filter_basis.filter FilterBasis.filter theorem mem_filter_iff (B : FilterBasis α) {U : Set α} : U ∈ B.filter ↔ ∃ s ∈ B, s ⊆ U := Iff.rfl #align filter_basis.mem_filter_iff FilterBasis.mem_filter_iff theorem mem_filter_of_mem (B : FilterBasis α) {U : Set α} : U ∈ B → U ∈ B.filter := fun U_in => ⟨U, U_in, Subset.refl _⟩ #align filter_basis.mem_filter_of_mem FilterBasis.mem_filter_of_mem theorem eq_iInf_principal (B : FilterBasis α) : B.filter = ⨅ s : B.sets, 𝓟 s := by have : Directed (· ≥ ·) fun s : B.sets => 𝓟 (s : Set α) := by rintro ⟨U, U_in⟩ ⟨V, V_in⟩ rcases B.inter_sets U_in V_in with ⟨W, W_in, W_sub⟩ use ⟨W, W_in⟩ simp only [ge_iff_le, le_principal_iff, mem_principal, Subtype.coe_mk] exact subset_inter_iff.mp W_sub ext U simp [mem_filter_iff, mem_iInf_of_directed this] #align filter_basis.eq_infi_principal FilterBasis.eq_iInf_principal protected theorem generate (B : FilterBasis α) : generate B.sets = B.filter := by apply le_antisymm · intro U U_in rcases B.mem_filter_iff.mp U_in with ⟨V, V_in, h⟩ exact GenerateSets.superset (GenerateSets.basic V_in) h · rw [le_generate_iff] apply mem_filter_of_mem #align filter_basis.generate FilterBasis.generate end FilterBasis namespace Filter namespace IsBasis variable {p : ι → Prop} {s : ι → Set α} /-- Constructs a filter from an indexed family of sets satisfying `IsBasis`. -/ protected def filter (h : IsBasis p s) : Filter α := h.filterBasis.filter #align filter.is_basis.filter Filter.IsBasis.filter protected theorem mem_filter_iff (h : IsBasis p s) {U : Set α} : U ∈ h.filter ↔ ∃ i, p i ∧ s i ⊆ U := by simp only [IsBasis.filter, FilterBasis.mem_filter_iff, mem_filterBasis_iff, exists_exists_and_eq_and] #align filter.is_basis.mem_filter_iff Filter.IsBasis.mem_filter_iff theorem filter_eq_generate (h : IsBasis p s) : h.filter = generate { U | ∃ i, p i ∧ s i = U } := by erw [h.filterBasis.generate]; rfl #align filter.is_basis.filter_eq_generate Filter.IsBasis.filter_eq_generate end IsBasis -- Porting note: was `protected` in Lean 3 but `protected` didn't work; removed /-- We say that a filter `l` has a basis `s : ι → Set α` bounded by `p : ι → Prop`, if `t ∈ l` if and only if `t` includes `s i` for some `i` such that `p i`. -/ structure HasBasis (l : Filter α) (p : ι → Prop) (s : ι → Set α) : Prop where /-- A set `t` belongs to a filter `l` iff it includes an element of the basis. -/ mem_iff' : ∀ t : Set α, t ∈ l ↔ ∃ i, p i ∧ s i ⊆ t #align filter.has_basis Filter.HasBasis section SameType variable {l l' : Filter α} {p : ι → Prop} {s : ι → Set α} {t : Set α} {i : ι} {p' : ι' → Prop} {s' : ι' → Set α} {i' : ι'} theorem hasBasis_generate (s : Set (Set α)) : (generate s).HasBasis (fun t => Set.Finite t ∧ t ⊆ s) fun t => ⋂₀ t := ⟨fun U => by simp only [mem_generate_iff, exists_prop, and_assoc, and_left_comm]⟩ #align filter.has_basis_generate Filter.hasBasis_generate /-- The smallest filter basis containing a given collection of sets. -/ def FilterBasis.ofSets (s : Set (Set α)) : FilterBasis α where sets := sInter '' { t | Set.Finite t ∧ t ⊆ s } nonempty := ⟨univ, ∅, ⟨⟨finite_empty, empty_subset s⟩, sInter_empty⟩⟩ inter_sets := by rintro _ _ ⟨a, ⟨fina, suba⟩, rfl⟩ ⟨b, ⟨finb, subb⟩, rfl⟩ exact ⟨⋂₀ (a ∪ b), mem_image_of_mem _ ⟨fina.union finb, union_subset suba subb⟩, (sInter_union _ _).subset⟩ #align filter.filter_basis.of_sets Filter.FilterBasis.ofSets lemma FilterBasis.ofSets_sets (s : Set (Set α)) : (FilterBasis.ofSets s).sets = sInter '' { t | Set.Finite t ∧ t ⊆ s } := rfl -- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`. /-- Definition of `HasBasis` unfolded with implicit set argument. -/ theorem HasBasis.mem_iff (hl : l.HasBasis p s) : t ∈ l ↔ ∃ i, p i ∧ s i ⊆ t := hl.mem_iff' t #align filter.has_basis.mem_iff Filter.HasBasis.mem_iffₓ theorem HasBasis.eq_of_same_basis (hl : l.HasBasis p s) (hl' : l'.HasBasis p s) : l = l' := by ext t rw [hl.mem_iff, hl'.mem_iff] #align filter.has_basis.eq_of_same_basis Filter.HasBasis.eq_of_same_basis -- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`. theorem hasBasis_iff : l.HasBasis p s ↔ ∀ t, t ∈ l ↔ ∃ i, p i ∧ s i ⊆ t := ⟨fun ⟨h⟩ => h, fun h => ⟨h⟩⟩ #align filter.has_basis_iff Filter.hasBasis_iffₓ theorem HasBasis.ex_mem (h : l.HasBasis p s) : ∃ i, p i := (h.mem_iff.mp univ_mem).imp fun _ => And.left #align filter.has_basis.ex_mem Filter.HasBasis.ex_mem protected theorem HasBasis.nonempty (h : l.HasBasis p s) : Nonempty ι := nonempty_of_exists h.ex_mem #align filter.has_basis.nonempty Filter.HasBasis.nonempty protected theorem IsBasis.hasBasis (h : IsBasis p s) : HasBasis h.filter p s := ⟨fun t => by simp only [h.mem_filter_iff, exists_prop]⟩ #align filter.is_basis.has_basis Filter.IsBasis.hasBasis protected theorem HasBasis.mem_of_superset (hl : l.HasBasis p s) (hi : p i) (ht : s i ⊆ t) : t ∈ l := hl.mem_iff.2 ⟨i, hi, ht⟩ #align filter.has_basis.mem_of_superset Filter.HasBasis.mem_of_superset theorem HasBasis.mem_of_mem (hl : l.HasBasis p s) (hi : p i) : s i ∈ l := hl.mem_of_superset hi Subset.rfl #align filter.has_basis.mem_of_mem Filter.HasBasis.mem_of_mem /-- Index of a basis set such that `s i ⊆ t` as an element of `Subtype p`. -/ noncomputable def HasBasis.index (h : l.HasBasis p s) (t : Set α) (ht : t ∈ l) : { i : ι // p i } := ⟨(h.mem_iff.1 ht).choose, (h.mem_iff.1 ht).choose_spec.1⟩ #align filter.has_basis.index Filter.HasBasis.index theorem HasBasis.property_index (h : l.HasBasis p s) (ht : t ∈ l) : p (h.index t ht) := (h.index t ht).2 #align filter.has_basis.property_index Filter.HasBasis.property_index theorem HasBasis.set_index_mem (h : l.HasBasis p s) (ht : t ∈ l) : s (h.index t ht) ∈ l := h.mem_of_mem <| h.property_index _ #align filter.has_basis.set_index_mem Filter.HasBasis.set_index_mem theorem HasBasis.set_index_subset (h : l.HasBasis p s) (ht : t ∈ l) : s (h.index t ht) ⊆ t := (h.mem_iff.1 ht).choose_spec.2 #align filter.has_basis.set_index_subset Filter.HasBasis.set_index_subset theorem HasBasis.isBasis (h : l.HasBasis p s) : IsBasis p s where nonempty := h.ex_mem inter hi hj := by simpa only [h.mem_iff] using inter_mem (h.mem_of_mem hi) (h.mem_of_mem hj) #align filter.has_basis.is_basis Filter.HasBasis.isBasis theorem HasBasis.filter_eq (h : l.HasBasis p s) : h.isBasis.filter = l := by ext U simp [h.mem_iff, IsBasis.mem_filter_iff] #align filter.has_basis.filter_eq Filter.HasBasis.filter_eq theorem HasBasis.eq_generate (h : l.HasBasis p s) : l = generate { U | ∃ i, p i ∧ s i = U } := by rw [← h.isBasis.filter_eq_generate, h.filter_eq] #align filter.has_basis.eq_generate Filter.HasBasis.eq_generate theorem generate_eq_generate_inter (s : Set (Set α)) : generate s = generate (sInter '' { t | Set.Finite t ∧ t ⊆ s }) := by rw [← FilterBasis.ofSets_sets, FilterBasis.generate, ← (hasBasis_generate s).filter_eq]; rfl #align filter.generate_eq_generate_inter Filter.generate_eq_generate_inter theorem ofSets_filter_eq_generate (s : Set (Set α)) : (FilterBasis.ofSets s).filter = generate s := by rw [← (FilterBasis.ofSets s).generate, FilterBasis.ofSets_sets, ← generate_eq_generate_inter] #align filter.of_sets_filter_eq_generate Filter.ofSets_filter_eq_generate protected theorem _root_.FilterBasis.hasBasis (B : FilterBasis α) : HasBasis B.filter (fun s : Set α => s ∈ B) id := ⟨fun _ => B.mem_filter_iff⟩ #align filter_basis.has_basis FilterBasis.hasBasis theorem HasBasis.to_hasBasis' (hl : l.HasBasis p s) (h : ∀ i, p i → ∃ i', p' i' ∧ s' i' ⊆ s i) (h' : ∀ i', p' i' → s' i' ∈ l) : l.HasBasis p' s' := by refine ⟨fun t => ⟨fun ht => ?_, fun ⟨i', hi', ht⟩ => mem_of_superset (h' i' hi') ht⟩⟩ rcases hl.mem_iff.1 ht with ⟨i, hi, ht⟩ rcases h i hi with ⟨i', hi', hs's⟩ exact ⟨i', hi', hs's.trans ht⟩ #align filter.has_basis.to_has_basis' Filter.HasBasis.to_hasBasis' theorem HasBasis.to_hasBasis (hl : l.HasBasis p s) (h : ∀ i, p i → ∃ i', p' i' ∧ s' i' ⊆ s i) (h' : ∀ i', p' i' → ∃ i, p i ∧ s i ⊆ s' i') : l.HasBasis p' s' := hl.to_hasBasis' h fun i' hi' => let ⟨i, hi, hss'⟩ := h' i' hi' hl.mem_iff.2 ⟨i, hi, hss'⟩ #align filter.has_basis.to_has_basis Filter.HasBasis.to_hasBasis protected lemma HasBasis.congr (hl : l.HasBasis p s) {p' s'} (hp : ∀ i, p i ↔ p' i) (hs : ∀ i, p i → s i = s' i) : l.HasBasis p' s' := ⟨fun t ↦ by simp only [hl.mem_iff, ← hp]; exact exists_congr fun i ↦ and_congr_right fun hi ↦ hs i hi ▸ Iff.rfl⟩ theorem HasBasis.to_subset (hl : l.HasBasis p s) {t : ι → Set α} (h : ∀ i, p i → t i ⊆ s i) (ht : ∀ i, p i → t i ∈ l) : l.HasBasis p t := hl.to_hasBasis' (fun i hi => ⟨i, hi, h i hi⟩) ht #align filter.has_basis.to_subset Filter.HasBasis.to_subset theorem HasBasis.eventually_iff (hl : l.HasBasis p s) {q : α → Prop} : (∀ᶠ x in l, q x) ↔ ∃ i, p i ∧ ∀ ⦃x⦄, x ∈ s i → q x := by simpa using hl.mem_iff #align filter.has_basis.eventually_iff Filter.HasBasis.eventually_iff theorem HasBasis.frequently_iff (hl : l.HasBasis p s) {q : α → Prop} : (∃ᶠ x in l, q x) ↔ ∀ i, p i → ∃ x ∈ s i, q x := by simp only [Filter.Frequently, hl.eventually_iff]; push_neg; rfl #align filter.has_basis.frequently_iff Filter.HasBasis.frequently_iff -- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`. theorem HasBasis.exists_iff (hl : l.HasBasis p s) {P : Set α → Prop} (mono : ∀ ⦃s t⦄, s ⊆ t → P t → P s) : (∃ s ∈ l, P s) ↔ ∃ i, p i ∧ P (s i) := ⟨fun ⟨_s, hs, hP⟩ => let ⟨i, hi, his⟩ := hl.mem_iff.1 hs ⟨i, hi, mono his hP⟩, fun ⟨i, hi, hP⟩ => ⟨s i, hl.mem_of_mem hi, hP⟩⟩ #align filter.has_basis.exists_iff Filter.HasBasis.exists_iffₓ theorem HasBasis.forall_iff (hl : l.HasBasis p s) {P : Set α → Prop} (mono : ∀ ⦃s t⦄, s ⊆ t → P s → P t) : (∀ s ∈ l, P s) ↔ ∀ i, p i → P (s i) := ⟨fun H i hi => H (s i) <| hl.mem_of_mem hi, fun H _s hs => let ⟨i, hi, his⟩ := hl.mem_iff.1 hs mono his (H i hi)⟩ #align filter.has_basis.forall_iff Filter.HasBasis.forall_iff protected theorem HasBasis.neBot_iff (hl : l.HasBasis p s) : NeBot l ↔ ∀ {i}, p i → (s i).Nonempty := forall_mem_nonempty_iff_neBot.symm.trans <| hl.forall_iff fun _ _ => Nonempty.mono #align filter.has_basis.ne_bot_iff Filter.HasBasis.neBot_iff theorem HasBasis.eq_bot_iff (hl : l.HasBasis p s) : l = ⊥ ↔ ∃ i, p i ∧ s i = ∅ := not_iff_not.1 <| neBot_iff.symm.trans <| hl.neBot_iff.trans <| by simp only [not_exists, not_and, nonempty_iff_ne_empty] #align filter.has_basis.eq_bot_iff Filter.HasBasis.eq_bot_iff theorem generate_neBot_iff {s : Set (Set α)} : NeBot (generate s) ↔ ∀ t, t ⊆ s → t.Finite → (⋂₀ t).Nonempty := (hasBasis_generate s).neBot_iff.trans <| by simp only [← and_imp, and_comm] #align filter.generate_ne_bot_iff Filter.generate_neBot_iff theorem basis_sets (l : Filter α) : l.HasBasis (fun s : Set α => s ∈ l) id := ⟨fun _ => exists_mem_subset_iff.symm⟩ #align filter.basis_sets Filter.basis_sets theorem asBasis_filter (f : Filter α) : f.asBasis.filter = f := Filter.ext fun _ => exists_mem_subset_iff #align filter.as_basis_filter Filter.asBasis_filter theorem hasBasis_self {l : Filter α} {P : Set α → Prop} : HasBasis l (fun s => s ∈ l ∧ P s) id ↔ ∀ t ∈ l, ∃ r ∈ l, P r ∧ r ⊆ t := by simp only [hasBasis_iff, id, and_assoc] exact forall_congr' fun s => ⟨fun h => h.1, fun h => ⟨h, fun ⟨t, hl, _, hts⟩ => mem_of_superset hl hts⟩⟩ #align filter.has_basis_self Filter.hasBasis_self theorem HasBasis.comp_surjective (h : l.HasBasis p s) {g : ι' → ι} (hg : Function.Surjective g) : l.HasBasis (p ∘ g) (s ∘ g) := ⟨fun _ => h.mem_iff.trans hg.exists⟩ #align filter.has_basis.comp_surjective Filter.HasBasis.comp_surjective theorem HasBasis.comp_equiv (h : l.HasBasis p s) (e : ι' ≃ ι) : l.HasBasis (p ∘ e) (s ∘ e) := h.comp_surjective e.surjective #align filter.has_basis.comp_equiv Filter.HasBasis.comp_equiv theorem HasBasis.to_image_id' (h : l.HasBasis p s) : l.HasBasis (fun t ↦ ∃ i, p i ∧ s i = t) id := ⟨fun _ ↦ by simp [h.mem_iff]⟩ theorem HasBasis.to_image_id {ι : Type*} {p : ι → Prop} {s : ι → Set α} (h : l.HasBasis p s) : l.HasBasis (· ∈ s '' {i | p i}) id := h.to_image_id' /-- If `{s i | p i}` is a basis of a filter `l` and each `s i` includes `s j` such that `p j ∧ q j`, then `{s j | p j ∧ q j}` is a basis of `l`. -/ theorem HasBasis.restrict (h : l.HasBasis p s) {q : ι → Prop} (hq : ∀ i, p i → ∃ j, p j ∧ q j ∧ s j ⊆ s i) : l.HasBasis (fun i => p i ∧ q i) s := by refine ⟨fun t => ⟨fun ht => ?_, fun ⟨i, hpi, hti⟩ => h.mem_iff.2 ⟨i, hpi.1, hti⟩⟩⟩ rcases h.mem_iff.1 ht with ⟨i, hpi, hti⟩ rcases hq i hpi with ⟨j, hpj, hqj, hji⟩ exact ⟨j, ⟨hpj, hqj⟩, hji.trans hti⟩ #align filter.has_basis.restrict Filter.HasBasis.restrict /-- If `{s i | p i}` is a basis of a filter `l` and `V ∈ l`, then `{s i | p i ∧ s i ⊆ V}` is a basis of `l`. -/ theorem HasBasis.restrict_subset (h : l.HasBasis p s) {V : Set α} (hV : V ∈ l) : l.HasBasis (fun i => p i ∧ s i ⊆ V) s := h.restrict fun _i hi => (h.mem_iff.1 (inter_mem hV (h.mem_of_mem hi))).imp fun _j hj => ⟨hj.1, subset_inter_iff.1 hj.2⟩ #align filter.has_basis.restrict_subset Filter.HasBasis.restrict_subset theorem HasBasis.hasBasis_self_subset {p : Set α → Prop} (h : l.HasBasis (fun s => s ∈ l ∧ p s) id) {V : Set α} (hV : V ∈ l) : l.HasBasis (fun s => s ∈ l ∧ p s ∧ s ⊆ V) id := by simpa only [and_assoc] using h.restrict_subset hV #align filter.has_basis.has_basis_self_subset Filter.HasBasis.hasBasis_self_subset theorem HasBasis.ge_iff (hl' : l'.HasBasis p' s') : l ≤ l' ↔ ∀ i', p' i' → s' i' ∈ l := ⟨fun h _i' hi' => h <| hl'.mem_of_mem hi', fun h _s hs => let ⟨_i', hi', hs⟩ := hl'.mem_iff.1 hs mem_of_superset (h _ hi') hs⟩ #align filter.has_basis.ge_iff Filter.HasBasis.ge_iff -- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`. theorem HasBasis.le_iff (hl : l.HasBasis p s) : l ≤ l' ↔ ∀ t ∈ l', ∃ i, p i ∧ s i ⊆ t := by simp only [le_def, hl.mem_iff] #align filter.has_basis.le_iff Filter.HasBasis.le_iffₓ -- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`. theorem HasBasis.le_basis_iff (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') : l ≤ l' ↔ ∀ i', p' i' → ∃ i, p i ∧ s i ⊆ s' i' := by simp only [hl'.ge_iff, hl.mem_iff] #align filter.has_basis.le_basis_iff Filter.HasBasis.le_basis_iffₓ -- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`. theorem HasBasis.ext (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') (h : ∀ i, p i → ∃ i', p' i' ∧ s' i' ⊆ s i) (h' : ∀ i', p' i' → ∃ i, p i ∧ s i ⊆ s' i') : l = l' := by apply le_antisymm · rw [hl.le_basis_iff hl'] simpa using h' · rw [hl'.le_basis_iff hl] simpa using h #align filter.has_basis.ext Filter.HasBasis.extₓ theorem HasBasis.inf' (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') : (l ⊓ l').HasBasis (fun i : PProd ι ι' => p i.1 ∧ p' i.2) fun i => s i.1 ∩ s' i.2 := ⟨by intro t constructor · simp only [mem_inf_iff, hl.mem_iff, hl'.mem_iff] rintro ⟨t, ⟨i, hi, ht⟩, t', ⟨i', hi', ht'⟩, rfl⟩ exact ⟨⟨i, i'⟩, ⟨hi, hi'⟩, inter_subset_inter ht ht'⟩ · rintro ⟨⟨i, i'⟩, ⟨hi, hi'⟩, H⟩ exact mem_inf_of_inter (hl.mem_of_mem hi) (hl'.mem_of_mem hi') H⟩ #align filter.has_basis.inf' Filter.HasBasis.inf' theorem HasBasis.inf {ι ι' : Type*} {p : ι → Prop} {s : ι → Set α} {p' : ι' → Prop} {s' : ι' → Set α} (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') : (l ⊓ l').HasBasis (fun i : ι × ι' => p i.1 ∧ p' i.2) fun i => s i.1 ∩ s' i.2 := (hl.inf' hl').comp_equiv Equiv.pprodEquivProd.symm #align filter.has_basis.inf Filter.HasBasis.inf theorem hasBasis_iInf' {ι : Type*} {ι' : ι → Type*} {l : ι → Filter α} {p : ∀ i, ι' i → Prop} {s : ∀ i, ι' i → Set α} (hl : ∀ i, (l i).HasBasis (p i) (s i)) : (⨅ i, l i).HasBasis (fun If : Set ι × ∀ i, ι' i => If.1.Finite ∧ ∀ i ∈ If.1, p i (If.2 i)) fun If : Set ι × ∀ i, ι' i => ⋂ i ∈ If.1, s i (If.2 i) := ⟨by intro t constructor · simp only [mem_iInf', (hl _).mem_iff] rintro ⟨I, hI, V, hV, -, rfl, -⟩ choose u hu using hV exact ⟨⟨I, u⟩, ⟨hI, fun i _ => (hu i).1⟩, iInter₂_mono fun i _ => (hu i).2⟩ · rintro ⟨⟨I, f⟩, ⟨hI₁, hI₂⟩, hsub⟩ refine mem_of_superset ?_ hsub exact (biInter_mem hI₁).mpr fun i hi => mem_iInf_of_mem i <| (hl i).mem_of_mem <| hI₂ _ hi⟩ #align filter.has_basis_infi' Filter.hasBasis_iInf' theorem hasBasis_iInf {ι : Type*} {ι' : ι → Type*} {l : ι → Filter α} {p : ∀ i, ι' i → Prop} {s : ∀ i, ι' i → Set α} (hl : ∀ i, (l i).HasBasis (p i) (s i)) : (⨅ i, l i).HasBasis (fun If : Σ I : Set ι, ∀ i : I, ι' i => If.1.Finite ∧ ∀ i : If.1, p i (If.2 i)) fun If => ⋂ i : If.1, s i (If.2 i) := by refine ⟨fun t => ⟨fun ht => ?_, ?_⟩⟩ · rcases (hasBasis_iInf' hl).mem_iff.mp ht with ⟨⟨I, f⟩, ⟨hI, hf⟩, hsub⟩ exact ⟨⟨I, fun i => f i⟩, ⟨hI, Subtype.forall.mpr hf⟩, trans (iInter_subtype _ _) hsub⟩ · rintro ⟨⟨I, f⟩, ⟨hI, hf⟩, hsub⟩ refine mem_of_superset ?_ hsub cases hI.nonempty_fintype exact iInter_mem.2 fun i => mem_iInf_of_mem ↑i <| (hl i).mem_of_mem <| hf _ #align filter.has_basis_infi Filter.hasBasis_iInf theorem hasBasis_iInf_of_directed' {ι : Type*} {ι' : ι → Sort _} [Nonempty ι] {l : ι → Filter α} (s : ∀ i, ι' i → Set α) (p : ∀ i, ι' i → Prop) (hl : ∀ i, (l i).HasBasis (p i) (s i)) (h : Directed (· ≥ ·) l) : (⨅ i, l i).HasBasis (fun ii' : Σi, ι' i => p ii'.1 ii'.2) fun ii' => s ii'.1 ii'.2 := by refine ⟨fun t => ?_⟩ rw [mem_iInf_of_directed h, Sigma.exists] exact exists_congr fun i => (hl i).mem_iff #align filter.has_basis_infi_of_directed' Filter.hasBasis_iInf_of_directed' theorem hasBasis_iInf_of_directed {ι : Type*} {ι' : Sort _} [Nonempty ι] {l : ι → Filter α} (s : ι → ι' → Set α) (p : ι → ι' → Prop) (hl : ∀ i, (l i).HasBasis (p i) (s i)) (h : Directed (· ≥ ·) l) : (⨅ i, l i).HasBasis (fun ii' : ι × ι' => p ii'.1 ii'.2) fun ii' => s ii'.1 ii'.2 := by refine ⟨fun t => ?_⟩ rw [mem_iInf_of_directed h, Prod.exists] exact exists_congr fun i => (hl i).mem_iff #align filter.has_basis_infi_of_directed Filter.hasBasis_iInf_of_directed theorem hasBasis_biInf_of_directed' {ι : Type*} {ι' : ι → Sort _} {dom : Set ι} (hdom : dom.Nonempty) {l : ι → Filter α} (s : ∀ i, ι' i → Set α) (p : ∀ i, ι' i → Prop) (hl : ∀ i ∈ dom, (l i).HasBasis (p i) (s i)) (h : DirectedOn (l ⁻¹'o GE.ge) dom) : (⨅ i ∈ dom, l i).HasBasis (fun ii' : Σi, ι' i => ii'.1 ∈ dom ∧ p ii'.1 ii'.2) fun ii' => s ii'.1 ii'.2 := by refine ⟨fun t => ?_⟩ rw [mem_biInf_of_directed h hdom, Sigma.exists] refine exists_congr fun i => ⟨?_, ?_⟩ · rintro ⟨hi, hti⟩ rcases (hl i hi).mem_iff.mp hti with ⟨b, hb, hbt⟩ exact ⟨b, ⟨hi, hb⟩, hbt⟩ · rintro ⟨b, ⟨hi, hb⟩, hibt⟩ exact ⟨hi, (hl i hi).mem_iff.mpr ⟨b, hb, hibt⟩⟩ #align filter.has_basis_binfi_of_directed' Filter.hasBasis_biInf_of_directed' theorem hasBasis_biInf_of_directed {ι : Type*} {ι' : Sort _} {dom : Set ι} (hdom : dom.Nonempty) {l : ι → Filter α} (s : ι → ι' → Set α) (p : ι → ι' → Prop) (hl : ∀ i ∈ dom, (l i).HasBasis (p i) (s i)) (h : DirectedOn (l ⁻¹'o GE.ge) dom) : (⨅ i ∈ dom, l i).HasBasis (fun ii' : ι × ι' => ii'.1 ∈ dom ∧ p ii'.1 ii'.2) fun ii' => s ii'.1 ii'.2 := by refine ⟨fun t => ?_⟩ rw [mem_biInf_of_directed h hdom, Prod.exists] refine exists_congr fun i => ⟨?_, ?_⟩ · rintro ⟨hi, hti⟩ rcases (hl i hi).mem_iff.mp hti with ⟨b, hb, hbt⟩ exact ⟨b, ⟨hi, hb⟩, hbt⟩ · rintro ⟨b, ⟨hi, hb⟩, hibt⟩ exact ⟨hi, (hl i hi).mem_iff.mpr ⟨b, hb, hibt⟩⟩ #align filter.has_basis_binfi_of_directed Filter.hasBasis_biInf_of_directed theorem hasBasis_principal (t : Set α) : (𝓟 t).HasBasis (fun _ : Unit => True) fun _ => t := ⟨fun U => by simp⟩ #align filter.has_basis_principal Filter.hasBasis_principal theorem hasBasis_pure (x : α) : (pure x : Filter α).HasBasis (fun _ : Unit => True) fun _ => {x} := by simp only [← principal_singleton, hasBasis_principal] #align filter.has_basis_pure Filter.hasBasis_pure theorem HasBasis.sup' (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') : (l ⊔ l').HasBasis (fun i : PProd ι ι' => p i.1 ∧ p' i.2) fun i => s i.1 ∪ s' i.2 := ⟨by intro t simp_rw [mem_sup, hl.mem_iff, hl'.mem_iff, PProd.exists, union_subset_iff, ← exists_and_right, ← exists_and_left] simp only [and_assoc, and_left_comm]⟩ #align filter.has_basis.sup' Filter.HasBasis.sup' theorem HasBasis.sup {ι ι' : Type*} {p : ι → Prop} {s : ι → Set α} {p' : ι' → Prop} {s' : ι' → Set α} (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') : (l ⊔ l').HasBasis (fun i : ι × ι' => p i.1 ∧ p' i.2) fun i => s i.1 ∪ s' i.2 := (hl.sup' hl').comp_equiv Equiv.pprodEquivProd.symm #align filter.has_basis.sup Filter.HasBasis.sup theorem hasBasis_iSup {ι : Sort*} {ι' : ι → Type*} {l : ι → Filter α} {p : ∀ i, ι' i → Prop} {s : ∀ i, ι' i → Set α} (hl : ∀ i, (l i).HasBasis (p i) (s i)) : (⨆ i, l i).HasBasis (fun f : ∀ i, ι' i => ∀ i, p i (f i)) fun f : ∀ i, ι' i => ⋃ i, s i (f i) := hasBasis_iff.mpr fun t => by simp only [hasBasis_iff, (hl _).mem_iff, Classical.skolem, forall_and, iUnion_subset_iff, mem_iSup] #align filter.has_basis_supr Filter.hasBasis_iSup theorem HasBasis.sup_principal (hl : l.HasBasis p s) (t : Set α) : (l ⊔ 𝓟 t).HasBasis p fun i => s i ∪ t := ⟨fun u => by simp only [(hl.sup' (hasBasis_principal t)).mem_iff, PProd.exists, exists_prop, and_true_iff, Unique.exists_iff]⟩ #align filter.has_basis.sup_principal Filter.HasBasis.sup_principal theorem HasBasis.sup_pure (hl : l.HasBasis p s) (x : α) : (l ⊔ pure x).HasBasis p fun i => s i ∪ {x} := by simp only [← principal_singleton, hl.sup_principal] #align filter.has_basis.sup_pure Filter.HasBasis.sup_pure theorem HasBasis.inf_principal (hl : l.HasBasis p s) (s' : Set α) : (l ⊓ 𝓟 s').HasBasis p fun i => s i ∩ s' := ⟨fun t => by simp only [mem_inf_principal, hl.mem_iff, subset_def, mem_setOf_eq, mem_inter_iff, and_imp]⟩ #align filter.has_basis.inf_principal Filter.HasBasis.inf_principal theorem HasBasis.principal_inf (hl : l.HasBasis p s) (s' : Set α) : (𝓟 s' ⊓ l).HasBasis p fun i => s' ∩ s i := by simpa only [inf_comm, inter_comm] using hl.inf_principal s' #align filter.has_basis.principal_inf Filter.HasBasis.principal_inf theorem HasBasis.inf_basis_neBot_iff (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') : NeBot (l ⊓ l') ↔ ∀ ⦃i⦄, p i → ∀ ⦃i'⦄, p' i' → (s i ∩ s' i').Nonempty := (hl.inf' hl').neBot_iff.trans <| by simp [@forall_swap _ ι'] #align filter.has_basis.inf_basis_ne_bot_iff Filter.HasBasis.inf_basis_neBot_iff theorem HasBasis.inf_neBot_iff (hl : l.HasBasis p s) : NeBot (l ⊓ l') ↔ ∀ ⦃i⦄, p i → ∀ ⦃s'⦄, s' ∈ l' → (s i ∩ s').Nonempty := hl.inf_basis_neBot_iff l'.basis_sets #align filter.has_basis.inf_ne_bot_iff Filter.HasBasis.inf_neBot_iff theorem HasBasis.inf_principal_neBot_iff (hl : l.HasBasis p s) {t : Set α} : NeBot (l ⊓ 𝓟 t) ↔ ∀ ⦃i⦄, p i → (s i ∩ t).Nonempty := (hl.inf_principal t).neBot_iff #align filter.has_basis.inf_principal_ne_bot_iff Filter.HasBasis.inf_principal_neBot_iff -- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`. theorem HasBasis.disjoint_iff (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') : Disjoint l l' ↔ ∃ i, p i ∧ ∃ i', p' i' ∧ Disjoint (s i) (s' i') := not_iff_not.mp <| by simp only [_root_.disjoint_iff, ← Ne.eq_def, ← neBot_iff, inf_eq_inter, hl.inf_basis_neBot_iff hl', not_exists, not_and, bot_eq_empty, ← nonempty_iff_ne_empty] #align filter.has_basis.disjoint_iff Filter.HasBasis.disjoint_iffₓ -- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`. theorem _root_.Disjoint.exists_mem_filter_basis (h : Disjoint l l') (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') : ∃ i, p i ∧ ∃ i', p' i' ∧ Disjoint (s i) (s' i') := (hl.disjoint_iff hl').1 h #align disjoint.exists_mem_filter_basis Disjoint.exists_mem_filter_basisₓ theorem _root_.Pairwise.exists_mem_filter_basis_of_disjoint {I} [Finite I] {l : I → Filter α} {ι : I → Sort*} {p : ∀ i, ι i → Prop} {s : ∀ i, ι i → Set α} (hd : Pairwise (Disjoint on l)) (h : ∀ i, (l i).HasBasis (p i) (s i)) : ∃ ind : ∀ i, ι i, (∀ i, p i (ind i)) ∧ Pairwise (Disjoint on fun i => s i (ind i)) := by rcases hd.exists_mem_filter_of_disjoint with ⟨t, htl, hd⟩ choose ind hp ht using fun i => (h i).mem_iff.1 (htl i) exact ⟨ind, hp, hd.mono fun i j hij => hij.mono (ht _) (ht _)⟩ #align pairwise.exists_mem_filter_basis_of_disjoint Pairwise.exists_mem_filter_basis_of_disjoint theorem _root_.Set.PairwiseDisjoint.exists_mem_filter_basis {I : Type*} {l : I → Filter α} {ι : I → Sort*} {p : ∀ i, ι i → Prop} {s : ∀ i, ι i → Set α} {S : Set I} (hd : S.PairwiseDisjoint l) (hS : S.Finite) (h : ∀ i, (l i).HasBasis (p i) (s i)) : ∃ ind : ∀ i, ι i, (∀ i, p i (ind i)) ∧ S.PairwiseDisjoint fun i => s i (ind i) := by rcases hd.exists_mem_filter hS with ⟨t, htl, hd⟩ choose ind hp ht using fun i => (h i).mem_iff.1 (htl i) exact ⟨ind, hp, hd.mono ht⟩ #align set.pairwise_disjoint.exists_mem_filter_basis Set.PairwiseDisjoint.exists_mem_filter_basis theorem inf_neBot_iff : NeBot (l ⊓ l') ↔ ∀ ⦃s : Set α⦄, s ∈ l → ∀ ⦃s'⦄, s' ∈ l' → (s ∩ s').Nonempty := l.basis_sets.inf_neBot_iff #align filter.inf_ne_bot_iff Filter.inf_neBot_iff theorem inf_principal_neBot_iff {s : Set α} : NeBot (l ⊓ 𝓟 s) ↔ ∀ U ∈ l, (U ∩ s).Nonempty := l.basis_sets.inf_principal_neBot_iff #align filter.inf_principal_ne_bot_iff Filter.inf_principal_neBot_iff theorem mem_iff_inf_principal_compl {f : Filter α} {s : Set α} : s ∈ f ↔ f ⊓ 𝓟 sᶜ = ⊥ := by refine not_iff_not.1 ((inf_principal_neBot_iff.trans ?_).symm.trans neBot_iff) exact ⟨fun h hs => by simpa [Set.not_nonempty_empty] using h s hs, fun hs t ht => inter_compl_nonempty_iff.2 fun hts => hs <| mem_of_superset ht hts⟩ #align filter.mem_iff_inf_principal_compl Filter.mem_iff_inf_principal_compl theorem not_mem_iff_inf_principal_compl {f : Filter α} {s : Set α} : s ∉ f ↔ NeBot (f ⊓ 𝓟 sᶜ) := (not_congr mem_iff_inf_principal_compl).trans neBot_iff.symm #align filter.not_mem_iff_inf_principal_compl Filter.not_mem_iff_inf_principal_compl @[simp] theorem disjoint_principal_right {f : Filter α} {s : Set α} : Disjoint f (𝓟 s) ↔ sᶜ ∈ f := by rw [mem_iff_inf_principal_compl, compl_compl, disjoint_iff] #align filter.disjoint_principal_right Filter.disjoint_principal_right @[simp] theorem disjoint_principal_left {f : Filter α} {s : Set α} : Disjoint (𝓟 s) f ↔ sᶜ ∈ f := by rw [disjoint_comm, disjoint_principal_right] #align filter.disjoint_principal_left Filter.disjoint_principal_left @[simp 1100] -- Porting note: higher priority for linter theorem disjoint_principal_principal {s t : Set α} : Disjoint (𝓟 s) (𝓟 t) ↔ Disjoint s t := by rw [← subset_compl_iff_disjoint_left, disjoint_principal_left, mem_principal] #align filter.disjoint_principal_principal Filter.disjoint_principal_principal alias ⟨_, _root_.Disjoint.filter_principal⟩ := disjoint_principal_principal #align disjoint.filter_principal Disjoint.filter_principal @[simp] theorem disjoint_pure_pure {x y : α} : Disjoint (pure x : Filter α) (pure y) ↔ x ≠ y := by simp only [← principal_singleton, disjoint_principal_principal, disjoint_singleton] #align filter.disjoint_pure_pure Filter.disjoint_pure_pure @[simp] theorem compl_diagonal_mem_prod {l₁ l₂ : Filter α} : (diagonal α)ᶜ ∈ l₁ ×ˢ l₂ ↔ Disjoint l₁ l₂ := by simp only [mem_prod_iff, Filter.disjoint_iff, prod_subset_compl_diagonal_iff_disjoint] #align filter.compl_diagonal_mem_prod Filter.compl_diagonal_mem_prod -- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`. theorem HasBasis.disjoint_iff_left (h : l.HasBasis p s) : Disjoint l l' ↔ ∃ i, p i ∧ (s i)ᶜ ∈ l' := by simp only [h.disjoint_iff l'.basis_sets, id, ← disjoint_principal_left, (hasBasis_principal _).disjoint_iff l'.basis_sets, true_and, Unique.exists_iff] #align filter.has_basis.disjoint_iff_left Filter.HasBasis.disjoint_iff_leftₓ -- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`. theorem HasBasis.disjoint_iff_right (h : l.HasBasis p s) : Disjoint l' l ↔ ∃ i, p i ∧ (s i)ᶜ ∈ l' := disjoint_comm.trans h.disjoint_iff_left #align filter.has_basis.disjoint_iff_right Filter.HasBasis.disjoint_iff_rightₓ theorem le_iff_forall_inf_principal_compl {f g : Filter α} : f ≤ g ↔ ∀ V ∈ g, f ⊓ 𝓟 Vᶜ = ⊥ := forall₂_congr fun _ _ => mem_iff_inf_principal_compl #align filter.le_iff_forall_inf_principal_compl Filter.le_iff_forall_inf_principal_compl theorem inf_neBot_iff_frequently_left {f g : Filter α} : NeBot (f ⊓ g) ↔ ∀ {p : α → Prop}, (∀ᶠ x in f, p x) → ∃ᶠ x in g, p x := by simp only [inf_neBot_iff, frequently_iff, and_comm]; rfl #align filter.inf_ne_bot_iff_frequently_left Filter.inf_neBot_iff_frequently_left theorem inf_neBot_iff_frequently_right {f g : Filter α} : NeBot (f ⊓ g) ↔ ∀ {p : α → Prop}, (∀ᶠ x in g, p x) → ∃ᶠ x in f, p x := by rw [inf_comm] exact inf_neBot_iff_frequently_left #align filter.inf_ne_bot_iff_frequently_right Filter.inf_neBot_iff_frequently_right theorem HasBasis.eq_biInf (h : l.HasBasis p s) : l = ⨅ (i) (_ : p i), 𝓟 (s i) := eq_biInf_of_mem_iff_exists_mem fun {_} => by simp only [h.mem_iff, mem_principal, exists_prop] #align filter.has_basis.eq_binfi Filter.HasBasis.eq_biInf theorem HasBasis.eq_iInf (h : l.HasBasis (fun _ => True) s) : l = ⨅ i, 𝓟 (s i) := by simpa only [iInf_true] using h.eq_biInf #align filter.has_basis.eq_infi Filter.HasBasis.eq_iInf theorem hasBasis_iInf_principal {s : ι → Set α} (h : Directed (· ≥ ·) s) [Nonempty ι] : (⨅ i, 𝓟 (s i)).HasBasis (fun _ => True) s := ⟨fun t => by simpa only [true_and] using mem_iInf_of_directed (h.mono_comp monotone_principal.dual) t⟩ #align filter.has_basis_infi_principal Filter.hasBasis_iInf_principal /-- If `s : ι → Set α` is an indexed family of sets, then finite intersections of `s i` form a basis of `⨅ i, 𝓟 (s i)`. -/
Mathlib/Order/Filter/Bases.lean
782
786
theorem hasBasis_iInf_principal_finite {ι : Type*} (s : ι → Set α) : (⨅ i, 𝓟 (s i)).HasBasis (fun t : Set ι => t.Finite) fun t => ⋂ i ∈ t, s i := by
refine ⟨fun U => (mem_iInf_finite _).trans ?_⟩ simp only [iInf_principal_finset, mem_iUnion, mem_principal, exists_prop, exists_finite_iff_finset, Finset.set_biInter_coe]
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Chris Hughes -/ import Mathlib.Algebra.Algebra.Defs import Mathlib.Algebra.Polynomial.FieldDivision import Mathlib.FieldTheory.Minpoly.Basic import Mathlib.RingTheory.Adjoin.Basic import Mathlib.RingTheory.FinitePresentation import Mathlib.RingTheory.FiniteType import Mathlib.RingTheory.PowerBasis import Mathlib.RingTheory.PrincipalIdealDomain import Mathlib.RingTheory.QuotientNoetherian #align_import ring_theory.adjoin_root from "leanprover-community/mathlib"@"5c4b3d41a84bd2a1d79c7d9265e58a891e71be89" /-! # Adjoining roots of polynomials This file defines the commutative ring `AdjoinRoot f`, the ring R[X]/(f) obtained from a commutative ring `R` and a polynomial `f : R[X]`. If furthermore `R` is a field and `f` is irreducible, the field structure on `AdjoinRoot f` is constructed. We suggest stating results on `IsAdjoinRoot` instead of `AdjoinRoot` to achieve higher generality, since `IsAdjoinRoot` works for all different constructions of `R[α]` including `AdjoinRoot f = R[X]/(f)` itself. ## Main definitions and results The main definitions are in the `AdjoinRoot` namespace. * `mk f : R[X] →+* AdjoinRoot f`, the natural ring homomorphism. * `of f : R →+* AdjoinRoot f`, the natural ring homomorphism. * `root f : AdjoinRoot f`, the image of X in R[X]/(f). * `lift (i : R →+* S) (x : S) (h : f.eval₂ i x = 0) : (AdjoinRoot f) →+* S`, the ring homomorphism from R[X]/(f) to S extending `i : R →+* S` and sending `X` to `x`. * `lift_hom (x : S) (hfx : aeval x f = 0) : AdjoinRoot f →ₐ[R] S`, the algebra homomorphism from R[X]/(f) to S extending `algebraMap R S` and sending `X` to `x` * `equiv : (AdjoinRoot f →ₐ[F] E) ≃ {x // x ∈ f.aroots E}` a bijection between algebra homomorphisms from `AdjoinRoot` and roots of `f` in `S` -/ noncomputable section open scoped Classical open Polynomial universe u v w variable {R : Type u} {S : Type v} {K : Type w} open Polynomial Ideal /-- Adjoin a root of a polynomial `f` to a commutative ring `R`. We define the new ring as the quotient of `R[X]` by the principal ideal generated by `f`. -/ def AdjoinRoot [CommRing R] (f : R[X]) : Type u := Polynomial R ⧸ (span {f} : Ideal R[X]) #align adjoin_root AdjoinRoot namespace AdjoinRoot section CommRing variable [CommRing R] (f : R[X]) instance instCommRing : CommRing (AdjoinRoot f) := Ideal.Quotient.commRing _ #align adjoin_root.comm_ring AdjoinRoot.instCommRing instance : Inhabited (AdjoinRoot f) := ⟨0⟩ instance : DecidableEq (AdjoinRoot f) := Classical.decEq _ protected theorem nontrivial [IsDomain R] (h : degree f ≠ 0) : Nontrivial (AdjoinRoot f) := Ideal.Quotient.nontrivial (by simp_rw [Ne, span_singleton_eq_top, Polynomial.isUnit_iff, not_exists, not_and] rintro x hx rfl exact h (degree_C hx.ne_zero)) #align adjoin_root.nontrivial AdjoinRoot.nontrivial /-- Ring homomorphism from `R[x]` to `AdjoinRoot f` sending `X` to the `root`. -/ def mk : R[X] →+* AdjoinRoot f := Ideal.Quotient.mk _ #align adjoin_root.mk AdjoinRoot.mk @[elab_as_elim] theorem induction_on {C : AdjoinRoot f → Prop} (x : AdjoinRoot f) (ih : ∀ p : R[X], C (mk f p)) : C x := Quotient.inductionOn' x ih #align adjoin_root.induction_on AdjoinRoot.induction_on /-- Embedding of the original ring `R` into `AdjoinRoot f`. -/ def of : R →+* AdjoinRoot f := (mk f).comp C #align adjoin_root.of AdjoinRoot.of instance instSMulAdjoinRoot [DistribSMul S R] [IsScalarTower S R R] : SMul S (AdjoinRoot f) := Submodule.Quotient.instSMul' _ instance [DistribSMul S R] [IsScalarTower S R R] : DistribSMul S (AdjoinRoot f) := Submodule.Quotient.distribSMul' _ @[simp] theorem smul_mk [DistribSMul S R] [IsScalarTower S R R] (a : S) (x : R[X]) : a • mk f x = mk f (a • x) := rfl #align adjoin_root.smul_mk AdjoinRoot.smul_mk theorem smul_of [DistribSMul S R] [IsScalarTower S R R] (a : S) (x : R) : a • of f x = of f (a • x) := by rw [of, RingHom.comp_apply, RingHom.comp_apply, smul_mk, smul_C] #align adjoin_root.smul_of AdjoinRoot.smul_of instance (R₁ R₂ : Type*) [SMul R₁ R₂] [DistribSMul R₁ R] [DistribSMul R₂ R] [IsScalarTower R₁ R R] [IsScalarTower R₂ R R] [IsScalarTower R₁ R₂ R] (f : R[X]) : IsScalarTower R₁ R₂ (AdjoinRoot f) := Submodule.Quotient.isScalarTower _ _ instance (R₁ R₂ : Type*) [DistribSMul R₁ R] [DistribSMul R₂ R] [IsScalarTower R₁ R R] [IsScalarTower R₂ R R] [SMulCommClass R₁ R₂ R] (f : R[X]) : SMulCommClass R₁ R₂ (AdjoinRoot f) := Submodule.Quotient.smulCommClass _ _ instance isScalarTower_right [DistribSMul S R] [IsScalarTower S R R] : IsScalarTower S (AdjoinRoot f) (AdjoinRoot f) := Ideal.Quotient.isScalarTower_right #align adjoin_root.is_scalar_tower_right AdjoinRoot.isScalarTower_right instance [Monoid S] [DistribMulAction S R] [IsScalarTower S R R] (f : R[X]) : DistribMulAction S (AdjoinRoot f) := Submodule.Quotient.distribMulAction' _ instance [CommSemiring S] [Algebra S R] : Algebra S (AdjoinRoot f) := Ideal.Quotient.algebra S @[simp] theorem algebraMap_eq : algebraMap R (AdjoinRoot f) = of f := rfl #align adjoin_root.algebra_map_eq AdjoinRoot.algebraMap_eq variable (S) theorem algebraMap_eq' [CommSemiring S] [Algebra S R] : algebraMap S (AdjoinRoot f) = (of f).comp (algebraMap S R) := rfl #align adjoin_root.algebra_map_eq' AdjoinRoot.algebraMap_eq' variable {S} theorem finiteType : Algebra.FiniteType R (AdjoinRoot f) := (Algebra.FiniteType.polynomial R).of_surjective _ (Ideal.Quotient.mkₐ_surjective R _) #align adjoin_root.finite_type AdjoinRoot.finiteType theorem finitePresentation : Algebra.FinitePresentation R (AdjoinRoot f) := (Algebra.FinitePresentation.polynomial R).quotient (Submodule.fg_span_singleton f) #align adjoin_root.finite_presentation AdjoinRoot.finitePresentation /-- The adjoined root. -/ def root : AdjoinRoot f := mk f X #align adjoin_root.root AdjoinRoot.root variable {f} instance hasCoeT : CoeTC R (AdjoinRoot f) := ⟨of f⟩ #align adjoin_root.has_coe_t AdjoinRoot.hasCoeT /-- Two `R`-`AlgHom` from `AdjoinRoot f` to the same `R`-algebra are the same iff they agree on `root f`. -/ @[ext] theorem algHom_ext [Semiring S] [Algebra R S] {g₁ g₂ : AdjoinRoot f →ₐ[R] S} (h : g₁ (root f) = g₂ (root f)) : g₁ = g₂ := Ideal.Quotient.algHom_ext R <| Polynomial.algHom_ext h #align adjoin_root.alg_hom_ext AdjoinRoot.algHom_ext @[simp] theorem mk_eq_mk {g h : R[X]} : mk f g = mk f h ↔ f ∣ g - h := Ideal.Quotient.eq.trans Ideal.mem_span_singleton #align adjoin_root.mk_eq_mk AdjoinRoot.mk_eq_mk @[simp] theorem mk_eq_zero {g : R[X]} : mk f g = 0 ↔ f ∣ g := mk_eq_mk.trans <| by rw [sub_zero] #align adjoin_root.mk_eq_zero AdjoinRoot.mk_eq_zero @[simp] theorem mk_self : mk f f = 0 := Quotient.sound' <| QuotientAddGroup.leftRel_apply.mpr (mem_span_singleton.2 <| by simp) #align adjoin_root.mk_self AdjoinRoot.mk_self @[simp] theorem mk_C (x : R) : mk f (C x) = x := rfl set_option linter.uppercaseLean3 false in #align adjoin_root.mk_C AdjoinRoot.mk_C @[simp] theorem mk_X : mk f X = root f := rfl set_option linter.uppercaseLean3 false in #align adjoin_root.mk_X AdjoinRoot.mk_X theorem mk_ne_zero_of_degree_lt (hf : Monic f) {g : R[X]} (h0 : g ≠ 0) (hd : degree g < degree f) : mk f g ≠ 0 := mk_eq_zero.not.2 <| hf.not_dvd_of_degree_lt h0 hd #align adjoin_root.mk_ne_zero_of_degree_lt AdjoinRoot.mk_ne_zero_of_degree_lt theorem mk_ne_zero_of_natDegree_lt (hf : Monic f) {g : R[X]} (h0 : g ≠ 0) (hd : natDegree g < natDegree f) : mk f g ≠ 0 := mk_eq_zero.not.2 <| hf.not_dvd_of_natDegree_lt h0 hd #align adjoin_root.mk_ne_zero_of_nat_degree_lt AdjoinRoot.mk_ne_zero_of_natDegree_lt @[simp] theorem aeval_eq (p : R[X]) : aeval (root f) p = mk f p := Polynomial.induction_on p (fun x => by rw [aeval_C] rfl) (fun p q ihp ihq => by rw [AlgHom.map_add, RingHom.map_add, ihp, ihq]) fun n x _ => by rw [AlgHom.map_mul, aeval_C, AlgHom.map_pow, aeval_X, RingHom.map_mul, mk_C, RingHom.map_pow, mk_X] rfl #align adjoin_root.aeval_eq AdjoinRoot.aeval_eq -- Porting note: the following proof was partly in term-mode, but I was not able to fix it. theorem adjoinRoot_eq_top : Algebra.adjoin R ({root f} : Set (AdjoinRoot f)) = ⊤ := by refine Algebra.eq_top_iff.2 fun x => ?_ induction x using AdjoinRoot.induction_on with | ih p => exact (Algebra.adjoin_singleton_eq_range_aeval R (root f)).symm ▸ ⟨p, aeval_eq p⟩ #align adjoin_root.adjoin_root_eq_top AdjoinRoot.adjoinRoot_eq_top @[simp] theorem eval₂_root (f : R[X]) : f.eval₂ (of f) (root f) = 0 := by rw [← algebraMap_eq, ← aeval_def, aeval_eq, mk_self] #align adjoin_root.eval₂_root AdjoinRoot.eval₂_root theorem isRoot_root (f : R[X]) : IsRoot (f.map (of f)) (root f) := by rw [IsRoot, eval_map, eval₂_root] #align adjoin_root.is_root_root AdjoinRoot.isRoot_root theorem isAlgebraic_root (hf : f ≠ 0) : IsAlgebraic R (root f) := ⟨f, hf, eval₂_root f⟩ #align adjoin_root.is_algebraic_root AdjoinRoot.isAlgebraic_root theorem of.injective_of_degree_ne_zero [IsDomain R] (hf : f.degree ≠ 0) : Function.Injective (AdjoinRoot.of f) := by rw [injective_iff_map_eq_zero] intro p hp rw [AdjoinRoot.of, RingHom.comp_apply, AdjoinRoot.mk_eq_zero] at hp by_cases h : f = 0 · exact C_eq_zero.mp (eq_zero_of_zero_dvd (by rwa [h] at hp)) · contrapose! hf with h_contra rw [← degree_C h_contra] apply le_antisymm (degree_le_of_dvd hp (by rwa [Ne, C_eq_zero])) _ rwa [degree_C h_contra, zero_le_degree_iff] #align adjoin_root.of.injective_of_degree_ne_zero AdjoinRoot.of.injective_of_degree_ne_zero variable [CommRing S] /-- Lift a ring homomorphism `i : R →+* S` to `AdjoinRoot f →+* S`. -/ def lift (i : R →+* S) (x : S) (h : f.eval₂ i x = 0) : AdjoinRoot f →+* S := by apply Ideal.Quotient.lift _ (eval₂RingHom i x) intro g H rcases mem_span_singleton.1 H with ⟨y, hy⟩ rw [hy, RingHom.map_mul, coe_eval₂RingHom, h, zero_mul] #align adjoin_root.lift AdjoinRoot.lift variable {i : R →+* S} {a : S} (h : f.eval₂ i a = 0) @[simp] theorem lift_mk (g : R[X]) : lift i a h (mk f g) = g.eval₂ i a := Ideal.Quotient.lift_mk _ _ _ #align adjoin_root.lift_mk AdjoinRoot.lift_mk @[simp] theorem lift_root : lift i a h (root f) = a := by rw [root, lift_mk, eval₂_X] #align adjoin_root.lift_root AdjoinRoot.lift_root @[simp] theorem lift_of {x : R} : lift i a h x = i x := by rw [← mk_C x, lift_mk, eval₂_C] #align adjoin_root.lift_of AdjoinRoot.lift_of @[simp] theorem lift_comp_of : (lift i a h).comp (of f) = i := RingHom.ext fun _ => @lift_of _ _ _ _ _ _ _ h _ #align adjoin_root.lift_comp_of AdjoinRoot.lift_comp_of variable (f) [Algebra R S] /-- Produce an algebra homomorphism `AdjoinRoot f →ₐ[R] S` sending `root f` to a root of `f` in `S`. -/ def liftHom (x : S) (hfx : aeval x f = 0) : AdjoinRoot f →ₐ[R] S := { lift (algebraMap R S) x hfx with commutes' := fun r => show lift _ _ hfx r = _ from lift_of hfx } #align adjoin_root.lift_hom AdjoinRoot.liftHom @[simp] theorem coe_liftHom (x : S) (hfx : aeval x f = 0) : (liftHom f x hfx : AdjoinRoot f →+* S) = lift (algebraMap R S) x hfx := rfl #align adjoin_root.coe_lift_hom AdjoinRoot.coe_liftHom @[simp]
Mathlib/RingTheory/AdjoinRoot.lean
315
318
theorem aeval_algHom_eq_zero (ϕ : AdjoinRoot f →ₐ[R] S) : aeval (ϕ (root f)) f = 0 := by
have h : ϕ.toRingHom.comp (of f) = algebraMap R S := RingHom.ext_iff.mpr ϕ.commutes rw [aeval_def, ← h, ← RingHom.map_zero ϕ.toRingHom, ← eval₂_root f, hom_eval₂] rfl
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.MeasureTheory.Function.ConditionalExpectation.CondexpL2 #align_import measure_theory.function.conditional_expectation.condexp_L1 from "leanprover-community/mathlib"@"d8bbb04e2d2a44596798a9207ceefc0fb236e41e" /-! # Conditional expectation in L1 This file contains two more steps of the construction of the conditional expectation, which is completed in `MeasureTheory.Function.ConditionalExpectation.Basic`. See that file for a description of the full process. The contitional expectation of an `L²` function is defined in `MeasureTheory.Function.ConditionalExpectation.CondexpL2`. In this file, we perform two steps. * Show that the conditional expectation of the indicator of a measurable set with finite measure is integrable and define a map `Set α → (E →L[ℝ] (α →₁[μ] E))` which to a set associates a linear map. That linear map sends `x ∈ E` to the conditional expectation of the indicator of the set with value `x`. * Extend that map to `condexpL1CLM : (α →₁[μ] E) →L[ℝ] (α →₁[μ] E)`. This is done using the same construction as the Bochner integral (see the file `MeasureTheory/Integral/SetToL1`). ## Main definitions * `condexpL1`: Conditional expectation of a function as a linear map from `L1` to itself. -/ noncomputable section open TopologicalSpace MeasureTheory.Lp Filter ContinuousLinearMap open scoped NNReal ENNReal Topology MeasureTheory namespace MeasureTheory variable {α β F F' G G' 𝕜 : Type*} {p : ℝ≥0∞} [RCLike 𝕜] -- 𝕜 for ℝ or ℂ -- F for a Lp submodule [NormedAddCommGroup F] [NormedSpace 𝕜 F] -- F' for integrals on a Lp submodule [NormedAddCommGroup F'] [NormedSpace 𝕜 F'] [NormedSpace ℝ F'] [CompleteSpace F'] -- G for a Lp add_subgroup [NormedAddCommGroup G] -- G' for integrals on a Lp add_subgroup [NormedAddCommGroup G'] [NormedSpace ℝ G'] [CompleteSpace G'] section CondexpInd /-! ## Conditional expectation of an indicator as a continuous linear map. The goal of this section is to build `condexpInd (hm : m ≤ m0) (μ : Measure α) (s : Set s) : G →L[ℝ] α →₁[μ] G`, which takes `x : G` to the conditional expectation of the indicator of the set `s` with value `x`, seen as an element of `α →₁[μ] G`. -/ variable {m m0 : MeasurableSpace α} {μ : Measure α} {s t : Set α} [NormedSpace ℝ G] section CondexpIndL1Fin set_option linter.uppercaseLean3 false /-- Conditional expectation of the indicator of a measurable set with finite measure, as a function in L1. -/ def condexpIndL1Fin (hm : m ≤ m0) [SigmaFinite (μ.trim hm)] (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : α →₁[μ] G := (integrable_condexpIndSMul hm hs hμs x).toL1 _ #align measure_theory.condexp_ind_L1_fin MeasureTheory.condexpIndL1Fin theorem condexpIndL1Fin_ae_eq_condexpIndSMul (hm : m ≤ m0) [SigmaFinite (μ.trim hm)] (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : condexpIndL1Fin hm hs hμs x =ᵐ[μ] condexpIndSMul hm hs hμs x := (integrable_condexpIndSMul hm hs hμs x).coeFn_toL1 #align measure_theory.condexp_ind_L1_fin_ae_eq_condexp_ind_smul MeasureTheory.condexpIndL1Fin_ae_eq_condexpIndSMul variable {hm : m ≤ m0} [SigmaFinite (μ.trim hm)] -- Porting note: this lemma fills the hole in `refine' (Memℒp.coeFn_toLp _) ...` -- which is not automatically filled in Lean 4 private theorem q {hs : MeasurableSet s} {hμs : μ s ≠ ∞} {x : G} : Memℒp (condexpIndSMul hm hs hμs x) 1 μ := by rw [memℒp_one_iff_integrable]; apply integrable_condexpIndSMul theorem condexpIndL1Fin_add (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x y : G) : condexpIndL1Fin hm hs hμs (x + y) = condexpIndL1Fin hm hs hμs x + condexpIndL1Fin hm hs hμs y := by ext1 refine (Memℒp.coeFn_toLp q).trans ?_ refine EventuallyEq.trans ?_ (Lp.coeFn_add _ _).symm refine EventuallyEq.trans ?_ (EventuallyEq.add (Memℒp.coeFn_toLp q).symm (Memℒp.coeFn_toLp q).symm) rw [condexpIndSMul_add] refine (Lp.coeFn_add _ _).trans (eventually_of_forall fun a => ?_) rfl #align measure_theory.condexp_ind_L1_fin_add MeasureTheory.condexpIndL1Fin_add theorem condexpIndL1Fin_smul (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (c : ℝ) (x : G) : condexpIndL1Fin hm hs hμs (c • x) = c • condexpIndL1Fin hm hs hμs x := by ext1 refine (Memℒp.coeFn_toLp q).trans ?_ refine EventuallyEq.trans ?_ (Lp.coeFn_smul _ _).symm rw [condexpIndSMul_smul hs hμs c x] refine (Lp.coeFn_smul _ _).trans ?_ refine (condexpIndL1Fin_ae_eq_condexpIndSMul hm hs hμs x).mono fun y hy => ?_ simp only [Pi.smul_apply, hy] #align measure_theory.condexp_ind_L1_fin_smul MeasureTheory.condexpIndL1Fin_smul theorem condexpIndL1Fin_smul' [NormedSpace ℝ F] [SMulCommClass ℝ 𝕜 F] (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (c : 𝕜) (x : F) : condexpIndL1Fin hm hs hμs (c • x) = c • condexpIndL1Fin hm hs hμs x := by ext1 refine (Memℒp.coeFn_toLp q).trans ?_ refine EventuallyEq.trans ?_ (Lp.coeFn_smul _ _).symm rw [condexpIndSMul_smul' hs hμs c x] refine (Lp.coeFn_smul _ _).trans ?_ refine (condexpIndL1Fin_ae_eq_condexpIndSMul hm hs hμs x).mono fun y hy => ?_ simp only [Pi.smul_apply, hy] #align measure_theory.condexp_ind_L1_fin_smul' MeasureTheory.condexpIndL1Fin_smul'
Mathlib/MeasureTheory/Function/ConditionalExpectation/CondexpL1.lean
128
143
theorem norm_condexpIndL1Fin_le (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : ‖condexpIndL1Fin hm hs hμs x‖ ≤ (μ s).toReal * ‖x‖ := by
have : 0 ≤ ∫ a : α, ‖condexpIndL1Fin hm hs hμs x a‖ ∂μ := by positivity rw [L1.norm_eq_integral_norm, ← ENNReal.toReal_ofReal (norm_nonneg x), ← ENNReal.toReal_mul, ← ENNReal.toReal_ofReal this, ENNReal.toReal_le_toReal ENNReal.ofReal_ne_top (ENNReal.mul_ne_top hμs ENNReal.ofReal_ne_top), ofReal_integral_norm_eq_lintegral_nnnorm] swap; · rw [← memℒp_one_iff_integrable]; exact Lp.memℒp _ have h_eq : ∫⁻ a, ‖condexpIndL1Fin hm hs hμs x a‖₊ ∂μ = ∫⁻ a, ‖condexpIndSMul hm hs hμs x a‖₊ ∂μ := by refine lintegral_congr_ae ?_ refine (condexpIndL1Fin_ae_eq_condexpIndSMul hm hs hμs x).mono fun z hz => ?_ dsimp only rw [hz] rw [h_eq, ofReal_norm_eq_coe_nnnorm] exact lintegral_nnnorm_condexpIndSMul_le hm hs hμs x
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura -/ import Mathlib.Algebra.BigOperators.Group.Finset #align_import data.nat.gcd.big_operators from "leanprover-community/mathlib"@"008205aa645b3f194c1da47025c5f110c8406eab" /-! # Lemmas about coprimality with big products. These lemmas are kept separate from `Data.Nat.GCD.Basic` in order to minimize imports. -/ namespace Nat variable {ι : Type*} theorem coprime_list_prod_left_iff {l : List ℕ} {k : ℕ} : Coprime l.prod k ↔ ∀ n ∈ l, Coprime n k := by induction l <;> simp [Nat.coprime_mul_iff_left, *]
Mathlib/Data/Nat/GCD/BigOperators.lean
24
26
theorem coprime_list_prod_right_iff {k : ℕ} {l : List ℕ} : Coprime k l.prod ↔ ∀ n ∈ l, Coprime k n := by
simp_rw [coprime_comm (n := k), coprime_list_prod_left_iff]
/- Copyright (c) 2022 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Order.Floor import Mathlib.Algebra.Order.Field.Power import Mathlib.Data.Nat.Log #align_import data.int.log from "leanprover-community/mathlib"@"1f0096e6caa61e9c849ec2adbd227e960e9dff58" /-! # Integer logarithms in a field with respect to a natural base This file defines two `ℤ`-valued analogs of the logarithm of `r : R` with base `b : ℕ`: * `Int.log b r`: Lower logarithm, or floor **log**. Greatest `k` such that `↑b^k ≤ r`. * `Int.clog b r`: Upper logarithm, or **c**eil **log**. Least `k` such that `r ≤ ↑b^k`. Note that `Int.log` gives the position of the left-most non-zero digit: ```lean #eval (Int.log 10 (0.09 : ℚ), Int.log 10 (0.10 : ℚ), Int.log 10 (0.11 : ℚ)) -- (-2, -1, -1) #eval (Int.log 10 (9 : ℚ), Int.log 10 (10 : ℚ), Int.log 10 (11 : ℚ)) -- (0, 1, 1) ``` which means it can be used for computing digit expansions ```lean import Data.Fin.VecNotation import Mathlib.Data.Rat.Floor def digits (b : ℕ) (q : ℚ) (n : ℕ) : ℕ := ⌊q * ((b : ℚ) ^ (n - Int.log b q))⌋₊ % b #eval digits 10 (1/7) ∘ ((↑) : Fin 8 → ℕ) -- ![1, 4, 2, 8, 5, 7, 1, 4] ``` ## Main results * For `Int.log`: * `Int.zpow_log_le_self`, `Int.lt_zpow_succ_log_self`: the bounds formed by `Int.log`, `(b : R) ^ log b r ≤ r < (b : R) ^ (log b r + 1)`. * `Int.zpow_log_gi`: the galois coinsertion between `zpow` and `Int.log`. * For `Int.clog`: * `Int.zpow_pred_clog_lt_self`, `Int.self_le_zpow_clog`: the bounds formed by `Int.clog`, `(b : R) ^ (clog b r - 1) < r ≤ (b : R) ^ clog b r`. * `Int.clog_zpow_gi`: the galois insertion between `Int.clog` and `zpow`. * `Int.neg_log_inv_eq_clog`, `Int.neg_clog_inv_eq_log`: the link between the two definitions. -/ variable {R : Type*} [LinearOrderedSemifield R] [FloorSemiring R] namespace Int /-- The greatest power of `b` such that `b ^ log b r ≤ r`. -/ def log (b : ℕ) (r : R) : ℤ := if 1 ≤ r then Nat.log b ⌊r⌋₊ else -Nat.clog b ⌈r⁻¹⌉₊ #align int.log Int.log theorem log_of_one_le_right (b : ℕ) {r : R} (hr : 1 ≤ r) : log b r = Nat.log b ⌊r⌋₊ := if_pos hr #align int.log_of_one_le_right Int.log_of_one_le_right theorem log_of_right_le_one (b : ℕ) {r : R} (hr : r ≤ 1) : log b r = -Nat.clog b ⌈r⁻¹⌉₊ := by obtain rfl | hr := hr.eq_or_lt · rw [log, if_pos hr, inv_one, Nat.ceil_one, Nat.floor_one, Nat.log_one_right, Nat.clog_one_right, Int.ofNat_zero, neg_zero] · exact if_neg hr.not_le #align int.log_of_right_le_one Int.log_of_right_le_one @[simp, norm_cast] theorem log_natCast (b : ℕ) (n : ℕ) : log b (n : R) = Nat.log b n := by cases n · simp [log_of_right_le_one] · rw [log_of_one_le_right, Nat.floor_natCast] simp #align int.log_nat_cast Int.log_natCast -- See note [no_index around OfNat.ofNat] @[simp] theorem log_ofNat (b : ℕ) (n : ℕ) [n.AtLeastTwo] : log b (no_index (OfNat.ofNat n : R)) = Nat.log b (OfNat.ofNat n) := log_natCast b n theorem log_of_left_le_one {b : ℕ} (hb : b ≤ 1) (r : R) : log b r = 0 := by rcases le_total 1 r with h | h · rw [log_of_one_le_right _ h, Nat.log_of_left_le_one hb, Int.ofNat_zero] · rw [log_of_right_le_one _ h, Nat.clog_of_left_le_one hb, Int.ofNat_zero, neg_zero] #align int.log_of_left_le_one Int.log_of_left_le_one theorem log_of_right_le_zero (b : ℕ) {r : R} (hr : r ≤ 0) : log b r = 0 := by rw [log_of_right_le_one _ (hr.trans zero_le_one), Nat.clog_of_right_le_one ((Nat.ceil_eq_zero.mpr <| inv_nonpos.2 hr).trans_le zero_le_one), Int.ofNat_zero, neg_zero] #align int.log_of_right_le_zero Int.log_of_right_le_zero theorem zpow_log_le_self {b : ℕ} {r : R} (hb : 1 < b) (hr : 0 < r) : (b : R) ^ log b r ≤ r := by rcases le_total 1 r with hr1 | hr1 · rw [log_of_one_le_right _ hr1] rw [zpow_natCast, ← Nat.cast_pow, ← Nat.le_floor_iff hr.le] exact Nat.pow_log_le_self b (Nat.floor_pos.mpr hr1).ne' · rw [log_of_right_le_one _ hr1, zpow_neg, zpow_natCast, ← Nat.cast_pow] exact inv_le_of_inv_le hr (Nat.ceil_le.1 <| Nat.le_pow_clog hb _) #align int.zpow_log_le_self Int.zpow_log_le_self theorem lt_zpow_succ_log_self {b : ℕ} (hb : 1 < b) (r : R) : r < (b : R) ^ (log b r + 1) := by rcases le_or_lt r 0 with hr | hr · rw [log_of_right_le_zero _ hr, zero_add, zpow_one] exact hr.trans_lt (zero_lt_one.trans_le <| mod_cast hb.le) rcases le_or_lt 1 r with hr1 | hr1 · rw [log_of_one_le_right _ hr1] rw [Int.ofNat_add_one_out, zpow_natCast, ← Nat.cast_pow] apply Nat.lt_of_floor_lt exact Nat.lt_pow_succ_log_self hb _ · rw [log_of_right_le_one _ hr1.le] have hcri : 1 < r⁻¹ := one_lt_inv hr hr1 have : 1 ≤ Nat.clog b ⌈r⁻¹⌉₊ := Nat.succ_le_of_lt (Nat.clog_pos hb <| Nat.one_lt_cast.1 <| hcri.trans_le (Nat.le_ceil _)) rw [neg_add_eq_sub, ← neg_sub, ← Int.ofNat_one, ← Int.ofNat_sub this, zpow_neg, zpow_natCast, lt_inv hr (pow_pos (Nat.cast_pos.mpr <| zero_lt_one.trans hb) _), ← Nat.cast_pow] refine Nat.lt_ceil.1 ?_ exact Nat.pow_pred_clog_lt_self hb <| Nat.one_lt_cast.1 <| hcri.trans_le <| Nat.le_ceil _ #align int.lt_zpow_succ_log_self Int.lt_zpow_succ_log_self @[simp] theorem log_zero_right (b : ℕ) : log b (0 : R) = 0 := log_of_right_le_zero b le_rfl #align int.log_zero_right Int.log_zero_right @[simp] theorem log_one_right (b : ℕ) : log b (1 : R) = 0 := by rw [log_of_one_le_right _ le_rfl, Nat.floor_one, Nat.log_one_right, Int.ofNat_zero] #align int.log_one_right Int.log_one_right -- Porting note: needed to replace b ^ z with (b : R) ^ z in the below theorem log_zpow {b : ℕ} (hb : 1 < b) (z : ℤ) : log b ((b : R) ^ z : R) = z := by obtain ⟨n, rfl | rfl⟩ := Int.eq_nat_or_neg z · rw [log_of_one_le_right _ (one_le_zpow_of_nonneg _ <| Int.natCast_nonneg _), zpow_natCast, ← Nat.cast_pow, Nat.floor_natCast, Nat.log_pow hb] exact mod_cast hb.le · rw [log_of_right_le_one _ (zpow_le_one_of_nonpos _ <| neg_nonpos.mpr (Int.natCast_nonneg _)), zpow_neg, inv_inv, zpow_natCast, ← Nat.cast_pow, Nat.ceil_natCast, Nat.clog_pow _ _ hb] exact mod_cast hb.le #align int.log_zpow Int.log_zpow @[mono] theorem log_mono_right {b : ℕ} {r₁ r₂ : R} (h₀ : 0 < r₁) (h : r₁ ≤ r₂) : log b r₁ ≤ log b r₂ := by rcases le_total r₁ 1 with h₁ | h₁ <;> rcases le_total r₂ 1 with h₂ | h₂ · rw [log_of_right_le_one _ h₁, log_of_right_le_one _ h₂, neg_le_neg_iff, Int.ofNat_le] exact Nat.clog_mono_right _ (Nat.ceil_mono <| inv_le_inv_of_le h₀ h) · rw [log_of_right_le_one _ h₁, log_of_one_le_right _ h₂] exact (neg_nonpos.mpr (Int.natCast_nonneg _)).trans (Int.natCast_nonneg _) · obtain rfl := le_antisymm h (h₂.trans h₁) rfl · rw [log_of_one_le_right _ h₁, log_of_one_le_right _ h₂, Int.ofNat_le] exact Nat.log_mono_right (Nat.floor_mono h) #align int.log_mono_right Int.log_mono_right variable (R) /-- Over suitable subtypes, `zpow` and `Int.log` form a galois coinsertion -/ def zpowLogGi {b : ℕ} (hb : 1 < b) : GaloisCoinsertion (fun z : ℤ => Subtype.mk ((b : R) ^ z) <| zpow_pos_of_pos (mod_cast zero_lt_one.trans hb) z) fun r : Set.Ioi (0 : R) => Int.log b (r : R) := GaloisCoinsertion.monotoneIntro (fun r₁ _ => log_mono_right r₁.2) (fun _ _ hz => Subtype.coe_le_coe.mp <| (zpow_strictMono <| mod_cast hb).monotone hz) (fun r => Subtype.coe_le_coe.mp <| zpow_log_le_self hb r.2) fun _ => log_zpow (R := R) hb _ #align int.zpow_log_gi Int.zpowLogGi variable {R} /-- `zpow b` and `Int.log b` (almost) form a Galois connection. -/ theorem lt_zpow_iff_log_lt {b : ℕ} (hb : 1 < b) {x : ℤ} {r : R} (hr : 0 < r) : r < (b : R) ^ x ↔ log b r < x := @GaloisConnection.lt_iff_lt _ _ _ _ _ _ (zpowLogGi R hb).gc x ⟨r, hr⟩ #align int.lt_zpow_iff_log_lt Int.lt_zpow_iff_log_lt /-- `zpow b` and `Int.log b` (almost) form a Galois connection. -/ theorem zpow_le_iff_le_log {b : ℕ} (hb : 1 < b) {x : ℤ} {r : R} (hr : 0 < r) : (b : R) ^ x ≤ r ↔ x ≤ log b r := @GaloisConnection.le_iff_le _ _ _ _ _ _ (zpowLogGi R hb).gc x ⟨r, hr⟩ #align int.zpow_le_iff_le_log Int.zpow_le_iff_le_log /-- The least power of `b` such that `r ≤ b ^ log b r`. -/ def clog (b : ℕ) (r : R) : ℤ := if 1 ≤ r then Nat.clog b ⌈r⌉₊ else -Nat.log b ⌊r⁻¹⌋₊ #align int.clog Int.clog theorem clog_of_one_le_right (b : ℕ) {r : R} (hr : 1 ≤ r) : clog b r = Nat.clog b ⌈r⌉₊ := if_pos hr #align int.clog_of_one_le_right Int.clog_of_one_le_right theorem clog_of_right_le_one (b : ℕ) {r : R} (hr : r ≤ 1) : clog b r = -Nat.log b ⌊r⁻¹⌋₊ := by obtain rfl | hr := hr.eq_or_lt · rw [clog, if_pos hr, inv_one, Nat.ceil_one, Nat.floor_one, Nat.log_one_right, Nat.clog_one_right, Int.ofNat_zero, neg_zero] · exact if_neg hr.not_le #align int.clog_of_right_le_one Int.clog_of_right_le_one theorem clog_of_right_le_zero (b : ℕ) {r : R} (hr : r ≤ 0) : clog b r = 0 := by rw [clog, if_neg (hr.trans_lt zero_lt_one).not_le, neg_eq_zero, Int.natCast_eq_zero, Nat.log_eq_zero_iff] rcases le_or_lt b 1 with hb | hb · exact Or.inr hb · refine Or.inl (lt_of_le_of_lt ?_ hb) exact Nat.floor_le_one_of_le_one ((inv_nonpos.2 hr).trans zero_le_one) #align int.clog_of_right_le_zero Int.clog_of_right_le_zero @[simp] theorem clog_inv (b : ℕ) (r : R) : clog b r⁻¹ = -log b r := by cases' lt_or_le 0 r with hrp hrp · obtain hr | hr := le_total 1 r · rw [clog_of_right_le_one _ (inv_le_one hr), log_of_one_le_right _ hr, inv_inv] · rw [clog_of_one_le_right _ (one_le_inv hrp hr), log_of_right_le_one _ hr, neg_neg] · rw [clog_of_right_le_zero _ (inv_nonpos.mpr hrp), log_of_right_le_zero _ hrp, neg_zero] #align int.clog_inv Int.clog_inv @[simp] theorem log_inv (b : ℕ) (r : R) : log b r⁻¹ = -clog b r := by rw [← inv_inv r, clog_inv, neg_neg, inv_inv] #align int.log_inv Int.log_inv -- note this is useful for writing in reverse theorem neg_log_inv_eq_clog (b : ℕ) (r : R) : -log b r⁻¹ = clog b r := by rw [log_inv, neg_neg] #align int.neg_log_inv_eq_clog Int.neg_log_inv_eq_clog theorem neg_clog_inv_eq_log (b : ℕ) (r : R) : -clog b r⁻¹ = log b r := by rw [clog_inv, neg_neg] #align int.neg_clog_inv_eq_log Int.neg_clog_inv_eq_log @[simp, norm_cast] theorem clog_natCast (b : ℕ) (n : ℕ) : clog b (n : R) = Nat.clog b n := by cases' n with n · simp [clog_of_right_le_one] · rw [clog_of_one_le_right, (Nat.ceil_eq_iff (Nat.succ_ne_zero n)).mpr] <;> simp #align int.clog_nat_cast Int.clog_natCast -- See note [no_index around OfNat.ofNat] @[simp] theorem clog_ofNat (b : ℕ) (n : ℕ) [n.AtLeastTwo] : clog b (no_index (OfNat.ofNat n : R)) = Nat.clog b (OfNat.ofNat n) := clog_natCast b n theorem clog_of_left_le_one {b : ℕ} (hb : b ≤ 1) (r : R) : clog b r = 0 := by rw [← neg_log_inv_eq_clog, log_of_left_le_one hb, neg_zero] #align int.clog_of_left_le_one Int.clog_of_left_le_one
Mathlib/Data/Int/Log.lean
251
257
theorem self_le_zpow_clog {b : ℕ} (hb : 1 < b) (r : R) : r ≤ (b : R) ^ clog b r := by
rcases le_or_lt r 0 with hr | hr · rw [clog_of_right_le_zero _ hr, zpow_zero] exact hr.trans zero_le_one rw [← neg_log_inv_eq_clog, zpow_neg, le_inv hr (zpow_pos_of_pos _ _)] · exact zpow_log_le_self hb (inv_pos.mpr hr) · exact Nat.cast_pos.mpr (zero_le_one.trans_lt hb)
/- 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.Compactness.SigmaCompact import Mathlib.Topology.Connected.TotallyDisconnected import Mathlib.Topology.Inseparable #align_import topology.separation from "leanprover-community/mathlib"@"d91e7f7a7f1c7e9f0e18fdb6bde4f652004c735d" /-! # Separation properties of topological spaces. This file defines the predicate `SeparatedNhds`, and common separation axioms (under the Kolmogorov classification). ## Main definitions * `SeparatedNhds`: Two `Set`s are separated by neighbourhoods if they are contained in disjoint open sets. * `T0Space`: A T₀/Kolmogorov space is a space where, for every two points `x ≠ y`, there is an open set that contains one, but not the other. * `R0Space`: An R₀ space (sometimes called a *symmetric space*) is a topological space such that the `Specializes` relation is symmetric. * `T1Space`: A T₁/Fréchet space is a space where every singleton set is closed. This is equivalent to, for every pair `x ≠ y`, there existing an open set containing `x` but not `y` (`t1Space_iff_exists_open` shows that these conditions are equivalent.) T₁ implies T₀ and R₀. * `R1Space`: An R₁/preregular space is a space where any two topologically distinguishable points have disjoint neighbourhoods. R₁ implies R₀. * `T2Space`: A T₂/Hausdorff space is a space where, for every two points `x ≠ y`, there is two disjoint open sets, one containing `x`, and the other `y`. T₂ implies T₁ and R₁. * `T25Space`: A T₂.₅/Urysohn space is a space where, for every two points `x ≠ y`, there is two open sets, one containing `x`, and the other `y`, whose closures are disjoint. T₂.₅ implies T₂. * `RegularSpace`: A regular space is one where, given any closed `C` and `x ∉ C`, there are disjoint open sets containing `x` and `C` respectively. Such a space is not necessarily Hausdorff. * `T3Space`: A T₃ space is a regular T₀ space. T₃ implies T₂.₅. * `NormalSpace`: A normal space, is one where given two disjoint closed sets, we can find two open sets that separate them. Such a space is not necessarily Hausdorff, even if it is T₀. * `T4Space`: A T₄ space is a normal T₁ space. T₄ implies T₃. * `CompletelyNormalSpace`: A completely normal space is one in which for any two sets `s`, `t` such that if both `closure s` is disjoint with `t`, and `s` is disjoint with `closure t`, then there exist disjoint neighbourhoods of `s` and `t`. `Embedding.completelyNormalSpace` allows us to conclude that this is equivalent to all subspaces being normal. Such a space is not necessarily Hausdorff or regular, even if it is T₀. * `T5Space`: A T₅ space is a completely normal T₁ space. T₅ implies T₄. Note that `mathlib` adopts the modern convention that `m ≤ n` if and only if `T_m → T_n`, but occasionally the literature swaps definitions for e.g. T₃ and regular. ## Main results ### T₀ spaces * `IsClosed.exists_closed_singleton`: Given a closed set `S` in a compact T₀ space, there is some `x ∈ S` such that `{x}` is closed. * `exists_isOpen_singleton_of_isOpen_finite`: Given an open finite set `S` in a T₀ space, there is some `x ∈ S` such that `{x}` is open. ### T₁ spaces * `isClosedMap_const`: The constant map is a closed map. * `discrete_of_t1_of_finite`: A finite T₁ space must have the discrete topology. ### T₂ spaces * `t2_iff_nhds`: A space is T₂ iff the neighbourhoods of distinct points generate the bottom filter. * `t2_iff_isClosed_diagonal`: A space is T₂ iff the `diagonal` of `X` (that is, the set of all points of the form `(a, a) : X × X`) is closed under the product topology. * `separatedNhds_of_finset_finset`: Any two disjoint finsets are `SeparatedNhds`. * Most topological constructions preserve Hausdorffness; these results are part of the typeclass inference system (e.g. `Embedding.t2Space`) * `Set.EqOn.closure`: If two functions are equal on some set `s`, they are equal on its closure. * `IsCompact.isClosed`: All compact sets are closed. * `WeaklyLocallyCompactSpace.locallyCompactSpace`: If a topological space is both weakly locally compact (i.e., each point has a compact neighbourhood) and is T₂, then it is locally compact. * `totallySeparatedSpace_of_t1_of_basis_clopen`: If `X` has a clopen basis, then it is a `TotallySeparatedSpace`. * `loc_compact_t2_tot_disc_iff_tot_sep`: A locally compact T₂ space is totally disconnected iff it is totally separated. * `t2Quotient`: the largest T2 quotient of a given topological space. If the space is also compact: * `normalOfCompactT2`: A compact T₂ space is a `NormalSpace`. * `connectedComponent_eq_iInter_isClopen`: The connected component of a point is the intersection of all its clopen neighbourhoods. * `compact_t2_tot_disc_iff_tot_sep`: Being a `TotallyDisconnectedSpace` is equivalent to being a `TotallySeparatedSpace`. * `ConnectedComponents.t2`: `ConnectedComponents X` is T₂ for `X` T₂ and compact. ### T₃ spaces * `disjoint_nested_nhds`: Given two points `x ≠ y`, we can find neighbourhoods `x ∈ V₁ ⊆ U₁` and `y ∈ V₂ ⊆ U₂`, with the `Vₖ` closed and the `Uₖ` open, such that the `Uₖ` are disjoint. ## References https://en.wikipedia.org/wiki/Separation_axiom -/ open Function Set Filter Topology TopologicalSpace open scoped Classical universe u v variable {X : Type*} {Y : Type*} [TopologicalSpace X] section Separation /-- `SeparatedNhds` is a predicate on pairs of sub`Set`s of a topological space. It holds if the two sub`Set`s are contained in disjoint open sets. -/ def SeparatedNhds : Set X → Set X → Prop := fun s t : Set X => ∃ U V : Set X, IsOpen U ∧ IsOpen V ∧ s ⊆ U ∧ t ⊆ V ∧ Disjoint U V #align separated_nhds SeparatedNhds theorem separatedNhds_iff_disjoint {s t : Set X} : SeparatedNhds s t ↔ Disjoint (𝓝ˢ s) (𝓝ˢ t) := by simp only [(hasBasis_nhdsSet s).disjoint_iff (hasBasis_nhdsSet t), SeparatedNhds, exists_prop, ← exists_and_left, and_assoc, and_comm, and_left_comm] #align separated_nhds_iff_disjoint separatedNhds_iff_disjoint alias ⟨SeparatedNhds.disjoint_nhdsSet, _⟩ := separatedNhds_iff_disjoint namespace SeparatedNhds variable {s s₁ s₂ t t₁ t₂ u : Set X} @[symm] theorem symm : SeparatedNhds s t → SeparatedNhds t s := fun ⟨U, V, oU, oV, aU, bV, UV⟩ => ⟨V, U, oV, oU, bV, aU, Disjoint.symm UV⟩ #align separated_nhds.symm SeparatedNhds.symm theorem comm (s t : Set X) : SeparatedNhds s t ↔ SeparatedNhds t s := ⟨symm, symm⟩ #align separated_nhds.comm SeparatedNhds.comm theorem preimage [TopologicalSpace Y] {f : X → Y} {s t : Set Y} (h : SeparatedNhds s t) (hf : Continuous f) : SeparatedNhds (f ⁻¹' s) (f ⁻¹' t) := let ⟨U, V, oU, oV, sU, tV, UV⟩ := h ⟨f ⁻¹' U, f ⁻¹' V, oU.preimage hf, oV.preimage hf, preimage_mono sU, preimage_mono tV, UV.preimage f⟩ #align separated_nhds.preimage SeparatedNhds.preimage protected theorem disjoint (h : SeparatedNhds s t) : Disjoint s t := let ⟨_, _, _, _, hsU, htV, hd⟩ := h; hd.mono hsU htV #align separated_nhds.disjoint SeparatedNhds.disjoint theorem disjoint_closure_left (h : SeparatedNhds s t) : Disjoint (closure s) t := let ⟨_U, _V, _, hV, hsU, htV, hd⟩ := h (hd.closure_left hV).mono (closure_mono hsU) htV #align separated_nhds.disjoint_closure_left SeparatedNhds.disjoint_closure_left theorem disjoint_closure_right (h : SeparatedNhds s t) : Disjoint s (closure t) := h.symm.disjoint_closure_left.symm #align separated_nhds.disjoint_closure_right SeparatedNhds.disjoint_closure_right @[simp] theorem empty_right (s : Set X) : SeparatedNhds s ∅ := ⟨_, _, isOpen_univ, isOpen_empty, fun a _ => mem_univ a, Subset.rfl, disjoint_empty _⟩ #align separated_nhds.empty_right SeparatedNhds.empty_right @[simp] theorem empty_left (s : Set X) : SeparatedNhds ∅ s := (empty_right _).symm #align separated_nhds.empty_left SeparatedNhds.empty_left theorem mono (h : SeparatedNhds s₂ t₂) (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : SeparatedNhds s₁ t₁ := let ⟨U, V, hU, hV, hsU, htV, hd⟩ := h ⟨U, V, hU, hV, hs.trans hsU, ht.trans htV, hd⟩ #align separated_nhds.mono SeparatedNhds.mono theorem union_left : SeparatedNhds s u → SeparatedNhds t u → SeparatedNhds (s ∪ t) u := by simpa only [separatedNhds_iff_disjoint, nhdsSet_union, disjoint_sup_left] using And.intro #align separated_nhds.union_left SeparatedNhds.union_left theorem union_right (ht : SeparatedNhds s t) (hu : SeparatedNhds s u) : SeparatedNhds s (t ∪ u) := (ht.symm.union_left hu.symm).symm #align separated_nhds.union_right SeparatedNhds.union_right end SeparatedNhds /-- A T₀ space, also known as a Kolmogorov space, is a topological space such that for every pair `x ≠ y`, there is an open set containing one but not the other. We formulate the definition in terms of the `Inseparable` relation. -/ class T0Space (X : Type u) [TopologicalSpace X] : Prop where /-- Two inseparable points in a T₀ space are equal. -/ t0 : ∀ ⦃x y : X⦄, Inseparable x y → x = y #align t0_space T0Space theorem t0Space_iff_inseparable (X : Type u) [TopologicalSpace X] : T0Space X ↔ ∀ x y : X, Inseparable x y → x = y := ⟨fun ⟨h⟩ => h, fun h => ⟨h⟩⟩ #align t0_space_iff_inseparable t0Space_iff_inseparable theorem t0Space_iff_not_inseparable (X : Type u) [TopologicalSpace X] : T0Space X ↔ Pairwise fun x y : X => ¬Inseparable x y := by simp only [t0Space_iff_inseparable, Ne, not_imp_not, Pairwise] #align t0_space_iff_not_inseparable t0Space_iff_not_inseparable theorem Inseparable.eq [T0Space X] {x y : X} (h : Inseparable x y) : x = y := T0Space.t0 h #align inseparable.eq Inseparable.eq /-- A topology `Inducing` map from a T₀ space is injective. -/ protected theorem Inducing.injective [TopologicalSpace Y] [T0Space X] {f : X → Y} (hf : Inducing f) : Injective f := fun _ _ h => (hf.inseparable_iff.1 <| .of_eq h).eq #align inducing.injective Inducing.injective /-- A topology `Inducing` map from a T₀ space is a topological embedding. -/ protected theorem Inducing.embedding [TopologicalSpace Y] [T0Space X] {f : X → Y} (hf : Inducing f) : Embedding f := ⟨hf, hf.injective⟩ #align inducing.embedding Inducing.embedding lemma embedding_iff_inducing [TopologicalSpace Y] [T0Space X] {f : X → Y} : Embedding f ↔ Inducing f := ⟨Embedding.toInducing, Inducing.embedding⟩ #align embedding_iff_inducing embedding_iff_inducing theorem t0Space_iff_nhds_injective (X : Type u) [TopologicalSpace X] : T0Space X ↔ Injective (𝓝 : X → Filter X) := t0Space_iff_inseparable X #align t0_space_iff_nhds_injective t0Space_iff_nhds_injective theorem nhds_injective [T0Space X] : Injective (𝓝 : X → Filter X) := (t0Space_iff_nhds_injective X).1 ‹_› #align nhds_injective nhds_injective theorem inseparable_iff_eq [T0Space X] {x y : X} : Inseparable x y ↔ x = y := nhds_injective.eq_iff #align inseparable_iff_eq inseparable_iff_eq @[simp] theorem nhds_eq_nhds_iff [T0Space X] {a b : X} : 𝓝 a = 𝓝 b ↔ a = b := nhds_injective.eq_iff #align nhds_eq_nhds_iff nhds_eq_nhds_iff @[simp] theorem inseparable_eq_eq [T0Space X] : Inseparable = @Eq X := funext₂ fun _ _ => propext inseparable_iff_eq #align inseparable_eq_eq inseparable_eq_eq theorem TopologicalSpace.IsTopologicalBasis.inseparable_iff {b : Set (Set X)} (hb : IsTopologicalBasis b) {x y : X} : Inseparable x y ↔ ∀ s ∈ b, (x ∈ s ↔ y ∈ s) := ⟨fun h s hs ↦ inseparable_iff_forall_open.1 h _ (hb.isOpen hs), fun h ↦ hb.nhds_hasBasis.eq_of_same_basis <| by convert hb.nhds_hasBasis using 2 exact and_congr_right (h _)⟩ theorem TopologicalSpace.IsTopologicalBasis.eq_iff [T0Space X] {b : Set (Set X)} (hb : IsTopologicalBasis b) {x y : X} : x = y ↔ ∀ s ∈ b, (x ∈ s ↔ y ∈ s) := inseparable_iff_eq.symm.trans hb.inseparable_iff theorem t0Space_iff_exists_isOpen_xor'_mem (X : Type u) [TopologicalSpace X] : T0Space X ↔ Pairwise fun x y => ∃ U : Set X, IsOpen U ∧ Xor' (x ∈ U) (y ∈ U) := by simp only [t0Space_iff_not_inseparable, xor_iff_not_iff, not_forall, exists_prop, inseparable_iff_forall_open, Pairwise] #align t0_space_iff_exists_is_open_xor_mem t0Space_iff_exists_isOpen_xor'_mem theorem exists_isOpen_xor'_mem [T0Space X] {x y : X} (h : x ≠ y) : ∃ U : Set X, IsOpen U ∧ Xor' (x ∈ U) (y ∈ U) := (t0Space_iff_exists_isOpen_xor'_mem X).1 ‹_› h #align exists_is_open_xor_mem exists_isOpen_xor'_mem /-- Specialization forms a partial order on a t0 topological space. -/ def specializationOrder (X) [TopologicalSpace X] [T0Space X] : PartialOrder X := { specializationPreorder X, PartialOrder.lift (OrderDual.toDual ∘ 𝓝) nhds_injective with } #align specialization_order specializationOrder instance SeparationQuotient.instT0Space : T0Space (SeparationQuotient X) := ⟨fun x y => Quotient.inductionOn₂' x y fun _ _ h => SeparationQuotient.mk_eq_mk.2 <| SeparationQuotient.inducing_mk.inseparable_iff.1 h⟩ theorem minimal_nonempty_closed_subsingleton [T0Space X] {s : Set X} (hs : IsClosed s) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsClosed t → t = s) : s.Subsingleton := by clear Y -- Porting note: added refine fun x hx y hy => of_not_not fun hxy => ?_ rcases exists_isOpen_xor'_mem hxy with ⟨U, hUo, hU⟩ wlog h : x ∈ U ∧ y ∉ U · refine this hs hmin y hy x hx (Ne.symm hxy) U hUo hU.symm (hU.resolve_left h) cases' h with hxU hyU have : s \ U = s := hmin (s \ U) diff_subset ⟨y, hy, hyU⟩ (hs.sdiff hUo) exact (this.symm.subset hx).2 hxU #align minimal_nonempty_closed_subsingleton minimal_nonempty_closed_subsingleton theorem minimal_nonempty_closed_eq_singleton [T0Space X] {s : Set X} (hs : IsClosed s) (hne : s.Nonempty) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsClosed t → t = s) : ∃ x, s = {x} := exists_eq_singleton_iff_nonempty_subsingleton.2 ⟨hne, minimal_nonempty_closed_subsingleton hs hmin⟩ #align minimal_nonempty_closed_eq_singleton minimal_nonempty_closed_eq_singleton /-- Given a closed set `S` in a compact T₀ space, there is some `x ∈ S` such that `{x}` is closed. -/ theorem IsClosed.exists_closed_singleton [T0Space X] [CompactSpace X] {S : Set X} (hS : IsClosed S) (hne : S.Nonempty) : ∃ x : X, x ∈ S ∧ IsClosed ({x} : Set X) := by obtain ⟨V, Vsub, Vne, Vcls, hV⟩ := hS.exists_minimal_nonempty_closed_subset hne rcases minimal_nonempty_closed_eq_singleton Vcls Vne hV with ⟨x, rfl⟩ exact ⟨x, Vsub (mem_singleton x), Vcls⟩ #align is_closed.exists_closed_singleton IsClosed.exists_closed_singleton theorem minimal_nonempty_open_subsingleton [T0Space X] {s : Set X} (hs : IsOpen s) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsOpen t → t = s) : s.Subsingleton := by clear Y -- Porting note: added refine fun x hx y hy => of_not_not fun hxy => ?_ rcases exists_isOpen_xor'_mem hxy with ⟨U, hUo, hU⟩ wlog h : x ∈ U ∧ y ∉ U · exact this hs hmin y hy x hx (Ne.symm hxy) U hUo hU.symm (hU.resolve_left h) cases' h with hxU hyU have : s ∩ U = s := hmin (s ∩ U) inter_subset_left ⟨x, hx, hxU⟩ (hs.inter hUo) exact hyU (this.symm.subset hy).2 #align minimal_nonempty_open_subsingleton minimal_nonempty_open_subsingleton theorem minimal_nonempty_open_eq_singleton [T0Space X] {s : Set X} (hs : IsOpen s) (hne : s.Nonempty) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsOpen t → t = s) : ∃ x, s = {x} := exists_eq_singleton_iff_nonempty_subsingleton.2 ⟨hne, minimal_nonempty_open_subsingleton hs hmin⟩ #align minimal_nonempty_open_eq_singleton minimal_nonempty_open_eq_singleton /-- Given an open finite set `S` in a T₀ space, there is some `x ∈ S` such that `{x}` is open. -/ theorem exists_isOpen_singleton_of_isOpen_finite [T0Space X] {s : Set X} (hfin : s.Finite) (hne : s.Nonempty) (ho : IsOpen s) : ∃ x ∈ s, IsOpen ({x} : Set X) := by lift s to Finset X using hfin induction' s using Finset.strongInductionOn with s ihs rcases em (∃ t, t ⊂ s ∧ t.Nonempty ∧ IsOpen (t : Set X)) with (⟨t, hts, htne, hto⟩ | ht) · rcases ihs t hts htne hto with ⟨x, hxt, hxo⟩ exact ⟨x, hts.1 hxt, hxo⟩ · -- Porting note: was `rcases minimal_nonempty_open_eq_singleton ho hne _ with ⟨x, hx⟩` -- https://github.com/leanprover/std4/issues/116 rsuffices ⟨x, hx⟩ : ∃ x, s.toSet = {x} · exact ⟨x, hx.symm ▸ rfl, hx ▸ ho⟩ refine minimal_nonempty_open_eq_singleton ho hne ?_ refine fun t hts htne hto => of_not_not fun hts' => ht ?_ lift t to Finset X using s.finite_toSet.subset hts exact ⟨t, ssubset_iff_subset_ne.2 ⟨hts, mt Finset.coe_inj.2 hts'⟩, htne, hto⟩ #align exists_open_singleton_of_open_finite exists_isOpen_singleton_of_isOpen_finite theorem exists_open_singleton_of_finite [T0Space X] [Finite X] [Nonempty X] : ∃ x : X, IsOpen ({x} : Set X) := let ⟨x, _, h⟩ := exists_isOpen_singleton_of_isOpen_finite (Set.toFinite _) univ_nonempty isOpen_univ ⟨x, h⟩ #align exists_open_singleton_of_fintype exists_open_singleton_of_finite theorem t0Space_of_injective_of_continuous [TopologicalSpace Y] {f : X → Y} (hf : Function.Injective f) (hf' : Continuous f) [T0Space Y] : T0Space X := ⟨fun _ _ h => hf <| (h.map hf').eq⟩ #align t0_space_of_injective_of_continuous t0Space_of_injective_of_continuous protected theorem Embedding.t0Space [TopologicalSpace Y] [T0Space Y] {f : X → Y} (hf : Embedding f) : T0Space X := t0Space_of_injective_of_continuous hf.inj hf.continuous #align embedding.t0_space Embedding.t0Space instance Subtype.t0Space [T0Space X] {p : X → Prop} : T0Space (Subtype p) := embedding_subtype_val.t0Space #align subtype.t0_space Subtype.t0Space theorem t0Space_iff_or_not_mem_closure (X : Type u) [TopologicalSpace X] : T0Space X ↔ Pairwise fun a b : X => a ∉ closure ({b} : Set X) ∨ b ∉ closure ({a} : Set X) := by simp only [t0Space_iff_not_inseparable, inseparable_iff_mem_closure, not_and_or] #align t0_space_iff_or_not_mem_closure t0Space_iff_or_not_mem_closure instance Prod.instT0Space [TopologicalSpace Y] [T0Space X] [T0Space Y] : T0Space (X × Y) := ⟨fun _ _ h => Prod.ext (h.map continuous_fst).eq (h.map continuous_snd).eq⟩ instance Pi.instT0Space {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, T0Space (X i)] : T0Space (∀ i, X i) := ⟨fun _ _ h => funext fun i => (h.map (continuous_apply i)).eq⟩ #align pi.t0_space Pi.instT0Space instance ULift.instT0Space [T0Space X] : T0Space (ULift X) := embedding_uLift_down.t0Space theorem T0Space.of_cover (h : ∀ x y, Inseparable x y → ∃ s : Set X, x ∈ s ∧ y ∈ s ∧ T0Space s) : T0Space X := by refine ⟨fun x y hxy => ?_⟩ rcases h x y hxy with ⟨s, hxs, hys, hs⟩ lift x to s using hxs; lift y to s using hys rw [← subtype_inseparable_iff] at hxy exact congr_arg Subtype.val hxy.eq #align t0_space.of_cover T0Space.of_cover theorem T0Space.of_open_cover (h : ∀ x, ∃ s : Set X, x ∈ s ∧ IsOpen s ∧ T0Space s) : T0Space X := T0Space.of_cover fun x _ hxy => let ⟨s, hxs, hso, hs⟩ := h x ⟨s, hxs, (hxy.mem_open_iff hso).1 hxs, hs⟩ #align t0_space.of_open_cover T0Space.of_open_cover /-- A topological space is called an R₀ space, if `Specializes` relation is symmetric. In other words, given two points `x y : X`, if every neighborhood of `y` contains `x`, then every neighborhood of `x` contains `y`. -/ @[mk_iff] class R0Space (X : Type u) [TopologicalSpace X] : Prop where /-- In an R₀ space, the `Specializes` relation is symmetric. -/ specializes_symmetric : Symmetric (Specializes : X → X → Prop) export R0Space (specializes_symmetric) section R0Space variable [R0Space X] {x y : X} /-- In an R₀ space, the `Specializes` relation is symmetric, dot notation version. -/ theorem Specializes.symm (h : x ⤳ y) : y ⤳ x := specializes_symmetric h #align specializes.symm Specializes.symm /-- In an R₀ space, the `Specializes` relation is symmetric, `Iff` version. -/ theorem specializes_comm : x ⤳ y ↔ y ⤳ x := ⟨Specializes.symm, Specializes.symm⟩ #align specializes_comm specializes_comm /-- In an R₀ space, `Specializes` is equivalent to `Inseparable`. -/ theorem specializes_iff_inseparable : x ⤳ y ↔ Inseparable x y := ⟨fun h ↦ h.antisymm h.symm, Inseparable.specializes⟩ #align specializes_iff_inseparable specializes_iff_inseparable /-- In an R₀ space, `Specializes` implies `Inseparable`. -/ alias ⟨Specializes.inseparable, _⟩ := specializes_iff_inseparable theorem Inducing.r0Space [TopologicalSpace Y] {f : Y → X} (hf : Inducing f) : R0Space Y where specializes_symmetric a b := by simpa only [← hf.specializes_iff] using Specializes.symm instance {p : X → Prop} : R0Space {x // p x} := inducing_subtype_val.r0Space instance [TopologicalSpace Y] [R0Space Y] : R0Space (X × Y) where specializes_symmetric _ _ h := h.fst.symm.prod h.snd.symm instance {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, R0Space (X i)] : R0Space (∀ i, X i) where specializes_symmetric _ _ h := specializes_pi.2 fun i ↦ (specializes_pi.1 h i).symm /-- In an R₀ space, the closure of a singleton is a compact set. -/ theorem isCompact_closure_singleton : IsCompact (closure {x}) := by refine isCompact_of_finite_subcover fun U hUo hxU ↦ ?_ obtain ⟨i, hi⟩ : ∃ i, x ∈ U i := mem_iUnion.1 <| hxU <| subset_closure rfl refine ⟨{i}, fun y hy ↦ ?_⟩ rw [← specializes_iff_mem_closure, specializes_comm] at hy simpa using hy.mem_open (hUo i) hi theorem Filter.coclosedCompact_le_cofinite : coclosedCompact X ≤ cofinite := le_cofinite_iff_compl_singleton_mem.2 fun _ ↦ compl_mem_coclosedCompact.2 isCompact_closure_singleton #align filter.coclosed_compact_le_cofinite Filter.coclosedCompact_le_cofinite variable (X) /-- In an R₀ space, relatively compact sets form a bornology. Its cobounded filter is `Filter.coclosedCompact`. See also `Bornology.inCompact` the bornology of sets contained in a compact set. -/ def Bornology.relativelyCompact : Bornology X where cobounded' := Filter.coclosedCompact X le_cofinite' := Filter.coclosedCompact_le_cofinite #align bornology.relatively_compact Bornology.relativelyCompact variable {X} theorem Bornology.relativelyCompact.isBounded_iff {s : Set X} : @Bornology.IsBounded _ (Bornology.relativelyCompact X) s ↔ IsCompact (closure s) := compl_mem_coclosedCompact #align bornology.relatively_compact.is_bounded_iff Bornology.relativelyCompact.isBounded_iff /-- In an R₀ space, the closure of a finite set is a compact set. -/ theorem Set.Finite.isCompact_closure {s : Set X} (hs : s.Finite) : IsCompact (closure s) := let _ : Bornology X := .relativelyCompact X Bornology.relativelyCompact.isBounded_iff.1 hs.isBounded end R0Space /-- A T₁ space, also known as a Fréchet space, is a topological space where every singleton set is closed. Equivalently, for every pair `x ≠ y`, there is an open set containing `x` and not `y`. -/ class T1Space (X : Type u) [TopologicalSpace X] : Prop where /-- A singleton in a T₁ space is a closed set. -/ t1 : ∀ x, IsClosed ({x} : Set X) #align t1_space T1Space theorem isClosed_singleton [T1Space X] {x : X} : IsClosed ({x} : Set X) := T1Space.t1 x #align is_closed_singleton isClosed_singleton theorem isOpen_compl_singleton [T1Space X] {x : X} : IsOpen ({x}ᶜ : Set X) := isClosed_singleton.isOpen_compl #align is_open_compl_singleton isOpen_compl_singleton theorem isOpen_ne [T1Space X] {x : X} : IsOpen { y | y ≠ x } := isOpen_compl_singleton #align is_open_ne isOpen_ne @[to_additive] theorem Continuous.isOpen_mulSupport [T1Space X] [One X] [TopologicalSpace Y] {f : Y → X} (hf : Continuous f) : IsOpen (mulSupport f) := isOpen_ne.preimage hf #align continuous.is_open_mul_support Continuous.isOpen_mulSupport #align continuous.is_open_support Continuous.isOpen_support theorem Ne.nhdsWithin_compl_singleton [T1Space X] {x y : X} (h : x ≠ y) : 𝓝[{y}ᶜ] x = 𝓝 x := isOpen_ne.nhdsWithin_eq h #align ne.nhds_within_compl_singleton Ne.nhdsWithin_compl_singleton theorem Ne.nhdsWithin_diff_singleton [T1Space X] {x y : X} (h : x ≠ y) (s : Set X) : 𝓝[s \ {y}] x = 𝓝[s] x := by rw [diff_eq, inter_comm, nhdsWithin_inter_of_mem] exact mem_nhdsWithin_of_mem_nhds (isOpen_ne.mem_nhds h) #align ne.nhds_within_diff_singleton Ne.nhdsWithin_diff_singleton lemma nhdsWithin_compl_singleton_le [T1Space X] (x y : X) : 𝓝[{x}ᶜ] x ≤ 𝓝[{y}ᶜ] x := by rcases eq_or_ne x y with rfl|hy · exact Eq.le rfl · rw [Ne.nhdsWithin_compl_singleton hy] exact nhdsWithin_le_nhds theorem isOpen_setOf_eventually_nhdsWithin [T1Space X] {p : X → Prop} : IsOpen { x | ∀ᶠ y in 𝓝[≠] x, p y } := by refine isOpen_iff_mem_nhds.mpr fun a ha => ?_ filter_upwards [eventually_nhds_nhdsWithin.mpr ha] with b hb rcases eq_or_ne a b with rfl | h · exact hb · rw [h.symm.nhdsWithin_compl_singleton] at hb exact hb.filter_mono nhdsWithin_le_nhds #align is_open_set_of_eventually_nhds_within isOpen_setOf_eventually_nhdsWithin protected theorem Set.Finite.isClosed [T1Space X] {s : Set X} (hs : Set.Finite s) : IsClosed s := by rw [← biUnion_of_singleton s] exact hs.isClosed_biUnion fun i _ => isClosed_singleton #align set.finite.is_closed Set.Finite.isClosed theorem TopologicalSpace.IsTopologicalBasis.exists_mem_of_ne [T1Space X] {b : Set (Set X)} (hb : IsTopologicalBasis b) {x y : X} (h : x ≠ y) : ∃ a ∈ b, x ∈ a ∧ y ∉ a := by rcases hb.isOpen_iff.1 isOpen_ne x h with ⟨a, ab, xa, ha⟩ exact ⟨a, ab, xa, fun h => ha h rfl⟩ #align topological_space.is_topological_basis.exists_mem_of_ne TopologicalSpace.IsTopologicalBasis.exists_mem_of_ne protected theorem Finset.isClosed [T1Space X] (s : Finset X) : IsClosed (s : Set X) := s.finite_toSet.isClosed #align finset.is_closed Finset.isClosed theorem t1Space_TFAE (X : Type u) [TopologicalSpace X] : List.TFAE [T1Space X, ∀ x, IsClosed ({ x } : Set X), ∀ x, IsOpen ({ x }ᶜ : Set X), Continuous (@CofiniteTopology.of X), ∀ ⦃x y : X⦄, x ≠ y → {y}ᶜ ∈ 𝓝 x, ∀ ⦃x y : X⦄, x ≠ y → ∃ s ∈ 𝓝 x, y ∉ s, ∀ ⦃x y : X⦄, x ≠ y → ∃ U : Set X, IsOpen U ∧ x ∈ U ∧ y ∉ U, ∀ ⦃x y : X⦄, x ≠ y → Disjoint (𝓝 x) (pure y), ∀ ⦃x y : X⦄, x ≠ y → Disjoint (pure x) (𝓝 y), ∀ ⦃x y : X⦄, x ⤳ y → x = y] := by tfae_have 1 ↔ 2 · exact ⟨fun h => h.1, fun h => ⟨h⟩⟩ tfae_have 2 ↔ 3 · simp only [isOpen_compl_iff] tfae_have 5 ↔ 3 · refine forall_swap.trans ?_ simp only [isOpen_iff_mem_nhds, mem_compl_iff, mem_singleton_iff] tfae_have 5 ↔ 6 · simp only [← subset_compl_singleton_iff, exists_mem_subset_iff] tfae_have 5 ↔ 7 · simp only [(nhds_basis_opens _).mem_iff, subset_compl_singleton_iff, exists_prop, and_assoc, and_left_comm] tfae_have 5 ↔ 8 · simp only [← principal_singleton, disjoint_principal_right] tfae_have 8 ↔ 9 · exact forall_swap.trans (by simp only [disjoint_comm, ne_comm]) tfae_have 1 → 4 · simp only [continuous_def, CofiniteTopology.isOpen_iff'] rintro H s (rfl | hs) exacts [isOpen_empty, compl_compl s ▸ (@Set.Finite.isClosed _ _ H _ hs).isOpen_compl] tfae_have 4 → 2 · exact fun h x => (CofiniteTopology.isClosed_iff.2 <| Or.inr (finite_singleton _)).preimage h tfae_have 2 ↔ 10 · simp only [← closure_subset_iff_isClosed, specializes_iff_mem_closure, subset_def, mem_singleton_iff, eq_comm] tfae_finish #align t1_space_tfae t1Space_TFAE theorem t1Space_iff_continuous_cofinite_of : T1Space X ↔ Continuous (@CofiniteTopology.of X) := (t1Space_TFAE X).out 0 3 #align t1_space_iff_continuous_cofinite_of t1Space_iff_continuous_cofinite_of theorem CofiniteTopology.continuous_of [T1Space X] : Continuous (@CofiniteTopology.of X) := t1Space_iff_continuous_cofinite_of.mp ‹_› #align cofinite_topology.continuous_of CofiniteTopology.continuous_of theorem t1Space_iff_exists_open : T1Space X ↔ Pairwise fun x y => ∃ U : Set X, IsOpen U ∧ x ∈ U ∧ y ∉ U := (t1Space_TFAE X).out 0 6 #align t1_space_iff_exists_open t1Space_iff_exists_open theorem t1Space_iff_disjoint_pure_nhds : T1Space X ↔ ∀ ⦃x y : X⦄, x ≠ y → Disjoint (pure x) (𝓝 y) := (t1Space_TFAE X).out 0 8 #align t1_space_iff_disjoint_pure_nhds t1Space_iff_disjoint_pure_nhds theorem t1Space_iff_disjoint_nhds_pure : T1Space X ↔ ∀ ⦃x y : X⦄, x ≠ y → Disjoint (𝓝 x) (pure y) := (t1Space_TFAE X).out 0 7 #align t1_space_iff_disjoint_nhds_pure t1Space_iff_disjoint_nhds_pure theorem t1Space_iff_specializes_imp_eq : T1Space X ↔ ∀ ⦃x y : X⦄, x ⤳ y → x = y := (t1Space_TFAE X).out 0 9 #align t1_space_iff_specializes_imp_eq t1Space_iff_specializes_imp_eq theorem disjoint_pure_nhds [T1Space X] {x y : X} (h : x ≠ y) : Disjoint (pure x) (𝓝 y) := t1Space_iff_disjoint_pure_nhds.mp ‹_› h #align disjoint_pure_nhds disjoint_pure_nhds theorem disjoint_nhds_pure [T1Space X] {x y : X} (h : x ≠ y) : Disjoint (𝓝 x) (pure y) := t1Space_iff_disjoint_nhds_pure.mp ‹_› h #align disjoint_nhds_pure disjoint_nhds_pure theorem Specializes.eq [T1Space X] {x y : X} (h : x ⤳ y) : x = y := t1Space_iff_specializes_imp_eq.1 ‹_› h #align specializes.eq Specializes.eq theorem specializes_iff_eq [T1Space X] {x y : X} : x ⤳ y ↔ x = y := ⟨Specializes.eq, fun h => h ▸ specializes_rfl⟩ #align specializes_iff_eq specializes_iff_eq @[simp] theorem specializes_eq_eq [T1Space X] : (· ⤳ ·) = @Eq X := funext₂ fun _ _ => propext specializes_iff_eq #align specializes_eq_eq specializes_eq_eq @[simp] theorem pure_le_nhds_iff [T1Space X] {a b : X} : pure a ≤ 𝓝 b ↔ a = b := specializes_iff_pure.symm.trans specializes_iff_eq #align pure_le_nhds_iff pure_le_nhds_iff @[simp] theorem nhds_le_nhds_iff [T1Space X] {a b : X} : 𝓝 a ≤ 𝓝 b ↔ a = b := specializes_iff_eq #align nhds_le_nhds_iff nhds_le_nhds_iff instance (priority := 100) [T1Space X] : R0Space X where specializes_symmetric _ _ := by rw [specializes_iff_eq, specializes_iff_eq]; exact Eq.symm instance : T1Space (CofiniteTopology X) := t1Space_iff_continuous_cofinite_of.mpr continuous_id theorem t1Space_antitone : Antitone (@T1Space X) := fun a _ h _ => @T1Space.mk _ a fun x => (T1Space.t1 x).mono h #align t1_space_antitone t1Space_antitone theorem continuousWithinAt_update_of_ne [T1Space X] [DecidableEq X] [TopologicalSpace Y] {f : X → Y} {s : Set X} {x x' : X} {y : Y} (hne : x' ≠ x) : ContinuousWithinAt (Function.update f x y) s x' ↔ ContinuousWithinAt f s x' := EventuallyEq.congr_continuousWithinAt (mem_nhdsWithin_of_mem_nhds <| mem_of_superset (isOpen_ne.mem_nhds hne) fun _y' hy' => Function.update_noteq hy' _ _) (Function.update_noteq hne _ _) #align continuous_within_at_update_of_ne continuousWithinAt_update_of_ne theorem continuousAt_update_of_ne [T1Space X] [DecidableEq X] [TopologicalSpace Y] {f : X → Y} {x x' : X} {y : Y} (hne : x' ≠ x) : ContinuousAt (Function.update f x y) x' ↔ ContinuousAt f x' := by simp only [← continuousWithinAt_univ, continuousWithinAt_update_of_ne hne] #align continuous_at_update_of_ne continuousAt_update_of_ne theorem continuousOn_update_iff [T1Space X] [DecidableEq X] [TopologicalSpace Y] {f : X → Y} {s : Set X} {x : X} {y : Y} : ContinuousOn (Function.update f x y) s ↔ ContinuousOn f (s \ {x}) ∧ (x ∈ s → Tendsto f (𝓝[s \ {x}] x) (𝓝 y)) := by rw [ContinuousOn, ← and_forall_ne x, and_comm] refine and_congr ⟨fun H z hz => ?_, fun H z hzx hzs => ?_⟩ (forall_congr' fun _ => ?_) · specialize H z hz.2 hz.1 rw [continuousWithinAt_update_of_ne hz.2] at H exact H.mono diff_subset · rw [continuousWithinAt_update_of_ne hzx] refine (H z ⟨hzs, hzx⟩).mono_of_mem (inter_mem_nhdsWithin _ ?_) exact isOpen_ne.mem_nhds hzx · exact continuousWithinAt_update_same #align continuous_on_update_iff continuousOn_update_iff theorem t1Space_of_injective_of_continuous [TopologicalSpace Y] {f : X → Y} (hf : Function.Injective f) (hf' : Continuous f) [T1Space Y] : T1Space X := t1Space_iff_specializes_imp_eq.2 fun _ _ h => hf (h.map hf').eq #align t1_space_of_injective_of_continuous t1Space_of_injective_of_continuous protected theorem Embedding.t1Space [TopologicalSpace Y] [T1Space Y] {f : X → Y} (hf : Embedding f) : T1Space X := t1Space_of_injective_of_continuous hf.inj hf.continuous #align embedding.t1_space Embedding.t1Space instance Subtype.t1Space {X : Type u} [TopologicalSpace X] [T1Space X] {p : X → Prop} : T1Space (Subtype p) := embedding_subtype_val.t1Space #align subtype.t1_space Subtype.t1Space instance [TopologicalSpace Y] [T1Space X] [T1Space Y] : T1Space (X × Y) := ⟨fun ⟨a, b⟩ => @singleton_prod_singleton _ _ a b ▸ isClosed_singleton.prod isClosed_singleton⟩ instance {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, T1Space (X i)] : T1Space (∀ i, X i) := ⟨fun f => univ_pi_singleton f ▸ isClosed_set_pi fun _ _ => isClosed_singleton⟩ instance ULift.instT1Space [T1Space X] : T1Space (ULift X) := embedding_uLift_down.t1Space -- see Note [lower instance priority] instance (priority := 100) TotallyDisconnectedSpace.t1Space [h: TotallyDisconnectedSpace X] : T1Space X := by rw [((t1Space_TFAE X).out 0 1 :)] intro x rw [← totallyDisconnectedSpace_iff_connectedComponent_singleton.mp h x] exact isClosed_connectedComponent -- see Note [lower instance priority] instance (priority := 100) T1Space.t0Space [T1Space X] : T0Space X := ⟨fun _ _ h => h.specializes.eq⟩ #align t1_space.t0_space T1Space.t0Space @[simp] theorem compl_singleton_mem_nhds_iff [T1Space X] {x y : X} : {x}ᶜ ∈ 𝓝 y ↔ y ≠ x := isOpen_compl_singleton.mem_nhds_iff #align compl_singleton_mem_nhds_iff compl_singleton_mem_nhds_iff theorem compl_singleton_mem_nhds [T1Space X] {x y : X} (h : y ≠ x) : {x}ᶜ ∈ 𝓝 y := compl_singleton_mem_nhds_iff.mpr h #align compl_singleton_mem_nhds compl_singleton_mem_nhds @[simp] theorem closure_singleton [T1Space X] {x : X} : closure ({x} : Set X) = {x} := isClosed_singleton.closure_eq #align closure_singleton closure_singleton -- Porting note (#11215): TODO: the proof was `hs.induction_on (by simp) fun x => by simp` theorem Set.Subsingleton.closure [T1Space X] {s : Set X} (hs : s.Subsingleton) : (closure s).Subsingleton := by rcases hs.eq_empty_or_singleton with (rfl | ⟨x, rfl⟩) <;> simp #align set.subsingleton.closure Set.Subsingleton.closure @[simp] theorem subsingleton_closure [T1Space X] {s : Set X} : (closure s).Subsingleton ↔ s.Subsingleton := ⟨fun h => h.anti subset_closure, fun h => h.closure⟩ #align subsingleton_closure subsingleton_closure theorem isClosedMap_const {X Y} [TopologicalSpace X] [TopologicalSpace Y] [T1Space Y] {y : Y} : IsClosedMap (Function.const X y) := IsClosedMap.of_nonempty fun s _ h2s => by simp_rw [const, h2s.image_const, isClosed_singleton] #align is_closed_map_const isClosedMap_const theorem nhdsWithin_insert_of_ne [T1Space X] {x y : X} {s : Set X} (hxy : x ≠ y) : 𝓝[insert y s] x = 𝓝[s] x := by refine le_antisymm (Filter.le_def.2 fun t ht => ?_) (nhdsWithin_mono x <| subset_insert y s) obtain ⟨o, ho, hxo, host⟩ := mem_nhdsWithin.mp ht refine mem_nhdsWithin.mpr ⟨o \ {y}, ho.sdiff isClosed_singleton, ⟨hxo, hxy⟩, ?_⟩ rw [inter_insert_of_not_mem <| not_mem_diff_of_mem (mem_singleton y)] exact (inter_subset_inter diff_subset Subset.rfl).trans host #align nhds_within_insert_of_ne nhdsWithin_insert_of_ne /-- If `t` is a subset of `s`, except for one point, then `insert x s` is a neighborhood of `x` within `t`. -/ theorem insert_mem_nhdsWithin_of_subset_insert [T1Space X] {x y : X} {s t : Set X} (hu : t ⊆ insert y s) : insert x s ∈ 𝓝[t] x := by rcases eq_or_ne x y with (rfl | h) · exact mem_of_superset self_mem_nhdsWithin hu refine nhdsWithin_mono x hu ?_ rw [nhdsWithin_insert_of_ne h] exact mem_of_superset self_mem_nhdsWithin (subset_insert x s) #align insert_mem_nhds_within_of_subset_insert insert_mem_nhdsWithin_of_subset_insert @[simp] theorem ker_nhds [T1Space X] (x : X) : (𝓝 x).ker = {x} := by simp [ker_nhds_eq_specializes] theorem biInter_basis_nhds [T1Space X] {ι : Sort*} {p : ι → Prop} {s : ι → Set X} {x : X} (h : (𝓝 x).HasBasis p s) : ⋂ (i) (_ : p i), s i = {x} := by rw [← h.ker, ker_nhds] #align bInter_basis_nhds biInter_basis_nhds @[simp] theorem compl_singleton_mem_nhdsSet_iff [T1Space X] {x : X} {s : Set X} : {x}ᶜ ∈ 𝓝ˢ s ↔ x ∉ s := by rw [isOpen_compl_singleton.mem_nhdsSet, subset_compl_singleton_iff] #align compl_singleton_mem_nhds_set_iff compl_singleton_mem_nhdsSet_iff @[simp] theorem nhdsSet_le_iff [T1Space X] {s t : Set X} : 𝓝ˢ s ≤ 𝓝ˢ t ↔ s ⊆ t := by refine ⟨?_, fun h => monotone_nhdsSet h⟩ simp_rw [Filter.le_def]; intro h x hx specialize h {x}ᶜ simp_rw [compl_singleton_mem_nhdsSet_iff] at h by_contra hxt exact h hxt hx #align nhds_set_le_iff nhdsSet_le_iff @[simp] theorem nhdsSet_inj_iff [T1Space X] {s t : Set X} : 𝓝ˢ s = 𝓝ˢ t ↔ s = t := by simp_rw [le_antisymm_iff] exact and_congr nhdsSet_le_iff nhdsSet_le_iff #align nhds_set_inj_iff nhdsSet_inj_iff theorem injective_nhdsSet [T1Space X] : Function.Injective (𝓝ˢ : Set X → Filter X) := fun _ _ hst => nhdsSet_inj_iff.mp hst #align injective_nhds_set injective_nhdsSet theorem strictMono_nhdsSet [T1Space X] : StrictMono (𝓝ˢ : Set X → Filter X) := monotone_nhdsSet.strictMono_of_injective injective_nhdsSet #align strict_mono_nhds_set strictMono_nhdsSet @[simp] theorem nhds_le_nhdsSet_iff [T1Space X] {s : Set X} {x : X} : 𝓝 x ≤ 𝓝ˢ s ↔ x ∈ s := by rw [← nhdsSet_singleton, nhdsSet_le_iff, singleton_subset_iff] #align nhds_le_nhds_set_iff nhds_le_nhdsSet_iff /-- Removing a non-isolated point from a dense set, one still obtains a dense set. -/ theorem Dense.diff_singleton [T1Space X] {s : Set X} (hs : Dense s) (x : X) [NeBot (𝓝[≠] x)] : Dense (s \ {x}) := hs.inter_of_isOpen_right (dense_compl_singleton x) isOpen_compl_singleton #align dense.diff_singleton Dense.diff_singleton /-- Removing a finset from a dense set in a space without isolated points, one still obtains a dense set. -/ theorem Dense.diff_finset [T1Space X] [∀ x : X, NeBot (𝓝[≠] x)] {s : Set X} (hs : Dense s) (t : Finset X) : Dense (s \ t) := by induction t using Finset.induction_on with | empty => simpa using hs | insert _ ih => rw [Finset.coe_insert, ← union_singleton, ← diff_diff] exact ih.diff_singleton _ #align dense.diff_finset Dense.diff_finset /-- Removing a finite set from a dense set in a space without isolated points, one still obtains a dense set. -/ theorem Dense.diff_finite [T1Space X] [∀ x : X, NeBot (𝓝[≠] x)] {s : Set X} (hs : Dense s) {t : Set X} (ht : t.Finite) : Dense (s \ t) := by convert hs.diff_finset ht.toFinset exact (Finite.coe_toFinset _).symm #align dense.diff_finite Dense.diff_finite /-- If a function to a `T1Space` tends to some limit `y` at some point `x`, then necessarily `y = f x`. -/ theorem eq_of_tendsto_nhds [TopologicalSpace Y] [T1Space Y] {f : X → Y} {x : X} {y : Y} (h : Tendsto f (𝓝 x) (𝓝 y)) : f x = y := by_contra fun hfa : f x ≠ y => have fact₁ : {f x}ᶜ ∈ 𝓝 y := compl_singleton_mem_nhds hfa.symm have fact₂ : Tendsto f (pure x) (𝓝 y) := h.comp (tendsto_id'.2 <| pure_le_nhds x) fact₂ fact₁ (Eq.refl <| f x) #align eq_of_tendsto_nhds eq_of_tendsto_nhds theorem Filter.Tendsto.eventually_ne [TopologicalSpace Y] [T1Space Y] {g : X → Y} {l : Filter X} {b₁ b₂ : Y} (hg : Tendsto g l (𝓝 b₁)) (hb : b₁ ≠ b₂) : ∀ᶠ z in l, g z ≠ b₂ := hg.eventually (isOpen_compl_singleton.eventually_mem hb) #align filter.tendsto.eventually_ne Filter.Tendsto.eventually_ne theorem ContinuousAt.eventually_ne [TopologicalSpace Y] [T1Space Y] {g : X → Y} {x : X} {y : Y} (hg1 : ContinuousAt g x) (hg2 : g x ≠ y) : ∀ᶠ z in 𝓝 x, g z ≠ y := hg1.tendsto.eventually_ne hg2 #align continuous_at.eventually_ne ContinuousAt.eventually_ne theorem eventually_ne_nhds [T1Space X] {a b : X} (h : a ≠ b) : ∀ᶠ x in 𝓝 a, x ≠ b := IsOpen.eventually_mem isOpen_ne h theorem eventually_ne_nhdsWithin [T1Space X] {a b : X} {s : Set X} (h : a ≠ b) : ∀ᶠ x in 𝓝[s] a, x ≠ b := Filter.Eventually.filter_mono nhdsWithin_le_nhds <| eventually_ne_nhds h /-- To prove a function to a `T1Space` is continuous at some point `x`, it suffices to prove that `f` admits *some* limit at `x`. -/ theorem continuousAt_of_tendsto_nhds [TopologicalSpace Y] [T1Space Y] {f : X → Y} {x : X} {y : Y} (h : Tendsto f (𝓝 x) (𝓝 y)) : ContinuousAt f x := by rwa [ContinuousAt, eq_of_tendsto_nhds h] #align continuous_at_of_tendsto_nhds continuousAt_of_tendsto_nhds @[simp] theorem tendsto_const_nhds_iff [T1Space X] {l : Filter Y} [NeBot l] {c d : X} : Tendsto (fun _ => c) l (𝓝 d) ↔ c = d := by simp_rw [Tendsto, Filter.map_const, pure_le_nhds_iff] #align tendsto_const_nhds_iff tendsto_const_nhds_iff /-- A point with a finite neighborhood has to be isolated. -/ theorem isOpen_singleton_of_finite_mem_nhds [T1Space X] (x : X) {s : Set X} (hs : s ∈ 𝓝 x) (hsf : s.Finite) : IsOpen ({x} : Set X) := by have A : {x} ⊆ s := by simp only [singleton_subset_iff, mem_of_mem_nhds hs] have B : IsClosed (s \ {x}) := (hsf.subset diff_subset).isClosed have C : (s \ {x})ᶜ ∈ 𝓝 x := B.isOpen_compl.mem_nhds fun h => h.2 rfl have D : {x} ∈ 𝓝 x := by simpa only [← diff_eq, diff_diff_cancel_left A] using inter_mem hs C rwa [← mem_interior_iff_mem_nhds, ← singleton_subset_iff, subset_interior_iff_isOpen] at D #align is_open_singleton_of_finite_mem_nhds isOpen_singleton_of_finite_mem_nhds /-- If the punctured neighborhoods of a point form a nontrivial filter, then any neighborhood is infinite. -/ theorem infinite_of_mem_nhds {X} [TopologicalSpace X] [T1Space X] (x : X) [hx : NeBot (𝓝[≠] x)] {s : Set X} (hs : s ∈ 𝓝 x) : Set.Infinite s := by refine fun hsf => hx.1 ?_ rw [← isOpen_singleton_iff_punctured_nhds] exact isOpen_singleton_of_finite_mem_nhds x hs hsf #align infinite_of_mem_nhds infinite_of_mem_nhds theorem discrete_of_t1_of_finite [T1Space X] [Finite X] : DiscreteTopology X := by apply singletons_open_iff_discrete.mp intro x rw [← isClosed_compl_iff] exact (Set.toFinite _).isClosed #align discrete_of_t1_of_finite discrete_of_t1_of_finite theorem PreconnectedSpace.trivial_of_discrete [PreconnectedSpace X] [DiscreteTopology X] : Subsingleton X := by rw [← not_nontrivial_iff_subsingleton] rintro ⟨x, y, hxy⟩ rw [Ne, ← mem_singleton_iff, (isClopen_discrete _).eq_univ <| singleton_nonempty y] at hxy exact hxy (mem_univ x) #align preconnected_space.trivial_of_discrete PreconnectedSpace.trivial_of_discrete theorem IsPreconnected.infinite_of_nontrivial [T1Space X] {s : Set X} (h : IsPreconnected s) (hs : s.Nontrivial) : s.Infinite := by refine mt (fun hf => (subsingleton_coe s).mp ?_) (not_subsingleton_iff.mpr hs) haveI := @discrete_of_t1_of_finite s _ _ hf.to_subtype exact @PreconnectedSpace.trivial_of_discrete _ _ (Subtype.preconnectedSpace h) _ #align is_preconnected.infinite_of_nontrivial IsPreconnected.infinite_of_nontrivial theorem ConnectedSpace.infinite [ConnectedSpace X] [Nontrivial X] [T1Space X] : Infinite X := infinite_univ_iff.mp <| isPreconnected_univ.infinite_of_nontrivial nontrivial_univ #align connected_space.infinite ConnectedSpace.infinite /-- A non-trivial connected T1 space has no isolated points. -/ instance (priority := 100) ConnectedSpace.neBot_nhdsWithin_compl_of_nontrivial_of_t1space [ConnectedSpace X] [Nontrivial X] [T1Space X] (x : X) : NeBot (𝓝[≠] x) := by by_contra contra rw [not_neBot, ← isOpen_singleton_iff_punctured_nhds] at contra replace contra := nonempty_inter isOpen_compl_singleton contra (compl_union_self _) (Set.nonempty_compl_of_nontrivial _) (singleton_nonempty _) simp [compl_inter_self {x}] at contra theorem SeparationQuotient.t1Space_iff : T1Space (SeparationQuotient X) ↔ R0Space X := by rw [r0Space_iff, ((t1Space_TFAE (SeparationQuotient X)).out 0 9 :)] constructor · intro h x y xspecy rw [← Inducing.specializes_iff inducing_mk, h xspecy] at * · rintro h ⟨x⟩ ⟨y⟩ sxspecsy have xspecy : x ⤳ y := (Inducing.specializes_iff inducing_mk).mp sxspecsy have yspecx : y ⤳ x := h xspecy erw [mk_eq_mk, inseparable_iff_specializes_and] exact ⟨xspecy, yspecx⟩ theorem singleton_mem_nhdsWithin_of_mem_discrete {s : Set X} [DiscreteTopology s] {x : X} (hx : x ∈ s) : {x} ∈ 𝓝[s] x := by have : ({⟨x, hx⟩} : Set s) ∈ 𝓝 (⟨x, hx⟩ : s) := by simp [nhds_discrete] simpa only [nhdsWithin_eq_map_subtype_coe hx, image_singleton] using @image_mem_map _ _ _ ((↑) : s → X) _ this #align singleton_mem_nhds_within_of_mem_discrete singleton_mem_nhdsWithin_of_mem_discrete /-- The neighbourhoods filter of `x` within `s`, under the discrete topology, is equal to the pure `x` filter (which is the principal filter at the singleton `{x}`.) -/ theorem nhdsWithin_of_mem_discrete {s : Set X} [DiscreteTopology s] {x : X} (hx : x ∈ s) : 𝓝[s] x = pure x := le_antisymm (le_pure_iff.2 <| singleton_mem_nhdsWithin_of_mem_discrete hx) (pure_le_nhdsWithin hx) #align nhds_within_of_mem_discrete nhdsWithin_of_mem_discrete theorem Filter.HasBasis.exists_inter_eq_singleton_of_mem_discrete {ι : Type*} {p : ι → Prop} {t : ι → Set X} {s : Set X} [DiscreteTopology s] {x : X} (hb : (𝓝 x).HasBasis p t) (hx : x ∈ s) : ∃ i, p i ∧ t i ∩ s = {x} := by rcases (nhdsWithin_hasBasis hb s).mem_iff.1 (singleton_mem_nhdsWithin_of_mem_discrete hx) with ⟨i, hi, hix⟩ exact ⟨i, hi, hix.antisymm <| singleton_subset_iff.2 ⟨mem_of_mem_nhds <| hb.mem_of_mem hi, hx⟩⟩ #align filter.has_basis.exists_inter_eq_singleton_of_mem_discrete Filter.HasBasis.exists_inter_eq_singleton_of_mem_discrete /-- A point `x` in a discrete subset `s` of a topological space admits a neighbourhood that only meets `s` at `x`. -/ theorem nhds_inter_eq_singleton_of_mem_discrete {s : Set X} [DiscreteTopology s] {x : X} (hx : x ∈ s) : ∃ U ∈ 𝓝 x, U ∩ s = {x} := by simpa using (𝓝 x).basis_sets.exists_inter_eq_singleton_of_mem_discrete hx #align nhds_inter_eq_singleton_of_mem_discrete nhds_inter_eq_singleton_of_mem_discrete /-- Let `x` be a point in a discrete subset `s` of a topological space, then there exists an open set that only meets `s` at `x`. -/ theorem isOpen_inter_eq_singleton_of_mem_discrete {s : Set X} [DiscreteTopology s] {x : X} (hx : x ∈ s) : ∃ U : Set X, IsOpen U ∧ U ∩ s = {x} := by obtain ⟨U, hU_nhds, hU_inter⟩ := nhds_inter_eq_singleton_of_mem_discrete hx obtain ⟨t, ht_sub, ht_open, ht_x⟩ := mem_nhds_iff.mp hU_nhds refine ⟨t, ht_open, Set.Subset.antisymm ?_ ?_⟩ · exact hU_inter ▸ Set.inter_subset_inter_left s ht_sub · rw [Set.subset_inter_iff, Set.singleton_subset_iff, Set.singleton_subset_iff] exact ⟨ht_x, hx⟩ /-- For point `x` in a discrete subset `s` of a topological space, there is a set `U` such that 1. `U` is a punctured neighborhood of `x` (ie. `U ∪ {x}` is a neighbourhood of `x`), 2. `U` is disjoint from `s`. -/ theorem disjoint_nhdsWithin_of_mem_discrete {s : Set X} [DiscreteTopology s] {x : X} (hx : x ∈ s) : ∃ U ∈ 𝓝[≠] x, Disjoint U s := let ⟨V, h, h'⟩ := nhds_inter_eq_singleton_of_mem_discrete hx ⟨{x}ᶜ ∩ V, inter_mem_nhdsWithin _ h, disjoint_iff_inter_eq_empty.mpr (by rw [inter_assoc, h', compl_inter_self])⟩ #align disjoint_nhds_within_of_mem_discrete disjoint_nhdsWithin_of_mem_discrete /-- Let `X` be a topological space and let `s, t ⊆ X` be two subsets. If there is an inclusion `t ⊆ s`, then the topological space structure on `t` induced by `X` is the same as the one obtained by the induced topological space structure on `s`. Use `embedding_inclusion` instead. -/ @[deprecated embedding_inclusion (since := "2023-02-02")] theorem TopologicalSpace.subset_trans {s t : Set X} (ts : t ⊆ s) : (instTopologicalSpaceSubtype : TopologicalSpace t) = (instTopologicalSpaceSubtype : TopologicalSpace s).induced (Set.inclusion ts) := (embedding_inclusion ts).induced #align topological_space.subset_trans TopologicalSpace.subset_trans /-! ### R₁ (preregular) spaces -/ section R1Space /-- A topological space is called a *preregular* (a.k.a. R₁) space, if any two topologically distinguishable points have disjoint neighbourhoods. -/ @[mk_iff r1Space_iff_specializes_or_disjoint_nhds] class R1Space (X : Type*) [TopologicalSpace X] : Prop where specializes_or_disjoint_nhds (x y : X) : Specializes x y ∨ Disjoint (𝓝 x) (𝓝 y) export R1Space (specializes_or_disjoint_nhds) variable [R1Space X] {x y : X} instance (priority := 100) : R0Space X where specializes_symmetric _ _ h := (specializes_or_disjoint_nhds _ _).resolve_right <| fun hd ↦ h.not_disjoint hd.symm theorem disjoint_nhds_nhds_iff_not_specializes : Disjoint (𝓝 x) (𝓝 y) ↔ ¬x ⤳ y := ⟨fun hd hspec ↦ hspec.not_disjoint hd, (specializes_or_disjoint_nhds _ _).resolve_left⟩ #align disjoint_nhds_nhds_iff_not_specializes disjoint_nhds_nhds_iff_not_specializes theorem specializes_iff_not_disjoint : x ⤳ y ↔ ¬Disjoint (𝓝 x) (𝓝 y) := disjoint_nhds_nhds_iff_not_specializes.not_left.symm theorem disjoint_nhds_nhds_iff_not_inseparable : Disjoint (𝓝 x) (𝓝 y) ↔ ¬Inseparable x y := by rw [disjoint_nhds_nhds_iff_not_specializes, specializes_iff_inseparable] theorem r1Space_iff_inseparable_or_disjoint_nhds {X : Type*} [TopologicalSpace X]: R1Space X ↔ ∀ x y : X, Inseparable x y ∨ Disjoint (𝓝 x) (𝓝 y) := ⟨fun _h x y ↦ (specializes_or_disjoint_nhds x y).imp_left Specializes.inseparable, fun h ↦ ⟨fun x y ↦ (h x y).imp_left Inseparable.specializes⟩⟩ theorem isClosed_setOf_specializes : IsClosed { p : X × X | p.1 ⤳ p.2 } := by simp only [← isOpen_compl_iff, compl_setOf, ← disjoint_nhds_nhds_iff_not_specializes, isOpen_setOf_disjoint_nhds_nhds] #align is_closed_set_of_specializes isClosed_setOf_specializes theorem isClosed_setOf_inseparable : IsClosed { p : X × X | Inseparable p.1 p.2 } := by simp only [← specializes_iff_inseparable, isClosed_setOf_specializes] #align is_closed_set_of_inseparable isClosed_setOf_inseparable /-- In an R₁ space, a point belongs to the closure of a compact set `K` if and only if it is topologically inseparable from some point of `K`. -/ theorem IsCompact.mem_closure_iff_exists_inseparable {K : Set X} (hK : IsCompact K) : y ∈ closure K ↔ ∃ x ∈ K, Inseparable x y := by refine ⟨fun hy ↦ ?_, fun ⟨x, hxK, hxy⟩ ↦ (hxy.mem_closed_iff isClosed_closure).1 <| subset_closure hxK⟩ contrapose! hy have : Disjoint (𝓝 y) (𝓝ˢ K) := hK.disjoint_nhdsSet_right.2 fun x hx ↦ (disjoint_nhds_nhds_iff_not_inseparable.2 (hy x hx)).symm simpa only [disjoint_iff, not_mem_closure_iff_nhdsWithin_eq_bot] using this.mono_right principal_le_nhdsSet theorem IsCompact.closure_eq_biUnion_inseparable {K : Set X} (hK : IsCompact K) : closure K = ⋃ x ∈ K, {y | Inseparable x y} := by ext; simp [hK.mem_closure_iff_exists_inseparable] /-- In an R₁ space, the closure of a compact set is the union of the closures of its points. -/ theorem IsCompact.closure_eq_biUnion_closure_singleton {K : Set X} (hK : IsCompact K) : closure K = ⋃ x ∈ K, closure {x} := by simp only [hK.closure_eq_biUnion_inseparable, ← specializes_iff_inseparable, specializes_iff_mem_closure, setOf_mem_eq] /-- In an R₁ space, if a compact set `K` is contained in an open set `U`, then its closure is also contained in `U`. -/ theorem IsCompact.closure_subset_of_isOpen {K : Set X} (hK : IsCompact K) {U : Set X} (hU : IsOpen U) (hKU : K ⊆ U) : closure K ⊆ U := by rw [hK.closure_eq_biUnion_inseparable, iUnion₂_subset_iff] exact fun x hx y hxy ↦ (hxy.mem_open_iff hU).1 (hKU hx) /-- The closure of a compact set in an R₁ space is a compact set. -/ protected theorem IsCompact.closure {K : Set X} (hK : IsCompact K) : IsCompact (closure K) := by refine isCompact_of_finite_subcover fun U hUo hKU ↦ ?_ rcases hK.elim_finite_subcover U hUo (subset_closure.trans hKU) with ⟨t, ht⟩ exact ⟨t, hK.closure_subset_of_isOpen (isOpen_biUnion fun _ _ ↦ hUo _) ht⟩ theorem IsCompact.closure_of_subset {s K : Set X} (hK : IsCompact K) (h : s ⊆ K) : IsCompact (closure s) := hK.closure.of_isClosed_subset isClosed_closure (closure_mono h) #align is_compact_closure_of_subset_compact IsCompact.closure_of_subset @[deprecated (since := "2024-01-28")] alias isCompact_closure_of_subset_compact := IsCompact.closure_of_subset @[simp] theorem exists_isCompact_superset_iff {s : Set X} : (∃ K, IsCompact K ∧ s ⊆ K) ↔ IsCompact (closure s) := ⟨fun ⟨_K, hK, hsK⟩ => hK.closure_of_subset hsK, fun h => ⟨closure s, h, subset_closure⟩⟩ #align exists_compact_superset_iff exists_isCompact_superset_iff @[deprecated (since := "2024-01-28")] alias exists_compact_superset_iff := exists_isCompact_superset_iff /-- If `K` and `L` are disjoint compact sets in an R₁ topological space and `L` is also closed, then `K` and `L` have disjoint neighborhoods. -/
Mathlib/Topology/Separation.lean
1,099
1,104
theorem SeparatedNhds.of_isCompact_isCompact_isClosed {K L : Set X} (hK : IsCompact K) (hL : IsCompact L) (h'L : IsClosed L) (hd : Disjoint K L) : SeparatedNhds K L := by
simp_rw [separatedNhds_iff_disjoint, hK.disjoint_nhdsSet_left, hL.disjoint_nhdsSet_right, disjoint_nhds_nhds_iff_not_inseparable] intro x hx y hy h exact absurd ((h.mem_closed_iff h'L).2 hy) <| disjoint_left.1 hd hx
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Computability.PartrecCode import Mathlib.Data.Set.Subsingleton #align_import computability.halting from "leanprover-community/mathlib"@"a50170a88a47570ed186b809ca754110590f9476" /-! # Computability theory and the halting problem A universal partial recursive function, Rice's theorem, and the halting problem. ## References * [Mario Carneiro, *Formalizing computability theory via partial recursive functions*][carneiro2019] -/ open Encodable Denumerable namespace Nat.Partrec open Computable Part theorem merge' {f g} (hf : Nat.Partrec f) (hg : Nat.Partrec g) : ∃ h, Nat.Partrec h ∧ ∀ a, (∀ x ∈ h a, x ∈ f a ∨ x ∈ g a) ∧ ((h a).Dom ↔ (f a).Dom ∨ (g a).Dom) := by obtain ⟨cf, rfl⟩ := Code.exists_code.1 hf obtain ⟨cg, rfl⟩ := Code.exists_code.1 hg have : Nat.Partrec fun n => Nat.rfindOpt fun k => cf.evaln k n <|> cg.evaln k n := Partrec.nat_iff.1 (Partrec.rfindOpt <| Primrec.option_orElse.to_comp.comp (Code.evaln_prim.to_comp.comp <| (snd.pair (const cf)).pair fst) (Code.evaln_prim.to_comp.comp <| (snd.pair (const cg)).pair fst)) refine ⟨_, this, fun n => ?_⟩ have : ∀ x ∈ rfindOpt fun k ↦ HOrElse.hOrElse (Code.evaln k cf n) fun _x ↦ Code.evaln k cg n, x ∈ Code.eval cf n ∨ x ∈ Code.eval cg n := by intro x h obtain ⟨k, e⟩ := Nat.rfindOpt_spec h revert e simp only [Option.mem_def] cases' e' : cf.evaln k n with y <;> simp <;> intro e · exact Or.inr (Code.evaln_sound e) · subst y exact Or.inl (Code.evaln_sound e') refine ⟨this, ⟨fun h => (this _ ⟨h, rfl⟩).imp Exists.fst Exists.fst, ?_⟩⟩ intro h rw [Nat.rfindOpt_dom] simp only [dom_iff_mem, Code.evaln_complete, Option.mem_def] at h obtain ⟨x, k, e⟩ | ⟨x, k, e⟩ := h · refine ⟨k, x, ?_⟩ simp only [e, Option.some_orElse, Option.mem_def] · refine ⟨k, ?_⟩ cases' cf.evaln k n with y · exact ⟨x, by simp only [e, Option.mem_def, Option.none_orElse]⟩ · exact ⟨y, by simp only [Option.some_orElse, Option.mem_def]⟩ #align nat.partrec.merge' Nat.Partrec.merge' end Nat.Partrec namespace Partrec variable {α : Type*} {β : Type*} {γ : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable σ] open Computable Part open Nat.Partrec (Code) open Nat.Partrec.Code theorem merge' {f g : α →. σ} (hf : Partrec f) (hg : Partrec g) : ∃ k : α →. σ, Partrec k ∧ ∀ a, (∀ x ∈ k a, x ∈ f a ∨ x ∈ g a) ∧ ((k a).Dom ↔ (f a).Dom ∨ (g a).Dom) := by let ⟨k, hk, H⟩ := Nat.Partrec.merge' (bind_decode₂_iff.1 hf) (bind_decode₂_iff.1 hg) let k' (a : α) := (k (encode a)).bind fun n => (decode (α := σ) n : Part σ) refine ⟨k', ((nat_iff.2 hk).comp Computable.encode).bind (Computable.decode.ofOption.comp snd).to₂, fun a => ?_⟩ have : ∀ x ∈ k' a, x ∈ f a ∨ x ∈ g a := by intro x h' simp only [k', exists_prop, mem_coe, mem_bind_iff, Option.mem_def] at h' obtain ⟨n, hn, hx⟩ := h' have := (H _).1 _ hn simp [mem_decode₂, encode_injective.eq_iff] at this obtain ⟨a', ha, rfl⟩ | ⟨a', ha, rfl⟩ := this <;> simp only [encodek, Option.some_inj] at hx <;> rw [hx] at ha · exact Or.inl ha · exact Or.inr ha refine ⟨this, ⟨fun h => (this _ ⟨h, rfl⟩).imp Exists.fst Exists.fst, ?_⟩⟩ intro h rw [bind_dom] have hk : (k (encode a)).Dom := (H _).2.2 (by simpa only [encodek₂, bind_some, coe_some] using h) exists hk simp only [exists_prop, mem_map_iff, mem_coe, mem_bind_iff, Option.mem_def] at H obtain ⟨a', _, y, _, e⟩ | ⟨a', _, y, _, e⟩ := (H _).1 _ ⟨hk, rfl⟩ <;> simp only [e.symm, encodek, coe_some, some_dom] #align partrec.merge' Partrec.merge' theorem merge {f g : α →. σ} (hf : Partrec f) (hg : Partrec g) (H : ∀ (a), ∀ x ∈ f a, ∀ y ∈ g a, x = y) : ∃ k : α →. σ, Partrec k ∧ ∀ a x, x ∈ k a ↔ x ∈ f a ∨ x ∈ g a := let ⟨k, hk, K⟩ := merge' hf hg ⟨k, hk, fun a x => ⟨(K _).1 _, fun h => by have : (k a).Dom := (K _).2.2 (h.imp Exists.fst Exists.fst) refine ⟨this, ?_⟩ cases' h with h h <;> cases' (K _).1 _ ⟨this, rfl⟩ with h' h' · exact mem_unique h' h · exact (H _ _ h _ h').symm · exact H _ _ h' _ h · exact mem_unique h' h⟩⟩ #align partrec.merge Partrec.merge theorem cond {c : α → Bool} {f : α →. σ} {g : α →. σ} (hc : Computable c) (hf : Partrec f) (hg : Partrec g) : Partrec fun a => cond (c a) (f a) (g a) := let ⟨cf, ef⟩ := exists_code.1 hf let ⟨cg, eg⟩ := exists_code.1 hg ((eval_part.comp (Computable.cond hc (const cf) (const cg)) Computable.encode).bind ((@Computable.decode σ _).comp snd).ofOption.to₂).of_eq fun a => by cases c a <;> simp [ef, eg, encodek] #align partrec.cond Partrec.cond nonrec theorem sum_casesOn {f : α → Sum β γ} {g : α → β →. σ} {h : α → γ →. σ} (hf : Computable f) (hg : Partrec₂ g) (hh : Partrec₂ h) : @Partrec _ σ _ _ fun a => Sum.casesOn (f a) (g a) (h a) := option_some_iff.1 <| (cond (sum_casesOn hf (const true).to₂ (const false).to₂) (sum_casesOn_left hf (option_some_iff.2 hg).to₂ (const Option.none).to₂) (sum_casesOn_right hf (const Option.none).to₂ (option_some_iff.2 hh).to₂)).of_eq fun a => by cases f a <;> simp only [Bool.cond_true, Bool.cond_false] #align partrec.sum_cases Partrec.sum_casesOn end Partrec /-- A computable predicate is one whose indicator function is computable. -/ def ComputablePred {α} [Primcodable α] (p : α → Prop) := ∃ _ : DecidablePred p, Computable fun a => decide (p a) #align computable_pred ComputablePred /-- A recursively enumerable predicate is one which is the domain of a computable partial function. -/ def RePred {α} [Primcodable α] (p : α → Prop) := Partrec fun a => Part.assert (p a) fun _ => Part.some () #align re_pred RePred theorem RePred.of_eq {α} [Primcodable α] {p q : α → Prop} (hp : RePred p) (H : ∀ a, p a ↔ q a) : RePred q := (funext fun a => propext (H a) : p = q) ▸ hp #align re_pred.of_eq RePred.of_eq theorem Partrec.dom_re {α β} [Primcodable α] [Primcodable β] {f : α →. β} (h : Partrec f) : RePred fun a => (f a).Dom := (h.map (Computable.const ()).to₂).of_eq fun n => Part.ext fun _ => by simp [Part.dom_iff_mem] #align partrec.dom_re Partrec.dom_re theorem ComputablePred.of_eq {α} [Primcodable α] {p q : α → Prop} (hp : ComputablePred p) (H : ∀ a, p a ↔ q a) : ComputablePred q := (funext fun a => propext (H a) : p = q) ▸ hp #align computable_pred.of_eq ComputablePred.of_eq namespace ComputablePred variable {α : Type*} {σ : Type*} variable [Primcodable α] [Primcodable σ] open Nat.Partrec (Code) open Nat.Partrec.Code Computable theorem computable_iff {p : α → Prop} : ComputablePred p ↔ ∃ f : α → Bool, Computable f ∧ p = fun a => (f a : Prop) := ⟨fun ⟨D, h⟩ => ⟨_, h, funext fun a => propext (Bool.decide_iff _).symm⟩, by rintro ⟨f, h, rfl⟩; exact ⟨by infer_instance, by simpa using h⟩⟩ #align computable_pred.computable_iff ComputablePred.computable_iff protected theorem not {p : α → Prop} (hp : ComputablePred p) : ComputablePred fun a => ¬p a := by obtain ⟨f, hf, rfl⟩ := computable_iff.1 hp exact ⟨by infer_instance, (cond hf (const false) (const true)).of_eq fun n => by simp only [Bool.not_eq_true] cases f n <;> rfl⟩ #align computable_pred.not ComputablePred.not theorem to_re {p : α → Prop} (hp : ComputablePred p) : RePred p := by obtain ⟨f, hf, rfl⟩ := computable_iff.1 hp unfold RePred dsimp only [] refine (Partrec.cond hf (Decidable.Partrec.const' (Part.some ())) Partrec.none).of_eq fun n => Part.ext fun a => ?_ cases a; cases f n <;> simp #align computable_pred.to_re ComputablePred.to_re /-- **Rice's Theorem** -/ theorem rice (C : Set (ℕ →. ℕ)) (h : ComputablePred fun c => eval c ∈ C) {f g} (hf : Nat.Partrec f) (hg : Nat.Partrec g) (fC : f ∈ C) : g ∈ C := by cases' h with _ h obtain ⟨c, e⟩ := fixed_point₂ (Partrec.cond (h.comp fst) ((Partrec.nat_iff.2 hg).comp snd).to₂ ((Partrec.nat_iff.2 hf).comp snd).to₂).to₂ simp only [Bool.cond_decide] at e by_cases H : eval c ∈ C · simp only [H, if_true] at e change (fun b => g b) ∈ C rwa [← e] · simp only [H, if_false] at e rw [e] at H contradiction #align computable_pred.rice ComputablePred.rice theorem rice₂ (C : Set Code) (H : ∀ cf cg, eval cf = eval cg → (cf ∈ C ↔ cg ∈ C)) : (ComputablePred fun c => c ∈ C) ↔ C = ∅ ∨ C = Set.univ := by classical exact have hC : ∀ f, f ∈ C ↔ eval f ∈ eval '' C := fun f => ⟨Set.mem_image_of_mem _, fun ⟨g, hg, e⟩ => (H _ _ e).1 hg⟩ ⟨fun h => or_iff_not_imp_left.2 fun C0 => Set.eq_univ_of_forall fun cg => let ⟨cf, fC⟩ := Set.nonempty_iff_ne_empty.2 C0 (hC _).2 <| rice (eval '' C) (h.of_eq hC) (Partrec.nat_iff.1 <| eval_part.comp (const cf) Computable.id) (Partrec.nat_iff.1 <| eval_part.comp (const cg) Computable.id) ((hC _).1 fC), fun h => by { obtain rfl | rfl := h <;> simp [ComputablePred, Set.mem_empty_iff_false] <;> exact ⟨by infer_instance, Computable.const _⟩ }⟩ #align computable_pred.rice₂ ComputablePred.rice₂ /-- The Halting problem is recursively enumerable -/ theorem halting_problem_re (n) : RePred fun c => (eval c n).Dom := (eval_part.comp Computable.id (Computable.const _)).dom_re #align computable_pred.halting_problem_re ComputablePred.halting_problem_re /-- The **Halting problem** is not computable -/ theorem halting_problem (n) : ¬ComputablePred fun c => (eval c n).Dom | h => rice { f | (f n).Dom } h Nat.Partrec.zero Nat.Partrec.none trivial #align computable_pred.halting_problem ComputablePred.halting_problem -- Post's theorem on the equivalence of r.e., co-r.e. sets and -- computable sets. The assumption that p is decidable is required -- unless we assume Markov's principle or LEM. -- @[nolint decidable_classical] theorem computable_iff_re_compl_re {p : α → Prop} [DecidablePred p] : ComputablePred p ↔ RePred p ∧ RePred fun a => ¬p a := ⟨fun h => ⟨h.to_re, h.not.to_re⟩, fun ⟨h₁, h₂⟩ => ⟨‹_›, by obtain ⟨k, pk, hk⟩ := Partrec.merge (h₁.map (Computable.const true).to₂) (h₂.map (Computable.const false).to₂) (by intro a x hx y hy simp only [Part.mem_map_iff, Part.mem_assert_iff, Part.mem_some_iff, exists_prop, and_true, exists_const] at hx hy cases hy.1 hx.1) refine Partrec.of_eq pk fun n => Part.eq_some_iff.2 ?_ rw [hk] simp only [Part.mem_map_iff, Part.mem_assert_iff, Part.mem_some_iff, exists_prop, and_true, true_eq_decide_iff, and_self, exists_const, false_eq_decide_iff] apply Decidable.em⟩⟩ #align computable_pred.computable_iff_re_compl_re ComputablePred.computable_iff_re_compl_re theorem computable_iff_re_compl_re' {p : α → Prop} : ComputablePred p ↔ RePred p ∧ RePred fun a => ¬p a := by classical exact computable_iff_re_compl_re #align computable_pred.computable_iff_re_compl_re' ComputablePred.computable_iff_re_compl_re' theorem halting_problem_not_re (n) : ¬RePred fun c => ¬(eval c n).Dom | h => halting_problem _ <| computable_iff_re_compl_re'.2 ⟨halting_problem_re _, h⟩ #align computable_pred.halting_problem_not_re ComputablePred.halting_problem_not_re end ComputablePred namespace Nat open Vector Part /-- A simplified basis for `Partrec`. -/ inductive Partrec' : ∀ {n}, (Vector ℕ n →. ℕ) → Prop | prim {n f} : @Primrec' n f → @Partrec' n f | comp {m n f} (g : Fin n → Vector ℕ m →. ℕ) : Partrec' f → (∀ i, Partrec' (g i)) → Partrec' fun v => (mOfFn fun i => g i v) >>= f | rfind {n} {f : Vector ℕ (n + 1) → ℕ} : @Partrec' (n + 1) f → Partrec' fun v => rfind fun n => some (f (n ::ᵥ v) = 0) #align nat.partrec' Nat.Partrec' end Nat namespace Nat.Partrec' open Vector Partrec Computable open Nat (Partrec') open Nat.Partrec' theorem to_part {n f} (pf : @Partrec' n f) : _root_.Partrec f := by induction pf with | prim hf => exact hf.to_prim.to_comp | comp _ _ _ hf hg => exact (Partrec.vector_mOfFn hg).bind (hf.comp snd) | rfind _ hf => have := hf.comp (vector_cons.comp snd fst) have := ((Primrec.eq.comp _root_.Primrec.id (_root_.Primrec.const 0)).to_comp.comp this).to₂.partrec₂ exact _root_.Partrec.rfind this #align nat.partrec'.to_part Nat.Partrec'.to_part theorem of_eq {n} {f g : Vector ℕ n →. ℕ} (hf : Partrec' f) (H : ∀ i, f i = g i) : Partrec' g := (funext H : f = g) ▸ hf #align nat.partrec'.of_eq Nat.Partrec'.of_eq theorem of_prim {n} {f : Vector ℕ n → ℕ} (hf : Primrec f) : @Partrec' n f := prim (Nat.Primrec'.of_prim hf) #align nat.partrec'.of_prim Nat.Partrec'.of_prim theorem head {n : ℕ} : @Partrec' n.succ (@head ℕ n) := prim Nat.Primrec'.head #align nat.partrec'.head Nat.Partrec'.head theorem tail {n f} (hf : @Partrec' n f) : @Partrec' n.succ fun v => f v.tail := (hf.comp _ fun i => @prim _ _ <| Nat.Primrec'.get i.succ).of_eq fun v => by simp; rw [← ofFn_get v.tail]; congr; funext i; simp #align nat.partrec'.tail Nat.Partrec'.tail protected theorem bind {n f g} (hf : @Partrec' n f) (hg : @Partrec' (n + 1) g) : @Partrec' n fun v => (f v).bind fun a => g (a ::ᵥ v) := (@comp n (n + 1) g (fun i => Fin.cases f (fun i v => some (v.get i)) i) hg fun i => by refine Fin.cases ?_ (fun i => ?_) i <;> simp [*] exact prim (Nat.Primrec'.get _)).of_eq fun v => by simp [mOfFn, Part.bind_assoc, pure] #align nat.partrec'.bind Nat.Partrec'.bind protected theorem map {n f} {g : Vector ℕ (n + 1) → ℕ} (hf : @Partrec' n f) (hg : @Partrec' (n + 1) g) : @Partrec' n fun v => (f v).map fun a => g (a ::ᵥ v) := by simp [(Part.bind_some_eq_map _ _).symm]; exact hf.bind hg #align nat.partrec'.map Nat.Partrec'.map /-- Analogous to `Nat.Partrec'` for `ℕ`-valued functions, a predicate for partial recursive vector-valued functions. -/ def Vec {n m} (f : Vector ℕ n → Vector ℕ m) := ∀ i, Partrec' fun v => (f v).get i #align nat.partrec'.vec Nat.Partrec'.Vec nonrec theorem Vec.prim {n m f} (hf : @Nat.Primrec'.Vec n m f) : Vec f := fun i => prim <| hf i #align nat.partrec'.vec.prim Nat.Partrec'.Vec.prim protected theorem nil {n} : @Vec n 0 fun _ => nil := fun i => i.elim0 #align nat.partrec'.nil Nat.Partrec'.nil protected theorem cons {n m} {f : Vector ℕ n → ℕ} {g} (hf : @Partrec' n f) (hg : @Vec n m g) : Vec fun v => f v ::ᵥ g v := fun i => Fin.cases (by simpa using hf) (fun i => by simp only [hg i, get_cons_succ]) i #align nat.partrec'.cons Nat.Partrec'.cons theorem idv {n} : @Vec n n id := Vec.prim Nat.Primrec'.idv #align nat.partrec'.idv Nat.Partrec'.idv theorem comp' {n m f g} (hf : @Partrec' m f) (hg : @Vec n m g) : Partrec' fun v => f (g v) := (hf.comp _ hg).of_eq fun v => by simp #align nat.partrec'.comp' Nat.Partrec'.comp'
Mathlib/Computability/Halting.lean
370
372
theorem comp₁ {n} (f : ℕ →. ℕ) {g : Vector ℕ n → ℕ} (hf : @Partrec' 1 fun v => f v.head) (hg : @Partrec' n g) : @Partrec' n fun v => f (g v) := by
simpa using hf.comp' (Partrec'.cons hg Partrec'.nil)
/- Copyright (c) 2023 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Data.Set.Image import Mathlib.Data.List.GetD #align_import data.set.list from "leanprover-community/mathlib"@"2ec920d35348cb2d13ac0e1a2ad9df0fdf1a76b4" /-! # Lemmas about `List`s and `Set.range` In this file we prove lemmas about range of some operations on lists. -/ open List variable {α β : Type*} (l : List α) namespace Set
Mathlib/Data/Set/List.lean
24
30
theorem range_list_map (f : α → β) : range (map f) = { l | ∀ x ∈ l, x ∈ range f } := by
refine antisymm (range_subset_iff.2 fun l => forall_mem_map_iff.2 fun y _ => mem_range_self _) fun l hl => ?_ induction' l with a l ihl; · exact ⟨[], rfl⟩ rcases ihl fun x hx => hl x <| subset_cons _ _ hx with ⟨l, rfl⟩ rcases hl a (mem_cons_self _ _) with ⟨a, rfl⟩ exact ⟨a :: l, map_cons _ _ _⟩
/- Copyright (c) 2022 David Kurniadi Angdinata. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Kurniadi Angdinata -/ import Mathlib.Algebra.Polynomial.Splits #align_import algebra.cubic_discriminant from "leanprover-community/mathlib"@"930133160e24036d5242039fe4972407cd4f1222" /-! # Cubics and discriminants This file defines cubic polynomials over a semiring and their discriminants over a splitting field. ## Main definitions * `Cubic`: the structure representing a cubic polynomial. * `Cubic.disc`: the discriminant of a cubic polynomial. ## Main statements * `Cubic.disc_ne_zero_iff_roots_nodup`: the cubic discriminant is not equal to zero if and only if the cubic has no duplicate roots. ## References * https://en.wikipedia.org/wiki/Cubic_equation * https://en.wikipedia.org/wiki/Discriminant ## Tags cubic, discriminant, polynomial, root -/ noncomputable section /-- The structure representing a cubic polynomial. -/ @[ext] structure Cubic (R : Type*) where (a b c d : R) #align cubic Cubic namespace Cubic open Cubic Polynomial open Polynomial variable {R S F K : Type*} instance [Inhabited R] : Inhabited (Cubic R) := ⟨⟨default, default, default, default⟩⟩ instance [Zero R] : Zero (Cubic R) := ⟨⟨0, 0, 0, 0⟩⟩ section Basic variable {P Q : Cubic R} {a b c d a' b' c' d' : R} [Semiring R] /-- Convert a cubic polynomial to a polynomial. -/ def toPoly (P : Cubic R) : R[X] := C P.a * X ^ 3 + C P.b * X ^ 2 + C P.c * X + C P.d #align cubic.to_poly Cubic.toPoly theorem C_mul_prod_X_sub_C_eq [CommRing S] {w x y z : S} : C w * (X - C x) * (X - C y) * (X - C z) = toPoly ⟨w, w * -(x + y + z), w * (x * y + x * z + y * z), w * -(x * y * z)⟩ := by simp only [toPoly, C_neg, C_add, C_mul] ring1 set_option linter.uppercaseLean3 false in #align cubic.C_mul_prod_X_sub_C_eq Cubic.C_mul_prod_X_sub_C_eq theorem prod_X_sub_C_eq [CommRing S] {x y z : S} : (X - C x) * (X - C y) * (X - C z) = toPoly ⟨1, -(x + y + z), x * y + x * z + y * z, -(x * y * z)⟩ := by rw [← one_mul <| X - C x, ← C_1, C_mul_prod_X_sub_C_eq, one_mul, one_mul, one_mul] set_option linter.uppercaseLean3 false in #align cubic.prod_X_sub_C_eq Cubic.prod_X_sub_C_eq /-! ### Coefficients -/ section Coeff private theorem coeffs : (∀ n > 3, P.toPoly.coeff n = 0) ∧ P.toPoly.coeff 3 = P.a ∧ P.toPoly.coeff 2 = P.b ∧ P.toPoly.coeff 1 = P.c ∧ P.toPoly.coeff 0 = P.d := by simp only [toPoly, coeff_add, coeff_C, coeff_C_mul_X, coeff_C_mul_X_pow] set_option tactic.skipAssignedInstances false in norm_num intro n hn repeat' rw [if_neg] any_goals linarith only [hn] repeat' rw [zero_add] @[simp] theorem coeff_eq_zero {n : ℕ} (hn : 3 < n) : P.toPoly.coeff n = 0 := coeffs.1 n hn #align cubic.coeff_eq_zero Cubic.coeff_eq_zero @[simp] theorem coeff_eq_a : P.toPoly.coeff 3 = P.a := coeffs.2.1 #align cubic.coeff_eq_a Cubic.coeff_eq_a @[simp] theorem coeff_eq_b : P.toPoly.coeff 2 = P.b := coeffs.2.2.1 #align cubic.coeff_eq_b Cubic.coeff_eq_b @[simp] theorem coeff_eq_c : P.toPoly.coeff 1 = P.c := coeffs.2.2.2.1 #align cubic.coeff_eq_c Cubic.coeff_eq_c @[simp] theorem coeff_eq_d : P.toPoly.coeff 0 = P.d := coeffs.2.2.2.2 #align cubic.coeff_eq_d Cubic.coeff_eq_d theorem a_of_eq (h : P.toPoly = Q.toPoly) : P.a = Q.a := by rw [← coeff_eq_a, h, coeff_eq_a] #align cubic.a_of_eq Cubic.a_of_eq
Mathlib/Algebra/CubicDiscriminant.lean
124
124
theorem b_of_eq (h : P.toPoly = Q.toPoly) : P.b = Q.b := by
rw [← coeff_eq_b, h, coeff_eq_b]
/- Copyright (c) 2014 Parikshit Khanna. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro -/ import Batteries.Control.ForInStep.Lemmas import Batteries.Data.List.Basic import Batteries.Tactic.Init import Batteries.Tactic.Alias namespace List open Nat /-! ### mem -/ @[simp] theorem mem_toArray {a : α} {l : List α} : a ∈ l.toArray ↔ a ∈ l := by simp [Array.mem_def] /-! ### drop -/ @[simp] theorem drop_one : ∀ l : List α, drop 1 l = tail l | [] | _ :: _ => rfl /-! ### zipWith -/ theorem zipWith_distrib_tail : (zipWith f l l').tail = zipWith f l.tail l'.tail := by rw [← drop_one]; simp [zipWith_distrib_drop] /-! ### List subset -/ theorem subset_def {l₁ l₂ : List α} : l₁ ⊆ l₂ ↔ ∀ {a : α}, a ∈ l₁ → a ∈ l₂ := .rfl @[simp] theorem nil_subset (l : List α) : [] ⊆ l := nofun @[simp] theorem Subset.refl (l : List α) : l ⊆ l := fun _ i => i theorem Subset.trans {l₁ l₂ l₃ : List α} (h₁ : l₁ ⊆ l₂) (h₂ : l₂ ⊆ l₃) : l₁ ⊆ l₃ := fun _ i => h₂ (h₁ i) instance : Trans (Membership.mem : α → List α → Prop) Subset Membership.mem := ⟨fun h₁ h₂ => h₂ h₁⟩ instance : Trans (Subset : List α → List α → Prop) Subset Subset := ⟨Subset.trans⟩ @[simp] theorem subset_cons (a : α) (l : List α) : l ⊆ a :: l := fun _ => Mem.tail _ theorem subset_of_cons_subset {a : α} {l₁ l₂ : List α} : a :: l₁ ⊆ l₂ → l₁ ⊆ l₂ := fun s _ i => s (mem_cons_of_mem _ i) theorem subset_cons_of_subset (a : α) {l₁ l₂ : List α} : l₁ ⊆ l₂ → l₁ ⊆ a :: l₂ := fun s _ i => .tail _ (s i) theorem cons_subset_cons {l₁ l₂ : List α} (a : α) (s : l₁ ⊆ l₂) : a :: l₁ ⊆ a :: l₂ := fun _ => by simp only [mem_cons]; exact Or.imp_right (@s _) @[simp] theorem subset_append_left (l₁ l₂ : List α) : l₁ ⊆ l₁ ++ l₂ := fun _ => mem_append_left _ @[simp] theorem subset_append_right (l₁ l₂ : List α) : l₂ ⊆ l₁ ++ l₂ := fun _ => mem_append_right _ theorem subset_append_of_subset_left (l₂ : List α) : l ⊆ l₁ → l ⊆ l₁ ++ l₂ := fun s => Subset.trans s <| subset_append_left _ _ theorem subset_append_of_subset_right (l₁ : List α) : l ⊆ l₂ → l ⊆ l₁ ++ l₂ := fun s => Subset.trans s <| subset_append_right _ _ @[simp] theorem cons_subset : a :: l ⊆ m ↔ a ∈ m ∧ l ⊆ m := by simp only [subset_def, mem_cons, or_imp, forall_and, forall_eq] @[simp] theorem append_subset {l₁ l₂ l : List α} : l₁ ++ l₂ ⊆ l ↔ l₁ ⊆ l ∧ l₂ ⊆ l := by simp [subset_def, or_imp, forall_and] theorem subset_nil {l : List α} : l ⊆ [] ↔ l = [] := ⟨fun h => match l with | [] => rfl | _::_ => (nomatch h (.head ..)), fun | rfl => Subset.refl _⟩ theorem map_subset {l₁ l₂ : List α} (f : α → β) (H : l₁ ⊆ l₂) : map f l₁ ⊆ map f l₂ := fun x => by simp only [mem_map]; exact .imp fun a => .imp_left (@H _) /-! ### sublists -/ @[simp] theorem nil_sublist : ∀ l : List α, [] <+ l | [] => .slnil | a :: l => (nil_sublist l).cons a @[simp] theorem Sublist.refl : ∀ l : List α, l <+ l | [] => .slnil | a :: l => (Sublist.refl l).cons₂ a theorem Sublist.trans {l₁ l₂ l₃ : List α} (h₁ : l₁ <+ l₂) (h₂ : l₂ <+ l₃) : l₁ <+ l₃ := by induction h₂ generalizing l₁ with | slnil => exact h₁ | cons _ _ IH => exact (IH h₁).cons _ | @cons₂ l₂ _ a _ IH => generalize e : a :: l₂ = l₂' match e ▸ h₁ with | .slnil => apply nil_sublist | .cons a' h₁' => cases e; apply (IH h₁').cons | .cons₂ a' h₁' => cases e; apply (IH h₁').cons₂ instance : Trans (@Sublist α) Sublist Sublist := ⟨Sublist.trans⟩ @[simp] theorem sublist_cons (a : α) (l : List α) : l <+ a :: l := (Sublist.refl l).cons _ theorem sublist_of_cons_sublist : a :: l₁ <+ l₂ → l₁ <+ l₂ := (sublist_cons a l₁).trans @[simp] theorem sublist_append_left : ∀ l₁ l₂ : List α, l₁ <+ l₁ ++ l₂ | [], _ => nil_sublist _ | _ :: l₁, l₂ => (sublist_append_left l₁ l₂).cons₂ _ @[simp] theorem sublist_append_right : ∀ l₁ l₂ : List α, l₂ <+ l₁ ++ l₂ | [], _ => Sublist.refl _ | _ :: l₁, l₂ => (sublist_append_right l₁ l₂).cons _ theorem sublist_append_of_sublist_left (s : l <+ l₁) : l <+ l₁ ++ l₂ := s.trans <| sublist_append_left .. theorem sublist_append_of_sublist_right (s : l <+ l₂) : l <+ l₁ ++ l₂ := s.trans <| sublist_append_right .. @[simp] theorem cons_sublist_cons : a :: l₁ <+ a :: l₂ ↔ l₁ <+ l₂ := ⟨fun | .cons _ s => sublist_of_cons_sublist s | .cons₂ _ s => s, .cons₂ _⟩ @[simp] theorem append_sublist_append_left : ∀ l, l ++ l₁ <+ l ++ l₂ ↔ l₁ <+ l₂ | [] => Iff.rfl | _ :: l => cons_sublist_cons.trans (append_sublist_append_left l) theorem Sublist.append_left : l₁ <+ l₂ → ∀ l, l ++ l₁ <+ l ++ l₂ := fun h l => (append_sublist_append_left l).mpr h theorem Sublist.append_right : l₁ <+ l₂ → ∀ l, l₁ ++ l <+ l₂ ++ l | .slnil, _ => Sublist.refl _ | .cons _ h, _ => (h.append_right _).cons _ | .cons₂ _ h, _ => (h.append_right _).cons₂ _ theorem sublist_or_mem_of_sublist (h : l <+ l₁ ++ a :: l₂) : l <+ l₁ ++ l₂ ∨ a ∈ l := by induction l₁ generalizing l with | nil => match h with | .cons _ h => exact .inl h | .cons₂ _ h => exact .inr (.head ..) | cons b l₁ IH => match h with | .cons _ h => exact (IH h).imp_left (Sublist.cons _) | .cons₂ _ h => exact (IH h).imp (Sublist.cons₂ _) (.tail _) theorem Sublist.reverse : l₁ <+ l₂ → l₁.reverse <+ l₂.reverse | .slnil => Sublist.refl _ | .cons _ h => by rw [reverse_cons]; exact sublist_append_of_sublist_left h.reverse | .cons₂ _ h => by rw [reverse_cons, reverse_cons]; exact h.reverse.append_right _ @[simp] theorem reverse_sublist : l₁.reverse <+ l₂.reverse ↔ l₁ <+ l₂ := ⟨fun h => l₁.reverse_reverse ▸ l₂.reverse_reverse ▸ h.reverse, Sublist.reverse⟩ @[simp] theorem append_sublist_append_right (l) : l₁ ++ l <+ l₂ ++ l ↔ l₁ <+ l₂ := ⟨fun h => by have := h.reverse simp only [reverse_append, append_sublist_append_left, reverse_sublist] at this exact this, fun h => h.append_right l⟩ theorem Sublist.append (hl : l₁ <+ l₂) (hr : r₁ <+ r₂) : l₁ ++ r₁ <+ l₂ ++ r₂ := (hl.append_right _).trans ((append_sublist_append_left _).2 hr) theorem Sublist.subset : l₁ <+ l₂ → l₁ ⊆ l₂ | .slnil, _, h => h | .cons _ s, _, h => .tail _ (s.subset h) | .cons₂ .., _, .head .. => .head .. | .cons₂ _ s, _, .tail _ h => .tail _ (s.subset h) instance : Trans (@Sublist α) Subset Subset := ⟨fun h₁ h₂ => trans h₁.subset h₂⟩ instance : Trans Subset (@Sublist α) Subset := ⟨fun h₁ h₂ => trans h₁ h₂.subset⟩ instance : Trans (Membership.mem : α → List α → Prop) Sublist Membership.mem := ⟨fun h₁ h₂ => h₂.subset h₁⟩ theorem Sublist.length_le : l₁ <+ l₂ → length l₁ ≤ length l₂ | .slnil => Nat.le_refl 0 | .cons _l s => le_succ_of_le (length_le s) | .cons₂ _ s => succ_le_succ (length_le s) @[simp] theorem sublist_nil {l : List α} : l <+ [] ↔ l = [] := ⟨fun s => subset_nil.1 s.subset, fun H => H ▸ Sublist.refl _⟩ theorem Sublist.eq_of_length : l₁ <+ l₂ → length l₁ = length l₂ → l₁ = l₂ | .slnil, _ => rfl | .cons a s, h => nomatch Nat.not_lt.2 s.length_le (h ▸ lt_succ_self _) | .cons₂ a s, h => by rw [s.eq_of_length (succ.inj h)] theorem Sublist.eq_of_length_le (s : l₁ <+ l₂) (h : length l₂ ≤ length l₁) : l₁ = l₂ := s.eq_of_length <| Nat.le_antisymm s.length_le h @[simp] theorem singleton_sublist {a : α} {l} : [a] <+ l ↔ a ∈ l := by refine ⟨fun h => h.subset (mem_singleton_self _), fun h => ?_⟩ obtain ⟨_, _, rfl⟩ := append_of_mem h exact ((nil_sublist _).cons₂ _).trans (sublist_append_right ..) @[simp] theorem replicate_sublist_replicate {m n} (a : α) : replicate m a <+ replicate n a ↔ m ≤ n := by refine ⟨fun h => ?_, fun h => ?_⟩ · have := h.length_le; simp only [length_replicate] at this ⊢; exact this · induction h with | refl => apply Sublist.refl | step => simp [*, replicate, Sublist.cons] theorem isSublist_iff_sublist [BEq α] [LawfulBEq α] {l₁ l₂ : List α} : l₁.isSublist l₂ ↔ l₁ <+ l₂ := by cases l₁ <;> cases l₂ <;> simp [isSublist] case cons.cons hd₁ tl₁ hd₂ tl₂ => if h_eq : hd₁ = hd₂ then simp [h_eq, cons_sublist_cons, isSublist_iff_sublist] else simp only [beq_iff_eq, h_eq] constructor · intro h_sub apply Sublist.cons exact isSublist_iff_sublist.mp h_sub · intro h_sub cases h_sub case cons h_sub => exact isSublist_iff_sublist.mpr h_sub case cons₂ => contradiction instance [DecidableEq α] (l₁ l₂ : List α) : Decidable (l₁ <+ l₂) := decidable_of_iff (l₁.isSublist l₂) isSublist_iff_sublist /-! ### tail -/ theorem tail_eq_tailD (l) : @tail α l = tailD l [] := by cases l <;> rfl theorem tail_eq_tail? (l) : @tail α l = (tail? l).getD [] := by simp [tail_eq_tailD] /-! ### next? -/ @[simp] theorem next?_nil : @next? α [] = none := rfl @[simp] theorem next?_cons (a l) : @next? α (a :: l) = some (a, l) := rfl /-! ### get? -/ theorem get_eq_iff : List.get l n = x ↔ l.get? n.1 = some x := by simp [get?_eq_some] theorem get?_inj (h₀ : i < xs.length) (h₁ : Nodup xs) (h₂ : xs.get? i = xs.get? j) : i = j := by induction xs generalizing i j with | nil => cases h₀ | cons x xs ih => match i, j with | 0, 0 => rfl | i+1, j+1 => simp; cases h₁ with | cons ha h₁ => exact ih (Nat.lt_of_succ_lt_succ h₀) h₁ h₂ | i+1, 0 => ?_ | 0, j+1 => ?_ all_goals simp at h₂ cases h₁; rename_i h' h have := h x ?_ rfl; cases this rw [mem_iff_get?] exact ⟨_, h₂⟩; exact ⟨_ , h₂.symm⟩ /-! ### drop -/ theorem tail_drop (l : List α) (n : Nat) : (l.drop n).tail = l.drop (n + 1) := by induction l generalizing n with | nil => simp | cons hd tl hl => cases n · simp · simp [hl] /-! ### modifyNth -/ @[simp] theorem modifyNth_nil (f : α → α) (n) : [].modifyNth f n = [] := by cases n <;> rfl @[simp] theorem modifyNth_zero_cons (f : α → α) (a : α) (l : List α) : (a :: l).modifyNth f 0 = f a :: l := rfl @[simp] theorem modifyNth_succ_cons (f : α → α) (a : α) (l : List α) (n) : (a :: l).modifyNth f (n + 1) = a :: l.modifyNth f n := by rfl theorem modifyNthTail_id : ∀ n (l : List α), l.modifyNthTail id n = l | 0, _ => rfl | _+1, [] => rfl | n+1, a :: l => congrArg (cons a) (modifyNthTail_id n l) theorem eraseIdx_eq_modifyNthTail : ∀ n (l : List α), eraseIdx l n = modifyNthTail tail n l | 0, l => by cases l <;> rfl | n+1, [] => rfl | n+1, a :: l => congrArg (cons _) (eraseIdx_eq_modifyNthTail _ _) @[deprecated] alias removeNth_eq_nth_tail := eraseIdx_eq_modifyNthTail theorem get?_modifyNth (f : α → α) : ∀ n (l : List α) m, (modifyNth f n l).get? m = (fun a => if n = m then f a else a) <$> l.get? m | n, l, 0 => by cases l <;> cases n <;> rfl | n, [], _+1 => by cases n <;> rfl | 0, _ :: l, m+1 => by cases h : l.get? m <;> simp [h, modifyNth, m.succ_ne_zero.symm] | n+1, a :: l, m+1 => (get?_modifyNth f n l m).trans <| by cases h' : l.get? m <;> by_cases h : n = m <;> simp [h, if_pos, if_neg, Option.map, mt Nat.succ.inj, not_false_iff, h'] theorem modifyNthTail_length (f : List α → List α) (H : ∀ l, length (f l) = length l) : ∀ n l, length (modifyNthTail f n l) = length l | 0, _ => H _ | _+1, [] => rfl | _+1, _ :: _ => congrArg (·+1) (modifyNthTail_length _ H _ _) theorem modifyNthTail_add (f : List α → List α) (n) (l₁ l₂ : List α) : modifyNthTail f (l₁.length + n) (l₁ ++ l₂) = l₁ ++ modifyNthTail f n l₂ := by induction l₁ <;> simp [*, Nat.succ_add] theorem exists_of_modifyNthTail (f : List α → List α) {n} {l : List α} (h : n ≤ l.length) : ∃ l₁ l₂, l = l₁ ++ l₂ ∧ l₁.length = n ∧ modifyNthTail f n l = l₁ ++ f l₂ := have ⟨_, _, eq, hl⟩ : ∃ l₁ l₂, l = l₁ ++ l₂ ∧ l₁.length = n := ⟨_, _, (take_append_drop n l).symm, length_take_of_le h⟩ ⟨_, _, eq, hl, hl ▸ eq ▸ modifyNthTail_add (n := 0) ..⟩ @[simp] theorem modify_get?_length (f : α → α) : ∀ n l, length (modifyNth f n l) = length l := modifyNthTail_length _ fun l => by cases l <;> rfl @[simp] theorem get?_modifyNth_eq (f : α → α) (n) (l : List α) : (modifyNth f n l).get? n = f <$> l.get? n := by simp only [get?_modifyNth, if_pos] @[simp] theorem get?_modifyNth_ne (f : α → α) {m n} (l : List α) (h : m ≠ n) : (modifyNth f m l).get? n = l.get? n := by simp only [get?_modifyNth, if_neg h, id_map'] theorem exists_of_modifyNth (f : α → α) {n} {l : List α} (h : n < l.length) : ∃ l₁ a l₂, l = l₁ ++ a :: l₂ ∧ l₁.length = n ∧ modifyNth f n l = l₁ ++ f a :: l₂ := match exists_of_modifyNthTail _ (Nat.le_of_lt h) with | ⟨_, _::_, eq, hl, H⟩ => ⟨_, _, _, eq, hl, H⟩ | ⟨_, [], eq, hl, _⟩ => nomatch Nat.ne_of_gt h (eq ▸ append_nil _ ▸ hl) theorem modifyNthTail_eq_take_drop (f : List α → List α) (H : f [] = []) : ∀ n l, modifyNthTail f n l = take n l ++ f (drop n l) | 0, _ => rfl | _ + 1, [] => H.symm | n + 1, b :: l => congrArg (cons b) (modifyNthTail_eq_take_drop f H n l) theorem modifyNth_eq_take_drop (f : α → α) : ∀ n l, modifyNth f n l = take n l ++ modifyHead f (drop n l) := modifyNthTail_eq_take_drop _ rfl theorem modifyNth_eq_take_cons_drop (f : α → α) {n l} (h) : modifyNth f n l = take n l ++ f (get l ⟨n, h⟩) :: drop (n + 1) l := by rw [modifyNth_eq_take_drop, drop_eq_get_cons h]; rfl /-! ### set -/ theorem set_eq_modifyNth (a : α) : ∀ n (l : List α), set l n a = modifyNth (fun _ => a) n l | 0, l => by cases l <;> rfl | n+1, [] => rfl | n+1, b :: l => congrArg (cons _) (set_eq_modifyNth _ _ _) theorem set_eq_take_cons_drop (a : α) {n l} (h : n < length l) : set l n a = take n l ++ a :: drop (n + 1) l := by rw [set_eq_modifyNth, modifyNth_eq_take_cons_drop _ h] theorem modifyNth_eq_set_get? (f : α → α) : ∀ n (l : List α), l.modifyNth f n = ((fun a => l.set n (f a)) <$> l.get? n).getD l | 0, l => by cases l <;> rfl | n+1, [] => rfl | n+1, b :: l => (congrArg (cons _) (modifyNth_eq_set_get? ..)).trans <| by cases h : l.get? n <;> simp [h] theorem modifyNth_eq_set_get (f : α → α) {n} {l : List α} (h) : l.modifyNth f n = l.set n (f (l.get ⟨n, h⟩)) := by rw [modifyNth_eq_set_get?, get?_eq_get h]; rfl theorem exists_of_set {l : List α} (h : n < l.length) : ∃ l₁ a l₂, l = l₁ ++ a :: l₂ ∧ l₁.length = n ∧ l.set n a' = l₁ ++ a' :: l₂ := by rw [set_eq_modifyNth]; exact exists_of_modifyNth _ h theorem exists_of_set' {l : List α} (h : n < l.length) : ∃ l₁ l₂, l = l₁ ++ l.get ⟨n, h⟩ :: l₂ ∧ l₁.length = n ∧ l.set n a' = l₁ ++ a' :: l₂ := have ⟨_, _, _, h₁, h₂, h₃⟩ := exists_of_set h; ⟨_, _, get_of_append h₁ h₂ ▸ h₁, h₂, h₃⟩ @[simp] theorem get?_set_eq (a : α) (n) (l : List α) : (set l n a).get? n = (fun _ => a) <$> l.get? n := by simp only [set_eq_modifyNth, get?_modifyNth_eq] theorem get?_set_eq_of_lt (a : α) {n} {l : List α} (h : n < length l) : (set l n a).get? n = some a := by rw [get?_set_eq, get?_eq_get h]; rfl @[simp] theorem get?_set_ne (a : α) {m n} (l : List α) (h : m ≠ n) : (set l m a).get? n = l.get? n := by simp only [set_eq_modifyNth, get?_modifyNth_ne _ _ h] theorem get?_set (a : α) {m n} (l : List α) : (set l m a).get? n = if m = n then (fun _ => a) <$> l.get? n else l.get? n := by by_cases m = n <;> simp [*, get?_set_eq, get?_set_ne] theorem get?_set_of_lt (a : α) {m n} (l : List α) (h : n < length l) : (set l m a).get? n = if m = n then some a else l.get? n := by simp [get?_set, get?_eq_get h] theorem get?_set_of_lt' (a : α) {m n} (l : List α) (h : m < length l) : (set l m a).get? n = if m = n then some a else l.get? n := by simp [get?_set]; split <;> subst_vars <;> simp [*, get?_eq_get h] theorem drop_set_of_lt (a : α) {n m : Nat} (l : List α) (h : n < m) : (l.set n a).drop m = l.drop m := List.ext fun i => by rw [get?_drop, get?_drop, get?_set_ne _ _ (by omega)] theorem take_set_of_lt (a : α) {n m : Nat} (l : List α) (h : m < n) : (l.set n a).take m = l.take m := List.ext fun i => by rw [get?_take_eq_if, get?_take_eq_if] split · next h' => rw [get?_set_ne _ _ (by omega)] · rfl /-! ### removeNth -/ theorem length_eraseIdx : ∀ {l i}, i < length l → length (@eraseIdx α l i) = length l - 1 | [], _, _ => rfl | _::_, 0, _ => by simp [eraseIdx] | x::xs, i+1, h => by have : i < length xs := Nat.lt_of_succ_lt_succ h simp [eraseIdx, ← Nat.add_one] rw [length_eraseIdx this, Nat.sub_add_cancel (Nat.lt_of_le_of_lt (Nat.zero_le _) this)] @[deprecated] alias length_removeNth := length_eraseIdx /-! ### tail -/ @[simp] theorem length_tail (l : List α) : length (tail l) = length l - 1 := by cases l <;> rfl /-! ### eraseP -/ @[simp] theorem eraseP_nil : [].eraseP p = [] := rfl theorem eraseP_cons (a : α) (l : List α) : (a :: l).eraseP p = bif p a then l else a :: l.eraseP p := rfl @[simp] theorem eraseP_cons_of_pos {l : List α} (p) (h : p a) : (a :: l).eraseP p = l := by simp [eraseP_cons, h] @[simp] theorem eraseP_cons_of_neg {l : List α} (p) (h : ¬p a) : (a :: l).eraseP p = a :: l.eraseP p := by simp [eraseP_cons, h] theorem eraseP_of_forall_not {l : List α} (h : ∀ a, a ∈ l → ¬p a) : l.eraseP p = l := by induction l with | nil => rfl | cons _ _ ih => simp [h _ (.head ..), ih (forall_mem_cons.1 h).2] theorem exists_of_eraseP : ∀ {l : List α} {a} (al : a ∈ l) (pa : p a), ∃ a l₁ l₂, (∀ b ∈ l₁, ¬p b) ∧ p a ∧ l = l₁ ++ a :: l₂ ∧ l.eraseP p = l₁ ++ l₂ | b :: l, a, al, pa => if pb : p b then ⟨b, [], l, forall_mem_nil _, pb, by simp [pb]⟩ else match al with | .head .. => nomatch pb pa | .tail _ al => let ⟨c, l₁, l₂, h₁, h₂, h₃, h₄⟩ := exists_of_eraseP al pa ⟨c, b::l₁, l₂, (forall_mem_cons ..).2 ⟨pb, h₁⟩, h₂, by rw [h₃, cons_append], by simp [pb, h₄]⟩ theorem exists_or_eq_self_of_eraseP (p) (l : List α) : l.eraseP p = l ∨ ∃ a l₁ l₂, (∀ b ∈ l₁, ¬p b) ∧ p a ∧ l = l₁ ++ a :: l₂ ∧ l.eraseP p = l₁ ++ l₂ := if h : ∃ a ∈ l, p a then let ⟨_, ha, pa⟩ := h .inr (exists_of_eraseP ha pa) else .inl (eraseP_of_forall_not (h ⟨·, ·, ·⟩)) @[simp] theorem length_eraseP_of_mem (al : a ∈ l) (pa : p a) : length (l.eraseP p) = Nat.pred (length l) := by let ⟨_, l₁, l₂, _, _, e₁, e₂⟩ := exists_of_eraseP al pa rw [e₂]; simp [length_append, e₁]; rfl theorem eraseP_append_left {a : α} (pa : p a) : ∀ {l₁ : List α} l₂, a ∈ l₁ → (l₁++l₂).eraseP p = l₁.eraseP p ++ l₂ | x :: xs, l₂, h => by by_cases h' : p x <;> simp [h'] rw [eraseP_append_left pa l₂ ((mem_cons.1 h).resolve_left (mt _ h'))] intro | rfl => exact pa theorem eraseP_append_right : ∀ {l₁ : List α} l₂, (∀ b ∈ l₁, ¬p b) → eraseP p (l₁++l₂) = l₁ ++ l₂.eraseP p | [], l₂, _ => rfl | x :: xs, l₂, h => by simp [(forall_mem_cons.1 h).1, eraseP_append_right _ (forall_mem_cons.1 h).2] theorem eraseP_sublist (l : List α) : l.eraseP p <+ l := by match exists_or_eq_self_of_eraseP p l with | .inl h => rw [h]; apply Sublist.refl | .inr ⟨c, l₁, l₂, _, _, h₃, h₄⟩ => rw [h₄, h₃]; simp theorem eraseP_subset (l : List α) : l.eraseP p ⊆ l := (eraseP_sublist l).subset protected theorem Sublist.eraseP : l₁ <+ l₂ → l₁.eraseP p <+ l₂.eraseP p | .slnil => Sublist.refl _ | .cons a s => by by_cases h : p a <;> simp [h] exacts [s.eraseP.trans (eraseP_sublist _), s.eraseP.cons _] | .cons₂ a s => by by_cases h : p a <;> simp [h] exacts [s, s.eraseP] theorem mem_of_mem_eraseP {l : List α} : a ∈ l.eraseP p → a ∈ l := (eraseP_subset _ ·) @[simp] theorem mem_eraseP_of_neg {l : List α} (pa : ¬p a) : a ∈ l.eraseP p ↔ a ∈ l := by refine ⟨mem_of_mem_eraseP, fun al => ?_⟩ match exists_or_eq_self_of_eraseP p l with | .inl h => rw [h]; assumption | .inr ⟨c, l₁, l₂, h₁, h₂, h₃, h₄⟩ => rw [h₄]; rw [h₃] at al have : a ≠ c := fun h => (h ▸ pa).elim h₂ simp [this] at al; simp [al] theorem eraseP_map (f : β → α) : ∀ (l : List β), (map f l).eraseP p = map f (l.eraseP (p ∘ f)) | [] => rfl | b::l => by by_cases h : p (f b) <;> simp [h, eraseP_map f l, eraseP_cons_of_pos] @[simp] theorem extractP_eq_find?_eraseP (l : List α) : extractP p l = (find? p l, eraseP p l) := by let rec go (acc) : ∀ xs, l = acc.data ++ xs → extractP.go p l xs acc = (xs.find? p, acc.data ++ xs.eraseP p) | [] => fun h => by simp [extractP.go, find?, eraseP, h] | x::xs => by simp [extractP.go, find?, eraseP]; cases p x <;> simp · intro h; rw [go _ xs]; {simp}; simp [h] exact go #[] _ rfl /-! ### erase -/ section erase variable [BEq α] theorem erase_eq_eraseP' (a : α) (l : List α) : l.erase a = l.eraseP (· == a) := by induction l · simp · next b t ih => rw [erase_cons, eraseP_cons, ih] if h : b == a then simp [h] else simp [h] theorem erase_eq_eraseP [LawfulBEq α] (a : α) : ∀ l : List α, l.erase a = l.eraseP (a == ·) | [] => rfl | b :: l => by if h : a = b then simp [h] else simp [h, Ne.symm h, erase_eq_eraseP a l] theorem exists_erase_eq [LawfulBEq α] {a : α} {l : List α} (h : a ∈ l) : ∃ l₁ l₂, a ∉ l₁ ∧ l = l₁ ++ a :: l₂ ∧ l.erase a = l₁ ++ l₂ := by let ⟨_, l₁, l₂, h₁, e, h₂, h₃⟩ := exists_of_eraseP h (beq_self_eq_true _) rw [erase_eq_eraseP]; exact ⟨l₁, l₂, fun h => h₁ _ h (beq_self_eq_true _), eq_of_beq e ▸ h₂, h₃⟩ @[simp] theorem length_erase_of_mem [LawfulBEq α] {a : α} {l : List α} (h : a ∈ l) : length (l.erase a) = Nat.pred (length l) := by rw [erase_eq_eraseP]; exact length_eraseP_of_mem h (beq_self_eq_true a) theorem erase_append_left [LawfulBEq α] {l₁ : List α} (l₂) (h : a ∈ l₁) : (l₁ ++ l₂).erase a = l₁.erase a ++ l₂ := by simp [erase_eq_eraseP]; exact eraseP_append_left (beq_self_eq_true a) l₂ h theorem erase_append_right [LawfulBEq α] {a : α} {l₁ : List α} (l₂ : List α) (h : a ∉ l₁) : (l₁ ++ l₂).erase a = (l₁ ++ l₂.erase a) := by rw [erase_eq_eraseP, erase_eq_eraseP, eraseP_append_right] intros b h' h''; rw [eq_of_beq h''] at h; exact h h' theorem erase_sublist (a : α) (l : List α) : l.erase a <+ l := erase_eq_eraseP' a l ▸ eraseP_sublist l theorem erase_subset (a : α) (l : List α) : l.erase a ⊆ l := (erase_sublist a l).subset theorem Sublist.erase (a : α) {l₁ l₂ : List α} (h : l₁ <+ l₂) : l₁.erase a <+ l₂.erase a := by simp only [erase_eq_eraseP']; exact h.eraseP @[deprecated] alias sublist.erase := Sublist.erase theorem mem_of_mem_erase {a b : α} {l : List α} (h : a ∈ l.erase b) : a ∈ l := erase_subset _ _ h @[simp] theorem mem_erase_of_ne [LawfulBEq α] {a b : α} {l : List α} (ab : a ≠ b) : a ∈ l.erase b ↔ a ∈ l := erase_eq_eraseP b l ▸ mem_eraseP_of_neg (mt eq_of_beq ab.symm) theorem erase_comm [LawfulBEq α] (a b : α) (l : List α) : (l.erase a).erase b = (l.erase b).erase a := by if ab : a == b then rw [eq_of_beq ab] else ?_ if ha : a ∈ l then ?_ else simp only [erase_of_not_mem ha, erase_of_not_mem (mt mem_of_mem_erase ha)] if hb : b ∈ l then ?_ else simp only [erase_of_not_mem hb, erase_of_not_mem (mt mem_of_mem_erase hb)] match l, l.erase a, exists_erase_eq ha with | _, _, ⟨l₁, l₂, ha', rfl, rfl⟩ => if h₁ : b ∈ l₁ then rw [erase_append_left _ h₁, erase_append_left _ h₁, erase_append_right _ (mt mem_of_mem_erase ha'), erase_cons_head] else rw [erase_append_right _ h₁, erase_append_right _ h₁, erase_append_right _ ha', erase_cons_tail _ ab, erase_cons_head] end erase /-! ### filter and partition -/ @[simp] theorem filter_sublist {p : α → Bool} : ∀ (l : List α), filter p l <+ l | [] => .slnil | a :: l => by rw [filter]; split <;> simp [Sublist.cons, Sublist.cons₂, filter_sublist l] /-! ### filterMap -/ theorem length_filter_le (p : α → Bool) (l : List α) : (l.filter p).length ≤ l.length := (filter_sublist _).length_le theorem length_filterMap_le (f : α → Option β) (l : List α) : (filterMap f l).length ≤ l.length := by rw [← length_map _ some, map_filterMap_some_eq_filter_map_is_some, ← length_map _ f] apply length_filter_le protected theorem Sublist.filterMap (f : α → Option β) (s : l₁ <+ l₂) : filterMap f l₁ <+ filterMap f l₂ := by induction s <;> simp <;> split <;> simp [*, cons, cons₂] theorem Sublist.filter (p : α → Bool) {l₁ l₂} (s : l₁ <+ l₂) : filter p l₁ <+ filter p l₂ := by rw [← filterMap_eq_filter]; apply s.filterMap @[simp] theorem filter_eq_self {l} : filter p l = l ↔ ∀ a ∈ l, p a := by induction l with simp | cons a l ih => cases h : p a <;> simp [*] intro h; exact Nat.lt_irrefl _ (h ▸ length_filter_le p l) @[simp] theorem filter_length_eq_length {l} : (filter p l).length = l.length ↔ ∀ a ∈ l, p a := Iff.trans ⟨l.filter_sublist.eq_of_length, congrArg length⟩ filter_eq_self /-! ### findIdx -/ @[simp] theorem findIdx_nil {α : Type _} (p : α → Bool) : [].findIdx p = 0 := rfl theorem findIdx_cons (p : α → Bool) (b : α) (l : List α) : (b :: l).findIdx p = bif p b then 0 else (l.findIdx p) + 1 := by cases H : p b with | true => simp [H, findIdx, findIdx.go] | false => simp [H, findIdx, findIdx.go, findIdx_go_succ] where findIdx_go_succ (p : α → Bool) (l : List α) (n : Nat) : List.findIdx.go p l (n + 1) = (findIdx.go p l n) + 1 := by cases l with | nil => unfold findIdx.go; exact Nat.succ_eq_add_one n | cons head tail => unfold findIdx.go cases p head <;> simp only [cond_false, cond_true] exact findIdx_go_succ p tail (n + 1) theorem findIdx_of_get?_eq_some {xs : List α} (w : xs.get? (xs.findIdx p) = some y) : p y := by induction xs with | nil => simp_all | cons x xs ih => by_cases h : p x <;> simp_all [findIdx_cons] theorem findIdx_get {xs : List α} {w : xs.findIdx p < xs.length} : p (xs.get ⟨xs.findIdx p, w⟩) := xs.findIdx_of_get?_eq_some (get?_eq_get w) theorem findIdx_lt_length_of_exists {xs : List α} (h : ∃ x ∈ xs, p x) : xs.findIdx p < xs.length := by induction xs with | nil => simp_all | cons x xs ih => by_cases p x · simp_all only [forall_exists_index, and_imp, mem_cons, exists_eq_or_imp, true_or, findIdx_cons, cond_true, length_cons] apply Nat.succ_pos · simp_all [findIdx_cons] refine Nat.succ_lt_succ ?_ obtain ⟨x', m', h'⟩ := h exact ih x' m' h' theorem findIdx_get?_eq_get_of_exists {xs : List α} (h : ∃ x ∈ xs, p x) : xs.get? (xs.findIdx p) = some (xs.get ⟨xs.findIdx p, xs.findIdx_lt_length_of_exists h⟩) := get?_eq_get (findIdx_lt_length_of_exists h) /-! ### findIdx? -/ @[simp] theorem findIdx?_nil : ([] : List α).findIdx? p i = none := rfl @[simp] theorem findIdx?_cons : (x :: xs).findIdx? p i = if p x then some i else findIdx? p xs (i + 1) := rfl @[simp] theorem findIdx?_succ : (xs : List α).findIdx? p (i+1) = (xs.findIdx? p i).map fun i => i + 1 := by induction xs generalizing i with simp | cons _ _ _ => split <;> simp_all theorem findIdx?_eq_some_iff (xs : List α) (p : α → Bool) : xs.findIdx? p = some i ↔ (xs.take (i + 1)).map p = replicate i false ++ [true] := by induction xs generalizing i with | nil => simp | cons x xs ih => simp only [findIdx?_cons, Nat.zero_add, findIdx?_succ, take_succ_cons, map_cons] split <;> cases i <;> simp_all theorem findIdx?_of_eq_some {xs : List α} {p : α → Bool} (w : xs.findIdx? p = some i) : match xs.get? i with | some a => p a | none => false := by induction xs generalizing i with | nil => simp_all | cons x xs ih => simp_all only [findIdx?_cons, Nat.zero_add, findIdx?_succ] split at w <;> cases i <;> simp_all theorem findIdx?_of_eq_none {xs : List α} {p : α → Bool} (w : xs.findIdx? p = none) : ∀ i, match xs.get? i with | some a => ¬ p a | none => true := by intro i induction xs generalizing i with | nil => simp_all | cons x xs ih => simp_all only [Bool.not_eq_true, findIdx?_cons, Nat.zero_add, findIdx?_succ] cases i with | zero => split at w <;> simp_all | succ i => simp only [get?_cons_succ] apply ih split at w <;> simp_all @[simp] theorem findIdx?_append : (xs ++ ys : List α).findIdx? p = (xs.findIdx? p <|> (ys.findIdx? p).map fun i => i + xs.length) := by induction xs with simp | cons _ _ _ => split <;> simp_all [Option.map_orElse, Option.map_map]; rfl @[simp] theorem findIdx?_replicate : (replicate n a).findIdx? p = if 0 < n ∧ p a then some 0 else none := by induction n with | zero => simp | succ n ih => simp only [replicate, findIdx?_cons, Nat.zero_add, findIdx?_succ, Nat.zero_lt_succ, true_and] split <;> simp_all /-! ### pairwise -/ theorem Pairwise.sublist : l₁ <+ l₂ → l₂.Pairwise R → l₁.Pairwise R | .slnil, h => h | .cons _ s, .cons _ h₂ => h₂.sublist s | .cons₂ _ s, .cons h₁ h₂ => (h₂.sublist s).cons fun _ h => h₁ _ (s.subset h) theorem pairwise_map {l : List α} : (l.map f).Pairwise R ↔ l.Pairwise fun a b => R (f a) (f b) := by induction l · simp · simp only [map, pairwise_cons, forall_mem_map_iff, *] theorem pairwise_append {l₁ l₂ : List α} : (l₁ ++ l₂).Pairwise R ↔ l₁.Pairwise R ∧ l₂.Pairwise R ∧ ∀ a ∈ l₁, ∀ b ∈ l₂, R a b := by induction l₁ <;> simp [*, or_imp, forall_and, and_assoc, and_left_comm] theorem pairwise_reverse {l : List α} : l.reverse.Pairwise R ↔ l.Pairwise (fun a b => R b a) := by induction l <;> simp [*, pairwise_append, and_comm] theorem Pairwise.imp {α R S} (H : ∀ {a b}, R a b → S a b) : ∀ {l : List α}, l.Pairwise R → l.Pairwise S | _, .nil => .nil | _, .cons h₁ h₂ => .cons (H ∘ h₁ ·) (h₂.imp H) /-! ### replaceF -/ theorem replaceF_nil : [].replaceF p = [] := rfl theorem replaceF_cons (a : α) (l : List α) : (a :: l).replaceF p = match p a with | none => a :: replaceF p l | some a' => a' :: l := rfl theorem replaceF_cons_of_some {l : List α} (p) (h : p a = some a') : (a :: l).replaceF p = a' :: l := by simp [replaceF_cons, h] theorem replaceF_cons_of_none {l : List α} (p) (h : p a = none) : (a :: l).replaceF p = a :: l.replaceF p := by simp [replaceF_cons, h] theorem replaceF_of_forall_none {l : List α} (h : ∀ a, a ∈ l → p a = none) : l.replaceF p = l := by induction l with | nil => rfl | cons _ _ ih => simp [h _ (.head ..), ih (forall_mem_cons.1 h).2] theorem exists_of_replaceF : ∀ {l : List α} {a a'} (al : a ∈ l) (pa : p a = some a'), ∃ a a' l₁ l₂, (∀ b ∈ l₁, p b = none) ∧ p a = some a' ∧ l = l₁ ++ a :: l₂ ∧ l.replaceF p = l₁ ++ a' :: l₂ | b :: l, a, a', al, pa => match pb : p b with | some b' => ⟨b, b', [], l, forall_mem_nil _, pb, by simp [pb]⟩ | none => match al with | .head .. => nomatch pb.symm.trans pa | .tail _ al => let ⟨c, c', l₁, l₂, h₁, h₂, h₃, h₄⟩ := exists_of_replaceF al pa ⟨c, c', b::l₁, l₂, (forall_mem_cons ..).2 ⟨pb, h₁⟩, h₂, by rw [h₃, cons_append], by simp [pb, h₄]⟩ theorem exists_or_eq_self_of_replaceF (p) (l : List α) : l.replaceF p = l ∨ ∃ a a' l₁ l₂, (∀ b ∈ l₁, p b = none) ∧ p a = some a' ∧ l = l₁ ++ a :: l₂ ∧ l.replaceF p = l₁ ++ a' :: l₂ := if h : ∃ a ∈ l, (p a).isSome then let ⟨_, ha, pa⟩ := h .inr (exists_of_replaceF ha (Option.get_mem pa)) else .inl <| replaceF_of_forall_none fun a ha => Option.not_isSome_iff_eq_none.1 fun h' => h ⟨a, ha, h'⟩ @[simp] theorem length_replaceF : length (replaceF f l) = length l := by induction l <;> simp [replaceF]; split <;> simp [*] /-! ### disjoint -/ theorem disjoint_symm (d : Disjoint l₁ l₂) : Disjoint l₂ l₁ := fun _ i₂ i₁ => d i₁ i₂ theorem disjoint_comm : Disjoint l₁ l₂ ↔ Disjoint l₂ l₁ := ⟨disjoint_symm, disjoint_symm⟩ theorem disjoint_left : Disjoint l₁ l₂ ↔ ∀ ⦃a⦄, a ∈ l₁ → a ∉ l₂ := by simp [Disjoint] theorem disjoint_right : Disjoint l₁ l₂ ↔ ∀ ⦃a⦄, a ∈ l₂ → a ∉ l₁ := disjoint_comm theorem disjoint_iff_ne : Disjoint l₁ l₂ ↔ ∀ a ∈ l₁, ∀ b ∈ l₂, a ≠ b := ⟨fun h _ al1 _ bl2 ab => h al1 (ab ▸ bl2), fun h _ al1 al2 => h _ al1 _ al2 rfl⟩ theorem disjoint_of_subset_left (ss : l₁ ⊆ l) (d : Disjoint l l₂) : Disjoint l₁ l₂ := fun _ m => d (ss m) theorem disjoint_of_subset_right (ss : l₂ ⊆ l) (d : Disjoint l₁ l) : Disjoint l₁ l₂ := fun _ m m₁ => d m (ss m₁) theorem disjoint_of_disjoint_cons_left {l₁ l₂} : Disjoint (a :: l₁) l₂ → Disjoint l₁ l₂ := disjoint_of_subset_left (subset_cons _ _) theorem disjoint_of_disjoint_cons_right {l₁ l₂} : Disjoint l₁ (a :: l₂) → Disjoint l₁ l₂ := disjoint_of_subset_right (subset_cons _ _) @[simp] theorem disjoint_nil_left (l : List α) : Disjoint [] l := fun a => (not_mem_nil a).elim @[simp] theorem disjoint_nil_right (l : List α) : Disjoint l [] := by rw [disjoint_comm]; exact disjoint_nil_left _ @[simp 1100] theorem singleton_disjoint : Disjoint [a] l ↔ a ∉ l := by simp [Disjoint] @[simp 1100] theorem disjoint_singleton : Disjoint l [a] ↔ a ∉ l := by rw [disjoint_comm, singleton_disjoint] @[simp] theorem disjoint_append_left : Disjoint (l₁ ++ l₂) l ↔ Disjoint l₁ l ∧ Disjoint l₂ l := by simp [Disjoint, or_imp, forall_and] @[simp] theorem disjoint_append_right : Disjoint l (l₁ ++ l₂) ↔ Disjoint l l₁ ∧ Disjoint l l₂ := disjoint_comm.trans <| by rw [disjoint_append_left]; simp [disjoint_comm] @[simp] theorem disjoint_cons_left : Disjoint (a::l₁) l₂ ↔ (a ∉ l₂) ∧ Disjoint l₁ l₂ := (disjoint_append_left (l₁ := [a])).trans <| by simp [singleton_disjoint] @[simp] theorem disjoint_cons_right : Disjoint l₁ (a :: l₂) ↔ (a ∉ l₁) ∧ Disjoint l₁ l₂ := disjoint_comm.trans <| by rw [disjoint_cons_left]; simp [disjoint_comm] theorem disjoint_of_disjoint_append_left_left (d : Disjoint (l₁ ++ l₂) l) : Disjoint l₁ l := (disjoint_append_left.1 d).1 theorem disjoint_of_disjoint_append_left_right (d : Disjoint (l₁ ++ l₂) l) : Disjoint l₂ l := (disjoint_append_left.1 d).2 theorem disjoint_of_disjoint_append_right_left (d : Disjoint l (l₁ ++ l₂)) : Disjoint l l₁ := (disjoint_append_right.1 d).1 theorem disjoint_of_disjoint_append_right_right (d : Disjoint l (l₁ ++ l₂)) : Disjoint l l₂ := (disjoint_append_right.1 d).2 /-! ### foldl / foldr -/ theorem foldl_hom (f : α₁ → α₂) (g₁ : α₁ → β → α₁) (g₂ : α₂ → β → α₂) (l : List β) (init : α₁) (H : ∀ x y, g₂ (f x) y = f (g₁ x y)) : l.foldl g₂ (f init) = f (l.foldl g₁ init) := by induction l generalizing init <;> simp [*, H] theorem foldr_hom (f : β₁ → β₂) (g₁ : α → β₁ → β₁) (g₂ : α → β₂ → β₂) (l : List α) (init : β₁) (H : ∀ x y, g₂ x (f y) = f (g₁ x y)) : l.foldr g₂ (f init) = f (l.foldr g₁ init) := by induction l <;> simp [*, H] /-! ### union -/ section union variable [BEq α] theorem union_def [BEq α] (l₁ l₂ : List α) : l₁ ∪ l₂ = foldr .insert l₂ l₁ := rfl @[simp] theorem nil_union (l : List α) : nil ∪ l = l := by simp [List.union_def, foldr] @[simp] theorem cons_union (a : α) (l₁ l₂ : List α) : (a :: l₁) ∪ l₂ = (l₁ ∪ l₂).insert a := by simp [List.union_def, foldr] @[simp] theorem mem_union_iff [LawfulBEq α] {x : α} {l₁ l₂ : List α} : x ∈ l₁ ∪ l₂ ↔ x ∈ l₁ ∨ x ∈ l₂ := by induction l₁ <;> simp [*, or_assoc] end union /-! ### inter -/ theorem inter_def [BEq α] (l₁ l₂ : List α) : l₁ ∩ l₂ = filter (elem · l₂) l₁ := rfl @[simp] theorem mem_inter_iff [BEq α] [LawfulBEq α] {x : α} {l₁ l₂ : List α} : x ∈ l₁ ∩ l₂ ↔ x ∈ l₁ ∧ x ∈ l₂ := by cases l₁ <;> simp [List.inter_def, mem_filter] /-! ### product -/ /-- List.prod satisfies a specification of cartesian product on lists. -/ @[simp] theorem pair_mem_product {xs : List α} {ys : List β} {x : α} {y : β} : (x, y) ∈ product xs ys ↔ x ∈ xs ∧ y ∈ ys := by simp only [product, and_imp, mem_map, Prod.mk.injEq, exists_eq_right_right, mem_bind, iff_self] /-! ### leftpad -/ /-- The length of the List returned by `List.leftpad n a l` is equal to the larger of `n` and `l.length` -/ @[simp] theorem leftpad_length (n : Nat) (a : α) (l : List α) : (leftpad n a l).length = max n l.length := by simp only [leftpad, length_append, length_replicate, Nat.sub_add_eq_max] theorem leftpad_prefix (n : Nat) (a : α) (l : List α) : replicate (n - length l) a <+: leftpad n a l := by simp only [IsPrefix, leftpad] exact Exists.intro l rfl theorem leftpad_suffix (n : Nat) (a : α) (l : List α) : l <:+ (leftpad n a l) := by simp only [IsSuffix, leftpad] exact Exists.intro (replicate (n - length l) a) rfl /-! ### monadic operations -/ -- we use ForIn.forIn as the simp normal form @[simp] theorem forIn_eq_forIn [Monad m] : @List.forIn α β m _ = forIn := rfl theorem forIn_eq_bindList [Monad m] [LawfulMonad m] (f : α → β → m (ForInStep β)) (l : List α) (init : β) : forIn l init f = ForInStep.run <$> (ForInStep.yield init).bindList f l := by induction l generalizing init <;> simp [*, map_eq_pure_bind] congr; ext (b | b) <;> simp @[simp] theorem forM_append [Monad m] [LawfulMonad m] (l₁ l₂ : List α) (f : α → m PUnit) : (l₁ ++ l₂).forM f = (do l₁.forM f; l₂.forM f) := by induction l₁ <;> simp [*] /-! ### diff -/ section Diff variable [BEq α] variable [LawfulBEq α] @[simp] theorem diff_nil (l : List α) : l.diff [] = l := rfl @[simp] theorem diff_cons (l₁ l₂ : List α) (a : α) : l₁.diff (a :: l₂) = (l₁.erase a).diff l₂ := by simp_all [List.diff, erase_of_not_mem] theorem diff_cons_right (l₁ l₂ : List α) (a : α) : l₁.diff (a :: l₂) = (l₁.diff l₂).erase a := by apply Eq.symm; induction l₂ generalizing l₁ <;> simp [erase_comm, *] theorem diff_erase (l₁ l₂ : List α) (a : α) : (l₁.diff l₂).erase a = (l₁.erase a).diff l₂ := by rw [← diff_cons_right, diff_cons] @[simp] theorem nil_diff (l : List α) : [].diff l = [] := by induction l <;> simp [*, erase_of_not_mem] theorem cons_diff (a : α) (l₁ l₂ : List α) : (a :: l₁).diff l₂ = if a ∈ l₂ then l₁.diff (l₂.erase a) else a :: l₁.diff l₂ := by induction l₂ generalizing l₁ with | nil => rfl | cons b l₂ ih => by_cases h : a = b next => simp [*] next => have := Ne.symm h simp[*] theorem cons_diff_of_mem {a : α} {l₂ : List α} (h : a ∈ l₂) (l₁ : List α) : (a :: l₁).diff l₂ = l₁.diff (l₂.erase a) := by rw [cons_diff, if_pos h] theorem cons_diff_of_not_mem {a : α} {l₂ : List α} (h : a ∉ l₂) (l₁ : List α) : (a :: l₁).diff l₂ = a :: l₁.diff l₂ := by rw [cons_diff, if_neg h] theorem diff_eq_foldl : ∀ l₁ l₂ : List α, l₁.diff l₂ = foldl List.erase l₁ l₂ | _, [] => rfl | l₁, a :: l₂ => (diff_cons l₁ l₂ a).trans (diff_eq_foldl _ _) @[simp] theorem diff_append (l₁ l₂ l₃ : List α) : l₁.diff (l₂ ++ l₃) = (l₁.diff l₂).diff l₃ := by simp only [diff_eq_foldl, foldl_append] theorem diff_sublist : ∀ l₁ l₂ : List α, l₁.diff l₂ <+ l₁ | _, [] => .refl _ | l₁, a :: l₂ => calc l₁.diff (a :: l₂) = (l₁.erase a).diff l₂ := diff_cons .. _ <+ l₁.erase a := diff_sublist .. _ <+ l₁ := erase_sublist .. theorem diff_subset (l₁ l₂ : List α) : l₁.diff l₂ ⊆ l₁ := (diff_sublist ..).subset theorem mem_diff_of_mem {a : α} : ∀ {l₁ l₂ : List α}, a ∈ l₁ → a ∉ l₂ → a ∈ l₁.diff l₂ | _, [], h₁, _ => h₁ | l₁, b :: l₂, h₁, h₂ => by rw [diff_cons] exact mem_diff_of_mem ((mem_erase_of_ne <| ne_of_not_mem_cons h₂).2 h₁) (mt (.tail _) h₂) theorem Sublist.diff_right : ∀ {l₁ l₂ l₃ : List α}, l₁ <+ l₂ → l₁.diff l₃ <+ l₂.diff l₃ | _, _, [], h => h | l₁, l₂, a :: l₃, h => by simp only [diff_cons, (h.erase _).diff_right] theorem Sublist.erase_diff_erase_sublist {a : α} : ∀ {l₁ l₂ : List α}, l₁ <+ l₂ → (l₂.erase a).diff (l₁.erase a) <+ l₂.diff l₁ | [], l₂, _ => erase_sublist _ _ | b :: l₁, l₂, h => by if heq : b = a then simp [heq] else simp [heq, erase_comm a] exact (erase_cons_head b _ ▸ h.erase b).erase_diff_erase_sublist end Diff /-! ### prefix, suffix, infix -/ @[simp] theorem prefix_append (l₁ l₂ : List α) : l₁ <+: l₁ ++ l₂ := ⟨l₂, rfl⟩ @[simp] theorem suffix_append (l₁ l₂ : List α) : l₂ <:+ l₁ ++ l₂ := ⟨l₁, rfl⟩ theorem infix_append (l₁ l₂ l₃ : List α) : l₂ <:+: l₁ ++ l₂ ++ l₃ := ⟨l₁, l₃, rfl⟩ @[simp] theorem infix_append' (l₁ l₂ l₃ : List α) : l₂ <:+: l₁ ++ (l₂ ++ l₃) := by rw [← List.append_assoc]; apply infix_append theorem IsPrefix.isInfix : l₁ <+: l₂ → l₁ <:+: l₂ := fun ⟨t, h⟩ => ⟨[], t, h⟩ theorem IsSuffix.isInfix : l₁ <:+ l₂ → l₁ <:+: l₂ := fun ⟨t, h⟩ => ⟨t, [], by rw [h, append_nil]⟩ theorem nil_prefix (l : List α) : [] <+: l := ⟨l, rfl⟩ theorem nil_suffix (l : List α) : [] <:+ l := ⟨l, append_nil _⟩ theorem nil_infix (l : List α) : [] <:+: l := (nil_prefix _).isInfix theorem prefix_refl (l : List α) : l <+: l := ⟨[], append_nil _⟩ theorem suffix_refl (l : List α) : l <:+ l := ⟨[], rfl⟩ theorem infix_refl (l : List α) : l <:+: l := (prefix_refl l).isInfix @[simp] theorem suffix_cons (a : α) : ∀ l, l <:+ a :: l := suffix_append [a] theorem infix_cons : l₁ <:+: l₂ → l₁ <:+: a :: l₂ := fun ⟨L₁, L₂, h⟩ => ⟨a :: L₁, L₂, h ▸ rfl⟩ theorem infix_concat : l₁ <:+: l₂ → l₁ <:+: concat l₂ a := fun ⟨L₁, L₂, h⟩ => ⟨L₁, concat L₂ a, by simp [← h, concat_eq_append, append_assoc]⟩ theorem IsPrefix.trans : ∀ {l₁ l₂ l₃ : List α}, l₁ <+: l₂ → l₂ <+: l₃ → l₁ <+: l₃ | _, _, _, ⟨r₁, rfl⟩, ⟨r₂, rfl⟩ => ⟨r₁ ++ r₂, (append_assoc _ _ _).symm⟩ theorem IsSuffix.trans : ∀ {l₁ l₂ l₃ : List α}, l₁ <:+ l₂ → l₂ <:+ l₃ → l₁ <:+ l₃ | _, _, _, ⟨l₁, rfl⟩, ⟨l₂, rfl⟩ => ⟨l₂ ++ l₁, append_assoc _ _ _⟩ theorem IsInfix.trans : ∀ {l₁ l₂ l₃ : List α}, l₁ <:+: l₂ → l₂ <:+: l₃ → l₁ <:+: l₃ | l, _, _, ⟨l₁, r₁, rfl⟩, ⟨l₂, r₂, rfl⟩ => ⟨l₂ ++ l₁, r₁ ++ r₂, by simp only [append_assoc]⟩ protected theorem IsInfix.sublist : l₁ <:+: l₂ → l₁ <+ l₂ | ⟨_, _, h⟩ => h ▸ (sublist_append_right ..).trans (sublist_append_left ..) protected theorem IsInfix.subset (hl : l₁ <:+: l₂) : l₁ ⊆ l₂ := hl.sublist.subset protected theorem IsPrefix.sublist (h : l₁ <+: l₂) : l₁ <+ l₂ := h.isInfix.sublist protected theorem IsPrefix.subset (hl : l₁ <+: l₂) : l₁ ⊆ l₂ := hl.sublist.subset protected theorem IsSuffix.sublist (h : l₁ <:+ l₂) : l₁ <+ l₂ := h.isInfix.sublist protected theorem IsSuffix.subset (hl : l₁ <:+ l₂) : l₁ ⊆ l₂ := hl.sublist.subset @[simp] theorem reverse_suffix : reverse l₁ <:+ reverse l₂ ↔ l₁ <+: l₂ := ⟨fun ⟨r, e⟩ => ⟨reverse r, by rw [← reverse_reverse l₁, ← reverse_append, e, reverse_reverse]⟩, fun ⟨r, e⟩ => ⟨reverse r, by rw [← reverse_append, e]⟩⟩ @[simp] theorem reverse_prefix : reverse l₁ <+: reverse l₂ ↔ l₁ <:+ l₂ := by rw [← reverse_suffix]; simp only [reverse_reverse] @[simp] theorem reverse_infix : reverse l₁ <:+: reverse l₂ ↔ l₁ <:+: l₂ := by refine ⟨fun ⟨s, t, e⟩ => ⟨reverse t, reverse s, ?_⟩, fun ⟨s, t, e⟩ => ⟨reverse t, reverse s, ?_⟩⟩ · rw [← reverse_reverse l₁, append_assoc, ← reverse_append, ← reverse_append, e, reverse_reverse] · rw [append_assoc, ← reverse_append, ← reverse_append, e] theorem IsInfix.length_le (h : l₁ <:+: l₂) : l₁.length ≤ l₂.length := h.sublist.length_le theorem IsPrefix.length_le (h : l₁ <+: l₂) : l₁.length ≤ l₂.length := h.sublist.length_le theorem IsSuffix.length_le (h : l₁ <:+ l₂) : l₁.length ≤ l₂.length := h.sublist.length_le @[simp] theorem infix_nil : l <:+: [] ↔ l = [] := ⟨(sublist_nil.1 ·.sublist), (· ▸ infix_refl _)⟩ @[simp] theorem prefix_nil : l <+: [] ↔ l = [] := ⟨(sublist_nil.1 ·.sublist), (· ▸ prefix_refl _)⟩ @[simp] theorem suffix_nil : l <:+ [] ↔ l = [] := ⟨(sublist_nil.1 ·.sublist), (· ▸ suffix_refl _)⟩ theorem infix_iff_prefix_suffix (l₁ l₂ : List α) : l₁ <:+: l₂ ↔ ∃ t, l₁ <+: t ∧ t <:+ l₂ := ⟨fun ⟨_, t, e⟩ => ⟨l₁ ++ t, ⟨_, rfl⟩, e ▸ append_assoc .. ▸ ⟨_, rfl⟩⟩, fun ⟨_, ⟨t, rfl⟩, s, e⟩ => ⟨s, t, append_assoc .. ▸ e⟩⟩ theorem IsInfix.eq_of_length (h : l₁ <:+: l₂) : l₁.length = l₂.length → l₁ = l₂ := h.sublist.eq_of_length theorem IsPrefix.eq_of_length (h : l₁ <+: l₂) : l₁.length = l₂.length → l₁ = l₂ := h.sublist.eq_of_length theorem IsSuffix.eq_of_length (h : l₁ <:+ l₂) : l₁.length = l₂.length → l₁ = l₂ := h.sublist.eq_of_length theorem prefix_of_prefix_length_le : ∀ {l₁ l₂ l₃ : List α}, l₁ <+: l₃ → l₂ <+: l₃ → length l₁ ≤ length l₂ → l₁ <+: l₂ | [], l₂, _, _, _, _ => nil_prefix _ | a :: l₁, b :: l₂, _, ⟨r₁, rfl⟩, ⟨r₂, e⟩, ll => by injection e with _ e'; subst b rcases prefix_of_prefix_length_le ⟨_, rfl⟩ ⟨_, e'⟩ (le_of_succ_le_succ ll) with ⟨r₃, rfl⟩ exact ⟨r₃, rfl⟩ theorem prefix_or_prefix_of_prefix (h₁ : l₁ <+: l₃) (h₂ : l₂ <+: l₃) : l₁ <+: l₂ ∨ l₂ <+: l₁ := (Nat.le_total (length l₁) (length l₂)).imp (prefix_of_prefix_length_le h₁ h₂) (prefix_of_prefix_length_le h₂ h₁) theorem suffix_of_suffix_length_le (h₁ : l₁ <:+ l₃) (h₂ : l₂ <:+ l₃) (ll : length l₁ ≤ length l₂) : l₁ <:+ l₂ := reverse_prefix.1 <| prefix_of_prefix_length_le (reverse_prefix.2 h₁) (reverse_prefix.2 h₂) (by simp [ll]) theorem suffix_or_suffix_of_suffix (h₁ : l₁ <:+ l₃) (h₂ : l₂ <:+ l₃) : l₁ <:+ l₂ ∨ l₂ <:+ l₁ := (prefix_or_prefix_of_prefix (reverse_prefix.2 h₁) (reverse_prefix.2 h₂)).imp reverse_prefix.1 reverse_prefix.1 theorem suffix_cons_iff : l₁ <:+ a :: l₂ ↔ l₁ = a :: l₂ ∨ l₁ <:+ l₂ := by constructor · rintro ⟨⟨hd, tl⟩, hl₃⟩ · exact Or.inl hl₃ · simp only [cons_append] at hl₃ injection hl₃ with _ hl₄ exact Or.inr ⟨_, hl₄⟩ · rintro (rfl | hl₁) · exact (a :: l₂).suffix_refl · exact hl₁.trans (l₂.suffix_cons _) theorem infix_cons_iff : l₁ <:+: a :: l₂ ↔ l₁ <+: a :: l₂ ∨ l₁ <:+: l₂ := by constructor · rintro ⟨⟨hd, tl⟩, t, hl₃⟩ · exact Or.inl ⟨t, hl₃⟩ · simp only [cons_append] at hl₃ injection hl₃ with _ hl₄ exact Or.inr ⟨_, t, hl₄⟩ · rintro (h | hl₁) · exact h.isInfix · exact infix_cons hl₁ theorem infix_of_mem_join : ∀ {L : List (List α)}, l ∈ L → l <:+: join L | l' :: _, h => match h with | List.Mem.head .. => infix_append [] _ _ | List.Mem.tail _ hlMemL => IsInfix.trans (infix_of_mem_join hlMemL) <| (suffix_append _ _).isInfix theorem prefix_append_right_inj (l) : l ++ l₁ <+: l ++ l₂ ↔ l₁ <+: l₂ := exists_congr fun r => by rw [append_assoc, append_right_inj] @[simp] theorem prefix_cons_inj (a) : a :: l₁ <+: a :: l₂ ↔ l₁ <+: l₂ := prefix_append_right_inj [a] theorem take_prefix (n) (l : List α) : take n l <+: l := ⟨_, take_append_drop _ _⟩ theorem drop_suffix (n) (l : List α) : drop n l <:+ l := ⟨_, take_append_drop _ _⟩ theorem take_sublist (n) (l : List α) : take n l <+ l := (take_prefix n l).sublist theorem drop_sublist (n) (l : List α) : drop n l <+ l := (drop_suffix n l).sublist theorem take_subset (n) (l : List α) : take n l ⊆ l := (take_sublist n l).subset theorem drop_subset (n) (l : List α) : drop n l ⊆ l := (drop_sublist n l).subset theorem mem_of_mem_take {l : List α} (h : a ∈ l.take n) : a ∈ l := take_subset n l h theorem IsPrefix.filter (p : α → Bool) ⦃l₁ l₂ : List α⦄ (h : l₁ <+: l₂) : l₁.filter p <+: l₂.filter p := by obtain ⟨xs, rfl⟩ := h rw [filter_append]; apply prefix_append theorem IsSuffix.filter (p : α → Bool) ⦃l₁ l₂ : List α⦄ (h : l₁ <:+ l₂) : l₁.filter p <:+ l₂.filter p := by obtain ⟨xs, rfl⟩ := h rw [filter_append]; apply suffix_append theorem IsInfix.filter (p : α → Bool) ⦃l₁ l₂ : List α⦄ (h : l₁ <:+: l₂) : l₁.filter p <:+: l₂.filter p := by obtain ⟨xs, ys, rfl⟩ := h rw [filter_append, filter_append]; apply infix_append _ /-! ### drop -/ theorem mem_of_mem_drop {n} {l : List α} (h : a ∈ l.drop n) : a ∈ l := drop_subset _ _ h theorem disjoint_take_drop : ∀ {l : List α}, l.Nodup → m ≤ n → Disjoint (l.take m) (l.drop n) | [], _, _ => by simp | x :: xs, hl, h => by cases m <;> cases n <;> simp only [disjoint_cons_left, drop, not_mem_nil, disjoint_nil_left, take, not_false_eq_true, and_self] · case succ.zero => cases h · cases hl with | cons h₀ h₁ => refine ⟨fun h => h₀ _ (mem_of_mem_drop h) rfl, ?_⟩ exact disjoint_take_drop h₁ (Nat.le_of_succ_le_succ h) /-! ### Chain -/ attribute [simp] Chain.nil @[simp] theorem chain_cons {a b : α} {l : List α} : Chain R a (b :: l) ↔ R a b ∧ Chain R b l := ⟨fun p => by cases p with | cons n p => exact ⟨n, p⟩, fun ⟨n, p⟩ => p.cons n⟩ theorem rel_of_chain_cons {a b : α} {l : List α} (p : Chain R a (b :: l)) : R a b := (chain_cons.1 p).1 theorem chain_of_chain_cons {a b : α} {l : List α} (p : Chain R a (b :: l)) : Chain R b l := (chain_cons.1 p).2 theorem Chain.imp' {R S : α → α → Prop} (HRS : ∀ ⦃a b⦄, R a b → S a b) {a b : α} (Hab : ∀ ⦃c⦄, R a c → S b c) {l : List α} (p : Chain R a l) : Chain S b l := by induction p generalizing b with | nil => constructor | cons r _ ih => constructor · exact Hab r · exact ih (@HRS _) theorem Chain.imp {R S : α → α → Prop} (H : ∀ a b, R a b → S a b) {a : α} {l : List α} (p : Chain R a l) : Chain S a l := p.imp' H (H a) protected theorem Pairwise.chain (p : Pairwise R (a :: l)) : Chain R a l := by let ⟨r, p'⟩ := pairwise_cons.1 p; clear p induction p' generalizing a with | nil => exact Chain.nil | @cons b l r' _ IH => simp only [chain_cons, forall_mem_cons] at r exact chain_cons.2 ⟨r.1, IH r'⟩ /-! ### range', range -/ @[simp] theorem length_range' (s step) : ∀ n : Nat, length (range' s n step) = n | 0 => rfl | _ + 1 => congrArg succ (length_range' _ _ _) @[simp] theorem range'_eq_nil : range' s n step = [] ↔ n = 0 := by rw [← length_eq_zero, length_range'] theorem mem_range' : ∀{n}, m ∈ range' s n step ↔ ∃ i < n, m = s + step * i | 0 => by simp [range', Nat.not_lt_zero] | n + 1 => by have h (i) : i ≤ n ↔ i = 0 ∨ ∃ j, i = succ j ∧ j < n := by cases i <;> simp [Nat.succ_le] simp [range', mem_range', Nat.lt_succ, h]; simp only [← exists_and_right, and_assoc] rw [exists_comm]; simp [Nat.mul_succ, Nat.add_assoc, Nat.add_comm] @[simp] theorem mem_range'_1 : m ∈ range' s n ↔ s ≤ m ∧ m < s + n := by simp [mem_range']; exact ⟨ fun ⟨i, h, e⟩ => e ▸ ⟨Nat.le_add_right .., Nat.add_lt_add_left h _⟩, fun ⟨h₁, h₂⟩ => ⟨m - s, Nat.sub_lt_left_of_lt_add h₁ h₂, (Nat.add_sub_cancel' h₁).symm⟩⟩ @[simp] theorem map_add_range' (a) : ∀ s n step, map (a + ·) (range' s n step) = range' (a + s) n step | _, 0, _ => rfl | s, n + 1, step => by simp [range', map_add_range' _ (s + step) n step, Nat.add_assoc]
.lake/packages/batteries/Batteries/Data/List/Lemmas.lean
1,296
1,300
theorem map_sub_range' (a s n : Nat) (h : a ≤ s) : map (· - a) (range' s n step) = range' (s - a) n step := by
conv => lhs; rw [← Nat.add_sub_cancel' h] rw [← map_add_range', map_map, (?_ : _∘_ = _), map_id] funext x; apply Nat.add_sub_cancel_left
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker, Johan Commelin -/ import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.BigOperators import Mathlib.Algebra.Polynomial.Degree.Lemmas import Mathlib.Algebra.Polynomial.Div #align_import data.polynomial.ring_division from "leanprover-community/mathlib"@"8efcf8022aac8e01df8d302dcebdbc25d6a886c8" /-! # Theory of univariate polynomials We prove basic results about univariate polynomials. -/ noncomputable section open Polynomial open Finset namespace Polynomial universe u v w z variable {R : Type u} {S : Type v} {T : Type w} {a b : R} {n : ℕ} section CommRing variable [CommRing R] {p q : R[X]} section variable [Semiring S] theorem natDegree_pos_of_aeval_root [Algebra R S] {p : R[X]} (hp : p ≠ 0) {z : S} (hz : aeval z p = 0) (inj : ∀ x : R, algebraMap R S x = 0 → x = 0) : 0 < p.natDegree := natDegree_pos_of_eval₂_root hp (algebraMap R S) hz inj #align polynomial.nat_degree_pos_of_aeval_root Polynomial.natDegree_pos_of_aeval_root theorem degree_pos_of_aeval_root [Algebra R S] {p : R[X]} (hp : p ≠ 0) {z : S} (hz : aeval z p = 0) (inj : ∀ x : R, algebraMap R S x = 0 → x = 0) : 0 < p.degree := natDegree_pos_iff_degree_pos.mp (natDegree_pos_of_aeval_root hp hz inj) #align polynomial.degree_pos_of_aeval_root Polynomial.degree_pos_of_aeval_root theorem modByMonic_eq_of_dvd_sub (hq : q.Monic) {p₁ p₂ : R[X]} (h : q ∣ p₁ - p₂) : p₁ %ₘ q = p₂ %ₘ q := by nontriviality R obtain ⟨f, sub_eq⟩ := h refine (div_modByMonic_unique (p₂ /ₘ q + f) _ hq ⟨?_, degree_modByMonic_lt _ hq⟩).2 rw [sub_eq_iff_eq_add.mp sub_eq, mul_add, ← add_assoc, modByMonic_add_div _ hq, add_comm] #align polynomial.mod_by_monic_eq_of_dvd_sub Polynomial.modByMonic_eq_of_dvd_sub theorem add_modByMonic (p₁ p₂ : R[X]) : (p₁ + p₂) %ₘ q = p₁ %ₘ q + p₂ %ₘ q := by by_cases hq : q.Monic · cases' subsingleton_or_nontrivial R with hR hR · simp only [eq_iff_true_of_subsingleton] · exact (div_modByMonic_unique (p₁ /ₘ q + p₂ /ₘ q) _ hq ⟨by rw [mul_add, add_left_comm, add_assoc, modByMonic_add_div _ hq, ← add_assoc, add_comm (q * _), modByMonic_add_div _ hq], (degree_add_le _ _).trans_lt (max_lt (degree_modByMonic_lt _ hq) (degree_modByMonic_lt _ hq))⟩).2 · simp_rw [modByMonic_eq_of_not_monic _ hq] #align polynomial.add_mod_by_monic Polynomial.add_modByMonic theorem smul_modByMonic (c : R) (p : R[X]) : c • p %ₘ q = c • (p %ₘ q) := by by_cases hq : q.Monic · cases' subsingleton_or_nontrivial R with hR hR · simp only [eq_iff_true_of_subsingleton] · exact (div_modByMonic_unique (c • (p /ₘ q)) (c • (p %ₘ q)) hq ⟨by rw [mul_smul_comm, ← smul_add, modByMonic_add_div p hq], (degree_smul_le _ _).trans_lt (degree_modByMonic_lt _ hq)⟩).2 · simp_rw [modByMonic_eq_of_not_monic _ hq] #align polynomial.smul_mod_by_monic Polynomial.smul_modByMonic /-- `_ %ₘ q` as an `R`-linear map. -/ @[simps] def modByMonicHom (q : R[X]) : R[X] →ₗ[R] R[X] where toFun p := p %ₘ q map_add' := add_modByMonic map_smul' := smul_modByMonic #align polynomial.mod_by_monic_hom Polynomial.modByMonicHom theorem neg_modByMonic (p mod : R[X]) : (-p) %ₘ mod = - (p %ₘ mod) := (modByMonicHom mod).map_neg p theorem sub_modByMonic (a b mod : R[X]) : (a - b) %ₘ mod = a %ₘ mod - b %ₘ mod := (modByMonicHom mod).map_sub a b end section variable [Ring S] theorem aeval_modByMonic_eq_self_of_root [Algebra R S] {p q : R[X]} (hq : q.Monic) {x : S} (hx : aeval x q = 0) : aeval x (p %ₘ q) = aeval x p := by --`eval₂_modByMonic_eq_self_of_root` doesn't work here as it needs commutativity rw [modByMonic_eq_sub_mul_div p hq, _root_.map_sub, _root_.map_mul, hx, zero_mul, sub_zero] #align polynomial.aeval_mod_by_monic_eq_self_of_root Polynomial.aeval_modByMonic_eq_self_of_root end end CommRing section NoZeroDivisors variable [Semiring R] [NoZeroDivisors R] {p q : R[X]} instance : NoZeroDivisors R[X] where eq_zero_or_eq_zero_of_mul_eq_zero h := by rw [← leadingCoeff_eq_zero, ← leadingCoeff_eq_zero] refine eq_zero_or_eq_zero_of_mul_eq_zero ?_ rw [← leadingCoeff_zero, ← leadingCoeff_mul, h] theorem natDegree_mul (hp : p ≠ 0) (hq : q ≠ 0) : (p*q).natDegree = p.natDegree + q.natDegree := by rw [← Nat.cast_inj (R := WithBot ℕ), ← degree_eq_natDegree (mul_ne_zero hp hq), Nat.cast_add, ← degree_eq_natDegree hp, ← degree_eq_natDegree hq, degree_mul] #align polynomial.nat_degree_mul Polynomial.natDegree_mul theorem trailingDegree_mul : (p * q).trailingDegree = p.trailingDegree + q.trailingDegree := by by_cases hp : p = 0 · rw [hp, zero_mul, trailingDegree_zero, top_add] by_cases hq : q = 0 · rw [hq, mul_zero, trailingDegree_zero, add_top] · rw [trailingDegree_eq_natTrailingDegree hp, trailingDegree_eq_natTrailingDegree hq, trailingDegree_eq_natTrailingDegree (mul_ne_zero hp hq), natTrailingDegree_mul hp hq] apply WithTop.coe_add #align polynomial.trailing_degree_mul Polynomial.trailingDegree_mul @[simp] theorem natDegree_pow (p : R[X]) (n : ℕ) : natDegree (p ^ n) = n * natDegree p := by classical obtain rfl | hp := eq_or_ne p 0 · obtain rfl | hn := eq_or_ne n 0 <;> simp [*] exact natDegree_pow' $ by rw [← leadingCoeff_pow, Ne, leadingCoeff_eq_zero]; exact pow_ne_zero _ hp #align polynomial.nat_degree_pow Polynomial.natDegree_pow theorem degree_le_mul_left (p : R[X]) (hq : q ≠ 0) : degree p ≤ degree (p * q) := by classical exact if hp : p = 0 then by simp only [hp, zero_mul, le_refl] else by rw [degree_mul, degree_eq_natDegree hp, degree_eq_natDegree hq]; exact WithBot.coe_le_coe.2 (Nat.le_add_right _ _) #align polynomial.degree_le_mul_left Polynomial.degree_le_mul_left theorem natDegree_le_of_dvd {p q : R[X]} (h1 : p ∣ q) (h2 : q ≠ 0) : p.natDegree ≤ q.natDegree := by rcases h1 with ⟨q, rfl⟩; rw [mul_ne_zero_iff] at h2 rw [natDegree_mul h2.1 h2.2]; exact Nat.le_add_right _ _ #align polynomial.nat_degree_le_of_dvd Polynomial.natDegree_le_of_dvd theorem degree_le_of_dvd {p q : R[X]} (h1 : p ∣ q) (h2 : q ≠ 0) : degree p ≤ degree q := by rcases h1 with ⟨q, rfl⟩; rw [mul_ne_zero_iff] at h2 exact degree_le_mul_left p h2.2 #align polynomial.degree_le_of_dvd Polynomial.degree_le_of_dvd theorem eq_zero_of_dvd_of_degree_lt {p q : R[X]} (h₁ : p ∣ q) (h₂ : degree q < degree p) : q = 0 := by by_contra hc exact (lt_iff_not_ge _ _).mp h₂ (degree_le_of_dvd h₁ hc) #align polynomial.eq_zero_of_dvd_of_degree_lt Polynomial.eq_zero_of_dvd_of_degree_lt theorem eq_zero_of_dvd_of_natDegree_lt {p q : R[X]} (h₁ : p ∣ q) (h₂ : natDegree q < natDegree p) : q = 0 := by by_contra hc exact (lt_iff_not_ge _ _).mp h₂ (natDegree_le_of_dvd h₁ hc) #align polynomial.eq_zero_of_dvd_of_nat_degree_lt Polynomial.eq_zero_of_dvd_of_natDegree_lt theorem not_dvd_of_degree_lt {p q : R[X]} (h0 : q ≠ 0) (hl : q.degree < p.degree) : ¬p ∣ q := by by_contra hcontra exact h0 (eq_zero_of_dvd_of_degree_lt hcontra hl) #align polynomial.not_dvd_of_degree_lt Polynomial.not_dvd_of_degree_lt theorem not_dvd_of_natDegree_lt {p q : R[X]} (h0 : q ≠ 0) (hl : q.natDegree < p.natDegree) : ¬p ∣ q := by by_contra hcontra exact h0 (eq_zero_of_dvd_of_natDegree_lt hcontra hl) #align polynomial.not_dvd_of_nat_degree_lt Polynomial.not_dvd_of_natDegree_lt /-- This lemma is useful for working with the `intDegree` of a rational function. -/ theorem natDegree_sub_eq_of_prod_eq {p₁ p₂ q₁ q₂ : R[X]} (hp₁ : p₁ ≠ 0) (hq₁ : q₁ ≠ 0) (hp₂ : p₂ ≠ 0) (hq₂ : q₂ ≠ 0) (h_eq : p₁ * q₂ = p₂ * q₁) : (p₁.natDegree : ℤ) - q₁.natDegree = (p₂.natDegree : ℤ) - q₂.natDegree := by rw [sub_eq_sub_iff_add_eq_add] norm_cast rw [← natDegree_mul hp₁ hq₂, ← natDegree_mul hp₂ hq₁, h_eq] #align polynomial.nat_degree_sub_eq_of_prod_eq Polynomial.natDegree_sub_eq_of_prod_eq theorem natDegree_eq_zero_of_isUnit (h : IsUnit p) : natDegree p = 0 := by nontriviality R obtain ⟨q, hq⟩ := h.exists_right_inv have := natDegree_mul (left_ne_zero_of_mul_eq_one hq) (right_ne_zero_of_mul_eq_one hq) rw [hq, natDegree_one, eq_comm, add_eq_zero_iff] at this exact this.1 #align polynomial.nat_degree_eq_zero_of_is_unit Polynomial.natDegree_eq_zero_of_isUnit theorem degree_eq_zero_of_isUnit [Nontrivial R] (h : IsUnit p) : degree p = 0 := (natDegree_eq_zero_iff_degree_le_zero.mp <| natDegree_eq_zero_of_isUnit h).antisymm (zero_le_degree_iff.mpr h.ne_zero) #align polynomial.degree_eq_zero_of_is_unit Polynomial.degree_eq_zero_of_isUnit @[simp] theorem degree_coe_units [Nontrivial R] (u : R[X]ˣ) : degree (u : R[X]) = 0 := degree_eq_zero_of_isUnit ⟨u, rfl⟩ #align polynomial.degree_coe_units Polynomial.degree_coe_units /-- Characterization of a unit of a polynomial ring over an integral domain `R`. See `Polynomial.isUnit_iff_coeff_isUnit_isNilpotent` when `R` is a commutative ring. -/ theorem isUnit_iff : IsUnit p ↔ ∃ r : R, IsUnit r ∧ C r = p := ⟨fun hp => ⟨p.coeff 0, let h := eq_C_of_natDegree_eq_zero (natDegree_eq_zero_of_isUnit hp) ⟨isUnit_C.1 (h ▸ hp), h.symm⟩⟩, fun ⟨_, hr, hrp⟩ => hrp ▸ isUnit_C.2 hr⟩ #align polynomial.is_unit_iff Polynomial.isUnit_iff theorem not_isUnit_of_degree_pos (p : R[X]) (hpl : 0 < p.degree) : ¬ IsUnit p := by cases subsingleton_or_nontrivial R · simp [Subsingleton.elim p 0] at hpl intro h simp [degree_eq_zero_of_isUnit h] at hpl theorem not_isUnit_of_natDegree_pos (p : R[X]) (hpl : 0 < p.natDegree) : ¬ IsUnit p := not_isUnit_of_degree_pos _ (natDegree_pos_iff_degree_pos.mp hpl) variable [CharZero R] end NoZeroDivisors section NoZeroDivisors variable [CommSemiring R] [NoZeroDivisors R] {p q : R[X]} theorem irreducible_of_monic (hp : p.Monic) (hp1 : p ≠ 1) : Irreducible p ↔ ∀ f g : R[X], f.Monic → g.Monic → f * g = p → f = 1 ∨ g = 1 := by refine ⟨fun h f g hf hg hp => (h.2 f g hp.symm).imp hf.eq_one_of_isUnit hg.eq_one_of_isUnit, fun h => ⟨hp1 ∘ hp.eq_one_of_isUnit, fun f g hfg => (h (g * C f.leadingCoeff) (f * C g.leadingCoeff) ?_ ?_ ?_).symm.imp (isUnit_of_mul_eq_one f _) (isUnit_of_mul_eq_one g _)⟩⟩ · rwa [Monic, leadingCoeff_mul, leadingCoeff_C, ← leadingCoeff_mul, mul_comm, ← hfg, ← Monic] · rwa [Monic, leadingCoeff_mul, leadingCoeff_C, ← leadingCoeff_mul, ← hfg, ← Monic] · rw [mul_mul_mul_comm, ← C_mul, ← leadingCoeff_mul, ← hfg, hp.leadingCoeff, C_1, mul_one, mul_comm, ← hfg] #align polynomial.irreducible_of_monic Polynomial.irreducible_of_monic theorem Monic.irreducible_iff_natDegree (hp : p.Monic) : Irreducible p ↔ p ≠ 1 ∧ ∀ f g : R[X], f.Monic → g.Monic → f * g = p → f.natDegree = 0 ∨ g.natDegree = 0 := by by_cases hp1 : p = 1; · simp [hp1] rw [irreducible_of_monic hp hp1, and_iff_right hp1] refine forall₄_congr fun a b ha hb => ?_ rw [ha.natDegree_eq_zero_iff_eq_one, hb.natDegree_eq_zero_iff_eq_one] #align polynomial.monic.irreducible_iff_nat_degree Polynomial.Monic.irreducible_iff_natDegree theorem Monic.irreducible_iff_natDegree' (hp : p.Monic) : Irreducible p ↔ p ≠ 1 ∧ ∀ f g : R[X], f.Monic → g.Monic → f * g = p → g.natDegree ∉ Ioc 0 (p.natDegree / 2) := by simp_rw [hp.irreducible_iff_natDegree, mem_Ioc, Nat.le_div_iff_mul_le zero_lt_two, mul_two] apply and_congr_right' constructor <;> intro h f g hf hg he <;> subst he · rw [hf.natDegree_mul hg, add_le_add_iff_right] exact fun ha => (h f g hf hg rfl).elim (ha.1.trans_le ha.2).ne' ha.1.ne' · simp_rw [hf.natDegree_mul hg, pos_iff_ne_zero] at h contrapose! h obtain hl | hl := le_total f.natDegree g.natDegree · exact ⟨g, f, hg, hf, mul_comm g f, h.1, add_le_add_left hl _⟩ · exact ⟨f, g, hf, hg, rfl, h.2, add_le_add_right hl _⟩ #align polynomial.monic.irreducible_iff_nat_degree' Polynomial.Monic.irreducible_iff_natDegree' /-- Alternate phrasing of `Polynomial.Monic.irreducible_iff_natDegree'` where we only have to check one divisor at a time. -/ theorem Monic.irreducible_iff_lt_natDegree_lt {p : R[X]} (hp : p.Monic) (hp1 : p ≠ 1) : Irreducible p ↔ ∀ q, Monic q → natDegree q ∈ Finset.Ioc 0 (natDegree p / 2) → ¬ q ∣ p := by rw [hp.irreducible_iff_natDegree', and_iff_right hp1] constructor · rintro h g hg hdg ⟨f, rfl⟩ exact h f g (hg.of_mul_monic_left hp) hg (mul_comm f g) hdg · rintro h f g - hg rfl hdg exact h g hg hdg (dvd_mul_left g f)
Mathlib/Algebra/Polynomial/RingDivision.lean
293
316
theorem Monic.not_irreducible_iff_exists_add_mul_eq_coeff (hm : p.Monic) (hnd : p.natDegree = 2) : ¬Irreducible p ↔ ∃ c₁ c₂, p.coeff 0 = c₁ * c₂ ∧ p.coeff 1 = c₁ + c₂ := by
cases subsingleton_or_nontrivial R · simp [natDegree_of_subsingleton] at hnd rw [hm.irreducible_iff_natDegree', and_iff_right, hnd] · push_neg constructor · rintro ⟨a, b, ha, hb, rfl, hdb⟩ simp only [zero_lt_two, Nat.div_self, ge_iff_le, Nat.Ioc_succ_singleton, zero_add, mem_singleton] at hdb have hda := hnd rw [ha.natDegree_mul hb, hdb] at hda use a.coeff 0, b.coeff 0, mul_coeff_zero a b simpa only [nextCoeff, hnd, add_right_cancel hda, hdb] using ha.nextCoeff_mul hb · rintro ⟨c₁, c₂, hmul, hadd⟩ refine ⟨X + C c₁, X + C c₂, monic_X_add_C _, monic_X_add_C _, ?_, ?_⟩ · rw [p.as_sum_range_C_mul_X_pow, hnd, Finset.sum_range_succ, Finset.sum_range_succ, Finset.sum_range_one, ← hnd, hm.coeff_natDegree, hnd, hmul, hadd, C_mul, C_add, C_1] ring · rw [mem_Ioc, natDegree_X_add_C _] simp · rintro rfl simp [natDegree_one] at hnd
/- 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, Yury Kudryashov -/ import Mathlib.Topology.Order.IsLUB /-! # Order topology on a densely ordered set -/ open Set Filter TopologicalSpace Topology Function open OrderDual (toDual ofDual) variable {α β γ : Type*} section DenselyOrdered variable [TopologicalSpace α] [LinearOrder α] [OrderTopology α] [DenselyOrdered α] {a b : α} {s : Set α} /-- The closure of the interval `(a, +∞)` is the closed interval `[a, +∞)`, unless `a` is a top element. -/ theorem closure_Ioi' {a : α} (h : (Ioi a).Nonempty) : closure (Ioi a) = Ici a := by apply Subset.antisymm · exact closure_minimal Ioi_subset_Ici_self isClosed_Ici · rw [← diff_subset_closure_iff, Ici_diff_Ioi_same, singleton_subset_iff] exact isGLB_Ioi.mem_closure h #align closure_Ioi' closure_Ioi' /-- The closure of the interval `(a, +∞)` is the closed interval `[a, +∞)`. -/ @[simp] theorem closure_Ioi (a : α) [NoMaxOrder α] : closure (Ioi a) = Ici a := closure_Ioi' nonempty_Ioi #align closure_Ioi closure_Ioi /-- The closure of the interval `(-∞, a)` is the closed interval `(-∞, a]`, unless `a` is a bottom element. -/ theorem closure_Iio' (h : (Iio a).Nonempty) : closure (Iio a) = Iic a := closure_Ioi' (α := αᵒᵈ) h #align closure_Iio' closure_Iio' /-- The closure of the interval `(-∞, a)` is the interval `(-∞, a]`. -/ @[simp] theorem closure_Iio (a : α) [NoMinOrder α] : closure (Iio a) = Iic a := closure_Iio' nonempty_Iio #align closure_Iio closure_Iio /-- The closure of the open interval `(a, b)` is the closed interval `[a, b]`. -/ @[simp] theorem closure_Ioo {a b : α} (hab : a ≠ b) : closure (Ioo a b) = Icc a b := by apply Subset.antisymm · exact closure_minimal Ioo_subset_Icc_self isClosed_Icc · cases' hab.lt_or_lt with hab hab · rw [← diff_subset_closure_iff, Icc_diff_Ioo_same hab.le] have hab' : (Ioo a b).Nonempty := nonempty_Ioo.2 hab simp only [insert_subset_iff, singleton_subset_iff] exact ⟨(isGLB_Ioo hab).mem_closure hab', (isLUB_Ioo hab).mem_closure hab'⟩ · rw [Icc_eq_empty_of_lt hab] exact empty_subset _ #align closure_Ioo closure_Ioo /-- The closure of the interval `(a, b]` is the closed interval `[a, b]`. -/ @[simp] theorem closure_Ioc {a b : α} (hab : a ≠ b) : closure (Ioc a b) = Icc a b := by apply Subset.antisymm · exact closure_minimal Ioc_subset_Icc_self isClosed_Icc · apply Subset.trans _ (closure_mono Ioo_subset_Ioc_self) rw [closure_Ioo hab] #align closure_Ioc closure_Ioc /-- The closure of the interval `[a, b)` is the closed interval `[a, b]`. -/ @[simp] theorem closure_Ico {a b : α} (hab : a ≠ b) : closure (Ico a b) = Icc a b := by apply Subset.antisymm · exact closure_minimal Ico_subset_Icc_self isClosed_Icc · apply Subset.trans _ (closure_mono Ioo_subset_Ico_self) rw [closure_Ioo hab] #align closure_Ico closure_Ico @[simp] theorem interior_Ici' {a : α} (ha : (Iio a).Nonempty) : interior (Ici a) = Ioi a := by rw [← compl_Iio, interior_compl, closure_Iio' ha, compl_Iic] #align interior_Ici' interior_Ici' theorem interior_Ici [NoMinOrder α] {a : α} : interior (Ici a) = Ioi a := interior_Ici' nonempty_Iio #align interior_Ici interior_Ici @[simp] theorem interior_Iic' {a : α} (ha : (Ioi a).Nonempty) : interior (Iic a) = Iio a := interior_Ici' (α := αᵒᵈ) ha #align interior_Iic' interior_Iic' theorem interior_Iic [NoMaxOrder α] {a : α} : interior (Iic a) = Iio a := interior_Iic' nonempty_Ioi #align interior_Iic interior_Iic @[simp] theorem interior_Icc [NoMinOrder α] [NoMaxOrder α] {a b : α} : interior (Icc a b) = Ioo a b := by rw [← Ici_inter_Iic, interior_inter, interior_Ici, interior_Iic, Ioi_inter_Iio] #align interior_Icc interior_Icc @[simp] theorem Icc_mem_nhds_iff [NoMinOrder α] [NoMaxOrder α] {a b x : α} : Icc a b ∈ 𝓝 x ↔ x ∈ Ioo a b := by rw [← interior_Icc, mem_interior_iff_mem_nhds] @[simp] theorem interior_Ico [NoMinOrder α] {a b : α} : interior (Ico a b) = Ioo a b := by rw [← Ici_inter_Iio, interior_inter, interior_Ici, interior_Iio, Ioi_inter_Iio] #align interior_Ico interior_Ico @[simp] theorem Ico_mem_nhds_iff [NoMinOrder α] {a b x : α} : Ico a b ∈ 𝓝 x ↔ x ∈ Ioo a b := by rw [← interior_Ico, mem_interior_iff_mem_nhds] @[simp] theorem interior_Ioc [NoMaxOrder α] {a b : α} : interior (Ioc a b) = Ioo a b := by rw [← Ioi_inter_Iic, interior_inter, interior_Ioi, interior_Iic, Ioi_inter_Iio] #align interior_Ioc interior_Ioc @[simp] theorem Ioc_mem_nhds_iff [NoMaxOrder α] {a b x : α} : Ioc a b ∈ 𝓝 x ↔ x ∈ Ioo a b := by rw [← interior_Ioc, mem_interior_iff_mem_nhds] theorem closure_interior_Icc {a b : α} (h : a ≠ b) : closure (interior (Icc a b)) = Icc a b := (closure_minimal interior_subset isClosed_Icc).antisymm <| calc Icc a b = closure (Ioo a b) := (closure_Ioo h).symm _ ⊆ closure (interior (Icc a b)) := closure_mono (interior_maximal Ioo_subset_Icc_self isOpen_Ioo) #align closure_interior_Icc closure_interior_Icc theorem Ioc_subset_closure_interior (a b : α) : Ioc a b ⊆ closure (interior (Ioc a b)) := by rcases eq_or_ne a b with (rfl | h) · simp · calc Ioc a b ⊆ Icc a b := Ioc_subset_Icc_self _ = closure (Ioo a b) := (closure_Ioo h).symm _ ⊆ closure (interior (Ioc a b)) := closure_mono (interior_maximal Ioo_subset_Ioc_self isOpen_Ioo) #align Ioc_subset_closure_interior Ioc_subset_closure_interior theorem Ico_subset_closure_interior (a b : α) : Ico a b ⊆ closure (interior (Ico a b)) := by simpa only [dual_Ioc] using Ioc_subset_closure_interior (OrderDual.toDual b) (OrderDual.toDual a) #align Ico_subset_closure_interior Ico_subset_closure_interior @[simp] theorem frontier_Ici' {a : α} (ha : (Iio a).Nonempty) : frontier (Ici a) = {a} := by simp [frontier, ha] #align frontier_Ici' frontier_Ici' theorem frontier_Ici [NoMinOrder α] {a : α} : frontier (Ici a) = {a} := frontier_Ici' nonempty_Iio #align frontier_Ici frontier_Ici @[simp] theorem frontier_Iic' {a : α} (ha : (Ioi a).Nonempty) : frontier (Iic a) = {a} := by simp [frontier, ha] #align frontier_Iic' frontier_Iic' theorem frontier_Iic [NoMaxOrder α] {a : α} : frontier (Iic a) = {a} := frontier_Iic' nonempty_Ioi #align frontier_Iic frontier_Iic @[simp] theorem frontier_Ioi' {a : α} (ha : (Ioi a).Nonempty) : frontier (Ioi a) = {a} := by simp [frontier, closure_Ioi' ha, Iic_diff_Iio, Icc_self] #align frontier_Ioi' frontier_Ioi' theorem frontier_Ioi [NoMaxOrder α] {a : α} : frontier (Ioi a) = {a} := frontier_Ioi' nonempty_Ioi #align frontier_Ioi frontier_Ioi @[simp] theorem frontier_Iio' {a : α} (ha : (Iio a).Nonempty) : frontier (Iio a) = {a} := by simp [frontier, closure_Iio' ha, Iic_diff_Iio, Icc_self] #align frontier_Iio' frontier_Iio' theorem frontier_Iio [NoMinOrder α] {a : α} : frontier (Iio a) = {a} := frontier_Iio' nonempty_Iio #align frontier_Iio frontier_Iio @[simp] theorem frontier_Icc [NoMinOrder α] [NoMaxOrder α] {a b : α} (h : a ≤ b) : frontier (Icc a b) = {a, b} := by simp [frontier, h, Icc_diff_Ioo_same] #align frontier_Icc frontier_Icc @[simp] theorem frontier_Ioo {a b : α} (h : a < b) : frontier (Ioo a b) = {a, b} := by rw [frontier, closure_Ioo h.ne, interior_Ioo, Icc_diff_Ioo_same h.le] #align frontier_Ioo frontier_Ioo @[simp] theorem frontier_Ico [NoMinOrder α] {a b : α} (h : a < b) : frontier (Ico a b) = {a, b} := by rw [frontier, closure_Ico h.ne, interior_Ico, Icc_diff_Ioo_same h.le] #align frontier_Ico frontier_Ico @[simp]
Mathlib/Topology/Order/DenselyOrdered.lean
202
203
theorem frontier_Ioc [NoMaxOrder α] {a b : α} (h : a < b) : frontier (Ioc a b) = {a, b} := by
rw [frontier, closure_Ioc h.ne, interior_Ioc, Icc_diff_Ioo_same h.le]
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.AlgebraicGeometry.AffineScheme import Mathlib.AlgebraicGeometry.Pullbacks import Mathlib.CategoryTheory.MorphismProperty.Limits import Mathlib.Data.List.TFAE #align_import algebraic_geometry.morphisms.basic from "leanprover-community/mathlib"@"434e2fd21c1900747afc6d13d8be7f4eedba7218" /-! # Properties of morphisms between Schemes We provide the basic framework for talking about properties of morphisms between Schemes. A `MorphismProperty Scheme` is a predicate on morphisms between schemes, and an `AffineTargetMorphismProperty` is a predicate on morphisms into affine schemes. Given a `P : AffineTargetMorphismProperty`, we may construct a `MorphismProperty` called `targetAffineLocally P` that holds for `f : X ⟶ Y` whenever `P` holds for the restriction of `f` on every affine open subset of `Y`. ## Main definitions - `AlgebraicGeometry.AffineTargetMorphismProperty.IsLocal`: We say that `P.IsLocal` if `P` satisfies the assumptions of the affine communication lemma (`AlgebraicGeometry.of_affine_open_cover`). That is, 1. `P` respects isomorphisms. 2. If `P` holds for `f : X ⟶ Y`, then `P` holds for `f ∣_ Y.basicOpen r` for any global section `r`. 3. If `P` holds for `f ∣_ Y.basicOpen r` for all `r` in a spanning set of the global sections, then `P` holds for `f`. - `AlgebraicGeometry.PropertyIsLocalAtTarget`: We say that `PropertyIsLocalAtTarget P` for `P : MorphismProperty Scheme` if 1. `P` respects isomorphisms. 2. If `P` holds for `f : X ⟶ Y`, then `P` holds for `f ∣_ U` for any `U`. 3. If `P` holds for `f ∣_ U` for an open cover `U` of `Y`, then `P` holds for `f`. ## Main results - `AlgebraicGeometry.AffineTargetMorphismProperty.IsLocal.affine_openCover_TFAE`: If `P.IsLocal`, then `targetAffineLocally P f` iff there exists an affine cover `{ Uᵢ }` of `Y` such that `P` holds for `f ∣_ Uᵢ`. - `AlgebraicGeometry.AffineTargetMorphismProperty.isLocalOfOpenCoverImply`: If the existence of an affine cover `{ Uᵢ }` of `Y` such that `P` holds for `f ∣_ Uᵢ` implies `targetAffineLocally P f`, then `P.IsLocal`. - `AlgebraicGeometry.AffineTargetMorphismProperty.IsLocal.affine_target_iff`: If `Y` is affine and `f : X ⟶ Y`, then `targetAffineLocally P f ↔ P f` provided `P.IsLocal`. - `AlgebraicGeometry.AffineTargetMorphismProperty.IsLocal.targetAffineLocallyIsLocal` : If `P.IsLocal`, then `PropertyIsLocalAtTarget (targetAffineLocally P)`. - `AlgebraicGeometry.PropertyIsLocalAtTarget.openCover_TFAE`: If `PropertyIsLocalAtTarget P`, then `P f` iff there exists an open cover `{ Uᵢ }` of `Y` such that `P` holds for `f ∣_ Uᵢ`. These results should not be used directly, and should be ported to each property that is local. -/ set_option linter.uppercaseLean3 false universe u open TopologicalSpace CategoryTheory CategoryTheory.Limits Opposite noncomputable section namespace AlgebraicGeometry /-- An `AffineTargetMorphismProperty` is a class of morphisms from an arbitrary scheme into an affine scheme. -/ def AffineTargetMorphismProperty := ∀ ⦃X Y : Scheme⦄ (_ : X ⟶ Y) [IsAffine Y], Prop #align algebraic_geometry.affine_target_morphism_property AlgebraicGeometry.AffineTargetMorphismProperty /-- `IsIso` as a `MorphismProperty`. -/ protected def Scheme.isIso : MorphismProperty Scheme := @IsIso Scheme _ #align algebraic_geometry.Scheme.is_iso AlgebraicGeometry.Scheme.isIso /-- `IsIso` as an `AffineTargetMorphismProperty`. -/ protected def Scheme.affineTargetIsIso : AffineTargetMorphismProperty := fun _ _ f _ => IsIso f #align algebraic_geometry.Scheme.affine_target_is_iso AlgebraicGeometry.Scheme.affineTargetIsIso instance : Inhabited AffineTargetMorphismProperty := ⟨Scheme.affineTargetIsIso⟩ /-- An `AffineTargetMorphismProperty` can be extended to a `MorphismProperty` such that it *never* holds when the target is not affine -/ def AffineTargetMorphismProperty.toProperty (P : AffineTargetMorphismProperty) : MorphismProperty Scheme := fun _ _ f => ∃ h, @P _ _ f h #align algebraic_geometry.affine_target_morphism_property.to_property AlgebraicGeometry.AffineTargetMorphismProperty.toProperty theorem AffineTargetMorphismProperty.toProperty_apply (P : AffineTargetMorphismProperty) {X Y : Scheme} (f : X ⟶ Y) [i : IsAffine Y] : P.toProperty f ↔ P f := by delta AffineTargetMorphismProperty.toProperty; simp [*] #align algebraic_geometry.affine_target_morphism_property.to_property_apply AlgebraicGeometry.AffineTargetMorphismProperty.toProperty_apply theorem affine_cancel_left_isIso {P : AffineTargetMorphismProperty} (hP : P.toProperty.RespectsIso) {X Y Z : Scheme} (f : X ⟶ Y) (g : Y ⟶ Z) [IsIso f] [IsAffine Z] : P (f ≫ g) ↔ P g := by rw [← P.toProperty_apply, ← P.toProperty_apply, hP.cancel_left_isIso] #align algebraic_geometry.affine_cancel_left_is_iso AlgebraicGeometry.affine_cancel_left_isIso theorem affine_cancel_right_isIso {P : AffineTargetMorphismProperty} (hP : P.toProperty.RespectsIso) {X Y Z : Scheme} (f : X ⟶ Y) (g : Y ⟶ Z) [IsIso g] [IsAffine Z] [IsAffine Y] : P (f ≫ g) ↔ P f := by rw [← P.toProperty_apply, ← P.toProperty_apply, hP.cancel_right_isIso] #align algebraic_geometry.affine_cancel_right_is_iso AlgebraicGeometry.affine_cancel_right_isIso theorem AffineTargetMorphismProperty.respectsIso_mk {P : AffineTargetMorphismProperty} (h₁ : ∀ {X Y Z} (e : X ≅ Y) (f : Y ⟶ Z) [IsAffine Z], P f → P (e.hom ≫ f)) (h₂ : ∀ {X Y Z} (e : Y ≅ Z) (f : X ⟶ Y) [h : IsAffine Y], P f → @P _ _ (f ≫ e.hom) (isAffineOfIso e.inv)) : P.toProperty.RespectsIso := by constructor · rintro X Y Z e f ⟨a, h⟩; exact ⟨a, h₁ e f h⟩ · rintro X Y Z e f ⟨a, h⟩; exact ⟨isAffineOfIso e.inv, h₂ e f h⟩ #align algebraic_geometry.affine_target_morphism_property.respects_iso_mk AlgebraicGeometry.AffineTargetMorphismProperty.respectsIso_mk /-- For a `P : AffineTargetMorphismProperty`, `targetAffineLocally P` holds for `f : X ⟶ Y` whenever `P` holds for the restriction of `f` on every affine open subset of `Y`. -/ def targetAffineLocally (P : AffineTargetMorphismProperty) : MorphismProperty Scheme := fun {X Y : Scheme} (f : X ⟶ Y) => ∀ U : Y.affineOpens, @P _ _ (f ∣_ U) U.prop #align algebraic_geometry.target_affine_locally AlgebraicGeometry.targetAffineLocally theorem IsAffineOpen.map_isIso {X Y : Scheme} {U : Opens Y.carrier} (hU : IsAffineOpen U) (f : X ⟶ Y) [IsIso f] : IsAffineOpen ((Opens.map f.1.base).obj U) := haveI : IsAffine _ := hU isAffineOfIso (f ∣_ U) #align algebraic_geometry.is_affine_open.map_is_iso AlgebraicGeometry.IsAffineOpen.map_isIso theorem targetAffineLocally_respectsIso {P : AffineTargetMorphismProperty} (hP : P.toProperty.RespectsIso) : (targetAffineLocally P).RespectsIso := by constructor · introv H U rw [morphismRestrict_comp, affine_cancel_left_isIso hP] exact H U · introv H rintro ⟨U, hU : IsAffineOpen U⟩; dsimp haveI : IsAffine _ := hU.map_isIso e.hom rw [morphismRestrict_comp, affine_cancel_right_isIso hP] exact H ⟨(Opens.map e.hom.val.base).obj U, hU.map_isIso e.hom⟩ #align algebraic_geometry.target_affine_locally_respects_iso AlgebraicGeometry.targetAffineLocally_respectsIso /-- We say that `P : AffineTargetMorphismProperty` is a local property if 1. `P` respects isomorphisms. 2. If `P` holds for `f : X ⟶ Y`, then `P` holds for `f ∣_ Y.basicOpen r` for any global section `r`. 3. If `P` holds for `f ∣_ Y.basicOpen r` for all `r` in a spanning set of the global sections, then `P` holds for `f`. -/ structure AffineTargetMorphismProperty.IsLocal (P : AffineTargetMorphismProperty) : Prop where /-- `P` as a morphism property respects isomorphisms -/ RespectsIso : P.toProperty.RespectsIso /-- `P` is stable under restriction to basic open set of global sections. -/ toBasicOpen : ∀ {X Y : Scheme} [IsAffine Y] (f : X ⟶ Y) (r : Y.presheaf.obj <| op ⊤), P f → @P _ _ (f ∣_ Y.basicOpen r) ((topIsAffineOpen Y).basicOpenIsAffine _) /-- `P` for `f` if `P` holds for `f` restricted to basic sets of a spanning set of the global sections -/ ofBasicOpenCover : ∀ {X Y : Scheme} [IsAffine Y] (f : X ⟶ Y) (s : Finset (Y.presheaf.obj <| op ⊤)) (_ : Ideal.span (s : Set (Y.presheaf.obj <| op ⊤)) = ⊤), (∀ r : s, @P _ _ (f ∣_ Y.basicOpen r.1) ((topIsAffineOpen Y).basicOpenIsAffine _)) → P f #align algebraic_geometry.affine_target_morphism_property.is_local AlgebraicGeometry.AffineTargetMorphismProperty.IsLocal /-- Specialization of `ConcreteCategory.id_apply` because `simp` can't see through the defeq. -/ @[local simp] lemma CommRingCat.id_apply (R : CommRingCat) (x : R) : 𝟙 R x = x := rfl theorem targetAffineLocallyOfOpenCover {P : AffineTargetMorphismProperty} (hP : P.IsLocal) {X Y : Scheme} (f : X ⟶ Y) (𝒰 : Y.OpenCover) [∀ i, IsAffine (𝒰.obj i)] (h𝒰 : ∀ i, P (pullback.snd : (𝒰.pullbackCover f).obj i ⟶ 𝒰.obj i)) : targetAffineLocally P f := by classical let S i := (⟨⟨Set.range (𝒰.map i).1.base, (𝒰.IsOpen i).base_open.isOpen_range⟩, rangeIsAffineOpenOfOpenImmersion (𝒰.map i)⟩ : Y.affineOpens) intro U apply of_affine_open_cover (P := _) U (Set.range S) · intro U r h haveI : IsAffine _ := U.2 have := hP.2 (f ∣_ U.1) replace this := this (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op r) h rw [← P.toProperty_apply] at this ⊢ exact (hP.1.arrow_mk_iso_iff (morphismRestrictRestrictBasicOpen f _ r)).mp this · intro U s hs H haveI : IsAffine _ := U.2 apply hP.3 (f ∣_ U.1) (s.image (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top).op)) · apply_fun Ideal.comap (Y.presheaf.map (eqToHom U.1.openEmbedding_obj_top.symm).op) at hs rw [Ideal.comap_top] at hs rw [← hs] simp only [eqToHom_op, eqToHom_map, Finset.coe_image] have : ∀ {R S : CommRingCat} (e : S = R) (s : Set S), Ideal.span (eqToHom e '' s) = Ideal.comap (eqToHom e.symm) (Ideal.span s) := by intro _ S e _ subst e simp only [eqToHom_refl, CommRingCat.id_apply, Set.image_id'] -- Porting note: Lean didn't see `𝟙 _` is just ring hom id exact (Ideal.comap_id _).symm apply this · rintro ⟨r, hr⟩ obtain ⟨r, hr', rfl⟩ := Finset.mem_image.mp hr specialize H ⟨r, hr'⟩ rw [← P.toProperty_apply] at H ⊢ exact (hP.1.arrow_mk_iso_iff (morphismRestrictRestrictBasicOpen f _ r)).mpr H · rw [Set.eq_univ_iff_forall] simp only [Set.mem_iUnion] intro x exact ⟨⟨_, ⟨𝒰.f x, rfl⟩⟩, 𝒰.Covers x⟩ · rintro ⟨_, i, rfl⟩ specialize h𝒰 i rw [← P.toProperty_apply] at h𝒰 ⊢ exact (hP.1.arrow_mk_iso_iff (morphismRestrictOpensRange f _)).mpr h𝒰 #align algebraic_geometry.target_affine_locally_of_open_cover AlgebraicGeometry.targetAffineLocallyOfOpenCover open List in theorem AffineTargetMorphismProperty.IsLocal.affine_openCover_TFAE {P : AffineTargetMorphismProperty} (hP : P.IsLocal) {X Y : Scheme.{u}} (f : X ⟶ Y) : TFAE [targetAffineLocally P f, ∃ (𝒰 : Scheme.OpenCover.{u} Y) (_ : ∀ i, IsAffine (𝒰.obj i)), ∀ i : 𝒰.J, P (pullback.snd : (𝒰.pullbackCover f).obj i ⟶ 𝒰.obj i), ∀ (𝒰 : Scheme.OpenCover.{u} Y) [∀ i, IsAffine (𝒰.obj i)] (i : 𝒰.J), P (pullback.snd : (𝒰.pullbackCover f).obj i ⟶ 𝒰.obj i), ∀ {U : Scheme} (g : U ⟶ Y) [IsAffine U] [IsOpenImmersion g], P (pullback.snd : pullback f g ⟶ U), ∃ (ι : Type u) (U : ι → Opens Y.carrier) (_ : iSup U = ⊤) (hU' : ∀ i, IsAffineOpen (U i)), ∀ i, @P _ _ (f ∣_ U i) (hU' i)] := by tfae_have 1 → 4 · intro H U g h₁ h₂ replace H := H ⟨⟨_, h₂.base_open.isOpen_range⟩, rangeIsAffineOpenOfOpenImmersion g⟩ rw [← P.toProperty_apply] at H ⊢ rwa [← hP.1.arrow_mk_iso_iff (morphismRestrictOpensRange f _)] tfae_have 4 → 3 · intro H 𝒰 h𝒰 i apply H tfae_have 3 → 2 · exact fun H => ⟨Y.affineCover, inferInstance, H Y.affineCover⟩ tfae_have 2 → 1 · rintro ⟨𝒰, h𝒰, H⟩; exact targetAffineLocallyOfOpenCover hP f 𝒰 H tfae_have 5 → 2 · rintro ⟨ι, U, hU, hU', H⟩ refine ⟨Y.openCoverOfSuprEqTop U hU, hU', ?_⟩ intro i specialize H i rw [← P.toProperty_apply, ← hP.1.arrow_mk_iso_iff (morphismRestrictOpensRange f _)] rw [← P.toProperty_apply] at H convert H all_goals ext1; exact Subtype.range_coe tfae_have 1 → 5 · intro H refine ⟨Y.carrier, fun x => (Scheme.Hom.opensRange <| Y.affineCover.map x), ?_, fun i => rangeIsAffineOpenOfOpenImmersion _, ?_⟩ · rw [eq_top_iff]; intro x _; erw [Opens.mem_iSup]; exact ⟨x, Y.affineCover.Covers x⟩ · intro i; exact H ⟨_, rangeIsAffineOpenOfOpenImmersion _⟩ tfae_finish #align algebraic_geometry.affine_target_morphism_property.is_local.affine_open_cover_tfae AlgebraicGeometry.AffineTargetMorphismProperty.IsLocal.affine_openCover_TFAE theorem AffineTargetMorphismProperty.isLocalOfOpenCoverImply (P : AffineTargetMorphismProperty) (hP : P.toProperty.RespectsIso) (H : ∀ {X Y : Scheme.{u}} (f : X ⟶ Y), (∃ (𝒰 : Scheme.OpenCover.{u} Y) (_ : ∀ i, IsAffine (𝒰.obj i)), ∀ i : 𝒰.J, P (pullback.snd : (𝒰.pullbackCover f).obj i ⟶ 𝒰.obj i)) → ∀ {U : Scheme} (g : U ⟶ Y) [IsAffine U] [IsOpenImmersion g], P (pullback.snd : pullback f g ⟶ U)) : P.IsLocal := by refine ⟨hP, ?_, ?_⟩ · introv h haveI : IsAffine _ := (topIsAffineOpen Y).basicOpenIsAffine r delta morphismRestrict rw [affine_cancel_left_isIso hP] refine @H _ _ f ⟨Scheme.openCoverOfIsIso (𝟙 Y), ?_, ?_⟩ _ (Y.ofRestrict _) _ _ · intro i; dsimp; infer_instance · intro i; dsimp rwa [← Category.comp_id pullback.snd, ← pullback.condition, affine_cancel_left_isIso hP] · introv hs hs' replace hs := ((topIsAffineOpen Y).basicOpen_union_eq_self_iff _).mpr hs have := H f ⟨Y.openCoverOfSuprEqTop _ hs, ?_, ?_⟩ (𝟙 _) · rwa [← Category.comp_id pullback.snd, ← pullback.condition, affine_cancel_left_isIso hP] at this · intro i; exact (topIsAffineOpen Y).basicOpenIsAffine _ · rintro (i : s) specialize hs' i haveI : IsAffine _ := (topIsAffineOpen Y).basicOpenIsAffine i.1 delta morphismRestrict at hs' rwa [affine_cancel_left_isIso hP] at hs' #align algebraic_geometry.affine_target_morphism_property.is_local_of_open_cover_imply AlgebraicGeometry.AffineTargetMorphismProperty.isLocalOfOpenCoverImply theorem AffineTargetMorphismProperty.IsLocal.affine_openCover_iff {P : AffineTargetMorphismProperty} (hP : P.IsLocal) {X Y : Scheme.{u}} (f : X ⟶ Y) (𝒰 : Scheme.OpenCover.{u} Y) [h𝒰 : ∀ i, IsAffine (𝒰.obj i)] : targetAffineLocally P f ↔ ∀ i, @P _ _ (pullback.snd : pullback f (𝒰.map i) ⟶ _) (h𝒰 i) := by refine ⟨fun H => let h := ((hP.affine_openCover_TFAE f).out 0 2).mp H; ?_, fun H => let h := ((hP.affine_openCover_TFAE f).out 1 0).mp; ?_⟩ · exact fun i => h 𝒰 i · exact h ⟨𝒰, inferInstance, H⟩ #align algebraic_geometry.affine_target_morphism_property.is_local.affine_open_cover_iff AlgebraicGeometry.AffineTargetMorphismProperty.IsLocal.affine_openCover_iff theorem AffineTargetMorphismProperty.IsLocal.affine_target_iff {P : AffineTargetMorphismProperty} (hP : P.IsLocal) {X Y : Scheme.{u}} (f : X ⟶ Y) [IsAffine Y] : targetAffineLocally P f ↔ P f := by haveI : ∀ i, IsAffine (Scheme.OpenCover.obj (Scheme.openCoverOfIsIso (𝟙 Y)) i) := fun i => by dsimp; infer_instance rw [hP.affine_openCover_iff f (Scheme.openCoverOfIsIso (𝟙 Y))] trans P (pullback.snd : pullback f (𝟙 _) ⟶ _) · exact ⟨fun H => H PUnit.unit, fun H _ => H⟩ rw [← Category.comp_id pullback.snd, ← pullback.condition, affine_cancel_left_isIso hP.1] #align algebraic_geometry.affine_target_morphism_property.is_local.affine_target_iff AlgebraicGeometry.AffineTargetMorphismProperty.IsLocal.affine_target_iff /-- We say that `P : MorphismProperty Scheme` is local at the target if 1. `P` respects isomorphisms. 2. If `P` holds for `f : X ⟶ Y`, then `P` holds for `f ∣_ U` for any `U`. 3. If `P` holds for `f ∣_ U` for an open cover `U` of `Y`, then `P` holds for `f`. -/ structure PropertyIsLocalAtTarget (P : MorphismProperty Scheme) : Prop where /-- `P` respects isomorphisms. -/ RespectsIso : P.RespectsIso /-- If `P` holds for `f : X ⟶ Y`, then `P` holds for `f ∣_ U` for any `U`. -/ restrict : ∀ {X Y : Scheme} (f : X ⟶ Y) (U : Opens Y.carrier), P f → P (f ∣_ U) /-- If `P` holds for `f ∣_ U` for an open cover `U` of `Y`, then `P` holds for `f`. -/ of_openCover : ∀ {X Y : Scheme.{u}} (f : X ⟶ Y) (𝒰 : Scheme.OpenCover.{u} Y), (∀ i : 𝒰.J, P (pullback.snd : (𝒰.pullbackCover f).obj i ⟶ 𝒰.obj i)) → P f #align algebraic_geometry.property_is_local_at_target AlgebraicGeometry.PropertyIsLocalAtTarget lemma propertyIsLocalAtTarget_of_morphismRestrict (P : MorphismProperty Scheme) (hP₁ : P.RespectsIso) (hP₂ : ∀ {X Y : Scheme.{u}} (f : X ⟶ Y) (U : Opens Y.carrier), P f → P (f ∣_ U)) (hP₃ : ∀ {X Y : Scheme.{u}} (f : X ⟶ Y) {ι : Type u} (U : ι → Opens Y.carrier) (_ : iSup U = ⊤), (∀ i, P (f ∣_ U i)) → P f) : PropertyIsLocalAtTarget P where RespectsIso := hP₁ restrict := hP₂ of_openCover {X Y} f 𝒰 h𝒰 := by apply hP₃ f (fun i : 𝒰.J => Scheme.Hom.opensRange (𝒰.map i)) 𝒰.iSup_opensRange simp_rw [hP₁.arrow_mk_iso_iff (morphismRestrictOpensRange f _)] exact h𝒰 theorem AffineTargetMorphismProperty.IsLocal.targetAffineLocallyIsLocal {P : AffineTargetMorphismProperty} (hP : P.IsLocal) : PropertyIsLocalAtTarget (targetAffineLocally P) := by constructor · exact targetAffineLocally_respectsIso hP.1 · intro X Y f U H V rw [← P.toProperty_apply (i := V.2), hP.1.arrow_mk_iso_iff (morphismRestrictRestrict f _ _)] convert H ⟨_, IsAffineOpen.imageIsOpenImmersion V.2 (Y.ofRestrict _)⟩ rw [← P.toProperty_apply] · rintro X Y f 𝒰 h𝒰 -- Porting note: rewrite `[(hP.affine_openCover_TFAE f).out 0 1` directly complains about -- metavariables have h01 := (hP.affine_openCover_TFAE f).out 0 1 rw [h01] refine ⟨𝒰.bind fun _ => Scheme.affineCover _, ?_, ?_⟩ · intro i; dsimp [Scheme.OpenCover.bind]; infer_instance · intro i specialize h𝒰 i.1 -- Porting note: rewrite `[(hP.affine_openCover_TFAE pullback.snd).out 0 1` directly -- complains about metavariables have h02 := (hP.affine_openCover_TFAE (pullback.snd : pullback f (𝒰.map i.fst) ⟶ _)).out 0 2 rw [h02] at h𝒰 specialize h𝒰 (Scheme.affineCover _) i.2 let e : pullback f ((𝒰.obj i.fst).affineCover.map i.snd ≫ 𝒰.map i.fst) ⟶ pullback (pullback.snd : pullback f (𝒰.map i.fst) ⟶ _) ((𝒰.obj i.fst).affineCover.map i.snd) := by refine (pullbackSymmetry _ _).hom ≫ ?_ refine (pullbackRightPullbackFstIso _ _ _).inv ≫ ?_ refine (pullbackSymmetry _ _).hom ≫ ?_ refine pullback.map _ _ _ _ (pullbackSymmetry _ _).hom (𝟙 _) (𝟙 _) ?_ ?_ <;> simp only [Category.comp_id, Category.id_comp, pullbackSymmetry_hom_comp_snd] rw [← affine_cancel_left_isIso hP.1 e] at h𝒰 convert h𝒰 using 1 simp [e] #align algebraic_geometry.affine_target_morphism_property.is_local.target_affine_locally_is_local AlgebraicGeometry.AffineTargetMorphismProperty.IsLocal.targetAffineLocallyIsLocal open List in theorem PropertyIsLocalAtTarget.openCover_TFAE {P : MorphismProperty Scheme} (hP : PropertyIsLocalAtTarget P) {X Y : Scheme.{u}} (f : X ⟶ Y) : TFAE [P f, ∃ 𝒰 : Scheme.OpenCover.{u} Y, ∀ i : 𝒰.J, P (pullback.snd : (𝒰.pullbackCover f).obj i ⟶ 𝒰.obj i), ∀ (𝒰 : Scheme.OpenCover.{u} Y) (i : 𝒰.J), P (pullback.snd : (𝒰.pullbackCover f).obj i ⟶ 𝒰.obj i), ∀ U : Opens Y.carrier, P (f ∣_ U), ∀ {U : Scheme} (g : U ⟶ Y) [IsOpenImmersion g], P (pullback.snd : pullback f g ⟶ U), ∃ (ι : Type u) (U : ι → Opens Y.carrier) (_ : iSup U = ⊤), ∀ i, P (f ∣_ U i)] := by tfae_have 2 → 1 · rintro ⟨𝒰, H⟩; exact hP.3 f 𝒰 H tfae_have 1 → 4 · intro H U; exact hP.2 f U H tfae_have 4 → 3 · intro H 𝒰 i rw [← hP.1.arrow_mk_iso_iff (morphismRestrictOpensRange f _)] exact H <| Scheme.Hom.opensRange (𝒰.map i) tfae_have 3 → 2 · exact fun H => ⟨Y.affineCover, H Y.affineCover⟩ tfae_have 4 → 5 · intro H U g hg rw [← hP.1.arrow_mk_iso_iff (morphismRestrictOpensRange f _)] apply H tfae_have 5 → 4 · intro H U erw [hP.1.cancel_left_isIso] apply H tfae_have 4 → 6 · intro H; exact ⟨PUnit, fun _ => ⊤, ciSup_const, fun _ => H _⟩ tfae_have 6 → 2 · rintro ⟨ι, U, hU, H⟩ refine ⟨Y.openCoverOfSuprEqTop U hU, ?_⟩ intro i rw [← hP.1.arrow_mk_iso_iff (morphismRestrictOpensRange f _)] convert H i all_goals ext1; exact Subtype.range_coe tfae_finish #align algebraic_geometry.property_is_local_at_target.open_cover_tfae AlgebraicGeometry.PropertyIsLocalAtTarget.openCover_TFAE theorem PropertyIsLocalAtTarget.openCover_iff {P : MorphismProperty Scheme} (hP : PropertyIsLocalAtTarget P) {X Y : Scheme.{u}} (f : X ⟶ Y) (𝒰 : Scheme.OpenCover.{u} Y) : P f ↔ ∀ i, P (pullback.snd : pullback f (𝒰.map i) ⟶ _) := by -- Porting note: couldn't get the term mode proof work refine ⟨fun H => let h := ((hP.openCover_TFAE f).out 0 2).mp H; fun i => ?_, fun H => let h := ((hP.openCover_TFAE f).out 1 0).mp; ?_⟩ · exact h 𝒰 i · exact h ⟨𝒰, H⟩ #align algebraic_geometry.property_is_local_at_target.open_cover_iff AlgebraicGeometry.PropertyIsLocalAtTarget.openCover_iff namespace AffineTargetMorphismProperty /-- A `P : AffineTargetMorphismProperty` is stable under base change if `P` holds for `Y ⟶ S` implies that `P` holds for `X ×ₛ Y ⟶ X` with `X` and `S` affine schemes. -/ def StableUnderBaseChange (P : AffineTargetMorphismProperty) : Prop := ∀ ⦃X Y S : Scheme⦄ [IsAffine S] [IsAffine X] (f : X ⟶ S) (g : Y ⟶ S), P g → P (pullback.fst : pullback f g ⟶ X) #align algebraic_geometry.affine_target_morphism_property.stable_under_base_change AlgebraicGeometry.AffineTargetMorphismProperty.StableUnderBaseChange theorem IsLocal.targetAffineLocallyPullbackFstOfRightOfStableUnderBaseChange {P : AffineTargetMorphismProperty} (hP : P.IsLocal) (hP' : P.StableUnderBaseChange) {X Y S : Scheme} (f : X ⟶ S) (g : Y ⟶ S) [IsAffine S] (H : P g) : targetAffineLocally P (pullback.fst : pullback f g ⟶ X) := by -- Porting note: rewrite `(hP.affine_openCover_TFAE ...).out 0 1` doesn't work have h01 := (hP.affine_openCover_TFAE (pullback.fst : pullback f g ⟶ X)).out 0 1 rw [h01] use X.affineCover, inferInstance intro i let e := pullbackSymmetry _ _ ≪≫ pullbackRightPullbackFstIso f g (X.affineCover.map i) have : e.hom ≫ pullback.fst = pullback.snd := by simp [e] rw [← this, affine_cancel_left_isIso hP.1] apply hP'; assumption #align algebraic_geometry.affine_target_morphism_property.is_local.target_affine_locally_pullback_fst_of_right_of_stable_under_base_change AlgebraicGeometry.AffineTargetMorphismProperty.IsLocal.targetAffineLocallyPullbackFstOfRightOfStableUnderBaseChange theorem IsLocal.stableUnderBaseChange {P : AffineTargetMorphismProperty} (hP : P.IsLocal) (hP' : P.StableUnderBaseChange) : (targetAffineLocally P).StableUnderBaseChange := MorphismProperty.StableUnderBaseChange.mk (targetAffineLocally_respectsIso hP.RespectsIso) (fun X Y S f g H => by -- Porting note: rewrite `(...openCover_TFAE).out 0 1` directly doesn't work, complains about -- metavariable have h01 := (hP.targetAffineLocallyIsLocal.openCover_TFAE (pullback.fst : pullback f g ⟶ X)).out 0 1 rw [h01] use S.affineCover.pullbackCover f intro i -- Porting note: rewrite `(hP.affine_openCover_TFAE g).out 0 3` directly doesn't work -- complains about metavariable have h03 := (hP.affine_openCover_TFAE g).out 0 3 rw [h03] at H let e : pullback (pullback.fst : pullback f g ⟶ _) ((S.affineCover.pullbackCover f).map i) ≅ _ := by refine pullbackSymmetry _ _ ≪≫ pullbackRightPullbackFstIso f g _ ≪≫ ?_ ≪≫ (pullbackRightPullbackFstIso (S.affineCover.map i) g (pullback.snd : pullback f (S.affineCover.map i) ⟶ _)).symm exact asIso (pullback.map _ _ _ _ (𝟙 _) (𝟙 _) (𝟙 _) (by simpa using pullback.condition) (by simp)) have : e.hom ≫ pullback.fst = pullback.snd := by simp [e] rw [← this, (targetAffineLocally_respectsIso hP.1).cancel_left_isIso] apply hP.targetAffineLocallyPullbackFstOfRightOfStableUnderBaseChange hP' rw [← pullbackSymmetry_hom_comp_snd, affine_cancel_left_isIso hP.1] apply H) #align algebraic_geometry.affine_target_morphism_property.is_local.stable_under_base_change AlgebraicGeometry.AffineTargetMorphismProperty.IsLocal.stableUnderBaseChange end AffineTargetMorphismProperty /-- The `AffineTargetMorphismProperty` associated to `(targetAffineLocally P).diagonal`. See `diagonal_targetAffineLocally_eq_targetAffineLocally`. -/ def AffineTargetMorphismProperty.diagonal (P : AffineTargetMorphismProperty) : AffineTargetMorphismProperty := fun {X _} f _ => ∀ {U₁ U₂ : Scheme} (f₁ : U₁ ⟶ X) (f₂ : U₂ ⟶ X) [IsAffine U₁] [IsAffine U₂] [IsOpenImmersion f₁] [IsOpenImmersion f₂], P (pullback.mapDesc f₁ f₂ f) #align algebraic_geometry.affine_target_morphism_property.diagonal AlgebraicGeometry.AffineTargetMorphismProperty.diagonal theorem AffineTargetMorphismProperty.diagonal_respectsIso (P : AffineTargetMorphismProperty) (hP : P.toProperty.RespectsIso) : P.diagonal.toProperty.RespectsIso := by delta AffineTargetMorphismProperty.diagonal apply AffineTargetMorphismProperty.respectsIso_mk · introv H _ _ rw [pullback.mapDesc_comp, affine_cancel_left_isIso hP, affine_cancel_right_isIso hP] -- Porting note: add the following two instances have i1 : IsOpenImmersion (f₁ ≫ e.hom) := PresheafedSpace.IsOpenImmersion.comp _ _ have i2 : IsOpenImmersion (f₂ ≫ e.hom) := PresheafedSpace.IsOpenImmersion.comp _ _ apply H · introv H _ _ -- Porting note: add the following two instances have _ : IsAffine Z := isAffineOfIso e.inv rw [pullback.mapDesc_comp, affine_cancel_right_isIso hP] apply H #align algebraic_geometry.affine_target_morphism_property.diagonal_respects_iso AlgebraicGeometry.AffineTargetMorphismProperty.diagonal_respectsIso
Mathlib/AlgebraicGeometry/Morphisms/Basic.lean
507
524
theorem diagonalTargetAffineLocallyOfOpenCover (P : AffineTargetMorphismProperty) (hP : P.IsLocal) {X Y : Scheme.{u}} (f : X ⟶ Y) (𝒰 : Scheme.OpenCover.{u} Y) [∀ i, IsAffine (𝒰.obj i)] (𝒰' : ∀ i, Scheme.OpenCover.{u} (pullback f (𝒰.map i))) [∀ i j, IsAffine ((𝒰' i).obj j)] (h𝒰' : ∀ i j k, P (pullback.mapDesc ((𝒰' i).map j) ((𝒰' i).map k) pullback.snd)) : (targetAffineLocally P).diagonal f := by
let 𝒱 := (Scheme.Pullback.openCoverOfBase 𝒰 f f).bind fun i => Scheme.Pullback.openCoverOfLeftRight.{u} (𝒰' i) (𝒰' i) pullback.snd pullback.snd have i1 : ∀ i, IsAffine (𝒱.obj i) := fun i => by dsimp [𝒱]; infer_instance apply (hP.affine_openCover_iff _ 𝒱).mpr rintro ⟨i, j, k⟩ dsimp [𝒱] convert (affine_cancel_left_isIso hP.1 (pullbackDiagonalMapIso _ _ ((𝒰' i).map j) ((𝒰' i).map k)).inv pullback.snd).mp _ pick_goal 3 · convert h𝒰' i j k; apply pullback.hom_ext <;> simp all_goals apply pullback.hom_ext <;> simp only [Category.assoc, pullback.lift_fst, pullback.lift_snd, pullback.lift_fst_assoc, pullback.lift_snd_assoc]
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir -/ import Mathlib.Algebra.Order.CauSeq.BigOperators import Mathlib.Data.Complex.Abs import Mathlib.Data.Complex.BigOperators import Mathlib.Data.Nat.Choose.Sum #align_import data.complex.exponential from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Exponential, trigonometric and hyperbolic trigonometric functions This file contains the definitions of the real and complex exponential, sine, cosine, tangent, hyperbolic sine, hyperbolic cosine, and hyperbolic tangent functions. -/ open CauSeq Finset IsAbsoluteValue open scoped Classical ComplexConjugate namespace Complex theorem isCauSeq_abs_exp (z : ℂ) : IsCauSeq _root_.abs fun n => ∑ m ∈ range n, abs (z ^ m / m.factorial) := let ⟨n, hn⟩ := exists_nat_gt (abs z) have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (abs.nonneg _) hn IsCauSeq.series_ratio_test n (abs z / n) (div_nonneg (abs.nonneg _) (le_of_lt hn0)) (by rwa [div_lt_iff hn0, one_mul]) fun m hm => by rw [abs_abs, abs_abs, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul, ← div_div, mul_div_assoc, mul_div_right_comm, map_mul, map_div₀, abs_natCast] gcongr exact le_trans hm (Nat.le_succ _) #align complex.is_cau_abs_exp Complex.isCauSeq_abs_exp noncomputable section theorem isCauSeq_exp (z : ℂ) : IsCauSeq abs fun n => ∑ m ∈ range n, z ^ m / m.factorial := (isCauSeq_abs_exp z).of_abv #align complex.is_cau_exp Complex.isCauSeq_exp /-- The Cauchy sequence consisting of partial sums of the Taylor series of the complex exponential function -/ -- Porting note (#11180): removed `@[pp_nodot]` def exp' (z : ℂ) : CauSeq ℂ Complex.abs := ⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩ #align complex.exp' Complex.exp' /-- The complex exponential function, defined via its Taylor series -/ -- Porting note (#11180): removed `@[pp_nodot]` -- Porting note: removed `irreducible` attribute, so I can prove things def exp (z : ℂ) : ℂ := CauSeq.lim (exp' z) #align complex.exp Complex.exp /-- The complex sine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def sin (z : ℂ) : ℂ := (exp (-z * I) - exp (z * I)) * I / 2 #align complex.sin Complex.sin /-- The complex cosine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def cos (z : ℂ) : ℂ := (exp (z * I) + exp (-z * I)) / 2 #align complex.cos Complex.cos /-- The complex tangent function, defined as `sin z / cos z` -/ -- Porting note (#11180): removed `@[pp_nodot]` def tan (z : ℂ) : ℂ := sin z / cos z #align complex.tan Complex.tan /-- The complex cotangent function, defined as `cos z / sin z` -/ def cot (z : ℂ) : ℂ := cos z / sin z /-- The complex hyperbolic sine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def sinh (z : ℂ) : ℂ := (exp z - exp (-z)) / 2 #align complex.sinh Complex.sinh /-- The complex hyperbolic cosine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def cosh (z : ℂ) : ℂ := (exp z + exp (-z)) / 2 #align complex.cosh Complex.cosh /-- The complex hyperbolic tangent function, defined as `sinh z / cosh z` -/ -- Porting note (#11180): removed `@[pp_nodot]` def tanh (z : ℂ) : ℂ := sinh z / cosh z #align complex.tanh Complex.tanh /-- scoped notation for the complex exponential function -/ scoped notation "cexp" => Complex.exp end end Complex namespace Real open Complex noncomputable section /-- The real exponential function, defined as the real part of the complex exponential -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def exp (x : ℝ) : ℝ := (exp x).re #align real.exp Real.exp /-- The real sine function, defined as the real part of the complex sine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def sin (x : ℝ) : ℝ := (sin x).re #align real.sin Real.sin /-- The real cosine function, defined as the real part of the complex cosine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def cos (x : ℝ) : ℝ := (cos x).re #align real.cos Real.cos /-- The real tangent function, defined as the real part of the complex tangent -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def tan (x : ℝ) : ℝ := (tan x).re #align real.tan Real.tan /-- The real cotangent function, defined as the real part of the complex cotangent -/ nonrec def cot (x : ℝ) : ℝ := (cot x).re /-- The real hypebolic sine function, defined as the real part of the complex hyperbolic sine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def sinh (x : ℝ) : ℝ := (sinh x).re #align real.sinh Real.sinh /-- The real hypebolic cosine function, defined as the real part of the complex hyperbolic cosine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def cosh (x : ℝ) : ℝ := (cosh x).re #align real.cosh Real.cosh /-- The real hypebolic tangent function, defined as the real part of the complex hyperbolic tangent -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def tanh (x : ℝ) : ℝ := (tanh x).re #align real.tanh Real.tanh /-- scoped notation for the real exponential function -/ scoped notation "rexp" => Real.exp end end Real namespace Complex variable (x y : ℂ) @[simp] theorem exp_zero : exp 0 = 1 := by rw [exp] refine lim_eq_of_equiv_const fun ε ε0 => ⟨1, fun j hj => ?_⟩ convert (config := .unfoldSameFun) ε0 -- Porting note: ε0 : ε > 0 but goal is _ < ε cases' j with j j · exact absurd hj (not_le_of_gt zero_lt_one) · dsimp [exp'] induction' j with j ih · dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl] · rw [← ih (by simp [Nat.succ_le_succ])] simp only [sum_range_succ, pow_succ] simp #align complex.exp_zero Complex.exp_zero theorem exp_add : exp (x + y) = exp x * exp y := by have hj : ∀ j : ℕ, (∑ m ∈ range j, (x + y) ^ m / m.factorial) = ∑ i ∈ range j, ∑ k ∈ range (i + 1), x ^ k / k.factorial * (y ^ (i - k) / (i - k).factorial) := by intro j refine Finset.sum_congr rfl fun m _ => ?_ rw [add_pow, div_eq_mul_inv, sum_mul] refine Finset.sum_congr rfl fun I hi => ?_ have h₁ : (m.choose I : ℂ) ≠ 0 := Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi)))) have h₂ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi) rw [← h₂, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv] simp only [mul_left_comm (m.choose I : ℂ), mul_assoc, mul_left_comm (m.choose I : ℂ)⁻¹, mul_comm (m.choose I : ℂ)] rw [inv_mul_cancel h₁] simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm] simp_rw [exp, exp', lim_mul_lim] apply (lim_eq_lim_of_equiv _).symm simp only [hj] exact cauchy_product (isCauSeq_abs_exp x) (isCauSeq_exp y) #align complex.exp_add Complex.exp_add -- Porting note (#11445): new definition /-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/ noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ := { toFun := fun z => exp (Multiplicative.toAdd z), map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List ℂ) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative ℂ) expMonoidHom l #align complex.exp_list_sum Complex.exp_list_sum theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s #align complex.exp_multiset_sum Complex.exp_multiset_sum theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) : exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (β := Multiplicative ℂ) expMonoidHom f s #align complex.exp_sum Complex.exp_sum lemma exp_nsmul (x : ℂ) (n : ℕ) : exp (n • x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative ℂ) ℂ _ _ expMonoidHom _ _ theorem exp_nat_mul (x : ℂ) : ∀ n : ℕ, exp (n * x) = exp x ^ n | 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero] | Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul] #align complex.exp_nat_mul Complex.exp_nat_mul theorem exp_ne_zero : exp x ≠ 0 := fun h => zero_ne_one <| by rw [← exp_zero, ← add_neg_self x, exp_add, h]; simp #align complex.exp_ne_zero Complex.exp_ne_zero theorem exp_neg : exp (-x) = (exp x)⁻¹ := by rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancel (exp_ne_zero x)] #align complex.exp_neg Complex.exp_neg theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] #align complex.exp_sub Complex.exp_sub theorem exp_int_mul (z : ℂ) (n : ℤ) : Complex.exp (n * z) = Complex.exp z ^ n := by cases n · simp [exp_nat_mul] · simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul] #align complex.exp_int_mul Complex.exp_int_mul @[simp] theorem exp_conj : exp (conj x) = conj (exp x) := by dsimp [exp] rw [← lim_conj] refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_) dsimp [exp', Function.comp_def, cauSeqConj] rw [map_sum (starRingEnd _)] refine sum_congr rfl fun n _ => ?_ rw [map_div₀, map_pow, ← ofReal_natCast, conj_ofReal] #align complex.exp_conj Complex.exp_conj @[simp] theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x := conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal] #align complex.of_real_exp_of_real_re Complex.ofReal_exp_ofReal_re @[simp, norm_cast] theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x := ofReal_exp_ofReal_re _ #align complex.of_real_exp Complex.ofReal_exp @[simp] theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im] #align complex.exp_of_real_im Complex.exp_ofReal_im theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x := rfl #align complex.exp_of_real_re Complex.exp_ofReal_re theorem two_sinh : 2 * sinh x = exp x - exp (-x) := mul_div_cancel₀ _ two_ne_zero #align complex.two_sinh Complex.two_sinh theorem two_cosh : 2 * cosh x = exp x + exp (-x) := mul_div_cancel₀ _ two_ne_zero #align complex.two_cosh Complex.two_cosh @[simp] theorem sinh_zero : sinh 0 = 0 := by simp [sinh] #align complex.sinh_zero Complex.sinh_zero @[simp] theorem sinh_neg : sinh (-x) = -sinh x := by simp [sinh, exp_neg, (neg_div _ _).symm, add_mul] #align complex.sinh_neg Complex.sinh_neg private theorem sinh_add_aux {a b c d : ℂ} : (a - b) * (c + d) + (a + b) * (c - d) = 2 * (a * c - b * d) := by ring theorem sinh_add : sinh (x + y) = sinh x * cosh y + cosh x * sinh y := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_sinh, exp_add, neg_add, exp_add, eq_comm, mul_add, ← mul_assoc, two_sinh, mul_left_comm, two_sinh, ← mul_right_inj' (two_ne_zero' ℂ), mul_add, mul_left_comm, two_cosh, ← mul_assoc, two_cosh] exact sinh_add_aux #align complex.sinh_add Complex.sinh_add @[simp] theorem cosh_zero : cosh 0 = 1 := by simp [cosh] #align complex.cosh_zero Complex.cosh_zero @[simp] theorem cosh_neg : cosh (-x) = cosh x := by simp [add_comm, cosh, exp_neg] #align complex.cosh_neg Complex.cosh_neg private theorem cosh_add_aux {a b c d : ℂ} : (a + b) * (c + d) + (a - b) * (c - d) = 2 * (a * c + b * d) := by ring theorem cosh_add : cosh (x + y) = cosh x * cosh y + sinh x * sinh y := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_cosh, exp_add, neg_add, exp_add, eq_comm, mul_add, ← mul_assoc, two_cosh, ← mul_assoc, two_sinh, ← mul_right_inj' (two_ne_zero' ℂ), mul_add, mul_left_comm, two_cosh, mul_left_comm, two_sinh] exact cosh_add_aux #align complex.cosh_add Complex.cosh_add theorem sinh_sub : sinh (x - y) = sinh x * cosh y - cosh x * sinh y := by simp [sub_eq_add_neg, sinh_add, sinh_neg, cosh_neg] #align complex.sinh_sub Complex.sinh_sub theorem cosh_sub : cosh (x - y) = cosh x * cosh y - sinh x * sinh y := by simp [sub_eq_add_neg, cosh_add, sinh_neg, cosh_neg] #align complex.cosh_sub Complex.cosh_sub theorem sinh_conj : sinh (conj x) = conj (sinh x) := by rw [sinh, ← RingHom.map_neg, exp_conj, exp_conj, ← RingHom.map_sub, sinh, map_div₀] -- Porting note: not nice simp [← one_add_one_eq_two] #align complex.sinh_conj Complex.sinh_conj @[simp] theorem ofReal_sinh_ofReal_re (x : ℝ) : ((sinh x).re : ℂ) = sinh x := conj_eq_iff_re.1 <| by rw [← sinh_conj, conj_ofReal] #align complex.of_real_sinh_of_real_re Complex.ofReal_sinh_ofReal_re @[simp, norm_cast] theorem ofReal_sinh (x : ℝ) : (Real.sinh x : ℂ) = sinh x := ofReal_sinh_ofReal_re _ #align complex.of_real_sinh Complex.ofReal_sinh @[simp] theorem sinh_ofReal_im (x : ℝ) : (sinh x).im = 0 := by rw [← ofReal_sinh_ofReal_re, ofReal_im] #align complex.sinh_of_real_im Complex.sinh_ofReal_im theorem sinh_ofReal_re (x : ℝ) : (sinh x).re = Real.sinh x := rfl #align complex.sinh_of_real_re Complex.sinh_ofReal_re theorem cosh_conj : cosh (conj x) = conj (cosh x) := by rw [cosh, ← RingHom.map_neg, exp_conj, exp_conj, ← RingHom.map_add, cosh, map_div₀] -- Porting note: not nice simp [← one_add_one_eq_two] #align complex.cosh_conj Complex.cosh_conj theorem ofReal_cosh_ofReal_re (x : ℝ) : ((cosh x).re : ℂ) = cosh x := conj_eq_iff_re.1 <| by rw [← cosh_conj, conj_ofReal] #align complex.of_real_cosh_of_real_re Complex.ofReal_cosh_ofReal_re @[simp, norm_cast] theorem ofReal_cosh (x : ℝ) : (Real.cosh x : ℂ) = cosh x := ofReal_cosh_ofReal_re _ #align complex.of_real_cosh Complex.ofReal_cosh @[simp] theorem cosh_ofReal_im (x : ℝ) : (cosh x).im = 0 := by rw [← ofReal_cosh_ofReal_re, ofReal_im] #align complex.cosh_of_real_im Complex.cosh_ofReal_im @[simp] theorem cosh_ofReal_re (x : ℝ) : (cosh x).re = Real.cosh x := rfl #align complex.cosh_of_real_re Complex.cosh_ofReal_re theorem tanh_eq_sinh_div_cosh : tanh x = sinh x / cosh x := rfl #align complex.tanh_eq_sinh_div_cosh Complex.tanh_eq_sinh_div_cosh @[simp] theorem tanh_zero : tanh 0 = 0 := by simp [tanh] #align complex.tanh_zero Complex.tanh_zero @[simp] theorem tanh_neg : tanh (-x) = -tanh x := by simp [tanh, neg_div] #align complex.tanh_neg Complex.tanh_neg theorem tanh_conj : tanh (conj x) = conj (tanh x) := by rw [tanh, sinh_conj, cosh_conj, ← map_div₀, tanh] #align complex.tanh_conj Complex.tanh_conj @[simp] theorem ofReal_tanh_ofReal_re (x : ℝ) : ((tanh x).re : ℂ) = tanh x := conj_eq_iff_re.1 <| by rw [← tanh_conj, conj_ofReal] #align complex.of_real_tanh_of_real_re Complex.ofReal_tanh_ofReal_re @[simp, norm_cast] theorem ofReal_tanh (x : ℝ) : (Real.tanh x : ℂ) = tanh x := ofReal_tanh_ofReal_re _ #align complex.of_real_tanh Complex.ofReal_tanh @[simp] theorem tanh_ofReal_im (x : ℝ) : (tanh x).im = 0 := by rw [← ofReal_tanh_ofReal_re, ofReal_im] #align complex.tanh_of_real_im Complex.tanh_ofReal_im theorem tanh_ofReal_re (x : ℝ) : (tanh x).re = Real.tanh x := rfl #align complex.tanh_of_real_re Complex.tanh_ofReal_re @[simp] theorem cosh_add_sinh : cosh x + sinh x = exp x := by rw [← mul_right_inj' (two_ne_zero' ℂ), mul_add, two_cosh, two_sinh, add_add_sub_cancel, two_mul] #align complex.cosh_add_sinh Complex.cosh_add_sinh @[simp] theorem sinh_add_cosh : sinh x + cosh x = exp x := by rw [add_comm, cosh_add_sinh] #align complex.sinh_add_cosh Complex.sinh_add_cosh @[simp] theorem exp_sub_cosh : exp x - cosh x = sinh x := sub_eq_iff_eq_add.2 (sinh_add_cosh x).symm #align complex.exp_sub_cosh Complex.exp_sub_cosh @[simp] theorem exp_sub_sinh : exp x - sinh x = cosh x := sub_eq_iff_eq_add.2 (cosh_add_sinh x).symm #align complex.exp_sub_sinh Complex.exp_sub_sinh @[simp] theorem cosh_sub_sinh : cosh x - sinh x = exp (-x) := by rw [← mul_right_inj' (two_ne_zero' ℂ), mul_sub, two_cosh, two_sinh, add_sub_sub_cancel, two_mul] #align complex.cosh_sub_sinh Complex.cosh_sub_sinh @[simp] theorem sinh_sub_cosh : sinh x - cosh x = -exp (-x) := by rw [← neg_sub, cosh_sub_sinh] #align complex.sinh_sub_cosh Complex.sinh_sub_cosh @[simp] theorem cosh_sq_sub_sinh_sq : cosh x ^ 2 - sinh x ^ 2 = 1 := by rw [sq_sub_sq, cosh_add_sinh, cosh_sub_sinh, ← exp_add, add_neg_self, exp_zero] #align complex.cosh_sq_sub_sinh_sq Complex.cosh_sq_sub_sinh_sq theorem cosh_sq : cosh x ^ 2 = sinh x ^ 2 + 1 := by rw [← cosh_sq_sub_sinh_sq x] ring #align complex.cosh_sq Complex.cosh_sq theorem sinh_sq : sinh x ^ 2 = cosh x ^ 2 - 1 := by rw [← cosh_sq_sub_sinh_sq x] ring #align complex.sinh_sq Complex.sinh_sq theorem cosh_two_mul : cosh (2 * x) = cosh x ^ 2 + sinh x ^ 2 := by rw [two_mul, cosh_add, sq, sq] #align complex.cosh_two_mul Complex.cosh_two_mul theorem sinh_two_mul : sinh (2 * x) = 2 * sinh x * cosh x := by rw [two_mul, sinh_add] ring #align complex.sinh_two_mul Complex.sinh_two_mul theorem cosh_three_mul : cosh (3 * x) = 4 * cosh x ^ 3 - 3 * cosh x := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, cosh_add x (2 * x)] simp only [cosh_two_mul, sinh_two_mul] have h2 : sinh x * (2 * sinh x * cosh x) = 2 * cosh x * sinh x ^ 2 := by ring rw [h2, sinh_sq] ring #align complex.cosh_three_mul Complex.cosh_three_mul theorem sinh_three_mul : sinh (3 * x) = 4 * sinh x ^ 3 + 3 * sinh x := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, sinh_add x (2 * x)] simp only [cosh_two_mul, sinh_two_mul] have h2 : cosh x * (2 * sinh x * cosh x) = 2 * sinh x * cosh x ^ 2 := by ring rw [h2, cosh_sq] ring #align complex.sinh_three_mul Complex.sinh_three_mul @[simp] theorem sin_zero : sin 0 = 0 := by simp [sin] #align complex.sin_zero Complex.sin_zero @[simp] theorem sin_neg : sin (-x) = -sin x := by simp [sin, sub_eq_add_neg, exp_neg, (neg_div _ _).symm, add_mul] #align complex.sin_neg Complex.sin_neg theorem two_sin : 2 * sin x = (exp (-x * I) - exp (x * I)) * I := mul_div_cancel₀ _ two_ne_zero #align complex.two_sin Complex.two_sin theorem two_cos : 2 * cos x = exp (x * I) + exp (-x * I) := mul_div_cancel₀ _ two_ne_zero #align complex.two_cos Complex.two_cos theorem sinh_mul_I : sinh (x * I) = sin x * I := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_sinh, ← mul_assoc, two_sin, mul_assoc, I_mul_I, mul_neg_one, neg_sub, neg_mul_eq_neg_mul] set_option linter.uppercaseLean3 false in #align complex.sinh_mul_I Complex.sinh_mul_I theorem cosh_mul_I : cosh (x * I) = cos x := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_cosh, two_cos, neg_mul_eq_neg_mul] set_option linter.uppercaseLean3 false in #align complex.cosh_mul_I Complex.cosh_mul_I theorem tanh_mul_I : tanh (x * I) = tan x * I := by rw [tanh_eq_sinh_div_cosh, cosh_mul_I, sinh_mul_I, mul_div_right_comm, tan] set_option linter.uppercaseLean3 false in #align complex.tanh_mul_I Complex.tanh_mul_I theorem cos_mul_I : cos (x * I) = cosh x := by rw [← cosh_mul_I]; ring_nf; simp set_option linter.uppercaseLean3 false in #align complex.cos_mul_I Complex.cos_mul_I theorem sin_mul_I : sin (x * I) = sinh x * I := by have h : I * sin (x * I) = -sinh x := by rw [mul_comm, ← sinh_mul_I] ring_nf simp rw [← neg_neg (sinh x), ← h] apply Complex.ext <;> simp set_option linter.uppercaseLean3 false in #align complex.sin_mul_I Complex.sin_mul_I theorem tan_mul_I : tan (x * I) = tanh x * I := by rw [tan, sin_mul_I, cos_mul_I, mul_div_right_comm, tanh_eq_sinh_div_cosh] set_option linter.uppercaseLean3 false in #align complex.tan_mul_I Complex.tan_mul_I theorem sin_add : sin (x + y) = sin x * cos y + cos x * sin y := by rw [← mul_left_inj' I_ne_zero, ← sinh_mul_I, add_mul, add_mul, mul_right_comm, ← sinh_mul_I, mul_assoc, ← sinh_mul_I, ← cosh_mul_I, ← cosh_mul_I, sinh_add] #align complex.sin_add Complex.sin_add @[simp] theorem cos_zero : cos 0 = 1 := by simp [cos] #align complex.cos_zero Complex.cos_zero @[simp] theorem cos_neg : cos (-x) = cos x := by simp [cos, sub_eq_add_neg, exp_neg, add_comm] #align complex.cos_neg Complex.cos_neg private theorem cos_add_aux {a b c d : ℂ} : (a + b) * (c + d) - (b - a) * (d - c) * -1 = 2 * (a * c + b * d) := by ring theorem cos_add : cos (x + y) = cos x * cos y - sin x * sin y := by rw [← cosh_mul_I, add_mul, cosh_add, cosh_mul_I, cosh_mul_I, sinh_mul_I, sinh_mul_I, mul_mul_mul_comm, I_mul_I, mul_neg_one, sub_eq_add_neg] #align complex.cos_add Complex.cos_add theorem sin_sub : sin (x - y) = sin x * cos y - cos x * sin y := by simp [sub_eq_add_neg, sin_add, sin_neg, cos_neg] #align complex.sin_sub Complex.sin_sub
Mathlib/Data/Complex/Exponential.lean
561
562
theorem cos_sub : cos (x - y) = cos x * cos y + sin x * sin y := by
simp [sub_eq_add_neg, cos_add, sin_neg, cos_neg]
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura -/ import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.Order.Ring.Nat import Mathlib.Tactic.NthRewrite #align_import data.nat.gcd.basic from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3" /-! # Definitions and properties of `Nat.gcd`, `Nat.lcm`, and `Nat.coprime` Generalizations of these are provided in a later file as `GCDMonoid.gcd` and `GCDMonoid.lcm`. Note that the global `IsCoprime` is not a straightforward generalization of `Nat.coprime`, see `Nat.isCoprime_iff_coprime` for the connection between the two. -/ namespace Nat /-! ### `gcd` -/ theorem gcd_greatest {a b d : ℕ} (hda : d ∣ a) (hdb : d ∣ b) (hd : ∀ e : ℕ, e ∣ a → e ∣ b → e ∣ d) : d = a.gcd b := (dvd_antisymm (hd _ (gcd_dvd_left a b) (gcd_dvd_right a b)) (dvd_gcd hda hdb)).symm #align nat.gcd_greatest Nat.gcd_greatest /-! Lemmas where one argument consists of addition of a multiple of the other -/ @[simp] theorem gcd_add_mul_right_right (m n k : ℕ) : gcd m (n + k * m) = gcd m n := by simp [gcd_rec m (n + k * m), gcd_rec m n] #align nat.gcd_add_mul_right_right Nat.gcd_add_mul_right_right @[simp] theorem gcd_add_mul_left_right (m n k : ℕ) : gcd m (n + m * k) = gcd m n := by simp [gcd_rec m (n + m * k), gcd_rec m n] #align nat.gcd_add_mul_left_right Nat.gcd_add_mul_left_right @[simp] theorem gcd_mul_right_add_right (m n k : ℕ) : gcd m (k * m + n) = gcd m n := by simp [add_comm _ n] #align nat.gcd_mul_right_add_right Nat.gcd_mul_right_add_right @[simp] theorem gcd_mul_left_add_right (m n k : ℕ) : gcd m (m * k + n) = gcd m n := by simp [add_comm _ n] #align nat.gcd_mul_left_add_right Nat.gcd_mul_left_add_right @[simp] theorem gcd_add_mul_right_left (m n k : ℕ) : gcd (m + k * n) n = gcd m n := by rw [gcd_comm, gcd_add_mul_right_right, gcd_comm] #align nat.gcd_add_mul_right_left Nat.gcd_add_mul_right_left @[simp] theorem gcd_add_mul_left_left (m n k : ℕ) : gcd (m + n * k) n = gcd m n := by rw [gcd_comm, gcd_add_mul_left_right, gcd_comm] #align nat.gcd_add_mul_left_left Nat.gcd_add_mul_left_left @[simp] theorem gcd_mul_right_add_left (m n k : ℕ) : gcd (k * n + m) n = gcd m n := by rw [gcd_comm, gcd_mul_right_add_right, gcd_comm] #align nat.gcd_mul_right_add_left Nat.gcd_mul_right_add_left @[simp] theorem gcd_mul_left_add_left (m n k : ℕ) : gcd (n * k + m) n = gcd m n := by rw [gcd_comm, gcd_mul_left_add_right, gcd_comm] #align nat.gcd_mul_left_add_left Nat.gcd_mul_left_add_left /-! Lemmas where one argument consists of an addition of the other -/ @[simp] theorem gcd_add_self_right (m n : ℕ) : gcd m (n + m) = gcd m n := Eq.trans (by rw [one_mul]) (gcd_add_mul_right_right m n 1) #align nat.gcd_add_self_right Nat.gcd_add_self_right @[simp] theorem gcd_add_self_left (m n : ℕ) : gcd (m + n) n = gcd m n := by rw [gcd_comm, gcd_add_self_right, gcd_comm] #align nat.gcd_add_self_left Nat.gcd_add_self_left @[simp] theorem gcd_self_add_left (m n : ℕ) : gcd (m + n) m = gcd n m := by rw [add_comm, gcd_add_self_left] #align nat.gcd_self_add_left Nat.gcd_self_add_left @[simp] theorem gcd_self_add_right (m n : ℕ) : gcd m (m + n) = gcd m n := by rw [add_comm, gcd_add_self_right] #align nat.gcd_self_add_right Nat.gcd_self_add_right /-! Lemmas where one argument consists of a subtraction of the other -/ @[simp] theorem gcd_sub_self_left {m n : ℕ} (h : m ≤ n) : gcd (n - m) m = gcd n m := by calc gcd (n - m) m = gcd (n - m + m) m := by rw [← gcd_add_self_left (n - m) m] _ = gcd n m := by rw [Nat.sub_add_cancel h] @[simp] theorem gcd_sub_self_right {m n : ℕ} (h : m ≤ n) : gcd m (n - m) = gcd m n := by rw [gcd_comm, gcd_sub_self_left h, gcd_comm] @[simp] theorem gcd_self_sub_left {m n : ℕ} (h : m ≤ n) : gcd (n - m) n = gcd m n := by have := Nat.sub_add_cancel h rw [gcd_comm m n, ← this, gcd_add_self_left (n - m) m] have : gcd (n - m) n = gcd (n - m) m := by nth_rw 2 [← Nat.add_sub_cancel' h] rw [gcd_add_self_right, gcd_comm] convert this @[simp] theorem gcd_self_sub_right {m n : ℕ} (h : m ≤ n) : gcd n (n - m) = gcd n m := by rw [gcd_comm, gcd_self_sub_left h, gcd_comm] /-! ### `lcm` -/ theorem lcm_dvd_mul (m n : ℕ) : lcm m n ∣ m * n := lcm_dvd (dvd_mul_right _ _) (dvd_mul_left _ _) #align nat.lcm_dvd_mul Nat.lcm_dvd_mul theorem lcm_dvd_iff {m n k : ℕ} : lcm m n ∣ k ↔ m ∣ k ∧ n ∣ k := ⟨fun h => ⟨(dvd_lcm_left _ _).trans h, (dvd_lcm_right _ _).trans h⟩, and_imp.2 lcm_dvd⟩ #align nat.lcm_dvd_iff Nat.lcm_dvd_iff theorem lcm_pos {m n : ℕ} : 0 < m → 0 < n → 0 < m.lcm n := by simp_rw [pos_iff_ne_zero] exact lcm_ne_zero #align nat.lcm_pos Nat.lcm_pos theorem lcm_mul_left {m n k : ℕ} : (m * n).lcm (m * k) = m * n.lcm k := by apply dvd_antisymm · exact lcm_dvd (mul_dvd_mul_left m (dvd_lcm_left n k)) (mul_dvd_mul_left m (dvd_lcm_right n k)) · have h : m ∣ lcm (m * n) (m * k) := (dvd_mul_right m n).trans (dvd_lcm_left (m * n) (m * k)) rw [← dvd_div_iff h, lcm_dvd_iff, dvd_div_iff h, dvd_div_iff h, ← lcm_dvd_iff] theorem lcm_mul_right {m n k : ℕ} : (m * n).lcm (k * n) = m.lcm k * n := by rw [mul_comm, mul_comm k n, lcm_mul_left, mul_comm] /-! ### `Coprime` See also `Nat.coprime_of_dvd` and `Nat.coprime_of_dvd'` to prove `Nat.Coprime m n`. -/ instance (m n : ℕ) : Decidable (Coprime m n) := inferInstanceAs (Decidable (gcd m n = 1)) theorem Coprime.lcm_eq_mul {m n : ℕ} (h : Coprime m n) : lcm m n = m * n := by rw [← one_mul (lcm m n), ← h.gcd_eq_one, gcd_mul_lcm] #align nat.coprime.lcm_eq_mul Nat.Coprime.lcm_eq_mul theorem Coprime.symmetric : Symmetric Coprime := fun _ _ => Coprime.symm #align nat.coprime.symmetric Nat.Coprime.symmetric theorem Coprime.dvd_mul_right {m n k : ℕ} (H : Coprime k n) : k ∣ m * n ↔ k ∣ m := ⟨H.dvd_of_dvd_mul_right, fun h => dvd_mul_of_dvd_left h n⟩ #align nat.coprime.dvd_mul_right Nat.Coprime.dvd_mul_right theorem Coprime.dvd_mul_left {m n k : ℕ} (H : Coprime k m) : k ∣ m * n ↔ k ∣ n := ⟨H.dvd_of_dvd_mul_left, fun h => dvd_mul_of_dvd_right h m⟩ #align nat.coprime.dvd_mul_left Nat.Coprime.dvd_mul_left @[simp]
Mathlib/Data/Nat/GCD/Basic.lean
166
167
theorem coprime_add_self_right {m n : ℕ} : Coprime m (n + m) ↔ Coprime m n := by
rw [Coprime, Coprime, gcd_add_self_right]
/- Copyright (c) 2021 Benjamin Davidson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Benjamin Davidson -/ import Mathlib.Algebra.Field.Opposite import Mathlib.Algebra.Group.Subgroup.ZPowers import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.Algebra.Ring.NegOnePow import Mathlib.Algebra.Order.Archimedean import Mathlib.GroupTheory.Coset #align_import algebra.periodic from "leanprover-community/mathlib"@"30413fc89f202a090a54d78e540963ed3de0056e" /-! # Periodicity In this file we define and then prove facts about periodic and antiperiodic functions. ## Main definitions * `Function.Periodic`: A function `f` is *periodic* if `∀ x, f (x + c) = f x`. `f` is referred to as periodic with period `c` or `c`-periodic. * `Function.Antiperiodic`: A function `f` is *antiperiodic* if `∀ x, f (x + c) = -f x`. `f` is referred to as antiperiodic with antiperiod `c` or `c`-antiperiodic. Note that any `c`-antiperiodic function will necessarily also be `2 • c`-periodic. ## Tags period, periodic, periodicity, antiperiodic -/ variable {α β γ : Type*} {f g : α → β} {c c₁ c₂ x : α} open Set namespace Function /-! ### Periodicity -/ /-- A function `f` is said to be `Periodic` with period `c` if for all `x`, `f (x + c) = f x`. -/ @[simp] def Periodic [Add α] (f : α → β) (c : α) : Prop := ∀ x : α, f (x + c) = f x #align function.periodic Function.Periodic protected theorem Periodic.funext [Add α] (h : Periodic f c) : (fun x => f (x + c)) = f := funext h #align function.periodic.funext Function.Periodic.funext protected theorem Periodic.comp [Add α] (h : Periodic f c) (g : β → γ) : Periodic (g ∘ f) c := by simp_all #align function.periodic.comp Function.Periodic.comp theorem Periodic.comp_addHom [Add α] [Add γ] (h : Periodic f c) (g : AddHom γ α) (g_inv : α → γ) (hg : RightInverse g_inv g) : Periodic (f ∘ g) (g_inv c) := fun x => by simp only [hg c, h (g x), map_add, comp_apply] #align function.periodic.comp_add_hom Function.Periodic.comp_addHom @[to_additive] protected theorem Periodic.mul [Add α] [Mul β] (hf : Periodic f c) (hg : Periodic g c) : Periodic (f * g) c := by simp_all #align function.periodic.mul Function.Periodic.mul #align function.periodic.add Function.Periodic.add @[to_additive] protected theorem Periodic.div [Add α] [Div β] (hf : Periodic f c) (hg : Periodic g c) : Periodic (f / g) c := by simp_all #align function.periodic.div Function.Periodic.div #align function.periodic.sub Function.Periodic.sub @[to_additive] theorem _root_.List.periodic_prod [Add α] [Monoid β] (l : List (α → β)) (hl : ∀ f ∈ l, Periodic f c) : Periodic l.prod c := by induction' l with g l ih hl · simp · rw [List.forall_mem_cons] at hl simpa only [List.prod_cons] using hl.1.mul (ih hl.2) #align list.periodic_prod List.periodic_prod #align list.periodic_sum List.periodic_sum @[to_additive] theorem _root_.Multiset.periodic_prod [Add α] [CommMonoid β] (s : Multiset (α → β)) (hs : ∀ f ∈ s, Periodic f c) : Periodic s.prod c := (s.prod_toList ▸ s.toList.periodic_prod) fun f hf => hs f <| Multiset.mem_toList.mp hf #align multiset.periodic_prod Multiset.periodic_prod #align multiset.periodic_sum Multiset.periodic_sum @[to_additive] theorem _root_.Finset.periodic_prod [Add α] [CommMonoid β] {ι : Type*} {f : ι → α → β} (s : Finset ι) (hs : ∀ i ∈ s, Periodic (f i) c) : Periodic (∏ i ∈ s, f i) c := s.prod_to_list f ▸ (s.toList.map f).periodic_prod (by simpa [-Periodic] ) #align finset.periodic_prod Finset.periodic_prod #align finset.periodic_sum Finset.periodic_sum @[to_additive] protected theorem Periodic.smul [Add α] [SMul γ β] (h : Periodic f c) (a : γ) : Periodic (a • f) c := by simp_all #align function.periodic.smul Function.Periodic.smul #align function.periodic.vadd Function.Periodic.vadd protected theorem Periodic.const_smul [AddMonoid α] [Group γ] [DistribMulAction γ α] (h : Periodic f c) (a : γ) : Periodic (fun x => f (a • x)) (a⁻¹ • c) := fun x => by simpa only [smul_add, smul_inv_smul] using h (a • x) #align function.periodic.const_smul Function.Periodic.const_smul protected theorem Periodic.const_smul₀ [AddCommMonoid α] [DivisionSemiring γ] [Module γ α] (h : Periodic f c) (a : γ) : Periodic (fun x => f (a • x)) (a⁻¹ • c) := fun x => by by_cases ha : a = 0 · simp only [ha, zero_smul] · simpa only [smul_add, smul_inv_smul₀ ha] using h (a • x) #align function.periodic.const_smul₀ Function.Periodic.const_smul₀ protected theorem Periodic.const_mul [DivisionSemiring α] (h : Periodic f c) (a : α) : Periodic (fun x => f (a * x)) (a⁻¹ * c) := Periodic.const_smul₀ h a #align function.periodic.const_mul Function.Periodic.const_mul theorem Periodic.const_inv_smul [AddMonoid α] [Group γ] [DistribMulAction γ α] (h : Periodic f c) (a : γ) : Periodic (fun x => f (a⁻¹ • x)) (a • c) := by simpa only [inv_inv] using h.const_smul a⁻¹ #align function.periodic.const_inv_smul Function.Periodic.const_inv_smul theorem Periodic.const_inv_smul₀ [AddCommMonoid α] [DivisionSemiring γ] [Module γ α] (h : Periodic f c) (a : γ) : Periodic (fun x => f (a⁻¹ • x)) (a • c) := by simpa only [inv_inv] using h.const_smul₀ a⁻¹ #align function.periodic.const_inv_smul₀ Function.Periodic.const_inv_smul₀ theorem Periodic.const_inv_mul [DivisionSemiring α] (h : Periodic f c) (a : α) : Periodic (fun x => f (a⁻¹ * x)) (a * c) := h.const_inv_smul₀ a #align function.periodic.const_inv_mul Function.Periodic.const_inv_mul theorem Periodic.mul_const [DivisionSemiring α] (h : Periodic f c) (a : α) : Periodic (fun x => f (x * a)) (c * a⁻¹) := h.const_smul₀ (MulOpposite.op a) #align function.periodic.mul_const Function.Periodic.mul_const theorem Periodic.mul_const' [DivisionSemiring α] (h : Periodic f c) (a : α) : Periodic (fun x => f (x * a)) (c / a) := by simpa only [div_eq_mul_inv] using h.mul_const a #align function.periodic.mul_const' Function.Periodic.mul_const' theorem Periodic.mul_const_inv [DivisionSemiring α] (h : Periodic f c) (a : α) : Periodic (fun x => f (x * a⁻¹)) (c * a) := h.const_inv_smul₀ (MulOpposite.op a) #align function.periodic.mul_const_inv Function.Periodic.mul_const_inv theorem Periodic.div_const [DivisionSemiring α] (h : Periodic f c) (a : α) : Periodic (fun x => f (x / a)) (c * a) := by simpa only [div_eq_mul_inv] using h.mul_const_inv a #align function.periodic.div_const Function.Periodic.div_const theorem Periodic.add_period [AddSemigroup α] (h1 : Periodic f c₁) (h2 : Periodic f c₂) : Periodic f (c₁ + c₂) := by simp_all [← add_assoc] #align function.periodic.add_period Function.Periodic.add_period theorem Periodic.sub_eq [AddGroup α] (h : Periodic f c) (x : α) : f (x - c) = f x := by simpa only [sub_add_cancel] using (h (x - c)).symm #align function.periodic.sub_eq Function.Periodic.sub_eq theorem Periodic.sub_eq' [AddCommGroup α] (h : Periodic f c) : f (c - x) = f (-x) := by simpa only [sub_eq_neg_add] using h (-x) #align function.periodic.sub_eq' Function.Periodic.sub_eq' protected theorem Periodic.neg [AddGroup α] (h : Periodic f c) : Periodic f (-c) := by simpa only [sub_eq_add_neg, Periodic] using h.sub_eq #align function.periodic.neg Function.Periodic.neg theorem Periodic.sub_period [AddGroup α] (h1 : Periodic f c₁) (h2 : Periodic f c₂) : Periodic f (c₁ - c₂) := fun x => by rw [sub_eq_add_neg, ← add_assoc, h2.neg, h1] #align function.periodic.sub_period Function.Periodic.sub_period theorem Periodic.const_add [AddSemigroup α] (h : Periodic f c) (a : α) : Periodic (fun x => f (a + x)) c := fun x => by simpa [add_assoc] using h (a + x) #align function.periodic.const_add Function.Periodic.const_add theorem Periodic.add_const [AddCommSemigroup α] (h : Periodic f c) (a : α) : Periodic (fun x => f (x + a)) c := fun x => by simpa only [add_right_comm] using h (x + a) #align function.periodic.add_const Function.Periodic.add_const theorem Periodic.const_sub [AddCommGroup α] (h : Periodic f c) (a : α) : Periodic (fun x => f (a - x)) c := fun x => by simp only [← sub_sub, h.sub_eq] #align function.periodic.const_sub Function.Periodic.const_sub theorem Periodic.sub_const [AddCommGroup α] (h : Periodic f c) (a : α) : Periodic (fun x => f (x - a)) c := by simpa only [sub_eq_add_neg] using h.add_const (-a) #align function.periodic.sub_const Function.Periodic.sub_const theorem Periodic.nsmul [AddMonoid α] (h : Periodic f c) (n : ℕ) : Periodic f (n • c) := by induction n <;> simp_all [Nat.succ_eq_add_one, add_nsmul, ← add_assoc, zero_nsmul] #align function.periodic.nsmul Function.Periodic.nsmul theorem Periodic.nat_mul [Semiring α] (h : Periodic f c) (n : ℕ) : Periodic f (n * c) := by simpa only [nsmul_eq_mul] using h.nsmul n #align function.periodic.nat_mul Function.Periodic.nat_mul theorem Periodic.neg_nsmul [AddGroup α] (h : Periodic f c) (n : ℕ) : Periodic f (-(n • c)) := (h.nsmul n).neg #align function.periodic.neg_nsmul Function.Periodic.neg_nsmul theorem Periodic.neg_nat_mul [Ring α] (h : Periodic f c) (n : ℕ) : Periodic f (-(n * c)) := (h.nat_mul n).neg #align function.periodic.neg_nat_mul Function.Periodic.neg_nat_mul theorem Periodic.sub_nsmul_eq [AddGroup α] (h : Periodic f c) (n : ℕ) : f (x - n • c) = f x := by simpa only [sub_eq_add_neg] using h.neg_nsmul n x #align function.periodic.sub_nsmul_eq Function.Periodic.sub_nsmul_eq theorem Periodic.sub_nat_mul_eq [Ring α] (h : Periodic f c) (n : ℕ) : f (x - n * c) = f x := by simpa only [nsmul_eq_mul] using h.sub_nsmul_eq n #align function.periodic.sub_nat_mul_eq Function.Periodic.sub_nat_mul_eq theorem Periodic.nsmul_sub_eq [AddCommGroup α] (h : Periodic f c) (n : ℕ) : f (n • c - x) = f (-x) := (h.nsmul n).sub_eq' #align function.periodic.nsmul_sub_eq Function.Periodic.nsmul_sub_eq
Mathlib/Algebra/Periodic.lean
225
226
theorem Periodic.nat_mul_sub_eq [Ring α] (h : Periodic f c) (n : ℕ) : f (n * c - x) = f (-x) := by
simpa only [sub_eq_neg_add] using h.nat_mul n (-x)
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Robert Y. Lewis -/ import Mathlib.Algebra.Order.CauSeq.Basic #align_import data.real.cau_seq_completion from "leanprover-community/mathlib"@"cf4c49c445991489058260d75dae0ff2b1abca28" /-! # Cauchy completion This file generalizes the Cauchy completion of `(ℚ, abs)` to the completion of a ring with absolute value. -/ namespace CauSeq.Completion open CauSeq section variable {α : Type*} [LinearOrderedField α] variable {β : Type*} [Ring β] (abv : β → α) [IsAbsoluteValue abv] -- TODO: rename this to `CauSeq.Completion` instead of `CauSeq.Completion.Cauchy`. /-- The Cauchy completion of a ring with absolute value. -/ def Cauchy := @Quotient (CauSeq _ abv) CauSeq.equiv set_option linter.uppercaseLean3 false in #align cau_seq.completion.Cauchy CauSeq.Completion.Cauchy variable {abv} /-- The map from Cauchy sequences into the Cauchy completion. -/ def mk : CauSeq _ abv → Cauchy abv := Quotient.mk'' #align cau_seq.completion.mk CauSeq.Completion.mk @[simp] theorem mk_eq_mk (f : CauSeq _ abv) : @Eq (Cauchy abv) ⟦f⟧ (mk f) := rfl #align cau_seq.completion.mk_eq_mk CauSeq.Completion.mk_eq_mk theorem mk_eq {f g : CauSeq _ abv} : mk f = mk g ↔ f ≈ g := Quotient.eq #align cau_seq.completion.mk_eq CauSeq.Completion.mk_eq /-- The map from the original ring into the Cauchy completion. -/ def ofRat (x : β) : Cauchy abv := mk (const abv x) #align cau_seq.completion.of_rat CauSeq.Completion.ofRat instance : Zero (Cauchy abv) := ⟨ofRat 0⟩ instance : One (Cauchy abv) := ⟨ofRat 1⟩ instance : Inhabited (Cauchy abv) := ⟨0⟩ theorem ofRat_zero : (ofRat 0 : Cauchy abv) = 0 := rfl #align cau_seq.completion.of_rat_zero CauSeq.Completion.ofRat_zero theorem ofRat_one : (ofRat 1 : Cauchy abv) = 1 := rfl #align cau_seq.completion.of_rat_one CauSeq.Completion.ofRat_one @[simp]
Mathlib/Algebra/Order/CauSeq/Completion.lean
73
75
theorem mk_eq_zero {f : CauSeq _ abv} : mk f = 0 ↔ LimZero f := by
have : mk f = 0 ↔ LimZero (f - 0) := Quotient.eq rwa [sub_zero] at this
/- 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.Compactness.SigmaCompact import Mathlib.Topology.Connected.TotallyDisconnected import Mathlib.Topology.Inseparable #align_import topology.separation from "leanprover-community/mathlib"@"d91e7f7a7f1c7e9f0e18fdb6bde4f652004c735d" /-! # Separation properties of topological spaces. This file defines the predicate `SeparatedNhds`, and common separation axioms (under the Kolmogorov classification). ## Main definitions * `SeparatedNhds`: Two `Set`s are separated by neighbourhoods if they are contained in disjoint open sets. * `T0Space`: A T₀/Kolmogorov space is a space where, for every two points `x ≠ y`, there is an open set that contains one, but not the other. * `R0Space`: An R₀ space (sometimes called a *symmetric space*) is a topological space such that the `Specializes` relation is symmetric. * `T1Space`: A T₁/Fréchet space is a space where every singleton set is closed. This is equivalent to, for every pair `x ≠ y`, there existing an open set containing `x` but not `y` (`t1Space_iff_exists_open` shows that these conditions are equivalent.) T₁ implies T₀ and R₀. * `R1Space`: An R₁/preregular space is a space where any two topologically distinguishable points have disjoint neighbourhoods. R₁ implies R₀. * `T2Space`: A T₂/Hausdorff space is a space where, for every two points `x ≠ y`, there is two disjoint open sets, one containing `x`, and the other `y`. T₂ implies T₁ and R₁. * `T25Space`: A T₂.₅/Urysohn space is a space where, for every two points `x ≠ y`, there is two open sets, one containing `x`, and the other `y`, whose closures are disjoint. T₂.₅ implies T₂. * `RegularSpace`: A regular space is one where, given any closed `C` and `x ∉ C`, there are disjoint open sets containing `x` and `C` respectively. Such a space is not necessarily Hausdorff. * `T3Space`: A T₃ space is a regular T₀ space. T₃ implies T₂.₅. * `NormalSpace`: A normal space, is one where given two disjoint closed sets, we can find two open sets that separate them. Such a space is not necessarily Hausdorff, even if it is T₀. * `T4Space`: A T₄ space is a normal T₁ space. T₄ implies T₃. * `CompletelyNormalSpace`: A completely normal space is one in which for any two sets `s`, `t` such that if both `closure s` is disjoint with `t`, and `s` is disjoint with `closure t`, then there exist disjoint neighbourhoods of `s` and `t`. `Embedding.completelyNormalSpace` allows us to conclude that this is equivalent to all subspaces being normal. Such a space is not necessarily Hausdorff or regular, even if it is T₀. * `T5Space`: A T₅ space is a completely normal T₁ space. T₅ implies T₄. Note that `mathlib` adopts the modern convention that `m ≤ n` if and only if `T_m → T_n`, but occasionally the literature swaps definitions for e.g. T₃ and regular. ## Main results ### T₀ spaces * `IsClosed.exists_closed_singleton`: Given a closed set `S` in a compact T₀ space, there is some `x ∈ S` such that `{x}` is closed. * `exists_isOpen_singleton_of_isOpen_finite`: Given an open finite set `S` in a T₀ space, there is some `x ∈ S` such that `{x}` is open. ### T₁ spaces * `isClosedMap_const`: The constant map is a closed map. * `discrete_of_t1_of_finite`: A finite T₁ space must have the discrete topology. ### T₂ spaces * `t2_iff_nhds`: A space is T₂ iff the neighbourhoods of distinct points generate the bottom filter. * `t2_iff_isClosed_diagonal`: A space is T₂ iff the `diagonal` of `X` (that is, the set of all points of the form `(a, a) : X × X`) is closed under the product topology. * `separatedNhds_of_finset_finset`: Any two disjoint finsets are `SeparatedNhds`. * Most topological constructions preserve Hausdorffness; these results are part of the typeclass inference system (e.g. `Embedding.t2Space`) * `Set.EqOn.closure`: If two functions are equal on some set `s`, they are equal on its closure. * `IsCompact.isClosed`: All compact sets are closed. * `WeaklyLocallyCompactSpace.locallyCompactSpace`: If a topological space is both weakly locally compact (i.e., each point has a compact neighbourhood) and is T₂, then it is locally compact. * `totallySeparatedSpace_of_t1_of_basis_clopen`: If `X` has a clopen basis, then it is a `TotallySeparatedSpace`. * `loc_compact_t2_tot_disc_iff_tot_sep`: A locally compact T₂ space is totally disconnected iff it is totally separated. * `t2Quotient`: the largest T2 quotient of a given topological space. If the space is also compact: * `normalOfCompactT2`: A compact T₂ space is a `NormalSpace`. * `connectedComponent_eq_iInter_isClopen`: The connected component of a point is the intersection of all its clopen neighbourhoods. * `compact_t2_tot_disc_iff_tot_sep`: Being a `TotallyDisconnectedSpace` is equivalent to being a `TotallySeparatedSpace`. * `ConnectedComponents.t2`: `ConnectedComponents X` is T₂ for `X` T₂ and compact. ### T₃ spaces * `disjoint_nested_nhds`: Given two points `x ≠ y`, we can find neighbourhoods `x ∈ V₁ ⊆ U₁` and `y ∈ V₂ ⊆ U₂`, with the `Vₖ` closed and the `Uₖ` open, such that the `Uₖ` are disjoint. ## References https://en.wikipedia.org/wiki/Separation_axiom -/ open Function Set Filter Topology TopologicalSpace open scoped Classical universe u v variable {X : Type*} {Y : Type*} [TopologicalSpace X] section Separation /-- `SeparatedNhds` is a predicate on pairs of sub`Set`s of a topological space. It holds if the two sub`Set`s are contained in disjoint open sets. -/ def SeparatedNhds : Set X → Set X → Prop := fun s t : Set X => ∃ U V : Set X, IsOpen U ∧ IsOpen V ∧ s ⊆ U ∧ t ⊆ V ∧ Disjoint U V #align separated_nhds SeparatedNhds theorem separatedNhds_iff_disjoint {s t : Set X} : SeparatedNhds s t ↔ Disjoint (𝓝ˢ s) (𝓝ˢ t) := by simp only [(hasBasis_nhdsSet s).disjoint_iff (hasBasis_nhdsSet t), SeparatedNhds, exists_prop, ← exists_and_left, and_assoc, and_comm, and_left_comm] #align separated_nhds_iff_disjoint separatedNhds_iff_disjoint alias ⟨SeparatedNhds.disjoint_nhdsSet, _⟩ := separatedNhds_iff_disjoint namespace SeparatedNhds variable {s s₁ s₂ t t₁ t₂ u : Set X} @[symm] theorem symm : SeparatedNhds s t → SeparatedNhds t s := fun ⟨U, V, oU, oV, aU, bV, UV⟩ => ⟨V, U, oV, oU, bV, aU, Disjoint.symm UV⟩ #align separated_nhds.symm SeparatedNhds.symm theorem comm (s t : Set X) : SeparatedNhds s t ↔ SeparatedNhds t s := ⟨symm, symm⟩ #align separated_nhds.comm SeparatedNhds.comm theorem preimage [TopologicalSpace Y] {f : X → Y} {s t : Set Y} (h : SeparatedNhds s t) (hf : Continuous f) : SeparatedNhds (f ⁻¹' s) (f ⁻¹' t) := let ⟨U, V, oU, oV, sU, tV, UV⟩ := h ⟨f ⁻¹' U, f ⁻¹' V, oU.preimage hf, oV.preimage hf, preimage_mono sU, preimage_mono tV, UV.preimage f⟩ #align separated_nhds.preimage SeparatedNhds.preimage protected theorem disjoint (h : SeparatedNhds s t) : Disjoint s t := let ⟨_, _, _, _, hsU, htV, hd⟩ := h; hd.mono hsU htV #align separated_nhds.disjoint SeparatedNhds.disjoint theorem disjoint_closure_left (h : SeparatedNhds s t) : Disjoint (closure s) t := let ⟨_U, _V, _, hV, hsU, htV, hd⟩ := h (hd.closure_left hV).mono (closure_mono hsU) htV #align separated_nhds.disjoint_closure_left SeparatedNhds.disjoint_closure_left theorem disjoint_closure_right (h : SeparatedNhds s t) : Disjoint s (closure t) := h.symm.disjoint_closure_left.symm #align separated_nhds.disjoint_closure_right SeparatedNhds.disjoint_closure_right @[simp] theorem empty_right (s : Set X) : SeparatedNhds s ∅ := ⟨_, _, isOpen_univ, isOpen_empty, fun a _ => mem_univ a, Subset.rfl, disjoint_empty _⟩ #align separated_nhds.empty_right SeparatedNhds.empty_right @[simp] theorem empty_left (s : Set X) : SeparatedNhds ∅ s := (empty_right _).symm #align separated_nhds.empty_left SeparatedNhds.empty_left theorem mono (h : SeparatedNhds s₂ t₂) (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : SeparatedNhds s₁ t₁ := let ⟨U, V, hU, hV, hsU, htV, hd⟩ := h ⟨U, V, hU, hV, hs.trans hsU, ht.trans htV, hd⟩ #align separated_nhds.mono SeparatedNhds.mono theorem union_left : SeparatedNhds s u → SeparatedNhds t u → SeparatedNhds (s ∪ t) u := by simpa only [separatedNhds_iff_disjoint, nhdsSet_union, disjoint_sup_left] using And.intro #align separated_nhds.union_left SeparatedNhds.union_left theorem union_right (ht : SeparatedNhds s t) (hu : SeparatedNhds s u) : SeparatedNhds s (t ∪ u) := (ht.symm.union_left hu.symm).symm #align separated_nhds.union_right SeparatedNhds.union_right end SeparatedNhds /-- A T₀ space, also known as a Kolmogorov space, is a topological space such that for every pair `x ≠ y`, there is an open set containing one but not the other. We formulate the definition in terms of the `Inseparable` relation. -/ class T0Space (X : Type u) [TopologicalSpace X] : Prop where /-- Two inseparable points in a T₀ space are equal. -/ t0 : ∀ ⦃x y : X⦄, Inseparable x y → x = y #align t0_space T0Space theorem t0Space_iff_inseparable (X : Type u) [TopologicalSpace X] : T0Space X ↔ ∀ x y : X, Inseparable x y → x = y := ⟨fun ⟨h⟩ => h, fun h => ⟨h⟩⟩ #align t0_space_iff_inseparable t0Space_iff_inseparable theorem t0Space_iff_not_inseparable (X : Type u) [TopologicalSpace X] : T0Space X ↔ Pairwise fun x y : X => ¬Inseparable x y := by simp only [t0Space_iff_inseparable, Ne, not_imp_not, Pairwise] #align t0_space_iff_not_inseparable t0Space_iff_not_inseparable theorem Inseparable.eq [T0Space X] {x y : X} (h : Inseparable x y) : x = y := T0Space.t0 h #align inseparable.eq Inseparable.eq /-- A topology `Inducing` map from a T₀ space is injective. -/ protected theorem Inducing.injective [TopologicalSpace Y] [T0Space X] {f : X → Y} (hf : Inducing f) : Injective f := fun _ _ h => (hf.inseparable_iff.1 <| .of_eq h).eq #align inducing.injective Inducing.injective /-- A topology `Inducing` map from a T₀ space is a topological embedding. -/ protected theorem Inducing.embedding [TopologicalSpace Y] [T0Space X] {f : X → Y} (hf : Inducing f) : Embedding f := ⟨hf, hf.injective⟩ #align inducing.embedding Inducing.embedding lemma embedding_iff_inducing [TopologicalSpace Y] [T0Space X] {f : X → Y} : Embedding f ↔ Inducing f := ⟨Embedding.toInducing, Inducing.embedding⟩ #align embedding_iff_inducing embedding_iff_inducing theorem t0Space_iff_nhds_injective (X : Type u) [TopologicalSpace X] : T0Space X ↔ Injective (𝓝 : X → Filter X) := t0Space_iff_inseparable X #align t0_space_iff_nhds_injective t0Space_iff_nhds_injective theorem nhds_injective [T0Space X] : Injective (𝓝 : X → Filter X) := (t0Space_iff_nhds_injective X).1 ‹_› #align nhds_injective nhds_injective theorem inseparable_iff_eq [T0Space X] {x y : X} : Inseparable x y ↔ x = y := nhds_injective.eq_iff #align inseparable_iff_eq inseparable_iff_eq @[simp] theorem nhds_eq_nhds_iff [T0Space X] {a b : X} : 𝓝 a = 𝓝 b ↔ a = b := nhds_injective.eq_iff #align nhds_eq_nhds_iff nhds_eq_nhds_iff @[simp] theorem inseparable_eq_eq [T0Space X] : Inseparable = @Eq X := funext₂ fun _ _ => propext inseparable_iff_eq #align inseparable_eq_eq inseparable_eq_eq theorem TopologicalSpace.IsTopologicalBasis.inseparable_iff {b : Set (Set X)} (hb : IsTopologicalBasis b) {x y : X} : Inseparable x y ↔ ∀ s ∈ b, (x ∈ s ↔ y ∈ s) := ⟨fun h s hs ↦ inseparable_iff_forall_open.1 h _ (hb.isOpen hs), fun h ↦ hb.nhds_hasBasis.eq_of_same_basis <| by convert hb.nhds_hasBasis using 2 exact and_congr_right (h _)⟩ theorem TopologicalSpace.IsTopologicalBasis.eq_iff [T0Space X] {b : Set (Set X)} (hb : IsTopologicalBasis b) {x y : X} : x = y ↔ ∀ s ∈ b, (x ∈ s ↔ y ∈ s) := inseparable_iff_eq.symm.trans hb.inseparable_iff theorem t0Space_iff_exists_isOpen_xor'_mem (X : Type u) [TopologicalSpace X] : T0Space X ↔ Pairwise fun x y => ∃ U : Set X, IsOpen U ∧ Xor' (x ∈ U) (y ∈ U) := by simp only [t0Space_iff_not_inseparable, xor_iff_not_iff, not_forall, exists_prop, inseparable_iff_forall_open, Pairwise] #align t0_space_iff_exists_is_open_xor_mem t0Space_iff_exists_isOpen_xor'_mem theorem exists_isOpen_xor'_mem [T0Space X] {x y : X} (h : x ≠ y) : ∃ U : Set X, IsOpen U ∧ Xor' (x ∈ U) (y ∈ U) := (t0Space_iff_exists_isOpen_xor'_mem X).1 ‹_› h #align exists_is_open_xor_mem exists_isOpen_xor'_mem /-- Specialization forms a partial order on a t0 topological space. -/ def specializationOrder (X) [TopologicalSpace X] [T0Space X] : PartialOrder X := { specializationPreorder X, PartialOrder.lift (OrderDual.toDual ∘ 𝓝) nhds_injective with } #align specialization_order specializationOrder instance SeparationQuotient.instT0Space : T0Space (SeparationQuotient X) := ⟨fun x y => Quotient.inductionOn₂' x y fun _ _ h => SeparationQuotient.mk_eq_mk.2 <| SeparationQuotient.inducing_mk.inseparable_iff.1 h⟩ theorem minimal_nonempty_closed_subsingleton [T0Space X] {s : Set X} (hs : IsClosed s) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsClosed t → t = s) : s.Subsingleton := by clear Y -- Porting note: added refine fun x hx y hy => of_not_not fun hxy => ?_ rcases exists_isOpen_xor'_mem hxy with ⟨U, hUo, hU⟩ wlog h : x ∈ U ∧ y ∉ U · refine this hs hmin y hy x hx (Ne.symm hxy) U hUo hU.symm (hU.resolve_left h) cases' h with hxU hyU have : s \ U = s := hmin (s \ U) diff_subset ⟨y, hy, hyU⟩ (hs.sdiff hUo) exact (this.symm.subset hx).2 hxU #align minimal_nonempty_closed_subsingleton minimal_nonempty_closed_subsingleton theorem minimal_nonempty_closed_eq_singleton [T0Space X] {s : Set X} (hs : IsClosed s) (hne : s.Nonempty) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsClosed t → t = s) : ∃ x, s = {x} := exists_eq_singleton_iff_nonempty_subsingleton.2 ⟨hne, minimal_nonempty_closed_subsingleton hs hmin⟩ #align minimal_nonempty_closed_eq_singleton minimal_nonempty_closed_eq_singleton /-- Given a closed set `S` in a compact T₀ space, there is some `x ∈ S` such that `{x}` is closed. -/ theorem IsClosed.exists_closed_singleton [T0Space X] [CompactSpace X] {S : Set X} (hS : IsClosed S) (hne : S.Nonempty) : ∃ x : X, x ∈ S ∧ IsClosed ({x} : Set X) := by obtain ⟨V, Vsub, Vne, Vcls, hV⟩ := hS.exists_minimal_nonempty_closed_subset hne rcases minimal_nonempty_closed_eq_singleton Vcls Vne hV with ⟨x, rfl⟩ exact ⟨x, Vsub (mem_singleton x), Vcls⟩ #align is_closed.exists_closed_singleton IsClosed.exists_closed_singleton theorem minimal_nonempty_open_subsingleton [T0Space X] {s : Set X} (hs : IsOpen s) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsOpen t → t = s) : s.Subsingleton := by clear Y -- Porting note: added refine fun x hx y hy => of_not_not fun hxy => ?_ rcases exists_isOpen_xor'_mem hxy with ⟨U, hUo, hU⟩ wlog h : x ∈ U ∧ y ∉ U · exact this hs hmin y hy x hx (Ne.symm hxy) U hUo hU.symm (hU.resolve_left h) cases' h with hxU hyU have : s ∩ U = s := hmin (s ∩ U) inter_subset_left ⟨x, hx, hxU⟩ (hs.inter hUo) exact hyU (this.symm.subset hy).2 #align minimal_nonempty_open_subsingleton minimal_nonempty_open_subsingleton theorem minimal_nonempty_open_eq_singleton [T0Space X] {s : Set X} (hs : IsOpen s) (hne : s.Nonempty) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsOpen t → t = s) : ∃ x, s = {x} := exists_eq_singleton_iff_nonempty_subsingleton.2 ⟨hne, minimal_nonempty_open_subsingleton hs hmin⟩ #align minimal_nonempty_open_eq_singleton minimal_nonempty_open_eq_singleton /-- Given an open finite set `S` in a T₀ space, there is some `x ∈ S` such that `{x}` is open. -/ theorem exists_isOpen_singleton_of_isOpen_finite [T0Space X] {s : Set X} (hfin : s.Finite) (hne : s.Nonempty) (ho : IsOpen s) : ∃ x ∈ s, IsOpen ({x} : Set X) := by lift s to Finset X using hfin induction' s using Finset.strongInductionOn with s ihs rcases em (∃ t, t ⊂ s ∧ t.Nonempty ∧ IsOpen (t : Set X)) with (⟨t, hts, htne, hto⟩ | ht) · rcases ihs t hts htne hto with ⟨x, hxt, hxo⟩ exact ⟨x, hts.1 hxt, hxo⟩ · -- Porting note: was `rcases minimal_nonempty_open_eq_singleton ho hne _ with ⟨x, hx⟩` -- https://github.com/leanprover/std4/issues/116 rsuffices ⟨x, hx⟩ : ∃ x, s.toSet = {x} · exact ⟨x, hx.symm ▸ rfl, hx ▸ ho⟩ refine minimal_nonempty_open_eq_singleton ho hne ?_ refine fun t hts htne hto => of_not_not fun hts' => ht ?_ lift t to Finset X using s.finite_toSet.subset hts exact ⟨t, ssubset_iff_subset_ne.2 ⟨hts, mt Finset.coe_inj.2 hts'⟩, htne, hto⟩ #align exists_open_singleton_of_open_finite exists_isOpen_singleton_of_isOpen_finite theorem exists_open_singleton_of_finite [T0Space X] [Finite X] [Nonempty X] : ∃ x : X, IsOpen ({x} : Set X) := let ⟨x, _, h⟩ := exists_isOpen_singleton_of_isOpen_finite (Set.toFinite _) univ_nonempty isOpen_univ ⟨x, h⟩ #align exists_open_singleton_of_fintype exists_open_singleton_of_finite theorem t0Space_of_injective_of_continuous [TopologicalSpace Y] {f : X → Y} (hf : Function.Injective f) (hf' : Continuous f) [T0Space Y] : T0Space X := ⟨fun _ _ h => hf <| (h.map hf').eq⟩ #align t0_space_of_injective_of_continuous t0Space_of_injective_of_continuous protected theorem Embedding.t0Space [TopologicalSpace Y] [T0Space Y] {f : X → Y} (hf : Embedding f) : T0Space X := t0Space_of_injective_of_continuous hf.inj hf.continuous #align embedding.t0_space Embedding.t0Space instance Subtype.t0Space [T0Space X] {p : X → Prop} : T0Space (Subtype p) := embedding_subtype_val.t0Space #align subtype.t0_space Subtype.t0Space theorem t0Space_iff_or_not_mem_closure (X : Type u) [TopologicalSpace X] : T0Space X ↔ Pairwise fun a b : X => a ∉ closure ({b} : Set X) ∨ b ∉ closure ({a} : Set X) := by simp only [t0Space_iff_not_inseparable, inseparable_iff_mem_closure, not_and_or] #align t0_space_iff_or_not_mem_closure t0Space_iff_or_not_mem_closure instance Prod.instT0Space [TopologicalSpace Y] [T0Space X] [T0Space Y] : T0Space (X × Y) := ⟨fun _ _ h => Prod.ext (h.map continuous_fst).eq (h.map continuous_snd).eq⟩ instance Pi.instT0Space {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, T0Space (X i)] : T0Space (∀ i, X i) := ⟨fun _ _ h => funext fun i => (h.map (continuous_apply i)).eq⟩ #align pi.t0_space Pi.instT0Space instance ULift.instT0Space [T0Space X] : T0Space (ULift X) := embedding_uLift_down.t0Space theorem T0Space.of_cover (h : ∀ x y, Inseparable x y → ∃ s : Set X, x ∈ s ∧ y ∈ s ∧ T0Space s) : T0Space X := by refine ⟨fun x y hxy => ?_⟩ rcases h x y hxy with ⟨s, hxs, hys, hs⟩ lift x to s using hxs; lift y to s using hys rw [← subtype_inseparable_iff] at hxy exact congr_arg Subtype.val hxy.eq #align t0_space.of_cover T0Space.of_cover theorem T0Space.of_open_cover (h : ∀ x, ∃ s : Set X, x ∈ s ∧ IsOpen s ∧ T0Space s) : T0Space X := T0Space.of_cover fun x _ hxy => let ⟨s, hxs, hso, hs⟩ := h x ⟨s, hxs, (hxy.mem_open_iff hso).1 hxs, hs⟩ #align t0_space.of_open_cover T0Space.of_open_cover /-- A topological space is called an R₀ space, if `Specializes` relation is symmetric. In other words, given two points `x y : X`, if every neighborhood of `y` contains `x`, then every neighborhood of `x` contains `y`. -/ @[mk_iff] class R0Space (X : Type u) [TopologicalSpace X] : Prop where /-- In an R₀ space, the `Specializes` relation is symmetric. -/ specializes_symmetric : Symmetric (Specializes : X → X → Prop) export R0Space (specializes_symmetric) section R0Space variable [R0Space X] {x y : X} /-- In an R₀ space, the `Specializes` relation is symmetric, dot notation version. -/ theorem Specializes.symm (h : x ⤳ y) : y ⤳ x := specializes_symmetric h #align specializes.symm Specializes.symm /-- In an R₀ space, the `Specializes` relation is symmetric, `Iff` version. -/ theorem specializes_comm : x ⤳ y ↔ y ⤳ x := ⟨Specializes.symm, Specializes.symm⟩ #align specializes_comm specializes_comm /-- In an R₀ space, `Specializes` is equivalent to `Inseparable`. -/ theorem specializes_iff_inseparable : x ⤳ y ↔ Inseparable x y := ⟨fun h ↦ h.antisymm h.symm, Inseparable.specializes⟩ #align specializes_iff_inseparable specializes_iff_inseparable /-- In an R₀ space, `Specializes` implies `Inseparable`. -/ alias ⟨Specializes.inseparable, _⟩ := specializes_iff_inseparable theorem Inducing.r0Space [TopologicalSpace Y] {f : Y → X} (hf : Inducing f) : R0Space Y where specializes_symmetric a b := by simpa only [← hf.specializes_iff] using Specializes.symm instance {p : X → Prop} : R0Space {x // p x} := inducing_subtype_val.r0Space instance [TopologicalSpace Y] [R0Space Y] : R0Space (X × Y) where specializes_symmetric _ _ h := h.fst.symm.prod h.snd.symm instance {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, R0Space (X i)] : R0Space (∀ i, X i) where specializes_symmetric _ _ h := specializes_pi.2 fun i ↦ (specializes_pi.1 h i).symm /-- In an R₀ space, the closure of a singleton is a compact set. -/ theorem isCompact_closure_singleton : IsCompact (closure {x}) := by refine isCompact_of_finite_subcover fun U hUo hxU ↦ ?_ obtain ⟨i, hi⟩ : ∃ i, x ∈ U i := mem_iUnion.1 <| hxU <| subset_closure rfl refine ⟨{i}, fun y hy ↦ ?_⟩ rw [← specializes_iff_mem_closure, specializes_comm] at hy simpa using hy.mem_open (hUo i) hi theorem Filter.coclosedCompact_le_cofinite : coclosedCompact X ≤ cofinite := le_cofinite_iff_compl_singleton_mem.2 fun _ ↦ compl_mem_coclosedCompact.2 isCompact_closure_singleton #align filter.coclosed_compact_le_cofinite Filter.coclosedCompact_le_cofinite variable (X) /-- In an R₀ space, relatively compact sets form a bornology. Its cobounded filter is `Filter.coclosedCompact`. See also `Bornology.inCompact` the bornology of sets contained in a compact set. -/ def Bornology.relativelyCompact : Bornology X where cobounded' := Filter.coclosedCompact X le_cofinite' := Filter.coclosedCompact_le_cofinite #align bornology.relatively_compact Bornology.relativelyCompact variable {X} theorem Bornology.relativelyCompact.isBounded_iff {s : Set X} : @Bornology.IsBounded _ (Bornology.relativelyCompact X) s ↔ IsCompact (closure s) := compl_mem_coclosedCompact #align bornology.relatively_compact.is_bounded_iff Bornology.relativelyCompact.isBounded_iff /-- In an R₀ space, the closure of a finite set is a compact set. -/ theorem Set.Finite.isCompact_closure {s : Set X} (hs : s.Finite) : IsCompact (closure s) := let _ : Bornology X := .relativelyCompact X Bornology.relativelyCompact.isBounded_iff.1 hs.isBounded end R0Space /-- A T₁ space, also known as a Fréchet space, is a topological space where every singleton set is closed. Equivalently, for every pair `x ≠ y`, there is an open set containing `x` and not `y`. -/ class T1Space (X : Type u) [TopologicalSpace X] : Prop where /-- A singleton in a T₁ space is a closed set. -/ t1 : ∀ x, IsClosed ({x} : Set X) #align t1_space T1Space theorem isClosed_singleton [T1Space X] {x : X} : IsClosed ({x} : Set X) := T1Space.t1 x #align is_closed_singleton isClosed_singleton theorem isOpen_compl_singleton [T1Space X] {x : X} : IsOpen ({x}ᶜ : Set X) := isClosed_singleton.isOpen_compl #align is_open_compl_singleton isOpen_compl_singleton theorem isOpen_ne [T1Space X] {x : X} : IsOpen { y | y ≠ x } := isOpen_compl_singleton #align is_open_ne isOpen_ne @[to_additive] theorem Continuous.isOpen_mulSupport [T1Space X] [One X] [TopologicalSpace Y] {f : Y → X} (hf : Continuous f) : IsOpen (mulSupport f) := isOpen_ne.preimage hf #align continuous.is_open_mul_support Continuous.isOpen_mulSupport #align continuous.is_open_support Continuous.isOpen_support theorem Ne.nhdsWithin_compl_singleton [T1Space X] {x y : X} (h : x ≠ y) : 𝓝[{y}ᶜ] x = 𝓝 x := isOpen_ne.nhdsWithin_eq h #align ne.nhds_within_compl_singleton Ne.nhdsWithin_compl_singleton theorem Ne.nhdsWithin_diff_singleton [T1Space X] {x y : X} (h : x ≠ y) (s : Set X) : 𝓝[s \ {y}] x = 𝓝[s] x := by rw [diff_eq, inter_comm, nhdsWithin_inter_of_mem] exact mem_nhdsWithin_of_mem_nhds (isOpen_ne.mem_nhds h) #align ne.nhds_within_diff_singleton Ne.nhdsWithin_diff_singleton lemma nhdsWithin_compl_singleton_le [T1Space X] (x y : X) : 𝓝[{x}ᶜ] x ≤ 𝓝[{y}ᶜ] x := by rcases eq_or_ne x y with rfl|hy · exact Eq.le rfl · rw [Ne.nhdsWithin_compl_singleton hy] exact nhdsWithin_le_nhds theorem isOpen_setOf_eventually_nhdsWithin [T1Space X] {p : X → Prop} : IsOpen { x | ∀ᶠ y in 𝓝[≠] x, p y } := by refine isOpen_iff_mem_nhds.mpr fun a ha => ?_ filter_upwards [eventually_nhds_nhdsWithin.mpr ha] with b hb rcases eq_or_ne a b with rfl | h · exact hb · rw [h.symm.nhdsWithin_compl_singleton] at hb exact hb.filter_mono nhdsWithin_le_nhds #align is_open_set_of_eventually_nhds_within isOpen_setOf_eventually_nhdsWithin protected theorem Set.Finite.isClosed [T1Space X] {s : Set X} (hs : Set.Finite s) : IsClosed s := by rw [← biUnion_of_singleton s] exact hs.isClosed_biUnion fun i _ => isClosed_singleton #align set.finite.is_closed Set.Finite.isClosed theorem TopologicalSpace.IsTopologicalBasis.exists_mem_of_ne [T1Space X] {b : Set (Set X)} (hb : IsTopologicalBasis b) {x y : X} (h : x ≠ y) : ∃ a ∈ b, x ∈ a ∧ y ∉ a := by rcases hb.isOpen_iff.1 isOpen_ne x h with ⟨a, ab, xa, ha⟩ exact ⟨a, ab, xa, fun h => ha h rfl⟩ #align topological_space.is_topological_basis.exists_mem_of_ne TopologicalSpace.IsTopologicalBasis.exists_mem_of_ne protected theorem Finset.isClosed [T1Space X] (s : Finset X) : IsClosed (s : Set X) := s.finite_toSet.isClosed #align finset.is_closed Finset.isClosed theorem t1Space_TFAE (X : Type u) [TopologicalSpace X] : List.TFAE [T1Space X, ∀ x, IsClosed ({ x } : Set X), ∀ x, IsOpen ({ x }ᶜ : Set X), Continuous (@CofiniteTopology.of X), ∀ ⦃x y : X⦄, x ≠ y → {y}ᶜ ∈ 𝓝 x, ∀ ⦃x y : X⦄, x ≠ y → ∃ s ∈ 𝓝 x, y ∉ s, ∀ ⦃x y : X⦄, x ≠ y → ∃ U : Set X, IsOpen U ∧ x ∈ U ∧ y ∉ U, ∀ ⦃x y : X⦄, x ≠ y → Disjoint (𝓝 x) (pure y), ∀ ⦃x y : X⦄, x ≠ y → Disjoint (pure x) (𝓝 y), ∀ ⦃x y : X⦄, x ⤳ y → x = y] := by tfae_have 1 ↔ 2 · exact ⟨fun h => h.1, fun h => ⟨h⟩⟩ tfae_have 2 ↔ 3 · simp only [isOpen_compl_iff] tfae_have 5 ↔ 3 · refine forall_swap.trans ?_ simp only [isOpen_iff_mem_nhds, mem_compl_iff, mem_singleton_iff] tfae_have 5 ↔ 6 · simp only [← subset_compl_singleton_iff, exists_mem_subset_iff] tfae_have 5 ↔ 7 · simp only [(nhds_basis_opens _).mem_iff, subset_compl_singleton_iff, exists_prop, and_assoc, and_left_comm] tfae_have 5 ↔ 8 · simp only [← principal_singleton, disjoint_principal_right] tfae_have 8 ↔ 9 · exact forall_swap.trans (by simp only [disjoint_comm, ne_comm]) tfae_have 1 → 4 · simp only [continuous_def, CofiniteTopology.isOpen_iff'] rintro H s (rfl | hs) exacts [isOpen_empty, compl_compl s ▸ (@Set.Finite.isClosed _ _ H _ hs).isOpen_compl] tfae_have 4 → 2 · exact fun h x => (CofiniteTopology.isClosed_iff.2 <| Or.inr (finite_singleton _)).preimage h tfae_have 2 ↔ 10 · simp only [← closure_subset_iff_isClosed, specializes_iff_mem_closure, subset_def, mem_singleton_iff, eq_comm] tfae_finish #align t1_space_tfae t1Space_TFAE theorem t1Space_iff_continuous_cofinite_of : T1Space X ↔ Continuous (@CofiniteTopology.of X) := (t1Space_TFAE X).out 0 3 #align t1_space_iff_continuous_cofinite_of t1Space_iff_continuous_cofinite_of theorem CofiniteTopology.continuous_of [T1Space X] : Continuous (@CofiniteTopology.of X) := t1Space_iff_continuous_cofinite_of.mp ‹_› #align cofinite_topology.continuous_of CofiniteTopology.continuous_of theorem t1Space_iff_exists_open : T1Space X ↔ Pairwise fun x y => ∃ U : Set X, IsOpen U ∧ x ∈ U ∧ y ∉ U := (t1Space_TFAE X).out 0 6 #align t1_space_iff_exists_open t1Space_iff_exists_open theorem t1Space_iff_disjoint_pure_nhds : T1Space X ↔ ∀ ⦃x y : X⦄, x ≠ y → Disjoint (pure x) (𝓝 y) := (t1Space_TFAE X).out 0 8 #align t1_space_iff_disjoint_pure_nhds t1Space_iff_disjoint_pure_nhds theorem t1Space_iff_disjoint_nhds_pure : T1Space X ↔ ∀ ⦃x y : X⦄, x ≠ y → Disjoint (𝓝 x) (pure y) := (t1Space_TFAE X).out 0 7 #align t1_space_iff_disjoint_nhds_pure t1Space_iff_disjoint_nhds_pure theorem t1Space_iff_specializes_imp_eq : T1Space X ↔ ∀ ⦃x y : X⦄, x ⤳ y → x = y := (t1Space_TFAE X).out 0 9 #align t1_space_iff_specializes_imp_eq t1Space_iff_specializes_imp_eq theorem disjoint_pure_nhds [T1Space X] {x y : X} (h : x ≠ y) : Disjoint (pure x) (𝓝 y) := t1Space_iff_disjoint_pure_nhds.mp ‹_› h #align disjoint_pure_nhds disjoint_pure_nhds theorem disjoint_nhds_pure [T1Space X] {x y : X} (h : x ≠ y) : Disjoint (𝓝 x) (pure y) := t1Space_iff_disjoint_nhds_pure.mp ‹_› h #align disjoint_nhds_pure disjoint_nhds_pure theorem Specializes.eq [T1Space X] {x y : X} (h : x ⤳ y) : x = y := t1Space_iff_specializes_imp_eq.1 ‹_› h #align specializes.eq Specializes.eq theorem specializes_iff_eq [T1Space X] {x y : X} : x ⤳ y ↔ x = y := ⟨Specializes.eq, fun h => h ▸ specializes_rfl⟩ #align specializes_iff_eq specializes_iff_eq @[simp] theorem specializes_eq_eq [T1Space X] : (· ⤳ ·) = @Eq X := funext₂ fun _ _ => propext specializes_iff_eq #align specializes_eq_eq specializes_eq_eq @[simp] theorem pure_le_nhds_iff [T1Space X] {a b : X} : pure a ≤ 𝓝 b ↔ a = b := specializes_iff_pure.symm.trans specializes_iff_eq #align pure_le_nhds_iff pure_le_nhds_iff @[simp] theorem nhds_le_nhds_iff [T1Space X] {a b : X} : 𝓝 a ≤ 𝓝 b ↔ a = b := specializes_iff_eq #align nhds_le_nhds_iff nhds_le_nhds_iff instance (priority := 100) [T1Space X] : R0Space X where specializes_symmetric _ _ := by rw [specializes_iff_eq, specializes_iff_eq]; exact Eq.symm instance : T1Space (CofiniteTopology X) := t1Space_iff_continuous_cofinite_of.mpr continuous_id theorem t1Space_antitone : Antitone (@T1Space X) := fun a _ h _ => @T1Space.mk _ a fun x => (T1Space.t1 x).mono h #align t1_space_antitone t1Space_antitone theorem continuousWithinAt_update_of_ne [T1Space X] [DecidableEq X] [TopologicalSpace Y] {f : X → Y} {s : Set X} {x x' : X} {y : Y} (hne : x' ≠ x) : ContinuousWithinAt (Function.update f x y) s x' ↔ ContinuousWithinAt f s x' := EventuallyEq.congr_continuousWithinAt (mem_nhdsWithin_of_mem_nhds <| mem_of_superset (isOpen_ne.mem_nhds hne) fun _y' hy' => Function.update_noteq hy' _ _) (Function.update_noteq hne _ _) #align continuous_within_at_update_of_ne continuousWithinAt_update_of_ne theorem continuousAt_update_of_ne [T1Space X] [DecidableEq X] [TopologicalSpace Y] {f : X → Y} {x x' : X} {y : Y} (hne : x' ≠ x) : ContinuousAt (Function.update f x y) x' ↔ ContinuousAt f x' := by simp only [← continuousWithinAt_univ, continuousWithinAt_update_of_ne hne] #align continuous_at_update_of_ne continuousAt_update_of_ne theorem continuousOn_update_iff [T1Space X] [DecidableEq X] [TopologicalSpace Y] {f : X → Y} {s : Set X} {x : X} {y : Y} : ContinuousOn (Function.update f x y) s ↔ ContinuousOn f (s \ {x}) ∧ (x ∈ s → Tendsto f (𝓝[s \ {x}] x) (𝓝 y)) := by rw [ContinuousOn, ← and_forall_ne x, and_comm] refine and_congr ⟨fun H z hz => ?_, fun H z hzx hzs => ?_⟩ (forall_congr' fun _ => ?_) · specialize H z hz.2 hz.1 rw [continuousWithinAt_update_of_ne hz.2] at H exact H.mono diff_subset · rw [continuousWithinAt_update_of_ne hzx] refine (H z ⟨hzs, hzx⟩).mono_of_mem (inter_mem_nhdsWithin _ ?_) exact isOpen_ne.mem_nhds hzx · exact continuousWithinAt_update_same #align continuous_on_update_iff continuousOn_update_iff theorem t1Space_of_injective_of_continuous [TopologicalSpace Y] {f : X → Y} (hf : Function.Injective f) (hf' : Continuous f) [T1Space Y] : T1Space X := t1Space_iff_specializes_imp_eq.2 fun _ _ h => hf (h.map hf').eq #align t1_space_of_injective_of_continuous t1Space_of_injective_of_continuous protected theorem Embedding.t1Space [TopologicalSpace Y] [T1Space Y] {f : X → Y} (hf : Embedding f) : T1Space X := t1Space_of_injective_of_continuous hf.inj hf.continuous #align embedding.t1_space Embedding.t1Space instance Subtype.t1Space {X : Type u} [TopologicalSpace X] [T1Space X] {p : X → Prop} : T1Space (Subtype p) := embedding_subtype_val.t1Space #align subtype.t1_space Subtype.t1Space instance [TopologicalSpace Y] [T1Space X] [T1Space Y] : T1Space (X × Y) := ⟨fun ⟨a, b⟩ => @singleton_prod_singleton _ _ a b ▸ isClosed_singleton.prod isClosed_singleton⟩ instance {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, T1Space (X i)] : T1Space (∀ i, X i) := ⟨fun f => univ_pi_singleton f ▸ isClosed_set_pi fun _ _ => isClosed_singleton⟩ instance ULift.instT1Space [T1Space X] : T1Space (ULift X) := embedding_uLift_down.t1Space -- see Note [lower instance priority] instance (priority := 100) TotallyDisconnectedSpace.t1Space [h: TotallyDisconnectedSpace X] : T1Space X := by rw [((t1Space_TFAE X).out 0 1 :)] intro x rw [← totallyDisconnectedSpace_iff_connectedComponent_singleton.mp h x] exact isClosed_connectedComponent -- see Note [lower instance priority] instance (priority := 100) T1Space.t0Space [T1Space X] : T0Space X := ⟨fun _ _ h => h.specializes.eq⟩ #align t1_space.t0_space T1Space.t0Space @[simp] theorem compl_singleton_mem_nhds_iff [T1Space X] {x y : X} : {x}ᶜ ∈ 𝓝 y ↔ y ≠ x := isOpen_compl_singleton.mem_nhds_iff #align compl_singleton_mem_nhds_iff compl_singleton_mem_nhds_iff theorem compl_singleton_mem_nhds [T1Space X] {x y : X} (h : y ≠ x) : {x}ᶜ ∈ 𝓝 y := compl_singleton_mem_nhds_iff.mpr h #align compl_singleton_mem_nhds compl_singleton_mem_nhds @[simp] theorem closure_singleton [T1Space X] {x : X} : closure ({x} : Set X) = {x} := isClosed_singleton.closure_eq #align closure_singleton closure_singleton -- Porting note (#11215): TODO: the proof was `hs.induction_on (by simp) fun x => by simp` theorem Set.Subsingleton.closure [T1Space X] {s : Set X} (hs : s.Subsingleton) : (closure s).Subsingleton := by rcases hs.eq_empty_or_singleton with (rfl | ⟨x, rfl⟩) <;> simp #align set.subsingleton.closure Set.Subsingleton.closure @[simp] theorem subsingleton_closure [T1Space X] {s : Set X} : (closure s).Subsingleton ↔ s.Subsingleton := ⟨fun h => h.anti subset_closure, fun h => h.closure⟩ #align subsingleton_closure subsingleton_closure theorem isClosedMap_const {X Y} [TopologicalSpace X] [TopologicalSpace Y] [T1Space Y] {y : Y} : IsClosedMap (Function.const X y) := IsClosedMap.of_nonempty fun s _ h2s => by simp_rw [const, h2s.image_const, isClosed_singleton] #align is_closed_map_const isClosedMap_const theorem nhdsWithin_insert_of_ne [T1Space X] {x y : X} {s : Set X} (hxy : x ≠ y) : 𝓝[insert y s] x = 𝓝[s] x := by refine le_antisymm (Filter.le_def.2 fun t ht => ?_) (nhdsWithin_mono x <| subset_insert y s) obtain ⟨o, ho, hxo, host⟩ := mem_nhdsWithin.mp ht refine mem_nhdsWithin.mpr ⟨o \ {y}, ho.sdiff isClosed_singleton, ⟨hxo, hxy⟩, ?_⟩ rw [inter_insert_of_not_mem <| not_mem_diff_of_mem (mem_singleton y)] exact (inter_subset_inter diff_subset Subset.rfl).trans host #align nhds_within_insert_of_ne nhdsWithin_insert_of_ne /-- If `t` is a subset of `s`, except for one point, then `insert x s` is a neighborhood of `x` within `t`. -/ theorem insert_mem_nhdsWithin_of_subset_insert [T1Space X] {x y : X} {s t : Set X} (hu : t ⊆ insert y s) : insert x s ∈ 𝓝[t] x := by rcases eq_or_ne x y with (rfl | h) · exact mem_of_superset self_mem_nhdsWithin hu refine nhdsWithin_mono x hu ?_ rw [nhdsWithin_insert_of_ne h] exact mem_of_superset self_mem_nhdsWithin (subset_insert x s) #align insert_mem_nhds_within_of_subset_insert insert_mem_nhdsWithin_of_subset_insert @[simp] theorem ker_nhds [T1Space X] (x : X) : (𝓝 x).ker = {x} := by simp [ker_nhds_eq_specializes] theorem biInter_basis_nhds [T1Space X] {ι : Sort*} {p : ι → Prop} {s : ι → Set X} {x : X} (h : (𝓝 x).HasBasis p s) : ⋂ (i) (_ : p i), s i = {x} := by rw [← h.ker, ker_nhds] #align bInter_basis_nhds biInter_basis_nhds @[simp] theorem compl_singleton_mem_nhdsSet_iff [T1Space X] {x : X} {s : Set X} : {x}ᶜ ∈ 𝓝ˢ s ↔ x ∉ s := by rw [isOpen_compl_singleton.mem_nhdsSet, subset_compl_singleton_iff] #align compl_singleton_mem_nhds_set_iff compl_singleton_mem_nhdsSet_iff @[simp] theorem nhdsSet_le_iff [T1Space X] {s t : Set X} : 𝓝ˢ s ≤ 𝓝ˢ t ↔ s ⊆ t := by refine ⟨?_, fun h => monotone_nhdsSet h⟩ simp_rw [Filter.le_def]; intro h x hx specialize h {x}ᶜ simp_rw [compl_singleton_mem_nhdsSet_iff] at h by_contra hxt exact h hxt hx #align nhds_set_le_iff nhdsSet_le_iff @[simp] theorem nhdsSet_inj_iff [T1Space X] {s t : Set X} : 𝓝ˢ s = 𝓝ˢ t ↔ s = t := by simp_rw [le_antisymm_iff] exact and_congr nhdsSet_le_iff nhdsSet_le_iff #align nhds_set_inj_iff nhdsSet_inj_iff theorem injective_nhdsSet [T1Space X] : Function.Injective (𝓝ˢ : Set X → Filter X) := fun _ _ hst => nhdsSet_inj_iff.mp hst #align injective_nhds_set injective_nhdsSet theorem strictMono_nhdsSet [T1Space X] : StrictMono (𝓝ˢ : Set X → Filter X) := monotone_nhdsSet.strictMono_of_injective injective_nhdsSet #align strict_mono_nhds_set strictMono_nhdsSet @[simp] theorem nhds_le_nhdsSet_iff [T1Space X] {s : Set X} {x : X} : 𝓝 x ≤ 𝓝ˢ s ↔ x ∈ s := by rw [← nhdsSet_singleton, nhdsSet_le_iff, singleton_subset_iff] #align nhds_le_nhds_set_iff nhds_le_nhdsSet_iff /-- Removing a non-isolated point from a dense set, one still obtains a dense set. -/ theorem Dense.diff_singleton [T1Space X] {s : Set X} (hs : Dense s) (x : X) [NeBot (𝓝[≠] x)] : Dense (s \ {x}) := hs.inter_of_isOpen_right (dense_compl_singleton x) isOpen_compl_singleton #align dense.diff_singleton Dense.diff_singleton /-- Removing a finset from a dense set in a space without isolated points, one still obtains a dense set. -/ theorem Dense.diff_finset [T1Space X] [∀ x : X, NeBot (𝓝[≠] x)] {s : Set X} (hs : Dense s) (t : Finset X) : Dense (s \ t) := by induction t using Finset.induction_on with | empty => simpa using hs | insert _ ih => rw [Finset.coe_insert, ← union_singleton, ← diff_diff] exact ih.diff_singleton _ #align dense.diff_finset Dense.diff_finset /-- Removing a finite set from a dense set in a space without isolated points, one still obtains a dense set. -/ theorem Dense.diff_finite [T1Space X] [∀ x : X, NeBot (𝓝[≠] x)] {s : Set X} (hs : Dense s) {t : Set X} (ht : t.Finite) : Dense (s \ t) := by convert hs.diff_finset ht.toFinset exact (Finite.coe_toFinset _).symm #align dense.diff_finite Dense.diff_finite /-- If a function to a `T1Space` tends to some limit `y` at some point `x`, then necessarily `y = f x`. -/ theorem eq_of_tendsto_nhds [TopologicalSpace Y] [T1Space Y] {f : X → Y} {x : X} {y : Y} (h : Tendsto f (𝓝 x) (𝓝 y)) : f x = y := by_contra fun hfa : f x ≠ y => have fact₁ : {f x}ᶜ ∈ 𝓝 y := compl_singleton_mem_nhds hfa.symm have fact₂ : Tendsto f (pure x) (𝓝 y) := h.comp (tendsto_id'.2 <| pure_le_nhds x) fact₂ fact₁ (Eq.refl <| f x) #align eq_of_tendsto_nhds eq_of_tendsto_nhds theorem Filter.Tendsto.eventually_ne [TopologicalSpace Y] [T1Space Y] {g : X → Y} {l : Filter X} {b₁ b₂ : Y} (hg : Tendsto g l (𝓝 b₁)) (hb : b₁ ≠ b₂) : ∀ᶠ z in l, g z ≠ b₂ := hg.eventually (isOpen_compl_singleton.eventually_mem hb) #align filter.tendsto.eventually_ne Filter.Tendsto.eventually_ne theorem ContinuousAt.eventually_ne [TopologicalSpace Y] [T1Space Y] {g : X → Y} {x : X} {y : Y} (hg1 : ContinuousAt g x) (hg2 : g x ≠ y) : ∀ᶠ z in 𝓝 x, g z ≠ y := hg1.tendsto.eventually_ne hg2 #align continuous_at.eventually_ne ContinuousAt.eventually_ne theorem eventually_ne_nhds [T1Space X] {a b : X} (h : a ≠ b) : ∀ᶠ x in 𝓝 a, x ≠ b := IsOpen.eventually_mem isOpen_ne h theorem eventually_ne_nhdsWithin [T1Space X] {a b : X} {s : Set X} (h : a ≠ b) : ∀ᶠ x in 𝓝[s] a, x ≠ b := Filter.Eventually.filter_mono nhdsWithin_le_nhds <| eventually_ne_nhds h /-- To prove a function to a `T1Space` is continuous at some point `x`, it suffices to prove that `f` admits *some* limit at `x`. -/ theorem continuousAt_of_tendsto_nhds [TopologicalSpace Y] [T1Space Y] {f : X → Y} {x : X} {y : Y} (h : Tendsto f (𝓝 x) (𝓝 y)) : ContinuousAt f x := by rwa [ContinuousAt, eq_of_tendsto_nhds h] #align continuous_at_of_tendsto_nhds continuousAt_of_tendsto_nhds @[simp] theorem tendsto_const_nhds_iff [T1Space X] {l : Filter Y} [NeBot l] {c d : X} : Tendsto (fun _ => c) l (𝓝 d) ↔ c = d := by simp_rw [Tendsto, Filter.map_const, pure_le_nhds_iff] #align tendsto_const_nhds_iff tendsto_const_nhds_iff /-- A point with a finite neighborhood has to be isolated. -/ theorem isOpen_singleton_of_finite_mem_nhds [T1Space X] (x : X) {s : Set X} (hs : s ∈ 𝓝 x) (hsf : s.Finite) : IsOpen ({x} : Set X) := by have A : {x} ⊆ s := by simp only [singleton_subset_iff, mem_of_mem_nhds hs] have B : IsClosed (s \ {x}) := (hsf.subset diff_subset).isClosed have C : (s \ {x})ᶜ ∈ 𝓝 x := B.isOpen_compl.mem_nhds fun h => h.2 rfl have D : {x} ∈ 𝓝 x := by simpa only [← diff_eq, diff_diff_cancel_left A] using inter_mem hs C rwa [← mem_interior_iff_mem_nhds, ← singleton_subset_iff, subset_interior_iff_isOpen] at D #align is_open_singleton_of_finite_mem_nhds isOpen_singleton_of_finite_mem_nhds /-- If the punctured neighborhoods of a point form a nontrivial filter, then any neighborhood is infinite. -/ theorem infinite_of_mem_nhds {X} [TopologicalSpace X] [T1Space X] (x : X) [hx : NeBot (𝓝[≠] x)] {s : Set X} (hs : s ∈ 𝓝 x) : Set.Infinite s := by refine fun hsf => hx.1 ?_ rw [← isOpen_singleton_iff_punctured_nhds] exact isOpen_singleton_of_finite_mem_nhds x hs hsf #align infinite_of_mem_nhds infinite_of_mem_nhds theorem discrete_of_t1_of_finite [T1Space X] [Finite X] : DiscreteTopology X := by apply singletons_open_iff_discrete.mp intro x rw [← isClosed_compl_iff] exact (Set.toFinite _).isClosed #align discrete_of_t1_of_finite discrete_of_t1_of_finite theorem PreconnectedSpace.trivial_of_discrete [PreconnectedSpace X] [DiscreteTopology X] : Subsingleton X := by rw [← not_nontrivial_iff_subsingleton] rintro ⟨x, y, hxy⟩ rw [Ne, ← mem_singleton_iff, (isClopen_discrete _).eq_univ <| singleton_nonempty y] at hxy exact hxy (mem_univ x) #align preconnected_space.trivial_of_discrete PreconnectedSpace.trivial_of_discrete theorem IsPreconnected.infinite_of_nontrivial [T1Space X] {s : Set X} (h : IsPreconnected s) (hs : s.Nontrivial) : s.Infinite := by refine mt (fun hf => (subsingleton_coe s).mp ?_) (not_subsingleton_iff.mpr hs) haveI := @discrete_of_t1_of_finite s _ _ hf.to_subtype exact @PreconnectedSpace.trivial_of_discrete _ _ (Subtype.preconnectedSpace h) _ #align is_preconnected.infinite_of_nontrivial IsPreconnected.infinite_of_nontrivial theorem ConnectedSpace.infinite [ConnectedSpace X] [Nontrivial X] [T1Space X] : Infinite X := infinite_univ_iff.mp <| isPreconnected_univ.infinite_of_nontrivial nontrivial_univ #align connected_space.infinite ConnectedSpace.infinite /-- A non-trivial connected T1 space has no isolated points. -/ instance (priority := 100) ConnectedSpace.neBot_nhdsWithin_compl_of_nontrivial_of_t1space [ConnectedSpace X] [Nontrivial X] [T1Space X] (x : X) : NeBot (𝓝[≠] x) := by by_contra contra rw [not_neBot, ← isOpen_singleton_iff_punctured_nhds] at contra replace contra := nonempty_inter isOpen_compl_singleton contra (compl_union_self _) (Set.nonempty_compl_of_nontrivial _) (singleton_nonempty _) simp [compl_inter_self {x}] at contra theorem SeparationQuotient.t1Space_iff : T1Space (SeparationQuotient X) ↔ R0Space X := by rw [r0Space_iff, ((t1Space_TFAE (SeparationQuotient X)).out 0 9 :)] constructor · intro h x y xspecy rw [← Inducing.specializes_iff inducing_mk, h xspecy] at * · rintro h ⟨x⟩ ⟨y⟩ sxspecsy have xspecy : x ⤳ y := (Inducing.specializes_iff inducing_mk).mp sxspecsy have yspecx : y ⤳ x := h xspecy erw [mk_eq_mk, inseparable_iff_specializes_and] exact ⟨xspecy, yspecx⟩ theorem singleton_mem_nhdsWithin_of_mem_discrete {s : Set X} [DiscreteTopology s] {x : X} (hx : x ∈ s) : {x} ∈ 𝓝[s] x := by have : ({⟨x, hx⟩} : Set s) ∈ 𝓝 (⟨x, hx⟩ : s) := by simp [nhds_discrete] simpa only [nhdsWithin_eq_map_subtype_coe hx, image_singleton] using @image_mem_map _ _ _ ((↑) : s → X) _ this #align singleton_mem_nhds_within_of_mem_discrete singleton_mem_nhdsWithin_of_mem_discrete /-- The neighbourhoods filter of `x` within `s`, under the discrete topology, is equal to the pure `x` filter (which is the principal filter at the singleton `{x}`.) -/ theorem nhdsWithin_of_mem_discrete {s : Set X} [DiscreteTopology s] {x : X} (hx : x ∈ s) : 𝓝[s] x = pure x := le_antisymm (le_pure_iff.2 <| singleton_mem_nhdsWithin_of_mem_discrete hx) (pure_le_nhdsWithin hx) #align nhds_within_of_mem_discrete nhdsWithin_of_mem_discrete theorem Filter.HasBasis.exists_inter_eq_singleton_of_mem_discrete {ι : Type*} {p : ι → Prop} {t : ι → Set X} {s : Set X} [DiscreteTopology s] {x : X} (hb : (𝓝 x).HasBasis p t) (hx : x ∈ s) : ∃ i, p i ∧ t i ∩ s = {x} := by rcases (nhdsWithin_hasBasis hb s).mem_iff.1 (singleton_mem_nhdsWithin_of_mem_discrete hx) with ⟨i, hi, hix⟩ exact ⟨i, hi, hix.antisymm <| singleton_subset_iff.2 ⟨mem_of_mem_nhds <| hb.mem_of_mem hi, hx⟩⟩ #align filter.has_basis.exists_inter_eq_singleton_of_mem_discrete Filter.HasBasis.exists_inter_eq_singleton_of_mem_discrete /-- A point `x` in a discrete subset `s` of a topological space admits a neighbourhood that only meets `s` at `x`. -/ theorem nhds_inter_eq_singleton_of_mem_discrete {s : Set X} [DiscreteTopology s] {x : X} (hx : x ∈ s) : ∃ U ∈ 𝓝 x, U ∩ s = {x} := by simpa using (𝓝 x).basis_sets.exists_inter_eq_singleton_of_mem_discrete hx #align nhds_inter_eq_singleton_of_mem_discrete nhds_inter_eq_singleton_of_mem_discrete /-- Let `x` be a point in a discrete subset `s` of a topological space, then there exists an open set that only meets `s` at `x`. -/ theorem isOpen_inter_eq_singleton_of_mem_discrete {s : Set X} [DiscreteTopology s] {x : X} (hx : x ∈ s) : ∃ U : Set X, IsOpen U ∧ U ∩ s = {x} := by obtain ⟨U, hU_nhds, hU_inter⟩ := nhds_inter_eq_singleton_of_mem_discrete hx obtain ⟨t, ht_sub, ht_open, ht_x⟩ := mem_nhds_iff.mp hU_nhds refine ⟨t, ht_open, Set.Subset.antisymm ?_ ?_⟩ · exact hU_inter ▸ Set.inter_subset_inter_left s ht_sub · rw [Set.subset_inter_iff, Set.singleton_subset_iff, Set.singleton_subset_iff] exact ⟨ht_x, hx⟩ /-- For point `x` in a discrete subset `s` of a topological space, there is a set `U` such that 1. `U` is a punctured neighborhood of `x` (ie. `U ∪ {x}` is a neighbourhood of `x`), 2. `U` is disjoint from `s`. -/ theorem disjoint_nhdsWithin_of_mem_discrete {s : Set X} [DiscreteTopology s] {x : X} (hx : x ∈ s) : ∃ U ∈ 𝓝[≠] x, Disjoint U s := let ⟨V, h, h'⟩ := nhds_inter_eq_singleton_of_mem_discrete hx ⟨{x}ᶜ ∩ V, inter_mem_nhdsWithin _ h, disjoint_iff_inter_eq_empty.mpr (by rw [inter_assoc, h', compl_inter_self])⟩ #align disjoint_nhds_within_of_mem_discrete disjoint_nhdsWithin_of_mem_discrete /-- Let `X` be a topological space and let `s, t ⊆ X` be two subsets. If there is an inclusion `t ⊆ s`, then the topological space structure on `t` induced by `X` is the same as the one obtained by the induced topological space structure on `s`. Use `embedding_inclusion` instead. -/ @[deprecated embedding_inclusion (since := "2023-02-02")] theorem TopologicalSpace.subset_trans {s t : Set X} (ts : t ⊆ s) : (instTopologicalSpaceSubtype : TopologicalSpace t) = (instTopologicalSpaceSubtype : TopologicalSpace s).induced (Set.inclusion ts) := (embedding_inclusion ts).induced #align topological_space.subset_trans TopologicalSpace.subset_trans /-! ### R₁ (preregular) spaces -/ section R1Space /-- A topological space is called a *preregular* (a.k.a. R₁) space, if any two topologically distinguishable points have disjoint neighbourhoods. -/ @[mk_iff r1Space_iff_specializes_or_disjoint_nhds] class R1Space (X : Type*) [TopologicalSpace X] : Prop where specializes_or_disjoint_nhds (x y : X) : Specializes x y ∨ Disjoint (𝓝 x) (𝓝 y) export R1Space (specializes_or_disjoint_nhds) variable [R1Space X] {x y : X} instance (priority := 100) : R0Space X where specializes_symmetric _ _ h := (specializes_or_disjoint_nhds _ _).resolve_right <| fun hd ↦ h.not_disjoint hd.symm theorem disjoint_nhds_nhds_iff_not_specializes : Disjoint (𝓝 x) (𝓝 y) ↔ ¬x ⤳ y := ⟨fun hd hspec ↦ hspec.not_disjoint hd, (specializes_or_disjoint_nhds _ _).resolve_left⟩ #align disjoint_nhds_nhds_iff_not_specializes disjoint_nhds_nhds_iff_not_specializes theorem specializes_iff_not_disjoint : x ⤳ y ↔ ¬Disjoint (𝓝 x) (𝓝 y) := disjoint_nhds_nhds_iff_not_specializes.not_left.symm theorem disjoint_nhds_nhds_iff_not_inseparable : Disjoint (𝓝 x) (𝓝 y) ↔ ¬Inseparable x y := by rw [disjoint_nhds_nhds_iff_not_specializes, specializes_iff_inseparable] theorem r1Space_iff_inseparable_or_disjoint_nhds {X : Type*} [TopologicalSpace X]: R1Space X ↔ ∀ x y : X, Inseparable x y ∨ Disjoint (𝓝 x) (𝓝 y) := ⟨fun _h x y ↦ (specializes_or_disjoint_nhds x y).imp_left Specializes.inseparable, fun h ↦ ⟨fun x y ↦ (h x y).imp_left Inseparable.specializes⟩⟩ theorem isClosed_setOf_specializes : IsClosed { p : X × X | p.1 ⤳ p.2 } := by simp only [← isOpen_compl_iff, compl_setOf, ← disjoint_nhds_nhds_iff_not_specializes, isOpen_setOf_disjoint_nhds_nhds] #align is_closed_set_of_specializes isClosed_setOf_specializes theorem isClosed_setOf_inseparable : IsClosed { p : X × X | Inseparable p.1 p.2 } := by simp only [← specializes_iff_inseparable, isClosed_setOf_specializes] #align is_closed_set_of_inseparable isClosed_setOf_inseparable /-- In an R₁ space, a point belongs to the closure of a compact set `K` if and only if it is topologically inseparable from some point of `K`. -/ theorem IsCompact.mem_closure_iff_exists_inseparable {K : Set X} (hK : IsCompact K) : y ∈ closure K ↔ ∃ x ∈ K, Inseparable x y := by refine ⟨fun hy ↦ ?_, fun ⟨x, hxK, hxy⟩ ↦ (hxy.mem_closed_iff isClosed_closure).1 <| subset_closure hxK⟩ contrapose! hy have : Disjoint (𝓝 y) (𝓝ˢ K) := hK.disjoint_nhdsSet_right.2 fun x hx ↦ (disjoint_nhds_nhds_iff_not_inseparable.2 (hy x hx)).symm simpa only [disjoint_iff, not_mem_closure_iff_nhdsWithin_eq_bot] using this.mono_right principal_le_nhdsSet theorem IsCompact.closure_eq_biUnion_inseparable {K : Set X} (hK : IsCompact K) : closure K = ⋃ x ∈ K, {y | Inseparable x y} := by ext; simp [hK.mem_closure_iff_exists_inseparable] /-- In an R₁ space, the closure of a compact set is the union of the closures of its points. -/ theorem IsCompact.closure_eq_biUnion_closure_singleton {K : Set X} (hK : IsCompact K) : closure K = ⋃ x ∈ K, closure {x} := by simp only [hK.closure_eq_biUnion_inseparable, ← specializes_iff_inseparable, specializes_iff_mem_closure, setOf_mem_eq] /-- In an R₁ space, if a compact set `K` is contained in an open set `U`, then its closure is also contained in `U`. -/ theorem IsCompact.closure_subset_of_isOpen {K : Set X} (hK : IsCompact K) {U : Set X} (hU : IsOpen U) (hKU : K ⊆ U) : closure K ⊆ U := by rw [hK.closure_eq_biUnion_inseparable, iUnion₂_subset_iff] exact fun x hx y hxy ↦ (hxy.mem_open_iff hU).1 (hKU hx) /-- The closure of a compact set in an R₁ space is a compact set. -/ protected theorem IsCompact.closure {K : Set X} (hK : IsCompact K) : IsCompact (closure K) := by refine isCompact_of_finite_subcover fun U hUo hKU ↦ ?_ rcases hK.elim_finite_subcover U hUo (subset_closure.trans hKU) with ⟨t, ht⟩ exact ⟨t, hK.closure_subset_of_isOpen (isOpen_biUnion fun _ _ ↦ hUo _) ht⟩ theorem IsCompact.closure_of_subset {s K : Set X} (hK : IsCompact K) (h : s ⊆ K) : IsCompact (closure s) := hK.closure.of_isClosed_subset isClosed_closure (closure_mono h) #align is_compact_closure_of_subset_compact IsCompact.closure_of_subset @[deprecated (since := "2024-01-28")] alias isCompact_closure_of_subset_compact := IsCompact.closure_of_subset @[simp] theorem exists_isCompact_superset_iff {s : Set X} : (∃ K, IsCompact K ∧ s ⊆ K) ↔ IsCompact (closure s) := ⟨fun ⟨_K, hK, hsK⟩ => hK.closure_of_subset hsK, fun h => ⟨closure s, h, subset_closure⟩⟩ #align exists_compact_superset_iff exists_isCompact_superset_iff @[deprecated (since := "2024-01-28")] alias exists_compact_superset_iff := exists_isCompact_superset_iff /-- If `K` and `L` are disjoint compact sets in an R₁ topological space and `L` is also closed, then `K` and `L` have disjoint neighborhoods. -/ theorem SeparatedNhds.of_isCompact_isCompact_isClosed {K L : Set X} (hK : IsCompact K) (hL : IsCompact L) (h'L : IsClosed L) (hd : Disjoint K L) : SeparatedNhds K L := by simp_rw [separatedNhds_iff_disjoint, hK.disjoint_nhdsSet_left, hL.disjoint_nhdsSet_right, disjoint_nhds_nhds_iff_not_inseparable] intro x hx y hy h exact absurd ((h.mem_closed_iff h'L).2 hy) <| disjoint_left.1 hd hx @[deprecated (since := "2024-01-28")] alias separatedNhds_of_isCompact_isCompact_isClosed := SeparatedNhds.of_isCompact_isCompact_isClosed /-- If a compact set is covered by two open sets, then we can cover it by two compact subsets. -/ theorem IsCompact.binary_compact_cover {K U V : Set X} (hK : IsCompact K) (hU : IsOpen U) (hV : IsOpen V) (h2K : K ⊆ U ∪ V) : ∃ K₁ K₂ : Set X, IsCompact K₁ ∧ IsCompact K₂ ∧ K₁ ⊆ U ∧ K₂ ⊆ V ∧ K = K₁ ∪ K₂ := by have hK' : IsCompact (closure K) := hK.closure have : SeparatedNhds (closure K \ U) (closure K \ V) := by apply SeparatedNhds.of_isCompact_isCompact_isClosed (hK'.diff hU) (hK'.diff hV) (isClosed_closure.sdiff hV) rw [disjoint_iff_inter_eq_empty, diff_inter_diff, diff_eq_empty] exact hK.closure_subset_of_isOpen (hU.union hV) h2K have : SeparatedNhds (K \ U) (K \ V) := this.mono (diff_subset_diff_left (subset_closure)) (diff_subset_diff_left (subset_closure)) rcases this with ⟨O₁, O₂, h1O₁, h1O₂, h2O₁, h2O₂, hO⟩ exact ⟨K \ O₁, K \ O₂, hK.diff h1O₁, hK.diff h1O₂, diff_subset_comm.mp h2O₁, diff_subset_comm.mp h2O₂, by rw [← diff_inter, hO.inter_eq, diff_empty]⟩ #align is_compact.binary_compact_cover IsCompact.binary_compact_cover /-- For every finite open cover `Uᵢ` of a compact set, there exists a compact cover `Kᵢ ⊆ Uᵢ`. -/ theorem IsCompact.finite_compact_cover {s : Set X} (hs : IsCompact s) {ι : Type*} (t : Finset ι) (U : ι → Set X) (hU : ∀ i ∈ t, IsOpen (U i)) (hsC : s ⊆ ⋃ i ∈ t, U i) : ∃ K : ι → Set X, (∀ i, IsCompact (K i)) ∧ (∀ i, K i ⊆ U i) ∧ s = ⋃ i ∈ t, K i := by induction' t using Finset.induction with x t hx ih generalizing U s · refine ⟨fun _ => ∅, fun _ => isCompact_empty, fun i => empty_subset _, ?_⟩ simpa only [subset_empty_iff, Finset.not_mem_empty, iUnion_false, iUnion_empty] using hsC simp only [Finset.set_biUnion_insert] at hsC simp only [Finset.forall_mem_insert] at hU have hU' : ∀ i ∈ t, IsOpen (U i) := fun i hi => hU.2 i hi rcases hs.binary_compact_cover hU.1 (isOpen_biUnion hU') hsC with ⟨K₁, K₂, h1K₁, h1K₂, h2K₁, h2K₂, hK⟩ rcases ih h1K₂ U hU' h2K₂ with ⟨K, h1K, h2K, h3K⟩ refine ⟨update K x K₁, ?_, ?_, ?_⟩ · intro i rcases eq_or_ne i x with rfl | hi · simp only [update_same, h1K₁] · simp only [update_noteq hi, h1K] · intro i rcases eq_or_ne i x with rfl | hi · simp only [update_same, h2K₁] · simp only [update_noteq hi, h2K] · simp only [Finset.set_biUnion_insert_update _ hx, hK, h3K] #align is_compact.finite_compact_cover IsCompact.finite_compact_cover theorem R1Space.of_continuous_specializes_imp [TopologicalSpace Y] {f : Y → X} (hc : Continuous f) (hspec : ∀ x y, f x ⤳ f y → x ⤳ y) : R1Space Y where specializes_or_disjoint_nhds x y := (specializes_or_disjoint_nhds (f x) (f y)).imp (hspec x y) <| ((hc.tendsto _).disjoint · (hc.tendsto _)) theorem Inducing.r1Space [TopologicalSpace Y] {f : Y → X} (hf : Inducing f) : R1Space Y := .of_continuous_specializes_imp hf.continuous fun _ _ ↦ hf.specializes_iff.1 protected theorem R1Space.induced (f : Y → X) : @R1Space Y (.induced f ‹_›) := @Inducing.r1Space _ _ _ _ (.induced f _) f (inducing_induced f) instance (p : X → Prop) : R1Space (Subtype p) := .induced _ protected theorem R1Space.sInf {X : Type*} {T : Set (TopologicalSpace X)} (hT : ∀ t ∈ T, @R1Space X t) : @R1Space X (sInf T) := by let _ := sInf T refine ⟨fun x y ↦ ?_⟩ simp only [Specializes, nhds_sInf] rcases em (∃ t ∈ T, Disjoint (@nhds X t x) (@nhds X t y)) with ⟨t, htT, htd⟩ | hTd · exact .inr <| htd.mono (iInf₂_le t htT) (iInf₂_le t htT) · push_neg at hTd exact .inl <| iInf₂_mono fun t ht ↦ ((hT t ht).1 x y).resolve_right (hTd t ht) protected theorem R1Space.iInf {ι X : Type*} {t : ι → TopologicalSpace X} (ht : ∀ i, @R1Space X (t i)) : @R1Space X (iInf t) := .sInf <| forall_mem_range.2 ht protected theorem R1Space.inf {X : Type*} {t₁ t₂ : TopologicalSpace X} (h₁ : @R1Space X t₁) (h₂ : @R1Space X t₂) : @R1Space X (t₁ ⊓ t₂) := by rw [inf_eq_iInf] apply R1Space.iInf simp [*] instance [TopologicalSpace Y] [R1Space Y] : R1Space (X × Y) := .inf (.induced _) (.induced _) instance {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, R1Space (X i)] : R1Space (∀ i, X i) := .iInf fun _ ↦ .induced _ theorem exists_mem_nhds_isCompact_mapsTo_of_isCompact_mem_nhds {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] [R1Space Y] {f : X → Y} {x : X} {K : Set X} {s : Set Y} (hf : Continuous f) (hs : s ∈ 𝓝 (f x)) (hKc : IsCompact K) (hKx : K ∈ 𝓝 x) : ∃ K ∈ 𝓝 x, IsCompact K ∧ MapsTo f K s := by have hc : IsCompact (f '' K \ interior s) := (hKc.image hf).diff isOpen_interior obtain ⟨U, V, Uo, Vo, hxU, hV, hd⟩ : SeparatedNhds {f x} (f '' K \ interior s) := by simp_rw [separatedNhds_iff_disjoint, nhdsSet_singleton, hc.disjoint_nhdsSet_right, disjoint_nhds_nhds_iff_not_inseparable] rintro y ⟨-, hys⟩ hxy refine hys <| (hxy.mem_open_iff isOpen_interior).1 ?_ rwa [mem_interior_iff_mem_nhds] refine ⟨K \ f ⁻¹' V, diff_mem hKx ?_, hKc.diff <| Vo.preimage hf, fun y hy ↦ ?_⟩ · filter_upwards [hf.continuousAt <| Uo.mem_nhds (hxU rfl)] with x hx using Set.disjoint_left.1 hd hx · by_contra hys exact hy.2 (hV ⟨mem_image_of_mem _ hy.1, not_mem_subset interior_subset hys⟩) instance (priority := 900) {X Y : Type*} [TopologicalSpace X] [WeaklyLocallyCompactSpace X] [TopologicalSpace Y] [R1Space Y] : LocallyCompactPair X Y where exists_mem_nhds_isCompact_mapsTo hf hs := let ⟨_K, hKc, hKx⟩ := exists_compact_mem_nhds _ exists_mem_nhds_isCompact_mapsTo_of_isCompact_mem_nhds hf hs hKc hKx /-- If a point in an R₁ space has a compact neighborhood, then it has a basis of compact closed neighborhoods. -/ theorem IsCompact.isCompact_isClosed_basis_nhds {x : X} {L : Set X} (hLc : IsCompact L) (hxL : L ∈ 𝓝 x) : (𝓝 x).HasBasis (fun K ↦ K ∈ 𝓝 x ∧ IsCompact K ∧ IsClosed K) (·) := hasBasis_self.2 fun _U hU ↦ let ⟨K, hKx, hKc, hKU⟩ := exists_mem_nhds_isCompact_mapsTo_of_isCompact_mem_nhds continuous_id (interior_mem_nhds.2 hU) hLc hxL ⟨closure K, mem_of_superset hKx subset_closure, ⟨hKc.closure, isClosed_closure⟩, (hKc.closure_subset_of_isOpen isOpen_interior hKU).trans interior_subset⟩ /-- In an R₁ space, the filters `coclosedCompact` and `cocompact` are equal. -/ @[simp] theorem Filter.coclosedCompact_eq_cocompact : coclosedCompact X = cocompact X := by refine le_antisymm ?_ cocompact_le_coclosedCompact rw [hasBasis_coclosedCompact.le_basis_iff hasBasis_cocompact] exact fun K hK ↦ ⟨closure K, ⟨isClosed_closure, hK.closure⟩, compl_subset_compl.2 subset_closure⟩ #align filter.coclosed_compact_eq_cocompact Filter.coclosedCompact_eq_cocompact /-- In an R₁ space, the bornologies `relativelyCompact` and `inCompact` are equal. -/ @[simp] theorem Bornology.relativelyCompact_eq_inCompact : Bornology.relativelyCompact X = Bornology.inCompact X := Bornology.ext _ _ Filter.coclosedCompact_eq_cocompact #align bornology.relatively_compact_eq_in_compact Bornology.relativelyCompact_eq_inCompact /-! ### Lemmas about a weakly locally compact R₁ space In fact, a space with these properties is locally compact and regular. Some lemmas are formulated using the latter assumptions below. -/ variable [WeaklyLocallyCompactSpace X] /-- In a (weakly) locally compact R₁ space, compact closed neighborhoods of a point `x` form a basis of neighborhoods of `x`. -/ theorem isCompact_isClosed_basis_nhds (x : X) : (𝓝 x).HasBasis (fun K => K ∈ 𝓝 x ∧ IsCompact K ∧ IsClosed K) (·) := let ⟨_L, hLc, hLx⟩ := exists_compact_mem_nhds x hLc.isCompact_isClosed_basis_nhds hLx /-- In a (weakly) locally compact R₁ space, each point admits a compact closed neighborhood. -/ theorem exists_mem_nhds_isCompact_isClosed (x : X) : ∃ K ∈ 𝓝 x, IsCompact K ∧ IsClosed K := (isCompact_isClosed_basis_nhds x).ex_mem -- see Note [lower instance priority] /-- A weakly locally compact R₁ space is locally compact. -/ instance (priority := 80) WeaklyLocallyCompactSpace.locallyCompactSpace : LocallyCompactSpace X := .of_hasBasis isCompact_isClosed_basis_nhds fun _ _ ⟨_, h, _⟩ ↦ h #align locally_compact_of_compact_nhds WeaklyLocallyCompactSpace.locallyCompactSpace /-- In a weakly locally compact R₁ space, every compact set has an open neighborhood with compact closure. -/ theorem exists_isOpen_superset_and_isCompact_closure {K : Set X} (hK : IsCompact K) : ∃ V, IsOpen V ∧ K ⊆ V ∧ IsCompact (closure V) := by rcases exists_compact_superset hK with ⟨K', hK', hKK'⟩ exact ⟨interior K', isOpen_interior, hKK', hK'.closure_of_subset interior_subset⟩ #align exists_open_superset_and_is_compact_closure exists_isOpen_superset_and_isCompact_closure @[deprecated (since := "2024-01-28")] alias exists_open_superset_and_isCompact_closure := exists_isOpen_superset_and_isCompact_closure /-- In a weakly locally compact R₁ space, every point has an open neighborhood with compact closure. -/ theorem exists_isOpen_mem_isCompact_closure (x : X) : ∃ U : Set X, IsOpen U ∧ x ∈ U ∧ IsCompact (closure U) := by simpa only [singleton_subset_iff] using exists_isOpen_superset_and_isCompact_closure isCompact_singleton #align exists_open_with_compact_closure exists_isOpen_mem_isCompact_closure @[deprecated (since := "2024-01-28")] alias exists_open_with_compact_closure := exists_isOpen_mem_isCompact_closure end R1Space /-- A T₂ space, also known as a Hausdorff space, is one in which for every `x ≠ y` there exists disjoint open sets around `x` and `y`. This is the most widely used of the separation axioms. -/ @[mk_iff] class T2Space (X : Type u) [TopologicalSpace X] : Prop where /-- Every two points in a Hausdorff space admit disjoint open neighbourhoods. -/ t2 : Pairwise fun x y => ∃ u v : Set X, IsOpen u ∧ IsOpen v ∧ x ∈ u ∧ y ∈ v ∧ Disjoint u v #align t2_space T2Space /-- Two different points can be separated by open sets. -/ theorem t2_separation [T2Space X] {x y : X} (h : x ≠ y) : ∃ u v : Set X, IsOpen u ∧ IsOpen v ∧ x ∈ u ∧ y ∈ v ∧ Disjoint u v := T2Space.t2 h #align t2_separation t2_separation -- todo: use this as a definition? theorem t2Space_iff_disjoint_nhds : T2Space X ↔ Pairwise fun x y : X => Disjoint (𝓝 x) (𝓝 y) := by refine (t2Space_iff X).trans (forall₃_congr fun x y _ => ?_) simp only [(nhds_basis_opens x).disjoint_iff (nhds_basis_opens y), exists_prop, ← exists_and_left, and_assoc, and_comm, and_left_comm] #align t2_space_iff_disjoint_nhds t2Space_iff_disjoint_nhds @[simp] theorem disjoint_nhds_nhds [T2Space X] {x y : X} : Disjoint (𝓝 x) (𝓝 y) ↔ x ≠ y := ⟨fun hd he => by simp [he, nhds_neBot.ne] at hd, (t2Space_iff_disjoint_nhds.mp ‹_› ·)⟩ #align disjoint_nhds_nhds disjoint_nhds_nhds theorem pairwise_disjoint_nhds [T2Space X] : Pairwise (Disjoint on (𝓝 : X → Filter X)) := fun _ _ => disjoint_nhds_nhds.2 #align pairwise_disjoint_nhds pairwise_disjoint_nhds protected theorem Set.pairwiseDisjoint_nhds [T2Space X] (s : Set X) : s.PairwiseDisjoint 𝓝 := pairwise_disjoint_nhds.set_pairwise s #align set.pairwise_disjoint_nhds Set.pairwiseDisjoint_nhds /-- Points of a finite set can be separated by open sets from each other. -/ theorem Set.Finite.t2_separation [T2Space X] {s : Set X} (hs : s.Finite) : ∃ U : X → Set X, (∀ x, x ∈ U x ∧ IsOpen (U x)) ∧ s.PairwiseDisjoint U := s.pairwiseDisjoint_nhds.exists_mem_filter_basis hs nhds_basis_opens #align set.finite.t2_separation Set.Finite.t2_separation -- see Note [lower instance priority] instance (priority := 100) T2Space.t1Space [T2Space X] : T1Space X := t1Space_iff_disjoint_pure_nhds.mpr fun _ _ hne => (disjoint_nhds_nhds.2 hne).mono_left <| pure_le_nhds _ #align t2_space.t1_space T2Space.t1Space -- see Note [lower instance priority] instance (priority := 100) T2Space.r1Space [T2Space X] : R1Space X := ⟨fun x y ↦ (eq_or_ne x y).imp specializes_of_eq disjoint_nhds_nhds.2⟩ theorem SeparationQuotient.t2Space_iff : T2Space (SeparationQuotient X) ↔ R1Space X := by simp only [t2Space_iff_disjoint_nhds, Pairwise, surjective_mk.forall₂, ne_eq, mk_eq_mk, r1Space_iff_inseparable_or_disjoint_nhds, ← disjoint_comap_iff surjective_mk, comap_mk_nhds_mk, ← or_iff_not_imp_left] instance SeparationQuotient.t2Space [R1Space X] : T2Space (SeparationQuotient X) := t2Space_iff.2 ‹_› instance (priority := 80) [R1Space X] [T0Space X] : T2Space X := t2Space_iff_disjoint_nhds.2 fun _x _y hne ↦ disjoint_nhds_nhds_iff_not_inseparable.2 fun hxy ↦ hne hxy.eq theorem R1Space.t2Space_iff_t0Space [R1Space X] : T2Space X ↔ T0Space X := by constructor <;> intro <;> infer_instance /-- A space is T₂ iff the neighbourhoods of distinct points generate the bottom filter. -/ theorem t2_iff_nhds : T2Space X ↔ ∀ {x y : X}, NeBot (𝓝 x ⊓ 𝓝 y) → x = y := by simp only [t2Space_iff_disjoint_nhds, disjoint_iff, neBot_iff, Ne, not_imp_comm, Pairwise] #align t2_iff_nhds t2_iff_nhds theorem eq_of_nhds_neBot [T2Space X] {x y : X} (h : NeBot (𝓝 x ⊓ 𝓝 y)) : x = y := t2_iff_nhds.mp ‹_› h #align eq_of_nhds_ne_bot eq_of_nhds_neBot theorem t2Space_iff_nhds : T2Space X ↔ Pairwise fun x y : X => ∃ U ∈ 𝓝 x, ∃ V ∈ 𝓝 y, Disjoint U V := by simp only [t2Space_iff_disjoint_nhds, Filter.disjoint_iff, Pairwise] #align t2_space_iff_nhds t2Space_iff_nhds theorem t2_separation_nhds [T2Space X] {x y : X} (h : x ≠ y) : ∃ u v, u ∈ 𝓝 x ∧ v ∈ 𝓝 y ∧ Disjoint u v := let ⟨u, v, open_u, open_v, x_in, y_in, huv⟩ := t2_separation h ⟨u, v, open_u.mem_nhds x_in, open_v.mem_nhds y_in, huv⟩ #align t2_separation_nhds t2_separation_nhds theorem t2_separation_compact_nhds [LocallyCompactSpace X] [T2Space X] {x y : X} (h : x ≠ y) : ∃ u v, u ∈ 𝓝 x ∧ v ∈ 𝓝 y ∧ IsCompact u ∧ IsCompact v ∧ Disjoint u v := by simpa only [exists_prop, ← exists_and_left, and_comm, and_assoc, and_left_comm] using ((compact_basis_nhds x).disjoint_iff (compact_basis_nhds y)).1 (disjoint_nhds_nhds.2 h) #align t2_separation_compact_nhds t2_separation_compact_nhds theorem t2_iff_ultrafilter : T2Space X ↔ ∀ {x y : X} (f : Ultrafilter X), ↑f ≤ 𝓝 x → ↑f ≤ 𝓝 y → x = y := t2_iff_nhds.trans <| by simp only [← exists_ultrafilter_iff, and_imp, le_inf_iff, exists_imp] #align t2_iff_ultrafilter t2_iff_ultrafilter theorem t2_iff_isClosed_diagonal : T2Space X ↔ IsClosed (diagonal X) := by simp only [t2Space_iff_disjoint_nhds, ← isOpen_compl_iff, isOpen_iff_mem_nhds, Prod.forall, nhds_prod_eq, compl_diagonal_mem_prod, mem_compl_iff, mem_diagonal_iff, Pairwise] #align t2_iff_is_closed_diagonal t2_iff_isClosed_diagonal theorem isClosed_diagonal [T2Space X] : IsClosed (diagonal X) := t2_iff_isClosed_diagonal.mp ‹_› #align is_closed_diagonal isClosed_diagonal -- Porting note: 2 lemmas moved below theorem tendsto_nhds_unique [T2Space X] {f : Y → X} {l : Filter Y} {a b : X} [NeBot l] (ha : Tendsto f l (𝓝 a)) (hb : Tendsto f l (𝓝 b)) : a = b := eq_of_nhds_neBot <| neBot_of_le <| le_inf ha hb #align tendsto_nhds_unique tendsto_nhds_unique theorem tendsto_nhds_unique' [T2Space X] {f : Y → X} {l : Filter Y} {a b : X} (_ : NeBot l) (ha : Tendsto f l (𝓝 a)) (hb : Tendsto f l (𝓝 b)) : a = b := eq_of_nhds_neBot <| neBot_of_le <| le_inf ha hb #align tendsto_nhds_unique' tendsto_nhds_unique' theorem tendsto_nhds_unique_of_eventuallyEq [T2Space X] {f g : Y → X} {l : Filter Y} {a b : X} [NeBot l] (ha : Tendsto f l (𝓝 a)) (hb : Tendsto g l (𝓝 b)) (hfg : f =ᶠ[l] g) : a = b := tendsto_nhds_unique (ha.congr' hfg) hb #align tendsto_nhds_unique_of_eventually_eq tendsto_nhds_unique_of_eventuallyEq theorem tendsto_nhds_unique_of_frequently_eq [T2Space X] {f g : Y → X} {l : Filter Y} {a b : X} (ha : Tendsto f l (𝓝 a)) (hb : Tendsto g l (𝓝 b)) (hfg : ∃ᶠ x in l, f x = g x) : a = b := have : ∃ᶠ z : X × X in 𝓝 (a, b), z.1 = z.2 := (ha.prod_mk_nhds hb).frequently hfg not_not.1 fun hne => this (isClosed_diagonal.isOpen_compl.mem_nhds hne) #align tendsto_nhds_unique_of_frequently_eq tendsto_nhds_unique_of_frequently_eq /-- If `s` and `t` are compact sets in a T₂ space, then the set neighborhoods filter of `s ∩ t` is the infimum of set neighborhoods filters for `s` and `t`. For general sets, only the `≤` inequality holds, see `nhdsSet_inter_le`. -/ theorem IsCompact.nhdsSet_inter_eq [T2Space X] {s t : Set X} (hs : IsCompact s) (ht : IsCompact t) : 𝓝ˢ (s ∩ t) = 𝓝ˢ s ⊓ 𝓝ˢ t := by refine le_antisymm (nhdsSet_inter_le _ _) ?_ simp_rw [hs.nhdsSet_inf_eq_biSup, ht.inf_nhdsSet_eq_biSup, nhdsSet, sSup_image] refine iSup₂_le fun x hxs ↦ iSup₂_le fun y hyt ↦ ?_ rcases eq_or_ne x y with (rfl|hne) · exact le_iSup₂_of_le x ⟨hxs, hyt⟩ (inf_idem _).le · exact (disjoint_nhds_nhds.mpr hne).eq_bot ▸ bot_le /-- If a function `f` is - injective on a compact set `s`; - continuous at every point of this set; - injective on a neighborhood of each point of this set, then it is injective on a neighborhood of this set. -/ theorem Set.InjOn.exists_mem_nhdsSet {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] [T2Space Y] {f : X → Y} {s : Set X} (inj : InjOn f s) (sc : IsCompact s) (fc : ∀ x ∈ s, ContinuousAt f x) (loc : ∀ x ∈ s, ∃ u ∈ 𝓝 x, InjOn f u) : ∃ t ∈ 𝓝ˢ s, InjOn f t := by have : ∀ x ∈ s ×ˢ s, ∀ᶠ y in 𝓝 x, f y.1 = f y.2 → y.1 = y.2 := fun (x, y) ⟨hx, hy⟩ ↦ by rcases eq_or_ne x y with rfl | hne · rcases loc x hx with ⟨u, hu, hf⟩ exact Filter.mem_of_superset (prod_mem_nhds hu hu) <| forall_prod_set.2 hf · suffices ∀ᶠ z in 𝓝 (x, y), f z.1 ≠ f z.2 from this.mono fun _ hne h ↦ absurd h hne refine (fc x hx).prod_map' (fc y hy) <| isClosed_diagonal.isOpen_compl.mem_nhds ?_ exact inj.ne hx hy hne rw [← eventually_nhdsSet_iff_forall, sc.nhdsSet_prod_eq sc] at this exact eventually_prod_self_iff.1 this /-- If a function `f` is - injective on a compact set `s`; - continuous at every point of this set; - injective on a neighborhood of each point of this set, then it is injective on an open neighborhood of this set. -/ theorem Set.InjOn.exists_isOpen_superset {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] [T2Space Y] {f : X → Y} {s : Set X} (inj : InjOn f s) (sc : IsCompact s) (fc : ∀ x ∈ s, ContinuousAt f x) (loc : ∀ x ∈ s, ∃ u ∈ 𝓝 x, InjOn f u) : ∃ t, IsOpen t ∧ s ⊆ t ∧ InjOn f t := let ⟨_t, hst, ht⟩ := inj.exists_mem_nhdsSet sc fc loc let ⟨u, huo, hsu, hut⟩ := mem_nhdsSet_iff_exists.1 hst ⟨u, huo, hsu, ht.mono hut⟩ section limUnder variable [T2Space X] {f : Filter X} /-! ### Properties of `lim` and `limUnder` In this section we use explicit `Nonempty X` instances for `lim` and `limUnder`. This way the lemmas are useful without a `Nonempty X` instance. -/ theorem lim_eq {x : X} [NeBot f] (h : f ≤ 𝓝 x) : @lim _ _ ⟨x⟩ f = x := tendsto_nhds_unique (le_nhds_lim ⟨x, h⟩) h set_option linter.uppercaseLean3 false in #align Lim_eq lim_eq theorem lim_eq_iff [NeBot f] (h : ∃ x : X, f ≤ 𝓝 x) {x} : @lim _ _ ⟨x⟩ f = x ↔ f ≤ 𝓝 x := ⟨fun c => c ▸ le_nhds_lim h, lim_eq⟩ set_option linter.uppercaseLean3 false in #align Lim_eq_iff lim_eq_iff theorem Ultrafilter.lim_eq_iff_le_nhds [CompactSpace X] {x : X} {F : Ultrafilter X} : F.lim = x ↔ ↑F ≤ 𝓝 x := ⟨fun h => h ▸ F.le_nhds_lim, lim_eq⟩ set_option linter.uppercaseLean3 false in #align ultrafilter.Lim_eq_iff_le_nhds Ultrafilter.lim_eq_iff_le_nhds theorem isOpen_iff_ultrafilter' [CompactSpace X] (U : Set X) : IsOpen U ↔ ∀ F : Ultrafilter X, F.lim ∈ U → U ∈ F.1 := by rw [isOpen_iff_ultrafilter] refine ⟨fun h F hF => h F.lim hF F F.le_nhds_lim, ?_⟩ intro cond x hx f h rw [← Ultrafilter.lim_eq_iff_le_nhds.2 h] at hx exact cond _ hx #align is_open_iff_ultrafilter' isOpen_iff_ultrafilter' theorem Filter.Tendsto.limUnder_eq {x : X} {f : Filter Y} [NeBot f] {g : Y → X} (h : Tendsto g f (𝓝 x)) : @limUnder _ _ _ ⟨x⟩ f g = x := lim_eq h #align filter.tendsto.lim_eq Filter.Tendsto.limUnder_eq theorem Filter.limUnder_eq_iff {f : Filter Y} [NeBot f] {g : Y → X} (h : ∃ x, Tendsto g f (𝓝 x)) {x} : @limUnder _ _ _ ⟨x⟩ f g = x ↔ Tendsto g f (𝓝 x) := ⟨fun c => c ▸ tendsto_nhds_limUnder h, Filter.Tendsto.limUnder_eq⟩ #align filter.lim_eq_iff Filter.limUnder_eq_iff theorem Continuous.limUnder_eq [TopologicalSpace Y] {f : Y → X} (h : Continuous f) (y : Y) : @limUnder _ _ _ ⟨f y⟩ (𝓝 y) f = f y := (h.tendsto y).limUnder_eq #align continuous.lim_eq Continuous.limUnder_eq @[simp] theorem lim_nhds (x : X) : @lim _ _ ⟨x⟩ (𝓝 x) = x := lim_eq le_rfl set_option linter.uppercaseLean3 false in #align Lim_nhds lim_nhds @[simp] theorem limUnder_nhds_id (x : X) : @limUnder _ _ _ ⟨x⟩ (𝓝 x) id = x := lim_nhds x #align lim_nhds_id limUnder_nhds_id @[simp] theorem lim_nhdsWithin {x : X} {s : Set X} (h : x ∈ closure s) : @lim _ _ ⟨x⟩ (𝓝[s] x) = x := haveI : NeBot (𝓝[s] x) := mem_closure_iff_clusterPt.1 h lim_eq inf_le_left set_option linter.uppercaseLean3 false in #align Lim_nhds_within lim_nhdsWithin @[simp] theorem limUnder_nhdsWithin_id {x : X} {s : Set X} (h : x ∈ closure s) : @limUnder _ _ _ ⟨x⟩ (𝓝[s] x) id = x := lim_nhdsWithin h #align lim_nhds_within_id limUnder_nhdsWithin_id end limUnder /-! ### `T2Space` constructions We use two lemmas to prove that various standard constructions generate Hausdorff spaces from Hausdorff spaces: * `separated_by_continuous` says that two points `x y : X` can be separated by open neighborhoods provided that there exists a continuous map `f : X → Y` with a Hausdorff codomain such that `f x ≠ f y`. We use this lemma to prove that topological spaces defined using `induced` are Hausdorff spaces. * `separated_by_openEmbedding` says that for an open embedding `f : X → Y` of a Hausdorff space `X`, the images of two distinct points `x y : X`, `x ≠ y` can be separated by open neighborhoods. We use this lemma to prove that topological spaces defined using `coinduced` are Hausdorff spaces. -/ -- see Note [lower instance priority] instance (priority := 100) DiscreteTopology.toT2Space [DiscreteTopology X] : T2Space X := ⟨fun x y h => ⟨{x}, {y}, isOpen_discrete _, isOpen_discrete _, rfl, rfl, disjoint_singleton.2 h⟩⟩ #align discrete_topology.to_t2_space DiscreteTopology.toT2Space theorem separated_by_continuous [TopologicalSpace Y] [T2Space Y] {f : X → Y} (hf : Continuous f) {x y : X} (h : f x ≠ f y) : ∃ u v : Set X, IsOpen u ∧ IsOpen v ∧ x ∈ u ∧ y ∈ v ∧ Disjoint u v := let ⟨u, v, uo, vo, xu, yv, uv⟩ := t2_separation h ⟨f ⁻¹' u, f ⁻¹' v, uo.preimage hf, vo.preimage hf, xu, yv, uv.preimage _⟩ #align separated_by_continuous separated_by_continuous theorem separated_by_openEmbedding [TopologicalSpace Y] [T2Space X] {f : X → Y} (hf : OpenEmbedding f) {x y : X} (h : x ≠ y) : ∃ u v : Set Y, IsOpen u ∧ IsOpen v ∧ f x ∈ u ∧ f y ∈ v ∧ Disjoint u v := let ⟨u, v, uo, vo, xu, yv, uv⟩ := t2_separation h ⟨f '' u, f '' v, hf.isOpenMap _ uo, hf.isOpenMap _ vo, mem_image_of_mem _ xu, mem_image_of_mem _ yv, disjoint_image_of_injective hf.inj uv⟩ #align separated_by_open_embedding separated_by_openEmbedding instance {p : X → Prop} [T2Space X] : T2Space (Subtype p) := inferInstance instance Prod.t2Space [T2Space X] [TopologicalSpace Y] [T2Space Y] : T2Space (X × Y) := inferInstance /-- If the codomain of an injective continuous function is a Hausdorff space, then so is its domain. -/ theorem T2Space.of_injective_continuous [TopologicalSpace Y] [T2Space Y] {f : X → Y} (hinj : Injective f) (hc : Continuous f) : T2Space X := ⟨fun _ _ h => separated_by_continuous hc (hinj.ne h)⟩ /-- If the codomain of a topological embedding is a Hausdorff space, then so is its domain. See also `T2Space.of_continuous_injective`. -/ theorem Embedding.t2Space [TopologicalSpace Y] [T2Space Y] {f : X → Y} (hf : Embedding f) : T2Space X := .of_injective_continuous hf.inj hf.continuous #align embedding.t2_space Embedding.t2Space instance ULift.instT2Space [T2Space X] : T2Space (ULift X) := embedding_uLift_down.t2Space instance [T2Space X] [TopologicalSpace Y] [T2Space Y] : T2Space (X ⊕ Y) := by constructor rintro (x | x) (y | y) h · exact separated_by_openEmbedding openEmbedding_inl <| ne_of_apply_ne _ h · exact separated_by_continuous continuous_isLeft <| by simp · exact separated_by_continuous continuous_isLeft <| by simp · exact separated_by_openEmbedding openEmbedding_inr <| ne_of_apply_ne _ h instance Pi.t2Space {Y : X → Type v} [∀ a, TopologicalSpace (Y a)] [∀ a, T2Space (Y a)] : T2Space (∀ a, Y a) := inferInstance #align Pi.t2_space Pi.t2Space instance Sigma.t2Space {ι} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ a, T2Space (X a)] : T2Space (Σi, X i) := by constructor rintro ⟨i, x⟩ ⟨j, y⟩ neq rcases eq_or_ne i j with (rfl | h) · replace neq : x ≠ y := ne_of_apply_ne _ neq exact separated_by_openEmbedding openEmbedding_sigmaMk neq · let _ := (⊥ : TopologicalSpace ι); have : DiscreteTopology ι := ⟨rfl⟩ exact separated_by_continuous (continuous_def.2 fun u _ => isOpen_sigma_fst_preimage u) h #align sigma.t2_space Sigma.t2Space section variable (X) /-- The smallest equivalence relation on a topological space giving a T2 quotient. -/ def t2Setoid : Setoid X := sInf {s | T2Space (Quotient s)} /-- The largest T2 quotient of a topological space. This construction is left-adjoint to the inclusion of T2 spaces into all topological spaces. -/ def t2Quotient := Quotient (t2Setoid X) namespace t2Quotient variable {X} instance : TopologicalSpace (t2Quotient X) := inferInstanceAs <| TopologicalSpace (Quotient _) /-- The map from a topological space to its largest T2 quotient. -/ def mk : X → t2Quotient X := Quotient.mk (t2Setoid X) lemma mk_eq {x y : X} : mk x = mk y ↔ ∀ s : Setoid X, T2Space (Quotient s) → s.Rel x y := Setoid.quotient_mk_sInf_eq variable (X) lemma surjective_mk : Surjective (mk : X → t2Quotient X) := surjective_quotient_mk _ lemma continuous_mk : Continuous (mk : X → t2Quotient X) := continuous_quotient_mk' variable {X} @[elab_as_elim] protected lemma inductionOn {motive : t2Quotient X → Prop} (q : t2Quotient X) (h : ∀ x, motive (t2Quotient.mk x)) : motive q := Quotient.inductionOn q h @[elab_as_elim] protected lemma inductionOn₂ [TopologicalSpace Y] {motive : t2Quotient X → t2Quotient Y → Prop} (q : t2Quotient X) (q' : t2Quotient Y) (h : ∀ x y, motive (mk x) (mk y)) : motive q q' := Quotient.inductionOn₂ q q' h /-- The largest T2 quotient of a topological space is indeed T2. -/ instance : T2Space (t2Quotient X) := by rw [t2Space_iff] rintro ⟨x⟩ ⟨y⟩ (h : ¬ t2Quotient.mk x = t2Quotient.mk y) obtain ⟨s, hs, hsxy⟩ : ∃ s, T2Space (Quotient s) ∧ Quotient.mk s x ≠ Quotient.mk s y := by simpa [t2Quotient.mk_eq] using h exact separated_by_continuous (continuous_map_sInf (by exact hs)) hsxy lemma compatible {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] [T2Space Y] {f : X → Y} (hf : Continuous f) : letI _ := t2Setoid X ∀ (a b : X), a ≈ b → f a = f b := by change t2Setoid X ≤ Setoid.ker f exact sInf_le <| .of_injective_continuous (Setoid.ker_lift_injective _) (hf.quotient_lift fun _ _ ↦ id) /-- The universal property of the largest T2 quotient of a topological space `X`: any continuous map from `X` to a T2 space `Y` uniquely factors through `t2Quotient X`. This declaration builds the factored map. Its continuity is `t2Quotient.continuous_lift`, the fact that it indeed factors the original map is `t2Quotient.lift_mk` and uniquenes is `t2Quotient.unique_lift`. -/ def lift {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] [T2Space Y] {f : X → Y} (hf : Continuous f) : t2Quotient X → Y := Quotient.lift f (t2Quotient.compatible hf) lemma continuous_lift {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] [T2Space Y] {f : X → Y} (hf : Continuous f) : Continuous (t2Quotient.lift hf) := continuous_coinduced_dom.mpr hf @[simp] lemma lift_mk {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] [T2Space Y] {f : X → Y} (hf : Continuous f) (x : X) : lift hf (mk x) = f x := Quotient.lift_mk (s := t2Setoid X) f (t2Quotient.compatible hf) x lemma unique_lift {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] [T2Space Y] {f : X → Y} (hf : Continuous f) {g : t2Quotient X → Y} (hfg : g ∘ mk = f) : g = lift hf := by apply surjective_mk X |>.right_cancellable |>.mp <| funext _ simp [← hfg] end t2Quotient end variable {Z : Type*} [TopologicalSpace Y] [TopologicalSpace Z] theorem isClosed_eq [T2Space X] {f g : Y → X} (hf : Continuous f) (hg : Continuous g) : IsClosed { y : Y | f y = g y } := continuous_iff_isClosed.mp (hf.prod_mk hg) _ isClosed_diagonal #align is_closed_eq isClosed_eq theorem isOpen_ne_fun [T2Space X] {f g : Y → X} (hf : Continuous f) (hg : Continuous g) : IsOpen { y : Y | f y ≠ g y } := isOpen_compl_iff.mpr <| isClosed_eq hf hg #align is_open_ne_fun isOpen_ne_fun /-- If two continuous maps are equal on `s`, then they are equal on the closure of `s`. See also `Set.EqOn.of_subset_closure` for a more general version. -/ protected theorem Set.EqOn.closure [T2Space X] {s : Set Y} {f g : Y → X} (h : EqOn f g s) (hf : Continuous f) (hg : Continuous g) : EqOn f g (closure s) := closure_minimal h (isClosed_eq hf hg) #align set.eq_on.closure Set.EqOn.closure /-- If two continuous functions are equal on a dense set, then they are equal. -/ theorem Continuous.ext_on [T2Space X] {s : Set Y} (hs : Dense s) {f g : Y → X} (hf : Continuous f) (hg : Continuous g) (h : EqOn f g s) : f = g := funext fun x => h.closure hf hg (hs x) #align continuous.ext_on Continuous.ext_on theorem eqOn_closure₂' [T2Space Z] {s : Set X} {t : Set Y} {f g : X → Y → Z} (h : ∀ x ∈ s, ∀ y ∈ t, f x y = g x y) (hf₁ : ∀ x, Continuous (f x)) (hf₂ : ∀ y, Continuous fun x => f x y) (hg₁ : ∀ x, Continuous (g x)) (hg₂ : ∀ y, Continuous fun x => g x y) : ∀ x ∈ closure s, ∀ y ∈ closure t, f x y = g x y := suffices closure s ⊆ ⋂ y ∈ closure t, { x | f x y = g x y } by simpa only [subset_def, mem_iInter] (closure_minimal fun x hx => mem_iInter₂.2 <| Set.EqOn.closure (h x hx) (hf₁ _) (hg₁ _)) <| isClosed_biInter fun y _ => isClosed_eq (hf₂ _) (hg₂ _) #align eq_on_closure₂' eqOn_closure₂' theorem eqOn_closure₂ [T2Space Z] {s : Set X} {t : Set Y} {f g : X → Y → Z} (h : ∀ x ∈ s, ∀ y ∈ t, f x y = g x y) (hf : Continuous (uncurry f)) (hg : Continuous (uncurry g)) : ∀ x ∈ closure s, ∀ y ∈ closure t, f x y = g x y := eqOn_closure₂' h hf.uncurry_left hf.uncurry_right hg.uncurry_left hg.uncurry_right #align eq_on_closure₂ eqOn_closure₂ /-- If `f x = g x` for all `x ∈ s` and `f`, `g` are continuous on `t`, `s ⊆ t ⊆ closure s`, then `f x = g x` for all `x ∈ t`. See also `Set.EqOn.closure`. -/ theorem Set.EqOn.of_subset_closure [T2Space Y] {s t : Set X} {f g : X → Y} (h : EqOn f g s) (hf : ContinuousOn f t) (hg : ContinuousOn g t) (hst : s ⊆ t) (hts : t ⊆ closure s) : EqOn f g t := by intro x hx have : (𝓝[s] x).NeBot := mem_closure_iff_clusterPt.mp (hts hx) exact tendsto_nhds_unique_of_eventuallyEq ((hf x hx).mono_left <| nhdsWithin_mono _ hst) ((hg x hx).mono_left <| nhdsWithin_mono _ hst) (h.eventuallyEq_of_mem self_mem_nhdsWithin) #align set.eq_on.of_subset_closure Set.EqOn.of_subset_closure theorem Function.LeftInverse.isClosed_range [T2Space X] {f : X → Y} {g : Y → X} (h : Function.LeftInverse f g) (hf : Continuous f) (hg : Continuous g) : IsClosed (range g) := have : EqOn (g ∘ f) id (closure <| range g) := h.rightInvOn_range.eqOn.closure (hg.comp hf) continuous_id isClosed_of_closure_subset fun x hx => ⟨f x, this hx⟩ #align function.left_inverse.closed_range Function.LeftInverse.isClosed_range @[deprecated (since := "2024-03-17")] alias Function.LeftInverse.closed_range := Function.LeftInverse.isClosed_range theorem Function.LeftInverse.closedEmbedding [T2Space X] {f : X → Y} {g : Y → X} (h : Function.LeftInverse f g) (hf : Continuous f) (hg : Continuous g) : ClosedEmbedding g := ⟨h.embedding hf hg, h.isClosed_range hf hg⟩ #align function.left_inverse.closed_embedding Function.LeftInverse.closedEmbedding theorem SeparatedNhds.of_isCompact_isCompact [T2Space X] {s t : Set X} (hs : IsCompact s) (ht : IsCompact t) (hst : Disjoint s t) : SeparatedNhds s t := by simp only [SeparatedNhds, prod_subset_compl_diagonal_iff_disjoint.symm] at hst ⊢ exact generalized_tube_lemma hs ht isClosed_diagonal.isOpen_compl hst #align is_compact_is_compact_separated SeparatedNhds.of_isCompact_isCompact @[deprecated (since := "2024-01-28")] alias separatedNhds_of_isCompact_isCompact := SeparatedNhds.of_isCompact_isCompact section SeparatedFinset theorem SeparatedNhds.of_finset_finset [T2Space X] (s t : Finset X) (h : Disjoint s t) : SeparatedNhds (s : Set X) t := .of_isCompact_isCompact s.finite_toSet.isCompact t.finite_toSet.isCompact <| mod_cast h #align finset_disjoint_finset_opens_of_t2 SeparatedNhds.of_finset_finset @[deprecated (since := "2024-01-28")] alias separatedNhds_of_finset_finset := SeparatedNhds.of_finset_finset theorem SeparatedNhds.of_singleton_finset [T2Space X] {x : X} {s : Finset X} (h : x ∉ s) : SeparatedNhds ({x} : Set X) s := mod_cast .of_finset_finset {x} s (Finset.disjoint_singleton_left.mpr h) #align point_disjoint_finset_opens_of_t2 SeparatedNhds.of_singleton_finset @[deprecated (since := "2024-01-28")] alias point_disjoint_finset_opens_of_t2 := SeparatedNhds.of_singleton_finset end SeparatedFinset /-- In a `T2Space`, every compact set is closed. -/ theorem IsCompact.isClosed [T2Space X] {s : Set X} (hs : IsCompact s) : IsClosed s := isOpen_compl_iff.1 <| isOpen_iff_forall_mem_open.mpr fun x hx => let ⟨u, v, _, vo, su, xv, uv⟩ := SeparatedNhds.of_isCompact_isCompact hs isCompact_singleton (disjoint_singleton_right.2 hx) ⟨v, (uv.mono_left <| show s ≤ u from su).subset_compl_left, vo, by simpa using xv⟩ #align is_compact.is_closed IsCompact.isClosed theorem IsCompact.preimage_continuous [CompactSpace X] [T2Space Y] {f : X → Y} {s : Set Y} (hs : IsCompact s) (hf : Continuous f) : IsCompact (f ⁻¹' s) := (hs.isClosed.preimage hf).isCompact lemma Pi.isCompact_iff {ι : Type*} {π : ι → Type*} [∀ i, TopologicalSpace (π i)] [∀ i, T2Space (π i)] {s : Set (Π i, π i)} : IsCompact s ↔ IsClosed s ∧ ∀ i, IsCompact (eval i '' s):= by constructor <;> intro H · exact ⟨H.isClosed, fun i ↦ H.image <| continuous_apply i⟩ · exact IsCompact.of_isClosed_subset (isCompact_univ_pi H.2) H.1 (subset_pi_eval_image univ s) lemma Pi.isCompact_closure_iff {ι : Type*} {π : ι → Type*} [∀ i, TopologicalSpace (π i)] [∀ i, T2Space (π i)] {s : Set (Π i, π i)} : IsCompact (closure s) ↔ ∀ i, IsCompact (closure <| eval i '' s) := by simp_rw [← exists_isCompact_superset_iff, Pi.exists_compact_superset_iff, image_subset_iff] /-- If `V : ι → Set X` is a decreasing family of compact sets then any neighborhood of `⋂ i, V i` contains some `V i`. This is a version of `exists_subset_nhds_of_isCompact'` where we don't need to assume each `V i` closed because it follows from compactness since `X` is assumed to be Hausdorff. -/ theorem exists_subset_nhds_of_isCompact [T2Space X] {ι : Type*} [Nonempty ι] {V : ι → Set X} (hV : Directed (· ⊇ ·) V) (hV_cpct : ∀ i, IsCompact (V i)) {U : Set X} (hU : ∀ x ∈ ⋂ i, V i, U ∈ 𝓝 x) : ∃ i, V i ⊆ U := exists_subset_nhds_of_isCompact' hV hV_cpct (fun i => (hV_cpct i).isClosed) hU #align exists_subset_nhds_of_is_compact exists_subset_nhds_of_isCompact theorem CompactExhaustion.isClosed [T2Space X] (K : CompactExhaustion X) (n : ℕ) : IsClosed (K n) := (K.isCompact n).isClosed #align compact_exhaustion.is_closed CompactExhaustion.isClosed theorem IsCompact.inter [T2Space X] {s t : Set X} (hs : IsCompact s) (ht : IsCompact t) : IsCompact (s ∩ t) := hs.inter_right <| ht.isClosed #align is_compact.inter IsCompact.inter theorem image_closure_of_isCompact [T2Space Y] {s : Set X} (hs : IsCompact (closure s)) {f : X → Y} (hf : ContinuousOn f (closure s)) : f '' closure s = closure (f '' s) := Subset.antisymm hf.image_closure <| closure_minimal (image_subset f subset_closure) (hs.image_of_continuousOn hf).isClosed #align image_closure_of_is_compact image_closure_of_isCompact /-- A continuous map from a compact space to a Hausdorff space is a closed map. -/ protected theorem Continuous.isClosedMap [CompactSpace X] [T2Space Y] {f : X → Y} (h : Continuous f) : IsClosedMap f := fun _s hs => (hs.isCompact.image h).isClosed #align continuous.is_closed_map Continuous.isClosedMap /-- A continuous injective map from a compact space to a Hausdorff space is a closed embedding. -/ theorem Continuous.closedEmbedding [CompactSpace X] [T2Space Y] {f : X → Y} (h : Continuous f) (hf : Function.Injective f) : ClosedEmbedding f := closedEmbedding_of_continuous_injective_closed h hf h.isClosedMap #align continuous.closed_embedding Continuous.closedEmbedding /-- A continuous surjective map from a compact space to a Hausdorff space is a quotient map. -/ theorem QuotientMap.of_surjective_continuous [CompactSpace X] [T2Space Y] {f : X → Y} (hsurj : Surjective f) (hcont : Continuous f) : QuotientMap f := hcont.isClosedMap.to_quotientMap hcont hsurj #align quotient_map.of_surjective_continuous QuotientMap.of_surjective_continuous theorem isPreirreducible_iff_subsingleton [T2Space X] {S : Set X} : IsPreirreducible S ↔ S.Subsingleton := by refine ⟨fun h x hx y hy => ?_, Set.Subsingleton.isPreirreducible⟩ by_contra e obtain ⟨U, V, hU, hV, hxU, hyV, h'⟩ := t2_separation e exact ((h U V hU hV ⟨x, hx, hxU⟩ ⟨y, hy, hyV⟩).mono inter_subset_right).not_disjoint h' #align is_preirreducible_iff_subsingleton isPreirreducible_iff_subsingleton -- todo: use `alias` + `attribute [protected]` once we get `attribute [protected]` protected lemma IsPreirreducible.subsingleton [T2Space X] {S : Set X} (h : IsPreirreducible S) : S.Subsingleton := isPreirreducible_iff_subsingleton.1 h #align is_preirreducible.subsingleton IsPreirreducible.subsingleton theorem isIrreducible_iff_singleton [T2Space X] {S : Set X} : IsIrreducible S ↔ ∃ x, S = {x} := by rw [IsIrreducible, isPreirreducible_iff_subsingleton, exists_eq_singleton_iff_nonempty_subsingleton] #align is_irreducible_iff_singleton isIrreducible_iff_singleton /-- There does not exist a nontrivial preirreducible T₂ space. -/ theorem not_preirreducible_nontrivial_t2 (X) [TopologicalSpace X] [PreirreducibleSpace X] [Nontrivial X] [T2Space X] : False := (PreirreducibleSpace.isPreirreducible_univ (X := X)).subsingleton.not_nontrivial nontrivial_univ #align not_preirreducible_nontrivial_t2 not_preirreducible_nontrivial_t2 end Separation section RegularSpace /-- A topological space is called a *regular space* if for any closed set `s` and `a ∉ s`, there exist disjoint open sets `U ⊇ s` and `V ∋ a`. We formulate this condition in terms of `Disjoint`ness of filters `𝓝ˢ s` and `𝓝 a`. -/ @[mk_iff] class RegularSpace (X : Type u) [TopologicalSpace X] : Prop where /-- If `a` is a point that does not belong to a closed set `s`, then `a` and `s` admit disjoint neighborhoods. -/ regular : ∀ {s : Set X} {a}, IsClosed s → a ∉ s → Disjoint (𝓝ˢ s) (𝓝 a) #align regular_space RegularSpace theorem regularSpace_TFAE (X : Type u) [TopologicalSpace X] : List.TFAE [RegularSpace X, ∀ (s : Set X) x, x ∉ closure s → Disjoint (𝓝ˢ s) (𝓝 x), ∀ (x : X) (s : Set X), Disjoint (𝓝ˢ s) (𝓝 x) ↔ x ∉ closure s, ∀ (x : X) (s : Set X), s ∈ 𝓝 x → ∃ t ∈ 𝓝 x, IsClosed t ∧ t ⊆ s, ∀ x : X, (𝓝 x).lift' closure ≤ 𝓝 x, ∀ x : X , (𝓝 x).lift' closure = 𝓝 x] := by tfae_have 1 ↔ 5 · rw [regularSpace_iff, (@compl_surjective (Set X) _).forall, forall_swap] simp only [isClosed_compl_iff, mem_compl_iff, Classical.not_not, @and_comm (_ ∈ _), (nhds_basis_opens _).lift'_closure.le_basis_iff (nhds_basis_opens _), and_imp, (nhds_basis_opens _).disjoint_iff_right, exists_prop, ← subset_interior_iff_mem_nhdsSet, interior_compl, compl_subset_compl] tfae_have 5 → 6 · exact fun h a => (h a).antisymm (𝓝 _).le_lift'_closure tfae_have 6 → 4 · intro H a s hs rw [← H] at hs rcases (𝓝 a).basis_sets.lift'_closure.mem_iff.mp hs with ⟨U, hU, hUs⟩ exact ⟨closure U, mem_of_superset hU subset_closure, isClosed_closure, hUs⟩ tfae_have 4 → 2 · intro H s a ha have ha' : sᶜ ∈ 𝓝 a := by rwa [← mem_interior_iff_mem_nhds, interior_compl] rcases H _ _ ha' with ⟨U, hU, hUc, hUs⟩ refine disjoint_of_disjoint_of_mem disjoint_compl_left ?_ hU rwa [← subset_interior_iff_mem_nhdsSet, hUc.isOpen_compl.interior_eq, subset_compl_comm] tfae_have 2 → 3 · refine fun H a s => ⟨fun hd has => mem_closure_iff_nhds_ne_bot.mp has ?_, H s a⟩ exact (hd.symm.mono_right <| @principal_le_nhdsSet _ _ s).eq_bot tfae_have 3 → 1 · exact fun H => ⟨fun hs ha => (H _ _).mpr <| hs.closure_eq.symm ▸ ha⟩ tfae_finish #align regular_space_tfae regularSpace_TFAE theorem RegularSpace.of_lift'_closure_le (h : ∀ x : X, (𝓝 x).lift' closure ≤ 𝓝 x) : RegularSpace X := Iff.mpr ((regularSpace_TFAE X).out 0 4) h theorem RegularSpace.of_lift'_closure (h : ∀ x : X, (𝓝 x).lift' closure = 𝓝 x) : RegularSpace X := Iff.mpr ((regularSpace_TFAE X).out 0 5) h #align regular_space.of_lift'_closure RegularSpace.of_lift'_closure @[deprecated (since := "2024-02-28")] alias RegularSpace.ofLift'_closure := RegularSpace.of_lift'_closure theorem RegularSpace.of_hasBasis {ι : X → Sort*} {p : ∀ a, ι a → Prop} {s : ∀ a, ι a → Set X} (h₁ : ∀ a, (𝓝 a).HasBasis (p a) (s a)) (h₂ : ∀ a i, p a i → IsClosed (s a i)) : RegularSpace X := .of_lift'_closure fun a => (h₁ a).lift'_closure_eq_self (h₂ a) #align regular_space.of_basis RegularSpace.of_hasBasis @[deprecated (since := "2024-02-28")] alias RegularSpace.ofBasis := RegularSpace.of_hasBasis theorem RegularSpace.of_exists_mem_nhds_isClosed_subset (h : ∀ (x : X), ∀ s ∈ 𝓝 x, ∃ t ∈ 𝓝 x, IsClosed t ∧ t ⊆ s) : RegularSpace X := Iff.mpr ((regularSpace_TFAE X).out 0 3) h #align regular_space.of_exists_mem_nhds_is_closed_subset RegularSpace.of_exists_mem_nhds_isClosed_subset @[deprecated (since := "2024-02-28")] alias RegularSpace.ofExistsMemNhdsIsClosedSubset := RegularSpace.of_exists_mem_nhds_isClosed_subset /-- A weakly locally compact R₁ space is regular. -/ instance (priority := 100) [WeaklyLocallyCompactSpace X] [R1Space X] : RegularSpace X := .of_hasBasis isCompact_isClosed_basis_nhds fun _ _ ⟨_, _, h⟩ ↦ h variable [RegularSpace X] {x : X} {s : Set X} theorem disjoint_nhdsSet_nhds : Disjoint (𝓝ˢ s) (𝓝 x) ↔ x ∉ closure s := by have h := (regularSpace_TFAE X).out 0 2 exact h.mp ‹_› _ _ #align disjoint_nhds_set_nhds disjoint_nhdsSet_nhds theorem disjoint_nhds_nhdsSet : Disjoint (𝓝 x) (𝓝ˢ s) ↔ x ∉ closure s := disjoint_comm.trans disjoint_nhdsSet_nhds #align disjoint_nhds_nhds_set disjoint_nhds_nhdsSet /-- A regular space is R₁. -/ instance (priority := 100) : R1Space X where specializes_or_disjoint_nhds _ _ := or_iff_not_imp_left.2 fun h ↦ by rwa [← nhdsSet_singleton, disjoint_nhdsSet_nhds, ← specializes_iff_mem_closure] theorem exists_mem_nhds_isClosed_subset {x : X} {s : Set X} (h : s ∈ 𝓝 x) : ∃ t ∈ 𝓝 x, IsClosed t ∧ t ⊆ s := by have h' := (regularSpace_TFAE X).out 0 3 exact h'.mp ‹_› _ _ h #align exists_mem_nhds_is_closed_subset exists_mem_nhds_isClosed_subset theorem closed_nhds_basis (x : X) : (𝓝 x).HasBasis (fun s : Set X => s ∈ 𝓝 x ∧ IsClosed s) id := hasBasis_self.2 fun _ => exists_mem_nhds_isClosed_subset #align closed_nhds_basis closed_nhds_basis theorem lift'_nhds_closure (x : X) : (𝓝 x).lift' closure = 𝓝 x := (closed_nhds_basis x).lift'_closure_eq_self fun _ => And.right #align lift'_nhds_closure lift'_nhds_closure theorem Filter.HasBasis.nhds_closure {ι : Sort*} {x : X} {p : ι → Prop} {s : ι → Set X} (h : (𝓝 x).HasBasis p s) : (𝓝 x).HasBasis p fun i => closure (s i) := lift'_nhds_closure x ▸ h.lift'_closure #align filter.has_basis.nhds_closure Filter.HasBasis.nhds_closure theorem hasBasis_nhds_closure (x : X) : (𝓝 x).HasBasis (fun s => s ∈ 𝓝 x) closure := (𝓝 x).basis_sets.nhds_closure #align has_basis_nhds_closure hasBasis_nhds_closure theorem hasBasis_opens_closure (x : X) : (𝓝 x).HasBasis (fun s => x ∈ s ∧ IsOpen s) closure := (nhds_basis_opens x).nhds_closure #align has_basis_opens_closure hasBasis_opens_closure theorem IsCompact.exists_isOpen_closure_subset {K U : Set X} (hK : IsCompact K) (hU : U ∈ 𝓝ˢ K) : ∃ V, IsOpen V ∧ K ⊆ V ∧ closure V ⊆ U := by have hd : Disjoint (𝓝ˢ K) (𝓝ˢ Uᶜ) := by simpa [hK.disjoint_nhdsSet_left, disjoint_nhds_nhdsSet, ← subset_interior_iff_mem_nhdsSet] using hU rcases ((hasBasis_nhdsSet _).disjoint_iff (hasBasis_nhdsSet _)).1 hd with ⟨V, ⟨hVo, hKV⟩, W, ⟨hW, hUW⟩, hVW⟩ refine ⟨V, hVo, hKV, Subset.trans ?_ (compl_subset_comm.1 hUW)⟩ exact closure_minimal hVW.subset_compl_right hW.isClosed_compl theorem IsCompact.lift'_closure_nhdsSet {K : Set X} (hK : IsCompact K) : (𝓝ˢ K).lift' closure = 𝓝ˢ K := by refine le_antisymm (fun U hU ↦ ?_) (le_lift'_closure _) rcases hK.exists_isOpen_closure_subset hU with ⟨V, hVo, hKV, hVU⟩ exact mem_of_superset (mem_lift' <| hVo.mem_nhdsSet.2 hKV) hVU theorem TopologicalSpace.IsTopologicalBasis.nhds_basis_closure {B : Set (Set X)} (hB : IsTopologicalBasis B) (x : X) : (𝓝 x).HasBasis (fun s : Set X => x ∈ s ∧ s ∈ B) closure := by simpa only [and_comm] using hB.nhds_hasBasis.nhds_closure #align topological_space.is_topological_basis.nhds_basis_closure TopologicalSpace.IsTopologicalBasis.nhds_basis_closure theorem TopologicalSpace.IsTopologicalBasis.exists_closure_subset {B : Set (Set X)} (hB : IsTopologicalBasis B) {x : X} {s : Set X} (h : s ∈ 𝓝 x) : ∃ t ∈ B, x ∈ t ∧ closure t ⊆ s := by simpa only [exists_prop, and_assoc] using hB.nhds_hasBasis.nhds_closure.mem_iff.mp h #align topological_space.is_topological_basis.exists_closure_subset TopologicalSpace.IsTopologicalBasis.exists_closure_subset protected theorem Inducing.regularSpace [TopologicalSpace Y] {f : Y → X} (hf : Inducing f) : RegularSpace Y := .of_hasBasis (fun b => by rw [hf.nhds_eq_comap b]; exact (closed_nhds_basis _).comap _) fun b s hs => by exact hs.2.preimage hf.continuous #align inducing.regular_space Inducing.regularSpace theorem regularSpace_induced (f : Y → X) : @RegularSpace Y (induced f ‹_›) := letI := induced f ‹_› (inducing_induced f).regularSpace #align regular_space_induced regularSpace_induced theorem regularSpace_sInf {X} {T : Set (TopologicalSpace X)} (h : ∀ t ∈ T, @RegularSpace X t) : @RegularSpace X (sInf T) := by let _ := sInf T have : ∀ a, (𝓝 a).HasBasis (fun If : Σ I : Set T, I → Set X => If.1.Finite ∧ ∀ i : If.1, If.2 i ∈ @nhds X i a ∧ @IsClosed X i (If.2 i)) fun If => ⋂ i : If.1, If.snd i := fun a ↦ by rw [nhds_sInf, ← iInf_subtype''] exact hasBasis_iInf fun t : T => @closed_nhds_basis X t (h t t.2) a refine .of_hasBasis this fun a If hIf => isClosed_iInter fun i => ?_ exact (hIf.2 i).2.mono (sInf_le (i : T).2) #align regular_space_Inf regularSpace_sInf theorem regularSpace_iInf {ι X} {t : ι → TopologicalSpace X} (h : ∀ i, @RegularSpace X (t i)) : @RegularSpace X (iInf t) := regularSpace_sInf <| forall_mem_range.mpr h #align regular_space_infi regularSpace_iInf theorem RegularSpace.inf {X} {t₁ t₂ : TopologicalSpace X} (h₁ : @RegularSpace X t₁) (h₂ : @RegularSpace X t₂) : @RegularSpace X (t₁ ⊓ t₂) := by rw [inf_eq_iInf] exact regularSpace_iInf (Bool.forall_bool.2 ⟨h₂, h₁⟩) #align regular_space.inf RegularSpace.inf instance {p : X → Prop} : RegularSpace (Subtype p) := embedding_subtype_val.toInducing.regularSpace instance [TopologicalSpace Y] [RegularSpace Y] : RegularSpace (X × Y) := (regularSpace_induced (@Prod.fst X Y)).inf (regularSpace_induced (@Prod.snd X Y)) instance {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, RegularSpace (X i)] : RegularSpace (∀ i, X i) := regularSpace_iInf fun _ => regularSpace_induced _ /-- In a regular space, if a compact set and a closed set are disjoint, then they have disjoint neighborhoods. -/ lemma SeparatedNhds.of_isCompact_isClosed {s t : Set X} (hs : IsCompact s) (ht : IsClosed t) (hst : Disjoint s t) : SeparatedNhds s t := by simpa only [separatedNhds_iff_disjoint, hs.disjoint_nhdsSet_left, disjoint_nhds_nhdsSet, ht.closure_eq, disjoint_left] using hst @[deprecated (since := "2024-01-28")] alias separatedNhds_of_isCompact_isClosed := SeparatedNhds.of_isCompact_isClosed end RegularSpace section LocallyCompactRegularSpace /-- In a (possibly non-Hausdorff) locally compact regular space, for every containment `K ⊆ U` of a compact set `K` in an open set `U`, there is a compact closed neighborhood `L` such that `K ⊆ L ⊆ U`: equivalently, there is a compact closed set `L` such that `K ⊆ interior L` and `L ⊆ U`. -/ theorem exists_compact_closed_between [LocallyCompactSpace X] [RegularSpace X] {K U : Set X} (hK : IsCompact K) (hU : IsOpen U) (h_KU : K ⊆ U) : ∃ L, IsCompact L ∧ IsClosed L ∧ K ⊆ interior L ∧ L ⊆ U := let ⟨L, L_comp, KL, LU⟩ := exists_compact_between hK hU h_KU ⟨closure L, L_comp.closure, isClosed_closure, KL.trans <| interior_mono subset_closure, L_comp.closure_subset_of_isOpen hU LU⟩ /-- In a locally compact regular space, given a compact set `K` inside an open set `U`, we can find an open set `V` between these sets with compact closure: `K ⊆ V` and the closure of `V` is inside `U`. -/ theorem exists_open_between_and_isCompact_closure [LocallyCompactSpace X] [RegularSpace X] {K U : Set X} (hK : IsCompact K) (hU : IsOpen U) (hKU : K ⊆ U) : ∃ V, IsOpen V ∧ K ⊆ V ∧ closure V ⊆ U ∧ IsCompact (closure V) := by rcases exists_compact_closed_between hK hU hKU with ⟨L, L_compact, L_closed, KL, LU⟩ have A : closure (interior L) ⊆ L := by apply (closure_mono interior_subset).trans (le_of_eq L_closed.closure_eq) refine ⟨interior L, isOpen_interior, KL, A.trans LU, ?_⟩ exact L_compact.closure_of_subset interior_subset #align exists_open_between_and_is_compact_closure exists_open_between_and_isCompact_closure @[deprecated WeaklyLocallyCompactSpace.locallyCompactSpace (since := "2023-09-03")] theorem locally_compact_of_compact [T2Space X] [CompactSpace X] : LocallyCompactSpace X := inferInstance #align locally_compact_of_compact locally_compact_of_compact end LocallyCompactRegularSpace section T25 /-- A T₂.₅ space, also known as a Urysohn space, is a topological space where for every pair `x ≠ y`, there are two open sets, with the intersection of closures empty, one containing `x` and the other `y` . -/ class T25Space (X : Type u) [TopologicalSpace X] : Prop where /-- Given two distinct points in a T₂.₅ space, their filters of closed neighborhoods are disjoint. -/ t2_5 : ∀ ⦃x y : X⦄, x ≠ y → Disjoint ((𝓝 x).lift' closure) ((𝓝 y).lift' closure) #align t2_5_space T25Space @[simp] theorem disjoint_lift'_closure_nhds [T25Space X] {x y : X} : Disjoint ((𝓝 x).lift' closure) ((𝓝 y).lift' closure) ↔ x ≠ y := ⟨fun h hxy => by simp [hxy, nhds_neBot.ne] at h, fun h => T25Space.t2_5 h⟩ #align disjoint_lift'_closure_nhds disjoint_lift'_closure_nhds -- see Note [lower instance priority] instance (priority := 100) T25Space.t2Space [T25Space X] : T2Space X := t2Space_iff_disjoint_nhds.2 fun _ _ hne => (disjoint_lift'_closure_nhds.2 hne).mono (le_lift'_closure _) (le_lift'_closure _) #align t2_5_space.t2_space T25Space.t2Space theorem exists_nhds_disjoint_closure [T25Space X] {x y : X} (h : x ≠ y) : ∃ s ∈ 𝓝 x, ∃ t ∈ 𝓝 y, Disjoint (closure s) (closure t) := ((𝓝 x).basis_sets.lift'_closure.disjoint_iff (𝓝 y).basis_sets.lift'_closure).1 <| disjoint_lift'_closure_nhds.2 h #align exists_nhds_disjoint_closure exists_nhds_disjoint_closure theorem exists_open_nhds_disjoint_closure [T25Space X] {x y : X} (h : x ≠ y) : ∃ u : Set X, x ∈ u ∧ IsOpen u ∧ ∃ v : Set X, y ∈ v ∧ IsOpen v ∧ Disjoint (closure u) (closure v) := by simpa only [exists_prop, and_assoc] using ((nhds_basis_opens x).lift'_closure.disjoint_iff (nhds_basis_opens y).lift'_closure).1 (disjoint_lift'_closure_nhds.2 h) #align exists_open_nhds_disjoint_closure exists_open_nhds_disjoint_closure theorem T25Space.of_injective_continuous [TopologicalSpace Y] [T25Space Y] {f : X → Y} (hinj : Injective f) (hcont : Continuous f) : T25Space X where t2_5 x y hne := (tendsto_lift'_closure_nhds hcont x).disjoint (t2_5 <| hinj.ne hne) (tendsto_lift'_closure_nhds hcont y) instance [T25Space X] {p : X → Prop} : T25Space {x // p x} := .of_injective_continuous Subtype.val_injective continuous_subtype_val section T25 section T3 /-- A T₃ space is a T₀ space which is a regular space. Any T₃ space is a T₁ space, a T₂ space, and a T₂.₅ space. -/ class T3Space (X : Type u) [TopologicalSpace X] extends T0Space X, RegularSpace X : Prop #align t3_space T3Space instance (priority := 90) instT3Space [T0Space X] [RegularSpace X] : T3Space X := ⟨⟩ theorem RegularSpace.t3Space_iff_t0Space [RegularSpace X] : T3Space X ↔ T0Space X := by constructor <;> intro <;> infer_instance -- see Note [lower instance priority] instance (priority := 100) T3Space.t25Space [T3Space X] : T25Space X := by refine ⟨fun x y hne => ?_⟩ rw [lift'_nhds_closure, lift'_nhds_closure] have : x ∉ closure {y} ∨ y ∉ closure {x} := (t0Space_iff_or_not_mem_closure X).mp inferInstance hne simp only [← disjoint_nhds_nhdsSet, nhdsSet_singleton] at this exact this.elim id fun h => h.symm #align t3_space.t2_5_space T3Space.t25Space protected theorem Embedding.t3Space [TopologicalSpace Y] [T3Space Y] {f : X → Y} (hf : Embedding f) : T3Space X := { toT0Space := hf.t0Space toRegularSpace := hf.toInducing.regularSpace } #align embedding.t3_space Embedding.t3Space instance Subtype.t3Space [T3Space X] {p : X → Prop} : T3Space (Subtype p) := embedding_subtype_val.t3Space #align subtype.t3_space Subtype.t3Space instance ULift.instT3Space [T3Space X] : T3Space (ULift X) := embedding_uLift_down.t3Space instance [TopologicalSpace Y] [T3Space X] [T3Space Y] : T3Space (X × Y) := ⟨⟩ instance {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, T3Space (X i)] : T3Space (∀ i, X i) := ⟨⟩ /-- Given two points `x ≠ y`, we can find neighbourhoods `x ∈ V₁ ⊆ U₁` and `y ∈ V₂ ⊆ U₂`, with the `Vₖ` closed and the `Uₖ` open, such that the `Uₖ` are disjoint. -/ theorem disjoint_nested_nhds [T3Space X] {x y : X} (h : x ≠ y) : ∃ U₁ ∈ 𝓝 x, ∃ V₁ ∈ 𝓝 x, ∃ U₂ ∈ 𝓝 y, ∃ V₂ ∈ 𝓝 y, IsClosed V₁ ∧ IsClosed V₂ ∧ IsOpen U₁ ∧ IsOpen U₂ ∧ V₁ ⊆ U₁ ∧ V₂ ⊆ U₂ ∧ Disjoint U₁ U₂ := by rcases t2_separation h with ⟨U₁, U₂, U₁_op, U₂_op, x_in, y_in, H⟩ rcases exists_mem_nhds_isClosed_subset (U₁_op.mem_nhds x_in) with ⟨V₁, V₁_in, V₁_closed, h₁⟩ rcases exists_mem_nhds_isClosed_subset (U₂_op.mem_nhds y_in) with ⟨V₂, V₂_in, V₂_closed, h₂⟩ exact ⟨U₁, mem_of_superset V₁_in h₁, V₁, V₁_in, U₂, mem_of_superset V₂_in h₂, V₂, V₂_in, V₁_closed, V₂_closed, U₁_op, U₂_op, h₁, h₂, H⟩ #align disjoint_nested_nhds disjoint_nested_nhds open SeparationQuotient /-- The `SeparationQuotient` of a regular space is a T₃ space. -/ instance [RegularSpace X] : T3Space (SeparationQuotient X) where regular {s a} hs ha := by rcases surjective_mk a with ⟨a, rfl⟩ rw [← disjoint_comap_iff surjective_mk, comap_mk_nhds_mk, comap_mk_nhdsSet] exact RegularSpace.regular (hs.preimage continuous_mk) ha end T3 section NormalSpace /-- A topological space is said to be a *normal space* if any two disjoint closed sets have disjoint open neighborhoods. -/ class NormalSpace (X : Type u) [TopologicalSpace X] : Prop where /-- Two disjoint sets in a normal space admit disjoint neighbourhoods. -/ normal : ∀ s t : Set X, IsClosed s → IsClosed t → Disjoint s t → SeparatedNhds s t theorem normal_separation [NormalSpace X] {s t : Set X} (H1 : IsClosed s) (H2 : IsClosed t) (H3 : Disjoint s t) : SeparatedNhds s t := NormalSpace.normal s t H1 H2 H3 #align normal_separation normal_separation theorem disjoint_nhdsSet_nhdsSet [NormalSpace X] {s t : Set X} (hs : IsClosed s) (ht : IsClosed t) (hd : Disjoint s t) : Disjoint (𝓝ˢ s) (𝓝ˢ t) := (normal_separation hs ht hd).disjoint_nhdsSet theorem normal_exists_closure_subset [NormalSpace X] {s t : Set X} (hs : IsClosed s) (ht : IsOpen t) (hst : s ⊆ t) : ∃ u, IsOpen u ∧ s ⊆ u ∧ closure u ⊆ t := by have : Disjoint s tᶜ := Set.disjoint_left.mpr fun x hxs hxt => hxt (hst hxs) rcases normal_separation hs (isClosed_compl_iff.2 ht) this with ⟨s', t', hs', ht', hss', htt', hs't'⟩ refine ⟨s', hs', hss', Subset.trans (closure_minimal ?_ (isClosed_compl_iff.2 ht')) (compl_subset_comm.1 htt')⟩ exact fun x hxs hxt => hs't'.le_bot ⟨hxs, hxt⟩ #align normal_exists_closure_subset normal_exists_closure_subset /-- If the codomain of a closed embedding is a normal space, then so is the domain. -/ protected theorem ClosedEmbedding.normalSpace [TopologicalSpace Y] [NormalSpace Y] {f : X → Y} (hf : ClosedEmbedding f) : NormalSpace X where normal s t hs ht hst := by have H : SeparatedNhds (f '' s) (f '' t) := NormalSpace.normal (f '' s) (f '' t) (hf.isClosedMap s hs) (hf.isClosedMap t ht) (disjoint_image_of_injective hf.inj hst) exact (H.preimage hf.continuous).mono (subset_preimage_image _ _) (subset_preimage_image _ _) instance (priority := 100) NormalSpace.of_compactSpace_r1Space [CompactSpace X] [R1Space X] : NormalSpace X where normal _s _t hs ht := .of_isCompact_isCompact_isClosed hs.isCompact ht.isCompact ht /-- A regular topological space with second countable topology is a normal space. TODO: The same is true for a regular Lindelöf space. -/ instance (priority := 100) NormalSpace.of_regularSpace_secondCountableTopology [RegularSpace X] [SecondCountableTopology X] : NormalSpace X := by have key : ∀ {s t : Set X}, IsClosed t → Disjoint s t → ∃ U : Set (countableBasis X), (s ⊆ ⋃ u ∈ U, ↑u) ∧ (∀ u ∈ U, Disjoint (closure ↑u) t) ∧ ∀ n : ℕ, IsClosed (⋃ (u ∈ U) (_ : Encodable.encode u ≤ n), closure (u : Set X)) := by intro s t hc hd rw [disjoint_left] at hd have : ∀ x ∈ s, ∃ U ∈ countableBasis X, x ∈ U ∧ Disjoint (closure U) t := by intro x hx rcases (isBasis_countableBasis X).exists_closure_subset (hc.compl_mem_nhds (hd hx)) with ⟨u, hu, hxu, hut⟩ exact ⟨u, hu, hxu, disjoint_left.2 hut⟩ choose! U hu hxu hd using this set V : s → countableBasis X := MapsTo.restrict _ _ _ hu refine ⟨range V, ?_, forall_mem_range.2 <| Subtype.forall.2 hd, fun n => ?_⟩ · rw [biUnion_range] exact fun x hx => mem_iUnion.2 ⟨⟨x, hx⟩, hxu x hx⟩ · simp only [← iSup_eq_iUnion, iSup_and'] exact (((finite_le_nat n).preimage_embedding (Encodable.encode' _)).subset <| inter_subset_right).isClosed_biUnion fun u _ => isClosed_closure refine { normal := fun s t hs ht hd => ?_ } rcases key ht hd with ⟨U, hsU, hUd, hUc⟩ rcases key hs hd.symm with ⟨V, htV, hVd, hVc⟩ refine ⟨⋃ u ∈ U, ↑u \ ⋃ (v ∈ V) (_ : Encodable.encode v ≤ Encodable.encode u), closure ↑v, ⋃ v ∈ V, ↑v \ ⋃ (u ∈ U) (_ : Encodable.encode u ≤ Encodable.encode v), closure ↑u, isOpen_biUnion fun u _ => (isOpen_of_mem_countableBasis u.2).sdiff (hVc _), isOpen_biUnion fun v _ => (isOpen_of_mem_countableBasis v.2).sdiff (hUc _), fun x hx => ?_, fun x hx => ?_, ?_⟩ · rcases mem_iUnion₂.1 (hsU hx) with ⟨u, huU, hxu⟩ refine mem_biUnion huU ⟨hxu, ?_⟩ simp only [mem_iUnion] rintro ⟨v, hvV, -, hxv⟩ exact (hVd v hvV).le_bot ⟨hxv, hx⟩ · rcases mem_iUnion₂.1 (htV hx) with ⟨v, hvV, hxv⟩ refine mem_biUnion hvV ⟨hxv, ?_⟩ simp only [mem_iUnion] rintro ⟨u, huU, -, hxu⟩ exact (hUd u huU).le_bot ⟨hxu, hx⟩ · simp only [disjoint_left, mem_iUnion, mem_diff, not_exists, not_and, not_forall, not_not] rintro a ⟨u, huU, hau, haV⟩ v hvV hav rcases le_total (Encodable.encode u) (Encodable.encode v) with hle | hle exacts [⟨u, huU, hle, subset_closure hau⟩, (haV _ hvV hle <| subset_closure hav).elim] #align normal_space_of_t3_second_countable NormalSpace.of_regularSpace_secondCountableTopology end NormalSpace section Normality /-- A T₄ space is a normal T₁ space. -/ class T4Space (X : Type u) [TopologicalSpace X] extends T1Space X, NormalSpace X : Prop #align normal_space NormalSpace instance (priority := 100) [T1Space X] [NormalSpace X] : T4Space X := ⟨⟩ -- see Note [lower instance priority] instance (priority := 100) T4Space.t3Space [T4Space X] : T3Space X where regular hs hxs := by simpa only [nhdsSet_singleton] using (normal_separation hs isClosed_singleton (disjoint_singleton_right.mpr hxs)).disjoint_nhdsSet #align normal_space.t3_space T4Space.t3Space @[deprecated inferInstance (since := "2024-01-28")] theorem T4Space.of_compactSpace_t2Space [CompactSpace X] [T2Space X] : T4Space X := inferInstance #align normal_of_compact_t2 T4Space.of_compactSpace_t2Space /-- If the codomain of a closed embedding is a T₄ space, then so is the domain. -/ protected theorem ClosedEmbedding.t4Space [TopologicalSpace Y] [T4Space Y] {f : X → Y} (hf : ClosedEmbedding f) : T4Space X where toT1Space := hf.toEmbedding.t1Space toNormalSpace := hf.normalSpace #align closed_embedding.normal_space ClosedEmbedding.t4Space instance ULift.instT4Space [T4Space X] : T4Space (ULift X) := ULift.closedEmbedding_down.t4Space namespace SeparationQuotient /-- The `SeparationQuotient` of a normal space is a normal space. -/ instance [NormalSpace X] : NormalSpace (SeparationQuotient X) where normal s t hs ht hd := separatedNhds_iff_disjoint.2 <| by rw [← disjoint_comap_iff surjective_mk, comap_mk_nhdsSet, comap_mk_nhdsSet] exact disjoint_nhdsSet_nhdsSet (hs.preimage continuous_mk) (ht.preimage continuous_mk) (hd.preimage mk) end SeparationQuotient variable (X) end Normality section CompletelyNormal /-- A topological space `X` is a *completely normal space* provided that for any two sets `s`, `t` such that if both `closure s` is disjoint with `t`, and `s` is disjoint with `closure t`, then there exist disjoint neighbourhoods of `s` and `t`. -/ class CompletelyNormalSpace (X : Type u) [TopologicalSpace X] : Prop where /-- If `closure s` is disjoint with `t`, and `s` is disjoint with `closure t`, then `s` and `t` admit disjoint neighbourhoods. -/ completely_normal : ∀ ⦃s t : Set X⦄, Disjoint (closure s) t → Disjoint s (closure t) → Disjoint (𝓝ˢ s) (𝓝ˢ t) export CompletelyNormalSpace (completely_normal) -- see Note [lower instance priority] /-- A completely normal space is a normal space. -/ instance (priority := 100) CompletelyNormalSpace.toNormalSpace [CompletelyNormalSpace X] : NormalSpace X where normal s t hs ht hd := separatedNhds_iff_disjoint.2 <| completely_normal (by rwa [hs.closure_eq]) (by rwa [ht.closure_eq]) theorem Embedding.completelyNormalSpace [TopologicalSpace Y] [CompletelyNormalSpace Y] {e : X → Y} (he : Embedding e) : CompletelyNormalSpace X := by refine ⟨fun s t hd₁ hd₂ => ?_⟩ simp only [he.toInducing.nhdsSet_eq_comap] refine disjoint_comap (completely_normal ?_ ?_) · rwa [← subset_compl_iff_disjoint_left, image_subset_iff, preimage_compl, ← he.closure_eq_preimage_closure_image, subset_compl_iff_disjoint_left] · rwa [← subset_compl_iff_disjoint_right, image_subset_iff, preimage_compl, ← he.closure_eq_preimage_closure_image, subset_compl_iff_disjoint_right] /-- A subspace of a completely normal space is a completely normal space. -/ instance [CompletelyNormalSpace X] {p : X → Prop} : CompletelyNormalSpace { x // p x } := embedding_subtype_val.completelyNormalSpace instance ULift.instCompletelyNormalSpace [CompletelyNormalSpace X] : CompletelyNormalSpace (ULift X) := embedding_uLift_down.completelyNormalSpace /-- A T₅ space is a normal T₁ space. -/ class T5Space (X : Type u) [TopologicalSpace X] extends T1Space X, CompletelyNormalSpace X : Prop #align t5_space T5Space theorem Embedding.t5Space [TopologicalSpace Y] [T5Space Y] {e : X → Y} (he : Embedding e) : T5Space X where __ := he.t1Space completely_normal := by have := Embedding.completelyNormalSpace he exact completely_normal #align embedding.t5_space Embedding.t5Space -- see Note [lower instance priority] /-- A `T₅` space is a `T₄` space. -/ instance (priority := 100) T5Space.toT4Space [T5Space X] : T4Space X where -- follows from type-class inference #align t5_space.to_normal_space T5Space.toT4Space /-- A subspace of a T₅ space is a T₅ space. -/ instance [T5Space X] {p : X → Prop} : T5Space { x // p x } := embedding_subtype_val.t5Space instance ULift.instT5Space [T5Space X] : T5Space (ULift X) := embedding_uLift_down.t5Space open SeparationQuotient /-- The `SeparationQuotient` of a completely normal R₀ space is a T₅ space. -/ instance [CompletelyNormalSpace X] [R0Space X] : T5Space (SeparationQuotient X) where t1 := by rwa [((t1Space_TFAE (SeparationQuotient X)).out 1 0 :), SeparationQuotient.t1Space_iff] completely_normal s t hd₁ hd₂ := by rw [← disjoint_comap_iff surjective_mk, comap_mk_nhdsSet, comap_mk_nhdsSet] apply completely_normal <;> rw [← preimage_mk_closure] exacts [hd₁.preimage mk, hd₂.preimage mk] end CompletelyNormal /-- In a compact T₂ space, the connected component of a point equals the intersection of all its clopen neighbourhoods. -/ theorem connectedComponent_eq_iInter_isClopen [T2Space X] [CompactSpace X] (x : X) : connectedComponent x = ⋂ s : { s : Set X // IsClopen s ∧ x ∈ s }, s := by apply Subset.antisymm connectedComponent_subset_iInter_isClopen -- Reduce to showing that the clopen intersection is connected. refine IsPreconnected.subset_connectedComponent ?_ (mem_iInter.2 fun s => s.2.2) -- We do this by showing that any disjoint cover by two closed sets implies -- that one of these closed sets must contain our whole thing. -- To reduce to the case where the cover is disjoint on all of `X` we need that `s` is closed have hs : @IsClosed X _ (⋂ s : { s : Set X // IsClopen s ∧ x ∈ s }, s) := isClosed_iInter fun s => s.2.1.1 rw [isPreconnected_iff_subset_of_fully_disjoint_closed hs] intro a b ha hb hab ab_disj -- Since our space is normal, we get two larger disjoint open sets containing the disjoint -- closed sets. If we can show that our intersection is a subset of any of these we can then -- "descend" this to show that it is a subset of either a or b. rcases normal_separation ha hb ab_disj with ⟨u, v, hu, hv, hau, hbv, huv⟩ obtain ⟨s, H⟩ : ∃ s : Set X, IsClopen s ∧ x ∈ s ∧ s ⊆ u ∪ v := by /- Now we find a clopen set `s` around `x`, contained in `u ∪ v`. We utilize the fact that `X \ u ∪ v` will be compact, so there must be some finite intersection of clopen neighbourhoods of `X` disjoint to it, but a finite intersection of clopen sets is clopen, so we let this be our `s`. -/ have H1 := (hu.union hv).isClosed_compl.isCompact.inter_iInter_nonempty (fun s : { s : Set X // IsClopen s ∧ x ∈ s } => s) fun s => s.2.1.1 rw [← not_disjoint_iff_nonempty_inter, imp_not_comm, not_forall] at H1 cases' H1 (disjoint_compl_left_iff_subset.2 <| hab.trans <| union_subset_union hau hbv) with si H2 refine ⟨⋂ U ∈ si, Subtype.val U, ?_, ?_, ?_⟩ · exact isClopen_biInter_finset fun s _ => s.2.1 · exact mem_iInter₂.2 fun s _ => s.2.2 · rwa [← disjoint_compl_left_iff_subset, disjoint_iff_inter_eq_empty, ← not_nonempty_iff_eq_empty] -- So, we get a disjoint decomposition `s = s ∩ u ∪ s ∩ v` of clopen sets. The intersection of all -- clopen neighbourhoods will then lie in whichever of u or v x lies in and hence will be a subset -- of either a or b. · have H1 := isClopen_inter_of_disjoint_cover_clopen H.1 H.2.2 hu hv huv rw [union_comm] at H have H2 := isClopen_inter_of_disjoint_cover_clopen H.1 H.2.2 hv hu huv.symm by_cases hxu : x ∈ u <;> [left; right] -- The x ∈ u case. · suffices ⋂ s : { s : Set X // IsClopen s ∧ x ∈ s }, ↑s ⊆ u from Disjoint.left_le_of_le_sup_right hab (huv.mono this hbv) · apply Subset.trans _ s.inter_subset_right exact iInter_subset (fun s : { s : Set X // IsClopen s ∧ x ∈ s } => s.1) ⟨s ∩ u, H1, mem_inter H.2.1 hxu⟩ -- If x ∉ u, we get x ∈ v since x ∈ u ∪ v. The rest is then like the x ∈ u case. · have h1 : x ∈ v := (hab.trans (union_subset_union hau hbv) (mem_iInter.2 fun i => i.2.2)).resolve_left hxu suffices ⋂ s : { s : Set X // IsClopen s ∧ x ∈ s }, ↑s ⊆ v from (huv.symm.mono this hau).left_le_of_le_sup_left hab · refine Subset.trans ?_ s.inter_subset_right exact iInter_subset (fun s : { s : Set X // IsClopen s ∧ x ∈ s } => s.1) ⟨s ∩ v, H2, mem_inter H.2.1 h1⟩ #align connected_component_eq_Inter_clopen connectedComponent_eq_iInter_isClopen section Profinite /-- A T1 space with a clopen basis is totally separated. -/ theorem totallySeparatedSpace_of_t1_of_basis_clopen [T1Space X] (h : IsTopologicalBasis { s : Set X | IsClopen s }) : TotallySeparatedSpace X := by constructor rintro x - y - hxy rcases h.mem_nhds_iff.mp (isOpen_ne.mem_nhds hxy) with ⟨U, hU, hxU, hyU⟩ exact ⟨U, Uᶜ, hU.isOpen, hU.compl.isOpen, hxU, fun h => hyU h rfl, (union_compl_self U).superset, disjoint_compl_right⟩ #align totally_separated_space_of_t1_of_basis_clopen totallySeparatedSpace_of_t1_of_basis_clopen variable [T2Space X] [CompactSpace X] /-- A compact Hausdorff space is totally disconnected if and only if it is totally separated, this is also true for locally compact spaces. -/ theorem compact_t2_tot_disc_iff_tot_sep : TotallyDisconnectedSpace X ↔ TotallySeparatedSpace X := by refine ⟨fun h => ⟨fun x _ y _ => ?_⟩, @TotallySeparatedSpace.totallyDisconnectedSpace _ _⟩ contrapose! intro hyp suffices x ∈ connectedComponent y by simpa [totallyDisconnectedSpace_iff_connectedComponent_singleton.1 h y, mem_singleton_iff] rw [connectedComponent_eq_iInter_isClopen, mem_iInter] rintro ⟨w : Set X, hw : IsClopen w, hy : y ∈ w⟩ by_contra hx exact hyp ⟨wᶜ, w, hw.1.isOpen_compl, hw.2, hx, hy, (@isCompl_compl _ w _).symm.codisjoint.top_le, disjoint_compl_left⟩ #align compact_t2_tot_disc_iff_tot_sep compact_t2_tot_disc_iff_tot_sep variable [TotallyDisconnectedSpace X] /-- A totally disconnected compact Hausdorff space is totally separated. -/ instance (priority := 100) : TotallySeparatedSpace X := compact_t2_tot_disc_iff_tot_sep.mp inferInstance theorem nhds_basis_clopen (x : X) : (𝓝 x).HasBasis (fun s : Set X => x ∈ s ∧ IsClopen s) id := ⟨fun U => by constructor · have hx : connectedComponent x = {x} := totallyDisconnectedSpace_iff_connectedComponent_singleton.mp ‹_› x rw [connectedComponent_eq_iInter_isClopen] at hx intro hU let N := { s // IsClopen s ∧ x ∈ s } rsuffices ⟨⟨s, hs, hs'⟩, hs''⟩ : ∃ s : N, s.val ⊆ U · exact ⟨s, ⟨hs', hs⟩, hs''⟩ haveI : Nonempty N := ⟨⟨univ, isClopen_univ, mem_univ x⟩⟩ have hNcl : ∀ s : N, IsClosed s.val := fun s => s.property.1.1 have hdir : Directed Superset fun s : N => s.val := by rintro ⟨s, hs, hxs⟩ ⟨t, ht, hxt⟩ exact ⟨⟨s ∩ t, hs.inter ht, ⟨hxs, hxt⟩⟩, inter_subset_left, inter_subset_right⟩ have h_nhd : ∀ y ∈ ⋂ s : N, s.val, U ∈ 𝓝 y := fun y y_in => by erw [hx, mem_singleton_iff] at y_in rwa [y_in] exact exists_subset_nhds_of_compactSpace hdir hNcl h_nhd · rintro ⟨V, ⟨hxV, -, V_op⟩, hUV : V ⊆ U⟩ rw [mem_nhds_iff] exact ⟨V, hUV, V_op, hxV⟩⟩ #align nhds_basis_clopen nhds_basis_clopen theorem isTopologicalBasis_isClopen : IsTopologicalBasis { s : Set X | IsClopen s } := by apply isTopologicalBasis_of_isOpen_of_nhds fun U (hU : IsClopen U) => hU.2 intro x U hxU U_op have : U ∈ 𝓝 x := IsOpen.mem_nhds U_op hxU rcases (nhds_basis_clopen x).mem_iff.mp this with ⟨V, ⟨hxV, hV⟩, hVU : V ⊆ U⟩ use V tauto #align is_topological_basis_clopen isTopologicalBasis_isClopen /-- Every member of an open set in a compact Hausdorff totally disconnected space is contained in a clopen set contained in the open set. -/ theorem compact_exists_isClopen_in_isOpen {x : X} {U : Set X} (is_open : IsOpen U) (memU : x ∈ U) : ∃ V : Set X, IsClopen V ∧ x ∈ V ∧ V ⊆ U := isTopologicalBasis_isClopen.mem_nhds_iff.1 (is_open.mem_nhds memU) #align compact_exists_clopen_in_open compact_exists_isClopen_in_isOpen end Profinite section LocallyCompact variable {H : Type*} [TopologicalSpace H] [LocallyCompactSpace H] [T2Space H] /-- A locally compact Hausdorff totally disconnected space has a basis with clopen elements. -/ theorem loc_compact_Haus_tot_disc_of_zero_dim [TotallyDisconnectedSpace H] : IsTopologicalBasis { s : Set H | IsClopen s } := by refine isTopologicalBasis_of_isOpen_of_nhds (fun u hu => hu.2) fun x U memU hU => ?_ obtain ⟨s, comp, xs, sU⟩ := exists_compact_subset hU memU let u : Set s := ((↑) : s → H) ⁻¹' interior s have u_open_in_s : IsOpen u := isOpen_interior.preimage continuous_subtype_val lift x to s using interior_subset xs haveI : CompactSpace s := isCompact_iff_compactSpace.1 comp obtain ⟨V : Set s, VisClopen, Vx, V_sub⟩ := compact_exists_isClopen_in_isOpen u_open_in_s xs have VisClopen' : IsClopen (((↑) : s → H) '' V) := by refine ⟨comp.isClosed.closedEmbedding_subtype_val.closed_iff_image_closed.1 VisClopen.1, ?_⟩ let v : Set u := ((↑) : u → s) ⁻¹' V have : ((↑) : u → H) = ((↑) : s → H) ∘ ((↑) : u → s) := rfl have f0 : Embedding ((↑) : u → H) := embedding_subtype_val.comp embedding_subtype_val have f1 : OpenEmbedding ((↑) : u → H) := by refine ⟨f0, ?_⟩ · have : Set.range ((↑) : u → H) = interior s := by rw [this, Set.range_comp, Subtype.range_coe, Subtype.image_preimage_coe] apply Set.inter_eq_self_of_subset_right interior_subset rw [this] apply isOpen_interior have f2 : IsOpen v := VisClopen.2.preimage continuous_subtype_val have f3 : ((↑) : s → H) '' V = ((↑) : u → H) '' v := by rw [this, image_comp, Subtype.image_preimage_coe, inter_eq_self_of_subset_right V_sub] rw [f3] apply f1.isOpenMap v f2 use (↑) '' V, VisClopen', by simp [Vx], Subset.trans (by simp) sU set_option linter.uppercaseLean3 false in #align loc_compact_Haus_tot_disc_of_zero_dim loc_compact_Haus_tot_disc_of_zero_dim /-- A locally compact Hausdorff space is totally disconnected if and only if it is totally separated. -/
Mathlib/Topology/Separation.lean
2,628
2,633
theorem loc_compact_t2_tot_disc_iff_tot_sep : TotallyDisconnectedSpace H ↔ TotallySeparatedSpace H := by
constructor · intro h exact totallySeparatedSpace_of_t1_of_basis_clopen loc_compact_Haus_tot_disc_of_zero_dim apply TotallySeparatedSpace.totallyDisconnectedSpace
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Eric Wieser -/ import Mathlib.Algebra.Quaternion import Mathlib.Analysis.InnerProductSpace.Basic import Mathlib.Analysis.InnerProductSpace.PiL2 import Mathlib.Topology.Algebra.Algebra #align_import analysis.quaternion from "leanprover-community/mathlib"@"07992a1d1f7a4176c6d3f160209608be4e198566" /-! # Quaternions as a normed algebra In this file we define the following structures on the space `ℍ := ℍ[ℝ]` of quaternions: * inner product space; * normed ring; * normed space over `ℝ`. We show that the norm on `ℍ[ℝ]` agrees with the euclidean norm of its components. ## Notation The following notation is available with `open Quaternion` or `open scoped Quaternion`: * `ℍ` : quaternions ## Tags quaternion, normed ring, normed space, normed algebra -/ @[inherit_doc] scoped[Quaternion] notation "ℍ" => Quaternion ℝ open scoped RealInnerProductSpace namespace Quaternion instance : Inner ℝ ℍ := ⟨fun a b => (a * star b).re⟩ theorem inner_self (a : ℍ) : ⟪a, a⟫ = normSq a := rfl #align quaternion.inner_self Quaternion.inner_self theorem inner_def (a b : ℍ) : ⟪a, b⟫ = (a * star b).re := rfl #align quaternion.inner_def Quaternion.inner_def noncomputable instance : NormedAddCommGroup ℍ := @InnerProductSpace.Core.toNormedAddCommGroup ℝ ℍ _ _ _ { toInner := inferInstance conj_symm := fun x y => by simp [inner_def, mul_comm] nonneg_re := fun x => normSq_nonneg definite := fun x => normSq_eq_zero.1 add_left := fun x y z => by simp only [inner_def, add_mul, add_re] smul_left := fun x y r => by simp [inner_def] } noncomputable instance : InnerProductSpace ℝ ℍ := InnerProductSpace.ofCore _ theorem normSq_eq_norm_mul_self (a : ℍ) : normSq a = ‖a‖ * ‖a‖ := by rw [← inner_self, real_inner_self_eq_norm_mul_norm] #align quaternion.norm_sq_eq_norm_sq Quaternion.normSq_eq_norm_mul_self instance : NormOneClass ℍ := ⟨by rw [norm_eq_sqrt_real_inner, inner_self, normSq.map_one, Real.sqrt_one]⟩ @[simp, norm_cast] theorem norm_coe (a : ℝ) : ‖(a : ℍ)‖ = ‖a‖ := by rw [norm_eq_sqrt_real_inner, inner_self, normSq_coe, Real.sqrt_sq_eq_abs, Real.norm_eq_abs] #align quaternion.norm_coe Quaternion.norm_coe @[simp, norm_cast] theorem nnnorm_coe (a : ℝ) : ‖(a : ℍ)‖₊ = ‖a‖₊ := Subtype.ext <| norm_coe a #align quaternion.nnnorm_coe Quaternion.nnnorm_coe @[simp, nolint simpNF] -- Porting note (#10959): simp cannot prove this
Mathlib/Analysis/Quaternion.lean
83
84
theorem norm_star (a : ℍ) : ‖star a‖ = ‖a‖ := by
simp_rw [norm_eq_sqrt_real_inner, inner_self, normSq_star]
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Analysis.Convex.Between import Mathlib.Analysis.Convex.Normed import Mathlib.Analysis.Normed.Group.AddTorsor #align_import analysis.convex.side from "leanprover-community/mathlib"@"a63928c34ec358b5edcda2bf7513c50052a5230f" /-! # Sides of affine subspaces This file defines notions of two points being on the same or opposite sides of an affine subspace. ## Main definitions * `s.WSameSide x y`: The points `x` and `y` are weakly on the same side of the affine subspace `s`. * `s.SSameSide x y`: The points `x` and `y` are strictly on the same side of the affine subspace `s`. * `s.WOppSide x y`: The points `x` and `y` are weakly on opposite sides of the affine subspace `s`. * `s.SOppSide x y`: The points `x` and `y` are strictly on opposite sides of the affine subspace `s`. -/ variable {R V V' P P' : Type*} open AffineEquiv AffineMap namespace AffineSubspace section StrictOrderedCommRing variable [StrictOrderedCommRing R] [AddCommGroup V] [Module R V] [AddTorsor V P] variable [AddCommGroup V'] [Module R V'] [AddTorsor V' P'] /-- The points `x` and `y` are weakly on the same side of `s`. -/ def WSameSide (s : AffineSubspace R P) (x y : P) : Prop := ∃ᵉ (p₁ ∈ s) (p₂ ∈ s), SameRay R (x -ᵥ p₁) (y -ᵥ p₂) #align affine_subspace.w_same_side AffineSubspace.WSameSide /-- The points `x` and `y` are strictly on the same side of `s`. -/ def SSameSide (s : AffineSubspace R P) (x y : P) : Prop := s.WSameSide x y ∧ x ∉ s ∧ y ∉ s #align affine_subspace.s_same_side AffineSubspace.SSameSide /-- The points `x` and `y` are weakly on opposite sides of `s`. -/ def WOppSide (s : AffineSubspace R P) (x y : P) : Prop := ∃ᵉ (p₁ ∈ s) (p₂ ∈ s), SameRay R (x -ᵥ p₁) (p₂ -ᵥ y) #align affine_subspace.w_opp_side AffineSubspace.WOppSide /-- The points `x` and `y` are strictly on opposite sides of `s`. -/ def SOppSide (s : AffineSubspace R P) (x y : P) : Prop := s.WOppSide x y ∧ x ∉ s ∧ y ∉ s #align affine_subspace.s_opp_side AffineSubspace.SOppSide theorem WSameSide.map {s : AffineSubspace R P} {x y : P} (h : s.WSameSide x y) (f : P →ᵃ[R] P') : (s.map f).WSameSide (f x) (f y) := by rcases h with ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨f p₁, mem_map_of_mem f hp₁, f p₂, mem_map_of_mem f hp₂, ?_⟩ simp_rw [← linearMap_vsub] exact h.map f.linear #align affine_subspace.w_same_side.map AffineSubspace.WSameSide.map theorem _root_.Function.Injective.wSameSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : (s.map f).WSameSide (f x) (f y) ↔ s.WSameSide x y := by refine ⟨fun h => ?_, fun h => h.map _⟩ rcases h with ⟨fp₁, hfp₁, fp₂, hfp₂, h⟩ rw [mem_map] at hfp₁ hfp₂ rcases hfp₁ with ⟨p₁, hp₁, rfl⟩ rcases hfp₂ with ⟨p₂, hp₂, rfl⟩ refine ⟨p₁, hp₁, p₂, hp₂, ?_⟩ simp_rw [← linearMap_vsub, (f.linear_injective_iff.2 hf).sameRay_map_iff] at h exact h #align function.injective.w_same_side_map_iff Function.Injective.wSameSide_map_iff theorem _root_.Function.Injective.sSameSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : (s.map f).SSameSide (f x) (f y) ↔ s.SSameSide x y := by simp_rw [SSameSide, hf.wSameSide_map_iff, mem_map_iff_mem_of_injective hf] #align function.injective.s_same_side_map_iff Function.Injective.sSameSide_map_iff @[simp] theorem _root_.AffineEquiv.wSameSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') : (s.map ↑f).WSameSide (f x) (f y) ↔ s.WSameSide x y := (show Function.Injective f.toAffineMap from f.injective).wSameSide_map_iff #align affine_equiv.w_same_side_map_iff AffineEquiv.wSameSide_map_iff @[simp] theorem _root_.AffineEquiv.sSameSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') : (s.map ↑f).SSameSide (f x) (f y) ↔ s.SSameSide x y := (show Function.Injective f.toAffineMap from f.injective).sSameSide_map_iff #align affine_equiv.s_same_side_map_iff AffineEquiv.sSameSide_map_iff theorem WOppSide.map {s : AffineSubspace R P} {x y : P} (h : s.WOppSide x y) (f : P →ᵃ[R] P') : (s.map f).WOppSide (f x) (f y) := by rcases h with ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨f p₁, mem_map_of_mem f hp₁, f p₂, mem_map_of_mem f hp₂, ?_⟩ simp_rw [← linearMap_vsub] exact h.map f.linear #align affine_subspace.w_opp_side.map AffineSubspace.WOppSide.map theorem _root_.Function.Injective.wOppSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : (s.map f).WOppSide (f x) (f y) ↔ s.WOppSide x y := by refine ⟨fun h => ?_, fun h => h.map _⟩ rcases h with ⟨fp₁, hfp₁, fp₂, hfp₂, h⟩ rw [mem_map] at hfp₁ hfp₂ rcases hfp₁ with ⟨p₁, hp₁, rfl⟩ rcases hfp₂ with ⟨p₂, hp₂, rfl⟩ refine ⟨p₁, hp₁, p₂, hp₂, ?_⟩ simp_rw [← linearMap_vsub, (f.linear_injective_iff.2 hf).sameRay_map_iff] at h exact h #align function.injective.w_opp_side_map_iff Function.Injective.wOppSide_map_iff theorem _root_.Function.Injective.sOppSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : (s.map f).SOppSide (f x) (f y) ↔ s.SOppSide x y := by simp_rw [SOppSide, hf.wOppSide_map_iff, mem_map_iff_mem_of_injective hf] #align function.injective.s_opp_side_map_iff Function.Injective.sOppSide_map_iff @[simp] theorem _root_.AffineEquiv.wOppSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') : (s.map ↑f).WOppSide (f x) (f y) ↔ s.WOppSide x y := (show Function.Injective f.toAffineMap from f.injective).wOppSide_map_iff #align affine_equiv.w_opp_side_map_iff AffineEquiv.wOppSide_map_iff @[simp] theorem _root_.AffineEquiv.sOppSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') : (s.map ↑f).SOppSide (f x) (f y) ↔ s.SOppSide x y := (show Function.Injective f.toAffineMap from f.injective).sOppSide_map_iff #align affine_equiv.s_opp_side_map_iff AffineEquiv.sOppSide_map_iff theorem WSameSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.WSameSide x y) : (s : Set P).Nonempty := ⟨h.choose, h.choose_spec.left⟩ #align affine_subspace.w_same_side.nonempty AffineSubspace.WSameSide.nonempty theorem SSameSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : (s : Set P).Nonempty := ⟨h.1.choose, h.1.choose_spec.left⟩ #align affine_subspace.s_same_side.nonempty AffineSubspace.SSameSide.nonempty theorem WOppSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.WOppSide x y) : (s : Set P).Nonempty := ⟨h.choose, h.choose_spec.left⟩ #align affine_subspace.w_opp_side.nonempty AffineSubspace.WOppSide.nonempty theorem SOppSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : (s : Set P).Nonempty := ⟨h.1.choose, h.1.choose_spec.left⟩ #align affine_subspace.s_opp_side.nonempty AffineSubspace.SOppSide.nonempty theorem SSameSide.wSameSide {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : s.WSameSide x y := h.1 #align affine_subspace.s_same_side.w_same_side AffineSubspace.SSameSide.wSameSide theorem SSameSide.left_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : x ∉ s := h.2.1 #align affine_subspace.s_same_side.left_not_mem AffineSubspace.SSameSide.left_not_mem theorem SSameSide.right_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : y ∉ s := h.2.2 #align affine_subspace.s_same_side.right_not_mem AffineSubspace.SSameSide.right_not_mem theorem SOppSide.wOppSide {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : s.WOppSide x y := h.1 #align affine_subspace.s_opp_side.w_opp_side AffineSubspace.SOppSide.wOppSide theorem SOppSide.left_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : x ∉ s := h.2.1 #align affine_subspace.s_opp_side.left_not_mem AffineSubspace.SOppSide.left_not_mem theorem SOppSide.right_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : y ∉ s := h.2.2 #align affine_subspace.s_opp_side.right_not_mem AffineSubspace.SOppSide.right_not_mem theorem wSameSide_comm {s : AffineSubspace R P} {x y : P} : s.WSameSide x y ↔ s.WSameSide y x := ⟨fun ⟨p₁, hp₁, p₂, hp₂, h⟩ => ⟨p₂, hp₂, p₁, hp₁, h.symm⟩, fun ⟨p₁, hp₁, p₂, hp₂, h⟩ => ⟨p₂, hp₂, p₁, hp₁, h.symm⟩⟩ #align affine_subspace.w_same_side_comm AffineSubspace.wSameSide_comm alias ⟨WSameSide.symm, _⟩ := wSameSide_comm #align affine_subspace.w_same_side.symm AffineSubspace.WSameSide.symm theorem sSameSide_comm {s : AffineSubspace R P} {x y : P} : s.SSameSide x y ↔ s.SSameSide y x := by rw [SSameSide, SSameSide, wSameSide_comm, and_comm (b := x ∉ s)] #align affine_subspace.s_same_side_comm AffineSubspace.sSameSide_comm alias ⟨SSameSide.symm, _⟩ := sSameSide_comm #align affine_subspace.s_same_side.symm AffineSubspace.SSameSide.symm theorem wOppSide_comm {s : AffineSubspace R P} {x y : P} : s.WOppSide x y ↔ s.WOppSide y x := by constructor · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨p₂, hp₂, p₁, hp₁, ?_⟩ rwa [SameRay.sameRay_comm, ← sameRay_neg_iff, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨p₂, hp₂, p₁, hp₁, ?_⟩ rwa [SameRay.sameRay_comm, ← sameRay_neg_iff, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] #align affine_subspace.w_opp_side_comm AffineSubspace.wOppSide_comm alias ⟨WOppSide.symm, _⟩ := wOppSide_comm #align affine_subspace.w_opp_side.symm AffineSubspace.WOppSide.symm theorem sOppSide_comm {s : AffineSubspace R P} {x y : P} : s.SOppSide x y ↔ s.SOppSide y x := by rw [SOppSide, SOppSide, wOppSide_comm, and_comm (b := x ∉ s)] #align affine_subspace.s_opp_side_comm AffineSubspace.sOppSide_comm alias ⟨SOppSide.symm, _⟩ := sOppSide_comm #align affine_subspace.s_opp_side.symm AffineSubspace.SOppSide.symm theorem not_wSameSide_bot (x y : P) : ¬(⊥ : AffineSubspace R P).WSameSide x y := fun ⟨_, h, _⟩ => h.elim #align affine_subspace.not_w_same_side_bot AffineSubspace.not_wSameSide_bot theorem not_sSameSide_bot (x y : P) : ¬(⊥ : AffineSubspace R P).SSameSide x y := fun h => not_wSameSide_bot x y h.wSameSide #align affine_subspace.not_s_same_side_bot AffineSubspace.not_sSameSide_bot theorem not_wOppSide_bot (x y : P) : ¬(⊥ : AffineSubspace R P).WOppSide x y := fun ⟨_, h, _⟩ => h.elim #align affine_subspace.not_w_opp_side_bot AffineSubspace.not_wOppSide_bot theorem not_sOppSide_bot (x y : P) : ¬(⊥ : AffineSubspace R P).SOppSide x y := fun h => not_wOppSide_bot x y h.wOppSide #align affine_subspace.not_s_opp_side_bot AffineSubspace.not_sOppSide_bot @[simp] theorem wSameSide_self_iff {s : AffineSubspace R P} {x : P} : s.WSameSide x x ↔ (s : Set P).Nonempty := ⟨fun h => h.nonempty, fun ⟨p, hp⟩ => ⟨p, hp, p, hp, SameRay.rfl⟩⟩ #align affine_subspace.w_same_side_self_iff AffineSubspace.wSameSide_self_iff theorem sSameSide_self_iff {s : AffineSubspace R P} {x : P} : s.SSameSide x x ↔ (s : Set P).Nonempty ∧ x ∉ s := ⟨fun ⟨h, hx, _⟩ => ⟨wSameSide_self_iff.1 h, hx⟩, fun ⟨h, hx⟩ => ⟨wSameSide_self_iff.2 h, hx, hx⟩⟩ #align affine_subspace.s_same_side_self_iff AffineSubspace.sSameSide_self_iff theorem wSameSide_of_left_mem {s : AffineSubspace R P} {x : P} (y : P) (hx : x ∈ s) : s.WSameSide x y := by refine ⟨x, hx, x, hx, ?_⟩ rw [vsub_self] apply SameRay.zero_left #align affine_subspace.w_same_side_of_left_mem AffineSubspace.wSameSide_of_left_mem theorem wSameSide_of_right_mem {s : AffineSubspace R P} (x : P) {y : P} (hy : y ∈ s) : s.WSameSide x y := (wSameSide_of_left_mem x hy).symm #align affine_subspace.w_same_side_of_right_mem AffineSubspace.wSameSide_of_right_mem theorem wOppSide_of_left_mem {s : AffineSubspace R P} {x : P} (y : P) (hx : x ∈ s) : s.WOppSide x y := by refine ⟨x, hx, x, hx, ?_⟩ rw [vsub_self] apply SameRay.zero_left #align affine_subspace.w_opp_side_of_left_mem AffineSubspace.wOppSide_of_left_mem theorem wOppSide_of_right_mem {s : AffineSubspace R P} (x : P) {y : P} (hy : y ∈ s) : s.WOppSide x y := (wOppSide_of_left_mem x hy).symm #align affine_subspace.w_opp_side_of_right_mem AffineSubspace.wOppSide_of_right_mem theorem wSameSide_vadd_left_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.WSameSide (v +ᵥ x) y ↔ s.WSameSide x y := by constructor · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨-v +ᵥ p₁, AffineSubspace.vadd_mem_of_mem_direction (Submodule.neg_mem _ hv) hp₁, p₂, hp₂, ?_⟩ rwa [vsub_vadd_eq_vsub_sub, sub_neg_eq_add, add_comm, ← vadd_vsub_assoc] · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨v +ᵥ p₁, AffineSubspace.vadd_mem_of_mem_direction hv hp₁, p₂, hp₂, ?_⟩ rwa [vadd_vsub_vadd_cancel_left] #align affine_subspace.w_same_side_vadd_left_iff AffineSubspace.wSameSide_vadd_left_iff theorem wSameSide_vadd_right_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.WSameSide x (v +ᵥ y) ↔ s.WSameSide x y := by rw [wSameSide_comm, wSameSide_vadd_left_iff hv, wSameSide_comm] #align affine_subspace.w_same_side_vadd_right_iff AffineSubspace.wSameSide_vadd_right_iff theorem sSameSide_vadd_left_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.SSameSide (v +ᵥ x) y ↔ s.SSameSide x y := by rw [SSameSide, SSameSide, wSameSide_vadd_left_iff hv, vadd_mem_iff_mem_of_mem_direction hv] #align affine_subspace.s_same_side_vadd_left_iff AffineSubspace.sSameSide_vadd_left_iff theorem sSameSide_vadd_right_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.SSameSide x (v +ᵥ y) ↔ s.SSameSide x y := by rw [sSameSide_comm, sSameSide_vadd_left_iff hv, sSameSide_comm] #align affine_subspace.s_same_side_vadd_right_iff AffineSubspace.sSameSide_vadd_right_iff theorem wOppSide_vadd_left_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.WOppSide (v +ᵥ x) y ↔ s.WOppSide x y := by constructor · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨-v +ᵥ p₁, AffineSubspace.vadd_mem_of_mem_direction (Submodule.neg_mem _ hv) hp₁, p₂, hp₂, ?_⟩ rwa [vsub_vadd_eq_vsub_sub, sub_neg_eq_add, add_comm, ← vadd_vsub_assoc] · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨v +ᵥ p₁, AffineSubspace.vadd_mem_of_mem_direction hv hp₁, p₂, hp₂, ?_⟩ rwa [vadd_vsub_vadd_cancel_left] #align affine_subspace.w_opp_side_vadd_left_iff AffineSubspace.wOppSide_vadd_left_iff theorem wOppSide_vadd_right_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.WOppSide x (v +ᵥ y) ↔ s.WOppSide x y := by rw [wOppSide_comm, wOppSide_vadd_left_iff hv, wOppSide_comm] #align affine_subspace.w_opp_side_vadd_right_iff AffineSubspace.wOppSide_vadd_right_iff theorem sOppSide_vadd_left_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.SOppSide (v +ᵥ x) y ↔ s.SOppSide x y := by rw [SOppSide, SOppSide, wOppSide_vadd_left_iff hv, vadd_mem_iff_mem_of_mem_direction hv] #align affine_subspace.s_opp_side_vadd_left_iff AffineSubspace.sOppSide_vadd_left_iff theorem sOppSide_vadd_right_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.SOppSide x (v +ᵥ y) ↔ s.SOppSide x y := by rw [sOppSide_comm, sOppSide_vadd_left_iff hv, sOppSide_comm] #align affine_subspace.s_opp_side_vadd_right_iff AffineSubspace.sOppSide_vadd_right_iff theorem wSameSide_smul_vsub_vadd_left {s : AffineSubspace R P} {p₁ p₂ : P} (x : P) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) {t : R} (ht : 0 ≤ t) : s.WSameSide (t • (x -ᵥ p₁) +ᵥ p₂) x := by refine ⟨p₂, hp₂, p₁, hp₁, ?_⟩ rw [vadd_vsub] exact SameRay.sameRay_nonneg_smul_left _ ht #align affine_subspace.w_same_side_smul_vsub_vadd_left AffineSubspace.wSameSide_smul_vsub_vadd_left theorem wSameSide_smul_vsub_vadd_right {s : AffineSubspace R P} {p₁ p₂ : P} (x : P) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) {t : R} (ht : 0 ≤ t) : s.WSameSide x (t • (x -ᵥ p₁) +ᵥ p₂) := (wSameSide_smul_vsub_vadd_left x hp₁ hp₂ ht).symm #align affine_subspace.w_same_side_smul_vsub_vadd_right AffineSubspace.wSameSide_smul_vsub_vadd_right theorem wSameSide_lineMap_left {s : AffineSubspace R P} {x : P} (y : P) (h : x ∈ s) {t : R} (ht : 0 ≤ t) : s.WSameSide (lineMap x y t) y := wSameSide_smul_vsub_vadd_left y h h ht #align affine_subspace.w_same_side_line_map_left AffineSubspace.wSameSide_lineMap_left theorem wSameSide_lineMap_right {s : AffineSubspace R P} {x : P} (y : P) (h : x ∈ s) {t : R} (ht : 0 ≤ t) : s.WSameSide y (lineMap x y t) := (wSameSide_lineMap_left y h ht).symm #align affine_subspace.w_same_side_line_map_right AffineSubspace.wSameSide_lineMap_right theorem wOppSide_smul_vsub_vadd_left {s : AffineSubspace R P} {p₁ p₂ : P} (x : P) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) {t : R} (ht : t ≤ 0) : s.WOppSide (t • (x -ᵥ p₁) +ᵥ p₂) x := by refine ⟨p₂, hp₂, p₁, hp₁, ?_⟩ rw [vadd_vsub, ← neg_neg t, neg_smul, ← smul_neg, neg_vsub_eq_vsub_rev] exact SameRay.sameRay_nonneg_smul_left _ (neg_nonneg.2 ht) #align affine_subspace.w_opp_side_smul_vsub_vadd_left AffineSubspace.wOppSide_smul_vsub_vadd_left theorem wOppSide_smul_vsub_vadd_right {s : AffineSubspace R P} {p₁ p₂ : P} (x : P) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) {t : R} (ht : t ≤ 0) : s.WOppSide x (t • (x -ᵥ p₁) +ᵥ p₂) := (wOppSide_smul_vsub_vadd_left x hp₁ hp₂ ht).symm #align affine_subspace.w_opp_side_smul_vsub_vadd_right AffineSubspace.wOppSide_smul_vsub_vadd_right theorem wOppSide_lineMap_left {s : AffineSubspace R P} {x : P} (y : P) (h : x ∈ s) {t : R} (ht : t ≤ 0) : s.WOppSide (lineMap x y t) y := wOppSide_smul_vsub_vadd_left y h h ht #align affine_subspace.w_opp_side_line_map_left AffineSubspace.wOppSide_lineMap_left theorem wOppSide_lineMap_right {s : AffineSubspace R P} {x : P} (y : P) (h : x ∈ s) {t : R} (ht : t ≤ 0) : s.WOppSide y (lineMap x y t) := (wOppSide_lineMap_left y h ht).symm #align affine_subspace.w_opp_side_line_map_right AffineSubspace.wOppSide_lineMap_right theorem _root_.Wbtw.wSameSide₂₃ {s : AffineSubspace R P} {x y z : P} (h : Wbtw R x y z) (hx : x ∈ s) : s.WSameSide y z := by rcases h with ⟨t, ⟨ht0, -⟩, rfl⟩ exact wSameSide_lineMap_left z hx ht0 #align wbtw.w_same_side₂₃ Wbtw.wSameSide₂₃ theorem _root_.Wbtw.wSameSide₃₂ {s : AffineSubspace R P} {x y z : P} (h : Wbtw R x y z) (hx : x ∈ s) : s.WSameSide z y := (h.wSameSide₂₃ hx).symm #align wbtw.w_same_side₃₂ Wbtw.wSameSide₃₂ theorem _root_.Wbtw.wSameSide₁₂ {s : AffineSubspace R P} {x y z : P} (h : Wbtw R x y z) (hz : z ∈ s) : s.WSameSide x y := h.symm.wSameSide₃₂ hz #align wbtw.w_same_side₁₂ Wbtw.wSameSide₁₂ theorem _root_.Wbtw.wSameSide₂₁ {s : AffineSubspace R P} {x y z : P} (h : Wbtw R x y z) (hz : z ∈ s) : s.WSameSide y x := h.symm.wSameSide₂₃ hz #align wbtw.w_same_side₂₁ Wbtw.wSameSide₂₁ theorem _root_.Wbtw.wOppSide₁₃ {s : AffineSubspace R P} {x y z : P} (h : Wbtw R x y z) (hy : y ∈ s) : s.WOppSide x z := by rcases h with ⟨t, ⟨ht0, ht1⟩, rfl⟩ refine ⟨_, hy, _, hy, ?_⟩ rcases ht1.lt_or_eq with (ht1' | rfl); swap · rw [lineMap_apply_one]; simp rcases ht0.lt_or_eq with (ht0' | rfl); swap · rw [lineMap_apply_zero]; simp refine Or.inr (Or.inr ⟨1 - t, t, sub_pos.2 ht1', ht0', ?_⟩) -- TODO: after lean4#2336 "simp made no progress feature" -- had to add `_` to several lemmas here. Not sure why! simp_rw [lineMap_apply _, vadd_vsub_assoc _, vsub_vadd_eq_vsub_sub _, ← neg_vsub_eq_vsub_rev z x, vsub_self _, zero_sub, ← neg_one_smul R (z -ᵥ x), ← add_smul, smul_neg, ← neg_smul, smul_smul] ring_nf #align wbtw.w_opp_side₁₃ Wbtw.wOppSide₁₃ theorem _root_.Wbtw.wOppSide₃₁ {s : AffineSubspace R P} {x y z : P} (h : Wbtw R x y z) (hy : y ∈ s) : s.WOppSide z x := h.symm.wOppSide₁₃ hy #align wbtw.w_opp_side₃₁ Wbtw.wOppSide₃₁ end StrictOrderedCommRing section LinearOrderedField variable [LinearOrderedField R] [AddCommGroup V] [Module R V] [AddTorsor V P] variable [AddCommGroup V'] [Module R V'] [AddTorsor V' P'] @[simp] theorem wOppSide_self_iff {s : AffineSubspace R P} {x : P} : s.WOppSide x x ↔ x ∈ s := by constructor · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ obtain ⟨a, -, -, -, -, h₁, -⟩ := h.exists_eq_smul_add rw [add_comm, vsub_add_vsub_cancel, ← eq_vadd_iff_vsub_eq] at h₁ rw [h₁] exact s.smul_vsub_vadd_mem a hp₂ hp₁ hp₁ · exact fun h => ⟨x, h, x, h, SameRay.rfl⟩ #align affine_subspace.w_opp_side_self_iff AffineSubspace.wOppSide_self_iff theorem not_sOppSide_self (s : AffineSubspace R P) (x : P) : ¬s.SOppSide x x := by rw [SOppSide] simp #align affine_subspace.not_s_opp_side_self AffineSubspace.not_sOppSide_self theorem wSameSide_iff_exists_left {s : AffineSubspace R P} {x y p₁ : P} (h : p₁ ∈ s) : s.WSameSide x y ↔ x ∈ s ∨ ∃ p₂ ∈ s, SameRay R (x -ᵥ p₁) (y -ᵥ p₂) := by constructor · rintro ⟨p₁', hp₁', p₂', hp₂', h0 | h0 | ⟨r₁, r₂, hr₁, hr₂, hr⟩⟩ · rw [vsub_eq_zero_iff_eq] at h0 rw [h0] exact Or.inl hp₁' · refine Or.inr ⟨p₂', hp₂', ?_⟩ rw [h0] exact SameRay.zero_right _ · refine Or.inr ⟨(r₁ / r₂) • (p₁ -ᵥ p₁') +ᵥ p₂', s.smul_vsub_vadd_mem _ h hp₁' hp₂', Or.inr (Or.inr ⟨r₁, r₂, hr₁, hr₂, ?_⟩)⟩ rw [vsub_vadd_eq_vsub_sub, smul_sub, ← hr, smul_smul, mul_div_cancel₀ _ hr₂.ne.symm, ← smul_sub, vsub_sub_vsub_cancel_right] · rintro (h' | ⟨h₁, h₂, h₃⟩) · exact wSameSide_of_left_mem y h' · exact ⟨p₁, h, h₁, h₂, h₃⟩ #align affine_subspace.w_same_side_iff_exists_left AffineSubspace.wSameSide_iff_exists_left theorem wSameSide_iff_exists_right {s : AffineSubspace R P} {x y p₂ : P} (h : p₂ ∈ s) : s.WSameSide x y ↔ y ∈ s ∨ ∃ p₁ ∈ s, SameRay R (x -ᵥ p₁) (y -ᵥ p₂) := by rw [wSameSide_comm, wSameSide_iff_exists_left h] simp_rw [SameRay.sameRay_comm] #align affine_subspace.w_same_side_iff_exists_right AffineSubspace.wSameSide_iff_exists_right theorem sSameSide_iff_exists_left {s : AffineSubspace R P} {x y p₁ : P} (h : p₁ ∈ s) : s.SSameSide x y ↔ x ∉ s ∧ y ∉ s ∧ ∃ p₂ ∈ s, SameRay R (x -ᵥ p₁) (y -ᵥ p₂) := by rw [SSameSide, and_comm, wSameSide_iff_exists_left h, and_assoc, and_congr_right_iff] intro hx rw [or_iff_right hx] #align affine_subspace.s_same_side_iff_exists_left AffineSubspace.sSameSide_iff_exists_left theorem sSameSide_iff_exists_right {s : AffineSubspace R P} {x y p₂ : P} (h : p₂ ∈ s) : s.SSameSide x y ↔ x ∉ s ∧ y ∉ s ∧ ∃ p₁ ∈ s, SameRay R (x -ᵥ p₁) (y -ᵥ p₂) := by rw [sSameSide_comm, sSameSide_iff_exists_left h, ← and_assoc, and_comm (a := y ∉ s), and_assoc] simp_rw [SameRay.sameRay_comm] #align affine_subspace.s_same_side_iff_exists_right AffineSubspace.sSameSide_iff_exists_right theorem wOppSide_iff_exists_left {s : AffineSubspace R P} {x y p₁ : P} (h : p₁ ∈ s) : s.WOppSide x y ↔ x ∈ s ∨ ∃ p₂ ∈ s, SameRay R (x -ᵥ p₁) (p₂ -ᵥ y) := by constructor · rintro ⟨p₁', hp₁', p₂', hp₂', h0 | h0 | ⟨r₁, r₂, hr₁, hr₂, hr⟩⟩ · rw [vsub_eq_zero_iff_eq] at h0 rw [h0] exact Or.inl hp₁' · refine Or.inr ⟨p₂', hp₂', ?_⟩ rw [h0] exact SameRay.zero_right _ · refine Or.inr ⟨(-r₁ / r₂) • (p₁ -ᵥ p₁') +ᵥ p₂', s.smul_vsub_vadd_mem _ h hp₁' hp₂', Or.inr (Or.inr ⟨r₁, r₂, hr₁, hr₂, ?_⟩)⟩ rw [vadd_vsub_assoc, smul_add, ← hr, smul_smul, neg_div, mul_neg, mul_div_cancel₀ _ hr₂.ne.symm, neg_smul, neg_add_eq_sub, ← smul_sub, vsub_sub_vsub_cancel_right] · rintro (h' | ⟨h₁, h₂, h₃⟩) · exact wOppSide_of_left_mem y h' · exact ⟨p₁, h, h₁, h₂, h₃⟩ #align affine_subspace.w_opp_side_iff_exists_left AffineSubspace.wOppSide_iff_exists_left theorem wOppSide_iff_exists_right {s : AffineSubspace R P} {x y p₂ : P} (h : p₂ ∈ s) : s.WOppSide x y ↔ y ∈ s ∨ ∃ p₁ ∈ s, SameRay R (x -ᵥ p₁) (p₂ -ᵥ y) := by rw [wOppSide_comm, wOppSide_iff_exists_left h] constructor · rintro (hy | ⟨p, hp, hr⟩) · exact Or.inl hy refine Or.inr ⟨p, hp, ?_⟩ rwa [SameRay.sameRay_comm, ← sameRay_neg_iff, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] · rintro (hy | ⟨p, hp, hr⟩) · exact Or.inl hy refine Or.inr ⟨p, hp, ?_⟩ rwa [SameRay.sameRay_comm, ← sameRay_neg_iff, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] #align affine_subspace.w_opp_side_iff_exists_right AffineSubspace.wOppSide_iff_exists_right theorem sOppSide_iff_exists_left {s : AffineSubspace R P} {x y p₁ : P} (h : p₁ ∈ s) : s.SOppSide x y ↔ x ∉ s ∧ y ∉ s ∧ ∃ p₂ ∈ s, SameRay R (x -ᵥ p₁) (p₂ -ᵥ y) := by rw [SOppSide, and_comm, wOppSide_iff_exists_left h, and_assoc, and_congr_right_iff] intro hx rw [or_iff_right hx] #align affine_subspace.s_opp_side_iff_exists_left AffineSubspace.sOppSide_iff_exists_left theorem sOppSide_iff_exists_right {s : AffineSubspace R P} {x y p₂ : P} (h : p₂ ∈ s) : s.SOppSide x y ↔ x ∉ s ∧ y ∉ s ∧ ∃ p₁ ∈ s, SameRay R (x -ᵥ p₁) (p₂ -ᵥ y) := by rw [SOppSide, and_comm, wOppSide_iff_exists_right h, and_assoc, and_congr_right_iff, and_congr_right_iff] rintro _ hy rw [or_iff_right hy] #align affine_subspace.s_opp_side_iff_exists_right AffineSubspace.sOppSide_iff_exists_right theorem WSameSide.trans {s : AffineSubspace R P} {x y z : P} (hxy : s.WSameSide x y) (hyz : s.WSameSide y z) (hy : y ∉ s) : s.WSameSide x z := by rcases hxy with ⟨p₁, hp₁, p₂, hp₂, hxy⟩ rw [wSameSide_iff_exists_left hp₂, or_iff_right hy] at hyz rcases hyz with ⟨p₃, hp₃, hyz⟩ refine ⟨p₁, hp₁, p₃, hp₃, hxy.trans hyz ?_⟩ refine fun h => False.elim ?_ rw [vsub_eq_zero_iff_eq] at h exact hy (h.symm ▸ hp₂) #align affine_subspace.w_same_side.trans AffineSubspace.WSameSide.trans theorem WSameSide.trans_sSameSide {s : AffineSubspace R P} {x y z : P} (hxy : s.WSameSide x y) (hyz : s.SSameSide y z) : s.WSameSide x z := hxy.trans hyz.1 hyz.2.1 #align affine_subspace.w_same_side.trans_s_same_side AffineSubspace.WSameSide.trans_sSameSide theorem WSameSide.trans_wOppSide {s : AffineSubspace R P} {x y z : P} (hxy : s.WSameSide x y) (hyz : s.WOppSide y z) (hy : y ∉ s) : s.WOppSide x z := by rcases hxy with ⟨p₁, hp₁, p₂, hp₂, hxy⟩ rw [wOppSide_iff_exists_left hp₂, or_iff_right hy] at hyz rcases hyz with ⟨p₃, hp₃, hyz⟩ refine ⟨p₁, hp₁, p₃, hp₃, hxy.trans hyz ?_⟩ refine fun h => False.elim ?_ rw [vsub_eq_zero_iff_eq] at h exact hy (h.symm ▸ hp₂) #align affine_subspace.w_same_side.trans_w_opp_side AffineSubspace.WSameSide.trans_wOppSide theorem WSameSide.trans_sOppSide {s : AffineSubspace R P} {x y z : P} (hxy : s.WSameSide x y) (hyz : s.SOppSide y z) : s.WOppSide x z := hxy.trans_wOppSide hyz.1 hyz.2.1 #align affine_subspace.w_same_side.trans_s_opp_side AffineSubspace.WSameSide.trans_sOppSide theorem SSameSide.trans_wSameSide {s : AffineSubspace R P} {x y z : P} (hxy : s.SSameSide x y) (hyz : s.WSameSide y z) : s.WSameSide x z := (hyz.symm.trans_sSameSide hxy.symm).symm #align affine_subspace.s_same_side.trans_w_same_side AffineSubspace.SSameSide.trans_wSameSide theorem SSameSide.trans {s : AffineSubspace R P} {x y z : P} (hxy : s.SSameSide x y) (hyz : s.SSameSide y z) : s.SSameSide x z := ⟨hxy.wSameSide.trans_sSameSide hyz, hxy.2.1, hyz.2.2⟩ #align affine_subspace.s_same_side.trans AffineSubspace.SSameSide.trans theorem SSameSide.trans_wOppSide {s : AffineSubspace R P} {x y z : P} (hxy : s.SSameSide x y) (hyz : s.WOppSide y z) : s.WOppSide x z := hxy.wSameSide.trans_wOppSide hyz hxy.2.2 #align affine_subspace.s_same_side.trans_w_opp_side AffineSubspace.SSameSide.trans_wOppSide theorem SSameSide.trans_sOppSide {s : AffineSubspace R P} {x y z : P} (hxy : s.SSameSide x y) (hyz : s.SOppSide y z) : s.SOppSide x z := ⟨hxy.trans_wOppSide hyz.1, hxy.2.1, hyz.2.2⟩ #align affine_subspace.s_same_side.trans_s_opp_side AffineSubspace.SSameSide.trans_sOppSide theorem WOppSide.trans_wSameSide {s : AffineSubspace R P} {x y z : P} (hxy : s.WOppSide x y) (hyz : s.WSameSide y z) (hy : y ∉ s) : s.WOppSide x z := (hyz.symm.trans_wOppSide hxy.symm hy).symm #align affine_subspace.w_opp_side.trans_w_same_side AffineSubspace.WOppSide.trans_wSameSide theorem WOppSide.trans_sSameSide {s : AffineSubspace R P} {x y z : P} (hxy : s.WOppSide x y) (hyz : s.SSameSide y z) : s.WOppSide x z := hxy.trans_wSameSide hyz.1 hyz.2.1 #align affine_subspace.w_opp_side.trans_s_same_side AffineSubspace.WOppSide.trans_sSameSide theorem WOppSide.trans {s : AffineSubspace R P} {x y z : P} (hxy : s.WOppSide x y) (hyz : s.WOppSide y z) (hy : y ∉ s) : s.WSameSide x z := by rcases hxy with ⟨p₁, hp₁, p₂, hp₂, hxy⟩ rw [wOppSide_iff_exists_left hp₂, or_iff_right hy] at hyz rcases hyz with ⟨p₃, hp₃, hyz⟩ rw [← sameRay_neg_iff, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] at hyz refine ⟨p₁, hp₁, p₃, hp₃, hxy.trans hyz ?_⟩ refine fun h => False.elim ?_ rw [vsub_eq_zero_iff_eq] at h exact hy (h ▸ hp₂) #align affine_subspace.w_opp_side.trans AffineSubspace.WOppSide.trans theorem WOppSide.trans_sOppSide {s : AffineSubspace R P} {x y z : P} (hxy : s.WOppSide x y) (hyz : s.SOppSide y z) : s.WSameSide x z := hxy.trans hyz.1 hyz.2.1 #align affine_subspace.w_opp_side.trans_s_opp_side AffineSubspace.WOppSide.trans_sOppSide theorem SOppSide.trans_wSameSide {s : AffineSubspace R P} {x y z : P} (hxy : s.SOppSide x y) (hyz : s.WSameSide y z) : s.WOppSide x z := (hyz.symm.trans_sOppSide hxy.symm).symm #align affine_subspace.s_opp_side.trans_w_same_side AffineSubspace.SOppSide.trans_wSameSide theorem SOppSide.trans_sSameSide {s : AffineSubspace R P} {x y z : P} (hxy : s.SOppSide x y) (hyz : s.SSameSide y z) : s.SOppSide x z := (hyz.symm.trans_sOppSide hxy.symm).symm #align affine_subspace.s_opp_side.trans_s_same_side AffineSubspace.SOppSide.trans_sSameSide theorem SOppSide.trans_wOppSide {s : AffineSubspace R P} {x y z : P} (hxy : s.SOppSide x y) (hyz : s.WOppSide y z) : s.WSameSide x z := (hyz.symm.trans_sOppSide hxy.symm).symm #align affine_subspace.s_opp_side.trans_w_opp_side AffineSubspace.SOppSide.trans_wOppSide theorem SOppSide.trans {s : AffineSubspace R P} {x y z : P} (hxy : s.SOppSide x y) (hyz : s.SOppSide y z) : s.SSameSide x z := ⟨hxy.trans_wOppSide hyz.1, hxy.2.1, hyz.2.2⟩ #align affine_subspace.s_opp_side.trans AffineSubspace.SOppSide.trans
Mathlib/Analysis/Convex/Side.lean
622
632
theorem wSameSide_and_wOppSide_iff {s : AffineSubspace R P} {x y : P} : s.WSameSide x y ∧ s.WOppSide x y ↔ x ∈ s ∨ y ∈ s := by
constructor · rintro ⟨hs, ho⟩ rw [wOppSide_comm] at ho by_contra h rw [not_or] at h exact h.1 (wOppSide_self_iff.1 (hs.trans_wOppSide ho h.2)) · rintro (h | h) · exact ⟨wSameSide_of_left_mem y h, wOppSide_of_left_mem y h⟩ · exact ⟨wSameSide_of_right_mem x h, wOppSide_of_right_mem x h⟩
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Angle import Mathlib.Analysis.SpecialFunctions.Trigonometric.Inverse #align_import analysis.special_functions.complex.arg from "leanprover-community/mathlib"@"2c1d8ca2812b64f88992a5294ea3dba144755cd1" /-! # The argument of a complex number. We define `arg : ℂ → ℝ`, returning a real number in the range (-π, π], such that for `x ≠ 0`, `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`, while `arg 0` defaults to `0` -/ open Filter Metric Set open scoped ComplexConjugate Real Topology namespace Complex variable {a x z : ℂ} /-- `arg` returns values in the range (-π, π], such that for `x ≠ 0`, `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`, `arg 0` defaults to `0` -/ noncomputable def arg (x : ℂ) : ℝ := if 0 ≤ x.re then Real.arcsin (x.im / abs x) else if 0 ≤ x.im then Real.arcsin ((-x).im / abs x) + π else Real.arcsin ((-x).im / abs x) - π #align complex.arg Complex.arg theorem sin_arg (x : ℂ) : Real.sin (arg x) = x.im / abs x := by unfold arg; split_ifs <;> simp [sub_eq_add_neg, arg, Real.sin_arcsin (abs_le.1 (abs_im_div_abs_le_one x)).1 (abs_le.1 (abs_im_div_abs_le_one x)).2, Real.sin_add, neg_div, Real.arcsin_neg, Real.sin_neg] #align complex.sin_arg Complex.sin_arg theorem cos_arg {x : ℂ} (hx : x ≠ 0) : Real.cos (arg x) = x.re / abs x := by rw [arg] split_ifs with h₁ h₂ · rw [Real.cos_arcsin] field_simp [Real.sqrt_sq, (abs.pos hx).le, *] · rw [Real.cos_add_pi, Real.cos_arcsin] field_simp [Real.sqrt_div (sq_nonneg _), Real.sqrt_sq_eq_abs, _root_.abs_of_neg (not_le.1 h₁), *] · rw [Real.cos_sub_pi, Real.cos_arcsin] field_simp [Real.sqrt_div (sq_nonneg _), Real.sqrt_sq_eq_abs, _root_.abs_of_neg (not_le.1 h₁), *] #align complex.cos_arg Complex.cos_arg @[simp] theorem abs_mul_exp_arg_mul_I (x : ℂ) : ↑(abs x) * exp (arg x * I) = x := by rcases eq_or_ne x 0 with (rfl | hx) · simp · have : abs x ≠ 0 := abs.ne_zero hx apply Complex.ext <;> field_simp [sin_arg, cos_arg hx, this, mul_comm (abs x)] set_option linter.uppercaseLean3 false in #align complex.abs_mul_exp_arg_mul_I Complex.abs_mul_exp_arg_mul_I @[simp] theorem abs_mul_cos_add_sin_mul_I (x : ℂ) : (abs x * (cos (arg x) + sin (arg x) * I) : ℂ) = x := by rw [← exp_mul_I, abs_mul_exp_arg_mul_I] set_option linter.uppercaseLean3 false in #align complex.abs_mul_cos_add_sin_mul_I Complex.abs_mul_cos_add_sin_mul_I @[simp] lemma abs_mul_cos_arg (x : ℂ) : abs x * Real.cos (arg x) = x.re := by simpa [-abs_mul_cos_add_sin_mul_I] using congr_arg re (abs_mul_cos_add_sin_mul_I x) @[simp] lemma abs_mul_sin_arg (x : ℂ) : abs x * Real.sin (arg x) = x.im := by simpa [-abs_mul_cos_add_sin_mul_I] using congr_arg im (abs_mul_cos_add_sin_mul_I x) theorem abs_eq_one_iff (z : ℂ) : abs z = 1 ↔ ∃ θ : ℝ, exp (θ * I) = z := by refine ⟨fun hz => ⟨arg z, ?_⟩, ?_⟩ · calc exp (arg z * I) = abs z * exp (arg z * I) := by rw [hz, ofReal_one, one_mul] _ = z := abs_mul_exp_arg_mul_I z · rintro ⟨θ, rfl⟩ exact Complex.abs_exp_ofReal_mul_I θ #align complex.abs_eq_one_iff Complex.abs_eq_one_iff @[simp] theorem range_exp_mul_I : (Set.range fun x : ℝ => exp (x * I)) = Metric.sphere 0 1 := by ext x simp only [mem_sphere_zero_iff_norm, norm_eq_abs, abs_eq_one_iff, Set.mem_range] set_option linter.uppercaseLean3 false in #align complex.range_exp_mul_I Complex.range_exp_mul_I theorem arg_mul_cos_add_sin_mul_I {r : ℝ} (hr : 0 < r) {θ : ℝ} (hθ : θ ∈ Set.Ioc (-π) π) : arg (r * (cos θ + sin θ * I)) = θ := by simp only [arg, map_mul, abs_cos_add_sin_mul_I, abs_of_nonneg hr.le, mul_one] simp only [re_ofReal_mul, im_ofReal_mul, neg_im, ← ofReal_cos, ← ofReal_sin, ← mk_eq_add_mul_I, neg_div, mul_div_cancel_left₀ _ hr.ne', mul_nonneg_iff_right_nonneg_of_pos hr] by_cases h₁ : θ ∈ Set.Icc (-(π / 2)) (π / 2) · rw [if_pos] exacts [Real.arcsin_sin' h₁, Real.cos_nonneg_of_mem_Icc h₁] · rw [Set.mem_Icc, not_and_or, not_le, not_le] at h₁ cases' h₁ with h₁ h₁ · replace hθ := hθ.1 have hcos : Real.cos θ < 0 := by rw [← neg_pos, ← Real.cos_add_pi] refine Real.cos_pos_of_mem_Ioo ⟨?_, ?_⟩ <;> linarith have hsin : Real.sin θ < 0 := Real.sin_neg_of_neg_of_neg_pi_lt (by linarith) hθ rw [if_neg, if_neg, ← Real.sin_add_pi, Real.arcsin_sin, add_sub_cancel_right] <;> [linarith; linarith; exact hsin.not_le; exact hcos.not_le] · replace hθ := hθ.2 have hcos : Real.cos θ < 0 := Real.cos_neg_of_pi_div_two_lt_of_lt h₁ (by linarith) have hsin : 0 ≤ Real.sin θ := Real.sin_nonneg_of_mem_Icc ⟨by linarith, hθ⟩ rw [if_neg, if_pos, ← Real.sin_sub_pi, Real.arcsin_sin, sub_add_cancel] <;> [linarith; linarith; exact hsin; exact hcos.not_le] set_option linter.uppercaseLean3 false in #align complex.arg_mul_cos_add_sin_mul_I Complex.arg_mul_cos_add_sin_mul_I theorem arg_cos_add_sin_mul_I {θ : ℝ} (hθ : θ ∈ Set.Ioc (-π) π) : arg (cos θ + sin θ * I) = θ := by rw [← one_mul (_ + _), ← ofReal_one, arg_mul_cos_add_sin_mul_I zero_lt_one hθ] set_option linter.uppercaseLean3 false in #align complex.arg_cos_add_sin_mul_I Complex.arg_cos_add_sin_mul_I lemma arg_exp_mul_I (θ : ℝ) : arg (exp (θ * I)) = toIocMod (mul_pos two_pos Real.pi_pos) (-π) θ := by convert arg_cos_add_sin_mul_I (θ := toIocMod (mul_pos two_pos Real.pi_pos) (-π) θ) _ using 2 · rw [← exp_mul_I, eq_sub_of_add_eq $ toIocMod_add_toIocDiv_zsmul _ _ θ, ofReal_sub, ofReal_zsmul, ofReal_mul, ofReal_ofNat, exp_mul_I_periodic.sub_zsmul_eq] · convert toIocMod_mem_Ioc _ _ _ ring @[simp] theorem arg_zero : arg 0 = 0 := by simp [arg, le_refl] #align complex.arg_zero Complex.arg_zero theorem ext_abs_arg {x y : ℂ} (h₁ : abs x = abs y) (h₂ : x.arg = y.arg) : x = y := by rw [← abs_mul_exp_arg_mul_I x, ← abs_mul_exp_arg_mul_I y, h₁, h₂] #align complex.ext_abs_arg Complex.ext_abs_arg theorem ext_abs_arg_iff {x y : ℂ} : x = y ↔ abs x = abs y ∧ arg x = arg y := ⟨fun h => h ▸ ⟨rfl, rfl⟩, and_imp.2 ext_abs_arg⟩ #align complex.ext_abs_arg_iff Complex.ext_abs_arg_iff theorem arg_mem_Ioc (z : ℂ) : arg z ∈ Set.Ioc (-π) π := by have hπ : 0 < π := Real.pi_pos rcases eq_or_ne z 0 with (rfl | hz) · simp [hπ, hπ.le] rcases existsUnique_add_zsmul_mem_Ioc Real.two_pi_pos (arg z) (-π) with ⟨N, hN, -⟩ rw [two_mul, neg_add_cancel_left, ← two_mul, zsmul_eq_mul] at hN rw [← abs_mul_cos_add_sin_mul_I z, ← cos_add_int_mul_two_pi _ N, ← sin_add_int_mul_two_pi _ N] have := arg_mul_cos_add_sin_mul_I (abs.pos hz) hN push_cast at this rwa [this] #align complex.arg_mem_Ioc Complex.arg_mem_Ioc @[simp] theorem range_arg : Set.range arg = Set.Ioc (-π) π := (Set.range_subset_iff.2 arg_mem_Ioc).antisymm fun _ hx => ⟨_, arg_cos_add_sin_mul_I hx⟩ #align complex.range_arg Complex.range_arg theorem arg_le_pi (x : ℂ) : arg x ≤ π := (arg_mem_Ioc x).2 #align complex.arg_le_pi Complex.arg_le_pi theorem neg_pi_lt_arg (x : ℂ) : -π < arg x := (arg_mem_Ioc x).1 #align complex.neg_pi_lt_arg Complex.neg_pi_lt_arg theorem abs_arg_le_pi (z : ℂ) : |arg z| ≤ π := abs_le.2 ⟨(neg_pi_lt_arg z).le, arg_le_pi z⟩ #align complex.abs_arg_le_pi Complex.abs_arg_le_pi @[simp] theorem arg_nonneg_iff {z : ℂ} : 0 ≤ arg z ↔ 0 ≤ z.im := by rcases eq_or_ne z 0 with (rfl | h₀); · simp calc 0 ≤ arg z ↔ 0 ≤ Real.sin (arg z) := ⟨fun h => Real.sin_nonneg_of_mem_Icc ⟨h, arg_le_pi z⟩, by contrapose! intro h exact Real.sin_neg_of_neg_of_neg_pi_lt h (neg_pi_lt_arg _)⟩ _ ↔ _ := by rw [sin_arg, le_div_iff (abs.pos h₀), zero_mul] #align complex.arg_nonneg_iff Complex.arg_nonneg_iff @[simp] theorem arg_neg_iff {z : ℂ} : arg z < 0 ↔ z.im < 0 := lt_iff_lt_of_le_iff_le arg_nonneg_iff #align complex.arg_neg_iff Complex.arg_neg_iff theorem arg_real_mul (x : ℂ) {r : ℝ} (hr : 0 < r) : arg (r * x) = arg x := by rcases eq_or_ne x 0 with (rfl | hx); · rw [mul_zero] conv_lhs => rw [← abs_mul_cos_add_sin_mul_I x, ← mul_assoc, ← ofReal_mul, arg_mul_cos_add_sin_mul_I (mul_pos hr (abs.pos hx)) x.arg_mem_Ioc] #align complex.arg_real_mul Complex.arg_real_mul theorem arg_mul_real {r : ℝ} (hr : 0 < r) (x : ℂ) : arg (x * r) = arg x := mul_comm x r ▸ arg_real_mul x hr theorem arg_eq_arg_iff {x y : ℂ} (hx : x ≠ 0) (hy : y ≠ 0) : arg x = arg y ↔ (abs y / abs x : ℂ) * x = y := by simp only [ext_abs_arg_iff, map_mul, map_div₀, abs_ofReal, abs_abs, div_mul_cancel₀ _ (abs.ne_zero hx), eq_self_iff_true, true_and_iff] rw [← ofReal_div, arg_real_mul] exact div_pos (abs.pos hy) (abs.pos hx) #align complex.arg_eq_arg_iff Complex.arg_eq_arg_iff @[simp] theorem arg_one : arg 1 = 0 := by simp [arg, zero_le_one] #align complex.arg_one Complex.arg_one @[simp] theorem arg_neg_one : arg (-1) = π := by simp [arg, le_refl, not_le.2 (zero_lt_one' ℝ)] #align complex.arg_neg_one Complex.arg_neg_one @[simp] theorem arg_I : arg I = π / 2 := by simp [arg, le_refl] set_option linter.uppercaseLean3 false in #align complex.arg_I Complex.arg_I @[simp] theorem arg_neg_I : arg (-I) = -(π / 2) := by simp [arg, le_refl] set_option linter.uppercaseLean3 false in #align complex.arg_neg_I Complex.arg_neg_I @[simp] theorem tan_arg (x : ℂ) : Real.tan (arg x) = x.im / x.re := by by_cases h : x = 0 · simp only [h, zero_div, Complex.zero_im, Complex.arg_zero, Real.tan_zero, Complex.zero_re] rw [Real.tan_eq_sin_div_cos, sin_arg, cos_arg h, div_div_div_cancel_right _ (abs.ne_zero h)] #align complex.tan_arg Complex.tan_arg theorem arg_ofReal_of_nonneg {x : ℝ} (hx : 0 ≤ x) : arg x = 0 := by simp [arg, hx] #align complex.arg_of_real_of_nonneg Complex.arg_ofReal_of_nonneg @[simp, norm_cast] lemma natCast_arg {n : ℕ} : arg n = 0 := ofReal_natCast n ▸ arg_ofReal_of_nonneg n.cast_nonneg @[simp] lemma ofNat_arg {n : ℕ} [n.AtLeastTwo] : arg (no_index (OfNat.ofNat n)) = 0 := natCast_arg theorem arg_eq_zero_iff {z : ℂ} : arg z = 0 ↔ 0 ≤ z.re ∧ z.im = 0 := by refine ⟨fun h => ?_, ?_⟩ · rw [← abs_mul_cos_add_sin_mul_I z, h] simp [abs.nonneg] · cases' z with x y rintro ⟨h, rfl : y = 0⟩ exact arg_ofReal_of_nonneg h #align complex.arg_eq_zero_iff Complex.arg_eq_zero_iff open ComplexOrder in lemma arg_eq_zero_iff_zero_le {z : ℂ} : arg z = 0 ↔ 0 ≤ z := by rw [arg_eq_zero_iff, eq_comm, nonneg_iff] theorem arg_eq_pi_iff {z : ℂ} : arg z = π ↔ z.re < 0 ∧ z.im = 0 := by by_cases h₀ : z = 0 · simp [h₀, lt_irrefl, Real.pi_ne_zero.symm] constructor · intro h rw [← abs_mul_cos_add_sin_mul_I z, h] simp [h₀] · cases' z with x y rintro ⟨h : x < 0, rfl : y = 0⟩ rw [← arg_neg_one, ← arg_real_mul (-1) (neg_pos.2 h)] simp [← ofReal_def] #align complex.arg_eq_pi_iff Complex.arg_eq_pi_iff open ComplexOrder in lemma arg_eq_pi_iff_lt_zero {z : ℂ} : arg z = π ↔ z < 0 := arg_eq_pi_iff theorem arg_lt_pi_iff {z : ℂ} : arg z < π ↔ 0 ≤ z.re ∨ z.im ≠ 0 := by rw [(arg_le_pi z).lt_iff_ne, not_iff_comm, not_or, not_le, Classical.not_not, arg_eq_pi_iff] #align complex.arg_lt_pi_iff Complex.arg_lt_pi_iff theorem arg_ofReal_of_neg {x : ℝ} (hx : x < 0) : arg x = π := arg_eq_pi_iff.2 ⟨hx, rfl⟩ #align complex.arg_of_real_of_neg Complex.arg_ofReal_of_neg theorem arg_eq_pi_div_two_iff {z : ℂ} : arg z = π / 2 ↔ z.re = 0 ∧ 0 < z.im := by by_cases h₀ : z = 0; · simp [h₀, lt_irrefl, Real.pi_div_two_pos.ne] constructor · intro h rw [← abs_mul_cos_add_sin_mul_I z, h] simp [h₀] · cases' z with x y rintro ⟨rfl : x = 0, hy : 0 < y⟩ rw [← arg_I, ← arg_real_mul I hy, ofReal_mul', I_re, I_im, mul_zero, mul_one] #align complex.arg_eq_pi_div_two_iff Complex.arg_eq_pi_div_two_iff theorem arg_eq_neg_pi_div_two_iff {z : ℂ} : arg z = -(π / 2) ↔ z.re = 0 ∧ z.im < 0 := by by_cases h₀ : z = 0; · simp [h₀, lt_irrefl, Real.pi_ne_zero] constructor · intro h rw [← abs_mul_cos_add_sin_mul_I z, h] simp [h₀] · cases' z with x y rintro ⟨rfl : x = 0, hy : y < 0⟩ rw [← arg_neg_I, ← arg_real_mul (-I) (neg_pos.2 hy), mk_eq_add_mul_I] simp #align complex.arg_eq_neg_pi_div_two_iff Complex.arg_eq_neg_pi_div_two_iff theorem arg_of_re_nonneg {x : ℂ} (hx : 0 ≤ x.re) : arg x = Real.arcsin (x.im / abs x) := if_pos hx #align complex.arg_of_re_nonneg Complex.arg_of_re_nonneg theorem arg_of_re_neg_of_im_nonneg {x : ℂ} (hx_re : x.re < 0) (hx_im : 0 ≤ x.im) : arg x = Real.arcsin ((-x).im / abs x) + π := by simp only [arg, hx_re.not_le, hx_im, if_true, if_false] #align complex.arg_of_re_neg_of_im_nonneg Complex.arg_of_re_neg_of_im_nonneg theorem arg_of_re_neg_of_im_neg {x : ℂ} (hx_re : x.re < 0) (hx_im : x.im < 0) : arg x = Real.arcsin ((-x).im / abs x) - π := by simp only [arg, hx_re.not_le, hx_im.not_le, if_false] #align complex.arg_of_re_neg_of_im_neg Complex.arg_of_re_neg_of_im_neg theorem arg_of_im_nonneg_of_ne_zero {z : ℂ} (h₁ : 0 ≤ z.im) (h₂ : z ≠ 0) : arg z = Real.arccos (z.re / abs z) := by rw [← cos_arg h₂, Real.arccos_cos (arg_nonneg_iff.2 h₁) (arg_le_pi _)] #align complex.arg_of_im_nonneg_of_ne_zero Complex.arg_of_im_nonneg_of_ne_zero theorem arg_of_im_pos {z : ℂ} (hz : 0 < z.im) : arg z = Real.arccos (z.re / abs z) := arg_of_im_nonneg_of_ne_zero hz.le fun h => hz.ne' <| h.symm ▸ rfl #align complex.arg_of_im_pos Complex.arg_of_im_pos theorem arg_of_im_neg {z : ℂ} (hz : z.im < 0) : arg z = -Real.arccos (z.re / abs z) := by have h₀ : z ≠ 0 := mt (congr_arg im) hz.ne rw [← cos_arg h₀, ← Real.cos_neg, Real.arccos_cos, neg_neg] exacts [neg_nonneg.2 (arg_neg_iff.2 hz).le, neg_le.2 (neg_pi_lt_arg z).le] #align complex.arg_of_im_neg Complex.arg_of_im_neg theorem arg_conj (x : ℂ) : arg (conj x) = if arg x = π then π else -arg x := by simp_rw [arg_eq_pi_iff, arg, neg_im, conj_im, conj_re, abs_conj, neg_div, neg_neg, Real.arcsin_neg] rcases lt_trichotomy x.re 0 with (hr | hr | hr) <;> rcases lt_trichotomy x.im 0 with (hi | hi | hi) · simp [hr, hr.not_le, hi.le, hi.ne, not_le.2 hi, add_comm] · simp [hr, hr.not_le, hi] · simp [hr, hr.not_le, hi.ne.symm, hi.le, not_le.2 hi, sub_eq_neg_add] · simp [hr] · simp [hr] · simp [hr] · simp [hr, hr.le, hi.ne] · simp [hr, hr.le, hr.le.not_lt] · simp [hr, hr.le, hr.le.not_lt] #align complex.arg_conj Complex.arg_conj theorem arg_inv (x : ℂ) : arg x⁻¹ = if arg x = π then π else -arg x := by rw [← arg_conj, inv_def, mul_comm] by_cases hx : x = 0 · simp [hx] · exact arg_real_mul (conj x) (by simp [hx]) #align complex.arg_inv Complex.arg_inv @[simp] lemma abs_arg_inv (x : ℂ) : |x⁻¹.arg| = |x.arg| := by rw [arg_inv]; split_ifs <;> simp [*] -- TODO: Replace the next two lemmas by general facts about periodic functions lemma abs_eq_one_iff' : abs x = 1 ↔ ∃ θ ∈ Set.Ioc (-π) π, exp (θ * I) = x := by rw [abs_eq_one_iff] constructor · rintro ⟨θ, rfl⟩ refine ⟨toIocMod (mul_pos two_pos Real.pi_pos) (-π) θ, ?_, ?_⟩ · convert toIocMod_mem_Ioc _ _ _ ring · rw [eq_sub_of_add_eq $ toIocMod_add_toIocDiv_zsmul _ _ θ, ofReal_sub, ofReal_zsmul, ofReal_mul, ofReal_ofNat, exp_mul_I_periodic.sub_zsmul_eq] · rintro ⟨θ, _, rfl⟩ exact ⟨θ, rfl⟩ lemma image_exp_Ioc_eq_sphere : (fun θ : ℝ ↦ exp (θ * I)) '' Set.Ioc (-π) π = sphere 0 1 := by ext; simpa using abs_eq_one_iff'.symm theorem arg_le_pi_div_two_iff {z : ℂ} : arg z ≤ π / 2 ↔ 0 ≤ re z ∨ im z < 0 := by rcases le_or_lt 0 (re z) with hre | hre · simp only [hre, arg_of_re_nonneg hre, Real.arcsin_le_pi_div_two, true_or_iff] simp only [hre.not_le, false_or_iff] rcases le_or_lt 0 (im z) with him | him · simp only [him.not_lt] rw [iff_false_iff, not_le, arg_of_re_neg_of_im_nonneg hre him, ← sub_lt_iff_lt_add, half_sub, Real.neg_pi_div_two_lt_arcsin, neg_im, neg_div, neg_lt_neg_iff, div_lt_one, ← _root_.abs_of_nonneg him, abs_im_lt_abs] exacts [hre.ne, abs.pos <| ne_of_apply_ne re hre.ne] · simp only [him] rw [iff_true_iff, arg_of_re_neg_of_im_neg hre him] exact (sub_le_self _ Real.pi_pos.le).trans (Real.arcsin_le_pi_div_two _) #align complex.arg_le_pi_div_two_iff Complex.arg_le_pi_div_two_iff theorem neg_pi_div_two_le_arg_iff {z : ℂ} : -(π / 2) ≤ arg z ↔ 0 ≤ re z ∨ 0 ≤ im z := by rcases le_or_lt 0 (re z) with hre | hre · simp only [hre, arg_of_re_nonneg hre, Real.neg_pi_div_two_le_arcsin, true_or_iff] simp only [hre.not_le, false_or_iff] rcases le_or_lt 0 (im z) with him | him · simp only [him] rw [iff_true_iff, arg_of_re_neg_of_im_nonneg hre him] exact (Real.neg_pi_div_two_le_arcsin _).trans (le_add_of_nonneg_right Real.pi_pos.le) · simp only [him.not_le] rw [iff_false_iff, not_le, arg_of_re_neg_of_im_neg hre him, sub_lt_iff_lt_add', ← sub_eq_add_neg, sub_half, Real.arcsin_lt_pi_div_two, div_lt_one, neg_im, ← abs_of_neg him, abs_im_lt_abs] exacts [hre.ne, abs.pos <| ne_of_apply_ne re hre.ne] #align complex.neg_pi_div_two_le_arg_iff Complex.neg_pi_div_two_le_arg_iff lemma neg_pi_div_two_lt_arg_iff {z : ℂ} : -(π / 2) < arg z ↔ 0 < re z ∨ 0 ≤ im z := by rw [lt_iff_le_and_ne, neg_pi_div_two_le_arg_iff, ne_comm, Ne, arg_eq_neg_pi_div_two_iff] rcases lt_trichotomy z.re 0 with hre | hre | hre · simp [hre.ne, hre.not_le, hre.not_lt] · simp [hre] · simp [hre, hre.le, hre.ne'] lemma arg_lt_pi_div_two_iff {z : ℂ} : arg z < π / 2 ↔ 0 < re z ∨ im z < 0 ∨ z = 0 := by rw [lt_iff_le_and_ne, arg_le_pi_div_two_iff, Ne, arg_eq_pi_div_two_iff] rcases lt_trichotomy z.re 0 with hre | hre | hre · have : z ≠ 0 := by simp [ext_iff, hre.ne] simp [hre.ne, hre.not_le, hre.not_lt, this] · have : z = 0 ↔ z.im = 0 := by simp [ext_iff, hre] simp [hre, this, or_comm, le_iff_eq_or_lt] · simp [hre, hre.le, hre.ne'] @[simp] theorem abs_arg_le_pi_div_two_iff {z : ℂ} : |arg z| ≤ π / 2 ↔ 0 ≤ re z := by rw [abs_le, arg_le_pi_div_two_iff, neg_pi_div_two_le_arg_iff, ← or_and_left, ← not_le, and_not_self_iff, or_false_iff] #align complex.abs_arg_le_pi_div_two_iff Complex.abs_arg_le_pi_div_two_iff @[simp] theorem abs_arg_lt_pi_div_two_iff {z : ℂ} : |arg z| < π / 2 ↔ 0 < re z ∨ z = 0 := by rw [abs_lt, arg_lt_pi_div_two_iff, neg_pi_div_two_lt_arg_iff, ← or_and_left] rcases eq_or_ne z 0 with hz | hz · simp [hz] · simp_rw [hz, or_false, ← not_lt, not_and_self_iff, or_false] @[simp] theorem arg_conj_coe_angle (x : ℂ) : (arg (conj x) : Real.Angle) = -arg x := by by_cases h : arg x = π <;> simp [arg_conj, h] #align complex.arg_conj_coe_angle Complex.arg_conj_coe_angle @[simp] theorem arg_inv_coe_angle (x : ℂ) : (arg x⁻¹ : Real.Angle) = -arg x := by by_cases h : arg x = π <;> simp [arg_inv, h] #align complex.arg_inv_coe_angle Complex.arg_inv_coe_angle theorem arg_neg_eq_arg_sub_pi_of_im_pos {x : ℂ} (hi : 0 < x.im) : arg (-x) = arg x - π := by rw [arg_of_im_pos hi, arg_of_im_neg (show (-x).im < 0 from Left.neg_neg_iff.2 hi)] simp [neg_div, Real.arccos_neg] #align complex.arg_neg_eq_arg_sub_pi_of_im_pos Complex.arg_neg_eq_arg_sub_pi_of_im_pos theorem arg_neg_eq_arg_add_pi_of_im_neg {x : ℂ} (hi : x.im < 0) : arg (-x) = arg x + π := by rw [arg_of_im_neg hi, arg_of_im_pos (show 0 < (-x).im from Left.neg_pos_iff.2 hi)] simp [neg_div, Real.arccos_neg, add_comm, ← sub_eq_add_neg] #align complex.arg_neg_eq_arg_add_pi_of_im_neg Complex.arg_neg_eq_arg_add_pi_of_im_neg theorem arg_neg_eq_arg_sub_pi_iff {x : ℂ} : arg (-x) = arg x - π ↔ 0 < x.im ∨ x.im = 0 ∧ x.re < 0 := by rcases lt_trichotomy x.im 0 with (hi | hi | hi) · simp [hi, hi.ne, hi.not_lt, arg_neg_eq_arg_add_pi_of_im_neg, sub_eq_add_neg, ← add_eq_zero_iff_eq_neg, Real.pi_ne_zero] · rw [(ext rfl hi : x = x.re)] rcases lt_trichotomy x.re 0 with (hr | hr | hr) · rw [arg_ofReal_of_neg hr, ← ofReal_neg, arg_ofReal_of_nonneg (Left.neg_pos_iff.2 hr).le] simp [hr] · simp [hr, hi, Real.pi_ne_zero] · rw [arg_ofReal_of_nonneg hr.le, ← ofReal_neg, arg_ofReal_of_neg (Left.neg_neg_iff.2 hr)] simp [hr.not_lt, ← add_eq_zero_iff_eq_neg, Real.pi_ne_zero] · simp [hi, arg_neg_eq_arg_sub_pi_of_im_pos] #align complex.arg_neg_eq_arg_sub_pi_iff Complex.arg_neg_eq_arg_sub_pi_iff theorem arg_neg_eq_arg_add_pi_iff {x : ℂ} : arg (-x) = arg x + π ↔ x.im < 0 ∨ x.im = 0 ∧ 0 < x.re := by rcases lt_trichotomy x.im 0 with (hi | hi | hi) · simp [hi, arg_neg_eq_arg_add_pi_of_im_neg] · rw [(ext rfl hi : x = x.re)] rcases lt_trichotomy x.re 0 with (hr | hr | hr) · rw [arg_ofReal_of_neg hr, ← ofReal_neg, arg_ofReal_of_nonneg (Left.neg_pos_iff.2 hr).le] simp [hr.not_lt, ← two_mul, Real.pi_ne_zero] · simp [hr, hi, Real.pi_ne_zero.symm] · rw [arg_ofReal_of_nonneg hr.le, ← ofReal_neg, arg_ofReal_of_neg (Left.neg_neg_iff.2 hr)] simp [hr] · simp [hi, hi.ne.symm, hi.not_lt, arg_neg_eq_arg_sub_pi_of_im_pos, sub_eq_add_neg, ← add_eq_zero_iff_neg_eq, Real.pi_ne_zero] #align complex.arg_neg_eq_arg_add_pi_iff Complex.arg_neg_eq_arg_add_pi_iff theorem arg_neg_coe_angle {x : ℂ} (hx : x ≠ 0) : (arg (-x) : Real.Angle) = arg x + π := by rcases lt_trichotomy x.im 0 with (hi | hi | hi) · rw [arg_neg_eq_arg_add_pi_of_im_neg hi, Real.Angle.coe_add] · rw [(ext rfl hi : x = x.re)] rcases lt_trichotomy x.re 0 with (hr | hr | hr) · rw [arg_ofReal_of_neg hr, ← ofReal_neg, arg_ofReal_of_nonneg (Left.neg_pos_iff.2 hr).le, ← Real.Angle.coe_add, ← two_mul, Real.Angle.coe_two_pi, Real.Angle.coe_zero] · exact False.elim (hx (ext hr hi)) · rw [arg_ofReal_of_nonneg hr.le, ← ofReal_neg, arg_ofReal_of_neg (Left.neg_neg_iff.2 hr), Real.Angle.coe_zero, zero_add] · rw [arg_neg_eq_arg_sub_pi_of_im_pos hi, Real.Angle.coe_sub, Real.Angle.sub_coe_pi_eq_add_coe_pi] #align complex.arg_neg_coe_angle Complex.arg_neg_coe_angle theorem arg_mul_cos_add_sin_mul_I_eq_toIocMod {r : ℝ} (hr : 0 < r) (θ : ℝ) : arg (r * (cos θ + sin θ * I)) = toIocMod Real.two_pi_pos (-π) θ := by have hi : toIocMod Real.two_pi_pos (-π) θ ∈ Set.Ioc (-π) π := by convert toIocMod_mem_Ioc _ _ θ ring convert arg_mul_cos_add_sin_mul_I hr hi using 3 simp [toIocMod, cos_sub_int_mul_two_pi, sin_sub_int_mul_two_pi] set_option linter.uppercaseLean3 false in #align complex.arg_mul_cos_add_sin_mul_I_eq_to_Ioc_mod Complex.arg_mul_cos_add_sin_mul_I_eq_toIocMod theorem arg_cos_add_sin_mul_I_eq_toIocMod (θ : ℝ) : arg (cos θ + sin θ * I) = toIocMod Real.two_pi_pos (-π) θ := by rw [← one_mul (_ + _), ← ofReal_one, arg_mul_cos_add_sin_mul_I_eq_toIocMod zero_lt_one] set_option linter.uppercaseLean3 false in #align complex.arg_cos_add_sin_mul_I_eq_to_Ioc_mod Complex.arg_cos_add_sin_mul_I_eq_toIocMod theorem arg_mul_cos_add_sin_mul_I_sub {r : ℝ} (hr : 0 < r) (θ : ℝ) : arg (r * (cos θ + sin θ * I)) - θ = 2 * π * ⌊(π - θ) / (2 * π)⌋ := by rw [arg_mul_cos_add_sin_mul_I_eq_toIocMod hr, toIocMod_sub_self, toIocDiv_eq_neg_floor, zsmul_eq_mul] ring_nf set_option linter.uppercaseLean3 false in #align complex.arg_mul_cos_add_sin_mul_I_sub Complex.arg_mul_cos_add_sin_mul_I_sub theorem arg_cos_add_sin_mul_I_sub (θ : ℝ) : arg (cos θ + sin θ * I) - θ = 2 * π * ⌊(π - θ) / (2 * π)⌋ := by rw [← one_mul (_ + _), ← ofReal_one, arg_mul_cos_add_sin_mul_I_sub zero_lt_one] set_option linter.uppercaseLean3 false in #align complex.arg_cos_add_sin_mul_I_sub Complex.arg_cos_add_sin_mul_I_sub theorem arg_mul_cos_add_sin_mul_I_coe_angle {r : ℝ} (hr : 0 < r) (θ : Real.Angle) : (arg (r * (Real.Angle.cos θ + Real.Angle.sin θ * I)) : Real.Angle) = θ := by induction' θ using Real.Angle.induction_on with θ rw [Real.Angle.cos_coe, Real.Angle.sin_coe, Real.Angle.angle_eq_iff_two_pi_dvd_sub] use ⌊(π - θ) / (2 * π)⌋ exact mod_cast arg_mul_cos_add_sin_mul_I_sub hr θ set_option linter.uppercaseLean3 false in #align complex.arg_mul_cos_add_sin_mul_I_coe_angle Complex.arg_mul_cos_add_sin_mul_I_coe_angle theorem arg_cos_add_sin_mul_I_coe_angle (θ : Real.Angle) : (arg (Real.Angle.cos θ + Real.Angle.sin θ * I) : Real.Angle) = θ := by rw [← one_mul (_ + _), ← ofReal_one, arg_mul_cos_add_sin_mul_I_coe_angle zero_lt_one] set_option linter.uppercaseLean3 false in #align complex.arg_cos_add_sin_mul_I_coe_angle Complex.arg_cos_add_sin_mul_I_coe_angle theorem arg_mul_coe_angle {x y : ℂ} (hx : x ≠ 0) (hy : y ≠ 0) : (arg (x * y) : Real.Angle) = arg x + arg y := by convert arg_mul_cos_add_sin_mul_I_coe_angle (mul_pos (abs.pos hx) (abs.pos hy)) (arg x + arg y : Real.Angle) using 3 simp_rw [← Real.Angle.coe_add, Real.Angle.sin_coe, Real.Angle.cos_coe, ofReal_cos, ofReal_sin, cos_add_sin_I, ofReal_add, add_mul, exp_add, ofReal_mul] rw [mul_assoc, mul_comm (exp _), ← mul_assoc (abs y : ℂ), abs_mul_exp_arg_mul_I, mul_comm y, ← mul_assoc, abs_mul_exp_arg_mul_I] #align complex.arg_mul_coe_angle Complex.arg_mul_coe_angle theorem arg_div_coe_angle {x y : ℂ} (hx : x ≠ 0) (hy : y ≠ 0) : (arg (x / y) : Real.Angle) = arg x - arg y := by rw [div_eq_mul_inv, arg_mul_coe_angle hx (inv_ne_zero hy), arg_inv_coe_angle, sub_eq_add_neg] #align complex.arg_div_coe_angle Complex.arg_div_coe_angle @[simp] theorem arg_coe_angle_toReal_eq_arg (z : ℂ) : (arg z : Real.Angle).toReal = arg z := by rw [Real.Angle.toReal_coe_eq_self_iff_mem_Ioc] exact arg_mem_Ioc _ #align complex.arg_coe_angle_to_real_eq_arg Complex.arg_coe_angle_toReal_eq_arg theorem arg_coe_angle_eq_iff_eq_toReal {z : ℂ} {θ : Real.Angle} : (arg z : Real.Angle) = θ ↔ arg z = θ.toReal := by rw [← Real.Angle.toReal_inj, arg_coe_angle_toReal_eq_arg] #align complex.arg_coe_angle_eq_iff_eq_to_real Complex.arg_coe_angle_eq_iff_eq_toReal @[simp] theorem arg_coe_angle_eq_iff {x y : ℂ} : (arg x : Real.Angle) = arg y ↔ arg x = arg y := by simp_rw [← Real.Angle.toReal_inj, arg_coe_angle_toReal_eq_arg] #align complex.arg_coe_angle_eq_iff Complex.arg_coe_angle_eq_iff lemma arg_mul_eq_add_arg_iff {x y : ℂ} (hx₀ : x ≠ 0) (hy₀ : y ≠ 0) : (x * y).arg = x.arg + y.arg ↔ arg x + arg y ∈ Set.Ioc (-π) π := by rw [← arg_coe_angle_toReal_eq_arg, arg_mul_coe_angle hx₀ hy₀, ← Real.Angle.coe_add, Real.Angle.toReal_coe_eq_self_iff_mem_Ioc] alias ⟨_, arg_mul⟩ := arg_mul_eq_add_arg_iff section slitPlane open ComplexOrder in /-- An alternative description of the slit plane as consisting of nonzero complex numbers whose argument is not π. -/ lemma mem_slitPlane_iff_arg {z : ℂ} : z ∈ slitPlane ↔ z.arg ≠ π ∧ z ≠ 0 := by simp only [mem_slitPlane_iff_not_le_zero, le_iff_lt_or_eq, ne_eq, arg_eq_pi_iff_lt_zero, not_or] lemma slitPlane_arg_ne_pi {z : ℂ} (hz : z ∈ slitPlane) : z.arg ≠ Real.pi := (mem_slitPlane_iff_arg.mp hz).1 end slitPlane section Continuity theorem arg_eq_nhds_of_re_pos (hx : 0 < x.re) : arg =ᶠ[𝓝 x] fun x => Real.arcsin (x.im / abs x) := ((continuous_re.tendsto _).eventually (lt_mem_nhds hx)).mono fun _ hy => arg_of_re_nonneg hy.le #align complex.arg_eq_nhds_of_re_pos Complex.arg_eq_nhds_of_re_pos theorem arg_eq_nhds_of_re_neg_of_im_pos (hx_re : x.re < 0) (hx_im : 0 < x.im) : arg =ᶠ[𝓝 x] fun x => Real.arcsin ((-x).im / abs x) + π := by suffices h_forall_nhds : ∀ᶠ y : ℂ in 𝓝 x, y.re < 0 ∧ 0 < y.im from h_forall_nhds.mono fun y hy => arg_of_re_neg_of_im_nonneg hy.1 hy.2.le refine IsOpen.eventually_mem ?_ (⟨hx_re, hx_im⟩ : x.re < 0 ∧ 0 < x.im) exact IsOpen.and (isOpen_lt continuous_re continuous_zero) (isOpen_lt continuous_zero continuous_im) #align complex.arg_eq_nhds_of_re_neg_of_im_pos Complex.arg_eq_nhds_of_re_neg_of_im_pos theorem arg_eq_nhds_of_re_neg_of_im_neg (hx_re : x.re < 0) (hx_im : x.im < 0) : arg =ᶠ[𝓝 x] fun x => Real.arcsin ((-x).im / abs x) - π := by suffices h_forall_nhds : ∀ᶠ y : ℂ in 𝓝 x, y.re < 0 ∧ y.im < 0 from h_forall_nhds.mono fun y hy => arg_of_re_neg_of_im_neg hy.1 hy.2 refine IsOpen.eventually_mem ?_ (⟨hx_re, hx_im⟩ : x.re < 0 ∧ x.im < 0) exact IsOpen.and (isOpen_lt continuous_re continuous_zero) (isOpen_lt continuous_im continuous_zero) #align complex.arg_eq_nhds_of_re_neg_of_im_neg Complex.arg_eq_nhds_of_re_neg_of_im_neg theorem arg_eq_nhds_of_im_pos (hz : 0 < im z) : arg =ᶠ[𝓝 z] fun x => Real.arccos (x.re / abs x) := ((continuous_im.tendsto _).eventually (lt_mem_nhds hz)).mono fun _ => arg_of_im_pos #align complex.arg_eq_nhds_of_im_pos Complex.arg_eq_nhds_of_im_pos theorem arg_eq_nhds_of_im_neg (hz : im z < 0) : arg =ᶠ[𝓝 z] fun x => -Real.arccos (x.re / abs x) := ((continuous_im.tendsto _).eventually (gt_mem_nhds hz)).mono fun _ => arg_of_im_neg #align complex.arg_eq_nhds_of_im_neg Complex.arg_eq_nhds_of_im_neg theorem continuousAt_arg (h : x ∈ slitPlane) : ContinuousAt arg x := by have h₀ : abs x ≠ 0 := by rw [abs.ne_zero_iff] exact slitPlane_ne_zero h rw [mem_slitPlane_iff, ← lt_or_lt_iff_ne] at h rcases h with (hx_re | hx_im | hx_im) exacts [(Real.continuousAt_arcsin.comp (continuous_im.continuousAt.div continuous_abs.continuousAt h₀)).congr (arg_eq_nhds_of_re_pos hx_re).symm, (Real.continuous_arccos.continuousAt.comp (continuous_re.continuousAt.div continuous_abs.continuousAt h₀)).neg.congr (arg_eq_nhds_of_im_neg hx_im).symm, (Real.continuous_arccos.continuousAt.comp (continuous_re.continuousAt.div continuous_abs.continuousAt h₀)).congr (arg_eq_nhds_of_im_pos hx_im).symm] #align complex.continuous_at_arg Complex.continuousAt_arg theorem tendsto_arg_nhdsWithin_im_neg_of_re_neg_of_im_zero {z : ℂ} (hre : z.re < 0) (him : z.im = 0) : Tendsto arg (𝓝[{ z : ℂ | z.im < 0 }] z) (𝓝 (-π)) := by suffices H : Tendsto (fun x : ℂ => Real.arcsin ((-x).im / abs x) - π) (𝓝[{ z : ℂ | z.im < 0 }] z) (𝓝 (-π)) by refine H.congr' ?_ have : ∀ᶠ x : ℂ in 𝓝 z, x.re < 0 := continuous_re.tendsto z (gt_mem_nhds hre) -- Porting note: need to specify the `nhdsWithin` set filter_upwards [self_mem_nhdsWithin (s := { z : ℂ | z.im < 0 }), mem_nhdsWithin_of_mem_nhds this] with _ him hre rw [arg, if_neg hre.not_le, if_neg him.not_le] convert (Real.continuousAt_arcsin.comp_continuousWithinAt ((continuous_im.continuousAt.comp_continuousWithinAt continuousWithinAt_neg).div -- Porting note: added type hint to assist in goal state below continuous_abs.continuousWithinAt (s := { z : ℂ | z.im < 0 }) (_ : abs z ≠ 0)) -- Porting note: specify constant precisely to assist in goal below ).sub_const π using 1 · simp [him] · lift z to ℝ using him simpa using hre.ne #align complex.tendsto_arg_nhds_within_im_neg_of_re_neg_of_im_zero Complex.tendsto_arg_nhdsWithin_im_neg_of_re_neg_of_im_zero theorem continuousWithinAt_arg_of_re_neg_of_im_zero {z : ℂ} (hre : z.re < 0) (him : z.im = 0) : ContinuousWithinAt arg { z : ℂ | 0 ≤ z.im } z := by have : arg =ᶠ[𝓝[{ z : ℂ | 0 ≤ z.im }] z] fun x => Real.arcsin ((-x).im / abs x) + π := by have : ∀ᶠ x : ℂ in 𝓝 z, x.re < 0 := continuous_re.tendsto z (gt_mem_nhds hre) filter_upwards [self_mem_nhdsWithin (s := { z : ℂ | 0 ≤ z.im }), mem_nhdsWithin_of_mem_nhds this] with _ him hre rw [arg, if_neg hre.not_le, if_pos him] refine ContinuousWithinAt.congr_of_eventuallyEq ?_ this ?_ · refine (Real.continuousAt_arcsin.comp_continuousWithinAt ((continuous_im.continuousAt.comp_continuousWithinAt continuousWithinAt_neg).div continuous_abs.continuousWithinAt ?_)).add tendsto_const_nhds lift z to ℝ using him simpa using hre.ne · rw [arg, if_neg hre.not_le, if_pos him.ge] #align complex.continuous_within_at_arg_of_re_neg_of_im_zero Complex.continuousWithinAt_arg_of_re_neg_of_im_zero
Mathlib/Analysis/SpecialFunctions/Complex/Arg.lean
681
684
theorem tendsto_arg_nhdsWithin_im_nonneg_of_re_neg_of_im_zero {z : ℂ} (hre : z.re < 0) (him : z.im = 0) : Tendsto arg (𝓝[{ z : ℂ | 0 ≤ z.im }] z) (𝓝 π) := by
simpa only [arg_eq_pi_iff.2 ⟨hre, him⟩] using (continuousWithinAt_arg_of_re_neg_of_im_zero hre him).tendsto
/- 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.Logic.Equiv.PartialEquiv import Mathlib.Topology.Sets.Opens #align_import topology.local_homeomorph from "leanprover-community/mathlib"@"431589bce478b2229eba14b14a283250428217db" /-! # Partial homeomorphisms This file defines homeomorphisms between open subsets of topological spaces. An element `e` of `PartialHomeomorph X Y` is an extension of `PartialEquiv X Y`, i.e., it is a pair of functions `e.toFun` and `e.invFun`, inverse of each other on the sets `e.source` and `e.target`. Additionally, we require that these sets are open, and that the functions are continuous on them. Equivalently, they are homeomorphisms there. As in equivs, we register a coercion to functions, and we use `e x` and `e.symm x` throughout instead of `e.toFun x` and `e.invFun x`. ## Main definitions * `Homeomorph.toPartialHomeomorph`: associating a partial homeomorphism to a homeomorphism, with `source = target = Set.univ`; * `PartialHomeomorph.symm`: the inverse of a partial homeomorphism * `PartialHomeomorph.trans`: the composition of two partial homeomorphisms * `PartialHomeomorph.refl`: the identity partial homeomorphism * `PartialHomeomorph.ofSet`: the identity on a set `s` * `PartialHomeomorph.EqOnSource`: equivalence relation describing the "right" notion of equality for partial homeomorphisms ## Implementation notes Most statements are copied from their `PartialEquiv` versions, although some care is required especially when restricting to subsets, as these should be open subsets. For design notes, see `PartialEquiv.lean`. ### Local coding conventions If a lemma deals with the intersection of a set with either source or target of a `PartialEquiv`, then it should use `e.source ∩ s` or `e.target ∩ t`, not `s ∩ e.source` or `t ∩ e.target`. -/ open Function Set Filter Topology variable {X X' : Type*} {Y Y' : Type*} {Z Z' : Type*} [TopologicalSpace X] [TopologicalSpace X'] [TopologicalSpace Y] [TopologicalSpace Y'] [TopologicalSpace Z] [TopologicalSpace Z'] /-- Partial homeomorphisms, defined on open subsets of the space -/ -- Porting note(#5171): this linter isn't ported yet. @[nolint has_nonempty_instance] structure PartialHomeomorph (X : Type*) (Y : Type*) [TopologicalSpace X] [TopologicalSpace Y] extends PartialEquiv X Y where open_source : IsOpen source open_target : IsOpen target continuousOn_toFun : ContinuousOn toFun source continuousOn_invFun : ContinuousOn invFun target #align local_homeomorph PartialHomeomorph namespace PartialHomeomorph variable (e : PartialHomeomorph X Y) /-! Basic properties; inverse (symm instance) -/ section Basic /-- Coercion of a partial homeomorphisms to a function. We don't use `e.toFun` because it is actually `e.toPartialEquiv.toFun`, so `simp` will apply lemmas about `toPartialEquiv`. While we may want to switch to this behavior later, doing it mid-port will break a lot of proofs. -/ @[coe] def toFun' : X → Y := e.toFun /-- Coercion of a `PartialHomeomorph` to function. Note that a `PartialHomeomorph` is not `DFunLike`. -/ instance : CoeFun (PartialHomeomorph X Y) fun _ => X → Y := ⟨fun e => e.toFun'⟩ /-- The inverse of a partial homeomorphism -/ @[symm] protected def symm : PartialHomeomorph Y X where toPartialEquiv := e.toPartialEquiv.symm open_source := e.open_target open_target := e.open_source continuousOn_toFun := e.continuousOn_invFun continuousOn_invFun := e.continuousOn_toFun #align local_homeomorph.symm PartialHomeomorph.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 (e : PartialHomeomorph X Y) : X → Y := e #align local_homeomorph.simps.apply PartialHomeomorph.Simps.apply /-- See Note [custom simps projection] -/ def Simps.symm_apply (e : PartialHomeomorph X Y) : Y → X := e.symm #align local_homeomorph.simps.symm_apply PartialHomeomorph.Simps.symm_apply initialize_simps_projections PartialHomeomorph (toFun → apply, invFun → symm_apply) protected theorem continuousOn : ContinuousOn e e.source := e.continuousOn_toFun #align local_homeomorph.continuous_on PartialHomeomorph.continuousOn theorem continuousOn_symm : ContinuousOn e.symm e.target := e.continuousOn_invFun #align local_homeomorph.continuous_on_symm PartialHomeomorph.continuousOn_symm @[simp, mfld_simps] theorem mk_coe (e : PartialEquiv X Y) (a b c d) : (PartialHomeomorph.mk e a b c d : X → Y) = e := rfl #align local_homeomorph.mk_coe PartialHomeomorph.mk_coe @[simp, mfld_simps] theorem mk_coe_symm (e : PartialEquiv X Y) (a b c d) : ((PartialHomeomorph.mk e a b c d).symm : Y → X) = e.symm := rfl #align local_homeomorph.mk_coe_symm PartialHomeomorph.mk_coe_symm theorem toPartialEquiv_injective : Injective (toPartialEquiv : PartialHomeomorph X Y → PartialEquiv X Y) | ⟨_, _, _, _, _⟩, ⟨_, _, _, _, _⟩, rfl => rfl #align local_homeomorph.to_local_equiv_injective PartialHomeomorph.toPartialEquiv_injective /- Register a few simp lemmas to make sure that `simp` puts the application of a local homeomorphism in its normal form, i.e., in terms of its coercion to a function. -/ @[simp, mfld_simps] theorem toFun_eq_coe (e : PartialHomeomorph X Y) : e.toFun = e := rfl #align local_homeomorph.to_fun_eq_coe PartialHomeomorph.toFun_eq_coe @[simp, mfld_simps] theorem invFun_eq_coe (e : PartialHomeomorph X Y) : e.invFun = e.symm := rfl #align local_homeomorph.inv_fun_eq_coe PartialHomeomorph.invFun_eq_coe @[simp, mfld_simps] theorem coe_coe : (e.toPartialEquiv : X → Y) = e := rfl #align local_homeomorph.coe_coe PartialHomeomorph.coe_coe @[simp, mfld_simps] theorem coe_coe_symm : (e.toPartialEquiv.symm : Y → X) = e.symm := rfl #align local_homeomorph.coe_coe_symm PartialHomeomorph.coe_coe_symm @[simp, mfld_simps] theorem map_source {x : X} (h : x ∈ e.source) : e x ∈ e.target := e.map_source' h #align local_homeomorph.map_source PartialHomeomorph.map_source /-- Variant of `map_source`, stated for images of subsets of `source`. -/ lemma map_source'' : e '' e.source ⊆ e.target := fun _ ⟨_, hx, hex⟩ ↦ mem_of_eq_of_mem (id hex.symm) (e.map_source' hx) @[simp, mfld_simps] theorem map_target {x : Y} (h : x ∈ e.target) : e.symm x ∈ e.source := e.map_target' h #align local_homeomorph.map_target PartialHomeomorph.map_target @[simp, mfld_simps] theorem left_inv {x : X} (h : x ∈ e.source) : e.symm (e x) = x := e.left_inv' h #align local_homeomorph.left_inv PartialHomeomorph.left_inv @[simp, mfld_simps] theorem right_inv {x : Y} (h : x ∈ e.target) : e (e.symm x) = x := e.right_inv' h #align local_homeomorph.right_inv PartialHomeomorph.right_inv theorem eq_symm_apply {x : X} {y : Y} (hx : x ∈ e.source) (hy : y ∈ e.target) : x = e.symm y ↔ e x = y := e.toPartialEquiv.eq_symm_apply hx hy #align local_homeomorph.eq_symm_apply PartialHomeomorph.eq_symm_apply protected theorem mapsTo : MapsTo e e.source e.target := fun _ => e.map_source #align local_homeomorph.maps_to PartialHomeomorph.mapsTo protected theorem symm_mapsTo : MapsTo e.symm e.target e.source := e.symm.mapsTo #align local_homeomorph.symm_maps_to PartialHomeomorph.symm_mapsTo protected theorem leftInvOn : LeftInvOn e.symm e e.source := fun _ => e.left_inv #align local_homeomorph.left_inv_on PartialHomeomorph.leftInvOn protected theorem rightInvOn : RightInvOn e.symm e e.target := fun _ => e.right_inv #align local_homeomorph.right_inv_on PartialHomeomorph.rightInvOn protected theorem invOn : InvOn e.symm e e.source e.target := ⟨e.leftInvOn, e.rightInvOn⟩ #align local_homeomorph.inv_on PartialHomeomorph.invOn protected theorem injOn : InjOn e e.source := e.leftInvOn.injOn #align local_homeomorph.inj_on PartialHomeomorph.injOn protected theorem bijOn : BijOn e e.source e.target := e.invOn.bijOn e.mapsTo e.symm_mapsTo #align local_homeomorph.bij_on PartialHomeomorph.bijOn protected theorem surjOn : SurjOn e e.source e.target := e.bijOn.surjOn #align local_homeomorph.surj_on PartialHomeomorph.surjOn end Basic /-- Interpret a `Homeomorph` as a `PartialHomeomorph` by restricting it to an open set `s` in the domain and to `t` in the codomain. -/ @[simps! (config := .asFn) apply symm_apply toPartialEquiv, simps! (config := .lemmasOnly) source target] def _root_.Homeomorph.toPartialHomeomorphOfImageEq (e : X ≃ₜ Y) (s : Set X) (hs : IsOpen s) (t : Set Y) (h : e '' s = t) : PartialHomeomorph X Y where toPartialEquiv := e.toPartialEquivOfImageEq s t h open_source := hs open_target := by simpa [← h] continuousOn_toFun := e.continuous.continuousOn continuousOn_invFun := e.symm.continuous.continuousOn /-- A homeomorphism induces a partial homeomorphism on the whole space -/ @[simps! (config := mfld_cfg)] def _root_.Homeomorph.toPartialHomeomorph (e : X ≃ₜ Y) : PartialHomeomorph X Y := e.toPartialHomeomorphOfImageEq univ isOpen_univ univ <| by rw [image_univ, e.surjective.range_eq] #align homeomorph.to_local_homeomorph Homeomorph.toPartialHomeomorph /-- Replace `toPartialEquiv` field to provide better definitional equalities. -/ def replaceEquiv (e : PartialHomeomorph X Y) (e' : PartialEquiv X Y) (h : e.toPartialEquiv = e') : PartialHomeomorph X Y where toPartialEquiv := e' open_source := h ▸ e.open_source open_target := h ▸ e.open_target continuousOn_toFun := h ▸ e.continuousOn_toFun continuousOn_invFun := h ▸ e.continuousOn_invFun #align local_homeomorph.replace_equiv PartialHomeomorph.replaceEquiv theorem replaceEquiv_eq_self (e' : PartialEquiv X Y) (h : e.toPartialEquiv = e') : e.replaceEquiv e' h = e := by cases e subst e' rfl #align local_homeomorph.replace_equiv_eq_self PartialHomeomorph.replaceEquiv_eq_self theorem source_preimage_target : e.source ⊆ e ⁻¹' e.target := e.mapsTo #align local_homeomorph.source_preimage_target PartialHomeomorph.source_preimage_target @[deprecated toPartialEquiv_injective (since := "2023-02-18")] theorem eq_of_partialEquiv_eq {e e' : PartialHomeomorph X Y} (h : e.toPartialEquiv = e'.toPartialEquiv) : e = e' := toPartialEquiv_injective h #align local_homeomorph.eq_of_local_equiv_eq PartialHomeomorph.eq_of_partialEquiv_eq theorem eventually_left_inverse {x} (hx : x ∈ e.source) : ∀ᶠ y in 𝓝 x, e.symm (e y) = y := (e.open_source.eventually_mem hx).mono e.left_inv' #align local_homeomorph.eventually_left_inverse PartialHomeomorph.eventually_left_inverse theorem eventually_left_inverse' {x} (hx : x ∈ e.target) : ∀ᶠ y in 𝓝 (e.symm x), e.symm (e y) = y := e.eventually_left_inverse (e.map_target hx) #align local_homeomorph.eventually_left_inverse' PartialHomeomorph.eventually_left_inverse' theorem eventually_right_inverse {x} (hx : x ∈ e.target) : ∀ᶠ y in 𝓝 x, e (e.symm y) = y := (e.open_target.eventually_mem hx).mono e.right_inv' #align local_homeomorph.eventually_right_inverse PartialHomeomorph.eventually_right_inverse theorem eventually_right_inverse' {x} (hx : x ∈ e.source) : ∀ᶠ y in 𝓝 (e x), e (e.symm y) = y := e.eventually_right_inverse (e.map_source hx) #align local_homeomorph.eventually_right_inverse' PartialHomeomorph.eventually_right_inverse' theorem eventually_ne_nhdsWithin {x} (hx : x ∈ e.source) : ∀ᶠ x' in 𝓝[≠] x, e x' ≠ e x := eventually_nhdsWithin_iff.2 <| (e.eventually_left_inverse hx).mono fun x' hx' => mt fun h => by rw [mem_singleton_iff, ← e.left_inv hx, ← h, hx'] #align local_homeomorph.eventually_ne_nhds_within PartialHomeomorph.eventually_ne_nhdsWithin theorem nhdsWithin_source_inter {x} (hx : x ∈ e.source) (s : Set X) : 𝓝[e.source ∩ s] x = 𝓝[s] x := nhdsWithin_inter_of_mem (mem_nhdsWithin_of_mem_nhds <| IsOpen.mem_nhds e.open_source hx) #align local_homeomorph.nhds_within_source_inter PartialHomeomorph.nhdsWithin_source_inter theorem nhdsWithin_target_inter {x} (hx : x ∈ e.target) (s : Set Y) : 𝓝[e.target ∩ s] x = 𝓝[s] x := e.symm.nhdsWithin_source_inter hx s #align local_homeomorph.nhds_within_target_inter PartialHomeomorph.nhdsWithin_target_inter theorem image_eq_target_inter_inv_preimage {s : Set X} (h : s ⊆ e.source) : e '' s = e.target ∩ e.symm ⁻¹' s := e.toPartialEquiv.image_eq_target_inter_inv_preimage h #align local_homeomorph.image_eq_target_inter_inv_preimage PartialHomeomorph.image_eq_target_inter_inv_preimage theorem image_source_inter_eq' (s : Set X) : e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' s := e.toPartialEquiv.image_source_inter_eq' s #align local_homeomorph.image_source_inter_eq' PartialHomeomorph.image_source_inter_eq' theorem image_source_inter_eq (s : Set X) : e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' (e.source ∩ s) := e.toPartialEquiv.image_source_inter_eq s #align local_homeomorph.image_source_inter_eq PartialHomeomorph.image_source_inter_eq theorem symm_image_eq_source_inter_preimage {s : Set Y} (h : s ⊆ e.target) : e.symm '' s = e.source ∩ e ⁻¹' s := e.symm.image_eq_target_inter_inv_preimage h #align local_homeomorph.symm_image_eq_source_inter_preimage PartialHomeomorph.symm_image_eq_source_inter_preimage theorem symm_image_target_inter_eq (s : Set Y) : e.symm '' (e.target ∩ s) = e.source ∩ e ⁻¹' (e.target ∩ s) := e.symm.image_source_inter_eq _ #align local_homeomorph.symm_image_target_inter_eq PartialHomeomorph.symm_image_target_inter_eq theorem source_inter_preimage_inv_preimage (s : Set X) : e.source ∩ e ⁻¹' (e.symm ⁻¹' s) = e.source ∩ s := e.toPartialEquiv.source_inter_preimage_inv_preimage s #align local_homeomorph.source_inter_preimage_inv_preimage PartialHomeomorph.source_inter_preimage_inv_preimage theorem target_inter_inv_preimage_preimage (s : Set Y) : e.target ∩ e.symm ⁻¹' (e ⁻¹' s) = e.target ∩ s := e.symm.source_inter_preimage_inv_preimage _ #align local_homeomorph.target_inter_inv_preimage_preimage PartialHomeomorph.target_inter_inv_preimage_preimage theorem source_inter_preimage_target_inter (s : Set Y) : e.source ∩ e ⁻¹' (e.target ∩ s) = e.source ∩ e ⁻¹' s := e.toPartialEquiv.source_inter_preimage_target_inter s #align local_homeomorph.source_inter_preimage_target_inter PartialHomeomorph.source_inter_preimage_target_inter theorem image_source_eq_target : e '' e.source = e.target := e.toPartialEquiv.image_source_eq_target #align local_homeomorph.image_source_eq_target PartialHomeomorph.image_source_eq_target theorem symm_image_target_eq_source : e.symm '' e.target = e.source := e.symm.image_source_eq_target #align local_homeomorph.symm_image_target_eq_source PartialHomeomorph.symm_image_target_eq_source /-- Two partial homeomorphisms are equal when they have equal `toFun`, `invFun` and `source`. It is not sufficient to have equal `toFun` and `source`, as this only determines `invFun` on the target. This would only be true for a weaker notion of equality, arguably the right one, called `EqOnSource`. -/ @[ext] protected theorem ext (e' : PartialHomeomorph X Y) (h : ∀ x, e x = e' x) (hinv : ∀ x, e.symm x = e'.symm x) (hs : e.source = e'.source) : e = e' := toPartialEquiv_injective (PartialEquiv.ext h hinv hs) #align local_homeomorph.ext PartialHomeomorph.ext protected theorem ext_iff {e e' : PartialHomeomorph X Y} : e = e' ↔ (∀ x, e x = e' x) ∧ (∀ x, e.symm x = e'.symm x) ∧ e.source = e'.source := ⟨by rintro rfl exact ⟨fun x => rfl, fun x => rfl, rfl⟩, fun h => e.ext e' h.1 h.2.1 h.2.2⟩ #align local_homeomorph.ext_iff PartialHomeomorph.ext_iff @[simp, mfld_simps] theorem symm_toPartialEquiv : e.symm.toPartialEquiv = e.toPartialEquiv.symm := rfl #align local_homeomorph.symm_to_local_equiv PartialHomeomorph.symm_toPartialEquiv -- The following lemmas are already simp via `PartialEquiv` theorem symm_source : e.symm.source = e.target := rfl #align local_homeomorph.symm_source PartialHomeomorph.symm_source theorem symm_target : e.symm.target = e.source := rfl #align local_homeomorph.symm_target PartialHomeomorph.symm_target @[simp, mfld_simps] theorem symm_symm : e.symm.symm = e := rfl #align local_homeomorph.symm_symm PartialHomeomorph.symm_symm theorem symm_bijective : Function.Bijective (PartialHomeomorph.symm : PartialHomeomorph X Y → PartialHomeomorph Y X) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ /-- A partial homeomorphism is continuous at any point of its source -/ protected theorem continuousAt {x : X} (h : x ∈ e.source) : ContinuousAt e x := (e.continuousOn x h).continuousAt (e.open_source.mem_nhds h) #align local_homeomorph.continuous_at PartialHomeomorph.continuousAt /-- A partial homeomorphism inverse is continuous at any point of its target -/ theorem continuousAt_symm {x : Y} (h : x ∈ e.target) : ContinuousAt e.symm x := e.symm.continuousAt h #align local_homeomorph.continuous_at_symm PartialHomeomorph.continuousAt_symm theorem tendsto_symm {x} (hx : x ∈ e.source) : Tendsto e.symm (𝓝 (e x)) (𝓝 x) := by simpa only [ContinuousAt, e.left_inv hx] using e.continuousAt_symm (e.map_source hx) #align local_homeomorph.tendsto_symm PartialHomeomorph.tendsto_symm theorem map_nhds_eq {x} (hx : x ∈ e.source) : map e (𝓝 x) = 𝓝 (e x) := le_antisymm (e.continuousAt hx) <| le_map_of_right_inverse (e.eventually_right_inverse' hx) (e.tendsto_symm hx) #align local_homeomorph.map_nhds_eq PartialHomeomorph.map_nhds_eq theorem symm_map_nhds_eq {x} (hx : x ∈ e.source) : map e.symm (𝓝 (e x)) = 𝓝 x := (e.symm.map_nhds_eq <| e.map_source hx).trans <| by rw [e.left_inv hx] #align local_homeomorph.symm_map_nhds_eq PartialHomeomorph.symm_map_nhds_eq theorem image_mem_nhds {x} (hx : x ∈ e.source) {s : Set X} (hs : s ∈ 𝓝 x) : e '' s ∈ 𝓝 (e x) := e.map_nhds_eq hx ▸ Filter.image_mem_map hs #align local_homeomorph.image_mem_nhds PartialHomeomorph.image_mem_nhds theorem map_nhdsWithin_eq {x} (hx : x ∈ e.source) (s : Set X) : map e (𝓝[s] x) = 𝓝[e '' (e.source ∩ s)] e x := calc map e (𝓝[s] x) = map e (𝓝[e.source ∩ s] x) := congr_arg (map e) (e.nhdsWithin_source_inter hx _).symm _ = 𝓝[e '' (e.source ∩ s)] e x := (e.leftInvOn.mono inter_subset_left).map_nhdsWithin_eq (e.left_inv hx) (e.continuousAt_symm (e.map_source hx)).continuousWithinAt (e.continuousAt hx).continuousWithinAt #align local_homeomorph.map_nhds_within_eq PartialHomeomorph.map_nhdsWithin_eq theorem map_nhdsWithin_preimage_eq {x} (hx : x ∈ e.source) (s : Set Y) : map e (𝓝[e ⁻¹' s] x) = 𝓝[s] e x := by rw [e.map_nhdsWithin_eq hx, e.image_source_inter_eq', e.target_inter_inv_preimage_preimage, e.nhdsWithin_target_inter (e.map_source hx)] #align local_homeomorph.map_nhds_within_preimage_eq PartialHomeomorph.map_nhdsWithin_preimage_eq theorem eventually_nhds {x : X} (p : Y → Prop) (hx : x ∈ e.source) : (∀ᶠ y in 𝓝 (e x), p y) ↔ ∀ᶠ x in 𝓝 x, p (e x) := Iff.trans (by rw [e.map_nhds_eq hx]) eventually_map #align local_homeomorph.eventually_nhds PartialHomeomorph.eventually_nhds theorem eventually_nhds' {x : X} (p : X → Prop) (hx : x ∈ e.source) : (∀ᶠ y in 𝓝 (e x), p (e.symm y)) ↔ ∀ᶠ x in 𝓝 x, p x := by rw [e.eventually_nhds _ hx] refine eventually_congr ((e.eventually_left_inverse hx).mono fun y hy => ?_) rw [hy] #align local_homeomorph.eventually_nhds' PartialHomeomorph.eventually_nhds' theorem eventually_nhdsWithin {x : X} (p : Y → Prop) {s : Set X} (hx : x ∈ e.source) : (∀ᶠ y in 𝓝[e.symm ⁻¹' s] e x, p y) ↔ ∀ᶠ x in 𝓝[s] x, p (e x) := by refine Iff.trans ?_ eventually_map rw [e.map_nhdsWithin_eq hx, e.image_source_inter_eq', e.nhdsWithin_target_inter (e.mapsTo hx)] #align local_homeomorph.eventually_nhds_within PartialHomeomorph.eventually_nhdsWithin theorem eventually_nhdsWithin' {x : X} (p : X → Prop) {s : Set X} (hx : x ∈ e.source) : (∀ᶠ y in 𝓝[e.symm ⁻¹' s] e x, p (e.symm y)) ↔ ∀ᶠ x in 𝓝[s] x, p x := by rw [e.eventually_nhdsWithin _ hx] refine eventually_congr <| (eventually_nhdsWithin_of_eventually_nhds <| e.eventually_left_inverse hx).mono fun y hy => ?_ rw [hy] #align local_homeomorph.eventually_nhds_within' PartialHomeomorph.eventually_nhdsWithin' /-- This lemma is useful in the manifold library in the case that `e` is a chart. It states that locally around `e x` the set `e.symm ⁻¹' s` is the same as the set intersected with the target of `e` and some other neighborhood of `f x` (which will be the source of a chart on `Z`). -/ theorem preimage_eventuallyEq_target_inter_preimage_inter {e : PartialHomeomorph X Y} {s : Set X} {t : Set Z} {x : X} {f : X → Z} (hf : ContinuousWithinAt f s x) (hxe : x ∈ e.source) (ht : t ∈ 𝓝 (f x)) : e.symm ⁻¹' s =ᶠ[𝓝 (e x)] (e.target ∩ e.symm ⁻¹' (s ∩ f ⁻¹' t) : Set Y) := by rw [eventuallyEq_set, e.eventually_nhds _ hxe] filter_upwards [e.open_source.mem_nhds hxe, mem_nhdsWithin_iff_eventually.mp (hf.preimage_mem_nhdsWithin ht)] intro y hy hyu simp_rw [mem_inter_iff, mem_preimage, mem_inter_iff, e.mapsTo hy, true_and_iff, iff_self_and, e.left_inv hy, iff_true_intro hyu] #align local_homeomorph.preimage_eventually_eq_target_inter_preimage_inter PartialHomeomorph.preimage_eventuallyEq_target_inter_preimage_inter theorem isOpen_inter_preimage {s : Set Y} (hs : IsOpen s) : IsOpen (e.source ∩ e ⁻¹' s) := e.continuousOn.isOpen_inter_preimage e.open_source hs #align local_homeomorph.preimage_open_of_open PartialHomeomorph.isOpen_inter_preimage theorem isOpen_inter_preimage_symm {s : Set X} (hs : IsOpen s) : IsOpen (e.target ∩ e.symm ⁻¹' s) := e.symm.continuousOn.isOpen_inter_preimage e.open_target hs #align local_homeomorph.preimage_open_of_open_symm PartialHomeomorph.isOpen_inter_preimage_symm /-- A partial homeomorphism is an open map on its source: the image of an open subset of the source is open. -/ lemma isOpen_image_of_subset_source {s : Set X} (hs : IsOpen s) (hse : s ⊆ e.source) : IsOpen (e '' s) := by rw [(image_eq_target_inter_inv_preimage (e := e) hse)] exact e.continuousOn_invFun.isOpen_inter_preimage e.open_target hs #align local_homeomorph.image_open_of_open PartialHomeomorph.isOpen_image_of_subset_source /-- The image of the restriction of an open set to the source is open. -/ theorem isOpen_image_source_inter {s : Set X} (hs : IsOpen s) : IsOpen (e '' (e.source ∩ s)) := e.isOpen_image_of_subset_source (e.open_source.inter hs) inter_subset_left #align local_homeomorph.image_open_of_open' PartialHomeomorph.isOpen_image_source_inter /-- The inverse of a partial homeomorphism `e` is an open map on `e.target`. -/ lemma isOpen_image_symm_of_subset_target {t : Set Y} (ht : IsOpen t) (hte : t ⊆ e.target) : IsOpen (e.symm '' t) := isOpen_image_of_subset_source e.symm ht (e.symm_source ▸ hte) lemma isOpen_symm_image_iff_of_subset_target {t : Set Y} (hs : t ⊆ e.target) : IsOpen (e.symm '' t) ↔ IsOpen t := by refine ⟨fun h ↦ ?_, fun h ↦ e.symm.isOpen_image_of_subset_source h hs⟩ have hs' : e.symm '' t ⊆ e.source := by rw [e.symm_image_eq_source_inter_preimage hs] apply Set.inter_subset_left rw [← e.image_symm_image_of_subset_target hs] exact e.isOpen_image_of_subset_source h hs' theorem isOpen_image_iff_of_subset_source {s : Set X} (hs : s ⊆ e.source) : IsOpen (e '' s) ↔ IsOpen s := by rw [← e.symm.isOpen_symm_image_iff_of_subset_target hs, e.symm_symm] section IsImage /-! ### `PartialHomeomorph.IsImage` relation We say that `t : Set Y` is an image of `s : Set X` under a partial homeomorphism `e` if any of the following equivalent conditions hold: * `e '' (e.source ∩ s) = e.target ∩ t`; * `e.source ∩ e ⁻¹ t = e.source ∩ s`; * `∀ x ∈ e.source, e x ∈ t ↔ x ∈ s` (this one is used in the definition). This definition is a restatement of `PartialEquiv.IsImage` for partial homeomorphisms. In this section we transfer API about `PartialEquiv.IsImage` to partial homeomorphisms and add a few `PartialHomeomorph`-specific lemmas like `PartialHomeomorph.IsImage.closure`. -/ /-- We say that `t : Set Y` is an image of `s : Set X` under a partial homeomorphism `e` if any of the following equivalent conditions hold: * `e '' (e.source ∩ s) = e.target ∩ t`; * `e.source ∩ e ⁻¹ t = e.source ∩ s`; * `∀ x ∈ e.source, e x ∈ t ↔ x ∈ s` (this one is used in the definition). -/ def IsImage (s : Set X) (t : Set Y) : Prop := ∀ ⦃x⦄, x ∈ e.source → (e x ∈ t ↔ x ∈ s) #align local_homeomorph.is_image PartialHomeomorph.IsImage namespace IsImage variable {e} {s : Set X} {t : Set Y} {x : X} {y : Y} theorem toPartialEquiv (h : e.IsImage s t) : e.toPartialEquiv.IsImage s t := h #align local_homeomorph.is_image.to_local_equiv PartialHomeomorph.IsImage.toPartialEquiv theorem apply_mem_iff (h : e.IsImage s t) (hx : x ∈ e.source) : e x ∈ t ↔ x ∈ s := h hx #align local_homeomorph.is_image.apply_mem_iff PartialHomeomorph.IsImage.apply_mem_iff protected theorem symm (h : e.IsImage s t) : e.symm.IsImage t s := h.toPartialEquiv.symm #align local_homeomorph.is_image.symm PartialHomeomorph.IsImage.symm theorem symm_apply_mem_iff (h : e.IsImage s t) (hy : y ∈ e.target) : e.symm y ∈ s ↔ y ∈ t := h.symm hy #align local_homeomorph.is_image.symm_apply_mem_iff PartialHomeomorph.IsImage.symm_apply_mem_iff @[simp] theorem symm_iff : e.symm.IsImage t s ↔ e.IsImage s t := ⟨fun h => h.symm, fun h => h.symm⟩ #align local_homeomorph.is_image.symm_iff PartialHomeomorph.IsImage.symm_iff protected theorem mapsTo (h : e.IsImage s t) : MapsTo e (e.source ∩ s) (e.target ∩ t) := h.toPartialEquiv.mapsTo #align local_homeomorph.is_image.maps_to PartialHomeomorph.IsImage.mapsTo theorem symm_mapsTo (h : e.IsImage s t) : MapsTo e.symm (e.target ∩ t) (e.source ∩ s) := h.symm.mapsTo #align local_homeomorph.is_image.symm_maps_to PartialHomeomorph.IsImage.symm_mapsTo theorem image_eq (h : e.IsImage s t) : e '' (e.source ∩ s) = e.target ∩ t := h.toPartialEquiv.image_eq #align local_homeomorph.is_image.image_eq PartialHomeomorph.IsImage.image_eq theorem symm_image_eq (h : e.IsImage s t) : e.symm '' (e.target ∩ t) = e.source ∩ s := h.symm.image_eq #align local_homeomorph.is_image.symm_image_eq PartialHomeomorph.IsImage.symm_image_eq theorem iff_preimage_eq : e.IsImage s t ↔ e.source ∩ e ⁻¹' t = e.source ∩ s := PartialEquiv.IsImage.iff_preimage_eq #align local_homeomorph.is_image.iff_preimage_eq PartialHomeomorph.IsImage.iff_preimage_eq alias ⟨preimage_eq, of_preimage_eq⟩ := iff_preimage_eq #align local_homeomorph.is_image.preimage_eq PartialHomeomorph.IsImage.preimage_eq #align local_homeomorph.is_image.of_preimage_eq PartialHomeomorph.IsImage.of_preimage_eq theorem iff_symm_preimage_eq : e.IsImage s t ↔ e.target ∩ e.symm ⁻¹' s = e.target ∩ t := symm_iff.symm.trans iff_preimage_eq #align local_homeomorph.is_image.iff_symm_preimage_eq PartialHomeomorph.IsImage.iff_symm_preimage_eq alias ⟨symm_preimage_eq, of_symm_preimage_eq⟩ := iff_symm_preimage_eq #align local_homeomorph.is_image.symm_preimage_eq PartialHomeomorph.IsImage.symm_preimage_eq #align local_homeomorph.is_image.of_symm_preimage_eq PartialHomeomorph.IsImage.of_symm_preimage_eq theorem iff_symm_preimage_eq' : e.IsImage s t ↔ e.target ∩ e.symm ⁻¹' (e.source ∩ s) = e.target ∩ t := by rw [iff_symm_preimage_eq, ← image_source_inter_eq, ← image_source_inter_eq'] #align local_homeomorph.is_image.iff_symm_preimage_eq' PartialHomeomorph.IsImage.iff_symm_preimage_eq' alias ⟨symm_preimage_eq', of_symm_preimage_eq'⟩ := iff_symm_preimage_eq' #align local_homeomorph.is_image.symm_preimage_eq' PartialHomeomorph.IsImage.symm_preimage_eq' #align local_homeomorph.is_image.of_symm_preimage_eq' PartialHomeomorph.IsImage.of_symm_preimage_eq' theorem iff_preimage_eq' : e.IsImage s t ↔ e.source ∩ e ⁻¹' (e.target ∩ t) = e.source ∩ s := symm_iff.symm.trans iff_symm_preimage_eq' #align local_homeomorph.is_image.iff_preimage_eq' PartialHomeomorph.IsImage.iff_preimage_eq' alias ⟨preimage_eq', of_preimage_eq'⟩ := iff_preimage_eq' #align local_homeomorph.is_image.preimage_eq' PartialHomeomorph.IsImage.preimage_eq' #align local_homeomorph.is_image.of_preimage_eq' PartialHomeomorph.IsImage.of_preimage_eq' theorem of_image_eq (h : e '' (e.source ∩ s) = e.target ∩ t) : e.IsImage s t := PartialEquiv.IsImage.of_image_eq h #align local_homeomorph.is_image.of_image_eq PartialHomeomorph.IsImage.of_image_eq theorem of_symm_image_eq (h : e.symm '' (e.target ∩ t) = e.source ∩ s) : e.IsImage s t := PartialEquiv.IsImage.of_symm_image_eq h #align local_homeomorph.is_image.of_symm_image_eq PartialHomeomorph.IsImage.of_symm_image_eq protected theorem compl (h : e.IsImage s t) : e.IsImage sᶜ tᶜ := fun _ hx => (h hx).not #align local_homeomorph.is_image.compl PartialHomeomorph.IsImage.compl protected theorem inter {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') : e.IsImage (s ∩ s') (t ∩ t') := fun _ hx => (h hx).and (h' hx) #align local_homeomorph.is_image.inter PartialHomeomorph.IsImage.inter protected theorem union {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') : e.IsImage (s ∪ s') (t ∪ t') := fun _ hx => (h hx).or (h' hx) #align local_homeomorph.is_image.union PartialHomeomorph.IsImage.union protected theorem diff {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') : e.IsImage (s \ s') (t \ t') := h.inter h'.compl #align local_homeomorph.is_image.diff PartialHomeomorph.IsImage.diff theorem leftInvOn_piecewise {e' : PartialHomeomorph X Y} [∀ i, Decidable (i ∈ s)] [∀ i, Decidable (i ∈ t)] (h : e.IsImage s t) (h' : e'.IsImage s t) : LeftInvOn (t.piecewise e.symm e'.symm) (s.piecewise e e') (s.ite e.source e'.source) := h.toPartialEquiv.leftInvOn_piecewise h' #align local_homeomorph.is_image.left_inv_on_piecewise PartialHomeomorph.IsImage.leftInvOn_piecewise theorem inter_eq_of_inter_eq_of_eqOn {e' : PartialHomeomorph X Y} (h : e.IsImage s t) (h' : e'.IsImage s t) (hs : e.source ∩ s = e'.source ∩ s) (Heq : EqOn e e' (e.source ∩ s)) : e.target ∩ t = e'.target ∩ t := h.toPartialEquiv.inter_eq_of_inter_eq_of_eqOn h' hs Heq #align local_homeomorph.is_image.inter_eq_of_inter_eq_of_eq_on PartialHomeomorph.IsImage.inter_eq_of_inter_eq_of_eqOn theorem symm_eqOn_of_inter_eq_of_eqOn {e' : PartialHomeomorph X Y} (h : e.IsImage s t) (hs : e.source ∩ s = e'.source ∩ s) (Heq : EqOn e e' (e.source ∩ s)) : EqOn e.symm e'.symm (e.target ∩ t) := h.toPartialEquiv.symm_eq_on_of_inter_eq_of_eqOn hs Heq #align local_homeomorph.is_image.symm_eq_on_of_inter_eq_of_eq_on PartialHomeomorph.IsImage.symm_eqOn_of_inter_eq_of_eqOn theorem map_nhdsWithin_eq (h : e.IsImage s t) (hx : x ∈ e.source) : map e (𝓝[s] x) = 𝓝[t] e x := by rw [e.map_nhdsWithin_eq hx, h.image_eq, e.nhdsWithin_target_inter (e.map_source hx)] #align local_homeomorph.is_image.map_nhds_within_eq PartialHomeomorph.IsImage.map_nhdsWithin_eq protected theorem closure (h : e.IsImage s t) : e.IsImage (closure s) (closure t) := fun x hx => by simp only [mem_closure_iff_nhdsWithin_neBot, ← h.map_nhdsWithin_eq hx, map_neBot_iff] #align local_homeomorph.is_image.closure PartialHomeomorph.IsImage.closure protected theorem interior (h : e.IsImage s t) : e.IsImage (interior s) (interior t) := by simpa only [closure_compl, compl_compl] using h.compl.closure.compl #align local_homeomorph.is_image.interior PartialHomeomorph.IsImage.interior protected theorem frontier (h : e.IsImage s t) : e.IsImage (frontier s) (frontier t) := h.closure.diff h.interior #align local_homeomorph.is_image.frontier PartialHomeomorph.IsImage.frontier theorem isOpen_iff (h : e.IsImage s t) : IsOpen (e.source ∩ s) ↔ IsOpen (e.target ∩ t) := ⟨fun hs => h.symm_preimage_eq' ▸ e.symm.isOpen_inter_preimage hs, fun hs => h.preimage_eq' ▸ e.isOpen_inter_preimage hs⟩ #align local_homeomorph.is_image.is_open_iff PartialHomeomorph.IsImage.isOpen_iff /-- Restrict a `PartialHomeomorph` to a pair of corresponding open sets. -/ @[simps toPartialEquiv] def restr (h : e.IsImage s t) (hs : IsOpen (e.source ∩ s)) : PartialHomeomorph X Y where toPartialEquiv := h.toPartialEquiv.restr open_source := hs open_target := h.isOpen_iff.1 hs continuousOn_toFun := e.continuousOn.mono inter_subset_left continuousOn_invFun := e.symm.continuousOn.mono inter_subset_left #align local_homeomorph.is_image.restr PartialHomeomorph.IsImage.restr end IsImage theorem isImage_source_target : e.IsImage e.source e.target := e.toPartialEquiv.isImage_source_target #align local_homeomorph.is_image_source_target PartialHomeomorph.isImage_source_target theorem isImage_source_target_of_disjoint (e' : PartialHomeomorph X Y) (hs : Disjoint e.source e'.source) (ht : Disjoint e.target e'.target) : e.IsImage e'.source e'.target := e.toPartialEquiv.isImage_source_target_of_disjoint e'.toPartialEquiv hs ht #align local_homeomorph.is_image_source_target_of_disjoint PartialHomeomorph.isImage_source_target_of_disjoint /-- Preimage of interior or interior of preimage coincide for partial homeomorphisms, when restricted to the source. -/ theorem preimage_interior (s : Set Y) : e.source ∩ e ⁻¹' interior s = e.source ∩ interior (e ⁻¹' s) := (IsImage.of_preimage_eq rfl).interior.preimage_eq #align local_homeomorph.preimage_interior PartialHomeomorph.preimage_interior theorem preimage_closure (s : Set Y) : e.source ∩ e ⁻¹' closure s = e.source ∩ closure (e ⁻¹' s) := (IsImage.of_preimage_eq rfl).closure.preimage_eq #align local_homeomorph.preimage_closure PartialHomeomorph.preimage_closure theorem preimage_frontier (s : Set Y) : e.source ∩ e ⁻¹' frontier s = e.source ∩ frontier (e ⁻¹' s) := (IsImage.of_preimage_eq rfl).frontier.preimage_eq #align local_homeomorph.preimage_frontier PartialHomeomorph.preimage_frontier end IsImage /-- A `PartialEquiv` with continuous open forward map and open source is a `PartialHomeomorph`. -/ def ofContinuousOpenRestrict (e : PartialEquiv X Y) (hc : ContinuousOn e e.source) (ho : IsOpenMap (e.source.restrict e)) (hs : IsOpen e.source) : PartialHomeomorph X Y where toPartialEquiv := e open_source := hs open_target := by simpa only [range_restrict, e.image_source_eq_target] using ho.isOpen_range continuousOn_toFun := hc continuousOn_invFun := e.image_source_eq_target ▸ ho.continuousOn_image_of_leftInvOn e.leftInvOn #align local_homeomorph.of_continuous_open_restrict PartialHomeomorph.ofContinuousOpenRestrict /-- A `PartialEquiv` with continuous open forward map and open source is a `PartialHomeomorph`. -/ def ofContinuousOpen (e : PartialEquiv X Y) (hc : ContinuousOn e e.source) (ho : IsOpenMap e) (hs : IsOpen e.source) : PartialHomeomorph X Y := ofContinuousOpenRestrict e hc (ho.restrict hs) hs #align local_homeomorph.of_continuous_open PartialHomeomorph.ofContinuousOpen /-- Restricting a partial homeomorphism `e` to `e.source ∩ s` when `s` is open. This is sometimes hard to use because of the openness assumption, but it has the advantage that when it can be used then its `PartialEquiv` is defeq to `PartialEquiv.restr`. -/ protected def restrOpen (s : Set X) (hs : IsOpen s) : PartialHomeomorph X Y := (@IsImage.of_symm_preimage_eq X Y _ _ e s (e.symm ⁻¹' s) rfl).restr (IsOpen.inter e.open_source hs) #align local_homeomorph.restr_open PartialHomeomorph.restrOpen @[simp, mfld_simps] theorem restrOpen_toPartialEquiv (s : Set X) (hs : IsOpen s) : (e.restrOpen s hs).toPartialEquiv = e.toPartialEquiv.restr s := rfl #align local_homeomorph.restr_open_to_local_equiv PartialHomeomorph.restrOpen_toPartialEquiv -- Already simp via `PartialEquiv` theorem restrOpen_source (s : Set X) (hs : IsOpen s) : (e.restrOpen s hs).source = e.source ∩ s := rfl #align local_homeomorph.restr_open_source PartialHomeomorph.restrOpen_source /-- Restricting a partial homeomorphism `e` to `e.source ∩ interior s`. We use the interior to make sure that the restriction is well defined whatever the set s, since partial homeomorphisms are by definition defined on open sets. In applications where `s` is open, this coincides with the restriction of partial equivalences -/ @[simps! (config := mfld_cfg) apply symm_apply, simps! (config := .lemmasOnly) source target] protected def restr (s : Set X) : PartialHomeomorph X Y := e.restrOpen (interior s) isOpen_interior #align local_homeomorph.restr PartialHomeomorph.restr @[simp, mfld_simps] theorem restr_toPartialEquiv (s : Set X) : (e.restr s).toPartialEquiv = e.toPartialEquiv.restr (interior s) := rfl #align local_homeomorph.restr_to_local_equiv PartialHomeomorph.restr_toPartialEquiv theorem restr_source' (s : Set X) (hs : IsOpen s) : (e.restr s).source = e.source ∩ s := by rw [e.restr_source, hs.interior_eq] #align local_homeomorph.restr_source' PartialHomeomorph.restr_source' theorem restr_toPartialEquiv' (s : Set X) (hs : IsOpen s) : (e.restr s).toPartialEquiv = e.toPartialEquiv.restr s := by rw [e.restr_toPartialEquiv, hs.interior_eq] #align local_homeomorph.restr_to_local_equiv' PartialHomeomorph.restr_toPartialEquiv' theorem restr_eq_of_source_subset {e : PartialHomeomorph X Y} {s : Set X} (h : e.source ⊆ s) : e.restr s = e := toPartialEquiv_injective <| PartialEquiv.restr_eq_of_source_subset <| interior_maximal h e.open_source #align local_homeomorph.restr_eq_of_source_subset PartialHomeomorph.restr_eq_of_source_subset @[simp, mfld_simps] theorem restr_univ {e : PartialHomeomorph X Y} : e.restr univ = e := restr_eq_of_source_subset (subset_univ _) #align local_homeomorph.restr_univ PartialHomeomorph.restr_univ theorem restr_source_inter (s : Set X) : e.restr (e.source ∩ s) = e.restr s := by refine PartialHomeomorph.ext _ _ (fun x => rfl) (fun x => rfl) ?_ simp [e.open_source.interior_eq, ← inter_assoc] #align local_homeomorph.restr_source_inter PartialHomeomorph.restr_source_inter /-- The identity on the whole space as a partial homeomorphism. -/ @[simps! (config := mfld_cfg) apply, simps! (config := .lemmasOnly) source target] protected def refl (X : Type*) [TopologicalSpace X] : PartialHomeomorph X X := (Homeomorph.refl X).toPartialHomeomorph #align local_homeomorph.refl PartialHomeomorph.refl @[simp, mfld_simps] theorem refl_partialEquiv : (PartialHomeomorph.refl X).toPartialEquiv = PartialEquiv.refl X := rfl #align local_homeomorph.refl_local_equiv PartialHomeomorph.refl_partialEquiv @[simp, mfld_simps] theorem refl_symm : (PartialHomeomorph.refl X).symm = PartialHomeomorph.refl X := rfl #align local_homeomorph.refl_symm PartialHomeomorph.refl_symm /-! ofSet: the identity on a set `s` -/ section ofSet variable {s : Set X} (hs : IsOpen s) /-- The identity partial equivalence on a set `s` -/ @[simps! (config := mfld_cfg) apply, simps! (config := .lemmasOnly) source target] def ofSet (s : Set X) (hs : IsOpen s) : PartialHomeomorph X X where toPartialEquiv := PartialEquiv.ofSet s open_source := hs open_target := hs continuousOn_toFun := continuous_id.continuousOn continuousOn_invFun := continuous_id.continuousOn #align local_homeomorph.of_set PartialHomeomorph.ofSet @[simp, mfld_simps] theorem ofSet_toPartialEquiv : (ofSet s hs).toPartialEquiv = PartialEquiv.ofSet s := rfl #align local_homeomorph.of_set_to_local_equiv PartialHomeomorph.ofSet_toPartialEquiv @[simp, mfld_simps] theorem ofSet_symm : (ofSet s hs).symm = ofSet s hs := rfl #align local_homeomorph.of_set_symm PartialHomeomorph.ofSet_symm @[simp, mfld_simps] theorem ofSet_univ_eq_refl : ofSet univ isOpen_univ = PartialHomeomorph.refl X := by ext <;> simp #align local_homeomorph.of_set_univ_eq_refl PartialHomeomorph.ofSet_univ_eq_refl end ofSet /-! `trans`: composition of two partial homeomorphisms -/ section trans variable (e' : PartialHomeomorph Y Z) /-- Composition of two partial homeomorphisms when the target of the first and the source of the second coincide. -/ @[simps! apply symm_apply toPartialEquiv, simps! (config := .lemmasOnly) source target] protected def trans' (h : e.target = e'.source) : PartialHomeomorph X Z where toPartialEquiv := PartialEquiv.trans' e.toPartialEquiv e'.toPartialEquiv h open_source := e.open_source open_target := e'.open_target continuousOn_toFun := e'.continuousOn.comp e.continuousOn <| h ▸ e.mapsTo continuousOn_invFun := e.continuousOn_symm.comp e'.continuousOn_symm <| h.symm ▸ e'.symm_mapsTo #align local_homeomorph.trans' PartialHomeomorph.trans' /-- Composing two partial homeomorphisms, by restricting to the maximal domain where their composition is well defined. -/ @[trans] protected def trans : PartialHomeomorph X Z := PartialHomeomorph.trans' (e.symm.restrOpen e'.source e'.open_source).symm (e'.restrOpen e.target e.open_target) (by simp [inter_comm]) #align local_homeomorph.trans PartialHomeomorph.trans @[simp, mfld_simps] theorem trans_toPartialEquiv : (e.trans e').toPartialEquiv = e.toPartialEquiv.trans e'.toPartialEquiv := rfl #align local_homeomorph.trans_to_local_equiv PartialHomeomorph.trans_toPartialEquiv @[simp, mfld_simps] theorem coe_trans : (e.trans e' : X → Z) = e' ∘ e := rfl #align local_homeomorph.coe_trans PartialHomeomorph.coe_trans @[simp, mfld_simps] theorem coe_trans_symm : ((e.trans e').symm : Z → X) = e.symm ∘ e'.symm := rfl #align local_homeomorph.coe_trans_symm PartialHomeomorph.coe_trans_symm theorem trans_apply {x : X} : (e.trans e') x = e' (e x) := rfl #align local_homeomorph.trans_apply PartialHomeomorph.trans_apply theorem trans_symm_eq_symm_trans_symm : (e.trans e').symm = e'.symm.trans e.symm := rfl #align local_homeomorph.trans_symm_eq_symm_trans_symm PartialHomeomorph.trans_symm_eq_symm_trans_symm /- This could be considered as a simp lemma, but there are many situations where it makes something simple into something more complicated. -/ theorem trans_source : (e.trans e').source = e.source ∩ e ⁻¹' e'.source := PartialEquiv.trans_source e.toPartialEquiv e'.toPartialEquiv #align local_homeomorph.trans_source PartialHomeomorph.trans_source theorem trans_source' : (e.trans e').source = e.source ∩ e ⁻¹' (e.target ∩ e'.source) := PartialEquiv.trans_source' e.toPartialEquiv e'.toPartialEquiv #align local_homeomorph.trans_source' PartialHomeomorph.trans_source' theorem trans_source'' : (e.trans e').source = e.symm '' (e.target ∩ e'.source) := PartialEquiv.trans_source'' e.toPartialEquiv e'.toPartialEquiv #align local_homeomorph.trans_source'' PartialHomeomorph.trans_source'' theorem image_trans_source : e '' (e.trans e').source = e.target ∩ e'.source := PartialEquiv.image_trans_source e.toPartialEquiv e'.toPartialEquiv #align local_homeomorph.image_trans_source PartialHomeomorph.image_trans_source theorem trans_target : (e.trans e').target = e'.target ∩ e'.symm ⁻¹' e.target := rfl #align local_homeomorph.trans_target PartialHomeomorph.trans_target theorem trans_target' : (e.trans e').target = e'.target ∩ e'.symm ⁻¹' (e'.source ∩ e.target) := trans_source' e'.symm e.symm #align local_homeomorph.trans_target' PartialHomeomorph.trans_target' theorem trans_target'' : (e.trans e').target = e' '' (e'.source ∩ e.target) := trans_source'' e'.symm e.symm #align local_homeomorph.trans_target'' PartialHomeomorph.trans_target'' theorem inv_image_trans_target : e'.symm '' (e.trans e').target = e'.source ∩ e.target := image_trans_source e'.symm e.symm #align local_homeomorph.inv_image_trans_target PartialHomeomorph.inv_image_trans_target theorem trans_assoc (e'' : PartialHomeomorph Z Z') : (e.trans e').trans e'' = e.trans (e'.trans e'') := toPartialEquiv_injective <| e.1.trans_assoc _ _ #align local_homeomorph.trans_assoc PartialHomeomorph.trans_assoc @[simp, mfld_simps] theorem trans_refl : e.trans (PartialHomeomorph.refl Y) = e := toPartialEquiv_injective e.1.trans_refl #align local_homeomorph.trans_refl PartialHomeomorph.trans_refl @[simp, mfld_simps] theorem refl_trans : (PartialHomeomorph.refl X).trans e = e := toPartialEquiv_injective e.1.refl_trans #align local_homeomorph.refl_trans PartialHomeomorph.refl_trans theorem trans_ofSet {s : Set Y} (hs : IsOpen s) : e.trans (ofSet s hs) = e.restr (e ⁻¹' s) := PartialHomeomorph.ext _ _ (fun _ => rfl) (fun _ => rfl) <| by rw [trans_source, restr_source, ofSet_source, ← preimage_interior, hs.interior_eq] #align local_homeomorph.trans_of_set PartialHomeomorph.trans_ofSet theorem trans_of_set' {s : Set Y} (hs : IsOpen s) : e.trans (ofSet s hs) = e.restr (e.source ∩ e ⁻¹' s) := by rw [trans_ofSet, restr_source_inter] #align local_homeomorph.trans_of_set' PartialHomeomorph.trans_of_set' theorem ofSet_trans {s : Set X} (hs : IsOpen s) : (ofSet s hs).trans e = e.restr s := PartialHomeomorph.ext _ _ (fun x => rfl) (fun x => rfl) <| by simp [hs.interior_eq, inter_comm] #align local_homeomorph.of_set_trans PartialHomeomorph.ofSet_trans
Mathlib/Topology/PartialHomeomorph.lean
932
934
theorem ofSet_trans' {s : Set X} (hs : IsOpen s) : (ofSet s hs).trans e = e.restr (e.source ∩ s) := by
rw [ofSet_trans, restr_source_inter]
/- 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, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.NormedSpace.FiniteDimension import Mathlib.MeasureTheory.Constructions.BorelSpace.ContinuousLinearMap import Mathlib.MeasureTheory.Function.StronglyMeasurable.Basic #align_import analysis.calculus.fderiv_measurable from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # Derivative is measurable In this file we prove that the derivative of any function with complete codomain is a measurable function. Namely, we prove: * `measurableSet_of_differentiableAt`: the set `{x | DifferentiableAt 𝕜 f x}` is measurable; * `measurable_fderiv`: the function `fderiv 𝕜 f` is measurable; * `measurable_fderiv_apply_const`: for a fixed vector `y`, the function `fun x ↦ fderiv 𝕜 f x y` is measurable; * `measurable_deriv`: the function `deriv f` is measurable (for `f : 𝕜 → F`). We also show the same results for the right derivative on the real line (see `measurable_derivWithin_Ici` and `measurable_derivWithin_Ioi`), following the same proof strategy. We also prove measurability statements for functions depending on a parameter: for `f : α → E → F`, we show the measurability of `(p : α × E) ↦ fderiv 𝕜 (f p.1) p.2`. This requires additional assumptions. We give versions of the above statements (appending `with_param` to their names) when `f` is continuous and `E` is locally compact. ## Implementation We give a proof that avoids second-countability issues, by expressing the differentiability set as a function of open sets in the following way. Define `A (L, r, ε)` to be the set of points where, on a ball of radius roughly `r` around `x`, the function is uniformly approximated by the linear map `L`, up to `ε r`. It is an open set. Let also `B (L, r, s, ε) = A (L, r, ε) ∩ A (L, s, ε)`: we require that at two possibly different scales `r` and `s`, the function is well approximated by the linear map `L`. It is also open. We claim that the differentiability set of `f` is exactly `D = ⋂ ε > 0, ⋃ δ > 0, ⋂ r, s < δ, ⋃ L, B (L, r, s, ε)`. In other words, for any `ε > 0`, we require that there is a size `δ` such that, for any two scales below this size, the function is well approximated by a linear map, common to the two scales. The set `⋃ L, B (L, r, s, ε)` is open, as a union of open sets. Converting the intersections and unions to countable ones (using real numbers of the form `2 ^ (-n)`), it follows that the differentiability set is measurable. To prove the claim, there are two inclusions. One is trivial: if the function is differentiable at `x`, then `x` belongs to `D` (just take `L` to be the derivative, and use that the differentiability exactly says that the map is well approximated by `L`). This is proved in `mem_A_of_differentiable` and `differentiable_set_subset_D`. For the other direction, the difficulty is that `L` in the union may depend on `ε, r, s`. The key point is that, in fact, it doesn't depend too much on them. First, if `x` belongs both to `A (L, r, ε)` and `A (L', r, ε)`, then `L` and `L'` have to be close on a shell, and thus `‖L - L'‖` is bounded by `ε` (see `norm_sub_le_of_mem_A`). Assume now `x ∈ D`. If one has two maps `L` and `L'` such that `x` belongs to `A (L, r, ε)` and to `A (L', r', ε')`, one deduces that `L` is close to `L'` by arguing as follows. Consider another scale `s` smaller than `r` and `r'`. Take a linear map `L₁` that approximates `f` around `x` both at scales `r` and `s` w.r.t. `ε` (it exists as `x` belongs to `D`). Take also `L₂` that approximates `f` around `x` both at scales `r'` and `s` w.r.t. `ε'`. Then `L₁` is close to `L` (as they are close on a shell of radius `r`), and `L₂` is close to `L₁` (as they are close on a shell of radius `s`), and `L'` is close to `L₂` (as they are close on a shell of radius `r'`). It follows that `L` is close to `L'`, as we claimed. It follows that the different approximating linear maps that show up form a Cauchy sequence when `ε` tends to `0`. When the target space is complete, this sequence converges, to a limit `f'`. With the same kind of arguments, one checks that `f` is differentiable with derivative `f'`. To show that the derivative itself is measurable, add in the definition of `B` and `D` a set `K` of continuous linear maps to which `L` should belong. Then, when `K` is complete, the set `D K` is exactly the set of points where `f` is differentiable with a derivative in `K`. ## Tags derivative, measurable function, Borel σ-algebra -/ set_option linter.uppercaseLean3 false -- A B D noncomputable section open Set Metric Asymptotics Filter ContinuousLinearMap MeasureTheory TopologicalSpace open scoped Topology namespace ContinuousLinearMap variable {𝕜 E F : Type*} [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [NormedSpace 𝕜 F] theorem measurable_apply₂ [MeasurableSpace E] [OpensMeasurableSpace E] [SecondCountableTopologyEither (E →L[𝕜] F) E] [MeasurableSpace F] [BorelSpace F] : Measurable fun p : (E →L[𝕜] F) × E => p.1 p.2 := isBoundedBilinearMap_apply.continuous.measurable #align continuous_linear_map.measurable_apply₂ ContinuousLinearMap.measurable_apply₂ end ContinuousLinearMap section fderiv variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {f : E → F} (K : Set (E →L[𝕜] F)) namespace FDerivMeasurableAux /-- The set `A f L r ε` is the set of points `x` around which the function `f` is well approximated at scale `r` by the linear map `L`, up to an error `ε`. We tweak the definition to make sure that this is an open set. -/ def A (f : E → F) (L : E →L[𝕜] F) (r ε : ℝ) : Set E := { x | ∃ r' ∈ Ioc (r / 2) r, ∀ y ∈ ball x r', ∀ z ∈ ball x r', ‖f z - f y - L (z - y)‖ < ε * r } #align fderiv_measurable_aux.A FDerivMeasurableAux.A /-- The set `B f K r s ε` is the set of points `x` around which there exists a continuous linear map `L` belonging to `K` (a given set of continuous linear maps) that approximates well the function `f` (up to an error `ε`), simultaneously at scales `r` and `s`. -/ def B (f : E → F) (K : Set (E →L[𝕜] F)) (r s ε : ℝ) : Set E := ⋃ L ∈ K, A f L r ε ∩ A f L s ε #align fderiv_measurable_aux.B FDerivMeasurableAux.B /-- The set `D f K` is a complicated set constructed using countable intersections and unions. Its main use is that, when `K` is complete, it is exactly the set of points where `f` is differentiable, with a derivative in `K`. -/ def D (f : E → F) (K : Set (E →L[𝕜] F)) : Set E := ⋂ e : ℕ, ⋃ n : ℕ, ⋂ (p ≥ n) (q ≥ n), B f K ((1 / 2) ^ p) ((1 / 2) ^ q) ((1 / 2) ^ e) #align fderiv_measurable_aux.D FDerivMeasurableAux.D theorem isOpen_A (L : E →L[𝕜] F) (r ε : ℝ) : IsOpen (A f L r ε) := by rw [Metric.isOpen_iff] rintro x ⟨r', r'_mem, hr'⟩ obtain ⟨s, s_gt, s_lt⟩ : ∃ s : ℝ, r / 2 < s ∧ s < r' := exists_between r'_mem.1 have : s ∈ Ioc (r / 2) r := ⟨s_gt, le_of_lt (s_lt.trans_le r'_mem.2)⟩ refine ⟨r' - s, by linarith, fun x' hx' => ⟨s, this, ?_⟩⟩ have B : ball x' s ⊆ ball x r' := ball_subset (le_of_lt hx') intro y hy z hz exact hr' y (B hy) z (B hz) #align fderiv_measurable_aux.is_open_A FDerivMeasurableAux.isOpen_A theorem isOpen_B {K : Set (E →L[𝕜] F)} {r s ε : ℝ} : IsOpen (B f K r s ε) := by simp [B, isOpen_biUnion, IsOpen.inter, isOpen_A] #align fderiv_measurable_aux.is_open_B FDerivMeasurableAux.isOpen_B theorem A_mono (L : E →L[𝕜] F) (r : ℝ) {ε δ : ℝ} (h : ε ≤ δ) : A f L r ε ⊆ A f L r δ := by rintro x ⟨r', r'r, hr'⟩ refine ⟨r', r'r, fun y hy z hz => (hr' y hy z hz).trans_le (mul_le_mul_of_nonneg_right h ?_)⟩ linarith [mem_ball.1 hy, r'r.2, @dist_nonneg _ _ y x] #align fderiv_measurable_aux.A_mono FDerivMeasurableAux.A_mono theorem le_of_mem_A {r ε : ℝ} {L : E →L[𝕜] F} {x : E} (hx : x ∈ A f L r ε) {y z : E} (hy : y ∈ closedBall x (r / 2)) (hz : z ∈ closedBall x (r / 2)) : ‖f z - f y - L (z - y)‖ ≤ ε * r := by rcases hx with ⟨r', r'mem, hr'⟩ apply le_of_lt exact hr' _ ((mem_closedBall.1 hy).trans_lt r'mem.1) _ ((mem_closedBall.1 hz).trans_lt r'mem.1) #align fderiv_measurable_aux.le_of_mem_A FDerivMeasurableAux.le_of_mem_A theorem mem_A_of_differentiable {ε : ℝ} (hε : 0 < ε) {x : E} (hx : DifferentiableAt 𝕜 f x) : ∃ R > 0, ∀ r ∈ Ioo (0 : ℝ) R, x ∈ A f (fderiv 𝕜 f x) r ε := by let δ := (ε / 2) / 2 obtain ⟨R, R_pos, hR⟩ : ∃ R > 0, ∀ y ∈ ball x R, ‖f y - f x - fderiv 𝕜 f x (y - x)‖ ≤ δ * ‖y - x‖ := eventually_nhds_iff_ball.1 <| hx.hasFDerivAt.isLittleO.bound <| by positivity refine ⟨R, R_pos, fun r hr => ?_⟩ have : r ∈ Ioc (r / 2) r := right_mem_Ioc.2 <| half_lt_self hr.1 refine ⟨r, this, fun y hy z hz => ?_⟩ calc ‖f z - f y - (fderiv 𝕜 f x) (z - y)‖ = ‖f z - f x - (fderiv 𝕜 f x) (z - x) - (f y - f x - (fderiv 𝕜 f x) (y - x))‖ := by simp only [map_sub]; abel_nf _ ≤ ‖f z - f x - (fderiv 𝕜 f x) (z - x)‖ + ‖f y - f x - (fderiv 𝕜 f x) (y - x)‖ := norm_sub_le _ _ _ ≤ δ * ‖z - x‖ + δ * ‖y - x‖ := add_le_add (hR _ (ball_subset_ball hr.2.le hz)) (hR _ (ball_subset_ball hr.2.le hy)) _ ≤ δ * r + δ * r := by rw [mem_ball_iff_norm] at hz hy; gcongr _ = (ε / 2) * r := by ring _ < ε * r := by gcongr; exacts [hr.1, half_lt_self hε] #align fderiv_measurable_aux.mem_A_of_differentiable FDerivMeasurableAux.mem_A_of_differentiable theorem norm_sub_le_of_mem_A {c : 𝕜} (hc : 1 < ‖c‖) {r ε : ℝ} (hε : 0 < ε) (hr : 0 < r) {x : E} {L₁ L₂ : E →L[𝕜] F} (h₁ : x ∈ A f L₁ r ε) (h₂ : x ∈ A f L₂ r ε) : ‖L₁ - L₂‖ ≤ 4 * ‖c‖ * ε := by refine opNorm_le_of_shell (half_pos hr) (by positivity) hc ?_ intro y ley ylt rw [div_div, div_le_iff' (mul_pos (by norm_num : (0 : ℝ) < 2) (zero_lt_one.trans hc))] at ley calc ‖(L₁ - L₂) y‖ = ‖f (x + y) - f x - L₂ (x + y - x) - (f (x + y) - f x - L₁ (x + y - x))‖ := by simp _ ≤ ‖f (x + y) - f x - L₂ (x + y - x)‖ + ‖f (x + y) - f x - L₁ (x + y - x)‖ := norm_sub_le _ _ _ ≤ ε * r + ε * r := by apply add_le_add · apply le_of_mem_A h₂ · simp only [le_of_lt (half_pos hr), mem_closedBall, dist_self] · simp only [dist_eq_norm, add_sub_cancel_left, mem_closedBall, ylt.le] · apply le_of_mem_A h₁ · simp only [le_of_lt (half_pos hr), mem_closedBall, dist_self] · simp only [dist_eq_norm, add_sub_cancel_left, mem_closedBall, ylt.le] _ = 2 * ε * r := by ring _ ≤ 2 * ε * (2 * ‖c‖ * ‖y‖) := by gcongr _ = 4 * ‖c‖ * ε * ‖y‖ := by ring #align fderiv_measurable_aux.norm_sub_le_of_mem_A FDerivMeasurableAux.norm_sub_le_of_mem_A /-- Easy inclusion: a differentiability point with derivative in `K` belongs to `D f K`. -/ theorem differentiable_set_subset_D : { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } ⊆ D f K := by intro x hx rw [D, mem_iInter] intro e have : (0 : ℝ) < (1 / 2) ^ e := by positivity rcases mem_A_of_differentiable this hx.1 with ⟨R, R_pos, hR⟩ obtain ⟨n, hn⟩ : ∃ n : ℕ, (1 / 2) ^ n < R := exists_pow_lt_of_lt_one R_pos (by norm_num : (1 : ℝ) / 2 < 1) simp only [mem_iUnion, mem_iInter, B, mem_inter_iff] refine ⟨n, fun p hp q hq => ⟨fderiv 𝕜 f x, hx.2, ⟨?_, ?_⟩⟩⟩ <;> · refine hR _ ⟨pow_pos (by norm_num) _, lt_of_le_of_lt ?_ hn⟩ exact pow_le_pow_of_le_one (by norm_num) (by norm_num) (by assumption) #align fderiv_measurable_aux.differentiable_set_subset_D FDerivMeasurableAux.differentiable_set_subset_D /-- Harder inclusion: at a point in `D f K`, the function `f` has a derivative, in `K`. -/ theorem D_subset_differentiable_set {K : Set (E →L[𝕜] F)} (hK : IsComplete K) : D f K ⊆ { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } := by have P : ∀ {n : ℕ}, (0 : ℝ) < (1 / 2) ^ n := fun {n} => pow_pos (by norm_num) n rcases NormedField.exists_one_lt_norm 𝕜 with ⟨c, hc⟩ intro x hx have : ∀ e : ℕ, ∃ n : ℕ, ∀ p q, n ≤ p → n ≤ q → ∃ L ∈ K, x ∈ A f L ((1 / 2) ^ p) ((1 / 2) ^ e) ∩ A f L ((1 / 2) ^ q) ((1 / 2) ^ e) := by intro e have := mem_iInter.1 hx e rcases mem_iUnion.1 this with ⟨n, hn⟩ refine ⟨n, fun p q hp hq => ?_⟩ simp only [mem_iInter, ge_iff_le] at hn rcases mem_iUnion.1 (hn p hp q hq) with ⟨L, hL⟩ exact ⟨L, exists_prop.mp <| mem_iUnion.1 hL⟩ /- Recast the assumptions: for each `e`, there exist `n e` and linear maps `L e p q` in `K` such that, for `p, q ≥ n e`, then `f` is well approximated by `L e p q` at scale `2 ^ (-p)` and `2 ^ (-q)`, with an error `2 ^ (-e)`. -/ choose! n L hn using this /- All the operators `L e p q` that show up are close to each other. To prove this, we argue that `L e p q` is close to `L e p r` (where `r` is large enough), as both approximate `f` at scale `2 ^(- p)`. And `L e p r` is close to `L e' p' r` as both approximate `f` at scale `2 ^ (- r)`. And `L e' p' r` is close to `L e' p' q'` as both approximate `f` at scale `2 ^ (- p')`. -/ have M : ∀ e p q e' p' q', n e ≤ p → n e ≤ q → n e' ≤ p' → n e' ≤ q' → e ≤ e' → ‖L e p q - L e' p' q'‖ ≤ 12 * ‖c‖ * (1 / 2) ^ e := by intro e p q e' p' q' hp hq hp' hq' he' let r := max (n e) (n e') have I : ((1 : ℝ) / 2) ^ e' ≤ (1 / 2) ^ e := pow_le_pow_of_le_one (by norm_num) (by norm_num) he' have J1 : ‖L e p q - L e p r‖ ≤ 4 * ‖c‖ * (1 / 2) ^ e := by have I1 : x ∈ A f (L e p q) ((1 / 2) ^ p) ((1 / 2) ^ e) := (hn e p q hp hq).2.1 have I2 : x ∈ A f (L e p r) ((1 / 2) ^ p) ((1 / 2) ^ e) := (hn e p r hp (le_max_left _ _)).2.1 exact norm_sub_le_of_mem_A hc P P I1 I2 have J2 : ‖L e p r - L e' p' r‖ ≤ 4 * ‖c‖ * (1 / 2) ^ e := by have I1 : x ∈ A f (L e p r) ((1 / 2) ^ r) ((1 / 2) ^ e) := (hn e p r hp (le_max_left _ _)).2.2 have I2 : x ∈ A f (L e' p' r) ((1 / 2) ^ r) ((1 / 2) ^ e') := (hn e' p' r hp' (le_max_right _ _)).2.2 exact norm_sub_le_of_mem_A hc P P I1 (A_mono _ _ I I2) have J3 : ‖L e' p' r - L e' p' q'‖ ≤ 4 * ‖c‖ * (1 / 2) ^ e := by have I1 : x ∈ A f (L e' p' r) ((1 / 2) ^ p') ((1 / 2) ^ e') := (hn e' p' r hp' (le_max_right _ _)).2.1 have I2 : x ∈ A f (L e' p' q') ((1 / 2) ^ p') ((1 / 2) ^ e') := (hn e' p' q' hp' hq').2.1 exact norm_sub_le_of_mem_A hc P P (A_mono _ _ I I1) (A_mono _ _ I I2) calc ‖L e p q - L e' p' q'‖ = ‖L e p q - L e p r + (L e p r - L e' p' r) + (L e' p' r - L e' p' q')‖ := by congr 1; abel _ ≤ ‖L e p q - L e p r‖ + ‖L e p r - L e' p' r‖ + ‖L e' p' r - L e' p' q'‖ := norm_add₃_le _ _ _ _ ≤ 4 * ‖c‖ * (1 / 2) ^ e + 4 * ‖c‖ * (1 / 2) ^ e + 4 * ‖c‖ * (1 / 2) ^ e := by gcongr _ = 12 * ‖c‖ * (1 / 2) ^ e := by ring /- For definiteness, use `L0 e = L e (n e) (n e)`, to have a single sequence. We claim that this is a Cauchy sequence. -/ let L0 : ℕ → E →L[𝕜] F := fun e => L e (n e) (n e) have : CauchySeq L0 := by rw [Metric.cauchySeq_iff'] intro ε εpos obtain ⟨e, he⟩ : ∃ e : ℕ, (1 / 2) ^ e < ε / (12 * ‖c‖) := exists_pow_lt_of_lt_one (by positivity) (by norm_num) refine ⟨e, fun e' he' => ?_⟩ rw [dist_comm, dist_eq_norm] calc ‖L0 e - L0 e'‖ ≤ 12 * ‖c‖ * (1 / 2) ^ e := M _ _ _ _ _ _ le_rfl le_rfl le_rfl le_rfl he' _ < 12 * ‖c‖ * (ε / (12 * ‖c‖)) := by gcongr _ = ε := by field_simp -- As it is Cauchy, the sequence `L0` converges, to a limit `f'` in `K`. obtain ⟨f', f'K, hf'⟩ : ∃ f' ∈ K, Tendsto L0 atTop (𝓝 f') := cauchySeq_tendsto_of_isComplete hK (fun e => (hn e (n e) (n e) le_rfl le_rfl).1) this have Lf' : ∀ e p, n e ≤ p → ‖L e (n e) p - f'‖ ≤ 12 * ‖c‖ * (1 / 2) ^ e := by intro e p hp apply le_of_tendsto (tendsto_const_nhds.sub hf').norm rw [eventually_atTop] exact ⟨e, fun e' he' => M _ _ _ _ _ _ le_rfl hp le_rfl le_rfl he'⟩ -- Let us show that `f` has derivative `f'` at `x`. have : HasFDerivAt f f' x := by simp only [hasFDerivAt_iff_isLittleO_nhds_zero, isLittleO_iff] /- to get an approximation with a precision `ε`, we will replace `f` with `L e (n e) m` for some large enough `e` (yielding a small error by uniform approximation). As one can vary `m`, this makes it possible to cover all scales, and thus to obtain a good linear approximation in the whole ball of radius `(1/2)^(n e)`. -/ intro ε εpos have pos : 0 < 4 + 12 * ‖c‖ := by positivity obtain ⟨e, he⟩ : ∃ e : ℕ, (1 / 2) ^ e < ε / (4 + 12 * ‖c‖) := exists_pow_lt_of_lt_one (div_pos εpos pos) (by norm_num) rw [eventually_nhds_iff_ball] refine ⟨(1 / 2) ^ (n e + 1), P, fun y hy => ?_⟩ -- We need to show that `f (x + y) - f x - f' y` is small. For this, we will work at scale -- `k` where `k` is chosen with `‖y‖ ∼ 2 ^ (-k)`. by_cases y_pos : y = 0; · simp [y_pos] have yzero : 0 < ‖y‖ := norm_pos_iff.mpr y_pos have y_lt : ‖y‖ < (1 / 2) ^ (n e + 1) := by simpa using mem_ball_iff_norm.1 hy have yone : ‖y‖ ≤ 1 := le_trans y_lt.le (pow_le_one _ (by norm_num) (by norm_num)) -- define the scale `k`. obtain ⟨k, hk, h'k⟩ : ∃ k : ℕ, (1 / 2) ^ (k + 1) < ‖y‖ ∧ ‖y‖ ≤ (1 / 2) ^ k := exists_nat_pow_near_of_lt_one yzero yone (by norm_num : (0 : ℝ) < 1 / 2) (by norm_num : (1 : ℝ) / 2 < 1) -- the scale is large enough (as `y` is small enough) have k_gt : n e < k := by have : ((1 : ℝ) / 2) ^ (k + 1) < (1 / 2) ^ (n e + 1) := lt_trans hk y_lt rw [pow_lt_pow_iff_right_of_lt_one (by norm_num : (0 : ℝ) < 1 / 2) (by norm_num)] at this omega set m := k - 1 have m_ge : n e ≤ m := Nat.le_sub_one_of_lt k_gt have km : k = m + 1 := (Nat.succ_pred_eq_of_pos (lt_of_le_of_lt (zero_le _) k_gt)).symm rw [km] at hk h'k -- `f` is well approximated by `L e (n e) k` at the relevant scale -- (in fact, we use `m = k - 1` instead of `k` because of the precise definition of `A`). have J1 : ‖f (x + y) - f x - L e (n e) m (x + y - x)‖ ≤ (1 / 2) ^ e * (1 / 2) ^ m := by apply le_of_mem_A (hn e (n e) m le_rfl m_ge).2.2 · simp only [mem_closedBall, dist_self] positivity · simpa only [dist_eq_norm, add_sub_cancel_left, mem_closedBall, pow_succ, mul_one_div] using h'k have J2 : ‖f (x + y) - f x - L e (n e) m y‖ ≤ 4 * (1 / 2) ^ e * ‖y‖ := calc ‖f (x + y) - f x - L e (n e) m y‖ ≤ (1 / 2) ^ e * (1 / 2) ^ m := by simpa only [add_sub_cancel_left] using J1 _ = 4 * (1 / 2) ^ e * (1 / 2) ^ (m + 2) := by field_simp; ring _ ≤ 4 * (1 / 2) ^ e * ‖y‖ := by gcongr -- use the previous estimates to see that `f (x + y) - f x - f' y` is small. calc ‖f (x + y) - f x - f' y‖ = ‖f (x + y) - f x - L e (n e) m y + (L e (n e) m - f') y‖ := congr_arg _ (by simp) _ ≤ 4 * (1 / 2) ^ e * ‖y‖ + 12 * ‖c‖ * (1 / 2) ^ e * ‖y‖ := norm_add_le_of_le J2 <| (le_opNorm _ _).trans <| by gcongr; exact Lf' _ _ m_ge _ = (4 + 12 * ‖c‖) * ‖y‖ * (1 / 2) ^ e := by ring _ ≤ (4 + 12 * ‖c‖) * ‖y‖ * (ε / (4 + 12 * ‖c‖)) := by gcongr _ = ε * ‖y‖ := by field_simp [ne_of_gt pos]; ring rw [← this.fderiv] at f'K exact ⟨this.differentiableAt, f'K⟩ #align fderiv_measurable_aux.D_subset_differentiable_set FDerivMeasurableAux.D_subset_differentiable_set theorem differentiable_set_eq_D (hK : IsComplete K) : { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } = D f K := Subset.antisymm (differentiable_set_subset_D _) (D_subset_differentiable_set hK) #align fderiv_measurable_aux.differentiable_set_eq_D FDerivMeasurableAux.differentiable_set_eq_D end FDerivMeasurableAux open FDerivMeasurableAux variable [MeasurableSpace E] [OpensMeasurableSpace E] variable (𝕜 f) /-- The set of differentiability points of a function, with derivative in a given complete set, is Borel-measurable. -/ theorem measurableSet_of_differentiableAt_of_isComplete {K : Set (E →L[𝕜] F)} (hK : IsComplete K) : MeasurableSet { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } := by -- Porting note: was -- simp [differentiable_set_eq_D K hK, D, isOpen_B.measurableSet, MeasurableSet.iInter, -- MeasurableSet.iUnion] simp only [D, differentiable_set_eq_D K hK] repeat apply_rules [MeasurableSet.iUnion, MeasurableSet.iInter] <;> intro exact isOpen_B.measurableSet #align measurable_set_of_differentiable_at_of_is_complete measurableSet_of_differentiableAt_of_isComplete variable [CompleteSpace F] /-- The set of differentiability points of a function taking values in a complete space is Borel-measurable. -/ theorem measurableSet_of_differentiableAt : MeasurableSet { x | DifferentiableAt 𝕜 f x } := by have : IsComplete (univ : Set (E →L[𝕜] F)) := complete_univ convert measurableSet_of_differentiableAt_of_isComplete 𝕜 f this simp #align measurable_set_of_differentiable_at measurableSet_of_differentiableAt @[measurability] theorem measurable_fderiv : Measurable (fderiv 𝕜 f) := by refine measurable_of_isClosed fun s hs => ?_ have : fderiv 𝕜 f ⁻¹' s = { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ s } ∪ { x | ¬DifferentiableAt 𝕜 f x } ∩ { _x | (0 : E →L[𝕜] F) ∈ s } := Set.ext fun x => mem_preimage.trans fderiv_mem_iff rw [this] exact (measurableSet_of_differentiableAt_of_isComplete _ _ hs.isComplete).union ((measurableSet_of_differentiableAt _ _).compl.inter (MeasurableSet.const _)) #align measurable_fderiv measurable_fderiv @[measurability] theorem measurable_fderiv_apply_const [MeasurableSpace F] [BorelSpace F] (y : E) : Measurable fun x => fderiv 𝕜 f x y := (ContinuousLinearMap.measurable_apply y).comp (measurable_fderiv 𝕜 f) #align measurable_fderiv_apply_const measurable_fderiv_apply_const variable {𝕜} @[measurability] theorem measurable_deriv [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [MeasurableSpace F] [BorelSpace F] (f : 𝕜 → F) : Measurable (deriv f) := by simpa only [fderiv_deriv] using measurable_fderiv_apply_const 𝕜 f 1 #align measurable_deriv measurable_deriv theorem stronglyMeasurable_deriv [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [h : SecondCountableTopologyEither 𝕜 F] (f : 𝕜 → F) : StronglyMeasurable (deriv f) := by borelize F rcases h.out with h𝕜|hF · exact stronglyMeasurable_iff_measurable_separable.2 ⟨measurable_deriv f, isSeparable_range_deriv _⟩ · exact (measurable_deriv f).stronglyMeasurable #align strongly_measurable_deriv stronglyMeasurable_deriv theorem aemeasurable_deriv [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [MeasurableSpace F] [BorelSpace F] (f : 𝕜 → F) (μ : Measure 𝕜) : AEMeasurable (deriv f) μ := (measurable_deriv f).aemeasurable #align ae_measurable_deriv aemeasurable_deriv theorem aestronglyMeasurable_deriv [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [SecondCountableTopologyEither 𝕜 F] (f : 𝕜 → F) (μ : Measure 𝕜) : AEStronglyMeasurable (deriv f) μ := (stronglyMeasurable_deriv f).aestronglyMeasurable #align ae_strongly_measurable_deriv aestronglyMeasurable_deriv end fderiv section RightDeriv variable {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] variable {f : ℝ → F} (K : Set F) namespace RightDerivMeasurableAux /-- The set `A f L r ε` is the set of points `x` around which the function `f` is well approximated at scale `r` by the linear map `h ↦ h • L`, up to an error `ε`. We tweak the definition to make sure that this is open on the right. -/ def A (f : ℝ → F) (L : F) (r ε : ℝ) : Set ℝ := { x | ∃ r' ∈ Ioc (r / 2) r, ∀ᵉ (y ∈ Icc x (x + r')) (z ∈ Icc x (x + r')), ‖f z - f y - (z - y) • L‖ ≤ ε * r } #align right_deriv_measurable_aux.A RightDerivMeasurableAux.A /-- The set `B f K r s ε` is the set of points `x` around which there exists a vector `L` belonging to `K` (a given set of vectors) such that `h • L` approximates well `f (x + h)` (up to an error `ε`), simultaneously at scales `r` and `s`. -/ def B (f : ℝ → F) (K : Set F) (r s ε : ℝ) : Set ℝ := ⋃ L ∈ K, A f L r ε ∩ A f L s ε #align right_deriv_measurable_aux.B RightDerivMeasurableAux.B /-- The set `D f K` is a complicated set constructed using countable intersections and unions. Its main use is that, when `K` is complete, it is exactly the set of points where `f` is differentiable, with a derivative in `K`. -/ def D (f : ℝ → F) (K : Set F) : Set ℝ := ⋂ e : ℕ, ⋃ n : ℕ, ⋂ (p ≥ n) (q ≥ n), B f K ((1 / 2) ^ p) ((1 / 2) ^ q) ((1 / 2) ^ e) #align right_deriv_measurable_aux.D RightDerivMeasurableAux.D theorem A_mem_nhdsWithin_Ioi {L : F} {r ε x : ℝ} (hx : x ∈ A f L r ε) : A f L r ε ∈ 𝓝[>] x := by rcases hx with ⟨r', rr', hr'⟩ rw [mem_nhdsWithin_Ioi_iff_exists_Ioo_subset] obtain ⟨s, s_gt, s_lt⟩ : ∃ s : ℝ, r / 2 < s ∧ s < r' := exists_between rr'.1 have : s ∈ Ioc (r / 2) r := ⟨s_gt, le_of_lt (s_lt.trans_le rr'.2)⟩ refine ⟨x + r' - s, by simp only [mem_Ioi]; linarith, fun x' hx' => ⟨s, this, ?_⟩⟩ have A : Icc x' (x' + s) ⊆ Icc x (x + r') := by apply Icc_subset_Icc hx'.1.le linarith [hx'.2] intro y hy z hz exact hr' y (A hy) z (A hz) #align right_deriv_measurable_aux.A_mem_nhds_within_Ioi RightDerivMeasurableAux.A_mem_nhdsWithin_Ioi theorem B_mem_nhdsWithin_Ioi {K : Set F} {r s ε x : ℝ} (hx : x ∈ B f K r s ε) : B f K r s ε ∈ 𝓝[>] x := by obtain ⟨L, LK, hL₁, hL₂⟩ : ∃ L : F, L ∈ K ∧ x ∈ A f L r ε ∧ x ∈ A f L s ε := by simpa only [B, mem_iUnion, mem_inter_iff, exists_prop] using hx filter_upwards [A_mem_nhdsWithin_Ioi hL₁, A_mem_nhdsWithin_Ioi hL₂] with y hy₁ hy₂ simp only [B, mem_iUnion, mem_inter_iff, exists_prop] exact ⟨L, LK, hy₁, hy₂⟩ #align right_deriv_measurable_aux.B_mem_nhds_within_Ioi RightDerivMeasurableAux.B_mem_nhdsWithin_Ioi theorem measurableSet_B {K : Set F} {r s ε : ℝ} : MeasurableSet (B f K r s ε) := measurableSet_of_mem_nhdsWithin_Ioi fun _ hx => B_mem_nhdsWithin_Ioi hx #align right_deriv_measurable_aux.measurable_set_B RightDerivMeasurableAux.measurableSet_B theorem A_mono (L : F) (r : ℝ) {ε δ : ℝ} (h : ε ≤ δ) : A f L r ε ⊆ A f L r δ := by rintro x ⟨r', r'r, hr'⟩ refine ⟨r', r'r, fun y hy z hz => (hr' y hy z hz).trans (mul_le_mul_of_nonneg_right h ?_)⟩ linarith [hy.1, hy.2, r'r.2] #align right_deriv_measurable_aux.A_mono RightDerivMeasurableAux.A_mono theorem le_of_mem_A {r ε : ℝ} {L : F} {x : ℝ} (hx : x ∈ A f L r ε) {y z : ℝ} (hy : y ∈ Icc x (x + r / 2)) (hz : z ∈ Icc x (x + r / 2)) : ‖f z - f y - (z - y) • L‖ ≤ ε * r := by rcases hx with ⟨r', r'mem, hr'⟩ have A : x + r / 2 ≤ x + r' := by linarith [r'mem.1] exact hr' _ ((Icc_subset_Icc le_rfl A) hy) _ ((Icc_subset_Icc le_rfl A) hz) #align right_deriv_measurable_aux.le_of_mem_A RightDerivMeasurableAux.le_of_mem_A theorem mem_A_of_differentiable {ε : ℝ} (hε : 0 < ε) {x : ℝ} (hx : DifferentiableWithinAt ℝ f (Ici x) x) : ∃ R > 0, ∀ r ∈ Ioo (0 : ℝ) R, x ∈ A f (derivWithin f (Ici x) x) r ε := by have := hx.hasDerivWithinAt simp_rw [hasDerivWithinAt_iff_isLittleO, isLittleO_iff] at this rcases mem_nhdsWithin_Ici_iff_exists_Ico_subset.1 (this (half_pos hε)) with ⟨m, xm, hm⟩ refine ⟨m - x, by linarith [show x < m from xm], fun r hr => ?_⟩ have : r ∈ Ioc (r / 2) r := ⟨half_lt_self hr.1, le_rfl⟩ refine ⟨r, this, fun y hy z hz => ?_⟩ calc ‖f z - f y - (z - y) • derivWithin f (Ici x) x‖ = ‖f z - f x - (z - x) • derivWithin f (Ici x) x - (f y - f x - (y - x) • derivWithin f (Ici x) x)‖ := by congr 1; simp only [sub_smul]; abel _ ≤ ‖f z - f x - (z - x) • derivWithin f (Ici x) x‖ + ‖f y - f x - (y - x) • derivWithin f (Ici x) x‖ := (norm_sub_le _ _) _ ≤ ε / 2 * ‖z - x‖ + ε / 2 * ‖y - x‖ := (add_le_add (hm ⟨hz.1, hz.2.trans_lt (by linarith [hr.2])⟩) (hm ⟨hy.1, hy.2.trans_lt (by linarith [hr.2])⟩)) _ ≤ ε / 2 * r + ε / 2 * r := by gcongr · rw [Real.norm_of_nonneg] <;> linarith [hz.1, hz.2] · rw [Real.norm_of_nonneg] <;> linarith [hy.1, hy.2] _ = ε * r := by ring #align right_deriv_measurable_aux.mem_A_of_differentiable RightDerivMeasurableAux.mem_A_of_differentiable theorem norm_sub_le_of_mem_A {r x : ℝ} (hr : 0 < r) (ε : ℝ) {L₁ L₂ : F} (h₁ : x ∈ A f L₁ r ε) (h₂ : x ∈ A f L₂ r ε) : ‖L₁ - L₂‖ ≤ 4 * ε := by suffices H : ‖(r / 2) • (L₁ - L₂)‖ ≤ r / 2 * (4 * ε) by rwa [norm_smul, Real.norm_of_nonneg (half_pos hr).le, mul_le_mul_left (half_pos hr)] at H calc ‖(r / 2) • (L₁ - L₂)‖ = ‖f (x + r / 2) - f x - (x + r / 2 - x) • L₂ - (f (x + r / 2) - f x - (x + r / 2 - x) • L₁)‖ := by simp [smul_sub] _ ≤ ‖f (x + r / 2) - f x - (x + r / 2 - x) • L₂‖ + ‖f (x + r / 2) - f x - (x + r / 2 - x) • L₁‖ := norm_sub_le _ _ _ ≤ ε * r + ε * r := by apply add_le_add · apply le_of_mem_A h₂ <;> simp [(half_pos hr).le] · apply le_of_mem_A h₁ <;> simp [(half_pos hr).le] _ = r / 2 * (4 * ε) := by ring #align right_deriv_measurable_aux.norm_sub_le_of_mem_A RightDerivMeasurableAux.norm_sub_le_of_mem_A /-- Easy inclusion: a differentiability point with derivative in `K` belongs to `D f K`. -/ theorem differentiable_set_subset_D : { x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ K } ⊆ D f K := by intro x hx rw [D, mem_iInter] intro e have : (0 : ℝ) < (1 / 2) ^ e := pow_pos (by norm_num) _ rcases mem_A_of_differentiable this hx.1 with ⟨R, R_pos, hR⟩ obtain ⟨n, hn⟩ : ∃ n : ℕ, (1 / 2) ^ n < R := exists_pow_lt_of_lt_one R_pos (by norm_num : (1 : ℝ) / 2 < 1) simp only [mem_iUnion, mem_iInter, B, mem_inter_iff] refine ⟨n, fun p hp q hq => ⟨derivWithin f (Ici x) x, hx.2, ⟨?_, ?_⟩⟩⟩ <;> · refine hR _ ⟨pow_pos (by norm_num) _, lt_of_le_of_lt ?_ hn⟩ exact pow_le_pow_of_le_one (by norm_num) (by norm_num) (by assumption) #align right_deriv_measurable_aux.differentiable_set_subset_D RightDerivMeasurableAux.differentiable_set_subset_D /-- Harder inclusion: at a point in `D f K`, the function `f` has a derivative, in `K`. -/ theorem D_subset_differentiable_set {K : Set F} (hK : IsComplete K) : D f K ⊆ { x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ K } := by have P : ∀ {n : ℕ}, (0 : ℝ) < (1 / 2) ^ n := fun {n} => pow_pos (by norm_num) n intro x hx have : ∀ e : ℕ, ∃ n : ℕ, ∀ p q, n ≤ p → n ≤ q → ∃ L ∈ K, x ∈ A f L ((1 / 2) ^ p) ((1 / 2) ^ e) ∩ A f L ((1 / 2) ^ q) ((1 / 2) ^ e) := by intro e have := mem_iInter.1 hx e rcases mem_iUnion.1 this with ⟨n, hn⟩ refine ⟨n, fun p q hp hq => ?_⟩ simp only [mem_iInter, ge_iff_le] at hn rcases mem_iUnion.1 (hn p hp q hq) with ⟨L, hL⟩ exact ⟨L, exists_prop.mp <| mem_iUnion.1 hL⟩ /- Recast the assumptions: for each `e`, there exist `n e` and linear maps `L e p q` in `K` such that, for `p, q ≥ n e`, then `f` is well approximated by `L e p q` at scale `2 ^ (-p)` and `2 ^ (-q)`, with an error `2 ^ (-e)`. -/ choose! n L hn using this /- All the operators `L e p q` that show up are close to each other. To prove this, we argue that `L e p q` is close to `L e p r` (where `r` is large enough), as both approximate `f` at scale `2 ^(- p)`. And `L e p r` is close to `L e' p' r` as both approximate `f` at scale `2 ^ (- r)`. And `L e' p' r` is close to `L e' p' q'` as both approximate `f` at scale `2 ^ (- p')`. -/ have M : ∀ e p q e' p' q', n e ≤ p → n e ≤ q → n e' ≤ p' → n e' ≤ q' → e ≤ e' → ‖L e p q - L e' p' q'‖ ≤ 12 * (1 / 2) ^ e := by intro e p q e' p' q' hp hq hp' hq' he' let r := max (n e) (n e') have I : ((1 : ℝ) / 2) ^ e' ≤ (1 / 2) ^ e := pow_le_pow_of_le_one (by norm_num) (by norm_num) he' have J1 : ‖L e p q - L e p r‖ ≤ 4 * (1 / 2) ^ e := by have I1 : x ∈ A f (L e p q) ((1 / 2) ^ p) ((1 / 2) ^ e) := (hn e p q hp hq).2.1 have I2 : x ∈ A f (L e p r) ((1 / 2) ^ p) ((1 / 2) ^ e) := (hn e p r hp (le_max_left _ _)).2.1 exact norm_sub_le_of_mem_A P _ I1 I2 have J2 : ‖L e p r - L e' p' r‖ ≤ 4 * (1 / 2) ^ e := by have I1 : x ∈ A f (L e p r) ((1 / 2) ^ r) ((1 / 2) ^ e) := (hn e p r hp (le_max_left _ _)).2.2 have I2 : x ∈ A f (L e' p' r) ((1 / 2) ^ r) ((1 / 2) ^ e') := (hn e' p' r hp' (le_max_right _ _)).2.2 exact norm_sub_le_of_mem_A P _ I1 (A_mono _ _ I I2) have J3 : ‖L e' p' r - L e' p' q'‖ ≤ 4 * (1 / 2) ^ e := by have I1 : x ∈ A f (L e' p' r) ((1 / 2) ^ p') ((1 / 2) ^ e') := (hn e' p' r hp' (le_max_right _ _)).2.1 have I2 : x ∈ A f (L e' p' q') ((1 / 2) ^ p') ((1 / 2) ^ e') := (hn e' p' q' hp' hq').2.1 exact norm_sub_le_of_mem_A P _ (A_mono _ _ I I1) (A_mono _ _ I I2) calc ‖L e p q - L e' p' q'‖ = ‖L e p q - L e p r + (L e p r - L e' p' r) + (L e' p' r - L e' p' q')‖ := by congr 1; abel _ ≤ ‖L e p q - L e p r‖ + ‖L e p r - L e' p' r‖ + ‖L e' p' r - L e' p' q'‖ := (le_trans (norm_add_le _ _) (add_le_add_right (norm_add_le _ _) _)) _ ≤ 4 * (1 / 2) ^ e + 4 * (1 / 2) ^ e + 4 * (1 / 2) ^ e := by gcongr -- Porting note: proof was `by apply_rules [add_le_add]` _ = 12 * (1 / 2) ^ e := by ring /- For definiteness, use `L0 e = L e (n e) (n e)`, to have a single sequence. We claim that this is a Cauchy sequence. -/ let L0 : ℕ → F := fun e => L e (n e) (n e) have : CauchySeq L0 := by rw [Metric.cauchySeq_iff'] intro ε εpos obtain ⟨e, he⟩ : ∃ e : ℕ, (1 / 2) ^ e < ε / 12 := exists_pow_lt_of_lt_one (div_pos εpos (by norm_num)) (by norm_num) refine ⟨e, fun e' he' => ?_⟩ rw [dist_comm, dist_eq_norm] calc ‖L0 e - L0 e'‖ ≤ 12 * (1 / 2) ^ e := M _ _ _ _ _ _ le_rfl le_rfl le_rfl le_rfl he' _ < 12 * (ε / 12) := mul_lt_mul' le_rfl he (le_of_lt P) (by norm_num) _ = ε := by field_simp [(by norm_num : (12 : ℝ) ≠ 0)] -- As it is Cauchy, the sequence `L0` converges, to a limit `f'` in `K`. obtain ⟨f', f'K, hf'⟩ : ∃ f' ∈ K, Tendsto L0 atTop (𝓝 f') := cauchySeq_tendsto_of_isComplete hK (fun e => (hn e (n e) (n e) le_rfl le_rfl).1) this have Lf' : ∀ e p, n e ≤ p → ‖L e (n e) p - f'‖ ≤ 12 * (1 / 2) ^ e := by intro e p hp apply le_of_tendsto (tendsto_const_nhds.sub hf').norm rw [eventually_atTop] exact ⟨e, fun e' he' => M _ _ _ _ _ _ le_rfl hp le_rfl le_rfl he'⟩ -- Let us show that `f` has right derivative `f'` at `x`. have : HasDerivWithinAt f f' (Ici x) x := by simp only [hasDerivWithinAt_iff_isLittleO, isLittleO_iff] /- to get an approximation with a precision `ε`, we will replace `f` with `L e (n e) m` for some large enough `e` (yielding a small error by uniform approximation). As one can vary `m`, this makes it possible to cover all scales, and thus to obtain a good linear approximation in the whole interval of length `(1/2)^(n e)`. -/ intro ε εpos obtain ⟨e, he⟩ : ∃ e : ℕ, (1 / 2) ^ e < ε / 16 := exists_pow_lt_of_lt_one (div_pos εpos (by norm_num)) (by norm_num) have xmem : x ∈ Ico x (x + (1 / 2) ^ (n e + 1)) := by simp only [one_div, left_mem_Ico, lt_add_iff_pos_right, inv_pos, pow_pos, zero_lt_two, zero_lt_one] filter_upwards [Icc_mem_nhdsWithin_Ici xmem] with y hy -- We need to show that `f y - f x - f' (y - x)` is small. For this, we will work at scale -- `k` where `k` is chosen with `‖y - x‖ ∼ 2 ^ (-k)`. rcases eq_or_lt_of_le hy.1 with (rfl | xy) · simp only [sub_self, zero_smul, norm_zero, mul_zero, le_rfl] have yzero : 0 < y - x := sub_pos.2 xy have y_le : y - x ≤ (1 / 2) ^ (n e + 1) := by linarith [hy.2] have yone : y - x ≤ 1 := le_trans y_le (pow_le_one _ (by norm_num) (by norm_num)) -- define the scale `k`. obtain ⟨k, hk, h'k⟩ : ∃ k : ℕ, (1 / 2) ^ (k + 1) < y - x ∧ y - x ≤ (1 / 2) ^ k := exists_nat_pow_near_of_lt_one yzero yone (by norm_num : (0 : ℝ) < 1 / 2) (by norm_num : (1 : ℝ) / 2 < 1) -- the scale is large enough (as `y - x` is small enough) have k_gt : n e < k := by have : ((1 : ℝ) / 2) ^ (k + 1) < (1 / 2) ^ (n e + 1) := lt_of_lt_of_le hk y_le rw [pow_lt_pow_iff_right_of_lt_one (by norm_num : (0 : ℝ) < 1 / 2) (by norm_num)] at this omega set m := k - 1 have m_ge : n e ≤ m := Nat.le_sub_one_of_lt k_gt have km : k = m + 1 := (Nat.succ_pred_eq_of_pos (lt_of_le_of_lt (zero_le _) k_gt)).symm rw [km] at hk h'k -- `f` is well approximated by `L e (n e) k` at the relevant scale -- (in fact, we use `m = k - 1` instead of `k` because of the precise definition of `A`). have J : ‖f y - f x - (y - x) • L e (n e) m‖ ≤ 4 * (1 / 2) ^ e * ‖y - x‖ := calc ‖f y - f x - (y - x) • L e (n e) m‖ ≤ (1 / 2) ^ e * (1 / 2) ^ m := by apply le_of_mem_A (hn e (n e) m le_rfl m_ge).2.2 · simp only [one_div, inv_pow, left_mem_Icc, le_add_iff_nonneg_right] positivity · simp only [pow_add, tsub_le_iff_left] at h'k simpa only [hy.1, mem_Icc, true_and_iff, one_div, pow_one] using h'k _ = 4 * (1 / 2) ^ e * (1 / 2) ^ (m + 2) := by field_simp; ring _ ≤ 4 * (1 / 2) ^ e * (y - x) := by gcongr _ = 4 * (1 / 2) ^ e * ‖y - x‖ := by rw [Real.norm_of_nonneg yzero.le] calc ‖f y - f x - (y - x) • f'‖ = ‖f y - f x - (y - x) • L e (n e) m + (y - x) • (L e (n e) m - f')‖ := by simp only [smul_sub, sub_add_sub_cancel] _ ≤ 4 * (1 / 2) ^ e * ‖y - x‖ + ‖y - x‖ * (12 * (1 / 2) ^ e) := norm_add_le_of_le J <| by rw [norm_smul]; gcongr; exact Lf' _ _ m_ge _ = 16 * ‖y - x‖ * (1 / 2) ^ e := by ring _ ≤ 16 * ‖y - x‖ * (ε / 16) := by gcongr _ = ε * ‖y - x‖ := by ring rw [← this.derivWithin (uniqueDiffOn_Ici x x Set.left_mem_Ici)] at f'K exact ⟨this.differentiableWithinAt, f'K⟩ #align right_deriv_measurable_aux.D_subset_differentiable_set RightDerivMeasurableAux.D_subset_differentiable_set theorem differentiable_set_eq_D (hK : IsComplete K) : { x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ K } = D f K := Subset.antisymm (differentiable_set_subset_D _) (D_subset_differentiable_set hK) #align right_deriv_measurable_aux.differentiable_set_eq_D RightDerivMeasurableAux.differentiable_set_eq_D end RightDerivMeasurableAux open RightDerivMeasurableAux variable (f) /-- The set of right differentiability points of a function, with derivative in a given complete set, is Borel-measurable. -/ theorem measurableSet_of_differentiableWithinAt_Ici_of_isComplete {K : Set F} (hK : IsComplete K) : MeasurableSet { x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ K } := by -- simp [differentiable_set_eq_d K hK, D, measurableSet_b, MeasurableSet.iInter, -- MeasurableSet.iUnion] simp only [differentiable_set_eq_D K hK, D] repeat apply_rules [MeasurableSet.iUnion, MeasurableSet.iInter] <;> intro exact measurableSet_B #align measurable_set_of_differentiable_within_at_Ici_of_is_complete measurableSet_of_differentiableWithinAt_Ici_of_isComplete variable [CompleteSpace F] /-- The set of right differentiability points of a function taking values in a complete space is Borel-measurable. -/ theorem measurableSet_of_differentiableWithinAt_Ici : MeasurableSet { x | DifferentiableWithinAt ℝ f (Ici x) x } := by have : IsComplete (univ : Set F) := complete_univ convert measurableSet_of_differentiableWithinAt_Ici_of_isComplete f this simp #align measurable_set_of_differentiable_within_at_Ici measurableSet_of_differentiableWithinAt_Ici @[measurability] theorem measurable_derivWithin_Ici [MeasurableSpace F] [BorelSpace F] : Measurable fun x => derivWithin f (Ici x) x := by refine measurable_of_isClosed fun s hs => ?_ have : (fun x => derivWithin f (Ici x) x) ⁻¹' s = { x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ s } ∪ { x | ¬DifferentiableWithinAt ℝ f (Ici x) x } ∩ { _x | (0 : F) ∈ s } := Set.ext fun x => mem_preimage.trans derivWithin_mem_iff rw [this] exact (measurableSet_of_differentiableWithinAt_Ici_of_isComplete _ hs.isComplete).union ((measurableSet_of_differentiableWithinAt_Ici _).compl.inter (MeasurableSet.const _)) #align measurable_deriv_within_Ici measurable_derivWithin_Ici theorem stronglyMeasurable_derivWithin_Ici : StronglyMeasurable (fun x ↦ derivWithin f (Ici x) x) := by borelize F apply stronglyMeasurable_iff_measurable_separable.2 ⟨measurable_derivWithin_Ici f, ?_⟩ obtain ⟨t, t_count, ht⟩ : ∃ t : Set ℝ, t.Countable ∧ Dense t := exists_countable_dense ℝ suffices H : range (fun x ↦ derivWithin f (Ici x) x) ⊆ closure (Submodule.span ℝ (f '' t)) from IsSeparable.mono (t_count.image f).isSeparable.span.closure H rintro - ⟨x, rfl⟩ suffices H' : range (fun y ↦ derivWithin f (Ici x) y) ⊆ closure (Submodule.span ℝ (f '' t)) from H' (mem_range_self _) apply range_derivWithin_subset_closure_span_image calc Ici x = closure (Ioi x ∩ closure t) := by simp [dense_iff_closure_eq.1 ht] _ ⊆ closure (closure (Ioi x ∩ t)) := by apply closure_mono simpa [inter_comm] using (isOpen_Ioi (a := x)).closure_inter (s := t) _ ⊆ closure (Ici x ∩ t) := by rw [closure_closure] exact closure_mono (inter_subset_inter_left _ Ioi_subset_Ici_self) #align strongly_measurable_deriv_within_Ici stronglyMeasurable_derivWithin_Ici theorem aemeasurable_derivWithin_Ici [MeasurableSpace F] [BorelSpace F] (μ : Measure ℝ) : AEMeasurable (fun x => derivWithin f (Ici x) x) μ := (measurable_derivWithin_Ici f).aemeasurable #align ae_measurable_deriv_within_Ici aemeasurable_derivWithin_Ici theorem aestronglyMeasurable_derivWithin_Ici (μ : Measure ℝ) : AEStronglyMeasurable (fun x => derivWithin f (Ici x) x) μ := (stronglyMeasurable_derivWithin_Ici f).aestronglyMeasurable #align ae_strongly_measurable_deriv_within_Ici aestronglyMeasurable_derivWithin_Ici /-- The set of right differentiability points of a function taking values in a complete space is Borel-measurable. -/ theorem measurableSet_of_differentiableWithinAt_Ioi : MeasurableSet { x | DifferentiableWithinAt ℝ f (Ioi x) x } := by simpa [differentiableWithinAt_Ioi_iff_Ici] using measurableSet_of_differentiableWithinAt_Ici f #align measurable_set_of_differentiable_within_at_Ioi measurableSet_of_differentiableWithinAt_Ioi @[measurability] theorem measurable_derivWithin_Ioi [MeasurableSpace F] [BorelSpace F] : Measurable fun x => derivWithin f (Ioi x) x := by simpa [derivWithin_Ioi_eq_Ici] using measurable_derivWithin_Ici f #align measurable_deriv_within_Ioi measurable_derivWithin_Ioi theorem stronglyMeasurable_derivWithin_Ioi : StronglyMeasurable (fun x ↦ derivWithin f (Ioi x) x) := by simpa [derivWithin_Ioi_eq_Ici] using stronglyMeasurable_derivWithin_Ici f #align strongly_measurable_deriv_within_Ioi stronglyMeasurable_derivWithin_Ioi theorem aemeasurable_derivWithin_Ioi [MeasurableSpace F] [BorelSpace F] (μ : Measure ℝ) : AEMeasurable (fun x => derivWithin f (Ioi x) x) μ := (measurable_derivWithin_Ioi f).aemeasurable #align ae_measurable_deriv_within_Ioi aemeasurable_derivWithin_Ioi theorem aestronglyMeasurable_derivWithin_Ioi (μ : Measure ℝ) : AEStronglyMeasurable (fun x => derivWithin f (Ioi x) x) μ := (stronglyMeasurable_derivWithin_Ioi f).aestronglyMeasurable #align ae_strongly_measurable_deriv_within_Ioi aestronglyMeasurable_derivWithin_Ioi end RightDeriv section WithParam /- In this section, we prove the measurability of the derivative in a context with parameters: given `f : α → E → F`, we want to show that `p ↦ fderiv 𝕜 (f p.1) p.2` is measurable. Contrary to the previous sections, some assumptions are needed for this: if `f p.1` depends arbitrarily on `p.1`, this is obviously false. We require that `f` is continuous and `E` is locally compact -- then the proofs in the previous sections adapt readily, as the set `A` defined above is open, so that the differentiability set `D` is measurable. -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [LocallyCompactSpace E] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {α : Type*} [TopologicalSpace α] [MeasurableSpace α] [MeasurableSpace E] [OpensMeasurableSpace α] [OpensMeasurableSpace E] {f : α → E → F} (K : Set (E →L[𝕜] F)) namespace FDerivMeasurableAux open Uniformity lemma isOpen_A_with_param {r s : ℝ} (hf : Continuous f.uncurry) (L : E →L[𝕜] F) : IsOpen {p : α × E | p.2 ∈ A (f p.1) L r s} := by have : ProperSpace E := .of_locallyCompactSpace 𝕜 simp only [A, half_lt_self_iff, not_lt, mem_Ioc, mem_ball, map_sub, mem_setOf_eq] apply isOpen_iff_mem_nhds.2 rintro ⟨a, x⟩ ⟨r', ⟨Irr', Ir'r⟩, hr⟩ have ha : Continuous (f a) := hf.uncurry_left a rcases exists_between Irr' with ⟨t, hrt, htr'⟩ rcases exists_between hrt with ⟨t', hrt', ht't⟩ obtain ⟨b, b_lt, hb⟩ : ∃ b, b < s * r ∧ ∀ y ∈ closedBall x t, ∀ z ∈ closedBall x t, ‖f a z - f a y - (L z - L y)‖ ≤ b := by have B : Continuous (fun (p : E × E) ↦ ‖f a p.2 - f a p.1 - (L p.2 - L p.1)‖) := by -- `continuity` took several seconds to solve this. refine continuous_norm.comp' <| Continuous.sub ?_ ?_ · exact ha.comp' continuous_snd |>.sub <| ha.comp' continuous_fst · exact L.continuous.comp' continuous_snd |>.sub <| L.continuous.comp' continuous_fst have C : (closedBall x t ×ˢ closedBall x t).Nonempty := by simp; linarith rcases ((isCompact_closedBall x t).prod (isCompact_closedBall x t)).exists_isMaxOn C B.continuousOn with ⟨p, pt, hp⟩ simp only [mem_prod, mem_closedBall] at pt refine ⟨‖f a p.2 - f a p.1 - (L p.2 - L p.1)‖, hr p.1 (pt.1.trans_lt htr') p.2 (pt.2.trans_lt htr'), fun y hy z hz ↦ ?_⟩ have D : (y, z) ∈ closedBall x t ×ˢ closedBall x t := mem_prod.2 ⟨hy, hz⟩ exact hp D obtain ⟨ε, εpos, hε⟩ : ∃ ε, 0 < ε ∧ b + 2 * ε < s * r := ⟨(s * r - b) / 3, by linarith, by linarith⟩ obtain ⟨u, u_open, au, hu⟩ : ∃ u, IsOpen u ∧ a ∈ u ∧ ∀ (p : α × E), p.1 ∈ u → p.2 ∈ closedBall x t → dist (f.uncurry p) (f.uncurry (a, p.2)) < ε := by have C : Continuous (fun (p : α × E) ↦ f a p.2) := -- `continuity` took several seconds to solve this. ha.comp' continuous_snd have D : ({a} ×ˢ closedBall x t).EqOn f.uncurry (fun p ↦ f a p.2) := by rintro ⟨b, y⟩ ⟨hb, -⟩ simp only [mem_singleton_iff] at hb simp [hb] obtain ⟨v, v_open, sub_v, hv⟩ : ∃ v, IsOpen v ∧ {a} ×ˢ closedBall x t ⊆ v ∧ ∀ p ∈ v, dist (Function.uncurry f p) (f a p.2) < ε := Uniform.exists_is_open_mem_uniformity_of_forall_mem_eq (s := {a} ×ˢ closedBall x t) (fun p _ ↦ hf.continuousAt) (fun p _ ↦ C.continuousAt) D (dist_mem_uniformity εpos) obtain ⟨w, w', w_open, -, sub_w, sub_w', hww'⟩ : ∃ (w : Set α) (w' : Set E), IsOpen w ∧ IsOpen w' ∧ {a} ⊆ w ∧ closedBall x t ⊆ w' ∧ w ×ˢ w' ⊆ v := generalized_tube_lemma isCompact_singleton (isCompact_closedBall x t) v_open sub_v refine ⟨w, w_open, sub_w rfl, ?_⟩ rintro ⟨b, y⟩ h hby exact hv _ (hww' ⟨h, sub_w' hby⟩) have : u ×ˢ ball x (t - t') ∈ 𝓝 (a, x) := prod_mem_nhds (u_open.mem_nhds au) (ball_mem_nhds _ (sub_pos.2 ht't)) filter_upwards [this] rintro ⟨a', x'⟩ ha'x' simp only [mem_prod, mem_ball] at ha'x' refine ⟨t', ⟨hrt', ht't.le.trans (htr'.le.trans Ir'r)⟩, fun y hy z hz ↦ ?_⟩ have dyx : dist y x ≤ t := by linarith [dist_triangle y x' x] have dzx : dist z x ≤ t := by linarith [dist_triangle z x' x] calc ‖f a' z - f a' y - (L z - L y)‖ = ‖(f a' z - f a z) + (f a y - f a' y) + (f a z - f a y - (L z - L y))‖ := by congr; abel _ ≤ ‖f a' z - f a z‖ + ‖f a y - f a' y‖ + ‖f a z - f a y - (L z - L y)‖ := norm_add₃_le _ _ _ _ ≤ ε + ε + b := by gcongr · rw [← dist_eq_norm] change dist (f.uncurry (a', z)) (f.uncurry (a, z)) ≤ ε apply (hu _ _ _).le · exact ha'x'.1 · simp [dzx] · rw [← dist_eq_norm'] change dist (f.uncurry (a', y)) (f.uncurry (a, y)) ≤ ε apply (hu _ _ _).le · exact ha'x'.1 · simp [dyx] · simp [hb, dyx, dzx] _ < s * r := by linarith lemma isOpen_B_with_param {r s t : ℝ} (hf : Continuous f.uncurry) (K : Set (E →L[𝕜] F)) : IsOpen {p : α × E | p.2 ∈ B (f p.1) K r s t} := by suffices H : IsOpen (⋃ L ∈ K, {p : α × E | p.2 ∈ A (f p.1) L r t ∧ p.2 ∈ A (f p.1) L s t}) by convert H; ext p; simp [B] refine isOpen_biUnion (fun L _ ↦ ?_) exact (isOpen_A_with_param hf L).inter (isOpen_A_with_param hf L) end FDerivMeasurableAux open FDerivMeasurableAux theorem measurableSet_of_differentiableAt_of_isComplete_with_param (hf : Continuous f.uncurry) {K : Set (E →L[𝕜] F)} (hK : IsComplete K) : MeasurableSet {p : α × E | DifferentiableAt 𝕜 (f p.1) p.2 ∧ fderiv 𝕜 (f p.1) p.2 ∈ K} := by have : {p : α × E | DifferentiableAt 𝕜 (f p.1) p.2 ∧ fderiv 𝕜 (f p.1) p.2 ∈ K} = {p : α × E | p.2 ∈ D (f p.1) K} := by simp [← differentiable_set_eq_D K hK] rw [this] simp only [D, mem_iInter, mem_iUnion] simp only [setOf_forall, setOf_exists] refine MeasurableSet.iInter (fun _ ↦ ?_) refine MeasurableSet.iUnion (fun _ ↦ ?_) refine MeasurableSet.iInter (fun _ ↦ ?_) refine MeasurableSet.iInter (fun _ ↦ ?_) refine MeasurableSet.iInter (fun _ ↦ ?_) refine MeasurableSet.iInter (fun _ ↦ ?_) have : ProperSpace E := .of_locallyCompactSpace 𝕜 exact (isOpen_B_with_param hf K).measurableSet variable (𝕜) variable [CompleteSpace F] /-- The set of differentiability points of a continuous function depending on a parameter taking values in a complete space is Borel-measurable. -/ theorem measurableSet_of_differentiableAt_with_param (hf : Continuous f.uncurry) : MeasurableSet {p : α × E | DifferentiableAt 𝕜 (f p.1) p.2} := by have : IsComplete (univ : Set (E →L[𝕜] F)) := complete_univ convert measurableSet_of_differentiableAt_of_isComplete_with_param hf this simp theorem measurable_fderiv_with_param (hf : Continuous f.uncurry) : Measurable (fun (p : α × E) ↦ fderiv 𝕜 (f p.1) p.2) := by refine measurable_of_isClosed (fun s hs ↦ ?_) have : (fun (p : α × E) ↦ fderiv 𝕜 (f p.1) p.2) ⁻¹' s = {p | DifferentiableAt 𝕜 (f p.1) p.2 ∧ fderiv 𝕜 (f p.1) p.2 ∈ s } ∪ { p | ¬DifferentiableAt 𝕜 (f p.1) p.2} ∩ { _p | (0 : E →L[𝕜] F) ∈ s} := Set.ext (fun x ↦ mem_preimage.trans fderiv_mem_iff) rw [this] exact (measurableSet_of_differentiableAt_of_isComplete_with_param hf hs.isComplete).union ((measurableSet_of_differentiableAt_with_param _ hf).compl.inter (MeasurableSet.const _)) theorem measurable_fderiv_apply_const_with_param [MeasurableSpace F] [BorelSpace F] (hf : Continuous f.uncurry) (y : E) : Measurable (fun (p : α × E) ↦ fderiv 𝕜 (f p.1) p.2 y) := (ContinuousLinearMap.measurable_apply y).comp (measurable_fderiv_with_param 𝕜 hf) variable {𝕜} theorem measurable_deriv_with_param [LocallyCompactSpace 𝕜] [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [MeasurableSpace F] [BorelSpace F] {f : α → 𝕜 → F} (hf : Continuous f.uncurry) : Measurable (fun (p : α × 𝕜) ↦ deriv (f p.1) p.2) := by simpa only [fderiv_deriv] using measurable_fderiv_apply_const_with_param 𝕜 hf 1
Mathlib/Analysis/Calculus/FDeriv/Measurable.lean
983
1,002
theorem stronglyMeasurable_deriv_with_param [LocallyCompactSpace 𝕜] [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [h : SecondCountableTopologyEither α F] {f : α → 𝕜 → F} (hf : Continuous f.uncurry) : StronglyMeasurable (fun (p : α × 𝕜) ↦ deriv (f p.1) p.2) := by
borelize F rcases h.out with hα|hF · have : ProperSpace 𝕜 := .of_locallyCompactSpace 𝕜 apply stronglyMeasurable_iff_measurable_separable.2 ⟨measurable_deriv_with_param hf, ?_⟩ have : range (fun (p : α × 𝕜) ↦ deriv (f p.1) p.2) ⊆ closure (Submodule.span 𝕜 (range f.uncurry)) := by rintro - ⟨p, rfl⟩ have A : deriv (f p.1) p.2 ∈ closure (Submodule.span 𝕜 (range (f p.1))) := by rw [← image_univ] apply range_deriv_subset_closure_span_image _ dense_univ (mem_range_self _) have B : range (f p.1) ⊆ range (f.uncurry) := by rintro - ⟨x, rfl⟩ exact mem_range_self (p.1, x) exact closure_mono (Submodule.span_mono B) A exact (isSeparable_range hf).span.closure.mono this · exact (measurable_deriv_with_param hf).stronglyMeasurable
/- 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, Floris van Doorn -/ import Mathlib.Geometry.Manifold.ContMDiff.Basic /-! ## Smoothness of standard maps associated to the product of manifolds This file contains results about smoothness of standard maps associated to products of manifolds - if `f` and `g` are smooth, so is their point-wise product. - the component projections from a product of manifolds are smooth. - functions into a product (*pi type*) are smooth iff their components are -/ open Set Function Filter ChartedSpace SmoothManifoldWithCorners open scoped Topology Manifold variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] -- declare a smooth manifold `M` over the pair `(E, H)`. {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) {M : Type*} [TopologicalSpace M] [ChartedSpace H M] [SmoothManifoldWithCorners I M] -- declare a smooth manifold `M'` over the pair `(E', H')`. {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H'] (I' : ModelWithCorners 𝕜 E' H') {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] [SmoothManifoldWithCorners I' M'] -- declare a manifold `M''` over the pair `(E'', H'')`. {E'' : Type*} [NormedAddCommGroup E''] [NormedSpace 𝕜 E''] {H'' : Type*} [TopologicalSpace H''] {I'' : ModelWithCorners 𝕜 E'' H''} {M'' : Type*} [TopologicalSpace M''] [ChartedSpace H'' M''] -- declare a smooth manifold `N` over the pair `(F, G)`. {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type*} [TopologicalSpace G] {J : ModelWithCorners 𝕜 F G} {N : Type*} [TopologicalSpace N] [ChartedSpace G N] [SmoothManifoldWithCorners J N] -- declare a smooth manifold `N'` over the pair `(F', G')`. {F' : Type*} [NormedAddCommGroup F'] [NormedSpace 𝕜 F'] {G' : Type*} [TopologicalSpace G'] {J' : ModelWithCorners 𝕜 F' G'} {N' : Type*} [TopologicalSpace N'] [ChartedSpace G' N'] [SmoothManifoldWithCorners J' N'] -- F₁, F₂, F₃, F₄ are normed spaces {F₁ : Type*} [NormedAddCommGroup F₁] [NormedSpace 𝕜 F₁] {F₂ : Type*} [NormedAddCommGroup F₂] [NormedSpace 𝕜 F₂] {F₃ : Type*} [NormedAddCommGroup F₃] [NormedSpace 𝕜 F₃] {F₄ : Type*} [NormedAddCommGroup F₄] [NormedSpace 𝕜 F₄] -- declare functions, sets, points and smoothness indices {e : PartialHomeomorph M H} {e' : PartialHomeomorph M' H'} {f f₁ : M → M'} {s s₁ t : Set M} {x : M} {m n : ℕ∞} variable {I I'} section ProdMk theorem ContMDiffWithinAt.prod_mk {f : M → M'} {g : M → N'} (hf : ContMDiffWithinAt I I' n f s x) (hg : ContMDiffWithinAt I J' n g s x) : ContMDiffWithinAt I (I'.prod J') n (fun x => (f x, g x)) s x := by rw [contMDiffWithinAt_iff] at * exact ⟨hf.1.prod hg.1, hf.2.prod hg.2⟩ #align cont_mdiff_within_at.prod_mk ContMDiffWithinAt.prod_mk theorem ContMDiffWithinAt.prod_mk_space {f : M → E'} {g : M → F'} (hf : ContMDiffWithinAt I 𝓘(𝕜, E') n f s x) (hg : ContMDiffWithinAt I 𝓘(𝕜, F') n g s x) : ContMDiffWithinAt I 𝓘(𝕜, E' × F') n (fun x => (f x, g x)) s x := by rw [contMDiffWithinAt_iff] at * exact ⟨hf.1.prod hg.1, hf.2.prod hg.2⟩ #align cont_mdiff_within_at.prod_mk_space ContMDiffWithinAt.prod_mk_space nonrec theorem ContMDiffAt.prod_mk {f : M → M'} {g : M → N'} (hf : ContMDiffAt I I' n f x) (hg : ContMDiffAt I J' n g x) : ContMDiffAt I (I'.prod J') n (fun x => (f x, g x)) x := hf.prod_mk hg #align cont_mdiff_at.prod_mk ContMDiffAt.prod_mk nonrec theorem ContMDiffAt.prod_mk_space {f : M → E'} {g : M → F'} (hf : ContMDiffAt I 𝓘(𝕜, E') n f x) (hg : ContMDiffAt I 𝓘(𝕜, F') n g x) : ContMDiffAt I 𝓘(𝕜, E' × F') n (fun x => (f x, g x)) x := hf.prod_mk_space hg #align cont_mdiff_at.prod_mk_space ContMDiffAt.prod_mk_space theorem ContMDiffOn.prod_mk {f : M → M'} {g : M → N'} (hf : ContMDiffOn I I' n f s) (hg : ContMDiffOn I J' n g s) : ContMDiffOn I (I'.prod J') n (fun x => (f x, g x)) s := fun x hx => (hf x hx).prod_mk (hg x hx) #align cont_mdiff_on.prod_mk ContMDiffOn.prod_mk theorem ContMDiffOn.prod_mk_space {f : M → E'} {g : M → F'} (hf : ContMDiffOn I 𝓘(𝕜, E') n f s) (hg : ContMDiffOn I 𝓘(𝕜, F') n g s) : ContMDiffOn I 𝓘(𝕜, E' × F') n (fun x => (f x, g x)) s := fun x hx => (hf x hx).prod_mk_space (hg x hx) #align cont_mdiff_on.prod_mk_space ContMDiffOn.prod_mk_space nonrec theorem ContMDiff.prod_mk {f : M → M'} {g : M → N'} (hf : ContMDiff I I' n f) (hg : ContMDiff I J' n g) : ContMDiff I (I'.prod J') n fun x => (f x, g x) := fun x => (hf x).prod_mk (hg x) #align cont_mdiff.prod_mk ContMDiff.prod_mk theorem ContMDiff.prod_mk_space {f : M → E'} {g : M → F'} (hf : ContMDiff I 𝓘(𝕜, E') n f) (hg : ContMDiff I 𝓘(𝕜, F') n g) : ContMDiff I 𝓘(𝕜, E' × F') n fun x => (f x, g x) := fun x => (hf x).prod_mk_space (hg x) #align cont_mdiff.prod_mk_space ContMDiff.prod_mk_space nonrec theorem SmoothWithinAt.prod_mk {f : M → M'} {g : M → N'} (hf : SmoothWithinAt I I' f s x) (hg : SmoothWithinAt I J' g s x) : SmoothWithinAt I (I'.prod J') (fun x => (f x, g x)) s x := hf.prod_mk hg #align smooth_within_at.prod_mk SmoothWithinAt.prod_mk nonrec theorem SmoothWithinAt.prod_mk_space {f : M → E'} {g : M → F'} (hf : SmoothWithinAt I 𝓘(𝕜, E') f s x) (hg : SmoothWithinAt I 𝓘(𝕜, F') g s x) : SmoothWithinAt I 𝓘(𝕜, E' × F') (fun x => (f x, g x)) s x := hf.prod_mk_space hg #align smooth_within_at.prod_mk_space SmoothWithinAt.prod_mk_space nonrec theorem SmoothAt.prod_mk {f : M → M'} {g : M → N'} (hf : SmoothAt I I' f x) (hg : SmoothAt I J' g x) : SmoothAt I (I'.prod J') (fun x => (f x, g x)) x := hf.prod_mk hg #align smooth_at.prod_mk SmoothAt.prod_mk nonrec theorem SmoothAt.prod_mk_space {f : M → E'} {g : M → F'} (hf : SmoothAt I 𝓘(𝕜, E') f x) (hg : SmoothAt I 𝓘(𝕜, F') g x) : SmoothAt I 𝓘(𝕜, E' × F') (fun x => (f x, g x)) x := hf.prod_mk_space hg #align smooth_at.prod_mk_space SmoothAt.prod_mk_space nonrec theorem SmoothOn.prod_mk {f : M → M'} {g : M → N'} (hf : SmoothOn I I' f s) (hg : SmoothOn I J' g s) : SmoothOn I (I'.prod J') (fun x => (f x, g x)) s := hf.prod_mk hg #align smooth_on.prod_mk SmoothOn.prod_mk nonrec theorem SmoothOn.prod_mk_space {f : M → E'} {g : M → F'} (hf : SmoothOn I 𝓘(𝕜, E') f s) (hg : SmoothOn I 𝓘(𝕜, F') g s) : SmoothOn I 𝓘(𝕜, E' × F') (fun x => (f x, g x)) s := hf.prod_mk_space hg #align smooth_on.prod_mk_space SmoothOn.prod_mk_space nonrec theorem Smooth.prod_mk {f : M → M'} {g : M → N'} (hf : Smooth I I' f) (hg : Smooth I J' g) : Smooth I (I'.prod J') fun x => (f x, g x) := hf.prod_mk hg #align smooth.prod_mk Smooth.prod_mk nonrec theorem Smooth.prod_mk_space {f : M → E'} {g : M → F'} (hf : Smooth I 𝓘(𝕜, E') f) (hg : Smooth I 𝓘(𝕜, F') g) : Smooth I 𝓘(𝕜, E' × F') fun x => (f x, g x) := hf.prod_mk_space hg #align smooth.prod_mk_space Smooth.prod_mk_space end ProdMk section Projections theorem contMDiffWithinAt_fst {s : Set (M × N)} {p : M × N} : ContMDiffWithinAt (I.prod J) I n Prod.fst s p := by /- porting note: `simp` fails to apply lemmas to `ModelProd`. Was rw [contMDiffWithinAt_iff'] refine' ⟨continuousWithinAt_fst, _⟩ refine' contDiffWithinAt_fst.congr (fun y hy => _) _ · simp only [mfld_simps] at hy simp only [hy, mfld_simps] · simp only [mfld_simps] -/ rw [contMDiffWithinAt_iff'] refine ⟨continuousWithinAt_fst, contDiffWithinAt_fst.congr (fun y hy => ?_) ?_⟩ · exact (extChartAt I p.1).right_inv ⟨hy.1.1.1, hy.1.2.1⟩ · exact (extChartAt I p.1).right_inv <| (extChartAt I p.1).map_source (mem_extChartAt_source _ _) #align cont_mdiff_within_at_fst contMDiffWithinAt_fst theorem ContMDiffWithinAt.fst {f : N → M × M'} {s : Set N} {x : N} (hf : ContMDiffWithinAt J (I.prod I') n f s x) : ContMDiffWithinAt J I n (fun x => (f x).1) s x := contMDiffWithinAt_fst.comp x hf (mapsTo_image f s) #align cont_mdiff_within_at.fst ContMDiffWithinAt.fst theorem contMDiffAt_fst {p : M × N} : ContMDiffAt (I.prod J) I n Prod.fst p := contMDiffWithinAt_fst #align cont_mdiff_at_fst contMDiffAt_fst theorem contMDiffOn_fst {s : Set (M × N)} : ContMDiffOn (I.prod J) I n Prod.fst s := fun _ _ => contMDiffWithinAt_fst #align cont_mdiff_on_fst contMDiffOn_fst theorem contMDiff_fst : ContMDiff (I.prod J) I n (@Prod.fst M N) := fun _ => contMDiffAt_fst #align cont_mdiff_fst contMDiff_fst theorem smoothWithinAt_fst {s : Set (M × N)} {p : M × N} : SmoothWithinAt (I.prod J) I Prod.fst s p := contMDiffWithinAt_fst #align smooth_within_at_fst smoothWithinAt_fst theorem smoothAt_fst {p : M × N} : SmoothAt (I.prod J) I Prod.fst p := contMDiffAt_fst #align smooth_at_fst smoothAt_fst theorem smoothOn_fst {s : Set (M × N)} : SmoothOn (I.prod J) I Prod.fst s := contMDiffOn_fst #align smooth_on_fst smoothOn_fst theorem smooth_fst : Smooth (I.prod J) I (@Prod.fst M N) := contMDiff_fst #align smooth_fst smooth_fst theorem ContMDiffAt.fst {f : N → M × M'} {x : N} (hf : ContMDiffAt J (I.prod I') n f x) : ContMDiffAt J I n (fun x => (f x).1) x := contMDiffAt_fst.comp x hf #align cont_mdiff_at.fst ContMDiffAt.fst theorem ContMDiff.fst {f : N → M × M'} (hf : ContMDiff J (I.prod I') n f) : ContMDiff J I n fun x => (f x).1 := contMDiff_fst.comp hf #align cont_mdiff.fst ContMDiff.fst theorem SmoothAt.fst {f : N → M × M'} {x : N} (hf : SmoothAt J (I.prod I') f x) : SmoothAt J I (fun x => (f x).1) x := smoothAt_fst.comp x hf #align smooth_at.fst SmoothAt.fst theorem Smooth.fst {f : N → M × M'} (hf : Smooth J (I.prod I') f) : Smooth J I fun x => (f x).1 := smooth_fst.comp hf #align smooth.fst Smooth.fst theorem contMDiffWithinAt_snd {s : Set (M × N)} {p : M × N} : ContMDiffWithinAt (I.prod J) J n Prod.snd s p := by /- porting note: `simp` fails to apply lemmas to `ModelProd`. Was rw [contMDiffWithinAt_iff'] refine' ⟨continuousWithinAt_snd, _⟩ refine' contDiffWithinAt_snd.congr (fun y hy => _) _ · simp only [mfld_simps] at hy simp only [hy, mfld_simps] · simp only [mfld_simps] -/ rw [contMDiffWithinAt_iff'] refine ⟨continuousWithinAt_snd, contDiffWithinAt_snd.congr (fun y hy => ?_) ?_⟩ · exact (extChartAt J p.2).right_inv ⟨hy.1.1.2, hy.1.2.2⟩ · exact (extChartAt J p.2).right_inv <| (extChartAt J p.2).map_source (mem_extChartAt_source _ _) #align cont_mdiff_within_at_snd contMDiffWithinAt_snd theorem ContMDiffWithinAt.snd {f : N → M × M'} {s : Set N} {x : N} (hf : ContMDiffWithinAt J (I.prod I') n f s x) : ContMDiffWithinAt J I' n (fun x => (f x).2) s x := contMDiffWithinAt_snd.comp x hf (mapsTo_image f s) #align cont_mdiff_within_at.snd ContMDiffWithinAt.snd theorem contMDiffAt_snd {p : M × N} : ContMDiffAt (I.prod J) J n Prod.snd p := contMDiffWithinAt_snd #align cont_mdiff_at_snd contMDiffAt_snd theorem contMDiffOn_snd {s : Set (M × N)} : ContMDiffOn (I.prod J) J n Prod.snd s := fun _ _ => contMDiffWithinAt_snd #align cont_mdiff_on_snd contMDiffOn_snd theorem contMDiff_snd : ContMDiff (I.prod J) J n (@Prod.snd M N) := fun _ => contMDiffAt_snd #align cont_mdiff_snd contMDiff_snd theorem smoothWithinAt_snd {s : Set (M × N)} {p : M × N} : SmoothWithinAt (I.prod J) J Prod.snd s p := contMDiffWithinAt_snd #align smooth_within_at_snd smoothWithinAt_snd theorem smoothAt_snd {p : M × N} : SmoothAt (I.prod J) J Prod.snd p := contMDiffAt_snd #align smooth_at_snd smoothAt_snd theorem smoothOn_snd {s : Set (M × N)} : SmoothOn (I.prod J) J Prod.snd s := contMDiffOn_snd #align smooth_on_snd smoothOn_snd theorem smooth_snd : Smooth (I.prod J) J (@Prod.snd M N) := contMDiff_snd #align smooth_snd smooth_snd theorem ContMDiffAt.snd {f : N → M × M'} {x : N} (hf : ContMDiffAt J (I.prod I') n f x) : ContMDiffAt J I' n (fun x => (f x).2) x := contMDiffAt_snd.comp x hf #align cont_mdiff_at.snd ContMDiffAt.snd theorem ContMDiff.snd {f : N → M × M'} (hf : ContMDiff J (I.prod I') n f) : ContMDiff J I' n fun x => (f x).2 := contMDiff_snd.comp hf #align cont_mdiff.snd ContMDiff.snd theorem SmoothAt.snd {f : N → M × M'} {x : N} (hf : SmoothAt J (I.prod I') f x) : SmoothAt J I' (fun x => (f x).2) x := smoothAt_snd.comp x hf #align smooth_at.snd SmoothAt.snd theorem Smooth.snd {f : N → M × M'} (hf : Smooth J (I.prod I') f) : Smooth J I' fun x => (f x).2 := smooth_snd.comp hf #align smooth.snd Smooth.snd end Projections theorem contMDiffWithinAt_prod_iff (f : M → M' × N') {s : Set M} {x : M} : ContMDiffWithinAt I (I'.prod J') n f s x ↔ ContMDiffWithinAt I I' n (Prod.fst ∘ f) s x ∧ ContMDiffWithinAt I J' n (Prod.snd ∘ f) s x := ⟨fun h => ⟨h.fst, h.snd⟩, fun h => h.1.prod_mk h.2⟩ #align cont_mdiff_within_at_prod_iff contMDiffWithinAt_prod_iff theorem contMDiffAt_prod_iff (f : M → M' × N') {x : M} : ContMDiffAt I (I'.prod J') n f x ↔ ContMDiffAt I I' n (Prod.fst ∘ f) x ∧ ContMDiffAt I J' n (Prod.snd ∘ f) x := by simp_rw [← contMDiffWithinAt_univ]; exact contMDiffWithinAt_prod_iff f #align cont_mdiff_at_prod_iff contMDiffAt_prod_iff theorem contMDiff_prod_iff (f : M → M' × N') : ContMDiff I (I'.prod J') n f ↔ ContMDiff I I' n (Prod.fst ∘ f) ∧ ContMDiff I J' n (Prod.snd ∘ f) := ⟨fun h => ⟨h.fst, h.snd⟩, fun h => by convert h.1.prod_mk h.2⟩ #align cont_mdiff_prod_iff contMDiff_prod_iff theorem smoothAt_prod_iff (f : M → M' × N') {x : M} : SmoothAt I (I'.prod J') f x ↔ SmoothAt I I' (Prod.fst ∘ f) x ∧ SmoothAt I J' (Prod.snd ∘ f) x := contMDiffAt_prod_iff f #align smooth_at_prod_iff smoothAt_prod_iff theorem smooth_prod_iff (f : M → M' × N') : Smooth I (I'.prod J') f ↔ Smooth I I' (Prod.fst ∘ f) ∧ Smooth I J' (Prod.snd ∘ f) := contMDiff_prod_iff f #align smooth_prod_iff smooth_prod_iff theorem smooth_prod_assoc : Smooth ((I.prod I').prod J) (I.prod (I'.prod J)) fun x : (M × M') × N => (x.1.1, x.1.2, x.2) := smooth_fst.fst.prod_mk <| smooth_fst.snd.prod_mk smooth_snd #align smooth_prod_assoc smooth_prod_assoc section prodMap variable {g : N → N'} {r : Set N} {y : N} /-- The product map of two `C^n` functions within a set at a point is `C^n` within the product set at the product point. -/ theorem ContMDiffWithinAt.prod_map' {p : M × N} (hf : ContMDiffWithinAt I I' n f s p.1) (hg : ContMDiffWithinAt J J' n g r p.2) : ContMDiffWithinAt (I.prod J) (I'.prod J') n (Prod.map f g) (s ×ˢ r) p := (hf.comp p contMDiffWithinAt_fst (prod_subset_preimage_fst _ _)).prod_mk <| hg.comp p contMDiffWithinAt_snd (prod_subset_preimage_snd _ _) #align cont_mdiff_within_at.prod_map' ContMDiffWithinAt.prod_map' theorem ContMDiffWithinAt.prod_map (hf : ContMDiffWithinAt I I' n f s x) (hg : ContMDiffWithinAt J J' n g r y) : ContMDiffWithinAt (I.prod J) (I'.prod J') n (Prod.map f g) (s ×ˢ r) (x, y) := ContMDiffWithinAt.prod_map' hf hg #align cont_mdiff_within_at.prod_map ContMDiffWithinAt.prod_map theorem ContMDiffAt.prod_map (hf : ContMDiffAt I I' n f x) (hg : ContMDiffAt J J' n g y) : ContMDiffAt (I.prod J) (I'.prod J') n (Prod.map f g) (x, y) := by rw [← contMDiffWithinAt_univ] at * convert hf.prod_map hg exact univ_prod_univ.symm #align cont_mdiff_at.prod_map ContMDiffAt.prod_map theorem ContMDiffAt.prod_map' {p : M × N} (hf : ContMDiffAt I I' n f p.1) (hg : ContMDiffAt J J' n g p.2) : ContMDiffAt (I.prod J) (I'.prod J') n (Prod.map f g) p := by rcases p with ⟨⟩ exact hf.prod_map hg #align cont_mdiff_at.prod_map' ContMDiffAt.prod_map' theorem ContMDiffOn.prod_map (hf : ContMDiffOn I I' n f s) (hg : ContMDiffOn J J' n g r) : ContMDiffOn (I.prod J) (I'.prod J') n (Prod.map f g) (s ×ˢ r) := (hf.comp contMDiffOn_fst (prod_subset_preimage_fst _ _)).prod_mk <| hg.comp contMDiffOn_snd (prod_subset_preimage_snd _ _) #align cont_mdiff_on.prod_map ContMDiffOn.prod_map
Mathlib/Geometry/Manifold/ContMDiff/Product.lean
360
363
theorem ContMDiff.prod_map (hf : ContMDiff I I' n f) (hg : ContMDiff J J' n g) : ContMDiff (I.prod J) (I'.prod J') n (Prod.map f g) := by
intro p exact (hf p.1).prod_map' (hg p.2)
/- Copyright (c) 2020 Fox Thomson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Fox Thomson, Markus Himmel -/ import Mathlib.Data.Nat.Bitwise import Mathlib.SetTheory.Game.Birthday import Mathlib.SetTheory.Game.Impartial #align_import set_theory.game.nim from "leanprover-community/mathlib"@"92ca63f0fb391a9ca5f22d2409a6080e786d99f7" /-! # Nim and the Sprague-Grundy theorem This file contains the definition for nim for any ordinal `o`. In the game of `nim o₁` both players may move to `nim o₂` for any `o₂ < o₁`. We also define a Grundy value for an impartial game `G` and prove the Sprague-Grundy theorem, that `G` is equivalent to `nim (grundyValue G)`. Finally, we compute the sum of finite Grundy numbers: if `G` and `H` have Grundy values `n` and `m`, where `n` and `m` are natural numbers, then `G + H` has the Grundy value `n xor m`. ## Implementation details The pen-and-paper definition of nim defines the possible moves of `nim o` to be `Set.Iio o`. However, this definition does not work for us because it would make the type of nim `Ordinal.{u} → SetTheory.PGame.{u + 1}`, which would make it impossible for us to state the Sprague-Grundy theorem, since that requires the type of `nim` to be `Ordinal.{u} → SetTheory.PGame.{u}`. For this reason, we instead use `o.out.α` for the possible moves. You can use `to_left_moves_nim` and `to_right_moves_nim` to convert an ordinal less than `o` into a left or right move of `nim o`, and vice versa. -/ noncomputable section universe u namespace SetTheory open scoped PGame namespace PGame -- Uses `noncomputable!` to avoid `rec_fn_macro only allowed in meta definitions` VM error /-- The definition of single-heap nim, which can be viewed as a pile of stones where each player can take a positive number of stones from it on their turn. -/ noncomputable def nim : Ordinal.{u} → PGame.{u} | o₁ => let f o₂ := have _ : Ordinal.typein o₁.out.r o₂ < o₁ := Ordinal.typein_lt_self o₂ nim (Ordinal.typein o₁.out.r o₂) ⟨o₁.out.α, o₁.out.α, f, f⟩ termination_by o => o #align pgame.nim SetTheory.PGame.nim open Ordinal theorem nim_def (o : Ordinal) : have : IsWellOrder (Quotient.out o).α (· < ·) := inferInstance nim o = PGame.mk o.out.α o.out.α (fun o₂ => nim (Ordinal.typein (· < ·) o₂)) fun o₂ => nim (Ordinal.typein (· < ·) o₂) := by rw [nim]; rfl #align pgame.nim_def SetTheory.PGame.nim_def theorem leftMoves_nim (o : Ordinal) : (nim o).LeftMoves = o.out.α := by rw [nim_def]; rfl #align pgame.left_moves_nim SetTheory.PGame.leftMoves_nim theorem rightMoves_nim (o : Ordinal) : (nim o).RightMoves = o.out.α := by rw [nim_def]; rfl #align pgame.right_moves_nim SetTheory.PGame.rightMoves_nim theorem moveLeft_nim_hEq (o : Ordinal) : have : IsWellOrder (Quotient.out o).α (· < ·) := inferInstance HEq (nim o).moveLeft fun i : o.out.α => nim (typein (· < ·) i) := by rw [nim_def]; rfl #align pgame.move_left_nim_heq SetTheory.PGame.moveLeft_nim_hEq theorem moveRight_nim_hEq (o : Ordinal) : have : IsWellOrder (Quotient.out o).α (· < ·) := inferInstance HEq (nim o).moveRight fun i : o.out.α => nim (typein (· < ·) i) := by rw [nim_def]; rfl #align pgame.move_right_nim_heq SetTheory.PGame.moveRight_nim_hEq /-- Turns an ordinal less than `o` into a left move for `nim o` and viceversa. -/ noncomputable def toLeftMovesNim {o : Ordinal} : Set.Iio o ≃ (nim o).LeftMoves := (enumIsoOut o).toEquiv.trans (Equiv.cast (leftMoves_nim o).symm) #align pgame.to_left_moves_nim SetTheory.PGame.toLeftMovesNim /-- Turns an ordinal less than `o` into a right move for `nim o` and viceversa. -/ noncomputable def toRightMovesNim {o : Ordinal} : Set.Iio o ≃ (nim o).RightMoves := (enumIsoOut o).toEquiv.trans (Equiv.cast (rightMoves_nim o).symm) #align pgame.to_right_moves_nim SetTheory.PGame.toRightMovesNim @[simp] theorem toLeftMovesNim_symm_lt {o : Ordinal} (i : (nim o).LeftMoves) : ↑(toLeftMovesNim.symm i) < o := (toLeftMovesNim.symm i).prop #align pgame.to_left_moves_nim_symm_lt SetTheory.PGame.toLeftMovesNim_symm_lt @[simp] theorem toRightMovesNim_symm_lt {o : Ordinal} (i : (nim o).RightMoves) : ↑(toRightMovesNim.symm i) < o := (toRightMovesNim.symm i).prop #align pgame.to_right_moves_nim_symm_lt SetTheory.PGame.toRightMovesNim_symm_lt @[simp] theorem moveLeft_nim' {o : Ordinal.{u}} (i) : (nim o).moveLeft i = nim (toLeftMovesNim.symm i).val := (congr_heq (moveLeft_nim_hEq o).symm (cast_heq _ i)).symm #align pgame.move_left_nim' SetTheory.PGame.moveLeft_nim' theorem moveLeft_nim {o : Ordinal} (i) : (nim o).moveLeft (toLeftMovesNim i) = nim i := by simp #align pgame.move_left_nim SetTheory.PGame.moveLeft_nim @[simp] theorem moveRight_nim' {o : Ordinal} (i) : (nim o).moveRight i = nim (toRightMovesNim.symm i).val := (congr_heq (moveRight_nim_hEq o).symm (cast_heq _ i)).symm #align pgame.move_right_nim' SetTheory.PGame.moveRight_nim' theorem moveRight_nim {o : Ordinal} (i) : (nim o).moveRight (toRightMovesNim i) = nim i := by simp #align pgame.move_right_nim SetTheory.PGame.moveRight_nim /-- A recursion principle for left moves of a nim game. -/ @[elab_as_elim] def leftMovesNimRecOn {o : Ordinal} {P : (nim o).LeftMoves → Sort*} (i : (nim o).LeftMoves) (H : ∀ a (H : a < o), P <| toLeftMovesNim ⟨a, H⟩) : P i := by rw [← toLeftMovesNim.apply_symm_apply i]; apply H #align pgame.left_moves_nim_rec_on SetTheory.PGame.leftMovesNimRecOn /-- A recursion principle for right moves of a nim game. -/ @[elab_as_elim] def rightMovesNimRecOn {o : Ordinal} {P : (nim o).RightMoves → Sort*} (i : (nim o).RightMoves) (H : ∀ a (H : a < o), P <| toRightMovesNim ⟨a, H⟩) : P i := by rw [← toRightMovesNim.apply_symm_apply i]; apply H #align pgame.right_moves_nim_rec_on SetTheory.PGame.rightMovesNimRecOn instance isEmpty_nim_zero_leftMoves : IsEmpty (nim 0).LeftMoves := by rw [nim_def] exact Ordinal.isEmpty_out_zero #align pgame.is_empty_nim_zero_left_moves SetTheory.PGame.isEmpty_nim_zero_leftMoves instance isEmpty_nim_zero_rightMoves : IsEmpty (nim 0).RightMoves := by rw [nim_def] exact Ordinal.isEmpty_out_zero #align pgame.is_empty_nim_zero_right_moves SetTheory.PGame.isEmpty_nim_zero_rightMoves /-- `nim 0` has exactly the same moves as `0`. -/ def nimZeroRelabelling : nim 0 ≡r 0 := Relabelling.isEmpty _ #align pgame.nim_zero_relabelling SetTheory.PGame.nimZeroRelabelling theorem nim_zero_equiv : nim 0 ≈ 0 := Equiv.isEmpty _ #align pgame.nim_zero_equiv SetTheory.PGame.nim_zero_equiv noncomputable instance uniqueNimOneLeftMoves : Unique (nim 1).LeftMoves := (Equiv.cast <| leftMoves_nim 1).unique #align pgame.unique_nim_one_left_moves SetTheory.PGame.uniqueNimOneLeftMoves noncomputable instance uniqueNimOneRightMoves : Unique (nim 1).RightMoves := (Equiv.cast <| rightMoves_nim 1).unique #align pgame.unique_nim_one_right_moves SetTheory.PGame.uniqueNimOneRightMoves @[simp] theorem default_nim_one_leftMoves_eq : (default : (nim 1).LeftMoves) = @toLeftMovesNim 1 ⟨0, Set.mem_Iio.mpr zero_lt_one⟩ := rfl #align pgame.default_nim_one_left_moves_eq SetTheory.PGame.default_nim_one_leftMoves_eq @[simp] theorem default_nim_one_rightMoves_eq : (default : (nim 1).RightMoves) = @toRightMovesNim 1 ⟨0, Set.mem_Iio.mpr zero_lt_one⟩ := rfl #align pgame.default_nim_one_right_moves_eq SetTheory.PGame.default_nim_one_rightMoves_eq @[simp] theorem toLeftMovesNim_one_symm (i) : (@toLeftMovesNim 1).symm i = ⟨0, Set.mem_Iio.mpr zero_lt_one⟩ := by simp [eq_iff_true_of_subsingleton] #align pgame.to_left_moves_nim_one_symm SetTheory.PGame.toLeftMovesNim_one_symm @[simp] theorem toRightMovesNim_one_symm (i) : (@toRightMovesNim 1).symm i = ⟨0, Set.mem_Iio.mpr zero_lt_one⟩ := by simp [eq_iff_true_of_subsingleton] #align pgame.to_right_moves_nim_one_symm SetTheory.PGame.toRightMovesNim_one_symm theorem nim_one_moveLeft (x) : (nim 1).moveLeft x = nim 0 := by simp #align pgame.nim_one_move_left SetTheory.PGame.nim_one_moveLeft theorem nim_one_moveRight (x) : (nim 1).moveRight x = nim 0 := by simp #align pgame.nim_one_move_right SetTheory.PGame.nim_one_moveRight /-- `nim 1` has exactly the same moves as `star`. -/ def nimOneRelabelling : nim 1 ≡r star := by rw [nim_def] refine ⟨?_, ?_, fun i => ?_, fun j => ?_⟩ any_goals dsimp; apply Equiv.equivOfUnique all_goals simp; exact nimZeroRelabelling #align pgame.nim_one_relabelling SetTheory.PGame.nimOneRelabelling theorem nim_one_equiv : nim 1 ≈ star := nimOneRelabelling.equiv #align pgame.nim_one_equiv SetTheory.PGame.nim_one_equiv @[simp] theorem nim_birthday (o : Ordinal) : (nim o).birthday = o := by induction' o using Ordinal.induction with o IH rw [nim_def, birthday_def] dsimp rw [max_eq_right le_rfl] convert lsub_typein o with i exact IH _ (typein_lt_self i) #align pgame.nim_birthday SetTheory.PGame.nim_birthday @[simp] theorem neg_nim (o : Ordinal) : -nim o = nim o := by induction' o using Ordinal.induction with o IH rw [nim_def]; dsimp; congr <;> funext i <;> exact IH _ (Ordinal.typein_lt_self i) #align pgame.neg_nim SetTheory.PGame.neg_nim instance nim_impartial (o : Ordinal) : Impartial (nim o) := by induction' o using Ordinal.induction with o IH rw [impartial_def, neg_nim] refine ⟨equiv_rfl, fun i => ?_, fun i => ?_⟩ <;> simpa using IH _ (typein_lt_self _) #align pgame.nim_impartial SetTheory.PGame.nim_impartial theorem nim_fuzzy_zero_of_ne_zero {o : Ordinal} (ho : o ≠ 0) : nim o ‖ 0 := by rw [Impartial.fuzzy_zero_iff_lf, nim_def, lf_zero_le] rw [← Ordinal.pos_iff_ne_zero] at ho exact ⟨(Ordinal.principalSegOut ho).top, by simp⟩ #align pgame.nim_fuzzy_zero_of_ne_zero SetTheory.PGame.nim_fuzzy_zero_of_ne_zero @[simp] theorem nim_add_equiv_zero_iff (o₁ o₂ : Ordinal) : (nim o₁ + nim o₂ ≈ 0) ↔ o₁ = o₂ := by constructor · refine not_imp_not.1 fun hne : _ ≠ _ => (Impartial.not_equiv_zero_iff (nim o₁ + nim o₂)).2 ?_ wlog h : o₁ < o₂ · exact (fuzzy_congr_left add_comm_equiv).1 (this _ _ hne.symm (hne.lt_or_lt.resolve_left h)) rw [Impartial.fuzzy_zero_iff_gf, zero_lf_le, nim_def o₂] refine ⟨toLeftMovesAdd (Sum.inr ?_), ?_⟩ · exact (Ordinal.principalSegOut h).top · -- Porting note: squeezed simp simpa only [Ordinal.typein_top, Ordinal.type_lt, PGame.add_moveLeft_inr, PGame.moveLeft_mk] using (Impartial.add_self (nim o₁)).2 · rintro rfl exact Impartial.add_self (nim o₁) #align pgame.nim_add_equiv_zero_iff SetTheory.PGame.nim_add_equiv_zero_iff @[simp] theorem nim_add_fuzzy_zero_iff {o₁ o₂ : Ordinal} : nim o₁ + nim o₂ ‖ 0 ↔ o₁ ≠ o₂ := by rw [iff_not_comm, Impartial.not_fuzzy_zero_iff, nim_add_equiv_zero_iff] #align pgame.nim_add_fuzzy_zero_iff SetTheory.PGame.nim_add_fuzzy_zero_iff @[simp] theorem nim_equiv_iff_eq {o₁ o₂ : Ordinal} : (nim o₁ ≈ nim o₂) ↔ o₁ = o₂ := by rw [Impartial.equiv_iff_add_equiv_zero, nim_add_equiv_zero_iff] #align pgame.nim_equiv_iff_eq SetTheory.PGame.nim_equiv_iff_eq /-- The Grundy value of an impartial game, the ordinal which corresponds to the game of nim that the game is equivalent to -/ noncomputable def grundyValue : PGame.{u} → Ordinal.{u} | G => Ordinal.mex.{u, u} fun i => grundyValue (G.moveLeft i) termination_by G => G #align pgame.grundy_value SetTheory.PGame.grundyValue theorem grundyValue_eq_mex_left (G : PGame) : grundyValue G = Ordinal.mex.{u, u} fun i => grundyValue (G.moveLeft i) := by rw [grundyValue] #align pgame.grundy_value_eq_mex_left SetTheory.PGame.grundyValue_eq_mex_left /-- The Sprague-Grundy theorem which states that every impartial game is equivalent to a game of nim, namely the game of nim corresponding to the games Grundy value -/ theorem equiv_nim_grundyValue : ∀ (G : PGame.{u}) [G.Impartial], G ≈ nim (grundyValue G) | G => by rw [Impartial.equiv_iff_add_equiv_zero, ← Impartial.forall_leftMoves_fuzzy_iff_equiv_zero] intro i apply leftMoves_add_cases i · intro i₁ rw [add_moveLeft_inl] apply (fuzzy_congr_left (add_congr_left (Equiv.symm (equiv_nim_grundyValue (G.moveLeft i₁))))).1 rw [nim_add_fuzzy_zero_iff] intro heq rw [eq_comm, grundyValue_eq_mex_left G] at heq -- Porting note: added universe annotation, argument have h := Ordinal.ne_mex.{u, u} (fun i ↦ grundyValue (moveLeft G i)) rw [heq] at h exact (h i₁).irrefl · intro i₂ rw [add_moveLeft_inr, ← Impartial.exists_left_move_equiv_iff_fuzzy_zero] revert i₂ rw [nim_def] intro i₂ have h' : ∃ i : G.LeftMoves, grundyValue (G.moveLeft i) = Ordinal.typein (Quotient.out (grundyValue G)).r i₂ := by revert i₂ rw [grundyValue_eq_mex_left] intro i₂ have hnotin : _ ∉ _ := fun hin => (le_not_le_of_lt (Ordinal.typein_lt_self i₂)).2 (csInf_le' hin) simpa using hnotin cases' h' with i hi use toLeftMovesAdd (Sum.inl i) rw [add_moveLeft_inl, moveLeft_mk] apply Equiv.trans (add_congr_left (equiv_nim_grundyValue (G.moveLeft i))) simpa only [hi] using Impartial.add_self (nim (grundyValue (G.moveLeft i))) termination_by G => G decreasing_by all_goals pgame_wf_tac #align pgame.equiv_nim_grundy_value SetTheory.PGame.equiv_nim_grundyValue theorem grundyValue_eq_iff_equiv_nim {G : PGame} [G.Impartial] {o : Ordinal} : grundyValue G = o ↔ (G ≈ nim o) := ⟨by rintro rfl; exact equiv_nim_grundyValue G, by intro h; rw [← nim_equiv_iff_eq]; exact Equiv.trans (Equiv.symm (equiv_nim_grundyValue G)) h⟩ #align pgame.grundy_value_eq_iff_equiv_nim SetTheory.PGame.grundyValue_eq_iff_equiv_nim @[simp] theorem nim_grundyValue (o : Ordinal.{u}) : grundyValue (nim o) = o := grundyValue_eq_iff_equiv_nim.2 PGame.equiv_rfl #align pgame.nim_grundy_value SetTheory.PGame.nim_grundyValue theorem grundyValue_eq_iff_equiv (G H : PGame) [G.Impartial] [H.Impartial] : grundyValue G = grundyValue H ↔ (G ≈ H) := grundyValue_eq_iff_equiv_nim.trans (equiv_congr_left.1 (equiv_nim_grundyValue H) _).symm #align pgame.grundy_value_eq_iff_equiv SetTheory.PGame.grundyValue_eq_iff_equiv @[simp] theorem grundyValue_zero : grundyValue 0 = 0 := grundyValue_eq_iff_equiv_nim.2 (Equiv.symm nim_zero_equiv) #align pgame.grundy_value_zero SetTheory.PGame.grundyValue_zero theorem grundyValue_iff_equiv_zero (G : PGame) [G.Impartial] : grundyValue G = 0 ↔ (G ≈ 0) := by rw [← grundyValue_eq_iff_equiv, grundyValue_zero] #align pgame.grundy_value_iff_equiv_zero SetTheory.PGame.grundyValue_iff_equiv_zero @[simp] theorem grundyValue_star : grundyValue star = 1 := grundyValue_eq_iff_equiv_nim.2 (Equiv.symm nim_one_equiv) #align pgame.grundy_value_star SetTheory.PGame.grundyValue_star @[simp]
Mathlib/SetTheory/Game/Nim.lean
342
343
theorem grundyValue_neg (G : PGame) [G.Impartial] : grundyValue (-G) = grundyValue G := by
rw [grundyValue_eq_iff_equiv_nim, neg_equiv_iff, neg_nim, ← grundyValue_eq_iff_equiv_nim]
/- Copyright (c) 2020 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.Algebra.Group.Conj import Mathlib.Algebra.Group.Pi.Lemmas import Mathlib.Algebra.Group.Subsemigroup.Operations import Mathlib.Algebra.Group.Submonoid.Operations import Mathlib.Algebra.Order.Group.Abs import Mathlib.Data.Set.Image import Mathlib.Order.Atoms import Mathlib.Tactic.ApplyFun #align_import group_theory.subgroup.basic from "leanprover-community/mathlib"@"4be589053caf347b899a494da75410deb55fb3ef" /-! # Subgroups This file defines multiplicative and additive subgroups as an extension of submonoids, in a bundled form (unbundled subgroups are in `Deprecated/Subgroups.lean`). We prove subgroups of a group form a complete lattice, and results about images and preimages of subgroups under group homomorphisms. The bundled subgroups use bundled monoid homomorphisms. There are also theorems about the subgroups generated by an element or a subset of a group, defined both inductively and as the infimum of the set of subgroups containing a given element/subset. Special thanks goes to Amelia Livingston and Yury Kudryashov for their help and inspiration. ## Main definitions Notation used here: - `G N` are `Group`s - `A` is an `AddGroup` - `H K` are `Subgroup`s of `G` or `AddSubgroup`s of `A` - `x` is an element of type `G` or type `A` - `f g : N →* G` are group homomorphisms - `s k` are sets of elements of type `G` Definitions in the file: * `Subgroup G` : the type of subgroups of a group `G` * `AddSubgroup A` : the type of subgroups of an additive group `A` * `CompleteLattice (Subgroup G)` : the subgroups of `G` form a complete lattice * `Subgroup.closure k` : the minimal subgroup that includes the set `k` * `Subgroup.subtype` : the natural group homomorphism from a subgroup of group `G` to `G` * `Subgroup.gi` : `closure` forms a Galois insertion with the coercion to set * `Subgroup.comap H f` : the preimage of a subgroup `H` along the group homomorphism `f` is also a subgroup * `Subgroup.map f H` : the image of a subgroup `H` along the group homomorphism `f` is also a subgroup * `Subgroup.prod H K` : the product of subgroups `H`, `K` of groups `G`, `N` respectively, `H × K` is a subgroup of `G × N` * `MonoidHom.range f` : the range of the group homomorphism `f` is a subgroup * `MonoidHom.ker f` : the kernel of a group homomorphism `f` is the subgroup of elements `x : G` such that `f x = 1` * `MonoidHom.eq_locus f g` : given group homomorphisms `f`, `g`, the elements of `G` such that `f x = g x` form a subgroup of `G` ## Implementation notes Subgroup inclusion is denoted `≤` rather than `⊆`, although `∈` is defined as membership of a subgroup's underlying set. ## Tags subgroup, subgroups -/ open Function open Int variable {G G' G'' : Type*} [Group G] [Group G'] [Group G''] variable {A : Type*} [AddGroup A] section SubgroupClass /-- `InvMemClass S G` states `S` is a type of subsets `s ⊆ G` closed under inverses. -/ class InvMemClass (S G : Type*) [Inv G] [SetLike S G] : Prop where /-- `s` is closed under inverses -/ inv_mem : ∀ {s : S} {x}, x ∈ s → x⁻¹ ∈ s #align inv_mem_class InvMemClass export InvMemClass (inv_mem) /-- `NegMemClass S G` states `S` is a type of subsets `s ⊆ G` closed under negation. -/ class NegMemClass (S G : Type*) [Neg G] [SetLike S G] : Prop where /-- `s` is closed under negation -/ neg_mem : ∀ {s : S} {x}, x ∈ s → -x ∈ s #align neg_mem_class NegMemClass export NegMemClass (neg_mem) /-- `SubgroupClass S G` states `S` is a type of subsets `s ⊆ G` that are subgroups of `G`. -/ class SubgroupClass (S G : Type*) [DivInvMonoid G] [SetLike S G] extends SubmonoidClass S G, InvMemClass S G : Prop #align subgroup_class SubgroupClass /-- `AddSubgroupClass S G` states `S` is a type of subsets `s ⊆ G` that are additive subgroups of `G`. -/ class AddSubgroupClass (S G : Type*) [SubNegMonoid G] [SetLike S G] extends AddSubmonoidClass S G, NegMemClass S G : Prop #align add_subgroup_class AddSubgroupClass attribute [to_additive] InvMemClass SubgroupClass attribute [aesop safe apply (rule_sets := [SetLike])] inv_mem neg_mem @[to_additive (attr := simp)] theorem inv_mem_iff {S G} [InvolutiveInv G] {_ : SetLike S G} [InvMemClass S G] {H : S} {x : G} : x⁻¹ ∈ H ↔ x ∈ H := ⟨fun h => inv_inv x ▸ inv_mem h, inv_mem⟩ #align inv_mem_iff inv_mem_iff #align neg_mem_iff neg_mem_iff @[simp] theorem abs_mem_iff {S G} [AddGroup G] [LinearOrder G] {_ : SetLike S G} [NegMemClass S G] {H : S} {x : G} : |x| ∈ H ↔ x ∈ H := by cases abs_choice x <;> simp [*] variable {M S : Type*} [DivInvMonoid M] [SetLike S M] [hSM : SubgroupClass S M] {H K : S} /-- A subgroup is closed under division. -/ @[to_additive (attr := aesop safe apply (rule_sets := [SetLike])) "An additive subgroup is closed under subtraction."] theorem div_mem {x y : M} (hx : x ∈ H) (hy : y ∈ H) : x / y ∈ H := by rw [div_eq_mul_inv]; exact mul_mem hx (inv_mem hy) #align div_mem div_mem #align sub_mem sub_mem @[to_additive (attr := aesop safe apply (rule_sets := [SetLike]))] theorem zpow_mem {x : M} (hx : x ∈ K) : ∀ n : ℤ, x ^ n ∈ K | (n : ℕ) => by rw [zpow_natCast] exact pow_mem hx n | -[n+1] => by rw [zpow_negSucc] exact inv_mem (pow_mem hx n.succ) #align zpow_mem zpow_mem #align zsmul_mem zsmul_mem variable [SetLike S G] [SubgroupClass S G] @[to_additive] theorem div_mem_comm_iff {a b : G} : a / b ∈ H ↔ b / a ∈ H := inv_div b a ▸ inv_mem_iff #align div_mem_comm_iff div_mem_comm_iff #align sub_mem_comm_iff sub_mem_comm_iff @[to_additive /-(attr := simp)-/] -- Porting note: `simp` cannot simplify LHS theorem exists_inv_mem_iff_exists_mem {P : G → Prop} : (∃ x : G, x ∈ H ∧ P x⁻¹) ↔ ∃ x ∈ H, P x := by constructor <;> · rintro ⟨x, x_in, hx⟩ exact ⟨x⁻¹, inv_mem x_in, by simp [hx]⟩ #align exists_inv_mem_iff_exists_mem exists_inv_mem_iff_exists_mem #align exists_neg_mem_iff_exists_mem exists_neg_mem_iff_exists_mem @[to_additive] theorem mul_mem_cancel_right {x y : G} (h : x ∈ H) : y * x ∈ H ↔ y ∈ H := ⟨fun hba => by simpa using mul_mem hba (inv_mem h), fun hb => mul_mem hb h⟩ #align mul_mem_cancel_right mul_mem_cancel_right #align add_mem_cancel_right add_mem_cancel_right @[to_additive] theorem mul_mem_cancel_left {x y : G} (h : x ∈ H) : x * y ∈ H ↔ y ∈ H := ⟨fun hab => by simpa using mul_mem (inv_mem h) hab, mul_mem h⟩ #align mul_mem_cancel_left mul_mem_cancel_left #align add_mem_cancel_left add_mem_cancel_left namespace InvMemClass /-- A subgroup of a group inherits an inverse. -/ @[to_additive "An additive subgroup of an `AddGroup` inherits an inverse."] instance inv {G : Type u_1} {S : Type u_2} [Inv G] [SetLike S G] [InvMemClass S G] {H : S} : Inv H := ⟨fun a => ⟨a⁻¹, inv_mem a.2⟩⟩ #align subgroup_class.has_inv InvMemClass.inv #align add_subgroup_class.has_neg NegMemClass.neg @[to_additive (attr := simp, norm_cast)] theorem coe_inv (x : H) : (x⁻¹).1 = x.1⁻¹ := rfl #align subgroup_class.coe_inv InvMemClass.coe_inv #align add_subgroup_class.coe_neg NegMemClass.coe_neg end InvMemClass namespace SubgroupClass @[to_additive (attr := deprecated (since := "2024-01-15"))] alias coe_inv := InvMemClass.coe_inv -- Here we assume H, K, and L are subgroups, but in fact any one of them -- could be allowed to be a subsemigroup. -- Counterexample where K and L are submonoids: H = ℤ, K = ℕ, L = -ℕ -- Counterexample where H and K are submonoids: H = {n | n = 0 ∨ 3 ≤ n}, K = 3ℕ + 4ℕ, L = 5ℤ @[to_additive] theorem subset_union {H K L : S} : (H : Set G) ⊆ K ∪ L ↔ H ≤ K ∨ H ≤ L := by refine ⟨fun h ↦ ?_, fun h x xH ↦ h.imp (· xH) (· xH)⟩ rw [or_iff_not_imp_left, SetLike.not_le_iff_exists] exact fun ⟨x, xH, xK⟩ y yH ↦ (h <| mul_mem xH yH).elim ((h yH).resolve_left fun yK ↦ xK <| (mul_mem_cancel_right yK).mp ·) (mul_mem_cancel_left <| (h xH).resolve_left xK).mp /-- A subgroup of a group inherits a division -/ @[to_additive "An additive subgroup of an `AddGroup` inherits a subtraction."] instance div {G : Type u_1} {S : Type u_2} [DivInvMonoid G] [SetLike S G] [SubgroupClass S G] {H : S} : Div H := ⟨fun a b => ⟨a / b, div_mem a.2 b.2⟩⟩ #align subgroup_class.has_div SubgroupClass.div #align add_subgroup_class.has_sub AddSubgroupClass.sub /-- An additive subgroup of an `AddGroup` inherits an integer scaling. -/ instance _root_.AddSubgroupClass.zsmul {M S} [SubNegMonoid M] [SetLike S M] [AddSubgroupClass S M] {H : S} : SMul ℤ H := ⟨fun n a => ⟨n • a.1, zsmul_mem a.2 n⟩⟩ #align add_subgroup_class.has_zsmul AddSubgroupClass.zsmul /-- A subgroup of a group inherits an integer power. -/ @[to_additive existing] instance zpow {M S} [DivInvMonoid M] [SetLike S M] [SubgroupClass S M] {H : S} : Pow H ℤ := ⟨fun a n => ⟨a.1 ^ n, zpow_mem a.2 n⟩⟩ #align subgroup_class.has_zpow SubgroupClass.zpow -- Porting note: additive align statement is given above @[to_additive (attr := simp, norm_cast)] theorem coe_div (x y : H) : (x / y).1 = x.1 / y.1 := rfl #align subgroup_class.coe_div SubgroupClass.coe_div #align add_subgroup_class.coe_sub AddSubgroupClass.coe_sub variable (H) -- Prefer subclasses of `Group` over subclasses of `SubgroupClass`. /-- A subgroup of a group inherits a group structure. -/ @[to_additive "An additive subgroup of an `AddGroup` inherits an `AddGroup` structure."] instance (priority := 75) toGroup : Group H := Subtype.coe_injective.group _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl #align subgroup_class.to_group SubgroupClass.toGroup #align add_subgroup_class.to_add_group AddSubgroupClass.toAddGroup -- Prefer subclasses of `CommGroup` over subclasses of `SubgroupClass`. /-- A subgroup of a `CommGroup` is a `CommGroup`. -/ @[to_additive "An additive subgroup of an `AddCommGroup` is an `AddCommGroup`."] instance (priority := 75) toCommGroup {G : Type*} [CommGroup G] [SetLike S G] [SubgroupClass S G] : CommGroup H := Subtype.coe_injective.commGroup _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl #align subgroup_class.to_comm_group SubgroupClass.toCommGroup #align add_subgroup_class.to_add_comm_group AddSubgroupClass.toAddCommGroup /-- The natural group hom from a subgroup of group `G` to `G`. -/ @[to_additive (attr := coe) "The natural group hom from an additive subgroup of `AddGroup` `G` to `G`."] protected def subtype : H →* G where toFun := ((↑) : H → G); map_one' := rfl; map_mul' := fun _ _ => rfl #align subgroup_class.subtype SubgroupClass.subtype #align add_subgroup_class.subtype AddSubgroupClass.subtype @[to_additive (attr := simp)] theorem coeSubtype : (SubgroupClass.subtype H : H → G) = ((↑) : H → G) := by rfl #align subgroup_class.coe_subtype SubgroupClass.coeSubtype #align add_subgroup_class.coe_subtype AddSubgroupClass.coeSubtype variable {H} @[to_additive (attr := simp, norm_cast)] theorem coe_pow (x : H) (n : ℕ) : ((x ^ n : H) : G) = (x : G) ^ n := rfl #align subgroup_class.coe_pow SubgroupClass.coe_pow #align add_subgroup_class.coe_smul AddSubgroupClass.coe_nsmul @[to_additive (attr := simp, norm_cast)] theorem coe_zpow (x : H) (n : ℤ) : ((x ^ n : H) : G) = (x : G) ^ n := rfl #align subgroup_class.coe_zpow SubgroupClass.coe_zpow #align add_subgroup_class.coe_zsmul AddSubgroupClass.coe_zsmul /-- The inclusion homomorphism from a subgroup `H` contained in `K` to `K`. -/ @[to_additive "The inclusion homomorphism from an additive subgroup `H` contained in `K` to `K`."] def inclusion {H K : S} (h : H ≤ K) : H →* K := MonoidHom.mk' (fun x => ⟨x, h x.prop⟩) fun _ _=> rfl #align subgroup_class.inclusion SubgroupClass.inclusion #align add_subgroup_class.inclusion AddSubgroupClass.inclusion @[to_additive (attr := simp)] theorem inclusion_self (x : H) : inclusion le_rfl x = x := by cases x rfl #align subgroup_class.inclusion_self SubgroupClass.inclusion_self #align add_subgroup_class.inclusion_self AddSubgroupClass.inclusion_self @[to_additive (attr := simp)] theorem inclusion_mk {h : H ≤ K} (x : G) (hx : x ∈ H) : inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ := rfl #align subgroup_class.inclusion_mk SubgroupClass.inclusion_mk #align add_subgroup_class.inclusion_mk AddSubgroupClass.inclusion_mk @[to_additive] theorem inclusion_right (h : H ≤ K) (x : K) (hx : (x : G) ∈ H) : inclusion h ⟨x, hx⟩ = x := by cases x rfl #align subgroup_class.inclusion_right SubgroupClass.inclusion_right #align add_subgroup_class.inclusion_right AddSubgroupClass.inclusion_right @[simp] theorem inclusion_inclusion {L : S} (hHK : H ≤ K) (hKL : K ≤ L) (x : H) : inclusion hKL (inclusion hHK x) = inclusion (hHK.trans hKL) x := by cases x rfl #align subgroup_class.inclusion_inclusion SubgroupClass.inclusion_inclusion @[to_additive (attr := simp)] theorem coe_inclusion {H K : S} {h : H ≤ K} (a : H) : (inclusion h a : G) = a := by cases a simp only [inclusion, MonoidHom.mk'_apply] #align subgroup_class.coe_inclusion SubgroupClass.coe_inclusion #align add_subgroup_class.coe_inclusion AddSubgroupClass.coe_inclusion @[to_additive (attr := simp)] theorem subtype_comp_inclusion {H K : S} (hH : H ≤ K) : (SubgroupClass.subtype K).comp (inclusion hH) = SubgroupClass.subtype H := by ext simp only [MonoidHom.comp_apply, coeSubtype, coe_inclusion] #align subgroup_class.subtype_comp_inclusion SubgroupClass.subtype_comp_inclusion #align add_subgroup_class.subtype_comp_inclusion AddSubgroupClass.subtype_comp_inclusion end SubgroupClass end SubgroupClass /-- A subgroup of a group `G` is a subset containing 1, closed under multiplication and closed under multiplicative inverse. -/ structure Subgroup (G : Type*) [Group G] extends Submonoid G where /-- `G` is closed under inverses -/ inv_mem' {x} : x ∈ carrier → x⁻¹ ∈ carrier #align subgroup Subgroup /-- An additive subgroup of an additive group `G` is a subset containing 0, closed under addition and additive inverse. -/ structure AddSubgroup (G : Type*) [AddGroup G] extends AddSubmonoid G where /-- `G` is closed under negation -/ neg_mem' {x} : x ∈ carrier → -x ∈ carrier #align add_subgroup AddSubgroup attribute [to_additive] Subgroup -- Porting note: Removed, translation already exists -- attribute [to_additive AddSubgroup.toAddSubmonoid] Subgroup.toSubmonoid /-- Reinterpret a `Subgroup` as a `Submonoid`. -/ add_decl_doc Subgroup.toSubmonoid #align subgroup.to_submonoid Subgroup.toSubmonoid /-- Reinterpret an `AddSubgroup` as an `AddSubmonoid`. -/ add_decl_doc AddSubgroup.toAddSubmonoid #align add_subgroup.to_add_submonoid AddSubgroup.toAddSubmonoid namespace Subgroup @[to_additive] instance : SetLike (Subgroup G) G where coe s := s.carrier coe_injective' p q h := by obtain ⟨⟨⟨hp,_⟩,_⟩,_⟩ := p obtain ⟨⟨⟨hq,_⟩,_⟩,_⟩ := q congr -- Porting note: Below can probably be written more uniformly @[to_additive] instance : SubgroupClass (Subgroup G) G where inv_mem := Subgroup.inv_mem' _ one_mem _ := (Subgroup.toSubmonoid _).one_mem' mul_mem := (Subgroup.toSubmonoid _).mul_mem' @[to_additive (attr := simp, nolint simpNF)] -- Porting note (#10675): dsimp can not prove this theorem mem_carrier {s : Subgroup G} {x : G} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl #align subgroup.mem_carrier Subgroup.mem_carrier #align add_subgroup.mem_carrier AddSubgroup.mem_carrier @[to_additive (attr := simp)] theorem mem_mk {s : Set G} {x : G} (h_one) (h_mul) (h_inv) : x ∈ mk ⟨⟨s, h_one⟩, h_mul⟩ h_inv ↔ x ∈ s := Iff.rfl #align subgroup.mem_mk Subgroup.mem_mk #align add_subgroup.mem_mk AddSubgroup.mem_mk @[to_additive (attr := simp, norm_cast)] theorem coe_set_mk {s : Set G} (h_one) (h_mul) (h_inv) : (mk ⟨⟨s, h_one⟩, h_mul⟩ h_inv : Set G) = s := rfl #align subgroup.coe_set_mk Subgroup.coe_set_mk #align add_subgroup.coe_set_mk AddSubgroup.coe_set_mk @[to_additive (attr := simp)] theorem mk_le_mk {s t : Set G} (h_one) (h_mul) (h_inv) (h_one') (h_mul') (h_inv') : mk ⟨⟨s, h_one⟩, h_mul⟩ h_inv ≤ mk ⟨⟨t, h_one'⟩, h_mul'⟩ h_inv' ↔ s ⊆ t := Iff.rfl #align subgroup.mk_le_mk Subgroup.mk_le_mk #align add_subgroup.mk_le_mk AddSubgroup.mk_le_mk initialize_simps_projections Subgroup (carrier → coe) initialize_simps_projections AddSubgroup (carrier → coe) @[to_additive (attr := simp)] theorem coe_toSubmonoid (K : Subgroup G) : (K.toSubmonoid : Set G) = K := rfl #align subgroup.coe_to_submonoid Subgroup.coe_toSubmonoid #align add_subgroup.coe_to_add_submonoid AddSubgroup.coe_toAddSubmonoid @[to_additive (attr := simp)] theorem mem_toSubmonoid (K : Subgroup G) (x : G) : x ∈ K.toSubmonoid ↔ x ∈ K := Iff.rfl #align subgroup.mem_to_submonoid Subgroup.mem_toSubmonoid #align add_subgroup.mem_to_add_submonoid AddSubgroup.mem_toAddSubmonoid @[to_additive] theorem toSubmonoid_injective : Function.Injective (toSubmonoid : Subgroup G → Submonoid G) := -- fun p q h => SetLike.ext'_iff.2 (show _ from SetLike.ext'_iff.1 h) fun p q h => by have := SetLike.ext'_iff.1 h rw [coe_toSubmonoid, coe_toSubmonoid] at this exact SetLike.ext'_iff.2 this #align subgroup.to_submonoid_injective Subgroup.toSubmonoid_injective #align add_subgroup.to_add_submonoid_injective AddSubgroup.toAddSubmonoid_injective @[to_additive (attr := simp)] theorem toSubmonoid_eq {p q : Subgroup G} : p.toSubmonoid = q.toSubmonoid ↔ p = q := toSubmonoid_injective.eq_iff #align subgroup.to_submonoid_eq Subgroup.toSubmonoid_eq #align add_subgroup.to_add_submonoid_eq AddSubgroup.toAddSubmonoid_eq @[to_additive (attr := mono)] theorem toSubmonoid_strictMono : StrictMono (toSubmonoid : Subgroup G → Submonoid G) := fun _ _ => id #align subgroup.to_submonoid_strict_mono Subgroup.toSubmonoid_strictMono #align add_subgroup.to_add_submonoid_strict_mono AddSubgroup.toAddSubmonoid_strictMono @[to_additive (attr := mono)] theorem toSubmonoid_mono : Monotone (toSubmonoid : Subgroup G → Submonoid G) := toSubmonoid_strictMono.monotone #align subgroup.to_submonoid_mono Subgroup.toSubmonoid_mono #align add_subgroup.to_add_submonoid_mono AddSubgroup.toAddSubmonoid_mono @[to_additive (attr := simp)] theorem toSubmonoid_le {p q : Subgroup G} : p.toSubmonoid ≤ q.toSubmonoid ↔ p ≤ q := Iff.rfl #align subgroup.to_submonoid_le Subgroup.toSubmonoid_le #align add_subgroup.to_add_submonoid_le AddSubgroup.toAddSubmonoid_le @[to_additive (attr := simp)] lemma coe_nonempty (s : Subgroup G) : (s : Set G).Nonempty := ⟨1, one_mem _⟩ end Subgroup /-! ### Conversion to/from `Additive`/`Multiplicative` -/ section mul_add /-- Subgroups of a group `G` are isomorphic to additive subgroups of `Additive G`. -/ @[simps!] def Subgroup.toAddSubgroup : Subgroup G ≃o AddSubgroup (Additive G) where toFun S := { Submonoid.toAddSubmonoid S.toSubmonoid with neg_mem' := S.inv_mem' } invFun S := { AddSubmonoid.toSubmonoid S.toAddSubmonoid with inv_mem' := S.neg_mem' } left_inv x := by cases x; rfl right_inv x := by cases x; rfl map_rel_iff' := Iff.rfl #align subgroup.to_add_subgroup Subgroup.toAddSubgroup #align subgroup.to_add_subgroup_symm_apply_coe Subgroup.toAddSubgroup_symm_apply_coe #align subgroup.to_add_subgroup_apply_coe Subgroup.toAddSubgroup_apply_coe /-- Additive subgroup of an additive group `Additive G` are isomorphic to subgroup of `G`. -/ abbrev AddSubgroup.toSubgroup' : AddSubgroup (Additive G) ≃o Subgroup G := Subgroup.toAddSubgroup.symm #align add_subgroup.to_subgroup' AddSubgroup.toSubgroup' /-- Additive subgroups of an additive group `A` are isomorphic to subgroups of `Multiplicative A`. -/ @[simps!] def AddSubgroup.toSubgroup : AddSubgroup A ≃o Subgroup (Multiplicative A) where toFun S := { AddSubmonoid.toSubmonoid S.toAddSubmonoid with inv_mem' := S.neg_mem' } invFun S := { Submonoid.toAddSubmonoid S.toSubmonoid with neg_mem' := S.inv_mem' } left_inv x := by cases x; rfl right_inv x := by cases x; rfl map_rel_iff' := Iff.rfl #align add_subgroup.to_subgroup AddSubgroup.toSubgroup #align add_subgroup.to_subgroup_apply_coe AddSubgroup.toSubgroup_apply_coe #align add_subgroup.to_subgroup_symm_apply_coe AddSubgroup.toSubgroup_symm_apply_coe /-- Subgroups of an additive group `Multiplicative A` are isomorphic to additive subgroups of `A`. -/ abbrev Subgroup.toAddSubgroup' : Subgroup (Multiplicative A) ≃o AddSubgroup A := AddSubgroup.toSubgroup.symm #align subgroup.to_add_subgroup' Subgroup.toAddSubgroup' end mul_add namespace Subgroup variable (H K : Subgroup G) /-- Copy of a subgroup with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ @[to_additive "Copy of an additive subgroup with a new `carrier` equal to the old one. Useful to fix definitional equalities"] protected def copy (K : Subgroup G) (s : Set G) (hs : s = K) : Subgroup G where carrier := s one_mem' := hs.symm ▸ K.one_mem' mul_mem' := hs.symm ▸ K.mul_mem' inv_mem' hx := by simpa [hs] using hx -- Porting note: `▸` didn't work here #align subgroup.copy Subgroup.copy #align add_subgroup.copy AddSubgroup.copy @[to_additive (attr := simp)] theorem coe_copy (K : Subgroup G) (s : Set G) (hs : s = ↑K) : (K.copy s hs : Set G) = s := rfl #align subgroup.coe_copy Subgroup.coe_copy #align add_subgroup.coe_copy AddSubgroup.coe_copy @[to_additive] theorem copy_eq (K : Subgroup G) (s : Set G) (hs : s = ↑K) : K.copy s hs = K := SetLike.coe_injective hs #align subgroup.copy_eq Subgroup.copy_eq #align add_subgroup.copy_eq AddSubgroup.copy_eq /-- Two subgroups are equal if they have the same elements. -/ @[to_additive (attr := ext) "Two `AddSubgroup`s are equal if they have the same elements."] theorem ext {H K : Subgroup G} (h : ∀ x, x ∈ H ↔ x ∈ K) : H = K := SetLike.ext h #align subgroup.ext Subgroup.ext #align add_subgroup.ext AddSubgroup.ext /-- A subgroup contains the group's 1. -/ @[to_additive "An `AddSubgroup` contains the group's 0."] protected theorem one_mem : (1 : G) ∈ H := one_mem _ #align subgroup.one_mem Subgroup.one_mem #align add_subgroup.zero_mem AddSubgroup.zero_mem /-- A subgroup is closed under multiplication. -/ @[to_additive "An `AddSubgroup` is closed under addition."] protected theorem mul_mem {x y : G} : x ∈ H → y ∈ H → x * y ∈ H := mul_mem #align subgroup.mul_mem Subgroup.mul_mem #align add_subgroup.add_mem AddSubgroup.add_mem /-- A subgroup is closed under inverse. -/ @[to_additive "An `AddSubgroup` is closed under inverse."] protected theorem inv_mem {x : G} : x ∈ H → x⁻¹ ∈ H := inv_mem #align subgroup.inv_mem Subgroup.inv_mem #align add_subgroup.neg_mem AddSubgroup.neg_mem /-- A subgroup is closed under division. -/ @[to_additive "An `AddSubgroup` is closed under subtraction."] protected theorem div_mem {x y : G} (hx : x ∈ H) (hy : y ∈ H) : x / y ∈ H := div_mem hx hy #align subgroup.div_mem Subgroup.div_mem #align add_subgroup.sub_mem AddSubgroup.sub_mem @[to_additive] protected theorem inv_mem_iff {x : G} : x⁻¹ ∈ H ↔ x ∈ H := inv_mem_iff #align subgroup.inv_mem_iff Subgroup.inv_mem_iff #align add_subgroup.neg_mem_iff AddSubgroup.neg_mem_iff @[to_additive] protected theorem div_mem_comm_iff {a b : G} : a / b ∈ H ↔ b / a ∈ H := div_mem_comm_iff #align subgroup.div_mem_comm_iff Subgroup.div_mem_comm_iff #align add_subgroup.sub_mem_comm_iff AddSubgroup.sub_mem_comm_iff @[to_additive] protected theorem exists_inv_mem_iff_exists_mem (K : Subgroup G) {P : G → Prop} : (∃ x : G, x ∈ K ∧ P x⁻¹) ↔ ∃ x ∈ K, P x := exists_inv_mem_iff_exists_mem #align subgroup.exists_inv_mem_iff_exists_mem Subgroup.exists_inv_mem_iff_exists_mem #align add_subgroup.exists_neg_mem_iff_exists_mem AddSubgroup.exists_neg_mem_iff_exists_mem @[to_additive] protected theorem mul_mem_cancel_right {x y : G} (h : x ∈ H) : y * x ∈ H ↔ y ∈ H := mul_mem_cancel_right h #align subgroup.mul_mem_cancel_right Subgroup.mul_mem_cancel_right #align add_subgroup.add_mem_cancel_right AddSubgroup.add_mem_cancel_right @[to_additive] protected theorem mul_mem_cancel_left {x y : G} (h : x ∈ H) : x * y ∈ H ↔ y ∈ H := mul_mem_cancel_left h #align subgroup.mul_mem_cancel_left Subgroup.mul_mem_cancel_left #align add_subgroup.add_mem_cancel_left AddSubgroup.add_mem_cancel_left @[to_additive] protected theorem pow_mem {x : G} (hx : x ∈ K) : ∀ n : ℕ, x ^ n ∈ K := pow_mem hx #align subgroup.pow_mem Subgroup.pow_mem #align add_subgroup.nsmul_mem AddSubgroup.nsmul_mem @[to_additive] protected theorem zpow_mem {x : G} (hx : x ∈ K) : ∀ n : ℤ, x ^ n ∈ K := zpow_mem hx #align subgroup.zpow_mem Subgroup.zpow_mem #align add_subgroup.zsmul_mem AddSubgroup.zsmul_mem /-- Construct a subgroup from a nonempty set that is closed under division. -/ @[to_additive "Construct a subgroup from a nonempty set that is closed under subtraction"] def ofDiv (s : Set G) (hsn : s.Nonempty) (hs : ∀ᵉ (x ∈ s) (y ∈ s), x * y⁻¹ ∈ s) : Subgroup G := have one_mem : (1 : G) ∈ s := by let ⟨x, hx⟩ := hsn simpa using hs x hx x hx have inv_mem : ∀ x, x ∈ s → x⁻¹ ∈ s := fun x hx => by simpa using hs 1 one_mem x hx { carrier := s one_mem' := one_mem inv_mem' := inv_mem _ mul_mem' := fun hx hy => by simpa using hs _ hx _ (inv_mem _ hy) } #align subgroup.of_div Subgroup.ofDiv #align add_subgroup.of_sub AddSubgroup.ofSub /-- A subgroup of a group inherits a multiplication. -/ @[to_additive "An `AddSubgroup` of an `AddGroup` inherits an addition."] instance mul : Mul H := H.toSubmonoid.mul #align subgroup.has_mul Subgroup.mul #align add_subgroup.has_add AddSubgroup.add /-- A subgroup of a group inherits a 1. -/ @[to_additive "An `AddSubgroup` of an `AddGroup` inherits a zero."] instance one : One H := H.toSubmonoid.one #align subgroup.has_one Subgroup.one #align add_subgroup.has_zero AddSubgroup.zero /-- A subgroup of a group inherits an inverse. -/ @[to_additive "An `AddSubgroup` of an `AddGroup` inherits an inverse."] instance inv : Inv H := ⟨fun a => ⟨a⁻¹, H.inv_mem a.2⟩⟩ #align subgroup.has_inv Subgroup.inv #align add_subgroup.has_neg AddSubgroup.neg /-- A subgroup of a group inherits a division -/ @[to_additive "An `AddSubgroup` of an `AddGroup` inherits a subtraction."] instance div : Div H := ⟨fun a b => ⟨a / b, H.div_mem a.2 b.2⟩⟩ #align subgroup.has_div Subgroup.div #align add_subgroup.has_sub AddSubgroup.sub /-- An `AddSubgroup` of an `AddGroup` inherits a natural scaling. -/ instance _root_.AddSubgroup.nsmul {G} [AddGroup G] {H : AddSubgroup G} : SMul ℕ H := ⟨fun n a => ⟨n • a, H.nsmul_mem a.2 n⟩⟩ #align add_subgroup.has_nsmul AddSubgroup.nsmul /-- A subgroup of a group inherits a natural power -/ @[to_additive existing] protected instance npow : Pow H ℕ := ⟨fun a n => ⟨a ^ n, H.pow_mem a.2 n⟩⟩ #align subgroup.has_npow Subgroup.npow /-- An `AddSubgroup` of an `AddGroup` inherits an integer scaling. -/ instance _root_.AddSubgroup.zsmul {G} [AddGroup G] {H : AddSubgroup G} : SMul ℤ H := ⟨fun n a => ⟨n • a, H.zsmul_mem a.2 n⟩⟩ #align add_subgroup.has_zsmul AddSubgroup.zsmul /-- A subgroup of a group inherits an integer power -/ @[to_additive existing] instance zpow : Pow H ℤ := ⟨fun a n => ⟨a ^ n, H.zpow_mem a.2 n⟩⟩ #align subgroup.has_zpow Subgroup.zpow @[to_additive (attr := simp, norm_cast)] theorem coe_mul (x y : H) : (↑(x * y) : G) = ↑x * ↑y := rfl #align subgroup.coe_mul Subgroup.coe_mul #align add_subgroup.coe_add AddSubgroup.coe_add @[to_additive (attr := simp, norm_cast)] theorem coe_one : ((1 : H) : G) = 1 := rfl #align subgroup.coe_one Subgroup.coe_one #align add_subgroup.coe_zero AddSubgroup.coe_zero @[to_additive (attr := simp, norm_cast)] theorem coe_inv (x : H) : ↑(x⁻¹ : H) = (x⁻¹ : G) := rfl #align subgroup.coe_inv Subgroup.coe_inv #align add_subgroup.coe_neg AddSubgroup.coe_neg @[to_additive (attr := simp, norm_cast)] theorem coe_div (x y : H) : (↑(x / y) : G) = ↑x / ↑y := rfl #align subgroup.coe_div Subgroup.coe_div #align add_subgroup.coe_sub AddSubgroup.coe_sub -- Porting note: removed simp, theorem has variable as head symbol @[to_additive (attr := norm_cast)] theorem coe_mk (x : G) (hx : x ∈ H) : ((⟨x, hx⟩ : H) : G) = x := rfl #align subgroup.coe_mk Subgroup.coe_mk #align add_subgroup.coe_mk AddSubgroup.coe_mk @[to_additive (attr := simp, norm_cast)] theorem coe_pow (x : H) (n : ℕ) : ((x ^ n : H) : G) = (x : G) ^ n := rfl #align subgroup.coe_pow Subgroup.coe_pow #align add_subgroup.coe_nsmul AddSubgroup.coe_nsmul @[to_additive (attr := norm_cast)] -- Porting note (#10685): dsimp can prove this theorem coe_zpow (x : H) (n : ℤ) : ((x ^ n : H) : G) = (x : G) ^ n := rfl #align subgroup.coe_zpow Subgroup.coe_zpow #align add_subgroup.coe_zsmul AddSubgroup.coe_zsmul @[to_additive] -- This can be proved by `Submonoid.mk_eq_one` theorem mk_eq_one {g : G} {h} : (⟨g, h⟩ : H) = 1 ↔ g = 1 := by simp #align subgroup.mk_eq_one_iff Subgroup.mk_eq_one #align add_subgroup.mk_eq_zero_iff AddSubgroup.mk_eq_zero /-- A subgroup of a group inherits a group structure. -/ @[to_additive "An `AddSubgroup` of an `AddGroup` inherits an `AddGroup` structure."] instance toGroup {G : Type*} [Group G] (H : Subgroup G) : Group H := Subtype.coe_injective.group _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl #align subgroup.to_group Subgroup.toGroup #align add_subgroup.to_add_group AddSubgroup.toAddGroup /-- A subgroup of a `CommGroup` is a `CommGroup`. -/ @[to_additive "An `AddSubgroup` of an `AddCommGroup` is an `AddCommGroup`."] instance toCommGroup {G : Type*} [CommGroup G] (H : Subgroup G) : CommGroup H := Subtype.coe_injective.commGroup _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl #align subgroup.to_comm_group Subgroup.toCommGroup #align add_subgroup.to_add_comm_group AddSubgroup.toAddCommGroup /-- The natural group hom from a subgroup of group `G` to `G`. -/ @[to_additive "The natural group hom from an `AddSubgroup` of `AddGroup` `G` to `G`."] protected def subtype : H →* G where toFun := ((↑) : H → G); map_one' := rfl; map_mul' _ _ := rfl #align subgroup.subtype Subgroup.subtype #align add_subgroup.subtype AddSubgroup.subtype @[to_additive (attr := simp)] theorem coeSubtype : ⇑ H.subtype = ((↑) : H → G) := rfl #align subgroup.coe_subtype Subgroup.coeSubtype #align add_subgroup.coe_subtype AddSubgroup.coeSubtype @[to_additive] theorem subtype_injective : Function.Injective (Subgroup.subtype H) := Subtype.coe_injective #align subgroup.subtype_injective Subgroup.subtype_injective #align add_subgroup.subtype_injective AddSubgroup.subtype_injective /-- The inclusion homomorphism from a subgroup `H` contained in `K` to `K`. -/ @[to_additive "The inclusion homomorphism from an additive subgroup `H` contained in `K` to `K`."] def inclusion {H K : Subgroup G} (h : H ≤ K) : H →* K := MonoidHom.mk' (fun x => ⟨x, h x.2⟩) fun _ _ => rfl #align subgroup.inclusion Subgroup.inclusion #align add_subgroup.inclusion AddSubgroup.inclusion @[to_additive (attr := simp)] theorem coe_inclusion {H K : Subgroup G} {h : H ≤ K} (a : H) : (inclusion h a : G) = a := by cases a simp only [inclusion, coe_mk, MonoidHom.mk'_apply] #align subgroup.coe_inclusion Subgroup.coe_inclusion #align add_subgroup.coe_inclusion AddSubgroup.coe_inclusion @[to_additive] theorem inclusion_injective {H K : Subgroup G} (h : H ≤ K) : Function.Injective <| inclusion h := Set.inclusion_injective h #align subgroup.inclusion_injective Subgroup.inclusion_injective #align add_subgroup.inclusion_injective AddSubgroup.inclusion_injective @[to_additive (attr := simp)] theorem subtype_comp_inclusion {H K : Subgroup G} (hH : H ≤ K) : K.subtype.comp (inclusion hH) = H.subtype := rfl #align subgroup.subtype_comp_inclusion Subgroup.subtype_comp_inclusion #align add_subgroup.subtype_comp_inclusion AddSubgroup.subtype_comp_inclusion /-- The subgroup `G` of the group `G`. -/ @[to_additive "The `AddSubgroup G` of the `AddGroup G`."] instance : Top (Subgroup G) := ⟨{ (⊤ : Submonoid G) with inv_mem' := fun _ => Set.mem_univ _ }⟩ /-- The top subgroup is isomorphic to the group. This is the group version of `Submonoid.topEquiv`. -/ @[to_additive (attr := simps!) "The top additive subgroup is isomorphic to the additive group. This is the additive group version of `AddSubmonoid.topEquiv`."] def topEquiv : (⊤ : Subgroup G) ≃* G := Submonoid.topEquiv #align subgroup.top_equiv Subgroup.topEquiv #align add_subgroup.top_equiv AddSubgroup.topEquiv #align subgroup.top_equiv_symm_apply_coe Subgroup.topEquiv_symm_apply_coe #align add_subgroup.top_equiv_symm_apply_coe AddSubgroup.topEquiv_symm_apply_coe #align add_subgroup.top_equiv_apply AddSubgroup.topEquiv_apply /-- The trivial subgroup `{1}` of a group `G`. -/ @[to_additive "The trivial `AddSubgroup` `{0}` of an `AddGroup` `G`."] instance : Bot (Subgroup G) := ⟨{ (⊥ : Submonoid G) with inv_mem' := by simp}⟩ @[to_additive] instance : Inhabited (Subgroup G) := ⟨⊥⟩ @[to_additive (attr := simp)] theorem mem_bot {x : G} : x ∈ (⊥ : Subgroup G) ↔ x = 1 := Iff.rfl #align subgroup.mem_bot Subgroup.mem_bot #align add_subgroup.mem_bot AddSubgroup.mem_bot @[to_additive (attr := simp)] theorem mem_top (x : G) : x ∈ (⊤ : Subgroup G) := Set.mem_univ x #align subgroup.mem_top Subgroup.mem_top #align add_subgroup.mem_top AddSubgroup.mem_top @[to_additive (attr := simp)] theorem coe_top : ((⊤ : Subgroup G) : Set G) = Set.univ := rfl #align subgroup.coe_top Subgroup.coe_top #align add_subgroup.coe_top AddSubgroup.coe_top @[to_additive (attr := simp)] theorem coe_bot : ((⊥ : Subgroup G) : Set G) = {1} := rfl #align subgroup.coe_bot Subgroup.coe_bot #align add_subgroup.coe_bot AddSubgroup.coe_bot @[to_additive] instance : Unique (⊥ : Subgroup G) := ⟨⟨1⟩, fun g => Subtype.ext g.2⟩ @[to_additive (attr := simp)] theorem top_toSubmonoid : (⊤ : Subgroup G).toSubmonoid = ⊤ := rfl #align subgroup.top_to_submonoid Subgroup.top_toSubmonoid #align add_subgroup.top_to_add_submonoid AddSubgroup.top_toAddSubmonoid @[to_additive (attr := simp)] theorem bot_toSubmonoid : (⊥ : Subgroup G).toSubmonoid = ⊥ := rfl #align subgroup.bot_to_submonoid Subgroup.bot_toSubmonoid #align add_subgroup.bot_to_add_submonoid AddSubgroup.bot_toAddSubmonoid @[to_additive] theorem eq_bot_iff_forall : H = ⊥ ↔ ∀ x ∈ H, x = (1 : G) := toSubmonoid_injective.eq_iff.symm.trans <| Submonoid.eq_bot_iff_forall _ #align subgroup.eq_bot_iff_forall Subgroup.eq_bot_iff_forall #align add_subgroup.eq_bot_iff_forall AddSubgroup.eq_bot_iff_forall @[to_additive] theorem eq_bot_of_subsingleton [Subsingleton H] : H = ⊥ := by rw [Subgroup.eq_bot_iff_forall] intro y hy rw [← Subgroup.coe_mk H y hy, Subsingleton.elim (⟨y, hy⟩ : H) 1, Subgroup.coe_one] #align subgroup.eq_bot_of_subsingleton Subgroup.eq_bot_of_subsingleton #align add_subgroup.eq_bot_of_subsingleton AddSubgroup.eq_bot_of_subsingleton @[to_additive (attr := simp, norm_cast)] theorem coe_eq_univ {H : Subgroup G} : (H : Set G) = Set.univ ↔ H = ⊤ := (SetLike.ext'_iff.trans (by rfl)).symm #align subgroup.coe_eq_univ Subgroup.coe_eq_univ #align add_subgroup.coe_eq_univ AddSubgroup.coe_eq_univ @[to_additive] theorem coe_eq_singleton {H : Subgroup G} : (∃ g : G, (H : Set G) = {g}) ↔ H = ⊥ := ⟨fun ⟨g, hg⟩ => haveI : Subsingleton (H : Set G) := by rw [hg] infer_instance H.eq_bot_of_subsingleton, fun h => ⟨1, SetLike.ext'_iff.mp h⟩⟩ #align subgroup.coe_eq_singleton Subgroup.coe_eq_singleton #align add_subgroup.coe_eq_singleton AddSubgroup.coe_eq_singleton @[to_additive] theorem nontrivial_iff_exists_ne_one (H : Subgroup G) : Nontrivial H ↔ ∃ x ∈ H, x ≠ (1 : G) := by rw [Subtype.nontrivial_iff_exists_ne (fun x => x ∈ H) (1 : H)] simp #align subgroup.nontrivial_iff_exists_ne_one Subgroup.nontrivial_iff_exists_ne_one #align add_subgroup.nontrivial_iff_exists_ne_zero AddSubgroup.nontrivial_iff_exists_ne_zero @[to_additive] theorem exists_ne_one_of_nontrivial (H : Subgroup G) [Nontrivial H] : ∃ x ∈ H, x ≠ 1 := by rwa [← Subgroup.nontrivial_iff_exists_ne_one] @[to_additive] theorem nontrivial_iff_ne_bot (H : Subgroup G) : Nontrivial H ↔ H ≠ ⊥ := by rw [nontrivial_iff_exists_ne_one, ne_eq, eq_bot_iff_forall] simp only [ne_eq, not_forall, exists_prop] /-- A subgroup is either the trivial subgroup or nontrivial. -/ @[to_additive "A subgroup is either the trivial subgroup or nontrivial."] theorem bot_or_nontrivial (H : Subgroup G) : H = ⊥ ∨ Nontrivial H := by have := nontrivial_iff_ne_bot H tauto #align subgroup.bot_or_nontrivial Subgroup.bot_or_nontrivial #align add_subgroup.bot_or_nontrivial AddSubgroup.bot_or_nontrivial /-- A subgroup is either the trivial subgroup or contains a non-identity element. -/ @[to_additive "A subgroup is either the trivial subgroup or contains a nonzero element."] theorem bot_or_exists_ne_one (H : Subgroup G) : H = ⊥ ∨ ∃ x ∈ H, x ≠ (1 : G) := by convert H.bot_or_nontrivial rw [nontrivial_iff_exists_ne_one] #align subgroup.bot_or_exists_ne_one Subgroup.bot_or_exists_ne_one #align add_subgroup.bot_or_exists_ne_zero AddSubgroup.bot_or_exists_ne_zero @[to_additive] lemma ne_bot_iff_exists_ne_one {H : Subgroup G} : H ≠ ⊥ ↔ ∃ a : ↥H, a ≠ 1 := by rw [← nontrivial_iff_ne_bot, nontrivial_iff_exists_ne_one] simp only [ne_eq, Subtype.exists, mk_eq_one, exists_prop] /-- The inf of two subgroups is their intersection. -/ @[to_additive "The inf of two `AddSubgroup`s is their intersection."] instance : Inf (Subgroup G) := ⟨fun H₁ H₂ => { H₁.toSubmonoid ⊓ H₂.toSubmonoid with inv_mem' := fun ⟨hx, hx'⟩ => ⟨H₁.inv_mem hx, H₂.inv_mem hx'⟩ }⟩ @[to_additive (attr := simp)] theorem coe_inf (p p' : Subgroup G) : ((p ⊓ p' : Subgroup G) : Set G) = (p : Set G) ∩ p' := rfl #align subgroup.coe_inf Subgroup.coe_inf #align add_subgroup.coe_inf AddSubgroup.coe_inf @[to_additive (attr := simp)] theorem mem_inf {p p' : Subgroup G} {x : G} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := Iff.rfl #align subgroup.mem_inf Subgroup.mem_inf #align add_subgroup.mem_inf AddSubgroup.mem_inf @[to_additive] instance : InfSet (Subgroup G) := ⟨fun s => { (⨅ S ∈ s, Subgroup.toSubmonoid S).copy (⋂ S ∈ s, ↑S) (by simp) with inv_mem' := fun {x} hx => Set.mem_biInter fun i h => i.inv_mem (by apply Set.mem_iInter₂.1 hx i h) }⟩ @[to_additive (attr := simp, norm_cast)] theorem coe_sInf (H : Set (Subgroup G)) : ((sInf H : Subgroup G) : Set G) = ⋂ s ∈ H, ↑s := rfl #align subgroup.coe_Inf Subgroup.coe_sInf #align add_subgroup.coe_Inf AddSubgroup.coe_sInf @[to_additive (attr := simp)] theorem mem_sInf {S : Set (Subgroup G)} {x : G} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := Set.mem_iInter₂ #align subgroup.mem_Inf Subgroup.mem_sInf #align add_subgroup.mem_Inf AddSubgroup.mem_sInf @[to_additive] theorem mem_iInf {ι : Sort*} {S : ι → Subgroup G} {x : G} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by simp only [iInf, mem_sInf, Set.forall_mem_range] #align subgroup.mem_infi Subgroup.mem_iInf #align add_subgroup.mem_infi AddSubgroup.mem_iInf @[to_additive (attr := simp, norm_cast)] theorem coe_iInf {ι : Sort*} {S : ι → Subgroup G} : (↑(⨅ i, S i) : Set G) = ⋂ i, S i := by simp only [iInf, coe_sInf, Set.biInter_range] #align subgroup.coe_infi Subgroup.coe_iInf #align add_subgroup.coe_infi AddSubgroup.coe_iInf /-- Subgroups of a group form a complete lattice. -/ @[to_additive "The `AddSubgroup`s of an `AddGroup` form a complete lattice."] instance : CompleteLattice (Subgroup G) := { completeLatticeOfInf (Subgroup G) fun _s => IsGLB.of_image SetLike.coe_subset_coe isGLB_biInf with bot := ⊥ bot_le := fun S _x hx => (mem_bot.1 hx).symm ▸ S.one_mem top := ⊤ le_top := fun _S x _hx => mem_top x inf := (· ⊓ ·) le_inf := fun _a _b _c ha hb _x hx => ⟨ha hx, hb hx⟩ inf_le_left := fun _a _b _x => And.left inf_le_right := fun _a _b _x => And.right } @[to_additive] theorem mem_sup_left {S T : Subgroup G} : ∀ {x : G}, x ∈ S → x ∈ S ⊔ T := have : S ≤ S ⊔ T := le_sup_left; fun h ↦ this h #align subgroup.mem_sup_left Subgroup.mem_sup_left #align add_subgroup.mem_sup_left AddSubgroup.mem_sup_left @[to_additive] theorem mem_sup_right {S T : Subgroup G} : ∀ {x : G}, x ∈ T → x ∈ S ⊔ T := have : T ≤ S ⊔ T := le_sup_right; fun h ↦ this h #align subgroup.mem_sup_right Subgroup.mem_sup_right #align add_subgroup.mem_sup_right AddSubgroup.mem_sup_right @[to_additive] theorem mul_mem_sup {S T : Subgroup G} {x y : G} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T := (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy) #align subgroup.mul_mem_sup Subgroup.mul_mem_sup #align add_subgroup.add_mem_sup AddSubgroup.add_mem_sup @[to_additive] theorem mem_iSup_of_mem {ι : Sort*} {S : ι → Subgroup G} (i : ι) : ∀ {x : G}, x ∈ S i → x ∈ iSup S := have : S i ≤ iSup S := le_iSup _ _; fun h ↦ this h #align subgroup.mem_supr_of_mem Subgroup.mem_iSup_of_mem #align add_subgroup.mem_supr_of_mem AddSubgroup.mem_iSup_of_mem @[to_additive] theorem mem_sSup_of_mem {S : Set (Subgroup G)} {s : Subgroup G} (hs : s ∈ S) : ∀ {x : G}, x ∈ s → x ∈ sSup S := have : s ≤ sSup S := le_sSup hs; fun h ↦ this h #align subgroup.mem_Sup_of_mem Subgroup.mem_sSup_of_mem #align add_subgroup.mem_Sup_of_mem AddSubgroup.mem_sSup_of_mem @[to_additive (attr := simp)] theorem subsingleton_iff : Subsingleton (Subgroup G) ↔ Subsingleton G := ⟨fun h => ⟨fun x y => have : ∀ i : G, i = 1 := fun i => mem_bot.mp <| Subsingleton.elim (⊤ : Subgroup G) ⊥ ▸ mem_top i (this x).trans (this y).symm⟩, fun h => ⟨fun x y => Subgroup.ext fun i => Subsingleton.elim 1 i ▸ by simp [Subgroup.one_mem]⟩⟩ #align subgroup.subsingleton_iff Subgroup.subsingleton_iff #align add_subgroup.subsingleton_iff AddSubgroup.subsingleton_iff @[to_additive (attr := simp)] theorem nontrivial_iff : Nontrivial (Subgroup G) ↔ Nontrivial G := not_iff_not.mp ((not_nontrivial_iff_subsingleton.trans subsingleton_iff).trans not_nontrivial_iff_subsingleton.symm) #align subgroup.nontrivial_iff Subgroup.nontrivial_iff #align add_subgroup.nontrivial_iff AddSubgroup.nontrivial_iff @[to_additive] instance [Subsingleton G] : Unique (Subgroup G) := ⟨⟨⊥⟩, fun a => @Subsingleton.elim _ (subsingleton_iff.mpr ‹_›) a _⟩ @[to_additive] instance [Nontrivial G] : Nontrivial (Subgroup G) := nontrivial_iff.mpr ‹_› @[to_additive] theorem eq_top_iff' : H = ⊤ ↔ ∀ x : G, x ∈ H := eq_top_iff.trans ⟨fun h m => h <| mem_top m, fun h m _ => h m⟩ #align subgroup.eq_top_iff' Subgroup.eq_top_iff' #align add_subgroup.eq_top_iff' AddSubgroup.eq_top_iff' /-- The `Subgroup` generated by a set. -/ @[to_additive "The `AddSubgroup` generated by a set"] def closure (k : Set G) : Subgroup G := sInf { K | k ⊆ K } #align subgroup.closure Subgroup.closure #align add_subgroup.closure AddSubgroup.closure variable {k : Set G} @[to_additive] theorem mem_closure {x : G} : x ∈ closure k ↔ ∀ K : Subgroup G, k ⊆ K → x ∈ K := mem_sInf #align subgroup.mem_closure Subgroup.mem_closure #align add_subgroup.mem_closure AddSubgroup.mem_closure /-- The subgroup generated by a set includes the set. -/ @[to_additive (attr := simp, aesop safe 20 apply (rule_sets := [SetLike])) "The `AddSubgroup` generated by a set includes the set."] theorem subset_closure : k ⊆ closure k := fun _ hx => mem_closure.2 fun _ hK => hK hx #align subgroup.subset_closure Subgroup.subset_closure #align add_subgroup.subset_closure AddSubgroup.subset_closure @[to_additive] theorem not_mem_of_not_mem_closure {P : G} (hP : P ∉ closure k) : P ∉ k := fun h => hP (subset_closure h) #align subgroup.not_mem_of_not_mem_closure Subgroup.not_mem_of_not_mem_closure #align add_subgroup.not_mem_of_not_mem_closure AddSubgroup.not_mem_of_not_mem_closure open Set /-- A subgroup `K` includes `closure k` if and only if it includes `k`. -/ @[to_additive (attr := simp) "An additive subgroup `K` includes `closure k` if and only if it includes `k`"] theorem closure_le : closure k ≤ K ↔ k ⊆ K := ⟨Subset.trans subset_closure, fun h => sInf_le h⟩ #align subgroup.closure_le Subgroup.closure_le #align add_subgroup.closure_le AddSubgroup.closure_le @[to_additive] theorem closure_eq_of_le (h₁ : k ⊆ K) (h₂ : K ≤ closure k) : closure k = K := le_antisymm ((closure_le <| K).2 h₁) h₂ #align subgroup.closure_eq_of_le Subgroup.closure_eq_of_le #align add_subgroup.closure_eq_of_le AddSubgroup.closure_eq_of_le /-- An induction principle for closure membership. If `p` holds for `1` and all elements of `k`, and is preserved under multiplication and inverse, then `p` holds for all elements of the closure of `k`. -/ @[to_additive (attr := elab_as_elim) "An induction principle for additive closure membership. If `p` holds for `0` and all elements of `k`, and is preserved under addition and inverses, then `p` holds for all elements of the additive closure of `k`."] theorem closure_induction {p : G → Prop} {x} (h : x ∈ closure k) (mem : ∀ x ∈ k, p x) (one : p 1) (mul : ∀ x y, p x → p y → p (x * y)) (inv : ∀ x, p x → p x⁻¹) : p x := (@closure_le _ _ ⟨⟨⟨setOf p, fun {x y} ↦ mul x y⟩, one⟩, fun {x} ↦ inv x⟩ k).2 mem h #align subgroup.closure_induction Subgroup.closure_induction #align add_subgroup.closure_induction AddSubgroup.closure_induction /-- A dependent version of `Subgroup.closure_induction`. -/ @[to_additive (attr := elab_as_elim) "A dependent version of `AddSubgroup.closure_induction`. "] theorem closure_induction' {p : ∀ x, x ∈ closure k → Prop} (mem : ∀ (x) (h : x ∈ k), p x (subset_closure h)) (one : p 1 (one_mem _)) (mul : ∀ x hx y hy, p x hx → p y hy → p (x * y) (mul_mem hx hy)) (inv : ∀ x hx, p x hx → p x⁻¹ (inv_mem hx)) {x} (hx : x ∈ closure k) : p x hx := by refine Exists.elim ?_ fun (hx : x ∈ closure k) (hc : p x hx) => hc exact closure_induction hx (fun x hx => ⟨_, mem x hx⟩) ⟨_, one⟩ (fun x y ⟨hx', hx⟩ ⟨hy', hy⟩ => ⟨_, mul _ _ _ _ hx hy⟩) fun x ⟨hx', hx⟩ => ⟨_, inv _ _ hx⟩ #align subgroup.closure_induction' Subgroup.closure_induction' #align add_subgroup.closure_induction' AddSubgroup.closure_induction' /-- An induction principle for closure membership for predicates with two arguments. -/ @[to_additive (attr := elab_as_elim) "An induction principle for additive closure membership, for predicates with two arguments."] theorem closure_induction₂ {p : G → G → Prop} {x} {y : G} (hx : x ∈ closure k) (hy : y ∈ closure k) (Hk : ∀ x ∈ k, ∀ y ∈ k, p x y) (H1_left : ∀ x, p 1 x) (H1_right : ∀ x, p x 1) (Hmul_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ * x₂) y) (Hmul_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ * y₂)) (Hinv_left : ∀ x y, p x y → p x⁻¹ y) (Hinv_right : ∀ x y, p x y → p x y⁻¹) : p x y := closure_induction hx (fun x xk => closure_induction hy (Hk x xk) (H1_right x) (Hmul_right x) (Hinv_right x)) (H1_left y) (fun z z' => Hmul_left z z' y) fun z => Hinv_left z y #align subgroup.closure_induction₂ Subgroup.closure_induction₂ #align add_subgroup.closure_induction₂ AddSubgroup.closure_induction₂ @[to_additive (attr := simp)] theorem closure_closure_coe_preimage {k : Set G} : closure (((↑) : closure k → G) ⁻¹' k) = ⊤ := eq_top_iff.2 fun x => Subtype.recOn x fun x hx _ => by refine closure_induction' (fun g hg => ?_) ?_ (fun g₁ g₂ hg₁ hg₂ => ?_) (fun g hg => ?_) hx · exact subset_closure hg · exact one_mem _ · exact mul_mem · exact inv_mem #align subgroup.closure_closure_coe_preimage Subgroup.closure_closure_coe_preimage #align add_subgroup.closure_closure_coe_preimage AddSubgroup.closure_closure_coe_preimage /-- If all the elements of a set `s` commute, then `closure s` is a commutative group. -/ @[to_additive "If all the elements of a set `s` commute, then `closure s` is an additive commutative group."] def closureCommGroupOfComm {k : Set G} (hcomm : ∀ x ∈ k, ∀ y ∈ k, x * y = y * x) : CommGroup (closure k) := { (closure k).toGroup with mul_comm := fun x y => by ext simp only [Subgroup.coe_mul] refine closure_induction₂ x.prop y.prop hcomm (fun x => by simp only [mul_one, one_mul]) (fun x => by simp only [mul_one, one_mul]) (fun x y z h₁ h₂ => by rw [mul_assoc, h₂, ← mul_assoc, h₁, mul_assoc]) (fun x y z h₁ h₂ => by rw [← mul_assoc, h₁, mul_assoc, h₂, ← mul_assoc]) (fun x y h => by rw [inv_mul_eq_iff_eq_mul, ← mul_assoc, h, mul_assoc, mul_inv_self, mul_one]) fun x y h => by rw [mul_inv_eq_iff_eq_mul, mul_assoc, h, ← mul_assoc, inv_mul_self, one_mul] } #align subgroup.closure_comm_group_of_comm Subgroup.closureCommGroupOfComm #align add_subgroup.closure_add_comm_group_of_comm AddSubgroup.closureAddCommGroupOfComm variable (G) /-- `closure` forms a Galois insertion with the coercion to set. -/ @[to_additive "`closure` forms a Galois insertion with the coercion to set."] protected def gi : GaloisInsertion (@closure G _) (↑) where choice s _ := closure s gc s t := @closure_le _ _ t s le_l_u _s := subset_closure choice_eq _s _h := rfl #align subgroup.gi Subgroup.gi #align add_subgroup.gi AddSubgroup.gi variable {G} /-- Subgroup closure of a set is monotone in its argument: if `h ⊆ k`, then `closure h ≤ closure k`. -/ @[to_additive "Additive subgroup closure of a set is monotone in its argument: if `h ⊆ k`, then `closure h ≤ closure k`"] theorem closure_mono ⦃h k : Set G⦄ (h' : h ⊆ k) : closure h ≤ closure k := (Subgroup.gi G).gc.monotone_l h' #align subgroup.closure_mono Subgroup.closure_mono #align add_subgroup.closure_mono AddSubgroup.closure_mono /-- Closure of a subgroup `K` equals `K`. -/ @[to_additive (attr := simp) "Additive closure of an additive subgroup `K` equals `K`"] theorem closure_eq : closure (K : Set G) = K := (Subgroup.gi G).l_u_eq K #align subgroup.closure_eq Subgroup.closure_eq #align add_subgroup.closure_eq AddSubgroup.closure_eq @[to_additive (attr := simp)] theorem closure_empty : closure (∅ : Set G) = ⊥ := (Subgroup.gi G).gc.l_bot #align subgroup.closure_empty Subgroup.closure_empty #align add_subgroup.closure_empty AddSubgroup.closure_empty @[to_additive (attr := simp)] theorem closure_univ : closure (univ : Set G) = ⊤ := @coe_top G _ ▸ closure_eq ⊤ #align subgroup.closure_univ Subgroup.closure_univ #align add_subgroup.closure_univ AddSubgroup.closure_univ @[to_additive] theorem closure_union (s t : Set G) : closure (s ∪ t) = closure s ⊔ closure t := (Subgroup.gi G).gc.l_sup #align subgroup.closure_union Subgroup.closure_union #align add_subgroup.closure_union AddSubgroup.closure_union @[to_additive] theorem sup_eq_closure (H H' : Subgroup G) : H ⊔ H' = closure ((H : Set G) ∪ (H' : Set G)) := by simp_rw [closure_union, closure_eq] @[to_additive] theorem closure_iUnion {ι} (s : ι → Set G) : closure (⋃ i, s i) = ⨆ i, closure (s i) := (Subgroup.gi G).gc.l_iSup #align subgroup.closure_Union Subgroup.closure_iUnion #align add_subgroup.closure_Union AddSubgroup.closure_iUnion @[to_additive (attr := simp)] theorem closure_eq_bot_iff : closure k = ⊥ ↔ k ⊆ {1} := le_bot_iff.symm.trans <| closure_le _ #align subgroup.closure_eq_bot_iff Subgroup.closure_eq_bot_iff #align add_subgroup.closure_eq_bot_iff AddSubgroup.closure_eq_bot_iff @[to_additive] theorem iSup_eq_closure {ι : Sort*} (p : ι → Subgroup G) : ⨆ i, p i = closure (⋃ i, (p i : Set G)) := by simp_rw [closure_iUnion, closure_eq] #align subgroup.supr_eq_closure Subgroup.iSup_eq_closure #align add_subgroup.supr_eq_closure AddSubgroup.iSup_eq_closure /-- The subgroup generated by an element of a group equals the set of integer number powers of the element. -/ @[to_additive "The `AddSubgroup` generated by an element of an `AddGroup` equals the set of natural number multiples of the element."] theorem mem_closure_singleton {x y : G} : y ∈ closure ({x} : Set G) ↔ ∃ n : ℤ, x ^ n = y := by refine ⟨fun hy => closure_induction hy ?_ ?_ ?_ ?_, fun ⟨n, hn⟩ => hn ▸ zpow_mem (subset_closure <| mem_singleton x) n⟩ · intro y hy rw [eq_of_mem_singleton hy] exact ⟨1, zpow_one x⟩ · exact ⟨0, zpow_zero x⟩ · rintro _ _ ⟨n, rfl⟩ ⟨m, rfl⟩ exact ⟨n + m, zpow_add x n m⟩ rintro _ ⟨n, rfl⟩ exact ⟨-n, zpow_neg x n⟩ #align subgroup.mem_closure_singleton Subgroup.mem_closure_singleton #align add_subgroup.mem_closure_singleton AddSubgroup.mem_closure_singleton @[to_additive] theorem closure_singleton_one : closure ({1} : Set G) = ⊥ := by simp [eq_bot_iff_forall, mem_closure_singleton] #align subgroup.closure_singleton_one Subgroup.closure_singleton_one #align add_subgroup.closure_singleton_zero AddSubgroup.closure_singleton_zero @[to_additive] theorem le_closure_toSubmonoid (S : Set G) : Submonoid.closure S ≤ (closure S).toSubmonoid := Submonoid.closure_le.2 subset_closure #align subgroup.le_closure_to_submonoid Subgroup.le_closure_toSubmonoid #align add_subgroup.le_closure_to_add_submonoid AddSubgroup.le_closure_toAddSubmonoid @[to_additive] theorem closure_eq_top_of_mclosure_eq_top {S : Set G} (h : Submonoid.closure S = ⊤) : closure S = ⊤ := (eq_top_iff' _).2 fun _ => le_closure_toSubmonoid _ <| h.symm ▸ trivial #align subgroup.closure_eq_top_of_mclosure_eq_top Subgroup.closure_eq_top_of_mclosure_eq_top #align add_subgroup.closure_eq_top_of_mclosure_eq_top AddSubgroup.closure_eq_top_of_mclosure_eq_top @[to_additive] theorem mem_iSup_of_directed {ι} [hι : Nonempty ι] {K : ι → Subgroup G} (hK : Directed (· ≤ ·) K) {x : G} : x ∈ (iSup K : Subgroup G) ↔ ∃ i, x ∈ K i := by refine ⟨?_, fun ⟨i, hi⟩ ↦ le_iSup K i hi⟩ suffices x ∈ closure (⋃ i, (K i : Set G)) → ∃ i, x ∈ K i by simpa only [closure_iUnion, closure_eq (K _)] using this refine fun hx ↦ closure_induction hx (fun _ ↦ mem_iUnion.1) ?_ ?_ ?_ · exact hι.elim fun i ↦ ⟨i, (K i).one_mem⟩ · rintro x y ⟨i, hi⟩ ⟨j, hj⟩ rcases hK i j with ⟨k, hki, hkj⟩ exact ⟨k, mul_mem (hki hi) (hkj hj)⟩ · rintro _ ⟨i, hi⟩ exact ⟨i, inv_mem hi⟩ #align subgroup.mem_supr_of_directed Subgroup.mem_iSup_of_directed #align add_subgroup.mem_supr_of_directed AddSubgroup.mem_iSup_of_directed @[to_additive] theorem coe_iSup_of_directed {ι} [Nonempty ι] {S : ι → Subgroup G} (hS : Directed (· ≤ ·) S) : ((⨆ i, S i : Subgroup G) : Set G) = ⋃ i, S i := Set.ext fun x ↦ by simp [mem_iSup_of_directed hS] #align subgroup.coe_supr_of_directed Subgroup.coe_iSup_of_directed #align add_subgroup.coe_supr_of_directed AddSubgroup.coe_iSup_of_directed @[to_additive] theorem mem_sSup_of_directedOn {K : Set (Subgroup G)} (Kne : K.Nonempty) (hK : DirectedOn (· ≤ ·) K) {x : G} : x ∈ sSup K ↔ ∃ s ∈ K, x ∈ s := by haveI : Nonempty K := Kne.to_subtype simp only [sSup_eq_iSup', mem_iSup_of_directed hK.directed_val, SetCoe.exists, Subtype.coe_mk, exists_prop] #align subgroup.mem_Sup_of_directed_on Subgroup.mem_sSup_of_directedOn #align add_subgroup.mem_Sup_of_directed_on AddSubgroup.mem_sSup_of_directedOn variable {N : Type*} [Group N] {P : Type*} [Group P] /-- The preimage of a subgroup along a monoid homomorphism is a subgroup. -/ @[to_additive "The preimage of an `AddSubgroup` along an `AddMonoid` homomorphism is an `AddSubgroup`."] def comap {N : Type*} [Group N] (f : G →* N) (H : Subgroup N) : Subgroup G := { H.toSubmonoid.comap f with carrier := f ⁻¹' H inv_mem' := fun {a} ha => show f a⁻¹ ∈ H by rw [f.map_inv]; exact H.inv_mem ha } #align subgroup.comap Subgroup.comap #align add_subgroup.comap AddSubgroup.comap @[to_additive (attr := simp)] theorem coe_comap (K : Subgroup N) (f : G →* N) : (K.comap f : Set G) = f ⁻¹' K := rfl #align subgroup.coe_comap Subgroup.coe_comap #align add_subgroup.coe_comap AddSubgroup.coe_comap @[simp] theorem toAddSubgroup_comap {G₂ : Type*} [Group G₂] (f : G →* G₂) (s : Subgroup G₂) : s.toAddSubgroup.comap (MonoidHom.toAdditive f) = Subgroup.toAddSubgroup (s.comap f) := rfl @[simp] theorem _root_.AddSubgroup.toSubgroup_comap {A A₂ : Type*} [AddGroup A] [AddGroup A₂] (f : A →+ A₂) (s : AddSubgroup A₂) : s.toSubgroup.comap (AddMonoidHom.toMultiplicative f) = AddSubgroup.toSubgroup (s.comap f) := rfl @[to_additive (attr := simp)] theorem mem_comap {K : Subgroup N} {f : G →* N} {x : G} : x ∈ K.comap f ↔ f x ∈ K := Iff.rfl #align subgroup.mem_comap Subgroup.mem_comap #align add_subgroup.mem_comap AddSubgroup.mem_comap @[to_additive] theorem comap_mono {f : G →* N} {K K' : Subgroup N} : K ≤ K' → comap f K ≤ comap f K' := preimage_mono #align subgroup.comap_mono Subgroup.comap_mono #align add_subgroup.comap_mono AddSubgroup.comap_mono @[to_additive] theorem comap_comap (K : Subgroup P) (g : N →* P) (f : G →* N) : (K.comap g).comap f = K.comap (g.comp f) := rfl #align subgroup.comap_comap Subgroup.comap_comap #align add_subgroup.comap_comap AddSubgroup.comap_comap @[to_additive (attr := simp)] theorem comap_id (K : Subgroup N) : K.comap (MonoidHom.id _) = K := by ext rfl #align subgroup.comap_id Subgroup.comap_id #align add_subgroup.comap_id AddSubgroup.comap_id /-- The image of a subgroup along a monoid homomorphism is a subgroup. -/ @[to_additive "The image of an `AddSubgroup` along an `AddMonoid` homomorphism is an `AddSubgroup`."] def map (f : G →* N) (H : Subgroup G) : Subgroup N := { H.toSubmonoid.map f with carrier := f '' H inv_mem' := by rintro _ ⟨x, hx, rfl⟩ exact ⟨x⁻¹, H.inv_mem hx, f.map_inv x⟩ } #align subgroup.map Subgroup.map #align add_subgroup.map AddSubgroup.map @[to_additive (attr := simp)] theorem coe_map (f : G →* N) (K : Subgroup G) : (K.map f : Set N) = f '' K := rfl #align subgroup.coe_map Subgroup.coe_map #align add_subgroup.coe_map AddSubgroup.coe_map @[to_additive (attr := simp)] theorem mem_map {f : G →* N} {K : Subgroup G} {y : N} : y ∈ K.map f ↔ ∃ x ∈ K, f x = y := Iff.rfl #align subgroup.mem_map Subgroup.mem_map #align add_subgroup.mem_map AddSubgroup.mem_map @[to_additive] theorem mem_map_of_mem (f : G →* N) {K : Subgroup G} {x : G} (hx : x ∈ K) : f x ∈ K.map f := mem_image_of_mem f hx #align subgroup.mem_map_of_mem Subgroup.mem_map_of_mem #align add_subgroup.mem_map_of_mem AddSubgroup.mem_map_of_mem @[to_additive] theorem apply_coe_mem_map (f : G →* N) (K : Subgroup G) (x : K) : f x ∈ K.map f := mem_map_of_mem f x.prop #align subgroup.apply_coe_mem_map Subgroup.apply_coe_mem_map #align add_subgroup.apply_coe_mem_map AddSubgroup.apply_coe_mem_map @[to_additive] theorem map_mono {f : G →* N} {K K' : Subgroup G} : K ≤ K' → map f K ≤ map f K' := image_subset _ #align subgroup.map_mono Subgroup.map_mono #align add_subgroup.map_mono AddSubgroup.map_mono @[to_additive (attr := simp)] theorem map_id : K.map (MonoidHom.id G) = K := SetLike.coe_injective <| image_id _ #align subgroup.map_id Subgroup.map_id #align add_subgroup.map_id AddSubgroup.map_id @[to_additive] theorem map_map (g : N →* P) (f : G →* N) : (K.map f).map g = K.map (g.comp f) := SetLike.coe_injective <| image_image _ _ _ #align subgroup.map_map Subgroup.map_map #align add_subgroup.map_map AddSubgroup.map_map @[to_additive (attr := simp)] theorem map_one_eq_bot : K.map (1 : G →* N) = ⊥ := eq_bot_iff.mpr <| by rintro x ⟨y, _, rfl⟩ simp #align subgroup.map_one_eq_bot Subgroup.map_one_eq_bot #align add_subgroup.map_zero_eq_bot AddSubgroup.map_zero_eq_bot @[to_additive] theorem mem_map_equiv {f : G ≃* N} {K : Subgroup G} {x : N} : x ∈ K.map f.toMonoidHom ↔ f.symm x ∈ K := by erw [@Set.mem_image_equiv _ _ (↑K) f.toEquiv x]; rfl #align subgroup.mem_map_equiv Subgroup.mem_map_equiv #align add_subgroup.mem_map_equiv AddSubgroup.mem_map_equiv -- The simpNF linter says that the LHS can be simplified via `Subgroup.mem_map`. -- However this is a higher priority lemma. -- https://github.com/leanprover/std4/issues/207 @[to_additive (attr := simp 1100, nolint simpNF)] theorem mem_map_iff_mem {f : G →* N} (hf : Function.Injective f) {K : Subgroup G} {x : G} : f x ∈ K.map f ↔ x ∈ K := hf.mem_set_image #align subgroup.mem_map_iff_mem Subgroup.mem_map_iff_mem #align add_subgroup.mem_map_iff_mem AddSubgroup.mem_map_iff_mem @[to_additive] theorem map_equiv_eq_comap_symm' (f : G ≃* N) (K : Subgroup G) : K.map f.toMonoidHom = K.comap f.symm.toMonoidHom := SetLike.coe_injective (f.toEquiv.image_eq_preimage K) #align subgroup.map_equiv_eq_comap_symm Subgroup.map_equiv_eq_comap_symm' #align add_subgroup.map_equiv_eq_comap_symm AddSubgroup.map_equiv_eq_comap_symm' @[to_additive] theorem map_equiv_eq_comap_symm (f : G ≃* N) (K : Subgroup G) : K.map f = K.comap (G := N) f.symm := map_equiv_eq_comap_symm' _ _ @[to_additive] theorem comap_equiv_eq_map_symm (f : N ≃* G) (K : Subgroup G) : K.comap (G := N) f = K.map f.symm := (map_equiv_eq_comap_symm f.symm K).symm @[to_additive] theorem comap_equiv_eq_map_symm' (f : N ≃* G) (K : Subgroup G) : K.comap f.toMonoidHom = K.map f.symm.toMonoidHom := (map_equiv_eq_comap_symm f.symm K).symm #align subgroup.comap_equiv_eq_map_symm Subgroup.comap_equiv_eq_map_symm' #align add_subgroup.comap_equiv_eq_map_symm AddSubgroup.comap_equiv_eq_map_symm' @[to_additive] theorem map_symm_eq_iff_map_eq {H : Subgroup N} {e : G ≃* N} : H.map ↑e.symm = K ↔ K.map ↑e = H := by constructor <;> rintro rfl · rw [map_map, ← MulEquiv.coe_monoidHom_trans, MulEquiv.symm_trans_self, MulEquiv.coe_monoidHom_refl, map_id] · rw [map_map, ← MulEquiv.coe_monoidHom_trans, MulEquiv.self_trans_symm, MulEquiv.coe_monoidHom_refl, map_id] #align subgroup.map_symm_eq_iff_map_eq Subgroup.map_symm_eq_iff_map_eq #align add_subgroup.map_symm_eq_iff_map_eq AddSubgroup.map_symm_eq_iff_map_eq @[to_additive] theorem map_le_iff_le_comap {f : G →* N} {K : Subgroup G} {H : Subgroup N} : K.map f ≤ H ↔ K ≤ H.comap f := image_subset_iff #align subgroup.map_le_iff_le_comap Subgroup.map_le_iff_le_comap #align add_subgroup.map_le_iff_le_comap AddSubgroup.map_le_iff_le_comap @[to_additive] theorem gc_map_comap (f : G →* N) : GaloisConnection (map f) (comap f) := fun _ _ => map_le_iff_le_comap #align subgroup.gc_map_comap Subgroup.gc_map_comap #align add_subgroup.gc_map_comap AddSubgroup.gc_map_comap @[to_additive] theorem map_sup (H K : Subgroup G) (f : G →* N) : (H ⊔ K).map f = H.map f ⊔ K.map f := (gc_map_comap f).l_sup #align subgroup.map_sup Subgroup.map_sup #align add_subgroup.map_sup AddSubgroup.map_sup @[to_additive] theorem map_iSup {ι : Sort*} (f : G →* N) (s : ι → Subgroup G) : (iSup s).map f = ⨆ i, (s i).map f := (gc_map_comap f).l_iSup #align subgroup.map_supr Subgroup.map_iSup #align add_subgroup.map_supr AddSubgroup.map_iSup @[to_additive] theorem comap_sup_comap_le (H K : Subgroup N) (f : G →* N) : comap f H ⊔ comap f K ≤ comap f (H ⊔ K) := Monotone.le_map_sup (fun _ _ => comap_mono) H K #align subgroup.comap_sup_comap_le Subgroup.comap_sup_comap_le #align add_subgroup.comap_sup_comap_le AddSubgroup.comap_sup_comap_le @[to_additive] theorem iSup_comap_le {ι : Sort*} (f : G →* N) (s : ι → Subgroup N) : ⨆ i, (s i).comap f ≤ (iSup s).comap f := Monotone.le_map_iSup fun _ _ => comap_mono #align subgroup.supr_comap_le Subgroup.iSup_comap_le #align add_subgroup.supr_comap_le AddSubgroup.iSup_comap_le @[to_additive] theorem comap_inf (H K : Subgroup N) (f : G →* N) : (H ⊓ K).comap f = H.comap f ⊓ K.comap f := (gc_map_comap f).u_inf #align subgroup.comap_inf Subgroup.comap_inf #align add_subgroup.comap_inf AddSubgroup.comap_inf @[to_additive] theorem comap_iInf {ι : Sort*} (f : G →* N) (s : ι → Subgroup N) : (iInf s).comap f = ⨅ i, (s i).comap f := (gc_map_comap f).u_iInf #align subgroup.comap_infi Subgroup.comap_iInf #align add_subgroup.comap_infi AddSubgroup.comap_iInf @[to_additive] theorem map_inf_le (H K : Subgroup G) (f : G →* N) : map f (H ⊓ K) ≤ map f H ⊓ map f K := le_inf (map_mono inf_le_left) (map_mono inf_le_right) #align subgroup.map_inf_le Subgroup.map_inf_le #align add_subgroup.map_inf_le AddSubgroup.map_inf_le @[to_additive] theorem map_inf_eq (H K : Subgroup G) (f : G →* N) (hf : Function.Injective f) : map f (H ⊓ K) = map f H ⊓ map f K := by rw [← SetLike.coe_set_eq] simp [Set.image_inter hf] #align subgroup.map_inf_eq Subgroup.map_inf_eq #align add_subgroup.map_inf_eq AddSubgroup.map_inf_eq @[to_additive (attr := simp)] theorem map_bot (f : G →* N) : (⊥ : Subgroup G).map f = ⊥ := (gc_map_comap f).l_bot #align subgroup.map_bot Subgroup.map_bot #align add_subgroup.map_bot AddSubgroup.map_bot @[to_additive (attr := simp)] theorem map_top_of_surjective (f : G →* N) (h : Function.Surjective f) : Subgroup.map f ⊤ = ⊤ := by rw [eq_top_iff] intro x _ obtain ⟨y, hy⟩ := h x exact ⟨y, trivial, hy⟩ #align subgroup.map_top_of_surjective Subgroup.map_top_of_surjective #align add_subgroup.map_top_of_surjective AddSubgroup.map_top_of_surjective @[to_additive (attr := simp)] theorem comap_top (f : G →* N) : (⊤ : Subgroup N).comap f = ⊤ := (gc_map_comap f).u_top #align subgroup.comap_top Subgroup.comap_top #align add_subgroup.comap_top AddSubgroup.comap_top /-- For any subgroups `H` and `K`, view `H ⊓ K` as a subgroup of `K`. -/ @[to_additive "For any subgroups `H` and `K`, view `H ⊓ K` as a subgroup of `K`."] def subgroupOf (H K : Subgroup G) : Subgroup K := H.comap K.subtype #align subgroup.subgroup_of Subgroup.subgroupOf #align add_subgroup.add_subgroup_of AddSubgroup.addSubgroupOf /-- If `H ≤ K`, then `H` as a subgroup of `K` is isomorphic to `H`. -/ @[to_additive (attr := simps) "If `H ≤ K`, then `H` as a subgroup of `K` is isomorphic to `H`."] def subgroupOfEquivOfLe {G : Type*} [Group G] {H K : Subgroup G} (h : H ≤ K) : H.subgroupOf K ≃* H where toFun g := ⟨g.1, g.2⟩ invFun g := ⟨⟨g.1, h g.2⟩, g.2⟩ left_inv _g := Subtype.ext (Subtype.ext rfl) right_inv _g := Subtype.ext rfl map_mul' _g _h := rfl #align subgroup.subgroup_of_equiv_of_le Subgroup.subgroupOfEquivOfLe #align add_subgroup.add_subgroup_of_equiv_of_le AddSubgroup.addSubgroupOfEquivOfLe #align subgroup.subgroup_of_equiv_of_le_symm_apply_coe_coe Subgroup.subgroupOfEquivOfLe_symm_apply_coe_coe #align add_subgroup.subgroup_of_equiv_of_le_symm_apply_coe_coe AddSubgroup.addSubgroupOfEquivOfLe_symm_apply_coe_coe #align subgroup.subgroup_of_equiv_of_le_apply_coe Subgroup.subgroupOfEquivOfLe_apply_coe #align add_subgroup.subgroup_of_equiv_of_le_apply_coe AddSubgroup.addSubgroupOfEquivOfLe_apply_coe @[to_additive (attr := simp)] theorem comap_subtype (H K : Subgroup G) : H.comap K.subtype = H.subgroupOf K := rfl #align subgroup.comap_subtype Subgroup.comap_subtype #align add_subgroup.comap_subtype AddSubgroup.comap_subtype @[to_additive (attr := simp)] theorem comap_inclusion_subgroupOf {K₁ K₂ : Subgroup G} (h : K₁ ≤ K₂) (H : Subgroup G) : (H.subgroupOf K₂).comap (inclusion h) = H.subgroupOf K₁ := rfl #align subgroup.comap_inclusion_subgroup_of Subgroup.comap_inclusion_subgroupOf #align add_subgroup.comap_inclusion_add_subgroup_of AddSubgroup.comap_inclusion_addSubgroupOf @[to_additive] theorem coe_subgroupOf (H K : Subgroup G) : (H.subgroupOf K : Set K) = K.subtype ⁻¹' H := rfl #align subgroup.coe_subgroup_of Subgroup.coe_subgroupOf #align add_subgroup.coe_add_subgroup_of AddSubgroup.coe_addSubgroupOf @[to_additive] theorem mem_subgroupOf {H K : Subgroup G} {h : K} : h ∈ H.subgroupOf K ↔ (h : G) ∈ H := Iff.rfl #align subgroup.mem_subgroup_of Subgroup.mem_subgroupOf #align add_subgroup.mem_add_subgroup_of AddSubgroup.mem_addSubgroupOf -- TODO(kmill): use `K ⊓ H` order for RHS to match `Subtype.image_preimage_coe` @[to_additive (attr := simp)] theorem subgroupOf_map_subtype (H K : Subgroup G) : (H.subgroupOf K).map K.subtype = H ⊓ K := SetLike.ext' <| by refine Subtype.image_preimage_coe _ _ |>.trans ?_; apply Set.inter_comm #align subgroup.subgroup_of_map_subtype Subgroup.subgroupOf_map_subtype #align add_subgroup.add_subgroup_of_map_subtype AddSubgroup.addSubgroupOf_map_subtype @[to_additive (attr := simp)] theorem bot_subgroupOf : (⊥ : Subgroup G).subgroupOf H = ⊥ := Eq.symm (Subgroup.ext fun _g => Subtype.ext_iff) #align subgroup.bot_subgroup_of Subgroup.bot_subgroupOf #align add_subgroup.bot_add_subgroup_of AddSubgroup.bot_addSubgroupOf @[to_additive (attr := simp)] theorem top_subgroupOf : (⊤ : Subgroup G).subgroupOf H = ⊤ := rfl #align subgroup.top_subgroup_of Subgroup.top_subgroupOf #align add_subgroup.top_add_subgroup_of AddSubgroup.top_addSubgroupOf @[to_additive] theorem subgroupOf_bot_eq_bot : H.subgroupOf ⊥ = ⊥ := Subsingleton.elim _ _ #align subgroup.subgroup_of_bot_eq_bot Subgroup.subgroupOf_bot_eq_bot #align add_subgroup.add_subgroup_of_bot_eq_bot AddSubgroup.addSubgroupOf_bot_eq_bot @[to_additive] theorem subgroupOf_bot_eq_top : H.subgroupOf ⊥ = ⊤ := Subsingleton.elim _ _ #align subgroup.subgroup_of_bot_eq_top Subgroup.subgroupOf_bot_eq_top #align add_subgroup.add_subgroup_of_bot_eq_top AddSubgroup.addSubgroupOf_bot_eq_top @[to_additive (attr := simp)] theorem subgroupOf_self : H.subgroupOf H = ⊤ := top_unique fun g _hg => g.2 #align subgroup.subgroup_of_self Subgroup.subgroupOf_self #align add_subgroup.add_subgroup_of_self AddSubgroup.addSubgroupOf_self @[to_additive (attr := simp)] theorem subgroupOf_inj {H₁ H₂ K : Subgroup G} : H₁.subgroupOf K = H₂.subgroupOf K ↔ H₁ ⊓ K = H₂ ⊓ K := by simpa only [SetLike.ext_iff, mem_inf, mem_subgroupOf, and_congr_left_iff] using Subtype.forall #align subgroup.subgroup_of_inj Subgroup.subgroupOf_inj #align add_subgroup.add_subgroup_of_inj AddSubgroup.addSubgroupOf_inj @[to_additive (attr := simp)] theorem inf_subgroupOf_right (H K : Subgroup G) : (H ⊓ K).subgroupOf K = H.subgroupOf K := subgroupOf_inj.2 (inf_right_idem _ _) #align subgroup.inf_subgroup_of_right Subgroup.inf_subgroupOf_right #align add_subgroup.inf_add_subgroup_of_right AddSubgroup.inf_addSubgroupOf_right @[to_additive (attr := simp)] theorem inf_subgroupOf_left (H K : Subgroup G) : (K ⊓ H).subgroupOf K = H.subgroupOf K := by rw [inf_comm, inf_subgroupOf_right] #align subgroup.inf_subgroup_of_left Subgroup.inf_subgroupOf_left #align add_subgroup.inf_add_subgroup_of_left AddSubgroup.inf_addSubgroupOf_left @[to_additive (attr := simp)] theorem subgroupOf_eq_bot {H K : Subgroup G} : H.subgroupOf K = ⊥ ↔ Disjoint H K := by rw [disjoint_iff, ← bot_subgroupOf, subgroupOf_inj, bot_inf_eq] #align subgroup.subgroup_of_eq_bot Subgroup.subgroupOf_eq_bot #align add_subgroup.add_subgroup_of_eq_bot AddSubgroup.addSubgroupOf_eq_bot @[to_additive (attr := simp)] theorem subgroupOf_eq_top {H K : Subgroup G} : H.subgroupOf K = ⊤ ↔ K ≤ H := by rw [← top_subgroupOf, subgroupOf_inj, top_inf_eq, inf_eq_right] #align subgroup.subgroup_of_eq_top Subgroup.subgroupOf_eq_top #align add_subgroup.add_subgroup_of_eq_top AddSubgroup.addSubgroupOf_eq_top /-- Given `Subgroup`s `H`, `K` of groups `G`, `N` respectively, `H × K` as a subgroup of `G × N`. -/ @[to_additive prod "Given `AddSubgroup`s `H`, `K` of `AddGroup`s `A`, `B` respectively, `H × K` as an `AddSubgroup` of `A × B`."] def prod (H : Subgroup G) (K : Subgroup N) : Subgroup (G × N) := { Submonoid.prod H.toSubmonoid K.toSubmonoid with inv_mem' := fun hx => ⟨H.inv_mem' hx.1, K.inv_mem' hx.2⟩ } #align subgroup.prod Subgroup.prod #align add_subgroup.prod AddSubgroup.prod @[to_additive coe_prod] theorem coe_prod (H : Subgroup G) (K : Subgroup N) : (H.prod K : Set (G × N)) = (H : Set G) ×ˢ (K : Set N) := rfl #align subgroup.coe_prod Subgroup.coe_prod #align add_subgroup.coe_prod AddSubgroup.coe_prod @[to_additive mem_prod] theorem mem_prod {H : Subgroup G} {K : Subgroup N} {p : G × N} : p ∈ H.prod K ↔ p.1 ∈ H ∧ p.2 ∈ K := Iff.rfl #align subgroup.mem_prod Subgroup.mem_prod #align add_subgroup.mem_prod AddSubgroup.mem_prod @[to_additive prod_mono] theorem prod_mono : ((· ≤ ·) ⇒ (· ≤ ·) ⇒ (· ≤ ·)) (@prod G _ N _) (@prod G _ N _) := fun _s _s' hs _t _t' ht => Set.prod_mono hs ht #align subgroup.prod_mono Subgroup.prod_mono #align add_subgroup.prod_mono AddSubgroup.prod_mono @[to_additive prod_mono_right] theorem prod_mono_right (K : Subgroup G) : Monotone fun t : Subgroup N => K.prod t := prod_mono (le_refl K) #align subgroup.prod_mono_right Subgroup.prod_mono_right #align add_subgroup.prod_mono_right AddSubgroup.prod_mono_right @[to_additive prod_mono_left] theorem prod_mono_left (H : Subgroup N) : Monotone fun K : Subgroup G => K.prod H := fun _ _ hs => prod_mono hs (le_refl H) #align subgroup.prod_mono_left Subgroup.prod_mono_left #align add_subgroup.prod_mono_left AddSubgroup.prod_mono_left @[to_additive prod_top] theorem prod_top (K : Subgroup G) : K.prod (⊤ : Subgroup N) = K.comap (MonoidHom.fst G N) := ext fun x => by simp [mem_prod, MonoidHom.coe_fst] #align subgroup.prod_top Subgroup.prod_top #align add_subgroup.prod_top AddSubgroup.prod_top @[to_additive top_prod] theorem top_prod (H : Subgroup N) : (⊤ : Subgroup G).prod H = H.comap (MonoidHom.snd G N) := ext fun x => by simp [mem_prod, MonoidHom.coe_snd] #align subgroup.top_prod Subgroup.top_prod #align add_subgroup.top_prod AddSubgroup.top_prod @[to_additive (attr := simp) top_prod_top] theorem top_prod_top : (⊤ : Subgroup G).prod (⊤ : Subgroup N) = ⊤ := (top_prod _).trans <| comap_top _ #align subgroup.top_prod_top Subgroup.top_prod_top #align add_subgroup.top_prod_top AddSubgroup.top_prod_top @[to_additive] theorem bot_prod_bot : (⊥ : Subgroup G).prod (⊥ : Subgroup N) = ⊥ := SetLike.coe_injective <| by simp [coe_prod, Prod.one_eq_mk] #align subgroup.bot_prod_bot Subgroup.bot_prod_bot #align add_subgroup.bot_sum_bot AddSubgroup.bot_sum_bot @[to_additive le_prod_iff] theorem le_prod_iff {H : Subgroup G} {K : Subgroup N} {J : Subgroup (G × N)} : J ≤ H.prod K ↔ map (MonoidHom.fst G N) J ≤ H ∧ map (MonoidHom.snd G N) J ≤ K := by simpa only [← Subgroup.toSubmonoid_le] using Submonoid.le_prod_iff #align subgroup.le_prod_iff Subgroup.le_prod_iff #align add_subgroup.le_prod_iff AddSubgroup.le_prod_iff @[to_additive prod_le_iff] theorem prod_le_iff {H : Subgroup G} {K : Subgroup N} {J : Subgroup (G × N)} : H.prod K ≤ J ↔ map (MonoidHom.inl G N) H ≤ J ∧ map (MonoidHom.inr G N) K ≤ J := by simpa only [← Subgroup.toSubmonoid_le] using Submonoid.prod_le_iff #align subgroup.prod_le_iff Subgroup.prod_le_iff #align add_subgroup.prod_le_iff AddSubgroup.prod_le_iff @[to_additive (attr := simp) prod_eq_bot_iff] theorem prod_eq_bot_iff {H : Subgroup G} {K : Subgroup N} : H.prod K = ⊥ ↔ H = ⊥ ∧ K = ⊥ := by simpa only [← Subgroup.toSubmonoid_eq] using Submonoid.prod_eq_bot_iff #align subgroup.prod_eq_bot_iff Subgroup.prod_eq_bot_iff #align add_subgroup.prod_eq_bot_iff AddSubgroup.prod_eq_bot_iff /-- Product of subgroups is isomorphic to their product as groups. -/ @[to_additive prodEquiv "Product of additive subgroups is isomorphic to their product as additive groups"] def prodEquiv (H : Subgroup G) (K : Subgroup N) : H.prod K ≃* H × K := { Equiv.Set.prod (H : Set G) (K : Set N) with map_mul' := fun _ _ => rfl } #align subgroup.prod_equiv Subgroup.prodEquiv #align add_subgroup.prod_equiv AddSubgroup.prodEquiv section Pi variable {η : Type*} {f : η → Type*} -- defined here and not in Algebra.Group.Submonoid.Operations to have access to Algebra.Group.Pi /-- A version of `Set.pi` for submonoids. Given an index set `I` and a family of submodules `s : Π i, Submonoid f i`, `pi I s` is the submonoid of dependent functions `f : Π i, f i` such that `f i` belongs to `Pi I s` whenever `i ∈ I`. -/ @[to_additive "A version of `Set.pi` for `AddSubmonoid`s. Given an index set `I` and a family of submodules `s : Π i, AddSubmonoid f i`, `pi I s` is the `AddSubmonoid` of dependent functions `f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`."] def _root_.Submonoid.pi [∀ i, MulOneClass (f i)] (I : Set η) (s : ∀ i, Submonoid (f i)) : Submonoid (∀ i, f i) where carrier := I.pi fun i => (s i).carrier one_mem' i _ := (s i).one_mem mul_mem' hp hq i hI := (s i).mul_mem (hp i hI) (hq i hI) #align submonoid.pi Submonoid.pi #align add_submonoid.pi AddSubmonoid.pi variable [∀ i, Group (f i)] /-- A version of `Set.pi` for subgroups. Given an index set `I` and a family of submodules `s : Π i, Subgroup f i`, `pi I s` is the subgroup of dependent functions `f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`. -/ @[to_additive "A version of `Set.pi` for `AddSubgroup`s. Given an index set `I` and a family of submodules `s : Π i, AddSubgroup f i`, `pi I s` is the `AddSubgroup` of dependent functions `f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`."] def pi (I : Set η) (H : ∀ i, Subgroup (f i)) : Subgroup (∀ i, f i) := { Submonoid.pi I fun i => (H i).toSubmonoid with inv_mem' := fun hp i hI => (H i).inv_mem (hp i hI) } #align subgroup.pi Subgroup.pi #align add_subgroup.pi AddSubgroup.pi @[to_additive] theorem coe_pi (I : Set η) (H : ∀ i, Subgroup (f i)) : (pi I H : Set (∀ i, f i)) = Set.pi I fun i => (H i : Set (f i)) := rfl #align subgroup.coe_pi Subgroup.coe_pi #align add_subgroup.coe_pi AddSubgroup.coe_pi @[to_additive] theorem mem_pi (I : Set η) {H : ∀ i, Subgroup (f i)} {p : ∀ i, f i} : p ∈ pi I H ↔ ∀ i : η, i ∈ I → p i ∈ H i := Iff.rfl #align subgroup.mem_pi Subgroup.mem_pi #align add_subgroup.mem_pi AddSubgroup.mem_pi @[to_additive] theorem pi_top (I : Set η) : (pi I fun i => (⊤ : Subgroup (f i))) = ⊤ := ext fun x => by simp [mem_pi] #align subgroup.pi_top Subgroup.pi_top #align add_subgroup.pi_top AddSubgroup.pi_top @[to_additive] theorem pi_empty (H : ∀ i, Subgroup (f i)) : pi ∅ H = ⊤ := ext fun x => by simp [mem_pi] #align subgroup.pi_empty Subgroup.pi_empty #align add_subgroup.pi_empty AddSubgroup.pi_empty @[to_additive] theorem pi_bot : (pi Set.univ fun i => (⊥ : Subgroup (f i))) = ⊥ := (eq_bot_iff_forall _).mpr fun p hp => by simp only [mem_pi, mem_bot] at * ext j exact hp j trivial #align subgroup.pi_bot Subgroup.pi_bot #align add_subgroup.pi_bot AddSubgroup.pi_bot @[to_additive] theorem le_pi_iff {I : Set η} {H : ∀ i, Subgroup (f i)} {J : Subgroup (∀ i, f i)} : J ≤ pi I H ↔ ∀ i : η, i ∈ I → map (Pi.evalMonoidHom f i) J ≤ H i := by constructor · intro h i hi rintro _ ⟨x, hx, rfl⟩ exact (h hx) _ hi · intro h x hx i hi exact h i hi ⟨_, hx, rfl⟩ #align subgroup.le_pi_iff Subgroup.le_pi_iff #align add_subgroup.le_pi_iff AddSubgroup.le_pi_iff @[to_additive (attr := simp)] theorem mulSingle_mem_pi [DecidableEq η] {I : Set η} {H : ∀ i, Subgroup (f i)} (i : η) (x : f i) : Pi.mulSingle i x ∈ pi I H ↔ i ∈ I → x ∈ H i := by constructor · intro h hi simpa using h i hi · intro h j hj by_cases heq : j = i · subst heq simpa using h hj · simp [heq, one_mem] #align subgroup.mul_single_mem_pi Subgroup.mulSingle_mem_pi #align add_subgroup.single_mem_pi AddSubgroup.single_mem_pi @[to_additive] theorem pi_eq_bot_iff (H : ∀ i, Subgroup (f i)) : pi Set.univ H = ⊥ ↔ ∀ i, H i = ⊥ := by classical simp only [eq_bot_iff_forall] constructor · intro h i x hx have : MonoidHom.mulSingle f i x = 1 := h (MonoidHom.mulSingle f i x) ((mulSingle_mem_pi i x).mpr fun _ => hx) simpa using congr_fun this i · exact fun h x hx => funext fun i => h _ _ (hx i trivial) #align subgroup.pi_eq_bot_iff Subgroup.pi_eq_bot_iff #align add_subgroup.pi_eq_bot_iff AddSubgroup.pi_eq_bot_iff end Pi /-- A subgroup is normal if whenever `n ∈ H`, then `g * n * g⁻¹ ∈ H` for every `g : G` -/ structure Normal : Prop where /-- `N` is closed under conjugation -/ conj_mem : ∀ n, n ∈ H → ∀ g : G, g * n * g⁻¹ ∈ H #align subgroup.normal Subgroup.Normal attribute [class] Normal end Subgroup namespace AddSubgroup /-- An AddSubgroup is normal if whenever `n ∈ H`, then `g + n - g ∈ H` for every `g : G` -/ structure Normal (H : AddSubgroup A) : Prop where /-- `N` is closed under additive conjugation -/ conj_mem : ∀ n, n ∈ H → ∀ g : A, g + n + -g ∈ H #align add_subgroup.normal AddSubgroup.Normal attribute [to_additive] Subgroup.Normal attribute [class] Normal end AddSubgroup namespace Subgroup variable {H K : Subgroup G} @[to_additive] instance (priority := 100) normal_of_comm {G : Type*} [CommGroup G] (H : Subgroup G) : H.Normal := ⟨by simp [mul_comm, mul_left_comm]⟩ #align subgroup.normal_of_comm Subgroup.normal_of_comm #align add_subgroup.normal_of_comm AddSubgroup.normal_of_comm namespace Normal variable (nH : H.Normal) @[to_additive] theorem conj_mem' (n : G) (hn : n ∈ H) (g : G) : g⁻¹ * n * g ∈ H := by convert nH.conj_mem n hn g⁻¹ rw [inv_inv] @[to_additive] theorem mem_comm {a b : G} (h : a * b ∈ H) : b * a ∈ H := by have : a⁻¹ * (a * b) * a⁻¹⁻¹ ∈ H := nH.conj_mem (a * b) h a⁻¹ -- Porting note: Previous code was: -- simpa simp_all only [inv_mul_cancel_left, inv_inv] #align subgroup.normal.mem_comm Subgroup.Normal.mem_comm #align add_subgroup.normal.mem_comm AddSubgroup.Normal.mem_comm @[to_additive] theorem mem_comm_iff {a b : G} : a * b ∈ H ↔ b * a ∈ H := ⟨nH.mem_comm, nH.mem_comm⟩ #align subgroup.normal.mem_comm_iff Subgroup.Normal.mem_comm_iff #align add_subgroup.normal.mem_comm_iff AddSubgroup.Normal.mem_comm_iff end Normal variable (H) /-- A subgroup is characteristic if it is fixed by all automorphisms. Several equivalent conditions are provided by lemmas of the form `Characteristic.iff...` -/ structure Characteristic : Prop where /-- `H` is fixed by all automorphisms -/ fixed : ∀ ϕ : G ≃* G, H.comap ϕ.toMonoidHom = H #align subgroup.characteristic Subgroup.Characteristic attribute [class] Characteristic instance (priority := 100) normal_of_characteristic [h : H.Characteristic] : H.Normal := ⟨fun a ha b => (SetLike.ext_iff.mp (h.fixed (MulAut.conj b)) a).mpr ha⟩ #align subgroup.normal_of_characteristic Subgroup.normal_of_characteristic end Subgroup namespace AddSubgroup variable (H : AddSubgroup A) /-- An `AddSubgroup` is characteristic if it is fixed by all automorphisms. Several equivalent conditions are provided by lemmas of the form `Characteristic.iff...` -/ structure Characteristic : Prop where /-- `H` is fixed by all automorphisms -/ fixed : ∀ ϕ : A ≃+ A, H.comap ϕ.toAddMonoidHom = H #align add_subgroup.characteristic AddSubgroup.Characteristic attribute [to_additive] Subgroup.Characteristic attribute [class] Characteristic instance (priority := 100) normal_of_characteristic [h : H.Characteristic] : H.Normal := ⟨fun a ha b => (SetLike.ext_iff.mp (h.fixed (AddAut.conj b)) a).mpr ha⟩ #align add_subgroup.normal_of_characteristic AddSubgroup.normal_of_characteristic end AddSubgroup namespace Subgroup variable {H K : Subgroup G} @[to_additive] theorem characteristic_iff_comap_eq : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.comap ϕ.toMonoidHom = H := ⟨Characteristic.fixed, Characteristic.mk⟩ #align subgroup.characteristic_iff_comap_eq Subgroup.characteristic_iff_comap_eq #align add_subgroup.characteristic_iff_comap_eq AddSubgroup.characteristic_iff_comap_eq @[to_additive] theorem characteristic_iff_comap_le : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.comap ϕ.toMonoidHom ≤ H := characteristic_iff_comap_eq.trans ⟨fun h ϕ => le_of_eq (h ϕ), fun h ϕ => le_antisymm (h ϕ) fun g hg => h ϕ.symm ((congr_arg (· ∈ H) (ϕ.symm_apply_apply g)).mpr hg)⟩ #align subgroup.characteristic_iff_comap_le Subgroup.characteristic_iff_comap_le #align add_subgroup.characteristic_iff_comap_le AddSubgroup.characteristic_iff_comap_le @[to_additive] theorem characteristic_iff_le_comap : H.Characteristic ↔ ∀ ϕ : G ≃* G, H ≤ H.comap ϕ.toMonoidHom := characteristic_iff_comap_eq.trans ⟨fun h ϕ => ge_of_eq (h ϕ), fun h ϕ => le_antisymm (fun g hg => (congr_arg (· ∈ H) (ϕ.symm_apply_apply g)).mp (h ϕ.symm hg)) (h ϕ)⟩ #align subgroup.characteristic_iff_le_comap Subgroup.characteristic_iff_le_comap #align add_subgroup.characteristic_iff_le_comap AddSubgroup.characteristic_iff_le_comap @[to_additive] theorem characteristic_iff_map_eq : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.map ϕ.toMonoidHom = H := by simp_rw [map_equiv_eq_comap_symm'] exact characteristic_iff_comap_eq.trans ⟨fun h ϕ => h ϕ.symm, fun h ϕ => h ϕ.symm⟩ #align subgroup.characteristic_iff_map_eq Subgroup.characteristic_iff_map_eq #align add_subgroup.characteristic_iff_map_eq AddSubgroup.characteristic_iff_map_eq @[to_additive] theorem characteristic_iff_map_le : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.map ϕ.toMonoidHom ≤ H := by simp_rw [map_equiv_eq_comap_symm'] exact characteristic_iff_comap_le.trans ⟨fun h ϕ => h ϕ.symm, fun h ϕ => h ϕ.symm⟩ #align subgroup.characteristic_iff_map_le Subgroup.characteristic_iff_map_le #align add_subgroup.characteristic_iff_map_le AddSubgroup.characteristic_iff_map_le @[to_additive] theorem characteristic_iff_le_map : H.Characteristic ↔ ∀ ϕ : G ≃* G, H ≤ H.map ϕ.toMonoidHom := by simp_rw [map_equiv_eq_comap_symm'] exact characteristic_iff_le_comap.trans ⟨fun h ϕ => h ϕ.symm, fun h ϕ => h ϕ.symm⟩ #align subgroup.characteristic_iff_le_map Subgroup.characteristic_iff_le_map #align add_subgroup.characteristic_iff_le_map AddSubgroup.characteristic_iff_le_map @[to_additive] instance botCharacteristic : Characteristic (⊥ : Subgroup G) := characteristic_iff_le_map.mpr fun _ϕ => bot_le #align subgroup.bot_characteristic Subgroup.botCharacteristic #align add_subgroup.bot_characteristic AddSubgroup.botCharacteristic @[to_additive] instance topCharacteristic : Characteristic (⊤ : Subgroup G) := characteristic_iff_map_le.mpr fun _ϕ => le_top #align subgroup.top_characteristic Subgroup.topCharacteristic #align add_subgroup.top_characteristic AddSubgroup.topCharacteristic variable (H) section Normalizer /-- The `normalizer` of `H` is the largest subgroup of `G` inside which `H` is normal. -/ @[to_additive "The `normalizer` of `H` is the largest subgroup of `G` inside which `H` is normal."] def normalizer : Subgroup G where carrier := { g : G | ∀ n, n ∈ H ↔ g * n * g⁻¹ ∈ H } one_mem' := by simp mul_mem' {a b} (ha : ∀ n, n ∈ H ↔ a * n * a⁻¹ ∈ H) (hb : ∀ n, n ∈ H ↔ b * n * b⁻¹ ∈ H) n := by rw [hb, ha] simp only [mul_assoc, mul_inv_rev] inv_mem' {a} (ha : ∀ n, n ∈ H ↔ a * n * a⁻¹ ∈ H) n := by rw [ha (a⁻¹ * n * a⁻¹⁻¹)] simp only [inv_inv, mul_assoc, mul_inv_cancel_left, mul_right_inv, mul_one] #align subgroup.normalizer Subgroup.normalizer #align add_subgroup.normalizer AddSubgroup.normalizer -- variant for sets. -- TODO should this replace `normalizer`? /-- The `setNormalizer` of `S` is the subgroup of `G` whose elements satisfy `g*S*g⁻¹=S` -/ @[to_additive "The `setNormalizer` of `S` is the subgroup of `G` whose elements satisfy `g+S-g=S`."] def setNormalizer (S : Set G) : Subgroup G where carrier := { g : G | ∀ n, n ∈ S ↔ g * n * g⁻¹ ∈ S } one_mem' := by simp mul_mem' {a b} (ha : ∀ n, n ∈ S ↔ a * n * a⁻¹ ∈ S) (hb : ∀ n, n ∈ S ↔ b * n * b⁻¹ ∈ S) n := by rw [hb, ha] simp only [mul_assoc, mul_inv_rev] inv_mem' {a} (ha : ∀ n, n ∈ S ↔ a * n * a⁻¹ ∈ S) n := by rw [ha (a⁻¹ * n * a⁻¹⁻¹)] simp only [inv_inv, mul_assoc, mul_inv_cancel_left, mul_right_inv, mul_one] #align subgroup.set_normalizer Subgroup.setNormalizer #align add_subgroup.set_normalizer AddSubgroup.setNormalizer variable {H} @[to_additive] theorem mem_normalizer_iff {g : G} : g ∈ H.normalizer ↔ ∀ h, h ∈ H ↔ g * h * g⁻¹ ∈ H := Iff.rfl #align subgroup.mem_normalizer_iff Subgroup.mem_normalizer_iff #align add_subgroup.mem_normalizer_iff AddSubgroup.mem_normalizer_iff @[to_additive] theorem mem_normalizer_iff'' {g : G} : g ∈ H.normalizer ↔ ∀ h : G, h ∈ H ↔ g⁻¹ * h * g ∈ H := by rw [← inv_mem_iff (x := g), mem_normalizer_iff, inv_inv] #align subgroup.mem_normalizer_iff'' Subgroup.mem_normalizer_iff'' #align add_subgroup.mem_normalizer_iff'' AddSubgroup.mem_normalizer_iff'' @[to_additive] theorem mem_normalizer_iff' {g : G} : g ∈ H.normalizer ↔ ∀ n, n * g ∈ H ↔ g * n ∈ H := ⟨fun h n => by rw [h, mul_assoc, mul_inv_cancel_right], fun h n => by rw [mul_assoc, ← h, inv_mul_cancel_right]⟩ #align subgroup.mem_normalizer_iff' Subgroup.mem_normalizer_iff' #align add_subgroup.mem_normalizer_iff' AddSubgroup.mem_normalizer_iff' @[to_additive] theorem le_normalizer : H ≤ normalizer H := fun x xH n => by rw [H.mul_mem_cancel_right (H.inv_mem xH), H.mul_mem_cancel_left xH] #align subgroup.le_normalizer Subgroup.le_normalizer #align add_subgroup.le_normalizer AddSubgroup.le_normalizer @[to_additive] instance (priority := 100) normal_in_normalizer : (H.subgroupOf H.normalizer).Normal := ⟨fun x xH g => by simpa only [mem_subgroupOf] using (g.2 x.1).1 xH⟩ #align subgroup.normal_in_normalizer Subgroup.normal_in_normalizer #align add_subgroup.normal_in_normalizer AddSubgroup.normal_in_normalizer @[to_additive] theorem normalizer_eq_top : H.normalizer = ⊤ ↔ H.Normal := eq_top_iff.trans ⟨fun h => ⟨fun a ha b => (h (mem_top b) a).mp ha⟩, fun h a _ha b => ⟨fun hb => h.conj_mem b hb a, fun hb => by rwa [h.mem_comm_iff, inv_mul_cancel_left] at hb⟩⟩ #align subgroup.normalizer_eq_top Subgroup.normalizer_eq_top #align add_subgroup.normalizer_eq_top AddSubgroup.normalizer_eq_top open scoped Classical @[to_additive] theorem le_normalizer_of_normal [hK : (H.subgroupOf K).Normal] (HK : H ≤ K) : K ≤ H.normalizer := fun x hx y => ⟨fun yH => hK.conj_mem ⟨y, HK yH⟩ yH ⟨x, hx⟩, fun yH => by simpa [mem_subgroupOf, mul_assoc] using hK.conj_mem ⟨x * y * x⁻¹, HK yH⟩ yH ⟨x⁻¹, K.inv_mem hx⟩⟩ #align subgroup.le_normalizer_of_normal Subgroup.le_normalizer_of_normal #align add_subgroup.le_normalizer_of_normal AddSubgroup.le_normalizer_of_normal variable {N : Type*} [Group N] /-- The preimage of the normalizer is contained in the normalizer of the preimage. -/ @[to_additive "The preimage of the normalizer is contained in the normalizer of the preimage."] theorem le_normalizer_comap (f : N →* G) : H.normalizer.comap f ≤ (H.comap f).normalizer := fun x => by simp only [mem_normalizer_iff, mem_comap] intro h n simp [h (f n)] #align subgroup.le_normalizer_comap Subgroup.le_normalizer_comap #align add_subgroup.le_normalizer_comap AddSubgroup.le_normalizer_comap /-- The image of the normalizer is contained in the normalizer of the image. -/ @[to_additive "The image of the normalizer is contained in the normalizer of the image."] theorem le_normalizer_map (f : G →* N) : H.normalizer.map f ≤ (H.map f).normalizer := fun _ => by simp only [and_imp, exists_prop, mem_map, exists_imp, mem_normalizer_iff] rintro x hx rfl n constructor · rintro ⟨y, hy, rfl⟩ use x * y * x⁻¹, (hx y).1 hy simp · rintro ⟨y, hyH, hy⟩ use x⁻¹ * y * x rw [hx] simp [hy, hyH, mul_assoc] #align subgroup.le_normalizer_map Subgroup.le_normalizer_map #align add_subgroup.le_normalizer_map AddSubgroup.le_normalizer_map variable (G) /-- Every proper subgroup `H` of `G` is a proper normal subgroup of the normalizer of `H` in `G`. -/ def _root_.NormalizerCondition := ∀ H : Subgroup G, H < ⊤ → H < normalizer H #align normalizer_condition NormalizerCondition variable {G} /-- Alternative phrasing of the normalizer condition: Only the full group is self-normalizing. This may be easier to work with, as it avoids inequalities and negations. -/ theorem _root_.normalizerCondition_iff_only_full_group_self_normalizing : NormalizerCondition G ↔ ∀ H : Subgroup G, H.normalizer = H → H = ⊤ := by apply forall_congr'; intro H simp only [lt_iff_le_and_ne, le_normalizer, true_and_iff, le_top, Ne] tauto #align normalizer_condition_iff_only_full_group_self_normalizing normalizerCondition_iff_only_full_group_self_normalizing variable (H) /-- In a group that satisfies the normalizer condition, every maximal subgroup is normal -/ theorem NormalizerCondition.normal_of_coatom (hnc : NormalizerCondition G) (hmax : IsCoatom H) : H.Normal := normalizer_eq_top.mp (hmax.2 _ (hnc H (lt_top_iff_ne_top.mpr hmax.1))) #align subgroup.normalizer_condition.normal_of_coatom Subgroup.NormalizerCondition.normal_of_coatom end Normalizer /-- Commutativity of a subgroup -/ structure IsCommutative : Prop where /-- `*` is commutative on `H` -/ is_comm : Std.Commutative (α := H) (· * ·) #align subgroup.is_commutative Subgroup.IsCommutative attribute [class] IsCommutative /-- Commutativity of an additive subgroup -/ structure _root_.AddSubgroup.IsCommutative (H : AddSubgroup A) : Prop where /-- `+` is commutative on `H` -/ is_comm : Std.Commutative (α := H) (· + ·) #align add_subgroup.is_commutative AddSubgroup.IsCommutative attribute [to_additive] Subgroup.IsCommutative attribute [class] AddSubgroup.IsCommutative /-- A commutative subgroup is commutative. -/ @[to_additive "A commutative subgroup is commutative."] instance IsCommutative.commGroup [h : H.IsCommutative] : CommGroup H := { H.toGroup with mul_comm := h.is_comm.comm } #align subgroup.is_commutative.comm_group Subgroup.IsCommutative.commGroup #align add_subgroup.is_commutative.add_comm_group AddSubgroup.IsCommutative.addCommGroup @[to_additive] instance map_isCommutative (f : G →* G') [H.IsCommutative] : (H.map f).IsCommutative := ⟨⟨by rintro ⟨-, a, ha, rfl⟩ ⟨-, b, hb, rfl⟩ rw [Subtype.ext_iff, coe_mul, coe_mul, Subtype.coe_mk, Subtype.coe_mk, ← map_mul, ← map_mul] exact congr_arg f (Subtype.ext_iff.mp (mul_comm (⟨a, ha⟩ : H) ⟨b, hb⟩))⟩⟩ #align subgroup.map_is_commutative Subgroup.map_isCommutative #align add_subgroup.map_is_commutative AddSubgroup.map_isCommutative @[to_additive] theorem comap_injective_isCommutative {f : G' →* G} (hf : Injective f) [H.IsCommutative] : (H.comap f).IsCommutative := ⟨⟨fun a b => Subtype.ext (by have := mul_comm (⟨f a, a.2⟩ : H) (⟨f b, b.2⟩ : H) rwa [Subtype.ext_iff, coe_mul, coe_mul, coe_mk, coe_mk, ← map_mul, ← map_mul, hf.eq_iff] at this)⟩⟩ #align subgroup.comap_injective_is_commutative Subgroup.comap_injective_isCommutative #align add_subgroup.comap_injective_is_commutative AddSubgroup.comap_injective_isCommutative @[to_additive] instance subgroupOf_isCommutative [H.IsCommutative] : (H.subgroupOf K).IsCommutative := H.comap_injective_isCommutative Subtype.coe_injective #align subgroup.subgroup_of_is_commutative Subgroup.subgroupOf_isCommutative #align add_subgroup.add_subgroup_of_is_commutative AddSubgroup.addSubgroupOf_isCommutative end Subgroup namespace MulEquiv variable {H : Type*} [Group H] /-- An isomorphism of groups gives an order isomorphism between the lattices of subgroups, defined by sending subgroups to their inverse images. See also `MulEquiv.mapSubgroup` which maps subgroups to their forward images. -/ @[simps] def comapSubgroup (f : G ≃* H) : Subgroup H ≃o Subgroup G where toFun := Subgroup.comap f invFun := Subgroup.comap f.symm left_inv sg := by simp [Subgroup.comap_comap] right_inv sh := by simp [Subgroup.comap_comap] map_rel_iff' {sg1 sg2} := ⟨fun h => by simpa [Subgroup.comap_comap] using Subgroup.comap_mono (f := (f.symm : H →* G)) h, Subgroup.comap_mono⟩ /-- An isomorphism of groups gives an order isomorphism between the lattices of subgroups, defined by sending subgroups to their forward images. See also `MulEquiv.comapSubgroup` which maps subgroups to their inverse images. -/ @[simps] def mapSubgroup {H : Type*} [Group H] (f : G ≃* H) : Subgroup G ≃o Subgroup H where toFun := Subgroup.map f invFun := Subgroup.map f.symm left_inv sg := by simp [Subgroup.map_map] right_inv sh := by simp [Subgroup.map_map] map_rel_iff' {sg1 sg2} := ⟨fun h => by simpa [Subgroup.map_map] using Subgroup.map_mono (f := (f.symm : H →* G)) h, Subgroup.map_mono⟩ @[simp] theorem isCoatom_comap {H : Type*} [Group H] (f : G ≃* H) {K : Subgroup H} : IsCoatom (Subgroup.comap (f : G →* H) K) ↔ IsCoatom K := OrderIso.isCoatom_iff (f.comapSubgroup) K @[simp] theorem isCoatom_map (f : G ≃* H) {K : Subgroup G} : IsCoatom (Subgroup.map (f : G →* H) K) ↔ IsCoatom K := OrderIso.isCoatom_iff (f.mapSubgroup) K end MulEquiv namespace Group variable {s : Set G} /-- Given a set `s`, `conjugatesOfSet s` is the set of all conjugates of the elements of `s`. -/ def conjugatesOfSet (s : Set G) : Set G := ⋃ a ∈ s, conjugatesOf a #align group.conjugates_of_set Group.conjugatesOfSet theorem mem_conjugatesOfSet_iff {x : G} : x ∈ conjugatesOfSet s ↔ ∃ a ∈ s, IsConj a x := by erw [Set.mem_iUnion₂]; simp only [conjugatesOf, isConj_iff, Set.mem_setOf_eq, exists_prop] #align group.mem_conjugates_of_set_iff Group.mem_conjugatesOfSet_iff theorem subset_conjugatesOfSet : s ⊆ conjugatesOfSet s := fun (x : G) (h : x ∈ s) => mem_conjugatesOfSet_iff.2 ⟨x, h, IsConj.refl _⟩ #align group.subset_conjugates_of_set Group.subset_conjugatesOfSet theorem conjugatesOfSet_mono {s t : Set G} (h : s ⊆ t) : conjugatesOfSet s ⊆ conjugatesOfSet t := Set.biUnion_subset_biUnion_left h #align group.conjugates_of_set_mono Group.conjugatesOfSet_mono theorem conjugates_subset_normal {N : Subgroup G} [tn : N.Normal] {a : G} (h : a ∈ N) : conjugatesOf a ⊆ N := by rintro a hc obtain ⟨c, rfl⟩ := isConj_iff.1 hc exact tn.conj_mem a h c #align group.conjugates_subset_normal Group.conjugates_subset_normal theorem conjugatesOfSet_subset {s : Set G} {N : Subgroup G} [N.Normal] (h : s ⊆ N) : conjugatesOfSet s ⊆ N := Set.iUnion₂_subset fun _x H => conjugates_subset_normal (h H) #align group.conjugates_of_set_subset Group.conjugatesOfSet_subset /-- The set of conjugates of `s` is closed under conjugation. -/ theorem conj_mem_conjugatesOfSet {x c : G} : x ∈ conjugatesOfSet s → c * x * c⁻¹ ∈ conjugatesOfSet s := fun H => by rcases mem_conjugatesOfSet_iff.1 H with ⟨a, h₁, h₂⟩ exact mem_conjugatesOfSet_iff.2 ⟨a, h₁, h₂.trans (isConj_iff.2 ⟨c, rfl⟩)⟩ #align group.conj_mem_conjugates_of_set Group.conj_mem_conjugatesOfSet end Group namespace Subgroup open Group variable {s : Set G} /-- The normal closure of a set `s` is the subgroup closure of all the conjugates of elements of `s`. It is the smallest normal subgroup containing `s`. -/ def normalClosure (s : Set G) : Subgroup G := closure (conjugatesOfSet s) #align subgroup.normal_closure Subgroup.normalClosure theorem conjugatesOfSet_subset_normalClosure : conjugatesOfSet s ⊆ normalClosure s := subset_closure #align subgroup.conjugates_of_set_subset_normal_closure Subgroup.conjugatesOfSet_subset_normalClosure theorem subset_normalClosure : s ⊆ normalClosure s := Set.Subset.trans subset_conjugatesOfSet conjugatesOfSet_subset_normalClosure #align subgroup.subset_normal_closure Subgroup.subset_normalClosure theorem le_normalClosure {H : Subgroup G} : H ≤ normalClosure ↑H := fun _ h => subset_normalClosure h #align subgroup.le_normal_closure Subgroup.le_normalClosure /-- The normal closure of `s` is a normal subgroup. -/ instance normalClosure_normal : (normalClosure s).Normal := ⟨fun n h g => by refine Subgroup.closure_induction h (fun x hx => ?_) ?_ (fun x y ihx ihy => ?_) fun x ihx => ?_ · exact conjugatesOfSet_subset_normalClosure (conj_mem_conjugatesOfSet hx) · simpa using (normalClosure s).one_mem · rw [← conj_mul] exact mul_mem ihx ihy · rw [← conj_inv] exact inv_mem ihx⟩ #align subgroup.normal_closure_normal Subgroup.normalClosure_normal /-- The normal closure of `s` is the smallest normal subgroup containing `s`. -/ theorem normalClosure_le_normal {N : Subgroup G} [N.Normal] (h : s ⊆ N) : normalClosure s ≤ N := by intro a w refine closure_induction w (fun x hx => ?_) ?_ (fun x y ihx ihy => ?_) fun x ihx => ?_ · exact conjugatesOfSet_subset h hx · exact one_mem _ · exact mul_mem ihx ihy · exact inv_mem ihx #align subgroup.normal_closure_le_normal Subgroup.normalClosure_le_normal theorem normalClosure_subset_iff {N : Subgroup G} [N.Normal] : s ⊆ N ↔ normalClosure s ≤ N := ⟨normalClosure_le_normal, Set.Subset.trans subset_normalClosure⟩ #align subgroup.normal_closure_subset_iff Subgroup.normalClosure_subset_iff theorem normalClosure_mono {s t : Set G} (h : s ⊆ t) : normalClosure s ≤ normalClosure t := normalClosure_le_normal (Set.Subset.trans h subset_normalClosure) #align subgroup.normal_closure_mono Subgroup.normalClosure_mono theorem normalClosure_eq_iInf : normalClosure s = ⨅ (N : Subgroup G) (_ : Normal N) (_ : s ⊆ N), N := le_antisymm (le_iInf fun N => le_iInf fun hN => le_iInf normalClosure_le_normal) (iInf_le_of_le (normalClosure s) (iInf_le_of_le (by infer_instance) (iInf_le_of_le subset_normalClosure le_rfl))) #align subgroup.normal_closure_eq_infi Subgroup.normalClosure_eq_iInf @[simp] theorem normalClosure_eq_self (H : Subgroup G) [H.Normal] : normalClosure ↑H = H := le_antisymm (normalClosure_le_normal rfl.subset) le_normalClosure #align subgroup.normal_closure_eq_self Subgroup.normalClosure_eq_self -- @[simp] -- Porting note (#10618): simp can prove this theorem normalClosure_idempotent : normalClosure ↑(normalClosure s) = normalClosure s := normalClosure_eq_self _ #align subgroup.normal_closure_idempotent Subgroup.normalClosure_idempotent theorem closure_le_normalClosure {s : Set G} : closure s ≤ normalClosure s := by simp only [subset_normalClosure, closure_le] #align subgroup.closure_le_normal_closure Subgroup.closure_le_normalClosure @[simp] theorem normalClosure_closure_eq_normalClosure {s : Set G} : normalClosure ↑(closure s) = normalClosure s := le_antisymm (normalClosure_le_normal closure_le_normalClosure) (normalClosure_mono subset_closure) #align subgroup.normal_closure_closure_eq_normal_closure Subgroup.normalClosure_closure_eq_normalClosure /-- The normal core of a subgroup `H` is the largest normal subgroup of `G` contained in `H`, as shown by `Subgroup.normalCore_eq_iSup`. -/ def normalCore (H : Subgroup G) : Subgroup G where carrier := { a : G | ∀ b : G, b * a * b⁻¹ ∈ H } one_mem' a := by rw [mul_one, mul_inv_self]; exact H.one_mem inv_mem' {a} h b := (congr_arg (· ∈ H) conj_inv).mp (H.inv_mem (h b)) mul_mem' {a b} ha hb c := (congr_arg (· ∈ H) conj_mul).mp (H.mul_mem (ha c) (hb c)) #align subgroup.normal_core Subgroup.normalCore theorem normalCore_le (H : Subgroup G) : H.normalCore ≤ H := fun a h => by rw [← mul_one a, ← inv_one, ← one_mul a] exact h 1 #align subgroup.normal_core_le Subgroup.normalCore_le instance normalCore_normal (H : Subgroup G) : H.normalCore.Normal := ⟨fun a h b c => by rw [mul_assoc, mul_assoc, ← mul_inv_rev, ← mul_assoc, ← mul_assoc]; exact h (c * b)⟩ #align subgroup.normal_core_normal Subgroup.normalCore_normal theorem normal_le_normalCore {H : Subgroup G} {N : Subgroup G} [hN : N.Normal] : N ≤ H.normalCore ↔ N ≤ H := ⟨ge_trans H.normalCore_le, fun h_le n hn g => h_le (hN.conj_mem n hn g)⟩ #align subgroup.normal_le_normal_core Subgroup.normal_le_normalCore theorem normalCore_mono {H K : Subgroup G} (h : H ≤ K) : H.normalCore ≤ K.normalCore := normal_le_normalCore.mpr (H.normalCore_le.trans h) #align subgroup.normal_core_mono Subgroup.normalCore_mono theorem normalCore_eq_iSup (H : Subgroup G) : H.normalCore = ⨆ (N : Subgroup G) (_ : Normal N) (_ : N ≤ H), N := le_antisymm (le_iSup_of_le H.normalCore (le_iSup_of_le H.normalCore_normal (le_iSup_of_le H.normalCore_le le_rfl))) (iSup_le fun _ => iSup_le fun _ => iSup_le normal_le_normalCore.mpr) #align subgroup.normal_core_eq_supr Subgroup.normalCore_eq_iSup @[simp] theorem normalCore_eq_self (H : Subgroup G) [H.Normal] : H.normalCore = H := le_antisymm H.normalCore_le (normal_le_normalCore.mpr le_rfl) #align subgroup.normal_core_eq_self Subgroup.normalCore_eq_self -- @[simp] -- Porting note (#10618): simp can prove this theorem normalCore_idempotent (H : Subgroup G) : H.normalCore.normalCore = H.normalCore := H.normalCore.normalCore_eq_self #align subgroup.normal_core_idempotent Subgroup.normalCore_idempotent end Subgroup namespace MonoidHom variable {N : Type*} {P : Type*} [Group N] [Group P] (K : Subgroup G) open Subgroup /-- The range of a monoid homomorphism from a group is a subgroup. -/ @[to_additive "The range of an `AddMonoidHom` from an `AddGroup` is an `AddSubgroup`."] def range (f : G →* N) : Subgroup N := Subgroup.copy ((⊤ : Subgroup G).map f) (Set.range f) (by simp [Set.ext_iff]) #align monoid_hom.range MonoidHom.range #align add_monoid_hom.range AddMonoidHom.range @[to_additive (attr := simp)] theorem coe_range (f : G →* N) : (f.range : Set N) = Set.range f := rfl #align monoid_hom.coe_range MonoidHom.coe_range #align add_monoid_hom.coe_range AddMonoidHom.coe_range @[to_additive (attr := simp)] theorem mem_range {f : G →* N} {y : N} : y ∈ f.range ↔ ∃ x, f x = y := Iff.rfl #align monoid_hom.mem_range MonoidHom.mem_range #align add_monoid_hom.mem_range AddMonoidHom.mem_range @[to_additive] theorem range_eq_map (f : G →* N) : f.range = (⊤ : Subgroup G).map f := by ext; simp #align monoid_hom.range_eq_map MonoidHom.range_eq_map #align add_monoid_hom.range_eq_map AddMonoidHom.range_eq_map @[to_additive (attr := simp)] theorem restrict_range (f : G →* N) : (f.restrict K).range = K.map f := by simp_rw [SetLike.ext_iff, mem_range, mem_map, restrict_apply, SetLike.exists, exists_prop, forall_const] #align monoid_hom.restrict_range MonoidHom.restrict_range #align add_monoid_hom.restrict_range AddMonoidHom.restrict_range /-- The canonical surjective group homomorphism `G →* f(G)` induced by a group homomorphism `G →* N`. -/ @[to_additive "The canonical surjective `AddGroup` homomorphism `G →+ f(G)` induced by a group homomorphism `G →+ N`."] def rangeRestrict (f : G →* N) : G →* f.range := codRestrict f _ fun x => ⟨x, rfl⟩ #align monoid_hom.range_restrict MonoidHom.rangeRestrict #align add_monoid_hom.range_restrict AddMonoidHom.rangeRestrict @[to_additive (attr := simp)] theorem coe_rangeRestrict (f : G →* N) (g : G) : (f.rangeRestrict g : N) = f g := rfl #align monoid_hom.coe_range_restrict MonoidHom.coe_rangeRestrict #align add_monoid_hom.coe_range_restrict AddMonoidHom.coe_rangeRestrict @[to_additive] theorem coe_comp_rangeRestrict (f : G →* N) : ((↑) : f.range → N) ∘ (⇑f.rangeRestrict : G → f.range) = f := rfl #align monoid_hom.coe_comp_range_restrict MonoidHom.coe_comp_rangeRestrict #align add_monoid_hom.coe_comp_range_restrict AddMonoidHom.coe_comp_rangeRestrict @[to_additive] theorem subtype_comp_rangeRestrict (f : G →* N) : f.range.subtype.comp f.rangeRestrict = f := ext <| f.coe_rangeRestrict #align monoid_hom.subtype_comp_range_restrict MonoidHom.subtype_comp_rangeRestrict #align add_monoid_hom.subtype_comp_range_restrict AddMonoidHom.subtype_comp_rangeRestrict @[to_additive] theorem rangeRestrict_surjective (f : G →* N) : Function.Surjective f.rangeRestrict := fun ⟨_, g, rfl⟩ => ⟨g, rfl⟩ #align monoid_hom.range_restrict_surjective MonoidHom.rangeRestrict_surjective #align add_monoid_hom.range_restrict_surjective AddMonoidHom.rangeRestrict_surjective @[to_additive (attr := simp)] lemma rangeRestrict_injective_iff {f : G →* N} : Injective f.rangeRestrict ↔ Injective f := by convert Set.injective_codRestrict _ @[to_additive] theorem map_range (g : N →* P) (f : G →* N) : f.range.map g = (g.comp f).range := by rw [range_eq_map, range_eq_map]; exact (⊤ : Subgroup G).map_map g f #align monoid_hom.map_range MonoidHom.map_range #align add_monoid_hom.map_range AddMonoidHom.map_range @[to_additive] theorem range_top_iff_surjective {N} [Group N] {f : G →* N} : f.range = (⊤ : Subgroup N) ↔ Function.Surjective f := SetLike.ext'_iff.trans <| Iff.trans (by rw [coe_range, coe_top]) Set.range_iff_surjective #align monoid_hom.range_top_iff_surjective MonoidHom.range_top_iff_surjective #align add_monoid_hom.range_top_iff_surjective AddMonoidHom.range_top_iff_surjective /-- The range of a surjective monoid homomorphism is the whole of the codomain. -/ @[to_additive (attr := simp) "The range of a surjective `AddMonoid` homomorphism is the whole of the codomain."] theorem range_top_of_surjective {N} [Group N] (f : G →* N) (hf : Function.Surjective f) : f.range = (⊤ : Subgroup N) := range_top_iff_surjective.2 hf #align monoid_hom.range_top_of_surjective MonoidHom.range_top_of_surjective #align add_monoid_hom.range_top_of_surjective AddMonoidHom.range_top_of_surjective @[to_additive (attr := simp)] theorem range_one : (1 : G →* N).range = ⊥ := SetLike.ext fun x => by simpa using @comm _ (· = ·) _ 1 x #align monoid_hom.range_one MonoidHom.range_one #align add_monoid_hom.range_zero AddMonoidHom.range_zero @[to_additive (attr := simp)] theorem _root_.Subgroup.subtype_range (H : Subgroup G) : H.subtype.range = H := by rw [range_eq_map, ← SetLike.coe_set_eq, coe_map, Subgroup.coeSubtype] ext simp #align subgroup.subtype_range Subgroup.subtype_range #align add_subgroup.subtype_range AddSubgroup.subtype_range @[to_additive (attr := simp)] theorem _root_.Subgroup.inclusion_range {H K : Subgroup G} (h_le : H ≤ K) : (inclusion h_le).range = H.subgroupOf K := Subgroup.ext fun g => Set.ext_iff.mp (Set.range_inclusion h_le) g #align subgroup.inclusion_range Subgroup.inclusion_range #align add_subgroup.inclusion_range AddSubgroup.inclusion_range @[to_additive]
Mathlib/Algebra/Group/Subgroup/Basic.lean
2,603
2,608
theorem subgroupOf_range_eq_of_le {G₁ G₂ : Type*} [Group G₁] [Group G₂] {K : Subgroup G₂} (f : G₁ →* G₂) (h : f.range ≤ K) : f.range.subgroupOf K = (f.codRestrict K fun x => h ⟨x, rfl⟩).range := by
ext k refine exists_congr ?_ simp [Subtype.ext_iff]
/- Copyright (c) 2020 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nicolò Cavalleri -/ import Mathlib.RingTheory.Derivation.Lie import Mathlib.Geometry.Manifold.DerivationBundle #align_import geometry.manifold.algebra.left_invariant_derivation from "leanprover-community/mathlib"@"b608348ffaeb7f557f2fd46876037abafd326ff3" /-! # Left invariant derivations In this file we define the concept of left invariant derivation for a Lie group. The concept is analogous to the more classical concept of left invariant vector fields, and it holds that the derivation associated to a vector field is left invariant iff the field is. Moreover we prove that `LeftInvariantDerivation I G` has the structure of a Lie algebra, hence implementing one of the possible definitions of the Lie algebra attached to a Lie group. -/ noncomputable section open scoped LieGroup Manifold Derivation variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) (G : Type*) [TopologicalSpace G] [ChartedSpace H G] [Monoid G] [SmoothMul I G] (g h : G) -- Generate trivial has_sizeof instance. It prevents weird type class inference timeout problems -- Porting note(#12096): removed @[nolint instance_priority], linter not ported yet -- @[local nolint instance_priority, local instance 10000] -- private def disable_has_sizeof {α} : SizeOf α := -- ⟨fun _ => 0⟩ /-- Left-invariant global derivations. A global derivation is left-invariant if it is equal to its pullback along left multiplication by an arbitrary element of `G`. -/ structure LeftInvariantDerivation extends Derivation 𝕜 C^∞⟮I, G; 𝕜⟯ C^∞⟮I, G; 𝕜⟯ where left_invariant'' : ∀ g, 𝒅ₕ (smoothLeftMul_one I g) (Derivation.evalAt 1 toDerivation) = Derivation.evalAt g toDerivation #align left_invariant_derivation LeftInvariantDerivation variable {I G} namespace LeftInvariantDerivation instance : Coe (LeftInvariantDerivation I G) (Derivation 𝕜 C^∞⟮I, G; 𝕜⟯ C^∞⟮I, G; 𝕜⟯) := ⟨toDerivation⟩ attribute [coe] toDerivation theorem toDerivation_injective : Function.Injective (toDerivation : LeftInvariantDerivation I G → _) := fun X Y h => by cases X; cases Y; congr #align left_invariant_derivation.coe_derivation_injective LeftInvariantDerivation.toDerivation_injective instance : FunLike (LeftInvariantDerivation I G) C^∞⟮I, G; 𝕜⟯ C^∞⟮I, G; 𝕜⟯ where coe f := f.toDerivation coe_injective' _ _ h := toDerivation_injective <| DFunLike.ext' h instance : LinearMapClass (LeftInvariantDerivation I G) 𝕜 C^∞⟮I, G; 𝕜⟯ C^∞⟮I, G; 𝕜⟯ where map_add f := map_add f.1 map_smulₛₗ f := map_smul f.1.1 variable {M : Type*} [TopologicalSpace M] [ChartedSpace H M] {x : M} {r : 𝕜} {X Y : LeftInvariantDerivation I G} {f f' : C^∞⟮I, G; 𝕜⟯} theorem toFun_eq_coe : X.toFun = ⇑X := rfl #align left_invariant_derivation.to_fun_eq_coe LeftInvariantDerivation.toFun_eq_coe #noalign left_invariant_derivation.coe_to_linear_map -- Porting note: now LHS is the same as RHS #noalign left_invariant_derivation.to_derivation_eq_coe theorem coe_injective : @Function.Injective (LeftInvariantDerivation I G) (_ → C^∞⟮I, G; 𝕜⟯) DFunLike.coe := DFunLike.coe_injective #align left_invariant_derivation.coe_injective LeftInvariantDerivation.coe_injective @[ext] theorem ext (h : ∀ f, X f = Y f) : X = Y := DFunLike.ext _ _ h #align left_invariant_derivation.ext LeftInvariantDerivation.ext variable (X Y f) theorem coe_derivation : ⇑(X : Derivation 𝕜 C^∞⟮I, G; 𝕜⟯ C^∞⟮I, G; 𝕜⟯) = (X : C^∞⟮I, G; 𝕜⟯ → C^∞⟮I, G; 𝕜⟯) := rfl #align left_invariant_derivation.coe_derivation LeftInvariantDerivation.coe_derivation /-- Premature version of the lemma. Prefer using `left_invariant` instead. -/ theorem left_invariant' : 𝒅ₕ (smoothLeftMul_one I g) (Derivation.evalAt (1 : G) ↑X) = Derivation.evalAt g ↑X := left_invariant'' X g #align left_invariant_derivation.left_invariant' LeftInvariantDerivation.left_invariant' -- Porting note: was `@[simp]` but `_root_.map_add` can prove it now protected theorem map_add : X (f + f') = X f + X f' := map_add X f f' #align left_invariant_derivation.map_add LeftInvariantDerivation.map_add -- Porting note: was `@[simp]` but `_root_.map_zero` can prove it now protected theorem map_zero : X 0 = 0 := map_zero X #align left_invariant_derivation.map_zero LeftInvariantDerivation.map_zero -- Porting note: was `@[simp]` but `_root_.map_neg` can prove it now protected theorem map_neg : X (-f) = -X f := map_neg X f #align left_invariant_derivation.map_neg LeftInvariantDerivation.map_neg -- Porting note: was `@[simp]` but `_root_.map_sub` can prove it now protected theorem map_sub : X (f - f') = X f - X f' := map_sub X f f' #align left_invariant_derivation.map_sub LeftInvariantDerivation.map_sub -- Porting note: was `@[simp]` but `_root_.map_smul` can prove it now protected theorem map_smul : X (r • f) = r • X f := map_smul X r f #align left_invariant_derivation.map_smul LeftInvariantDerivation.map_smul @[simp] theorem leibniz : X (f * f') = f • X f' + f' • X f := X.leibniz' _ _ #align left_invariant_derivation.leibniz LeftInvariantDerivation.leibniz instance : Zero (LeftInvariantDerivation I G) := ⟨⟨0, fun g => by simp only [_root_.map_zero]⟩⟩ instance : Inhabited (LeftInvariantDerivation I G) := ⟨0⟩ instance : Add (LeftInvariantDerivation I G) where add X Y := ⟨X + Y, fun g => by simp only [map_add, Derivation.coe_add, left_invariant', Pi.add_apply]⟩ instance : Neg (LeftInvariantDerivation I G) where neg X := ⟨-X, fun g => by simp [left_invariant']⟩ instance : Sub (LeftInvariantDerivation I G) where sub X Y := ⟨X - Y, fun g => by simp [left_invariant']⟩ @[simp] theorem coe_add : ⇑(X + Y) = X + Y := rfl #align left_invariant_derivation.coe_add LeftInvariantDerivation.coe_add @[simp] theorem coe_zero : ⇑(0 : LeftInvariantDerivation I G) = 0 := rfl #align left_invariant_derivation.coe_zero LeftInvariantDerivation.coe_zero @[simp] theorem coe_neg : ⇑(-X) = -X := rfl #align left_invariant_derivation.coe_neg LeftInvariantDerivation.coe_neg @[simp] theorem coe_sub : ⇑(X - Y) = X - Y := rfl #align left_invariant_derivation.coe_sub LeftInvariantDerivation.coe_sub @[simp, norm_cast] theorem lift_add : (↑(X + Y) : Derivation 𝕜 C^∞⟮I, G; 𝕜⟯ C^∞⟮I, G; 𝕜⟯) = X + Y := rfl #align left_invariant_derivation.lift_add LeftInvariantDerivation.lift_add @[simp, norm_cast] theorem lift_zero : (↑(0 : LeftInvariantDerivation I G) : Derivation 𝕜 C^∞⟮I, G; 𝕜⟯ C^∞⟮I, G; 𝕜⟯) = 0 := rfl #align left_invariant_derivation.lift_zero LeftInvariantDerivation.lift_zero instance hasNatScalar : SMul ℕ (LeftInvariantDerivation I G) where smul r X := ⟨r • X.1, fun g => by simp_rw [LinearMap.map_smul_of_tower _ r, left_invariant']⟩ #align left_invariant_derivation.has_nat_scalar LeftInvariantDerivation.hasNatScalar instance hasIntScalar : SMul ℤ (LeftInvariantDerivation I G) where smul r X := ⟨r • X.1, fun g => by simp_rw [LinearMap.map_smul_of_tower _ r, left_invariant']⟩ #align left_invariant_derivation.has_int_scalar LeftInvariantDerivation.hasIntScalar instance : AddCommGroup (LeftInvariantDerivation I G) := coe_injective.addCommGroup _ coe_zero coe_add coe_neg coe_sub (fun _ _ => rfl) fun _ _ => rfl instance : SMul 𝕜 (LeftInvariantDerivation I G) where smul r X := ⟨r • X.1, fun g => by simp_rw [LinearMap.map_smul, left_invariant']⟩ variable (r) @[simp] theorem coe_smul : ⇑(r • X) = r • ⇑X := rfl #align left_invariant_derivation.coe_smul LeftInvariantDerivation.coe_smul @[simp] theorem lift_smul (k : 𝕜) : (k • X).1 = k • X.1 := rfl #align left_invariant_derivation.lift_smul LeftInvariantDerivation.lift_smul variable (I G) /-- The coercion to function is a monoid homomorphism. -/ @[simps] def coeFnAddMonoidHom : LeftInvariantDerivation I G →+ C^∞⟮I, G; 𝕜⟯ → C^∞⟮I, G; 𝕜⟯ := ⟨⟨DFunLike.coe, coe_zero⟩, coe_add⟩ #align left_invariant_derivation.coe_fn_add_monoid_hom LeftInvariantDerivation.coeFnAddMonoidHom variable {I G} instance : Module 𝕜 (LeftInvariantDerivation I G) := coe_injective.module _ (coeFnAddMonoidHom I G) coe_smul /-- Evaluation at a point for left invariant derivation. Same thing as for generic global derivations (`Derivation.evalAt`). -/ def evalAt : LeftInvariantDerivation I G →ₗ[𝕜] PointDerivation I g where toFun X := Derivation.evalAt g X.1 map_add' _ _ := rfl map_smul' _ _ := rfl #align left_invariant_derivation.eval_at LeftInvariantDerivation.evalAt theorem evalAt_apply : evalAt g X f = (X f) g := rfl #align left_invariant_derivation.eval_at_apply LeftInvariantDerivation.evalAt_apply @[simp] theorem evalAt_coe : Derivation.evalAt g ↑X = evalAt g X := rfl #align left_invariant_derivation.eval_at_coe LeftInvariantDerivation.evalAt_coe theorem left_invariant : 𝒅ₕ (smoothLeftMul_one I g) (evalAt (1 : G) X) = evalAt g X := X.left_invariant'' g #align left_invariant_derivation.left_invariant LeftInvariantDerivation.left_invariant theorem evalAt_mul : evalAt (g * h) X = 𝒅ₕ (L_apply I g h) (evalAt h X) := by ext f rw [← left_invariant, apply_hfdifferential, apply_hfdifferential, L_mul, fdifferential_comp, apply_fdifferential] -- Porting note: more agressive here erw [LinearMap.comp_apply] -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [apply_fdifferential, ← apply_hfdifferential, left_invariant] #align left_invariant_derivation.eval_at_mul LeftInvariantDerivation.evalAt_mul
Mathlib/Geometry/Manifold/Algebra/LeftInvariantDerivation.lean
249
252
theorem comp_L : (X f).comp (𝑳 I g) = X (f.comp (𝑳 I g)) := by
ext h rw [ContMDiffMap.comp_apply, L_apply, ← evalAt_apply, evalAt_mul, apply_hfdifferential, apply_fdifferential, evalAt_apply]
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Yakov Pechersky, Eric Wieser -/ import Mathlib.Data.List.Basic /-! # Properties of `List.enum` -/ namespace List variable {α β : Type*} #align list.length_enum_from List.enumFrom_length #align list.length_enum List.enum_length @[simp] theorem get?_enumFrom : ∀ n (l : List α) m, get? (enumFrom n l) m = (get? l m).map fun a => (n + m, a) | n, [], m => rfl | n, a :: l, 0 => rfl | n, a :: l, m + 1 => (get?_enumFrom (n + 1) l m).trans <| by rw [Nat.add_right_comm]; rfl #align list.enum_from_nth List.get?_enumFrom @[deprecated (since := "2024-04-06")] alias enumFrom_get? := get?_enumFrom @[simp] theorem get?_enum (l : List α) (n) : get? (enum l) n = (get? l n).map fun a => (n, a) := by rw [enum, get?_enumFrom, Nat.zero_add] #align list.enum_nth List.get?_enum @[deprecated (since := "2024-04-06")] alias enum_get? := get?_enum @[simp] theorem enumFrom_map_snd : ∀ (n) (l : List α), map Prod.snd (enumFrom n l) = l | _, [] => rfl | _, _ :: _ => congr_arg (cons _) (enumFrom_map_snd _ _) #align list.enum_from_map_snd List.enumFrom_map_snd @[simp] theorem enum_map_snd (l : List α) : map Prod.snd (enum l) = l := enumFrom_map_snd _ _ #align list.enum_map_snd List.enum_map_snd @[simp] theorem get_enumFrom (l : List α) (n) (i : Fin (l.enumFrom n).length) : (l.enumFrom n).get i = (n + i, l.get (i.cast enumFrom_length)) := by simp [get_eq_get?] #align list.nth_le_enum_from List.get_enumFrom @[simp] theorem get_enum (l : List α) (i : Fin l.enum.length) : l.enum.get i = (i.1, l.get (i.cast enum_length)) := by simp [enum] #align list.nth_le_enum List.get_enum theorem mk_add_mem_enumFrom_iff_get? {n i : ℕ} {x : α} {l : List α} : (n + i, x) ∈ enumFrom n l ↔ l.get? i = x := by simp [mem_iff_get?] theorem mk_mem_enumFrom_iff_le_and_get?_sub {n i : ℕ} {x : α} {l : List α} : (i, x) ∈ enumFrom n l ↔ n ≤ i ∧ l.get? (i - n) = x := by if h : n ≤ i then rcases Nat.exists_eq_add_of_le h with ⟨i, rfl⟩ simp [mk_add_mem_enumFrom_iff_get?, Nat.add_sub_cancel_left] else have : ∀ k, n + k ≠ i := by rintro k rfl; simp at h simp [h, mem_iff_get?, this] theorem mk_mem_enum_iff_get? {i : ℕ} {x : α} {l : List α} : (i, x) ∈ enum l ↔ l.get? i = x := by simp [enum, mk_mem_enumFrom_iff_le_and_get?_sub] theorem mem_enum_iff_get? {x : ℕ × α} {l : List α} : x ∈ enum l ↔ l.get? x.1 = x.2 := mk_mem_enum_iff_get? theorem le_fst_of_mem_enumFrom {x : ℕ × α} {n : ℕ} {l : List α} (h : x ∈ enumFrom n l) : n ≤ x.1 := (mk_mem_enumFrom_iff_le_and_get?_sub.1 h).1 theorem fst_lt_add_of_mem_enumFrom {x : ℕ × α} {n : ℕ} {l : List α} (h : x ∈ enumFrom n l) : x.1 < n + length l := by rcases mem_iff_get.1 h with ⟨i, rfl⟩ simpa using i.is_lt theorem fst_lt_of_mem_enum {x : ℕ × α} {l : List α} (h : x ∈ enum l) : x.1 < length l := by simpa using fst_lt_add_of_mem_enumFrom h theorem snd_mem_of_mem_enumFrom {x : ℕ × α} {n : ℕ} {l : List α} (h : x ∈ enumFrom n l) : x.2 ∈ l := enumFrom_map_snd n l ▸ mem_map_of_mem _ h theorem snd_mem_of_mem_enum {x : ℕ × α} {l : List α} (h : x ∈ enum l) : x.2 ∈ l := snd_mem_of_mem_enumFrom h theorem mem_enumFrom {x : α} {i j : ℕ} (xs : List α) (h : (i, x) ∈ xs.enumFrom j) : j ≤ i ∧ i < j + xs.length ∧ x ∈ xs := ⟨le_fst_of_mem_enumFrom h, fst_lt_add_of_mem_enumFrom h, snd_mem_of_mem_enumFrom h⟩ #align list.mem_enum_from List.mem_enumFrom @[simp] theorem enum_nil : enum ([] : List α) = [] := rfl #align list.enum_nil List.enum_nil #align list.enum_from_nil List.enumFrom_nil #align list.enum_from_cons List.enumFrom_cons @[simp] theorem enum_cons (x : α) (xs : List α) : enum (x :: xs) = (0, x) :: enumFrom 1 xs := rfl #align list.enum_cons List.enum_cons @[simp] theorem enumFrom_singleton (x : α) (n : ℕ) : enumFrom n [x] = [(n, x)] := rfl #align list.enum_from_singleton List.enumFrom_singleton @[simp] theorem enum_singleton (x : α) : enum [x] = [(0, x)] := rfl #align list.enum_singleton List.enum_singleton theorem enumFrom_append (xs ys : List α) (n : ℕ) : enumFrom n (xs ++ ys) = enumFrom n xs ++ enumFrom (n + xs.length) ys := by induction' xs with x xs IH generalizing ys n · simp · rw [cons_append, enumFrom_cons, IH, ← cons_append, ← enumFrom_cons, length, Nat.add_right_comm, Nat.add_assoc] #align list.enum_from_append List.enumFrom_append theorem enum_append (xs ys : List α) : enum (xs ++ ys) = enum xs ++ enumFrom xs.length ys := by simp [enum, enumFrom_append] #align list.enum_append List.enum_append theorem map_fst_add_enumFrom_eq_enumFrom (l : List α) (n k : ℕ) : map (Prod.map (· + n) id) (enumFrom k l) = enumFrom (n + k) l := ext_get? fun i ↦ by simp [(· ∘ ·), Nat.add_comm, Nat.add_left_comm] #align list.map_fst_add_enum_from_eq_enum_from List.map_fst_add_enumFrom_eq_enumFrom theorem map_fst_add_enum_eq_enumFrom (l : List α) (n : ℕ) : map (Prod.map (· + n) id) (enum l) = enumFrom n l := map_fst_add_enumFrom_eq_enumFrom l _ _ #align list.map_fst_add_enum_eq_enum_from List.map_fst_add_enum_eq_enumFrom
Mathlib/Data/List/Enum.lean
146
148
theorem enumFrom_cons' (n : ℕ) (x : α) (xs : List α) : enumFrom n (x :: xs) = (n, x) :: (enumFrom n xs).map (Prod.map Nat.succ id) := by
rw [enumFrom_cons, Nat.add_comm, ← map_fst_add_enumFrom_eq_enumFrom]
/- Copyright (c) 2022 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Topology.Order.LeftRight import Mathlib.Topology.Order.Monotone #align_import topology.algebra.order.left_right_lim from "leanprover-community/mathlib"@"0a0ec35061ed9960bf0e7ffb0335f44447b58977" /-! # Left and right limits We define the (strict) left and right limits of a function. * `leftLim f x` is the strict left limit of `f` at `x` (using `f x` as a garbage value if `x` is isolated to its left). * `rightLim f x` is the strict right limit of `f` at `x` (using `f x` as a garbage value if `x` is isolated to its right). We develop a comprehensive API for monotone functions. Notably, * `Monotone.continuousAt_iff_leftLim_eq_rightLim` states that a monotone function is continuous at a point if and only if its left and right limits coincide. * `Monotone.countable_not_continuousAt` asserts that a monotone function taking values in a second-countable space has at most countably many discontinuity points. We also port the API to antitone functions. ## TODO Prove corresponding stronger results for `StrictMono` and `StrictAnti` functions. -/ open Set Filter open Topology section variable {α β : Type*} [LinearOrder α] [TopologicalSpace β] /-- Let `f : α → β` be a function from a linear order `α` to a topological space `β`, and let `a : α`. The limit strictly to the left of `f` at `a`, denoted with `leftLim f a`, is defined by using the order topology on `α`. If `a` is isolated to its left or the function has no left limit, we use `f a` instead to guarantee a good behavior in most cases. -/ noncomputable def Function.leftLim (f : α → β) (a : α) : β := by classical haveI : Nonempty β := ⟨f a⟩ letI : TopologicalSpace α := Preorder.topology α exact if 𝓝[<] a = ⊥ ∨ ¬∃ y, Tendsto f (𝓝[<] a) (𝓝 y) then f a else limUnder (𝓝[<] a) f #align function.left_lim Function.leftLim /-- Let `f : α → β` be a function from a linear order `α` to a topological space `β`, and let `a : α`. The limit strictly to the right of `f` at `a`, denoted with `rightLim f a`, is defined by using the order topology on `α`. If `a` is isolated to its right or the function has no right limit, , we use `f a` instead to guarantee a good behavior in most cases. -/ noncomputable def Function.rightLim (f : α → β) (a : α) : β := @Function.leftLim αᵒᵈ β _ _ f a #align function.right_lim Function.rightLim open Function theorem leftLim_eq_of_tendsto [hα : TopologicalSpace α] [h'α : OrderTopology α] [T2Space β] {f : α → β} {a : α} {y : β} (h : 𝓝[<] a ≠ ⊥) (h' : Tendsto f (𝓝[<] a) (𝓝 y)) : leftLim f a = y := by have h'' : ∃ y, Tendsto f (𝓝[<] a) (𝓝 y) := ⟨y, h'⟩ rw [h'α.topology_eq_generate_intervals] at h h' h'' simp only [leftLim, h, h'', not_true, or_self_iff, if_false] haveI := neBot_iff.2 h exact lim_eq h' #align left_lim_eq_of_tendsto leftLim_eq_of_tendsto theorem leftLim_eq_of_eq_bot [hα : TopologicalSpace α] [h'α : OrderTopology α] (f : α → β) {a : α} (h : 𝓝[<] a = ⊥) : leftLim f a = f a := by rw [h'α.topology_eq_generate_intervals] at h simp [leftLim, ite_eq_left_iff, h] #align left_lim_eq_of_eq_bot leftLim_eq_of_eq_bot theorem rightLim_eq_of_tendsto [TopologicalSpace α] [OrderTopology α] [T2Space β] {f : α → β} {a : α} {y : β} (h : 𝓝[>] a ≠ ⊥) (h' : Tendsto f (𝓝[>] a) (𝓝 y)) : Function.rightLim f a = y := @leftLim_eq_of_tendsto αᵒᵈ _ _ _ _ _ _ f a y h h' #align right_lim_eq_of_tendsto rightLim_eq_of_tendsto theorem rightLim_eq_of_eq_bot [TopologicalSpace α] [OrderTopology α] (f : α → β) {a : α} (h : 𝓝[>] a = ⊥) : rightLim f a = f a := @leftLim_eq_of_eq_bot αᵒᵈ _ _ _ _ _ f a h end open Function namespace Monotone variable {α β : Type*} [LinearOrder α] [ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderTopology β] {f : α → β} (hf : Monotone f) {x y : α} theorem leftLim_eq_sSup [TopologicalSpace α] [OrderTopology α] (h : 𝓝[<] x ≠ ⊥) : leftLim f x = sSup (f '' Iio x) := leftLim_eq_of_tendsto h (hf.tendsto_nhdsWithin_Iio x) #align monotone.left_lim_eq_Sup Monotone.leftLim_eq_sSup theorem rightLim_eq_sInf [TopologicalSpace α] [OrderTopology α] (h : 𝓝[>] x ≠ ⊥) : rightLim f x = sInf (f '' Ioi x) := rightLim_eq_of_tendsto h (hf.tendsto_nhdsWithin_Ioi x) #align right_lim_eq_Inf Monotone.rightLim_eq_sInf theorem leftLim_le (h : x ≤ y) : leftLim f x ≤ f y := by letI : TopologicalSpace α := Preorder.topology α haveI : OrderTopology α := ⟨rfl⟩ rcases eq_or_ne (𝓝[<] x) ⊥ with (h' | h') · simpa [leftLim, h'] using hf h haveI A : NeBot (𝓝[<] x) := neBot_iff.2 h' rw [leftLim_eq_sSup hf h'] refine csSup_le ?_ ?_ · simp only [image_nonempty] exact (forall_mem_nonempty_iff_neBot.2 A) _ self_mem_nhdsWithin · simp only [mem_image, mem_Iio, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] intro z hz exact hf (hz.le.trans h) #align monotone.left_lim_le Monotone.leftLim_le theorem le_leftLim (h : x < y) : f x ≤ leftLim f y := by letI : TopologicalSpace α := Preorder.topology α haveI : OrderTopology α := ⟨rfl⟩ rcases eq_or_ne (𝓝[<] y) ⊥ with (h' | h') · rw [leftLim_eq_of_eq_bot _ h'] exact hf h.le rw [leftLim_eq_sSup hf h'] refine le_csSup ⟨f y, ?_⟩ (mem_image_of_mem _ h) simp only [upperBounds, mem_image, mem_Iio, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂, mem_setOf_eq] intro z hz exact hf hz.le #align monotone.le_left_lim Monotone.le_leftLim @[mono] protected theorem leftLim : Monotone (leftLim f) := by intro x y h rcases eq_or_lt_of_le h with (rfl | hxy) · exact le_rfl · exact (hf.leftLim_le le_rfl).trans (hf.le_leftLim hxy) #align monotone.left_lim Monotone.leftLim theorem le_rightLim (h : x ≤ y) : f x ≤ rightLim f y := hf.dual.leftLim_le h #align monotone.le_right_lim Monotone.le_rightLim theorem rightLim_le (h : x < y) : rightLim f x ≤ f y := hf.dual.le_leftLim h #align monotone.right_lim_le Monotone.rightLim_le @[mono] protected theorem rightLim : Monotone (rightLim f) := fun _ _ h => hf.dual.leftLim h #align monotone.right_lim Monotone.rightLim theorem leftLim_le_rightLim (h : x ≤ y) : leftLim f x ≤ rightLim f y := (hf.leftLim_le le_rfl).trans (hf.le_rightLim h) #align monotone.left_lim_le_right_lim Monotone.leftLim_le_rightLim theorem rightLim_le_leftLim (h : x < y) : rightLim f x ≤ leftLim f y := by letI : TopologicalSpace α := Preorder.topology α haveI : OrderTopology α := ⟨rfl⟩ rcases eq_or_ne (𝓝[<] y) ⊥ with (h' | h') · simp [leftLim, h'] exact rightLim_le hf h obtain ⟨a, ⟨xa, ay⟩⟩ : (Ioo x y).Nonempty := forall_mem_nonempty_iff_neBot.2 (neBot_iff.2 h') (Ioo x y) (Ioo_mem_nhdsWithin_Iio ⟨h, le_refl _⟩) calc rightLim f x ≤ f a := hf.rightLim_le xa _ ≤ leftLim f y := hf.le_leftLim ay #align monotone.right_lim_le_left_lim Monotone.rightLim_le_leftLim variable [TopologicalSpace α] [OrderTopology α]
Mathlib/Topology/Order/LeftRightLim.lean
179
183
theorem tendsto_leftLim (x : α) : Tendsto f (𝓝[<] x) (𝓝 (leftLim f x)) := by
rcases eq_or_ne (𝓝[<] x) ⊥ with (h' | h') · simp [h'] rw [leftLim_eq_sSup hf h'] exact hf.tendsto_nhdsWithin_Iio x
/- Copyright (c) 2022 Eric Rodriguez. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Rodriguez, Eric Wieser -/ import Mathlib.Data.List.Chain #align_import data.list.destutter from "leanprover-community/mathlib"@"7b78d1776212a91ecc94cf601f83bdcc46b04213" /-! # Destuttering of Lists This file proves theorems about `List.destutter` (in `Data.List.Defs`), which greedily removes all non-related items that are adjacent in a list, e.g. `[2, 2, 3, 3, 2].destutter (≠) = [2, 3, 2]`. Note that we make no guarantees of being the longest sublist with this property; e.g., `[123, 1, 2, 5, 543, 1000].destutter (<) = [123, 543, 1000]`, but a longer ascending chain could be `[1, 2, 5, 543, 1000]`. ## Main statements * `List.destutter_sublist`: `l.destutter` is a sublist of `l`. * `List.destutter_is_chain'`: `l.destutter` satisfies `Chain' R`. * Analogies of these theorems for `List.destutter'`, which is the `destutter` equivalent of `Chain`. ## Tags adjacent, chain, duplicates, remove, list, stutter, destutter -/ variable {α : Type*} (l : List α) (R : α → α → Prop) [DecidableRel R] {a b : α} namespace List @[simp] theorem destutter'_nil : destutter' R a [] = [a] := rfl #align list.destutter'_nil List.destutter'_nil theorem destutter'_cons : (b :: l).destutter' R a = if R a b then a :: destutter' R b l else destutter' R a l := rfl #align list.destutter'_cons List.destutter'_cons variable {R} @[simp] theorem destutter'_cons_pos (h : R b a) : (a :: l).destutter' R b = b :: l.destutter' R a := by rw [destutter', if_pos h] #align list.destutter'_cons_pos List.destutter'_cons_pos @[simp] theorem destutter'_cons_neg (h : ¬R b a) : (a :: l).destutter' R b = l.destutter' R b := by rw [destutter', if_neg h] #align list.destutter'_cons_neg List.destutter'_cons_neg variable (R) @[simp] theorem destutter'_singleton : [b].destutter' R a = if R a b then [a, b] else [a] := by split_ifs with h <;> simp! [h] #align list.destutter'_singleton List.destutter'_singleton theorem destutter'_sublist (a) : l.destutter' R a <+ a :: l := by induction' l with b l hl generalizing a · simp rw [destutter'] split_ifs · exact Sublist.cons₂ a (hl b) · exact (hl a).trans ((l.sublist_cons b).cons_cons a) #align list.destutter'_sublist List.destutter'_sublist
Mathlib/Data/List/Destutter.lean
73
79
theorem mem_destutter' (a) : a ∈ l.destutter' R a := by
induction' l with b l hl · simp rw [destutter'] split_ifs · simp · assumption
/- Copyright (c) 2022 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.Data.Opposite import Mathlib.Data.Set.Defs #align_import data.set.opposite from "leanprover-community/mathlib"@"fc2ed6f838ce7c9b7c7171e58d78eaf7b438fb0e" /-! # The opposite of a set The opposite of a set `s` is simply the set obtained by taking the opposite of each member of `s`. -/ variable {α : Type*} open Opposite namespace Set /-- The opposite of a set `s` is the set obtained by taking the opposite of each member of `s`. -/ protected def op (s : Set α) : Set αᵒᵖ := unop ⁻¹' s #align set.op Set.op /-- The unop of a set `s` is the set obtained by taking the unop of each member of `s`. -/ protected def unop (s : Set αᵒᵖ) : Set α := op ⁻¹' s #align set.unop Set.unop @[simp] theorem mem_op {s : Set α} {a : αᵒᵖ} : a ∈ s.op ↔ unop a ∈ s := Iff.rfl #align set.mem_op Set.mem_op @[simp 1100]
Mathlib/Data/Set/Opposite.lean
39
39
theorem op_mem_op {s : Set α} {a : α} : op a ∈ s.op ↔ a ∈ s := by
rfl
/- Copyright (c) 2022 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Finsupp.Defs #align_import data.list.to_finsupp from "leanprover-community/mathlib"@"06a655b5fcfbda03502f9158bbf6c0f1400886f9" /-! # Lists as finsupp ## Main definitions - `List.toFinsupp`: Interpret a list as a finitely supported function, where the indexing type is `ℕ`, and the values are either the elements of the list (accessing by indexing) or `0` outside of the list. ## Main theorems - `List.toFinsupp_eq_sum_map_enum_single`: A `l : List M` over `M` an `AddMonoid`, when interpreted as a finitely supported function, is equal to the sum of `Finsupp.single` produced by mapping over `List.enum l`. ## Implementation details The functions defined here rely on a decidability predicate that each element in the list can be decidably determined to be not equal to zero or that one can decide one is out of the bounds of a list. For concretely defined lists that are made up of elements of decidable terms, this holds. More work will be needed to support lists over non-dec-eq types like `ℝ`, where the elements are beyond the dec-eq terms of casted values from `ℕ, ℤ, ℚ`. -/ namespace List variable {M : Type*} [Zero M] (l : List M) [DecidablePred (getD l · 0 ≠ 0)] (n : ℕ) /-- Indexing into a `l : List M`, as a finitely-supported function, where the support are all the indices within the length of the list that index to a non-zero value. Indices beyond the end of the list are sent to 0. This is a computable version of the `Finsupp.onFinset` construction. -/ def toFinsupp : ℕ →₀ M where toFun i := getD l i 0 support := (Finset.range l.length).filter fun i => getD l i 0 ≠ 0 mem_support_toFun n := by simp only [Ne, Finset.mem_filter, Finset.mem_range, and_iff_right_iff_imp] contrapose! exact getD_eq_default _ _ #align list.to_finsupp List.toFinsupp @[norm_cast] theorem coe_toFinsupp : (l.toFinsupp : ℕ → M) = (l.getD · 0) := rfl #align list.coe_to_finsupp List.coe_toFinsupp @[simp, norm_cast] theorem toFinsupp_apply (i : ℕ) : (l.toFinsupp : ℕ → M) i = l.getD i 0 := rfl #align list.to_finsupp_apply List.toFinsupp_apply theorem toFinsupp_support : l.toFinsupp.support = (Finset.range l.length).filter (getD l · 0 ≠ 0) := rfl #align list.to_finsupp_support List.toFinsupp_support theorem toFinsupp_apply_lt (hn : n < l.length) : l.toFinsupp n = l.get ⟨n, hn⟩ := getD_eq_get _ _ _ theorem toFinsupp_apply_fin (n : Fin l.length) : l.toFinsupp n = l.get n := getD_eq_get _ _ _ set_option linter.deprecated false in @[deprecated (since := "2023-04-10")] theorem toFinsupp_apply_lt' (hn : n < l.length) : l.toFinsupp n = l.nthLe n hn := getD_eq_get _ _ _ #align list.to_finsupp_apply_lt List.toFinsupp_apply_lt' theorem toFinsupp_apply_le (hn : l.length ≤ n) : l.toFinsupp n = 0 := getD_eq_default _ _ hn #align list.to_finsupp_apply_le List.toFinsupp_apply_le @[simp] theorem toFinsupp_nil [DecidablePred fun i => getD ([] : List M) i 0 ≠ 0] : toFinsupp ([] : List M) = 0 := by ext simp #align list.to_finsupp_nil List.toFinsupp_nil theorem toFinsupp_singleton (x : M) [DecidablePred (getD [x] · 0 ≠ 0)] : toFinsupp [x] = Finsupp.single 0 x := by ext ⟨_ | i⟩ <;> simp [Finsupp.single_apply, (Nat.zero_lt_succ _).ne] #align list.to_finsupp_singleton List.toFinsupp_singleton @[simp] theorem toFinsupp_cons_apply_zero (x : M) (xs : List M) [DecidablePred (getD (x::xs) · 0 ≠ 0)] : (x::xs).toFinsupp 0 = x := rfl #align list.to_finsupp_cons_apply_zero List.toFinsupp_cons_apply_zero @[simp] theorem toFinsupp_cons_apply_succ (x : M) (xs : List M) (n : ℕ) [DecidablePred (getD (x::xs) · 0 ≠ 0)] [DecidablePred (getD xs · 0 ≠ 0)] : (x::xs).toFinsupp n.succ = xs.toFinsupp n := rfl #align list.to_finsupp_cons_apply_succ List.toFinsupp_cons_apply_succ -- Porting note (#10756): new theorem theorem toFinsupp_append {R : Type*} [AddZeroClass R] (l₁ l₂ : List R) [DecidablePred (getD (l₁ ++ l₂) · 0 ≠ 0)] [DecidablePred (getD l₁ · 0 ≠ 0)] [DecidablePred (getD l₂ · 0 ≠ 0)] : toFinsupp (l₁ ++ l₂) = toFinsupp l₁ + (toFinsupp l₂).embDomain (addLeftEmbedding l₁.length) := by ext n simp only [toFinsupp_apply, Finsupp.add_apply] cases lt_or_le n l₁.length with | inl h => rw [getD_append _ _ _ _ h, Finsupp.embDomain_notin_range, add_zero] rintro ⟨k, rfl : length l₁ + k = n⟩ omega | inr h => rcases Nat.exists_eq_add_of_le h with ⟨k, rfl⟩ rw [getD_append_right _ _ _ _ h, Nat.add_sub_cancel_left, getD_eq_default _ _ h, zero_add] exact Eq.symm (Finsupp.embDomain_apply _ _ _) theorem toFinsupp_cons_eq_single_add_embDomain {R : Type*} [AddZeroClass R] (x : R) (xs : List R) [DecidablePred (getD (x::xs) · 0 ≠ 0)] [DecidablePred (getD xs · 0 ≠ 0)] : toFinsupp (x::xs) = Finsupp.single 0 x + (toFinsupp xs).embDomain ⟨Nat.succ, Nat.succ_injective⟩ := by classical convert toFinsupp_append [x] xs using 3 · exact (toFinsupp_singleton x).symm · ext n exact add_comm n 1 #align list.to_finsupp_cons_eq_single_add_emb_domain List.toFinsupp_cons_eq_single_add_embDomain
Mathlib/Data/List/ToFinsupp.lean
139
143
theorem toFinsupp_concat_eq_toFinsupp_add_single {R : Type*} [AddZeroClass R] (x : R) (xs : List R) [DecidablePred fun i => getD (xs ++ [x]) i 0 ≠ 0] [DecidablePred fun i => getD xs i 0 ≠ 0] : toFinsupp (xs ++ [x]) = toFinsupp xs + Finsupp.single xs.length x := by
classical rw [toFinsupp_append, toFinsupp_singleton, Finsupp.embDomain_single, addLeftEmbedding_apply, add_zero]
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Algebra.Tower import Mathlib.Algebra.Module.BigOperators import Mathlib.LinearAlgebra.Basis #align_import ring_theory.algebra_tower from "leanprover-community/mathlib"@"94825b2b0b982306be14d891c4f063a1eca4f370" /-! # Towers of algebras We set up the basic theory of algebra towers. An algebra tower A/S/R is expressed by having instances of `Algebra A S`, `Algebra R S`, `Algebra R A` and `IsScalarTower R S A`, the later asserting the compatibility condition `(r • s) • a = r • (s • a)`. In `FieldTheory/Tower.lean` we use this to prove the tower law for finite extensions, that if `R` and `S` are both fields, then `[A:R] = [A:S] [S:A]`. In this file we prepare the main lemma: if `{bi | i ∈ I}` is an `R`-basis of `S` and `{cj | j ∈ J}` is an `S`-basis of `A`, then `{bi cj | i ∈ I, j ∈ J}` is an `R`-basis of `A`. This statement does not require the base rings to be a field, so we also generalize the lemma to rings in this file. -/ open Pointwise universe u v w u₁ variable (R : Type u) (S : Type v) (A : Type w) (B : Type u₁) namespace IsScalarTower section Semiring variable [CommSemiring R] [CommSemiring S] [Semiring A] [Semiring B] variable [Algebra R S] [Algebra S A] [Algebra S B] [Algebra R A] [Algebra R B] variable [IsScalarTower R S A] [IsScalarTower R S B] /-- Suppose that `R → S → A` is a tower of algebras. If an element `r : R` is invertible in `S`, then it is invertible in `A`. -/ def Invertible.algebraTower (r : R) [Invertible (algebraMap R S r)] : Invertible (algebraMap R A r) := Invertible.copy (Invertible.map (algebraMap S A) (algebraMap R S r)) (algebraMap R A r) (IsScalarTower.algebraMap_apply R S A r) #align is_scalar_tower.invertible.algebra_tower IsScalarTower.Invertible.algebraTower /-- A natural number that is invertible when coerced to `R` is also invertible when coerced to any `R`-algebra. -/ def invertibleAlgebraCoeNat (n : ℕ) [inv : Invertible (n : R)] : Invertible (n : A) := haveI : Invertible (algebraMap ℕ R n) := inv Invertible.algebraTower ℕ R A n #align is_scalar_tower.invertible_algebra_coe_nat IsScalarTower.invertibleAlgebraCoeNat end Semiring section CommSemiring variable [CommSemiring R] [CommSemiring A] [CommSemiring B] variable [Algebra R A] [Algebra A B] [Algebra R B] [IsScalarTower R A B] end CommSemiring end IsScalarTower section AlgebraMapCoeffs variable {R} {ι M : Type*} [CommSemiring R] [Semiring A] [AddCommMonoid M] variable [Algebra R A] [Module A M] [Module R M] [IsScalarTower R A M] variable (b : Basis ι R M) (h : Function.Bijective (algebraMap R A)) /-- If `R` and `A` have a bijective `algebraMap R A` and act identically on `M`, then a basis for `M` as `R`-module is also a basis for `M` as `R'`-module. -/ @[simps! repr_apply_support_val repr_apply_toFun] noncomputable def Basis.algebraMapCoeffs : Basis ι A M := b.mapCoeffs (RingEquiv.ofBijective _ h) fun c x => by simp #align basis.algebra_map_coeffs Basis.algebraMapCoeffs #noalign Basis.algebraMapCoeffs_repr_symm_apply -- failed simpNF linter theorem Basis.algebraMapCoeffs_apply (i : ι) : b.algebraMapCoeffs A h i = b i := b.mapCoeffs_apply _ _ _ #align basis.algebra_map_coeffs_apply Basis.algebraMapCoeffs_apply @[simp] theorem Basis.coe_algebraMapCoeffs : (b.algebraMapCoeffs A h : ι → M) = b := b.coe_mapCoeffs _ _ #align basis.coe_algebra_map_coeffs Basis.coe_algebraMapCoeffs end AlgebraMapCoeffs section Semiring open Finsupp open scoped Classical universe v₁ w₁ variable {R S A} variable [Semiring R] [Semiring S] [AddCommMonoid A] variable [Module R S] [Module S A] [Module R A] [IsScalarTower R S A] theorem linearIndependent_smul {ι : Type v₁} {b : ι → S} {ι' : Type w₁} {c : ι' → A} (hb : LinearIndependent R b) (hc : LinearIndependent S c) : LinearIndependent R fun p : ι × ι' => b p.1 • c p.2 := by rw [linearIndependent_iff'] at hb hc; rw [linearIndependent_iff'']; rintro s g hg hsg ⟨i, k⟩ by_cases hik : (i, k) ∈ s · have h1 : ∑ i ∈ s.image Prod.fst ×ˢ s.image Prod.snd, g i • b i.1 • c i.2 = 0 := by rw [← hsg] exact (Finset.sum_subset Finset.subset_product fun p _ hp => show g p • b p.1 • c p.2 = 0 by rw [hg p hp, zero_smul]).symm rw [Finset.sum_product_right] at h1 simp_rw [← smul_assoc, ← Finset.sum_smul] at h1 exact hb _ _ (hc _ _ h1 k (Finset.mem_image_of_mem _ hik)) i (Finset.mem_image_of_mem _ hik) exact hg _ hik #align linear_independent_smul linearIndependent_smul variable (R) -- LinearIndependent is enough if S is a ring rather than semiring. theorem Basis.isScalarTower_of_nonempty {ι} [Nonempty ι] (b : Basis ι S A) : IsScalarTower R S S := (b.repr.symm.comp <| lsingle <| Classical.arbitrary ι).isScalarTower_of_injective R (b.repr.symm.injective.comp <| single_injective _) theorem Basis.isScalarTower_finsupp {ι} (b : Basis ι S A) : IsScalarTower R S (ι →₀ S) := b.repr.symm.isScalarTower_of_injective R b.repr.symm.injective variable {R} /-- `Basis.SMul (b : Basis ι R S) (c : Basis ι S A)` is the `R`-basis on `A` where the `(i, j)`th basis vector is `b i • c j`. -/ noncomputable def Basis.smul {ι : Type v₁} {ι' : Type w₁} (b : Basis ι R S) (c : Basis ι' S A) : Basis (ι × ι') R A := haveI := c.isScalarTower_finsupp R .ofRepr (c.repr.restrictScalars R ≪≫ₗ (Finsupp.lcongr (Equiv.refl _) b.repr ≪≫ₗ ((finsuppProdLEquiv R).symm ≪≫ₗ Finsupp.lcongr (Equiv.prodComm ι' ι) (LinearEquiv.refl _ _)))) #align basis.smul Basis.smul @[simp] theorem Basis.smul_repr {ι : Type v₁} {ι' : Type w₁} (b : Basis ι R S) (c : Basis ι' S A) (x ij) : (b.smul c).repr x ij = b.repr (c.repr x ij.2) ij.1 := by simp [Basis.smul] #align basis.smul_repr Basis.smul_repr theorem Basis.smul_repr_mk {ι : Type v₁} {ι' : Type w₁} (b : Basis ι R S) (c : Basis ι' S A) (x i j) : (b.smul c).repr x (i, j) = b.repr (c.repr x j) i := b.smul_repr c x (i, j) #align basis.smul_repr_mk Basis.smul_repr_mk @[simp]
Mathlib/RingTheory/AlgebraTower.lean
160
170
theorem Basis.smul_apply {ι : Type v₁} {ι' : Type w₁} (b : Basis ι R S) (c : Basis ι' S A) (ij) : (b.smul c) ij = b ij.1 • c ij.2 := by
obtain ⟨i, j⟩ := ij rw [Basis.apply_eq_iff] ext ⟨i', j'⟩ rw [Basis.smul_repr, LinearEquiv.map_smul, Basis.repr_self, Finsupp.smul_apply, Finsupp.single_apply] dsimp only split_ifs with hi · simp [hi, Finsupp.single_apply] · simp [hi]
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Yury Kudryashov -/ import Mathlib.Algebra.CharP.Invertible import Mathlib.Analysis.NormedSpace.Basic import Mathlib.Analysis.Normed.Group.AddTorsor import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.normed_space.add_torsor from "leanprover-community/mathlib"@"837f72de63ad6cd96519cde5f1ffd5ed8d280ad0" /-! # Torsors of normed space actions. This file contains lemmas about normed additive torsors over normed spaces. -/ noncomputable section open NNReal Topology open Filter variable {α V P W Q : Type*} [SeminormedAddCommGroup V] [PseudoMetricSpace P] [NormedAddTorsor V P] [NormedAddCommGroup W] [MetricSpace Q] [NormedAddTorsor W Q] section NormedSpace variable {𝕜 : Type*} [NormedField 𝕜] [NormedSpace 𝕜 V] [NormedSpace 𝕜 W] open AffineMap theorem AffineSubspace.isClosed_direction_iff (s : AffineSubspace 𝕜 Q) : IsClosed (s.direction : Set W) ↔ IsClosed (s : Set Q) := by rcases s.eq_bot_or_nonempty with (rfl | ⟨x, hx⟩); · simp [isClosed_singleton] rw [← (IsometryEquiv.vaddConst x).toHomeomorph.symm.isClosed_image, AffineSubspace.coe_direction_eq_vsub_set_right hx] rfl #align affine_subspace.is_closed_direction_iff AffineSubspace.isClosed_direction_iff @[simp] theorem dist_center_homothety (p₁ p₂ : P) (c : 𝕜) : dist p₁ (homothety p₁ c p₂) = ‖c‖ * dist p₁ p₂ := by simp [homothety_def, norm_smul, ← dist_eq_norm_vsub, dist_comm] #align dist_center_homothety dist_center_homothety @[simp] theorem nndist_center_homothety (p₁ p₂ : P) (c : 𝕜) : nndist p₁ (homothety p₁ c p₂) = ‖c‖₊ * nndist p₁ p₂ := NNReal.eq <| dist_center_homothety _ _ _ #align nndist_center_homothety nndist_center_homothety @[simp] theorem dist_homothety_center (p₁ p₂ : P) (c : 𝕜) : dist (homothety p₁ c p₂) p₁ = ‖c‖ * dist p₁ p₂ := by rw [dist_comm, dist_center_homothety] #align dist_homothety_center dist_homothety_center @[simp] theorem nndist_homothety_center (p₁ p₂ : P) (c : 𝕜) : nndist (homothety p₁ c p₂) p₁ = ‖c‖₊ * nndist p₁ p₂ := NNReal.eq <| dist_homothety_center _ _ _ #align nndist_homothety_center nndist_homothety_center @[simp] theorem dist_lineMap_lineMap (p₁ p₂ : P) (c₁ c₂ : 𝕜) : dist (lineMap p₁ p₂ c₁) (lineMap p₁ p₂ c₂) = dist c₁ c₂ * dist p₁ p₂ := by rw [dist_comm p₁ p₂] simp only [lineMap_apply, dist_eq_norm_vsub, vadd_vsub_vadd_cancel_right, ← sub_smul, norm_smul, vsub_eq_sub] #align dist_line_map_line_map dist_lineMap_lineMap @[simp] theorem nndist_lineMap_lineMap (p₁ p₂ : P) (c₁ c₂ : 𝕜) : nndist (lineMap p₁ p₂ c₁) (lineMap p₁ p₂ c₂) = nndist c₁ c₂ * nndist p₁ p₂ := NNReal.eq <| dist_lineMap_lineMap _ _ _ _ #align nndist_line_map_line_map nndist_lineMap_lineMap theorem lipschitzWith_lineMap (p₁ p₂ : P) : LipschitzWith (nndist p₁ p₂) (lineMap p₁ p₂ : 𝕜 → P) := LipschitzWith.of_dist_le_mul fun c₁ c₂ => ((dist_lineMap_lineMap p₁ p₂ c₁ c₂).trans (mul_comm _ _)).le #align lipschitz_with_line_map lipschitzWith_lineMap @[simp] theorem dist_lineMap_left (p₁ p₂ : P) (c : 𝕜) : dist (lineMap p₁ p₂ c) p₁ = ‖c‖ * dist p₁ p₂ := by simpa only [lineMap_apply_zero, dist_zero_right] using dist_lineMap_lineMap p₁ p₂ c 0 #align dist_line_map_left dist_lineMap_left @[simp] theorem nndist_lineMap_left (p₁ p₂ : P) (c : 𝕜) : nndist (lineMap p₁ p₂ c) p₁ = ‖c‖₊ * nndist p₁ p₂ := NNReal.eq <| dist_lineMap_left _ _ _ #align nndist_line_map_left nndist_lineMap_left @[simp] theorem dist_left_lineMap (p₁ p₂ : P) (c : 𝕜) : dist p₁ (lineMap p₁ p₂ c) = ‖c‖ * dist p₁ p₂ := (dist_comm _ _).trans (dist_lineMap_left _ _ _) #align dist_left_line_map dist_left_lineMap @[simp] theorem nndist_left_lineMap (p₁ p₂ : P) (c : 𝕜) : nndist p₁ (lineMap p₁ p₂ c) = ‖c‖₊ * nndist p₁ p₂ := NNReal.eq <| dist_left_lineMap _ _ _ #align nndist_left_line_map nndist_left_lineMap @[simp] theorem dist_lineMap_right (p₁ p₂ : P) (c : 𝕜) : dist (lineMap p₁ p₂ c) p₂ = ‖1 - c‖ * dist p₁ p₂ := by simpa only [lineMap_apply_one, dist_eq_norm'] using dist_lineMap_lineMap p₁ p₂ c 1 #align dist_line_map_right dist_lineMap_right @[simp] theorem nndist_lineMap_right (p₁ p₂ : P) (c : 𝕜) : nndist (lineMap p₁ p₂ c) p₂ = ‖1 - c‖₊ * nndist p₁ p₂ := NNReal.eq <| dist_lineMap_right _ _ _ #align nndist_line_map_right nndist_lineMap_right @[simp] theorem dist_right_lineMap (p₁ p₂ : P) (c : 𝕜) : dist p₂ (lineMap p₁ p₂ c) = ‖1 - c‖ * dist p₁ p₂ := (dist_comm _ _).trans (dist_lineMap_right _ _ _) #align dist_right_line_map dist_right_lineMap @[simp] theorem nndist_right_lineMap (p₁ p₂ : P) (c : 𝕜) : nndist p₂ (lineMap p₁ p₂ c) = ‖1 - c‖₊ * nndist p₁ p₂ := NNReal.eq <| dist_right_lineMap _ _ _ #align nndist_right_line_map nndist_right_lineMap @[simp] theorem dist_homothety_self (p₁ p₂ : P) (c : 𝕜) : dist (homothety p₁ c p₂) p₂ = ‖1 - c‖ * dist p₁ p₂ := by rw [homothety_eq_lineMap, dist_lineMap_right] #align dist_homothety_self dist_homothety_self @[simp] theorem nndist_homothety_self (p₁ p₂ : P) (c : 𝕜) : nndist (homothety p₁ c p₂) p₂ = ‖1 - c‖₊ * nndist p₁ p₂ := NNReal.eq <| dist_homothety_self _ _ _ #align nndist_homothety_self nndist_homothety_self @[simp] theorem dist_self_homothety (p₁ p₂ : P) (c : 𝕜) : dist p₂ (homothety p₁ c p₂) = ‖1 - c‖ * dist p₁ p₂ := by rw [dist_comm, dist_homothety_self] #align dist_self_homothety dist_self_homothety @[simp] theorem nndist_self_homothety (p₁ p₂ : P) (c : 𝕜) : nndist p₂ (homothety p₁ c p₂) = ‖1 - c‖₊ * nndist p₁ p₂ := NNReal.eq <| dist_self_homothety _ _ _ #align nndist_self_homothety nndist_self_homothety section invertibleTwo variable [Invertible (2 : 𝕜)] @[simp] theorem dist_left_midpoint (p₁ p₂ : P) : dist p₁ (midpoint 𝕜 p₁ p₂) = ‖(2 : 𝕜)‖⁻¹ * dist p₁ p₂ := by rw [midpoint, dist_comm, dist_lineMap_left, invOf_eq_inv, ← norm_inv] #align dist_left_midpoint dist_left_midpoint @[simp] theorem nndist_left_midpoint (p₁ p₂ : P) : nndist p₁ (midpoint 𝕜 p₁ p₂) = ‖(2 : 𝕜)‖₊⁻¹ * nndist p₁ p₂ := NNReal.eq <| dist_left_midpoint _ _ #align nndist_left_midpoint nndist_left_midpoint @[simp] theorem dist_midpoint_left (p₁ p₂ : P) : dist (midpoint 𝕜 p₁ p₂) p₁ = ‖(2 : 𝕜)‖⁻¹ * dist p₁ p₂ := by rw [dist_comm, dist_left_midpoint] #align dist_midpoint_left dist_midpoint_left @[simp] theorem nndist_midpoint_left (p₁ p₂ : P) : nndist (midpoint 𝕜 p₁ p₂) p₁ = ‖(2 : 𝕜)‖₊⁻¹ * nndist p₁ p₂ := NNReal.eq <| dist_midpoint_left _ _ #align nndist_midpoint_left nndist_midpoint_left @[simp] theorem dist_midpoint_right (p₁ p₂ : P) : dist (midpoint 𝕜 p₁ p₂) p₂ = ‖(2 : 𝕜)‖⁻¹ * dist p₁ p₂ := by rw [midpoint_comm, dist_midpoint_left, dist_comm] #align dist_midpoint_right dist_midpoint_right @[simp] theorem nndist_midpoint_right (p₁ p₂ : P) : nndist (midpoint 𝕜 p₁ p₂) p₂ = ‖(2 : 𝕜)‖₊⁻¹ * nndist p₁ p₂ := NNReal.eq <| dist_midpoint_right _ _ #align nndist_midpoint_right nndist_midpoint_right @[simp] theorem dist_right_midpoint (p₁ p₂ : P) : dist p₂ (midpoint 𝕜 p₁ p₂) = ‖(2 : 𝕜)‖⁻¹ * dist p₁ p₂ := by rw [dist_comm, dist_midpoint_right] #align dist_right_midpoint dist_right_midpoint @[simp] theorem nndist_right_midpoint (p₁ p₂ : P) : nndist p₂ (midpoint 𝕜 p₁ p₂) = ‖(2 : 𝕜)‖₊⁻¹ * nndist p₁ p₂ := NNReal.eq <| dist_right_midpoint _ _ #align nndist_right_midpoint nndist_right_midpoint theorem dist_midpoint_midpoint_le' (p₁ p₂ p₃ p₄ : P) : dist (midpoint 𝕜 p₁ p₂) (midpoint 𝕜 p₃ p₄) ≤ (dist p₁ p₃ + dist p₂ p₄) / ‖(2 : 𝕜)‖ := by rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, midpoint_vsub_midpoint] rw [midpoint_eq_smul_add, norm_smul, invOf_eq_inv, norm_inv, ← div_eq_inv_mul] exact div_le_div_of_nonneg_right (norm_add_le _ _) (norm_nonneg _) #align dist_midpoint_midpoint_le' dist_midpoint_midpoint_le' theorem nndist_midpoint_midpoint_le' (p₁ p₂ p₃ p₄ : P) : nndist (midpoint 𝕜 p₁ p₂) (midpoint 𝕜 p₃ p₄) ≤ (nndist p₁ p₃ + nndist p₂ p₄) / ‖(2 : 𝕜)‖₊ := dist_midpoint_midpoint_le' _ _ _ _ #align nndist_midpoint_midpoint_le' nndist_midpoint_midpoint_le' end invertibleTwo @[simp] theorem dist_pointReflection_left (p q : P) : dist (Equiv.pointReflection p q) p = dist p q := by simp [dist_eq_norm_vsub V, Equiv.pointReflection_vsub_left (G := V)] @[simp] theorem dist_left_pointReflection (p q : P) : dist p (Equiv.pointReflection p q) = dist p q := (dist_comm _ _).trans (dist_pointReflection_left _ _) variable (𝕜) in
Mathlib/Analysis/NormedSpace/AddTorsor.lean
227
230
theorem dist_pointReflection_right (p q : P) : dist (Equiv.pointReflection p q) q = ‖(2 : 𝕜)‖ * dist p q := by
simp [dist_eq_norm_vsub V, Equiv.pointReflection_vsub_right (G := V), nsmul_eq_smul_cast 𝕜, norm_smul]
/- Copyright (c) 2021 Bryan Gin-ge Chen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz, Bryan Gin-ge Chen, Yaël Dillies -/ import Mathlib.Order.BooleanAlgebra import Mathlib.Logic.Equiv.Basic #align_import order.symm_diff from "leanprover-community/mathlib"@"6eb334bd8f3433d5b08ba156b8ec3e6af47e1904" /-! # Symmetric difference and bi-implication This file defines the symmetric difference and bi-implication operators in (co-)Heyting algebras. ## Examples Some examples are * The symmetric difference of two sets is the set of elements that are in either but not both. * The symmetric difference on propositions is `Xor'`. * The symmetric difference on `Bool` is `Bool.xor`. * The equivalence of propositions. Two propositions are equivalent if they imply each other. * The symmetric difference translates to addition when considering a Boolean algebra as a Boolean ring. ## Main declarations * `symmDiff`: The symmetric difference operator, defined as `(a \ b) ⊔ (b \ a)` * `bihimp`: The bi-implication operator, defined as `(b ⇨ a) ⊓ (a ⇨ b)` In generalized Boolean algebras, the symmetric difference operator is: * `symmDiff_comm`: commutative, and * `symmDiff_assoc`: associative. ## Notations * `a ∆ b`: `symmDiff a b` * `a ⇔ b`: `bihimp a b` ## References The proof of associativity follows the note "Associativity of the Symmetric Difference of Sets: A Proof from the Book" by John McCuan: * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> ## Tags boolean ring, generalized boolean algebra, boolean algebra, symmetric difference, bi-implication, Heyting -/ open Function OrderDual variable {ι α β : Type*} {π : ι → Type*} /-- The symmetric difference operator on a type with `⊔` and `\` is `(A \ B) ⊔ (B \ A)`. -/ def symmDiff [Sup α] [SDiff α] (a b : α) : α := a \ b ⊔ b \ a #align symm_diff symmDiff /-- The Heyting bi-implication is `(b ⇨ a) ⊓ (a ⇨ b)`. This generalizes equivalence of propositions. -/ def bihimp [Inf α] [HImp α] (a b : α) : α := (b ⇨ a) ⊓ (a ⇨ b) #align bihimp bihimp /-- Notation for symmDiff -/ scoped[symmDiff] infixl:100 " ∆ " => symmDiff /-- Notation for bihimp -/ scoped[symmDiff] infixl:100 " ⇔ " => bihimp open scoped symmDiff theorem symmDiff_def [Sup α] [SDiff α] (a b : α) : a ∆ b = a \ b ⊔ b \ a := rfl #align symm_diff_def symmDiff_def theorem bihimp_def [Inf α] [HImp α] (a b : α) : a ⇔ b = (b ⇨ a) ⊓ (a ⇨ b) := rfl #align bihimp_def bihimp_def theorem symmDiff_eq_Xor' (p q : Prop) : p ∆ q = Xor' p q := rfl #align symm_diff_eq_xor symmDiff_eq_Xor' @[simp] theorem bihimp_iff_iff {p q : Prop} : p ⇔ q ↔ (p ↔ q) := (iff_iff_implies_and_implies _ _).symm.trans Iff.comm #align bihimp_iff_iff bihimp_iff_iff @[simp] theorem Bool.symmDiff_eq_xor : ∀ p q : Bool, p ∆ q = xor p q := by decide #align bool.symm_diff_eq_bxor Bool.symmDiff_eq_xor section GeneralizedCoheytingAlgebra variable [GeneralizedCoheytingAlgebra α] (a b c d : α) @[simp] theorem toDual_symmDiff : toDual (a ∆ b) = toDual a ⇔ toDual b := rfl #align to_dual_symm_diff toDual_symmDiff @[simp] theorem ofDual_bihimp (a b : αᵒᵈ) : ofDual (a ⇔ b) = ofDual a ∆ ofDual b := rfl #align of_dual_bihimp ofDual_bihimp theorem symmDiff_comm : a ∆ b = b ∆ a := by simp only [symmDiff, sup_comm] #align symm_diff_comm symmDiff_comm instance symmDiff_isCommutative : Std.Commutative (α := α) (· ∆ ·) := ⟨symmDiff_comm⟩ #align symm_diff_is_comm symmDiff_isCommutative @[simp] theorem symmDiff_self : a ∆ a = ⊥ := by rw [symmDiff, sup_idem, sdiff_self] #align symm_diff_self symmDiff_self @[simp] theorem symmDiff_bot : a ∆ ⊥ = a := by rw [symmDiff, sdiff_bot, bot_sdiff, sup_bot_eq] #align symm_diff_bot symmDiff_bot @[simp] theorem bot_symmDiff : ⊥ ∆ a = a := by rw [symmDiff_comm, symmDiff_bot] #align bot_symm_diff bot_symmDiff @[simp] theorem symmDiff_eq_bot {a b : α} : a ∆ b = ⊥ ↔ a = b := by simp_rw [symmDiff, sup_eq_bot_iff, sdiff_eq_bot_iff, le_antisymm_iff] #align symm_diff_eq_bot symmDiff_eq_bot theorem symmDiff_of_le {a b : α} (h : a ≤ b) : a ∆ b = b \ a := by rw [symmDiff, sdiff_eq_bot_iff.2 h, bot_sup_eq] #align symm_diff_of_le symmDiff_of_le theorem symmDiff_of_ge {a b : α} (h : b ≤ a) : a ∆ b = a \ b := by rw [symmDiff, sdiff_eq_bot_iff.2 h, sup_bot_eq] #align symm_diff_of_ge symmDiff_of_ge theorem symmDiff_le {a b c : α} (ha : a ≤ b ⊔ c) (hb : b ≤ a ⊔ c) : a ∆ b ≤ c := sup_le (sdiff_le_iff.2 ha) <| sdiff_le_iff.2 hb #align symm_diff_le symmDiff_le theorem symmDiff_le_iff {a b c : α} : a ∆ b ≤ c ↔ a ≤ b ⊔ c ∧ b ≤ a ⊔ c := by simp_rw [symmDiff, sup_le_iff, sdiff_le_iff] #align symm_diff_le_iff symmDiff_le_iff @[simp] theorem symmDiff_le_sup {a b : α} : a ∆ b ≤ a ⊔ b := sup_le_sup sdiff_le sdiff_le #align symm_diff_le_sup symmDiff_le_sup theorem symmDiff_eq_sup_sdiff_inf : a ∆ b = (a ⊔ b) \ (a ⊓ b) := by simp [sup_sdiff, symmDiff] #align symm_diff_eq_sup_sdiff_inf symmDiff_eq_sup_sdiff_inf theorem Disjoint.symmDiff_eq_sup {a b : α} (h : Disjoint a b) : a ∆ b = a ⊔ b := by rw [symmDiff, h.sdiff_eq_left, h.sdiff_eq_right] #align disjoint.symm_diff_eq_sup Disjoint.symmDiff_eq_sup theorem symmDiff_sdiff : a ∆ b \ c = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) := by rw [symmDiff, sup_sdiff_distrib, sdiff_sdiff_left, sdiff_sdiff_left] #align symm_diff_sdiff symmDiff_sdiff @[simp] theorem symmDiff_sdiff_inf : a ∆ b \ (a ⊓ b) = a ∆ b := by rw [symmDiff_sdiff] simp [symmDiff] #align symm_diff_sdiff_inf symmDiff_sdiff_inf @[simp] theorem symmDiff_sdiff_eq_sup : a ∆ (b \ a) = a ⊔ b := by rw [symmDiff, sdiff_idem] exact le_antisymm (sup_le_sup sdiff_le sdiff_le) (sup_le le_sdiff_sup <| le_sdiff_sup.trans <| sup_le le_sup_right le_sdiff_sup) #align symm_diff_sdiff_eq_sup symmDiff_sdiff_eq_sup @[simp] theorem sdiff_symmDiff_eq_sup : (a \ b) ∆ b = a ⊔ b := by rw [symmDiff_comm, symmDiff_sdiff_eq_sup, sup_comm] #align sdiff_symm_diff_eq_sup sdiff_symmDiff_eq_sup @[simp] theorem symmDiff_sup_inf : a ∆ b ⊔ a ⊓ b = a ⊔ b := by refine le_antisymm (sup_le symmDiff_le_sup inf_le_sup) ?_ rw [sup_inf_left, symmDiff] refine sup_le (le_inf le_sup_right ?_) (le_inf ?_ le_sup_right) · rw [sup_right_comm] exact le_sup_of_le_left le_sdiff_sup · rw [sup_assoc] exact le_sup_of_le_right le_sdiff_sup #align symm_diff_sup_inf symmDiff_sup_inf @[simp] theorem inf_sup_symmDiff : a ⊓ b ⊔ a ∆ b = a ⊔ b := by rw [sup_comm, symmDiff_sup_inf] #align inf_sup_symm_diff inf_sup_symmDiff @[simp] theorem symmDiff_symmDiff_inf : a ∆ b ∆ (a ⊓ b) = a ⊔ b := by rw [← symmDiff_sdiff_inf a, sdiff_symmDiff_eq_sup, symmDiff_sup_inf] #align symm_diff_symm_diff_inf symmDiff_symmDiff_inf @[simp] theorem inf_symmDiff_symmDiff : (a ⊓ b) ∆ (a ∆ b) = a ⊔ b := by rw [symmDiff_comm, symmDiff_symmDiff_inf] #align inf_symm_diff_symm_diff inf_symmDiff_symmDiff theorem symmDiff_triangle : a ∆ c ≤ a ∆ b ⊔ b ∆ c := by refine (sup_le_sup (sdiff_triangle a b c) <| sdiff_triangle _ b _).trans_eq ?_ rw [sup_comm (c \ b), sup_sup_sup_comm, symmDiff, symmDiff] #align symm_diff_triangle symmDiff_triangle theorem le_symmDiff_sup_right (a b : α) : a ≤ (a ∆ b) ⊔ b := by convert symmDiff_triangle a b ⊥ <;> rw [symmDiff_bot] theorem le_symmDiff_sup_left (a b : α) : b ≤ (a ∆ b) ⊔ a := symmDiff_comm a b ▸ le_symmDiff_sup_right .. end GeneralizedCoheytingAlgebra section GeneralizedHeytingAlgebra variable [GeneralizedHeytingAlgebra α] (a b c d : α) @[simp] theorem toDual_bihimp : toDual (a ⇔ b) = toDual a ∆ toDual b := rfl #align to_dual_bihimp toDual_bihimp @[simp] theorem ofDual_symmDiff (a b : αᵒᵈ) : ofDual (a ∆ b) = ofDual a ⇔ ofDual b := rfl #align of_dual_symm_diff ofDual_symmDiff theorem bihimp_comm : a ⇔ b = b ⇔ a := by simp only [(· ⇔ ·), inf_comm] #align bihimp_comm bihimp_comm instance bihimp_isCommutative : Std.Commutative (α := α) (· ⇔ ·) := ⟨bihimp_comm⟩ #align bihimp_is_comm bihimp_isCommutative @[simp] theorem bihimp_self : a ⇔ a = ⊤ := by rw [bihimp, inf_idem, himp_self] #align bihimp_self bihimp_self @[simp] theorem bihimp_top : a ⇔ ⊤ = a := by rw [bihimp, himp_top, top_himp, inf_top_eq] #align bihimp_top bihimp_top @[simp] theorem top_bihimp : ⊤ ⇔ a = a := by rw [bihimp_comm, bihimp_top] #align top_bihimp top_bihimp @[simp] theorem bihimp_eq_top {a b : α} : a ⇔ b = ⊤ ↔ a = b := @symmDiff_eq_bot αᵒᵈ _ _ _ #align bihimp_eq_top bihimp_eq_top theorem bihimp_of_le {a b : α} (h : a ≤ b) : a ⇔ b = b ⇨ a := by rw [bihimp, himp_eq_top_iff.2 h, inf_top_eq] #align bihimp_of_le bihimp_of_le theorem bihimp_of_ge {a b : α} (h : b ≤ a) : a ⇔ b = a ⇨ b := by rw [bihimp, himp_eq_top_iff.2 h, top_inf_eq] #align bihimp_of_ge bihimp_of_ge theorem le_bihimp {a b c : α} (hb : a ⊓ b ≤ c) (hc : a ⊓ c ≤ b) : a ≤ b ⇔ c := le_inf (le_himp_iff.2 hc) <| le_himp_iff.2 hb #align le_bihimp le_bihimp theorem le_bihimp_iff {a b c : α} : a ≤ b ⇔ c ↔ a ⊓ b ≤ c ∧ a ⊓ c ≤ b := by simp_rw [bihimp, le_inf_iff, le_himp_iff, and_comm] #align le_bihimp_iff le_bihimp_iff @[simp] theorem inf_le_bihimp {a b : α} : a ⊓ b ≤ a ⇔ b := inf_le_inf le_himp le_himp #align inf_le_bihimp inf_le_bihimp theorem bihimp_eq_inf_himp_inf : a ⇔ b = a ⊔ b ⇨ a ⊓ b := by simp [himp_inf_distrib, bihimp] #align bihimp_eq_inf_himp_inf bihimp_eq_inf_himp_inf theorem Codisjoint.bihimp_eq_inf {a b : α} (h : Codisjoint a b) : a ⇔ b = a ⊓ b := by rw [bihimp, h.himp_eq_left, h.himp_eq_right] #align codisjoint.bihimp_eq_inf Codisjoint.bihimp_eq_inf theorem himp_bihimp : a ⇨ b ⇔ c = (a ⊓ c ⇨ b) ⊓ (a ⊓ b ⇨ c) := by rw [bihimp, himp_inf_distrib, himp_himp, himp_himp] #align himp_bihimp himp_bihimp @[simp] theorem sup_himp_bihimp : a ⊔ b ⇨ a ⇔ b = a ⇔ b := by rw [himp_bihimp] simp [bihimp] #align sup_himp_bihimp sup_himp_bihimp @[simp] theorem bihimp_himp_eq_inf : a ⇔ (a ⇨ b) = a ⊓ b := @symmDiff_sdiff_eq_sup αᵒᵈ _ _ _ #align bihimp_himp_eq_inf bihimp_himp_eq_inf @[simp] theorem himp_bihimp_eq_inf : (b ⇨ a) ⇔ b = a ⊓ b := @sdiff_symmDiff_eq_sup αᵒᵈ _ _ _ #align himp_bihimp_eq_inf himp_bihimp_eq_inf @[simp] theorem bihimp_inf_sup : a ⇔ b ⊓ (a ⊔ b) = a ⊓ b := @symmDiff_sup_inf αᵒᵈ _ _ _ #align bihimp_inf_sup bihimp_inf_sup @[simp] theorem sup_inf_bihimp : (a ⊔ b) ⊓ a ⇔ b = a ⊓ b := @inf_sup_symmDiff αᵒᵈ _ _ _ #align sup_inf_bihimp sup_inf_bihimp @[simp] theorem bihimp_bihimp_sup : a ⇔ b ⇔ (a ⊔ b) = a ⊓ b := @symmDiff_symmDiff_inf αᵒᵈ _ _ _ #align bihimp_bihimp_sup bihimp_bihimp_sup @[simp] theorem sup_bihimp_bihimp : (a ⊔ b) ⇔ (a ⇔ b) = a ⊓ b := @inf_symmDiff_symmDiff αᵒᵈ _ _ _ #align sup_bihimp_bihimp sup_bihimp_bihimp theorem bihimp_triangle : a ⇔ b ⊓ b ⇔ c ≤ a ⇔ c := @symmDiff_triangle αᵒᵈ _ _ _ _ #align bihimp_triangle bihimp_triangle end GeneralizedHeytingAlgebra section CoheytingAlgebra variable [CoheytingAlgebra α] (a : α) @[simp] theorem symmDiff_top' : a ∆ ⊤ = ¬a := by simp [symmDiff] #align symm_diff_top' symmDiff_top' @[simp] theorem top_symmDiff' : ⊤ ∆ a = ¬a := by simp [symmDiff] #align top_symm_diff' top_symmDiff' @[simp] theorem hnot_symmDiff_self : (¬a) ∆ a = ⊤ := by rw [eq_top_iff, symmDiff, hnot_sdiff, sup_sdiff_self] exact Codisjoint.top_le codisjoint_hnot_left #align hnot_symm_diff_self hnot_symmDiff_self @[simp] theorem symmDiff_hnot_self : a ∆ (¬a) = ⊤ := by rw [symmDiff_comm, hnot_symmDiff_self] #align symm_diff_hnot_self symmDiff_hnot_self theorem IsCompl.symmDiff_eq_top {a b : α} (h : IsCompl a b) : a ∆ b = ⊤ := by rw [h.eq_hnot, hnot_symmDiff_self] #align is_compl.symm_diff_eq_top IsCompl.symmDiff_eq_top end CoheytingAlgebra section HeytingAlgebra variable [HeytingAlgebra α] (a : α) @[simp] theorem bihimp_bot : a ⇔ ⊥ = aᶜ := by simp [bihimp] #align bihimp_bot bihimp_bot @[simp] theorem bot_bihimp : ⊥ ⇔ a = aᶜ := by simp [bihimp] #align bot_bihimp bot_bihimp @[simp] theorem compl_bihimp_self : aᶜ ⇔ a = ⊥ := @hnot_symmDiff_self αᵒᵈ _ _ #align compl_bihimp_self compl_bihimp_self @[simp] theorem bihimp_hnot_self : a ⇔ aᶜ = ⊥ := @symmDiff_hnot_self αᵒᵈ _ _ #align bihimp_hnot_self bihimp_hnot_self theorem IsCompl.bihimp_eq_bot {a b : α} (h : IsCompl a b) : a ⇔ b = ⊥ := by rw [h.eq_compl, compl_bihimp_self] #align is_compl.bihimp_eq_bot IsCompl.bihimp_eq_bot end HeytingAlgebra section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra α] (a b c d : α) @[simp] theorem sup_sdiff_symmDiff : (a ⊔ b) \ a ∆ b = a ⊓ b := sdiff_eq_symm inf_le_sup (by rw [symmDiff_eq_sup_sdiff_inf]) #align sup_sdiff_symm_diff sup_sdiff_symmDiff theorem disjoint_symmDiff_inf : Disjoint (a ∆ b) (a ⊓ b) := by rw [symmDiff_eq_sup_sdiff_inf] exact disjoint_sdiff_self_left #align disjoint_symm_diff_inf disjoint_symmDiff_inf theorem inf_symmDiff_distrib_left : a ⊓ b ∆ c = (a ⊓ b) ∆ (a ⊓ c) := by rw [symmDiff_eq_sup_sdiff_inf, inf_sdiff_distrib_left, inf_sup_left, inf_inf_distrib_left, symmDiff_eq_sup_sdiff_inf] #align inf_symm_diff_distrib_left inf_symmDiff_distrib_left theorem inf_symmDiff_distrib_right : a ∆ b ⊓ c = (a ⊓ c) ∆ (b ⊓ c) := by simp_rw [inf_comm _ c, inf_symmDiff_distrib_left] #align inf_symm_diff_distrib_right inf_symmDiff_distrib_right theorem sdiff_symmDiff : c \ a ∆ b = c ⊓ a ⊓ b ⊔ c \ a ⊓ c \ b := by simp only [(· ∆ ·), sdiff_sdiff_sup_sdiff'] #align sdiff_symm_diff sdiff_symmDiff theorem sdiff_symmDiff' : c \ a ∆ b = c ⊓ a ⊓ b ⊔ c \ (a ⊔ b) := by rw [sdiff_symmDiff, sdiff_sup] #align sdiff_symm_diff' sdiff_symmDiff' @[simp] theorem symmDiff_sdiff_left : a ∆ b \ a = b \ a := by rw [symmDiff_def, sup_sdiff, sdiff_idem, sdiff_sdiff_self, bot_sup_eq] #align symm_diff_sdiff_left symmDiff_sdiff_left @[simp] theorem symmDiff_sdiff_right : a ∆ b \ b = a \ b := by rw [symmDiff_comm, symmDiff_sdiff_left] #align symm_diff_sdiff_right symmDiff_sdiff_right @[simp] theorem sdiff_symmDiff_left : a \ a ∆ b = a ⊓ b := by simp [sdiff_symmDiff] #align sdiff_symm_diff_left sdiff_symmDiff_left @[simp] theorem sdiff_symmDiff_right : b \ a ∆ b = a ⊓ b := by rw [symmDiff_comm, inf_comm, sdiff_symmDiff_left] #align sdiff_symm_diff_right sdiff_symmDiff_right theorem symmDiff_eq_sup : a ∆ b = a ⊔ b ↔ Disjoint a b := by refine ⟨fun h => ?_, Disjoint.symmDiff_eq_sup⟩ rw [symmDiff_eq_sup_sdiff_inf, sdiff_eq_self_iff_disjoint] at h exact h.of_disjoint_inf_of_le le_sup_left #align symm_diff_eq_sup symmDiff_eq_sup @[simp] theorem le_symmDiff_iff_left : a ≤ a ∆ b ↔ Disjoint a b := by refine ⟨fun h => ?_, fun h => h.symmDiff_eq_sup.symm ▸ le_sup_left⟩ rw [symmDiff_eq_sup_sdiff_inf] at h exact disjoint_iff_inf_le.mpr (le_sdiff_iff.1 <| inf_le_of_left_le h).le #align le_symm_diff_iff_left le_symmDiff_iff_left @[simp] theorem le_symmDiff_iff_right : b ≤ a ∆ b ↔ Disjoint a b := by rw [symmDiff_comm, le_symmDiff_iff_left, disjoint_comm] #align le_symm_diff_iff_right le_symmDiff_iff_right theorem symmDiff_symmDiff_left : a ∆ b ∆ c = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) ⊔ c \ (a ⊔ b) ⊔ a ⊓ b ⊓ c := calc a ∆ b ∆ c = a ∆ b \ c ⊔ c \ a ∆ b := symmDiff_def _ _ _ = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) ⊔ (c \ (a ⊔ b) ⊔ c ⊓ a ⊓ b) := by { rw [sdiff_symmDiff', sup_comm (c ⊓ a ⊓ b), symmDiff_sdiff] } _ = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) ⊔ c \ (a ⊔ b) ⊔ a ⊓ b ⊓ c := by ac_rfl #align symm_diff_symm_diff_left symmDiff_symmDiff_left theorem symmDiff_symmDiff_right : a ∆ (b ∆ c) = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) ⊔ c \ (a ⊔ b) ⊔ a ⊓ b ⊓ c := calc a ∆ (b ∆ c) = a \ b ∆ c ⊔ b ∆ c \ a := symmDiff_def _ _ _ = a \ (b ⊔ c) ⊔ a ⊓ b ⊓ c ⊔ (b \ (c ⊔ a) ⊔ c \ (b ⊔ a)) := by { rw [sdiff_symmDiff', sup_comm (a ⊓ b ⊓ c), symmDiff_sdiff] } _ = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) ⊔ c \ (a ⊔ b) ⊔ a ⊓ b ⊓ c := by ac_rfl #align symm_diff_symm_diff_right symmDiff_symmDiff_right theorem symmDiff_assoc : a ∆ b ∆ c = a ∆ (b ∆ c) := by rw [symmDiff_symmDiff_left, symmDiff_symmDiff_right] #align symm_diff_assoc symmDiff_assoc instance symmDiff_isAssociative : Std.Associative (α := α) (· ∆ ·) := ⟨symmDiff_assoc⟩ #align symm_diff_is_assoc symmDiff_isAssociative theorem symmDiff_left_comm : a ∆ (b ∆ c) = b ∆ (a ∆ c) := by simp_rw [← symmDiff_assoc, symmDiff_comm] #align symm_diff_left_comm symmDiff_left_comm theorem symmDiff_right_comm : a ∆ b ∆ c = a ∆ c ∆ b := by simp_rw [symmDiff_assoc, symmDiff_comm] #align symm_diff_right_comm symmDiff_right_comm theorem symmDiff_symmDiff_symmDiff_comm : a ∆ b ∆ (c ∆ d) = a ∆ c ∆ (b ∆ d) := by simp_rw [symmDiff_assoc, symmDiff_left_comm] #align symm_diff_symm_diff_symm_diff_comm symmDiff_symmDiff_symmDiff_comm @[simp] theorem symmDiff_symmDiff_cancel_left : a ∆ (a ∆ b) = b := by simp [← symmDiff_assoc] #align symm_diff_symm_diff_cancel_left symmDiff_symmDiff_cancel_left @[simp] theorem symmDiff_symmDiff_cancel_right : b ∆ a ∆ a = b := by simp [symmDiff_assoc] #align symm_diff_symm_diff_cancel_right symmDiff_symmDiff_cancel_right @[simp] theorem symmDiff_symmDiff_self' : a ∆ b ∆ a = b := by rw [symmDiff_comm, symmDiff_symmDiff_cancel_left] #align symm_diff_symm_diff_self' symmDiff_symmDiff_self' theorem symmDiff_left_involutive (a : α) : Involutive (· ∆ a) := symmDiff_symmDiff_cancel_right _ #align symm_diff_left_involutive symmDiff_left_involutive theorem symmDiff_right_involutive (a : α) : Involutive (a ∆ ·) := symmDiff_symmDiff_cancel_left _ #align symm_diff_right_involutive symmDiff_right_involutive theorem symmDiff_left_injective (a : α) : Injective (· ∆ a) := Function.Involutive.injective (symmDiff_left_involutive a) #align symm_diff_left_injective symmDiff_left_injective theorem symmDiff_right_injective (a : α) : Injective (a ∆ ·) := Function.Involutive.injective (symmDiff_right_involutive _) #align symm_diff_right_injective symmDiff_right_injective theorem symmDiff_left_surjective (a : α) : Surjective (· ∆ a) := Function.Involutive.surjective (symmDiff_left_involutive _) #align symm_diff_left_surjective symmDiff_left_surjective theorem symmDiff_right_surjective (a : α) : Surjective (a ∆ ·) := Function.Involutive.surjective (symmDiff_right_involutive _) #align symm_diff_right_surjective symmDiff_right_surjective variable {a b c} @[simp] theorem symmDiff_left_inj : a ∆ b = c ∆ b ↔ a = c := (symmDiff_left_injective _).eq_iff #align symm_diff_left_inj symmDiff_left_inj @[simp] theorem symmDiff_right_inj : a ∆ b = a ∆ c ↔ b = c := (symmDiff_right_injective _).eq_iff #align symm_diff_right_inj symmDiff_right_inj @[simp] theorem symmDiff_eq_left : a ∆ b = a ↔ b = ⊥ := calc a ∆ b = a ↔ a ∆ b = a ∆ ⊥ := by rw [symmDiff_bot] _ ↔ b = ⊥ := by rw [symmDiff_right_inj] #align symm_diff_eq_left symmDiff_eq_left @[simp] theorem symmDiff_eq_right : a ∆ b = b ↔ a = ⊥ := by rw [symmDiff_comm, symmDiff_eq_left] #align symm_diff_eq_right symmDiff_eq_right protected theorem Disjoint.symmDiff_left (ha : Disjoint a c) (hb : Disjoint b c) : Disjoint (a ∆ b) c := by rw [symmDiff_eq_sup_sdiff_inf] exact (ha.sup_left hb).disjoint_sdiff_left #align disjoint.symm_diff_left Disjoint.symmDiff_left protected theorem Disjoint.symmDiff_right (ha : Disjoint a b) (hb : Disjoint a c) : Disjoint a (b ∆ c) := (ha.symm.symmDiff_left hb.symm).symm #align disjoint.symm_diff_right Disjoint.symmDiff_right theorem symmDiff_eq_iff_sdiff_eq (ha : a ≤ c) : a ∆ b = c ↔ c \ a = b := by rw [← symmDiff_of_le ha] exact ((symmDiff_right_involutive a).toPerm _).apply_eq_iff_eq_symm_apply.trans eq_comm #align symm_diff_eq_iff_sdiff_eq symmDiff_eq_iff_sdiff_eq end GeneralizedBooleanAlgebra section BooleanAlgebra variable [BooleanAlgebra α] (a b c d : α) /-! `CogeneralizedBooleanAlgebra` isn't actually a typeclass, but the lemmas in here are dual to the `GeneralizedBooleanAlgebra` ones -/ section CogeneralizedBooleanAlgebra @[simp] theorem inf_himp_bihimp : a ⇔ b ⇨ a ⊓ b = a ⊔ b := @sup_sdiff_symmDiff αᵒᵈ _ _ _ #align inf_himp_bihimp inf_himp_bihimp theorem codisjoint_bihimp_sup : Codisjoint (a ⇔ b) (a ⊔ b) := @disjoint_symmDiff_inf αᵒᵈ _ _ _ #align codisjoint_bihimp_sup codisjoint_bihimp_sup @[simp] theorem himp_bihimp_left : a ⇨ a ⇔ b = a ⇨ b := @symmDiff_sdiff_left αᵒᵈ _ _ _ #align himp_bihimp_left himp_bihimp_left @[simp] theorem himp_bihimp_right : b ⇨ a ⇔ b = b ⇨ a := @symmDiff_sdiff_right αᵒᵈ _ _ _ #align himp_bihimp_right himp_bihimp_right @[simp] theorem bihimp_himp_left : a ⇔ b ⇨ a = a ⊔ b := @sdiff_symmDiff_left αᵒᵈ _ _ _ #align bihimp_himp_left bihimp_himp_left @[simp] theorem bihimp_himp_right : a ⇔ b ⇨ b = a ⊔ b := @sdiff_symmDiff_right αᵒᵈ _ _ _ #align bihimp_himp_right bihimp_himp_right @[simp] theorem bihimp_eq_inf : a ⇔ b = a ⊓ b ↔ Codisjoint a b := @symmDiff_eq_sup αᵒᵈ _ _ _ #align bihimp_eq_inf bihimp_eq_inf @[simp] theorem bihimp_le_iff_left : a ⇔ b ≤ a ↔ Codisjoint a b := @le_symmDiff_iff_left αᵒᵈ _ _ _ #align bihimp_le_iff_left bihimp_le_iff_left @[simp] theorem bihimp_le_iff_right : a ⇔ b ≤ b ↔ Codisjoint a b := @le_symmDiff_iff_right αᵒᵈ _ _ _ #align bihimp_le_iff_right bihimp_le_iff_right theorem bihimp_assoc : a ⇔ b ⇔ c = a ⇔ (b ⇔ c) := @symmDiff_assoc αᵒᵈ _ _ _ _ #align bihimp_assoc bihimp_assoc instance bihimp_isAssociative : Std.Associative (α := α) (· ⇔ ·) := ⟨bihimp_assoc⟩ #align bihimp_is_assoc bihimp_isAssociative theorem bihimp_left_comm : a ⇔ (b ⇔ c) = b ⇔ (a ⇔ c) := by simp_rw [← bihimp_assoc, bihimp_comm] #align bihimp_left_comm bihimp_left_comm theorem bihimp_right_comm : a ⇔ b ⇔ c = a ⇔ c ⇔ b := by simp_rw [bihimp_assoc, bihimp_comm] #align bihimp_right_comm bihimp_right_comm theorem bihimp_bihimp_bihimp_comm : a ⇔ b ⇔ (c ⇔ d) = a ⇔ c ⇔ (b ⇔ d) := by simp_rw [bihimp_assoc, bihimp_left_comm] #align bihimp_bihimp_bihimp_comm bihimp_bihimp_bihimp_comm @[simp] theorem bihimp_bihimp_cancel_left : a ⇔ (a ⇔ b) = b := by simp [← bihimp_assoc] #align bihimp_bihimp_cancel_left bihimp_bihimp_cancel_left @[simp] theorem bihimp_bihimp_cancel_right : b ⇔ a ⇔ a = b := by simp [bihimp_assoc] #align bihimp_bihimp_cancel_right bihimp_bihimp_cancel_right @[simp] theorem bihimp_bihimp_self : a ⇔ b ⇔ a = b := by rw [bihimp_comm, bihimp_bihimp_cancel_left] #align bihimp_bihimp_self bihimp_bihimp_self theorem bihimp_left_involutive (a : α) : Involutive (· ⇔ a) := bihimp_bihimp_cancel_right _ #align bihimp_left_involutive bihimp_left_involutive theorem bihimp_right_involutive (a : α) : Involutive (a ⇔ ·) := bihimp_bihimp_cancel_left _ #align bihimp_right_involutive bihimp_right_involutive theorem bihimp_left_injective (a : α) : Injective (· ⇔ a) := @symmDiff_left_injective αᵒᵈ _ _ #align bihimp_left_injective bihimp_left_injective theorem bihimp_right_injective (a : α) : Injective (a ⇔ ·) := @symmDiff_right_injective αᵒᵈ _ _ #align bihimp_right_injective bihimp_right_injective theorem bihimp_left_surjective (a : α) : Surjective (· ⇔ a) := @symmDiff_left_surjective αᵒᵈ _ _ #align bihimp_left_surjective bihimp_left_surjective theorem bihimp_right_surjective (a : α) : Surjective (a ⇔ ·) := @symmDiff_right_surjective αᵒᵈ _ _ #align bihimp_right_surjective bihimp_right_surjective variable {a b c} @[simp] theorem bihimp_left_inj : a ⇔ b = c ⇔ b ↔ a = c := (bihimp_left_injective _).eq_iff #align bihimp_left_inj bihimp_left_inj @[simp] theorem bihimp_right_inj : a ⇔ b = a ⇔ c ↔ b = c := (bihimp_right_injective _).eq_iff #align bihimp_right_inj bihimp_right_inj @[simp] theorem bihimp_eq_left : a ⇔ b = a ↔ b = ⊤ := @symmDiff_eq_left αᵒᵈ _ _ _ #align bihimp_eq_left bihimp_eq_left @[simp] theorem bihimp_eq_right : a ⇔ b = b ↔ a = ⊤ := @symmDiff_eq_right αᵒᵈ _ _ _ #align bihimp_eq_right bihimp_eq_right protected theorem Codisjoint.bihimp_left (ha : Codisjoint a c) (hb : Codisjoint b c) : Codisjoint (a ⇔ b) c := (ha.inf_left hb).mono_left inf_le_bihimp #align codisjoint.bihimp_left Codisjoint.bihimp_left protected theorem Codisjoint.bihimp_right (ha : Codisjoint a b) (hb : Codisjoint a c) : Codisjoint a (b ⇔ c) := (ha.inf_right hb).mono_right inf_le_bihimp #align codisjoint.bihimp_right Codisjoint.bihimp_right end CogeneralizedBooleanAlgebra theorem symmDiff_eq : a ∆ b = a ⊓ bᶜ ⊔ b ⊓ aᶜ := by simp only [(· ∆ ·), sdiff_eq] #align symm_diff_eq symmDiff_eq theorem bihimp_eq : a ⇔ b = (a ⊔ bᶜ) ⊓ (b ⊔ aᶜ) := by simp only [(· ⇔ ·), himp_eq] #align bihimp_eq bihimp_eq theorem symmDiff_eq' : a ∆ b = (a ⊔ b) ⊓ (aᶜ ⊔ bᶜ) := by rw [symmDiff_eq_sup_sdiff_inf, sdiff_eq, compl_inf] #align symm_diff_eq' symmDiff_eq' theorem bihimp_eq' : a ⇔ b = a ⊓ b ⊔ aᶜ ⊓ bᶜ := @symmDiff_eq' αᵒᵈ _ _ _ #align bihimp_eq' bihimp_eq' theorem symmDiff_top : a ∆ ⊤ = aᶜ := symmDiff_top' _ #align symm_diff_top symmDiff_top theorem top_symmDiff : ⊤ ∆ a = aᶜ := top_symmDiff' _ #align top_symm_diff top_symmDiff @[simp] theorem compl_symmDiff : (a ∆ b)ᶜ = a ⇔ b := by simp_rw [symmDiff, compl_sup_distrib, compl_sdiff, bihimp, inf_comm] #align compl_symm_diff compl_symmDiff @[simp] theorem compl_bihimp : (a ⇔ b)ᶜ = a ∆ b := @compl_symmDiff αᵒᵈ _ _ _ #align compl_bihimp compl_bihimp @[simp] theorem compl_symmDiff_compl : aᶜ ∆ bᶜ = a ∆ b := (sup_comm _ _).trans <| by simp_rw [compl_sdiff_compl, sdiff_eq, symmDiff_eq] #align compl_symm_diff_compl compl_symmDiff_compl @[simp] theorem compl_bihimp_compl : aᶜ ⇔ bᶜ = a ⇔ b := @compl_symmDiff_compl αᵒᵈ _ _ _ #align compl_bihimp_compl compl_bihimp_compl @[simp] theorem symmDiff_eq_top : a ∆ b = ⊤ ↔ IsCompl a b := by rw [symmDiff_eq', ← compl_inf, inf_eq_top_iff, compl_eq_top, isCompl_iff, disjoint_iff, codisjoint_iff, and_comm] #align symm_diff_eq_top symmDiff_eq_top @[simp] theorem bihimp_eq_bot : a ⇔ b = ⊥ ↔ IsCompl a b := by rw [bihimp_eq', ← compl_sup, sup_eq_bot_iff, compl_eq_bot, isCompl_iff, disjoint_iff, codisjoint_iff] #align bihimp_eq_bot bihimp_eq_bot @[simp] theorem compl_symmDiff_self : aᶜ ∆ a = ⊤ := hnot_symmDiff_self _ #align compl_symm_diff_self compl_symmDiff_self @[simp] theorem symmDiff_compl_self : a ∆ aᶜ = ⊤ := symmDiff_hnot_self _ #align symm_diff_compl_self symmDiff_compl_self
Mathlib/Order/SymmDiff.lean
780
791
theorem symmDiff_symmDiff_right' : a ∆ (b ∆ c) = a ⊓ b ⊓ c ⊔ a ⊓ bᶜ ⊓ cᶜ ⊔ aᶜ ⊓ b ⊓ cᶜ ⊔ aᶜ ⊓ bᶜ ⊓ c := calc a ∆ (b ∆ c) = a ⊓ (b ⊓ c ⊔ bᶜ ⊓ cᶜ) ⊔ (b ⊓ cᶜ ⊔ c ⊓ bᶜ) ⊓ aᶜ := by
{ rw [symmDiff_eq, compl_symmDiff, bihimp_eq', symmDiff_eq] } _ = a ⊓ b ⊓ c ⊔ a ⊓ bᶜ ⊓ cᶜ ⊔ b ⊓ cᶜ ⊓ aᶜ ⊔ c ⊓ bᶜ ⊓ aᶜ := by { rw [inf_sup_left, inf_sup_right, ← sup_assoc, ← inf_assoc, ← inf_assoc] } _ = a ⊓ b ⊓ c ⊔ a ⊓ bᶜ ⊓ cᶜ ⊔ aᶜ ⊓ b ⊓ cᶜ ⊔ aᶜ ⊓ bᶜ ⊓ c := (by congr 1 · congr 1 rw [inf_comm, inf_assoc] · apply inf_left_right_swap)
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel, Adam Topaz, Johan Commelin, Jakob von Raumer -/ import Mathlib.CategoryTheory.Abelian.Opposite import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Zero import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Kernels import Mathlib.CategoryTheory.Preadditive.LeftExact import Mathlib.CategoryTheory.Adjunction.Limits import Mathlib.Algebra.Homology.Exact import Mathlib.Tactic.TFAE #align_import category_theory.abelian.exact from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a" /-! # Exact sequences in abelian categories In an abelian category, we get several interesting results related to exactness which are not true in more general settings. ## Main results * `(f, g)` is exact if and only if `f ≫ g = 0` and `kernel.ι g ≫ cokernel.π f = 0`. This characterisation tends to be less cumbersome to work with than the original definition involving the comparison map `image f ⟶ kernel g`. * If `(f, g)` is exact, then `image.ι f` has the universal property of the kernel of `g`. * `f` is a monomorphism iff `kernel.ι f = 0` iff `Exact 0 f`, and `f` is an epimorphism iff `cokernel.π = 0` iff `Exact f 0`. * A faithful functor between abelian categories that preserves zero morphisms reflects exact sequences. * `X ⟶ Y ⟶ Z ⟶ 0` is exact if and only if the second map is a cokernel of the first, and `0 ⟶ X ⟶ Y ⟶ Z` is exact if and only if the first map is a kernel of the second. * An exact functor preserves exactness, more specifically, `F` preserves finite colimits and finite limits, if and only if `Exact f g` implies `Exact (F.map f) (F.map g)`. -/ universe v₁ v₂ u₁ u₂ noncomputable section open CategoryTheory Limits Preadditive variable {C : Type u₁} [Category.{v₁} C] [Abelian C] namespace CategoryTheory namespace Abelian variable {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) attribute [local instance] hasEqualizers_of_hasKernels /-- In an abelian category, a pair of morphisms `f : X ⟶ Y`, `g : Y ⟶ Z` is exact iff `imageSubobject f = kernelSubobject g`. -/ theorem exact_iff_image_eq_kernel : Exact f g ↔ imageSubobject f = kernelSubobject g := by constructor · intro h have : IsIso (imageToKernel f g h.w) := have := h.epi; isIso_of_mono_of_epi _ refine Subobject.eq_of_comm (asIso (imageToKernel _ _ h.w)) ?_ simp · apply exact_of_image_eq_kernel #align category_theory.abelian.exact_iff_image_eq_kernel CategoryTheory.Abelian.exact_iff_image_eq_kernel theorem exact_iff : Exact f g ↔ f ≫ g = 0 ∧ kernel.ι g ≫ cokernel.π f = 0 := by constructor · exact fun h ↦ ⟨h.1, kernel_comp_cokernel f g h⟩ · refine fun h ↦ ⟨h.1, ?_⟩ suffices hl : IsLimit (KernelFork.ofι (imageSubobject f).arrow (imageSubobject_arrow_comp_eq_zero h.1)) by have : imageToKernel f g h.1 = (hl.conePointUniqueUpToIso (limit.isLimit _)).hom ≫ (kernelSubobjectIso _).inv := by ext; simp rw [this] infer_instance refine KernelFork.IsLimit.ofι _ _ (fun u hu ↦ ?_) ?_ (fun _ _ _ h ↦ ?_) · refine kernel.lift (cokernel.π f) u ?_ ≫ (imageIsoImage f).hom ≫ (imageSubobjectIso _).inv rw [← kernel.lift_ι g u hu, Category.assoc, h.2, comp_zero] · aesop_cat · rw [← cancel_mono (imageSubobject f).arrow, h] simp #align category_theory.abelian.exact_iff CategoryTheory.Abelian.exact_iff theorem exact_iff' {cg : KernelFork g} (hg : IsLimit cg) {cf : CokernelCofork f} (hf : IsColimit cf) : Exact f g ↔ f ≫ g = 0 ∧ cg.ι ≫ cf.π = 0 := by constructor · intro h exact ⟨h.1, fork_ι_comp_cofork_π f g h cg cf⟩ · rw [exact_iff] refine fun h => ⟨h.1, ?_⟩ apply zero_of_epi_comp (IsLimit.conePointUniqueUpToIso hg (limit.isLimit _)).hom apply zero_of_comp_mono (IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) hf).hom simp [h.2] #align category_theory.abelian.exact_iff' CategoryTheory.Abelian.exact_iff' open List in theorem exact_tfae : TFAE [Exact f g, f ≫ g = 0 ∧ kernel.ι g ≫ cokernel.π f = 0, imageSubobject f = kernelSubobject g] := by tfae_have 1 ↔ 2; · apply exact_iff tfae_have 1 ↔ 3; · apply exact_iff_image_eq_kernel tfae_finish #align category_theory.abelian.exact_tfae CategoryTheory.Abelian.exact_tfae nonrec theorem IsEquivalence.exact_iff {D : Type u₁} [Category.{v₁} D] [Abelian D] (F : C ⥤ D) [F.IsEquivalence] : Exact (F.map f) (F.map g) ↔ Exact f g := by simp only [exact_iff, ← F.map_eq_zero_iff, F.map_comp, Category.assoc, ← kernelComparison_comp_ι g F, ← π_comp_cokernelComparison f F] rw [IsIso.comp_left_eq_zero (kernelComparison g F), ← Category.assoc, IsIso.comp_right_eq_zero _ (cokernelComparison f F)] #align category_theory.abelian.is_equivalence.exact_iff CategoryTheory.Abelian.IsEquivalence.exact_iff /-- The dual result is true even in non-abelian categories, see `CategoryTheory.exact_comp_mono_iff`. -/ theorem exact_epi_comp_iff {W : C} (h : W ⟶ X) [Epi h] : Exact (h ≫ f) g ↔ Exact f g := by refine ⟨fun hfg => ?_, fun h => exact_epi_comp h⟩ let hc := isCokernelOfComp _ _ (colimit.isColimit (parallelPair (h ≫ f) 0)) (by rw [← cancel_epi h, ← Category.assoc, CokernelCofork.condition, comp_zero]) rfl refine (exact_iff' _ _ (limit.isLimit _) hc).2 ⟨?_, ((exact_iff _ _).1 hfg).2⟩ exact zero_of_epi_comp h (by rw [← hfg.1, Category.assoc]) #align category_theory.abelian.exact_epi_comp_iff CategoryTheory.Abelian.exact_epi_comp_iff /-- If `(f, g)` is exact, then `Abelian.image.ι f` is a kernel of `g`. -/ def isLimitImage (h : Exact f g) : IsLimit (KernelFork.ofι (Abelian.image.ι f) (image_ι_comp_eq_zero h.1) : KernelFork g) := by rw [exact_iff] at h exact KernelFork.IsLimit.ofι _ _ (fun u hu ↦ kernel.lift (cokernel.π f) u (by rw [← kernel.lift_ι g u hu, Category.assoc, h.2, comp_zero])) (by aesop_cat) (fun _ _ _ hm => by rw [← cancel_mono (image.ι f), hm, kernel.lift_ι]) #align category_theory.abelian.is_limit_image CategoryTheory.Abelian.isLimitImage /-- If `(f, g)` is exact, then `image.ι f` is a kernel of `g`. -/ def isLimitImage' (h : Exact f g) : IsLimit (KernelFork.ofι (Limits.image.ι f) (Limits.image_ι_comp_eq_zero h.1)) := IsKernel.isoKernel _ _ (isLimitImage f g h) (imageIsoImage f).symm <| IsImage.lift_fac _ _ #align category_theory.abelian.is_limit_image' CategoryTheory.Abelian.isLimitImage' /-- If `(f, g)` is exact, then `Abelian.coimage.π g` is a cokernel of `f`. -/ def isColimitCoimage (h : Exact f g) : IsColimit (CokernelCofork.ofπ (Abelian.coimage.π g) (Abelian.comp_coimage_π_eq_zero h.1) : CokernelCofork f) := by rw [exact_iff] at h refine CokernelCofork.IsColimit.ofπ _ _ (fun u hu => cokernel.desc (kernel.ι g) u (by rw [← cokernel.π_desc f u hu, ← Category.assoc, h.2, zero_comp])) (by aesop_cat) ?_ intros _ _ _ _ hm ext rw [hm, cokernel.π_desc] #align category_theory.abelian.is_colimit_coimage CategoryTheory.Abelian.isColimitCoimage /-- If `(f, g)` is exact, then `factorThruImage g` is a cokernel of `f`. -/ def isColimitImage (h : Exact f g) : IsColimit (CokernelCofork.ofπ (Limits.factorThruImage g) (comp_factorThruImage_eq_zero h.1)) := IsCokernel.cokernelIso _ _ (isColimitCoimage f g h) (coimageIsoImage' g) <| (cancel_mono (Limits.image.ι g)).1 <| by simp #align category_theory.abelian.is_colimit_image CategoryTheory.Abelian.isColimitImage theorem exact_cokernel : Exact f (cokernel.π f) := by rw [exact_iff] aesop_cat #align category_theory.abelian.exact_cokernel CategoryTheory.Abelian.exact_cokernel -- Porting note: this can no longer be an instance in Lean4 lemma mono_cokernel_desc_of_exact (h : Exact f g) : Mono (cokernel.desc f g h.w) := suffices h : cokernel.desc f g h.w = (IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) (isColimitImage f g h)).hom ≫ Limits.image.ι g from h.symm ▸ mono_comp _ _ (cancel_epi (cokernel.π f)).1 <| by simp -- Porting note: this can no longer be an instance in Lean4 /-- If `ex : Exact f g` and `epi g`, then `cokernel.desc _ _ ex.w` is an isomorphism. -/ lemma isIso_cokernel_desc_of_exact_of_epi (ex : Exact f g) [Epi g] : IsIso (cokernel.desc f g ex.w) := have := mono_cokernel_desc_of_exact _ _ ex isIso_of_mono_of_epi (Limits.cokernel.desc f g ex.w) -- Porting note: removed the simp attribute because the lemma may never apply automatically @[reassoc (attr := nolint unusedHavesSuffices)] theorem cokernel.desc.inv [Epi g] (ex : Exact f g) : have := isIso_cokernel_desc_of_exact_of_epi _ _ ex g ≫ inv (cokernel.desc _ _ ex.w) = cokernel.π _ := by have := isIso_cokernel_desc_of_exact_of_epi _ _ ex simp #align category_theory.abelian.cokernel.desc.inv CategoryTheory.Abelian.cokernel.desc.inv -- Porting note: this can no longer be an instance in Lean4 lemma isIso_kernel_lift_of_exact_of_mono (ex : Exact f g) [Mono f] : IsIso (kernel.lift g f ex.w) := have := ex.epi_kernel_lift isIso_of_mono_of_epi (Limits.kernel.lift g f ex.w) -- Porting note: removed the simp attribute because the lemma may never apply automatically @[reassoc (attr := nolint unusedHavesSuffices)] theorem kernel.lift.inv [Mono f] (ex : Exact f g) : have := isIso_kernel_lift_of_exact_of_mono _ _ ex inv (kernel.lift _ _ ex.w) ≫ f = kernel.ι g := by have := isIso_kernel_lift_of_exact_of_mono _ _ ex simp #align category_theory.abelian.kernel.lift.inv CategoryTheory.Abelian.kernel.lift.inv /-- If `X ⟶ Y ⟶ Z ⟶ 0` is exact, then the second map is a cokernel of the first. -/ def isColimitOfExactOfEpi [Epi g] (h : Exact f g) : IsColimit (CokernelCofork.ofπ _ h.w) := IsColimit.ofIsoColimit (colimit.isColimit _) <| Cocones.ext ⟨cokernel.desc _ _ h.w, epiDesc g (cokernel.π f) ((exact_iff _ _).1 h).2, (cancel_epi (cokernel.π f)).1 (by aesop_cat), (cancel_epi g).1 (by aesop_cat)⟩ (by rintro (_|_) <;> simp [h.w]) #align category_theory.abelian.is_colimit_of_exact_of_epi CategoryTheory.Abelian.isColimitOfExactOfEpi /-- If `0 ⟶ X ⟶ Y ⟶ Z` is exact, then the first map is a kernel of the second. -/ def isLimitOfExactOfMono [Mono f] (h : Exact f g) : IsLimit (KernelFork.ofι _ h.w) := IsLimit.ofIsoLimit (limit.isLimit _) <| Cones.ext ⟨monoLift f (kernel.ι g) ((exact_iff _ _).1 h).2, kernel.lift _ _ h.w, (cancel_mono (kernel.ι g)).1 (by aesop_cat), (cancel_mono f).1 (by aesop_cat)⟩ fun j => by cases j <;> simp #align category_theory.abelian.is_limit_of_exact_of_mono CategoryTheory.Abelian.isLimitOfExactOfMono theorem exact_of_is_cokernel (w : f ≫ g = 0) (h : IsColimit (CokernelCofork.ofπ _ w)) : Exact f g := by refine (exact_iff _ _).2 ⟨w, ?_⟩ have := h.fac (CokernelCofork.ofπ _ (cokernel.condition f)) WalkingParallelPair.one simp only [Cofork.ofπ_ι_app] at this rw [← this, ← Category.assoc, kernel.condition, zero_comp] #align category_theory.abelian.exact_of_is_cokernel CategoryTheory.Abelian.exact_of_is_cokernel theorem exact_of_is_kernel (w : f ≫ g = 0) (h : IsLimit (KernelFork.ofι _ w)) : Exact f g := by refine (exact_iff _ _).2 ⟨w, ?_⟩ have := h.fac (KernelFork.ofι _ (kernel.condition g)) WalkingParallelPair.zero simp only [Fork.ofι_π_app] at this rw [← this, Category.assoc, cokernel.condition, comp_zero] #align category_theory.abelian.exact_of_is_kernel CategoryTheory.Abelian.exact_of_is_kernel theorem exact_iff_exact_image_ι : Exact f g ↔ Exact (Abelian.image.ι f) g := by conv_lhs => rw [← Abelian.image.fac f] rw [exact_epi_comp_iff] #align category_theory.abelian.exact_iff_exact_image_ι CategoryTheory.Abelian.exact_iff_exact_image_ι theorem exact_iff_exact_coimage_π : Exact f g ↔ Exact f (coimage.π g) := by conv_lhs => rw [← Abelian.coimage.fac g] rw [exact_comp_mono_iff] #align category_theory.abelian.exact_iff_exact_coimage_π CategoryTheory.Abelian.exact_iff_exact_coimage_π section variable (Z) open List in theorem tfae_mono : TFAE [Mono f, kernel.ι f = 0, Exact (0 : Z ⟶ X) f] := by tfae_have 3 → 2 · exact kernel_ι_eq_zero_of_exact_zero_left Z tfae_have 1 → 3 · intros exact exact_zero_left_of_mono Z tfae_have 2 → 1 · exact mono_of_kernel_ι_eq_zero _ tfae_finish #align category_theory.abelian.tfae_mono CategoryTheory.Abelian.tfae_mono -- Note we've already proved `mono_iff_exact_zero_left : mono f ↔ Exact (0 : Z ⟶ X) f` -- in any preadditive category with kernels and images. theorem mono_iff_kernel_ι_eq_zero : Mono f ↔ kernel.ι f = 0 := (tfae_mono X f).out 0 1 #align category_theory.abelian.mono_iff_kernel_ι_eq_zero CategoryTheory.Abelian.mono_iff_kernel_ι_eq_zero open List in theorem tfae_epi : TFAE [Epi f, cokernel.π f = 0, Exact f (0 : Y ⟶ Z)] := by tfae_have 3 → 2 · rw [exact_iff] rintro ⟨-, h⟩ exact zero_of_epi_comp _ h tfae_have 1 → 3 · rw [exact_iff] intro exact ⟨by simp, by simp [cokernel.π_of_epi]⟩ tfae_have 2 → 1 · exact epi_of_cokernel_π_eq_zero _ tfae_finish #align category_theory.abelian.tfae_epi CategoryTheory.Abelian.tfae_epi -- Note we've already proved `epi_iff_exact_zero_right : epi f ↔ exact f (0 : Y ⟶ Z)` -- in any preadditive category with equalizers and images. theorem epi_iff_cokernel_π_eq_zero : Epi f ↔ cokernel.π f = 0 := (tfae_epi X f).out 0 1 #align category_theory.abelian.epi_iff_cokernel_π_eq_zero CategoryTheory.Abelian.epi_iff_cokernel_π_eq_zero end section Opposite theorem Exact.op (h : Exact f g) : Exact g.op f.op := by rw [exact_iff] refine ⟨by simp [← op_comp, h.w], Quiver.Hom.unop_inj ?_⟩ simp only [unop_comp, cokernel.π_op, eqToHom_refl, kernel.ι_op, Category.id_comp, Category.assoc, kernel_comp_cokernel_assoc _ _ h, zero_comp, comp_zero, unop_zero] #align category_theory.abelian.exact.op CategoryTheory.Abelian.Exact.op theorem Exact.op_iff : Exact g.op f.op ↔ Exact f g := ⟨fun e => by rw [← IsEquivalence.exact_iff _ _ (opOpEquivalence C).inverse] exact Exact.op _ _ e, Exact.op _ _⟩ #align category_theory.abelian.exact.op_iff CategoryTheory.Abelian.Exact.op_iff theorem Exact.unop {X Y Z : Cᵒᵖ} (g : X ⟶ Y) (f : Y ⟶ Z) (h : Exact g f) : Exact f.unop g.unop := by rw [← f.op_unop, ← g.op_unop] at h rwa [← Exact.op_iff] #align category_theory.abelian.exact.unop CategoryTheory.Abelian.Exact.unop theorem Exact.unop_iff {X Y Z : Cᵒᵖ} (g : X ⟶ Y) (f : Y ⟶ Z) : Exact f.unop g.unop ↔ Exact g f := ⟨fun e => by rwa [← f.op_unop, ← g.op_unop, ← Exact.op_iff] at e, fun e => by rw [← Exact.op_iff] exact e⟩ #align category_theory.abelian.exact.unop_iff CategoryTheory.Abelian.Exact.unop_iff end Opposite end Abelian namespace Functor section variable {D : Type u₂} [Category.{v₂} D] [Abelian D] variable (F : C ⥤ D) [PreservesZeroMorphisms F] instance (priority := 100) reflectsExactSequencesOfPreservesZeroMorphismsOfFaithful [Faithful F] : ReflectsExactSequences F where reflects {X Y Z} f g hfg := by rw [Abelian.exact_iff, ← F.map_comp, F.map_eq_zero_iff] at hfg refine (Abelian.exact_iff _ _).2 ⟨hfg.1, F.zero_of_map_zero _ ?_⟩ obtain ⟨k, hk⟩ := kernel.lift' (F.map g) (F.map (kernel.ι g)) (by simp only [← F.map_comp, kernel.condition, CategoryTheory.Functor.map_zero]) obtain ⟨l, hl⟩ := cokernel.desc' (F.map f) (F.map (cokernel.π f)) (by simp only [← F.map_comp, cokernel.condition, CategoryTheory.Functor.map_zero]) rw [F.map_comp, ← hk, ← hl, Category.assoc, reassoc_of% hfg.2, zero_comp, comp_zero] #align category_theory.functor.reflects_exact_sequences_of_preserves_zero_morphisms_of_faithful CategoryTheory.Functor.reflectsExactSequencesOfPreservesZeroMorphismsOfFaithful end end Functor namespace Functor open Limits Abelian variable {A : Type u₁} {B : Type u₂} [Category.{v₁} A] [Category.{v₂} B] variable [Abelian A] [Abelian B] variable (L : A ⥤ B) section variable [PreservesFiniteLimits L] [PreservesFiniteColimits L] /-- A functor preserving finite limits and finite colimits preserves exactness. The converse result is also true, see `Functor.preservesFiniteLimitsOfMapExact` and `Functor.preservesFiniteColimitsOfMapExact`. -/ theorem map_exact {X Y Z : A} (f : X ⟶ Y) (g : Y ⟶ Z) (e1 : Exact f g) : Exact (L.map f) (L.map g) := by let hcoker := isColimitOfHasCokernelOfPreservesColimit L f let hker := isLimitOfHasKernelOfPreservesLimit L g refine (exact_iff' _ _ hker hcoker).2 ⟨by simp [← L.map_comp, e1.1], ?_⟩ simp only [Fork.ι_ofι, Cofork.π_ofπ, ← L.map_comp, kernel_comp_cokernel _ _ e1, L.map_zero] #align category_theory.functor.map_exact CategoryTheory.Functor.map_exact end section variable (h : ∀ ⦃X Y Z : A⦄ {f : X ⟶ Y} {g : Y ⟶ Z}, Exact f g → Exact (L.map f) (L.map g)) open ZeroObject /-- A functor which preserves exactness preserves zero morphisms. -/
Mathlib/CategoryTheory/Abelian/Exact.lean
380
383
theorem preservesZeroMorphisms_of_map_exact : L.PreservesZeroMorphisms := by
replace h := (h (exact_of_zero (𝟙 0) (𝟙 0))).w rw [L.map_id, Category.comp_id] at h exact preservesZeroMorphisms_of_map_zero_object (idZeroEquivIsoZero _ h)
/- 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, Kevin Buzzard, Yury Kudryashov, Frédéric Dupuis, Heather Macbeth -/ import Mathlib.Algebra.Module.Submodule.EqLocus import Mathlib.Algebra.Module.Submodule.RestrictScalars import Mathlib.Algebra.Ring.Idempotents import Mathlib.Data.Set.Pointwise.SMul import Mathlib.LinearAlgebra.Basic import Mathlib.Order.CompactlyGenerated.Basic import Mathlib.Order.OmegaCompletePartialOrder #align_import linear_algebra.span from "leanprover-community/mathlib"@"10878f6bf1dab863445907ab23fbfcefcb5845d0" /-! # The span of a set of vectors, as a submodule * `Submodule.span s` is defined to be the smallest submodule containing the set `s`. ## Notations * We introduce the notation `R ∙ v` for the span of a singleton, `Submodule.span R {v}`. This is `\span`, not the same as the scalar multiplication `•`/`\bub`. -/ variable {R R₂ K M M₂ V S : Type*} namespace Submodule open Function Set open Pointwise section AddCommMonoid variable [Semiring R] [AddCommMonoid M] [Module R M] variable {x : M} (p p' : Submodule R M) variable [Semiring R₂] {σ₁₂ : R →+* R₂} variable [AddCommMonoid M₂] [Module R₂ M₂] variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F σ₁₂ M M₂] section variable (R) /-- The span of a set `s ⊆ M` is the smallest submodule of M that contains `s`. -/ def span (s : Set M) : Submodule R M := sInf { p | s ⊆ p } #align submodule.span Submodule.span variable {R} -- Porting note: renamed field to `principal'` and added `principal` to fix explicit argument /-- An `R`-submodule of `M` is principal if it is generated by one element. -/ @[mk_iff] class IsPrincipal (S : Submodule R M) : Prop where principal' : ∃ a, S = span R {a} #align submodule.is_principal Submodule.IsPrincipal theorem IsPrincipal.principal (S : Submodule R M) [S.IsPrincipal] : ∃ a, S = span R {a} := Submodule.IsPrincipal.principal' #align submodule.is_principal.principal Submodule.IsPrincipal.principal end variable {s t : Set M} theorem mem_span : x ∈ span R s ↔ ∀ p : Submodule R M, s ⊆ p → x ∈ p := mem_iInter₂ #align submodule.mem_span Submodule.mem_span @[aesop safe 20 apply (rule_sets := [SetLike])] theorem subset_span : s ⊆ span R s := fun _ h => mem_span.2 fun _ hp => hp h #align submodule.subset_span Submodule.subset_span theorem span_le {p} : span R s ≤ p ↔ s ⊆ p := ⟨Subset.trans subset_span, fun ss _ h => mem_span.1 h _ ss⟩ #align submodule.span_le Submodule.span_le theorem span_mono (h : s ⊆ t) : span R s ≤ span R t := span_le.2 <| Subset.trans h subset_span #align submodule.span_mono Submodule.span_mono theorem span_monotone : Monotone (span R : Set M → Submodule R M) := fun _ _ => span_mono #align submodule.span_monotone Submodule.span_monotone theorem span_eq_of_le (h₁ : s ⊆ p) (h₂ : p ≤ span R s) : span R s = p := le_antisymm (span_le.2 h₁) h₂ #align submodule.span_eq_of_le Submodule.span_eq_of_le theorem span_eq : span R (p : Set M) = p := span_eq_of_le _ (Subset.refl _) subset_span #align submodule.span_eq Submodule.span_eq theorem span_eq_span (hs : s ⊆ span R t) (ht : t ⊆ span R s) : span R s = span R t := le_antisymm (span_le.2 hs) (span_le.2 ht) #align submodule.span_eq_span Submodule.span_eq_span /-- A version of `Submodule.span_eq` for subobjects closed under addition and scalar multiplication and containing zero. In general, this should not be used directly, but can be used to quickly generate proofs for specific types of subobjects. -/ lemma coe_span_eq_self [SetLike S M] [AddSubmonoidClass S M] [SMulMemClass S R M] (s : S) : (span R (s : Set M) : Set M) = s := by refine le_antisymm ?_ subset_span let s' : Submodule R M := { carrier := s add_mem' := add_mem zero_mem' := zero_mem _ smul_mem' := SMulMemClass.smul_mem } exact span_le (p := s') |>.mpr le_rfl /-- A version of `Submodule.span_eq` for when the span is by a smaller ring. -/ @[simp] theorem span_coe_eq_restrictScalars [Semiring S] [SMul S R] [Module S M] [IsScalarTower S R M] : span S (p : Set M) = p.restrictScalars S := span_eq (p.restrictScalars S) #align submodule.span_coe_eq_restrict_scalars Submodule.span_coe_eq_restrictScalars /-- A version of `Submodule.map_span_le` that does not require the `RingHomSurjective` assumption. -/ theorem image_span_subset (f : F) (s : Set M) (N : Submodule R₂ M₂) : f '' span R s ⊆ N ↔ ∀ m ∈ s, f m ∈ N := image_subset_iff.trans <| span_le (p := N.comap f) theorem image_span_subset_span (f : F) (s : Set M) : f '' span R s ⊆ span R₂ (f '' s) := (image_span_subset f s _).2 fun x hx ↦ subset_span ⟨x, hx, rfl⟩ theorem map_span [RingHomSurjective σ₁₂] (f : F) (s : Set M) : (span R s).map f = span R₂ (f '' s) := Eq.symm <| span_eq_of_le _ (Set.image_subset f subset_span) (image_span_subset_span f s) #align submodule.map_span Submodule.map_span alias _root_.LinearMap.map_span := Submodule.map_span #align linear_map.map_span LinearMap.map_span theorem map_span_le [RingHomSurjective σ₁₂] (f : F) (s : Set M) (N : Submodule R₂ M₂) : map f (span R s) ≤ N ↔ ∀ m ∈ s, f m ∈ N := image_span_subset f s N #align submodule.map_span_le Submodule.map_span_le alias _root_.LinearMap.map_span_le := Submodule.map_span_le #align linear_map.map_span_le LinearMap.map_span_le @[simp] theorem span_insert_zero : span R (insert (0 : M) s) = span R s := by refine le_antisymm ?_ (Submodule.span_mono (Set.subset_insert 0 s)) rw [span_le, Set.insert_subset_iff] exact ⟨by simp only [SetLike.mem_coe, Submodule.zero_mem], Submodule.subset_span⟩ #align submodule.span_insert_zero Submodule.span_insert_zero -- See also `span_preimage_eq` below. theorem span_preimage_le (f : F) (s : Set M₂) : span R (f ⁻¹' s) ≤ (span R₂ s).comap f := by rw [span_le, comap_coe] exact preimage_mono subset_span #align submodule.span_preimage_le Submodule.span_preimage_le alias _root_.LinearMap.span_preimage_le := Submodule.span_preimage_le #align linear_map.span_preimage_le LinearMap.span_preimage_le theorem closure_subset_span {s : Set M} : (AddSubmonoid.closure s : Set M) ⊆ span R s := (@AddSubmonoid.closure_le _ _ _ (span R s).toAddSubmonoid).mpr subset_span #align submodule.closure_subset_span Submodule.closure_subset_span theorem closure_le_toAddSubmonoid_span {s : Set M} : AddSubmonoid.closure s ≤ (span R s).toAddSubmonoid := closure_subset_span #align submodule.closure_le_to_add_submonoid_span Submodule.closure_le_toAddSubmonoid_span @[simp] theorem span_closure {s : Set M} : span R (AddSubmonoid.closure s : Set M) = span R s := le_antisymm (span_le.mpr closure_subset_span) (span_mono AddSubmonoid.subset_closure) #align submodule.span_closure Submodule.span_closure /-- An induction principle for span membership. If `p` holds for 0 and all elements of `s`, and is preserved under addition and scalar multiplication, then `p` holds for all elements of the span of `s`. -/ @[elab_as_elim] theorem span_induction {p : M → Prop} (h : x ∈ span R s) (mem : ∀ x ∈ s, p x) (zero : p 0) (add : ∀ x y, p x → p y → p (x + y)) (smul : ∀ (a : R) (x), p x → p (a • x)) : p x := ((@span_le (p := ⟨⟨⟨p, by intros x y; exact add x y⟩, zero⟩, smul⟩)) s).2 mem h #align submodule.span_induction Submodule.span_induction /-- An induction principle for span membership. This is a version of `Submodule.span_induction` for binary predicates. -/ theorem span_induction₂ {p : M → M → Prop} {a b : M} (ha : a ∈ Submodule.span R s) (hb : b ∈ Submodule.span R s) (mem_mem : ∀ x ∈ s, ∀ y ∈ s, p x y) (zero_left : ∀ y, p 0 y) (zero_right : ∀ x, p x 0) (add_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ + x₂) y) (add_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ + y₂)) (smul_left : ∀ (r : R) x y, p x y → p (r • x) y) (smul_right : ∀ (r : R) x y, p x y → p x (r • y)) : p a b := Submodule.span_induction ha (fun x hx => Submodule.span_induction hb (mem_mem x hx) (zero_right x) (add_right x) fun r => smul_right r x) (zero_left b) (fun x₁ x₂ => add_left x₁ x₂ b) fun r x => smul_left r x b /-- A dependent version of `Submodule.span_induction`. -/ @[elab_as_elim] theorem span_induction' {p : ∀ x, x ∈ span R s → Prop} (mem : ∀ (x) (h : x ∈ s), p x (subset_span h)) (zero : p 0 (Submodule.zero_mem _)) (add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (Submodule.add_mem _ ‹_› ‹_›)) (smul : ∀ (a : R) (x hx), p x hx → p (a • x) (Submodule.smul_mem _ _ ‹_›)) {x} (hx : x ∈ span R s) : p x hx := by refine Exists.elim ?_ fun (hx : x ∈ span R s) (hc : p x hx) => hc refine span_induction hx (fun m hm => ⟨subset_span hm, mem m hm⟩) ⟨zero_mem _, zero⟩ (fun x y hx hy => Exists.elim hx fun hx' hx => Exists.elim hy fun hy' hy => ⟨add_mem hx' hy', add _ _ _ _ hx hy⟩) fun r x hx => Exists.elim hx fun hx' hx => ⟨smul_mem _ _ hx', smul r _ _ hx⟩ #align submodule.span_induction' Submodule.span_induction' open AddSubmonoid in theorem span_eq_closure {s : Set M} : (span R s).toAddSubmonoid = closure (@univ R • s) := by refine le_antisymm (fun x hx ↦ span_induction hx (fun x hx ↦ subset_closure ⟨1, trivial, x, hx, one_smul R x⟩) (zero_mem _) (fun _ _ ↦ add_mem) fun r m hm ↦ closure_induction hm ?_ ?_ fun _ _ h h' ↦ ?_) (closure_le.2 ?_) · rintro _ ⟨r, -, m, hm, rfl⟩; exact smul_mem _ _ (subset_span hm) · rintro _ ⟨r', -, m, hm, rfl⟩; exact subset_closure ⟨r * r', trivial, m, hm, mul_smul r r' m⟩ · rw [smul_zero]; apply zero_mem · rw [smul_add]; exact add_mem h h' /-- A variant of `span_induction` that combines `∀ x ∈ s, p x` and `∀ r x, p x → p (r • x)` into a single condition `∀ r, ∀ x ∈ s, p (r • x)`, which can be easier to verify. -/ @[elab_as_elim] theorem closure_induction {p : M → Prop} (h : x ∈ span R s) (zero : p 0) (add : ∀ x y, p x → p y → p (x + y)) (smul_mem : ∀ r : R, ∀ x ∈ s, p (r • x)) : p x := by rw [← mem_toAddSubmonoid, span_eq_closure] at h refine AddSubmonoid.closure_induction h ?_ zero add rintro _ ⟨r, -, m, hm, rfl⟩ exact smul_mem r m hm /-- A dependent version of `Submodule.closure_induction`. -/ @[elab_as_elim] theorem closure_induction' {p : ∀ x, x ∈ span R s → Prop} (zero : p 0 (Submodule.zero_mem _)) (add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (Submodule.add_mem _ ‹_› ‹_›)) (smul_mem : ∀ (r x) (h : x ∈ s), p (r • x) (Submodule.smul_mem _ _ <| subset_span h)) {x} (hx : x ∈ span R s) : p x hx := by refine Exists.elim ?_ fun (hx : x ∈ span R s) (hc : p x hx) ↦ hc refine closure_induction hx ⟨zero_mem _, zero⟩ (fun x y hx hy ↦ Exists.elim hx fun hx' hx ↦ Exists.elim hy fun hy' hy ↦ ⟨add_mem hx' hy', add _ _ _ _ hx hy⟩) fun r x hx ↦ ⟨Submodule.smul_mem _ _ (subset_span hx), smul_mem r x hx⟩ @[simp] theorem span_span_coe_preimage : span R (((↑) : span R s → M) ⁻¹' s) = ⊤ := eq_top_iff.2 fun x ↦ Subtype.recOn x fun x hx _ ↦ by refine span_induction' (p := fun x hx ↦ (⟨x, hx⟩ : span R s) ∈ span R (Subtype.val ⁻¹' s)) (fun x' hx' ↦ subset_span hx') ?_ (fun x _ y _ ↦ ?_) (fun r x _ ↦ ?_) hx · exact zero_mem _ · exact add_mem · exact smul_mem _ _ #align submodule.span_span_coe_preimage Submodule.span_span_coe_preimage @[simp] lemma span_setOf_mem_eq_top : span R {x : span R s | (x : M) ∈ s} = ⊤ := span_span_coe_preimage theorem span_nat_eq_addSubmonoid_closure (s : Set M) : (span ℕ s).toAddSubmonoid = AddSubmonoid.closure s := by refine Eq.symm (AddSubmonoid.closure_eq_of_le subset_span ?_) apply (OrderIso.to_galoisConnection (AddSubmonoid.toNatSubmodule (M := M)).symm).l_le (a := span ℕ s) (b := AddSubmonoid.closure s) rw [span_le] exact AddSubmonoid.subset_closure #align submodule.span_nat_eq_add_submonoid_closure Submodule.span_nat_eq_addSubmonoid_closure @[simp] theorem span_nat_eq (s : AddSubmonoid M) : (span ℕ (s : Set M)).toAddSubmonoid = s := by rw [span_nat_eq_addSubmonoid_closure, s.closure_eq] #align submodule.span_nat_eq Submodule.span_nat_eq theorem span_int_eq_addSubgroup_closure {M : Type*} [AddCommGroup M] (s : Set M) : (span ℤ s).toAddSubgroup = AddSubgroup.closure s := Eq.symm <| AddSubgroup.closure_eq_of_le _ subset_span fun x hx => span_induction hx (fun x hx => AddSubgroup.subset_closure hx) (AddSubgroup.zero_mem _) (fun _ _ => AddSubgroup.add_mem _) fun _ _ _ => AddSubgroup.zsmul_mem _ ‹_› _ #align submodule.span_int_eq_add_subgroup_closure Submodule.span_int_eq_addSubgroup_closure @[simp] theorem span_int_eq {M : Type*} [AddCommGroup M] (s : AddSubgroup M) : (span ℤ (s : Set M)).toAddSubgroup = s := by rw [span_int_eq_addSubgroup_closure, s.closure_eq] #align submodule.span_int_eq Submodule.span_int_eq section variable (R M) /-- `span` forms a Galois insertion with the coercion from submodule to set. -/ protected def gi : GaloisInsertion (@span R M _ _ _) (↑) where choice s _ := span R s gc _ _ := span_le le_l_u _ := subset_span choice_eq _ _ := rfl #align submodule.gi Submodule.gi end @[simp] theorem span_empty : span R (∅ : Set M) = ⊥ := (Submodule.gi R M).gc.l_bot #align submodule.span_empty Submodule.span_empty @[simp] theorem span_univ : span R (univ : Set M) = ⊤ := eq_top_iff.2 <| SetLike.le_def.2 <| subset_span #align submodule.span_univ Submodule.span_univ theorem span_union (s t : Set M) : span R (s ∪ t) = span R s ⊔ span R t := (Submodule.gi R M).gc.l_sup #align submodule.span_union Submodule.span_union theorem span_iUnion {ι} (s : ι → Set M) : span R (⋃ i, s i) = ⨆ i, span R (s i) := (Submodule.gi R M).gc.l_iSup #align submodule.span_Union Submodule.span_iUnion /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem span_iUnion₂ {ι} {κ : ι → Sort*} (s : ∀ i, κ i → Set M) : span R (⋃ (i) (j), s i j) = ⨆ (i) (j), span R (s i j) := (Submodule.gi R M).gc.l_iSup₂ #align submodule.span_Union₂ Submodule.span_iUnion₂ theorem span_attach_biUnion [DecidableEq M] {α : Type*} (s : Finset α) (f : s → Finset M) : span R (s.attach.biUnion f : Set M) = ⨆ x, span R (f x) := by simp [span_iUnion] #align submodule.span_attach_bUnion Submodule.span_attach_biUnion theorem sup_span : p ⊔ span R s = span R (p ∪ s) := by rw [Submodule.span_union, p.span_eq] #align submodule.sup_span Submodule.sup_span theorem span_sup : span R s ⊔ p = span R (s ∪ p) := by rw [Submodule.span_union, p.span_eq] #align submodule.span_sup Submodule.span_sup notation:1000 /- Note that the character `∙` U+2219 used below is different from the scalar multiplication character `•` U+2022. -/ R " ∙ " x => span R (singleton x) theorem span_eq_iSup_of_singleton_spans (s : Set M) : span R s = ⨆ x ∈ s, R ∙ x := by simp only [← span_iUnion, Set.biUnion_of_singleton s] #align submodule.span_eq_supr_of_singleton_spans Submodule.span_eq_iSup_of_singleton_spans theorem span_range_eq_iSup {ι : Sort*} {v : ι → M} : span R (range v) = ⨆ i, R ∙ v i := by rw [span_eq_iSup_of_singleton_spans, iSup_range] #align submodule.span_range_eq_supr Submodule.span_range_eq_iSup
Mathlib/LinearAlgebra/Span.lean
355
358
theorem span_smul_le (s : Set M) (r : R) : span R (r • s) ≤ span R s := by
rw [span_le] rintro _ ⟨x, hx, rfl⟩ exact smul_mem (span R s) r (subset_span hx)
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Group.Nat import Mathlib.Algebra.Order.Sub.Canonical import Mathlib.Data.List.Perm import Mathlib.Data.Set.List import Mathlib.Init.Quot import Mathlib.Order.Hom.Basic #align_import data.multiset.basic from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Multisets These are implemented as the quotient of a list by permutations. ## Notation We define the global infix notation `::ₘ` for `Multiset.cons`. -/ universe v open List Subtype Nat Function variable {α : Type*} {β : Type v} {γ : Type*} /-- `Multiset α` is the quotient of `List α` by list permutation. The result is a type of finite sets with duplicates allowed. -/ def Multiset.{u} (α : Type u) : Type u := Quotient (List.isSetoid α) #align multiset Multiset namespace Multiset -- Porting note: new /-- The quotient map from `List α` to `Multiset α`. -/ @[coe] def ofList : List α → Multiset α := Quot.mk _ instance : Coe (List α) (Multiset α) := ⟨ofList⟩ @[simp] theorem quot_mk_to_coe (l : List α) : @Eq (Multiset α) ⟦l⟧ l := rfl #align multiset.quot_mk_to_coe Multiset.quot_mk_to_coe @[simp] theorem quot_mk_to_coe' (l : List α) : @Eq (Multiset α) (Quot.mk (· ≈ ·) l) l := rfl #align multiset.quot_mk_to_coe' Multiset.quot_mk_to_coe' @[simp] theorem quot_mk_to_coe'' (l : List α) : @Eq (Multiset α) (Quot.mk Setoid.r l) l := rfl #align multiset.quot_mk_to_coe'' Multiset.quot_mk_to_coe'' @[simp] theorem coe_eq_coe {l₁ l₂ : List α} : (l₁ : Multiset α) = l₂ ↔ l₁ ~ l₂ := Quotient.eq #align multiset.coe_eq_coe Multiset.coe_eq_coe -- Porting note: new instance; -- Porting note (#11215): TODO: move to better place instance [DecidableEq α] (l₁ l₂ : List α) : Decidable (l₁ ≈ l₂) := inferInstanceAs (Decidable (l₁ ~ l₂)) -- Porting note: `Quotient.recOnSubsingleton₂ s₁ s₂` was in parens which broke elaboration instance decidableEq [DecidableEq α] : DecidableEq (Multiset α) | s₁, s₂ => Quotient.recOnSubsingleton₂ s₁ s₂ fun _ _ => decidable_of_iff' _ Quotient.eq #align multiset.has_decidable_eq Multiset.decidableEq /-- defines a size for a multiset by referring to the size of the underlying list -/ protected def sizeOf [SizeOf α] (s : Multiset α) : ℕ := (Quot.liftOn s SizeOf.sizeOf) fun _ _ => Perm.sizeOf_eq_sizeOf #align multiset.sizeof Multiset.sizeOf instance [SizeOf α] : SizeOf (Multiset α) := ⟨Multiset.sizeOf⟩ /-! ### Empty multiset -/ /-- `0 : Multiset α` is the empty set -/ protected def zero : Multiset α := @nil α #align multiset.zero Multiset.zero instance : Zero (Multiset α) := ⟨Multiset.zero⟩ instance : EmptyCollection (Multiset α) := ⟨0⟩ instance inhabitedMultiset : Inhabited (Multiset α) := ⟨0⟩ #align multiset.inhabited_multiset Multiset.inhabitedMultiset instance [IsEmpty α] : Unique (Multiset α) where default := 0 uniq := by rintro ⟨_ | ⟨a, l⟩⟩; exacts [rfl, isEmptyElim a] @[simp] theorem coe_nil : (@nil α : Multiset α) = 0 := rfl #align multiset.coe_nil Multiset.coe_nil @[simp] theorem empty_eq_zero : (∅ : Multiset α) = 0 := rfl #align multiset.empty_eq_zero Multiset.empty_eq_zero @[simp] theorem coe_eq_zero (l : List α) : (l : Multiset α) = 0 ↔ l = [] := Iff.trans coe_eq_coe perm_nil #align multiset.coe_eq_zero Multiset.coe_eq_zero theorem coe_eq_zero_iff_isEmpty (l : List α) : (l : Multiset α) = 0 ↔ l.isEmpty := Iff.trans (coe_eq_zero l) isEmpty_iff_eq_nil.symm #align multiset.coe_eq_zero_iff_empty Multiset.coe_eq_zero_iff_isEmpty /-! ### `Multiset.cons` -/ /-- `cons a s` is the multiset which contains `s` plus one more instance of `a`. -/ def cons (a : α) (s : Multiset α) : Multiset α := Quot.liftOn s (fun l => (a :: l : Multiset α)) fun _ _ p => Quot.sound (p.cons a) #align multiset.cons Multiset.cons @[inherit_doc Multiset.cons] infixr:67 " ::ₘ " => Multiset.cons instance : Insert α (Multiset α) := ⟨cons⟩ @[simp] theorem insert_eq_cons (a : α) (s : Multiset α) : insert a s = a ::ₘ s := rfl #align multiset.insert_eq_cons Multiset.insert_eq_cons @[simp] theorem cons_coe (a : α) (l : List α) : (a ::ₘ l : Multiset α) = (a :: l : List α) := rfl #align multiset.cons_coe Multiset.cons_coe @[simp] theorem cons_inj_left {a b : α} (s : Multiset α) : a ::ₘ s = b ::ₘ s ↔ a = b := ⟨Quot.inductionOn s fun l e => have : [a] ++ l ~ [b] ++ l := Quotient.exact e singleton_perm_singleton.1 <| (perm_append_right_iff _).1 this, congr_arg (· ::ₘ _)⟩ #align multiset.cons_inj_left Multiset.cons_inj_left @[simp]
Mathlib/Data/Multiset/Basic.lean
157
158
theorem cons_inj_right (a : α) : ∀ {s t : Multiset α}, a ::ₘ s = a ::ₘ t ↔ s = t := by
rintro ⟨l₁⟩ ⟨l₂⟩; simp
/- Copyright (c) 2021 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Algebra.Group.Subgroup.Actions import Mathlib.Algebra.Order.Module.Algebra import Mathlib.LinearAlgebra.LinearIndependent import Mathlib.Algebra.Ring.Subring.Units #align_import linear_algebra.ray from "leanprover-community/mathlib"@"0f6670b8af2dff699de1c0b4b49039b31bc13c46" /-! # Rays in modules This file defines rays in modules. ## Main definitions * `SameRay`: two vectors belong to the same ray if they are proportional with a nonnegative coefficient. * `Module.Ray` is a type for the equivalence class of nonzero vectors in a module with some common positive multiple. -/ noncomputable section section StrictOrderedCommSemiring variable (R : Type*) [StrictOrderedCommSemiring R] variable {M : Type*} [AddCommMonoid M] [Module R M] variable {N : Type*} [AddCommMonoid N] [Module R N] variable (ι : Type*) [DecidableEq ι] /-- Two vectors are in the same ray if either one of them is zero or some positive multiples of them are equal (in the typical case over a field, this means one of them is a nonnegative multiple of the other). -/ def SameRay (v₁ v₂ : M) : Prop := v₁ = 0 ∨ v₂ = 0 ∨ ∃ r₁ r₂ : R, 0 < r₁ ∧ 0 < r₂ ∧ r₁ • v₁ = r₂ • v₂ #align same_ray SameRay variable {R} namespace SameRay variable {x y z : M} @[simp] theorem zero_left (y : M) : SameRay R 0 y := Or.inl rfl #align same_ray.zero_left SameRay.zero_left @[simp] theorem zero_right (x : M) : SameRay R x 0 := Or.inr <| Or.inl rfl #align same_ray.zero_right SameRay.zero_right @[nontriviality] theorem of_subsingleton [Subsingleton M] (x y : M) : SameRay R x y := by rw [Subsingleton.elim x 0] exact zero_left _ #align same_ray.of_subsingleton SameRay.of_subsingleton @[nontriviality] theorem of_subsingleton' [Subsingleton R] (x y : M) : SameRay R x y := haveI := Module.subsingleton R M of_subsingleton x y #align same_ray.of_subsingleton' SameRay.of_subsingleton' /-- `SameRay` is reflexive. -/ @[refl] theorem refl (x : M) : SameRay R x x := by nontriviality R exact Or.inr (Or.inr <| ⟨1, 1, zero_lt_one, zero_lt_one, rfl⟩) #align same_ray.refl SameRay.refl protected theorem rfl : SameRay R x x := refl _ #align same_ray.rfl SameRay.rfl /-- `SameRay` is symmetric. -/ @[symm] theorem symm (h : SameRay R x y) : SameRay R y x := (or_left_comm.1 h).imp_right <| Or.imp_right fun ⟨r₁, r₂, h₁, h₂, h⟩ => ⟨r₂, r₁, h₂, h₁, h.symm⟩ #align same_ray.symm SameRay.symm /-- If `x` and `y` are nonzero vectors on the same ray, then there exist positive numbers `r₁ r₂` such that `r₁ • x = r₂ • y`. -/ theorem exists_pos (h : SameRay R x y) (hx : x ≠ 0) (hy : y ≠ 0) : ∃ r₁ r₂ : R, 0 < r₁ ∧ 0 < r₂ ∧ r₁ • x = r₂ • y := (h.resolve_left hx).resolve_left hy #align same_ray.exists_pos SameRay.exists_pos theorem sameRay_comm : SameRay R x y ↔ SameRay R y x := ⟨SameRay.symm, SameRay.symm⟩ #align same_ray_comm SameRay.sameRay_comm /-- `SameRay` is transitive unless the vector in the middle is zero and both other vectors are nonzero. -/ theorem trans (hxy : SameRay R x y) (hyz : SameRay R y z) (hy : y = 0 → x = 0 ∨ z = 0) : SameRay R x z := by rcases eq_or_ne x 0 with (rfl | hx); · exact zero_left z rcases eq_or_ne z 0 with (rfl | hz); · exact zero_right x rcases eq_or_ne y 0 with (rfl | hy); · exact (hy rfl).elim (fun h => (hx h).elim) fun h => (hz h).elim rcases hxy.exists_pos hx hy with ⟨r₁, r₂, hr₁, hr₂, h₁⟩ rcases hyz.exists_pos hy hz with ⟨r₃, r₄, hr₃, hr₄, h₂⟩ refine Or.inr (Or.inr <| ⟨r₃ * r₁, r₂ * r₄, mul_pos hr₃ hr₁, mul_pos hr₂ hr₄, ?_⟩) rw [mul_smul, mul_smul, h₁, ← h₂, smul_comm] #align same_ray.trans SameRay.trans variable {S : Type*} [OrderedCommSemiring S] [Algebra S R] [Module S M] [SMulPosMono S R] [IsScalarTower S R M] {a : S} /-- A vector is in the same ray as a nonnegative multiple of itself. -/ lemma sameRay_nonneg_smul_right (v : M) (h : 0 ≤ a) : SameRay R v (a • v) := by obtain h | h := (algebraMap_nonneg R h).eq_or_gt · rw [← algebraMap_smul R a v, h, zero_smul] exact zero_right _ · refine Or.inr $ Or.inr ⟨algebraMap S R a, 1, h, by nontriviality R; exact zero_lt_one, ?_⟩ rw [algebraMap_smul, one_smul] #align same_ray_nonneg_smul_right SameRay.sameRay_nonneg_smul_right /-- A nonnegative multiple of a vector is in the same ray as that vector. -/ lemma sameRay_nonneg_smul_left (v : M) (ha : 0 ≤ a) : SameRay R (a • v) v := (sameRay_nonneg_smul_right v ha).symm #align same_ray_nonneg_smul_left SameRay.sameRay_nonneg_smul_left /-- A vector is in the same ray as a positive multiple of itself. -/ lemma sameRay_pos_smul_right (v : M) (ha : 0 < a) : SameRay R v (a • v) := sameRay_nonneg_smul_right v ha.le #align same_ray_pos_smul_right SameRay.sameRay_pos_smul_right /-- A positive multiple of a vector is in the same ray as that vector. -/ lemma sameRay_pos_smul_left (v : M) (ha : 0 < a) : SameRay R (a • v) v := sameRay_nonneg_smul_left v ha.le #align same_ray_pos_smul_left SameRay.sameRay_pos_smul_left /-- A vector is in the same ray as a nonnegative multiple of one it is in the same ray as. -/ lemma nonneg_smul_right (h : SameRay R x y) (ha : 0 ≤ a) : SameRay R x (a • y) := h.trans (sameRay_nonneg_smul_right y ha) fun hy => Or.inr <| by rw [hy, smul_zero] #align same_ray.nonneg_smul_right SameRay.nonneg_smul_right /-- A nonnegative multiple of a vector is in the same ray as one it is in the same ray as. -/ lemma nonneg_smul_left (h : SameRay R x y) (ha : 0 ≤ a) : SameRay R (a • x) y := (h.symm.nonneg_smul_right ha).symm #align same_ray.nonneg_smul_left SameRay.nonneg_smul_left /-- A vector is in the same ray as a positive multiple of one it is in the same ray as. -/ theorem pos_smul_right (h : SameRay R x y) (ha : 0 < a) : SameRay R x (a • y) := h.nonneg_smul_right ha.le #align same_ray.pos_smul_right SameRay.pos_smul_right /-- A positive multiple of a vector is in the same ray as one it is in the same ray as. -/ theorem pos_smul_left (h : SameRay R x y) (hr : 0 < a) : SameRay R (a • x) y := h.nonneg_smul_left hr.le #align same_ray.pos_smul_left SameRay.pos_smul_left /-- If two vectors are on the same ray then they remain so after applying a linear map. -/ theorem map (f : M →ₗ[R] N) (h : SameRay R x y) : SameRay R (f x) (f y) := (h.imp fun hx => by rw [hx, map_zero]) <| Or.imp (fun hy => by rw [hy, map_zero]) fun ⟨r₁, r₂, hr₁, hr₂, h⟩ => ⟨r₁, r₂, hr₁, hr₂, by rw [← f.map_smul, ← f.map_smul, h]⟩ #align same_ray.map SameRay.map /-- The images of two vectors under an injective linear map are on the same ray if and only if the original vectors are on the same ray. -/ theorem _root_.Function.Injective.sameRay_map_iff {F : Type*} [FunLike F M N] [LinearMapClass F R M N] {f : F} (hf : Function.Injective f) : SameRay R (f x) (f y) ↔ SameRay R x y := by simp only [SameRay, map_zero, ← hf.eq_iff, map_smul] #align function.injective.same_ray_map_iff Function.Injective.sameRay_map_iff /-- The images of two vectors under a linear equivalence are on the same ray if and only if the original vectors are on the same ray. -/ @[simp] theorem sameRay_map_iff (e : M ≃ₗ[R] N) : SameRay R (e x) (e y) ↔ SameRay R x y := Function.Injective.sameRay_map_iff (EquivLike.injective e) #align same_ray_map_iff SameRay.sameRay_map_iff /-- If two vectors are on the same ray then both scaled by the same action are also on the same ray. -/ theorem smul {S : Type*} [Monoid S] [DistribMulAction S M] [SMulCommClass R S M] (h : SameRay R x y) (s : S) : SameRay R (s • x) (s • y) := h.map (s • (LinearMap.id : M →ₗ[R] M)) #align same_ray.smul SameRay.smul /-- If `x` and `y` are on the same ray as `z`, then so is `x + y`. -/ theorem add_left (hx : SameRay R x z) (hy : SameRay R y z) : SameRay R (x + y) z := by rcases eq_or_ne x 0 with (rfl | hx₀); · rwa [zero_add] rcases eq_or_ne y 0 with (rfl | hy₀); · rwa [add_zero] rcases eq_or_ne z 0 with (rfl | hz₀); · apply zero_right rcases hx.exists_pos hx₀ hz₀ with ⟨rx, rz₁, hrx, hrz₁, Hx⟩ rcases hy.exists_pos hy₀ hz₀ with ⟨ry, rz₂, hry, hrz₂, Hy⟩ refine Or.inr (Or.inr ⟨rx * ry, ry * rz₁ + rx * rz₂, mul_pos hrx hry, ?_, ?_⟩) · apply_rules [add_pos, mul_pos] · simp only [mul_smul, smul_add, add_smul, ← Hx, ← Hy] rw [smul_comm] #align same_ray.add_left SameRay.add_left /-- If `y` and `z` are on the same ray as `x`, then so is `y + z`. -/ theorem add_right (hy : SameRay R x y) (hz : SameRay R x z) : SameRay R x (y + z) := (hy.symm.add_left hz.symm).symm #align same_ray.add_right SameRay.add_right end SameRay -- Porting note(#5171): removed has_nonempty_instance nolint, no such linter set_option linter.unusedVariables false in /-- Nonzero vectors, as used to define rays. This type depends on an unused argument `R` so that `RayVector.Setoid` can be an instance. -/ @[nolint unusedArguments] def RayVector (R M : Type*) [Zero M] := { v : M // v ≠ 0 } #align ray_vector RayVector -- Porting note: Made Coe into CoeOut so it's not dangerous anymore instance RayVector.coe [Zero M] : CoeOut (RayVector R M) M where coe := Subtype.val #align ray_vector.has_coe RayVector.coe instance {R M : Type*} [Zero M] [Nontrivial M] : Nonempty (RayVector R M) := let ⟨x, hx⟩ := exists_ne (0 : M) ⟨⟨x, hx⟩⟩ variable (R M) /-- The setoid of the `SameRay` relation for the subtype of nonzero vectors. -/ instance RayVector.Setoid : Setoid (RayVector R M) where r x y := SameRay R (x : M) y iseqv := ⟨fun x => SameRay.refl _, fun h => h.symm, by intros x y z hxy hyz exact hxy.trans hyz fun hy => (y.2 hy).elim⟩ /-- A ray (equivalence class of nonzero vectors with common positive multiples) in a module. -/ -- Porting note(#5171): removed has_nonempty_instance nolint, no such linter def Module.Ray := Quotient (RayVector.Setoid R M) #align module.ray Module.Ray variable {R M} /-- Equivalence of nonzero vectors, in terms of `SameRay`. -/ theorem equiv_iff_sameRay {v₁ v₂ : RayVector R M} : v₁ ≈ v₂ ↔ SameRay R (v₁ : M) v₂ := Iff.rfl #align equiv_iff_same_ray equiv_iff_sameRay variable (R) -- Porting note: Removed `protected` here, not in namespace /-- The ray given by a nonzero vector. -/ def rayOfNeZero (v : M) (h : v ≠ 0) : Module.Ray R M := ⟦⟨v, h⟩⟧ #align ray_of_ne_zero rayOfNeZero /-- An induction principle for `Module.Ray`, used as `induction x using Module.Ray.ind`. -/ theorem Module.Ray.ind {C : Module.Ray R M → Prop} (h : ∀ (v) (hv : v ≠ 0), C (rayOfNeZero R v hv)) (x : Module.Ray R M) : C x := Quotient.ind (Subtype.rec <| h) x #align module.ray.ind Module.Ray.ind variable {R} instance [Nontrivial M] : Nonempty (Module.Ray R M) := Nonempty.map Quotient.mk' inferInstance /-- The rays given by two nonzero vectors are equal if and only if those vectors satisfy `SameRay`. -/ theorem ray_eq_iff {v₁ v₂ : M} (hv₁ : v₁ ≠ 0) (hv₂ : v₂ ≠ 0) : rayOfNeZero R _ hv₁ = rayOfNeZero R _ hv₂ ↔ SameRay R v₁ v₂ := Quotient.eq' #align ray_eq_iff ray_eq_iff /-- The ray given by a positive multiple of a nonzero vector. -/ @[simp] theorem ray_pos_smul {v : M} (h : v ≠ 0) {r : R} (hr : 0 < r) (hrv : r • v ≠ 0) : rayOfNeZero R (r • v) hrv = rayOfNeZero R v h := (ray_eq_iff _ _).2 <| SameRay.sameRay_pos_smul_left v hr #align ray_pos_smul ray_pos_smul /-- An equivalence between modules implies an equivalence between ray vectors. -/ def RayVector.mapLinearEquiv (e : M ≃ₗ[R] N) : RayVector R M ≃ RayVector R N := Equiv.subtypeEquiv e.toEquiv fun _ => e.map_ne_zero_iff.symm #align ray_vector.map_linear_equiv RayVector.mapLinearEquiv /-- An equivalence between modules implies an equivalence between rays. -/ def Module.Ray.map (e : M ≃ₗ[R] N) : Module.Ray R M ≃ Module.Ray R N := Quotient.congr (RayVector.mapLinearEquiv e) fun _ _=> (SameRay.sameRay_map_iff _).symm #align module.ray.map Module.Ray.map @[simp] theorem Module.Ray.map_apply (e : M ≃ₗ[R] N) (v : M) (hv : v ≠ 0) : Module.Ray.map e (rayOfNeZero _ v hv) = rayOfNeZero _ (e v) (e.map_ne_zero_iff.2 hv) := rfl #align module.ray.map_apply Module.Ray.map_apply @[simp] theorem Module.Ray.map_refl : (Module.Ray.map <| LinearEquiv.refl R M) = Equiv.refl _ := Equiv.ext <| Module.Ray.ind R fun _ _ => rfl #align module.ray.map_refl Module.Ray.map_refl @[simp] theorem Module.Ray.map_symm (e : M ≃ₗ[R] N) : (Module.Ray.map e).symm = Module.Ray.map e.symm := rfl #align module.ray.map_symm Module.Ray.map_symm section Action variable {G : Type*} [Group G] [DistribMulAction G M] /-- Any invertible action preserves the non-zeroness of ray vectors. This is primarily of interest when `G = Rˣ` -/ instance {R : Type*} : MulAction G (RayVector R M) where smul r := Subtype.map (r • ·) fun _ => (smul_ne_zero_iff_ne _).2 mul_smul a b _ := Subtype.ext <| mul_smul a b _ one_smul _ := Subtype.ext <| one_smul _ _ variable [SMulCommClass R G M] /-- Any invertible action preserves the non-zeroness of rays. This is primarily of interest when `G = Rˣ` -/ instance : MulAction G (Module.Ray R M) where smul r := Quotient.map (r • ·) fun _ _ h => h.smul _ mul_smul a b := Quotient.ind fun _ => congr_arg Quotient.mk' <| mul_smul a b _ one_smul := Quotient.ind fun _ => congr_arg Quotient.mk' <| one_smul _ _ /-- The action via `LinearEquiv.apply_distribMulAction` corresponds to `Module.Ray.map`. -/ @[simp] theorem Module.Ray.linearEquiv_smul_eq_map (e : M ≃ₗ[R] M) (v : Module.Ray R M) : e • v = Module.Ray.map e v := rfl #align module.ray.linear_equiv_smul_eq_map Module.Ray.linearEquiv_smul_eq_map @[simp] theorem smul_rayOfNeZero (g : G) (v : M) (hv) : g • rayOfNeZero R v hv = rayOfNeZero R (g • v) ((smul_ne_zero_iff_ne _).2 hv) := rfl #align smul_ray_of_ne_zero smul_rayOfNeZero end Action namespace Module.Ray -- Porting note: `(u.1 : R)` was `(u : R)`, CoeHead from R to Rˣ does not seem to work. /-- Scaling by a positive unit is a no-op. -/ theorem units_smul_of_pos (u : Rˣ) (hu : 0 < (u.1 : R)) (v : Module.Ray R M) : u • v = v := by induction v using Module.Ray.ind rw [smul_rayOfNeZero, ray_eq_iff] exact SameRay.sameRay_pos_smul_left _ hu #align module.ray.units_smul_of_pos Module.Ray.units_smul_of_pos /-- An arbitrary `RayVector` giving a ray. -/ def someRayVector (x : Module.Ray R M) : RayVector R M := Quotient.out x #align module.ray.some_ray_vector Module.Ray.someRayVector /-- The ray of `someRayVector`. -/ @[simp] theorem someRayVector_ray (x : Module.Ray R M) : (⟦x.someRayVector⟧ : Module.Ray R M) = x := Quotient.out_eq _ #align module.ray.some_ray_vector_ray Module.Ray.someRayVector_ray /-- An arbitrary nonzero vector giving a ray. -/ def someVector (x : Module.Ray R M) : M := x.someRayVector #align module.ray.some_vector Module.Ray.someVector /-- `someVector` is nonzero. -/ @[simp] theorem someVector_ne_zero (x : Module.Ray R M) : x.someVector ≠ 0 := x.someRayVector.property #align module.ray.some_vector_ne_zero Module.Ray.someVector_ne_zero /-- The ray of `someVector`. -/ @[simp] theorem someVector_ray (x : Module.Ray R M) : rayOfNeZero R _ x.someVector_ne_zero = x := (congr_arg _ (Subtype.coe_eta _ _) : _).trans x.out_eq #align module.ray.some_vector_ray Module.Ray.someVector_ray end Module.Ray end StrictOrderedCommSemiring section StrictOrderedCommRing variable {R : Type*} [StrictOrderedCommRing R] variable {M N : Type*} [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N] {x y : M} /-- `SameRay.neg` as an `iff`. -/ @[simp] theorem sameRay_neg_iff : SameRay R (-x) (-y) ↔ SameRay R x y := by simp only [SameRay, neg_eq_zero, smul_neg, neg_inj] #align same_ray_neg_iff sameRay_neg_iff alias ⟨SameRay.of_neg, SameRay.neg⟩ := sameRay_neg_iff #align same_ray.of_neg SameRay.of_neg #align same_ray.neg SameRay.neg theorem sameRay_neg_swap : SameRay R (-x) y ↔ SameRay R x (-y) := by rw [← sameRay_neg_iff, neg_neg] #align same_ray_neg_swap sameRay_neg_swap theorem eq_zero_of_sameRay_neg_smul_right [NoZeroSMulDivisors R M] {r : R} (hr : r < 0) (h : SameRay R x (r • x)) : x = 0 := by rcases h with (rfl | h₀ | ⟨r₁, r₂, hr₁, hr₂, h⟩) · rfl · simpa [hr.ne] using h₀ · rw [← sub_eq_zero, smul_smul, ← sub_smul, smul_eq_zero] at h refine h.resolve_left (ne_of_gt <| sub_pos.2 ?_) exact (mul_neg_of_pos_of_neg hr₂ hr).trans hr₁ #align eq_zero_of_same_ray_neg_smul_right eq_zero_of_sameRay_neg_smul_right /-- If a vector is in the same ray as its negation, that vector is zero. -/ theorem eq_zero_of_sameRay_self_neg [NoZeroSMulDivisors R M] (h : SameRay R x (-x)) : x = 0 := by nontriviality M; haveI : Nontrivial R := Module.nontrivial R M refine eq_zero_of_sameRay_neg_smul_right (neg_lt_zero.2 (zero_lt_one' R)) ?_ rwa [neg_one_smul] #align eq_zero_of_same_ray_self_neg eq_zero_of_sameRay_self_neg namespace RayVector /-- Negating a nonzero vector. -/ instance {R : Type*} : Neg (RayVector R M) := ⟨fun v => ⟨-v, neg_ne_zero.2 v.prop⟩⟩ /-- Negating a nonzero vector commutes with coercion to the underlying module. -/ @[simp, norm_cast] theorem coe_neg {R : Type*} (v : RayVector R M) : ↑(-v) = -(v : M) := rfl #align ray_vector.coe_neg RayVector.coe_neg /-- Negating a nonzero vector twice produces the original vector. -/ instance {R : Type*} : InvolutiveNeg (RayVector R M) where neg := Neg.neg neg_neg v := by rw [Subtype.ext_iff, coe_neg, coe_neg, neg_neg] /-- If two nonzero vectors are equivalent, so are their negations. -/ @[simp] theorem equiv_neg_iff {v₁ v₂ : RayVector R M} : -v₁ ≈ -v₂ ↔ v₁ ≈ v₂ := sameRay_neg_iff #align ray_vector.equiv_neg_iff RayVector.equiv_neg_iff end RayVector variable (R) /-- Negating a ray. -/ instance : Neg (Module.Ray R M) := ⟨Quotient.map (fun v => -v) fun _ _ => RayVector.equiv_neg_iff.2⟩ /-- The ray given by the negation of a nonzero vector. -/ @[simp] theorem neg_rayOfNeZero (v : M) (h : v ≠ 0) : -rayOfNeZero R _ h = rayOfNeZero R (-v) (neg_ne_zero.2 h) := rfl #align neg_ray_of_ne_zero neg_rayOfNeZero namespace Module.Ray variable {R} /-- Negating a ray twice produces the original ray. -/ instance : InvolutiveNeg (Module.Ray R M) where neg := Neg.neg neg_neg x := by apply ind R (by simp) x -- Quotient.ind (fun a => congr_arg Quotient.mk' <| neg_neg _) x /-- A ray does not equal its own negation. -/ theorem ne_neg_self [NoZeroSMulDivisors R M] (x : Module.Ray R M) : x ≠ -x := by induction' x using Module.Ray.ind with x hx rw [neg_rayOfNeZero, Ne, ray_eq_iff] exact mt eq_zero_of_sameRay_self_neg hx #align module.ray.ne_neg_self Module.Ray.ne_neg_self theorem neg_units_smul (u : Rˣ) (v : Module.Ray R M) : -u • v = -(u • v) := by induction v using Module.Ray.ind simp only [smul_rayOfNeZero, Units.smul_def, Units.val_neg, neg_smul, neg_rayOfNeZero] #align module.ray.neg_units_smul Module.Ray.neg_units_smul -- Porting note: `(u.1 : R)` was `(u : R)`, CoeHead from R to Rˣ does not seem to work. /-- Scaling by a negative unit is negation. -/ theorem units_smul_of_neg (u : Rˣ) (hu : u.1 < 0) (v : Module.Ray R M) : u • v = -v := by rw [← neg_inj, neg_neg, ← neg_units_smul, units_smul_of_pos] rwa [Units.val_neg, Right.neg_pos_iff] #align module.ray.units_smul_of_neg Module.Ray.units_smul_of_neg @[simp] protected theorem map_neg (f : M ≃ₗ[R] N) (v : Module.Ray R M) : map f (-v) = -map f v := by induction' v using Module.Ray.ind with g hg simp #align module.ray.map_neg Module.Ray.map_neg end Module.Ray end StrictOrderedCommRing section LinearOrderedCommRing variable {R : Type*} [LinearOrderedCommRing R] variable {M : Type*} [AddCommGroup M] [Module R M] -- Porting note: Needed to add coercion ↥ below /-- `SameRay` follows from membership of `MulAction.orbit` for the `Units.posSubgroup`. -/ theorem sameRay_of_mem_orbit {v₁ v₂ : M} (h : v₁ ∈ MulAction.orbit ↥(Units.posSubgroup R) v₂) : SameRay R v₁ v₂ := by rcases h with ⟨⟨r, hr : 0 < r.1⟩, rfl : r • v₂ = v₁⟩ exact SameRay.sameRay_pos_smul_left _ hr #align same_ray_of_mem_orbit sameRay_of_mem_orbit /-- Scaling by an inverse unit is the same as scaling by itself. -/ @[simp] theorem units_inv_smul (u : Rˣ) (v : Module.Ray R M) : u⁻¹ • v = u • v := have := mul_self_pos.2 u.ne_zero calc u⁻¹ • v = (u * u) • u⁻¹ • v := Eq.symm <| (u⁻¹ • v).units_smul_of_pos _ (by exact this) _ = u • v := by rw [mul_smul, smul_inv_smul] #align units_inv_smul units_inv_smul section variable [NoZeroSMulDivisors R M] @[simp] theorem sameRay_smul_right_iff {v : M} {r : R} : SameRay R v (r • v) ↔ 0 ≤ r ∨ v = 0 := ⟨fun hrv => or_iff_not_imp_left.2 fun hr => eq_zero_of_sameRay_neg_smul_right (not_le.1 hr) hrv, or_imp.2 ⟨SameRay.sameRay_nonneg_smul_right v, fun h => h.symm ▸ SameRay.zero_left _⟩⟩ #align same_ray_smul_right_iff sameRay_smul_right_iff /-- A nonzero vector is in the same ray as a multiple of itself if and only if that multiple is positive. -/ theorem sameRay_smul_right_iff_of_ne {v : M} (hv : v ≠ 0) {r : R} (hr : r ≠ 0) : SameRay R v (r • v) ↔ 0 < r := by simp only [sameRay_smul_right_iff, hv, or_false_iff, hr.symm.le_iff_lt] #align same_ray_smul_right_iff_of_ne sameRay_smul_right_iff_of_ne @[simp] theorem sameRay_smul_left_iff {v : M} {r : R} : SameRay R (r • v) v ↔ 0 ≤ r ∨ v = 0 := SameRay.sameRay_comm.trans sameRay_smul_right_iff #align same_ray_smul_left_iff sameRay_smul_left_iff /-- A multiple of a nonzero vector is in the same ray as that vector if and only if that multiple is positive. -/ theorem sameRay_smul_left_iff_of_ne {v : M} (hv : v ≠ 0) {r : R} (hr : r ≠ 0) : SameRay R (r • v) v ↔ 0 < r := SameRay.sameRay_comm.trans (sameRay_smul_right_iff_of_ne hv hr) #align same_ray_smul_left_iff_of_ne sameRay_smul_left_iff_of_ne @[simp] theorem sameRay_neg_smul_right_iff {v : M} {r : R} : SameRay R (-v) (r • v) ↔ r ≤ 0 ∨ v = 0 := by rw [← sameRay_neg_iff, neg_neg, ← neg_smul, sameRay_smul_right_iff, neg_nonneg] #align same_ray_neg_smul_right_iff sameRay_neg_smul_right_iff
Mathlib/LinearAlgebra/Ray.lean
554
556
theorem sameRay_neg_smul_right_iff_of_ne {v : M} {r : R} (hv : v ≠ 0) (hr : r ≠ 0) : SameRay R (-v) (r • v) ↔ r < 0 := by
simp only [sameRay_neg_smul_right_iff, hv, or_false_iff, hr.le_iff_lt]
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Data.List.Lattice import Mathlib.Data.List.Range import Mathlib.Data.Bool.Basic #align_import data.list.intervals from "leanprover-community/mathlib"@"7b78d1776212a91ecc94cf601f83bdcc46b04213" /-! # Intervals in ℕ This file defines intervals of naturals. `List.Ico m n` is the list of integers greater than `m` and strictly less than `n`. ## TODO - Define `Ioo` and `Icc`, state basic lemmas about them. - Also do the versions for integers? - One could generalise even further, defining 'locally finite partial orders', for which `Set.Ico a b` is `[Finite]`, and 'locally finite total orders', for which there is a list model. - Once the above is done, get rid of `Data.Int.range` (and maybe `List.range'`?). -/ open Nat namespace List /-- `Ico n m` is the list of natural numbers `n ≤ x < m`. (Ico stands for "interval, closed-open".) See also `Data/Set/Intervals.lean` for `Set.Ico`, modelling intervals in general preorders, and `Multiset.Ico` and `Finset.Ico` for `n ≤ x < m` as a multiset or as a finset. -/ def Ico (n m : ℕ) : List ℕ := range' n (m - n) #align list.Ico List.Ico namespace Ico theorem zero_bot (n : ℕ) : Ico 0 n = range n := by rw [Ico, Nat.sub_zero, range_eq_range'] #align list.Ico.zero_bot List.Ico.zero_bot @[simp] theorem length (n m : ℕ) : length (Ico n m) = m - n := by dsimp [Ico] simp [length_range', autoParam] #align list.Ico.length List.Ico.length theorem pairwise_lt (n m : ℕ) : Pairwise (· < ·) (Ico n m) := by dsimp [Ico] simp [pairwise_lt_range', autoParam] #align list.Ico.pairwise_lt List.Ico.pairwise_lt theorem nodup (n m : ℕ) : Nodup (Ico n m) := by dsimp [Ico] simp [nodup_range', autoParam] #align list.Ico.nodup List.Ico.nodup @[simp] theorem mem {n m l : ℕ} : l ∈ Ico n m ↔ n ≤ l ∧ l < m := by suffices n ≤ l ∧ l < n + (m - n) ↔ n ≤ l ∧ l < m by simp [Ico, this] rcases le_total n m with hnm | hmn · rw [Nat.add_sub_cancel' hnm] · rw [Nat.sub_eq_zero_iff_le.mpr hmn, Nat.add_zero] exact and_congr_right fun hnl => Iff.intro (fun hln => (not_le_of_gt hln hnl).elim) fun hlm => lt_of_lt_of_le hlm hmn #align list.Ico.mem List.Ico.mem theorem eq_nil_of_le {n m : ℕ} (h : m ≤ n) : Ico n m = [] := by simp [Ico, Nat.sub_eq_zero_iff_le.mpr h] #align list.Ico.eq_nil_of_le List.Ico.eq_nil_of_le theorem map_add (n m k : ℕ) : (Ico n m).map (k + ·) = Ico (n + k) (m + k) := by rw [Ico, Ico, map_add_range', Nat.add_sub_add_right m k, Nat.add_comm n k] #align list.Ico.map_add List.Ico.map_add theorem map_sub (n m k : ℕ) (h₁ : k ≤ n) : ((Ico n m).map fun x => x - k) = Ico (n - k) (m - k) := by rw [Ico, Ico, Nat.sub_sub_sub_cancel_right h₁, map_sub_range' _ _ _ h₁] #align list.Ico.map_sub List.Ico.map_sub @[simp] theorem self_empty {n : ℕ} : Ico n n = [] := eq_nil_of_le (le_refl n) #align list.Ico.self_empty List.Ico.self_empty @[simp] theorem eq_empty_iff {n m : ℕ} : Ico n m = [] ↔ m ≤ n := Iff.intro (fun h => Nat.sub_eq_zero_iff_le.mp <| by rw [← length, h, List.length]) eq_nil_of_le #align list.Ico.eq_empty_iff List.Ico.eq_empty_iff theorem append_consecutive {n m l : ℕ} (hnm : n ≤ m) (hml : m ≤ l) : Ico n m ++ Ico m l = Ico n l := by dsimp only [Ico] convert range'_append n (m-n) (l-m) 1 using 2 · rw [Nat.one_mul, Nat.add_sub_cancel' hnm] · rw [Nat.sub_add_sub_cancel hml hnm] #align list.Ico.append_consecutive List.Ico.append_consecutive @[simp] theorem inter_consecutive (n m l : ℕ) : Ico n m ∩ Ico m l = [] := by apply eq_nil_iff_forall_not_mem.2 intro a simp only [and_imp, not_and, not_lt, List.mem_inter_iff, List.Ico.mem] intro _ h₂ h₃ exfalso exact not_lt_of_ge h₃ h₂ #align list.Ico.inter_consecutive List.Ico.inter_consecutive @[simp] theorem bagInter_consecutive (n m l : Nat) : @List.bagInter ℕ instBEqOfDecidableEq (Ico n m) (Ico m l) = [] := (bagInter_nil_iff_inter_nil _ _).2 (by convert inter_consecutive n m l) #align list.Ico.bag_inter_consecutive List.Ico.bagInter_consecutive @[simp] theorem succ_singleton {n : ℕ} : Ico n (n + 1) = [n] := by dsimp [Ico] simp [range', Nat.add_sub_cancel_left] #align list.Ico.succ_singleton List.Ico.succ_singleton theorem succ_top {n m : ℕ} (h : n ≤ m) : Ico n (m + 1) = Ico n m ++ [m] := by rwa [← succ_singleton, append_consecutive] exact Nat.le_succ _ #align list.Ico.succ_top List.Ico.succ_top
Mathlib/Data/List/Intervals.lean
130
132
theorem eq_cons {n m : ℕ} (h : n < m) : Ico n m = n :: Ico (n + 1) m := by
rw [← append_consecutive (Nat.le_succ n) h, succ_singleton] rfl
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Algebra.Order.Group.Instances import Mathlib.Analysis.Convex.Segment import Mathlib.Tactic.GCongr #align_import analysis.convex.star from "leanprover-community/mathlib"@"9003f28797c0664a49e4179487267c494477d853" /-! # Star-convex sets This files defines star-convex sets (aka star domains, star-shaped set, radially convex set). A set is star-convex at `x` if every segment from `x` to a point in the set is contained in the set. This is the prototypical example of a contractible set in homotopy theory (by scaling every point towards `x`), but has wider uses. Note that this has nothing to do with star rings, `Star` and co. ## Main declarations * `StarConvex 𝕜 x s`: `s` is star-convex at `x` with scalars `𝕜`. ## Implementation notes Instead of saying that a set is star-convex, we say a set is star-convex *at a point*. This has the advantage of allowing us to talk about convexity as being "everywhere star-convexity" and of making the union of star-convex sets be star-convex. Incidentally, this choice means we don't need to assume a set is nonempty for it to be star-convex. Concretely, the empty set is star-convex at every point. ## TODO Balanced sets are star-convex. The closure of a star-convex set is star-convex. Star-convex sets are contractible. A nonempty open star-convex set in `ℝ^n` is diffeomorphic to the entire space. -/ open Set open Convex Pointwise variable {𝕜 E F : Type*} section OrderedSemiring variable [OrderedSemiring 𝕜] section AddCommMonoid variable [AddCommMonoid E] [AddCommMonoid F] section SMul variable (𝕜) [SMul 𝕜 E] [SMul 𝕜 F] (x : E) (s : Set E) /-- Star-convexity of sets. `s` is star-convex at `x` if every segment from `x` to a point in `s` is contained in `s`. -/ def StarConvex : Prop := ∀ ⦃y : E⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → a • x + b • y ∈ s #align star_convex StarConvex variable {𝕜 x s} {t : Set E} theorem starConvex_iff_segment_subset : StarConvex 𝕜 x s ↔ ∀ ⦃y⦄, y ∈ s → [x -[𝕜] y] ⊆ s := by constructor · rintro h y hy z ⟨a, b, ha, hb, hab, rfl⟩ exact h hy ha hb hab · rintro h y hy a b ha hb hab exact h hy ⟨a, b, ha, hb, hab, rfl⟩ #align star_convex_iff_segment_subset starConvex_iff_segment_subset theorem StarConvex.segment_subset (h : StarConvex 𝕜 x s) {y : E} (hy : y ∈ s) : [x -[𝕜] y] ⊆ s := starConvex_iff_segment_subset.1 h hy #align star_convex.segment_subset StarConvex.segment_subset theorem StarConvex.openSegment_subset (h : StarConvex 𝕜 x s) {y : E} (hy : y ∈ s) : openSegment 𝕜 x y ⊆ s := (openSegment_subset_segment 𝕜 x y).trans (h.segment_subset hy) #align star_convex.open_segment_subset StarConvex.openSegment_subset /-- Alternative definition of star-convexity, in terms of pointwise set operations. -/ theorem starConvex_iff_pointwise_add_subset : StarConvex 𝕜 x s ↔ ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → a • {x} + b • s ⊆ s := by refine ⟨?_, fun h y hy a b ha hb hab => h ha hb hab (add_mem_add (smul_mem_smul_set <| mem_singleton _) ⟨_, hy, rfl⟩)⟩ rintro hA a b ha hb hab w ⟨au, ⟨u, rfl : u = x, rfl⟩, bv, ⟨v, hv, rfl⟩, rfl⟩ exact hA hv ha hb hab #align star_convex_iff_pointwise_add_subset starConvex_iff_pointwise_add_subset theorem starConvex_empty (x : E) : StarConvex 𝕜 x ∅ := fun _ hy => hy.elim #align star_convex_empty starConvex_empty theorem starConvex_univ (x : E) : StarConvex 𝕜 x univ := fun _ _ _ _ _ _ _ => trivial #align star_convex_univ starConvex_univ theorem StarConvex.inter (hs : StarConvex 𝕜 x s) (ht : StarConvex 𝕜 x t) : StarConvex 𝕜 x (s ∩ t) := fun _ hy _ _ ha hb hab => ⟨hs hy.left ha hb hab, ht hy.right ha hb hab⟩ #align star_convex.inter StarConvex.inter theorem starConvex_sInter {S : Set (Set E)} (h : ∀ s ∈ S, StarConvex 𝕜 x s) : StarConvex 𝕜 x (⋂₀ S) := fun _ hy _ _ ha hb hab s hs => h s hs (hy s hs) ha hb hab #align star_convex_sInter starConvex_sInter theorem starConvex_iInter {ι : Sort*} {s : ι → Set E} (h : ∀ i, StarConvex 𝕜 x (s i)) : StarConvex 𝕜 x (⋂ i, s i) := sInter_range s ▸ starConvex_sInter <| forall_mem_range.2 h #align star_convex_Inter starConvex_iInter theorem StarConvex.union (hs : StarConvex 𝕜 x s) (ht : StarConvex 𝕜 x t) : StarConvex 𝕜 x (s ∪ t) := by rintro y (hy | hy) a b ha hb hab · exact Or.inl (hs hy ha hb hab) · exact Or.inr (ht hy ha hb hab) #align star_convex.union StarConvex.union theorem starConvex_iUnion {ι : Sort*} {s : ι → Set E} (hs : ∀ i, StarConvex 𝕜 x (s i)) : StarConvex 𝕜 x (⋃ i, s i) := by rintro y hy a b ha hb hab rw [mem_iUnion] at hy ⊢ obtain ⟨i, hy⟩ := hy exact ⟨i, hs i hy ha hb hab⟩ #align star_convex_Union starConvex_iUnion theorem starConvex_sUnion {S : Set (Set E)} (hS : ∀ s ∈ S, StarConvex 𝕜 x s) : StarConvex 𝕜 x (⋃₀ S) := by rw [sUnion_eq_iUnion] exact starConvex_iUnion fun s => hS _ s.2 #align star_convex_sUnion starConvex_sUnion theorem StarConvex.prod {y : F} {s : Set E} {t : Set F} (hs : StarConvex 𝕜 x s) (ht : StarConvex 𝕜 y t) : StarConvex 𝕜 (x, y) (s ×ˢ t) := fun _ hy _ _ ha hb hab => ⟨hs hy.1 ha hb hab, ht hy.2 ha hb hab⟩ #align star_convex.prod StarConvex.prod theorem starConvex_pi {ι : Type*} {E : ι → Type*} [∀ i, AddCommMonoid (E i)] [∀ i, SMul 𝕜 (E i)] {x : ∀ i, E i} {s : Set ι} {t : ∀ i, Set (E i)} (ht : ∀ ⦃i⦄, i ∈ s → StarConvex 𝕜 (x i) (t i)) : StarConvex 𝕜 x (s.pi t) := fun _ hy _ _ ha hb hab i hi => ht hi (hy i hi) ha hb hab #align star_convex_pi starConvex_pi end SMul section Module variable [Module 𝕜 E] [Module 𝕜 F] {x y z : E} {s : Set E} theorem StarConvex.mem (hs : StarConvex 𝕜 x s) (h : s.Nonempty) : x ∈ s := by obtain ⟨y, hy⟩ := h convert hs hy zero_le_one le_rfl (add_zero 1) rw [one_smul, zero_smul, add_zero] #align star_convex.mem StarConvex.mem theorem starConvex_iff_forall_pos (hx : x ∈ s) : StarConvex 𝕜 x s ↔ ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s := by refine ⟨fun h y hy a b ha hb hab => h hy ha.le hb.le hab, ?_⟩ intro h y hy a b ha hb hab obtain rfl | ha := ha.eq_or_lt · rw [zero_add] at hab rwa [hab, one_smul, zero_smul, zero_add] obtain rfl | hb := hb.eq_or_lt · rw [add_zero] at hab rwa [hab, one_smul, zero_smul, add_zero] exact h hy ha hb hab #align star_convex_iff_forall_pos starConvex_iff_forall_pos theorem starConvex_iff_forall_ne_pos (hx : x ∈ s) : StarConvex 𝕜 x s ↔ ∀ ⦃y⦄, y ∈ s → x ≠ y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s := by refine ⟨fun h y hy _ a b ha hb hab => h hy ha.le hb.le hab, ?_⟩ intro h y hy a b ha hb hab obtain rfl | ha' := ha.eq_or_lt · rw [zero_add] at hab rwa [hab, zero_smul, one_smul, zero_add] obtain rfl | hb' := hb.eq_or_lt · rw [add_zero] at hab rwa [hab, zero_smul, one_smul, add_zero] obtain rfl | hxy := eq_or_ne x y · rwa [Convex.combo_self hab] exact h hy hxy ha' hb' hab #align star_convex_iff_forall_ne_pos starConvex_iff_forall_ne_pos theorem starConvex_iff_openSegment_subset (hx : x ∈ s) : StarConvex 𝕜 x s ↔ ∀ ⦃y⦄, y ∈ s → openSegment 𝕜 x y ⊆ s := starConvex_iff_segment_subset.trans <| forall₂_congr fun _ hy => (openSegment_subset_iff_segment_subset hx hy).symm #align star_convex_iff_open_segment_subset starConvex_iff_openSegment_subset theorem starConvex_singleton (x : E) : StarConvex 𝕜 x {x} := by rintro y (rfl : y = x) a b _ _ hab exact Convex.combo_self hab _ #align star_convex_singleton starConvex_singleton theorem StarConvex.linear_image (hs : StarConvex 𝕜 x s) (f : E →ₗ[𝕜] F) : StarConvex 𝕜 (f x) (f '' s) := by rintro _ ⟨y, hy, rfl⟩ a b ha hb hab exact ⟨a • x + b • y, hs hy ha hb hab, by rw [f.map_add, f.map_smul, f.map_smul]⟩ #align star_convex.linear_image StarConvex.linear_image theorem StarConvex.is_linear_image (hs : StarConvex 𝕜 x s) {f : E → F} (hf : IsLinearMap 𝕜 f) : StarConvex 𝕜 (f x) (f '' s) := hs.linear_image <| hf.mk' f #align star_convex.is_linear_image StarConvex.is_linear_image theorem StarConvex.linear_preimage {s : Set F} (f : E →ₗ[𝕜] F) (hs : StarConvex 𝕜 (f x) s) : StarConvex 𝕜 x (f ⁻¹' s) := by intro y hy a b ha hb hab rw [mem_preimage, f.map_add, f.map_smul, f.map_smul] exact hs hy ha hb hab #align star_convex.linear_preimage StarConvex.linear_preimage theorem StarConvex.is_linear_preimage {s : Set F} {f : E → F} (hs : StarConvex 𝕜 (f x) s) (hf : IsLinearMap 𝕜 f) : StarConvex 𝕜 x (preimage f s) := hs.linear_preimage <| hf.mk' f #align star_convex.is_linear_preimage StarConvex.is_linear_preimage theorem StarConvex.add {t : Set E} (hs : StarConvex 𝕜 x s) (ht : StarConvex 𝕜 y t) : StarConvex 𝕜 (x + y) (s + t) := by rw [← add_image_prod] exact (hs.prod ht).is_linear_image IsLinearMap.isLinearMap_add #align star_convex.add StarConvex.add theorem StarConvex.add_left (hs : StarConvex 𝕜 x s) (z : E) : StarConvex 𝕜 (z + x) ((fun x => z + x) '' s) := by intro y hy a b ha hb hab obtain ⟨y', hy', rfl⟩ := hy refine ⟨a • x + b • y', hs hy' ha hb hab, ?_⟩ rw [smul_add, smul_add, add_add_add_comm, ← add_smul, hab, one_smul] #align star_convex.add_left StarConvex.add_left theorem StarConvex.add_right (hs : StarConvex 𝕜 x s) (z : E) : StarConvex 𝕜 (x + z) ((fun x => x + z) '' s) := by intro y hy a b ha hb hab obtain ⟨y', hy', rfl⟩ := hy refine ⟨a • x + b • y', hs hy' ha hb hab, ?_⟩ rw [smul_add, smul_add, add_add_add_comm, ← add_smul, hab, one_smul] #align star_convex.add_right StarConvex.add_right /-- The translation of a star-convex set is also star-convex. -/ theorem StarConvex.preimage_add_right (hs : StarConvex 𝕜 (z + x) s) : StarConvex 𝕜 x ((fun x => z + x) ⁻¹' s) := by intro y hy a b ha hb hab have h := hs hy ha hb hab rwa [smul_add, smul_add, add_add_add_comm, ← add_smul, hab, one_smul] at h #align star_convex.preimage_add_right StarConvex.preimage_add_right /-- The translation of a star-convex set is also star-convex. -/ theorem StarConvex.preimage_add_left (hs : StarConvex 𝕜 (x + z) s) : StarConvex 𝕜 x ((fun x => x + z) ⁻¹' s) := by rw [add_comm] at hs simpa only [add_comm] using hs.preimage_add_right #align star_convex.preimage_add_left StarConvex.preimage_add_left end Module end AddCommMonoid section AddCommGroup variable [AddCommGroup E] [Module 𝕜 E] {x y : E} theorem StarConvex.sub' {s : Set (E × E)} (hs : StarConvex 𝕜 (x, y) s) : StarConvex 𝕜 (x - y) ((fun x : E × E => x.1 - x.2) '' s) := hs.is_linear_image IsLinearMap.isLinearMap_sub #align star_convex.sub' StarConvex.sub' end AddCommGroup end OrderedSemiring section OrderedCommSemiring variable [OrderedCommSemiring 𝕜] section AddCommMonoid variable [AddCommMonoid E] [AddCommMonoid F] [Module 𝕜 E] [Module 𝕜 F] {x : E} {s : Set E} theorem StarConvex.smul (hs : StarConvex 𝕜 x s) (c : 𝕜) : StarConvex 𝕜 (c • x) (c • s) := hs.linear_image <| LinearMap.lsmul _ _ c #align star_convex.smul StarConvex.smul theorem StarConvex.preimage_smul {c : 𝕜} (hs : StarConvex 𝕜 (c • x) s) : StarConvex 𝕜 x ((fun z => c • z) ⁻¹' s) := hs.linear_preimage (LinearMap.lsmul _ _ c) #align star_convex.preimage_smul StarConvex.preimage_smul theorem StarConvex.affinity (hs : StarConvex 𝕜 x s) (z : E) (c : 𝕜) : StarConvex 𝕜 (z + c • x) ((fun x => z + c • x) '' s) := by have h := (hs.smul c).add_left z rwa [← image_smul, image_image] at h #align star_convex.affinity StarConvex.affinity end AddCommMonoid end OrderedCommSemiring section OrderedRing variable [OrderedRing 𝕜] section AddCommMonoid variable [AddCommMonoid E] [SMulWithZero 𝕜 E] {s : Set E} theorem starConvex_zero_iff : StarConvex 𝕜 0 s ↔ ∀ ⦃x : E⦄, x ∈ s → ∀ ⦃a : 𝕜⦄, 0 ≤ a → a ≤ 1 → a • x ∈ s := by refine forall_congr' fun x => forall_congr' fun _ => ⟨fun h a ha₀ ha₁ => ?_, fun h a b ha hb hab => ?_⟩ · simpa only [sub_add_cancel, eq_self_iff_true, forall_true_left, zero_add, smul_zero] using h (sub_nonneg_of_le ha₁) ha₀ · rw [smul_zero, zero_add] exact h hb (by rw [← hab]; exact le_add_of_nonneg_left ha) #align star_convex_zero_iff starConvex_zero_iff end AddCommMonoid section AddCommGroup variable [AddCommGroup E] [AddCommGroup F] [Module 𝕜 E] [Module 𝕜 F] {x y : E} {s t : Set E} theorem StarConvex.add_smul_mem (hs : StarConvex 𝕜 x s) (hy : x + y ∈ s) {t : 𝕜} (ht₀ : 0 ≤ t) (ht₁ : t ≤ 1) : x + t • y ∈ s := by have h : x + t • y = (1 - t) • x + t • (x + y) := by rw [smul_add, ← add_assoc, ← add_smul, sub_add_cancel, one_smul] rw [h] exact hs hy (sub_nonneg_of_le ht₁) ht₀ (sub_add_cancel _ _) #align star_convex.add_smul_mem StarConvex.add_smul_mem
Mathlib/Analysis/Convex/Star.lean
340
341
theorem StarConvex.smul_mem (hs : StarConvex 𝕜 0 s) (hx : x ∈ s) {t : 𝕜} (ht₀ : 0 ≤ t) (ht₁ : t ≤ 1) : t • x ∈ s := by
simpa using hs.add_smul_mem (by simpa using hx) ht₀ ht₁
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir -/ import Mathlib.Algebra.Order.CauSeq.BigOperators import Mathlib.Data.Complex.Abs import Mathlib.Data.Complex.BigOperators import Mathlib.Data.Nat.Choose.Sum #align_import data.complex.exponential from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Exponential, trigonometric and hyperbolic trigonometric functions This file contains the definitions of the real and complex exponential, sine, cosine, tangent, hyperbolic sine, hyperbolic cosine, and hyperbolic tangent functions. -/ open CauSeq Finset IsAbsoluteValue open scoped Classical ComplexConjugate namespace Complex theorem isCauSeq_abs_exp (z : ℂ) : IsCauSeq _root_.abs fun n => ∑ m ∈ range n, abs (z ^ m / m.factorial) := let ⟨n, hn⟩ := exists_nat_gt (abs z) have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (abs.nonneg _) hn IsCauSeq.series_ratio_test n (abs z / n) (div_nonneg (abs.nonneg _) (le_of_lt hn0)) (by rwa [div_lt_iff hn0, one_mul]) fun m hm => by rw [abs_abs, abs_abs, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul, ← div_div, mul_div_assoc, mul_div_right_comm, map_mul, map_div₀, abs_natCast] gcongr exact le_trans hm (Nat.le_succ _) #align complex.is_cau_abs_exp Complex.isCauSeq_abs_exp noncomputable section theorem isCauSeq_exp (z : ℂ) : IsCauSeq abs fun n => ∑ m ∈ range n, z ^ m / m.factorial := (isCauSeq_abs_exp z).of_abv #align complex.is_cau_exp Complex.isCauSeq_exp /-- The Cauchy sequence consisting of partial sums of the Taylor series of the complex exponential function -/ -- Porting note (#11180): removed `@[pp_nodot]` def exp' (z : ℂ) : CauSeq ℂ Complex.abs := ⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩ #align complex.exp' Complex.exp' /-- The complex exponential function, defined via its Taylor series -/ -- Porting note (#11180): removed `@[pp_nodot]` -- Porting note: removed `irreducible` attribute, so I can prove things def exp (z : ℂ) : ℂ := CauSeq.lim (exp' z) #align complex.exp Complex.exp /-- The complex sine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def sin (z : ℂ) : ℂ := (exp (-z * I) - exp (z * I)) * I / 2 #align complex.sin Complex.sin /-- The complex cosine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def cos (z : ℂ) : ℂ := (exp (z * I) + exp (-z * I)) / 2 #align complex.cos Complex.cos /-- The complex tangent function, defined as `sin z / cos z` -/ -- Porting note (#11180): removed `@[pp_nodot]` def tan (z : ℂ) : ℂ := sin z / cos z #align complex.tan Complex.tan /-- The complex cotangent function, defined as `cos z / sin z` -/ def cot (z : ℂ) : ℂ := cos z / sin z /-- The complex hyperbolic sine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def sinh (z : ℂ) : ℂ := (exp z - exp (-z)) / 2 #align complex.sinh Complex.sinh /-- The complex hyperbolic cosine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def cosh (z : ℂ) : ℂ := (exp z + exp (-z)) / 2 #align complex.cosh Complex.cosh /-- The complex hyperbolic tangent function, defined as `sinh z / cosh z` -/ -- Porting note (#11180): removed `@[pp_nodot]` def tanh (z : ℂ) : ℂ := sinh z / cosh z #align complex.tanh Complex.tanh /-- scoped notation for the complex exponential function -/ scoped notation "cexp" => Complex.exp end end Complex namespace Real open Complex noncomputable section /-- The real exponential function, defined as the real part of the complex exponential -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def exp (x : ℝ) : ℝ := (exp x).re #align real.exp Real.exp /-- The real sine function, defined as the real part of the complex sine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def sin (x : ℝ) : ℝ := (sin x).re #align real.sin Real.sin /-- The real cosine function, defined as the real part of the complex cosine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def cos (x : ℝ) : ℝ := (cos x).re #align real.cos Real.cos /-- The real tangent function, defined as the real part of the complex tangent -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def tan (x : ℝ) : ℝ := (tan x).re #align real.tan Real.tan /-- The real cotangent function, defined as the real part of the complex cotangent -/ nonrec def cot (x : ℝ) : ℝ := (cot x).re /-- The real hypebolic sine function, defined as the real part of the complex hyperbolic sine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def sinh (x : ℝ) : ℝ := (sinh x).re #align real.sinh Real.sinh /-- The real hypebolic cosine function, defined as the real part of the complex hyperbolic cosine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def cosh (x : ℝ) : ℝ := (cosh x).re #align real.cosh Real.cosh /-- The real hypebolic tangent function, defined as the real part of the complex hyperbolic tangent -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def tanh (x : ℝ) : ℝ := (tanh x).re #align real.tanh Real.tanh /-- scoped notation for the real exponential function -/ scoped notation "rexp" => Real.exp end end Real namespace Complex variable (x y : ℂ) @[simp] theorem exp_zero : exp 0 = 1 := by rw [exp] refine lim_eq_of_equiv_const fun ε ε0 => ⟨1, fun j hj => ?_⟩ convert (config := .unfoldSameFun) ε0 -- Porting note: ε0 : ε > 0 but goal is _ < ε cases' j with j j · exact absurd hj (not_le_of_gt zero_lt_one) · dsimp [exp'] induction' j with j ih · dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl] · rw [← ih (by simp [Nat.succ_le_succ])] simp only [sum_range_succ, pow_succ] simp #align complex.exp_zero Complex.exp_zero theorem exp_add : exp (x + y) = exp x * exp y := by have hj : ∀ j : ℕ, (∑ m ∈ range j, (x + y) ^ m / m.factorial) = ∑ i ∈ range j, ∑ k ∈ range (i + 1), x ^ k / k.factorial * (y ^ (i - k) / (i - k).factorial) := by intro j refine Finset.sum_congr rfl fun m _ => ?_ rw [add_pow, div_eq_mul_inv, sum_mul] refine Finset.sum_congr rfl fun I hi => ?_ have h₁ : (m.choose I : ℂ) ≠ 0 := Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi)))) have h₂ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi) rw [← h₂, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv] simp only [mul_left_comm (m.choose I : ℂ), mul_assoc, mul_left_comm (m.choose I : ℂ)⁻¹, mul_comm (m.choose I : ℂ)] rw [inv_mul_cancel h₁] simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm] simp_rw [exp, exp', lim_mul_lim] apply (lim_eq_lim_of_equiv _).symm simp only [hj] exact cauchy_product (isCauSeq_abs_exp x) (isCauSeq_exp y) #align complex.exp_add Complex.exp_add -- Porting note (#11445): new definition /-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/ noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ := { toFun := fun z => exp (Multiplicative.toAdd z), map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List ℂ) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative ℂ) expMonoidHom l #align complex.exp_list_sum Complex.exp_list_sum theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s #align complex.exp_multiset_sum Complex.exp_multiset_sum theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) : exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (β := Multiplicative ℂ) expMonoidHom f s #align complex.exp_sum Complex.exp_sum lemma exp_nsmul (x : ℂ) (n : ℕ) : exp (n • x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative ℂ) ℂ _ _ expMonoidHom _ _ theorem exp_nat_mul (x : ℂ) : ∀ n : ℕ, exp (n * x) = exp x ^ n | 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero] | Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul] #align complex.exp_nat_mul Complex.exp_nat_mul theorem exp_ne_zero : exp x ≠ 0 := fun h => zero_ne_one <| by rw [← exp_zero, ← add_neg_self x, exp_add, h]; simp #align complex.exp_ne_zero Complex.exp_ne_zero theorem exp_neg : exp (-x) = (exp x)⁻¹ := by rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancel (exp_ne_zero x)] #align complex.exp_neg Complex.exp_neg theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] #align complex.exp_sub Complex.exp_sub theorem exp_int_mul (z : ℂ) (n : ℤ) : Complex.exp (n * z) = Complex.exp z ^ n := by cases n · simp [exp_nat_mul] · simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul] #align complex.exp_int_mul Complex.exp_int_mul @[simp] theorem exp_conj : exp (conj x) = conj (exp x) := by dsimp [exp] rw [← lim_conj] refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_) dsimp [exp', Function.comp_def, cauSeqConj] rw [map_sum (starRingEnd _)] refine sum_congr rfl fun n _ => ?_ rw [map_div₀, map_pow, ← ofReal_natCast, conj_ofReal] #align complex.exp_conj Complex.exp_conj @[simp] theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x := conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal] #align complex.of_real_exp_of_real_re Complex.ofReal_exp_ofReal_re @[simp, norm_cast] theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x := ofReal_exp_ofReal_re _ #align complex.of_real_exp Complex.ofReal_exp @[simp] theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im] #align complex.exp_of_real_im Complex.exp_ofReal_im theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x := rfl #align complex.exp_of_real_re Complex.exp_ofReal_re theorem two_sinh : 2 * sinh x = exp x - exp (-x) := mul_div_cancel₀ _ two_ne_zero #align complex.two_sinh Complex.two_sinh theorem two_cosh : 2 * cosh x = exp x + exp (-x) := mul_div_cancel₀ _ two_ne_zero #align complex.two_cosh Complex.two_cosh @[simp] theorem sinh_zero : sinh 0 = 0 := by simp [sinh] #align complex.sinh_zero Complex.sinh_zero @[simp] theorem sinh_neg : sinh (-x) = -sinh x := by simp [sinh, exp_neg, (neg_div _ _).symm, add_mul] #align complex.sinh_neg Complex.sinh_neg private theorem sinh_add_aux {a b c d : ℂ} : (a - b) * (c + d) + (a + b) * (c - d) = 2 * (a * c - b * d) := by ring theorem sinh_add : sinh (x + y) = sinh x * cosh y + cosh x * sinh y := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_sinh, exp_add, neg_add, exp_add, eq_comm, mul_add, ← mul_assoc, two_sinh, mul_left_comm, two_sinh, ← mul_right_inj' (two_ne_zero' ℂ), mul_add, mul_left_comm, two_cosh, ← mul_assoc, two_cosh] exact sinh_add_aux #align complex.sinh_add Complex.sinh_add @[simp] theorem cosh_zero : cosh 0 = 1 := by simp [cosh] #align complex.cosh_zero Complex.cosh_zero @[simp] theorem cosh_neg : cosh (-x) = cosh x := by simp [add_comm, cosh, exp_neg] #align complex.cosh_neg Complex.cosh_neg private theorem cosh_add_aux {a b c d : ℂ} : (a + b) * (c + d) + (a - b) * (c - d) = 2 * (a * c + b * d) := by ring theorem cosh_add : cosh (x + y) = cosh x * cosh y + sinh x * sinh y := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_cosh, exp_add, neg_add, exp_add, eq_comm, mul_add, ← mul_assoc, two_cosh, ← mul_assoc, two_sinh, ← mul_right_inj' (two_ne_zero' ℂ), mul_add, mul_left_comm, two_cosh, mul_left_comm, two_sinh] exact cosh_add_aux #align complex.cosh_add Complex.cosh_add theorem sinh_sub : sinh (x - y) = sinh x * cosh y - cosh x * sinh y := by simp [sub_eq_add_neg, sinh_add, sinh_neg, cosh_neg] #align complex.sinh_sub Complex.sinh_sub theorem cosh_sub : cosh (x - y) = cosh x * cosh y - sinh x * sinh y := by simp [sub_eq_add_neg, cosh_add, sinh_neg, cosh_neg] #align complex.cosh_sub Complex.cosh_sub theorem sinh_conj : sinh (conj x) = conj (sinh x) := by rw [sinh, ← RingHom.map_neg, exp_conj, exp_conj, ← RingHom.map_sub, sinh, map_div₀] -- Porting note: not nice simp [← one_add_one_eq_two] #align complex.sinh_conj Complex.sinh_conj @[simp] theorem ofReal_sinh_ofReal_re (x : ℝ) : ((sinh x).re : ℂ) = sinh x := conj_eq_iff_re.1 <| by rw [← sinh_conj, conj_ofReal] #align complex.of_real_sinh_of_real_re Complex.ofReal_sinh_ofReal_re @[simp, norm_cast] theorem ofReal_sinh (x : ℝ) : (Real.sinh x : ℂ) = sinh x := ofReal_sinh_ofReal_re _ #align complex.of_real_sinh Complex.ofReal_sinh @[simp] theorem sinh_ofReal_im (x : ℝ) : (sinh x).im = 0 := by rw [← ofReal_sinh_ofReal_re, ofReal_im] #align complex.sinh_of_real_im Complex.sinh_ofReal_im theorem sinh_ofReal_re (x : ℝ) : (sinh x).re = Real.sinh x := rfl #align complex.sinh_of_real_re Complex.sinh_ofReal_re theorem cosh_conj : cosh (conj x) = conj (cosh x) := by rw [cosh, ← RingHom.map_neg, exp_conj, exp_conj, ← RingHom.map_add, cosh, map_div₀] -- Porting note: not nice simp [← one_add_one_eq_two] #align complex.cosh_conj Complex.cosh_conj theorem ofReal_cosh_ofReal_re (x : ℝ) : ((cosh x).re : ℂ) = cosh x := conj_eq_iff_re.1 <| by rw [← cosh_conj, conj_ofReal] #align complex.of_real_cosh_of_real_re Complex.ofReal_cosh_ofReal_re @[simp, norm_cast] theorem ofReal_cosh (x : ℝ) : (Real.cosh x : ℂ) = cosh x := ofReal_cosh_ofReal_re _ #align complex.of_real_cosh Complex.ofReal_cosh @[simp] theorem cosh_ofReal_im (x : ℝ) : (cosh x).im = 0 := by rw [← ofReal_cosh_ofReal_re, ofReal_im] #align complex.cosh_of_real_im Complex.cosh_ofReal_im @[simp] theorem cosh_ofReal_re (x : ℝ) : (cosh x).re = Real.cosh x := rfl #align complex.cosh_of_real_re Complex.cosh_ofReal_re theorem tanh_eq_sinh_div_cosh : tanh x = sinh x / cosh x := rfl #align complex.tanh_eq_sinh_div_cosh Complex.tanh_eq_sinh_div_cosh @[simp] theorem tanh_zero : tanh 0 = 0 := by simp [tanh] #align complex.tanh_zero Complex.tanh_zero @[simp] theorem tanh_neg : tanh (-x) = -tanh x := by simp [tanh, neg_div] #align complex.tanh_neg Complex.tanh_neg theorem tanh_conj : tanh (conj x) = conj (tanh x) := by rw [tanh, sinh_conj, cosh_conj, ← map_div₀, tanh] #align complex.tanh_conj Complex.tanh_conj @[simp] theorem ofReal_tanh_ofReal_re (x : ℝ) : ((tanh x).re : ℂ) = tanh x := conj_eq_iff_re.1 <| by rw [← tanh_conj, conj_ofReal] #align complex.of_real_tanh_of_real_re Complex.ofReal_tanh_ofReal_re @[simp, norm_cast] theorem ofReal_tanh (x : ℝ) : (Real.tanh x : ℂ) = tanh x := ofReal_tanh_ofReal_re _ #align complex.of_real_tanh Complex.ofReal_tanh @[simp] theorem tanh_ofReal_im (x : ℝ) : (tanh x).im = 0 := by rw [← ofReal_tanh_ofReal_re, ofReal_im] #align complex.tanh_of_real_im Complex.tanh_ofReal_im theorem tanh_ofReal_re (x : ℝ) : (tanh x).re = Real.tanh x := rfl #align complex.tanh_of_real_re Complex.tanh_ofReal_re @[simp] theorem cosh_add_sinh : cosh x + sinh x = exp x := by rw [← mul_right_inj' (two_ne_zero' ℂ), mul_add, two_cosh, two_sinh, add_add_sub_cancel, two_mul] #align complex.cosh_add_sinh Complex.cosh_add_sinh @[simp] theorem sinh_add_cosh : sinh x + cosh x = exp x := by rw [add_comm, cosh_add_sinh] #align complex.sinh_add_cosh Complex.sinh_add_cosh @[simp] theorem exp_sub_cosh : exp x - cosh x = sinh x := sub_eq_iff_eq_add.2 (sinh_add_cosh x).symm #align complex.exp_sub_cosh Complex.exp_sub_cosh @[simp] theorem exp_sub_sinh : exp x - sinh x = cosh x := sub_eq_iff_eq_add.2 (cosh_add_sinh x).symm #align complex.exp_sub_sinh Complex.exp_sub_sinh @[simp] theorem cosh_sub_sinh : cosh x - sinh x = exp (-x) := by rw [← mul_right_inj' (two_ne_zero' ℂ), mul_sub, two_cosh, two_sinh, add_sub_sub_cancel, two_mul] #align complex.cosh_sub_sinh Complex.cosh_sub_sinh @[simp] theorem sinh_sub_cosh : sinh x - cosh x = -exp (-x) := by rw [← neg_sub, cosh_sub_sinh] #align complex.sinh_sub_cosh Complex.sinh_sub_cosh @[simp] theorem cosh_sq_sub_sinh_sq : cosh x ^ 2 - sinh x ^ 2 = 1 := by rw [sq_sub_sq, cosh_add_sinh, cosh_sub_sinh, ← exp_add, add_neg_self, exp_zero] #align complex.cosh_sq_sub_sinh_sq Complex.cosh_sq_sub_sinh_sq theorem cosh_sq : cosh x ^ 2 = sinh x ^ 2 + 1 := by rw [← cosh_sq_sub_sinh_sq x] ring #align complex.cosh_sq Complex.cosh_sq theorem sinh_sq : sinh x ^ 2 = cosh x ^ 2 - 1 := by rw [← cosh_sq_sub_sinh_sq x] ring #align complex.sinh_sq Complex.sinh_sq theorem cosh_two_mul : cosh (2 * x) = cosh x ^ 2 + sinh x ^ 2 := by rw [two_mul, cosh_add, sq, sq] #align complex.cosh_two_mul Complex.cosh_two_mul theorem sinh_two_mul : sinh (2 * x) = 2 * sinh x * cosh x := by rw [two_mul, sinh_add] ring #align complex.sinh_two_mul Complex.sinh_two_mul theorem cosh_three_mul : cosh (3 * x) = 4 * cosh x ^ 3 - 3 * cosh x := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, cosh_add x (2 * x)] simp only [cosh_two_mul, sinh_two_mul] have h2 : sinh x * (2 * sinh x * cosh x) = 2 * cosh x * sinh x ^ 2 := by ring rw [h2, sinh_sq] ring #align complex.cosh_three_mul Complex.cosh_three_mul theorem sinh_three_mul : sinh (3 * x) = 4 * sinh x ^ 3 + 3 * sinh x := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, sinh_add x (2 * x)] simp only [cosh_two_mul, sinh_two_mul] have h2 : cosh x * (2 * sinh x * cosh x) = 2 * sinh x * cosh x ^ 2 := by ring rw [h2, cosh_sq] ring #align complex.sinh_three_mul Complex.sinh_three_mul @[simp] theorem sin_zero : sin 0 = 0 := by simp [sin] #align complex.sin_zero Complex.sin_zero @[simp] theorem sin_neg : sin (-x) = -sin x := by simp [sin, sub_eq_add_neg, exp_neg, (neg_div _ _).symm, add_mul] #align complex.sin_neg Complex.sin_neg theorem two_sin : 2 * sin x = (exp (-x * I) - exp (x * I)) * I := mul_div_cancel₀ _ two_ne_zero #align complex.two_sin Complex.two_sin theorem two_cos : 2 * cos x = exp (x * I) + exp (-x * I) := mul_div_cancel₀ _ two_ne_zero #align complex.two_cos Complex.two_cos theorem sinh_mul_I : sinh (x * I) = sin x * I := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_sinh, ← mul_assoc, two_sin, mul_assoc, I_mul_I, mul_neg_one, neg_sub, neg_mul_eq_neg_mul] set_option linter.uppercaseLean3 false in #align complex.sinh_mul_I Complex.sinh_mul_I theorem cosh_mul_I : cosh (x * I) = cos x := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_cosh, two_cos, neg_mul_eq_neg_mul] set_option linter.uppercaseLean3 false in #align complex.cosh_mul_I Complex.cosh_mul_I theorem tanh_mul_I : tanh (x * I) = tan x * I := by rw [tanh_eq_sinh_div_cosh, cosh_mul_I, sinh_mul_I, mul_div_right_comm, tan] set_option linter.uppercaseLean3 false in #align complex.tanh_mul_I Complex.tanh_mul_I theorem cos_mul_I : cos (x * I) = cosh x := by rw [← cosh_mul_I]; ring_nf; simp set_option linter.uppercaseLean3 false in #align complex.cos_mul_I Complex.cos_mul_I theorem sin_mul_I : sin (x * I) = sinh x * I := by have h : I * sin (x * I) = -sinh x := by rw [mul_comm, ← sinh_mul_I] ring_nf simp rw [← neg_neg (sinh x), ← h] apply Complex.ext <;> simp set_option linter.uppercaseLean3 false in #align complex.sin_mul_I Complex.sin_mul_I theorem tan_mul_I : tan (x * I) = tanh x * I := by rw [tan, sin_mul_I, cos_mul_I, mul_div_right_comm, tanh_eq_sinh_div_cosh] set_option linter.uppercaseLean3 false in #align complex.tan_mul_I Complex.tan_mul_I theorem sin_add : sin (x + y) = sin x * cos y + cos x * sin y := by rw [← mul_left_inj' I_ne_zero, ← sinh_mul_I, add_mul, add_mul, mul_right_comm, ← sinh_mul_I, mul_assoc, ← sinh_mul_I, ← cosh_mul_I, ← cosh_mul_I, sinh_add] #align complex.sin_add Complex.sin_add @[simp] theorem cos_zero : cos 0 = 1 := by simp [cos] #align complex.cos_zero Complex.cos_zero @[simp] theorem cos_neg : cos (-x) = cos x := by simp [cos, sub_eq_add_neg, exp_neg, add_comm] #align complex.cos_neg Complex.cos_neg private theorem cos_add_aux {a b c d : ℂ} : (a + b) * (c + d) - (b - a) * (d - c) * -1 = 2 * (a * c + b * d) := by ring theorem cos_add : cos (x + y) = cos x * cos y - sin x * sin y := by rw [← cosh_mul_I, add_mul, cosh_add, cosh_mul_I, cosh_mul_I, sinh_mul_I, sinh_mul_I, mul_mul_mul_comm, I_mul_I, mul_neg_one, sub_eq_add_neg] #align complex.cos_add Complex.cos_add theorem sin_sub : sin (x - y) = sin x * cos y - cos x * sin y := by simp [sub_eq_add_neg, sin_add, sin_neg, cos_neg] #align complex.sin_sub Complex.sin_sub theorem cos_sub : cos (x - y) = cos x * cos y + sin x * sin y := by simp [sub_eq_add_neg, cos_add, sin_neg, cos_neg] #align complex.cos_sub Complex.cos_sub theorem sin_add_mul_I (x y : ℂ) : sin (x + y * I) = sin x * cosh y + cos x * sinh y * I := by rw [sin_add, cos_mul_I, sin_mul_I, mul_assoc] set_option linter.uppercaseLean3 false in #align complex.sin_add_mul_I Complex.sin_add_mul_I theorem sin_eq (z : ℂ) : sin z = sin z.re * cosh z.im + cos z.re * sinh z.im * I := by convert sin_add_mul_I z.re z.im; exact (re_add_im z).symm #align complex.sin_eq Complex.sin_eq theorem cos_add_mul_I (x y : ℂ) : cos (x + y * I) = cos x * cosh y - sin x * sinh y * I := by rw [cos_add, cos_mul_I, sin_mul_I, mul_assoc] set_option linter.uppercaseLean3 false in #align complex.cos_add_mul_I Complex.cos_add_mul_I theorem cos_eq (z : ℂ) : cos z = cos z.re * cosh z.im - sin z.re * sinh z.im * I := by convert cos_add_mul_I z.re z.im; exact (re_add_im z).symm #align complex.cos_eq Complex.cos_eq theorem sin_sub_sin : sin x - sin y = 2 * sin ((x - y) / 2) * cos ((x + y) / 2) := by have s1 := sin_add ((x + y) / 2) ((x - y) / 2) have s2 := sin_sub ((x + y) / 2) ((x - y) / 2) rw [div_add_div_same, add_sub, add_right_comm, add_sub_cancel_right, half_add_self] at s1 rw [div_sub_div_same, ← sub_add, add_sub_cancel_left, half_add_self] at s2 rw [s1, s2] ring #align complex.sin_sub_sin Complex.sin_sub_sin theorem cos_sub_cos : cos x - cos y = -2 * sin ((x + y) / 2) * sin ((x - y) / 2) := by have s1 := cos_add ((x + y) / 2) ((x - y) / 2) have s2 := cos_sub ((x + y) / 2) ((x - y) / 2) rw [div_add_div_same, add_sub, add_right_comm, add_sub_cancel_right, half_add_self] at s1 rw [div_sub_div_same, ← sub_add, add_sub_cancel_left, half_add_self] at s2 rw [s1, s2] ring #align complex.cos_sub_cos Complex.cos_sub_cos theorem sin_add_sin : sin x + sin y = 2 * sin ((x + y) / 2) * cos ((x - y) / 2) := by simpa using sin_sub_sin x (-y) theorem cos_add_cos : cos x + cos y = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) := by calc cos x + cos y = cos ((x + y) / 2 + (x - y) / 2) + cos ((x + y) / 2 - (x - y) / 2) := ?_ _ = cos ((x + y) / 2) * cos ((x - y) / 2) - sin ((x + y) / 2) * sin ((x - y) / 2) + (cos ((x + y) / 2) * cos ((x - y) / 2) + sin ((x + y) / 2) * sin ((x - y) / 2)) := ?_ _ = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) := ?_ · congr <;> field_simp · rw [cos_add, cos_sub] ring #align complex.cos_add_cos Complex.cos_add_cos theorem sin_conj : sin (conj x) = conj (sin x) := by rw [← mul_left_inj' I_ne_zero, ← sinh_mul_I, ← conj_neg_I, ← RingHom.map_mul, ← RingHom.map_mul, sinh_conj, mul_neg, sinh_neg, sinh_mul_I, mul_neg] #align complex.sin_conj Complex.sin_conj @[simp] theorem ofReal_sin_ofReal_re (x : ℝ) : ((sin x).re : ℂ) = sin x := conj_eq_iff_re.1 <| by rw [← sin_conj, conj_ofReal] #align complex.of_real_sin_of_real_re Complex.ofReal_sin_ofReal_re @[simp, norm_cast] theorem ofReal_sin (x : ℝ) : (Real.sin x : ℂ) = sin x := ofReal_sin_ofReal_re _ #align complex.of_real_sin Complex.ofReal_sin @[simp] theorem sin_ofReal_im (x : ℝ) : (sin x).im = 0 := by rw [← ofReal_sin_ofReal_re, ofReal_im] #align complex.sin_of_real_im Complex.sin_ofReal_im theorem sin_ofReal_re (x : ℝ) : (sin x).re = Real.sin x := rfl #align complex.sin_of_real_re Complex.sin_ofReal_re theorem cos_conj : cos (conj x) = conj (cos x) := by rw [← cosh_mul_I, ← conj_neg_I, ← RingHom.map_mul, ← cosh_mul_I, cosh_conj, mul_neg, cosh_neg] #align complex.cos_conj Complex.cos_conj @[simp] theorem ofReal_cos_ofReal_re (x : ℝ) : ((cos x).re : ℂ) = cos x := conj_eq_iff_re.1 <| by rw [← cos_conj, conj_ofReal] #align complex.of_real_cos_of_real_re Complex.ofReal_cos_ofReal_re @[simp, norm_cast] theorem ofReal_cos (x : ℝ) : (Real.cos x : ℂ) = cos x := ofReal_cos_ofReal_re _ #align complex.of_real_cos Complex.ofReal_cos @[simp] theorem cos_ofReal_im (x : ℝ) : (cos x).im = 0 := by rw [← ofReal_cos_ofReal_re, ofReal_im] #align complex.cos_of_real_im Complex.cos_ofReal_im theorem cos_ofReal_re (x : ℝ) : (cos x).re = Real.cos x := rfl #align complex.cos_of_real_re Complex.cos_ofReal_re @[simp] theorem tan_zero : tan 0 = 0 := by simp [tan] #align complex.tan_zero Complex.tan_zero theorem tan_eq_sin_div_cos : tan x = sin x / cos x := rfl #align complex.tan_eq_sin_div_cos Complex.tan_eq_sin_div_cos theorem tan_mul_cos {x : ℂ} (hx : cos x ≠ 0) : tan x * cos x = sin x := by rw [tan_eq_sin_div_cos, div_mul_cancel₀ _ hx] #align complex.tan_mul_cos Complex.tan_mul_cos @[simp] theorem tan_neg : tan (-x) = -tan x := by simp [tan, neg_div] #align complex.tan_neg Complex.tan_neg theorem tan_conj : tan (conj x) = conj (tan x) := by rw [tan, sin_conj, cos_conj, ← map_div₀, tan] #align complex.tan_conj Complex.tan_conj @[simp] theorem ofReal_tan_ofReal_re (x : ℝ) : ((tan x).re : ℂ) = tan x := conj_eq_iff_re.1 <| by rw [← tan_conj, conj_ofReal] #align complex.of_real_tan_of_real_re Complex.ofReal_tan_ofReal_re @[simp, norm_cast] theorem ofReal_tan (x : ℝ) : (Real.tan x : ℂ) = tan x := ofReal_tan_ofReal_re _ #align complex.of_real_tan Complex.ofReal_tan @[simp] theorem tan_ofReal_im (x : ℝ) : (tan x).im = 0 := by rw [← ofReal_tan_ofReal_re, ofReal_im] #align complex.tan_of_real_im Complex.tan_ofReal_im theorem tan_ofReal_re (x : ℝ) : (tan x).re = Real.tan x := rfl #align complex.tan_of_real_re Complex.tan_ofReal_re theorem cos_add_sin_I : cos x + sin x * I = exp (x * I) := by rw [← cosh_add_sinh, sinh_mul_I, cosh_mul_I] set_option linter.uppercaseLean3 false in #align complex.cos_add_sin_I Complex.cos_add_sin_I theorem cos_sub_sin_I : cos x - sin x * I = exp (-x * I) := by rw [neg_mul, ← cosh_sub_sinh, sinh_mul_I, cosh_mul_I] set_option linter.uppercaseLean3 false in #align complex.cos_sub_sin_I Complex.cos_sub_sin_I @[simp] theorem sin_sq_add_cos_sq : sin x ^ 2 + cos x ^ 2 = 1 := Eq.trans (by rw [cosh_mul_I, sinh_mul_I, mul_pow, I_sq, mul_neg_one, sub_neg_eq_add, add_comm]) (cosh_sq_sub_sinh_sq (x * I)) #align complex.sin_sq_add_cos_sq Complex.sin_sq_add_cos_sq @[simp] theorem cos_sq_add_sin_sq : cos x ^ 2 + sin x ^ 2 = 1 := by rw [add_comm, sin_sq_add_cos_sq] #align complex.cos_sq_add_sin_sq Complex.cos_sq_add_sin_sq theorem cos_two_mul' : cos (2 * x) = cos x ^ 2 - sin x ^ 2 := by rw [two_mul, cos_add, ← sq, ← sq] #align complex.cos_two_mul' Complex.cos_two_mul' theorem cos_two_mul : cos (2 * x) = 2 * cos x ^ 2 - 1 := by rw [cos_two_mul', eq_sub_iff_add_eq.2 (sin_sq_add_cos_sq x), ← sub_add, sub_add_eq_add_sub, two_mul] #align complex.cos_two_mul Complex.cos_two_mul theorem sin_two_mul : sin (2 * x) = 2 * sin x * cos x := by rw [two_mul, sin_add, two_mul, add_mul, mul_comm] #align complex.sin_two_mul Complex.sin_two_mul theorem cos_sq : cos x ^ 2 = 1 / 2 + cos (2 * x) / 2 := by simp [cos_two_mul, div_add_div_same, mul_div_cancel_left₀, two_ne_zero, -one_div] #align complex.cos_sq Complex.cos_sq theorem cos_sq' : cos x ^ 2 = 1 - sin x ^ 2 := by rw [← sin_sq_add_cos_sq x, add_sub_cancel_left] #align complex.cos_sq' Complex.cos_sq' theorem sin_sq : sin x ^ 2 = 1 - cos x ^ 2 := by rw [← sin_sq_add_cos_sq x, add_sub_cancel_right] #align complex.sin_sq Complex.sin_sq theorem inv_one_add_tan_sq {x : ℂ} (hx : cos x ≠ 0) : (1 + tan x ^ 2)⁻¹ = cos x ^ 2 := by rw [tan_eq_sin_div_cos, div_pow] field_simp #align complex.inv_one_add_tan_sq Complex.inv_one_add_tan_sq theorem tan_sq_div_one_add_tan_sq {x : ℂ} (hx : cos x ≠ 0) : tan x ^ 2 / (1 + tan x ^ 2) = sin x ^ 2 := by simp only [← tan_mul_cos hx, mul_pow, ← inv_one_add_tan_sq hx, div_eq_mul_inv, one_mul] #align complex.tan_sq_div_one_add_tan_sq Complex.tan_sq_div_one_add_tan_sq theorem cos_three_mul : cos (3 * x) = 4 * cos x ^ 3 - 3 * cos x := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, cos_add x (2 * x)] simp only [cos_two_mul, sin_two_mul, mul_add, mul_sub, mul_one, sq] have h2 : 4 * cos x ^ 3 = 2 * cos x * cos x * cos x + 2 * cos x * cos x ^ 2 := by ring rw [h2, cos_sq'] ring #align complex.cos_three_mul Complex.cos_three_mul theorem sin_three_mul : sin (3 * x) = 3 * sin x - 4 * sin x ^ 3 := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, sin_add x (2 * x)] simp only [cos_two_mul, sin_two_mul, cos_sq'] have h2 : cos x * (2 * sin x * cos x) = 2 * sin x * cos x ^ 2 := by ring rw [h2, cos_sq'] ring #align complex.sin_three_mul Complex.sin_three_mul theorem exp_mul_I : exp (x * I) = cos x + sin x * I := (cos_add_sin_I _).symm set_option linter.uppercaseLean3 false in #align complex.exp_mul_I Complex.exp_mul_I theorem exp_add_mul_I : exp (x + y * I) = exp x * (cos y + sin y * I) := by rw [exp_add, exp_mul_I] set_option linter.uppercaseLean3 false in #align complex.exp_add_mul_I Complex.exp_add_mul_I theorem exp_eq_exp_re_mul_sin_add_cos : exp x = exp x.re * (cos x.im + sin x.im * I) := by rw [← exp_add_mul_I, re_add_im] #align complex.exp_eq_exp_re_mul_sin_add_cos Complex.exp_eq_exp_re_mul_sin_add_cos theorem exp_re : (exp x).re = Real.exp x.re * Real.cos x.im := by rw [exp_eq_exp_re_mul_sin_add_cos] simp [exp_ofReal_re, cos_ofReal_re] #align complex.exp_re Complex.exp_re theorem exp_im : (exp x).im = Real.exp x.re * Real.sin x.im := by rw [exp_eq_exp_re_mul_sin_add_cos] simp [exp_ofReal_re, sin_ofReal_re] #align complex.exp_im Complex.exp_im @[simp] theorem exp_ofReal_mul_I_re (x : ℝ) : (exp (x * I)).re = Real.cos x := by simp [exp_mul_I, cos_ofReal_re] set_option linter.uppercaseLean3 false in #align complex.exp_of_real_mul_I_re Complex.exp_ofReal_mul_I_re @[simp] theorem exp_ofReal_mul_I_im (x : ℝ) : (exp (x * I)).im = Real.sin x := by simp [exp_mul_I, sin_ofReal_re] set_option linter.uppercaseLean3 false in #align complex.exp_of_real_mul_I_im Complex.exp_ofReal_mul_I_im /-- **De Moivre's formula** -/ theorem cos_add_sin_mul_I_pow (n : ℕ) (z : ℂ) : (cos z + sin z * I) ^ n = cos (↑n * z) + sin (↑n * z) * I := by rw [← exp_mul_I, ← exp_mul_I] induction' n with n ih · rw [pow_zero, Nat.cast_zero, zero_mul, zero_mul, exp_zero] · rw [pow_succ, ih, Nat.cast_succ, add_mul, add_mul, one_mul, exp_add] set_option linter.uppercaseLean3 false in #align complex.cos_add_sin_mul_I_pow Complex.cos_add_sin_mul_I_pow end Complex namespace Real open Complex variable (x y : ℝ) @[simp] theorem exp_zero : exp 0 = 1 := by simp [Real.exp] #align real.exp_zero Real.exp_zero nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp] #align real.exp_add Real.exp_add -- Porting note (#11445): new definition /-- the exponential function as a monoid hom from `Multiplicative ℝ` to `ℝ` -/ noncomputable def expMonoidHom : MonoidHom (Multiplicative ℝ) ℝ := { toFun := fun x => exp (Multiplicative.toAdd x), map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List ℝ) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative ℝ) expMonoidHom l #align real.exp_list_sum Real.exp_list_sum theorem exp_multiset_sum (s : Multiset ℝ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℝ) ℝ _ _ expMonoidHom s #align real.exp_multiset_sum Real.exp_multiset_sum theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℝ) : exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (β := Multiplicative ℝ) expMonoidHom f s #align real.exp_sum Real.exp_sum lemma exp_nsmul (x : ℝ) (n : ℕ) : exp (n • x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative ℝ) ℝ _ _ expMonoidHom _ _ nonrec theorem exp_nat_mul (x : ℝ) (n : ℕ) : exp (n * x) = exp x ^ n := ofReal_injective (by simp [exp_nat_mul]) #align real.exp_nat_mul Real.exp_nat_mul nonrec theorem exp_ne_zero : exp x ≠ 0 := fun h => exp_ne_zero x <| by rw [exp, ← ofReal_inj] at h; simp_all #align real.exp_ne_zero Real.exp_ne_zero nonrec theorem exp_neg : exp (-x) = (exp x)⁻¹ := ofReal_injective <| by simp [exp_neg] #align real.exp_neg Real.exp_neg theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] #align real.exp_sub Real.exp_sub @[simp] theorem sin_zero : sin 0 = 0 := by simp [sin] #align real.sin_zero Real.sin_zero @[simp] theorem sin_neg : sin (-x) = -sin x := by simp [sin, exp_neg, (neg_div _ _).symm, add_mul] #align real.sin_neg Real.sin_neg nonrec theorem sin_add : sin (x + y) = sin x * cos y + cos x * sin y := ofReal_injective <| by simp [sin_add] #align real.sin_add Real.sin_add @[simp] theorem cos_zero : cos 0 = 1 := by simp [cos] #align real.cos_zero Real.cos_zero @[simp] theorem cos_neg : cos (-x) = cos x := by simp [cos, exp_neg] #align real.cos_neg Real.cos_neg @[simp] theorem cos_abs : cos |x| = cos x := by cases le_total x 0 <;> simp only [*, _root_.abs_of_nonneg, abs_of_nonpos, cos_neg] #align real.cos_abs Real.cos_abs nonrec theorem cos_add : cos (x + y) = cos x * cos y - sin x * sin y := ofReal_injective <| by simp [cos_add] #align real.cos_add Real.cos_add theorem sin_sub : sin (x - y) = sin x * cos y - cos x * sin y := by simp [sub_eq_add_neg, sin_add, sin_neg, cos_neg] #align real.sin_sub Real.sin_sub theorem cos_sub : cos (x - y) = cos x * cos y + sin x * sin y := by simp [sub_eq_add_neg, cos_add, sin_neg, cos_neg] #align real.cos_sub Real.cos_sub nonrec theorem sin_sub_sin : sin x - sin y = 2 * sin ((x - y) / 2) * cos ((x + y) / 2) := ofReal_injective <| by simp [sin_sub_sin] #align real.sin_sub_sin Real.sin_sub_sin nonrec theorem cos_sub_cos : cos x - cos y = -2 * sin ((x + y) / 2) * sin ((x - y) / 2) := ofReal_injective <| by simp [cos_sub_cos] #align real.cos_sub_cos Real.cos_sub_cos nonrec theorem cos_add_cos : cos x + cos y = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) := ofReal_injective <| by simp [cos_add_cos] #align real.cos_add_cos Real.cos_add_cos nonrec theorem tan_eq_sin_div_cos : tan x = sin x / cos x := ofReal_injective <| by simp [tan_eq_sin_div_cos] #align real.tan_eq_sin_div_cos Real.tan_eq_sin_div_cos theorem tan_mul_cos {x : ℝ} (hx : cos x ≠ 0) : tan x * cos x = sin x := by rw [tan_eq_sin_div_cos, div_mul_cancel₀ _ hx] #align real.tan_mul_cos Real.tan_mul_cos @[simp] theorem tan_zero : tan 0 = 0 := by simp [tan] #align real.tan_zero Real.tan_zero @[simp] theorem tan_neg : tan (-x) = -tan x := by simp [tan, neg_div] #align real.tan_neg Real.tan_neg @[simp] nonrec theorem sin_sq_add_cos_sq : sin x ^ 2 + cos x ^ 2 = 1 := ofReal_injective (by simp [sin_sq_add_cos_sq]) #align real.sin_sq_add_cos_sq Real.sin_sq_add_cos_sq @[simp] theorem cos_sq_add_sin_sq : cos x ^ 2 + sin x ^ 2 = 1 := by rw [add_comm, sin_sq_add_cos_sq] #align real.cos_sq_add_sin_sq Real.cos_sq_add_sin_sq theorem sin_sq_le_one : sin x ^ 2 ≤ 1 := by rw [← sin_sq_add_cos_sq x]; exact le_add_of_nonneg_right (sq_nonneg _) #align real.sin_sq_le_one Real.sin_sq_le_one theorem cos_sq_le_one : cos x ^ 2 ≤ 1 := by rw [← sin_sq_add_cos_sq x]; exact le_add_of_nonneg_left (sq_nonneg _) #align real.cos_sq_le_one Real.cos_sq_le_one theorem abs_sin_le_one : |sin x| ≤ 1 := abs_le_one_iff_mul_self_le_one.2 <| by simp only [← sq, sin_sq_le_one] #align real.abs_sin_le_one Real.abs_sin_le_one theorem abs_cos_le_one : |cos x| ≤ 1 := abs_le_one_iff_mul_self_le_one.2 <| by simp only [← sq, cos_sq_le_one] #align real.abs_cos_le_one Real.abs_cos_le_one theorem sin_le_one : sin x ≤ 1 := (abs_le.1 (abs_sin_le_one _)).2 #align real.sin_le_one Real.sin_le_one theorem cos_le_one : cos x ≤ 1 := (abs_le.1 (abs_cos_le_one _)).2 #align real.cos_le_one Real.cos_le_one theorem neg_one_le_sin : -1 ≤ sin x := (abs_le.1 (abs_sin_le_one _)).1 #align real.neg_one_le_sin Real.neg_one_le_sin theorem neg_one_le_cos : -1 ≤ cos x := (abs_le.1 (abs_cos_le_one _)).1 #align real.neg_one_le_cos Real.neg_one_le_cos nonrec theorem cos_two_mul : cos (2 * x) = 2 * cos x ^ 2 - 1 := ofReal_injective <| by simp [cos_two_mul] #align real.cos_two_mul Real.cos_two_mul nonrec theorem cos_two_mul' : cos (2 * x) = cos x ^ 2 - sin x ^ 2 := ofReal_injective <| by simp [cos_two_mul'] #align real.cos_two_mul' Real.cos_two_mul' nonrec theorem sin_two_mul : sin (2 * x) = 2 * sin x * cos x := ofReal_injective <| by simp [sin_two_mul] #align real.sin_two_mul Real.sin_two_mul nonrec theorem cos_sq : cos x ^ 2 = 1 / 2 + cos (2 * x) / 2 := ofReal_injective <| by simp [cos_sq] #align real.cos_sq Real.cos_sq theorem cos_sq' : cos x ^ 2 = 1 - sin x ^ 2 := by rw [← sin_sq_add_cos_sq x, add_sub_cancel_left] #align real.cos_sq' Real.cos_sq' theorem sin_sq : sin x ^ 2 = 1 - cos x ^ 2 := eq_sub_iff_add_eq.2 <| sin_sq_add_cos_sq _ #align real.sin_sq Real.sin_sq lemma sin_sq_eq_half_sub : sin x ^ 2 = 1 / 2 - cos (2 * x) / 2 := by rw [sin_sq, cos_sq, ← sub_sub, sub_half] theorem abs_sin_eq_sqrt_one_sub_cos_sq (x : ℝ) : |sin x| = √(1 - cos x ^ 2) := by rw [← sin_sq, sqrt_sq_eq_abs] #align real.abs_sin_eq_sqrt_one_sub_cos_sq Real.abs_sin_eq_sqrt_one_sub_cos_sq theorem abs_cos_eq_sqrt_one_sub_sin_sq (x : ℝ) : |cos x| = √(1 - sin x ^ 2) := by rw [← cos_sq', sqrt_sq_eq_abs] #align real.abs_cos_eq_sqrt_one_sub_sin_sq Real.abs_cos_eq_sqrt_one_sub_sin_sq theorem inv_one_add_tan_sq {x : ℝ} (hx : cos x ≠ 0) : (1 + tan x ^ 2)⁻¹ = cos x ^ 2 := have : Complex.cos x ≠ 0 := mt (congr_arg re) hx ofReal_inj.1 <| by simpa using Complex.inv_one_add_tan_sq this #align real.inv_one_add_tan_sq Real.inv_one_add_tan_sq theorem tan_sq_div_one_add_tan_sq {x : ℝ} (hx : cos x ≠ 0) : tan x ^ 2 / (1 + tan x ^ 2) = sin x ^ 2 := by simp only [← tan_mul_cos hx, mul_pow, ← inv_one_add_tan_sq hx, div_eq_mul_inv, one_mul] #align real.tan_sq_div_one_add_tan_sq Real.tan_sq_div_one_add_tan_sq theorem inv_sqrt_one_add_tan_sq {x : ℝ} (hx : 0 < cos x) : (√(1 + tan x ^ 2))⁻¹ = cos x := by rw [← sqrt_sq hx.le, ← sqrt_inv, inv_one_add_tan_sq hx.ne'] #align real.inv_sqrt_one_add_tan_sq Real.inv_sqrt_one_add_tan_sq theorem tan_div_sqrt_one_add_tan_sq {x : ℝ} (hx : 0 < cos x) : tan x / √(1 + tan x ^ 2) = sin x := by rw [← tan_mul_cos hx.ne', ← inv_sqrt_one_add_tan_sq hx, div_eq_mul_inv] #align real.tan_div_sqrt_one_add_tan_sq Real.tan_div_sqrt_one_add_tan_sq nonrec theorem cos_three_mul : cos (3 * x) = 4 * cos x ^ 3 - 3 * cos x := by rw [← ofReal_inj]; simp [cos_three_mul] #align real.cos_three_mul Real.cos_three_mul nonrec theorem sin_three_mul : sin (3 * x) = 3 * sin x - 4 * sin x ^ 3 := by rw [← ofReal_inj]; simp [sin_three_mul] #align real.sin_three_mul Real.sin_three_mul /-- The definition of `sinh` in terms of `exp`. -/ nonrec theorem sinh_eq (x : ℝ) : sinh x = (exp x - exp (-x)) / 2 := ofReal_injective <| by simp [Complex.sinh] #align real.sinh_eq Real.sinh_eq @[simp] theorem sinh_zero : sinh 0 = 0 := by simp [sinh] #align real.sinh_zero Real.sinh_zero @[simp] theorem sinh_neg : sinh (-x) = -sinh x := by simp [sinh, exp_neg, (neg_div _ _).symm, add_mul] #align real.sinh_neg Real.sinh_neg nonrec theorem sinh_add : sinh (x + y) = sinh x * cosh y + cosh x * sinh y := by rw [← ofReal_inj]; simp [sinh_add] #align real.sinh_add Real.sinh_add /-- The definition of `cosh` in terms of `exp`. -/ theorem cosh_eq (x : ℝ) : cosh x = (exp x + exp (-x)) / 2 := eq_div_of_mul_eq two_ne_zero <| by rw [cosh, exp, exp, Complex.ofReal_neg, Complex.cosh, mul_two, ← Complex.add_re, ← mul_two, div_mul_cancel₀ _ (two_ne_zero' ℂ), Complex.add_re] #align real.cosh_eq Real.cosh_eq @[simp] theorem cosh_zero : cosh 0 = 1 := by simp [cosh] #align real.cosh_zero Real.cosh_zero @[simp] theorem cosh_neg : cosh (-x) = cosh x := ofReal_inj.1 <| by simp #align real.cosh_neg Real.cosh_neg @[simp] theorem cosh_abs : cosh |x| = cosh x := by cases le_total x 0 <;> simp [*, _root_.abs_of_nonneg, abs_of_nonpos] #align real.cosh_abs Real.cosh_abs nonrec theorem cosh_add : cosh (x + y) = cosh x * cosh y + sinh x * sinh y := by rw [← ofReal_inj]; simp [cosh_add] #align real.cosh_add Real.cosh_add theorem sinh_sub : sinh (x - y) = sinh x * cosh y - cosh x * sinh y := by simp [sub_eq_add_neg, sinh_add, sinh_neg, cosh_neg] #align real.sinh_sub Real.sinh_sub theorem cosh_sub : cosh (x - y) = cosh x * cosh y - sinh x * sinh y := by simp [sub_eq_add_neg, cosh_add, sinh_neg, cosh_neg] #align real.cosh_sub Real.cosh_sub nonrec theorem tanh_eq_sinh_div_cosh : tanh x = sinh x / cosh x := ofReal_inj.1 <| by simp [tanh_eq_sinh_div_cosh] #align real.tanh_eq_sinh_div_cosh Real.tanh_eq_sinh_div_cosh @[simp] theorem tanh_zero : tanh 0 = 0 := by simp [tanh] #align real.tanh_zero Real.tanh_zero @[simp] theorem tanh_neg : tanh (-x) = -tanh x := by simp [tanh, neg_div] #align real.tanh_neg Real.tanh_neg @[simp] theorem cosh_add_sinh : cosh x + sinh x = exp x := by rw [← ofReal_inj]; simp #align real.cosh_add_sinh Real.cosh_add_sinh @[simp] theorem sinh_add_cosh : sinh x + cosh x = exp x := by rw [add_comm, cosh_add_sinh] #align real.sinh_add_cosh Real.sinh_add_cosh @[simp] theorem exp_sub_cosh : exp x - cosh x = sinh x := sub_eq_iff_eq_add.2 (sinh_add_cosh x).symm #align real.exp_sub_cosh Real.exp_sub_cosh @[simp] theorem exp_sub_sinh : exp x - sinh x = cosh x := sub_eq_iff_eq_add.2 (cosh_add_sinh x).symm #align real.exp_sub_sinh Real.exp_sub_sinh @[simp] theorem cosh_sub_sinh : cosh x - sinh x = exp (-x) := by rw [← ofReal_inj] simp #align real.cosh_sub_sinh Real.cosh_sub_sinh @[simp] theorem sinh_sub_cosh : sinh x - cosh x = -exp (-x) := by rw [← neg_sub, cosh_sub_sinh] #align real.sinh_sub_cosh Real.sinh_sub_cosh @[simp] theorem cosh_sq_sub_sinh_sq (x : ℝ) : cosh x ^ 2 - sinh x ^ 2 = 1 := by rw [← ofReal_inj]; simp #align real.cosh_sq_sub_sinh_sq Real.cosh_sq_sub_sinh_sq nonrec theorem cosh_sq : cosh x ^ 2 = sinh x ^ 2 + 1 := by rw [← ofReal_inj]; simp [cosh_sq] #align real.cosh_sq Real.cosh_sq theorem cosh_sq' : cosh x ^ 2 = 1 + sinh x ^ 2 := (cosh_sq x).trans (add_comm _ _) #align real.cosh_sq' Real.cosh_sq' nonrec theorem sinh_sq : sinh x ^ 2 = cosh x ^ 2 - 1 := by rw [← ofReal_inj]; simp [sinh_sq] #align real.sinh_sq Real.sinh_sq nonrec theorem cosh_two_mul : cosh (2 * x) = cosh x ^ 2 + sinh x ^ 2 := by rw [← ofReal_inj]; simp [cosh_two_mul] #align real.cosh_two_mul Real.cosh_two_mul nonrec theorem sinh_two_mul : sinh (2 * x) = 2 * sinh x * cosh x := by rw [← ofReal_inj]; simp [sinh_two_mul] #align real.sinh_two_mul Real.sinh_two_mul nonrec theorem cosh_three_mul : cosh (3 * x) = 4 * cosh x ^ 3 - 3 * cosh x := by rw [← ofReal_inj]; simp [cosh_three_mul] #align real.cosh_three_mul Real.cosh_three_mul nonrec theorem sinh_three_mul : sinh (3 * x) = 4 * sinh x ^ 3 + 3 * sinh x := by rw [← ofReal_inj]; simp [sinh_three_mul] #align real.sinh_three_mul Real.sinh_three_mul open IsAbsoluteValue Nat theorem sum_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) (n : ℕ) : ∑ i ∈ range n, x ^ i / i ! ≤ exp x := calc ∑ i ∈ range n, x ^ i / i ! ≤ lim (⟨_, isCauSeq_re (exp' x)⟩ : CauSeq ℝ abs) := by refine le_lim (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp only [exp', const_apply, re_sum] norm_cast refine sum_le_sum_of_subset_of_nonneg (range_mono hj) fun _ _ _ ↦ ?_ positivity _ = exp x := by rw [exp, Complex.exp, ← cauSeqRe, lim_re] #align real.sum_le_exp_of_nonneg Real.sum_le_exp_of_nonneg lemma pow_div_factorial_le_exp (hx : 0 ≤ x) (n : ℕ) : x ^ n / n ! ≤ exp x := calc x ^ n / n ! ≤ ∑ k ∈ range (n + 1), x ^ k / k ! := single_le_sum (f := fun k ↦ x ^ k / k !) (fun k _ ↦ by positivity) (self_mem_range_succ n) _ ≤ exp x := sum_le_exp_of_nonneg hx _ theorem quadratic_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : 1 + x + x ^ 2 / 2 ≤ exp x := calc 1 + x + x ^ 2 / 2 = ∑ i ∈ range 3, x ^ i / i ! := by simp only [sum_range_succ, range_one, sum_singleton, _root_.pow_zero, factorial, cast_one, ne_eq, one_ne_zero, not_false_eq_true, div_self, pow_one, mul_one, div_one, Nat.mul_one, cast_succ, add_right_inj] ring_nf _ ≤ exp x := sum_le_exp_of_nonneg hx 3 #align real.quadratic_le_exp_of_nonneg Real.quadratic_le_exp_of_nonneg private theorem add_one_lt_exp_of_pos {x : ℝ} (hx : 0 < x) : x + 1 < exp x := (by nlinarith : x + 1 < 1 + x + x ^ 2 / 2).trans_le (quadratic_le_exp_of_nonneg hx.le) private theorem add_one_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : x + 1 ≤ exp x := by rcases eq_or_lt_of_le hx with (rfl | h) · simp exact (add_one_lt_exp_of_pos h).le theorem one_le_exp {x : ℝ} (hx : 0 ≤ x) : 1 ≤ exp x := by linarith [add_one_le_exp_of_nonneg hx] #align real.one_le_exp Real.one_le_exp theorem exp_pos (x : ℝ) : 0 < exp x := (le_total 0 x).elim (lt_of_lt_of_le zero_lt_one ∘ one_le_exp) fun h => by rw [← neg_neg x, Real.exp_neg] exact inv_pos.2 (lt_of_lt_of_le zero_lt_one (one_le_exp (neg_nonneg.2 h))) #align real.exp_pos Real.exp_pos lemma exp_nonneg (x : ℝ) : 0 ≤ exp x := x.exp_pos.le @[simp] theorem abs_exp (x : ℝ) : |exp x| = exp x := abs_of_pos (exp_pos _) #align real.abs_exp Real.abs_exp lemma exp_abs_le (x : ℝ) : exp |x| ≤ exp x + exp (-x) := by cases le_total x 0 <;> simp [abs_of_nonpos, _root_.abs_of_nonneg, exp_nonneg, *] @[mono] theorem exp_strictMono : StrictMono exp := fun x y h => by rw [← sub_add_cancel y x, Real.exp_add] exact (lt_mul_iff_one_lt_left (exp_pos _)).2 (lt_of_lt_of_le (by linarith) (add_one_le_exp_of_nonneg (by linarith))) #align real.exp_strict_mono Real.exp_strictMono @[gcongr] theorem exp_lt_exp_of_lt {x y : ℝ} (h : x < y) : exp x < exp y := exp_strictMono h @[mono] theorem exp_monotone : Monotone exp := exp_strictMono.monotone #align real.exp_monotone Real.exp_monotone @[gcongr] theorem exp_le_exp_of_le {x y : ℝ} (h : x ≤ y) : exp x ≤ exp y := exp_monotone h @[simp] theorem exp_lt_exp {x y : ℝ} : exp x < exp y ↔ x < y := exp_strictMono.lt_iff_lt #align real.exp_lt_exp Real.exp_lt_exp @[simp] theorem exp_le_exp {x y : ℝ} : exp x ≤ exp y ↔ x ≤ y := exp_strictMono.le_iff_le #align real.exp_le_exp Real.exp_le_exp theorem exp_injective : Function.Injective exp := exp_strictMono.injective #align real.exp_injective Real.exp_injective @[simp] theorem exp_eq_exp {x y : ℝ} : exp x = exp y ↔ x = y := exp_injective.eq_iff #align real.exp_eq_exp Real.exp_eq_exp @[simp] theorem exp_eq_one_iff : exp x = 1 ↔ x = 0 := exp_injective.eq_iff' exp_zero #align real.exp_eq_one_iff Real.exp_eq_one_iff @[simp] theorem one_lt_exp_iff {x : ℝ} : 1 < exp x ↔ 0 < x := by rw [← exp_zero, exp_lt_exp] #align real.one_lt_exp_iff Real.one_lt_exp_iff @[simp] theorem exp_lt_one_iff {x : ℝ} : exp x < 1 ↔ x < 0 := by rw [← exp_zero, exp_lt_exp] #align real.exp_lt_one_iff Real.exp_lt_one_iff @[simp] theorem exp_le_one_iff {x : ℝ} : exp x ≤ 1 ↔ x ≤ 0 := exp_zero ▸ exp_le_exp #align real.exp_le_one_iff Real.exp_le_one_iff @[simp] theorem one_le_exp_iff {x : ℝ} : 1 ≤ exp x ↔ 0 ≤ x := exp_zero ▸ exp_le_exp #align real.one_le_exp_iff Real.one_le_exp_iff /-- `Real.cosh` is always positive -/ theorem cosh_pos (x : ℝ) : 0 < Real.cosh x := (cosh_eq x).symm ▸ half_pos (add_pos (exp_pos x) (exp_pos (-x))) #align real.cosh_pos Real.cosh_pos theorem sinh_lt_cosh : sinh x < cosh x := lt_of_pow_lt_pow_left 2 (cosh_pos _).le <| (cosh_sq x).symm ▸ lt_add_one _ #align real.sinh_lt_cosh Real.sinh_lt_cosh end Real namespace Complex theorem sum_div_factorial_le {α : Type*} [LinearOrderedField α] (n j : ℕ) (hn : 0 < n) : (∑ m ∈ filter (fun k => n ≤ k) (range j), (1 / m.factorial : α)) ≤ n.succ / (n.factorial * n) := calc (∑ m ∈ filter (fun k => n ≤ k) (range j), (1 / m.factorial : α)) = ∑ m ∈ range (j - n), (1 / ((m + n).factorial : α)) := by refine sum_nbij' (· - n) (· + n) ?_ ?_ ?_ ?_ ?_ <;> simp (config := { contextual := true }) [lt_tsub_iff_right, tsub_add_cancel_of_le] _ ≤ ∑ m ∈ range (j - n), ((n.factorial : α) * (n.succ : α) ^ m)⁻¹ := by simp_rw [one_div] gcongr rw [← Nat.cast_pow, ← Nat.cast_mul, Nat.cast_le, add_comm] exact Nat.factorial_mul_pow_le_factorial _ = (n.factorial : α)⁻¹ * ∑ m ∈ range (j - n), (n.succ : α)⁻¹ ^ m := by simp [mul_inv, ← mul_sum, ← sum_mul, mul_comm, inv_pow] _ = ((n.succ : α) - n.succ * (n.succ : α)⁻¹ ^ (j - n)) / (n.factorial * n) := by have h₁ : (n.succ : α) ≠ 1 := @Nat.cast_one α _ ▸ mt Nat.cast_inj.1 (mt Nat.succ.inj (pos_iff_ne_zero.1 hn)) have h₂ : (n.succ : α) ≠ 0 := by positivity have h₃ : (n.factorial * n : α) ≠ 0 := by positivity have h₄ : (n.succ - 1 : α) = n := by simp rw [geom_sum_inv h₁ h₂, eq_div_iff_mul_eq h₃, mul_comm _ (n.factorial * n : α), ← mul_assoc (n.factorial⁻¹ : α), ← mul_inv_rev, h₄, ← mul_assoc (n.factorial * n : α), mul_comm (n : α) n.factorial, mul_inv_cancel h₃, one_mul, mul_comm] _ ≤ n.succ / (n.factorial * n : α) := by gcongr; apply sub_le_self; positivity #align complex.sum_div_factorial_le Complex.sum_div_factorial_le theorem exp_bound {x : ℂ} (hx : abs x ≤ 1) {n : ℕ} (hn : 0 < n) : abs (exp x - ∑ m ∈ range n, x ^ m / m.factorial) ≤ abs x ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) := by rw [← lim_const (abv := Complex.abs) (∑ m ∈ range n, _), exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_abs] refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show abs ((∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial) ≤ abs x ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) rw [sum_range_sub_sum_range hj] calc abs (∑ m ∈ (range j).filter fun k => n ≤ k, (x ^ m / m.factorial : ℂ)) = abs (∑ m ∈ (range j).filter fun k => n ≤ k, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)) := by refine congr_arg abs (sum_congr rfl fun m hm => ?_) rw [mem_filter, mem_range] at hm rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2] _ ≤ ∑ m ∈ filter (fun k => n ≤ k) (range j), abs (x ^ n * (x ^ (m - n) / m.factorial)) := (IsAbsoluteValue.abv_sum Complex.abs _ _) _ ≤ ∑ m ∈ filter (fun k => n ≤ k) (range j), abs x ^ n * (1 / m.factorial) := by simp_rw [map_mul, map_pow, map_div₀, abs_natCast] gcongr rw [abv_pow abs] exact pow_le_one _ (abs.nonneg _) hx _ = abs x ^ n * ∑ m ∈ (range j).filter fun k => n ≤ k, (1 / m.factorial : ℝ) := by simp [abs_mul, abv_pow abs, abs_div, ← mul_sum] _ ≤ abs x ^ n * (n.succ * (n.factorial * n : ℝ)⁻¹) := by gcongr exact sum_div_factorial_le _ _ hn #align complex.exp_bound Complex.exp_bound theorem exp_bound' {x : ℂ} {n : ℕ} (hx : abs x / n.succ ≤ 1 / 2) : abs (exp x - ∑ m ∈ range n, x ^ m / m.factorial) ≤ abs x ^ n / n.factorial * 2 := by rw [← lim_const (abv := Complex.abs) (∑ m ∈ range n, _), exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_abs] refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show abs ((∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial) ≤ abs x ^ n / n.factorial * 2 let k := j - n have hj : j = n + k := (add_tsub_cancel_of_le hj).symm rw [hj, sum_range_add_sub_sum_range] calc abs (∑ i ∈ range k, x ^ (n + i) / ((n + i).factorial : ℂ)) ≤ ∑ i ∈ range k, abs (x ^ (n + i) / ((n + i).factorial : ℂ)) := IsAbsoluteValue.abv_sum _ _ _ _ ≤ ∑ i ∈ range k, abs x ^ (n + i) / (n + i).factorial := by simp [Complex.abs_natCast, map_div₀, abv_pow abs] _ ≤ ∑ i ∈ range k, abs x ^ (n + i) / ((n.factorial : ℝ) * (n.succ : ℝ) ^ i) := ?_ _ = ∑ i ∈ range k, abs x ^ n / n.factorial * (abs x ^ i / (n.succ : ℝ) ^ i) := ?_ _ ≤ abs x ^ n / ↑n.factorial * 2 := ?_ · gcongr exact mod_cast Nat.factorial_mul_pow_le_factorial · refine Finset.sum_congr rfl fun _ _ => ?_ simp only [pow_add, div_eq_inv_mul, mul_inv, mul_left_comm, mul_assoc] · rw [← mul_sum] gcongr simp_rw [← div_pow] rw [geom_sum_eq, div_le_iff_of_neg] · trans (-1 : ℝ) · linarith · simp only [neg_le_sub_iff_le_add, div_pow, Nat.cast_succ, le_add_iff_nonneg_left] positivity · linarith · linarith #align complex.exp_bound' Complex.exp_bound' theorem abs_exp_sub_one_le {x : ℂ} (hx : abs x ≤ 1) : abs (exp x - 1) ≤ 2 * abs x := calc abs (exp x - 1) = abs (exp x - ∑ m ∈ range 1, x ^ m / m.factorial) := by simp [sum_range_succ] _ ≤ abs x ^ 1 * ((Nat.succ 1 : ℝ) * ((Nat.factorial 1) * (1 : ℕ) : ℝ)⁻¹) := (exp_bound hx (by decide)) _ = 2 * abs x := by simp [two_mul, mul_two, mul_add, mul_comm, add_mul, Nat.factorial] #align complex.abs_exp_sub_one_le Complex.abs_exp_sub_one_le theorem abs_exp_sub_one_sub_id_le {x : ℂ} (hx : abs x ≤ 1) : abs (exp x - 1 - x) ≤ abs x ^ 2 := calc abs (exp x - 1 - x) = abs (exp x - ∑ m ∈ range 2, x ^ m / m.factorial) := by simp [sub_eq_add_neg, sum_range_succ_comm, add_assoc, Nat.factorial] _ ≤ abs x ^ 2 * ((Nat.succ 2 : ℝ) * (Nat.factorial 2 * (2 : ℕ) : ℝ)⁻¹) := (exp_bound hx (by decide)) _ ≤ abs x ^ 2 * 1 := by gcongr; norm_num [Nat.factorial] _ = abs x ^ 2 := by rw [mul_one] #align complex.abs_exp_sub_one_sub_id_le Complex.abs_exp_sub_one_sub_id_le end Complex namespace Real open Complex Finset nonrec theorem exp_bound {x : ℝ} (hx : |x| ≤ 1) {n : ℕ} (hn : 0 < n) : |exp x - ∑ m ∈ range n, x ^ m / m.factorial| ≤ |x| ^ n * (n.succ / (n.factorial * n)) := by have hxc : Complex.abs x ≤ 1 := mod_cast hx convert exp_bound hxc hn using 2 <;> -- Porting note: was `norm_cast` simp only [← abs_ofReal, ← ofReal_sub, ← ofReal_exp, ← ofReal_sum, ← ofReal_pow, ← ofReal_div, ← ofReal_natCast] #align real.exp_bound Real.exp_bound theorem exp_bound' {x : ℝ} (h1 : 0 ≤ x) (h2 : x ≤ 1) {n : ℕ} (hn : 0 < n) : Real.exp x ≤ (∑ m ∈ Finset.range n, x ^ m / m.factorial) + x ^ n * (n + 1) / (n.factorial * n) := by have h3 : |x| = x := by simpa have h4 : |x| ≤ 1 := by rwa [h3] have h' := Real.exp_bound h4 hn rw [h3] at h' have h'' := (abs_sub_le_iff.1 h').1 have t := sub_le_iff_le_add'.1 h'' simpa [mul_div_assoc] using t #align real.exp_bound' Real.exp_bound' theorem abs_exp_sub_one_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1| ≤ 2 * |x| := by have : |x| ≤ 1 := mod_cast hx -- Porting note: was --exact_mod_cast Complex.abs_exp_sub_one_le (x := x) this have := Complex.abs_exp_sub_one_le (x := x) (by simpa using this) rw [← ofReal_exp, ← ofReal_one, ← ofReal_sub, abs_ofReal, abs_ofReal] at this exact this #align real.abs_exp_sub_one_le Real.abs_exp_sub_one_le theorem abs_exp_sub_one_sub_id_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1 - x| ≤ x ^ 2 := by rw [← _root_.sq_abs] -- Porting note: was -- exact_mod_cast Complex.abs_exp_sub_one_sub_id_le this have : Complex.abs x ≤ 1 := mod_cast hx have := Complex.abs_exp_sub_one_sub_id_le this rw [← ofReal_one, ← ofReal_exp, ← ofReal_sub, ← ofReal_sub, abs_ofReal, abs_ofReal] at this exact this #align real.abs_exp_sub_one_sub_id_le Real.abs_exp_sub_one_sub_id_le /-- A finite initial segment of the exponential series, followed by an arbitrary tail. For fixed `n` this is just a linear map wrt `r`, and each map is a simple linear function of the previous (see `expNear_succ`), with `expNear n x r ⟶ exp x` as `n ⟶ ∞`, for any `r`. -/ noncomputable def expNear (n : ℕ) (x r : ℝ) : ℝ := (∑ m ∈ range n, x ^ m / m.factorial) + x ^ n / n.factorial * r #align real.exp_near Real.expNear @[simp] theorem expNear_zero (x r) : expNear 0 x r = r := by simp [expNear] #align real.exp_near_zero Real.expNear_zero @[simp] theorem expNear_succ (n x r) : expNear (n + 1) x r = expNear n x (1 + x / (n + 1) * r) := by simp [expNear, range_succ, mul_add, add_left_comm, add_assoc, pow_succ, div_eq_mul_inv, mul_inv, Nat.factorial] ac_rfl #align real.exp_near_succ Real.expNear_succ theorem expNear_sub (n x r₁ r₂) : expNear n x r₁ - expNear n x r₂ = x ^ n / n.factorial * (r₁ - r₂) := by simp [expNear, mul_sub] #align real.exp_near_sub Real.expNear_sub theorem exp_approx_end (n m : ℕ) (x : ℝ) (e₁ : n + 1 = m) (h : |x| ≤ 1) : |exp x - expNear m x 0| ≤ |x| ^ m / m.factorial * ((m + 1) / m) := by simp only [expNear, mul_zero, add_zero] convert exp_bound (n := m) h ?_ using 1 · field_simp [mul_comm] · omega #align real.exp_approx_end Real.exp_approx_end theorem exp_approx_succ {n} {x a₁ b₁ : ℝ} (m : ℕ) (e₁ : n + 1 = m) (a₂ b₂ : ℝ) (e : |1 + x / m * a₂ - a₁| ≤ b₁ - |x| / m * b₂) (h : |exp x - expNear m x a₂| ≤ |x| ^ m / m.factorial * b₂) : |exp x - expNear n x a₁| ≤ |x| ^ n / n.factorial * b₁ := by refine (abs_sub_le _ _ _).trans ((add_le_add_right h _).trans ?_) subst e₁; rw [expNear_succ, expNear_sub, abs_mul] convert mul_le_mul_of_nonneg_left (a := |x| ^ n / ↑(Nat.factorial n)) (le_sub_iff_add_le'.1 e) ?_ using 1 · simp [mul_add, pow_succ', div_eq_mul_inv, abs_mul, abs_inv, ← pow_abs, mul_inv, Nat.factorial] ac_rfl · simp [div_nonneg, abs_nonneg] #align real.exp_approx_succ Real.exp_approx_succ theorem exp_approx_end' {n} {x a b : ℝ} (m : ℕ) (e₁ : n + 1 = m) (rm : ℝ) (er : ↑m = rm) (h : |x| ≤ 1) (e : |1 - a| ≤ b - |x| / rm * ((rm + 1) / rm)) : |exp x - expNear n x a| ≤ |x| ^ n / n.factorial * b := by subst er exact exp_approx_succ _ e₁ _ _ (by simpa using e) (exp_approx_end _ _ _ e₁ h) #align real.exp_approx_end' Real.exp_approx_end' theorem exp_1_approx_succ_eq {n} {a₁ b₁ : ℝ} {m : ℕ} (en : n + 1 = m) {rm : ℝ} (er : ↑m = rm) (h : |exp 1 - expNear m 1 ((a₁ - 1) * rm)| ≤ |1| ^ m / m.factorial * (b₁ * rm)) : |exp 1 - expNear n 1 a₁| ≤ |1| ^ n / n.factorial * b₁ := by subst er refine exp_approx_succ _ en _ _ ?_ h field_simp [show (m : ℝ) ≠ 0 by norm_cast; omega] #align real.exp_1_approx_succ_eq Real.exp_1_approx_succ_eq
Mathlib/Data/Complex/Exponential.lean
1,504
1,505
theorem exp_approx_start (x a b : ℝ) (h : |exp x - expNear 0 x a| ≤ |x| ^ 0 / Nat.factorial 0 * b) : |exp x - a| ≤ b := by
simpa using h
/- Copyright (c) 2021 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Combinatorics.SimpleGraph.Subgraph import Mathlib.Data.List.Rotate #align_import combinatorics.simple_graph.connectivity from "leanprover-community/mathlib"@"b99e2d58a5e6861833fa8de11e51a81144258db4" /-! # Graph connectivity In a simple graph, * A *walk* is a finite sequence of adjacent vertices, and can be thought of equally well as a sequence of directed edges. * A *trail* is a walk whose edges each appear no more than once. * A *path* is a trail whose vertices appear no more than once. * A *cycle* is a nonempty trail whose first and last vertices are the same and whose vertices except for the first appear no more than once. **Warning:** graph theorists mean something different by "path" than do homotopy theorists. A "walk" in graph theory is a "path" in homotopy theory. Another warning: some graph theorists use "path" and "simple path" for "walk" and "path." Some definitions and theorems have inspiration from multigraph counterparts in [Chou1994]. ## Main definitions * `SimpleGraph.Walk` (with accompanying pattern definitions `SimpleGraph.Walk.nil'` and `SimpleGraph.Walk.cons'`) * `SimpleGraph.Walk.IsTrail`, `SimpleGraph.Walk.IsPath`, and `SimpleGraph.Walk.IsCycle`. * `SimpleGraph.Path` * `SimpleGraph.Walk.map` and `SimpleGraph.Path.map` for the induced map on walks, given an (injective) graph homomorphism. * `SimpleGraph.Reachable` for the relation of whether there exists a walk between a given pair of vertices * `SimpleGraph.Preconnected` and `SimpleGraph.Connected` are predicates on simple graphs for whether every vertex can be reached from every other, and in the latter case, whether the vertex type is nonempty. * `SimpleGraph.ConnectedComponent` is the type of connected components of a given graph. * `SimpleGraph.IsBridge` for whether an edge is a bridge edge ## Main statements * `SimpleGraph.isBridge_iff_mem_and_forall_cycle_not_mem` characterizes bridge edges in terms of there being no cycle containing them. ## Tags walks, trails, paths, circuits, cycles, bridge edges -/ open Function universe u v w namespace SimpleGraph variable {V : Type u} {V' : Type v} {V'' : Type w} variable (G : SimpleGraph V) (G' : SimpleGraph V') (G'' : SimpleGraph V'') /-- A walk is a sequence of adjacent vertices. For vertices `u v : V`, the type `walk u v` consists of all walks starting at `u` and ending at `v`. We say that a walk *visits* the vertices it contains. The set of vertices a walk visits is `SimpleGraph.Walk.support`. See `SimpleGraph.Walk.nil'` and `SimpleGraph.Walk.cons'` for patterns that can be useful in definitions since they make the vertices explicit. -/ inductive Walk : V → V → Type u | nil {u : V} : Walk u u | cons {u v w : V} (h : G.Adj u v) (p : Walk v w) : Walk u w deriving DecidableEq #align simple_graph.walk SimpleGraph.Walk attribute [refl] Walk.nil @[simps] instance Walk.instInhabited (v : V) : Inhabited (G.Walk v v) := ⟨Walk.nil⟩ #align simple_graph.walk.inhabited SimpleGraph.Walk.instInhabited /-- The one-edge walk associated to a pair of adjacent vertices. -/ @[match_pattern, reducible] def Adj.toWalk {G : SimpleGraph V} {u v : V} (h : G.Adj u v) : G.Walk u v := Walk.cons h Walk.nil #align simple_graph.adj.to_walk SimpleGraph.Adj.toWalk namespace Walk variable {G} /-- Pattern to get `Walk.nil` with the vertex as an explicit argument. -/ @[match_pattern] abbrev nil' (u : V) : G.Walk u u := Walk.nil #align simple_graph.walk.nil' SimpleGraph.Walk.nil' /-- Pattern to get `Walk.cons` with the vertices as explicit arguments. -/ @[match_pattern] abbrev cons' (u v w : V) (h : G.Adj u v) (p : G.Walk v w) : G.Walk u w := Walk.cons h p #align simple_graph.walk.cons' SimpleGraph.Walk.cons' /-- Change the endpoints of a walk using equalities. This is helpful for relaxing definitional equality constraints and to be able to state otherwise difficult-to-state lemmas. While this is a simple wrapper around `Eq.rec`, it gives a canonical way to write it. The simp-normal form is for the `copy` to be pushed outward. That way calculations can occur within the "copy context." -/ protected def copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : G.Walk u' v' := hu ▸ hv ▸ p #align simple_graph.walk.copy SimpleGraph.Walk.copy @[simp] theorem copy_rfl_rfl {u v} (p : G.Walk u v) : p.copy rfl rfl = p := rfl #align simple_graph.walk.copy_rfl_rfl SimpleGraph.Walk.copy_rfl_rfl @[simp] theorem copy_copy {u v u' v' u'' v''} (p : G.Walk u v) (hu : u = u') (hv : v = v') (hu' : u' = u'') (hv' : v' = v'') : (p.copy hu hv).copy hu' hv' = p.copy (hu.trans hu') (hv.trans hv') := by subst_vars rfl #align simple_graph.walk.copy_copy SimpleGraph.Walk.copy_copy @[simp] theorem copy_nil {u u'} (hu : u = u') : (Walk.nil : G.Walk u u).copy hu hu = Walk.nil := by subst_vars rfl #align simple_graph.walk.copy_nil SimpleGraph.Walk.copy_nil theorem copy_cons {u v w u' w'} (h : G.Adj u v) (p : G.Walk v w) (hu : u = u') (hw : w = w') : (Walk.cons h p).copy hu hw = Walk.cons (hu ▸ h) (p.copy rfl hw) := by subst_vars rfl #align simple_graph.walk.copy_cons SimpleGraph.Walk.copy_cons @[simp] theorem cons_copy {u v w v' w'} (h : G.Adj u v) (p : G.Walk v' w') (hv : v' = v) (hw : w' = w) : Walk.cons h (p.copy hv hw) = (Walk.cons (hv ▸ h) p).copy rfl hw := by subst_vars rfl #align simple_graph.walk.cons_copy SimpleGraph.Walk.cons_copy theorem exists_eq_cons_of_ne {u v : V} (hne : u ≠ v) : ∀ (p : G.Walk u v), ∃ (w : V) (h : G.Adj u w) (p' : G.Walk w v), p = cons h p' | nil => (hne rfl).elim | cons h p' => ⟨_, h, p', rfl⟩ #align simple_graph.walk.exists_eq_cons_of_ne SimpleGraph.Walk.exists_eq_cons_of_ne /-- The length of a walk is the number of edges/darts along it. -/ def length {u v : V} : G.Walk u v → ℕ | nil => 0 | cons _ q => q.length.succ #align simple_graph.walk.length SimpleGraph.Walk.length /-- The concatenation of two compatible walks. -/ @[trans] def append {u v w : V} : G.Walk u v → G.Walk v w → G.Walk u w | nil, q => q | cons h p, q => cons h (p.append q) #align simple_graph.walk.append SimpleGraph.Walk.append /-- The reversed version of `SimpleGraph.Walk.cons`, concatenating an edge to the end of a walk. -/ def concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : G.Walk u w := p.append (cons h nil) #align simple_graph.walk.concat SimpleGraph.Walk.concat theorem concat_eq_append {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : p.concat h = p.append (cons h nil) := rfl #align simple_graph.walk.concat_eq_append SimpleGraph.Walk.concat_eq_append /-- The concatenation of the reverse of the first walk with the second walk. -/ protected def reverseAux {u v w : V} : G.Walk u v → G.Walk u w → G.Walk v w | nil, q => q | cons h p, q => Walk.reverseAux p (cons (G.symm h) q) #align simple_graph.walk.reverse_aux SimpleGraph.Walk.reverseAux /-- The walk in reverse. -/ @[symm] def reverse {u v : V} (w : G.Walk u v) : G.Walk v u := w.reverseAux nil #align simple_graph.walk.reverse SimpleGraph.Walk.reverse /-- Get the `n`th vertex from a walk, where `n` is generally expected to be between `0` and `p.length`, inclusive. If `n` is greater than or equal to `p.length`, the result is the path's endpoint. -/ def getVert {u v : V} : G.Walk u v → ℕ → V | nil, _ => u | cons _ _, 0 => u | cons _ q, n + 1 => q.getVert n #align simple_graph.walk.get_vert SimpleGraph.Walk.getVert @[simp] theorem getVert_zero {u v} (w : G.Walk u v) : w.getVert 0 = u := by cases w <;> rfl #align simple_graph.walk.get_vert_zero SimpleGraph.Walk.getVert_zero theorem getVert_of_length_le {u v} (w : G.Walk u v) {i : ℕ} (hi : w.length ≤ i) : w.getVert i = v := by induction w generalizing i with | nil => rfl | cons _ _ ih => cases i · cases hi · exact ih (Nat.succ_le_succ_iff.1 hi) #align simple_graph.walk.get_vert_of_length_le SimpleGraph.Walk.getVert_of_length_le @[simp] theorem getVert_length {u v} (w : G.Walk u v) : w.getVert w.length = v := w.getVert_of_length_le rfl.le #align simple_graph.walk.get_vert_length SimpleGraph.Walk.getVert_length
Mathlib/Combinatorics/SimpleGraph/Connectivity.lean
226
233
theorem adj_getVert_succ {u v} (w : G.Walk u v) {i : ℕ} (hi : i < w.length) : G.Adj (w.getVert i) (w.getVert (i + 1)) := by
induction w generalizing i with | nil => cases hi | cons hxy _ ih => cases i · simp [getVert, hxy] · exact ih (Nat.succ_lt_succ_iff.1 hi)
/- Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel -/ import Mathlib.Topology.EMetricSpace.Basic import Mathlib.Topology.Bornology.Constructions import Mathlib.Data.Set.Pointwise.Interval import Mathlib.Topology.Order.DenselyOrdered /-! ## Pseudo-metric spaces This file defines pseudo-metric spaces: these differ from metric spaces by not imposing the condition `dist x y = 0 → x = y`. Many definitions and theorems expected on (pseudo-)metric spaces are already introduced on uniform spaces and topological spaces. For example: open and closed sets, compactness, completeness, continuity and uniform continuity. ## Main definitions * `Dist α`: Endows a space `α` with a function `dist a b`. * `PseudoMetricSpace α`: A space endowed with a distance function, which can be zero even if the two elements are non-equal. * `Metric.ball x ε`: The set of all points `y` with `dist y x < ε`. * `Metric.Bounded s`: Whether a subset of a `PseudoMetricSpace` is bounded. * `MetricSpace α`: A `PseudoMetricSpace` with the guarantee `dist x y = 0 → x = y`. Additional useful definitions: * `nndist a b`: `dist` as a function to the non-negative reals. * `Metric.closedBall x ε`: The set of all points `y` with `dist y x ≤ ε`. * `Metric.sphere x ε`: The set of all points `y` with `dist y x = ε`. TODO (anyone): Add "Main results" section. ## Tags pseudo_metric, dist -/ open Set Filter TopologicalSpace Bornology open scoped ENNReal NNReal Uniformity Topology universe u v w variable {α : Type u} {β : Type v} {X ι : Type*} theorem UniformSpace.ofDist_aux (ε : ℝ) (hε : 0 < ε) : ∃ δ > (0 : ℝ), ∀ x < δ, ∀ y < δ, x + y < ε := ⟨ε / 2, half_pos hε, fun _x hx _y hy => add_halves ε ▸ add_lt_add hx hy⟩ /-- Construct a uniform structure from a distance function and metric space axioms -/ def UniformSpace.ofDist (dist : α → α → ℝ) (dist_self : ∀ x : α, dist x x = 0) (dist_comm : ∀ x y : α, dist x y = dist y x) (dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) : UniformSpace α := .ofFun dist dist_self dist_comm dist_triangle ofDist_aux #align uniform_space_of_dist UniformSpace.ofDist -- Porting note: dropped the `dist_self` argument /-- Construct a bornology from a distance function and metric space axioms. -/ abbrev Bornology.ofDist {α : Type*} (dist : α → α → ℝ) (dist_comm : ∀ x y, dist x y = dist y x) (dist_triangle : ∀ x y z, dist x z ≤ dist x y + dist y z) : Bornology α := Bornology.ofBounded { s : Set α | ∃ C, ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → dist x y ≤ C } ⟨0, fun x hx y => hx.elim⟩ (fun s ⟨c, hc⟩ t h => ⟨c, fun x hx y hy => hc (h hx) (h hy)⟩) (fun s hs t ht => by rcases s.eq_empty_or_nonempty with rfl | ⟨x, hx⟩ · rwa [empty_union] rcases t.eq_empty_or_nonempty with rfl | ⟨y, hy⟩ · rwa [union_empty] rsuffices ⟨C, hC⟩ : ∃ C, ∀ z ∈ s ∪ t, dist x z ≤ C · refine ⟨C + C, fun a ha b hb => (dist_triangle a x b).trans ?_⟩ simpa only [dist_comm] using add_le_add (hC _ ha) (hC _ hb) rcases hs with ⟨Cs, hs⟩; rcases ht with ⟨Ct, ht⟩ refine ⟨max Cs (dist x y + Ct), fun z hz => hz.elim (fun hz => (hs hx hz).trans (le_max_left _ _)) (fun hz => (dist_triangle x y z).trans <| (add_le_add le_rfl (ht hy hz)).trans (le_max_right _ _))⟩) fun z => ⟨dist z z, forall_eq.2 <| forall_eq.2 le_rfl⟩ #align bornology.of_dist Bornology.ofDistₓ /-- The distance function (given an ambient metric space on `α`), which returns a nonnegative real number `dist x y` given `x y : α`. -/ @[ext] class Dist (α : Type*) where dist : α → α → ℝ #align has_dist Dist export Dist (dist) -- the uniform structure and the emetric space structure are embedded in the metric space structure -- to avoid instance diamond issues. See Note [forgetful inheritance]. /-- This is an internal lemma used inside the default of `PseudoMetricSpace.edist`. -/ private theorem dist_nonneg' {α} {x y : α} (dist : α → α → ℝ) (dist_self : ∀ x : α, dist x x = 0) (dist_comm : ∀ x y : α, dist x y = dist y x) (dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) : 0 ≤ dist x y := have : 0 ≤ 2 * dist x y := calc 0 = dist x x := (dist_self _).symm _ ≤ dist x y + dist y x := dist_triangle _ _ _ _ = 2 * dist x y := by rw [two_mul, dist_comm] nonneg_of_mul_nonneg_right this two_pos #noalign pseudo_metric_space.edist_dist_tac -- Porting note (#11215): TODO: restore /-- Pseudo metric and Metric spaces A pseudo metric space is endowed with a distance for which the requirement `d(x,y)=0 → x = y` might not hold. A metric space is a pseudo metric space such that `d(x,y)=0 → x = y`. Each pseudo metric space induces a canonical `UniformSpace` and hence a canonical `TopologicalSpace` This is enforced in the type class definition, by extending the `UniformSpace` structure. When instantiating a `PseudoMetricSpace` structure, the uniformity fields are not necessary, they will be filled in by default. In the same way, each (pseudo) metric space induces a (pseudo) emetric space structure. It is included in the structure, but filled in by default. -/ class PseudoMetricSpace (α : Type u) extends Dist α : Type u where dist_self : ∀ x : α, dist x x = 0 dist_comm : ∀ x y : α, dist x y = dist y x dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z edist : α → α → ℝ≥0∞ := fun x y => ENNReal.ofNNReal ⟨dist x y, dist_nonneg' _ ‹_› ‹_› ‹_›⟩ edist_dist : ∀ x y : α, edist x y = ENNReal.ofReal (dist x y) -- Porting note (#11215): TODO: add := by _ toUniformSpace : UniformSpace α := .ofDist dist dist_self dist_comm dist_triangle uniformity_dist : 𝓤 α = ⨅ ε > 0, 𝓟 { p : α × α | dist p.1 p.2 < ε } := by intros; rfl toBornology : Bornology α := Bornology.ofDist dist dist_comm dist_triangle cobounded_sets : (Bornology.cobounded α).sets = { s | ∃ C : ℝ, ∀ x ∈ sᶜ, ∀ y ∈ sᶜ, dist x y ≤ C } := by intros; rfl #align pseudo_metric_space PseudoMetricSpace /-- Two pseudo metric space structures with the same distance function coincide. -/ @[ext] theorem PseudoMetricSpace.ext {α : Type*} {m m' : PseudoMetricSpace α} (h : m.toDist = m'.toDist) : m = m' := by cases' m with d _ _ _ ed hed U hU B hB cases' m' with d' _ _ _ ed' hed' U' hU' B' hB' obtain rfl : d = d' := h congr · ext x y : 2 rw [hed, hed'] · exact UniformSpace.ext (hU.trans hU'.symm) · ext : 2 rw [← Filter.mem_sets, ← Filter.mem_sets, hB, hB'] #align pseudo_metric_space.ext PseudoMetricSpace.ext variable [PseudoMetricSpace α] attribute [instance] PseudoMetricSpace.toUniformSpace PseudoMetricSpace.toBornology -- see Note [lower instance priority] instance (priority := 200) PseudoMetricSpace.toEDist : EDist α := ⟨PseudoMetricSpace.edist⟩ #align pseudo_metric_space.to_has_edist PseudoMetricSpace.toEDist /-- Construct a pseudo-metric space structure whose underlying topological space structure (definitionally) agrees which a pre-existing topology which is compatible with a given distance function. -/ def PseudoMetricSpace.ofDistTopology {α : Type u} [TopologicalSpace α] (dist : α → α → ℝ) (dist_self : ∀ x : α, dist x x = 0) (dist_comm : ∀ x y : α, dist x y = dist y x) (dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) (H : ∀ s : Set α, IsOpen s ↔ ∀ x ∈ s, ∃ ε > 0, ∀ y, dist x y < ε → y ∈ s) : PseudoMetricSpace α := { dist := dist dist_self := dist_self dist_comm := dist_comm dist_triangle := dist_triangle edist_dist := fun x y => by exact ENNReal.coe_nnreal_eq _ toUniformSpace := (UniformSpace.ofDist dist dist_self dist_comm dist_triangle).replaceTopology <| TopologicalSpace.ext_iff.2 fun s ↦ (H s).trans <| forall₂_congr fun x _ ↦ ((UniformSpace.hasBasis_ofFun (exists_gt (0 : ℝ)) dist dist_self dist_comm dist_triangle UniformSpace.ofDist_aux).comap (Prod.mk x)).mem_iff.symm uniformity_dist := rfl toBornology := Bornology.ofDist dist dist_comm dist_triangle cobounded_sets := rfl } #align pseudo_metric_space.of_dist_topology PseudoMetricSpace.ofDistTopology @[simp] theorem dist_self (x : α) : dist x x = 0 := PseudoMetricSpace.dist_self x #align dist_self dist_self theorem dist_comm (x y : α) : dist x y = dist y x := PseudoMetricSpace.dist_comm x y #align dist_comm dist_comm theorem edist_dist (x y : α) : edist x y = ENNReal.ofReal (dist x y) := PseudoMetricSpace.edist_dist x y #align edist_dist edist_dist theorem dist_triangle (x y z : α) : dist x z ≤ dist x y + dist y z := PseudoMetricSpace.dist_triangle x y z #align dist_triangle dist_triangle theorem dist_triangle_left (x y z : α) : dist x y ≤ dist z x + dist z y := by rw [dist_comm z]; apply dist_triangle #align dist_triangle_left dist_triangle_left theorem dist_triangle_right (x y z : α) : dist x y ≤ dist x z + dist y z := by rw [dist_comm y]; apply dist_triangle #align dist_triangle_right dist_triangle_right theorem dist_triangle4 (x y z w : α) : dist x w ≤ dist x y + dist y z + dist z w := calc dist x w ≤ dist x z + dist z w := dist_triangle x z w _ ≤ dist x y + dist y z + dist z w := add_le_add_right (dist_triangle x y z) _ #align dist_triangle4 dist_triangle4 theorem dist_triangle4_left (x₁ y₁ x₂ y₂ : α) : dist x₂ y₂ ≤ dist x₁ y₁ + (dist x₁ x₂ + dist y₁ y₂) := by rw [add_left_comm, dist_comm x₁, ← add_assoc] apply dist_triangle4 #align dist_triangle4_left dist_triangle4_left theorem dist_triangle4_right (x₁ y₁ x₂ y₂ : α) : dist x₁ y₁ ≤ dist x₁ x₂ + dist y₁ y₂ + dist x₂ y₂ := by rw [add_right_comm, dist_comm y₁] apply dist_triangle4 #align dist_triangle4_right dist_triangle4_right /-- The triangle (polygon) inequality for sequences of points; `Finset.Ico` version. -/ theorem dist_le_Ico_sum_dist (f : ℕ → α) {m n} (h : m ≤ n) : dist (f m) (f n) ≤ ∑ i ∈ Finset.Ico m n, dist (f i) (f (i + 1)) := by induction n, h using Nat.le_induction with | base => rw [Finset.Ico_self, Finset.sum_empty, dist_self] | succ n hle ihn => calc dist (f m) (f (n + 1)) ≤ dist (f m) (f n) + dist (f n) (f (n + 1)) := dist_triangle _ _ _ _ ≤ (∑ i ∈ Finset.Ico m n, _) + _ := add_le_add ihn le_rfl _ = ∑ i ∈ Finset.Ico m (n + 1), _ := by { rw [Nat.Ico_succ_right_eq_insert_Ico hle, Finset.sum_insert, add_comm]; simp } #align dist_le_Ico_sum_dist dist_le_Ico_sum_dist /-- The triangle (polygon) inequality for sequences of points; `Finset.range` version. -/ theorem dist_le_range_sum_dist (f : ℕ → α) (n : ℕ) : dist (f 0) (f n) ≤ ∑ i ∈ Finset.range n, dist (f i) (f (i + 1)) := Nat.Ico_zero_eq_range ▸ dist_le_Ico_sum_dist f (Nat.zero_le n) #align dist_le_range_sum_dist dist_le_range_sum_dist /-- A version of `dist_le_Ico_sum_dist` with each intermediate distance replaced with an upper estimate. -/ theorem dist_le_Ico_sum_of_dist_le {f : ℕ → α} {m n} (hmn : m ≤ n) {d : ℕ → ℝ} (hd : ∀ {k}, m ≤ k → k < n → dist (f k) (f (k + 1)) ≤ d k) : dist (f m) (f n) ≤ ∑ i ∈ Finset.Ico m n, d i := le_trans (dist_le_Ico_sum_dist f hmn) <| Finset.sum_le_sum fun _k hk => hd (Finset.mem_Ico.1 hk).1 (Finset.mem_Ico.1 hk).2 #align dist_le_Ico_sum_of_dist_le dist_le_Ico_sum_of_dist_le /-- A version of `dist_le_range_sum_dist` with each intermediate distance replaced with an upper estimate. -/ theorem dist_le_range_sum_of_dist_le {f : ℕ → α} (n : ℕ) {d : ℕ → ℝ} (hd : ∀ {k}, k < n → dist (f k) (f (k + 1)) ≤ d k) : dist (f 0) (f n) ≤ ∑ i ∈ Finset.range n, d i := Nat.Ico_zero_eq_range ▸ dist_le_Ico_sum_of_dist_le (zero_le n) fun _ => hd #align dist_le_range_sum_of_dist_le dist_le_range_sum_of_dist_le theorem swap_dist : Function.swap (@dist α _) = dist := by funext x y; exact dist_comm _ _ #align swap_dist swap_dist theorem abs_dist_sub_le (x y z : α) : |dist x z - dist y z| ≤ dist x y := abs_sub_le_iff.2 ⟨sub_le_iff_le_add.2 (dist_triangle _ _ _), sub_le_iff_le_add.2 (dist_triangle_left _ _ _)⟩ #align abs_dist_sub_le abs_dist_sub_le theorem dist_nonneg {x y : α} : 0 ≤ dist x y := dist_nonneg' dist dist_self dist_comm dist_triangle #align dist_nonneg dist_nonneg namespace Mathlib.Meta.Positivity open Lean Meta Qq Function /-- Extension for the `positivity` tactic: distances are nonnegative. -/ @[positivity Dist.dist _ _] def evalDist : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(@Dist.dist $β $inst $a $b) => let _inst ← synthInstanceQ q(PseudoMetricSpace $β) assertInstancesCommute pure (.nonnegative q(dist_nonneg)) | _, _, _ => throwError "not dist" end Mathlib.Meta.Positivity example {x y : α} : 0 ≤ dist x y := by positivity @[simp] theorem abs_dist {a b : α} : |dist a b| = dist a b := abs_of_nonneg dist_nonneg #align abs_dist abs_dist /-- A version of `Dist` that takes value in `ℝ≥0`. -/ class NNDist (α : Type*) where nndist : α → α → ℝ≥0 #align has_nndist NNDist export NNDist (nndist) -- see Note [lower instance priority] /-- Distance as a nonnegative real number. -/ instance (priority := 100) PseudoMetricSpace.toNNDist : NNDist α := ⟨fun a b => ⟨dist a b, dist_nonneg⟩⟩ #align pseudo_metric_space.to_has_nndist PseudoMetricSpace.toNNDist /-- Express `dist` in terms of `nndist`-/ theorem dist_nndist (x y : α) : dist x y = nndist x y := rfl #align dist_nndist dist_nndist @[simp, norm_cast] theorem coe_nndist (x y : α) : ↑(nndist x y) = dist x y := rfl #align coe_nndist coe_nndist /-- Express `edist` in terms of `nndist`-/ theorem edist_nndist (x y : α) : edist x y = nndist x y := by rw [edist_dist, dist_nndist, ENNReal.ofReal_coe_nnreal] #align edist_nndist edist_nndist /-- Express `nndist` in terms of `edist`-/ theorem nndist_edist (x y : α) : nndist x y = (edist x y).toNNReal := by simp [edist_nndist] #align nndist_edist nndist_edist @[simp, norm_cast] theorem coe_nnreal_ennreal_nndist (x y : α) : ↑(nndist x y) = edist x y := (edist_nndist x y).symm #align coe_nnreal_ennreal_nndist coe_nnreal_ennreal_nndist @[simp, norm_cast] theorem edist_lt_coe {x y : α} {c : ℝ≥0} : edist x y < c ↔ nndist x y < c := by rw [edist_nndist, ENNReal.coe_lt_coe] #align edist_lt_coe edist_lt_coe @[simp, norm_cast] theorem edist_le_coe {x y : α} {c : ℝ≥0} : edist x y ≤ c ↔ nndist x y ≤ c := by rw [edist_nndist, ENNReal.coe_le_coe] #align edist_le_coe edist_le_coe /-- In a pseudometric space, the extended distance is always finite-/ theorem edist_lt_top {α : Type*} [PseudoMetricSpace α] (x y : α) : edist x y < ⊤ := (edist_dist x y).symm ▸ ENNReal.ofReal_lt_top #align edist_lt_top edist_lt_top /-- In a pseudometric space, the extended distance is always finite-/ theorem edist_ne_top (x y : α) : edist x y ≠ ⊤ := (edist_lt_top x y).ne #align edist_ne_top edist_ne_top /-- `nndist x x` vanishes-/ @[simp] theorem nndist_self (a : α) : nndist a a = 0 := NNReal.coe_eq_zero.1 (dist_self a) #align nndist_self nndist_self -- Porting note: `dist_nndist` and `coe_nndist` moved up @[simp, norm_cast] theorem dist_lt_coe {x y : α} {c : ℝ≥0} : dist x y < c ↔ nndist x y < c := Iff.rfl #align dist_lt_coe dist_lt_coe @[simp, norm_cast] theorem dist_le_coe {x y : α} {c : ℝ≥0} : dist x y ≤ c ↔ nndist x y ≤ c := Iff.rfl #align dist_le_coe dist_le_coe @[simp] theorem edist_lt_ofReal {x y : α} {r : ℝ} : edist x y < ENNReal.ofReal r ↔ dist x y < r := by rw [edist_dist, ENNReal.ofReal_lt_ofReal_iff_of_nonneg dist_nonneg] #align edist_lt_of_real edist_lt_ofReal @[simp] theorem edist_le_ofReal {x y : α} {r : ℝ} (hr : 0 ≤ r) : edist x y ≤ ENNReal.ofReal r ↔ dist x y ≤ r := by rw [edist_dist, ENNReal.ofReal_le_ofReal_iff hr] #align edist_le_of_real edist_le_ofReal /-- Express `nndist` in terms of `dist`-/ theorem nndist_dist (x y : α) : nndist x y = Real.toNNReal (dist x y) := by rw [dist_nndist, Real.toNNReal_coe] #align nndist_dist nndist_dist theorem nndist_comm (x y : α) : nndist x y = nndist y x := NNReal.eq <| dist_comm x y #align nndist_comm nndist_comm /-- Triangle inequality for the nonnegative distance-/ theorem nndist_triangle (x y z : α) : nndist x z ≤ nndist x y + nndist y z := dist_triangle _ _ _ #align nndist_triangle nndist_triangle theorem nndist_triangle_left (x y z : α) : nndist x y ≤ nndist z x + nndist z y := dist_triangle_left _ _ _ #align nndist_triangle_left nndist_triangle_left theorem nndist_triangle_right (x y z : α) : nndist x y ≤ nndist x z + nndist y z := dist_triangle_right _ _ _ #align nndist_triangle_right nndist_triangle_right /-- Express `dist` in terms of `edist`-/ theorem dist_edist (x y : α) : dist x y = (edist x y).toReal := by rw [edist_dist, ENNReal.toReal_ofReal dist_nonneg] #align dist_edist dist_edist namespace Metric -- instantiate pseudometric space as a topology variable {x y z : α} {δ ε ε₁ ε₂ : ℝ} {s : Set α} /-- `ball x ε` is the set of all points `y` with `dist y x < ε` -/ def ball (x : α) (ε : ℝ) : Set α := { y | dist y x < ε } #align metric.ball Metric.ball @[simp] theorem mem_ball : y ∈ ball x ε ↔ dist y x < ε := Iff.rfl #align metric.mem_ball Metric.mem_ball theorem mem_ball' : y ∈ ball x ε ↔ dist x y < ε := by rw [dist_comm, mem_ball] #align metric.mem_ball' Metric.mem_ball' theorem pos_of_mem_ball (hy : y ∈ ball x ε) : 0 < ε := dist_nonneg.trans_lt hy #align metric.pos_of_mem_ball Metric.pos_of_mem_ball theorem mem_ball_self (h : 0 < ε) : x ∈ ball x ε := by rwa [mem_ball, dist_self] #align metric.mem_ball_self Metric.mem_ball_self @[simp] theorem nonempty_ball : (ball x ε).Nonempty ↔ 0 < ε := ⟨fun ⟨_x, hx⟩ => pos_of_mem_ball hx, fun h => ⟨x, mem_ball_self h⟩⟩ #align metric.nonempty_ball Metric.nonempty_ball @[simp] theorem ball_eq_empty : ball x ε = ∅ ↔ ε ≤ 0 := by rw [← not_nonempty_iff_eq_empty, nonempty_ball, not_lt] #align metric.ball_eq_empty Metric.ball_eq_empty @[simp] theorem ball_zero : ball x 0 = ∅ := by rw [ball_eq_empty] #align metric.ball_zero Metric.ball_zero /-- If a point belongs to an open ball, then there is a strictly smaller radius whose ball also contains it. See also `exists_lt_subset_ball`. -/ theorem exists_lt_mem_ball_of_mem_ball (h : x ∈ ball y ε) : ∃ ε' < ε, x ∈ ball y ε' := by simp only [mem_ball] at h ⊢ exact ⟨(dist x y + ε) / 2, by linarith, by linarith⟩ #align metric.exists_lt_mem_ball_of_mem_ball Metric.exists_lt_mem_ball_of_mem_ball theorem ball_eq_ball (ε : ℝ) (x : α) : UniformSpace.ball x { p | dist p.2 p.1 < ε } = Metric.ball x ε := rfl #align metric.ball_eq_ball Metric.ball_eq_ball theorem ball_eq_ball' (ε : ℝ) (x : α) : UniformSpace.ball x { p | dist p.1 p.2 < ε } = Metric.ball x ε := by ext simp [dist_comm, UniformSpace.ball] #align metric.ball_eq_ball' Metric.ball_eq_ball' @[simp] theorem iUnion_ball_nat (x : α) : ⋃ n : ℕ, ball x n = univ := iUnion_eq_univ_iff.2 fun y => exists_nat_gt (dist y x) #align metric.Union_ball_nat Metric.iUnion_ball_nat @[simp] theorem iUnion_ball_nat_succ (x : α) : ⋃ n : ℕ, ball x (n + 1) = univ := iUnion_eq_univ_iff.2 fun y => (exists_nat_gt (dist y x)).imp fun _ h => h.trans (lt_add_one _) #align metric.Union_ball_nat_succ Metric.iUnion_ball_nat_succ /-- `closedBall x ε` is the set of all points `y` with `dist y x ≤ ε` -/ def closedBall (x : α) (ε : ℝ) := { y | dist y x ≤ ε } #align metric.closed_ball Metric.closedBall @[simp] theorem mem_closedBall : y ∈ closedBall x ε ↔ dist y x ≤ ε := Iff.rfl #align metric.mem_closed_ball Metric.mem_closedBall theorem mem_closedBall' : y ∈ closedBall x ε ↔ dist x y ≤ ε := by rw [dist_comm, mem_closedBall] #align metric.mem_closed_ball' Metric.mem_closedBall' /-- `sphere x ε` is the set of all points `y` with `dist y x = ε` -/ def sphere (x : α) (ε : ℝ) := { y | dist y x = ε } #align metric.sphere Metric.sphere @[simp] theorem mem_sphere : y ∈ sphere x ε ↔ dist y x = ε := Iff.rfl #align metric.mem_sphere Metric.mem_sphere
Mathlib/Topology/MetricSpace/PseudoMetric.lean
484
484
theorem mem_sphere' : y ∈ sphere x ε ↔ dist x y = ε := by
rw [dist_comm, mem_sphere]
/- 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.Compactness.SigmaCompact import Mathlib.Topology.Connected.TotallyDisconnected import Mathlib.Topology.Inseparable #align_import topology.separation from "leanprover-community/mathlib"@"d91e7f7a7f1c7e9f0e18fdb6bde4f652004c735d" /-! # Separation properties of topological spaces. This file defines the predicate `SeparatedNhds`, and common separation axioms (under the Kolmogorov classification). ## Main definitions * `SeparatedNhds`: Two `Set`s are separated by neighbourhoods if they are contained in disjoint open sets. * `T0Space`: A T₀/Kolmogorov space is a space where, for every two points `x ≠ y`, there is an open set that contains one, but not the other. * `R0Space`: An R₀ space (sometimes called a *symmetric space*) is a topological space such that the `Specializes` relation is symmetric. * `T1Space`: A T₁/Fréchet space is a space where every singleton set is closed. This is equivalent to, for every pair `x ≠ y`, there existing an open set containing `x` but not `y` (`t1Space_iff_exists_open` shows that these conditions are equivalent.) T₁ implies T₀ and R₀. * `R1Space`: An R₁/preregular space is a space where any two topologically distinguishable points have disjoint neighbourhoods. R₁ implies R₀. * `T2Space`: A T₂/Hausdorff space is a space where, for every two points `x ≠ y`, there is two disjoint open sets, one containing `x`, and the other `y`. T₂ implies T₁ and R₁. * `T25Space`: A T₂.₅/Urysohn space is a space where, for every two points `x ≠ y`, there is two open sets, one containing `x`, and the other `y`, whose closures are disjoint. T₂.₅ implies T₂. * `RegularSpace`: A regular space is one where, given any closed `C` and `x ∉ C`, there are disjoint open sets containing `x` and `C` respectively. Such a space is not necessarily Hausdorff. * `T3Space`: A T₃ space is a regular T₀ space. T₃ implies T₂.₅. * `NormalSpace`: A normal space, is one where given two disjoint closed sets, we can find two open sets that separate them. Such a space is not necessarily Hausdorff, even if it is T₀. * `T4Space`: A T₄ space is a normal T₁ space. T₄ implies T₃. * `CompletelyNormalSpace`: A completely normal space is one in which for any two sets `s`, `t` such that if both `closure s` is disjoint with `t`, and `s` is disjoint with `closure t`, then there exist disjoint neighbourhoods of `s` and `t`. `Embedding.completelyNormalSpace` allows us to conclude that this is equivalent to all subspaces being normal. Such a space is not necessarily Hausdorff or regular, even if it is T₀. * `T5Space`: A T₅ space is a completely normal T₁ space. T₅ implies T₄. Note that `mathlib` adopts the modern convention that `m ≤ n` if and only if `T_m → T_n`, but occasionally the literature swaps definitions for e.g. T₃ and regular. ## Main results ### T₀ spaces * `IsClosed.exists_closed_singleton`: Given a closed set `S` in a compact T₀ space, there is some `x ∈ S` such that `{x}` is closed. * `exists_isOpen_singleton_of_isOpen_finite`: Given an open finite set `S` in a T₀ space, there is some `x ∈ S` such that `{x}` is open. ### T₁ spaces * `isClosedMap_const`: The constant map is a closed map. * `discrete_of_t1_of_finite`: A finite T₁ space must have the discrete topology. ### T₂ spaces * `t2_iff_nhds`: A space is T₂ iff the neighbourhoods of distinct points generate the bottom filter. * `t2_iff_isClosed_diagonal`: A space is T₂ iff the `diagonal` of `X` (that is, the set of all points of the form `(a, a) : X × X`) is closed under the product topology. * `separatedNhds_of_finset_finset`: Any two disjoint finsets are `SeparatedNhds`. * Most topological constructions preserve Hausdorffness; these results are part of the typeclass inference system (e.g. `Embedding.t2Space`) * `Set.EqOn.closure`: If two functions are equal on some set `s`, they are equal on its closure. * `IsCompact.isClosed`: All compact sets are closed. * `WeaklyLocallyCompactSpace.locallyCompactSpace`: If a topological space is both weakly locally compact (i.e., each point has a compact neighbourhood) and is T₂, then it is locally compact. * `totallySeparatedSpace_of_t1_of_basis_clopen`: If `X` has a clopen basis, then it is a `TotallySeparatedSpace`. * `loc_compact_t2_tot_disc_iff_tot_sep`: A locally compact T₂ space is totally disconnected iff it is totally separated. * `t2Quotient`: the largest T2 quotient of a given topological space. If the space is also compact: * `normalOfCompactT2`: A compact T₂ space is a `NormalSpace`. * `connectedComponent_eq_iInter_isClopen`: The connected component of a point is the intersection of all its clopen neighbourhoods. * `compact_t2_tot_disc_iff_tot_sep`: Being a `TotallyDisconnectedSpace` is equivalent to being a `TotallySeparatedSpace`. * `ConnectedComponents.t2`: `ConnectedComponents X` is T₂ for `X` T₂ and compact. ### T₃ spaces * `disjoint_nested_nhds`: Given two points `x ≠ y`, we can find neighbourhoods `x ∈ V₁ ⊆ U₁` and `y ∈ V₂ ⊆ U₂`, with the `Vₖ` closed and the `Uₖ` open, such that the `Uₖ` are disjoint. ## References https://en.wikipedia.org/wiki/Separation_axiom -/ open Function Set Filter Topology TopologicalSpace open scoped Classical universe u v variable {X : Type*} {Y : Type*} [TopologicalSpace X] section Separation /-- `SeparatedNhds` is a predicate on pairs of sub`Set`s of a topological space. It holds if the two sub`Set`s are contained in disjoint open sets. -/ def SeparatedNhds : Set X → Set X → Prop := fun s t : Set X => ∃ U V : Set X, IsOpen U ∧ IsOpen V ∧ s ⊆ U ∧ t ⊆ V ∧ Disjoint U V #align separated_nhds SeparatedNhds theorem separatedNhds_iff_disjoint {s t : Set X} : SeparatedNhds s t ↔ Disjoint (𝓝ˢ s) (𝓝ˢ t) := by simp only [(hasBasis_nhdsSet s).disjoint_iff (hasBasis_nhdsSet t), SeparatedNhds, exists_prop, ← exists_and_left, and_assoc, and_comm, and_left_comm] #align separated_nhds_iff_disjoint separatedNhds_iff_disjoint alias ⟨SeparatedNhds.disjoint_nhdsSet, _⟩ := separatedNhds_iff_disjoint namespace SeparatedNhds variable {s s₁ s₂ t t₁ t₂ u : Set X} @[symm] theorem symm : SeparatedNhds s t → SeparatedNhds t s := fun ⟨U, V, oU, oV, aU, bV, UV⟩ => ⟨V, U, oV, oU, bV, aU, Disjoint.symm UV⟩ #align separated_nhds.symm SeparatedNhds.symm theorem comm (s t : Set X) : SeparatedNhds s t ↔ SeparatedNhds t s := ⟨symm, symm⟩ #align separated_nhds.comm SeparatedNhds.comm theorem preimage [TopologicalSpace Y] {f : X → Y} {s t : Set Y} (h : SeparatedNhds s t) (hf : Continuous f) : SeparatedNhds (f ⁻¹' s) (f ⁻¹' t) := let ⟨U, V, oU, oV, sU, tV, UV⟩ := h ⟨f ⁻¹' U, f ⁻¹' V, oU.preimage hf, oV.preimage hf, preimage_mono sU, preimage_mono tV, UV.preimage f⟩ #align separated_nhds.preimage SeparatedNhds.preimage protected theorem disjoint (h : SeparatedNhds s t) : Disjoint s t := let ⟨_, _, _, _, hsU, htV, hd⟩ := h; hd.mono hsU htV #align separated_nhds.disjoint SeparatedNhds.disjoint theorem disjoint_closure_left (h : SeparatedNhds s t) : Disjoint (closure s) t := let ⟨_U, _V, _, hV, hsU, htV, hd⟩ := h (hd.closure_left hV).mono (closure_mono hsU) htV #align separated_nhds.disjoint_closure_left SeparatedNhds.disjoint_closure_left theorem disjoint_closure_right (h : SeparatedNhds s t) : Disjoint s (closure t) := h.symm.disjoint_closure_left.symm #align separated_nhds.disjoint_closure_right SeparatedNhds.disjoint_closure_right @[simp] theorem empty_right (s : Set X) : SeparatedNhds s ∅ := ⟨_, _, isOpen_univ, isOpen_empty, fun a _ => mem_univ a, Subset.rfl, disjoint_empty _⟩ #align separated_nhds.empty_right SeparatedNhds.empty_right @[simp] theorem empty_left (s : Set X) : SeparatedNhds ∅ s := (empty_right _).symm #align separated_nhds.empty_left SeparatedNhds.empty_left theorem mono (h : SeparatedNhds s₂ t₂) (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : SeparatedNhds s₁ t₁ := let ⟨U, V, hU, hV, hsU, htV, hd⟩ := h ⟨U, V, hU, hV, hs.trans hsU, ht.trans htV, hd⟩ #align separated_nhds.mono SeparatedNhds.mono theorem union_left : SeparatedNhds s u → SeparatedNhds t u → SeparatedNhds (s ∪ t) u := by simpa only [separatedNhds_iff_disjoint, nhdsSet_union, disjoint_sup_left] using And.intro #align separated_nhds.union_left SeparatedNhds.union_left theorem union_right (ht : SeparatedNhds s t) (hu : SeparatedNhds s u) : SeparatedNhds s (t ∪ u) := (ht.symm.union_left hu.symm).symm #align separated_nhds.union_right SeparatedNhds.union_right end SeparatedNhds /-- A T₀ space, also known as a Kolmogorov space, is a topological space such that for every pair `x ≠ y`, there is an open set containing one but not the other. We formulate the definition in terms of the `Inseparable` relation. -/ class T0Space (X : Type u) [TopologicalSpace X] : Prop where /-- Two inseparable points in a T₀ space are equal. -/ t0 : ∀ ⦃x y : X⦄, Inseparable x y → x = y #align t0_space T0Space theorem t0Space_iff_inseparable (X : Type u) [TopologicalSpace X] : T0Space X ↔ ∀ x y : X, Inseparable x y → x = y := ⟨fun ⟨h⟩ => h, fun h => ⟨h⟩⟩ #align t0_space_iff_inseparable t0Space_iff_inseparable theorem t0Space_iff_not_inseparable (X : Type u) [TopologicalSpace X] : T0Space X ↔ Pairwise fun x y : X => ¬Inseparable x y := by simp only [t0Space_iff_inseparable, Ne, not_imp_not, Pairwise] #align t0_space_iff_not_inseparable t0Space_iff_not_inseparable theorem Inseparable.eq [T0Space X] {x y : X} (h : Inseparable x y) : x = y := T0Space.t0 h #align inseparable.eq Inseparable.eq /-- A topology `Inducing` map from a T₀ space is injective. -/ protected theorem Inducing.injective [TopologicalSpace Y] [T0Space X] {f : X → Y} (hf : Inducing f) : Injective f := fun _ _ h => (hf.inseparable_iff.1 <| .of_eq h).eq #align inducing.injective Inducing.injective /-- A topology `Inducing` map from a T₀ space is a topological embedding. -/ protected theorem Inducing.embedding [TopologicalSpace Y] [T0Space X] {f : X → Y} (hf : Inducing f) : Embedding f := ⟨hf, hf.injective⟩ #align inducing.embedding Inducing.embedding lemma embedding_iff_inducing [TopologicalSpace Y] [T0Space X] {f : X → Y} : Embedding f ↔ Inducing f := ⟨Embedding.toInducing, Inducing.embedding⟩ #align embedding_iff_inducing embedding_iff_inducing theorem t0Space_iff_nhds_injective (X : Type u) [TopologicalSpace X] : T0Space X ↔ Injective (𝓝 : X → Filter X) := t0Space_iff_inseparable X #align t0_space_iff_nhds_injective t0Space_iff_nhds_injective theorem nhds_injective [T0Space X] : Injective (𝓝 : X → Filter X) := (t0Space_iff_nhds_injective X).1 ‹_› #align nhds_injective nhds_injective theorem inseparable_iff_eq [T0Space X] {x y : X} : Inseparable x y ↔ x = y := nhds_injective.eq_iff #align inseparable_iff_eq inseparable_iff_eq @[simp] theorem nhds_eq_nhds_iff [T0Space X] {a b : X} : 𝓝 a = 𝓝 b ↔ a = b := nhds_injective.eq_iff #align nhds_eq_nhds_iff nhds_eq_nhds_iff @[simp] theorem inseparable_eq_eq [T0Space X] : Inseparable = @Eq X := funext₂ fun _ _ => propext inseparable_iff_eq #align inseparable_eq_eq inseparable_eq_eq theorem TopologicalSpace.IsTopologicalBasis.inseparable_iff {b : Set (Set X)} (hb : IsTopologicalBasis b) {x y : X} : Inseparable x y ↔ ∀ s ∈ b, (x ∈ s ↔ y ∈ s) := ⟨fun h s hs ↦ inseparable_iff_forall_open.1 h _ (hb.isOpen hs), fun h ↦ hb.nhds_hasBasis.eq_of_same_basis <| by convert hb.nhds_hasBasis using 2 exact and_congr_right (h _)⟩ theorem TopologicalSpace.IsTopologicalBasis.eq_iff [T0Space X] {b : Set (Set X)} (hb : IsTopologicalBasis b) {x y : X} : x = y ↔ ∀ s ∈ b, (x ∈ s ↔ y ∈ s) := inseparable_iff_eq.symm.trans hb.inseparable_iff theorem t0Space_iff_exists_isOpen_xor'_mem (X : Type u) [TopologicalSpace X] : T0Space X ↔ Pairwise fun x y => ∃ U : Set X, IsOpen U ∧ Xor' (x ∈ U) (y ∈ U) := by simp only [t0Space_iff_not_inseparable, xor_iff_not_iff, not_forall, exists_prop, inseparable_iff_forall_open, Pairwise] #align t0_space_iff_exists_is_open_xor_mem t0Space_iff_exists_isOpen_xor'_mem theorem exists_isOpen_xor'_mem [T0Space X] {x y : X} (h : x ≠ y) : ∃ U : Set X, IsOpen U ∧ Xor' (x ∈ U) (y ∈ U) := (t0Space_iff_exists_isOpen_xor'_mem X).1 ‹_› h #align exists_is_open_xor_mem exists_isOpen_xor'_mem /-- Specialization forms a partial order on a t0 topological space. -/ def specializationOrder (X) [TopologicalSpace X] [T0Space X] : PartialOrder X := { specializationPreorder X, PartialOrder.lift (OrderDual.toDual ∘ 𝓝) nhds_injective with } #align specialization_order specializationOrder instance SeparationQuotient.instT0Space : T0Space (SeparationQuotient X) := ⟨fun x y => Quotient.inductionOn₂' x y fun _ _ h => SeparationQuotient.mk_eq_mk.2 <| SeparationQuotient.inducing_mk.inseparable_iff.1 h⟩ theorem minimal_nonempty_closed_subsingleton [T0Space X] {s : Set X} (hs : IsClosed s) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsClosed t → t = s) : s.Subsingleton := by clear Y -- Porting note: added refine fun x hx y hy => of_not_not fun hxy => ?_ rcases exists_isOpen_xor'_mem hxy with ⟨U, hUo, hU⟩ wlog h : x ∈ U ∧ y ∉ U · refine this hs hmin y hy x hx (Ne.symm hxy) U hUo hU.symm (hU.resolve_left h) cases' h with hxU hyU have : s \ U = s := hmin (s \ U) diff_subset ⟨y, hy, hyU⟩ (hs.sdiff hUo) exact (this.symm.subset hx).2 hxU #align minimal_nonempty_closed_subsingleton minimal_nonempty_closed_subsingleton theorem minimal_nonempty_closed_eq_singleton [T0Space X] {s : Set X} (hs : IsClosed s) (hne : s.Nonempty) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsClosed t → t = s) : ∃ x, s = {x} := exists_eq_singleton_iff_nonempty_subsingleton.2 ⟨hne, minimal_nonempty_closed_subsingleton hs hmin⟩ #align minimal_nonempty_closed_eq_singleton minimal_nonempty_closed_eq_singleton /-- Given a closed set `S` in a compact T₀ space, there is some `x ∈ S` such that `{x}` is closed. -/ theorem IsClosed.exists_closed_singleton [T0Space X] [CompactSpace X] {S : Set X} (hS : IsClosed S) (hne : S.Nonempty) : ∃ x : X, x ∈ S ∧ IsClosed ({x} : Set X) := by obtain ⟨V, Vsub, Vne, Vcls, hV⟩ := hS.exists_minimal_nonempty_closed_subset hne rcases minimal_nonempty_closed_eq_singleton Vcls Vne hV with ⟨x, rfl⟩ exact ⟨x, Vsub (mem_singleton x), Vcls⟩ #align is_closed.exists_closed_singleton IsClosed.exists_closed_singleton theorem minimal_nonempty_open_subsingleton [T0Space X] {s : Set X} (hs : IsOpen s) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsOpen t → t = s) : s.Subsingleton := by clear Y -- Porting note: added refine fun x hx y hy => of_not_not fun hxy => ?_ rcases exists_isOpen_xor'_mem hxy with ⟨U, hUo, hU⟩ wlog h : x ∈ U ∧ y ∉ U · exact this hs hmin y hy x hx (Ne.symm hxy) U hUo hU.symm (hU.resolve_left h) cases' h with hxU hyU have : s ∩ U = s := hmin (s ∩ U) inter_subset_left ⟨x, hx, hxU⟩ (hs.inter hUo) exact hyU (this.symm.subset hy).2 #align minimal_nonempty_open_subsingleton minimal_nonempty_open_subsingleton theorem minimal_nonempty_open_eq_singleton [T0Space X] {s : Set X} (hs : IsOpen s) (hne : s.Nonempty) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsOpen t → t = s) : ∃ x, s = {x} := exists_eq_singleton_iff_nonempty_subsingleton.2 ⟨hne, minimal_nonempty_open_subsingleton hs hmin⟩ #align minimal_nonempty_open_eq_singleton minimal_nonempty_open_eq_singleton /-- Given an open finite set `S` in a T₀ space, there is some `x ∈ S` such that `{x}` is open. -/ theorem exists_isOpen_singleton_of_isOpen_finite [T0Space X] {s : Set X} (hfin : s.Finite) (hne : s.Nonempty) (ho : IsOpen s) : ∃ x ∈ s, IsOpen ({x} : Set X) := by lift s to Finset X using hfin induction' s using Finset.strongInductionOn with s ihs rcases em (∃ t, t ⊂ s ∧ t.Nonempty ∧ IsOpen (t : Set X)) with (⟨t, hts, htne, hto⟩ | ht) · rcases ihs t hts htne hto with ⟨x, hxt, hxo⟩ exact ⟨x, hts.1 hxt, hxo⟩ · -- Porting note: was `rcases minimal_nonempty_open_eq_singleton ho hne _ with ⟨x, hx⟩` -- https://github.com/leanprover/std4/issues/116 rsuffices ⟨x, hx⟩ : ∃ x, s.toSet = {x} · exact ⟨x, hx.symm ▸ rfl, hx ▸ ho⟩ refine minimal_nonempty_open_eq_singleton ho hne ?_ refine fun t hts htne hto => of_not_not fun hts' => ht ?_ lift t to Finset X using s.finite_toSet.subset hts exact ⟨t, ssubset_iff_subset_ne.2 ⟨hts, mt Finset.coe_inj.2 hts'⟩, htne, hto⟩ #align exists_open_singleton_of_open_finite exists_isOpen_singleton_of_isOpen_finite theorem exists_open_singleton_of_finite [T0Space X] [Finite X] [Nonempty X] : ∃ x : X, IsOpen ({x} : Set X) := let ⟨x, _, h⟩ := exists_isOpen_singleton_of_isOpen_finite (Set.toFinite _) univ_nonempty isOpen_univ ⟨x, h⟩ #align exists_open_singleton_of_fintype exists_open_singleton_of_finite theorem t0Space_of_injective_of_continuous [TopologicalSpace Y] {f : X → Y} (hf : Function.Injective f) (hf' : Continuous f) [T0Space Y] : T0Space X := ⟨fun _ _ h => hf <| (h.map hf').eq⟩ #align t0_space_of_injective_of_continuous t0Space_of_injective_of_continuous protected theorem Embedding.t0Space [TopologicalSpace Y] [T0Space Y] {f : X → Y} (hf : Embedding f) : T0Space X := t0Space_of_injective_of_continuous hf.inj hf.continuous #align embedding.t0_space Embedding.t0Space instance Subtype.t0Space [T0Space X] {p : X → Prop} : T0Space (Subtype p) := embedding_subtype_val.t0Space #align subtype.t0_space Subtype.t0Space theorem t0Space_iff_or_not_mem_closure (X : Type u) [TopologicalSpace X] : T0Space X ↔ Pairwise fun a b : X => a ∉ closure ({b} : Set X) ∨ b ∉ closure ({a} : Set X) := by simp only [t0Space_iff_not_inseparable, inseparable_iff_mem_closure, not_and_or] #align t0_space_iff_or_not_mem_closure t0Space_iff_or_not_mem_closure instance Prod.instT0Space [TopologicalSpace Y] [T0Space X] [T0Space Y] : T0Space (X × Y) := ⟨fun _ _ h => Prod.ext (h.map continuous_fst).eq (h.map continuous_snd).eq⟩ instance Pi.instT0Space {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, T0Space (X i)] : T0Space (∀ i, X i) := ⟨fun _ _ h => funext fun i => (h.map (continuous_apply i)).eq⟩ #align pi.t0_space Pi.instT0Space instance ULift.instT0Space [T0Space X] : T0Space (ULift X) := embedding_uLift_down.t0Space theorem T0Space.of_cover (h : ∀ x y, Inseparable x y → ∃ s : Set X, x ∈ s ∧ y ∈ s ∧ T0Space s) : T0Space X := by refine ⟨fun x y hxy => ?_⟩ rcases h x y hxy with ⟨s, hxs, hys, hs⟩ lift x to s using hxs; lift y to s using hys rw [← subtype_inseparable_iff] at hxy exact congr_arg Subtype.val hxy.eq #align t0_space.of_cover T0Space.of_cover theorem T0Space.of_open_cover (h : ∀ x, ∃ s : Set X, x ∈ s ∧ IsOpen s ∧ T0Space s) : T0Space X := T0Space.of_cover fun x _ hxy => let ⟨s, hxs, hso, hs⟩ := h x ⟨s, hxs, (hxy.mem_open_iff hso).1 hxs, hs⟩ #align t0_space.of_open_cover T0Space.of_open_cover /-- A topological space is called an R₀ space, if `Specializes` relation is symmetric. In other words, given two points `x y : X`, if every neighborhood of `y` contains `x`, then every neighborhood of `x` contains `y`. -/ @[mk_iff] class R0Space (X : Type u) [TopologicalSpace X] : Prop where /-- In an R₀ space, the `Specializes` relation is symmetric. -/ specializes_symmetric : Symmetric (Specializes : X → X → Prop) export R0Space (specializes_symmetric) section R0Space variable [R0Space X] {x y : X} /-- In an R₀ space, the `Specializes` relation is symmetric, dot notation version. -/ theorem Specializes.symm (h : x ⤳ y) : y ⤳ x := specializes_symmetric h #align specializes.symm Specializes.symm /-- In an R₀ space, the `Specializes` relation is symmetric, `Iff` version. -/ theorem specializes_comm : x ⤳ y ↔ y ⤳ x := ⟨Specializes.symm, Specializes.symm⟩ #align specializes_comm specializes_comm /-- In an R₀ space, `Specializes` is equivalent to `Inseparable`. -/ theorem specializes_iff_inseparable : x ⤳ y ↔ Inseparable x y := ⟨fun h ↦ h.antisymm h.symm, Inseparable.specializes⟩ #align specializes_iff_inseparable specializes_iff_inseparable /-- In an R₀ space, `Specializes` implies `Inseparable`. -/ alias ⟨Specializes.inseparable, _⟩ := specializes_iff_inseparable theorem Inducing.r0Space [TopologicalSpace Y] {f : Y → X} (hf : Inducing f) : R0Space Y where specializes_symmetric a b := by simpa only [← hf.specializes_iff] using Specializes.symm instance {p : X → Prop} : R0Space {x // p x} := inducing_subtype_val.r0Space instance [TopologicalSpace Y] [R0Space Y] : R0Space (X × Y) where specializes_symmetric _ _ h := h.fst.symm.prod h.snd.symm instance {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, R0Space (X i)] : R0Space (∀ i, X i) where specializes_symmetric _ _ h := specializes_pi.2 fun i ↦ (specializes_pi.1 h i).symm /-- In an R₀ space, the closure of a singleton is a compact set. -/ theorem isCompact_closure_singleton : IsCompact (closure {x}) := by refine isCompact_of_finite_subcover fun U hUo hxU ↦ ?_ obtain ⟨i, hi⟩ : ∃ i, x ∈ U i := mem_iUnion.1 <| hxU <| subset_closure rfl refine ⟨{i}, fun y hy ↦ ?_⟩ rw [← specializes_iff_mem_closure, specializes_comm] at hy simpa using hy.mem_open (hUo i) hi theorem Filter.coclosedCompact_le_cofinite : coclosedCompact X ≤ cofinite := le_cofinite_iff_compl_singleton_mem.2 fun _ ↦ compl_mem_coclosedCompact.2 isCompact_closure_singleton #align filter.coclosed_compact_le_cofinite Filter.coclosedCompact_le_cofinite variable (X) /-- In an R₀ space, relatively compact sets form a bornology. Its cobounded filter is `Filter.coclosedCompact`. See also `Bornology.inCompact` the bornology of sets contained in a compact set. -/ def Bornology.relativelyCompact : Bornology X where cobounded' := Filter.coclosedCompact X le_cofinite' := Filter.coclosedCompact_le_cofinite #align bornology.relatively_compact Bornology.relativelyCompact variable {X} theorem Bornology.relativelyCompact.isBounded_iff {s : Set X} : @Bornology.IsBounded _ (Bornology.relativelyCompact X) s ↔ IsCompact (closure s) := compl_mem_coclosedCompact #align bornology.relatively_compact.is_bounded_iff Bornology.relativelyCompact.isBounded_iff /-- In an R₀ space, the closure of a finite set is a compact set. -/ theorem Set.Finite.isCompact_closure {s : Set X} (hs : s.Finite) : IsCompact (closure s) := let _ : Bornology X := .relativelyCompact X Bornology.relativelyCompact.isBounded_iff.1 hs.isBounded end R0Space /-- A T₁ space, also known as a Fréchet space, is a topological space where every singleton set is closed. Equivalently, for every pair `x ≠ y`, there is an open set containing `x` and not `y`. -/ class T1Space (X : Type u) [TopologicalSpace X] : Prop where /-- A singleton in a T₁ space is a closed set. -/ t1 : ∀ x, IsClosed ({x} : Set X) #align t1_space T1Space theorem isClosed_singleton [T1Space X] {x : X} : IsClosed ({x} : Set X) := T1Space.t1 x #align is_closed_singleton isClosed_singleton theorem isOpen_compl_singleton [T1Space X] {x : X} : IsOpen ({x}ᶜ : Set X) := isClosed_singleton.isOpen_compl #align is_open_compl_singleton isOpen_compl_singleton theorem isOpen_ne [T1Space X] {x : X} : IsOpen { y | y ≠ x } := isOpen_compl_singleton #align is_open_ne isOpen_ne @[to_additive] theorem Continuous.isOpen_mulSupport [T1Space X] [One X] [TopologicalSpace Y] {f : Y → X} (hf : Continuous f) : IsOpen (mulSupport f) := isOpen_ne.preimage hf #align continuous.is_open_mul_support Continuous.isOpen_mulSupport #align continuous.is_open_support Continuous.isOpen_support theorem Ne.nhdsWithin_compl_singleton [T1Space X] {x y : X} (h : x ≠ y) : 𝓝[{y}ᶜ] x = 𝓝 x := isOpen_ne.nhdsWithin_eq h #align ne.nhds_within_compl_singleton Ne.nhdsWithin_compl_singleton theorem Ne.nhdsWithin_diff_singleton [T1Space X] {x y : X} (h : x ≠ y) (s : Set X) : 𝓝[s \ {y}] x = 𝓝[s] x := by rw [diff_eq, inter_comm, nhdsWithin_inter_of_mem] exact mem_nhdsWithin_of_mem_nhds (isOpen_ne.mem_nhds h) #align ne.nhds_within_diff_singleton Ne.nhdsWithin_diff_singleton lemma nhdsWithin_compl_singleton_le [T1Space X] (x y : X) : 𝓝[{x}ᶜ] x ≤ 𝓝[{y}ᶜ] x := by rcases eq_or_ne x y with rfl|hy · exact Eq.le rfl · rw [Ne.nhdsWithin_compl_singleton hy] exact nhdsWithin_le_nhds theorem isOpen_setOf_eventually_nhdsWithin [T1Space X] {p : X → Prop} : IsOpen { x | ∀ᶠ y in 𝓝[≠] x, p y } := by refine isOpen_iff_mem_nhds.mpr fun a ha => ?_ filter_upwards [eventually_nhds_nhdsWithin.mpr ha] with b hb rcases eq_or_ne a b with rfl | h · exact hb · rw [h.symm.nhdsWithin_compl_singleton] at hb exact hb.filter_mono nhdsWithin_le_nhds #align is_open_set_of_eventually_nhds_within isOpen_setOf_eventually_nhdsWithin protected theorem Set.Finite.isClosed [T1Space X] {s : Set X} (hs : Set.Finite s) : IsClosed s := by rw [← biUnion_of_singleton s] exact hs.isClosed_biUnion fun i _ => isClosed_singleton #align set.finite.is_closed Set.Finite.isClosed theorem TopologicalSpace.IsTopologicalBasis.exists_mem_of_ne [T1Space X] {b : Set (Set X)} (hb : IsTopologicalBasis b) {x y : X} (h : x ≠ y) : ∃ a ∈ b, x ∈ a ∧ y ∉ a := by rcases hb.isOpen_iff.1 isOpen_ne x h with ⟨a, ab, xa, ha⟩ exact ⟨a, ab, xa, fun h => ha h rfl⟩ #align topological_space.is_topological_basis.exists_mem_of_ne TopologicalSpace.IsTopologicalBasis.exists_mem_of_ne protected theorem Finset.isClosed [T1Space X] (s : Finset X) : IsClosed (s : Set X) := s.finite_toSet.isClosed #align finset.is_closed Finset.isClosed theorem t1Space_TFAE (X : Type u) [TopologicalSpace X] : List.TFAE [T1Space X, ∀ x, IsClosed ({ x } : Set X), ∀ x, IsOpen ({ x }ᶜ : Set X), Continuous (@CofiniteTopology.of X), ∀ ⦃x y : X⦄, x ≠ y → {y}ᶜ ∈ 𝓝 x, ∀ ⦃x y : X⦄, x ≠ y → ∃ s ∈ 𝓝 x, y ∉ s, ∀ ⦃x y : X⦄, x ≠ y → ∃ U : Set X, IsOpen U ∧ x ∈ U ∧ y ∉ U, ∀ ⦃x y : X⦄, x ≠ y → Disjoint (𝓝 x) (pure y), ∀ ⦃x y : X⦄, x ≠ y → Disjoint (pure x) (𝓝 y), ∀ ⦃x y : X⦄, x ⤳ y → x = y] := by tfae_have 1 ↔ 2 · exact ⟨fun h => h.1, fun h => ⟨h⟩⟩ tfae_have 2 ↔ 3 · simp only [isOpen_compl_iff] tfae_have 5 ↔ 3 · refine forall_swap.trans ?_ simp only [isOpen_iff_mem_nhds, mem_compl_iff, mem_singleton_iff] tfae_have 5 ↔ 6 · simp only [← subset_compl_singleton_iff, exists_mem_subset_iff] tfae_have 5 ↔ 7 · simp only [(nhds_basis_opens _).mem_iff, subset_compl_singleton_iff, exists_prop, and_assoc, and_left_comm] tfae_have 5 ↔ 8 · simp only [← principal_singleton, disjoint_principal_right] tfae_have 8 ↔ 9 · exact forall_swap.trans (by simp only [disjoint_comm, ne_comm]) tfae_have 1 → 4 · simp only [continuous_def, CofiniteTopology.isOpen_iff'] rintro H s (rfl | hs) exacts [isOpen_empty, compl_compl s ▸ (@Set.Finite.isClosed _ _ H _ hs).isOpen_compl] tfae_have 4 → 2 · exact fun h x => (CofiniteTopology.isClosed_iff.2 <| Or.inr (finite_singleton _)).preimage h tfae_have 2 ↔ 10 · simp only [← closure_subset_iff_isClosed, specializes_iff_mem_closure, subset_def, mem_singleton_iff, eq_comm] tfae_finish #align t1_space_tfae t1Space_TFAE theorem t1Space_iff_continuous_cofinite_of : T1Space X ↔ Continuous (@CofiniteTopology.of X) := (t1Space_TFAE X).out 0 3 #align t1_space_iff_continuous_cofinite_of t1Space_iff_continuous_cofinite_of theorem CofiniteTopology.continuous_of [T1Space X] : Continuous (@CofiniteTopology.of X) := t1Space_iff_continuous_cofinite_of.mp ‹_› #align cofinite_topology.continuous_of CofiniteTopology.continuous_of theorem t1Space_iff_exists_open : T1Space X ↔ Pairwise fun x y => ∃ U : Set X, IsOpen U ∧ x ∈ U ∧ y ∉ U := (t1Space_TFAE X).out 0 6 #align t1_space_iff_exists_open t1Space_iff_exists_open theorem t1Space_iff_disjoint_pure_nhds : T1Space X ↔ ∀ ⦃x y : X⦄, x ≠ y → Disjoint (pure x) (𝓝 y) := (t1Space_TFAE X).out 0 8 #align t1_space_iff_disjoint_pure_nhds t1Space_iff_disjoint_pure_nhds theorem t1Space_iff_disjoint_nhds_pure : T1Space X ↔ ∀ ⦃x y : X⦄, x ≠ y → Disjoint (𝓝 x) (pure y) := (t1Space_TFAE X).out 0 7 #align t1_space_iff_disjoint_nhds_pure t1Space_iff_disjoint_nhds_pure theorem t1Space_iff_specializes_imp_eq : T1Space X ↔ ∀ ⦃x y : X⦄, x ⤳ y → x = y := (t1Space_TFAE X).out 0 9 #align t1_space_iff_specializes_imp_eq t1Space_iff_specializes_imp_eq theorem disjoint_pure_nhds [T1Space X] {x y : X} (h : x ≠ y) : Disjoint (pure x) (𝓝 y) := t1Space_iff_disjoint_pure_nhds.mp ‹_› h #align disjoint_pure_nhds disjoint_pure_nhds theorem disjoint_nhds_pure [T1Space X] {x y : X} (h : x ≠ y) : Disjoint (𝓝 x) (pure y) := t1Space_iff_disjoint_nhds_pure.mp ‹_› h #align disjoint_nhds_pure disjoint_nhds_pure theorem Specializes.eq [T1Space X] {x y : X} (h : x ⤳ y) : x = y := t1Space_iff_specializes_imp_eq.1 ‹_› h #align specializes.eq Specializes.eq theorem specializes_iff_eq [T1Space X] {x y : X} : x ⤳ y ↔ x = y := ⟨Specializes.eq, fun h => h ▸ specializes_rfl⟩ #align specializes_iff_eq specializes_iff_eq @[simp] theorem specializes_eq_eq [T1Space X] : (· ⤳ ·) = @Eq X := funext₂ fun _ _ => propext specializes_iff_eq #align specializes_eq_eq specializes_eq_eq @[simp] theorem pure_le_nhds_iff [T1Space X] {a b : X} : pure a ≤ 𝓝 b ↔ a = b := specializes_iff_pure.symm.trans specializes_iff_eq #align pure_le_nhds_iff pure_le_nhds_iff @[simp] theorem nhds_le_nhds_iff [T1Space X] {a b : X} : 𝓝 a ≤ 𝓝 b ↔ a = b := specializes_iff_eq #align nhds_le_nhds_iff nhds_le_nhds_iff instance (priority := 100) [T1Space X] : R0Space X where specializes_symmetric _ _ := by rw [specializes_iff_eq, specializes_iff_eq]; exact Eq.symm instance : T1Space (CofiniteTopology X) := t1Space_iff_continuous_cofinite_of.mpr continuous_id theorem t1Space_antitone : Antitone (@T1Space X) := fun a _ h _ => @T1Space.mk _ a fun x => (T1Space.t1 x).mono h #align t1_space_antitone t1Space_antitone theorem continuousWithinAt_update_of_ne [T1Space X] [DecidableEq X] [TopologicalSpace Y] {f : X → Y} {s : Set X} {x x' : X} {y : Y} (hne : x' ≠ x) : ContinuousWithinAt (Function.update f x y) s x' ↔ ContinuousWithinAt f s x' := EventuallyEq.congr_continuousWithinAt (mem_nhdsWithin_of_mem_nhds <| mem_of_superset (isOpen_ne.mem_nhds hne) fun _y' hy' => Function.update_noteq hy' _ _) (Function.update_noteq hne _ _) #align continuous_within_at_update_of_ne continuousWithinAt_update_of_ne theorem continuousAt_update_of_ne [T1Space X] [DecidableEq X] [TopologicalSpace Y] {f : X → Y} {x x' : X} {y : Y} (hne : x' ≠ x) : ContinuousAt (Function.update f x y) x' ↔ ContinuousAt f x' := by simp only [← continuousWithinAt_univ, continuousWithinAt_update_of_ne hne] #align continuous_at_update_of_ne continuousAt_update_of_ne theorem continuousOn_update_iff [T1Space X] [DecidableEq X] [TopologicalSpace Y] {f : X → Y} {s : Set X} {x : X} {y : Y} : ContinuousOn (Function.update f x y) s ↔ ContinuousOn f (s \ {x}) ∧ (x ∈ s → Tendsto f (𝓝[s \ {x}] x) (𝓝 y)) := by rw [ContinuousOn, ← and_forall_ne x, and_comm] refine and_congr ⟨fun H z hz => ?_, fun H z hzx hzs => ?_⟩ (forall_congr' fun _ => ?_) · specialize H z hz.2 hz.1 rw [continuousWithinAt_update_of_ne hz.2] at H exact H.mono diff_subset · rw [continuousWithinAt_update_of_ne hzx] refine (H z ⟨hzs, hzx⟩).mono_of_mem (inter_mem_nhdsWithin _ ?_) exact isOpen_ne.mem_nhds hzx · exact continuousWithinAt_update_same #align continuous_on_update_iff continuousOn_update_iff theorem t1Space_of_injective_of_continuous [TopologicalSpace Y] {f : X → Y} (hf : Function.Injective f) (hf' : Continuous f) [T1Space Y] : T1Space X := t1Space_iff_specializes_imp_eq.2 fun _ _ h => hf (h.map hf').eq #align t1_space_of_injective_of_continuous t1Space_of_injective_of_continuous protected theorem Embedding.t1Space [TopologicalSpace Y] [T1Space Y] {f : X → Y} (hf : Embedding f) : T1Space X := t1Space_of_injective_of_continuous hf.inj hf.continuous #align embedding.t1_space Embedding.t1Space instance Subtype.t1Space {X : Type u} [TopologicalSpace X] [T1Space X] {p : X → Prop} : T1Space (Subtype p) := embedding_subtype_val.t1Space #align subtype.t1_space Subtype.t1Space instance [TopologicalSpace Y] [T1Space X] [T1Space Y] : T1Space (X × Y) := ⟨fun ⟨a, b⟩ => @singleton_prod_singleton _ _ a b ▸ isClosed_singleton.prod isClosed_singleton⟩ instance {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, T1Space (X i)] : T1Space (∀ i, X i) := ⟨fun f => univ_pi_singleton f ▸ isClosed_set_pi fun _ _ => isClosed_singleton⟩ instance ULift.instT1Space [T1Space X] : T1Space (ULift X) := embedding_uLift_down.t1Space -- see Note [lower instance priority] instance (priority := 100) TotallyDisconnectedSpace.t1Space [h: TotallyDisconnectedSpace X] : T1Space X := by rw [((t1Space_TFAE X).out 0 1 :)] intro x rw [← totallyDisconnectedSpace_iff_connectedComponent_singleton.mp h x] exact isClosed_connectedComponent -- see Note [lower instance priority] instance (priority := 100) T1Space.t0Space [T1Space X] : T0Space X := ⟨fun _ _ h => h.specializes.eq⟩ #align t1_space.t0_space T1Space.t0Space @[simp] theorem compl_singleton_mem_nhds_iff [T1Space X] {x y : X} : {x}ᶜ ∈ 𝓝 y ↔ y ≠ x := isOpen_compl_singleton.mem_nhds_iff #align compl_singleton_mem_nhds_iff compl_singleton_mem_nhds_iff theorem compl_singleton_mem_nhds [T1Space X] {x y : X} (h : y ≠ x) : {x}ᶜ ∈ 𝓝 y := compl_singleton_mem_nhds_iff.mpr h #align compl_singleton_mem_nhds compl_singleton_mem_nhds @[simp] theorem closure_singleton [T1Space X] {x : X} : closure ({x} : Set X) = {x} := isClosed_singleton.closure_eq #align closure_singleton closure_singleton -- Porting note (#11215): TODO: the proof was `hs.induction_on (by simp) fun x => by simp` theorem Set.Subsingleton.closure [T1Space X] {s : Set X} (hs : s.Subsingleton) : (closure s).Subsingleton := by rcases hs.eq_empty_or_singleton with (rfl | ⟨x, rfl⟩) <;> simp #align set.subsingleton.closure Set.Subsingleton.closure @[simp] theorem subsingleton_closure [T1Space X] {s : Set X} : (closure s).Subsingleton ↔ s.Subsingleton := ⟨fun h => h.anti subset_closure, fun h => h.closure⟩ #align subsingleton_closure subsingleton_closure theorem isClosedMap_const {X Y} [TopologicalSpace X] [TopologicalSpace Y] [T1Space Y] {y : Y} : IsClosedMap (Function.const X y) := IsClosedMap.of_nonempty fun s _ h2s => by simp_rw [const, h2s.image_const, isClosed_singleton] #align is_closed_map_const isClosedMap_const theorem nhdsWithin_insert_of_ne [T1Space X] {x y : X} {s : Set X} (hxy : x ≠ y) : 𝓝[insert y s] x = 𝓝[s] x := by refine le_antisymm (Filter.le_def.2 fun t ht => ?_) (nhdsWithin_mono x <| subset_insert y s) obtain ⟨o, ho, hxo, host⟩ := mem_nhdsWithin.mp ht refine mem_nhdsWithin.mpr ⟨o \ {y}, ho.sdiff isClosed_singleton, ⟨hxo, hxy⟩, ?_⟩ rw [inter_insert_of_not_mem <| not_mem_diff_of_mem (mem_singleton y)] exact (inter_subset_inter diff_subset Subset.rfl).trans host #align nhds_within_insert_of_ne nhdsWithin_insert_of_ne /-- If `t` is a subset of `s`, except for one point, then `insert x s` is a neighborhood of `x` within `t`. -/ theorem insert_mem_nhdsWithin_of_subset_insert [T1Space X] {x y : X} {s t : Set X} (hu : t ⊆ insert y s) : insert x s ∈ 𝓝[t] x := by rcases eq_or_ne x y with (rfl | h) · exact mem_of_superset self_mem_nhdsWithin hu refine nhdsWithin_mono x hu ?_ rw [nhdsWithin_insert_of_ne h] exact mem_of_superset self_mem_nhdsWithin (subset_insert x s) #align insert_mem_nhds_within_of_subset_insert insert_mem_nhdsWithin_of_subset_insert @[simp] theorem ker_nhds [T1Space X] (x : X) : (𝓝 x).ker = {x} := by simp [ker_nhds_eq_specializes] theorem biInter_basis_nhds [T1Space X] {ι : Sort*} {p : ι → Prop} {s : ι → Set X} {x : X} (h : (𝓝 x).HasBasis p s) : ⋂ (i) (_ : p i), s i = {x} := by rw [← h.ker, ker_nhds] #align bInter_basis_nhds biInter_basis_nhds @[simp]
Mathlib/Topology/Separation.lean
777
778
theorem compl_singleton_mem_nhdsSet_iff [T1Space X] {x : X} {s : Set X} : {x}ᶜ ∈ 𝓝ˢ s ↔ x ∉ s := by
rw [isOpen_compl_singleton.mem_nhdsSet, subset_compl_singleton_iff]
/- Copyright (c) 2022 Matej Penciak. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Matej Penciak, Moritz Doll, Fabien Clery -/ import Mathlib.LinearAlgebra.Matrix.NonsingularInverse #align_import linear_algebra.symplectic_group from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a" /-! # The Symplectic Group This file defines the symplectic group and proves elementary properties. ## Main Definitions * `Matrix.J`: the canonical `2n × 2n` skew-symmetric matrix * `symplecticGroup`: the group of symplectic matrices ## TODO * Every symplectic matrix has determinant 1. * For `n = 1` the symplectic group coincides with the special linear group. -/ open Matrix variable {l R : Type*} namespace Matrix variable (l) [DecidableEq l] (R) [CommRing R] section JMatrixLemmas /-- The matrix defining the canonical skew-symmetric bilinear form. -/ def J : Matrix (Sum l l) (Sum l l) R := Matrix.fromBlocks 0 (-1) 1 0 set_option linter.uppercaseLean3 false in #align matrix.J Matrix.J @[simp] theorem J_transpose : (J l R)ᵀ = -J l R := by rw [J, fromBlocks_transpose, ← neg_one_smul R (fromBlocks _ _ _ _ : Matrix (l ⊕ l) (l ⊕ l) R), fromBlocks_smul, Matrix.transpose_zero, Matrix.transpose_one, transpose_neg] simp [fromBlocks] set_option linter.uppercaseLean3 false in #align matrix.J_transpose Matrix.J_transpose variable [Fintype l] theorem J_squared : J l R * J l R = -1 := by rw [J, fromBlocks_multiply] simp only [Matrix.zero_mul, Matrix.neg_mul, zero_add, neg_zero, Matrix.one_mul, add_zero] rw [← neg_zero, ← Matrix.fromBlocks_neg, ← fromBlocks_one] set_option linter.uppercaseLean3 false in #align matrix.J_squared Matrix.J_squared theorem J_inv : (J l R)⁻¹ = -J l R := by refine Matrix.inv_eq_right_inv ?_ rw [Matrix.mul_neg, J_squared] exact neg_neg 1 set_option linter.uppercaseLean3 false in #align matrix.J_inv Matrix.J_inv theorem J_det_mul_J_det : det (J l R) * det (J l R) = 1 := by rw [← det_mul, J_squared, ← one_smul R (-1 : Matrix _ _ R), smul_neg, ← neg_smul, det_smul, Fintype.card_sum, det_one, mul_one] apply Even.neg_one_pow exact even_add_self _ set_option linter.uppercaseLean3 false in #align matrix.J_det_mul_J_det Matrix.J_det_mul_J_det theorem isUnit_det_J : IsUnit (det (J l R)) := isUnit_iff_exists_inv.mpr ⟨det (J l R), J_det_mul_J_det _ _⟩ set_option linter.uppercaseLean3 false in #align matrix.is_unit_det_J Matrix.isUnit_det_J end JMatrixLemmas variable [Fintype l] /-- The group of symplectic matrices over a ring `R`. -/ def symplecticGroup : Submonoid (Matrix (Sum l l) (Sum l l) R) where carrier := { A | A * J l R * Aᵀ = J l R } mul_mem' {a b} ha hb := by simp only [Set.mem_setOf_eq, transpose_mul] at * rw [← Matrix.mul_assoc, a.mul_assoc, a.mul_assoc, hb] exact ha one_mem' := by simp #align matrix.symplectic_group Matrix.symplecticGroup end Matrix namespace SymplecticGroup variable [DecidableEq l] [Fintype l] [CommRing R] open Matrix theorem mem_iff {A : Matrix (Sum l l) (Sum l l) R} : A ∈ symplecticGroup l R ↔ A * J l R * Aᵀ = J l R := by simp [symplecticGroup] #align symplectic_group.mem_iff SymplecticGroup.mem_iff -- Porting note: Previous proof was `by infer_instance` instance coeMatrix : Coe (symplecticGroup l R) (Matrix (Sum l l) (Sum l l) R) := ⟨Subtype.val⟩ #align symplectic_group.coe_matrix SymplecticGroup.coeMatrix section SymplecticJ variable (l) (R)
Mathlib/LinearAlgebra/SymplecticGroup.lean
114
116
theorem J_mem : J l R ∈ symplecticGroup l R := by
rw [mem_iff, J, fromBlocks_multiply, fromBlocks_transpose, fromBlocks_multiply] simp
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Logic.Basic import Mathlib.Tactic.Positivity.Basic #align_import algebra.order.hom.basic from "leanprover-community/mathlib"@"28aa996fc6fb4317f0083c4e6daf79878d81be33" /-! # Algebraic order homomorphism classes This file defines hom classes for common properties at the intersection of order theory and algebra. ## Typeclasses Basic typeclasses * `NonnegHomClass`: Homs are nonnegative: `∀ f a, 0 ≤ f a` * `SubadditiveHomClass`: Homs are subadditive: `∀ f a b, f (a + b) ≤ f a + f b` * `SubmultiplicativeHomClass`: Homs are submultiplicative: `∀ f a b, f (a * b) ≤ f a * f b` * `MulLEAddHomClass`: `∀ f a b, f (a * b) ≤ f a + f b` * `NonarchimedeanHomClass`: `∀ a b, f (a + b) ≤ max (f a) (f b)` Group norms * `AddGroupSeminormClass`: Homs are nonnegative, subadditive, even and preserve zero. * `GroupSeminormClass`: Homs are nonnegative, respect `f (a * b) ≤ f a + f b`, `f a⁻¹ = f a` and preserve zero. * `AddGroupNormClass`: Homs are seminorms such that `f x = 0 → x = 0` for all `x`. * `GroupNormClass`: Homs are seminorms such that `f x = 0 → x = 1` for all `x`. Ring norms * `RingSeminormClass`: Homs are submultiplicative group norms. * `RingNormClass`: Homs are ring seminorms that are also additive group norms. * `MulRingSeminormClass`: Homs are ring seminorms that are multiplicative. * `MulRingNormClass`: Homs are ring norms that are multiplicative. ## Notes Typeclasses for seminorms are defined here while types of seminorms are defined in `Analysis.Normed.Group.Seminorm` and `Analysis.Normed.Ring.Seminorm` because absolute values are multiplicative ring norms but outside of this use we only consider real-valued seminorms. ## TODO Finitary versions of the current lemmas. -/ library_note "out-param inheritance"/-- Diamond inheritance cannot depend on `outParam`s in the following circumstances: * there are three classes `Top`, `Middle`, `Bottom` * all of these classes have a parameter `(α : outParam _)` * all of these classes have an instance parameter `[Root α]` that depends on this `outParam` * the `Root` class has two child classes: `Left` and `Right`, these are siblings in the hierarchy * the instance `Bottom.toMiddle` takes a `[Left α]` parameter * the instance `Middle.toTop` takes a `[Right α]` parameter * there is a `Leaf` class that inherits from both `Left` and `Right`. In that case, given instances `Bottom α` and `Leaf α`, Lean cannot synthesize a `Top α` instance, even though the hypotheses of the instances `Bottom.toMiddle` and `Middle.toTop` are satisfied. There are two workarounds: * You could replace the bundled inheritance implemented by the instance `Middle.toTop` with unbundled inheritance implemented by adding a `[Top α]` parameter to the `Middle` class. This is the preferred option since it is also more compatible with Lean 4, at the cost of being more work to implement and more verbose to use. * You could weaken the `Bottom.toMiddle` instance by making it depend on a subclass of `Middle.toTop`'s parameter, in this example replacing `[Left α]` with `[Leaf α]`. -/ open Function variable {ι F α β γ δ : Type*} /-! ### Basics -/ /-- `NonnegHomClass F α β` states that `F` is a type of nonnegative morphisms. -/ class NonnegHomClass (F α β : Type*) [Zero β] [LE β] [FunLike F α β] : Prop where /-- the image of any element is non negative. -/ apply_nonneg (f : F) : ∀ a, 0 ≤ f a #align nonneg_hom_class NonnegHomClass /-- `SubadditiveHomClass F α β` states that `F` is a type of subadditive morphisms. -/ class SubadditiveHomClass (F α β : Type*) [Add α] [Add β] [LE β] [FunLike F α β] : Prop where /-- the image of a sum is less or equal than the sum of the images. -/ map_add_le_add (f : F) : ∀ a b, f (a + b) ≤ f a + f b #align subadditive_hom_class SubadditiveHomClass /-- `SubmultiplicativeHomClass F α β` states that `F` is a type of submultiplicative morphisms. -/ @[to_additive SubadditiveHomClass] class SubmultiplicativeHomClass (F α β : Type*) [Mul α] [Mul β] [LE β] [FunLike F α β] : Prop where /-- the image of a product is less or equal than the product of the images. -/ map_mul_le_mul (f : F) : ∀ a b, f (a * b) ≤ f a * f b #align submultiplicative_hom_class SubmultiplicativeHomClass /-- `MulLEAddHomClass F α β` states that `F` is a type of subadditive morphisms. -/ @[to_additive SubadditiveHomClass] class MulLEAddHomClass (F α β : Type*) [Mul α] [Add β] [LE β] [FunLike F α β] : Prop where /-- the image of a product is less or equal than the sum of the images. -/ map_mul_le_add (f : F) : ∀ a b, f (a * b) ≤ f a + f b #align mul_le_add_hom_class MulLEAddHomClass /-- `NonarchimedeanHomClass F α β` states that `F` is a type of non-archimedean morphisms. -/ class NonarchimedeanHomClass (F α β : Type*) [Add α] [LinearOrder β] [FunLike F α β] : Prop where /-- the image of a sum is less or equal than the maximum of the images. -/ map_add_le_max (f : F) : ∀ a b, f (a + b) ≤ max (f a) (f b) #align nonarchimedean_hom_class NonarchimedeanHomClass export NonnegHomClass (apply_nonneg) export SubadditiveHomClass (map_add_le_add) export SubmultiplicativeHomClass (map_mul_le_mul) export MulLEAddHomClass (map_mul_le_add) export NonarchimedeanHomClass (map_add_le_max) attribute [simp] apply_nonneg variable [FunLike F α β] @[to_additive] theorem le_map_mul_map_div [Group α] [CommSemigroup β] [LE β] [SubmultiplicativeHomClass F α β] (f : F) (a b : α) : f a ≤ f b * f (a / b) := by simpa only [mul_comm, div_mul_cancel] using map_mul_le_mul f (a / b) b #align le_map_mul_map_div le_map_mul_map_div #align le_map_add_map_sub le_map_add_map_sub @[to_additive existing] theorem le_map_add_map_div [Group α] [AddCommSemigroup β] [LE β] [MulLEAddHomClass F α β] (f : F) (a b : α) : f a ≤ f b + f (a / b) := by simpa only [add_comm, div_mul_cancel] using map_mul_le_add f (a / b) b #align le_map_add_map_div le_map_add_map_div -- #align le_map_add_map_sub le_map_add_map_sub -- Porting note (#11215): TODO: `to_additive` clashes @[to_additive] theorem le_map_div_mul_map_div [Group α] [CommSemigroup β] [LE β] [SubmultiplicativeHomClass F α β] (f : F) (a b c : α) : f (a / c) ≤ f (a / b) * f (b / c) := by simpa only [div_mul_div_cancel'] using map_mul_le_mul f (a / b) (b / c) #align le_map_div_mul_map_div le_map_div_mul_map_div #align le_map_sub_add_map_sub le_map_sub_add_map_sub @[to_additive existing] theorem le_map_div_add_map_div [Group α] [AddCommSemigroup β] [LE β] [MulLEAddHomClass F α β] (f : F) (a b c : α) : f (a / c) ≤ f (a / b) + f (b / c) := by simpa only [div_mul_div_cancel'] using map_mul_le_add f (a / b) (b / c) #align le_map_div_add_map_div le_map_div_add_map_div -- #align le_map_sub_add_map_sub le_map_sub_add_map_sub -- Porting note (#11215): TODO: `to_additive` clashes namespace Mathlib.Meta.Positivity open Lean Meta Qq Function /-- Extension for the `positivity` tactic: nonnegative maps take nonnegative values. -/ @[positivity DFunLike.coe _ _] def evalMap : PositivityExt where eval {_ β} _ _ e := do let .app (.app _ f) a ← whnfR e | throwError "not ↑f · where f is of NonnegHomClass" let pa ← mkAppOptM ``apply_nonneg #[none, none, β, none, none, none, none, f, a] pure (.nonnegative pa) end Mathlib.Meta.Positivity /-! ### Group (semi)norms -/ /-- `AddGroupSeminormClass F α` states that `F` is a type of `β`-valued seminorms on the additive group `α`. You should extend this class when you extend `AddGroupSeminorm`. -/ class AddGroupSeminormClass (F α β : Type*) [AddGroup α] [OrderedAddCommMonoid β] [FunLike F α β] extends SubadditiveHomClass F α β : Prop where /-- The image of zero is zero. -/ map_zero (f : F) : f 0 = 0 /-- The map is invariant under negation of its argument. -/ map_neg_eq_map (f : F) (a : α) : f (-a) = f a #align add_group_seminorm_class AddGroupSeminormClass /-- `GroupSeminormClass F α` states that `F` is a type of `β`-valued seminorms on the group `α`. You should extend this class when you extend `GroupSeminorm`. -/ @[to_additive] class GroupSeminormClass (F α β : Type*) [Group α] [OrderedAddCommMonoid β] [FunLike F α β] extends MulLEAddHomClass F α β : Prop where /-- The image of one is zero. -/ map_one_eq_zero (f : F) : f 1 = 0 /-- The map is invariant under inversion of its argument. -/ map_inv_eq_map (f : F) (a : α) : f a⁻¹ = f a #align group_seminorm_class GroupSeminormClass /-- `AddGroupNormClass F α` states that `F` is a type of `β`-valued norms on the additive group `α`. You should extend this class when you extend `AddGroupNorm`. -/ class AddGroupNormClass (F α β : Type*) [AddGroup α] [OrderedAddCommMonoid β] [FunLike F α β] extends AddGroupSeminormClass F α β : Prop where /-- The argument is zero if its image under the map is zero. -/ eq_zero_of_map_eq_zero (f : F) {a : α} : f a = 0 → a = 0 #align add_group_norm_class AddGroupNormClass /-- `GroupNormClass F α` states that `F` is a type of `β`-valued norms on the group `α`. You should extend this class when you extend `GroupNorm`. -/ @[to_additive] class GroupNormClass (F α β : Type*) [Group α] [OrderedAddCommMonoid β] [FunLike F α β] extends GroupSeminormClass F α β : Prop where /-- The argument is one if its image under the map is zero. -/ eq_one_of_map_eq_zero (f : F) {a : α} : f a = 0 → a = 1 #align group_norm_class GroupNormClass export AddGroupSeminormClass (map_neg_eq_map) export GroupSeminormClass (map_one_eq_zero map_inv_eq_map) export AddGroupNormClass (eq_zero_of_map_eq_zero) export GroupNormClass (eq_one_of_map_eq_zero) attribute [simp] map_one_eq_zero -- Porting note: `to_additive` translation already exists attribute [simp] map_neg_eq_map attribute [simp] map_inv_eq_map -- Porting note: `to_additive` translation already exists attribute [to_additive] GroupSeminormClass.toMulLEAddHomClass -- See note [lower instance priority] instance (priority := 100) AddGroupSeminormClass.toZeroHomClass [AddGroup α] [OrderedAddCommMonoid β] [AddGroupSeminormClass F α β] : ZeroHomClass F α β := { ‹AddGroupSeminormClass F α β› with } #align add_group_seminorm_class.to_zero_hom_class AddGroupSeminormClass.toZeroHomClass section GroupSeminormClass variable [Group α] [OrderedAddCommMonoid β] [GroupSeminormClass F α β] (f : F) (x y : α) @[to_additive] theorem map_div_le_add : f (x / y) ≤ f x + f y := by rw [div_eq_mul_inv, ← map_inv_eq_map f y] exact map_mul_le_add _ _ _ #align map_div_le_add map_div_le_add #align map_sub_le_add map_sub_le_add @[to_additive] theorem map_div_rev : f (x / y) = f (y / x) := by rw [← inv_div, map_inv_eq_map] #align map_div_rev map_div_rev #align map_sub_rev map_sub_rev @[to_additive]
Mathlib/Algebra/Order/Hom/Basic.lean
253
254
theorem le_map_add_map_div' : f x ≤ f y + f (y / x) := by
simpa only [add_comm, map_div_rev, div_mul_cancel] using map_mul_le_add f (x / y) y
/- Copyright (c) 2018 Michael Jendrusch. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Jendrusch, Scott Morrison, Bhavik Mehta, Jakob von Raumer -/ import Mathlib.CategoryTheory.Functor.Trifunctor import Mathlib.CategoryTheory.Products.Basic #align_import category_theory.monoidal.category from "leanprover-community/mathlib"@"32253a1a1071173b33dc7d6a218cf722c6feb514" /-! # Monoidal categories A monoidal category is a category equipped with a tensor product, unitors, and an associator. In the definition, we provide the tensor product as a pair of functions * `tensorObj : C → C → C` * `tensorHom : (X₁ ⟶ Y₁) → (X₂ ⟶ Y₂) → ((X₁ ⊗ X₂) ⟶ (Y₁ ⊗ Y₂))` and allow use of the overloaded notation `⊗` for both. The unitors and associator are provided componentwise. The tensor product can be expressed as a functor via `tensor : C × C ⥤ C`. The unitors and associator are gathered together as natural isomorphisms in `leftUnitor_nat_iso`, `rightUnitor_nat_iso` and `associator_nat_iso`. Some consequences of the definition are proved in other files after proving the coherence theorem, e.g. `(λ_ (𝟙_ C)).hom = (ρ_ (𝟙_ C)).hom` in `CategoryTheory.Monoidal.CoherenceLemmas`. ## Implementation notes In the definition of monoidal categories, we also provide the whiskering operators: * `whiskerLeft (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : X ⊗ Y₁ ⟶ X ⊗ Y₂`, denoted by `X ◁ f`, * `whiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : X₁ ⊗ Y ⟶ X₂ ⊗ Y`, denoted by `f ▷ Y`. These are products of an object and a morphism (the terminology "whiskering" is borrowed from 2-category theory). The tensor product of morphisms `tensorHom` can be defined in terms of the whiskerings. There are two possible such definitions, which are related by the exchange property of the whiskerings. These two definitions are accessed by `tensorHom_def` and `tensorHom_def'`. By default, `tensorHom` is defined so that `tensorHom_def` holds definitionally. If you want to provide `tensorHom` and define `whiskerLeft` and `whiskerRight` in terms of it, you can use the alternative constructor `CategoryTheory.MonoidalCategory.ofTensorHom`. The whiskerings are useful when considering simp-normal forms of morphisms in monoidal categories. ### Simp-normal form for morphisms Rewriting involving associators and unitors could be very complicated. We try to ease this complexity by putting carefully chosen simp lemmas that rewrite any morphisms into the simp-normal form defined below. Rewriting into simp-normal form is especially useful in preprocessing performed by the `coherence` tactic. The simp-normal form of morphisms is defined to be an expression that has the minimal number of parentheses. More precisely, 1. it is a composition of morphisms like `f₁ ≫ f₂ ≫ f₃ ≫ f₄ ≫ f₅` such that each `fᵢ` is either a structural morphisms (morphisms made up only of identities, associators, unitors) or non-structural morphisms, and 2. each non-structural morphism in the composition is of the form `X₁ ◁ X₂ ◁ X₃ ◁ f ▷ X₄ ▷ X₅`, where each `Xᵢ` is a object that is not the identity or a tensor and `f` is a non-structural morphisms that is not the identity or a composite. Note that `X₁ ◁ X₂ ◁ X₃ ◁ f ▷ X₄ ▷ X₅` is actually `X₁ ◁ (X₂ ◁ (X₃ ◁ ((f ▷ X₄) ▷ X₅)))`. Currently, the simp lemmas don't rewrite `𝟙 X ⊗ f` and `f ⊗ 𝟙 Y` into `X ◁ f` and `f ▷ Y`, respectively, since it requires a huge refactoring. We hope to add these simp lemmas soon. ## References * Tensor categories, Etingof, Gelaki, Nikshych, Ostrik, http://www-math.mit.edu/~etingof/egnobookfinal.pdf * <https://stacks.math.columbia.edu/tag/0FFK>. -/ universe v u open CategoryTheory.Category open CategoryTheory.Iso namespace CategoryTheory /-- Auxiliary structure to carry only the data fields of (and provide notation for) `MonoidalCategory`. -/ class MonoidalCategoryStruct (C : Type u) [𝒞 : Category.{v} C] where /-- curried tensor product of objects -/ tensorObj : C → C → C /-- left whiskering for morphisms -/ whiskerLeft (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : tensorObj X Y₁ ⟶ tensorObj X Y₂ /-- right whiskering for morphisms -/ whiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : tensorObj X₁ Y ⟶ tensorObj X₂ Y /-- Tensor product of identity maps is the identity: `(𝟙 X₁ ⊗ 𝟙 X₂) = 𝟙 (X₁ ⊗ X₂)` -/ -- By default, it is defined in terms of whiskerings. tensorHom {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g: X₂ ⟶ Y₂) : (tensorObj X₁ X₂ ⟶ tensorObj Y₁ Y₂) := whiskerRight f X₂ ≫ whiskerLeft Y₁ g /-- The tensor unity in the monoidal structure `𝟙_ C` -/ tensorUnit : C /-- The associator isomorphism `(X ⊗ Y) ⊗ Z ≃ X ⊗ (Y ⊗ Z)` -/ associator : ∀ X Y Z : C, tensorObj (tensorObj X Y) Z ≅ tensorObj X (tensorObj Y Z) /-- The left unitor: `𝟙_ C ⊗ X ≃ X` -/ leftUnitor : ∀ X : C, tensorObj tensorUnit X ≅ X /-- The right unitor: `X ⊗ 𝟙_ C ≃ X` -/ rightUnitor : ∀ X : C, tensorObj X tensorUnit ≅ X namespace MonoidalCategory export MonoidalCategoryStruct (tensorObj whiskerLeft whiskerRight tensorHom tensorUnit associator leftUnitor rightUnitor) end MonoidalCategory namespace MonoidalCategory /-- Notation for `tensorObj`, the tensor product of objects in a monoidal category -/ scoped infixr:70 " ⊗ " => MonoidalCategoryStruct.tensorObj /-- Notation for the `whiskerLeft` operator of monoidal categories -/ scoped infixr:81 " ◁ " => MonoidalCategoryStruct.whiskerLeft /-- Notation for the `whiskerRight` operator of monoidal categories -/ scoped infixl:81 " ▷ " => MonoidalCategoryStruct.whiskerRight /-- Notation for `tensorHom`, the tensor product of morphisms in a monoidal category -/ scoped infixr:70 " ⊗ " => MonoidalCategoryStruct.tensorHom /-- Notation for `tensorUnit`, the two-sided identity of `⊗` -/ scoped notation "𝟙_ " C:max => (MonoidalCategoryStruct.tensorUnit : C) open Lean PrettyPrinter.Delaborator SubExpr in /-- Used to ensure that `𝟙_` notation is used, as the ascription makes this not automatic. -/ @[delab app.CategoryTheory.MonoidalCategoryStruct.tensorUnit] def delabTensorUnit : Delab := whenPPOption getPPNotation <| withOverApp 3 do let e ← getExpr guard <| e.isAppOfArity ``MonoidalCategoryStruct.tensorUnit 3 let C ← withNaryArg 0 delab `(𝟙_ $C) /-- Notation for the monoidal `associator`: `(X ⊗ Y) ⊗ Z ≃ X ⊗ (Y ⊗ Z)` -/ scoped notation "α_" => MonoidalCategoryStruct.associator /-- Notation for the `leftUnitor`: `𝟙_C ⊗ X ≃ X` -/ scoped notation "λ_" => MonoidalCategoryStruct.leftUnitor /-- Notation for the `rightUnitor`: `X ⊗ 𝟙_C ≃ X` -/ scoped notation "ρ_" => MonoidalCategoryStruct.rightUnitor end MonoidalCategory open MonoidalCategory /-- In a monoidal category, we can take the tensor product of objects, `X ⊗ Y` and of morphisms `f ⊗ g`. Tensor product does not need to be strictly associative on objects, but there is a specified associator, `α_ X Y Z : (X ⊗ Y) ⊗ Z ≅ X ⊗ (Y ⊗ Z)`. There is a tensor unit `𝟙_ C`, with specified left and right unitor isomorphisms `λ_ X : 𝟙_ C ⊗ X ≅ X` and `ρ_ X : X ⊗ 𝟙_ C ≅ X`. These associators and unitors satisfy the pentagon and triangle equations. See <https://stacks.math.columbia.edu/tag/0FFK>. -/ -- Porting note: The Mathport did not translate the temporary notation class MonoidalCategory (C : Type u) [𝒞 : Category.{v} C] extends MonoidalCategoryStruct C where tensorHom_def {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g: X₂ ⟶ Y₂) : f ⊗ g = (f ▷ X₂) ≫ (Y₁ ◁ g) := by aesop_cat /-- Tensor product of identity maps is the identity: `(𝟙 X₁ ⊗ 𝟙 X₂) = 𝟙 (X₁ ⊗ X₂)` -/ tensor_id : ∀ X₁ X₂ : C, 𝟙 X₁ ⊗ 𝟙 X₂ = 𝟙 (X₁ ⊗ X₂) := by aesop_cat /-- Composition of tensor products is tensor product of compositions: `(f₁ ⊗ g₁) ∘ (f₂ ⊗ g₂) = (f₁ ∘ f₂) ⊗ (g₁ ⊗ g₂)` -/ tensor_comp : ∀ {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (g₁ : Y₁ ⟶ Z₁) (g₂ : Y₂ ⟶ Z₂), (f₁ ≫ g₁) ⊗ (f₂ ≫ g₂) = (f₁ ⊗ f₂) ≫ (g₁ ⊗ g₂) := by aesop_cat whiskerLeft_id : ∀ (X Y : C), X ◁ 𝟙 Y = 𝟙 (X ⊗ Y) := by aesop_cat id_whiskerRight : ∀ (X Y : C), 𝟙 X ▷ Y = 𝟙 (X ⊗ Y) := by aesop_cat /-- Naturality of the associator isomorphism: `(f₁ ⊗ f₂) ⊗ f₃ ≃ f₁ ⊗ (f₂ ⊗ f₃)` -/ associator_naturality : ∀ {X₁ X₂ X₃ Y₁ Y₂ Y₃ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (f₃ : X₃ ⟶ Y₃), ((f₁ ⊗ f₂) ⊗ f₃) ≫ (α_ Y₁ Y₂ Y₃).hom = (α_ X₁ X₂ X₃).hom ≫ (f₁ ⊗ (f₂ ⊗ f₃)) := by aesop_cat /-- Naturality of the left unitor, commutativity of `𝟙_ C ⊗ X ⟶ 𝟙_ C ⊗ Y ⟶ Y` and `𝟙_ C ⊗ X ⟶ X ⟶ Y` -/ leftUnitor_naturality : ∀ {X Y : C} (f : X ⟶ Y), 𝟙_ _ ◁ f ≫ (λ_ Y).hom = (λ_ X).hom ≫ f := by aesop_cat /-- Naturality of the right unitor: commutativity of `X ⊗ 𝟙_ C ⟶ Y ⊗ 𝟙_ C ⟶ Y` and `X ⊗ 𝟙_ C ⟶ X ⟶ Y` -/ rightUnitor_naturality : ∀ {X Y : C} (f : X ⟶ Y), f ▷ 𝟙_ _ ≫ (ρ_ Y).hom = (ρ_ X).hom ≫ f := by aesop_cat /-- The pentagon identity relating the isomorphism between `X ⊗ (Y ⊗ (Z ⊗ W))` and `((X ⊗ Y) ⊗ Z) ⊗ W` -/ pentagon : ∀ W X Y Z : C, (α_ W X Y).hom ▷ Z ≫ (α_ W (X ⊗ Y) Z).hom ≫ W ◁ (α_ X Y Z).hom = (α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom := by aesop_cat /-- The identity relating the isomorphisms between `X ⊗ (𝟙_ C ⊗ Y)`, `(X ⊗ 𝟙_ C) ⊗ Y` and `X ⊗ Y` -/ triangle : ∀ X Y : C, (α_ X (𝟙_ _) Y).hom ≫ X ◁ (λ_ Y).hom = (ρ_ X).hom ▷ Y := by aesop_cat #align category_theory.monoidal_category CategoryTheory.MonoidalCategory attribute [reassoc] MonoidalCategory.tensorHom_def attribute [reassoc, simp] MonoidalCategory.whiskerLeft_id attribute [reassoc, simp] MonoidalCategory.id_whiskerRight attribute [reassoc] MonoidalCategory.tensor_comp attribute [simp] MonoidalCategory.tensor_comp attribute [reassoc] MonoidalCategory.associator_naturality attribute [reassoc] MonoidalCategory.leftUnitor_naturality attribute [reassoc] MonoidalCategory.rightUnitor_naturality attribute [reassoc (attr := simp)] MonoidalCategory.pentagon attribute [reassoc (attr := simp)] MonoidalCategory.triangle namespace MonoidalCategory variable {C : Type u} [𝒞 : Category.{v} C] [MonoidalCategory C] @[simp] theorem id_tensorHom (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : 𝟙 X ⊗ f = X ◁ f := by simp [tensorHom_def] @[simp] theorem tensorHom_id {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : f ⊗ 𝟙 Y = f ▷ Y := by simp [tensorHom_def] @[reassoc, simp] theorem whiskerLeft_comp (W : C) {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) : W ◁ (f ≫ g) = W ◁ f ≫ W ◁ g := by simp only [← id_tensorHom, ← tensor_comp, comp_id] @[reassoc, simp] theorem id_whiskerLeft {X Y : C} (f : X ⟶ Y) : 𝟙_ C ◁ f = (λ_ X).hom ≫ f ≫ (λ_ Y).inv := by rw [← assoc, ← leftUnitor_naturality]; simp [id_tensorHom] #align category_theory.monoidal_category.left_unitor_conjugation CategoryTheory.MonoidalCategory.id_whiskerLeft @[reassoc, simp] theorem tensor_whiskerLeft (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : (X ⊗ Y) ◁ f = (α_ X Y Z).hom ≫ X ◁ Y ◁ f ≫ (α_ X Y Z').inv := by simp only [← id_tensorHom, ← tensorHom_id] rw [← assoc, ← associator_naturality] simp @[reassoc, simp] theorem comp_whiskerRight {W X Y : C} (f : W ⟶ X) (g : X ⟶ Y) (Z : C) : (f ≫ g) ▷ Z = f ▷ Z ≫ g ▷ Z := by simp only [← tensorHom_id, ← tensor_comp, id_comp] @[reassoc, simp] theorem whiskerRight_id {X Y : C} (f : X ⟶ Y) : f ▷ 𝟙_ C = (ρ_ X).hom ≫ f ≫ (ρ_ Y).inv := by rw [← assoc, ← rightUnitor_naturality]; simp [tensorHom_id] #align category_theory.monoidal_category.right_unitor_conjugation CategoryTheory.MonoidalCategory.whiskerRight_id @[reassoc, simp] theorem whiskerRight_tensor {X X' : C} (f : X ⟶ X') (Y Z : C) : f ▷ (Y ⊗ Z) = (α_ X Y Z).inv ≫ f ▷ Y ▷ Z ≫ (α_ X' Y Z).hom := by simp only [← id_tensorHom, ← tensorHom_id] rw [associator_naturality] simp [tensor_id] @[reassoc, simp] theorem whisker_assoc (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) : (X ◁ f) ▷ Z = (α_ X Y Z).hom ≫ X ◁ f ▷ Z ≫ (α_ X Y' Z).inv := by simp only [← id_tensorHom, ← tensorHom_id] rw [← assoc, ← associator_naturality] simp @[reassoc] theorem whisker_exchange {W X Y Z : C} (f : W ⟶ X) (g : Y ⟶ Z) : W ◁ g ≫ f ▷ Z = f ▷ Y ≫ X ◁ g := by simp only [← id_tensorHom, ← tensorHom_id, ← tensor_comp, id_comp, comp_id] @[reassoc] theorem tensorHom_def' {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : f ⊗ g = X₁ ◁ g ≫ f ▷ Y₂ := whisker_exchange f g ▸ tensorHom_def f g end MonoidalCategory open scoped MonoidalCategory open MonoidalCategory variable {C : Type u} [𝒞 : Category.{v} C] [MonoidalCategory C] namespace MonoidalCategory @[reassoc (attr := simp)] theorem whiskerLeft_hom_inv (X : C) {Y Z : C} (f : Y ≅ Z) : X ◁ f.hom ≫ X ◁ f.inv = 𝟙 (X ⊗ Y) := by rw [← whiskerLeft_comp, hom_inv_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem hom_inv_whiskerRight {X Y : C} (f : X ≅ Y) (Z : C) : f.hom ▷ Z ≫ f.inv ▷ Z = 𝟙 (X ⊗ Z) := by rw [← comp_whiskerRight, hom_inv_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_inv_hom (X : C) {Y Z : C} (f : Y ≅ Z) : X ◁ f.inv ≫ X ◁ f.hom = 𝟙 (X ⊗ Z) := by rw [← whiskerLeft_comp, inv_hom_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem inv_hom_whiskerRight {X Y : C} (f : X ≅ Y) (Z : C) : f.inv ▷ Z ≫ f.hom ▷ Z = 𝟙 (Y ⊗ Z) := by rw [← comp_whiskerRight, inv_hom_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_hom_inv' (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : X ◁ f ≫ X ◁ inv f = 𝟙 (X ⊗ Y) := by rw [← whiskerLeft_comp, IsIso.hom_inv_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem hom_inv_whiskerRight' {X Y : C} (f : X ⟶ Y) [IsIso f] (Z : C) : f ▷ Z ≫ inv f ▷ Z = 𝟙 (X ⊗ Z) := by rw [← comp_whiskerRight, IsIso.hom_inv_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_inv_hom' (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : X ◁ inv f ≫ X ◁ f = 𝟙 (X ⊗ Z) := by rw [← whiskerLeft_comp, IsIso.inv_hom_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem inv_hom_whiskerRight' {X Y : C} (f : X ⟶ Y) [IsIso f] (Z : C) : inv f ▷ Z ≫ f ▷ Z = 𝟙 (Y ⊗ Z) := by rw [← comp_whiskerRight, IsIso.inv_hom_id, id_whiskerRight] /-- The left whiskering of an isomorphism is an isomorphism. -/ @[simps] def whiskerLeftIso (X : C) {Y Z : C} (f : Y ≅ Z) : X ⊗ Y ≅ X ⊗ Z where hom := X ◁ f.hom inv := X ◁ f.inv instance whiskerLeft_isIso (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : IsIso (X ◁ f) := (whiskerLeftIso X (asIso f)).isIso_hom @[simp] theorem inv_whiskerLeft (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : inv (X ◁ f) = X ◁ inv f := by aesop_cat @[simp] lemma whiskerLeftIso_refl (W X : C) : whiskerLeftIso W (Iso.refl X) = Iso.refl (W ⊗ X) := Iso.ext (whiskerLeft_id W X) @[simp] lemma whiskerLeftIso_trans (W : C) {X Y Z : C} (f : X ≅ Y) (g : Y ≅ Z) : whiskerLeftIso W (f ≪≫ g) = whiskerLeftIso W f ≪≫ whiskerLeftIso W g := Iso.ext (whiskerLeft_comp W f.hom g.hom) @[simp] lemma whiskerLeftIso_symm (W : C) {X Y : C} (f : X ≅ Y) : (whiskerLeftIso W f).symm = whiskerLeftIso W f.symm := rfl /-- The right whiskering of an isomorphism is an isomorphism. -/ @[simps!] def whiskerRightIso {X Y : C} (f : X ≅ Y) (Z : C) : X ⊗ Z ≅ Y ⊗ Z where hom := f.hom ▷ Z inv := f.inv ▷ Z instance whiskerRight_isIso {X Y : C} (f : X ⟶ Y) (Z : C) [IsIso f] : IsIso (f ▷ Z) := (whiskerRightIso (asIso f) Z).isIso_hom @[simp] theorem inv_whiskerRight {X Y : C} (f : X ⟶ Y) (Z : C) [IsIso f] : inv (f ▷ Z) = inv f ▷ Z := by aesop_cat @[simp] lemma whiskerRightIso_refl (X W : C) : whiskerRightIso (Iso.refl X) W = Iso.refl (X ⊗ W) := Iso.ext (id_whiskerRight X W) @[simp] lemma whiskerRightIso_trans {X Y Z : C} (f : X ≅ Y) (g : Y ≅ Z) (W : C) : whiskerRightIso (f ≪≫ g) W = whiskerRightIso f W ≪≫ whiskerRightIso g W := Iso.ext (comp_whiskerRight f.hom g.hom W) @[simp] lemma whiskerRightIso_symm {X Y : C} (f : X ≅ Y) (W : C) : (whiskerRightIso f W).symm = whiskerRightIso f.symm W := rfl end MonoidalCategory /-- The tensor product of two isomorphisms is an isomorphism. -/ @[simps] def tensorIso {C : Type u} {X Y X' Y' : C} [Category.{v} C] [MonoidalCategory.{v} C] (f : X ≅ Y) (g : X' ≅ Y') : X ⊗ X' ≅ Y ⊗ Y' where hom := f.hom ⊗ g.hom inv := f.inv ⊗ g.inv hom_inv_id := by rw [← tensor_comp, Iso.hom_inv_id, Iso.hom_inv_id, ← tensor_id] inv_hom_id := by rw [← tensor_comp, Iso.inv_hom_id, Iso.inv_hom_id, ← tensor_id] #align category_theory.tensor_iso CategoryTheory.tensorIso /-- Notation for `tensorIso`, the tensor product of isomorphisms -/ infixr:70 " ⊗ " => tensorIso namespace MonoidalCategory section variable {C : Type u} [Category.{v} C] [MonoidalCategory.{v} C] instance tensor_isIso {W X Y Z : C} (f : W ⟶ X) [IsIso f] (g : Y ⟶ Z) [IsIso g] : IsIso (f ⊗ g) := (asIso f ⊗ asIso g).isIso_hom #align category_theory.monoidal_category.tensor_is_iso CategoryTheory.MonoidalCategory.tensor_isIso @[simp] theorem inv_tensor {W X Y Z : C} (f : W ⟶ X) [IsIso f] (g : Y ⟶ Z) [IsIso g] : inv (f ⊗ g) = inv f ⊗ inv g := by simp [tensorHom_def ,whisker_exchange] #align category_theory.monoidal_category.inv_tensor CategoryTheory.MonoidalCategory.inv_tensor variable {U V W X Y Z : C} theorem whiskerLeft_dite {P : Prop} [Decidable P] (X : C) {Y Z : C} (f : P → (Y ⟶ Z)) (f' : ¬P → (Y ⟶ Z)) : X ◁ (if h : P then f h else f' h) = if h : P then X ◁ f h else X ◁ f' h := by split_ifs <;> rfl theorem dite_whiskerRight {P : Prop} [Decidable P] {X Y : C} (f : P → (X ⟶ Y)) (f' : ¬P → (X ⟶ Y)) (Z : C): (if h : P then f h else f' h) ▷ Z = if h : P then f h ▷ Z else f' h ▷ Z := by split_ifs <;> rfl theorem tensor_dite {P : Prop} [Decidable P] {W X Y Z : C} (f : W ⟶ X) (g : P → (Y ⟶ Z)) (g' : ¬P → (Y ⟶ Z)) : (f ⊗ if h : P then g h else g' h) = if h : P then f ⊗ g h else f ⊗ g' h := by split_ifs <;> rfl #align category_theory.monoidal_category.tensor_dite CategoryTheory.MonoidalCategory.tensor_dite theorem dite_tensor {P : Prop} [Decidable P] {W X Y Z : C} (f : W ⟶ X) (g : P → (Y ⟶ Z)) (g' : ¬P → (Y ⟶ Z)) : (if h : P then g h else g' h) ⊗ f = if h : P then g h ⊗ f else g' h ⊗ f := by split_ifs <;> rfl #align category_theory.monoidal_category.dite_tensor CategoryTheory.MonoidalCategory.dite_tensor @[simp] theorem whiskerLeft_eqToHom (X : C) {Y Z : C} (f : Y = Z) : X ◁ eqToHom f = eqToHom (congr_arg₂ tensorObj rfl f) := by cases f simp only [whiskerLeft_id, eqToHom_refl] @[simp] theorem eqToHom_whiskerRight {X Y : C} (f : X = Y) (Z : C) : eqToHom f ▷ Z = eqToHom (congr_arg₂ tensorObj f rfl) := by cases f simp only [id_whiskerRight, eqToHom_refl] @[reassoc] theorem associator_naturality_left {X X' : C} (f : X ⟶ X') (Y Z : C) : f ▷ Y ▷ Z ≫ (α_ X' Y Z).hom = (α_ X Y Z).hom ≫ f ▷ (Y ⊗ Z) := by simp @[reassoc] theorem associator_inv_naturality_left {X X' : C} (f : X ⟶ X') (Y Z : C) : f ▷ (Y ⊗ Z) ≫ (α_ X' Y Z).inv = (α_ X Y Z).inv ≫ f ▷ Y ▷ Z := by simp @[reassoc] theorem whiskerRight_tensor_symm {X X' : C} (f : X ⟶ X') (Y Z : C) : f ▷ Y ▷ Z = (α_ X Y Z).hom ≫ f ▷ (Y ⊗ Z) ≫ (α_ X' Y Z).inv := by simp @[reassoc] theorem associator_naturality_middle (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) : (X ◁ f) ▷ Z ≫ (α_ X Y' Z).hom = (α_ X Y Z).hom ≫ X ◁ f ▷ Z := by simp @[reassoc] theorem associator_inv_naturality_middle (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) : X ◁ f ▷ Z ≫ (α_ X Y' Z).inv = (α_ X Y Z).inv ≫ (X ◁ f) ▷ Z := by simp @[reassoc] theorem whisker_assoc_symm (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) : X ◁ f ▷ Z = (α_ X Y Z).inv ≫ (X ◁ f) ▷ Z ≫ (α_ X Y' Z).hom := by simp @[reassoc] theorem associator_naturality_right (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : (X ⊗ Y) ◁ f ≫ (α_ X Y Z').hom = (α_ X Y Z).hom ≫ X ◁ Y ◁ f := by simp @[reassoc] theorem associator_inv_naturality_right (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : X ◁ Y ◁ f ≫ (α_ X Y Z').inv = (α_ X Y Z).inv ≫ (X ⊗ Y) ◁ f := by simp @[reassoc] theorem tensor_whiskerLeft_symm (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : X ◁ Y ◁ f = (α_ X Y Z).inv ≫ (X ⊗ Y) ◁ f ≫ (α_ X Y Z').hom := by simp @[reassoc] theorem leftUnitor_inv_naturality {X Y : C} (f : X ⟶ Y) : f ≫ (λ_ Y).inv = (λ_ X).inv ≫ _ ◁ f := by simp #align category_theory.monoidal_category.left_unitor_inv_naturality CategoryTheory.MonoidalCategory.leftUnitor_inv_naturality @[reassoc] theorem id_whiskerLeft_symm {X X' : C} (f : X ⟶ X') : f = (λ_ X).inv ≫ 𝟙_ C ◁ f ≫ (λ_ X').hom := by simp only [id_whiskerLeft, assoc, inv_hom_id, comp_id, inv_hom_id_assoc] @[reassoc] theorem rightUnitor_inv_naturality {X X' : C} (f : X ⟶ X') : f ≫ (ρ_ X').inv = (ρ_ X).inv ≫ f ▷ _ := by simp #align category_theory.monoidal_category.right_unitor_inv_naturality CategoryTheory.MonoidalCategory.rightUnitor_inv_naturality @[reassoc] theorem whiskerRight_id_symm {X Y : C} (f : X ⟶ Y) : f = (ρ_ X).inv ≫ f ▷ 𝟙_ C ≫ (ρ_ Y).hom := by simp theorem whiskerLeft_iff {X Y : C} (f g : X ⟶ Y) : 𝟙_ C ◁ f = 𝟙_ C ◁ g ↔ f = g := by simp theorem whiskerRight_iff {X Y : C} (f g : X ⟶ Y) : f ▷ 𝟙_ C = g ▷ 𝟙_ C ↔ f = g := by simp /-! The lemmas in the next section are true by coherence, but we prove them directly as they are used in proving the coherence theorem. -/ section @[reassoc (attr := simp)] theorem pentagon_inv : W ◁ (α_ X Y Z).inv ≫ (α_ W (X ⊗ Y) Z).inv ≫ (α_ W X Y).inv ▷ Z = (α_ W X (Y ⊗ Z)).inv ≫ (α_ (W ⊗ X) Y Z).inv := eq_of_inv_eq_inv (by simp) #align category_theory.monoidal_category.pentagon_inv CategoryTheory.MonoidalCategory.pentagon_inv @[reassoc (attr := simp)] theorem pentagon_inv_inv_hom_hom_inv : (α_ W (X ⊗ Y) Z).inv ≫ (α_ W X Y).inv ▷ Z ≫ (α_ (W ⊗ X) Y Z).hom = W ◁ (α_ X Y Z).hom ≫ (α_ W X (Y ⊗ Z)).inv := by rw [← cancel_epi (W ◁ (α_ X Y Z).inv), ← cancel_mono (α_ (W ⊗ X) Y Z).inv] simp @[reassoc (attr := simp)] theorem pentagon_inv_hom_hom_hom_inv : (α_ (W ⊗ X) Y Z).inv ≫ (α_ W X Y).hom ▷ Z ≫ (α_ W (X ⊗ Y) Z).hom = (α_ W X (Y ⊗ Z)).hom ≫ W ◁ (α_ X Y Z).inv := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_hom_inv_inv_inv_inv : W ◁ (α_ X Y Z).hom ≫ (α_ W X (Y ⊗ Z)).inv ≫ (α_ (W ⊗ X) Y Z).inv = (α_ W (X ⊗ Y) Z).inv ≫ (α_ W X Y).inv ▷ Z := by simp [← cancel_epi (W ◁ (α_ X Y Z).inv)] @[reassoc (attr := simp)] theorem pentagon_hom_hom_inv_hom_hom : (α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom ≫ W ◁ (α_ X Y Z).inv = (α_ W X Y).hom ▷ Z ≫ (α_ W (X ⊗ Y) Z).hom := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_hom_inv_inv_inv_hom : (α_ W X (Y ⊗ Z)).hom ≫ W ◁ (α_ X Y Z).inv ≫ (α_ W (X ⊗ Y) Z).inv = (α_ (W ⊗ X) Y Z).inv ≫ (α_ W X Y).hom ▷ Z := by rw [← cancel_epi (α_ W X (Y ⊗ Z)).inv, ← cancel_mono ((α_ W X Y).inv ▷ Z)] simp @[reassoc (attr := simp)] theorem pentagon_hom_hom_inv_inv_hom : (α_ W (X ⊗ Y) Z).hom ≫ W ◁ (α_ X Y Z).hom ≫ (α_ W X (Y ⊗ Z)).inv = (α_ W X Y).inv ▷ Z ≫ (α_ (W ⊗ X) Y Z).hom := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_inv_hom_hom_hom_hom : (α_ W X Y).inv ▷ Z ≫ (α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom = (α_ W (X ⊗ Y) Z).hom ≫ W ◁ (α_ X Y Z).hom := by simp [← cancel_epi ((α_ W X Y).hom ▷ Z)] @[reassoc (attr := simp)] theorem pentagon_inv_inv_hom_inv_inv : (α_ W X (Y ⊗ Z)).inv ≫ (α_ (W ⊗ X) Y Z).inv ≫ (α_ W X Y).hom ▷ Z = W ◁ (α_ X Y Z).inv ≫ (α_ W (X ⊗ Y) Z).inv := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem triangle_assoc_comp_right (X Y : C) : (α_ X (𝟙_ C) Y).inv ≫ ((ρ_ X).hom ▷ Y) = X ◁ (λ_ Y).hom := by rw [← triangle, Iso.inv_hom_id_assoc] #align category_theory.monoidal_category.triangle_assoc_comp_right CategoryTheory.MonoidalCategory.triangle_assoc_comp_right @[reassoc (attr := simp)] theorem triangle_assoc_comp_right_inv (X Y : C) : (ρ_ X).inv ▷ Y ≫ (α_ X (𝟙_ C) Y).hom = X ◁ (λ_ Y).inv := by simp [← cancel_mono (X ◁ (λ_ Y).hom)] #align category_theory.monoidal_category.triangle_assoc_comp_right_inv CategoryTheory.MonoidalCategory.triangle_assoc_comp_right_inv @[reassoc (attr := simp)] theorem triangle_assoc_comp_left_inv (X Y : C) : (X ◁ (λ_ Y).inv) ≫ (α_ X (𝟙_ C) Y).inv = (ρ_ X).inv ▷ Y := by simp [← cancel_mono ((ρ_ X).hom ▷ Y)] #align category_theory.monoidal_category.triangle_assoc_comp_left_inv CategoryTheory.MonoidalCategory.triangle_assoc_comp_left_inv /-- We state it as a simp lemma, which is regarded as an involved version of `id_whiskerRight X Y : 𝟙 X ▷ Y = 𝟙 (X ⊗ Y)`. -/ @[reassoc, simp] theorem leftUnitor_whiskerRight (X Y : C) : (λ_ X).hom ▷ Y = (α_ (𝟙_ C) X Y).hom ≫ (λ_ (X ⊗ Y)).hom := by rw [← whiskerLeft_iff, whiskerLeft_comp, ← cancel_epi (α_ _ _ _).hom, ← cancel_epi ((α_ _ _ _).hom ▷ _), pentagon_assoc, triangle, ← associator_naturality_middle, ← comp_whiskerRight_assoc, triangle, associator_naturality_left] @[reassoc, simp] theorem leftUnitor_inv_whiskerRight (X Y : C) : (λ_ X).inv ▷ Y = (λ_ (X ⊗ Y)).inv ≫ (α_ (𝟙_ C) X Y).inv := eq_of_inv_eq_inv (by simp) @[reassoc, simp] theorem whiskerLeft_rightUnitor (X Y : C) : X ◁ (ρ_ Y).hom = (α_ X Y (𝟙_ C)).inv ≫ (ρ_ (X ⊗ Y)).hom := by rw [← whiskerRight_iff, comp_whiskerRight, ← cancel_epi (α_ _ _ _).inv, ← cancel_epi (X ◁ (α_ _ _ _).inv), pentagon_inv_assoc, triangle_assoc_comp_right, ← associator_inv_naturality_middle, ← whiskerLeft_comp_assoc, triangle_assoc_comp_right, associator_inv_naturality_right] @[reassoc, simp] theorem whiskerLeft_rightUnitor_inv (X Y : C) : X ◁ (ρ_ Y).inv = (ρ_ (X ⊗ Y)).inv ≫ (α_ X Y (𝟙_ C)).hom := eq_of_inv_eq_inv (by simp) @[reassoc] theorem leftUnitor_tensor (X Y : C) : (λ_ (X ⊗ Y)).hom = (α_ (𝟙_ C) X Y).inv ≫ (λ_ X).hom ▷ Y := by simp @[reassoc] theorem leftUnitor_tensor_inv (X Y : C) : (λ_ (X ⊗ Y)).inv = (λ_ X).inv ▷ Y ≫ (α_ (𝟙_ C) X Y).hom := by simp @[reassoc] theorem rightUnitor_tensor (X Y : C) : (ρ_ (X ⊗ Y)).hom = (α_ X Y (𝟙_ C)).hom ≫ X ◁ (ρ_ Y).hom := by simp #align category_theory.monoidal_category.right_unitor_tensor CategoryTheory.MonoidalCategory.rightUnitor_tensor @[reassoc] theorem rightUnitor_tensor_inv (X Y : C) : (ρ_ (X ⊗ Y)).inv = X ◁ (ρ_ Y).inv ≫ (α_ X Y (𝟙_ C)).inv := by simp #align category_theory.monoidal_category.right_unitor_tensor_inv CategoryTheory.MonoidalCategory.rightUnitor_tensor_inv end @[reassoc] theorem associator_inv_naturality {X Y Z X' Y' Z' : C} (f : X ⟶ X') (g : Y ⟶ Y') (h : Z ⟶ Z') : (f ⊗ g ⊗ h) ≫ (α_ X' Y' Z').inv = (α_ X Y Z).inv ≫ ((f ⊗ g) ⊗ h) := by simp [tensorHom_def] #align category_theory.monoidal_category.associator_inv_naturality CategoryTheory.MonoidalCategory.associator_inv_naturality @[reassoc, simp] theorem associator_conjugation {X X' Y Y' Z Z' : C} (f : X ⟶ X') (g : Y ⟶ Y') (h : Z ⟶ Z') : (f ⊗ g) ⊗ h = (α_ X Y Z).hom ≫ (f ⊗ g ⊗ h) ≫ (α_ X' Y' Z').inv := by rw [associator_inv_naturality, hom_inv_id_assoc] #align category_theory.monoidal_category.associator_conjugation CategoryTheory.MonoidalCategory.associator_conjugation @[reassoc] theorem associator_inv_conjugation {X X' Y Y' Z Z' : C} (f : X ⟶ X') (g : Y ⟶ Y') (h : Z ⟶ Z') : f ⊗ g ⊗ h = (α_ X Y Z).inv ≫ ((f ⊗ g) ⊗ h) ≫ (α_ X' Y' Z').hom := by rw [associator_naturality, inv_hom_id_assoc] #align category_theory.monoidal_category.associator_inv_conjugation CategoryTheory.MonoidalCategory.associator_inv_conjugation -- TODO these next two lemmas aren't so fundamental, and perhaps could be removed -- (replacing their usages by their proofs). @[reassoc] theorem id_tensor_associator_naturality {X Y Z Z' : C} (h : Z ⟶ Z') : (𝟙 (X ⊗ Y) ⊗ h) ≫ (α_ X Y Z').hom = (α_ X Y Z).hom ≫ (𝟙 X ⊗ 𝟙 Y ⊗ h) := by rw [← tensor_id, associator_naturality] #align category_theory.monoidal_category.id_tensor_associator_naturality CategoryTheory.MonoidalCategory.id_tensor_associator_naturality @[reassoc] theorem id_tensor_associator_inv_naturality {X Y Z X' : C} (f : X ⟶ X') : (f ⊗ 𝟙 (Y ⊗ Z)) ≫ (α_ X' Y Z).inv = (α_ X Y Z).inv ≫ ((f ⊗ 𝟙 Y) ⊗ 𝟙 Z) := by rw [← tensor_id, associator_inv_naturality] #align category_theory.monoidal_category.id_tensor_associator_inv_naturality CategoryTheory.MonoidalCategory.id_tensor_associator_inv_naturality @[reassoc (attr := simp)]
Mathlib/CategoryTheory/Monoidal/Category.lean
678
680
theorem hom_inv_id_tensor {V W X Y Z : C} (f : V ≅ W) (g : X ⟶ Y) (h : Y ⟶ Z) : (f.hom ⊗ g) ≫ (f.inv ⊗ h) = (𝟙 V ⊗ g) ≫ (𝟙 V ⊗ h) := by
rw [← tensor_comp, f.hom_inv_id]; simp [id_tensorHom]
/- Copyright (c) 2015 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Robert Y. Lewis, Yury G. Kudryashov -/ import Mathlib.Algebra.Order.Monoid.OrderDual import Mathlib.Tactic.Lift import Mathlib.Tactic.Monotonicity.Attr /-! # Lemmas about the interaction of power operations with order in terms of `CovariantClass` -/ open Function variable {β G M : Type*} section Monoid variable [Monoid M] section Preorder variable [Preorder M] section Left variable [CovariantClass M M (· * ·) (· ≤ ·)] {x : M} @[to_additive (attr := mono, gcongr) nsmul_le_nsmul_right] theorem pow_le_pow_left' [CovariantClass M M (swap (· * ·)) (· ≤ ·)] {a b : M} (hab : a ≤ b) : ∀ i : ℕ, a ^ i ≤ b ^ i | 0 => by simp | k + 1 => by rw [pow_succ, pow_succ] exact mul_le_mul' (pow_le_pow_left' hab k) hab #align pow_le_pow_of_le_left' pow_le_pow_left' #align nsmul_le_nsmul_of_le_right nsmul_le_nsmul_right @[to_additive nsmul_nonneg] theorem one_le_pow_of_one_le' {a : M} (H : 1 ≤ a) : ∀ n : ℕ, 1 ≤ a ^ n | 0 => by simp | k + 1 => by rw [pow_succ] exact one_le_mul (one_le_pow_of_one_le' H k) H #align one_le_pow_of_one_le' one_le_pow_of_one_le' #align nsmul_nonneg nsmul_nonneg @[to_additive nsmul_nonpos] theorem pow_le_one' {a : M} (H : a ≤ 1) (n : ℕ) : a ^ n ≤ 1 := @one_le_pow_of_one_le' Mᵒᵈ _ _ _ _ H n #align pow_le_one' pow_le_one' #align nsmul_nonpos nsmul_nonpos @[to_additive (attr := gcongr) nsmul_le_nsmul_left] theorem pow_le_pow_right' {a : M} {n m : ℕ} (ha : 1 ≤ a) (h : n ≤ m) : a ^ n ≤ a ^ m := let ⟨k, hk⟩ := Nat.le.dest h calc a ^ n ≤ a ^ n * a ^ k := le_mul_of_one_le_right' (one_le_pow_of_one_le' ha _) _ = a ^ m := by rw [← hk, pow_add] #align pow_le_pow' pow_le_pow_right' #align nsmul_le_nsmul nsmul_le_nsmul_left @[to_additive nsmul_le_nsmul_left_of_nonpos] theorem pow_le_pow_right_of_le_one' {a : M} {n m : ℕ} (ha : a ≤ 1) (h : n ≤ m) : a ^ m ≤ a ^ n := pow_le_pow_right' (M := Mᵒᵈ) ha h #align pow_le_pow_of_le_one' pow_le_pow_right_of_le_one' #align nsmul_le_nsmul_of_nonpos nsmul_le_nsmul_left_of_nonpos @[to_additive nsmul_pos] theorem one_lt_pow' {a : M} (ha : 1 < a) {k : ℕ} (hk : k ≠ 0) : 1 < a ^ k := by rcases Nat.exists_eq_succ_of_ne_zero hk with ⟨l, rfl⟩ clear hk induction' l with l IH · rw [pow_succ]; simpa using ha · rw [pow_succ] exact one_lt_mul'' IH ha #align one_lt_pow' one_lt_pow' #align nsmul_pos nsmul_pos @[to_additive nsmul_neg] theorem pow_lt_one' {a : M} (ha : a < 1) {k : ℕ} (hk : k ≠ 0) : a ^ k < 1 := @one_lt_pow' Mᵒᵈ _ _ _ _ ha k hk #align pow_lt_one' pow_lt_one' #align nsmul_neg nsmul_neg @[to_additive (attr := gcongr) nsmul_lt_nsmul_left] theorem pow_lt_pow_right' [CovariantClass M M (· * ·) (· < ·)] {a : M} {n m : ℕ} (ha : 1 < a) (h : n < m) : a ^ n < a ^ m := by rcases Nat.le.dest h with ⟨k, rfl⟩; clear h rw [pow_add, pow_succ, mul_assoc, ← pow_succ'] exact lt_mul_of_one_lt_right' _ (one_lt_pow' ha k.succ_ne_zero) #align pow_lt_pow_right' pow_lt_pow_right' #align nsmul_lt_nsmul_left nsmul_lt_nsmul_left @[to_additive nsmul_left_strictMono] theorem pow_right_strictMono' [CovariantClass M M (· * ·) (· < ·)] {a : M} (ha : 1 < a) : StrictMono ((a ^ ·) : ℕ → M) := fun _ _ => pow_lt_pow_right' ha #align pow_strict_mono_left pow_right_strictMono' #align nsmul_strict_mono_right nsmul_left_strictMono @[to_additive Left.pow_nonneg] theorem Left.one_le_pow_of_le (hx : 1 ≤ x) : ∀ {n : ℕ}, 1 ≤ x ^ n | 0 => (pow_zero x).ge | n + 1 => by rw [pow_succ] exact Left.one_le_mul (Left.one_le_pow_of_le hx) hx #align left.one_le_pow_of_le Left.one_le_pow_of_le #align left.pow_nonneg Left.pow_nonneg @[to_additive Left.pow_nonpos] theorem Left.pow_le_one_of_le (hx : x ≤ 1) : ∀ {n : ℕ}, x ^ n ≤ 1 | 0 => (pow_zero _).le | n + 1 => by rw [pow_succ] exact Left.mul_le_one (Left.pow_le_one_of_le hx) hx #align left.pow_le_one_of_le Left.pow_le_one_of_le #align left.pow_nonpos Left.pow_nonpos end Left section Right variable [CovariantClass M M (swap (· * ·)) (· ≤ ·)] {x : M} @[to_additive Right.pow_nonneg] theorem Right.one_le_pow_of_le (hx : 1 ≤ x) : ∀ {n : ℕ}, 1 ≤ x ^ n | 0 => (pow_zero _).ge | n + 1 => by rw [pow_succ] exact Right.one_le_mul (Right.one_le_pow_of_le hx) hx #align right.one_le_pow_of_le Right.one_le_pow_of_le #align right.pow_nonneg Right.pow_nonneg @[to_additive Right.pow_nonpos] theorem Right.pow_le_one_of_le (hx : x ≤ 1) : ∀ {n : ℕ}, x ^ n ≤ 1 | 0 => (pow_zero _).le | n + 1 => by rw [pow_succ] exact Right.mul_le_one (Right.pow_le_one_of_le hx) hx #align right.pow_le_one_of_le Right.pow_le_one_of_le #align right.pow_nonpos Right.pow_nonpos end Right section CovariantLTSwap variable [Preorder β] [CovariantClass M M (· * ·) (· < ·)] [CovariantClass M M (swap (· * ·)) (· < ·)] {f : β → M} {n : ℕ} @[to_additive StrictMono.const_nsmul] theorem StrictMono.pow_const (hf : StrictMono f) : ∀ {n : ℕ}, n ≠ 0 → StrictMono (f · ^ n) | 0, hn => (hn rfl).elim | 1, _ => by simpa | Nat.succ <| Nat.succ n, _ => by simpa only [pow_succ] using (hf.pow_const n.succ_ne_zero).mul' hf #align strict_mono.pow_const StrictMono.pow_const #align strict_mono.const_nsmul StrictMono.const_nsmul /-- See also `pow_left_strictMonoOn`. -/ @[to_additive nsmul_right_strictMono] -- Porting note: nolint to_additive_doc theorem pow_left_strictMono (hn : n ≠ 0) : StrictMono (· ^ n : M → M) := strictMono_id.pow_const hn #align pow_strict_mono_right' pow_left_strictMono #align nsmul_strict_mono_left nsmul_right_strictMono @[to_additive (attr := mono, gcongr) nsmul_lt_nsmul_right] lemma pow_lt_pow_left' (hn : n ≠ 0) {a b : M} (hab : a < b) : a ^ n < b ^ n := pow_left_strictMono hn hab end CovariantLTSwap section CovariantLESwap variable [Preorder β] [CovariantClass M M (· * ·) (· ≤ ·)] [CovariantClass M M (swap (· * ·)) (· ≤ ·)] @[to_additive Monotone.const_nsmul] theorem Monotone.pow_const {f : β → M} (hf : Monotone f) : ∀ n : ℕ, Monotone fun a => f a ^ n | 0 => by simpa using monotone_const | n + 1 => by simp_rw [pow_succ] exact (Monotone.pow_const hf _).mul' hf #align monotone.pow_right Monotone.pow_const #align monotone.const_nsmul Monotone.const_nsmul @[to_additive nsmul_right_mono] theorem pow_left_mono (n : ℕ) : Monotone fun a : M => a ^ n := monotone_id.pow_const _ #align pow_mono_right pow_left_mono #align nsmul_mono_left nsmul_right_mono end CovariantLESwap @[to_additive Left.pow_neg] theorem Left.pow_lt_one_of_lt [CovariantClass M M (· * ·) (· < ·)] {n : ℕ} {x : M} (hn : 0 < n) (h : x < 1) : x ^ n < 1 := Nat.le_induction ((pow_one _).trans_lt h) (fun n _ ih => by rw [pow_succ] exact mul_lt_one ih h) _ (Nat.succ_le_iff.2 hn) #align left.pow_lt_one_of_lt Left.pow_lt_one_of_lt #align left.pow_neg Left.pow_neg @[to_additive Right.pow_neg] theorem Right.pow_lt_one_of_lt [CovariantClass M M (swap (· * ·)) (· < ·)] {n : ℕ} {x : M} (hn : 0 < n) (h : x < 1) : x ^ n < 1 := Nat.le_induction ((pow_one _).trans_lt h) (fun n _ ih => by rw [pow_succ] exact Right.mul_lt_one ih h) _ (Nat.succ_le_iff.2 hn) #align right.pow_lt_one_of_lt Right.pow_lt_one_of_lt #align right.pow_neg Right.pow_neg end Preorder section LinearOrder variable [LinearOrder M] section CovariantLE variable [CovariantClass M M (· * ·) (· ≤ ·)] -- This generalises to lattices. See `pow_two_semiclosed` @[to_additive nsmul_nonneg_iff] theorem one_le_pow_iff {x : M} {n : ℕ} (hn : n ≠ 0) : 1 ≤ x ^ n ↔ 1 ≤ x := ⟨le_imp_le_of_lt_imp_lt fun h => pow_lt_one' h hn, fun h => one_le_pow_of_one_le' h n⟩ #align one_le_pow_iff one_le_pow_iff #align nsmul_nonneg_iff nsmul_nonneg_iff @[to_additive] theorem pow_le_one_iff {x : M} {n : ℕ} (hn : n ≠ 0) : x ^ n ≤ 1 ↔ x ≤ 1 := @one_le_pow_iff Mᵒᵈ _ _ _ _ _ hn #align pow_le_one_iff pow_le_one_iff #align nsmul_nonpos_iff nsmul_nonpos_iff @[to_additive nsmul_pos_iff] theorem one_lt_pow_iff {x : M} {n : ℕ} (hn : n ≠ 0) : 1 < x ^ n ↔ 1 < x := lt_iff_lt_of_le_iff_le (pow_le_one_iff hn) #align one_lt_pow_iff one_lt_pow_iff #align nsmul_pos_iff nsmul_pos_iff @[to_additive] theorem pow_lt_one_iff {x : M} {n : ℕ} (hn : n ≠ 0) : x ^ n < 1 ↔ x < 1 := lt_iff_lt_of_le_iff_le (one_le_pow_iff hn) #align pow_lt_one_iff pow_lt_one_iff #align nsmul_neg_iff nsmul_neg_iff @[to_additive]
Mathlib/Algebra/Order/Monoid/Unbundled/Pow.lean
251
253
theorem pow_eq_one_iff {x : M} {n : ℕ} (hn : n ≠ 0) : x ^ n = 1 ↔ x = 1 := by
simp only [le_antisymm_iff] rw [pow_le_one_iff hn, one_le_pow_iff hn]
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Order.Ring.Defs import Mathlib.Algebra.Group.Int import Mathlib.Data.Nat.Dist import Mathlib.Data.Ordmap.Ordnode import Mathlib.Tactic.Abel import Mathlib.Tactic.Linarith #align_import data.ordmap.ordset from "leanprover-community/mathlib"@"47b51515e69f59bca5cf34ef456e6000fe205a69" /-! # Verification of the `Ordnode α` datatype This file proves the correctness of the operations in `Data.Ordmap.Ordnode`. The public facing version is the type `Ordset α`, which is a wrapper around `Ordnode α` which includes the correctness invariant of the type, and it exposes parallel operations like `insert` as functions on `Ordset` that do the same thing but bundle the correctness proofs. The advantage is that it is possible to, for example, prove that the result of `find` on `insert` will actually find the element, while `Ordnode` cannot guarantee this if the input tree did not satisfy the type invariants. ## Main definitions * `Ordset α`: A well formed set of values of type `α` ## Implementation notes The majority of this file is actually in the `Ordnode` namespace, because we first have to prove the correctness of all the operations (and defining what correctness means here is actually somewhat subtle). So all the actual `Ordset` operations are at the very end, once we have all the theorems. An `Ordnode α` is an inductive type which describes a tree which stores the `size` at internal nodes. The correctness invariant of an `Ordnode α` is: * `Ordnode.Sized t`: All internal `size` fields must match the actual measured size of the tree. (This is not hard to satisfy.) * `Ordnode.Balanced t`: Unless the tree has the form `()` or `((a) b)` or `(a (b))` (that is, nil or a single singleton subtree), the two subtrees must satisfy `size l ≤ δ * size r` and `size r ≤ δ * size l`, where `δ := 3` is a global parameter of the data structure (and this property must hold recursively at subtrees). This is why we say this is a "size balanced tree" data structure. * `Ordnode.Bounded lo hi t`: The members of the tree must be in strictly increasing order, meaning that if `a` is in the left subtree and `b` is the root, then `a ≤ b` and `¬ (b ≤ a)`. We enforce this using `Ordnode.Bounded` which includes also a global upper and lower bound. Because the `Ordnode` file was ported from Haskell, the correctness invariants of some of the functions have not been spelled out, and some theorems like `Ordnode.Valid'.balanceL_aux` show very intricate assumptions on the sizes, which may need to be revised if it turns out some operations violate these assumptions, because there is a decent amount of slop in the actual data structure invariants, so the theorem will go through with multiple choices of assumption. **Note:** This file is incomplete, in the sense that the intent is to have verified versions and lemmas about all the definitions in `Ordnode.lean`, but at the moment only a few operations are verified (the hard part should be out of the way, but still). Contributors are encouraged to pick this up and finish the job, if it appeals to you. ## Tags ordered map, ordered set, data structure, verified programming -/ variable {α : Type*} namespace Ordnode /-! ### delta and ratio -/ theorem not_le_delta {s} (H : 1 ≤ s) : ¬s ≤ delta * 0 := not_le_of_gt H #align ordnode.not_le_delta Ordnode.not_le_delta theorem delta_lt_false {a b : ℕ} (h₁ : delta * a < b) (h₂ : delta * b < a) : False := not_le_of_lt (lt_trans ((mul_lt_mul_left (by decide)).2 h₁) h₂) <| by simpa [mul_assoc] using Nat.mul_le_mul_right a (by decide : 1 ≤ delta * delta) #align ordnode.delta_lt_false Ordnode.delta_lt_false /-! ### `singleton` -/ /-! ### `size` and `empty` -/ /-- O(n). Computes the actual number of elements in the set, ignoring the cached `size` field. -/ def realSize : Ordnode α → ℕ | nil => 0 | node _ l _ r => realSize l + realSize r + 1 #align ordnode.real_size Ordnode.realSize /-! ### `Sized` -/ /-- The `Sized` property asserts that all the `size` fields in nodes match the actual size of the respective subtrees. -/ def Sized : Ordnode α → Prop | nil => True | node s l _ r => s = size l + size r + 1 ∧ Sized l ∧ Sized r #align ordnode.sized Ordnode.Sized theorem Sized.node' {l x r} (hl : @Sized α l) (hr : Sized r) : Sized (node' l x r) := ⟨rfl, hl, hr⟩ #align ordnode.sized.node' Ordnode.Sized.node' theorem Sized.eq_node' {s l x r} (h : @Sized α (node s l x r)) : node s l x r = .node' l x r := by rw [h.1] #align ordnode.sized.eq_node' Ordnode.Sized.eq_node' theorem Sized.size_eq {s l x r} (H : Sized (@node α s l x r)) : size (@node α s l x r) = size l + size r + 1 := H.1 #align ordnode.sized.size_eq Ordnode.Sized.size_eq @[elab_as_elim] theorem Sized.induction {t} (hl : @Sized α t) {C : Ordnode α → Prop} (H0 : C nil) (H1 : ∀ l x r, C l → C r → C (.node' l x r)) : C t := by induction t with | nil => exact H0 | node _ _ _ _ t_ih_l t_ih_r => rw [hl.eq_node'] exact H1 _ _ _ (t_ih_l hl.2.1) (t_ih_r hl.2.2) #align ordnode.sized.induction Ordnode.Sized.induction theorem size_eq_realSize : ∀ {t : Ordnode α}, Sized t → size t = realSize t | nil, _ => rfl | node s l x r, ⟨h₁, h₂, h₃⟩ => by rw [size, h₁, size_eq_realSize h₂, size_eq_realSize h₃]; rfl #align ordnode.size_eq_real_size Ordnode.size_eq_realSize @[simp] theorem Sized.size_eq_zero {t : Ordnode α} (ht : Sized t) : size t = 0 ↔ t = nil := by cases t <;> [simp;simp [ht.1]] #align ordnode.sized.size_eq_zero Ordnode.Sized.size_eq_zero theorem Sized.pos {s l x r} (h : Sized (@node α s l x r)) : 0 < s := by rw [h.1]; apply Nat.le_add_left #align ordnode.sized.pos Ordnode.Sized.pos /-! `dual` -/ theorem dual_dual : ∀ t : Ordnode α, dual (dual t) = t | nil => rfl | node s l x r => by rw [dual, dual, dual_dual l, dual_dual r] #align ordnode.dual_dual Ordnode.dual_dual @[simp] theorem size_dual (t : Ordnode α) : size (dual t) = size t := by cases t <;> rfl #align ordnode.size_dual Ordnode.size_dual /-! `Balanced` -/ /-- The `BalancedSz l r` asserts that a hypothetical tree with children of sizes `l` and `r` is balanced: either `l ≤ δ * r` and `r ≤ δ * r`, or the tree is trivial with a singleton on one side and nothing on the other. -/ def BalancedSz (l r : ℕ) : Prop := l + r ≤ 1 ∨ l ≤ delta * r ∧ r ≤ delta * l #align ordnode.balanced_sz Ordnode.BalancedSz instance BalancedSz.dec : DecidableRel BalancedSz := fun _ _ => Or.decidable #align ordnode.balanced_sz.dec Ordnode.BalancedSz.dec /-- The `Balanced t` asserts that the tree `t` satisfies the balance invariants (at every level). -/ def Balanced : Ordnode α → Prop | nil => True | node _ l _ r => BalancedSz (size l) (size r) ∧ Balanced l ∧ Balanced r #align ordnode.balanced Ordnode.Balanced instance Balanced.dec : DecidablePred (@Balanced α) | nil => by unfold Balanced infer_instance | node _ l _ r => by unfold Balanced haveI := Balanced.dec l haveI := Balanced.dec r infer_instance #align ordnode.balanced.dec Ordnode.Balanced.dec @[symm] theorem BalancedSz.symm {l r : ℕ} : BalancedSz l r → BalancedSz r l := Or.imp (by rw [add_comm]; exact id) And.symm #align ordnode.balanced_sz.symm Ordnode.BalancedSz.symm theorem balancedSz_zero {l : ℕ} : BalancedSz l 0 ↔ l ≤ 1 := by simp (config := { contextual := true }) [BalancedSz] #align ordnode.balanced_sz_zero Ordnode.balancedSz_zero theorem balancedSz_up {l r₁ r₂ : ℕ} (h₁ : r₁ ≤ r₂) (h₂ : l + r₂ ≤ 1 ∨ r₂ ≤ delta * l) (H : BalancedSz l r₁) : BalancedSz l r₂ := by refine or_iff_not_imp_left.2 fun h => ?_ refine ⟨?_, h₂.resolve_left h⟩ cases H with | inl H => cases r₂ · cases h (le_trans (Nat.add_le_add_left (Nat.zero_le _) _) H) · exact le_trans (le_trans (Nat.le_add_right _ _) H) (Nat.le_add_left 1 _) | inr H => exact le_trans H.1 (Nat.mul_le_mul_left _ h₁) #align ordnode.balanced_sz_up Ordnode.balancedSz_up theorem balancedSz_down {l r₁ r₂ : ℕ} (h₁ : r₁ ≤ r₂) (h₂ : l + r₂ ≤ 1 ∨ l ≤ delta * r₁) (H : BalancedSz l r₂) : BalancedSz l r₁ := have : l + r₂ ≤ 1 → BalancedSz l r₁ := fun H => Or.inl (le_trans (Nat.add_le_add_left h₁ _) H) Or.casesOn H this fun H => Or.casesOn h₂ this fun h₂ => Or.inr ⟨h₂, le_trans h₁ H.2⟩ #align ordnode.balanced_sz_down Ordnode.balancedSz_down theorem Balanced.dual : ∀ {t : Ordnode α}, Balanced t → Balanced (dual t) | nil, _ => ⟨⟩ | node _ l _ r, ⟨b, bl, br⟩ => ⟨by rw [size_dual, size_dual]; exact b.symm, br.dual, bl.dual⟩ #align ordnode.balanced.dual Ordnode.Balanced.dual /-! ### `rotate` and `balance` -/ /-- Build a tree from three nodes, left associated (ignores the invariants). -/ def node3L (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : Ordnode α := node' (node' l x m) y r #align ordnode.node3_l Ordnode.node3L /-- Build a tree from three nodes, right associated (ignores the invariants). -/ def node3R (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : Ordnode α := node' l x (node' m y r) #align ordnode.node3_r Ordnode.node3R /-- Build a tree from three nodes, with `a () b -> (a ()) b` and `a (b c) d -> ((a b) (c d))`. -/ def node4L : Ordnode α → α → Ordnode α → α → Ordnode α → Ordnode α | l, x, node _ ml y mr, z, r => node' (node' l x ml) y (node' mr z r) | l, x, nil, z, r => node3L l x nil z r #align ordnode.node4_l Ordnode.node4L -- should not happen /-- Build a tree from three nodes, with `a () b -> a (() b)` and `a (b c) d -> ((a b) (c d))`. -/ def node4R : Ordnode α → α → Ordnode α → α → Ordnode α → Ordnode α | l, x, node _ ml y mr, z, r => node' (node' l x ml) y (node' mr z r) | l, x, nil, z, r => node3R l x nil z r #align ordnode.node4_r Ordnode.node4R -- should not happen /-- Concatenate two nodes, performing a left rotation `x (y z) -> ((x y) z)` if balance is upset. -/ def rotateL : Ordnode α → α → Ordnode α → Ordnode α | l, x, node _ m y r => if size m < ratio * size r then node3L l x m y r else node4L l x m y r | l, x, nil => node' l x nil #align ordnode.rotate_l Ordnode.rotateL -- Porting note (#11467): during the port we marked these lemmas with `@[eqns]` -- to emulate the old Lean 3 behaviour. theorem rotateL_node (l : Ordnode α) (x : α) (sz : ℕ) (m : Ordnode α) (y : α) (r : Ordnode α) : rotateL l x (node sz m y r) = if size m < ratio * size r then node3L l x m y r else node4L l x m y r := rfl theorem rotateL_nil (l : Ordnode α) (x : α) : rotateL l x nil = node' l x nil := rfl -- should not happen /-- Concatenate two nodes, performing a right rotation `(x y) z -> (x (y z))` if balance is upset. -/ def rotateR : Ordnode α → α → Ordnode α → Ordnode α | node _ l x m, y, r => if size m < ratio * size l then node3R l x m y r else node4R l x m y r | nil, y, r => node' nil y r #align ordnode.rotate_r Ordnode.rotateR -- Porting note (#11467): during the port we marked these lemmas with `@[eqns]` -- to emulate the old Lean 3 behaviour. theorem rotateR_node (sz : ℕ) (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : rotateR (node sz l x m) y r = if size m < ratio * size l then node3R l x m y r else node4R l x m y r := rfl theorem rotateR_nil (y : α) (r : Ordnode α) : rotateR nil y r = node' nil y r := rfl -- should not happen /-- A left balance operation. This will rebalance a concatenation, assuming the original nodes are not too far from balanced. -/ def balanceL' (l : Ordnode α) (x : α) (r : Ordnode α) : Ordnode α := if size l + size r ≤ 1 then node' l x r else if size l > delta * size r then rotateR l x r else node' l x r #align ordnode.balance_l' Ordnode.balanceL' /-- A right balance operation. This will rebalance a concatenation, assuming the original nodes are not too far from balanced. -/ def balanceR' (l : Ordnode α) (x : α) (r : Ordnode α) : Ordnode α := if size l + size r ≤ 1 then node' l x r else if size r > delta * size l then rotateL l x r else node' l x r #align ordnode.balance_r' Ordnode.balanceR' /-- The full balance operation. This is the same as `balance`, but with less manual inlining. It is somewhat easier to work with this version in proofs. -/ def balance' (l : Ordnode α) (x : α) (r : Ordnode α) : Ordnode α := if size l + size r ≤ 1 then node' l x r else if size r > delta * size l then rotateL l x r else if size l > delta * size r then rotateR l x r else node' l x r #align ordnode.balance' Ordnode.balance' theorem dual_node' (l : Ordnode α) (x : α) (r : Ordnode α) : dual (node' l x r) = node' (dual r) x (dual l) := by simp [node', add_comm] #align ordnode.dual_node' Ordnode.dual_node' theorem dual_node3L (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : dual (node3L l x m y r) = node3R (dual r) y (dual m) x (dual l) := by simp [node3L, node3R, dual_node', add_comm] #align ordnode.dual_node3_l Ordnode.dual_node3L theorem dual_node3R (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : dual (node3R l x m y r) = node3L (dual r) y (dual m) x (dual l) := by simp [node3L, node3R, dual_node', add_comm] #align ordnode.dual_node3_r Ordnode.dual_node3R theorem dual_node4L (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : dual (node4L l x m y r) = node4R (dual r) y (dual m) x (dual l) := by cases m <;> simp [node4L, node4R, node3R, dual_node3L, dual_node', add_comm] #align ordnode.dual_node4_l Ordnode.dual_node4L theorem dual_node4R (l : Ordnode α) (x : α) (m : Ordnode α) (y : α) (r : Ordnode α) : dual (node4R l x m y r) = node4L (dual r) y (dual m) x (dual l) := by cases m <;> simp [node4L, node4R, node3L, dual_node3R, dual_node', add_comm] #align ordnode.dual_node4_r Ordnode.dual_node4R theorem dual_rotateL (l : Ordnode α) (x : α) (r : Ordnode α) : dual (rotateL l x r) = rotateR (dual r) x (dual l) := by cases r <;> simp [rotateL, rotateR, dual_node']; split_ifs <;> simp [dual_node3L, dual_node4L, node3R, add_comm] #align ordnode.dual_rotate_l Ordnode.dual_rotateL theorem dual_rotateR (l : Ordnode α) (x : α) (r : Ordnode α) : dual (rotateR l x r) = rotateL (dual r) x (dual l) := by rw [← dual_dual (rotateL _ _ _), dual_rotateL, dual_dual, dual_dual] #align ordnode.dual_rotate_r Ordnode.dual_rotateR theorem dual_balance' (l : Ordnode α) (x : α) (r : Ordnode α) : dual (balance' l x r) = balance' (dual r) x (dual l) := by simp [balance', add_comm]; split_ifs with h h_1 h_2 <;> simp [dual_node', dual_rotateL, dual_rotateR, add_comm] cases delta_lt_false h_1 h_2 #align ordnode.dual_balance' Ordnode.dual_balance' theorem dual_balanceL (l : Ordnode α) (x : α) (r : Ordnode α) : dual (balanceL l x r) = balanceR (dual r) x (dual l) := by unfold balanceL balanceR cases' r with rs rl rx rr · cases' l with ls ll lx lr; · rfl cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> dsimp only [dual, id] <;> try rfl split_ifs with h <;> repeat simp [h, add_comm] · cases' l with ls ll lx lr; · rfl dsimp only [dual, id] split_ifs; swap; · simp [add_comm] cases' ll with lls lll llx llr <;> cases' lr with lrs lrl lrx lrr <;> try rfl dsimp only [dual, id] split_ifs with h <;> simp [h, add_comm] #align ordnode.dual_balance_l Ordnode.dual_balanceL theorem dual_balanceR (l : Ordnode α) (x : α) (r : Ordnode α) : dual (balanceR l x r) = balanceL (dual r) x (dual l) := by rw [← dual_dual (balanceL _ _ _), dual_balanceL, dual_dual, dual_dual] #align ordnode.dual_balance_r Ordnode.dual_balanceR theorem Sized.node3L {l x m y r} (hl : @Sized α l) (hm : Sized m) (hr : Sized r) : Sized (node3L l x m y r) := (hl.node' hm).node' hr #align ordnode.sized.node3_l Ordnode.Sized.node3L theorem Sized.node3R {l x m y r} (hl : @Sized α l) (hm : Sized m) (hr : Sized r) : Sized (node3R l x m y r) := hl.node' (hm.node' hr) #align ordnode.sized.node3_r Ordnode.Sized.node3R theorem Sized.node4L {l x m y r} (hl : @Sized α l) (hm : Sized m) (hr : Sized r) : Sized (node4L l x m y r) := by cases m <;> [exact (hl.node' hm).node' hr; exact (hl.node' hm.2.1).node' (hm.2.2.node' hr)] #align ordnode.sized.node4_l Ordnode.Sized.node4L theorem node3L_size {l x m y r} : size (@node3L α l x m y r) = size l + size m + size r + 2 := by dsimp [node3L, node', size]; rw [add_right_comm _ 1] #align ordnode.node3_l_size Ordnode.node3L_size theorem node3R_size {l x m y r} : size (@node3R α l x m y r) = size l + size m + size r + 2 := by dsimp [node3R, node', size]; rw [← add_assoc, ← add_assoc] #align ordnode.node3_r_size Ordnode.node3R_size theorem node4L_size {l x m y r} (hm : Sized m) : size (@node4L α l x m y r) = size l + size m + size r + 2 := by cases m <;> simp [node4L, node3L, node'] <;> [abel; (simp [size, hm.1]; abel)] #align ordnode.node4_l_size Ordnode.node4L_size theorem Sized.dual : ∀ {t : Ordnode α}, Sized t → Sized (dual t) | nil, _ => ⟨⟩ | node _ l _ r, ⟨rfl, sl, sr⟩ => ⟨by simp [size_dual, add_comm], Sized.dual sr, Sized.dual sl⟩ #align ordnode.sized.dual Ordnode.Sized.dual theorem Sized.dual_iff {t : Ordnode α} : Sized (.dual t) ↔ Sized t := ⟨fun h => by rw [← dual_dual t]; exact h.dual, Sized.dual⟩ #align ordnode.sized.dual_iff Ordnode.Sized.dual_iff theorem Sized.rotateL {l x r} (hl : @Sized α l) (hr : Sized r) : Sized (rotateL l x r) := by cases r; · exact hl.node' hr rw [Ordnode.rotateL_node]; split_ifs · exact hl.node3L hr.2.1 hr.2.2 · exact hl.node4L hr.2.1 hr.2.2 #align ordnode.sized.rotate_l Ordnode.Sized.rotateL theorem Sized.rotateR {l x r} (hl : @Sized α l) (hr : Sized r) : Sized (rotateR l x r) := Sized.dual_iff.1 <| by rw [dual_rotateR]; exact hr.dual.rotateL hl.dual #align ordnode.sized.rotate_r Ordnode.Sized.rotateR
Mathlib/Data/Ordmap/Ordset.lean
423
427
theorem Sized.rotateL_size {l x r} (hm : Sized r) : size (@Ordnode.rotateL α l x r) = size l + size r + 1 := by
cases r <;> simp [Ordnode.rotateL] simp only [hm.1] split_ifs <;> simp [node3L_size, node4L_size hm.2.1] <;> abel
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.AlgebraicGeometry.Morphisms.QuasiCompact import Mathlib.Topology.QuasiSeparated #align_import algebraic_geometry.morphisms.quasi_separated from "leanprover-community/mathlib"@"1a51edf13debfcbe223fa06b1cb353b9ed9751cc" /-! # Quasi-separated morphisms A morphism of schemes `f : X ⟶ Y` is quasi-separated if the diagonal morphism `X ⟶ X ×[Y] X` is quasi-compact. A scheme is quasi-separated if the intersections of any two affine open sets is quasi-compact. (`AlgebraicGeometry.quasiSeparatedSpace_iff_affine`) We show that a morphism is quasi-separated if the preimage of every affine open is quasi-separated. We also show that this property is local at the target, and is stable under compositions and base-changes. ## Main result - `AlgebraicGeometry.is_localization_basicOpen_of_qcqs` (**Qcqs lemma**): If `U` is qcqs, then `Γ(X, D(f)) ≃ Γ(X, U)_f` for every `f : Γ(X, U)`. -/ noncomputable section open CategoryTheory CategoryTheory.Limits Opposite TopologicalSpace universe u open scoped AlgebraicGeometry namespace AlgebraicGeometry variable {X Y : Scheme.{u}} (f : X ⟶ Y) /-- A morphism is `QuasiSeparated` if diagonal map is quasi-compact. -/ @[mk_iff] class QuasiSeparated (f : X ⟶ Y) : Prop where /-- A morphism is `QuasiSeparated` if diagonal map is quasi-compact. -/ diagonalQuasiCompact : QuasiCompact (pullback.diagonal f) := by infer_instance #align algebraic_geometry.quasi_separated AlgebraicGeometry.QuasiSeparated /-- The `AffineTargetMorphismProperty` corresponding to `QuasiSeparated`, asserting that the domain is a quasi-separated scheme. -/ def QuasiSeparated.affineProperty : AffineTargetMorphismProperty := fun X _ _ _ => QuasiSeparatedSpace X.carrier #align algebraic_geometry.quasi_separated.affine_property AlgebraicGeometry.QuasiSeparated.affineProperty theorem quasiSeparatedSpace_iff_affine (X : Scheme) : QuasiSeparatedSpace X.carrier ↔ ∀ U V : X.affineOpens, IsCompact (U ∩ V : Set X.carrier) := by rw [quasiSeparatedSpace_iff] constructor · intro H U V; exact H U V U.1.2 U.2.isCompact V.1.2 V.2.isCompact · intro H suffices ∀ (U : Opens X.carrier) (_ : IsCompact U.1) (V : Opens X.carrier) (_ : IsCompact V.1), IsCompact (U ⊓ V).1 by intro U V hU hU' hV hV'; exact this ⟨U, hU⟩ hU' ⟨V, hV⟩ hV' intro U hU V hV -- Porting note: it complains "unable to find motive", but telling Lean that motive is -- underscore is actually sufficient, weird apply compact_open_induction_on (P := _) V hV · simp · intro S _ V hV change IsCompact (U.1 ∩ (S.1 ∪ V.1)) rw [Set.inter_union_distrib_left] apply hV.union clear hV apply compact_open_induction_on (P := _) U hU · simp · intro S _ W hW change IsCompact ((S.1 ∪ W.1) ∩ V.1) rw [Set.union_inter_distrib_right] apply hW.union apply H #align algebraic_geometry.quasi_separated_space_iff_affine AlgebraicGeometry.quasiSeparatedSpace_iff_affine theorem quasi_compact_affineProperty_iff_quasiSeparatedSpace {X Y : Scheme} [IsAffine Y] (f : X ⟶ Y) : QuasiCompact.affineProperty.diagonal f ↔ QuasiSeparatedSpace X.carrier := by delta AffineTargetMorphismProperty.diagonal rw [quasiSeparatedSpace_iff_affine] constructor · intro H U V haveI : IsAffine _ := U.2 haveI : IsAffine _ := V.2 let g : pullback (X.ofRestrict U.1.openEmbedding) (X.ofRestrict V.1.openEmbedding) ⟶ X := pullback.fst ≫ X.ofRestrict _ -- Porting note: `inferInstance` does not work here have : IsOpenImmersion g := PresheafedSpace.IsOpenImmersion.comp _ _ have e := Homeomorph.ofEmbedding _ this.base_open.toEmbedding rw [IsOpenImmersion.range_pullback_to_base_of_left] at e erw [Subtype.range_coe, Subtype.range_coe] at e rw [isCompact_iff_compactSpace] exact @Homeomorph.compactSpace _ _ _ _ (H _ _) e · introv H h₁ h₂ let g : pullback f₁ f₂ ⟶ X := pullback.fst ≫ f₁ -- Porting note: `inferInstance` does not work here have : IsOpenImmersion g := PresheafedSpace.IsOpenImmersion.comp _ _ have e := Homeomorph.ofEmbedding _ this.base_open.toEmbedding rw [IsOpenImmersion.range_pullback_to_base_of_left] at e simp_rw [isCompact_iff_compactSpace] at H exact @Homeomorph.compactSpace _ _ _ _ (H ⟨⟨_, h₁.base_open.isOpen_range⟩, rangeIsAffineOpenOfOpenImmersion _⟩ ⟨⟨_, h₂.base_open.isOpen_range⟩, rangeIsAffineOpenOfOpenImmersion _⟩) e.symm #align algebraic_geometry.quasi_compact_affine_property_iff_quasi_separated_space AlgebraicGeometry.quasi_compact_affineProperty_iff_quasiSeparatedSpace theorem quasiSeparated_eq_diagonal_is_quasiCompact : @QuasiSeparated = MorphismProperty.diagonal @QuasiCompact := by ext; exact quasiSeparated_iff _ #align algebraic_geometry.quasi_separated_eq_diagonal_is_quasi_compact AlgebraicGeometry.quasiSeparated_eq_diagonal_is_quasiCompact theorem quasi_compact_affineProperty_diagonal_eq : QuasiCompact.affineProperty.diagonal = QuasiSeparated.affineProperty := by funext; rw [quasi_compact_affineProperty_iff_quasiSeparatedSpace]; rfl #align algebraic_geometry.quasi_compact_affine_property_diagonal_eq AlgebraicGeometry.quasi_compact_affineProperty_diagonal_eq theorem quasiSeparated_eq_affineProperty_diagonal : @QuasiSeparated = targetAffineLocally QuasiCompact.affineProperty.diagonal := by rw [quasiSeparated_eq_diagonal_is_quasiCompact, quasiCompact_eq_affineProperty] exact diagonal_targetAffineLocally_eq_targetAffineLocally _ QuasiCompact.affineProperty_isLocal #align algebraic_geometry.quasi_separated_eq_affine_property_diagonal AlgebraicGeometry.quasiSeparated_eq_affineProperty_diagonal theorem quasiSeparated_eq_affineProperty : @QuasiSeparated = targetAffineLocally QuasiSeparated.affineProperty := by rw [quasiSeparated_eq_affineProperty_diagonal, quasi_compact_affineProperty_diagonal_eq] #align algebraic_geometry.quasi_separated_eq_affine_property AlgebraicGeometry.quasiSeparated_eq_affineProperty theorem QuasiSeparated.affineProperty_isLocal : QuasiSeparated.affineProperty.IsLocal := quasi_compact_affineProperty_diagonal_eq ▸ QuasiCompact.affineProperty_isLocal.diagonal #align algebraic_geometry.quasi_separated.affine_property_is_local AlgebraicGeometry.QuasiSeparated.affineProperty_isLocal instance (priority := 900) quasiSeparatedOfMono {X Y : Scheme} (f : X ⟶ Y) [Mono f] : QuasiSeparated f where #align algebraic_geometry.quasi_separated_of_mono AlgebraicGeometry.quasiSeparatedOfMono instance quasiSeparated_isStableUnderComposition : MorphismProperty.IsStableUnderComposition @QuasiSeparated := quasiSeparated_eq_diagonal_is_quasiCompact.symm ▸ (MorphismProperty.diagonal_isStableUnderComposition quasiCompact_respectsIso quasiCompact_stableUnderBaseChange) #align algebraic_geometry.quasi_separated_stable_under_composition AlgebraicGeometry.quasiSeparated_isStableUnderComposition theorem quasiSeparated_stableUnderBaseChange : MorphismProperty.StableUnderBaseChange @QuasiSeparated := quasiSeparated_eq_diagonal_is_quasiCompact.symm ▸ quasiCompact_stableUnderBaseChange.diagonal quasiCompact_respectsIso #align algebraic_geometry.quasi_separated_stable_under_base_change AlgebraicGeometry.quasiSeparated_stableUnderBaseChange instance quasiSeparatedComp {X Y Z : Scheme} (f : X ⟶ Y) (g : Y ⟶ Z) [QuasiSeparated f] [QuasiSeparated g] : QuasiSeparated (f ≫ g) := MorphismProperty.comp_mem _ f g inferInstance inferInstance #align algebraic_geometry.quasi_separated_comp AlgebraicGeometry.quasiSeparatedComp theorem quasiSeparated_respectsIso : MorphismProperty.RespectsIso @QuasiSeparated := quasiSeparated_eq_diagonal_is_quasiCompact.symm ▸ quasiCompact_respectsIso.diagonal #align algebraic_geometry.quasi_separated_respects_iso AlgebraicGeometry.quasiSeparated_respectsIso open List in theorem QuasiSeparated.affine_openCover_TFAE {X Y : Scheme.{u}} (f : X ⟶ Y) : TFAE [QuasiSeparated f, ∃ (𝒰 : Scheme.OpenCover.{u} Y) (_ : ∀ i, IsAffine (𝒰.obj i)), ∀ i : 𝒰.J, QuasiSeparatedSpace (pullback f (𝒰.map i)).carrier, ∀ (𝒰 : Scheme.OpenCover.{u} Y) [∀ i, IsAffine (𝒰.obj i)] (i : 𝒰.J), QuasiSeparatedSpace (pullback f (𝒰.map i)).carrier, ∀ {U : Scheme} (g : U ⟶ Y) [IsAffine U] [IsOpenImmersion g], QuasiSeparatedSpace (pullback f g).carrier, ∃ (𝒰 : Scheme.OpenCover.{u} Y) (_ : ∀ i, IsAffine (𝒰.obj i)) (𝒰' : ∀ i : 𝒰.J, Scheme.OpenCover.{u} (pullback f (𝒰.map i))) (_ : ∀ i j, IsAffine ((𝒰' i).obj j)), ∀ (i : 𝒰.J) (j k : (𝒰' i).J), CompactSpace (pullback ((𝒰' i).map j) ((𝒰' i).map k)).carrier] := by have := QuasiCompact.affineProperty_isLocal.diagonal_affine_openCover_TFAE f simp_rw [← quasiCompact_eq_affineProperty, ← quasiSeparated_eq_diagonal_is_quasiCompact, quasi_compact_affineProperty_diagonal_eq] at this exact this #align algebraic_geometry.quasi_separated.affine_open_cover_tfae AlgebraicGeometry.QuasiSeparated.affine_openCover_TFAE theorem QuasiSeparated.is_local_at_target : PropertyIsLocalAtTarget @QuasiSeparated := quasiSeparated_eq_affineProperty_diagonal.symm ▸ QuasiCompact.affineProperty_isLocal.diagonal.targetAffineLocallyIsLocal #align algebraic_geometry.quasi_separated.is_local_at_target AlgebraicGeometry.QuasiSeparated.is_local_at_target open List in theorem QuasiSeparated.openCover_TFAE {X Y : Scheme.{u}} (f : X ⟶ Y) : TFAE [QuasiSeparated f, ∃ 𝒰 : Scheme.OpenCover.{u} Y, ∀ i : 𝒰.J, QuasiSeparated (pullback.snd : (𝒰.pullbackCover f).obj i ⟶ 𝒰.obj i), ∀ (𝒰 : Scheme.OpenCover.{u} Y) (i : 𝒰.J), QuasiSeparated (pullback.snd : (𝒰.pullbackCover f).obj i ⟶ 𝒰.obj i), ∀ U : Opens Y.carrier, QuasiSeparated (f ∣_ U), ∀ {U : Scheme} (g : U ⟶ Y) [IsOpenImmersion g], QuasiSeparated (pullback.snd : pullback f g ⟶ _), ∃ (ι : Type u) (U : ι → Opens Y.carrier) (_ : iSup U = ⊤), ∀ i, QuasiSeparated (f ∣_ U i)] := QuasiSeparated.is_local_at_target.openCover_TFAE f #align algebraic_geometry.quasi_separated.open_cover_tfae AlgebraicGeometry.QuasiSeparated.openCover_TFAE theorem quasiSeparated_over_affine_iff {X Y : Scheme} (f : X ⟶ Y) [IsAffine Y] : QuasiSeparated f ↔ QuasiSeparatedSpace X.carrier := by rw [quasiSeparated_eq_affineProperty, QuasiSeparated.affineProperty_isLocal.affine_target_iff f, QuasiSeparated.affineProperty] #align algebraic_geometry.quasi_separated_over_affine_iff AlgebraicGeometry.quasiSeparated_over_affine_iff theorem quasiSeparatedSpace_iff_quasiSeparated (X : Scheme) : QuasiSeparatedSpace X.carrier ↔ QuasiSeparated (terminal.from X) := (quasiSeparated_over_affine_iff _).symm #align algebraic_geometry.quasi_separated_space_iff_quasi_separated AlgebraicGeometry.quasiSeparatedSpace_iff_quasiSeparated theorem QuasiSeparated.affine_openCover_iff {X Y : Scheme.{u}} (𝒰 : Scheme.OpenCover.{u} Y) [∀ i, IsAffine (𝒰.obj i)] (f : X ⟶ Y) : QuasiSeparated f ↔ ∀ i, QuasiSeparatedSpace (pullback f (𝒰.map i)).carrier := by rw [quasiSeparated_eq_affineProperty, QuasiSeparated.affineProperty_isLocal.affine_openCover_iff f 𝒰] rfl #align algebraic_geometry.quasi_separated.affine_open_cover_iff AlgebraicGeometry.QuasiSeparated.affine_openCover_iff theorem QuasiSeparated.openCover_iff {X Y : Scheme.{u}} (𝒰 : Scheme.OpenCover.{u} Y) (f : X ⟶ Y) : QuasiSeparated f ↔ ∀ i, QuasiSeparated (pullback.snd : pullback f (𝒰.map i) ⟶ _) := QuasiSeparated.is_local_at_target.openCover_iff f 𝒰 #align algebraic_geometry.quasi_separated.open_cover_iff AlgebraicGeometry.QuasiSeparated.openCover_iff instance {X Y S : Scheme} (f : X ⟶ S) (g : Y ⟶ S) [QuasiSeparated g] : QuasiSeparated (pullback.fst : pullback f g ⟶ X) := quasiSeparated_stableUnderBaseChange.fst f g inferInstance instance {X Y S : Scheme} (f : X ⟶ S) (g : Y ⟶ S) [QuasiSeparated f] : QuasiSeparated (pullback.snd : pullback f g ⟶ Y) := quasiSeparated_stableUnderBaseChange.snd f g inferInstance instance {X Y Z : Scheme} (f : X ⟶ Y) (g : Y ⟶ Z) [QuasiSeparated f] [QuasiSeparated g] : QuasiSeparated (f ≫ g) := MorphismProperty.comp_mem _ f g inferInstance inferInstance
Mathlib/AlgebraicGeometry/Morphisms/QuasiSeparated.lean
246
251
theorem quasiSeparatedSpace_of_quasiSeparated {X Y : Scheme} (f : X ⟶ Y) [hY : QuasiSeparatedSpace Y.carrier] [QuasiSeparated f] : QuasiSeparatedSpace X.carrier := by
rw [quasiSeparatedSpace_iff_quasiSeparated] at hY ⊢ have : f ≫ terminal.from Y = terminal.from X := terminalIsTerminal.hom_ext _ _ rw [← this] infer_instance
/- Copyright (c) 2022 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Heather Macbeth, Johan Commelin -/ import Mathlib.RingTheory.WittVector.Domain import Mathlib.RingTheory.WittVector.MulCoeff import Mathlib.RingTheory.DiscreteValuationRing.Basic import Mathlib.Tactic.LinearCombination #align_import ring_theory.witt_vector.discrete_valuation_ring from "leanprover-community/mathlib"@"c163ec99dfc664628ca15d215fce0a5b9c265b68" /-! # Witt vectors over a perfect ring This file establishes that Witt vectors over a perfect field are a discrete valuation ring. When `k` is a perfect ring, a nonzero `a : 𝕎 k` can be written as `p^m * b` for some `m : ℕ` and `b : 𝕎 k` with nonzero 0th coefficient. When `k` is also a field, this `b` can be chosen to be a unit of `𝕎 k`. ## Main declarations * `WittVector.exists_eq_pow_p_mul`: the existence of this element `b` over a perfect ring * `WittVector.exists_eq_pow_p_mul'`: the existence of this unit `b` over a perfect field * `WittVector.discreteValuationRing`: `𝕎 k` is a discrete valuation ring if `k` is a perfect field -/ noncomputable section namespace WittVector variable {p : ℕ} [hp : Fact p.Prime] local notation "𝕎" => WittVector p section CommRing variable {k : Type*} [CommRing k] [CharP k p] /-- This is the `n+1`st coefficient of our inverse. -/ def succNthValUnits (n : ℕ) (a : Units k) (A : 𝕎 k) (bs : Fin (n + 1) → k) : k := -↑(a⁻¹ ^ p ^ (n + 1)) * (A.coeff (n + 1) * ↑(a⁻¹ ^ p ^ (n + 1)) + nthRemainder p n (truncateFun (n + 1) A) bs) #align witt_vector.succ_nth_val_units WittVector.succNthValUnits /-- Recursively defines the sequence of coefficients for the inverse to a Witt vector whose first entry is a unit. -/ noncomputable def inverseCoeff (a : Units k) (A : 𝕎 k) : ℕ → k | 0 => ↑a⁻¹ | n + 1 => succNthValUnits n a A fun i => inverseCoeff a A i.val #align witt_vector.inverse_coeff WittVector.inverseCoeff /-- Upgrade a Witt vector `A` whose first entry `A.coeff 0` is a unit to be, itself, a unit in `𝕎 k`. -/ def mkUnit {a : Units k} {A : 𝕎 k} (hA : A.coeff 0 = a) : Units (𝕎 k) := Units.mkOfMulEqOne A (@WittVector.mk' p _ (inverseCoeff a A)) (by ext n induction' n with n _ · simp [WittVector.mul_coeff_zero, inverseCoeff, hA] let H_coeff := A.coeff (n + 1) * ↑(a⁻¹ ^ p ^ (n + 1)) + nthRemainder p n (truncateFun (n + 1) A) fun i : Fin (n + 1) => inverseCoeff a A i have H := Units.mul_inv (a ^ p ^ (n + 1)) linear_combination (norm := skip) -H_coeff * H have ha : (a : k) ^ p ^ (n + 1) = ↑(a ^ p ^ (n + 1)) := by norm_cast have ha_inv : (↑a⁻¹ : k) ^ p ^ (n + 1) = ↑(a ^ p ^ (n + 1))⁻¹ := by norm_cast simp only [nthRemainder_spec, inverseCoeff, succNthValUnits, hA, one_coeff_eq_of_pos, Nat.succ_pos', ha_inv, ha, inv_pow] ring!) #align witt_vector.mk_unit WittVector.mkUnit @[simp] theorem coe_mkUnit {a : Units k} {A : 𝕎 k} (hA : A.coeff 0 = a) : (mkUnit hA : 𝕎 k) = A := rfl #align witt_vector.coe_mk_unit WittVector.coe_mkUnit end CommRing section Field variable {k : Type*} [Field k] [CharP k p]
Mathlib/RingTheory/WittVector/DiscreteValuationRing.lean
88
91
theorem isUnit_of_coeff_zero_ne_zero (x : 𝕎 k) (hx : x.coeff 0 ≠ 0) : IsUnit x := by
let y : kˣ := Units.mk0 (x.coeff 0) hx have hy : x.coeff 0 = y := rfl exact (mkUnit hy).isUnit
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Order.PropInstances #align_import order.heyting.basic from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # Heyting algebras This file defines Heyting, co-Heyting and bi-Heyting algebras. A Heyting algebra is a bounded distributive lattice with an implication operation `⇨` such that `a ≤ b ⇨ c ↔ a ⊓ b ≤ c`. It also comes with a pseudo-complement `ᶜ`, such that `aᶜ = a ⇨ ⊥`. Co-Heyting algebras are dual to Heyting algebras. They have a difference `\` and a negation `¬` such that `a \ b ≤ c ↔ a ≤ b ⊔ c` and `¬a = ⊤ \ a`. Bi-Heyting algebras are Heyting algebras that are also co-Heyting algebras. From a logic standpoint, Heyting algebras precisely model intuitionistic logic, whereas boolean algebras model classical logic. Heyting algebras are the order theoretic equivalent of cartesian-closed categories. ## Main declarations * `GeneralizedHeytingAlgebra`: Heyting algebra without a top element (nor negation). * `GeneralizedCoheytingAlgebra`: Co-Heyting algebra without a bottom element (nor complement). * `HeytingAlgebra`: Heyting algebra. * `CoheytingAlgebra`: Co-Heyting algebra. * `BiheytingAlgebra`: bi-Heyting algebra. ## References * [Francis Borceux, *Handbook of Categorical Algebra III*][borceux-vol3] ## Tags Heyting, Brouwer, algebra, implication, negation, intuitionistic -/ open Function OrderDual universe u variable {ι α β : Type*} /-! ### Notation -/ section variable (α β) instance Prod.instHImp [HImp α] [HImp β] : HImp (α × β) := ⟨fun a b => (a.1 ⇨ b.1, a.2 ⇨ b.2)⟩ instance Prod.instHNot [HNot α] [HNot β] : HNot (α × β) := ⟨fun a => (¬a.1, ¬a.2)⟩ instance Prod.instSDiff [SDiff α] [SDiff β] : SDiff (α × β) := ⟨fun a b => (a.1 \ b.1, a.2 \ b.2)⟩ instance Prod.instHasCompl [HasCompl α] [HasCompl β] : HasCompl (α × β) := ⟨fun a => (a.1ᶜ, a.2ᶜ)⟩ end @[simp] theorem fst_himp [HImp α] [HImp β] (a b : α × β) : (a ⇨ b).1 = a.1 ⇨ b.1 := rfl #align fst_himp fst_himp @[simp] theorem snd_himp [HImp α] [HImp β] (a b : α × β) : (a ⇨ b).2 = a.2 ⇨ b.2 := rfl #align snd_himp snd_himp @[simp] theorem fst_hnot [HNot α] [HNot β] (a : α × β) : (¬a).1 = ¬a.1 := rfl #align fst_hnot fst_hnot @[simp] theorem snd_hnot [HNot α] [HNot β] (a : α × β) : (¬a).2 = ¬a.2 := rfl #align snd_hnot snd_hnot @[simp] theorem fst_sdiff [SDiff α] [SDiff β] (a b : α × β) : (a \ b).1 = a.1 \ b.1 := rfl #align fst_sdiff fst_sdiff @[simp] theorem snd_sdiff [SDiff α] [SDiff β] (a b : α × β) : (a \ b).2 = a.2 \ b.2 := rfl #align snd_sdiff snd_sdiff @[simp] theorem fst_compl [HasCompl α] [HasCompl β] (a : α × β) : aᶜ.1 = a.1ᶜ := rfl #align fst_compl fst_compl @[simp] theorem snd_compl [HasCompl α] [HasCompl β] (a : α × β) : aᶜ.2 = a.2ᶜ := rfl #align snd_compl snd_compl namespace Pi variable {π : ι → Type*} instance [∀ i, HImp (π i)] : HImp (∀ i, π i) := ⟨fun a b i => a i ⇨ b i⟩ instance [∀ i, HNot (π i)] : HNot (∀ i, π i) := ⟨fun a i => ¬a i⟩ theorem himp_def [∀ i, HImp (π i)] (a b : ∀ i, π i) : a ⇨ b = fun i => a i ⇨ b i := rfl #align pi.himp_def Pi.himp_def theorem hnot_def [∀ i, HNot (π i)] (a : ∀ i, π i) : ¬a = fun i => ¬a i := rfl #align pi.hnot_def Pi.hnot_def @[simp] theorem himp_apply [∀ i, HImp (π i)] (a b : ∀ i, π i) (i : ι) : (a ⇨ b) i = a i ⇨ b i := rfl #align pi.himp_apply Pi.himp_apply @[simp] theorem hnot_apply [∀ i, HNot (π i)] (a : ∀ i, π i) (i : ι) : (¬a) i = ¬a i := rfl #align pi.hnot_apply Pi.hnot_apply end Pi /-- A generalized Heyting algebra is a lattice with an additional binary operation `⇨` called Heyting implication such that `a ⇨` is right adjoint to `a ⊓`. This generalizes `HeytingAlgebra` by not requiring a bottom element. -/ class GeneralizedHeytingAlgebra (α : Type*) extends Lattice α, OrderTop α, HImp α where /-- `a ⇨` is right adjoint to `a ⊓` -/ le_himp_iff (a b c : α) : a ≤ b ⇨ c ↔ a ⊓ b ≤ c #align generalized_heyting_algebra GeneralizedHeytingAlgebra #align generalized_heyting_algebra.to_order_top GeneralizedHeytingAlgebra.toOrderTop /-- A generalized co-Heyting algebra is a lattice with an additional binary difference operation `\` such that `\ a` is right adjoint to `⊔ a`. This generalizes `CoheytingAlgebra` by not requiring a top element. -/ class GeneralizedCoheytingAlgebra (α : Type*) extends Lattice α, OrderBot α, SDiff α where /-- `\ a` is right adjoint to `⊔ a` -/ sdiff_le_iff (a b c : α) : a \ b ≤ c ↔ a ≤ b ⊔ c #align generalized_coheyting_algebra GeneralizedCoheytingAlgebra #align generalized_coheyting_algebra.to_order_bot GeneralizedCoheytingAlgebra.toOrderBot /-- A Heyting algebra is a bounded lattice with an additional binary operation `⇨` called Heyting implication such that `a ⇨` is right adjoint to `a ⊓`. -/ class HeytingAlgebra (α : Type*) extends GeneralizedHeytingAlgebra α, OrderBot α, HasCompl α where /-- `a ⇨` is right adjoint to `a ⊓` -/ himp_bot (a : α) : a ⇨ ⊥ = aᶜ #align heyting_algebra HeytingAlgebra /-- A co-Heyting algebra is a bounded lattice with an additional binary difference operation `\` such that `\ a` is right adjoint to `⊔ a`. -/ class CoheytingAlgebra (α : Type*) extends GeneralizedCoheytingAlgebra α, OrderTop α, HNot α where /-- `⊤ \ a` is `¬a` -/ top_sdiff (a : α) : ⊤ \ a = ¬a #align coheyting_algebra CoheytingAlgebra /-- A bi-Heyting algebra is a Heyting algebra that is also a co-Heyting algebra. -/ class BiheytingAlgebra (α : Type*) extends HeytingAlgebra α, SDiff α, HNot α where /-- `\ a` is right adjoint to `⊔ a` -/ sdiff_le_iff (a b c : α) : a \ b ≤ c ↔ a ≤ b ⊔ c /-- `⊤ \ a` is `¬a` -/ top_sdiff (a : α) : ⊤ \ a = ¬a #align biheyting_algebra BiheytingAlgebra -- See note [lower instance priority] attribute [instance 100] GeneralizedHeytingAlgebra.toOrderTop attribute [instance 100] GeneralizedCoheytingAlgebra.toOrderBot -- See note [lower instance priority] instance (priority := 100) HeytingAlgebra.toBoundedOrder [HeytingAlgebra α] : BoundedOrder α := { bot_le := ‹HeytingAlgebra α›.bot_le } --#align heyting_algebra.to_bounded_order HeytingAlgebra.toBoundedOrder -- See note [lower instance priority] instance (priority := 100) CoheytingAlgebra.toBoundedOrder [CoheytingAlgebra α] : BoundedOrder α := { ‹CoheytingAlgebra α› with } #align coheyting_algebra.to_bounded_order CoheytingAlgebra.toBoundedOrder -- See note [lower instance priority] instance (priority := 100) BiheytingAlgebra.toCoheytingAlgebra [BiheytingAlgebra α] : CoheytingAlgebra α := { ‹BiheytingAlgebra α› with } #align biheyting_algebra.to_coheyting_algebra BiheytingAlgebra.toCoheytingAlgebra -- See note [reducible non-instances] /-- Construct a Heyting algebra from the lattice structure and Heyting implication alone. -/ abbrev HeytingAlgebra.ofHImp [DistribLattice α] [BoundedOrder α] (himp : α → α → α) (le_himp_iff : ∀ a b c, a ≤ himp b c ↔ a ⊓ b ≤ c) : HeytingAlgebra α := { ‹DistribLattice α›, ‹BoundedOrder α› with himp, compl := fun a => himp a ⊥, le_himp_iff, himp_bot := fun a => rfl } #align heyting_algebra.of_himp HeytingAlgebra.ofHImp -- See note [reducible non-instances] /-- Construct a Heyting algebra from the lattice structure and complement operator alone. -/ abbrev HeytingAlgebra.ofCompl [DistribLattice α] [BoundedOrder α] (compl : α → α) (le_himp_iff : ∀ a b c, a ≤ compl b ⊔ c ↔ a ⊓ b ≤ c) : HeytingAlgebra α where himp := (compl · ⊔ ·) compl := compl le_himp_iff := le_himp_iff himp_bot _ := sup_bot_eq _ #align heyting_algebra.of_compl HeytingAlgebra.ofCompl -- See note [reducible non-instances] /-- Construct a co-Heyting algebra from the lattice structure and the difference alone. -/ abbrev CoheytingAlgebra.ofSDiff [DistribLattice α] [BoundedOrder α] (sdiff : α → α → α) (sdiff_le_iff : ∀ a b c, sdiff a b ≤ c ↔ a ≤ b ⊔ c) : CoheytingAlgebra α := { ‹DistribLattice α›, ‹BoundedOrder α› with sdiff, hnot := fun a => sdiff ⊤ a, sdiff_le_iff, top_sdiff := fun a => rfl } #align coheyting_algebra.of_sdiff CoheytingAlgebra.ofSDiff -- See note [reducible non-instances] /-- Construct a co-Heyting algebra from the difference and Heyting negation alone. -/ abbrev CoheytingAlgebra.ofHNot [DistribLattice α] [BoundedOrder α] (hnot : α → α) (sdiff_le_iff : ∀ a b c, a ⊓ hnot b ≤ c ↔ a ≤ b ⊔ c) : CoheytingAlgebra α where sdiff a b := a ⊓ hnot b hnot := hnot sdiff_le_iff := sdiff_le_iff top_sdiff _ := top_inf_eq _ #align coheyting_algebra.of_hnot CoheytingAlgebra.ofHNot /-! In this section, we'll give interpretations of these results in the Heyting algebra model of intuitionistic logic,- where `≤` can be interpreted as "validates", `⇨` as "implies", `⊓` as "and", `⊔` as "or", `⊥` as "false" and `⊤` as "true". Note that we confuse `→` and `⊢` because those are the same in this logic. See also `Prop.heytingAlgebra`. -/ section GeneralizedHeytingAlgebra variable [GeneralizedHeytingAlgebra α] {a b c d : α} /-- `p → q → r ↔ p ∧ q → r` -/ @[simp] theorem le_himp_iff : a ≤ b ⇨ c ↔ a ⊓ b ≤ c := GeneralizedHeytingAlgebra.le_himp_iff _ _ _ #align le_himp_iff le_himp_iff /-- `p → q → r ↔ q ∧ p → r` -/ theorem le_himp_iff' : a ≤ b ⇨ c ↔ b ⊓ a ≤ c := by rw [le_himp_iff, inf_comm] #align le_himp_iff' le_himp_iff' /-- `p → q → r ↔ q → p → r` -/ theorem le_himp_comm : a ≤ b ⇨ c ↔ b ≤ a ⇨ c := by rw [le_himp_iff, le_himp_iff'] #align le_himp_comm le_himp_comm /-- `p → q → p` -/ theorem le_himp : a ≤ b ⇨ a := le_himp_iff.2 inf_le_left #align le_himp le_himp /-- `p → p → q ↔ p → q` -/ theorem le_himp_iff_left : a ≤ a ⇨ b ↔ a ≤ b := by rw [le_himp_iff, inf_idem] #align le_himp_iff_left le_himp_iff_left /-- `p → p` -/ @[simp] theorem himp_self : a ⇨ a = ⊤ := top_le_iff.1 <| le_himp_iff.2 inf_le_right #align himp_self himp_self /-- `(p → q) ∧ p → q` -/ theorem himp_inf_le : (a ⇨ b) ⊓ a ≤ b := le_himp_iff.1 le_rfl #align himp_inf_le himp_inf_le /-- `p ∧ (p → q) → q` -/ theorem inf_himp_le : a ⊓ (a ⇨ b) ≤ b := by rw [inf_comm, ← le_himp_iff] #align inf_himp_le inf_himp_le /-- `p ∧ (p → q) ↔ p ∧ q` -/ @[simp] theorem inf_himp (a b : α) : a ⊓ (a ⇨ b) = a ⊓ b := le_antisymm (le_inf inf_le_left <| by rw [inf_comm, ← le_himp_iff]) <| inf_le_inf_left _ le_himp #align inf_himp inf_himp /-- `(p → q) ∧ p ↔ q ∧ p` -/ @[simp] theorem himp_inf_self (a b : α) : (a ⇨ b) ⊓ a = b ⊓ a := by rw [inf_comm, inf_himp, inf_comm] #align himp_inf_self himp_inf_self /-- The **deduction theorem** in the Heyting algebra model of intuitionistic logic: an implication holds iff the conclusion follows from the hypothesis. -/ @[simp] theorem himp_eq_top_iff : a ⇨ b = ⊤ ↔ a ≤ b := by rw [← top_le_iff, le_himp_iff, top_inf_eq] #align himp_eq_top_iff himp_eq_top_iff /-- `p → true`, `true → p ↔ p` -/ @[simp] theorem himp_top : a ⇨ ⊤ = ⊤ := himp_eq_top_iff.2 le_top #align himp_top himp_top @[simp] theorem top_himp : ⊤ ⇨ a = a := eq_of_forall_le_iff fun b => by rw [le_himp_iff, inf_top_eq] #align top_himp top_himp /-- `p → q → r ↔ p ∧ q → r` -/ theorem himp_himp (a b c : α) : a ⇨ b ⇨ c = a ⊓ b ⇨ c := eq_of_forall_le_iff fun d => by simp_rw [le_himp_iff, inf_assoc] #align himp_himp himp_himp /-- `(q → r) → (p → q) → q → r` -/ theorem himp_le_himp_himp_himp : b ⇨ c ≤ (a ⇨ b) ⇨ a ⇨ c := by rw [le_himp_iff, le_himp_iff, inf_assoc, himp_inf_self, ← inf_assoc, himp_inf_self, inf_assoc] exact inf_le_left #align himp_le_himp_himp_himp himp_le_himp_himp_himp @[simp] theorem himp_inf_himp_inf_le : (b ⇨ c) ⊓ (a ⇨ b) ⊓ a ≤ c := by simpa using @himp_le_himp_himp_himp /-- `p → q → r ↔ q → p → r` -/ theorem himp_left_comm (a b c : α) : a ⇨ b ⇨ c = b ⇨ a ⇨ c := by simp_rw [himp_himp, inf_comm] #align himp_left_comm himp_left_comm @[simp] theorem himp_idem : b ⇨ b ⇨ a = b ⇨ a := by rw [himp_himp, inf_idem] #align himp_idem himp_idem theorem himp_inf_distrib (a b c : α) : a ⇨ b ⊓ c = (a ⇨ b) ⊓ (a ⇨ c) := eq_of_forall_le_iff fun d => by simp_rw [le_himp_iff, le_inf_iff, le_himp_iff] #align himp_inf_distrib himp_inf_distrib theorem sup_himp_distrib (a b c : α) : a ⊔ b ⇨ c = (a ⇨ c) ⊓ (b ⇨ c) := eq_of_forall_le_iff fun d => by rw [le_inf_iff, le_himp_comm, sup_le_iff] simp_rw [le_himp_comm] #align sup_himp_distrib sup_himp_distrib theorem himp_le_himp_left (h : a ≤ b) : c ⇨ a ≤ c ⇨ b := le_himp_iff.2 <| himp_inf_le.trans h #align himp_le_himp_left himp_le_himp_left theorem himp_le_himp_right (h : a ≤ b) : b ⇨ c ≤ a ⇨ c := le_himp_iff.2 <| (inf_le_inf_left _ h).trans himp_inf_le #align himp_le_himp_right himp_le_himp_right theorem himp_le_himp (hab : a ≤ b) (hcd : c ≤ d) : b ⇨ c ≤ a ⇨ d := (himp_le_himp_right hab).trans <| himp_le_himp_left hcd #align himp_le_himp himp_le_himp @[simp] theorem sup_himp_self_left (a b : α) : a ⊔ b ⇨ a = b ⇨ a := by rw [sup_himp_distrib, himp_self, top_inf_eq] #align sup_himp_self_left sup_himp_self_left @[simp] theorem sup_himp_self_right (a b : α) : a ⊔ b ⇨ b = a ⇨ b := by rw [sup_himp_distrib, himp_self, inf_top_eq] #align sup_himp_self_right sup_himp_self_right theorem Codisjoint.himp_eq_right (h : Codisjoint a b) : b ⇨ a = a := by conv_rhs => rw [← @top_himp _ _ a] rw [← h.eq_top, sup_himp_self_left] #align codisjoint.himp_eq_right Codisjoint.himp_eq_right theorem Codisjoint.himp_eq_left (h : Codisjoint a b) : a ⇨ b = b := h.symm.himp_eq_right #align codisjoint.himp_eq_left Codisjoint.himp_eq_left theorem Codisjoint.himp_inf_cancel_right (h : Codisjoint a b) : a ⇨ a ⊓ b = b := by rw [himp_inf_distrib, himp_self, top_inf_eq, h.himp_eq_left] #align codisjoint.himp_inf_cancel_right Codisjoint.himp_inf_cancel_right theorem Codisjoint.himp_inf_cancel_left (h : Codisjoint a b) : b ⇨ a ⊓ b = a := by rw [himp_inf_distrib, himp_self, inf_top_eq, h.himp_eq_right] #align codisjoint.himp_inf_cancel_left Codisjoint.himp_inf_cancel_left /-- See `himp_le` for a stronger version in Boolean algebras. -/ theorem Codisjoint.himp_le_of_right_le (hac : Codisjoint a c) (hba : b ≤ a) : c ⇨ b ≤ a := (himp_le_himp_left hba).trans_eq hac.himp_eq_right #align codisjoint.himp_le_of_right_le Codisjoint.himp_le_of_right_le theorem le_himp_himp : a ≤ (a ⇨ b) ⇨ b := le_himp_iff.2 inf_himp_le #align le_himp_himp le_himp_himp @[simp] lemma himp_eq_himp_iff : b ⇨ a = a ⇨ b ↔ a = b := by simp [le_antisymm_iff] lemma himp_ne_himp_iff : b ⇨ a ≠ a ⇨ b ↔ a ≠ b := himp_eq_himp_iff.not theorem himp_triangle (a b c : α) : (a ⇨ b) ⊓ (b ⇨ c) ≤ a ⇨ c := by rw [le_himp_iff, inf_right_comm, ← le_himp_iff] exact himp_inf_le.trans le_himp_himp #align himp_triangle himp_triangle theorem himp_inf_himp_cancel (hba : b ≤ a) (hcb : c ≤ b) : (a ⇨ b) ⊓ (b ⇨ c) = a ⇨ c := (himp_triangle _ _ _).antisymm <| le_inf (himp_le_himp_left hcb) (himp_le_himp_right hba) #align himp_inf_himp_cancel himp_inf_himp_cancel -- See note [lower instance priority] instance (priority := 100) GeneralizedHeytingAlgebra.toDistribLattice : DistribLattice α := DistribLattice.ofInfSupLe fun a b c => by simp_rw [inf_comm a, ← le_himp_iff, sup_le_iff, le_himp_iff, ← sup_le_iff]; rfl #align generalized_heyting_algebra.to_distrib_lattice GeneralizedHeytingAlgebra.toDistribLattice instance OrderDual.instGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra αᵒᵈ where sdiff a b := toDual (ofDual b ⇨ ofDual a) sdiff_le_iff a b c := by rw [sup_comm]; exact le_himp_iff instance Prod.instGeneralizedHeytingAlgebra [GeneralizedHeytingAlgebra β] : GeneralizedHeytingAlgebra (α × β) where le_himp_iff _ _ _ := and_congr le_himp_iff le_himp_iff #align prod.generalized_heyting_algebra Prod.instGeneralizedHeytingAlgebra instance Pi.instGeneralizedHeytingAlgebra {α : ι → Type*} [∀ i, GeneralizedHeytingAlgebra (α i)] : GeneralizedHeytingAlgebra (∀ i, α i) where le_himp_iff i := by simp [le_def] #align pi.generalized_heyting_algebra Pi.instGeneralizedHeytingAlgebra end GeneralizedHeytingAlgebra section GeneralizedCoheytingAlgebra variable [GeneralizedCoheytingAlgebra α] {a b c d : α} @[simp] theorem sdiff_le_iff : a \ b ≤ c ↔ a ≤ b ⊔ c := GeneralizedCoheytingAlgebra.sdiff_le_iff _ _ _ #align sdiff_le_iff sdiff_le_iff theorem sdiff_le_iff' : a \ b ≤ c ↔ a ≤ c ⊔ b := by rw [sdiff_le_iff, sup_comm] #align sdiff_le_iff' sdiff_le_iff' theorem sdiff_le_comm : a \ b ≤ c ↔ a \ c ≤ b := by rw [sdiff_le_iff, sdiff_le_iff'] #align sdiff_le_comm sdiff_le_comm theorem sdiff_le : a \ b ≤ a := sdiff_le_iff.2 le_sup_right #align sdiff_le sdiff_le theorem Disjoint.disjoint_sdiff_left (h : Disjoint a b) : Disjoint (a \ c) b := h.mono_left sdiff_le #align disjoint.disjoint_sdiff_left Disjoint.disjoint_sdiff_left theorem Disjoint.disjoint_sdiff_right (h : Disjoint a b) : Disjoint a (b \ c) := h.mono_right sdiff_le #align disjoint.disjoint_sdiff_right Disjoint.disjoint_sdiff_right theorem sdiff_le_iff_left : a \ b ≤ b ↔ a ≤ b := by rw [sdiff_le_iff, sup_idem] #align sdiff_le_iff_left sdiff_le_iff_left @[simp] theorem sdiff_self : a \ a = ⊥ := le_bot_iff.1 <| sdiff_le_iff.2 le_sup_left #align sdiff_self sdiff_self theorem le_sup_sdiff : a ≤ b ⊔ a \ b := sdiff_le_iff.1 le_rfl #align le_sup_sdiff le_sup_sdiff theorem le_sdiff_sup : a ≤ a \ b ⊔ b := by rw [sup_comm, ← sdiff_le_iff] #align le_sdiff_sup le_sdiff_sup theorem sup_sdiff_left : a ⊔ a \ b = a := sup_of_le_left sdiff_le #align sup_sdiff_left sup_sdiff_left theorem sup_sdiff_right : a \ b ⊔ a = a := sup_of_le_right sdiff_le #align sup_sdiff_right sup_sdiff_right theorem inf_sdiff_left : a \ b ⊓ a = a \ b := inf_of_le_left sdiff_le #align inf_sdiff_left inf_sdiff_left theorem inf_sdiff_right : a ⊓ a \ b = a \ b := inf_of_le_right sdiff_le #align inf_sdiff_right inf_sdiff_right @[simp] theorem sup_sdiff_self (a b : α) : a ⊔ b \ a = a ⊔ b := le_antisymm (sup_le_sup_left sdiff_le _) (sup_le le_sup_left le_sup_sdiff) #align sup_sdiff_self sup_sdiff_self @[simp] theorem sdiff_sup_self (a b : α) : b \ a ⊔ a = b ⊔ a := by rw [sup_comm, sup_sdiff_self, sup_comm] #align sdiff_sup_self sdiff_sup_self alias sup_sdiff_self_left := sdiff_sup_self #align sup_sdiff_self_left sup_sdiff_self_left alias sup_sdiff_self_right := sup_sdiff_self #align sup_sdiff_self_right sup_sdiff_self_right theorem sup_sdiff_eq_sup (h : c ≤ a) : a ⊔ b \ c = a ⊔ b := sup_congr_left (sdiff_le.trans le_sup_right) <| le_sup_sdiff.trans <| sup_le_sup_right h _ #align sup_sdiff_eq_sup sup_sdiff_eq_sup -- cf. `Set.union_diff_cancel'` theorem sup_sdiff_cancel' (hab : a ≤ b) (hbc : b ≤ c) : b ⊔ c \ a = c := by rw [sup_sdiff_eq_sup hab, sup_of_le_right hbc] #align sup_sdiff_cancel' sup_sdiff_cancel' theorem sup_sdiff_cancel_right (h : a ≤ b) : a ⊔ b \ a = b := sup_sdiff_cancel' le_rfl h #align sup_sdiff_cancel_right sup_sdiff_cancel_right theorem sdiff_sup_cancel (h : b ≤ a) : a \ b ⊔ b = a := by rw [sup_comm, sup_sdiff_cancel_right h] #align sdiff_sup_cancel sdiff_sup_cancel theorem sup_le_of_le_sdiff_left (h : b ≤ c \ a) (hac : a ≤ c) : a ⊔ b ≤ c := sup_le hac <| h.trans sdiff_le #align sup_le_of_le_sdiff_left sup_le_of_le_sdiff_left theorem sup_le_of_le_sdiff_right (h : a ≤ c \ b) (hbc : b ≤ c) : a ⊔ b ≤ c := sup_le (h.trans sdiff_le) hbc #align sup_le_of_le_sdiff_right sup_le_of_le_sdiff_right @[simp] theorem sdiff_eq_bot_iff : a \ b = ⊥ ↔ a ≤ b := by rw [← le_bot_iff, sdiff_le_iff, sup_bot_eq] #align sdiff_eq_bot_iff sdiff_eq_bot_iff @[simp] theorem sdiff_bot : a \ ⊥ = a := eq_of_forall_ge_iff fun b => by rw [sdiff_le_iff, bot_sup_eq] #align sdiff_bot sdiff_bot @[simp] theorem bot_sdiff : ⊥ \ a = ⊥ := sdiff_eq_bot_iff.2 bot_le #align bot_sdiff bot_sdiff theorem sdiff_sdiff_sdiff_le_sdiff : (a \ b) \ (a \ c) ≤ c \ b := by rw [sdiff_le_iff, sdiff_le_iff, sup_left_comm, sup_sdiff_self, sup_left_comm, sdiff_sup_self, sup_left_comm] exact le_sup_left #align sdiff_sdiff_sdiff_le_sdiff sdiff_sdiff_sdiff_le_sdiff @[simp] theorem le_sup_sdiff_sup_sdiff : a ≤ b ⊔ (a \ c ⊔ c \ b) := by simpa using @sdiff_sdiff_sdiff_le_sdiff theorem sdiff_sdiff (a b c : α) : (a \ b) \ c = a \ (b ⊔ c) := eq_of_forall_ge_iff fun d => by simp_rw [sdiff_le_iff, sup_assoc] #align sdiff_sdiff sdiff_sdiff theorem sdiff_sdiff_left : (a \ b) \ c = a \ (b ⊔ c) := sdiff_sdiff _ _ _ #align sdiff_sdiff_left sdiff_sdiff_left theorem sdiff_right_comm (a b c : α) : (a \ b) \ c = (a \ c) \ b := by simp_rw [sdiff_sdiff, sup_comm] #align sdiff_right_comm sdiff_right_comm theorem sdiff_sdiff_comm : (a \ b) \ c = (a \ c) \ b := sdiff_right_comm _ _ _ #align sdiff_sdiff_comm sdiff_sdiff_comm @[simp] theorem sdiff_idem : (a \ b) \ b = a \ b := by rw [sdiff_sdiff_left, sup_idem] #align sdiff_idem sdiff_idem @[simp] theorem sdiff_sdiff_self : (a \ b) \ a = ⊥ := by rw [sdiff_sdiff_comm, sdiff_self, bot_sdiff] #align sdiff_sdiff_self sdiff_sdiff_self theorem sup_sdiff_distrib (a b c : α) : (a ⊔ b) \ c = a \ c ⊔ b \ c := eq_of_forall_ge_iff fun d => by simp_rw [sdiff_le_iff, sup_le_iff, sdiff_le_iff] #align sup_sdiff_distrib sup_sdiff_distrib theorem sdiff_inf_distrib (a b c : α) : a \ (b ⊓ c) = a \ b ⊔ a \ c := eq_of_forall_ge_iff fun d => by rw [sup_le_iff, sdiff_le_comm, le_inf_iff] simp_rw [sdiff_le_comm] #align sdiff_inf_distrib sdiff_inf_distrib theorem sup_sdiff : (a ⊔ b) \ c = a \ c ⊔ b \ c := sup_sdiff_distrib _ _ _ #align sup_sdiff sup_sdiff @[simp]
Mathlib/Order/Heyting/Basic.lean
595
595
theorem sup_sdiff_right_self : (a ⊔ b) \ b = a \ b := by
rw [sup_sdiff, sdiff_self, sup_bot_eq]
/- 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.MeasureTheory.Measure.NullMeasurable import Mathlib.MeasureTheory.MeasurableSpace.Basic import Mathlib.Topology.Algebra.Order.LiminfLimsup #align_import measure_theory.measure.measure_space from "leanprover-community/mathlib"@"343e80208d29d2d15f8050b929aa50fe4ce71b55" /-! # Measure spaces The definition of a measure and a measure space are in `MeasureTheory.MeasureSpaceDef`, with only a few basic properties. This file provides many more properties of these objects. This separation allows the measurability tactic to import only the file `MeasureSpaceDef`, and to be available in `MeasureSpace` (through `MeasurableSpace`). Given a measurable space `α`, a measure on `α` is a function that sends measurable sets to the extended nonnegative reals that satisfies the following conditions: 1. `μ ∅ = 0`; 2. `μ` is countably additive. This means that the measure of a countable union of pairwise disjoint sets is equal to the measure of the individual sets. Every measure can be canonically extended to an outer measure, so that it assigns values to all subsets, not just the measurable subsets. On the other hand, a measure that is countably additive on measurable sets can be restricted to measurable sets to obtain a measure. In this file a measure is defined to be an outer measure that is countably additive on measurable sets, with the additional assumption that the outer measure is the canonical extension of the restricted measure. Measures on `α` form a complete lattice, and are closed under scalar multiplication with `ℝ≥0∞`. Given a measure, the null sets are the sets where `μ s = 0`, where `μ` denotes the corresponding outer measure (so `s` might not be measurable). We can then define the completion of `μ` as the measure on the least `σ`-algebra that also contains all null sets, by defining the measure to be `0` on the null sets. ## Main statements * `completion` is the completion of a measure to all null measurable sets. * `Measure.ofMeasurable` and `OuterMeasure.toMeasure` are two important ways to define a measure. ## Implementation notes Given `μ : Measure α`, `μ s` is the value of the *outer measure* applied to `s`. This conveniently allows us to apply the measure to sets without proving that they are measurable. We get countable subadditivity for all sets, but only countable additivity for measurable sets. You often don't want to define a measure via its constructor. Two ways that are sometimes more convenient: * `Measure.ofMeasurable` is a way to define a measure by only giving its value on measurable sets and proving the properties (1) and (2) mentioned above. * `OuterMeasure.toMeasure` is a way of obtaining a measure from an outer measure by showing that all measurable sets in the measurable space are Carathéodory measurable. To prove that two measures are equal, there are multiple options: * `ext`: two measures are equal if they are equal on all measurable sets. * `ext_of_generateFrom_of_iUnion`: two measures are equal if they are equal on a π-system generating the measurable sets, if the π-system contains a spanning increasing sequence of sets where the measures take finite value (in particular the measures are σ-finite). This is a special case of the more general `ext_of_generateFrom_of_cover` * `ext_of_generate_finite`: two finite measures are equal if they are equal on a π-system generating the measurable sets. This is a special case of `ext_of_generateFrom_of_iUnion` using `C ∪ {univ}`, but is easier to work with. A `MeasureSpace` is a class that is a measurable space with a canonical measure. The measure is denoted `volume`. ## References * <https://en.wikipedia.org/wiki/Measure_(mathematics)> * <https://en.wikipedia.org/wiki/Complete_measure> * <https://en.wikipedia.org/wiki/Almost_everywhere> ## Tags measure, almost everywhere, measure space, completion, null set, null measurable set -/ noncomputable section open Set open Filter hiding map open Function MeasurableSpace open scoped Classical symmDiff open Topology Filter ENNReal NNReal Interval MeasureTheory variable {α β γ δ ι R R' : Type*} namespace MeasureTheory section variable {m : MeasurableSpace α} {μ μ₁ μ₂ : Measure α} {s s₁ s₂ t : Set α} instance ae_isMeasurablyGenerated : IsMeasurablyGenerated (ae μ) := ⟨fun _s hs => let ⟨t, hst, htm, htμ⟩ := exists_measurable_superset_of_null hs ⟨tᶜ, compl_mem_ae_iff.2 htμ, htm.compl, compl_subset_comm.1 hst⟩⟩ #align measure_theory.ae_is_measurably_generated MeasureTheory.ae_isMeasurablyGenerated /-- See also `MeasureTheory.ae_restrict_uIoc_iff`. -/ theorem ae_uIoc_iff [LinearOrder α] {a b : α} {P : α → Prop} : (∀ᵐ x ∂μ, x ∈ Ι a b → P x) ↔ (∀ᵐ x ∂μ, x ∈ Ioc a b → P x) ∧ ∀ᵐ x ∂μ, x ∈ Ioc b a → P x := by simp only [uIoc_eq_union, mem_union, or_imp, eventually_and] #align measure_theory.ae_uIoc_iff MeasureTheory.ae_uIoc_iff theorem measure_union (hd : Disjoint s₁ s₂) (h : MeasurableSet s₂) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ := measure_union₀ h.nullMeasurableSet hd.aedisjoint #align measure_theory.measure_union MeasureTheory.measure_union theorem measure_union' (hd : Disjoint s₁ s₂) (h : MeasurableSet s₁) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ := measure_union₀' h.nullMeasurableSet hd.aedisjoint #align measure_theory.measure_union' MeasureTheory.measure_union' theorem measure_inter_add_diff (s : Set α) (ht : MeasurableSet t) : μ (s ∩ t) + μ (s \ t) = μ s := measure_inter_add_diff₀ _ ht.nullMeasurableSet #align measure_theory.measure_inter_add_diff MeasureTheory.measure_inter_add_diff theorem measure_diff_add_inter (s : Set α) (ht : MeasurableSet t) : μ (s \ t) + μ (s ∩ t) = μ s := (add_comm _ _).trans (measure_inter_add_diff s ht) #align measure_theory.measure_diff_add_inter MeasureTheory.measure_diff_add_inter theorem measure_union_add_inter (s : Set α) (ht : MeasurableSet t) : μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by rw [← measure_inter_add_diff (s ∪ t) ht, Set.union_inter_cancel_right, union_diff_right, ← measure_inter_add_diff s ht] ac_rfl #align measure_theory.measure_union_add_inter MeasureTheory.measure_union_add_inter theorem measure_union_add_inter' (hs : MeasurableSet s) (t : Set α) : μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by rw [union_comm, inter_comm, measure_union_add_inter t hs, add_comm] #align measure_theory.measure_union_add_inter' MeasureTheory.measure_union_add_inter' lemma measure_symmDiff_eq (hs : MeasurableSet s) (ht : MeasurableSet t) : μ (s ∆ t) = μ (s \ t) + μ (t \ s) := by simpa only [symmDiff_def, sup_eq_union] using measure_union disjoint_sdiff_sdiff (ht.diff hs) lemma measure_symmDiff_le (s t u : Set α) : μ (s ∆ u) ≤ μ (s ∆ t) + μ (t ∆ u) := le_trans (μ.mono <| symmDiff_triangle s t u) (measure_union_le (s ∆ t) (t ∆ u)) theorem measure_add_measure_compl (h : MeasurableSet s) : μ s + μ sᶜ = μ univ := measure_add_measure_compl₀ h.nullMeasurableSet #align measure_theory.measure_add_measure_compl MeasureTheory.measure_add_measure_compl theorem measure_biUnion₀ {s : Set β} {f : β → Set α} (hs : s.Countable) (hd : s.Pairwise (AEDisjoint μ on f)) (h : ∀ b ∈ s, NullMeasurableSet (f b) μ) : μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) := by haveI := hs.toEncodable rw [biUnion_eq_iUnion] exact measure_iUnion₀ (hd.on_injective Subtype.coe_injective fun x => x.2) fun x => h x x.2 #align measure_theory.measure_bUnion₀ MeasureTheory.measure_biUnion₀ theorem measure_biUnion {s : Set β} {f : β → Set α} (hs : s.Countable) (hd : s.PairwiseDisjoint f) (h : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) := measure_biUnion₀ hs hd.aedisjoint fun b hb => (h b hb).nullMeasurableSet #align measure_theory.measure_bUnion MeasureTheory.measure_biUnion theorem measure_sUnion₀ {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise (AEDisjoint μ)) (h : ∀ s ∈ S, NullMeasurableSet s μ) : μ (⋃₀ S) = ∑' s : S, μ s := by rw [sUnion_eq_biUnion, measure_biUnion₀ hs hd h] #align measure_theory.measure_sUnion₀ MeasureTheory.measure_sUnion₀ theorem measure_sUnion {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise Disjoint) (h : ∀ s ∈ S, MeasurableSet s) : μ (⋃₀ S) = ∑' s : S, μ s := by rw [sUnion_eq_biUnion, measure_biUnion hs hd h] #align measure_theory.measure_sUnion MeasureTheory.measure_sUnion theorem measure_biUnion_finset₀ {s : Finset ι} {f : ι → Set α} (hd : Set.Pairwise (↑s) (AEDisjoint μ on f)) (hm : ∀ b ∈ s, NullMeasurableSet (f b) μ) : μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) := by rw [← Finset.sum_attach, Finset.attach_eq_univ, ← tsum_fintype] exact measure_biUnion₀ s.countable_toSet hd hm #align measure_theory.measure_bUnion_finset₀ MeasureTheory.measure_biUnion_finset₀ theorem measure_biUnion_finset {s : Finset ι} {f : ι → Set α} (hd : PairwiseDisjoint (↑s) f) (hm : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) := measure_biUnion_finset₀ hd.aedisjoint fun b hb => (hm b hb).nullMeasurableSet #align measure_theory.measure_bUnion_finset MeasureTheory.measure_biUnion_finset /-- The measure of an a.e. disjoint union (even uncountable) of null-measurable sets is at least the sum of the measures of the sets. -/ theorem tsum_meas_le_meas_iUnion_of_disjoint₀ {ι : Type*} [MeasurableSpace α] (μ : Measure α) {As : ι → Set α} (As_mble : ∀ i : ι, NullMeasurableSet (As i) μ) (As_disj : Pairwise (AEDisjoint μ on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) := by rw [ENNReal.tsum_eq_iSup_sum, iSup_le_iff] intro s simp only [← measure_biUnion_finset₀ (fun _i _hi _j _hj hij => As_disj hij) fun i _ => As_mble i] gcongr exact iUnion_subset fun _ ↦ Subset.rfl /-- The measure of a disjoint union (even uncountable) of measurable sets is at least the sum of the measures of the sets. -/ theorem tsum_meas_le_meas_iUnion_of_disjoint {ι : Type*} [MeasurableSpace α] (μ : Measure α) {As : ι → Set α} (As_mble : ∀ i : ι, MeasurableSet (As i)) (As_disj : Pairwise (Disjoint on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) := tsum_meas_le_meas_iUnion_of_disjoint₀ μ (fun i ↦ (As_mble i).nullMeasurableSet) (fun _ _ h ↦ Disjoint.aedisjoint (As_disj h)) #align measure_theory.tsum_meas_le_meas_Union_of_disjoint MeasureTheory.tsum_meas_le_meas_iUnion_of_disjoint /-- If `s` is a countable set, then the measure of its preimage can be found as the sum of measures of the fibers `f ⁻¹' {y}`. -/ theorem tsum_measure_preimage_singleton {s : Set β} (hs : s.Countable) {f : α → β} (hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑' b : s, μ (f ⁻¹' {↑b})) = μ (f ⁻¹' s) := by rw [← Set.biUnion_preimage_singleton, measure_biUnion hs (pairwiseDisjoint_fiber f s) hf] #align measure_theory.tsum_measure_preimage_singleton MeasureTheory.tsum_measure_preimage_singleton lemma measure_preimage_eq_zero_iff_of_countable {s : Set β} {f : α → β} (hs : s.Countable) : μ (f ⁻¹' s) = 0 ↔ ∀ x ∈ s, μ (f ⁻¹' {x}) = 0 := by rw [← biUnion_preimage_singleton, measure_biUnion_null_iff hs] /-- If `s` is a `Finset`, then the measure of its preimage can be found as the sum of measures of the fibers `f ⁻¹' {y}`. -/ theorem sum_measure_preimage_singleton (s : Finset β) {f : α → β} (hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑ b ∈ s, μ (f ⁻¹' {b})) = μ (f ⁻¹' ↑s) := by simp only [← measure_biUnion_finset (pairwiseDisjoint_fiber f s) hf, Finset.set_biUnion_preimage_singleton] #align measure_theory.sum_measure_preimage_singleton MeasureTheory.sum_measure_preimage_singleton theorem measure_diff_null' (h : μ (s₁ ∩ s₂) = 0) : μ (s₁ \ s₂) = μ s₁ := measure_congr <| diff_ae_eq_self.2 h #align measure_theory.measure_diff_null' MeasureTheory.measure_diff_null' theorem measure_add_diff (hs : MeasurableSet s) (t : Set α) : μ s + μ (t \ s) = μ (s ∪ t) := by rw [← measure_union' disjoint_sdiff_right hs, union_diff_self] #align measure_theory.measure_add_diff MeasureTheory.measure_add_diff theorem measure_diff' (s : Set α) (hm : MeasurableSet t) (h_fin : μ t ≠ ∞) : μ (s \ t) = μ (s ∪ t) - μ t := Eq.symm <| ENNReal.sub_eq_of_add_eq h_fin <| by rw [add_comm, measure_add_diff hm, union_comm] #align measure_theory.measure_diff' MeasureTheory.measure_diff' theorem measure_diff (h : s₂ ⊆ s₁) (h₂ : MeasurableSet s₂) (h_fin : μ s₂ ≠ ∞) : μ (s₁ \ s₂) = μ s₁ - μ s₂ := by rw [measure_diff' _ h₂ h_fin, union_eq_self_of_subset_right h] #align measure_theory.measure_diff MeasureTheory.measure_diff theorem le_measure_diff : μ s₁ - μ s₂ ≤ μ (s₁ \ s₂) := tsub_le_iff_left.2 <| (measure_le_inter_add_diff μ s₁ s₂).trans <| by gcongr; apply inter_subset_right #align measure_theory.le_measure_diff MeasureTheory.le_measure_diff /-- If the measure of the symmetric difference of two sets is finite, then one has infinite measure if and only if the other one does. -/ theorem measure_eq_top_iff_of_symmDiff (hμst : μ (s ∆ t) ≠ ∞) : μ s = ∞ ↔ μ t = ∞ := by suffices h : ∀ u v, μ (u ∆ v) ≠ ∞ → μ u = ∞ → μ v = ∞ from ⟨h s t hμst, h t s (symmDiff_comm s t ▸ hμst)⟩ intro u v hμuv hμu by_contra! hμv apply hμuv rw [Set.symmDiff_def, eq_top_iff] calc ∞ = μ u - μ v := (WithTop.sub_eq_top_iff.2 ⟨hμu, hμv⟩).symm _ ≤ μ (u \ v) := le_measure_diff _ ≤ μ (u \ v ∪ v \ u) := measure_mono subset_union_left /-- If the measure of the symmetric difference of two sets is finite, then one has finite measure if and only if the other one does. -/ theorem measure_ne_top_iff_of_symmDiff (hμst : μ (s ∆ t) ≠ ∞) : μ s ≠ ∞ ↔ μ t ≠ ∞ := (measure_eq_top_iff_of_symmDiff hμst).ne theorem measure_diff_lt_of_lt_add (hs : MeasurableSet s) (hst : s ⊆ t) (hs' : μ s ≠ ∞) {ε : ℝ≥0∞} (h : μ t < μ s + ε) : μ (t \ s) < ε := by rw [measure_diff hst hs hs']; rw [add_comm] at h exact ENNReal.sub_lt_of_lt_add (measure_mono hst) h #align measure_theory.measure_diff_lt_of_lt_add MeasureTheory.measure_diff_lt_of_lt_add theorem measure_diff_le_iff_le_add (hs : MeasurableSet s) (hst : s ⊆ t) (hs' : μ s ≠ ∞) {ε : ℝ≥0∞} : μ (t \ s) ≤ ε ↔ μ t ≤ μ s + ε := by rw [measure_diff hst hs hs', tsub_le_iff_left] #align measure_theory.measure_diff_le_iff_le_add MeasureTheory.measure_diff_le_iff_le_add theorem measure_eq_measure_of_null_diff {s t : Set α} (hst : s ⊆ t) (h_nulldiff : μ (t \ s) = 0) : μ s = μ t := measure_congr <| EventuallyLE.antisymm (HasSubset.Subset.eventuallyLE hst) (ae_le_set.mpr h_nulldiff) #align measure_theory.measure_eq_measure_of_null_diff MeasureTheory.measure_eq_measure_of_null_diff theorem measure_eq_measure_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₁ = μ s₂ ∧ μ s₂ = μ s₃ := by have le12 : μ s₁ ≤ μ s₂ := measure_mono h12 have le23 : μ s₂ ≤ μ s₃ := measure_mono h23 have key : μ s₃ ≤ μ s₁ := calc μ s₃ = μ (s₃ \ s₁ ∪ s₁) := by rw [diff_union_of_subset (h12.trans h23)] _ ≤ μ (s₃ \ s₁) + μ s₁ := measure_union_le _ _ _ = μ s₁ := by simp only [h_nulldiff, zero_add] exact ⟨le12.antisymm (le23.trans key), le23.antisymm (key.trans le12)⟩ #align measure_theory.measure_eq_measure_of_between_null_diff MeasureTheory.measure_eq_measure_of_between_null_diff theorem measure_eq_measure_smaller_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₁ = μ s₂ := (measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).1 #align measure_theory.measure_eq_measure_smaller_of_between_null_diff MeasureTheory.measure_eq_measure_smaller_of_between_null_diff theorem measure_eq_measure_larger_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₂ = μ s₃ := (measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).2 #align measure_theory.measure_eq_measure_larger_of_between_null_diff MeasureTheory.measure_eq_measure_larger_of_between_null_diff lemma measure_compl₀ (h : NullMeasurableSet s μ) (hs : μ s ≠ ∞) : μ sᶜ = μ Set.univ - μ s := by rw [← measure_add_measure_compl₀ h, ENNReal.add_sub_cancel_left hs] theorem measure_compl (h₁ : MeasurableSet s) (h_fin : μ s ≠ ∞) : μ sᶜ = μ univ - μ s := measure_compl₀ h₁.nullMeasurableSet h_fin #align measure_theory.measure_compl MeasureTheory.measure_compl lemma measure_inter_conull' (ht : μ (s \ t) = 0) : μ (s ∩ t) = μ s := by rw [← diff_compl, measure_diff_null']; rwa [← diff_eq] lemma measure_inter_conull (ht : μ tᶜ = 0) : μ (s ∩ t) = μ s := by rw [← diff_compl, measure_diff_null ht] @[simp] theorem union_ae_eq_left_iff_ae_subset : (s ∪ t : Set α) =ᵐ[μ] s ↔ t ≤ᵐ[μ] s := by rw [ae_le_set] refine ⟨fun h => by simpa only [union_diff_left] using (ae_eq_set.mp h).1, fun h => eventuallyLE_antisymm_iff.mpr ⟨by rwa [ae_le_set, union_diff_left], HasSubset.Subset.eventuallyLE subset_union_left⟩⟩ #align measure_theory.union_ae_eq_left_iff_ae_subset MeasureTheory.union_ae_eq_left_iff_ae_subset @[simp] theorem union_ae_eq_right_iff_ae_subset : (s ∪ t : Set α) =ᵐ[μ] t ↔ s ≤ᵐ[μ] t := by rw [union_comm, union_ae_eq_left_iff_ae_subset] #align measure_theory.union_ae_eq_right_iff_ae_subset MeasureTheory.union_ae_eq_right_iff_ae_subset theorem ae_eq_of_ae_subset_of_measure_ge (h₁ : s ≤ᵐ[μ] t) (h₂ : μ t ≤ μ s) (hsm : MeasurableSet s) (ht : μ t ≠ ∞) : s =ᵐ[μ] t := by refine eventuallyLE_antisymm_iff.mpr ⟨h₁, ae_le_set.mpr ?_⟩ replace h₂ : μ t = μ s := h₂.antisymm (measure_mono_ae h₁) replace ht : μ s ≠ ∞ := h₂ ▸ ht rw [measure_diff' t hsm ht, measure_congr (union_ae_eq_left_iff_ae_subset.mpr h₁), h₂, tsub_self] #align measure_theory.ae_eq_of_ae_subset_of_measure_ge MeasureTheory.ae_eq_of_ae_subset_of_measure_ge /-- If `s ⊆ t`, `μ t ≤ μ s`, `μ t ≠ ∞`, and `s` is measurable, then `s =ᵐ[μ] t`. -/ theorem ae_eq_of_subset_of_measure_ge (h₁ : s ⊆ t) (h₂ : μ t ≤ μ s) (hsm : MeasurableSet s) (ht : μ t ≠ ∞) : s =ᵐ[μ] t := ae_eq_of_ae_subset_of_measure_ge (HasSubset.Subset.eventuallyLE h₁) h₂ hsm ht #align measure_theory.ae_eq_of_subset_of_measure_ge MeasureTheory.ae_eq_of_subset_of_measure_ge theorem measure_iUnion_congr_of_subset [Countable β] {s : β → Set α} {t : β → Set α} (hsub : ∀ b, s b ⊆ t b) (h_le : ∀ b, μ (t b) ≤ μ (s b)) : μ (⋃ b, s b) = μ (⋃ b, t b) := by rcases Classical.em (∃ b, μ (t b) = ∞) with (⟨b, hb⟩ | htop) · calc μ (⋃ b, s b) = ∞ := top_unique (hb ▸ (h_le b).trans <| measure_mono <| subset_iUnion _ _) _ = μ (⋃ b, t b) := Eq.symm <| top_unique <| hb ▸ measure_mono (subset_iUnion _ _) push_neg at htop refine le_antisymm (measure_mono (iUnion_mono hsub)) ?_ set M := toMeasurable μ have H : ∀ b, (M (t b) ∩ M (⋃ b, s b) : Set α) =ᵐ[μ] M (t b) := by refine fun b => ae_eq_of_subset_of_measure_ge inter_subset_left ?_ ?_ ?_ · calc μ (M (t b)) = μ (t b) := measure_toMeasurable _ _ ≤ μ (s b) := h_le b _ ≤ μ (M (t b) ∩ M (⋃ b, s b)) := measure_mono <| subset_inter ((hsub b).trans <| subset_toMeasurable _ _) ((subset_iUnion _ _).trans <| subset_toMeasurable _ _) · exact (measurableSet_toMeasurable _ _).inter (measurableSet_toMeasurable _ _) · rw [measure_toMeasurable] exact htop b calc μ (⋃ b, t b) ≤ μ (⋃ b, M (t b)) := measure_mono (iUnion_mono fun b => subset_toMeasurable _ _) _ = μ (⋃ b, M (t b) ∩ M (⋃ b, s b)) := measure_congr (EventuallyEq.countable_iUnion H).symm _ ≤ μ (M (⋃ b, s b)) := measure_mono (iUnion_subset fun b => inter_subset_right) _ = μ (⋃ b, s b) := measure_toMeasurable _ #align measure_theory.measure_Union_congr_of_subset MeasureTheory.measure_iUnion_congr_of_subset theorem measure_union_congr_of_subset {t₁ t₂ : Set α} (hs : s₁ ⊆ s₂) (hsμ : μ s₂ ≤ μ s₁) (ht : t₁ ⊆ t₂) (htμ : μ t₂ ≤ μ t₁) : μ (s₁ ∪ t₁) = μ (s₂ ∪ t₂) := by rw [union_eq_iUnion, union_eq_iUnion] exact measure_iUnion_congr_of_subset (Bool.forall_bool.2 ⟨ht, hs⟩) (Bool.forall_bool.2 ⟨htμ, hsμ⟩) #align measure_theory.measure_union_congr_of_subset MeasureTheory.measure_union_congr_of_subset @[simp] theorem measure_iUnion_toMeasurable [Countable β] (s : β → Set α) : μ (⋃ b, toMeasurable μ (s b)) = μ (⋃ b, s b) := Eq.symm <| measure_iUnion_congr_of_subset (fun _b => subset_toMeasurable _ _) fun _b => (measure_toMeasurable _).le #align measure_theory.measure_Union_to_measurable MeasureTheory.measure_iUnion_toMeasurable theorem measure_biUnion_toMeasurable {I : Set β} (hc : I.Countable) (s : β → Set α) : μ (⋃ b ∈ I, toMeasurable μ (s b)) = μ (⋃ b ∈ I, s b) := by haveI := hc.toEncodable simp only [biUnion_eq_iUnion, measure_iUnion_toMeasurable] #align measure_theory.measure_bUnion_to_measurable MeasureTheory.measure_biUnion_toMeasurable @[simp] theorem measure_toMeasurable_union : μ (toMeasurable μ s ∪ t) = μ (s ∪ t) := Eq.symm <| measure_union_congr_of_subset (subset_toMeasurable _ _) (measure_toMeasurable _).le Subset.rfl le_rfl #align measure_theory.measure_to_measurable_union MeasureTheory.measure_toMeasurable_union @[simp] theorem measure_union_toMeasurable : μ (s ∪ toMeasurable μ t) = μ (s ∪ t) := Eq.symm <| measure_union_congr_of_subset Subset.rfl le_rfl (subset_toMeasurable _ _) (measure_toMeasurable _).le #align measure_theory.measure_union_to_measurable MeasureTheory.measure_union_toMeasurable theorem sum_measure_le_measure_univ {s : Finset ι} {t : ι → Set α} (h : ∀ i ∈ s, MeasurableSet (t i)) (H : Set.PairwiseDisjoint (↑s) t) : (∑ i ∈ s, μ (t i)) ≤ μ (univ : Set α) := by rw [← measure_biUnion_finset H h] exact measure_mono (subset_univ _) #align measure_theory.sum_measure_le_measure_univ MeasureTheory.sum_measure_le_measure_univ theorem tsum_measure_le_measure_univ {s : ι → Set α} (hs : ∀ i, MeasurableSet (s i)) (H : Pairwise (Disjoint on s)) : (∑' i, μ (s i)) ≤ μ (univ : Set α) := by rw [ENNReal.tsum_eq_iSup_sum] exact iSup_le fun s => sum_measure_le_measure_univ (fun i _hi => hs i) fun i _hi j _hj hij => H hij #align measure_theory.tsum_measure_le_measure_univ MeasureTheory.tsum_measure_le_measure_univ /-- Pigeonhole principle for measure spaces: if `∑' i, μ (s i) > μ univ`, then one of the intersections `s i ∩ s j` is not empty. -/ theorem exists_nonempty_inter_of_measure_univ_lt_tsum_measure {m : MeasurableSpace α} (μ : Measure α) {s : ι → Set α} (hs : ∀ i, MeasurableSet (s i)) (H : μ (univ : Set α) < ∑' i, μ (s i)) : ∃ i j, i ≠ j ∧ (s i ∩ s j).Nonempty := by contrapose! H apply tsum_measure_le_measure_univ hs intro i j hij exact disjoint_iff_inter_eq_empty.mpr (H i j hij) #align measure_theory.exists_nonempty_inter_of_measure_univ_lt_tsum_measure MeasureTheory.exists_nonempty_inter_of_measure_univ_lt_tsum_measure /-- Pigeonhole principle for measure spaces: if `s` is a `Finset` and `∑ i ∈ s, μ (t i) > μ univ`, then one of the intersections `t i ∩ t j` is not empty. -/ theorem exists_nonempty_inter_of_measure_univ_lt_sum_measure {m : MeasurableSpace α} (μ : Measure α) {s : Finset ι} {t : ι → Set α} (h : ∀ i ∈ s, MeasurableSet (t i)) (H : μ (univ : Set α) < ∑ i ∈ s, μ (t i)) : ∃ i ∈ s, ∃ j ∈ s, ∃ _h : i ≠ j, (t i ∩ t j).Nonempty := by contrapose! H apply sum_measure_le_measure_univ h intro i hi j hj hij exact disjoint_iff_inter_eq_empty.mpr (H i hi j hj hij) #align measure_theory.exists_nonempty_inter_of_measure_univ_lt_sum_measure MeasureTheory.exists_nonempty_inter_of_measure_univ_lt_sum_measure /-- If two sets `s` and `t` are included in a set `u`, and `μ s + μ t > μ u`, then `s` intersects `t`. Version assuming that `t` is measurable. -/ theorem nonempty_inter_of_measure_lt_add {m : MeasurableSpace α} (μ : Measure α) {s t u : Set α} (ht : MeasurableSet t) (h's : s ⊆ u) (h't : t ⊆ u) (h : μ u < μ s + μ t) : (s ∩ t).Nonempty := by rw [← Set.not_disjoint_iff_nonempty_inter] contrapose! h calc μ s + μ t = μ (s ∪ t) := (measure_union h ht).symm _ ≤ μ u := measure_mono (union_subset h's h't) #align measure_theory.nonempty_inter_of_measure_lt_add MeasureTheory.nonempty_inter_of_measure_lt_add /-- If two sets `s` and `t` are included in a set `u`, and `μ s + μ t > μ u`, then `s` intersects `t`. Version assuming that `s` is measurable. -/ theorem nonempty_inter_of_measure_lt_add' {m : MeasurableSpace α} (μ : Measure α) {s t u : Set α} (hs : MeasurableSet s) (h's : s ⊆ u) (h't : t ⊆ u) (h : μ u < μ s + μ t) : (s ∩ t).Nonempty := by rw [add_comm] at h rw [inter_comm] exact nonempty_inter_of_measure_lt_add μ hs h't h's h #align measure_theory.nonempty_inter_of_measure_lt_add' MeasureTheory.nonempty_inter_of_measure_lt_add' /-- Continuity from below: the measure of the union of a directed sequence of (not necessarily -measurable) sets is the supremum of the measures. -/ theorem measure_iUnion_eq_iSup [Countable ι] {s : ι → Set α} (hd : Directed (· ⊆ ·) s) : μ (⋃ i, s i) = ⨆ i, μ (s i) := by cases nonempty_encodable ι -- WLOG, `ι = ℕ` generalize ht : Function.extend Encodable.encode s ⊥ = t replace hd : Directed (· ⊆ ·) t := ht ▸ hd.extend_bot Encodable.encode_injective suffices μ (⋃ n, t n) = ⨆ n, μ (t n) by simp only [← ht, Function.apply_extend μ, ← iSup_eq_iUnion, iSup_extend_bot Encodable.encode_injective, (· ∘ ·), Pi.bot_apply, bot_eq_empty, measure_empty] at this exact this.trans (iSup_extend_bot Encodable.encode_injective _) clear! ι -- The `≥` inequality is trivial refine le_antisymm ?_ (iSup_le fun i => measure_mono <| subset_iUnion _ _) -- Choose `T n ⊇ t n` of the same measure, put `Td n = disjointed T` set T : ℕ → Set α := fun n => toMeasurable μ (t n) set Td : ℕ → Set α := disjointed T have hm : ∀ n, MeasurableSet (Td n) := MeasurableSet.disjointed fun n => measurableSet_toMeasurable _ _ calc μ (⋃ n, t n) ≤ μ (⋃ n, T n) := measure_mono (iUnion_mono fun i => subset_toMeasurable _ _) _ = μ (⋃ n, Td n) := by rw [iUnion_disjointed] _ ≤ ∑' n, μ (Td n) := measure_iUnion_le _ _ = ⨆ I : Finset ℕ, ∑ n ∈ I, μ (Td n) := ENNReal.tsum_eq_iSup_sum _ ≤ ⨆ n, μ (t n) := iSup_le fun I => by rcases hd.finset_le I with ⟨N, hN⟩ calc (∑ n ∈ I, μ (Td n)) = μ (⋃ n ∈ I, Td n) := (measure_biUnion_finset ((disjoint_disjointed T).set_pairwise I) fun n _ => hm n).symm _ ≤ μ (⋃ n ∈ I, T n) := measure_mono (iUnion₂_mono fun n _hn => disjointed_subset _ _) _ = μ (⋃ n ∈ I, t n) := measure_biUnion_toMeasurable I.countable_toSet _ _ ≤ μ (t N) := measure_mono (iUnion₂_subset hN) _ ≤ ⨆ n, μ (t n) := le_iSup (μ ∘ t) N #align measure_theory.measure_Union_eq_supr MeasureTheory.measure_iUnion_eq_iSup /-- Continuity from below: the measure of the union of a sequence of (not necessarily measurable) sets is the supremum of the measures of the partial unions. -/ theorem measure_iUnion_eq_iSup' {α ι : Type*} [MeasurableSpace α] {μ : Measure α} [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] {f : ι → Set α} : μ (⋃ i, f i) = ⨆ i, μ (Accumulate f i) := by have hd : Directed (· ⊆ ·) (Accumulate f) := by intro i j rcases directed_of (· ≤ ·) i j with ⟨k, rik, rjk⟩ exact ⟨k, biUnion_subset_biUnion_left fun l rli ↦ le_trans rli rik, biUnion_subset_biUnion_left fun l rlj ↦ le_trans rlj rjk⟩ rw [← iUnion_accumulate] exact measure_iUnion_eq_iSup hd theorem measure_biUnion_eq_iSup {s : ι → Set α} {t : Set ι} (ht : t.Countable) (hd : DirectedOn ((· ⊆ ·) on s) t) : μ (⋃ i ∈ t, s i) = ⨆ i ∈ t, μ (s i) := by haveI := ht.toEncodable rw [biUnion_eq_iUnion, measure_iUnion_eq_iSup hd.directed_val, ← iSup_subtype''] #align measure_theory.measure_bUnion_eq_supr MeasureTheory.measure_biUnion_eq_iSup /-- Continuity from above: the measure of the intersection of a decreasing sequence of measurable sets is the infimum of the measures. -/ theorem measure_iInter_eq_iInf [Countable ι] {s : ι → Set α} (h : ∀ i, MeasurableSet (s i)) (hd : Directed (· ⊇ ·) s) (hfin : ∃ i, μ (s i) ≠ ∞) : μ (⋂ i, s i) = ⨅ i, μ (s i) := by rcases hfin with ⟨k, hk⟩ have : ∀ t ⊆ s k, μ t ≠ ∞ := fun t ht => ne_top_of_le_ne_top hk (measure_mono ht) rw [← ENNReal.sub_sub_cancel hk (iInf_le _ k), ENNReal.sub_iInf, ← ENNReal.sub_sub_cancel hk (measure_mono (iInter_subset _ k)), ← measure_diff (iInter_subset _ k) (MeasurableSet.iInter h) (this _ (iInter_subset _ k)), diff_iInter, measure_iUnion_eq_iSup] · congr 1 refine le_antisymm (iSup_mono' fun i => ?_) (iSup_mono fun i => ?_) · rcases hd i k with ⟨j, hji, hjk⟩ use j rw [← measure_diff hjk (h _) (this _ hjk)] gcongr · rw [tsub_le_iff_right, ← measure_union, Set.union_comm] · exact measure_mono (diff_subset_iff.1 Subset.rfl) · apply disjoint_sdiff_left · apply h i · exact hd.mono_comp _ fun _ _ => diff_subset_diff_right #align measure_theory.measure_Inter_eq_infi MeasureTheory.measure_iInter_eq_iInf /-- Continuity from above: the measure of the intersection of a sequence of measurable sets is the infimum of the measures of the partial intersections. -/ theorem measure_iInter_eq_iInf' {α ι : Type*} [MeasurableSpace α] {μ : Measure α} [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] {f : ι → Set α} (h : ∀ i, MeasurableSet (f i)) (hfin : ∃ i, μ (f i) ≠ ∞) : μ (⋂ i, f i) = ⨅ i, μ (⋂ j ≤ i, f j) := by let s := fun i ↦ ⋂ j ≤ i, f j have iInter_eq : ⋂ i, f i = ⋂ i, s i := by ext x; simp [s]; constructor · exact fun h _ j _ ↦ h j · intro h i rcases directed_of (· ≤ ·) i i with ⟨j, rij, -⟩ exact h j i rij have ms : ∀ i, MeasurableSet (s i) := fun i ↦ MeasurableSet.biInter (countable_univ.mono <| subset_univ _) fun i _ ↦ h i have hd : Directed (· ⊇ ·) s := by intro i j rcases directed_of (· ≤ ·) i j with ⟨k, rik, rjk⟩ exact ⟨k, biInter_subset_biInter_left fun j rji ↦ le_trans rji rik, biInter_subset_biInter_left fun i rij ↦ le_trans rij rjk⟩ have hfin' : ∃ i, μ (s i) ≠ ∞ := by rcases hfin with ⟨i, hi⟩ rcases directed_of (· ≤ ·) i i with ⟨j, rij, -⟩ exact ⟨j, ne_top_of_le_ne_top hi <| measure_mono <| biInter_subset_of_mem rij⟩ exact iInter_eq ▸ measure_iInter_eq_iInf ms hd hfin' /-- Continuity from below: the measure of the union of an increasing sequence of (not necessarily measurable) sets is the limit of the measures. -/ theorem tendsto_measure_iUnion [Preorder ι] [IsDirected ι (· ≤ ·)] [Countable ι] {s : ι → Set α} (hm : Monotone s) : Tendsto (μ ∘ s) atTop (𝓝 (μ (⋃ n, s n))) := by rw [measure_iUnion_eq_iSup hm.directed_le] exact tendsto_atTop_iSup fun n m hnm => measure_mono <| hm hnm #align measure_theory.tendsto_measure_Union MeasureTheory.tendsto_measure_iUnion /-- Continuity from below: the measure of the union of a sequence of (not necessarily measurable) sets is the limit of the measures of the partial unions. -/ theorem tendsto_measure_iUnion' {α ι : Type*} [MeasurableSpace α] {μ : Measure α} [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] {f : ι → Set α} : Tendsto (fun i ↦ μ (Accumulate f i)) atTop (𝓝 (μ (⋃ i, f i))) := by rw [measure_iUnion_eq_iSup'] exact tendsto_atTop_iSup fun i j hij ↦ by gcongr /-- Continuity from above: the measure of the intersection of a decreasing sequence of measurable sets is the limit of the measures. -/ theorem tendsto_measure_iInter [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] {s : ι → Set α} (hs : ∀ n, MeasurableSet (s n)) (hm : Antitone s) (hf : ∃ i, μ (s i) ≠ ∞) : Tendsto (μ ∘ s) atTop (𝓝 (μ (⋂ n, s n))) := by rw [measure_iInter_eq_iInf hs hm.directed_ge hf] exact tendsto_atTop_iInf fun n m hnm => measure_mono <| hm hnm #align measure_theory.tendsto_measure_Inter MeasureTheory.tendsto_measure_iInter /-- Continuity from above: the measure of the intersection of a sequence of measurable sets such that one has finite measure is the limit of the measures of the partial intersections. -/ theorem tendsto_measure_iInter' {α ι : Type*} [MeasurableSpace α] {μ : Measure α} [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] {f : ι → Set α} (hm : ∀ i, MeasurableSet (f i)) (hf : ∃ i, μ (f i) ≠ ∞) : Tendsto (fun i ↦ μ (⋂ j ∈ {j | j ≤ i}, f j)) atTop (𝓝 (μ (⋂ i, f i))) := by rw [measure_iInter_eq_iInf' hm hf] exact tendsto_atTop_iInf fun i j hij ↦ measure_mono <| biInter_subset_biInter_left fun k hki ↦ le_trans hki hij /-- The measure of the intersection of a decreasing sequence of measurable sets indexed by a linear order with first countable topology is the limit of the measures. -/ theorem tendsto_measure_biInter_gt {ι : Type*} [LinearOrder ι] [TopologicalSpace ι] [OrderTopology ι] [DenselyOrdered ι] [FirstCountableTopology ι] {s : ι → Set α} {a : ι} (hs : ∀ r > a, MeasurableSet (s r)) (hm : ∀ i j, a < i → i ≤ j → s i ⊆ s j) (hf : ∃ r > a, μ (s r) ≠ ∞) : Tendsto (μ ∘ s) (𝓝[Ioi a] a) (𝓝 (μ (⋂ r > a, s r))) := by refine tendsto_order.2 ⟨fun l hl => ?_, fun L hL => ?_⟩ · filter_upwards [self_mem_nhdsWithin (s := Ioi a)] with r hr using hl.trans_le (measure_mono (biInter_subset_of_mem hr)) obtain ⟨u, u_anti, u_pos, u_lim⟩ : ∃ u : ℕ → ι, StrictAnti u ∧ (∀ n : ℕ, a < u n) ∧ Tendsto u atTop (𝓝 a) := by rcases hf with ⟨r, ar, _⟩ rcases exists_seq_strictAnti_tendsto' ar with ⟨w, w_anti, w_mem, w_lim⟩ exact ⟨w, w_anti, fun n => (w_mem n).1, w_lim⟩ have A : Tendsto (μ ∘ s ∘ u) atTop (𝓝 (μ (⋂ n, s (u n)))) := by refine tendsto_measure_iInter (fun n => hs _ (u_pos n)) ?_ ?_ · intro m n hmn exact hm _ _ (u_pos n) (u_anti.antitone hmn) · rcases hf with ⟨r, rpos, hr⟩ obtain ⟨n, hn⟩ : ∃ n : ℕ, u n < r := ((tendsto_order.1 u_lim).2 r rpos).exists refine ⟨n, ne_of_lt (lt_of_le_of_lt ?_ hr.lt_top)⟩ exact measure_mono (hm _ _ (u_pos n) hn.le) have B : ⋂ n, s (u n) = ⋂ r > a, s r := by apply Subset.antisymm · simp only [subset_iInter_iff, gt_iff_lt] intro r rpos obtain ⟨n, hn⟩ : ∃ n, u n < r := ((tendsto_order.1 u_lim).2 _ rpos).exists exact Subset.trans (iInter_subset _ n) (hm (u n) r (u_pos n) hn.le) · simp only [subset_iInter_iff, gt_iff_lt] intro n apply biInter_subset_of_mem exact u_pos n rw [B] at A obtain ⟨n, hn⟩ : ∃ n, μ (s (u n)) < L := ((tendsto_order.1 A).2 _ hL).exists have : Ioc a (u n) ∈ 𝓝[>] a := Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, u_pos n⟩ filter_upwards [this] with r hr using lt_of_le_of_lt (measure_mono (hm _ _ hr.1 hr.2)) hn #align measure_theory.tendsto_measure_bInter_gt MeasureTheory.tendsto_measure_biInter_gt /-- One direction of the **Borel-Cantelli lemma** (sometimes called the "*first* Borel-Cantelli lemma"): if (sᵢ) is a sequence of sets such that `∑ μ sᵢ` is finite, then the limit superior of the `sᵢ` is a null set. Note: for the *second* Borel-Cantelli lemma (applying to independent sets in a probability space), see `ProbabilityTheory.measure_limsup_eq_one`. -/ theorem measure_limsup_eq_zero {s : ℕ → Set α} (hs : (∑' i, μ (s i)) ≠ ∞) : μ (limsup s atTop) = 0 := by -- First we replace the sequence `sₙ` with a sequence of measurable sets `tₙ ⊇ sₙ` of the same -- measure. set t : ℕ → Set α := fun n => toMeasurable μ (s n) have ht : (∑' i, μ (t i)) ≠ ∞ := by simpa only [t, measure_toMeasurable] using hs suffices μ (limsup t atTop) = 0 by have A : s ≤ t := fun n => subset_toMeasurable μ (s n) -- TODO default args fail exact measure_mono_null (limsup_le_limsup (eventually_of_forall (Pi.le_def.mp A))) this -- Next we unfold `limsup` for sets and replace equality with an inequality simp only [limsup_eq_iInf_iSup_of_nat', Set.iInf_eq_iInter, Set.iSup_eq_iUnion, ← nonpos_iff_eq_zero] -- Finally, we estimate `μ (⋃ i, t (i + n))` by `∑ i', μ (t (i + n))` refine le_of_tendsto_of_tendsto' (tendsto_measure_iInter (fun i => MeasurableSet.iUnion fun b => measurableSet_toMeasurable _ _) ?_ ⟨0, ne_top_of_le_ne_top ht (measure_iUnion_le t)⟩) (ENNReal.tendsto_sum_nat_add (μ ∘ t) ht) fun n => measure_iUnion_le _ intro n m hnm x simp only [Set.mem_iUnion] exact fun ⟨i, hi⟩ => ⟨i + (m - n), by simpa only [add_assoc, tsub_add_cancel_of_le hnm] using hi⟩ #align measure_theory.measure_limsup_eq_zero MeasureTheory.measure_limsup_eq_zero theorem measure_liminf_eq_zero {s : ℕ → Set α} (h : (∑' i, μ (s i)) ≠ ∞) : μ (liminf s atTop) = 0 := by rw [← le_zero_iff] have : liminf s atTop ≤ limsup s atTop := liminf_le_limsup exact (μ.mono this).trans (by simp [measure_limsup_eq_zero h]) #align measure_theory.measure_liminf_eq_zero MeasureTheory.measure_liminf_eq_zero -- Need to specify `α := Set α` below because of diamond; see #19041 theorem limsup_ae_eq_of_forall_ae_eq (s : ℕ → Set α) {t : Set α} (h : ∀ n, s n =ᵐ[μ] t) : limsup (α := Set α) s atTop =ᵐ[μ] t := by simp_rw [ae_eq_set] at h ⊢ constructor · rw [atTop.limsup_sdiff s t] apply measure_limsup_eq_zero simp [h] · rw [atTop.sdiff_limsup s t] apply measure_liminf_eq_zero simp [h] #align measure_theory.limsup_ae_eq_of_forall_ae_eq MeasureTheory.limsup_ae_eq_of_forall_ae_eq -- Need to specify `α := Set α` above because of diamond; see #19041 theorem liminf_ae_eq_of_forall_ae_eq (s : ℕ → Set α) {t : Set α} (h : ∀ n, s n =ᵐ[μ] t) : liminf (α := Set α) s atTop =ᵐ[μ] t := by simp_rw [ae_eq_set] at h ⊢ constructor · rw [atTop.liminf_sdiff s t] apply measure_liminf_eq_zero simp [h] · rw [atTop.sdiff_liminf s t] apply measure_limsup_eq_zero simp [h] #align measure_theory.liminf_ae_eq_of_forall_ae_eq MeasureTheory.liminf_ae_eq_of_forall_ae_eq theorem measure_if {x : β} {t : Set β} {s : Set α} : μ (if x ∈ t then s else ∅) = indicator t (fun _ => μ s) x := by split_ifs with h <;> simp [h] #align measure_theory.measure_if MeasureTheory.measure_if end section OuterMeasure variable [ms : MeasurableSpace α] {s t : Set α} /-- Obtain a measure by giving an outer measure where all sets in the σ-algebra are Carathéodory measurable. -/ def OuterMeasure.toMeasure (m : OuterMeasure α) (h : ms ≤ m.caratheodory) : Measure α := Measure.ofMeasurable (fun s _ => m s) m.empty fun _f hf hd => m.iUnion_eq_of_caratheodory (fun i => h _ (hf i)) hd #align measure_theory.outer_measure.to_measure MeasureTheory.OuterMeasure.toMeasure theorem le_toOuterMeasure_caratheodory (μ : Measure α) : ms ≤ μ.toOuterMeasure.caratheodory := fun _s hs _t => (measure_inter_add_diff _ hs).symm #align measure_theory.le_to_outer_measure_caratheodory MeasureTheory.le_toOuterMeasure_caratheodory @[simp] theorem toMeasure_toOuterMeasure (m : OuterMeasure α) (h : ms ≤ m.caratheodory) : (m.toMeasure h).toOuterMeasure = m.trim := rfl #align measure_theory.to_measure_to_outer_measure MeasureTheory.toMeasure_toOuterMeasure @[simp] theorem toMeasure_apply (m : OuterMeasure α) (h : ms ≤ m.caratheodory) {s : Set α} (hs : MeasurableSet s) : m.toMeasure h s = m s := m.trim_eq hs #align measure_theory.to_measure_apply MeasureTheory.toMeasure_apply theorem le_toMeasure_apply (m : OuterMeasure α) (h : ms ≤ m.caratheodory) (s : Set α) : m s ≤ m.toMeasure h s := m.le_trim s #align measure_theory.le_to_measure_apply MeasureTheory.le_toMeasure_apply theorem toMeasure_apply₀ (m : OuterMeasure α) (h : ms ≤ m.caratheodory) {s : Set α} (hs : NullMeasurableSet s (m.toMeasure h)) : m.toMeasure h s = m s := by refine le_antisymm ?_ (le_toMeasure_apply _ _ _) rcases hs.exists_measurable_subset_ae_eq with ⟨t, hts, htm, heq⟩ calc m.toMeasure h s = m.toMeasure h t := measure_congr heq.symm _ = m t := toMeasure_apply m h htm _ ≤ m s := m.mono hts #align measure_theory.to_measure_apply₀ MeasureTheory.toMeasure_apply₀ @[simp] theorem toOuterMeasure_toMeasure {μ : Measure α} : μ.toOuterMeasure.toMeasure (le_toOuterMeasure_caratheodory _) = μ := Measure.ext fun _s => μ.toOuterMeasure.trim_eq #align measure_theory.to_outer_measure_to_measure MeasureTheory.toOuterMeasure_toMeasure @[simp] theorem boundedBy_measure (μ : Measure α) : OuterMeasure.boundedBy μ = μ.toOuterMeasure := μ.toOuterMeasure.boundedBy_eq_self #align measure_theory.bounded_by_measure MeasureTheory.boundedBy_measure end OuterMeasure section /- Porting note: These variables are wrapped by an anonymous section because they interrupt synthesizing instances in `MeasureSpace` section. -/ variable {m0 : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ] variable {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : Measure α} {s s' t : Set α} namespace Measure /-- If `u` is a superset of `t` with the same (finite) measure (both sets possibly non-measurable), then for any measurable set `s` one also has `μ (t ∩ s) = μ (u ∩ s)`. -/ theorem measure_inter_eq_of_measure_eq {s t u : Set α} (hs : MeasurableSet s) (h : μ t = μ u) (htu : t ⊆ u) (ht_ne_top : μ t ≠ ∞) : μ (t ∩ s) = μ (u ∩ s) := by rw [h] at ht_ne_top refine le_antisymm (by gcongr) ?_ have A : μ (u ∩ s) + μ (u \ s) ≤ μ (t ∩ s) + μ (u \ s) := calc μ (u ∩ s) + μ (u \ s) = μ u := measure_inter_add_diff _ hs _ = μ t := h.symm _ = μ (t ∩ s) + μ (t \ s) := (measure_inter_add_diff _ hs).symm _ ≤ μ (t ∩ s) + μ (u \ s) := by gcongr have B : μ (u \ s) ≠ ∞ := (lt_of_le_of_lt (measure_mono diff_subset) ht_ne_top.lt_top).ne exact ENNReal.le_of_add_le_add_right B A #align measure_theory.measure.measure_inter_eq_of_measure_eq MeasureTheory.Measure.measure_inter_eq_of_measure_eq /-- The measurable superset `toMeasurable μ t` of `t` (which has the same measure as `t`) satisfies, for any measurable set `s`, the equality `μ (toMeasurable μ t ∩ s) = μ (u ∩ s)`. Here, we require that the measure of `t` is finite. The conclusion holds without this assumption when the measure is s-finite (for example when it is σ-finite), see `measure_toMeasurable_inter_of_sFinite`. -/ theorem measure_toMeasurable_inter {s t : Set α} (hs : MeasurableSet s) (ht : μ t ≠ ∞) : μ (toMeasurable μ t ∩ s) = μ (t ∩ s) := (measure_inter_eq_of_measure_eq hs (measure_toMeasurable t).symm (subset_toMeasurable μ t) ht).symm #align measure_theory.measure.measure_to_measurable_inter MeasureTheory.Measure.measure_toMeasurable_inter /-! ### The `ℝ≥0∞`-module of measures -/ instance instZero [MeasurableSpace α] : Zero (Measure α) := ⟨{ toOuterMeasure := 0 m_iUnion := fun _f _hf _hd => tsum_zero.symm trim_le := OuterMeasure.trim_zero.le }⟩ #align measure_theory.measure.has_zero MeasureTheory.Measure.instZero @[simp] theorem zero_toOuterMeasure {_m : MeasurableSpace α} : (0 : Measure α).toOuterMeasure = 0 := rfl #align measure_theory.measure.zero_to_outer_measure MeasureTheory.Measure.zero_toOuterMeasure @[simp, norm_cast] theorem coe_zero {_m : MeasurableSpace α} : ⇑(0 : Measure α) = 0 := rfl #align measure_theory.measure.coe_zero MeasureTheory.Measure.coe_zero @[nontriviality] lemma apply_eq_zero_of_isEmpty [IsEmpty α] {_ : MeasurableSpace α} (μ : Measure α) (s : Set α) : μ s = 0 := by rw [eq_empty_of_isEmpty s, measure_empty] instance instSubsingleton [IsEmpty α] {m : MeasurableSpace α} : Subsingleton (Measure α) := ⟨fun μ ν => by ext1 s _; rw [apply_eq_zero_of_isEmpty, apply_eq_zero_of_isEmpty]⟩ #align measure_theory.measure.subsingleton MeasureTheory.Measure.instSubsingleton theorem eq_zero_of_isEmpty [IsEmpty α] {_m : MeasurableSpace α} (μ : Measure α) : μ = 0 := Subsingleton.elim μ 0 #align measure_theory.measure.eq_zero_of_is_empty MeasureTheory.Measure.eq_zero_of_isEmpty instance instInhabited [MeasurableSpace α] : Inhabited (Measure α) := ⟨0⟩ #align measure_theory.measure.inhabited MeasureTheory.Measure.instInhabited instance instAdd [MeasurableSpace α] : Add (Measure α) := ⟨fun μ₁ μ₂ => { toOuterMeasure := μ₁.toOuterMeasure + μ₂.toOuterMeasure m_iUnion := fun s hs hd => show μ₁ (⋃ i, s i) + μ₂ (⋃ i, s i) = ∑' i, (μ₁ (s i) + μ₂ (s i)) by rw [ENNReal.tsum_add, measure_iUnion hd hs, measure_iUnion hd hs] trim_le := by rw [OuterMeasure.trim_add, μ₁.trimmed, μ₂.trimmed] }⟩ #align measure_theory.measure.has_add MeasureTheory.Measure.instAdd @[simp] theorem add_toOuterMeasure {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) : (μ₁ + μ₂).toOuterMeasure = μ₁.toOuterMeasure + μ₂.toOuterMeasure := rfl #align measure_theory.measure.add_to_outer_measure MeasureTheory.Measure.add_toOuterMeasure @[simp, norm_cast] theorem coe_add {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) : ⇑(μ₁ + μ₂) = μ₁ + μ₂ := rfl #align measure_theory.measure.coe_add MeasureTheory.Measure.coe_add theorem add_apply {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) (s : Set α) : (μ₁ + μ₂) s = μ₁ s + μ₂ s := rfl #align measure_theory.measure.add_apply MeasureTheory.Measure.add_apply section SMul variable [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] variable [SMul R' ℝ≥0∞] [IsScalarTower R' ℝ≥0∞ ℝ≥0∞] instance instSMul [MeasurableSpace α] : SMul R (Measure α) := ⟨fun c μ => { toOuterMeasure := c • μ.toOuterMeasure m_iUnion := fun s hs hd => by simp only [OuterMeasure.smul_apply, coe_toOuterMeasure, ENNReal.tsum_const_smul, measure_iUnion hd hs] trim_le := by rw [OuterMeasure.trim_smul, μ.trimmed] }⟩ #align measure_theory.measure.has_smul MeasureTheory.Measure.instSMul @[simp] theorem smul_toOuterMeasure {_m : MeasurableSpace α} (c : R) (μ : Measure α) : (c • μ).toOuterMeasure = c • μ.toOuterMeasure := rfl #align measure_theory.measure.smul_to_outer_measure MeasureTheory.Measure.smul_toOuterMeasure @[simp, norm_cast] theorem coe_smul {_m : MeasurableSpace α} (c : R) (μ : Measure α) : ⇑(c • μ) = c • ⇑μ := rfl #align measure_theory.measure.coe_smul MeasureTheory.Measure.coe_smul @[simp] theorem smul_apply {_m : MeasurableSpace α} (c : R) (μ : Measure α) (s : Set α) : (c • μ) s = c • μ s := rfl #align measure_theory.measure.smul_apply MeasureTheory.Measure.smul_apply instance instSMulCommClass [SMulCommClass R R' ℝ≥0∞] [MeasurableSpace α] : SMulCommClass R R' (Measure α) := ⟨fun _ _ _ => ext fun _ _ => smul_comm _ _ _⟩ #align measure_theory.measure.smul_comm_class MeasureTheory.Measure.instSMulCommClass instance instIsScalarTower [SMul R R'] [IsScalarTower R R' ℝ≥0∞] [MeasurableSpace α] : IsScalarTower R R' (Measure α) := ⟨fun _ _ _ => ext fun _ _ => smul_assoc _ _ _⟩ #align measure_theory.measure.is_scalar_tower MeasureTheory.Measure.instIsScalarTower instance instIsCentralScalar [SMul Rᵐᵒᵖ ℝ≥0∞] [IsCentralScalar R ℝ≥0∞] [MeasurableSpace α] : IsCentralScalar R (Measure α) := ⟨fun _ _ => ext fun _ _ => op_smul_eq_smul _ _⟩ #align measure_theory.measure.is_central_scalar MeasureTheory.Measure.instIsCentralScalar end SMul instance instNoZeroSMulDivisors [Zero R] [SMulWithZero R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [NoZeroSMulDivisors R ℝ≥0∞] : NoZeroSMulDivisors R (Measure α) where eq_zero_or_eq_zero_of_smul_eq_zero h := by simpa [Ne, ext_iff', forall_or_left] using h instance instMulAction [Monoid R] [MulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [MeasurableSpace α] : MulAction R (Measure α) := Injective.mulAction _ toOuterMeasure_injective smul_toOuterMeasure #align measure_theory.measure.mul_action MeasureTheory.Measure.instMulAction instance instAddCommMonoid [MeasurableSpace α] : AddCommMonoid (Measure α) := toOuterMeasure_injective.addCommMonoid toOuterMeasure zero_toOuterMeasure add_toOuterMeasure fun _ _ => smul_toOuterMeasure _ _ #align measure_theory.measure.add_comm_monoid MeasureTheory.Measure.instAddCommMonoid /-- Coercion to function as an additive monoid homomorphism. -/ def coeAddHom {_ : MeasurableSpace α} : Measure α →+ Set α → ℝ≥0∞ where toFun := (⇑) map_zero' := coe_zero map_add' := coe_add #align measure_theory.measure.coe_add_hom MeasureTheory.Measure.coeAddHom @[simp] theorem coe_finset_sum {_m : MeasurableSpace α} (I : Finset ι) (μ : ι → Measure α) : ⇑(∑ i ∈ I, μ i) = ∑ i ∈ I, ⇑(μ i) := map_sum coeAddHom μ I #align measure_theory.measure.coe_finset_sum MeasureTheory.Measure.coe_finset_sum theorem finset_sum_apply {m : MeasurableSpace α} (I : Finset ι) (μ : ι → Measure α) (s : Set α) : (∑ i ∈ I, μ i) s = ∑ i ∈ I, μ i s := by rw [coe_finset_sum, Finset.sum_apply] #align measure_theory.measure.finset_sum_apply MeasureTheory.Measure.finset_sum_apply instance instDistribMulAction [Monoid R] [DistribMulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [MeasurableSpace α] : DistribMulAction R (Measure α) := Injective.distribMulAction ⟨⟨toOuterMeasure, zero_toOuterMeasure⟩, add_toOuterMeasure⟩ toOuterMeasure_injective smul_toOuterMeasure #align measure_theory.measure.distrib_mul_action MeasureTheory.Measure.instDistribMulAction instance instModule [Semiring R] [Module R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [MeasurableSpace α] : Module R (Measure α) := Injective.module R ⟨⟨toOuterMeasure, zero_toOuterMeasure⟩, add_toOuterMeasure⟩ toOuterMeasure_injective smul_toOuterMeasure #align measure_theory.measure.module MeasureTheory.Measure.instModule @[simp] theorem coe_nnreal_smul_apply {_m : MeasurableSpace α} (c : ℝ≥0) (μ : Measure α) (s : Set α) : (c • μ) s = c * μ s := rfl #align measure_theory.measure.coe_nnreal_smul_apply MeasureTheory.Measure.coe_nnreal_smul_apply @[simp] theorem nnreal_smul_coe_apply {_m : MeasurableSpace α} (c : ℝ≥0) (μ : Measure α) (s : Set α) : c • μ s = c * μ s := by rfl theorem ae_smul_measure_iff {p : α → Prop} {c : ℝ≥0∞} (hc : c ≠ 0) : (∀ᵐ x ∂c • μ, p x) ↔ ∀ᵐ x ∂μ, p x := by simp only [ae_iff, Algebra.id.smul_eq_mul, smul_apply, or_iff_right_iff_imp, mul_eq_zero] simp only [IsEmpty.forall_iff, hc] #align measure_theory.measure.ae_smul_measure_iff MeasureTheory.Measure.ae_smul_measure_iff theorem measure_eq_left_of_subset_of_measure_add_eq {s t : Set α} (h : (μ + ν) t ≠ ∞) (h' : s ⊆ t) (h'' : (μ + ν) s = (μ + ν) t) : μ s = μ t := by refine le_antisymm (measure_mono h') ?_ have : μ t + ν t ≤ μ s + ν t := calc μ t + ν t = μ s + ν s := h''.symm _ ≤ μ s + ν t := by gcongr apply ENNReal.le_of_add_le_add_right _ this exact ne_top_of_le_ne_top h (le_add_left le_rfl) #align measure_theory.measure.measure_eq_left_of_subset_of_measure_add_eq MeasureTheory.Measure.measure_eq_left_of_subset_of_measure_add_eq theorem measure_eq_right_of_subset_of_measure_add_eq {s t : Set α} (h : (μ + ν) t ≠ ∞) (h' : s ⊆ t) (h'' : (μ + ν) s = (μ + ν) t) : ν s = ν t := by rw [add_comm] at h'' h exact measure_eq_left_of_subset_of_measure_add_eq h h' h'' #align measure_theory.measure.measure_eq_right_of_subset_of_measure_add_eq MeasureTheory.Measure.measure_eq_right_of_subset_of_measure_add_eq theorem measure_toMeasurable_add_inter_left {s t : Set α} (hs : MeasurableSet s) (ht : (μ + ν) t ≠ ∞) : μ (toMeasurable (μ + ν) t ∩ s) = μ (t ∩ s) := by refine (measure_inter_eq_of_measure_eq hs ?_ (subset_toMeasurable _ _) ?_).symm · refine measure_eq_left_of_subset_of_measure_add_eq ?_ (subset_toMeasurable _ _) (measure_toMeasurable t).symm rwa [measure_toMeasurable t] · simp only [not_or, ENNReal.add_eq_top, Pi.add_apply, Ne, coe_add] at ht exact ht.1 #align measure_theory.measure.measure_to_measurable_add_inter_left MeasureTheory.Measure.measure_toMeasurable_add_inter_left theorem measure_toMeasurable_add_inter_right {s t : Set α} (hs : MeasurableSet s) (ht : (μ + ν) t ≠ ∞) : ν (toMeasurable (μ + ν) t ∩ s) = ν (t ∩ s) := by rw [add_comm] at ht ⊢ exact measure_toMeasurable_add_inter_left hs ht #align measure_theory.measure.measure_to_measurable_add_inter_right MeasureTheory.Measure.measure_toMeasurable_add_inter_right /-! ### The complete lattice of measures -/ /-- Measures are partially ordered. -/ instance instPartialOrder [MeasurableSpace α] : PartialOrder (Measure α) where le m₁ m₂ := ∀ s, m₁ s ≤ m₂ s le_refl m s := le_rfl le_trans m₁ m₂ m₃ h₁ h₂ s := le_trans (h₁ s) (h₂ s) le_antisymm m₁ m₂ h₁ h₂ := ext fun s _ => le_antisymm (h₁ s) (h₂ s) #align measure_theory.measure.partial_order MeasureTheory.Measure.instPartialOrder theorem toOuterMeasure_le : μ₁.toOuterMeasure ≤ μ₂.toOuterMeasure ↔ μ₁ ≤ μ₂ := .rfl #align measure_theory.measure.to_outer_measure_le MeasureTheory.Measure.toOuterMeasure_le theorem le_iff : μ₁ ≤ μ₂ ↔ ∀ s, MeasurableSet s → μ₁ s ≤ μ₂ s := outerMeasure_le_iff #align measure_theory.measure.le_iff MeasureTheory.Measure.le_iff theorem le_intro (h : ∀ s, MeasurableSet s → s.Nonempty → μ₁ s ≤ μ₂ s) : μ₁ ≤ μ₂ := le_iff.2 fun s hs ↦ s.eq_empty_or_nonempty.elim (by rintro rfl; simp) (h s hs) theorem le_iff' : μ₁ ≤ μ₂ ↔ ∀ s, μ₁ s ≤ μ₂ s := .rfl #align measure_theory.measure.le_iff' MeasureTheory.Measure.le_iff' theorem lt_iff : μ < ν ↔ μ ≤ ν ∧ ∃ s, MeasurableSet s ∧ μ s < ν s := lt_iff_le_not_le.trans <| and_congr Iff.rfl <| by simp only [le_iff, not_forall, not_le, exists_prop] #align measure_theory.measure.lt_iff MeasureTheory.Measure.lt_iff theorem lt_iff' : μ < ν ↔ μ ≤ ν ∧ ∃ s, μ s < ν s := lt_iff_le_not_le.trans <| and_congr Iff.rfl <| by simp only [le_iff', not_forall, not_le] #align measure_theory.measure.lt_iff' MeasureTheory.Measure.lt_iff' instance covariantAddLE [MeasurableSpace α] : CovariantClass (Measure α) (Measure α) (· + ·) (· ≤ ·) := ⟨fun _ν _μ₁ _μ₂ hμ s => add_le_add_left (hμ s) _⟩ #align measure_theory.measure.covariant_add_le MeasureTheory.Measure.covariantAddLE protected theorem le_add_left (h : μ ≤ ν) : μ ≤ ν' + ν := fun s => le_add_left (h s) #align measure_theory.measure.le_add_left MeasureTheory.Measure.le_add_left protected theorem le_add_right (h : μ ≤ ν) : μ ≤ ν + ν' := fun s => le_add_right (h s) #align measure_theory.measure.le_add_right MeasureTheory.Measure.le_add_right section sInf variable {m : Set (Measure α)} theorem sInf_caratheodory (s : Set α) (hs : MeasurableSet s) : MeasurableSet[(sInf (toOuterMeasure '' m)).caratheodory] s := by rw [OuterMeasure.sInf_eq_boundedBy_sInfGen] refine OuterMeasure.boundedBy_caratheodory fun t => ?_ simp only [OuterMeasure.sInfGen, le_iInf_iff, forall_mem_image, measure_eq_iInf t, coe_toOuterMeasure] intro μ hμ u htu _hu have hm : ∀ {s t}, s ⊆ t → OuterMeasure.sInfGen (toOuterMeasure '' m) s ≤ μ t := by intro s t hst rw [OuterMeasure.sInfGen_def, iInf_image] exact iInf₂_le_of_le μ hμ <| measure_mono hst rw [← measure_inter_add_diff u hs] exact add_le_add (hm <| inter_subset_inter_left _ htu) (hm <| diff_subset_diff_left htu) #align measure_theory.measure.Inf_caratheodory MeasureTheory.Measure.sInf_caratheodory instance [MeasurableSpace α] : InfSet (Measure α) := ⟨fun m => (sInf (toOuterMeasure '' m)).toMeasure <| sInf_caratheodory⟩ theorem sInf_apply (hs : MeasurableSet s) : sInf m s = sInf (toOuterMeasure '' m) s := toMeasure_apply _ _ hs #align measure_theory.measure.Inf_apply MeasureTheory.Measure.sInf_apply private theorem measure_sInf_le (h : μ ∈ m) : sInf m ≤ μ := have : sInf (toOuterMeasure '' m) ≤ μ.toOuterMeasure := sInf_le (mem_image_of_mem _ h) le_iff.2 fun s hs => by rw [sInf_apply hs]; exact this s private theorem measure_le_sInf (h : ∀ μ' ∈ m, μ ≤ μ') : μ ≤ sInf m := have : μ.toOuterMeasure ≤ sInf (toOuterMeasure '' m) := le_sInf <| forall_mem_image.2 fun μ hμ ↦ toOuterMeasure_le.2 <| h _ hμ le_iff.2 fun s hs => by rw [sInf_apply hs]; exact this s instance instCompleteSemilatticeInf [MeasurableSpace α] : CompleteSemilatticeInf (Measure α) := { (by infer_instance : PartialOrder (Measure α)), (by infer_instance : InfSet (Measure α)) with sInf_le := fun _s _a => measure_sInf_le le_sInf := fun _s _a => measure_le_sInf } #align measure_theory.measure.complete_semilattice_Inf MeasureTheory.Measure.instCompleteSemilatticeInf instance instCompleteLattice [MeasurableSpace α] : CompleteLattice (Measure α) := { completeLatticeOfCompleteSemilatticeInf (Measure α) with top := { toOuterMeasure := ⊤, m_iUnion := by intro f _ _ refine (measure_iUnion_le _).antisymm ?_ if hne : (⋃ i, f i).Nonempty then rw [OuterMeasure.top_apply hne] exact le_top else simp_all [Set.not_nonempty_iff_eq_empty] trim_le := le_top }, le_top := fun μ => toOuterMeasure_le.mp le_top bot := 0 bot_le := fun _a _s => bot_le } #align measure_theory.measure.complete_lattice MeasureTheory.Measure.instCompleteLattice end sInf @[simp] theorem _root_.MeasureTheory.OuterMeasure.toMeasure_top : (⊤ : OuterMeasure α).toMeasure (by rw [OuterMeasure.top_caratheodory]; exact le_top) = (⊤ : Measure α) := toOuterMeasure_toMeasure (μ := ⊤) #align measure_theory.outer_measure.to_measure_top MeasureTheory.OuterMeasure.toMeasure_top @[simp] theorem toOuterMeasure_top [MeasurableSpace α] : (⊤ : Measure α).toOuterMeasure = (⊤ : OuterMeasure α) := rfl #align measure_theory.measure.to_outer_measure_top MeasureTheory.Measure.toOuterMeasure_top @[simp] theorem top_add : ⊤ + μ = ⊤ := top_unique <| Measure.le_add_right le_rfl #align measure_theory.measure.top_add MeasureTheory.Measure.top_add @[simp] theorem add_top : μ + ⊤ = ⊤ := top_unique <| Measure.le_add_left le_rfl #align measure_theory.measure.add_top MeasureTheory.Measure.add_top protected theorem zero_le {_m0 : MeasurableSpace α} (μ : Measure α) : 0 ≤ μ := bot_le #align measure_theory.measure.zero_le MeasureTheory.Measure.zero_le theorem nonpos_iff_eq_zero' : μ ≤ 0 ↔ μ = 0 := μ.zero_le.le_iff_eq #align measure_theory.measure.nonpos_iff_eq_zero' MeasureTheory.Measure.nonpos_iff_eq_zero' @[simp] theorem measure_univ_eq_zero : μ univ = 0 ↔ μ = 0 := ⟨fun h => bot_unique fun s => (h ▸ measure_mono (subset_univ s) : μ s ≤ 0), fun h => h.symm ▸ rfl⟩ #align measure_theory.measure.measure_univ_eq_zero MeasureTheory.Measure.measure_univ_eq_zero theorem measure_univ_ne_zero : μ univ ≠ 0 ↔ μ ≠ 0 := measure_univ_eq_zero.not #align measure_theory.measure.measure_univ_ne_zero MeasureTheory.Measure.measure_univ_ne_zero instance [NeZero μ] : NeZero (μ univ) := ⟨measure_univ_ne_zero.2 <| NeZero.ne μ⟩ @[simp] theorem measure_univ_pos : 0 < μ univ ↔ μ ≠ 0 := pos_iff_ne_zero.trans measure_univ_ne_zero #align measure_theory.measure.measure_univ_pos MeasureTheory.Measure.measure_univ_pos /-! ### Pushforward and pullback -/ /-- Lift a linear map between `OuterMeasure` spaces such that for each measure `μ` every measurable set is caratheodory-measurable w.r.t. `f μ` to a linear map between `Measure` spaces. -/ def liftLinear {m0 : MeasurableSpace α} (f : OuterMeasure α →ₗ[ℝ≥0∞] OuterMeasure β) (hf : ∀ μ : Measure α, ‹_› ≤ (f μ.toOuterMeasure).caratheodory) : Measure α →ₗ[ℝ≥0∞] Measure β where toFun μ := (f μ.toOuterMeasure).toMeasure (hf μ) map_add' μ₁ μ₂ := ext fun s hs => by simp only [map_add, coe_add, Pi.add_apply, toMeasure_apply, add_toOuterMeasure, OuterMeasure.coe_add, hs] map_smul' c μ := ext fun s hs => by simp only [LinearMap.map_smulₛₗ, coe_smul, Pi.smul_apply, toMeasure_apply, smul_toOuterMeasure (R := ℝ≥0∞), OuterMeasure.coe_smul (R := ℝ≥0∞), smul_apply, hs] #align measure_theory.measure.lift_linear MeasureTheory.Measure.liftLinear lemma liftLinear_apply₀ {f : OuterMeasure α →ₗ[ℝ≥0∞] OuterMeasure β} (hf) {s : Set β} (hs : NullMeasurableSet s (liftLinear f hf μ)) : liftLinear f hf μ s = f μ.toOuterMeasure s := toMeasure_apply₀ _ (hf μ) hs @[simp] theorem liftLinear_apply {f : OuterMeasure α →ₗ[ℝ≥0∞] OuterMeasure β} (hf) {s : Set β} (hs : MeasurableSet s) : liftLinear f hf μ s = f μ.toOuterMeasure s := toMeasure_apply _ (hf μ) hs #align measure_theory.measure.lift_linear_apply MeasureTheory.Measure.liftLinear_apply theorem le_liftLinear_apply {f : OuterMeasure α →ₗ[ℝ≥0∞] OuterMeasure β} (hf) (s : Set β) : f μ.toOuterMeasure s ≤ liftLinear f hf μ s := le_toMeasure_apply _ (hf μ) s #align measure_theory.measure.le_lift_linear_apply MeasureTheory.Measure.le_liftLinear_apply /-- The pushforward of a measure as a linear map. It is defined to be `0` if `f` is not a measurable function. -/ def mapₗ [MeasurableSpace α] (f : α → β) : Measure α →ₗ[ℝ≥0∞] Measure β := if hf : Measurable f then liftLinear (OuterMeasure.map f) fun μ _s hs t => le_toOuterMeasure_caratheodory μ _ (hf hs) (f ⁻¹' t) else 0 #align measure_theory.measure.mapₗ MeasureTheory.Measure.mapₗ theorem mapₗ_congr {f g : α → β} (hf : Measurable f) (hg : Measurable g) (h : f =ᵐ[μ] g) : mapₗ f μ = mapₗ g μ := by ext1 s hs simpa only [mapₗ, hf, hg, hs, dif_pos, liftLinear_apply, OuterMeasure.map_apply] using measure_congr (h.preimage s) #align measure_theory.measure.mapₗ_congr MeasureTheory.Measure.mapₗ_congr /-- The pushforward of a measure. It is defined to be `0` if `f` is not an almost everywhere measurable function. -/ irreducible_def map [MeasurableSpace α] (f : α → β) (μ : Measure α) : Measure β := if hf : AEMeasurable f μ then mapₗ (hf.mk f) μ else 0 #align measure_theory.measure.map MeasureTheory.Measure.map theorem mapₗ_mk_apply_of_aemeasurable {f : α → β} (hf : AEMeasurable f μ) : mapₗ (hf.mk f) μ = map f μ := by simp [map, hf] #align measure_theory.measure.mapₗ_mk_apply_of_ae_measurable MeasureTheory.Measure.mapₗ_mk_apply_of_aemeasurable theorem mapₗ_apply_of_measurable {f : α → β} (hf : Measurable f) (μ : Measure α) : mapₗ f μ = map f μ := by simp only [← mapₗ_mk_apply_of_aemeasurable hf.aemeasurable] exact mapₗ_congr hf hf.aemeasurable.measurable_mk hf.aemeasurable.ae_eq_mk #align measure_theory.measure.mapₗ_apply_of_measurable MeasureTheory.Measure.mapₗ_apply_of_measurable @[simp] theorem map_add (μ ν : Measure α) {f : α → β} (hf : Measurable f) : (μ + ν).map f = μ.map f + ν.map f := by simp [← mapₗ_apply_of_measurable hf] #align measure_theory.measure.map_add MeasureTheory.Measure.map_add @[simp] theorem map_zero (f : α → β) : (0 : Measure α).map f = 0 := by by_cases hf : AEMeasurable f (0 : Measure α) <;> simp [map, hf] #align measure_theory.measure.map_zero MeasureTheory.Measure.map_zero @[simp] theorem map_of_not_aemeasurable {f : α → β} {μ : Measure α} (hf : ¬AEMeasurable f μ) : μ.map f = 0 := by simp [map, hf] #align measure_theory.measure.map_of_not_ae_measurable MeasureTheory.Measure.map_of_not_aemeasurable theorem map_congr {f g : α → β} (h : f =ᵐ[μ] g) : Measure.map f μ = Measure.map g μ := by by_cases hf : AEMeasurable f μ · have hg : AEMeasurable g μ := hf.congr h simp only [← mapₗ_mk_apply_of_aemeasurable hf, ← mapₗ_mk_apply_of_aemeasurable hg] exact mapₗ_congr hf.measurable_mk hg.measurable_mk (hf.ae_eq_mk.symm.trans (h.trans hg.ae_eq_mk)) · have hg : ¬AEMeasurable g μ := by simpa [← aemeasurable_congr h] using hf simp [map_of_not_aemeasurable, hf, hg] #align measure_theory.measure.map_congr MeasureTheory.Measure.map_congr @[simp] protected theorem map_smul (c : ℝ≥0∞) (μ : Measure α) (f : α → β) : (c • μ).map f = c • μ.map f := by rcases eq_or_ne c 0 with (rfl | hc); · simp by_cases hf : AEMeasurable f μ · have hfc : AEMeasurable f (c • μ) := ⟨hf.mk f, hf.measurable_mk, (ae_smul_measure_iff hc).2 hf.ae_eq_mk⟩ simp only [← mapₗ_mk_apply_of_aemeasurable hf, ← mapₗ_mk_apply_of_aemeasurable hfc, LinearMap.map_smulₛₗ, RingHom.id_apply] congr 1 apply mapₗ_congr hfc.measurable_mk hf.measurable_mk exact EventuallyEq.trans ((ae_smul_measure_iff hc).1 hfc.ae_eq_mk.symm) hf.ae_eq_mk · have hfc : ¬AEMeasurable f (c • μ) := by intro hfc exact hf ⟨hfc.mk f, hfc.measurable_mk, (ae_smul_measure_iff hc).1 hfc.ae_eq_mk⟩ simp [map_of_not_aemeasurable hf, map_of_not_aemeasurable hfc] #align measure_theory.measure.map_smul MeasureTheory.Measure.map_smul @[simp] protected theorem map_smul_nnreal (c : ℝ≥0) (μ : Measure α) (f : α → β) : (c • μ).map f = c • μ.map f := μ.map_smul (c : ℝ≥0∞) f #align measure_theory.measure.map_smul_nnreal MeasureTheory.Measure.map_smul_nnreal variable {f : α → β} lemma map_apply₀ {f : α → β} (hf : AEMeasurable f μ) {s : Set β} (hs : NullMeasurableSet s (map f μ)) : μ.map f s = μ (f ⁻¹' s) := by rw [map, dif_pos hf, mapₗ, dif_pos hf.measurable_mk] at hs ⊢ rw [liftLinear_apply₀ _ hs, measure_congr (hf.ae_eq_mk.preimage s)] rfl /-- We can evaluate the pushforward on measurable sets. For non-measurable sets, see `MeasureTheory.Measure.le_map_apply` and `MeasurableEquiv.map_apply`. -/ @[simp] theorem map_apply_of_aemeasurable (hf : AEMeasurable f μ) {s : Set β} (hs : MeasurableSet s) : μ.map f s = μ (f ⁻¹' s) := map_apply₀ hf hs.nullMeasurableSet #align measure_theory.measure.map_apply_of_ae_measurable MeasureTheory.Measure.map_apply_of_aemeasurable @[simp] theorem map_apply (hf : Measurable f) {s : Set β} (hs : MeasurableSet s) : μ.map f s = μ (f ⁻¹' s) := map_apply_of_aemeasurable hf.aemeasurable hs #align measure_theory.measure.map_apply MeasureTheory.Measure.map_apply theorem map_toOuterMeasure (hf : AEMeasurable f μ) : (μ.map f).toOuterMeasure = (OuterMeasure.map f μ.toOuterMeasure).trim := by rw [← trimmed, OuterMeasure.trim_eq_trim_iff] intro s hs simp [hf, hs] #align measure_theory.measure.map_to_outer_measure MeasureTheory.Measure.map_toOuterMeasure @[simp] lemma map_eq_zero_iff (hf : AEMeasurable f μ) : μ.map f = 0 ↔ μ = 0 := by simp_rw [← measure_univ_eq_zero, map_apply_of_aemeasurable hf .univ, preimage_univ] @[simp] lemma mapₗ_eq_zero_iff (hf : Measurable f) : Measure.mapₗ f μ = 0 ↔ μ = 0 := by rw [mapₗ_apply_of_measurable hf, map_eq_zero_iff hf.aemeasurable] lemma map_ne_zero_iff (hf : AEMeasurable f μ) : μ.map f ≠ 0 ↔ μ ≠ 0 := (map_eq_zero_iff hf).not lemma mapₗ_ne_zero_iff (hf : Measurable f) : Measure.mapₗ f μ ≠ 0 ↔ μ ≠ 0 := (mapₗ_eq_zero_iff hf).not @[simp] theorem map_id : map id μ = μ := ext fun _ => map_apply measurable_id #align measure_theory.measure.map_id MeasureTheory.Measure.map_id @[simp] theorem map_id' : map (fun x => x) μ = μ := map_id #align measure_theory.measure.map_id' MeasureTheory.Measure.map_id' theorem map_map {g : β → γ} {f : α → β} (hg : Measurable g) (hf : Measurable f) : (μ.map f).map g = μ.map (g ∘ f) := ext fun s hs => by simp [hf, hg, hs, hg hs, hg.comp hf, ← preimage_comp] #align measure_theory.measure.map_map MeasureTheory.Measure.map_map @[mono] theorem map_mono {f : α → β} (h : μ ≤ ν) (hf : Measurable f) : μ.map f ≤ ν.map f := le_iff.2 fun s hs ↦ by simp [hf.aemeasurable, hs, h _] #align measure_theory.measure.map_mono MeasureTheory.Measure.map_mono /-- Even if `s` is not measurable, we can bound `map f μ s` from below. See also `MeasurableEquiv.map_apply`. -/ theorem le_map_apply {f : α → β} (hf : AEMeasurable f μ) (s : Set β) : μ (f ⁻¹' s) ≤ μ.map f s := calc μ (f ⁻¹' s) ≤ μ (f ⁻¹' toMeasurable (μ.map f) s) := by gcongr; apply subset_toMeasurable _ = μ.map f (toMeasurable (μ.map f) s) := (map_apply_of_aemeasurable hf <| measurableSet_toMeasurable _ _).symm _ = μ.map f s := measure_toMeasurable _ #align measure_theory.measure.le_map_apply MeasureTheory.Measure.le_map_apply theorem le_map_apply_image {f : α → β} (hf : AEMeasurable f μ) (s : Set α) : μ s ≤ μ.map f (f '' s) := (measure_mono (subset_preimage_image f s)).trans (le_map_apply hf _) /-- Even if `s` is not measurable, `map f μ s = 0` implies that `μ (f ⁻¹' s) = 0`. -/ theorem preimage_null_of_map_null {f : α → β} (hf : AEMeasurable f μ) {s : Set β} (hs : μ.map f s = 0) : μ (f ⁻¹' s) = 0 := nonpos_iff_eq_zero.mp <| (le_map_apply hf s).trans_eq hs #align measure_theory.measure.preimage_null_of_map_null MeasureTheory.Measure.preimage_null_of_map_null theorem tendsto_ae_map {f : α → β} (hf : AEMeasurable f μ) : Tendsto f (ae μ) (ae (μ.map f)) := fun _ hs => preimage_null_of_map_null hf hs #align measure_theory.measure.tendsto_ae_map MeasureTheory.Measure.tendsto_ae_map /-- Pullback of a `Measure` as a linear map. If `f` sends each measurable set to a measurable set, then for each measurable set `s` we have `comapₗ f μ s = μ (f '' s)`. If the linearity is not needed, please use `comap` instead, which works for a larger class of functions. -/ def comapₗ [MeasurableSpace α] (f : α → β) : Measure β →ₗ[ℝ≥0∞] Measure α := if hf : Injective f ∧ ∀ s, MeasurableSet s → MeasurableSet (f '' s) then liftLinear (OuterMeasure.comap f) fun μ s hs t => by simp only [OuterMeasure.comap_apply, image_inter hf.1, image_diff hf.1] apply le_toOuterMeasure_caratheodory exact hf.2 s hs else 0 #align measure_theory.measure.comapₗ MeasureTheory.Measure.comapₗ theorem comapₗ_apply {β} [MeasurableSpace α] {mβ : MeasurableSpace β} (f : α → β) (hfi : Injective f) (hf : ∀ s, MeasurableSet s → MeasurableSet (f '' s)) (μ : Measure β) (hs : MeasurableSet s) : comapₗ f μ s = μ (f '' s) := by rw [comapₗ, dif_pos, liftLinear_apply _ hs, OuterMeasure.comap_apply, coe_toOuterMeasure] exact ⟨hfi, hf⟩ #align measure_theory.measure.comapₗ_apply MeasureTheory.Measure.comapₗ_apply /-- Pullback of a `Measure`. If `f` sends each measurable set to a null-measurable set, then for each measurable set `s` we have `comap f μ s = μ (f '' s)`. -/ def comap [MeasurableSpace α] (f : α → β) (μ : Measure β) : Measure α := if hf : Injective f ∧ ∀ s, MeasurableSet s → NullMeasurableSet (f '' s) μ then (OuterMeasure.comap f μ.toOuterMeasure).toMeasure fun s hs t => by simp only [OuterMeasure.comap_apply, image_inter hf.1, image_diff hf.1] exact (measure_inter_add_diff₀ _ (hf.2 s hs)).symm else 0 #align measure_theory.measure.comap MeasureTheory.Measure.comap theorem comap_apply₀ [MeasurableSpace α] (f : α → β) (μ : Measure β) (hfi : Injective f) (hf : ∀ s, MeasurableSet s → NullMeasurableSet (f '' s) μ) (hs : NullMeasurableSet s (comap f μ)) : comap f μ s = μ (f '' s) := by rw [comap, dif_pos (And.intro hfi hf)] at hs ⊢ rw [toMeasure_apply₀ _ _ hs, OuterMeasure.comap_apply, coe_toOuterMeasure] #align measure_theory.measure.comap_apply₀ MeasureTheory.Measure.comap_apply₀ theorem le_comap_apply {β} [MeasurableSpace α] {mβ : MeasurableSpace β} (f : α → β) (μ : Measure β) (hfi : Injective f) (hf : ∀ s, MeasurableSet s → NullMeasurableSet (f '' s) μ) (s : Set α) : μ (f '' s) ≤ comap f μ s := by rw [comap, dif_pos (And.intro hfi hf)] exact le_toMeasure_apply _ _ _ #align measure_theory.measure.le_comap_apply MeasureTheory.Measure.le_comap_apply theorem comap_apply {β} [MeasurableSpace α] {_mβ : MeasurableSpace β} (f : α → β) (hfi : Injective f) (hf : ∀ s, MeasurableSet s → MeasurableSet (f '' s)) (μ : Measure β) (hs : MeasurableSet s) : comap f μ s = μ (f '' s) := comap_apply₀ f μ hfi (fun s hs => (hf s hs).nullMeasurableSet) hs.nullMeasurableSet #align measure_theory.measure.comap_apply MeasureTheory.Measure.comap_apply theorem comapₗ_eq_comap {β} [MeasurableSpace α] {_mβ : MeasurableSpace β} (f : α → β) (hfi : Injective f) (hf : ∀ s, MeasurableSet s → MeasurableSet (f '' s)) (μ : Measure β) (hs : MeasurableSet s) : comapₗ f μ s = comap f μ s := (comapₗ_apply f hfi hf μ hs).trans (comap_apply f hfi hf μ hs).symm #align measure_theory.measure.comapₗ_eq_comap MeasureTheory.Measure.comapₗ_eq_comap theorem measure_image_eq_zero_of_comap_eq_zero {β} [MeasurableSpace α] {_mβ : MeasurableSpace β} (f : α → β) (μ : Measure β) (hfi : Injective f) (hf : ∀ s, MeasurableSet s → NullMeasurableSet (f '' s) μ) {s : Set α} (hs : comap f μ s = 0) : μ (f '' s) = 0 := le_antisymm ((le_comap_apply f μ hfi hf s).trans hs.le) (zero_le _) #align measure_theory.measure.measure_image_eq_zero_of_comap_eq_zero MeasureTheory.Measure.measure_image_eq_zero_of_comap_eq_zero theorem ae_eq_image_of_ae_eq_comap {β} [MeasurableSpace α] {mβ : MeasurableSpace β} (f : α → β) (μ : Measure β) (hfi : Injective f) (hf : ∀ s, MeasurableSet s → NullMeasurableSet (f '' s) μ) {s t : Set α} (hst : s =ᵐ[comap f μ] t) : f '' s =ᵐ[μ] f '' t := by rw [EventuallyEq, ae_iff] at hst ⊢ have h_eq_α : { a : α | ¬s a = t a } = s \ t ∪ t \ s := by ext1 x simp only [eq_iff_iff, mem_setOf_eq, mem_union, mem_diff] tauto have h_eq_β : { a : β | ¬(f '' s) a = (f '' t) a } = f '' s \ f '' t ∪ f '' t \ f '' s := by ext1 x simp only [eq_iff_iff, mem_setOf_eq, mem_union, mem_diff] tauto rw [← Set.image_diff hfi, ← Set.image_diff hfi, ← Set.image_union] at h_eq_β rw [h_eq_β] rw [h_eq_α] at hst exact measure_image_eq_zero_of_comap_eq_zero f μ hfi hf hst #align measure_theory.measure.ae_eq_image_of_ae_eq_comap MeasureTheory.Measure.ae_eq_image_of_ae_eq_comap theorem NullMeasurableSet.image {β} [MeasurableSpace α] {mβ : MeasurableSpace β} (f : α → β) (μ : Measure β) (hfi : Injective f) (hf : ∀ s, MeasurableSet s → NullMeasurableSet (f '' s) μ) {s : Set α} (hs : NullMeasurableSet s (μ.comap f)) : NullMeasurableSet (f '' s) μ := by refine ⟨toMeasurable μ (f '' toMeasurable (μ.comap f) s), measurableSet_toMeasurable _ _, ?_⟩ refine EventuallyEq.trans ?_ (NullMeasurableSet.toMeasurable_ae_eq ?_).symm swap · exact hf _ (measurableSet_toMeasurable _ _) have h : toMeasurable (comap f μ) s =ᵐ[comap f μ] s := NullMeasurableSet.toMeasurable_ae_eq hs exact ae_eq_image_of_ae_eq_comap f μ hfi hf h.symm #align measure_theory.measure.null_measurable_set.image MeasureTheory.Measure.NullMeasurableSet.image theorem comap_preimage {β} [MeasurableSpace α] {mβ : MeasurableSpace β} (f : α → β) (μ : Measure β) {s : Set β} (hf : Injective f) (hf' : Measurable f) (h : ∀ t, MeasurableSet t → NullMeasurableSet (f '' t) μ) (hs : MeasurableSet s) : μ.comap f (f ⁻¹' s) = μ (s ∩ range f) := by rw [comap_apply₀ _ _ hf h (hf' hs).nullMeasurableSet, image_preimage_eq_inter_range] #align measure_theory.measure.comap_preimage MeasureTheory.Measure.comap_preimage section Sum /-- Sum of an indexed family of measures. -/ noncomputable def sum (f : ι → Measure α) : Measure α := (OuterMeasure.sum fun i => (f i).toOuterMeasure).toMeasure <| le_trans (le_iInf fun _ => le_toOuterMeasure_caratheodory _) (OuterMeasure.le_sum_caratheodory _) #align measure_theory.measure.sum MeasureTheory.Measure.sum theorem le_sum_apply (f : ι → Measure α) (s : Set α) : ∑' i, f i s ≤ sum f s := le_toMeasure_apply _ _ _ #align measure_theory.measure.le_sum_apply MeasureTheory.Measure.le_sum_apply @[simp] theorem sum_apply (f : ι → Measure α) {s : Set α} (hs : MeasurableSet s) : sum f s = ∑' i, f i s := toMeasure_apply _ _ hs #align measure_theory.measure.sum_apply MeasureTheory.Measure.sum_apply theorem sum_apply₀ (f : ι → Measure α) {s : Set α} (hs : NullMeasurableSet s (sum f)) : sum f s = ∑' i, f i s := by apply le_antisymm ?_ (le_sum_apply _ _) rcases hs.exists_measurable_subset_ae_eq with ⟨t, ts, t_meas, ht⟩ calc sum f s = sum f t := measure_congr ht.symm _ = ∑' i, f i t := sum_apply _ t_meas _ ≤ ∑' i, f i s := ENNReal.tsum_le_tsum fun i ↦ measure_mono ts /-! For the next theorem, the countability assumption is necessary. For a counterexample, consider an uncountable space, with a distinguished point `x₀`, and the sigma-algebra made of countable sets not containing `x₀`, and their complements. All points but `x₀` are measurable. Consider the sum of the Dirac masses at points different from `x₀`, and `s = x₀`. For any Dirac mass `δ_x`, we have `δ_x (x₀) = 0`, so `∑' x, δ_x (x₀) = 0`. On the other hand, the measure `sum δ_x` gives mass one to each point different from `x₀`, so it gives infinite mass to any measurable set containing `x₀` (as such a set is uncountable), and by outer regularity one get `sum δ_x {x₀} = ∞`. -/ theorem sum_apply_of_countable [Countable ι] (f : ι → Measure α) (s : Set α) : sum f s = ∑' i, f i s := by apply le_antisymm ?_ (le_sum_apply _ _) rcases exists_measurable_superset_forall_eq f s with ⟨t, hst, htm, ht⟩ calc sum f s ≤ sum f t := measure_mono hst _ = ∑' i, f i t := sum_apply _ htm _ = ∑' i, f i s := by simp [ht] theorem le_sum (μ : ι → Measure α) (i : ι) : μ i ≤ sum μ := le_iff.2 fun s hs ↦ by simpa only [sum_apply μ hs] using ENNReal.le_tsum i #align measure_theory.measure.le_sum MeasureTheory.Measure.le_sum @[simp] theorem sum_apply_eq_zero [Countable ι] {μ : ι → Measure α} {s : Set α} : sum μ s = 0 ↔ ∀ i, μ i s = 0 := by simp [sum_apply_of_countable] #align measure_theory.measure.sum_apply_eq_zero MeasureTheory.Measure.sum_apply_eq_zero theorem sum_apply_eq_zero' {μ : ι → Measure α} {s : Set α} (hs : MeasurableSet s) : sum μ s = 0 ↔ ∀ i, μ i s = 0 := by simp [hs] #align measure_theory.measure.sum_apply_eq_zero' MeasureTheory.Measure.sum_apply_eq_zero' @[simp] lemma sum_zero : Measure.sum (fun (_ : ι) ↦ (0 : Measure α)) = 0 := by ext s hs simp [Measure.sum_apply _ hs] theorem sum_sum {ι' : Type*} (μ : ι → ι' → Measure α) : (sum fun n => sum (μ n)) = sum (fun (p : ι × ι') ↦ μ p.1 p.2) := by ext1 s hs simp [sum_apply _ hs, ENNReal.tsum_prod'] theorem sum_comm {ι' : Type*} (μ : ι → ι' → Measure α) : (sum fun n => sum (μ n)) = sum fun m => sum fun n => μ n m := by ext1 s hs simp_rw [sum_apply _ hs] rw [ENNReal.tsum_comm] #align measure_theory.measure.sum_comm MeasureTheory.Measure.sum_comm theorem ae_sum_iff [Countable ι] {μ : ι → Measure α} {p : α → Prop} : (∀ᵐ x ∂sum μ, p x) ↔ ∀ i, ∀ᵐ x ∂μ i, p x := sum_apply_eq_zero #align measure_theory.measure.ae_sum_iff MeasureTheory.Measure.ae_sum_iff theorem ae_sum_iff' {μ : ι → Measure α} {p : α → Prop} (h : MeasurableSet { x | p x }) : (∀ᵐ x ∂sum μ, p x) ↔ ∀ i, ∀ᵐ x ∂μ i, p x := sum_apply_eq_zero' h.compl #align measure_theory.measure.ae_sum_iff' MeasureTheory.Measure.ae_sum_iff' @[simp] theorem sum_fintype [Fintype ι] (μ : ι → Measure α) : sum μ = ∑ i, μ i := by ext1 s hs simp only [sum_apply, finset_sum_apply, hs, tsum_fintype] #align measure_theory.measure.sum_fintype MeasureTheory.Measure.sum_fintype
Mathlib/MeasureTheory/Measure/MeasureSpace.lean
1,550
1,551
theorem sum_coe_finset (s : Finset ι) (μ : ι → Measure α) : (sum fun i : s => μ i) = ∑ i ∈ s, μ i := by
rw [sum_fintype, Finset.sum_coe_sort s μ]
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.TangentCone import Mathlib.Analysis.NormedSpace.OperatorNorm.Asymptotics #align_import analysis.calculus.fderiv.basic from "leanprover-community/mathlib"@"41bef4ae1254365bc190aee63b947674d2977f01" /-! # The Fréchet derivative Let `E` and `F` be normed spaces, `f : E → F`, and `f' : E →L[𝕜] F` a continuous 𝕜-linear map, where `𝕜` is a non-discrete normed field. Then `HasFDerivWithinAt f f' s x` says that `f` has derivative `f'` at `x`, where the domain of interest is restricted to `s`. We also have `HasFDerivAt f f' x := HasFDerivWithinAt f f' x univ` Finally, `HasStrictFDerivAt f f' x` means that `f : E → F` has derivative `f' : E →L[𝕜] F` in the sense of strict differentiability, i.e., `f y - f z - f'(y - z) = o(y - z)` as `y, z → x`. This notion is used in the inverse function theorem, and is defined here only to avoid proving theorems like `IsBoundedBilinearMap.hasFDerivAt` twice: first for `HasFDerivAt`, then for `HasStrictFDerivAt`. ## Main results In addition to the definition and basic properties of the derivative, the folder `Analysis/Calculus/FDeriv/` contains the usual formulas (and existence assertions) for the derivative of * constants * the identity * bounded linear maps (`Linear.lean`) * bounded bilinear maps (`Bilinear.lean`) * sum of two functions (`Add.lean`) * sum of finitely many functions (`Add.lean`) * multiplication of a function by a scalar constant (`Add.lean`) * negative of a function (`Add.lean`) * subtraction of two functions (`Add.lean`) * multiplication of a function by a scalar function (`Mul.lean`) * multiplication of two scalar functions (`Mul.lean`) * composition of functions (the chain rule) (`Comp.lean`) * inverse function (`Mul.lean`) (assuming that it exists; the inverse function theorem is in `../Inverse.lean`) For most binary operations we also define `const_op` and `op_const` theorems for the cases when the first or second argument is a constant. This makes writing chains of `HasDerivAt`'s easier, and they more frequently lead to the desired result. One can also interpret the derivative of a function `f : 𝕜 → E` as an element of `E` (by identifying a linear function from `𝕜` to `E` with its value at `1`). Results on the Fréchet derivative are translated to this more elementary point of view on the derivative in the file `Deriv.lean`. The derivative of polynomials is handled there, as it is naturally one-dimensional. The simplifier is set up to prove automatically that some functions are differentiable, or differentiable at a point (but not differentiable on a set or within a set at a point, as checking automatically that the good domains are mapped one to the other when using composition is not something the simplifier can easily do). This means that one can write `example (x : ℝ) : Differentiable ℝ (fun x ↦ sin (exp (3 + x^2)) - 5 * cos x) := by simp`. If there are divisions, one needs to supply to the simplifier proofs that the denominators do not vanish, as in ```lean example (x : ℝ) (h : 1 + sin x ≠ 0) : DifferentiableAt ℝ (fun x ↦ exp x / (1 + sin x)) x := by simp [h] ``` Of course, these examples only work once `exp`, `cos` and `sin` have been shown to be differentiable, in `Analysis.SpecialFunctions.Trigonometric`. The simplifier is not set up to compute the Fréchet derivative of maps (as these are in general complicated multidimensional linear maps), but it will compute one-dimensional derivatives, see `Deriv.lean`. ## Implementation details The derivative is defined in terms of the `isLittleO` relation, but also characterized in terms of the `Tendsto` relation. We also introduce predicates `DifferentiableWithinAt 𝕜 f s x` (where `𝕜` is the base field, `f` the function to be differentiated, `x` the point at which the derivative is asserted to exist, and `s` the set along which the derivative is defined), as well as `DifferentiableAt 𝕜 f x`, `DifferentiableOn 𝕜 f s` and `Differentiable 𝕜 f` to express the existence of a derivative. To be able to compute with derivatives, we write `fderivWithin 𝕜 f s x` and `fderiv 𝕜 f x` for some choice of a derivative if it exists, and the zero function otherwise. This choice only behaves well along sets for which the derivative is unique, i.e., those for which the tangent directions span a dense subset of the whole space. The predicates `UniqueDiffWithinAt s x` and `UniqueDiffOn s`, defined in `TangentCone.lean` express this property. We prove that indeed they imply the uniqueness of the derivative. This is satisfied for open subsets, and in particular for `univ`. This uniqueness only holds when the field is non-discrete, which we request at the very beginning: otherwise, a derivative can be defined, but it has no interesting properties whatsoever. To make sure that the simplifier can prove automatically that functions are differentiable, we tag many lemmas with the `simp` attribute, for instance those saying that the sum of differentiable functions is differentiable, as well as their product, their cartesian product, and so on. A notable exception is the chain rule: we do not mark as a simp lemma the fact that, if `f` and `g` are differentiable, then their composition also is: `simp` would always be able to match this lemma, by taking `f` or `g` to be the identity. Instead, for every reasonable function (say, `exp`), we add a lemma that if `f` is differentiable then so is `(fun x ↦ exp (f x))`. This means adding some boilerplate lemmas, but these can also be useful in their own right. Tests for this ability of the simplifier (with more examples) are provided in `Tests/Differentiable.lean`. ## Tags derivative, differentiable, Fréchet, calculus -/ open Filter Asymptotics ContinuousLinearMap Set Metric open scoped Classical open Topology NNReal Filter Asymptotics ENNReal noncomputable section section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] variable {G' : Type*} [NormedAddCommGroup G'] [NormedSpace 𝕜 G'] /-- A function `f` has the continuous linear map `f'` as derivative along the filter `L` if `f x' = f x + f' (x' - x) + o (x' - x)` when `x'` converges along the filter `L`. This definition is designed to be specialized for `L = 𝓝 x` (in `HasFDerivAt`), giving rise to the usual notion of Fréchet derivative, and for `L = 𝓝[s] x` (in `HasFDerivWithinAt`), giving rise to the notion of Fréchet derivative along the set `s`. -/ @[mk_iff hasFDerivAtFilter_iff_isLittleO] structure HasFDerivAtFilter (f : E → F) (f' : E →L[𝕜] F) (x : E) (L : Filter E) : Prop where of_isLittleO :: isLittleO : (fun x' => f x' - f x - f' (x' - x)) =o[L] fun x' => x' - x #align has_fderiv_at_filter HasFDerivAtFilter /-- A function `f` has the continuous linear map `f'` as derivative at `x` within a set `s` if `f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x` inside `s`. -/ @[fun_prop] def HasFDerivWithinAt (f : E → F) (f' : E →L[𝕜] F) (s : Set E) (x : E) := HasFDerivAtFilter f f' x (𝓝[s] x) #align has_fderiv_within_at HasFDerivWithinAt /-- A function `f` has the continuous linear map `f'` as derivative at `x` if `f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x`. -/ @[fun_prop] def HasFDerivAt (f : E → F) (f' : E →L[𝕜] F) (x : E) := HasFDerivAtFilter f f' x (𝓝 x) #align has_fderiv_at HasFDerivAt /-- A function `f` has derivative `f'` at `a` in the sense of *strict differentiability* if `f x - f y - f' (x - y) = o(x - y)` as `x, y → a`. This form of differentiability is required, e.g., by the inverse function theorem. Any `C^1` function on a vector space over `ℝ` is strictly differentiable but this definition works, e.g., for vector spaces over `p`-adic numbers. -/ @[fun_prop] def HasStrictFDerivAt (f : E → F) (f' : E →L[𝕜] F) (x : E) := (fun p : E × E => f p.1 - f p.2 - f' (p.1 - p.2)) =o[𝓝 (x, x)] fun p : E × E => p.1 - p.2 #align has_strict_fderiv_at HasStrictFDerivAt variable (𝕜) /-- A function `f` is differentiable at a point `x` within a set `s` if it admits a derivative there (possibly non-unique). -/ @[fun_prop] def DifferentiableWithinAt (f : E → F) (s : Set E) (x : E) := ∃ f' : E →L[𝕜] F, HasFDerivWithinAt f f' s x #align differentiable_within_at DifferentiableWithinAt /-- A function `f` is differentiable at a point `x` if it admits a derivative there (possibly non-unique). -/ @[fun_prop] def DifferentiableAt (f : E → F) (x : E) := ∃ f' : E →L[𝕜] F, HasFDerivAt f f' x #align differentiable_at DifferentiableAt /-- If `f` has a derivative at `x` within `s`, then `fderivWithin 𝕜 f s x` is such a derivative. Otherwise, it is set to `0`. If `x` is isolated in `s`, we take the derivative within `s` to be zero for convenience. -/ irreducible_def fderivWithin (f : E → F) (s : Set E) (x : E) : E →L[𝕜] F := if 𝓝[s \ {x}] x = ⊥ then 0 else if h : ∃ f', HasFDerivWithinAt f f' s x then Classical.choose h else 0 #align fderiv_within fderivWithin /-- If `f` has a derivative at `x`, then `fderiv 𝕜 f x` is such a derivative. Otherwise, it is set to `0`. -/ irreducible_def fderiv (f : E → F) (x : E) : E →L[𝕜] F := if h : ∃ f', HasFDerivAt f f' x then Classical.choose h else 0 #align fderiv fderiv /-- `DifferentiableOn 𝕜 f s` means that `f` is differentiable within `s` at any point of `s`. -/ @[fun_prop] def DifferentiableOn (f : E → F) (s : Set E) := ∀ x ∈ s, DifferentiableWithinAt 𝕜 f s x #align differentiable_on DifferentiableOn /-- `Differentiable 𝕜 f` means that `f` is differentiable at any point. -/ @[fun_prop] def Differentiable (f : E → F) := ∀ x, DifferentiableAt 𝕜 f x #align differentiable Differentiable variable {𝕜} variable {f f₀ f₁ g : E → F} variable {f' f₀' f₁' g' : E →L[𝕜] F} variable (e : E →L[𝕜] F) variable {x : E} variable {s t : Set E} variable {L L₁ L₂ : Filter E} theorem fderivWithin_zero_of_isolated (h : 𝓝[s \ {x}] x = ⊥) : fderivWithin 𝕜 f s x = 0 := by rw [fderivWithin, if_pos h] theorem fderivWithin_zero_of_nmem_closure (h : x ∉ closure s) : fderivWithin 𝕜 f s x = 0 := by apply fderivWithin_zero_of_isolated simp only [mem_closure_iff_nhdsWithin_neBot, neBot_iff, Ne, Classical.not_not] at h rw [eq_bot_iff, ← h] exact nhdsWithin_mono _ diff_subset theorem fderivWithin_zero_of_not_differentiableWithinAt (h : ¬DifferentiableWithinAt 𝕜 f s x) : fderivWithin 𝕜 f s x = 0 := by have : ¬∃ f', HasFDerivWithinAt f f' s x := h simp [fderivWithin, this] #align fderiv_within_zero_of_not_differentiable_within_at fderivWithin_zero_of_not_differentiableWithinAt theorem fderiv_zero_of_not_differentiableAt (h : ¬DifferentiableAt 𝕜 f x) : fderiv 𝕜 f x = 0 := by have : ¬∃ f', HasFDerivAt f f' x := h simp [fderiv, this] #align fderiv_zero_of_not_differentiable_at fderiv_zero_of_not_differentiableAt section DerivativeUniqueness /- In this section, we discuss the uniqueness of the derivative. We prove that the definitions `UniqueDiffWithinAt` and `UniqueDiffOn` indeed imply the uniqueness of the derivative. -/ /-- If a function f has a derivative f' at x, a rescaled version of f around x converges to f', i.e., `n (f (x + (1/n) v) - f x)` converges to `f' v`. More generally, if `c n` tends to infinity and `c n * d n` tends to `v`, then `c n * (f (x + d n) - f x)` tends to `f' v`. This lemma expresses this fact, for functions having a derivative within a set. Its specific formulation is useful for tangent cone related discussions. -/ theorem HasFDerivWithinAt.lim (h : HasFDerivWithinAt f f' s x) {α : Type*} (l : Filter α) {c : α → 𝕜} {d : α → E} {v : E} (dtop : ∀ᶠ n in l, x + d n ∈ s) (clim : Tendsto (fun n => ‖c n‖) l atTop) (cdlim : Tendsto (fun n => c n • d n) l (𝓝 v)) : Tendsto (fun n => c n • (f (x + d n) - f x)) l (𝓝 (f' v)) := by have tendsto_arg : Tendsto (fun n => x + d n) l (𝓝[s] x) := by conv in 𝓝[s] x => rw [← add_zero x] rw [nhdsWithin, tendsto_inf] constructor · apply tendsto_const_nhds.add (tangentConeAt.lim_zero l clim cdlim) · rwa [tendsto_principal] have : (fun y => f y - f x - f' (y - x)) =o[𝓝[s] x] fun y => y - x := h.isLittleO have : (fun n => f (x + d n) - f x - f' (x + d n - x)) =o[l] fun n => x + d n - x := this.comp_tendsto tendsto_arg have : (fun n => f (x + d n) - f x - f' (d n)) =o[l] d := by simpa only [add_sub_cancel_left] have : (fun n => c n • (f (x + d n) - f x - f' (d n))) =o[l] fun n => c n • d n := (isBigO_refl c l).smul_isLittleO this have : (fun n => c n • (f (x + d n) - f x - f' (d n))) =o[l] fun _ => (1 : ℝ) := this.trans_isBigO (cdlim.isBigO_one ℝ) have L1 : Tendsto (fun n => c n • (f (x + d n) - f x - f' (d n))) l (𝓝 0) := (isLittleO_one_iff ℝ).1 this have L2 : Tendsto (fun n => f' (c n • d n)) l (𝓝 (f' v)) := Tendsto.comp f'.cont.continuousAt cdlim have L3 : Tendsto (fun n => c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n)) l (𝓝 (0 + f' v)) := L1.add L2 have : (fun n => c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n)) = fun n => c n • (f (x + d n) - f x) := by ext n simp [smul_add, smul_sub] rwa [this, zero_add] at L3 #align has_fderiv_within_at.lim HasFDerivWithinAt.lim /-- If `f'` and `f₁'` are two derivatives of `f` within `s` at `x`, then they are equal on the tangent cone to `s` at `x` -/ theorem HasFDerivWithinAt.unique_on (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt f f₁' s x) : EqOn f' f₁' (tangentConeAt 𝕜 s x) := fun _ ⟨_, _, dtop, clim, cdlim⟩ => tendsto_nhds_unique (hf.lim atTop dtop clim cdlim) (hg.lim atTop dtop clim cdlim) #align has_fderiv_within_at.unique_on HasFDerivWithinAt.unique_on /-- `UniqueDiffWithinAt` achieves its goal: it implies the uniqueness of the derivative. -/ theorem UniqueDiffWithinAt.eq (H : UniqueDiffWithinAt 𝕜 s x) (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt f f₁' s x) : f' = f₁' := ContinuousLinearMap.ext_on H.1 (hf.unique_on hg) #align unique_diff_within_at.eq UniqueDiffWithinAt.eq theorem UniqueDiffOn.eq (H : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (h : HasFDerivWithinAt f f' s x) (h₁ : HasFDerivWithinAt f f₁' s x) : f' = f₁' := (H x hx).eq h h₁ #align unique_diff_on.eq UniqueDiffOn.eq end DerivativeUniqueness section FDerivProperties /-! ### Basic properties of the derivative -/ theorem hasFDerivAtFilter_iff_tendsto : HasFDerivAtFilter f f' x L ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) L (𝓝 0) := by have h : ∀ x', ‖x' - x‖ = 0 → ‖f x' - f x - f' (x' - x)‖ = 0 := fun x' hx' => by rw [sub_eq_zero.1 (norm_eq_zero.1 hx')] simp rw [hasFDerivAtFilter_iff_isLittleO, ← isLittleO_norm_left, ← isLittleO_norm_right, isLittleO_iff_tendsto h] exact tendsto_congr fun _ => div_eq_inv_mul _ _ #align has_fderiv_at_filter_iff_tendsto hasFDerivAtFilter_iff_tendsto theorem hasFDerivWithinAt_iff_tendsto : HasFDerivWithinAt f f' s x ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) (𝓝[s] x) (𝓝 0) := hasFDerivAtFilter_iff_tendsto #align has_fderiv_within_at_iff_tendsto hasFDerivWithinAt_iff_tendsto theorem hasFDerivAt_iff_tendsto : HasFDerivAt f f' x ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) (𝓝 x) (𝓝 0) := hasFDerivAtFilter_iff_tendsto #align has_fderiv_at_iff_tendsto hasFDerivAt_iff_tendsto theorem hasFDerivAt_iff_isLittleO_nhds_zero : HasFDerivAt f f' x ↔ (fun h : E => f (x + h) - f x - f' h) =o[𝓝 0] fun h => h := by rw [HasFDerivAt, hasFDerivAtFilter_iff_isLittleO, ← map_add_left_nhds_zero x, isLittleO_map] simp [(· ∘ ·)] #align has_fderiv_at_iff_is_o_nhds_zero hasFDerivAt_iff_isLittleO_nhds_zero /-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz on a neighborhood of `x₀` then its derivative at `x₀` has norm bounded by `C`. This version only assumes that `‖f x - f x₀‖ ≤ C * ‖x - x₀‖` in a neighborhood of `x`. -/ theorem HasFDerivAt.le_of_lip' {f : E → F} {f' : E →L[𝕜] F} {x₀ : E} (hf : HasFDerivAt f f' x₀) {C : ℝ} (hC₀ : 0 ≤ C) (hlip : ∀ᶠ x in 𝓝 x₀, ‖f x - f x₀‖ ≤ C * ‖x - x₀‖) : ‖f'‖ ≤ C := by refine le_of_forall_pos_le_add fun ε ε0 => opNorm_le_of_nhds_zero ?_ ?_ · exact add_nonneg hC₀ ε0.le rw [← map_add_left_nhds_zero x₀, eventually_map] at hlip filter_upwards [isLittleO_iff.1 (hasFDerivAt_iff_isLittleO_nhds_zero.1 hf) ε0, hlip] with y hy hyC rw [add_sub_cancel_left] at hyC calc ‖f' y‖ ≤ ‖f (x₀ + y) - f x₀‖ + ‖f (x₀ + y) - f x₀ - f' y‖ := norm_le_insert _ _ _ ≤ C * ‖y‖ + ε * ‖y‖ := add_le_add hyC hy _ = (C + ε) * ‖y‖ := (add_mul _ _ _).symm #align has_fderiv_at.le_of_lip' HasFDerivAt.le_of_lip' /-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz on a neighborhood of `x₀` then its derivative at `x₀` has norm bounded by `C`. -/ theorem HasFDerivAt.le_of_lipschitzOn {f : E → F} {f' : E →L[𝕜] F} {x₀ : E} (hf : HasFDerivAt f f' x₀) {s : Set E} (hs : s ∈ 𝓝 x₀) {C : ℝ≥0} (hlip : LipschitzOnWith C f s) : ‖f'‖ ≤ C := by refine hf.le_of_lip' C.coe_nonneg ?_ filter_upwards [hs] with x hx using hlip.norm_sub_le hx (mem_of_mem_nhds hs) #align has_fderiv_at.le_of_lip HasFDerivAt.le_of_lipschitzOn /-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz then its derivative at `x₀` has norm bounded by `C`. -/ theorem HasFDerivAt.le_of_lipschitz {f : E → F} {f' : E →L[𝕜] F} {x₀ : E} (hf : HasFDerivAt f f' x₀) {C : ℝ≥0} (hlip : LipschitzWith C f) : ‖f'‖ ≤ C := hf.le_of_lipschitzOn univ_mem (lipschitzOn_univ.2 hlip) nonrec theorem HasFDerivAtFilter.mono (h : HasFDerivAtFilter f f' x L₂) (hst : L₁ ≤ L₂) : HasFDerivAtFilter f f' x L₁ := .of_isLittleO <| h.isLittleO.mono hst #align has_fderiv_at_filter.mono HasFDerivAtFilter.mono theorem HasFDerivWithinAt.mono_of_mem (h : HasFDerivWithinAt f f' t x) (hst : t ∈ 𝓝[s] x) : HasFDerivWithinAt f f' s x := h.mono <| nhdsWithin_le_iff.mpr hst #align has_fderiv_within_at.mono_of_mem HasFDerivWithinAt.mono_of_mem #align has_fderiv_within_at.nhds_within HasFDerivWithinAt.mono_of_mem nonrec theorem HasFDerivWithinAt.mono (h : HasFDerivWithinAt f f' t x) (hst : s ⊆ t) : HasFDerivWithinAt f f' s x := h.mono <| nhdsWithin_mono _ hst #align has_fderiv_within_at.mono HasFDerivWithinAt.mono theorem HasFDerivAt.hasFDerivAtFilter (h : HasFDerivAt f f' x) (hL : L ≤ 𝓝 x) : HasFDerivAtFilter f f' x L := h.mono hL #align has_fderiv_at.has_fderiv_at_filter HasFDerivAt.hasFDerivAtFilter @[fun_prop] theorem HasFDerivAt.hasFDerivWithinAt (h : HasFDerivAt f f' x) : HasFDerivWithinAt f f' s x := h.hasFDerivAtFilter inf_le_left #align has_fderiv_at.has_fderiv_within_at HasFDerivAt.hasFDerivWithinAt @[fun_prop] theorem HasFDerivWithinAt.differentiableWithinAt (h : HasFDerivWithinAt f f' s x) : DifferentiableWithinAt 𝕜 f s x := ⟨f', h⟩ #align has_fderiv_within_at.differentiable_within_at HasFDerivWithinAt.differentiableWithinAt @[fun_prop] theorem HasFDerivAt.differentiableAt (h : HasFDerivAt f f' x) : DifferentiableAt 𝕜 f x := ⟨f', h⟩ #align has_fderiv_at.differentiable_at HasFDerivAt.differentiableAt @[simp] theorem hasFDerivWithinAt_univ : HasFDerivWithinAt f f' univ x ↔ HasFDerivAt f f' x := by simp only [HasFDerivWithinAt, nhdsWithin_univ] rfl #align has_fderiv_within_at_univ hasFDerivWithinAt_univ alias ⟨HasFDerivWithinAt.hasFDerivAt_of_univ, _⟩ := hasFDerivWithinAt_univ #align has_fderiv_within_at.has_fderiv_at_of_univ HasFDerivWithinAt.hasFDerivAt_of_univ theorem hasFDerivWithinAt_of_mem_nhds (h : s ∈ 𝓝 x) : HasFDerivWithinAt f f' s x ↔ HasFDerivAt f f' x := by rw [HasFDerivAt, HasFDerivWithinAt, nhdsWithin_eq_nhds.mpr h] lemma hasFDerivWithinAt_of_isOpen (h : IsOpen s) (hx : x ∈ s) : HasFDerivWithinAt f f' s x ↔ HasFDerivAt f f' x := hasFDerivWithinAt_of_mem_nhds (h.mem_nhds hx) theorem hasFDerivWithinAt_insert {y : E} : HasFDerivWithinAt f f' (insert y s) x ↔ HasFDerivWithinAt f f' s x := by rcases eq_or_ne x y with (rfl | h) · simp_rw [HasFDerivWithinAt, hasFDerivAtFilter_iff_isLittleO] apply Asymptotics.isLittleO_insert simp only [sub_self, map_zero] refine ⟨fun h => h.mono <| subset_insert y s, fun hf => hf.mono_of_mem ?_⟩ simp_rw [nhdsWithin_insert_of_ne h, self_mem_nhdsWithin] #align has_fderiv_within_at_insert hasFDerivWithinAt_insert alias ⟨HasFDerivWithinAt.of_insert, HasFDerivWithinAt.insert'⟩ := hasFDerivWithinAt_insert #align has_fderiv_within_at.of_insert HasFDerivWithinAt.of_insert #align has_fderiv_within_at.insert' HasFDerivWithinAt.insert' protected theorem HasFDerivWithinAt.insert (h : HasFDerivWithinAt g g' s x) : HasFDerivWithinAt g g' (insert x s) x := h.insert' #align has_fderiv_within_at.insert HasFDerivWithinAt.insert theorem hasFDerivWithinAt_diff_singleton (y : E) : HasFDerivWithinAt f f' (s \ {y}) x ↔ HasFDerivWithinAt f f' s x := by rw [← hasFDerivWithinAt_insert, insert_diff_singleton, hasFDerivWithinAt_insert] #align has_fderiv_within_at_diff_singleton hasFDerivWithinAt_diff_singleton theorem HasStrictFDerivAt.isBigO_sub (hf : HasStrictFDerivAt f f' x) : (fun p : E × E => f p.1 - f p.2) =O[𝓝 (x, x)] fun p : E × E => p.1 - p.2 := hf.isBigO.congr_of_sub.2 (f'.isBigO_comp _ _) set_option linter.uppercaseLean3 false in #align has_strict_fderiv_at.is_O_sub HasStrictFDerivAt.isBigO_sub theorem HasFDerivAtFilter.isBigO_sub (h : HasFDerivAtFilter f f' x L) : (fun x' => f x' - f x) =O[L] fun x' => x' - x := h.isLittleO.isBigO.congr_of_sub.2 (f'.isBigO_sub _ _) set_option linter.uppercaseLean3 false in #align has_fderiv_at_filter.is_O_sub HasFDerivAtFilter.isBigO_sub @[fun_prop] protected theorem HasStrictFDerivAt.hasFDerivAt (hf : HasStrictFDerivAt f f' x) : HasFDerivAt f f' x := by rw [HasFDerivAt, hasFDerivAtFilter_iff_isLittleO, isLittleO_iff] exact fun c hc => tendsto_id.prod_mk_nhds tendsto_const_nhds (isLittleO_iff.1 hf hc) #align has_strict_fderiv_at.has_fderiv_at HasStrictFDerivAt.hasFDerivAt protected theorem HasStrictFDerivAt.differentiableAt (hf : HasStrictFDerivAt f f' x) : DifferentiableAt 𝕜 f x := hf.hasFDerivAt.differentiableAt #align has_strict_fderiv_at.differentiable_at HasStrictFDerivAt.differentiableAt /-- If `f` is strictly differentiable at `x` with derivative `f'` and `K > ‖f'‖₊`, then `f` is `K`-Lipschitz in a neighborhood of `x`. -/ theorem HasStrictFDerivAt.exists_lipschitzOnWith_of_nnnorm_lt (hf : HasStrictFDerivAt f f' x) (K : ℝ≥0) (hK : ‖f'‖₊ < K) : ∃ s ∈ 𝓝 x, LipschitzOnWith K f s := by have := hf.add_isBigOWith (f'.isBigOWith_comp _ _) hK simp only [sub_add_cancel, IsBigOWith] at this rcases exists_nhds_square this with ⟨U, Uo, xU, hU⟩ exact ⟨U, Uo.mem_nhds xU, lipschitzOnWith_iff_norm_sub_le.2 fun x hx y hy => hU (mk_mem_prod hx hy)⟩ #align has_strict_fderiv_at.exists_lipschitz_on_with_of_nnnorm_lt HasStrictFDerivAt.exists_lipschitzOnWith_of_nnnorm_lt /-- If `f` is strictly differentiable at `x` with derivative `f'`, then `f` is Lipschitz in a neighborhood of `x`. See also `HasStrictFDerivAt.exists_lipschitzOnWith_of_nnnorm_lt` for a more precise statement. -/ theorem HasStrictFDerivAt.exists_lipschitzOnWith (hf : HasStrictFDerivAt f f' x) : ∃ K, ∃ s ∈ 𝓝 x, LipschitzOnWith K f s := (exists_gt _).imp hf.exists_lipschitzOnWith_of_nnnorm_lt #align has_strict_fderiv_at.exists_lipschitz_on_with HasStrictFDerivAt.exists_lipschitzOnWith /-- Directional derivative agrees with `HasFDeriv`. -/ theorem HasFDerivAt.lim (hf : HasFDerivAt f f' x) (v : E) {α : Type*} {c : α → 𝕜} {l : Filter α} (hc : Tendsto (fun n => ‖c n‖) l atTop) : Tendsto (fun n => c n • (f (x + (c n)⁻¹ • v) - f x)) l (𝓝 (f' v)) := by refine (hasFDerivWithinAt_univ.2 hf).lim _ univ_mem hc ?_ intro U hU refine (eventually_ne_of_tendsto_norm_atTop hc (0 : 𝕜)).mono fun y hy => ?_ convert mem_of_mem_nhds hU dsimp only rw [← mul_smul, mul_inv_cancel hy, one_smul] #align has_fderiv_at.lim HasFDerivAt.lim theorem HasFDerivAt.unique (h₀ : HasFDerivAt f f₀' x) (h₁ : HasFDerivAt f f₁' x) : f₀' = f₁' := by rw [← hasFDerivWithinAt_univ] at h₀ h₁ exact uniqueDiffWithinAt_univ.eq h₀ h₁ #align has_fderiv_at.unique HasFDerivAt.unique theorem hasFDerivWithinAt_inter' (h : t ∈ 𝓝[s] x) : HasFDerivWithinAt f f' (s ∩ t) x ↔ HasFDerivWithinAt f f' s x := by simp [HasFDerivWithinAt, nhdsWithin_restrict'' s h] #align has_fderiv_within_at_inter' hasFDerivWithinAt_inter' theorem hasFDerivWithinAt_inter (h : t ∈ 𝓝 x) : HasFDerivWithinAt f f' (s ∩ t) x ↔ HasFDerivWithinAt f f' s x := by simp [HasFDerivWithinAt, nhdsWithin_restrict' s h] #align has_fderiv_within_at_inter hasFDerivWithinAt_inter theorem HasFDerivWithinAt.union (hs : HasFDerivWithinAt f f' s x) (ht : HasFDerivWithinAt f f' t x) : HasFDerivWithinAt f f' (s ∪ t) x := by simp only [HasFDerivWithinAt, nhdsWithin_union] exact .of_isLittleO <| hs.isLittleO.sup ht.isLittleO #align has_fderiv_within_at.union HasFDerivWithinAt.union theorem HasFDerivWithinAt.hasFDerivAt (h : HasFDerivWithinAt f f' s x) (hs : s ∈ 𝓝 x) : HasFDerivAt f f' x := by rwa [← univ_inter s, hasFDerivWithinAt_inter hs, hasFDerivWithinAt_univ] at h #align has_fderiv_within_at.has_fderiv_at HasFDerivWithinAt.hasFDerivAt theorem DifferentiableWithinAt.differentiableAt (h : DifferentiableWithinAt 𝕜 f s x) (hs : s ∈ 𝓝 x) : DifferentiableAt 𝕜 f x := h.imp fun _ hf' => hf'.hasFDerivAt hs #align differentiable_within_at.differentiable_at DifferentiableWithinAt.differentiableAt /-- If `x` is isolated in `s`, then `f` has any derivative at `x` within `s`, as this statement is empty. -/ theorem HasFDerivWithinAt.of_nhdsWithin_eq_bot (h : 𝓝[s\{x}] x = ⊥) : HasFDerivWithinAt f f' s x := by rw [← hasFDerivWithinAt_diff_singleton x, HasFDerivWithinAt, h, hasFDerivAtFilter_iff_isLittleO] apply isLittleO_bot /-- If `x` is not in the closure of `s`, then `f` has any derivative at `x` within `s`, as this statement is empty. -/ theorem hasFDerivWithinAt_of_nmem_closure (h : x ∉ closure s) : HasFDerivWithinAt f f' s x := .of_nhdsWithin_eq_bot <| eq_bot_mono (nhdsWithin_mono _ diff_subset) <| by rwa [mem_closure_iff_nhdsWithin_neBot, not_neBot] at h #align has_fderiv_within_at_of_not_mem_closure hasFDerivWithinAt_of_nmem_closure theorem DifferentiableWithinAt.hasFDerivWithinAt (h : DifferentiableWithinAt 𝕜 f s x) : HasFDerivWithinAt f (fderivWithin 𝕜 f s x) s x := by by_cases H : 𝓝[s \ {x}] x = ⊥ · exact .of_nhdsWithin_eq_bot H · unfold DifferentiableWithinAt at h rw [fderivWithin, if_neg H, dif_pos h] exact Classical.choose_spec h #align differentiable_within_at.has_fderiv_within_at DifferentiableWithinAt.hasFDerivWithinAt theorem DifferentiableAt.hasFDerivAt (h : DifferentiableAt 𝕜 f x) : HasFDerivAt f (fderiv 𝕜 f x) x := by dsimp only [DifferentiableAt] at h rw [fderiv, dif_pos h] exact Classical.choose_spec h #align differentiable_at.has_fderiv_at DifferentiableAt.hasFDerivAt theorem DifferentiableOn.hasFDerivAt (h : DifferentiableOn 𝕜 f s) (hs : s ∈ 𝓝 x) : HasFDerivAt f (fderiv 𝕜 f x) x := ((h x (mem_of_mem_nhds hs)).differentiableAt hs).hasFDerivAt #align differentiable_on.has_fderiv_at DifferentiableOn.hasFDerivAt theorem DifferentiableOn.differentiableAt (h : DifferentiableOn 𝕜 f s) (hs : s ∈ 𝓝 x) : DifferentiableAt 𝕜 f x := (h.hasFDerivAt hs).differentiableAt #align differentiable_on.differentiable_at DifferentiableOn.differentiableAt theorem DifferentiableOn.eventually_differentiableAt (h : DifferentiableOn 𝕜 f s) (hs : s ∈ 𝓝 x) : ∀ᶠ y in 𝓝 x, DifferentiableAt 𝕜 f y := (eventually_eventually_nhds.2 hs).mono fun _ => h.differentiableAt #align differentiable_on.eventually_differentiable_at DifferentiableOn.eventually_differentiableAt protected theorem HasFDerivAt.fderiv (h : HasFDerivAt f f' x) : fderiv 𝕜 f x = f' := by ext rw [h.unique h.differentiableAt.hasFDerivAt] #align has_fderiv_at.fderiv HasFDerivAt.fderiv theorem fderiv_eq {f' : E → E →L[𝕜] F} (h : ∀ x, HasFDerivAt f (f' x) x) : fderiv 𝕜 f = f' := funext fun x => (h x).fderiv #align fderiv_eq fderiv_eq variable (𝕜) /-- Converse to the mean value inequality: if `f` is `C`-lipschitz on a neighborhood of `x₀` then its derivative at `x₀` has norm bounded by `C`. This version only assumes that `‖f x - f x₀‖ ≤ C * ‖x - x₀‖` in a neighborhood of `x`. -/ theorem norm_fderiv_le_of_lip' {f : E → F} {x₀ : E} {C : ℝ} (hC₀ : 0 ≤ C) (hlip : ∀ᶠ x in 𝓝 x₀, ‖f x - f x₀‖ ≤ C * ‖x - x₀‖) : ‖fderiv 𝕜 f x₀‖ ≤ C := by by_cases hf : DifferentiableAt 𝕜 f x₀ · exact hf.hasFDerivAt.le_of_lip' hC₀ hlip · rw [fderiv_zero_of_not_differentiableAt hf] simp [hC₀] /-- Converse to the mean value inequality: if `f` is `C`-lipschitz on a neighborhood of `x₀` then its derivative at `x₀` has norm bounded by `C`. Version using `fderiv`. -/ -- Porting note: renamed so that dot-notation makes sense theorem norm_fderiv_le_of_lipschitzOn {f : E → F} {x₀ : E} {s : Set E} (hs : s ∈ 𝓝 x₀) {C : ℝ≥0} (hlip : LipschitzOnWith C f s) : ‖fderiv 𝕜 f x₀‖ ≤ C := by refine norm_fderiv_le_of_lip' 𝕜 C.coe_nonneg ?_ filter_upwards [hs] with x hx using hlip.norm_sub_le hx (mem_of_mem_nhds hs) #align fderiv_at.le_of_lip norm_fderiv_le_of_lipschitzOn /-- Converse to the mean value inequality: if `f` is `C`-lipschitz then its derivative at `x₀` has norm bounded by `C`. Version using `fderiv`. -/ theorem norm_fderiv_le_of_lipschitz {f : E → F} {x₀ : E} {C : ℝ≥0} (hlip : LipschitzWith C f) : ‖fderiv 𝕜 f x₀‖ ≤ C := norm_fderiv_le_of_lipschitzOn 𝕜 univ_mem (lipschitzOn_univ.2 hlip) variable {𝕜} protected theorem HasFDerivWithinAt.fderivWithin (h : HasFDerivWithinAt f f' s x) (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 f s x = f' := (hxs.eq h h.differentiableWithinAt.hasFDerivWithinAt).symm #align has_fderiv_within_at.fderiv_within HasFDerivWithinAt.fderivWithin theorem DifferentiableWithinAt.mono (h : DifferentiableWithinAt 𝕜 f t x) (st : s ⊆ t) : DifferentiableWithinAt 𝕜 f s x := by rcases h with ⟨f', hf'⟩ exact ⟨f', hf'.mono st⟩ #align differentiable_within_at.mono DifferentiableWithinAt.mono theorem DifferentiableWithinAt.mono_of_mem (h : DifferentiableWithinAt 𝕜 f s x) {t : Set E} (hst : s ∈ 𝓝[t] x) : DifferentiableWithinAt 𝕜 f t x := (h.hasFDerivWithinAt.mono_of_mem hst).differentiableWithinAt #align differentiable_within_at.mono_of_mem DifferentiableWithinAt.mono_of_mem theorem differentiableWithinAt_univ : DifferentiableWithinAt 𝕜 f univ x ↔ DifferentiableAt 𝕜 f x := by simp only [DifferentiableWithinAt, hasFDerivWithinAt_univ, DifferentiableAt] #align differentiable_within_at_univ differentiableWithinAt_univ theorem differentiableWithinAt_inter (ht : t ∈ 𝓝 x) : DifferentiableWithinAt 𝕜 f (s ∩ t) x ↔ DifferentiableWithinAt 𝕜 f s x := by simp only [DifferentiableWithinAt, hasFDerivWithinAt_inter ht] #align differentiable_within_at_inter differentiableWithinAt_inter
Mathlib/Analysis/Calculus/FDeriv/Basic.lean
641
643
theorem differentiableWithinAt_inter' (ht : t ∈ 𝓝[s] x) : DifferentiableWithinAt 𝕜 f (s ∩ t) x ↔ DifferentiableWithinAt 𝕜 f s x := by
simp only [DifferentiableWithinAt, hasFDerivWithinAt_inter' ht]
/- Copyright (c) 2023 Peter Nelson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Peter Nelson -/ import Mathlib.Data.Set.Card import Mathlib.Order.Minimal import Mathlib.Data.Matroid.Init /-! # Matroids A `Matroid` is a structure that combinatorially abstracts the notion of linear independence and dependence; matroids have connections with graph theory, discrete optimization, additive combinatorics and algebraic geometry. Mathematically, a matroid `M` is a structure on a set `E` comprising a collection of subsets of `E` called the bases of `M`, where the bases are required to obey certain axioms. This file gives a definition of a matroid `M` in terms of its bases, and some API relating independent sets (subsets of bases) and the notion of a basis of a set `X` (a maximal independent subset of `X`). ## Main definitions * a `Matroid α` on a type `α` is a structure comprising a 'ground set' and a suitably behaved 'base' predicate. Given `M : Matroid α` ... * `M.E` denotes the ground set of `M`, which has type `Set α` * For `B : Set α`, `M.Base B` means that `B` is a base of `M`. * For `I : Set α`, `M.Indep I` means that `I` is independent in `M` (that is, `I` is contained in a base of `M`). * For `D : Set α`, `M.Dep D` means that `D` is contained in the ground set of `M` but isn't independent. * For `I : Set α` and `X : Set α`, `M.Basis I X` means that `I` is a maximal independent subset of `X`. * `M.Finite` means that `M` has finite ground set. * `M.Nonempty` means that the ground set of `M` is nonempty. * `FiniteRk M` means that the bases of `M` are finite. * `InfiniteRk M` means that the bases of `M` are infinite. * `RkPos M` means that the bases of `M` are nonempty. * `Finitary M` means that a set is independent if and only if all its finite subsets are independent. * `aesop_mat` : a tactic designed to prove `X ⊆ M.E` for some set `X` and matroid `M`. ## Implementation details There are a few design decisions worth discussing. ### Finiteness The first is that our matroids are allowed to be infinite. Unlike with many mathematical structures, this isn't such an obvious choice. Finite matroids have been studied since the 1930's, and there was never controversy as to what is and isn't an example of a finite matroid - in fact, surprisingly many apparently different definitions of a matroid give rise to the same class of objects. However, generalizing different definitions of a finite matroid to the infinite in the obvious way (i.e. by simply allowing the ground set to be infinite) gives a number of different notions of 'infinite matroid' that disagree with each other, and that all lack nice properties. Many different competing notions of infinite matroid were studied through the years; in fact, the problem of which definition is the best was only really solved in 2013, when Bruhn et al. [2] showed that there is a unique 'reasonable' notion of an infinite matroid (these objects had previously defined by Higgs under the name 'B-matroid'). These are defined by adding one carefully chosen axiom to the standard set, and adapting existing axioms to not mention set cardinalities; they enjoy nearly all the nice properties of standard finite matroids. Even though at least 90% of the literature is on finite matroids, B-matroids are the definition we use, because they allow for additional generality, nearly all theorems are still true and just as easy to state, and (hopefully) the more general definition will prevent the need for a costly future refactor. The disadvantage is that developing API for the finite case is harder work (for instance, it is harder to prove that something is a matroid in the first place, and one must deal with `ℕ∞` rather than `ℕ`). For serious work on finite matroids, we provide the typeclasses `[M.Finite]` and `[FiniteRk M]` and associated API. ### Cardinality Just as with bases of a vector space, all bases of a finite matroid `M` are finite and have the same cardinality; this cardinality is an important invariant known as the 'rank' of `M`. For infinite matroids, bases are not in general equicardinal; in fact the equicardinality of bases of infinite matroids is independent of ZFC [3]. What is still true is that either all bases are finite and equicardinal, or all bases are infinite. This means that the natural notion of 'size' for a set in matroid theory is given by the function `Set.encard`, which is the cardinality as a term in `ℕ∞`. We use this function extensively in building the API; it is preferable to both `Set.ncard` and `Finset.card` because it allows infinite sets to be handled without splitting into cases. ### The ground `Set` A last place where we make a consequential choice is making the ground set of a matroid a structure field of type `Set α` (where `α` is the type of 'possible matroid elements') rather than just having a type `α` of all the matroid elements. This is because of how common it is to simultaneously consider a number of matroids on different but related ground sets. For example, a matroid `M` on ground set `E` can have its structure 'restricted' to some subset `R ⊆ E` to give a smaller matroid `M ↾ R` with ground set `R`. A statement like `(M ↾ R₁) ↾ R₂ = M ↾ R₂` is mathematically obvious. But if the ground set of a matroid is a type, this doesn't typecheck, and is only true up to canonical isomorphism. Restriction is just the tip of the iceberg here; one can also 'contract' and 'delete' elements and sets of elements in a matroid to give a smaller matroid, and in practice it is common to make statements like `M₁.E = M₂.E ∩ M₃.E` and `((M ⟋ e) ↾ R) ⟋ C = M ⟋ (C ∪ {e}) ↾ R`. Such things are a nightmare to work with unless `=` is actually propositional equality (especially because the relevant coercions are usually between sets and not just elements). So the solution is that the ground set `M.E` has type `Set α`, and there are elements of type `α` that aren't in the matroid. The tradeoff is that for many statements, one now has to add hypotheses of the form `X ⊆ M.E` to make sure than `X` is actually 'in the matroid', rather than letting a 'type of matroid elements' take care of this invisibly. It still seems that this is worth it. The tactic `aesop_mat` exists specifically to discharge such goals with minimal fuss (using default values). The tactic works fairly well, but has room for improvement. Even though the carrier set is written `M.E`, A related decision is to not have matroids themselves be a typeclass. This would make things be notationally simpler (having `Base` in the presence of `[Matroid α]` rather than `M.Base` for a term `M : Matroid α`) but is again just too awkward when one has multiple matroids on the same type. In fact, in regular written mathematics, it is normal to explicitly indicate which matroid something is happening in, so our notation mirrors common practice. ### Notation We use a couple of nonstandard conventions in theorem names that are related to the above. First, we mirror common informal practice by referring explicitly to the `ground` set rather than the notation `E`. (Writing `ground` everywhere in a proof term would be unwieldy, and writing `E` in theorem names would be unnatural to read.) Second, because we are typically interested in subsets of the ground set `M.E`, using `Set.compl` is inconvenient, since `Xᶜ ⊆ M.E` is typically false for `X ⊆ M.E`. On the other hand (especially when duals arise), it is common to complement a set `X ⊆ M.E` *within* the ground set, giving `M.E \ X`. For this reason, we use the term `compl` in theorem names to refer to taking a set difference with respect to the ground set, rather than a complement within a type. The lemma `compl_base_dual` is one of the many examples of this. ## References [1] The standard text on matroid theory [J. G. Oxley, Matroid Theory, Oxford University Press, New York, 2011.] [2] The robust axiomatic definition of infinite matroids [H. Bruhn, R. Diestel, M. Kriesell, R. Pendavingh, P. Wollan, Axioms for infinite matroids, Adv. Math 239 (2013), 18-46] [3] Equicardinality of matroid bases is independent of ZFC. [N. Bowler, S. Geschke, Self-dual uniform matroids on infinite sets, Proc. Amer. Math. Soc. 144 (2016), 459-471] -/ set_option autoImplicit true open Set /-- A predicate `P` on sets satisfies the **exchange property** if, for all `X` and `Y` satisfying `P` and all `a ∈ X \ Y`, there exists `b ∈ Y \ X` so that swapping `a` for `b` in `X` maintains `P`. -/ def Matroid.ExchangeProperty {α : Type _} (P : Set α → Prop) : Prop := ∀ X Y, P X → P Y → ∀ a ∈ X \ Y, ∃ b ∈ Y \ X, P (insert b (X \ {a})) /-- A set `X` has the maximal subset property for a predicate `P` if every subset of `X` satisfying `P` is contained in a maximal subset of `X` satisfying `P`. -/ def Matroid.ExistsMaximalSubsetProperty {α : Type _} (P : Set α → Prop) (X : Set α) : Prop := ∀ I, P I → I ⊆ X → (maximals (· ⊆ ·) {Y | P Y ∧ I ⊆ Y ∧ Y ⊆ X}).Nonempty /-- A `Matroid α` is a ground set `E` of type `Set α`, and a nonempty collection of its subsets satisfying the exchange property and the maximal subset property. Each such set is called a `Base` of `M`. An `Indep`endent set is just a set contained in a base, but we include this predicate as a structure field for better definitional properties. In most cases, using this definition directly is not the best way to construct a matroid, since it requires specifying both the bases and independent sets. If the bases are known, use `Matroid.ofBase` or a variant. If just the independent sets are known, define an `IndepMatroid`, and then use `IndepMatroid.matroid`. -/ @[ext] structure Matroid (α : Type _) where /-- `M` has a ground set `E`. -/ (E : Set α) /-- `M` has a predicate `Base` definining its bases. -/ (Base : Set α → Prop) /-- `M` has a predicate `Indep` defining its independent sets. -/ (Indep : Set α → Prop) /-- The `Indep`endent sets are those contained in `Base`s. -/ (indep_iff' : ∀ ⦃I⦄, Indep I ↔ ∃ B, Base B ∧ I ⊆ B) /-- There is at least one `Base`. -/ (exists_base : ∃ B, Base B) /-- For any bases `B`, `B'` and `e ∈ B \ B'`, there is some `f ∈ B' \ B` for which `B-e+f` is a base. -/ (base_exchange : Matroid.ExchangeProperty Base) /-- Every independent subset `I` of a set `X` for is contained in a maximal independent subset of `X`. -/ (maximality : ∀ X, X ⊆ E → Matroid.ExistsMaximalSubsetProperty Indep X) /-- Every base is contained in the ground set. -/ (subset_ground : ∀ B, Base B → B ⊆ E) namespace Matroid variable {α : Type*} {M : Matroid α} /-- Typeclass for a matroid having finite ground set. Just a wrapper for `M.E.Finite`-/ protected class Finite (M : Matroid α) : Prop where /-- The ground set is finite -/ (ground_finite : M.E.Finite) /-- Typeclass for a matroid having nonempty ground set. Just a wrapper for `M.E.Nonempty`-/ protected class Nonempty (M : Matroid α) : Prop where /-- The ground set is nonempty -/ (ground_nonempty : M.E.Nonempty) theorem ground_nonempty (M : Matroid α) [M.Nonempty] : M.E.Nonempty := Nonempty.ground_nonempty theorem ground_nonempty_iff (M : Matroid α) : M.E.Nonempty ↔ M.Nonempty := ⟨fun h ↦ ⟨h⟩, fun ⟨h⟩ ↦ h⟩ theorem ground_finite (M : Matroid α) [M.Finite] : M.E.Finite := Finite.ground_finite theorem set_finite (M : Matroid α) [M.Finite] (X : Set α) (hX : X ⊆ M.E := by aesop) : X.Finite := M.ground_finite.subset hX instance finite_of_finite [Finite α] {M : Matroid α} : M.Finite := ⟨Set.toFinite _⟩ /-- A `FiniteRk` matroid is one whose bases are finite -/ class FiniteRk (M : Matroid α) : Prop where /-- There is a finite base -/ exists_finite_base : ∃ B, M.Base B ∧ B.Finite instance finiteRk_of_finite (M : Matroid α) [M.Finite] : FiniteRk M := ⟨M.exists_base.imp (fun B hB ↦ ⟨hB, M.set_finite B (M.subset_ground _ hB)⟩)⟩ /-- An `InfiniteRk` matroid is one whose bases are infinite. -/ class InfiniteRk (M : Matroid α) : Prop where /-- There is an infinite base -/ exists_infinite_base : ∃ B, M.Base B ∧ B.Infinite /-- A `RkPos` matroid is one whose bases are nonempty. -/ class RkPos (M : Matroid α) : Prop where /-- The empty set isn't a base -/ empty_not_base : ¬M.Base ∅ theorem rkPos_iff_empty_not_base : M.RkPos ↔ ¬M.Base ∅ := ⟨fun ⟨h⟩ ↦ h, fun h ↦ ⟨h⟩⟩ section exchange namespace ExchangeProperty variable {Base : Set α → Prop} (exch : ExchangeProperty Base) /-- A family of sets with the exchange property is an antichain. -/ theorem antichain (hB : Base B) (hB' : Base B') (h : B ⊆ B') : B = B' := h.antisymm (fun x hx ↦ by_contra (fun hxB ↦ let ⟨_, hy, _⟩ := exch B' B hB' hB x ⟨hx, hxB⟩; hy.2 <| h hy.1))
Mathlib/Data/Matroid/Basic.lean
268
286
theorem encard_diff_le_aux (exch : ExchangeProperty Base) (hB₁ : Base B₁) (hB₂ : Base B₂) : (B₁ \ B₂).encard ≤ (B₂ \ B₁).encard := by
obtain (he | hinf | ⟨e, he, hcard⟩) := (B₂ \ B₁).eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt · rw [exch.antichain hB₂ hB₁ (diff_eq_empty.mp he)] · exact le_top.trans_eq hinf.symm obtain ⟨f, hf, hB'⟩ := exch B₂ B₁ hB₂ hB₁ e he have : encard (insert f (B₂ \ {e}) \ B₁) < encard (B₂ \ B₁) := by rw [insert_diff_of_mem _ hf.1, diff_diff_comm]; exact hcard have hencard := encard_diff_le_aux exch hB₁ hB' rw [insert_diff_of_mem _ hf.1, diff_diff_comm, ← union_singleton, ← diff_diff, diff_diff_right, inter_singleton_eq_empty.mpr he.2, union_empty] at hencard rw [← encard_diff_singleton_add_one he, ← encard_diff_singleton_add_one hf] exact add_le_add_right hencard 1 termination_by (B₂ \ B₁).encard
/- Copyright (c) 2020 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.BigOperators.Ring import Mathlib.Combinatorics.SimpleGraph.Dart import Mathlib.Combinatorics.SimpleGraph.Finite import Mathlib.Data.ZMod.Parity #align_import combinatorics.simple_graph.degree_sum from "leanprover-community/mathlib"@"90659cbe25e59ec302e2fb92b00e9732160cc620" /-! # Degree-sum formula and handshaking lemma The degree-sum formula is that the sum of the degrees of the vertices in a finite graph is equal to twice the number of edges. The handshaking lemma, a corollary, is that the number of odd-degree vertices is even. ## Main definitions - `SimpleGraph.sum_degrees_eq_twice_card_edges` is the degree-sum formula. - `SimpleGraph.even_card_odd_degree_vertices` is the handshaking lemma. - `SimpleGraph.odd_card_odd_degree_vertices_ne` is that the number of odd-degree vertices different from a given odd-degree vertex is odd. - `SimpleGraph.exists_ne_odd_degree_of_exists_odd_degree` is that the existence of an odd-degree vertex implies the existence of another one. ## Implementation notes We give a combinatorial proof by using the facts that (1) the map from darts to vertices is such that each fiber has cardinality the degree of the corresponding vertex and that (2) the map from darts to edges is 2-to-1. ## Tags simple graphs, sums, degree-sum formula, handshaking lemma -/ open Finset namespace SimpleGraph universe u variable {V : Type u} (G : SimpleGraph V) section DegreeSum variable [Fintype V] [DecidableRel G.Adj] -- Porting note: Changed to `Fintype (Sym2 V)` to match Combinatorics.SimpleGraph.Basic variable [Fintype (Sym2 V)] theorem dart_fst_fiber [DecidableEq V] (v : V) : (univ.filter fun d : G.Dart => d.fst = v) = univ.image (G.dartOfNeighborSet v) := by ext d simp only [mem_image, true_and_iff, mem_filter, SetCoe.exists, mem_univ, exists_prop_of_true] constructor · rintro rfl exact ⟨_, d.adj, by ext <;> rfl⟩ · rintro ⟨e, he, rfl⟩ rfl #align simple_graph.dart_fst_fiber SimpleGraph.dart_fst_fiber theorem dart_fst_fiber_card_eq_degree [DecidableEq V] (v : V) : (univ.filter fun d : G.Dart => d.fst = v).card = G.degree v := by simpa only [dart_fst_fiber, Finset.card_univ, card_neighborSet_eq_degree] using card_image_of_injective univ (G.dartOfNeighborSet_injective v) #align simple_graph.dart_fst_fiber_card_eq_degree SimpleGraph.dart_fst_fiber_card_eq_degree theorem dart_card_eq_sum_degrees : Fintype.card G.Dart = ∑ v, G.degree v := by haveI := Classical.decEq V simp only [← card_univ, ← dart_fst_fiber_card_eq_degree] exact card_eq_sum_card_fiberwise (by simp) #align simple_graph.dart_card_eq_sum_degrees SimpleGraph.dart_card_eq_sum_degrees variable {G} theorem Dart.edge_fiber [DecidableEq V] (d : G.Dart) : (univ.filter fun d' : G.Dart => d'.edge = d.edge) = {d, d.symm} := Finset.ext fun d' => by simpa using dart_edge_eq_iff d' d #align simple_graph.dart.edge_fiber SimpleGraph.Dart.edge_fiber variable (G) theorem dart_edge_fiber_card [DecidableEq V] (e : Sym2 V) (h : e ∈ G.edgeSet) : (univ.filter fun d : G.Dart => d.edge = e).card = 2 := by refine Sym2.ind (fun v w h => ?_) e h let d : G.Dart := ⟨(v, w), h⟩ convert congr_arg card d.edge_fiber rw [card_insert_of_not_mem, card_singleton] rw [mem_singleton] exact d.symm_ne.symm #align simple_graph.dart_edge_fiber_card SimpleGraph.dart_edge_fiber_card theorem dart_card_eq_twice_card_edges : Fintype.card G.Dart = 2 * G.edgeFinset.card := by classical rw [← card_univ] rw [@card_eq_sum_card_fiberwise _ _ _ Dart.edge _ G.edgeFinset fun d _h => by rw [mem_edgeFinset]; apply Dart.edge_mem] rw [← mul_comm, sum_const_nat] intro e h apply G.dart_edge_fiber_card e rwa [← mem_edgeFinset] #align simple_graph.dart_card_eq_twice_card_edges SimpleGraph.dart_card_eq_twice_card_edges /-- The degree-sum formula. This is also known as the handshaking lemma, which might more specifically refer to `SimpleGraph.even_card_odd_degree_vertices`. -/ theorem sum_degrees_eq_twice_card_edges : ∑ v, G.degree v = 2 * G.edgeFinset.card := G.dart_card_eq_sum_degrees.symm.trans G.dart_card_eq_twice_card_edges #align simple_graph.sum_degrees_eq_twice_card_edges SimpleGraph.sum_degrees_eq_twice_card_edges lemma two_mul_card_edgeFinset : 2 * G.edgeFinset.card = (univ.filter fun (x, y) ↦ G.Adj x y).card := by rw [← dart_card_eq_twice_card_edges, ← card_univ] refine card_bij' (fun d _ ↦ (d.fst, d.snd)) (fun xy h ↦ ⟨xy, (mem_filter.1 h).2⟩) ?_ ?_ ?_ ?_ <;> simp end DegreeSum /-- The handshaking lemma. See also `SimpleGraph.sum_degrees_eq_twice_card_edges`. -/ theorem even_card_odd_degree_vertices [Fintype V] [DecidableRel G.Adj] : Even (univ.filter fun v => Odd (G.degree v)).card := by classical have h := congr_arg (fun n => ↑n : ℕ → ZMod 2) G.sum_degrees_eq_twice_card_edges simp only [ZMod.natCast_self, zero_mul, Nat.cast_mul] at h rw [Nat.cast_sum, ← sum_filter_ne_zero] at h rw [@sum_congr _ _ _ _ (fun v => (G.degree v : ZMod 2)) (fun _v => (1 : ZMod 2)) _ rfl] at h · simp only [filter_congr, mul_one, nsmul_eq_mul, sum_const, Ne] at h rw [← ZMod.eq_zero_iff_even] convert h exact ZMod.ne_zero_iff_odd.symm · intro v simp only [true_and_iff, mem_filter, mem_univ, Ne] rw [ZMod.eq_zero_iff_even, ZMod.eq_one_iff_odd, Nat.odd_iff_not_even, imp_self] trivial #align simple_graph.even_card_odd_degree_vertices SimpleGraph.even_card_odd_degree_vertices
Mathlib/Combinatorics/SimpleGraph/DegreeSum.lean
141
160
theorem odd_card_odd_degree_vertices_ne [Fintype V] [DecidableEq V] [DecidableRel G.Adj] (v : V) (h : Odd (G.degree v)) : Odd (univ.filter fun w => w ≠ v ∧ Odd (G.degree w)).card := by
rcases G.even_card_odd_degree_vertices with ⟨k, hg⟩ have hk : 0 < k := by have hh : (filter (fun v : V => Odd (G.degree v)) univ).Nonempty := by use v simp only [true_and_iff, mem_filter, mem_univ] exact h rwa [← card_pos, hg, ← two_mul, mul_pos_iff_of_pos_left] at hh exact zero_lt_two have hc : (fun w : V => w ≠ v ∧ Odd (G.degree w)) = fun w : V => Odd (G.degree w) ∧ w ≠ v := by ext w rw [and_comm] simp only [hc, filter_congr] rw [← filter_filter, filter_ne', card_erase_of_mem] · refine ⟨k - 1, tsub_eq_of_eq_add <| hg.trans ?_⟩ rw [add_assoc, one_add_one_eq_two, ← Nat.mul_succ, ← two_mul] congr omega · simpa only [true_and_iff, mem_filter, mem_univ]
/- Copyright (c) 2021 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.Tactic.CategoryTheory.Elementwise import Mathlib.CategoryTheory.Limits.Shapes.Multiequalizer import Mathlib.CategoryTheory.Limits.Constructions.EpiMono import Mathlib.CategoryTheory.Limits.Preserves.Limits import Mathlib.CategoryTheory.Limits.Shapes.Types #align_import category_theory.glue_data from "leanprover-community/mathlib"@"14b69e9f3c16630440a2cbd46f1ddad0d561dee7" /-! # Gluing data We define `GlueData` as a family of data needed to glue topological spaces, schemes, etc. We provide the API to realize it as a multispan diagram, and also state lemmas about its interaction with a functor that preserves certain pullbacks. -/ noncomputable section open CategoryTheory.Limits namespace CategoryTheory universe v u₁ u₂ variable (C : Type u₁) [Category.{v} C] {C' : Type u₂} [Category.{v} C'] /-- A gluing datum consists of 1. An index type `J` 2. An object `U i` for each `i : J`. 3. An object `V i j` for each `i j : J`. 4. A monomorphism `f i j : V i j ⟶ U i` for each `i j : J`. 5. A transition map `t i j : V i j ⟶ V j i` for each `i j : J`. such that 6. `f i i` is an isomorphism. 7. `t i i` is the identity. 8. The pullback for `f i j` and `f i k` exists. 9. `V i j ×[U i] V i k ⟶ V i j ⟶ V j i` factors through `V j k ×[U j] V j i ⟶ V j i` via some `t' : V i j ×[U i] V i k ⟶ V j k ×[U j] V j i`. 10. `t' i j k ≫ t' j k i ≫ t' k i j = 𝟙 _`. -/ -- Porting note(#5171): linter not ported yet -- @[nolint has_nonempty_instance] structure GlueData where J : Type v U : J → C V : J × J → C f : ∀ i j, V (i, j) ⟶ U i f_mono : ∀ i j, Mono (f i j) := by infer_instance f_hasPullback : ∀ i j k, HasPullback (f i j) (f i k) := by infer_instance f_id : ∀ i, IsIso (f i i) := by infer_instance t : ∀ i j, V (i, j) ⟶ V (j, i) t_id : ∀ i, t i i = 𝟙 _ t' : ∀ i j k, pullback (f i j) (f i k) ⟶ pullback (f j k) (f j i) t_fac : ∀ i j k, t' i j k ≫ pullback.snd = pullback.fst ≫ t i j cocycle : ∀ i j k, t' i j k ≫ t' j k i ≫ t' k i j = 𝟙 _ #align category_theory.glue_data CategoryTheory.GlueData attribute [simp] GlueData.t_id attribute [instance] GlueData.f_id GlueData.f_mono GlueData.f_hasPullback attribute [reassoc] GlueData.t_fac GlueData.cocycle namespace GlueData variable {C} variable (D : GlueData C) @[simp] theorem t'_iij (i j : D.J) : D.t' i i j = (pullbackSymmetry _ _).hom := by have eq₁ := D.t_fac i i j have eq₂ := (IsIso.eq_comp_inv (D.f i i)).mpr (@pullback.condition _ _ _ _ _ _ (D.f i j) _) rw [D.t_id, Category.comp_id, eq₂] at eq₁ have eq₃ := (IsIso.eq_comp_inv (D.f i i)).mp eq₁ rw [Category.assoc, ← pullback.condition, ← Category.assoc] at eq₃ exact Mono.right_cancellation _ _ ((Mono.right_cancellation _ _ eq₃).trans (pullbackSymmetry_hom_comp_fst _ _).symm) #align category_theory.glue_data.t'_iij CategoryTheory.GlueData.t'_iij theorem t'_jii (i j : D.J) : D.t' j i i = pullback.fst ≫ D.t j i ≫ inv pullback.snd := by rw [← Category.assoc, ← D.t_fac] simp #align category_theory.glue_data.t'_jii CategoryTheory.GlueData.t'_jii theorem t'_iji (i j : D.J) : D.t' i j i = pullback.fst ≫ D.t i j ≫ inv pullback.snd := by rw [← Category.assoc, ← D.t_fac] simp #align category_theory.glue_data.t'_iji CategoryTheory.GlueData.t'_iji @[reassoc, elementwise (attr := simp)] theorem t_inv (i j : D.J) : D.t i j ≫ D.t j i = 𝟙 _ := by have eq : (pullbackSymmetry (D.f i i) (D.f i j)).hom = pullback.snd ≫ inv pullback.fst := by simp have := D.cocycle i j i rw [D.t'_iij, D.t'_jii, D.t'_iji, fst_eq_snd_of_mono_eq, eq] at this simp only [Category.assoc, IsIso.inv_hom_id_assoc] at this rw [← IsIso.eq_inv_comp, ← Category.assoc, IsIso.comp_inv_eq] at this simpa using this #align category_theory.glue_data.t_inv CategoryTheory.GlueData.t_inv
Mathlib/CategoryTheory/GlueData.lean
108
111
theorem t'_inv (i j k : D.J) : D.t' i j k ≫ (pullbackSymmetry _ _).hom ≫ D.t' j i k ≫ (pullbackSymmetry _ _).hom = 𝟙 _ := by
rw [← cancel_mono (pullback.fst : pullback (D.f i j) (D.f i k) ⟶ _)] simp [t_fac, t_fac_assoc]
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Algebra.Polynomial.Degree.Definitions import Mathlib.Algebra.Polynomial.Eval import Mathlib.Algebra.Polynomial.Monic import Mathlib.Algebra.Polynomial.RingDivision import Mathlib.Tactic.Abel #align_import ring_theory.polynomial.pochhammer from "leanprover-community/mathlib"@"53b216bcc1146df1c4a0a86877890ea9f1f01589" /-! # The Pochhammer polynomials We define and prove some basic relations about `ascPochhammer S n : S[X] := X * (X + 1) * ... * (X + n - 1)` which is also known as the rising factorial and about `descPochhammer R n : R[X] := X * (X - 1) * ... * (X - n + 1)` which is also known as the falling factorial. Versions of this definition that are focused on `Nat` can be found in `Data.Nat.Factorial` as `Nat.ascFactorial` and `Nat.descFactorial`. ## Implementation As with many other families of polynomials, even though the coefficients are always in `ℕ` or `ℤ` , we define the polynomial with coefficients in any `[Semiring S]` or `[Ring R]`. ## TODO There is lots more in this direction: * q-factorials, q-binomials, q-Pochhammer. -/ universe u v open Polynomial open Polynomial section Semiring variable (S : Type u) [Semiring S] /-- `ascPochhammer S n` is the polynomial `X * (X + 1) * ... * (X + n - 1)`, with coefficients in the semiring `S`. -/ noncomputable def ascPochhammer : ℕ → S[X] | 0 => 1 | n + 1 => X * (ascPochhammer n).comp (X + 1) #align pochhammer ascPochhammer @[simp] theorem ascPochhammer_zero : ascPochhammer S 0 = 1 := rfl #align pochhammer_zero ascPochhammer_zero @[simp] theorem ascPochhammer_one : ascPochhammer S 1 = X := by simp [ascPochhammer] #align pochhammer_one ascPochhammer_one theorem ascPochhammer_succ_left (n : ℕ) : ascPochhammer S (n + 1) = X * (ascPochhammer S n).comp (X + 1) := by rw [ascPochhammer] #align pochhammer_succ_left ascPochhammer_succ_left theorem monic_ascPochhammer (n : ℕ) [Nontrivial S] [NoZeroDivisors S] : Monic <| ascPochhammer S n := by induction' n with n hn · simp · have : leadingCoeff (X + 1 : S[X]) = 1 := leadingCoeff_X_add_C 1 rw [ascPochhammer_succ_left, Monic.def, leadingCoeff_mul, leadingCoeff_comp (ne_zero_of_eq_one <| natDegree_X_add_C 1 : natDegree (X + 1) ≠ 0), hn, monic_X, one_mul, one_mul, this, one_pow] section variable {S} {T : Type v} [Semiring T] @[simp] theorem ascPochhammer_map (f : S →+* T) (n : ℕ) : (ascPochhammer S n).map f = ascPochhammer T n := by induction' n with n ih · simp · simp [ih, ascPochhammer_succ_left, map_comp] #align pochhammer_map ascPochhammer_map theorem ascPochhammer_eval₂ (f : S →+* T) (n : ℕ) (t : T) : (ascPochhammer T n).eval t = (ascPochhammer S n).eval₂ f t := by rw [← ascPochhammer_map f] exact eval_map f t theorem ascPochhammer_eval_comp {R : Type*} [CommSemiring R] (n : ℕ) (p : R[X]) [Algebra R S] (x : S) : ((ascPochhammer S n).comp (p.map (algebraMap R S))).eval x = (ascPochhammer S n).eval (p.eval₂ (algebraMap R S) x) := by rw [ascPochhammer_eval₂ (algebraMap R S), ← eval₂_comp', ← ascPochhammer_map (algebraMap R S), ← map_comp, eval_map] end @[simp, norm_cast] theorem ascPochhammer_eval_cast (n k : ℕ) : (((ascPochhammer ℕ n).eval k : ℕ) : S) = ((ascPochhammer S n).eval k : S) := by rw [← ascPochhammer_map (algebraMap ℕ S), eval_map, ← eq_natCast (algebraMap ℕ S), eval₂_at_natCast,Nat.cast_id] #align pochhammer_eval_cast ascPochhammer_eval_cast theorem ascPochhammer_eval_zero {n : ℕ} : (ascPochhammer S n).eval 0 = if n = 0 then 1 else 0 := by cases n · simp · simp [X_mul, Nat.succ_ne_zero, ascPochhammer_succ_left] #align pochhammer_eval_zero ascPochhammer_eval_zero theorem ascPochhammer_zero_eval_zero : (ascPochhammer S 0).eval 0 = 1 := by simp #align pochhammer_zero_eval_zero ascPochhammer_zero_eval_zero @[simp] theorem ascPochhammer_ne_zero_eval_zero {n : ℕ} (h : n ≠ 0) : (ascPochhammer S n).eval 0 = 0 := by simp [ascPochhammer_eval_zero, h] #align pochhammer_ne_zero_eval_zero ascPochhammer_ne_zero_eval_zero theorem ascPochhammer_succ_right (n : ℕ) : ascPochhammer S (n + 1) = ascPochhammer S n * (X + (n : S[X])) := by suffices h : ascPochhammer ℕ (n + 1) = ascPochhammer ℕ n * (X + (n : ℕ[X])) by apply_fun Polynomial.map (algebraMap ℕ S) at h simpa only [ascPochhammer_map, Polynomial.map_mul, Polynomial.map_add, map_X, Polynomial.map_natCast] using h induction' n with n ih · simp · conv_lhs => rw [ascPochhammer_succ_left, ih, mul_comp, ← mul_assoc, ← ascPochhammer_succ_left, add_comp, X_comp, natCast_comp, add_assoc, add_comm (1 : ℕ[X]), ← Nat.cast_succ] #align pochhammer_succ_right ascPochhammer_succ_right theorem ascPochhammer_succ_eval {S : Type*} [Semiring S] (n : ℕ) (k : S) : (ascPochhammer S (n + 1)).eval k = (ascPochhammer S n).eval k * (k + n) := by rw [ascPochhammer_succ_right, mul_add, eval_add, eval_mul_X, ← Nat.cast_comm, ← C_eq_natCast, eval_C_mul, Nat.cast_comm, ← mul_add] #align pochhammer_succ_eval ascPochhammer_succ_eval theorem ascPochhammer_succ_comp_X_add_one (n : ℕ) : (ascPochhammer S (n + 1)).comp (X + 1) = ascPochhammer S (n + 1) + (n + 1) • (ascPochhammer S n).comp (X + 1) := by suffices (ascPochhammer ℕ (n + 1)).comp (X + 1) = ascPochhammer ℕ (n + 1) + (n + 1) * (ascPochhammer ℕ n).comp (X + 1) by simpa [map_comp] using congr_arg (Polynomial.map (Nat.castRingHom S)) this nth_rw 2 [ascPochhammer_succ_left] rw [← add_mul, ascPochhammer_succ_right ℕ n, mul_comp, mul_comm, add_comp, X_comp, natCast_comp, add_comm, ← add_assoc] ring set_option linter.uppercaseLean3 false in #align pochhammer_succ_comp_X_add_one ascPochhammer_succ_comp_X_add_one theorem ascPochhammer_mul (n m : ℕ) : ascPochhammer S n * (ascPochhammer S m).comp (X + (n : S[X])) = ascPochhammer S (n + m) := by induction' m with m ih · simp · rw [ascPochhammer_succ_right, Polynomial.mul_X_add_natCast_comp, ← mul_assoc, ih, ← add_assoc, ascPochhammer_succ_right, Nat.cast_add, add_assoc] #align pochhammer_mul ascPochhammer_mul theorem ascPochhammer_nat_eq_ascFactorial (n : ℕ) : ∀ k, (ascPochhammer ℕ k).eval n = n.ascFactorial k | 0 => by rw [ascPochhammer_zero, eval_one, Nat.ascFactorial_zero] | t + 1 => by rw [ascPochhammer_succ_right, eval_mul, ascPochhammer_nat_eq_ascFactorial n t, eval_add, eval_X, eval_natCast, Nat.cast_id, Nat.ascFactorial_succ, mul_comm] #align pochhammer_nat_eq_asc_factorial ascPochhammer_nat_eq_ascFactorial theorem ascPochhammer_nat_eq_descFactorial (a b : ℕ) : (ascPochhammer ℕ b).eval a = (a + b - 1).descFactorial b := by rw [ascPochhammer_nat_eq_ascFactorial, Nat.add_descFactorial_eq_ascFactorial'] #align pochhammer_nat_eq_desc_factorial ascPochhammer_nat_eq_descFactorial @[simp]
Mathlib/RingTheory/Polynomial/Pochhammer.lean
178
187
theorem ascPochhammer_natDegree (n : ℕ) [NoZeroDivisors S] [Nontrivial S] : (ascPochhammer S n).natDegree = n := by
induction' n with n hn · simp · have : natDegree (X + (n : S[X])) = 1 := natDegree_X_add_C (n : S) rw [ascPochhammer_succ_right, natDegree_mul _ (ne_zero_of_natDegree_gt <| this.symm ▸ Nat.zero_lt_one), hn, this] cases n · simp · refine ne_zero_of_natDegree_gt <| hn.symm ▸ Nat.add_one_pos _
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Data.Int.Bitwise import Mathlib.LinearAlgebra.Matrix.NonsingularInverse import Mathlib.LinearAlgebra.Matrix.Symmetric #align_import linear_algebra.matrix.zpow from "leanprover-community/mathlib"@"03fda9112aa6708947da13944a19310684bfdfcb" /-! # Integer powers of square matrices In this file, we define integer power of matrices, relying on the nonsingular inverse definition for negative powers. ## Implementation details The main definition is a direct recursive call on the integer inductive type, as provided by the `DivInvMonoid.Pow` default implementation. The lemma names are taken from `Algebra.GroupWithZero.Power`. ## Tags matrix inverse, matrix powers -/ open Matrix namespace Matrix variable {n' : Type*} [DecidableEq n'] [Fintype n'] {R : Type*} [CommRing R] local notation "M" => Matrix n' n' R noncomputable instance : DivInvMonoid M := { show Monoid M by infer_instance, show Inv M by infer_instance with } section NatPow @[simp] theorem inv_pow' (A : M) (n : ℕ) : A⁻¹ ^ n = (A ^ n)⁻¹ := by induction' n with n ih · simp · rw [pow_succ A, mul_inv_rev, ← ih, ← pow_succ'] #align matrix.inv_pow' Matrix.inv_pow' theorem pow_sub' (A : M) {m n : ℕ} (ha : IsUnit A.det) (h : n ≤ m) : A ^ (m - n) = A ^ m * (A ^ n)⁻¹ := by rw [← tsub_add_cancel_of_le h, pow_add, Matrix.mul_assoc, mul_nonsing_inv, tsub_add_cancel_of_le h, Matrix.mul_one] simpa using ha.pow n #align matrix.pow_sub' Matrix.pow_sub' theorem pow_inv_comm' (A : M) (m n : ℕ) : A⁻¹ ^ m * A ^ n = A ^ n * A⁻¹ ^ m := by induction' n with n IH generalizing m · simp cases' m with m m · simp rcases nonsing_inv_cancel_or_zero A with (⟨h, h'⟩ | h) · calc A⁻¹ ^ (m + 1) * A ^ (n + 1) = A⁻¹ ^ m * (A⁻¹ * A) * A ^ n := by simp only [pow_succ A⁻¹, pow_succ' A, Matrix.mul_assoc] _ = A ^ n * A⁻¹ ^ m := by simp only [h, Matrix.mul_one, Matrix.one_mul, IH m] _ = A ^ n * (A * A⁻¹) * A⁻¹ ^ m := by simp only [h', Matrix.mul_one, Matrix.one_mul] _ = A ^ (n + 1) * A⁻¹ ^ (m + 1) := by simp only [pow_succ A, pow_succ' A⁻¹, Matrix.mul_assoc] · simp [h] #align matrix.pow_inv_comm' Matrix.pow_inv_comm' end NatPow section ZPow open Int @[simp] theorem one_zpow : ∀ n : ℤ, (1 : M) ^ n = 1 | (n : ℕ) => by rw [zpow_natCast, one_pow] | -[n+1] => by rw [zpow_negSucc, one_pow, inv_one] #align matrix.one_zpow Matrix.one_zpow theorem zero_zpow : ∀ z : ℤ, z ≠ 0 → (0 : M) ^ z = 0 | (n : ℕ), h => by rw [zpow_natCast, zero_pow] exact mod_cast h | -[n+1], _ => by simp [zero_pow n.succ_ne_zero] #align matrix.zero_zpow Matrix.zero_zpow
Mathlib/LinearAlgebra/Matrix/ZPow.lean
92
95
theorem zero_zpow_eq (n : ℤ) : (0 : M) ^ n = if n = 0 then 1 else 0 := by
split_ifs with h · rw [h, zpow_zero] · rw [zero_zpow _ h]
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Floris van Doorn -/ import Mathlib.CategoryTheory.Limits.Filtered import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts import Mathlib.CategoryTheory.Limits.Shapes.Kernels import Mathlib.CategoryTheory.DiscreteCategory #align_import category_theory.limits.opposites from "leanprover-community/mathlib"@"ac3ae212f394f508df43e37aa093722fa9b65d31" /-! # Limits in `C` give colimits in `Cᵒᵖ`. We also give special cases for (co)products, (co)equalizers, and pullbacks / pushouts. -/ universe v₁ v₂ u₁ u₂ noncomputable section open CategoryTheory open CategoryTheory.Functor open Opposite namespace CategoryTheory.Limits variable {C : Type u₁} [Category.{v₁} C] variable {J : Type u₂} [Category.{v₂} J] #align category_theory.limits.is_limit_cocone_op CategoryTheory.Limits.IsColimit.op #align category_theory.limits.is_colimit_cone_op CategoryTheory.Limits.IsLimit.op #align category_theory.limits.is_limit_cocone_unop CategoryTheory.Limits.IsColimit.unop #align category_theory.limits.is_colimit_cone_unop CategoryTheory.Limits.IsLimit.unop -- 2024-03-26 @[deprecated] alias isLimitCoconeOp := IsColimit.op @[deprecated] alias isColimitConeOp := IsLimit.op @[deprecated] alias isLimitCoconeUnop := IsColimit.unop @[deprecated] alias isColimitConeUnop := IsLimit.unop /-- Turn a colimit for `F : J ⥤ Cᵒᵖ` into a limit for `F.leftOp : Jᵒᵖ ⥤ C`. -/ @[simps] def isLimitConeLeftOpOfCocone (F : J ⥤ Cᵒᵖ) {c : Cocone F} (hc : IsColimit c) : IsLimit (coneLeftOpOfCocone c) where lift s := (hc.desc (coconeOfConeLeftOp s)).unop fac s j := Quiver.Hom.op_inj <| by simp only [coneLeftOpOfCocone_π_app, op_comp, Quiver.Hom.op_unop, IsColimit.fac, coconeOfConeLeftOp_ι_app, op_unop] uniq s m w := by refine Quiver.Hom.op_inj (hc.hom_ext fun j => Quiver.Hom.unop_inj ?_) simpa only [Quiver.Hom.op_unop, IsColimit.fac, coconeOfConeLeftOp_ι_app] using w (op j) #align category_theory.limits.is_limit_cone_left_op_of_cocone CategoryTheory.Limits.isLimitConeLeftOpOfCocone /-- Turn a limit of `F : J ⥤ Cᵒᵖ` into a colimit of `F.leftOp : Jᵒᵖ ⥤ C`. -/ @[simps] def isColimitCoconeLeftOpOfCone (F : J ⥤ Cᵒᵖ) {c : Cone F} (hc : IsLimit c) : IsColimit (coconeLeftOpOfCone c) where desc s := (hc.lift (coneOfCoconeLeftOp s)).unop fac s j := Quiver.Hom.op_inj <| by simp only [coconeLeftOpOfCone_ι_app, op_comp, Quiver.Hom.op_unop, IsLimit.fac, coneOfCoconeLeftOp_π_app, op_unop] uniq s m w := by refine Quiver.Hom.op_inj (hc.hom_ext fun j => Quiver.Hom.unop_inj ?_) simpa only [Quiver.Hom.op_unop, IsLimit.fac, coneOfCoconeLeftOp_π_app] using w (op j) #align category_theory.limits.is_colimit_cocone_left_op_of_cone CategoryTheory.Limits.isColimitCoconeLeftOpOfCone /-- Turn a colimit for `F : Jᵒᵖ ⥤ C` into a limit for `F.rightOp : J ⥤ Cᵒᵖ`. -/ @[simps] def isLimitConeRightOpOfCocone (F : Jᵒᵖ ⥤ C) {c : Cocone F} (hc : IsColimit c) : IsLimit (coneRightOpOfCocone c) where lift s := (hc.desc (coconeOfConeRightOp s)).op fac s j := Quiver.Hom.unop_inj (by simp) uniq s m w := by refine Quiver.Hom.unop_inj (hc.hom_ext fun j => Quiver.Hom.op_inj ?_) simpa only [Quiver.Hom.unop_op, IsColimit.fac] using w (unop j) #align category_theory.limits.is_limit_cone_right_op_of_cocone CategoryTheory.Limits.isLimitConeRightOpOfCocone /-- Turn a limit for `F : Jᵒᵖ ⥤ C` into a colimit for `F.rightOp : J ⥤ Cᵒᵖ`. -/ @[simps] def isColimitCoconeRightOpOfCone (F : Jᵒᵖ ⥤ C) {c : Cone F} (hc : IsLimit c) : IsColimit (coconeRightOpOfCone c) where desc s := (hc.lift (coneOfCoconeRightOp s)).op fac s j := Quiver.Hom.unop_inj (by simp) uniq s m w := by refine Quiver.Hom.unop_inj (hc.hom_ext fun j => Quiver.Hom.op_inj ?_) simpa only [Quiver.Hom.unop_op, IsLimit.fac] using w (unop j) #align category_theory.limits.is_colimit_cocone_right_op_of_cone CategoryTheory.Limits.isColimitCoconeRightOpOfCone /-- Turn a colimit for `F : Jᵒᵖ ⥤ Cᵒᵖ` into a limit for `F.unop : J ⥤ C`. -/ @[simps] def isLimitConeUnopOfCocone (F : Jᵒᵖ ⥤ Cᵒᵖ) {c : Cocone F} (hc : IsColimit c) : IsLimit (coneUnopOfCocone c) where lift s := (hc.desc (coconeOfConeUnop s)).unop fac s j := Quiver.Hom.op_inj (by simp) uniq s m w := by refine Quiver.Hom.op_inj (hc.hom_ext fun j => Quiver.Hom.unop_inj ?_) simpa only [Quiver.Hom.op_unop, IsColimit.fac] using w (unop j) #align category_theory.limits.is_limit_cone_unop_of_cocone CategoryTheory.Limits.isLimitConeUnopOfCocone /-- Turn a limit of `F : Jᵒᵖ ⥤ Cᵒᵖ` into a colimit of `F.unop : J ⥤ C`. -/ @[simps] def isColimitCoconeUnopOfCone (F : Jᵒᵖ ⥤ Cᵒᵖ) {c : Cone F} (hc : IsLimit c) : IsColimit (coconeUnopOfCone c) where desc s := (hc.lift (coneOfCoconeUnop s)).unop fac s j := Quiver.Hom.op_inj (by simp) uniq s m w := by refine Quiver.Hom.op_inj (hc.hom_ext fun j => Quiver.Hom.unop_inj ?_) simpa only [Quiver.Hom.op_unop, IsLimit.fac] using w (unop j) #align category_theory.limits.is_colimit_cocone_unop_of_cone CategoryTheory.Limits.isColimitCoconeUnopOfCone /-- Turn a colimit for `F.leftOp : Jᵒᵖ ⥤ C` into a limit for `F : J ⥤ Cᵒᵖ`. -/ @[simps] def isLimitConeOfCoconeLeftOp (F : J ⥤ Cᵒᵖ) {c : Cocone F.leftOp} (hc : IsColimit c) : IsLimit (coneOfCoconeLeftOp c) where lift s := (hc.desc (coconeLeftOpOfCone s)).op fac s j := Quiver.Hom.unop_inj <| by simp only [coneOfCoconeLeftOp_π_app, unop_comp, Quiver.Hom.unop_op, IsColimit.fac, coconeLeftOpOfCone_ι_app, unop_op] uniq s m w := by refine Quiver.Hom.unop_inj (hc.hom_ext fun j => Quiver.Hom.op_inj ?_) simpa only [Quiver.Hom.unop_op, IsColimit.fac, coneOfCoconeLeftOp_π_app] using w (unop j) #align category_theory.limits.is_limit_cone_of_cocone_left_op CategoryTheory.Limits.isLimitConeOfCoconeLeftOp /-- Turn a limit of `F.leftOp : Jᵒᵖ ⥤ C` into a colimit of `F : J ⥤ Cᵒᵖ`. -/ @[simps] def isColimitCoconeOfConeLeftOp (F : J ⥤ Cᵒᵖ) {c : Cone F.leftOp} (hc : IsLimit c) : IsColimit (coconeOfConeLeftOp c) where desc s := (hc.lift (coneLeftOpOfCocone s)).op fac s j := Quiver.Hom.unop_inj <| by simp only [coconeOfConeLeftOp_ι_app, unop_comp, Quiver.Hom.unop_op, IsLimit.fac, coneLeftOpOfCocone_π_app, unop_op] uniq s m w := by refine Quiver.Hom.unop_inj (hc.hom_ext fun j => Quiver.Hom.op_inj ?_) simpa only [Quiver.Hom.unop_op, IsLimit.fac, coconeOfConeLeftOp_ι_app] using w (unop j) #align category_theory.limits.is_colimit_cocone_of_cone_left_op CategoryTheory.Limits.isColimitCoconeOfConeLeftOp /-- Turn a colimit for `F.rightOp : J ⥤ Cᵒᵖ` into a limit for `F : Jᵒᵖ ⥤ C`. -/ @[simps] def isLimitConeOfCoconeRightOp (F : Jᵒᵖ ⥤ C) {c : Cocone F.rightOp} (hc : IsColimit c) : IsLimit (coneOfCoconeRightOp c) where lift s := (hc.desc (coconeRightOpOfCone s)).unop fac s j := Quiver.Hom.op_inj (by simp) uniq s m w := by refine Quiver.Hom.op_inj (hc.hom_ext fun j => Quiver.Hom.unop_inj ?_) simpa only [Quiver.Hom.op_unop, IsColimit.fac] using w (op j) #align category_theory.limits.is_limit_cone_of_cocone_right_op CategoryTheory.Limits.isLimitConeOfCoconeRightOp /-- Turn a limit for `F.rightOp : J ⥤ Cᵒᵖ` into a limit for `F : Jᵒᵖ ⥤ C`. -/ @[simps] def isColimitCoconeOfConeRightOp (F : Jᵒᵖ ⥤ C) {c : Cone F.rightOp} (hc : IsLimit c) : IsColimit (coconeOfConeRightOp c) where desc s := (hc.lift (coneRightOpOfCocone s)).unop fac s j := Quiver.Hom.op_inj (by simp) uniq s m w := by refine Quiver.Hom.op_inj (hc.hom_ext fun j => Quiver.Hom.unop_inj ?_) simpa only [Quiver.Hom.op_unop, IsLimit.fac] using w (op j) #align category_theory.limits.is_colimit_cocone_of_cone_right_op CategoryTheory.Limits.isColimitCoconeOfConeRightOp /-- Turn a colimit for `F.unop : J ⥤ C` into a limit for `F : Jᵒᵖ ⥤ Cᵒᵖ`. -/ @[simps] def isLimitConeOfCoconeUnop (F : Jᵒᵖ ⥤ Cᵒᵖ) {c : Cocone F.unop} (hc : IsColimit c) : IsLimit (coneOfCoconeUnop c) where lift s := (hc.desc (coconeUnopOfCone s)).op fac s j := Quiver.Hom.unop_inj (by simp) uniq s m w := by refine Quiver.Hom.unop_inj (hc.hom_ext fun j => Quiver.Hom.op_inj ?_) simpa only [Quiver.Hom.unop_op, IsColimit.fac] using w (op j) #align category_theory.limits.is_limit_cone_of_cocone_unop CategoryTheory.Limits.isLimitConeOfCoconeUnop /-- Turn a limit for `F.unop : J ⥤ C` into a colimit for `F : Jᵒᵖ ⥤ Cᵒᵖ`. -/ @[simps] def isColimitConeOfCoconeUnop (F : Jᵒᵖ ⥤ Cᵒᵖ) {c : Cone F.unop} (hc : IsLimit c) : IsColimit (coconeOfConeUnop c) where desc s := (hc.lift (coneUnopOfCocone s)).op fac s j := Quiver.Hom.unop_inj (by simp) uniq s m w := by refine Quiver.Hom.unop_inj (hc.hom_ext fun j => Quiver.Hom.op_inj ?_) simpa only [Quiver.Hom.unop_op, IsLimit.fac] using w (op j) #align category_theory.limits.is_colimit_cone_of_cocone_unop CategoryTheory.Limits.isColimitConeOfCoconeUnop /-- If `F.leftOp : Jᵒᵖ ⥤ C` has a colimit, we can construct a limit for `F : J ⥤ Cᵒᵖ`. -/ theorem hasLimit_of_hasColimit_leftOp (F : J ⥤ Cᵒᵖ) [HasColimit F.leftOp] : HasLimit F := HasLimit.mk { cone := coneOfCoconeLeftOp (colimit.cocone F.leftOp) isLimit := isLimitConeOfCoconeLeftOp _ (colimit.isColimit _) } #align category_theory.limits.has_limit_of_has_colimit_left_op CategoryTheory.Limits.hasLimit_of_hasColimit_leftOp theorem hasLimit_of_hasColimit_op (F : J ⥤ C) [HasColimit F.op] : HasLimit F := HasLimit.mk { cone := (colimit.cocone F.op).unop isLimit := (colimit.isColimit _).unop } theorem hasLimit_op_of_hasColimit (F : J ⥤ C) [HasColimit F] : HasLimit F.op := HasLimit.mk { cone := (colimit.cocone F).op isLimit := (colimit.isColimit _).op } #align category_theory.limits.has_limit_of_has_colimit_op CategoryTheory.Limits.hasLimit_of_hasColimit_op /-- If `C` has colimits of shape `Jᵒᵖ`, we can construct limits in `Cᵒᵖ` of shape `J`. -/ theorem hasLimitsOfShape_op_of_hasColimitsOfShape [HasColimitsOfShape Jᵒᵖ C] : HasLimitsOfShape J Cᵒᵖ := { has_limit := fun F => hasLimit_of_hasColimit_leftOp F } #align category_theory.limits.has_limits_of_shape_op_of_has_colimits_of_shape CategoryTheory.Limits.hasLimitsOfShape_op_of_hasColimitsOfShape theorem hasLimitsOfShape_of_hasColimitsOfShape_op [HasColimitsOfShape Jᵒᵖ Cᵒᵖ] : HasLimitsOfShape J C := { has_limit := fun F => hasLimit_of_hasColimit_op F } #align category_theory.limits.has_limits_of_shape_of_has_colimits_of_shape_op CategoryTheory.Limits.hasLimitsOfShape_of_hasColimitsOfShape_op attribute [local instance] hasLimitsOfShape_op_of_hasColimitsOfShape /-- If `C` has colimits, we can construct limits for `Cᵒᵖ`. -/ instance hasLimits_op_of_hasColimits [HasColimits C] : HasLimits Cᵒᵖ := ⟨fun _ => inferInstance⟩ #align category_theory.limits.has_limits_op_of_has_colimits CategoryTheory.Limits.hasLimits_op_of_hasColimits theorem hasLimits_of_hasColimits_op [HasColimits Cᵒᵖ] : HasLimits C := { has_limits_of_shape := fun _ _ => hasLimitsOfShape_of_hasColimitsOfShape_op } #align category_theory.limits.has_limits_of_has_colimits_op CategoryTheory.Limits.hasLimits_of_hasColimits_op instance has_cofiltered_limits_op_of_has_filtered_colimits [HasFilteredColimitsOfSize.{v₂, u₂} C] : HasCofilteredLimitsOfSize.{v₂, u₂} Cᵒᵖ where HasLimitsOfShape _ _ _ := hasLimitsOfShape_op_of_hasColimitsOfShape #align category_theory.limits.has_cofiltered_limits_op_of_has_filtered_colimits CategoryTheory.Limits.has_cofiltered_limits_op_of_has_filtered_colimits theorem has_cofiltered_limits_of_has_filtered_colimits_op [HasFilteredColimitsOfSize.{v₂, u₂} Cᵒᵖ] : HasCofilteredLimitsOfSize.{v₂, u₂} C := { HasLimitsOfShape := fun _ _ _ => hasLimitsOfShape_of_hasColimitsOfShape_op } #align category_theory.limits.has_cofiltered_limits_of_has_filtered_colimits_op CategoryTheory.Limits.has_cofiltered_limits_of_has_filtered_colimits_op /-- If `F.leftOp : Jᵒᵖ ⥤ C` has a limit, we can construct a colimit for `F : J ⥤ Cᵒᵖ`. -/ theorem hasColimit_of_hasLimit_leftOp (F : J ⥤ Cᵒᵖ) [HasLimit F.leftOp] : HasColimit F := HasColimit.mk { cocone := coconeOfConeLeftOp (limit.cone F.leftOp) isColimit := isColimitCoconeOfConeLeftOp _ (limit.isLimit _) } #align category_theory.limits.has_colimit_of_has_limit_left_op CategoryTheory.Limits.hasColimit_of_hasLimit_leftOp theorem hasColimit_of_hasLimit_op (F : J ⥤ C) [HasLimit F.op] : HasColimit F := HasColimit.mk { cocone := (limit.cone F.op).unop isColimit := (limit.isLimit _).unop } #align category_theory.limits.has_colimit_of_has_limit_op CategoryTheory.Limits.hasColimit_of_hasLimit_op theorem hasColimit_op_of_hasLimit (F : J ⥤ C) [HasLimit F] : HasColimit F.op := HasColimit.mk { cocone := (limit.cone F).op isColimit := (limit.isLimit _).op } /-- If `C` has colimits of shape `Jᵒᵖ`, we can construct limits in `Cᵒᵖ` of shape `J`. -/ instance hasColimitsOfShape_op_of_hasLimitsOfShape [HasLimitsOfShape Jᵒᵖ C] : HasColimitsOfShape J Cᵒᵖ where has_colimit F := hasColimit_of_hasLimit_leftOp F #align category_theory.limits.has_colimits_of_shape_op_of_has_limits_of_shape CategoryTheory.Limits.hasColimitsOfShape_op_of_hasLimitsOfShape theorem hasColimitsOfShape_of_hasLimitsOfShape_op [HasLimitsOfShape Jᵒᵖ Cᵒᵖ] : HasColimitsOfShape J C := { has_colimit := fun F => hasColimit_of_hasLimit_op F } #align category_theory.limits.has_colimits_of_shape_of_has_limits_of_shape_op CategoryTheory.Limits.hasColimitsOfShape_of_hasLimitsOfShape_op /-- If `C` has limits, we can construct colimits for `Cᵒᵖ`. -/ instance hasColimits_op_of_hasLimits [HasLimits C] : HasColimits Cᵒᵖ := ⟨fun _ => inferInstance⟩ #align category_theory.limits.has_colimits_op_of_has_limits CategoryTheory.Limits.hasColimits_op_of_hasLimits theorem hasColimits_of_hasLimits_op [HasLimits Cᵒᵖ] : HasColimits C := { has_colimits_of_shape := fun _ _ => hasColimitsOfShape_of_hasLimitsOfShape_op } #align category_theory.limits.has_colimits_of_has_limits_op CategoryTheory.Limits.hasColimits_of_hasLimits_op instance has_filtered_colimits_op_of_has_cofiltered_limits [HasCofilteredLimitsOfSize.{v₂, u₂} C] : HasFilteredColimitsOfSize.{v₂, u₂} Cᵒᵖ where HasColimitsOfShape _ _ _ := inferInstance #align category_theory.limits.has_filtered_colimits_op_of_has_cofiltered_limits CategoryTheory.Limits.has_filtered_colimits_op_of_has_cofiltered_limits theorem has_filtered_colimits_of_has_cofiltered_limits_op [HasCofilteredLimitsOfSize.{v₂, u₂} Cᵒᵖ] : HasFilteredColimitsOfSize.{v₂, u₂} C := { HasColimitsOfShape := fun _ _ _ => hasColimitsOfShape_of_hasLimitsOfShape_op } #align category_theory.limits.has_filtered_colimits_of_has_cofiltered_limits_op CategoryTheory.Limits.has_filtered_colimits_of_has_cofiltered_limits_op variable (X : Type v₂) /-- If `C` has products indexed by `X`, then `Cᵒᵖ` has coproducts indexed by `X`. -/ instance hasCoproductsOfShape_opposite [HasProductsOfShape X C] : HasCoproductsOfShape X Cᵒᵖ := by haveI : HasLimitsOfShape (Discrete X)ᵒᵖ C := hasLimitsOfShape_of_equivalence (Discrete.opposite X).symm infer_instance #align category_theory.limits.has_coproducts_of_shape_opposite CategoryTheory.Limits.hasCoproductsOfShape_opposite theorem hasCoproductsOfShape_of_opposite [HasProductsOfShape X Cᵒᵖ] : HasCoproductsOfShape X C := haveI : HasLimitsOfShape (Discrete X)ᵒᵖ Cᵒᵖ := hasLimitsOfShape_of_equivalence (Discrete.opposite X).symm hasColimitsOfShape_of_hasLimitsOfShape_op #align category_theory.limits.has_coproducts_of_shape_of_opposite CategoryTheory.Limits.hasCoproductsOfShape_of_opposite /-- If `C` has coproducts indexed by `X`, then `Cᵒᵖ` has products indexed by `X`. -/ instance hasProductsOfShape_opposite [HasCoproductsOfShape X C] : HasProductsOfShape X Cᵒᵖ := by haveI : HasColimitsOfShape (Discrete X)ᵒᵖ C := hasColimitsOfShape_of_equivalence (Discrete.opposite X).symm infer_instance #align category_theory.limits.has_products_of_shape_opposite CategoryTheory.Limits.hasProductsOfShape_opposite theorem hasProductsOfShape_of_opposite [HasCoproductsOfShape X Cᵒᵖ] : HasProductsOfShape X C := haveI : HasColimitsOfShape (Discrete X)ᵒᵖ Cᵒᵖ := hasColimitsOfShape_of_equivalence (Discrete.opposite X).symm hasLimitsOfShape_of_hasColimitsOfShape_op #align category_theory.limits.has_products_of_shape_of_opposite CategoryTheory.Limits.hasProductsOfShape_of_opposite instance hasProducts_opposite [HasCoproducts.{v₂} C] : HasProducts.{v₂} Cᵒᵖ := fun _ => inferInstance #align category_theory.limits.has_products_opposite CategoryTheory.Limits.hasProducts_opposite theorem hasProducts_of_opposite [HasCoproducts.{v₂} Cᵒᵖ] : HasProducts.{v₂} C := fun X => hasProductsOfShape_of_opposite X #align category_theory.limits.has_products_of_opposite CategoryTheory.Limits.hasProducts_of_opposite instance hasCoproducts_opposite [HasProducts.{v₂} C] : HasCoproducts.{v₂} Cᵒᵖ := fun _ => inferInstance #align category_theory.limits.has_coproducts_opposite CategoryTheory.Limits.hasCoproducts_opposite theorem hasCoproducts_of_opposite [HasProducts.{v₂} Cᵒᵖ] : HasCoproducts.{v₂} C := fun X => hasCoproductsOfShape_of_opposite X #align category_theory.limits.has_coproducts_of_opposite CategoryTheory.Limits.hasCoproducts_of_opposite instance hasFiniteCoproducts_opposite [HasFiniteProducts C] : HasFiniteCoproducts Cᵒᵖ where out _ := Limits.hasCoproductsOfShape_opposite _ #align category_theory.limits.has_finite_coproducts_opposite CategoryTheory.Limits.hasFiniteCoproducts_opposite theorem hasFiniteCoproducts_of_opposite [HasFiniteProducts Cᵒᵖ] : HasFiniteCoproducts C := { out := fun _ => hasCoproductsOfShape_of_opposite _ } #align category_theory.limits.has_finite_coproducts_of_opposite CategoryTheory.Limits.hasFiniteCoproducts_of_opposite instance hasFiniteProducts_opposite [HasFiniteCoproducts C] : HasFiniteProducts Cᵒᵖ where out _ := inferInstance #align category_theory.limits.has_finite_products_opposite CategoryTheory.Limits.hasFiniteProducts_opposite theorem hasFiniteProducts_of_opposite [HasFiniteCoproducts Cᵒᵖ] : HasFiniteProducts C := { out := fun _ => hasProductsOfShape_of_opposite _ } #align category_theory.limits.has_finite_products_of_opposite CategoryTheory.Limits.hasFiniteProducts_of_opposite section OppositeCoproducts variable {α : Type*} {Z : α → C} [HasCoproduct Z] instance : HasLimit (Discrete.functor Z).op := hasLimit_op_of_hasColimit (Discrete.functor Z) instance : HasLimit ((Discrete.opposite α).inverse ⋙ (Discrete.functor Z).op) := hasLimitEquivalenceComp (Discrete.opposite α).symm instance : HasProduct (op <| Z ·) := hasLimitOfIso ((Discrete.natIsoFunctor ≪≫ Discrete.natIso (fun _ ↦ by rfl)) : (Discrete.opposite α).inverse ⋙ (Discrete.functor Z).op ≅ Discrete.functor (op <| Z ·)) /-- A `Cofan` gives a `Fan` in the opposite category. -/ @[simp] def Cofan.op (c : Cofan Z) : Fan (op <| Z ·) := Fan.mk _ (fun a ↦ (c.inj a).op) /-- If a `Cofan` is colimit, then its opposite is limit. -/ def Cofan.IsColimit.op {c : Cofan Z} (hc : IsColimit c) : IsLimit c.op := by let e : Discrete.functor (Opposite.op <| Z ·) ≅ (Discrete.opposite α).inverse ⋙ (Discrete.functor Z).op := Discrete.natIso (fun _ ↦ Iso.refl _) refine IsLimit.ofIsoLimit ((IsLimit.postcomposeInvEquiv e _).2 (IsLimit.whiskerEquivalence hc.op (Discrete.opposite α).symm)) (Cones.ext (Iso.refl _) (fun ⟨a⟩ ↦ ?_)) dsimp erw [Category.id_comp, Category.comp_id] rfl /-- The canonical isomorphism from the opposite of an abstract coproduct to the corresponding product in the opposite category. -/ def opCoproductIsoProduct' {c : Cofan Z} {f : Fan (op <| Z ·)} (hc : IsColimit c) (hf : IsLimit f) : op c.pt ≅ f.pt := IsLimit.conePointUniqueUpToIso (Cofan.IsColimit.op hc) hf variable (Z) in /-- The canonical isomorphism from the opposite of the coproduct to the product in the opposite category. -/ def opCoproductIsoProduct : op (∐ Z) ≅ ∏ᶜ (op <| Z ·) := opCoproductIsoProduct' (coproductIsCoproduct Z) (productIsProduct (op <| Z ·)) theorem opCoproductIsoProduct'_inv_comp_inj {c : Cofan Z} {f : Fan (op <| Z ·)} (hc : IsColimit c) (hf : IsLimit f) (b : α) : (opCoproductIsoProduct' hc hf).inv ≫ (c.inj b).op = f.proj b := IsLimit.conePointUniqueUpToIso_inv_comp (Cofan.IsColimit.op hc) hf ⟨b⟩ theorem opCoproductIsoProduct'_comp_self {c c' : Cofan Z} {f : Fan (op <| Z ·)} (hc : IsColimit c) (hc' : IsColimit c') (hf : IsLimit f) : (opCoproductIsoProduct' hc hf).hom ≫ (opCoproductIsoProduct' hc' hf).inv = (hc.coconePointUniqueUpToIso hc').op.inv := by apply Quiver.Hom.unop_inj apply hc'.hom_ext intro ⟨j⟩ change c'.inj _ ≫ _ = _ simp only [unop_op, unop_comp, Discrete.functor_obj, const_obj_obj, Iso.op_inv, Quiver.Hom.unop_op, IsColimit.comp_coconePointUniqueUpToIso_inv] apply Quiver.Hom.op_inj simp only [op_comp, op_unop, Quiver.Hom.op_unop, Category.assoc, opCoproductIsoProduct'_inv_comp_inj] rw [← opCoproductIsoProduct'_inv_comp_inj hc hf] simp only [Iso.hom_inv_id_assoc] rfl variable (Z) in theorem opCoproductIsoProduct_inv_comp_ι (b : α) : (opCoproductIsoProduct Z).inv ≫ (Sigma.ι Z b).op = Pi.π (op <| Z ·) b := opCoproductIsoProduct'_inv_comp_inj _ _ b theorem desc_op_comp_opCoproductIsoProduct'_hom {c : Cofan Z} {f : Fan (op <| Z ·)} (hc : IsColimit c) (hf : IsLimit f) (c' : Cofan Z) : (hc.desc c').op ≫ (opCoproductIsoProduct' hc hf).hom = hf.lift c'.op := by refine (Iso.eq_comp_inv _).mp (Quiver.Hom.unop_inj (hc.hom_ext (fun ⟨j⟩ ↦ Quiver.Hom.op_inj ?_))) simp only [unop_op, Discrete.functor_obj, const_obj_obj, Quiver.Hom.unop_op, IsColimit.fac, Cofan.op, unop_comp, op_comp, op_unop, Quiver.Hom.op_unop, Category.assoc] erw [opCoproductIsoProduct'_inv_comp_inj, IsLimit.fac] rfl theorem desc_op_comp_opCoproductIsoProduct_hom {X : C} (π : (a : α) → Z a ⟶ X) : (Sigma.desc π).op ≫ (opCoproductIsoProduct Z).hom = Pi.lift (fun a ↦ (π a).op) := by convert desc_op_comp_opCoproductIsoProduct'_hom (coproductIsCoproduct Z) (productIsProduct (op <| Z ·)) (Cofan.mk _ π) · ext; simp [Sigma.desc, coproductIsCoproduct] · ext; simp [Pi.lift, productIsProduct] end OppositeCoproducts section OppositeProducts variable {α : Type*} {Z : α → C} [HasProduct Z] instance : HasColimit (Discrete.functor Z).op := hasColimit_op_of_hasLimit (Discrete.functor Z) instance : HasColimit ((Discrete.opposite α).inverse ⋙ (Discrete.functor Z).op) := hasColimit_equivalence_comp (Discrete.opposite α).symm instance : HasCoproduct (op <| Z ·) := hasColimitOfIso ((Discrete.natIsoFunctor ≪≫ Discrete.natIso (fun _ ↦ by rfl)) : (Discrete.opposite α).inverse ⋙ (Discrete.functor Z).op ≅ Discrete.functor (op <| Z ·)).symm /-- A `Fan` gives a `Cofan` in the opposite category. -/ @[simp] def Fan.op (f : Fan Z) : Cofan (op <| Z ·) := Cofan.mk _ (fun a ↦ (f.proj a).op) /-- If a `Fan` is limit, then its opposite is colimit. -/ def Fan.IsLimit.op {f : Fan Z} (hf : IsLimit f) : IsColimit f.op := by let e : Discrete.functor (Opposite.op <| Z ·) ≅ (Discrete.opposite α).inverse ⋙ (Discrete.functor Z).op := Discrete.natIso (fun _ ↦ Iso.refl _) refine IsColimit.ofIsoColimit ((IsColimit.precomposeHomEquiv e _).2 (IsColimit.whiskerEquivalence hf.op (Discrete.opposite α).symm)) (Cocones.ext (Iso.refl _) (fun ⟨a⟩ ↦ ?_)) dsimp erw [Category.id_comp, Category.comp_id] rfl /-- The canonical isomorphism from the opposite of an abstract product to the corresponding coproduct in the opposite category. -/ def opProductIsoCoproduct' {f : Fan Z} {c : Cofan (op <| Z ·)} (hf : IsLimit f) (hc : IsColimit c) : op f.pt ≅ c.pt := IsColimit.coconePointUniqueUpToIso (Fan.IsLimit.op hf) hc variable (Z) in /-- The canonical isomorphism from the opposite of the product to the coproduct in the opposite category. -/ def opProductIsoCoproduct : op (∏ᶜ Z) ≅ ∐ (op <| Z ·) := opProductIsoCoproduct' (productIsProduct Z) (coproductIsCoproduct (op <| Z ·)) theorem proj_comp_opProductIsoCoproduct'_hom {f : Fan Z} {c : Cofan (op <| Z ·)} (hf : IsLimit f) (hc : IsColimit c) (b : α) : (f.proj b).op ≫ (opProductIsoCoproduct' hf hc).hom = c.inj b := IsColimit.comp_coconePointUniqueUpToIso_hom (Fan.IsLimit.op hf) hc ⟨b⟩ theorem opProductIsoCoproduct'_comp_self {f f' : Fan Z} {c : Cofan (op <| Z ·)} (hf : IsLimit f) (hf' : IsLimit f') (hc : IsColimit c) : (opProductIsoCoproduct' hf hc).hom ≫ (opProductIsoCoproduct' hf' hc).inv = (hf.conePointUniqueUpToIso hf').op.inv := by apply Quiver.Hom.unop_inj apply hf.hom_ext intro ⟨j⟩ change _ ≫ f.proj _ = _ simp only [unop_op, unop_comp, Category.assoc, Discrete.functor_obj, Iso.op_inv, Quiver.Hom.unop_op, IsLimit.conePointUniqueUpToIso_inv_comp] apply Quiver.Hom.op_inj simp only [op_comp, op_unop, Quiver.Hom.op_unop, proj_comp_opProductIsoCoproduct'_hom] rw [← proj_comp_opProductIsoCoproduct'_hom hf' hc] simp only [Category.assoc, Iso.hom_inv_id, Category.comp_id] rfl variable (Z) in theorem π_comp_opProductIsoCoproduct_hom (b : α) : (Pi.π Z b).op ≫ (opProductIsoCoproduct Z).hom = Sigma.ι (op <| Z ·) b := proj_comp_opProductIsoCoproduct'_hom _ _ b theorem opProductIsoCoproduct'_inv_comp_lift {f : Fan Z} {c : Cofan (op <| Z ·)} (hf : IsLimit f) (hc : IsColimit c) (f' : Fan Z) : (opProductIsoCoproduct' hf hc).inv ≫ (hf.lift f').op = hc.desc f'.op := by refine (Iso.inv_comp_eq _).mpr (Quiver.Hom.unop_inj (hf.hom_ext (fun ⟨j⟩ ↦ Quiver.Hom.op_inj ?_))) simp only [Discrete.functor_obj, unop_op, Quiver.Hom.unop_op, IsLimit.fac, Fan.op, unop_comp, Category.assoc, op_comp, op_unop, Quiver.Hom.op_unop] erw [← Category.assoc, proj_comp_opProductIsoCoproduct'_hom, IsColimit.fac] rfl theorem opProductIsoCoproduct_inv_comp_lift {X : C} (π : (a : α) → X ⟶ Z a) : (opProductIsoCoproduct Z).inv ≫ (Pi.lift π).op = Sigma.desc (fun a ↦ (π a).op) := by convert opProductIsoCoproduct'_inv_comp_lift (productIsProduct Z) (coproductIsCoproduct (op <| Z ·)) (Fan.mk _ π) · ext; simp [Pi.lift, productIsProduct] · ext; simp [Sigma.desc, coproductIsCoproduct] end OppositeProducts instance hasEqualizers_opposite [HasCoequalizers C] : HasEqualizers Cᵒᵖ := by haveI : HasColimitsOfShape WalkingParallelPairᵒᵖ C := hasColimitsOfShape_of_equivalence walkingParallelPairOpEquiv infer_instance #align category_theory.limits.has_equalizers_opposite CategoryTheory.Limits.hasEqualizers_opposite instance hasCoequalizers_opposite [HasEqualizers C] : HasCoequalizers Cᵒᵖ := by haveI : HasLimitsOfShape WalkingParallelPairᵒᵖ C := hasLimitsOfShape_of_equivalence walkingParallelPairOpEquiv infer_instance #align category_theory.limits.has_coequalizers_opposite CategoryTheory.Limits.hasCoequalizers_opposite instance hasFiniteColimits_opposite [HasFiniteLimits C] : HasFiniteColimits Cᵒᵖ := ⟨fun _ _ _ => inferInstance⟩ #align category_theory.limits.has_finite_colimits_opposite CategoryTheory.Limits.hasFiniteColimits_opposite instance hasFiniteLimits_opposite [HasFiniteColimits C] : HasFiniteLimits Cᵒᵖ := ⟨fun _ _ _ => inferInstance⟩ #align category_theory.limits.has_finite_limits_opposite CategoryTheory.Limits.hasFiniteLimits_opposite instance hasPullbacks_opposite [HasPushouts C] : HasPullbacks Cᵒᵖ := by haveI : HasColimitsOfShape WalkingCospanᵒᵖ C := hasColimitsOfShape_of_equivalence walkingCospanOpEquiv.symm apply hasLimitsOfShape_op_of_hasColimitsOfShape #align category_theory.limits.has_pullbacks_opposite CategoryTheory.Limits.hasPullbacks_opposite instance hasPushouts_opposite [HasPullbacks C] : HasPushouts Cᵒᵖ := by haveI : HasLimitsOfShape WalkingSpanᵒᵖ C := hasLimitsOfShape_of_equivalence walkingSpanOpEquiv.symm infer_instance #align category_theory.limits.has_pushouts_opposite CategoryTheory.Limits.hasPushouts_opposite /-- The canonical isomorphism relating `Span f.op g.op` and `(Cospan f g).op` -/ @[simps!] def spanOp {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : span f.op g.op ≅ walkingCospanOpEquiv.inverse ⋙ (cospan f g).op := NatIso.ofComponents (by rintro (_ | _ | _) <;> rfl) (by rintro (_ | _ | _) (_ | _ | _) f <;> cases f <;> aesop_cat) #align category_theory.limits.span_op CategoryTheory.Limits.spanOp /-- The canonical isomorphism relating `(Cospan f g).op` and `Span f.op g.op` -/ @[simps!] def opCospan {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) : (cospan f g).op ≅ walkingCospanOpEquiv.functor ⋙ span f.op g.op := calc (cospan f g).op ≅ 𝟭 _ ⋙ (cospan f g).op := by rfl _ ≅ (walkingCospanOpEquiv.functor ⋙ walkingCospanOpEquiv.inverse) ⋙ (cospan f g).op := (isoWhiskerRight walkingCospanOpEquiv.unitIso _) _ ≅ walkingCospanOpEquiv.functor ⋙ walkingCospanOpEquiv.inverse ⋙ (cospan f g).op := (Functor.associator _ _ _) _ ≅ walkingCospanOpEquiv.functor ⋙ span f.op g.op := isoWhiskerLeft _ (spanOp f g).symm #align category_theory.limits.op_cospan CategoryTheory.Limits.opCospan /-- The canonical isomorphism relating `Cospan f.op g.op` and `(Span f g).op` -/ @[simps!] def cospanOp {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : cospan f.op g.op ≅ walkingSpanOpEquiv.inverse ⋙ (span f g).op := NatIso.ofComponents (by rintro (_ | _ | _) <;> rfl) (by rintro (_ | _ | _) (_ | _ | _) f <;> cases f <;> aesop_cat) #align category_theory.limits.cospan_op CategoryTheory.Limits.cospanOp /-- The canonical isomorphism relating `(Span f g).op` and `Cospan f.op g.op` -/ @[simps!] def opSpan {X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z) : (span f g).op ≅ walkingSpanOpEquiv.functor ⋙ cospan f.op g.op := calc (span f g).op ≅ 𝟭 _ ⋙ (span f g).op := by rfl _ ≅ (walkingSpanOpEquiv.functor ⋙ walkingSpanOpEquiv.inverse) ⋙ (span f g).op := (isoWhiskerRight walkingSpanOpEquiv.unitIso _) _ ≅ walkingSpanOpEquiv.functor ⋙ walkingSpanOpEquiv.inverse ⋙ (span f g).op := (Functor.associator _ _ _) _ ≅ walkingSpanOpEquiv.functor ⋙ cospan f.op g.op := isoWhiskerLeft _ (cospanOp f g).symm #align category_theory.limits.op_span CategoryTheory.Limits.opSpan namespace PushoutCocone -- Porting note: it was originally @[simps (config := lemmasOnly)] /-- The obvious map `PushoutCocone f g → PullbackCone f.unop g.unop` -/ @[simps!] def unop {X Y Z : Cᵒᵖ} {f : X ⟶ Y} {g : X ⟶ Z} (c : PushoutCocone f g) : PullbackCone f.unop g.unop := Cocone.unop ((Cocones.precompose (opCospan f.unop g.unop).hom).obj (Cocone.whisker walkingCospanOpEquiv.functor c)) #align category_theory.limits.pushout_cocone.unop CategoryTheory.Limits.PushoutCocone.unop -- Porting note (#10618): removed simp attribute as the equality can already be obtained by simp theorem unop_fst {X Y Z : Cᵒᵖ} {f : X ⟶ Y} {g : X ⟶ Z} (c : PushoutCocone f g) : c.unop.fst = c.inl.unop := by simp #align category_theory.limits.pushout_cocone.unop_fst CategoryTheory.Limits.PushoutCocone.unop_fst -- Porting note (#10618): removed simp attribute as the equality can already be obtained by simp theorem unop_snd {X Y Z : Cᵒᵖ} {f : X ⟶ Y} {g : X ⟶ Z} (c : PushoutCocone f g) : c.unop.snd = c.inr.unop := by aesop_cat #align category_theory.limits.pushout_cocone.unop_snd CategoryTheory.Limits.PushoutCocone.unop_snd -- Porting note: it was originally @[simps (config := lemmasOnly)] /-- The obvious map `PushoutCocone f.op g.op → PullbackCone f g` -/ @[simps!] def op {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} (c : PushoutCocone f g) : PullbackCone f.op g.op := (Cones.postcompose (cospanOp f g).symm.hom).obj (Cone.whisker walkingSpanOpEquiv.inverse (Cocone.op c)) #align category_theory.limits.pushout_cocone.op CategoryTheory.Limits.PushoutCocone.op -- Porting note (#10618): removed simp attribute as the equality can already be obtained by simp theorem op_fst {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} (c : PushoutCocone f g) : c.op.fst = c.inl.op := by aesop_cat #align category_theory.limits.pushout_cocone.op_fst CategoryTheory.Limits.PushoutCocone.op_fst -- Porting note (#10618): removed simp attribute as the equality can already be obtained by simp theorem op_snd {X Y Z : C} {f : X ⟶ Y} {g : X ⟶ Z} (c : PushoutCocone f g) : c.op.snd = c.inr.op := by aesop_cat #align category_theory.limits.pushout_cocone.op_snd CategoryTheory.Limits.PushoutCocone.op_snd end PushoutCocone namespace PullbackCone -- Porting note: it was originally @[simps (config := lemmasOnly)] /-- The obvious map `PullbackCone f g → PushoutCocone f.unop g.unop` -/ @[simps!] def unop {X Y Z : Cᵒᵖ} {f : X ⟶ Z} {g : Y ⟶ Z} (c : PullbackCone f g) : PushoutCocone f.unop g.unop := Cone.unop ((Cones.postcompose (opSpan f.unop g.unop).symm.hom).obj (Cone.whisker walkingSpanOpEquiv.functor c)) #align category_theory.limits.pullback_cone.unop CategoryTheory.Limits.PullbackCone.unop -- Porting note (#10618): removed simp attribute as the equality can already be obtained by simp
Mathlib/CategoryTheory/Limits/Opposites.lean
666
667
theorem unop_inl {X Y Z : Cᵒᵖ} {f : X ⟶ Z} {g : Y ⟶ Z} (c : PullbackCone f g) : c.unop.inl = c.fst.unop := by
aesop_cat
/- Copyright (c) 2022 Joachim Breitner. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joachim Breitner -/ import Mathlib.GroupTheory.OrderOfElement import Mathlib.Data.Finset.NoncommProd import Mathlib.Data.Fintype.BigOperators import Mathlib.Data.Nat.GCD.BigOperators import Mathlib.Order.SupIndep #align_import group_theory.noncomm_pi_coprod from "leanprover-community/mathlib"@"6f9f36364eae3f42368b04858fd66d6d9ae730d8" /-! # Canonical homomorphism from a finite family of monoids This file defines the construction of the canonical homomorphism from a family of monoids. Given a family of morphisms `ϕ i : N i →* M` for each `i : ι` where elements in the images of different morphisms commute, we obtain a canonical morphism `MonoidHom.noncommPiCoprod : (Π i, N i) →* M` that coincides with `ϕ` ## Main definitions * `MonoidHom.noncommPiCoprod : (Π i, N i) →* M` is the main homomorphism * `Subgroup.noncommPiCoprod : (Π i, H i) →* G` is the specialization to `H i : Subgroup G` and the subgroup embedding. ## Main theorems * `MonoidHom.noncommPiCoprod` coincides with `ϕ i` when restricted to `N i` * `MonoidHom.noncommPiCoprod_mrange`: The range of `MonoidHom.noncommPiCoprod` is `⨆ (i : ι), (ϕ i).mrange` * `MonoidHom.noncommPiCoprod_range`: The range of `MonoidHom.noncommPiCoprod` is `⨆ (i : ι), (ϕ i).range` * `Subgroup.noncommPiCoprod_range`: The range of `Subgroup.noncommPiCoprod` is `⨆ (i : ι), H i`. * `MonoidHom.injective_noncommPiCoprod_of_independent`: in the case of groups, `pi_hom.hom` is injective if the `ϕ` are injective and the ranges of the `ϕ` are independent. * `MonoidHom.independent_range_of_coprime_order`: If the `N i` have coprime orders, then the ranges of the `ϕ` are independent. * `Subgroup.independent_of_coprime_order`: If commuting normal subgroups `H i` have coprime orders, they are independent. -/ namespace Subgroup variable {G : Type*} [Group G] /-- `Finset.noncommProd` is “injective” in `f` if `f` maps into independent subgroups. This generalizes (one direction of) `Subgroup.disjoint_iff_mul_eq_one`. -/ @[to_additive "`Finset.noncommSum` is “injective” in `f` if `f` maps into independent subgroups. This generalizes (one direction of) `AddSubgroup.disjoint_iff_add_eq_zero`. "] theorem eq_one_of_noncommProd_eq_one_of_independent {ι : Type*} (s : Finset ι) (f : ι → G) (comm) (K : ι → Subgroup G) (hind : CompleteLattice.Independent K) (hmem : ∀ x ∈ s, f x ∈ K x) (heq1 : s.noncommProd f comm = 1) : ∀ i ∈ s, f i = 1 := by classical revert heq1 induction' s using Finset.induction_on with i s hnmem ih · simp · have hcomm := comm.mono (Finset.coe_subset.2 <| Finset.subset_insert _ _) simp only [Finset.forall_mem_insert] at hmem have hmem_bsupr : s.noncommProd f hcomm ∈ ⨆ i ∈ (s : Set ι), K i := by refine Subgroup.noncommProd_mem _ _ ?_ intro x hx have : K x ≤ ⨆ i ∈ (s : Set ι), K i := le_iSup₂ (f := fun i _ => K i) x hx exact this (hmem.2 x hx) intro heq1 rw [Finset.noncommProd_insert_of_not_mem _ _ _ _ hnmem] at heq1 have hnmem' : i ∉ (s : Set ι) := by simpa obtain ⟨heq1i : f i = 1, heq1S : s.noncommProd f _ = 1⟩ := Subgroup.disjoint_iff_mul_eq_one.mp (hind.disjoint_biSup hnmem') hmem.1 hmem_bsupr heq1 intro i h simp only [Finset.mem_insert] at h rcases h with (rfl | h) · exact heq1i · refine ih hcomm hmem.2 heq1S _ h #align subgroup.eq_one_of_noncomm_prod_eq_one_of_independent Subgroup.eq_one_of_noncommProd_eq_one_of_independent #align add_subgroup.eq_zero_of_noncomm_sum_eq_zero_of_independent AddSubgroup.eq_zero_of_noncommSum_eq_zero_of_independent end Subgroup section FamilyOfMonoids variable {M : Type*} [Monoid M] -- We have a family of monoids -- The fintype assumption is not always used, but declared here, to keep things in order variable {ι : Type*} [DecidableEq ι] [Fintype ι] variable {N : ι → Type*} [∀ i, Monoid (N i)] -- And morphisms ϕ into G variable (ϕ : ∀ i : ι, N i →* M) -- We assume that the elements of different morphism commute variable (hcomm : Pairwise fun i j => ∀ x y, Commute (ϕ i x) (ϕ j y)) -- We use `f` and `g` to denote elements of `Π (i : ι), N i` variable (f g : ∀ i : ι, N i) namespace MonoidHom /-- The canonical homomorphism from a family of monoids. -/ @[to_additive "The canonical homomorphism from a family of additive monoids. See also `LinearMap.lsum` for a linear version without the commutativity assumption."] def noncommPiCoprod : (∀ i : ι, N i) →* M where toFun f := Finset.univ.noncommProd (fun i => ϕ i (f i)) fun i _ j _ h => hcomm h _ _ map_one' := by apply (Finset.noncommProd_eq_pow_card _ _ _ _ _).trans (one_pow _) simp map_mul' f g := by classical simp only convert @Finset.noncommProd_mul_distrib _ _ _ _ (fun i => ϕ i (f i)) (fun i => ϕ i (g i)) _ _ _ · exact map_mul _ _ _ · rintro i - j - h exact hcomm h _ _ #align monoid_hom.noncomm_pi_coprod MonoidHom.noncommPiCoprod #align add_monoid_hom.noncomm_pi_coprod AddMonoidHom.noncommPiCoprod variable {hcomm} @[to_additive (attr := simp)] theorem noncommPiCoprod_mulSingle (i : ι) (y : N i) : noncommPiCoprod ϕ hcomm (Pi.mulSingle i y) = ϕ i y := by change Finset.univ.noncommProd (fun j => ϕ j (Pi.mulSingle i y j)) (fun _ _ _ _ h => hcomm h _ _) = ϕ i y rw [← Finset.insert_erase (Finset.mem_univ i)] rw [Finset.noncommProd_insert_of_not_mem _ _ _ _ (Finset.not_mem_erase i _)] rw [Pi.mulSingle_eq_same] rw [Finset.noncommProd_eq_pow_card] · rw [one_pow] exact mul_one _ · intro j hj simp only [Finset.mem_erase] at hj simp [hj] #align monoid_hom.noncomm_pi_coprod_mul_single MonoidHom.noncommPiCoprod_mulSingle #align add_monoid_hom.noncomm_pi_coprod_single AddMonoidHom.noncommPiCoprod_single /-- The universal property of `MonoidHom.noncommPiCoprod` -/ @[to_additive "The universal property of `AddMonoidHom.noncommPiCoprod`"] def noncommPiCoprodEquiv : { ϕ : ∀ i, N i →* M // Pairwise fun i j => ∀ x y, Commute (ϕ i x) (ϕ j y) } ≃ ((∀ i, N i) →* M) where toFun ϕ := noncommPiCoprod ϕ.1 ϕ.2 invFun f := ⟨fun i => f.comp (MonoidHom.mulSingle N i), fun i j hij x y => Commute.map (Pi.mulSingle_commute hij x y) f⟩ left_inv ϕ := by ext simp only [coe_comp, Function.comp_apply, mulSingle_apply, noncommPiCoprod_mulSingle] right_inv f := pi_ext fun i x => by simp only [noncommPiCoprod_mulSingle, coe_comp, Function.comp_apply, mulSingle_apply] #align monoid_hom.noncomm_pi_coprod_equiv MonoidHom.noncommPiCoprodEquiv #align add_monoid_hom.noncomm_pi_coprod_equiv AddMonoidHom.noncommPiCoprodEquiv @[to_additive] theorem noncommPiCoprod_mrange : MonoidHom.mrange (noncommPiCoprod ϕ hcomm) = ⨆ i : ι, MonoidHom.mrange (ϕ i) := by letI := Classical.decEq ι apply le_antisymm · rintro x ⟨f, rfl⟩ refine Submonoid.noncommProd_mem _ _ _ (fun _ _ _ _ h => hcomm h _ _) (fun i _ => ?_) apply Submonoid.mem_sSup_of_mem · use i simp · refine iSup_le ?_ rintro i x ⟨y, rfl⟩ exact ⟨Pi.mulSingle i y, noncommPiCoprod_mulSingle _ _ _⟩ #align monoid_hom.noncomm_pi_coprod_mrange MonoidHom.noncommPiCoprod_mrange #align add_monoid_hom.noncomm_pi_coprod_mrange AddMonoidHom.noncommPiCoprod_mrange end MonoidHom end FamilyOfMonoids section FamilyOfGroups variable {G : Type*} [Group G] variable {ι : Type*} [hdec : DecidableEq ι] [hfin : Fintype ι] variable {H : ι → Type*} [∀ i, Group (H i)] variable (ϕ : ∀ i : ι, H i →* G) variable {hcomm : Pairwise fun i j : ι => ∀ (x : H i) (y : H j), Commute (ϕ i x) (ϕ j y)} -- We use `f` and `g` to denote elements of `Π (i : ι), H i` variable (f g : ∀ i : ι, H i) namespace MonoidHom -- The subgroup version of `MonoidHom.noncommPiCoprod_mrange` @[to_additive]
Mathlib/GroupTheory/NoncommPiCoprod.lean
193
204
theorem noncommPiCoprod_range : (noncommPiCoprod ϕ hcomm).range = ⨆ i : ι, (ϕ i).range := by
letI := Classical.decEq ι apply le_antisymm · rintro x ⟨f, rfl⟩ refine Subgroup.noncommProd_mem _ (fun _ _ _ _ h => hcomm h _ _) ?_ intro i _hi apply Subgroup.mem_sSup_of_mem · use i simp · refine iSup_le ?_ rintro i x ⟨y, rfl⟩ exact ⟨Pi.mulSingle i y, noncommPiCoprod_mulSingle _ _ _⟩
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Fabian Glöckle, Kyle Miller -/ import Mathlib.LinearAlgebra.FiniteDimensional import Mathlib.LinearAlgebra.FreeModule.Finite.Basic import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition import Mathlib.LinearAlgebra.Projection import Mathlib.LinearAlgebra.SesquilinearForm import Mathlib.RingTheory.TensorProduct.Basic import Mathlib.RingTheory.Ideal.LocalRing #align_import linear_algebra.dual from "leanprover-community/mathlib"@"b1c017582e9f18d8494e5c18602a8cb4a6f843ac" /-! # Dual vector spaces The dual space of an $R$-module $M$ is the $R$-module of $R$-linear maps $M \to R$. ## Main definitions * Duals and transposes: * `Module.Dual R M` defines the dual space of the `R`-module `M`, as `M →ₗ[R] R`. * `Module.dualPairing R M` is the canonical pairing between `Dual R M` and `M`. * `Module.Dual.eval R M : M →ₗ[R] Dual R (Dual R)` is the canonical map to the double dual. * `Module.Dual.transpose` is the linear map from `M →ₗ[R] M'` to `Dual R M' →ₗ[R] Dual R M`. * `LinearMap.dualMap` is `Module.Dual.transpose` of a given linear map, for dot notation. * `LinearEquiv.dualMap` is for the dual of an equivalence. * Bases: * `Basis.toDual` produces the map `M →ₗ[R] Dual R M` associated to a basis for an `R`-module `M`. * `Basis.toDual_equiv` is the equivalence `M ≃ₗ[R] Dual R M` associated to a finite basis. * `Basis.dualBasis` is a basis for `Dual R M` given a finite basis for `M`. * `Module.dual_bases e ε` is the proposition that the families `e` of vectors and `ε` of dual vectors have the characteristic properties of a basis and a dual. * Submodules: * `Submodule.dualRestrict W` is the transpose `Dual R M →ₗ[R] Dual R W` of the inclusion map. * `Submodule.dualAnnihilator W` is the kernel of `W.dualRestrict`. That is, it is the submodule of `dual R M` whose elements all annihilate `W`. * `Submodule.dualRestrict_comap W'` is the dual annihilator of `W' : Submodule R (Dual R M)`, pulled back along `Module.Dual.eval R M`. * `Submodule.dualCopairing W` is the canonical pairing between `W.dualAnnihilator` and `M ⧸ W`. It is nondegenerate for vector spaces (`subspace.dualCopairing_nondegenerate`). * `Submodule.dualPairing W` is the canonical pairing between `Dual R M ⧸ W.dualAnnihilator` and `W`. It is nondegenerate for vector spaces (`Subspace.dualPairing_nondegenerate`). * Vector spaces: * `Subspace.dualLift W` is an arbitrary section (using choice) of `Submodule.dualRestrict W`. ## Main results * Bases: * `Module.dualBasis.basis` and `Module.dualBasis.coe_basis`: if `e` and `ε` form a dual pair, then `e` is a basis. * `Module.dualBasis.coe_dualBasis`: if `e` and `ε` form a dual pair, then `ε` is a basis. * Annihilators: * `Module.dualAnnihilator_gc R M` is the antitone Galois correspondence between `Submodule.dualAnnihilator` and `Submodule.dualConnihilator`. * `LinearMap.ker_dual_map_eq_dualAnnihilator_range` says that `f.dual_map.ker = f.range.dualAnnihilator` * `LinearMap.range_dual_map_eq_dualAnnihilator_ker_of_subtype_range_surjective` says that `f.dual_map.range = f.ker.dualAnnihilator`; this is specialized to vector spaces in `LinearMap.range_dual_map_eq_dualAnnihilator_ker`. * `Submodule.dualQuotEquivDualAnnihilator` is the equivalence `Dual R (M ⧸ W) ≃ₗ[R] W.dualAnnihilator` * `Submodule.quotDualCoannihilatorToDual` is the nondegenerate pairing `M ⧸ W.dualCoannihilator →ₗ[R] Dual R W`. It is an perfect pairing when `R` is a field and `W` is finite-dimensional. * Vector spaces: * `Subspace.dualAnnihilator_dualConnihilator_eq` says that the double dual annihilator, pulled back ground `Module.Dual.eval`, is the original submodule. * `Subspace.dualAnnihilator_gci` says that `module.dualAnnihilator_gc R M` is an antitone Galois coinsertion. * `Subspace.quotAnnihilatorEquiv` is the equivalence `Dual K V ⧸ W.dualAnnihilator ≃ₗ[K] Dual K W`. * `LinearMap.dualPairing_nondegenerate` says that `Module.dualPairing` is nondegenerate. * `Subspace.is_compl_dualAnnihilator` says that the dual annihilator carries complementary subspaces to complementary subspaces. * Finite-dimensional vector spaces: * `Module.evalEquiv` is the equivalence `V ≃ₗ[K] Dual K (Dual K V)` * `Module.mapEvalEquiv` is the order isomorphism between subspaces of `V` and subspaces of `Dual K (Dual K V)`. * `Subspace.orderIsoFiniteCodimDim` is the antitone order isomorphism between finite-codimensional subspaces of `V` and finite-dimensional subspaces of `Dual K V`. * `Subspace.orderIsoFiniteDimensional` is the antitone order isomorphism between subspaces of a finite-dimensional vector space `V` and subspaces of its dual. * `Subspace.quotDualEquivAnnihilator W` is the equivalence `(Dual K V ⧸ W.dualLift.range) ≃ₗ[K] W.dualAnnihilator`, where `W.dualLift.range` is a copy of `Dual K W` inside `Dual K V`. * `Subspace.quotEquivAnnihilator W` is the equivalence `(V ⧸ W) ≃ₗ[K] W.dualAnnihilator` * `Subspace.dualQuotDistrib W` is an equivalence `Dual K (V₁ ⧸ W) ≃ₗ[K] Dual K V₁ ⧸ W.dualLift.range` from an arbitrary choice of splitting of `V₁`. -/ noncomputable section namespace Module -- Porting note: max u v universe issues so name and specific below universe uR uA uM uM' uM'' variable (R : Type uR) (A : Type uA) (M : Type uM) variable [CommSemiring R] [AddCommMonoid M] [Module R M] /-- The dual space of an R-module M is the R-module of linear maps `M → R`. -/ abbrev Dual := M →ₗ[R] R #align module.dual Module.Dual /-- The canonical pairing of a vector space and its algebraic dual. -/ def dualPairing (R M) [CommSemiring R] [AddCommMonoid M] [Module R M] : Module.Dual R M →ₗ[R] M →ₗ[R] R := LinearMap.id #align module.dual_pairing Module.dualPairing @[simp] theorem dualPairing_apply (v x) : dualPairing R M v x = v x := rfl #align module.dual_pairing_apply Module.dualPairing_apply namespace Dual instance : Inhabited (Dual R M) := ⟨0⟩ /-- Maps a module M to the dual of the dual of M. See `Module.erange_coe` and `Module.evalEquiv`. -/ def eval : M →ₗ[R] Dual R (Dual R M) := LinearMap.flip LinearMap.id #align module.dual.eval Module.Dual.eval @[simp] theorem eval_apply (v : M) (a : Dual R M) : eval R M v a = a v := rfl #align module.dual.eval_apply Module.Dual.eval_apply variable {R M} {M' : Type uM'} variable [AddCommMonoid M'] [Module R M'] /-- The transposition of linear maps, as a linear map from `M →ₗ[R] M'` to `Dual R M' →ₗ[R] Dual R M`. -/ def transpose : (M →ₗ[R] M') →ₗ[R] Dual R M' →ₗ[R] Dual R M := (LinearMap.llcomp R M M' R).flip #align module.dual.transpose Module.Dual.transpose -- Porting note: with reducible def need to specify some parameters to transpose explicitly theorem transpose_apply (u : M →ₗ[R] M') (l : Dual R M') : transpose (R := R) u l = l.comp u := rfl #align module.dual.transpose_apply Module.Dual.transpose_apply variable {M'' : Type uM''} [AddCommMonoid M''] [Module R M''] -- Porting note: with reducible def need to specify some parameters to transpose explicitly theorem transpose_comp (u : M' →ₗ[R] M'') (v : M →ₗ[R] M') : transpose (R := R) (u.comp v) = (transpose (R := R) v).comp (transpose (R := R) u) := rfl #align module.dual.transpose_comp Module.Dual.transpose_comp end Dual section Prod variable (M' : Type uM') [AddCommMonoid M'] [Module R M'] /-- Taking duals distributes over products. -/ @[simps!] def dualProdDualEquivDual : (Module.Dual R M × Module.Dual R M') ≃ₗ[R] Module.Dual R (M × M') := LinearMap.coprodEquiv R #align module.dual_prod_dual_equiv_dual Module.dualProdDualEquivDual @[simp] theorem dualProdDualEquivDual_apply (φ : Module.Dual R M) (ψ : Module.Dual R M') : dualProdDualEquivDual R M M' (φ, ψ) = φ.coprod ψ := rfl #align module.dual_prod_dual_equiv_dual_apply Module.dualProdDualEquivDual_apply end Prod end Module section DualMap open Module universe u v v' variable {R : Type u} [CommSemiring R] {M₁ : Type v} {M₂ : Type v'} variable [AddCommMonoid M₁] [Module R M₁] [AddCommMonoid M₂] [Module R M₂] /-- Given a linear map `f : M₁ →ₗ[R] M₂`, `f.dualMap` is the linear map between the dual of `M₂` and `M₁` such that it maps the functional `φ` to `φ ∘ f`. -/ def LinearMap.dualMap (f : M₁ →ₗ[R] M₂) : Dual R M₂ →ₗ[R] Dual R M₁ := -- Porting note: with reducible def need to specify some parameters to transpose explicitly Module.Dual.transpose (R := R) f #align linear_map.dual_map LinearMap.dualMap lemma LinearMap.dualMap_eq_lcomp (f : M₁ →ₗ[R] M₂) : f.dualMap = f.lcomp R := rfl -- Porting note: with reducible def need to specify some parameters to transpose explicitly theorem LinearMap.dualMap_def (f : M₁ →ₗ[R] M₂) : f.dualMap = Module.Dual.transpose (R := R) f := rfl #align linear_map.dual_map_def LinearMap.dualMap_def theorem LinearMap.dualMap_apply' (f : M₁ →ₗ[R] M₂) (g : Dual R M₂) : f.dualMap g = g.comp f := rfl #align linear_map.dual_map_apply' LinearMap.dualMap_apply' @[simp] theorem LinearMap.dualMap_apply (f : M₁ →ₗ[R] M₂) (g : Dual R M₂) (x : M₁) : f.dualMap g x = g (f x) := rfl #align linear_map.dual_map_apply LinearMap.dualMap_apply @[simp] theorem LinearMap.dualMap_id : (LinearMap.id : M₁ →ₗ[R] M₁).dualMap = LinearMap.id := by ext rfl #align linear_map.dual_map_id LinearMap.dualMap_id theorem LinearMap.dualMap_comp_dualMap {M₃ : Type*} [AddCommGroup M₃] [Module R M₃] (f : M₁ →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) : f.dualMap.comp g.dualMap = (g.comp f).dualMap := rfl #align linear_map.dual_map_comp_dual_map LinearMap.dualMap_comp_dualMap /-- If a linear map is surjective, then its dual is injective. -/ theorem LinearMap.dualMap_injective_of_surjective {f : M₁ →ₗ[R] M₂} (hf : Function.Surjective f) : Function.Injective f.dualMap := by intro φ ψ h ext x obtain ⟨y, rfl⟩ := hf x exact congr_arg (fun g : Module.Dual R M₁ => g y) h #align linear_map.dual_map_injective_of_surjective LinearMap.dualMap_injective_of_surjective /-- The `Linear_equiv` version of `LinearMap.dualMap`. -/ def LinearEquiv.dualMap (f : M₁ ≃ₗ[R] M₂) : Dual R M₂ ≃ₗ[R] Dual R M₁ where __ := f.toLinearMap.dualMap invFun := f.symm.toLinearMap.dualMap left_inv φ := LinearMap.ext fun x ↦ congr_arg φ (f.right_inv x) right_inv φ := LinearMap.ext fun x ↦ congr_arg φ (f.left_inv x) #align linear_equiv.dual_map LinearEquiv.dualMap @[simp] theorem LinearEquiv.dualMap_apply (f : M₁ ≃ₗ[R] M₂) (g : Dual R M₂) (x : M₁) : f.dualMap g x = g (f x) := rfl #align linear_equiv.dual_map_apply LinearEquiv.dualMap_apply @[simp] theorem LinearEquiv.dualMap_refl : (LinearEquiv.refl R M₁).dualMap = LinearEquiv.refl R (Dual R M₁) := by ext rfl #align linear_equiv.dual_map_refl LinearEquiv.dualMap_refl @[simp] theorem LinearEquiv.dualMap_symm {f : M₁ ≃ₗ[R] M₂} : (LinearEquiv.dualMap f).symm = LinearEquiv.dualMap f.symm := rfl #align linear_equiv.dual_map_symm LinearEquiv.dualMap_symm theorem LinearEquiv.dualMap_trans {M₃ : Type*} [AddCommGroup M₃] [Module R M₃] (f : M₁ ≃ₗ[R] M₂) (g : M₂ ≃ₗ[R] M₃) : g.dualMap.trans f.dualMap = (f.trans g).dualMap := rfl #align linear_equiv.dual_map_trans LinearEquiv.dualMap_trans @[simp] lemma Dual.apply_one_mul_eq (f : Dual R R) (r : R) : f 1 * r = f r := by conv_rhs => rw [← mul_one r, ← smul_eq_mul] rw [map_smul, smul_eq_mul, mul_comm] @[simp] lemma LinearMap.range_dualMap_dual_eq_span_singleton (f : Dual R M₁) : range f.dualMap = R ∙ f := by ext m rw [Submodule.mem_span_singleton] refine ⟨fun ⟨r, hr⟩ ↦ ⟨r 1, ?_⟩, fun ⟨r, hr⟩ ↦ ⟨r • LinearMap.id, ?_⟩⟩ · ext; simp [dualMap_apply', ← hr] · ext; simp [dualMap_apply', ← hr] end DualMap namespace Basis universe u v w open Module Module.Dual Submodule LinearMap Cardinal Function universe uR uM uK uV uι variable {R : Type uR} {M : Type uM} {K : Type uK} {V : Type uV} {ι : Type uι} section CommSemiring variable [CommSemiring R] [AddCommMonoid M] [Module R M] [DecidableEq ι] variable (b : Basis ι R M) /-- The linear map from a vector space equipped with basis to its dual vector space, taking basis elements to corresponding dual basis elements. -/ def toDual : M →ₗ[R] Module.Dual R M := b.constr ℕ fun v => b.constr ℕ fun w => if w = v then (1 : R) else 0 #align basis.to_dual Basis.toDual theorem toDual_apply (i j : ι) : b.toDual (b i) (b j) = if i = j then 1 else 0 := by erw [constr_basis b, constr_basis b] simp only [eq_comm] #align basis.to_dual_apply Basis.toDual_apply @[simp] theorem toDual_total_left (f : ι →₀ R) (i : ι) : b.toDual (Finsupp.total ι M R b f) (b i) = f i := by rw [Finsupp.total_apply, Finsupp.sum, _root_.map_sum, LinearMap.sum_apply] simp_rw [LinearMap.map_smul, LinearMap.smul_apply, toDual_apply, smul_eq_mul, mul_boole, Finset.sum_ite_eq'] split_ifs with h · rfl · rw [Finsupp.not_mem_support_iff.mp h] #align basis.to_dual_total_left Basis.toDual_total_left @[simp] theorem toDual_total_right (f : ι →₀ R) (i : ι) : b.toDual (b i) (Finsupp.total ι M R b f) = f i := by rw [Finsupp.total_apply, Finsupp.sum, _root_.map_sum] simp_rw [LinearMap.map_smul, toDual_apply, smul_eq_mul, mul_boole, Finset.sum_ite_eq] split_ifs with h · rfl · rw [Finsupp.not_mem_support_iff.mp h] #align basis.to_dual_total_right Basis.toDual_total_right theorem toDual_apply_left (m : M) (i : ι) : b.toDual m (b i) = b.repr m i := by rw [← b.toDual_total_left, b.total_repr] #align basis.to_dual_apply_left Basis.toDual_apply_left theorem toDual_apply_right (i : ι) (m : M) : b.toDual (b i) m = b.repr m i := by rw [← b.toDual_total_right, b.total_repr] #align basis.to_dual_apply_right Basis.toDual_apply_right theorem coe_toDual_self (i : ι) : b.toDual (b i) = b.coord i := by ext apply toDual_apply_right #align basis.coe_to_dual_self Basis.coe_toDual_self /-- `h.toDual_flip v` is the linear map sending `w` to `h.toDual w v`. -/ def toDualFlip (m : M) : M →ₗ[R] R := b.toDual.flip m #align basis.to_dual_flip Basis.toDualFlip theorem toDualFlip_apply (m₁ m₂ : M) : b.toDualFlip m₁ m₂ = b.toDual m₂ m₁ := rfl #align basis.to_dual_flip_apply Basis.toDualFlip_apply theorem toDual_eq_repr (m : M) (i : ι) : b.toDual m (b i) = b.repr m i := b.toDual_apply_left m i #align basis.to_dual_eq_repr Basis.toDual_eq_repr theorem toDual_eq_equivFun [Finite ι] (m : M) (i : ι) : b.toDual m (b i) = b.equivFun m i := by rw [b.equivFun_apply, toDual_eq_repr] #align basis.to_dual_eq_equiv_fun Basis.toDual_eq_equivFun theorem toDual_injective : Injective b.toDual := fun x y h ↦ b.ext_elem_iff.mpr fun i ↦ by simp_rw [← toDual_eq_repr]; exact DFunLike.congr_fun h _ theorem toDual_inj (m : M) (a : b.toDual m = 0) : m = 0 := b.toDual_injective (by rwa [_root_.map_zero]) #align basis.to_dual_inj Basis.toDual_inj -- Porting note (#11036): broken dot notation lean4#1910 LinearMap.ker theorem toDual_ker : LinearMap.ker b.toDual = ⊥ := ker_eq_bot'.mpr b.toDual_inj #align basis.to_dual_ker Basis.toDual_ker -- Porting note (#11036): broken dot notation lean4#1910 LinearMap.range theorem toDual_range [Finite ι] : LinearMap.range b.toDual = ⊤ := by refine eq_top_iff'.2 fun f => ?_ let lin_comb : ι →₀ R := Finsupp.equivFunOnFinite.symm fun i => f (b i) refine ⟨Finsupp.total ι M R b lin_comb, b.ext fun i => ?_⟩ rw [b.toDual_eq_repr _ i, repr_total b] rfl #align basis.to_dual_range Basis.toDual_range end CommSemiring section variable [CommSemiring R] [AddCommMonoid M] [Module R M] [Fintype ι] variable (b : Basis ι R M) @[simp] theorem sum_dual_apply_smul_coord (f : Module.Dual R M) : (∑ x, f (b x) • b.coord x) = f := by ext m simp_rw [LinearMap.sum_apply, LinearMap.smul_apply, smul_eq_mul, mul_comm (f _), ← smul_eq_mul, ← f.map_smul, ← _root_.map_sum, Basis.coord_apply, Basis.sum_repr] #align basis.sum_dual_apply_smul_coord Basis.sum_dual_apply_smul_coord end section CommRing variable [CommRing R] [AddCommGroup M] [Module R M] [DecidableEq ι] variable (b : Basis ι R M) section Finite variable [Finite ι] /-- A vector space is linearly equivalent to its dual space. -/ def toDualEquiv : M ≃ₗ[R] Dual R M := LinearEquiv.ofBijective b.toDual ⟨ker_eq_bot.mp b.toDual_ker, range_eq_top.mp b.toDual_range⟩ #align basis.to_dual_equiv Basis.toDualEquiv -- `simps` times out when generating this @[simp] theorem toDualEquiv_apply (m : M) : b.toDualEquiv m = b.toDual m := rfl #align basis.to_dual_equiv_apply Basis.toDualEquiv_apply -- Not sure whether this is true for free modules over a commutative ring /-- A vector space over a field is isomorphic to its dual if and only if it is finite-dimensional: a consequence of the Erdős-Kaplansky theorem. -/ theorem linearEquiv_dual_iff_finiteDimensional [Field K] [AddCommGroup V] [Module K V] : Nonempty (V ≃ₗ[K] Dual K V) ↔ FiniteDimensional K V := by refine ⟨fun ⟨e⟩ ↦ ?_, fun h ↦ ⟨(Module.Free.chooseBasis K V).toDualEquiv⟩⟩ rw [FiniteDimensional, ← Module.rank_lt_alpeh0_iff] by_contra! apply (lift_rank_lt_rank_dual this).ne have := e.lift_rank_eq rwa [lift_umax.{uV,uK}, lift_id'.{uV,uK}] at this /-- Maps a basis for `V` to a basis for the dual space. -/ def dualBasis : Basis ι R (Dual R M) := b.map b.toDualEquiv #align basis.dual_basis Basis.dualBasis -- We use `j = i` to match `Basis.repr_self` theorem dualBasis_apply_self (i j : ι) : b.dualBasis i (b j) = if j = i then 1 else 0 := by convert b.toDual_apply i j using 2 rw [@eq_comm _ j i] #align basis.dual_basis_apply_self Basis.dualBasis_apply_self theorem total_dualBasis (f : ι →₀ R) (i : ι) : Finsupp.total ι (Dual R M) R b.dualBasis f (b i) = f i := by cases nonempty_fintype ι rw [Finsupp.total_apply, Finsupp.sum_fintype, LinearMap.sum_apply] · simp_rw [LinearMap.smul_apply, smul_eq_mul, dualBasis_apply_self, mul_boole, Finset.sum_ite_eq, if_pos (Finset.mem_univ i)] · intro rw [zero_smul] #align basis.total_dual_basis Basis.total_dualBasis theorem dualBasis_repr (l : Dual R M) (i : ι) : b.dualBasis.repr l i = l (b i) := by rw [← total_dualBasis b, Basis.total_repr b.dualBasis l] #align basis.dual_basis_repr Basis.dualBasis_repr theorem dualBasis_apply (i : ι) (m : M) : b.dualBasis i m = b.repr m i := b.toDual_apply_right i m #align basis.dual_basis_apply Basis.dualBasis_apply @[simp] theorem coe_dualBasis : ⇑b.dualBasis = b.coord := by ext i x apply dualBasis_apply #align basis.coe_dual_basis Basis.coe_dualBasis @[simp] theorem toDual_toDual : b.dualBasis.toDual.comp b.toDual = Dual.eval R M := by refine b.ext fun i => b.dualBasis.ext fun j => ?_ rw [LinearMap.comp_apply, toDual_apply_left, coe_toDual_self, ← coe_dualBasis, Dual.eval_apply, Basis.repr_self, Finsupp.single_apply, dualBasis_apply_self] #align basis.to_dual_to_dual Basis.toDual_toDual end Finite theorem dualBasis_equivFun [Finite ι] (l : Dual R M) (i : ι) : b.dualBasis.equivFun l i = l (b i) := by rw [Basis.equivFun_apply, dualBasis_repr] #align basis.dual_basis_equiv_fun Basis.dualBasis_equivFun theorem eval_ker {ι : Type*} (b : Basis ι R M) : LinearMap.ker (Dual.eval R M) = ⊥ := by rw [ker_eq_bot'] intro m hm simp_rw [LinearMap.ext_iff, Dual.eval_apply, zero_apply] at hm exact (Basis.forall_coord_eq_zero_iff _).mp fun i => hm (b.coord i) #align basis.eval_ker Basis.eval_ker -- Porting note (#11036): broken dot notation lean4#1910 LinearMap.range theorem eval_range {ι : Type*} [Finite ι] (b : Basis ι R M) : LinearMap.range (Dual.eval R M) = ⊤ := by classical cases nonempty_fintype ι rw [← b.toDual_toDual, range_comp, b.toDual_range, Submodule.map_top, toDual_range _] #align basis.eval_range Basis.eval_range section variable [Finite R M] [Free R M] instance dual_free : Free R (Dual R M) := Free.of_basis (Free.chooseBasis R M).dualBasis #align basis.dual_free Basis.dual_free instance dual_finite : Finite R (Dual R M) := Finite.of_basis (Free.chooseBasis R M).dualBasis #align basis.dual_finite Basis.dual_finite end end CommRing /-- `simp` normal form version of `total_dualBasis` -/ @[simp] theorem total_coord [CommRing R] [AddCommGroup M] [Module R M] [Finite ι] (b : Basis ι R M) (f : ι →₀ R) (i : ι) : Finsupp.total ι (Dual R M) R b.coord f (b i) = f i := by haveI := Classical.decEq ι rw [← coe_dualBasis, total_dualBasis] #align basis.total_coord Basis.total_coord theorem dual_rank_eq [CommRing K] [AddCommGroup V] [Module K V] [Finite ι] (b : Basis ι K V) : Cardinal.lift.{uK,uV} (Module.rank K V) = Module.rank K (Dual K V) := by classical rw [← lift_umax.{uV,uK}, b.toDualEquiv.lift_rank_eq, lift_id'.{uV,uK}] #align basis.dual_rank_eq Basis.dual_rank_eq end Basis namespace Module universe uK uV variable {K : Type uK} {V : Type uV} variable [CommRing K] [AddCommGroup V] [Module K V] [Module.Free K V] open Module Module.Dual Submodule LinearMap Cardinal Basis FiniteDimensional section variable (K) (V) -- Porting note (#11036): broken dot notation lean4#1910 LinearMap.ker theorem eval_ker : LinearMap.ker (eval K V) = ⊥ := by classical exact (Module.Free.chooseBasis K V).eval_ker #align module.eval_ker Module.eval_ker theorem map_eval_injective : (Submodule.map (eval K V)).Injective := by apply Submodule.map_injective_of_injective rw [← LinearMap.ker_eq_bot] exact eval_ker K V #align module.map_eval_injective Module.map_eval_injective theorem comap_eval_surjective : (Submodule.comap (eval K V)).Surjective := by apply Submodule.comap_surjective_of_injective rw [← LinearMap.ker_eq_bot] exact eval_ker K V #align module.comap_eval_surjective Module.comap_eval_surjective end section variable (K) theorem eval_apply_eq_zero_iff (v : V) : (eval K V) v = 0 ↔ v = 0 := by simpa only using SetLike.ext_iff.mp (eval_ker K V) v #align module.eval_apply_eq_zero_iff Module.eval_apply_eq_zero_iff theorem eval_apply_injective : Function.Injective (eval K V) := (injective_iff_map_eq_zero' (eval K V)).mpr (eval_apply_eq_zero_iff K) #align module.eval_apply_injective Module.eval_apply_injective theorem forall_dual_apply_eq_zero_iff (v : V) : (∀ φ : Module.Dual K V, φ v = 0) ↔ v = 0 := by rw [← eval_apply_eq_zero_iff K v, LinearMap.ext_iff] rfl #align module.forall_dual_apply_eq_zero_iff Module.forall_dual_apply_eq_zero_iff @[simp] theorem subsingleton_dual_iff : Subsingleton (Dual K V) ↔ Subsingleton V := by refine ⟨fun h ↦ ⟨fun v w ↦ ?_⟩, fun h ↦ ⟨fun f g ↦ ?_⟩⟩ · rw [← sub_eq_zero, ← forall_dual_apply_eq_zero_iff K (v - w)] intros f simp [Subsingleton.elim f 0] · ext v simp [Subsingleton.elim v 0] instance instSubsingletonDual [Subsingleton V] : Subsingleton (Dual K V) := (subsingleton_dual_iff K).mp inferInstance @[simp] theorem nontrivial_dual_iff : Nontrivial (Dual K V) ↔ Nontrivial V := by rw [← not_iff_not, not_nontrivial_iff_subsingleton, not_nontrivial_iff_subsingleton, subsingleton_dual_iff] instance instNontrivialDual [Nontrivial V] : Nontrivial (Dual K V) := (nontrivial_dual_iff K).mpr inferInstance theorem finite_dual_iff : Finite K (Dual K V) ↔ Finite K V := by constructor <;> intro h · obtain ⟨⟨ι, b⟩⟩ := Module.Free.exists_basis (R := K) (M := V) nontriviality K obtain ⟨⟨s, span_s⟩⟩ := h classical haveI := (b.linearIndependent.map' _ b.toDual_ker).finite_of_le_span_finite _ s ?_ · exact Finite.of_basis b · rw [span_s]; apply le_top · infer_instance end theorem dual_rank_eq [Module.Finite K V] : Cardinal.lift.{uK,uV} (Module.rank K V) = Module.rank K (Dual K V) := (Module.Free.chooseBasis K V).dual_rank_eq #align module.dual_rank_eq Module.dual_rank_eq -- Porting note (#11036): broken dot notation lean4#1910 LinearMap.range theorem erange_coe [Module.Finite K V] : LinearMap.range (eval K V) = ⊤ := (Module.Free.chooseBasis K V).eval_range #align module.erange_coe Module.erange_coe section IsReflexive open Function variable (R M N : Type*) [CommRing R] [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N] /-- A reflexive module is one for which the natural map to its double dual is a bijection. Any finitely-generated free module (and thus any finite-dimensional vector space) is reflexive. See `Module.IsReflexive.of_finite_of_free`. -/ class IsReflexive : Prop where /-- A reflexive module is one for which the natural map to its double dual is a bijection. -/ bijective_dual_eval' : Bijective (Dual.eval R M) lemma bijective_dual_eval [IsReflexive R M] : Bijective (Dual.eval R M) := IsReflexive.bijective_dual_eval' instance IsReflexive.of_finite_of_free [Finite R M] [Free R M] : IsReflexive R M where bijective_dual_eval' := ⟨LinearMap.ker_eq_bot.mp (Free.chooseBasis R M).eval_ker, LinearMap.range_eq_top.mp (Free.chooseBasis R M).eval_range⟩ variable [IsReflexive R M] /-- The bijection between a reflexive module and its double dual, bundled as a `LinearEquiv`. -/ def evalEquiv : M ≃ₗ[R] Dual R (Dual R M) := LinearEquiv.ofBijective _ (bijective_dual_eval R M) #align module.eval_equiv Module.evalEquiv @[simp] lemma evalEquiv_toLinearMap : evalEquiv R M = Dual.eval R M := rfl #align module.eval_equiv_to_linear_map Module.evalEquiv_toLinearMap @[simp] lemma evalEquiv_apply (m : M) : evalEquiv R M m = Dual.eval R M m := rfl @[simp] lemma apply_evalEquiv_symm_apply (f : Dual R M) (g : Dual R (Dual R M)) : f ((evalEquiv R M).symm g) = g f := by set m := (evalEquiv R M).symm g rw [← (evalEquiv R M).apply_symm_apply g, evalEquiv_apply, Dual.eval_apply] @[simp] lemma symm_dualMap_evalEquiv : (evalEquiv R M).symm.dualMap = Dual.eval R (Dual R M) := by ext; simp /-- The dual of a reflexive module is reflexive. -/ instance Dual.instIsReflecive : IsReflexive R (Dual R M) := ⟨by simpa only [← symm_dualMap_evalEquiv] using (evalEquiv R M).dualMap.symm.bijective⟩ /-- The isomorphism `Module.evalEquiv` induces an order isomorphism on subspaces. -/ def mapEvalEquiv : Submodule R M ≃o Submodule R (Dual R (Dual R M)) := Submodule.orderIsoMapComap (evalEquiv R M) #align module.map_eval_equiv Module.mapEvalEquiv @[simp] theorem mapEvalEquiv_apply (W : Submodule R M) : mapEvalEquiv R M W = W.map (Dual.eval R M) := rfl #align module.map_eval_equiv_apply Module.mapEvalEquiv_apply @[simp] theorem mapEvalEquiv_symm_apply (W'' : Submodule R (Dual R (Dual R M))) : (mapEvalEquiv R M).symm W'' = W''.comap (Dual.eval R M) := rfl #align module.map_eval_equiv_symm_apply Module.mapEvalEquiv_symm_apply instance _root_.Prod.instModuleIsReflexive [IsReflexive R N] : IsReflexive R (M × N) where bijective_dual_eval' := by let e : Dual R (Dual R (M × N)) ≃ₗ[R] Dual R (Dual R M) × Dual R (Dual R N) := (dualProdDualEquivDual R M N).dualMap.trans (dualProdDualEquivDual R (Dual R M) (Dual R N)).symm have : Dual.eval R (M × N) = e.symm.comp ((Dual.eval R M).prodMap (Dual.eval R N)) := by ext m f <;> simp [e] simp only [this, LinearEquiv.trans_symm, LinearEquiv.symm_symm, LinearEquiv.dualMap_symm, coe_comp, LinearEquiv.coe_coe, EquivLike.comp_bijective] exact (bijective_dual_eval R M).prodMap (bijective_dual_eval R N) variable {R M N} in lemma equiv (e : M ≃ₗ[R] N) : IsReflexive R N where bijective_dual_eval' := by let ed : Dual R (Dual R N) ≃ₗ[R] Dual R (Dual R M) := e.symm.dualMap.dualMap have : Dual.eval R N = ed.symm.comp ((Dual.eval R M).comp e.symm.toLinearMap) := by ext m f exact DFunLike.congr_arg f (e.apply_symm_apply m).symm simp only [this, LinearEquiv.trans_symm, LinearEquiv.symm_symm, LinearEquiv.dualMap_symm, coe_comp, LinearEquiv.coe_coe, EquivLike.comp_bijective] exact Bijective.comp (bijective_dual_eval R M) (LinearEquiv.bijective _) instance _root_.MulOpposite.instModuleIsReflexive : IsReflexive R (MulOpposite M) := equiv <| MulOpposite.opLinearEquiv _ instance _root_.ULift.instModuleIsReflexive.{w} : IsReflexive R (ULift.{w} M) := equiv ULift.moduleEquiv.symm end IsReflexive end Module namespace Submodule open Module variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] {p : Submodule R M} theorem exists_dual_map_eq_bot_of_nmem {x : M} (hx : x ∉ p) (hp' : Free R (M ⧸ p)) : ∃ f : Dual R M, f x ≠ 0 ∧ p.map f = ⊥ := by suffices ∃ f : Dual R (M ⧸ p), f (p.mkQ x) ≠ 0 by obtain ⟨f, hf⟩ := this; exact ⟨f.comp p.mkQ, hf, by simp [Submodule.map_comp]⟩ rwa [← Submodule.Quotient.mk_eq_zero, ← Submodule.mkQ_apply, ← forall_dual_apply_eq_zero_iff (K := R), not_forall] at hx theorem exists_dual_map_eq_bot_of_lt_top (hp : p < ⊤) (hp' : Free R (M ⧸ p)) : ∃ f : Dual R M, f ≠ 0 ∧ p.map f = ⊥ := by obtain ⟨x, hx⟩ : ∃ x : M, x ∉ p := by rw [lt_top_iff_ne_top] at hp; contrapose! hp; ext; simp [hp] obtain ⟨f, hf, hf'⟩ := p.exists_dual_map_eq_bot_of_nmem hx hp' exact ⟨f, by aesop, hf'⟩ end Submodule section DualBases open Module variable {R M ι : Type*} variable [CommSemiring R] [AddCommMonoid M] [Module R M] [DecidableEq ι] -- Porting note: replace use_finite_instance tactic open Lean.Elab.Tactic in /-- Try using `Set.to_finite` to dispatch a `Set.finite` goal. -/ def evalUseFiniteInstance : TacticM Unit := do evalTactic (← `(tactic| intros; apply Set.toFinite)) elab "use_finite_instance" : tactic => evalUseFiniteInstance /-- `e` and `ε` have characteristic properties of a basis and its dual -/ -- @[nolint has_nonempty_instance] Porting note (#5171): removed structure Module.DualBases (e : ι → M) (ε : ι → Dual R M) : Prop where eval : ∀ i j : ι, ε i (e j) = if i = j then 1 else 0 protected total : ∀ {m : M}, (∀ i, ε i m = 0) → m = 0 protected finite : ∀ m : M, { i | ε i m ≠ 0 }.Finite := by use_finite_instance #align module.dual_bases Module.DualBases end DualBases namespace Module.DualBases open Module Module.Dual LinearMap Function variable {R M ι : Type*} variable [CommRing R] [AddCommGroup M] [Module R M] variable {e : ι → M} {ε : ι → Dual R M} /-- The coefficients of `v` on the basis `e` -/ def coeffs [DecidableEq ι] (h : DualBases e ε) (m : M) : ι →₀ R where toFun i := ε i m support := (h.finite m).toFinset mem_support_toFun i := by rw [Set.Finite.mem_toFinset, Set.mem_setOf_eq] #align module.dual_bases.coeffs Module.DualBases.coeffs @[simp] theorem coeffs_apply [DecidableEq ι] (h : DualBases e ε) (m : M) (i : ι) : h.coeffs m i = ε i m := rfl #align module.dual_bases.coeffs_apply Module.DualBases.coeffs_apply /-- linear combinations of elements of `e`. This is a convenient abbreviation for `Finsupp.total _ M R e l` -/ def lc {ι} (e : ι → M) (l : ι →₀ R) : M := l.sum fun (i : ι) (a : R) => a • e i #align module.dual_bases.lc Module.DualBases.lc theorem lc_def (e : ι → M) (l : ι →₀ R) : lc e l = Finsupp.total _ _ R e l := rfl #align module.dual_bases.lc_def Module.DualBases.lc_def open Module variable [DecidableEq ι] (h : DualBases e ε) theorem dual_lc (l : ι →₀ R) (i : ι) : ε i (DualBases.lc e l) = l i := by rw [lc, _root_.map_finsupp_sum, Finsupp.sum_eq_single i (g := fun a b ↦ (ε i) (b • e a))] -- Porting note: cannot get at • -- simp only [h.eval, map_smul, smul_eq_mul] · simp [h.eval, smul_eq_mul] · intro q _ q_ne simp [q_ne.symm, h.eval, smul_eq_mul] · simp #align module.dual_bases.dual_lc Module.DualBases.dual_lc @[simp] theorem coeffs_lc (l : ι →₀ R) : h.coeffs (DualBases.lc e l) = l := by ext i rw [h.coeffs_apply, h.dual_lc] #align module.dual_bases.coeffs_lc Module.DualBases.coeffs_lc /-- For any m : M n, \sum_{p ∈ Q n} (ε p m) • e p = m -/ @[simp] theorem lc_coeffs (m : M) : DualBases.lc e (h.coeffs m) = m := by refine eq_of_sub_eq_zero <| h.total fun i ↦ ?_ simp [LinearMap.map_sub, h.dual_lc, sub_eq_zero] #align module.dual_bases.lc_coeffs Module.DualBases.lc_coeffs /-- `(h : DualBases e ε).basis` shows the family of vectors `e` forms a basis. -/ @[simps] def basis : Basis ι R M := Basis.ofRepr { toFun := coeffs h invFun := lc e left_inv := lc_coeffs h right_inv := coeffs_lc h map_add' := fun v w => by ext i exact (ε i).map_add v w map_smul' := fun c v => by ext i exact (ε i).map_smul c v } #align module.dual_bases.basis Module.DualBases.basis -- Porting note: from simpNF the LHS simplifies; it yields lc_def.symm -- probably not a useful simp lemma; nolint simpNF since it cannot see this removal attribute [-simp, nolint simpNF] basis_repr_symm_apply @[simp] theorem coe_basis : ⇑h.basis = e := by ext i rw [Basis.apply_eq_iff] ext j rw [h.basis_repr_apply, coeffs_apply, h.eval, Finsupp.single_apply] convert if_congr (eq_comm (a := j) (b := i)) rfl rfl #align module.dual_bases.coe_basis Module.DualBases.coe_basis -- `convert` to get rid of a `DecidableEq` mismatch theorem mem_of_mem_span {H : Set ι} {x : M} (hmem : x ∈ Submodule.span R (e '' H)) : ∀ i : ι, ε i x ≠ 0 → i ∈ H := by intro i hi rcases (Finsupp.mem_span_image_iff_total _).mp hmem with ⟨l, supp_l, rfl⟩ apply not_imp_comm.mp ((Finsupp.mem_supported' _ _).mp supp_l i) rwa [← lc_def, h.dual_lc] at hi #align module.dual_bases.mem_of_mem_span Module.DualBases.mem_of_mem_span theorem coe_dualBasis [_root_.Finite ι] : ⇑h.basis.dualBasis = ε := funext fun i => h.basis.ext fun j => by rw [h.basis.dualBasis_apply_self, h.coe_basis, h.eval, if_congr eq_comm rfl rfl] #align module.dual_bases.coe_dual_basis Module.DualBases.coe_dualBasis end Module.DualBases namespace Submodule universe u v w variable {R : Type u} {M : Type v} [CommSemiring R] [AddCommMonoid M] [Module R M] variable {W : Submodule R M} /-- The `dualRestrict` of a submodule `W` of `M` is the linear map from the dual of `M` to the dual of `W` such that the domain of each linear map is restricted to `W`. -/ def dualRestrict (W : Submodule R M) : Module.Dual R M →ₗ[R] Module.Dual R W := LinearMap.domRestrict' W #align submodule.dual_restrict Submodule.dualRestrict theorem dualRestrict_def (W : Submodule R M) : W.dualRestrict = W.subtype.dualMap := rfl #align submodule.dual_restrict_def Submodule.dualRestrict_def @[simp] theorem dualRestrict_apply (W : Submodule R M) (φ : Module.Dual R M) (x : W) : W.dualRestrict φ x = φ (x : M) := rfl #align submodule.dual_restrict_apply Submodule.dualRestrict_apply /-- The `dualAnnihilator` of a submodule `W` is the set of linear maps `φ` such that `φ w = 0` for all `w ∈ W`. -/ def dualAnnihilator {R : Type u} {M : Type v} [CommSemiring R] [AddCommMonoid M] [Module R M] (W : Submodule R M) : Submodule R <| Module.Dual R M := -- Porting note (#11036): broken dot notation lean4#1910 LinearMap.ker LinearMap.ker W.dualRestrict #align submodule.dual_annihilator Submodule.dualAnnihilator @[simp] theorem mem_dualAnnihilator (φ : Module.Dual R M) : φ ∈ W.dualAnnihilator ↔ ∀ w ∈ W, φ w = 0 := by refine LinearMap.mem_ker.trans ?_ simp_rw [LinearMap.ext_iff, dualRestrict_apply] exact ⟨fun h w hw => h ⟨w, hw⟩, fun h w => h w.1 w.2⟩ #align submodule.mem_dual_annihilator Submodule.mem_dualAnnihilator /-- That $\operatorname{ker}(\iota^* : V^* \to W^*) = \operatorname{ann}(W)$. This is the definition of the dual annihilator of the submodule $W$. -/ theorem dualRestrict_ker_eq_dualAnnihilator (W : Submodule R M) : -- Porting note (#11036): broken dot notation lean4#1910 LinearMap.ker LinearMap.ker W.dualRestrict = W.dualAnnihilator := rfl #align submodule.dual_restrict_ker_eq_dual_annihilator Submodule.dualRestrict_ker_eq_dualAnnihilator /-- The `dualAnnihilator` of a submodule of the dual space pulled back along the evaluation map `Module.Dual.eval`. -/ def dualCoannihilator (Φ : Submodule R (Module.Dual R M)) : Submodule R M := Φ.dualAnnihilator.comap (Module.Dual.eval R M) #align submodule.dual_coannihilator Submodule.dualCoannihilator @[simp] theorem mem_dualCoannihilator {Φ : Submodule R (Module.Dual R M)} (x : M) : x ∈ Φ.dualCoannihilator ↔ ∀ φ ∈ Φ, (φ x : R) = 0 := by simp_rw [dualCoannihilator, mem_comap, mem_dualAnnihilator, Module.Dual.eval_apply] #align submodule.mem_dual_coannihilator Submodule.mem_dualCoannihilator theorem comap_dualAnnihilator (Φ : Submodule R (Module.Dual R M)) : Φ.dualAnnihilator.comap (Module.Dual.eval R M) = Φ.dualCoannihilator := rfl theorem map_dualCoannihilator_le (Φ : Submodule R (Module.Dual R M)) : Φ.dualCoannihilator.map (Module.Dual.eval R M) ≤ Φ.dualAnnihilator := map_le_iff_le_comap.mpr (comap_dualAnnihilator Φ).le variable (R M) in theorem dualAnnihilator_gc : GaloisConnection (OrderDual.toDual ∘ (dualAnnihilator : Submodule R M → Submodule R (Module.Dual R M))) (dualCoannihilator ∘ OrderDual.ofDual) := by intro a b induction b using OrderDual.rec simp only [Function.comp_apply, OrderDual.toDual_le_toDual, OrderDual.ofDual_toDual] constructor <;> · intro h x hx simp only [mem_dualAnnihilator, mem_dualCoannihilator] intro y hy have := h hy simp only [mem_dualAnnihilator, mem_dualCoannihilator] at this exact this x hx #align submodule.dual_annihilator_gc Submodule.dualAnnihilator_gc theorem le_dualAnnihilator_iff_le_dualCoannihilator {U : Submodule R (Module.Dual R M)} {V : Submodule R M} : U ≤ V.dualAnnihilator ↔ V ≤ U.dualCoannihilator := (dualAnnihilator_gc R M).le_iff_le #align submodule.le_dual_annihilator_iff_le_dual_coannihilator Submodule.le_dualAnnihilator_iff_le_dualCoannihilator @[simp] theorem dualAnnihilator_bot : (⊥ : Submodule R M).dualAnnihilator = ⊤ := (dualAnnihilator_gc R M).l_bot #align submodule.dual_annihilator_bot Submodule.dualAnnihilator_bot @[simp] theorem dualAnnihilator_top : (⊤ : Submodule R M).dualAnnihilator = ⊥ := by rw [eq_bot_iff] intro v simp_rw [mem_dualAnnihilator, mem_bot, mem_top, forall_true_left] exact fun h => LinearMap.ext h #align submodule.dual_annihilator_top Submodule.dualAnnihilator_top @[simp] theorem dualCoannihilator_bot : (⊥ : Submodule R (Module.Dual R M)).dualCoannihilator = ⊤ := (dualAnnihilator_gc R M).u_top #align submodule.dual_coannihilator_bot Submodule.dualCoannihilator_bot @[mono] theorem dualAnnihilator_anti {U V : Submodule R M} (hUV : U ≤ V) : V.dualAnnihilator ≤ U.dualAnnihilator := (dualAnnihilator_gc R M).monotone_l hUV #align submodule.dual_annihilator_anti Submodule.dualAnnihilator_anti @[mono] theorem dualCoannihilator_anti {U V : Submodule R (Module.Dual R M)} (hUV : U ≤ V) : V.dualCoannihilator ≤ U.dualCoannihilator := (dualAnnihilator_gc R M).monotone_u hUV #align submodule.dual_coannihilator_anti Submodule.dualCoannihilator_anti theorem le_dualAnnihilator_dualCoannihilator (U : Submodule R M) : U ≤ U.dualAnnihilator.dualCoannihilator := (dualAnnihilator_gc R M).le_u_l U #align submodule.le_dual_annihilator_dual_coannihilator Submodule.le_dualAnnihilator_dualCoannihilator theorem le_dualCoannihilator_dualAnnihilator (U : Submodule R (Module.Dual R M)) : U ≤ U.dualCoannihilator.dualAnnihilator := (dualAnnihilator_gc R M).l_u_le U #align submodule.le_dual_coannihilator_dual_annihilator Submodule.le_dualCoannihilator_dualAnnihilator theorem dualAnnihilator_dualCoannihilator_dualAnnihilator (U : Submodule R M) : U.dualAnnihilator.dualCoannihilator.dualAnnihilator = U.dualAnnihilator := (dualAnnihilator_gc R M).l_u_l_eq_l U #align submodule.dual_annihilator_dual_coannihilator_dual_annihilator Submodule.dualAnnihilator_dualCoannihilator_dualAnnihilator theorem dualCoannihilator_dualAnnihilator_dualCoannihilator (U : Submodule R (Module.Dual R M)) : U.dualCoannihilator.dualAnnihilator.dualCoannihilator = U.dualCoannihilator := (dualAnnihilator_gc R M).u_l_u_eq_u U #align submodule.dual_coannihilator_dual_annihilator_dual_coannihilator Submodule.dualCoannihilator_dualAnnihilator_dualCoannihilator theorem dualAnnihilator_sup_eq (U V : Submodule R M) : (U ⊔ V).dualAnnihilator = U.dualAnnihilator ⊓ V.dualAnnihilator := (dualAnnihilator_gc R M).l_sup #align submodule.dual_annihilator_sup_eq Submodule.dualAnnihilator_sup_eq theorem dualCoannihilator_sup_eq (U V : Submodule R (Module.Dual R M)) : (U ⊔ V).dualCoannihilator = U.dualCoannihilator ⊓ V.dualCoannihilator := (dualAnnihilator_gc R M).u_inf #align submodule.dual_coannihilator_sup_eq Submodule.dualCoannihilator_sup_eq theorem dualAnnihilator_iSup_eq {ι : Sort*} (U : ι → Submodule R M) : (⨆ i : ι, U i).dualAnnihilator = ⨅ i : ι, (U i).dualAnnihilator := (dualAnnihilator_gc R M).l_iSup #align submodule.dual_annihilator_supr_eq Submodule.dualAnnihilator_iSup_eq theorem dualCoannihilator_iSup_eq {ι : Sort*} (U : ι → Submodule R (Module.Dual R M)) : (⨆ i : ι, U i).dualCoannihilator = ⨅ i : ι, (U i).dualCoannihilator := (dualAnnihilator_gc R M).u_iInf #align submodule.dual_coannihilator_supr_eq Submodule.dualCoannihilator_iSup_eq /-- See also `Subspace.dualAnnihilator_inf_eq` for vector subspaces. -/ theorem sup_dualAnnihilator_le_inf (U V : Submodule R M) : U.dualAnnihilator ⊔ V.dualAnnihilator ≤ (U ⊓ V).dualAnnihilator := by rw [le_dualAnnihilator_iff_le_dualCoannihilator, dualCoannihilator_sup_eq] apply inf_le_inf <;> exact le_dualAnnihilator_dualCoannihilator _ #align submodule.sup_dual_annihilator_le_inf Submodule.sup_dualAnnihilator_le_inf /-- See also `Subspace.dualAnnihilator_iInf_eq` for vector subspaces when `ι` is finite. -/ theorem iSup_dualAnnihilator_le_iInf {ι : Sort*} (U : ι → Submodule R M) : ⨆ i : ι, (U i).dualAnnihilator ≤ (⨅ i : ι, U i).dualAnnihilator := by rw [le_dualAnnihilator_iff_le_dualCoannihilator, dualCoannihilator_iSup_eq] apply iInf_mono exact fun i : ι => le_dualAnnihilator_dualCoannihilator (U i) #align submodule.supr_dual_annihilator_le_infi Submodule.iSup_dualAnnihilator_le_iInf end Submodule namespace Subspace open Submodule LinearMap universe u v w -- We work in vector spaces because `exists_is_compl` only hold for vector spaces variable {K : Type u} {V : Type v} [Field K] [AddCommGroup V] [Module K V] @[simp] theorem dualCoannihilator_top (W : Subspace K V) : (⊤ : Subspace K (Module.Dual K W)).dualCoannihilator = ⊥ := by rw [dualCoannihilator, dualAnnihilator_top, comap_bot, Module.eval_ker] #align subspace.dual_coannihilator_top Subspace.dualCoannihilator_top @[simp] theorem dualAnnihilator_dualCoannihilator_eq {W : Subspace K V} : W.dualAnnihilator.dualCoannihilator = W := by refine le_antisymm (fun v ↦ Function.mtr ?_) (le_dualAnnihilator_dualCoannihilator _) simp only [mem_dualAnnihilator, mem_dualCoannihilator] rw [← Quotient.mk_eq_zero W, ← Module.forall_dual_apply_eq_zero_iff K] push_neg refine fun ⟨φ, hφ⟩ ↦ ⟨φ.comp W.mkQ, fun w hw ↦ ?_, hφ⟩ rw [comp_apply, mkQ_apply, (Quotient.mk_eq_zero W).mpr hw, φ.map_zero] #align subspace.dual_annihilator_dual_coannihilator_eq Subspace.dualAnnihilator_dualCoannihilator_eq -- exact elaborates slowly theorem forall_mem_dualAnnihilator_apply_eq_zero_iff (W : Subspace K V) (v : V) : (∀ φ : Module.Dual K V, φ ∈ W.dualAnnihilator → φ v = 0) ↔ v ∈ W := by rw [← SetLike.ext_iff.mp dualAnnihilator_dualCoannihilator_eq v, mem_dualCoannihilator] #align subspace.forall_mem_dual_annihilator_apply_eq_zero_iff Subspace.forall_mem_dualAnnihilator_apply_eq_zero_iff
Mathlib/LinearAlgebra/Dual.lean
1,071
1,073
theorem comap_dualAnnihilator_dualAnnihilator (W : Subspace K V) : W.dualAnnihilator.dualAnnihilator.comap (Module.Dual.eval K V) = W := by
ext; rw [Iff.comm, ← forall_mem_dualAnnihilator_apply_eq_zero_iff]; simp
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Chris Hughes -/ import Mathlib.Algebra.Algebra.Defs import Mathlib.Algebra.Polynomial.FieldDivision import Mathlib.FieldTheory.Minpoly.Basic import Mathlib.RingTheory.Adjoin.Basic import Mathlib.RingTheory.FinitePresentation import Mathlib.RingTheory.FiniteType import Mathlib.RingTheory.PowerBasis import Mathlib.RingTheory.PrincipalIdealDomain import Mathlib.RingTheory.QuotientNoetherian #align_import ring_theory.adjoin_root from "leanprover-community/mathlib"@"5c4b3d41a84bd2a1d79c7d9265e58a891e71be89" /-! # Adjoining roots of polynomials This file defines the commutative ring `AdjoinRoot f`, the ring R[X]/(f) obtained from a commutative ring `R` and a polynomial `f : R[X]`. If furthermore `R` is a field and `f` is irreducible, the field structure on `AdjoinRoot f` is constructed. We suggest stating results on `IsAdjoinRoot` instead of `AdjoinRoot` to achieve higher generality, since `IsAdjoinRoot` works for all different constructions of `R[α]` including `AdjoinRoot f = R[X]/(f)` itself. ## Main definitions and results The main definitions are in the `AdjoinRoot` namespace. * `mk f : R[X] →+* AdjoinRoot f`, the natural ring homomorphism. * `of f : R →+* AdjoinRoot f`, the natural ring homomorphism. * `root f : AdjoinRoot f`, the image of X in R[X]/(f). * `lift (i : R →+* S) (x : S) (h : f.eval₂ i x = 0) : (AdjoinRoot f) →+* S`, the ring homomorphism from R[X]/(f) to S extending `i : R →+* S` and sending `X` to `x`. * `lift_hom (x : S) (hfx : aeval x f = 0) : AdjoinRoot f →ₐ[R] S`, the algebra homomorphism from R[X]/(f) to S extending `algebraMap R S` and sending `X` to `x` * `equiv : (AdjoinRoot f →ₐ[F] E) ≃ {x // x ∈ f.aroots E}` a bijection between algebra homomorphisms from `AdjoinRoot` and roots of `f` in `S` -/ noncomputable section open scoped Classical open Polynomial universe u v w variable {R : Type u} {S : Type v} {K : Type w} open Polynomial Ideal /-- Adjoin a root of a polynomial `f` to a commutative ring `R`. We define the new ring as the quotient of `R[X]` by the principal ideal generated by `f`. -/ def AdjoinRoot [CommRing R] (f : R[X]) : Type u := Polynomial R ⧸ (span {f} : Ideal R[X]) #align adjoin_root AdjoinRoot namespace AdjoinRoot section CommRing variable [CommRing R] (f : R[X]) instance instCommRing : CommRing (AdjoinRoot f) := Ideal.Quotient.commRing _ #align adjoin_root.comm_ring AdjoinRoot.instCommRing instance : Inhabited (AdjoinRoot f) := ⟨0⟩ instance : DecidableEq (AdjoinRoot f) := Classical.decEq _ protected theorem nontrivial [IsDomain R] (h : degree f ≠ 0) : Nontrivial (AdjoinRoot f) := Ideal.Quotient.nontrivial (by simp_rw [Ne, span_singleton_eq_top, Polynomial.isUnit_iff, not_exists, not_and] rintro x hx rfl exact h (degree_C hx.ne_zero)) #align adjoin_root.nontrivial AdjoinRoot.nontrivial /-- Ring homomorphism from `R[x]` to `AdjoinRoot f` sending `X` to the `root`. -/ def mk : R[X] →+* AdjoinRoot f := Ideal.Quotient.mk _ #align adjoin_root.mk AdjoinRoot.mk @[elab_as_elim] theorem induction_on {C : AdjoinRoot f → Prop} (x : AdjoinRoot f) (ih : ∀ p : R[X], C (mk f p)) : C x := Quotient.inductionOn' x ih #align adjoin_root.induction_on AdjoinRoot.induction_on /-- Embedding of the original ring `R` into `AdjoinRoot f`. -/ def of : R →+* AdjoinRoot f := (mk f).comp C #align adjoin_root.of AdjoinRoot.of instance instSMulAdjoinRoot [DistribSMul S R] [IsScalarTower S R R] : SMul S (AdjoinRoot f) := Submodule.Quotient.instSMul' _ instance [DistribSMul S R] [IsScalarTower S R R] : DistribSMul S (AdjoinRoot f) := Submodule.Quotient.distribSMul' _ @[simp] theorem smul_mk [DistribSMul S R] [IsScalarTower S R R] (a : S) (x : R[X]) : a • mk f x = mk f (a • x) := rfl #align adjoin_root.smul_mk AdjoinRoot.smul_mk theorem smul_of [DistribSMul S R] [IsScalarTower S R R] (a : S) (x : R) : a • of f x = of f (a • x) := by rw [of, RingHom.comp_apply, RingHom.comp_apply, smul_mk, smul_C] #align adjoin_root.smul_of AdjoinRoot.smul_of instance (R₁ R₂ : Type*) [SMul R₁ R₂] [DistribSMul R₁ R] [DistribSMul R₂ R] [IsScalarTower R₁ R R] [IsScalarTower R₂ R R] [IsScalarTower R₁ R₂ R] (f : R[X]) : IsScalarTower R₁ R₂ (AdjoinRoot f) := Submodule.Quotient.isScalarTower _ _ instance (R₁ R₂ : Type*) [DistribSMul R₁ R] [DistribSMul R₂ R] [IsScalarTower R₁ R R] [IsScalarTower R₂ R R] [SMulCommClass R₁ R₂ R] (f : R[X]) : SMulCommClass R₁ R₂ (AdjoinRoot f) := Submodule.Quotient.smulCommClass _ _ instance isScalarTower_right [DistribSMul S R] [IsScalarTower S R R] : IsScalarTower S (AdjoinRoot f) (AdjoinRoot f) := Ideal.Quotient.isScalarTower_right #align adjoin_root.is_scalar_tower_right AdjoinRoot.isScalarTower_right instance [Monoid S] [DistribMulAction S R] [IsScalarTower S R R] (f : R[X]) : DistribMulAction S (AdjoinRoot f) := Submodule.Quotient.distribMulAction' _ instance [CommSemiring S] [Algebra S R] : Algebra S (AdjoinRoot f) := Ideal.Quotient.algebra S @[simp] theorem algebraMap_eq : algebraMap R (AdjoinRoot f) = of f := rfl #align adjoin_root.algebra_map_eq AdjoinRoot.algebraMap_eq variable (S) theorem algebraMap_eq' [CommSemiring S] [Algebra S R] : algebraMap S (AdjoinRoot f) = (of f).comp (algebraMap S R) := rfl #align adjoin_root.algebra_map_eq' AdjoinRoot.algebraMap_eq' variable {S} theorem finiteType : Algebra.FiniteType R (AdjoinRoot f) := (Algebra.FiniteType.polynomial R).of_surjective _ (Ideal.Quotient.mkₐ_surjective R _) #align adjoin_root.finite_type AdjoinRoot.finiteType theorem finitePresentation : Algebra.FinitePresentation R (AdjoinRoot f) := (Algebra.FinitePresentation.polynomial R).quotient (Submodule.fg_span_singleton f) #align adjoin_root.finite_presentation AdjoinRoot.finitePresentation /-- The adjoined root. -/ def root : AdjoinRoot f := mk f X #align adjoin_root.root AdjoinRoot.root variable {f} instance hasCoeT : CoeTC R (AdjoinRoot f) := ⟨of f⟩ #align adjoin_root.has_coe_t AdjoinRoot.hasCoeT /-- Two `R`-`AlgHom` from `AdjoinRoot f` to the same `R`-algebra are the same iff they agree on `root f`. -/ @[ext] theorem algHom_ext [Semiring S] [Algebra R S] {g₁ g₂ : AdjoinRoot f →ₐ[R] S} (h : g₁ (root f) = g₂ (root f)) : g₁ = g₂ := Ideal.Quotient.algHom_ext R <| Polynomial.algHom_ext h #align adjoin_root.alg_hom_ext AdjoinRoot.algHom_ext @[simp] theorem mk_eq_mk {g h : R[X]} : mk f g = mk f h ↔ f ∣ g - h := Ideal.Quotient.eq.trans Ideal.mem_span_singleton #align adjoin_root.mk_eq_mk AdjoinRoot.mk_eq_mk @[simp] theorem mk_eq_zero {g : R[X]} : mk f g = 0 ↔ f ∣ g := mk_eq_mk.trans <| by rw [sub_zero] #align adjoin_root.mk_eq_zero AdjoinRoot.mk_eq_zero @[simp] theorem mk_self : mk f f = 0 := Quotient.sound' <| QuotientAddGroup.leftRel_apply.mpr (mem_span_singleton.2 <| by simp) #align adjoin_root.mk_self AdjoinRoot.mk_self @[simp] theorem mk_C (x : R) : mk f (C x) = x := rfl set_option linter.uppercaseLean3 false in #align adjoin_root.mk_C AdjoinRoot.mk_C @[simp] theorem mk_X : mk f X = root f := rfl set_option linter.uppercaseLean3 false in #align adjoin_root.mk_X AdjoinRoot.mk_X theorem mk_ne_zero_of_degree_lt (hf : Monic f) {g : R[X]} (h0 : g ≠ 0) (hd : degree g < degree f) : mk f g ≠ 0 := mk_eq_zero.not.2 <| hf.not_dvd_of_degree_lt h0 hd #align adjoin_root.mk_ne_zero_of_degree_lt AdjoinRoot.mk_ne_zero_of_degree_lt theorem mk_ne_zero_of_natDegree_lt (hf : Monic f) {g : R[X]} (h0 : g ≠ 0) (hd : natDegree g < natDegree f) : mk f g ≠ 0 := mk_eq_zero.not.2 <| hf.not_dvd_of_natDegree_lt h0 hd #align adjoin_root.mk_ne_zero_of_nat_degree_lt AdjoinRoot.mk_ne_zero_of_natDegree_lt @[simp] theorem aeval_eq (p : R[X]) : aeval (root f) p = mk f p := Polynomial.induction_on p (fun x => by rw [aeval_C] rfl) (fun p q ihp ihq => by rw [AlgHom.map_add, RingHom.map_add, ihp, ihq]) fun n x _ => by rw [AlgHom.map_mul, aeval_C, AlgHom.map_pow, aeval_X, RingHom.map_mul, mk_C, RingHom.map_pow, mk_X] rfl #align adjoin_root.aeval_eq AdjoinRoot.aeval_eq -- Porting note: the following proof was partly in term-mode, but I was not able to fix it. theorem adjoinRoot_eq_top : Algebra.adjoin R ({root f} : Set (AdjoinRoot f)) = ⊤ := by refine Algebra.eq_top_iff.2 fun x => ?_ induction x using AdjoinRoot.induction_on with | ih p => exact (Algebra.adjoin_singleton_eq_range_aeval R (root f)).symm ▸ ⟨p, aeval_eq p⟩ #align adjoin_root.adjoin_root_eq_top AdjoinRoot.adjoinRoot_eq_top @[simp] theorem eval₂_root (f : R[X]) : f.eval₂ (of f) (root f) = 0 := by rw [← algebraMap_eq, ← aeval_def, aeval_eq, mk_self] #align adjoin_root.eval₂_root AdjoinRoot.eval₂_root theorem isRoot_root (f : R[X]) : IsRoot (f.map (of f)) (root f) := by rw [IsRoot, eval_map, eval₂_root] #align adjoin_root.is_root_root AdjoinRoot.isRoot_root theorem isAlgebraic_root (hf : f ≠ 0) : IsAlgebraic R (root f) := ⟨f, hf, eval₂_root f⟩ #align adjoin_root.is_algebraic_root AdjoinRoot.isAlgebraic_root theorem of.injective_of_degree_ne_zero [IsDomain R] (hf : f.degree ≠ 0) : Function.Injective (AdjoinRoot.of f) := by rw [injective_iff_map_eq_zero] intro p hp rw [AdjoinRoot.of, RingHom.comp_apply, AdjoinRoot.mk_eq_zero] at hp by_cases h : f = 0 · exact C_eq_zero.mp (eq_zero_of_zero_dvd (by rwa [h] at hp)) · contrapose! hf with h_contra rw [← degree_C h_contra] apply le_antisymm (degree_le_of_dvd hp (by rwa [Ne, C_eq_zero])) _ rwa [degree_C h_contra, zero_le_degree_iff] #align adjoin_root.of.injective_of_degree_ne_zero AdjoinRoot.of.injective_of_degree_ne_zero variable [CommRing S] /-- Lift a ring homomorphism `i : R →+* S` to `AdjoinRoot f →+* S`. -/ def lift (i : R →+* S) (x : S) (h : f.eval₂ i x = 0) : AdjoinRoot f →+* S := by apply Ideal.Quotient.lift _ (eval₂RingHom i x) intro g H rcases mem_span_singleton.1 H with ⟨y, hy⟩ rw [hy, RingHom.map_mul, coe_eval₂RingHom, h, zero_mul] #align adjoin_root.lift AdjoinRoot.lift variable {i : R →+* S} {a : S} (h : f.eval₂ i a = 0) @[simp] theorem lift_mk (g : R[X]) : lift i a h (mk f g) = g.eval₂ i a := Ideal.Quotient.lift_mk _ _ _ #align adjoin_root.lift_mk AdjoinRoot.lift_mk @[simp] theorem lift_root : lift i a h (root f) = a := by rw [root, lift_mk, eval₂_X] #align adjoin_root.lift_root AdjoinRoot.lift_root @[simp] theorem lift_of {x : R} : lift i a h x = i x := by rw [← mk_C x, lift_mk, eval₂_C] #align adjoin_root.lift_of AdjoinRoot.lift_of @[simp] theorem lift_comp_of : (lift i a h).comp (of f) = i := RingHom.ext fun _ => @lift_of _ _ _ _ _ _ _ h _ #align adjoin_root.lift_comp_of AdjoinRoot.lift_comp_of variable (f) [Algebra R S] /-- Produce an algebra homomorphism `AdjoinRoot f →ₐ[R] S` sending `root f` to a root of `f` in `S`. -/ def liftHom (x : S) (hfx : aeval x f = 0) : AdjoinRoot f →ₐ[R] S := { lift (algebraMap R S) x hfx with commutes' := fun r => show lift _ _ hfx r = _ from lift_of hfx } #align adjoin_root.lift_hom AdjoinRoot.liftHom @[simp] theorem coe_liftHom (x : S) (hfx : aeval x f = 0) : (liftHom f x hfx : AdjoinRoot f →+* S) = lift (algebraMap R S) x hfx := rfl #align adjoin_root.coe_lift_hom AdjoinRoot.coe_liftHom @[simp] theorem aeval_algHom_eq_zero (ϕ : AdjoinRoot f →ₐ[R] S) : aeval (ϕ (root f)) f = 0 := by have h : ϕ.toRingHom.comp (of f) = algebraMap R S := RingHom.ext_iff.mpr ϕ.commutes rw [aeval_def, ← h, ← RingHom.map_zero ϕ.toRingHom, ← eval₂_root f, hom_eval₂] rfl #align adjoin_root.aeval_alg_hom_eq_zero AdjoinRoot.aeval_algHom_eq_zero @[simp] theorem liftHom_eq_algHom (f : R[X]) (ϕ : AdjoinRoot f →ₐ[R] S) : liftHom f (ϕ (root f)) (aeval_algHom_eq_zero f ϕ) = ϕ := by suffices ϕ.equalizer (liftHom f (ϕ (root f)) (aeval_algHom_eq_zero f ϕ)) = ⊤ by exact (AlgHom.ext fun x => (SetLike.ext_iff.mp this x).mpr Algebra.mem_top).symm rw [eq_top_iff, ← adjoinRoot_eq_top, Algebra.adjoin_le_iff, Set.singleton_subset_iff] exact (@lift_root _ _ _ _ _ _ _ (aeval_algHom_eq_zero f ϕ)).symm #align adjoin_root.lift_hom_eq_alg_hom AdjoinRoot.liftHom_eq_algHom variable (hfx : aeval a f = 0) @[simp] theorem liftHom_mk {g : R[X]} : liftHom f a hfx (mk f g) = aeval a g := lift_mk hfx g #align adjoin_root.lift_hom_mk AdjoinRoot.liftHom_mk @[simp] theorem liftHom_root : liftHom f a hfx (root f) = a := lift_root hfx #align adjoin_root.lift_hom_root AdjoinRoot.liftHom_root @[simp] theorem liftHom_of {x : R} : liftHom f a hfx (of f x) = algebraMap _ _ x := lift_of hfx #align adjoin_root.lift_hom_of AdjoinRoot.liftHom_of section AdjoinInv @[simp] theorem root_isInv (r : R) : of _ r * root (C r * X - 1) = 1 := by convert sub_eq_zero.1 ((eval₂_sub _).symm.trans <| eval₂_root <| C r * X - 1) <;> simp only [eval₂_mul, eval₂_C, eval₂_X, eval₂_one] #align adjoin_root.root_is_inv AdjoinRoot.root_isInv theorem algHom_subsingleton {S : Type*} [CommRing S] [Algebra R S] {r : R} : Subsingleton (AdjoinRoot (C r * X - 1) →ₐ[R] S) := ⟨fun f g => algHom_ext (@inv_unique _ _ (algebraMap R S r) _ _ (by rw [← f.commutes, ← f.map_mul, algebraMap_eq, root_isInv, map_one]) (by rw [← g.commutes, ← g.map_mul, algebraMap_eq, root_isInv, map_one]))⟩ #align adjoin_root.alg_hom_subsingleton AdjoinRoot.algHom_subsingleton end AdjoinInv section Prime variable {f} theorem isDomain_of_prime (hf : Prime f) : IsDomain (AdjoinRoot f) := (Ideal.Quotient.isDomain_iff_prime (span {f} : Ideal R[X])).mpr <| (Ideal.span_singleton_prime hf.ne_zero).mpr hf #align adjoin_root.is_domain_of_prime AdjoinRoot.isDomain_of_prime theorem noZeroSMulDivisors_of_prime_of_degree_ne_zero [IsDomain R] (hf : Prime f) (hf' : f.degree ≠ 0) : NoZeroSMulDivisors R (AdjoinRoot f) := haveI := isDomain_of_prime hf NoZeroSMulDivisors.iff_algebraMap_injective.mpr (of.injective_of_degree_ne_zero hf') #align adjoin_root.no_zero_smul_divisors_of_prime_of_degree_ne_zero AdjoinRoot.noZeroSMulDivisors_of_prime_of_degree_ne_zero end Prime end CommRing section Irreducible variable [Field K] {f : K[X]} instance span_maximal_of_irreducible [Fact (Irreducible f)] : (span {f}).IsMaximal := PrincipalIdealRing.isMaximal_of_irreducible <| Fact.out #align adjoin_root.span_maximal_of_irreducible AdjoinRoot.span_maximal_of_irreducible noncomputable instance instGroupWithZero [Fact (Irreducible f)] : GroupWithZero (AdjoinRoot f) := Quotient.groupWithZero (span {f} : Ideal K[X]) noncomputable instance instField [Fact (Irreducible f)] : Field (AdjoinRoot f) where __ := instCommRing _ __ := instGroupWithZero nnqsmul := (· • ·) qsmul := (· • ·) nnratCast_def q := by rw [← map_natCast (of f), ← map_natCast (of f), ← map_div₀, ← NNRat.cast_def]; rfl ratCast_def q := by rw [← map_natCast (of f), ← map_intCast (of f), ← map_div₀, ← Rat.cast_def]; rfl nnqsmul_def q x := AdjoinRoot.induction_on (C := fun y ↦ q • y = (of f) q * y) x fun p ↦ by simp only [smul_mk, of, RingHom.comp_apply, ← (mk f).map_mul, Polynomial.nnqsmul_eq_C_mul] qsmul_def q x := -- Porting note: I gave the explicit motive and changed `rw` to `simp`. AdjoinRoot.induction_on (C := fun y ↦ q • y = (of f) q * y) x fun p ↦ by simp only [smul_mk, of, RingHom.comp_apply, ← (mk f).map_mul, Polynomial.qsmul_eq_C_mul] #align adjoin_root.field AdjoinRoot.instField theorem coe_injective (h : degree f ≠ 0) : Function.Injective ((↑) : K → AdjoinRoot f) := have := AdjoinRoot.nontrivial f h (of f).injective #align adjoin_root.coe_injective AdjoinRoot.coe_injective theorem coe_injective' [Fact (Irreducible f)] : Function.Injective ((↑) : K → AdjoinRoot f) := (of f).injective #align adjoin_root.coe_injective' AdjoinRoot.coe_injective' variable (f) theorem mul_div_root_cancel [Fact (Irreducible f)] : (X - C (root f)) * ((f.map (of f)) / (X - C (root f))) = f.map (of f) := mul_div_eq_iff_isRoot.2 <| isRoot_root _ #align adjoin_root.mul_div_root_cancel AdjoinRoot.mul_div_root_cancel end Irreducible section IsNoetherianRing instance [CommRing R] [IsNoetherianRing R] {f : R[X]} : IsNoetherianRing (AdjoinRoot f) := Ideal.Quotient.isNoetherianRing _ end IsNoetherianRing section PowerBasis variable [CommRing R] {g : R[X]} theorem isIntegral_root' (hg : g.Monic) : IsIntegral R (root g) := ⟨g, hg, eval₂_root g⟩ #align adjoin_root.is_integral_root' AdjoinRoot.isIntegral_root' /-- `AdjoinRoot.modByMonicHom` sends the equivalence class of `f` mod `g` to `f %ₘ g`. This is a well-defined right inverse to `AdjoinRoot.mk`, see `AdjoinRoot.mk_leftInverse`. -/ def modByMonicHom (hg : g.Monic) : AdjoinRoot g →ₗ[R] R[X] := (Submodule.liftQ _ (Polynomial.modByMonicHom g) fun f (hf : f ∈ (Ideal.span {g}).restrictScalars R) => (mem_ker_modByMonic hg).mpr (Ideal.mem_span_singleton.mp hf)).comp <| (Submodule.Quotient.restrictScalarsEquiv R (Ideal.span {g} : Ideal R[X])).symm.toLinearMap #align adjoin_root.mod_by_monic_hom AdjoinRoot.modByMonicHom @[simp] theorem modByMonicHom_mk (hg : g.Monic) (f : R[X]) : modByMonicHom hg (mk g f) = f %ₘ g := rfl #align adjoin_root.mod_by_monic_hom_mk AdjoinRoot.modByMonicHom_mk -- Porting note: the following proof was partly in term-mode, but I was not able to fix it. theorem mk_leftInverse (hg : g.Monic) : Function.LeftInverse (mk g) (modByMonicHom hg) := by intro f induction f using AdjoinRoot.induction_on rw [modByMonicHom_mk hg, mk_eq_mk, modByMonic_eq_sub_mul_div _ hg, sub_sub_cancel_left, dvd_neg] apply dvd_mul_right #align adjoin_root.mk_left_inverse AdjoinRoot.mk_leftInverse theorem mk_surjective : Function.Surjective (mk g) := Ideal.Quotient.mk_surjective #align adjoin_root.mk_surjective AdjoinRoot.mk_surjectiveₓ /-- The elements `1, root g, ..., root g ^ (d - 1)` form a basis for `AdjoinRoot g`, where `g` is a monic polynomial of degree `d`. -/ def powerBasisAux' (hg : g.Monic) : Basis (Fin g.natDegree) R (AdjoinRoot g) := Basis.ofEquivFun { toFun := fun f i => (modByMonicHom hg f).coeff i invFun := fun c => mk g <| ∑ i : Fin g.natDegree, monomial i (c i) map_add' := fun f₁ f₂ => funext fun i => by simp only [(modByMonicHom hg).map_add, coeff_add, Pi.add_apply] map_smul' := fun f₁ f₂ => funext fun i => by simp only [(modByMonicHom hg).map_smul, coeff_smul, Pi.smul_apply, RingHom.id_apply] -- Porting note: another proof that I converted to tactic mode left_inv := by intro f induction f using AdjoinRoot.induction_on simp only [modByMonicHom_mk, sum_modByMonic_coeff hg degree_le_natDegree] refine (mk_eq_mk.mpr ?_).symm rw [modByMonic_eq_sub_mul_div _ hg, sub_sub_cancel] exact dvd_mul_right _ _ right_inv := fun x => funext fun i => by nontriviality R simp only [modByMonicHom_mk] rw [(modByMonic_eq_self_iff hg).mpr, finset_sum_coeff] · simp_rw [coeff_monomial, Fin.val_eq_val, Finset.sum_ite_eq', if_pos (Finset.mem_univ _)] · simp_rw [← C_mul_X_pow_eq_monomial] exact (degree_eq_natDegree <| hg.ne_zero).symm ▸ degree_sum_fin_lt _ } #align adjoin_root.power_basis_aux' AdjoinRoot.powerBasisAux' -- This lemma could be autogenerated by `@[simps]` but unfortunately that would require -- unfolding that causes a timeout. -- This lemma should have the simp tag but this causes a lint issue. theorem powerBasisAux'_repr_symm_apply (hg : g.Monic) (c : Fin g.natDegree →₀ R) : (powerBasisAux' hg).repr.symm c = mk g (∑ i : Fin _, monomial i (c i)) := rfl #align adjoin_root.power_basis_aux'_repr_symm_apply AdjoinRoot.powerBasisAux'_repr_symm_apply -- This lemma could be autogenerated by `@[simps]` but unfortunately that would require -- unfolding that causes a timeout. @[simp] theorem powerBasisAux'_repr_apply_to_fun (hg : g.Monic) (f : AdjoinRoot g) (i : Fin g.natDegree) : (powerBasisAux' hg).repr f i = (modByMonicHom hg f).coeff ↑i := rfl #align adjoin_root.power_basis_aux'_repr_apply_to_fun AdjoinRoot.powerBasisAux'_repr_apply_to_fun /-- The power basis `1, root g, ..., root g ^ (d - 1)` for `AdjoinRoot g`, where `g` is a monic polynomial of degree `d`. -/ @[simps] def powerBasis' (hg : g.Monic) : PowerBasis R (AdjoinRoot g) where gen := root g dim := g.natDegree basis := powerBasisAux' hg basis_eq_pow i := by simp only [powerBasisAux', Basis.coe_ofEquivFun, LinearEquiv.coe_symm_mk] rw [Finset.sum_eq_single i] · rw [Function.update_same, monomial_one_right_eq_X_pow, (mk g).map_pow, mk_X] · intro j _ hj rw [← monomial_zero_right _] convert congr_arg _ (Function.update_noteq hj _ _) -- Fix `DecidableEq` mismatch · intros have := Finset.mem_univ i contradiction #align adjoin_root.power_basis' AdjoinRoot.powerBasis' variable [Field K] {f : K[X]} theorem isIntegral_root (hf : f ≠ 0) : IsIntegral K (root f) := (isAlgebraic_root hf).isIntegral #align adjoin_root.is_integral_root AdjoinRoot.isIntegral_root theorem minpoly_root (hf : f ≠ 0) : minpoly K (root f) = f * C f.leadingCoeff⁻¹ := by have f'_monic : Monic _ := monic_mul_leadingCoeff_inv hf refine (minpoly.unique K _ f'_monic ?_ ?_).symm · rw [AlgHom.map_mul, aeval_eq, mk_self, zero_mul] intro q q_monic q_aeval have commutes : (lift (algebraMap K (AdjoinRoot f)) (root f) q_aeval).comp (mk q) = mk f := by ext · simp only [RingHom.comp_apply, mk_C, lift_of] rfl · simp only [RingHom.comp_apply, mk_X, lift_root] rw [degree_eq_natDegree f'_monic.ne_zero, degree_eq_natDegree q_monic.ne_zero, Nat.cast_le, natDegree_mul hf, natDegree_C, add_zero] · apply natDegree_le_of_dvd · have : mk f q = 0 := by rw [← commutes, RingHom.comp_apply, mk_self, RingHom.map_zero] exact mk_eq_zero.1 this · exact q_monic.ne_zero · rwa [Ne, C_eq_zero, inv_eq_zero, leadingCoeff_eq_zero] #align adjoin_root.minpoly_root AdjoinRoot.minpoly_root /-- The elements `1, root f, ..., root f ^ (d - 1)` form a basis for `AdjoinRoot f`, where `f` is an irreducible polynomial over a field of degree `d`. -/ def powerBasisAux (hf : f ≠ 0) : Basis (Fin f.natDegree) K (AdjoinRoot f) := by let f' := f * C f.leadingCoeff⁻¹ have deg_f' : f'.natDegree = f.natDegree := by rw [natDegree_mul hf, natDegree_C, add_zero] · rwa [Ne, C_eq_zero, inv_eq_zero, leadingCoeff_eq_zero] have minpoly_eq : minpoly K (root f) = f' := minpoly_root hf apply @Basis.mk _ _ _ fun i : Fin f.natDegree => root f ^ i.val · rw [← deg_f', ← minpoly_eq] exact linearIndependent_pow (root f) · rintro y - rw [← deg_f', ← minpoly_eq] apply (isIntegral_root hf).mem_span_pow obtain ⟨g⟩ := y use g rw [aeval_eq] rfl #align adjoin_root.power_basis_aux AdjoinRoot.powerBasisAux /-- The power basis `1, root f, ..., root f ^ (d - 1)` for `AdjoinRoot f`, where `f` is an irreducible polynomial over a field of degree `d`. -/ @[simps!] -- Porting note: was `[simps]` def powerBasis (hf : f ≠ 0) : PowerBasis K (AdjoinRoot f) where gen := root f dim := f.natDegree basis := powerBasisAux hf basis_eq_pow := by simp [powerBasisAux] #align adjoin_root.power_basis AdjoinRoot.powerBasis theorem minpoly_powerBasis_gen (hf : f ≠ 0) : minpoly K (powerBasis hf).gen = f * C f.leadingCoeff⁻¹ := by rw [powerBasis_gen, minpoly_root hf] #align adjoin_root.minpoly_power_basis_gen AdjoinRoot.minpoly_powerBasis_gen theorem minpoly_powerBasis_gen_of_monic (hf : f.Monic) (hf' : f ≠ 0 := hf.ne_zero) : minpoly K (powerBasis hf').gen = f := by rw [minpoly_powerBasis_gen hf', hf.leadingCoeff, inv_one, C.map_one, mul_one] #align adjoin_root.minpoly_power_basis_gen_of_monic AdjoinRoot.minpoly_powerBasis_gen_of_monic end PowerBasis section Equiv section minpoly variable [CommRing R] [CommRing S] [Algebra R S] (x : S) (R) open Algebra Polynomial /-- The surjective algebra morphism `R[X]/(minpoly R x) → R[x]`. If `R` is a integrally closed domain and `x` is integral, this is an isomorphism, see `minpoly.equivAdjoin`. -/ @[simps!] def Minpoly.toAdjoin : AdjoinRoot (minpoly R x) →ₐ[R] adjoin R ({x} : Set S) := liftHom _ ⟨x, self_mem_adjoin_singleton R x⟩ (by simp [← Subalgebra.coe_eq_zero, aeval_subalgebra_coe]) #align adjoin_root.minpoly.to_adjoin AdjoinRoot.Minpoly.toAdjoin variable {R x} theorem Minpoly.toAdjoin_apply' (a : AdjoinRoot (minpoly R x)) : Minpoly.toAdjoin R x a = liftHom (minpoly R x) (⟨x, self_mem_adjoin_singleton R x⟩ : adjoin R ({x} : Set S)) (by simp [← Subalgebra.coe_eq_zero, aeval_subalgebra_coe]) a := rfl #align adjoin_root.minpoly.to_adjoin_apply' AdjoinRoot.Minpoly.toAdjoin_apply' theorem Minpoly.toAdjoin.apply_X : Minpoly.toAdjoin R x (mk (minpoly R x) X) = ⟨x, self_mem_adjoin_singleton R x⟩ := by simp [toAdjoin] set_option linter.uppercaseLean3 false in #align adjoin_root.minpoly.to_adjoin.apply_X AdjoinRoot.Minpoly.toAdjoin.apply_X variable (R x)
Mathlib/RingTheory/AdjoinRoot.lean
641
643
theorem Minpoly.toAdjoin.surjective : Function.Surjective (Minpoly.toAdjoin R x) := by
rw [← range_top_iff_surjective, _root_.eq_top_iff, ← adjoin_adjoin_coe_preimage] exact adjoin_le fun ⟨y₁, y₂⟩ h ↦ ⟨mk (minpoly R x) X, by simpa [toAdjoin] using h.symm⟩
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Mario Carneiro, Johan Commelin -/ import Mathlib.NumberTheory.Padics.PadicNumbers import Mathlib.RingTheory.DiscreteValuationRing.Basic #align_import number_theory.padics.padic_integers from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9" /-! # p-adic integers This file defines the `p`-adic integers `ℤ_[p]` as the subtype of `ℚ_[p]` with norm `≤ 1`. We show that `ℤ_[p]` * is complete, * is nonarchimedean, * is a normed ring, * is a local ring, and * is a discrete valuation ring. The relation between `ℤ_[p]` and `ZMod p` is established in another file. ## Important definitions * `PadicInt` : the type of `p`-adic integers ## Notation We introduce the notation `ℤ_[p]` for the `p`-adic integers. ## Implementation notes Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically by taking `[Fact p.Prime]` as a type class argument. Coercions into `ℤ_[p]` are set up to work with the `norm_cast` tactic. ## References * [F. Q. Gouvêa, *p-adic numbers*][gouvea1997] * [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019] * <https://en.wikipedia.org/wiki/P-adic_number> ## Tags p-adic, p adic, padic, p-adic integer -/ open Padic Metric LocalRing noncomputable section open scoped Classical /-- The `p`-adic integers `ℤ_[p]` are the `p`-adic numbers with norm `≤ 1`. -/ def PadicInt (p : ℕ) [Fact p.Prime] := { x : ℚ_[p] // ‖x‖ ≤ 1 } #align padic_int PadicInt /-- The ring of `p`-adic integers. -/ notation "ℤ_[" p "]" => PadicInt p namespace PadicInt /-! ### Ring structure and coercion to `ℚ_[p]` -/ variable {p : ℕ} [Fact p.Prime] instance : Coe ℤ_[p] ℚ_[p] := ⟨Subtype.val⟩ theorem ext {x y : ℤ_[p]} : (x : ℚ_[p]) = y → x = y := Subtype.ext #align padic_int.ext PadicInt.ext variable (p) /-- The `p`-adic integers as a subring of `ℚ_[p]`. -/ def subring : Subring ℚ_[p] where carrier := { x : ℚ_[p] | ‖x‖ ≤ 1 } zero_mem' := by set_option tactic.skipAssignedInstances false in norm_num one_mem' := by set_option tactic.skipAssignedInstances false in norm_num add_mem' hx hy := (padicNormE.nonarchimedean _ _).trans <| max_le_iff.2 ⟨hx, hy⟩ mul_mem' hx hy := (padicNormE.mul _ _).trans_le <| mul_le_one hx (norm_nonneg _) hy neg_mem' hx := (norm_neg _).trans_le hx #align padic_int.subring PadicInt.subring @[simp] theorem mem_subring_iff {x : ℚ_[p]} : x ∈ subring p ↔ ‖x‖ ≤ 1 := Iff.rfl #align padic_int.mem_subring_iff PadicInt.mem_subring_iff variable {p} /-- Addition on `ℤ_[p]` is inherited from `ℚ_[p]`. -/ instance : Add ℤ_[p] := (by infer_instance : Add (subring p)) /-- Multiplication on `ℤ_[p]` is inherited from `ℚ_[p]`. -/ instance : Mul ℤ_[p] := (by infer_instance : Mul (subring p)) /-- Negation on `ℤ_[p]` is inherited from `ℚ_[p]`. -/ instance : Neg ℤ_[p] := (by infer_instance : Neg (subring p)) /-- Subtraction on `ℤ_[p]` is inherited from `ℚ_[p]`. -/ instance : Sub ℤ_[p] := (by infer_instance : Sub (subring p)) /-- Zero on `ℤ_[p]` is inherited from `ℚ_[p]`. -/ instance : Zero ℤ_[p] := (by infer_instance : Zero (subring p)) instance : Inhabited ℤ_[p] := ⟨0⟩ /-- One on `ℤ_[p]` is inherited from `ℚ_[p]`. -/ instance : One ℤ_[p] := ⟨⟨1, by norm_num⟩⟩ @[simp] theorem mk_zero {h} : (⟨0, h⟩ : ℤ_[p]) = (0 : ℤ_[p]) := rfl #align padic_int.mk_zero PadicInt.mk_zero @[simp, norm_cast] theorem coe_add (z1 z2 : ℤ_[p]) : ((z1 + z2 : ℤ_[p]) : ℚ_[p]) = z1 + z2 := rfl #align padic_int.coe_add PadicInt.coe_add @[simp, norm_cast] theorem coe_mul (z1 z2 : ℤ_[p]) : ((z1 * z2 : ℤ_[p]) : ℚ_[p]) = z1 * z2 := rfl #align padic_int.coe_mul PadicInt.coe_mul @[simp, norm_cast] theorem coe_neg (z1 : ℤ_[p]) : ((-z1 : ℤ_[p]) : ℚ_[p]) = -z1 := rfl #align padic_int.coe_neg PadicInt.coe_neg @[simp, norm_cast] theorem coe_sub (z1 z2 : ℤ_[p]) : ((z1 - z2 : ℤ_[p]) : ℚ_[p]) = z1 - z2 := rfl #align padic_int.coe_sub PadicInt.coe_sub @[simp, norm_cast] theorem coe_one : ((1 : ℤ_[p]) : ℚ_[p]) = 1 := rfl #align padic_int.coe_one PadicInt.coe_one @[simp, norm_cast] theorem coe_zero : ((0 : ℤ_[p]) : ℚ_[p]) = 0 := rfl #align padic_int.coe_zero PadicInt.coe_zero theorem coe_eq_zero (z : ℤ_[p]) : (z : ℚ_[p]) = 0 ↔ z = 0 := by rw [← coe_zero, Subtype.coe_inj] #align padic_int.coe_eq_zero PadicInt.coe_eq_zero theorem coe_ne_zero (z : ℤ_[p]) : (z : ℚ_[p]) ≠ 0 ↔ z ≠ 0 := z.coe_eq_zero.not #align padic_int.coe_ne_zero PadicInt.coe_ne_zero instance : AddCommGroup ℤ_[p] := (by infer_instance : AddCommGroup (subring p)) instance instCommRing : CommRing ℤ_[p] := (by infer_instance : CommRing (subring p)) @[simp, norm_cast] theorem coe_natCast (n : ℕ) : ((n : ℤ_[p]) : ℚ_[p]) = n := rfl #align padic_int.coe_nat_cast PadicInt.coe_natCast @[deprecated (since := "2024-04-17")] alias coe_nat_cast := coe_natCast @[simp, norm_cast] theorem coe_intCast (z : ℤ) : ((z : ℤ_[p]) : ℚ_[p]) = z := rfl #align padic_int.coe_int_cast PadicInt.coe_intCast @[deprecated (since := "2024-04-17")] alias coe_int_cast := coe_intCast /-- The coercion from `ℤ_[p]` to `ℚ_[p]` as a ring homomorphism. -/ def Coe.ringHom : ℤ_[p] →+* ℚ_[p] := (subring p).subtype #align padic_int.coe.ring_hom PadicInt.Coe.ringHom @[simp, norm_cast] theorem coe_pow (x : ℤ_[p]) (n : ℕ) : (↑(x ^ n) : ℚ_[p]) = (↑x : ℚ_[p]) ^ n := rfl #align padic_int.coe_pow PadicInt.coe_pow -- @[simp] -- Porting note: not in simpNF theorem mk_coe (k : ℤ_[p]) : (⟨k, k.2⟩ : ℤ_[p]) = k := Subtype.coe_eta _ _ #align padic_int.mk_coe PadicInt.mk_coe /-- The inverse of a `p`-adic integer with norm equal to `1` is also a `p`-adic integer. Otherwise, the inverse is defined to be `0`. -/ def inv : ℤ_[p] → ℤ_[p] | ⟨k, _⟩ => if h : ‖k‖ = 1 then ⟨k⁻¹, by simp [h]⟩ else 0 #align padic_int.inv PadicInt.inv instance : CharZero ℤ_[p] where cast_injective m n h := Nat.cast_injective (by rw [Subtype.ext_iff] at h; norm_cast at h) @[norm_cast] -- @[simp] -- Porting note: not in simpNF theorem intCast_eq (z1 z2 : ℤ) : (z1 : ℤ_[p]) = z2 ↔ z1 = z2 := by suffices (z1 : ℚ_[p]) = z2 ↔ z1 = z2 from Iff.trans (by norm_cast) this norm_cast #align padic_int.coe_int_eq PadicInt.intCast_eq -- 2024-04-05 @[deprecated] alias coe_int_eq := intCast_eq /-- A sequence of integers that is Cauchy with respect to the `p`-adic norm converges to a `p`-adic integer. -/ def ofIntSeq (seq : ℕ → ℤ) (h : IsCauSeq (padicNorm p) fun n => seq n) : ℤ_[p] := ⟨⟦⟨_, h⟩⟧, show ↑(PadicSeq.norm _) ≤ (1 : ℝ) by rw [PadicSeq.norm] split_ifs with hne <;> norm_cast apply padicNorm.of_int⟩ #align padic_int.of_int_seq PadicInt.ofIntSeq end PadicInt namespace PadicInt /-! ### Instances We now show that `ℤ_[p]` is a * complete metric space * normed ring * integral domain -/ variable (p : ℕ) [Fact p.Prime] instance : MetricSpace ℤ_[p] := Subtype.metricSpace instance completeSpace : CompleteSpace ℤ_[p] := have : IsClosed { x : ℚ_[p] | ‖x‖ ≤ 1 } := isClosed_le continuous_norm continuous_const this.completeSpace_coe #align padic_int.complete_space PadicInt.completeSpace instance : Norm ℤ_[p] := ⟨fun z => ‖(z : ℚ_[p])‖⟩ variable {p} theorem norm_def {z : ℤ_[p]} : ‖z‖ = ‖(z : ℚ_[p])‖ := rfl #align padic_int.norm_def PadicInt.norm_def variable (p) instance : NormedCommRing ℤ_[p] := { PadicInt.instCommRing with dist_eq := fun ⟨_, _⟩ ⟨_, _⟩ => rfl norm_mul := by simp [norm_def] norm := norm } instance : NormOneClass ℤ_[p] := ⟨norm_def.trans norm_one⟩ instance isAbsoluteValue : IsAbsoluteValue fun z : ℤ_[p] => ‖z‖ where abv_nonneg' := norm_nonneg abv_eq_zero' := by simp [norm_eq_zero] abv_add' := fun ⟨_, _⟩ ⟨_, _⟩ => norm_add_le _ _ abv_mul' _ _ := by simp only [norm_def, padicNormE.mul, PadicInt.coe_mul] #align padic_int.is_absolute_value PadicInt.isAbsoluteValue variable {p} instance : IsDomain ℤ_[p] := Function.Injective.isDomain (subring p).subtype Subtype.coe_injective end PadicInt namespace PadicInt /-! ### Norm -/ variable {p : ℕ} [Fact p.Prime] theorem norm_le_one (z : ℤ_[p]) : ‖z‖ ≤ 1 := z.2 #align padic_int.norm_le_one PadicInt.norm_le_one @[simp]
Mathlib/NumberTheory/Padics/PadicIntegers.lean
273
273
theorem norm_mul (z1 z2 : ℤ_[p]) : ‖z1 * z2‖ = ‖z1‖ * ‖z2‖ := by
simp [norm_def]
/- Copyright (c) 2021 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Analysis.MeanInequalities import Mathlib.Analysis.MeanInequalitiesPow import Mathlib.Analysis.SpecialFunctions.Pow.Continuity import Mathlib.Data.Set.Image import Mathlib.Topology.Algebra.Order.LiminfLimsup #align_import analysis.normed_space.lp_space from "leanprover-community/mathlib"@"de83b43717abe353f425855fcf0cedf9ea0fe8a4" /-! # ℓp space This file describes properties of elements `f` of a pi-type `∀ i, E i` with finite "norm", defined for `p : ℝ≥0∞` as the size of the support of `f` if `p=0`, `(∑' a, ‖f a‖^p) ^ (1/p)` for `0 < p < ∞` and `⨆ a, ‖f a‖` for `p=∞`. The Prop-valued `Memℓp f p` states that a function `f : ∀ i, E i` has finite norm according to the above definition; that is, `f` has finite support if `p = 0`, `Summable (fun a ↦ ‖f a‖^p)` if `0 < p < ∞`, and `BddAbove (norm '' (Set.range f))` if `p = ∞`. The space `lp E p` is the subtype of elements of `∀ i : α, E i` which satisfy `Memℓp f p`. For `1 ≤ p`, the "norm" is genuinely a norm and `lp` is a complete metric space. ## Main definitions * `Memℓp f p` : property that the function `f` satisfies, as appropriate, `f` finitely supported if `p = 0`, `Summable (fun a ↦ ‖f a‖^p)` if `0 < p < ∞`, and `BddAbove (norm '' (Set.range f))` if `p = ∞`. * `lp E p` : elements of `∀ i : α, E i` such that `Memℓp f p`. Defined as an `AddSubgroup` of a type synonym `PreLp` for `∀ i : α, E i`, and equipped with a `NormedAddCommGroup` structure. Under appropriate conditions, this is also equipped with the instances `lp.normedSpace`, `lp.completeSpace`. For `p=∞`, there is also `lp.inftyNormedRing`, `lp.inftyNormedAlgebra`, `lp.inftyStarRing` and `lp.inftyCstarRing`. ## Main results * `Memℓp.of_exponent_ge`: For `q ≤ p`, a function which is `Memℓp` for `q` is also `Memℓp` for `p`. * `lp.memℓp_of_tendsto`, `lp.norm_le_of_tendsto`: A pointwise limit of functions in `lp`, all with `lp` norm `≤ C`, is itself in `lp` and has `lp` norm `≤ C`. * `lp.tsum_mul_le_mul_norm`: basic form of Hölder's inequality ## Implementation Since `lp` is defined as an `AddSubgroup`, dot notation does not work. Use `lp.norm_neg f` to say that `‖-f‖ = ‖f‖`, instead of the non-working `f.norm_neg`. ## TODO * More versions of Hölder's inequality (for example: the case `p = 1`, `q = ∞`; a version for normed rings which has `‖∑' i, f i * g i‖` rather than `∑' i, ‖f i‖ * g i‖` on the RHS; a version for three exponents satisfying `1 / r = 1 / p + 1 / q`) -/ noncomputable section open scoped NNReal ENNReal Function variable {α : Type*} {E : α → Type*} {p q : ℝ≥0∞} [∀ i, NormedAddCommGroup (E i)] /-! ### `Memℓp` predicate -/ /-- The property that `f : ∀ i : α, E i` * is finitely supported, if `p = 0`, or * admits an upper bound for `Set.range (fun i ↦ ‖f i‖)`, if `p = ∞`, or * has the series `∑' i, ‖f i‖ ^ p` be summable, if `0 < p < ∞`. -/ def Memℓp (f : ∀ i, E i) (p : ℝ≥0∞) : Prop := if p = 0 then Set.Finite { i | f i ≠ 0 } else if p = ∞ then BddAbove (Set.range fun i => ‖f i‖) else Summable fun i => ‖f i‖ ^ p.toReal #align mem_ℓp Memℓp theorem memℓp_zero_iff {f : ∀ i, E i} : Memℓp f 0 ↔ Set.Finite { i | f i ≠ 0 } := by dsimp [Memℓp] rw [if_pos rfl] #align mem_ℓp_zero_iff memℓp_zero_iff theorem memℓp_zero {f : ∀ i, E i} (hf : Set.Finite { i | f i ≠ 0 }) : Memℓp f 0 := memℓp_zero_iff.2 hf #align mem_ℓp_zero memℓp_zero theorem memℓp_infty_iff {f : ∀ i, E i} : Memℓp f ∞ ↔ BddAbove (Set.range fun i => ‖f i‖) := by dsimp [Memℓp] rw [if_neg ENNReal.top_ne_zero, if_pos rfl] #align mem_ℓp_infty_iff memℓp_infty_iff theorem memℓp_infty {f : ∀ i, E i} (hf : BddAbove (Set.range fun i => ‖f i‖)) : Memℓp f ∞ := memℓp_infty_iff.2 hf #align mem_ℓp_infty memℓp_infty theorem memℓp_gen_iff (hp : 0 < p.toReal) {f : ∀ i, E i} : Memℓp f p ↔ Summable fun i => ‖f i‖ ^ p.toReal := by rw [ENNReal.toReal_pos_iff] at hp dsimp [Memℓp] rw [if_neg hp.1.ne', if_neg hp.2.ne] #align mem_ℓp_gen_iff memℓp_gen_iff theorem memℓp_gen {f : ∀ i, E i} (hf : Summable fun i => ‖f i‖ ^ p.toReal) : Memℓp f p := by rcases p.trichotomy with (rfl | rfl | hp) · apply memℓp_zero have H : Summable fun _ : α => (1 : ℝ) := by simpa using hf exact (Set.Finite.of_summable_const (by norm_num) H).subset (Set.subset_univ _) · apply memℓp_infty have H : Summable fun _ : α => (1 : ℝ) := by simpa using hf simpa using ((Set.Finite.of_summable_const (by norm_num) H).image fun i => ‖f i‖).bddAbove exact (memℓp_gen_iff hp).2 hf #align mem_ℓp_gen memℓp_gen theorem memℓp_gen' {C : ℝ} {f : ∀ i, E i} (hf : ∀ s : Finset α, ∑ i ∈ s, ‖f i‖ ^ p.toReal ≤ C) : Memℓp f p := by apply memℓp_gen use ⨆ s : Finset α, ∑ i ∈ s, ‖f i‖ ^ p.toReal apply hasSum_of_isLUB_of_nonneg · intro b exact Real.rpow_nonneg (norm_nonneg _) _ apply isLUB_ciSup use C rintro - ⟨s, rfl⟩ exact hf s #align mem_ℓp_gen' memℓp_gen' theorem zero_memℓp : Memℓp (0 : ∀ i, E i) p := by rcases p.trichotomy with (rfl | rfl | hp) · apply memℓp_zero simp · apply memℓp_infty simp only [norm_zero, Pi.zero_apply] exact bddAbove_singleton.mono Set.range_const_subset · apply memℓp_gen simp [Real.zero_rpow hp.ne', summable_zero] #align zero_mem_ℓp zero_memℓp theorem zero_mem_ℓp' : Memℓp (fun i : α => (0 : E i)) p := zero_memℓp #align zero_mem_ℓp' zero_mem_ℓp' namespace Memℓp theorem finite_dsupport {f : ∀ i, E i} (hf : Memℓp f 0) : Set.Finite { i | f i ≠ 0 } := memℓp_zero_iff.1 hf #align mem_ℓp.finite_dsupport Memℓp.finite_dsupport theorem bddAbove {f : ∀ i, E i} (hf : Memℓp f ∞) : BddAbove (Set.range fun i => ‖f i‖) := memℓp_infty_iff.1 hf #align mem_ℓp.bdd_above Memℓp.bddAbove theorem summable (hp : 0 < p.toReal) {f : ∀ i, E i} (hf : Memℓp f p) : Summable fun i => ‖f i‖ ^ p.toReal := (memℓp_gen_iff hp).1 hf #align mem_ℓp.summable Memℓp.summable theorem neg {f : ∀ i, E i} (hf : Memℓp f p) : Memℓp (-f) p := by rcases p.trichotomy with (rfl | rfl | hp) · apply memℓp_zero simp [hf.finite_dsupport] · apply memℓp_infty simpa using hf.bddAbove · apply memℓp_gen simpa using hf.summable hp #align mem_ℓp.neg Memℓp.neg @[simp] theorem neg_iff {f : ∀ i, E i} : Memℓp (-f) p ↔ Memℓp f p := ⟨fun h => neg_neg f ▸ h.neg, Memℓp.neg⟩ #align mem_ℓp.neg_iff Memℓp.neg_iff theorem of_exponent_ge {p q : ℝ≥0∞} {f : ∀ i, E i} (hfq : Memℓp f q) (hpq : q ≤ p) : Memℓp f p := by rcases ENNReal.trichotomy₂ hpq with (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ | ⟨rfl, hp⟩ | ⟨rfl, rfl⟩ | ⟨hq, rfl⟩ | ⟨hq, _, hpq'⟩) · exact hfq · apply memℓp_infty obtain ⟨C, hC⟩ := (hfq.finite_dsupport.image fun i => ‖f i‖).bddAbove use max 0 C rintro x ⟨i, rfl⟩ by_cases hi : f i = 0 · simp [hi] · exact (hC ⟨i, hi, rfl⟩).trans (le_max_right _ _) · apply memℓp_gen have : ∀ i ∉ hfq.finite_dsupport.toFinset, ‖f i‖ ^ p.toReal = 0 := by intro i hi have : f i = 0 := by simpa using hi simp [this, Real.zero_rpow hp.ne'] exact summable_of_ne_finset_zero this · exact hfq · apply memℓp_infty obtain ⟨A, hA⟩ := (hfq.summable hq).tendsto_cofinite_zero.bddAbove_range_of_cofinite use A ^ q.toReal⁻¹ rintro x ⟨i, rfl⟩ have : 0 ≤ ‖f i‖ ^ q.toReal := by positivity simpa [← Real.rpow_mul, mul_inv_cancel hq.ne'] using Real.rpow_le_rpow this (hA ⟨i, rfl⟩) (inv_nonneg.mpr hq.le) · apply memℓp_gen have hf' := hfq.summable hq refine .of_norm_bounded_eventually _ hf' (@Set.Finite.subset _ { i | 1 ≤ ‖f i‖ } ?_ _ ?_) · have H : { x : α | 1 ≤ ‖f x‖ ^ q.toReal }.Finite := by simpa using eventually_lt_of_tendsto_lt (by norm_num) hf'.tendsto_cofinite_zero exact H.subset fun i hi => Real.one_le_rpow hi hq.le · show ∀ i, ¬|‖f i‖ ^ p.toReal| ≤ ‖f i‖ ^ q.toReal → 1 ≤ ‖f i‖ intro i hi have : 0 ≤ ‖f i‖ ^ p.toReal := Real.rpow_nonneg (norm_nonneg _) p.toReal simp only [abs_of_nonneg, this] at hi contrapose! hi exact Real.rpow_le_rpow_of_exponent_ge' (norm_nonneg _) hi.le hq.le hpq' #align mem_ℓp.of_exponent_ge Memℓp.of_exponent_ge theorem add {f g : ∀ i, E i} (hf : Memℓp f p) (hg : Memℓp g p) : Memℓp (f + g) p := by rcases p.trichotomy with (rfl | rfl | hp) · apply memℓp_zero refine (hf.finite_dsupport.union hg.finite_dsupport).subset fun i => ?_ simp only [Pi.add_apply, Ne, Set.mem_union, Set.mem_setOf_eq] contrapose! rintro ⟨hf', hg'⟩ simp [hf', hg'] · apply memℓp_infty obtain ⟨A, hA⟩ := hf.bddAbove obtain ⟨B, hB⟩ := hg.bddAbove refine ⟨A + B, ?_⟩ rintro a ⟨i, rfl⟩ exact le_trans (norm_add_le _ _) (add_le_add (hA ⟨i, rfl⟩) (hB ⟨i, rfl⟩)) apply memℓp_gen let C : ℝ := if p.toReal < 1 then 1 else (2 : ℝ) ^ (p.toReal - 1) refine .of_nonneg_of_le ?_ (fun i => ?_) (((hf.summable hp).add (hg.summable hp)).mul_left C) · intro; positivity · refine (Real.rpow_le_rpow (norm_nonneg _) (norm_add_le _ _) hp.le).trans ?_ dsimp only [C] split_ifs with h · simpa using NNReal.coe_le_coe.2 (NNReal.rpow_add_le_add_rpow ‖f i‖₊ ‖g i‖₊ hp.le h.le) · let F : Fin 2 → ℝ≥0 := ![‖f i‖₊, ‖g i‖₊] simp only [not_lt] at h simpa [Fin.sum_univ_succ] using Real.rpow_sum_le_const_mul_sum_rpow_of_nonneg Finset.univ h fun i _ => (F i).coe_nonneg #align mem_ℓp.add Memℓp.add theorem sub {f g : ∀ i, E i} (hf : Memℓp f p) (hg : Memℓp g p) : Memℓp (f - g) p := by rw [sub_eq_add_neg]; exact hf.add hg.neg #align mem_ℓp.sub Memℓp.sub theorem finset_sum {ι} (s : Finset ι) {f : ι → ∀ i, E i} (hf : ∀ i ∈ s, Memℓp (f i) p) : Memℓp (fun a => ∑ i ∈ s, f i a) p := by haveI : DecidableEq ι := Classical.decEq _ revert hf refine Finset.induction_on s ?_ ?_ · simp only [zero_mem_ℓp', Finset.sum_empty, imp_true_iff] · intro i s his ih hf simp only [his, Finset.sum_insert, not_false_iff] exact (hf i (s.mem_insert_self i)).add (ih fun j hj => hf j (Finset.mem_insert_of_mem hj)) #align mem_ℓp.finset_sum Memℓp.finset_sum section BoundedSMul variable {𝕜 : Type*} [NormedRing 𝕜] [∀ i, Module 𝕜 (E i)] [∀ i, BoundedSMul 𝕜 (E i)] theorem const_smul {f : ∀ i, E i} (hf : Memℓp f p) (c : 𝕜) : Memℓp (c • f) p := by rcases p.trichotomy with (rfl | rfl | hp) · apply memℓp_zero refine hf.finite_dsupport.subset fun i => (?_ : ¬c • f i = 0 → ¬f i = 0) exact not_imp_not.mpr fun hf' => hf'.symm ▸ smul_zero c · obtain ⟨A, hA⟩ := hf.bddAbove refine memℓp_infty ⟨‖c‖ * A, ?_⟩ rintro a ⟨i, rfl⟩ dsimp only [Pi.smul_apply] refine (norm_smul_le _ _).trans ?_ gcongr exact hA ⟨i, rfl⟩ · apply memℓp_gen dsimp only [Pi.smul_apply] have := (hf.summable hp).mul_left (↑(‖c‖₊ ^ p.toReal) : ℝ) simp_rw [← coe_nnnorm, ← NNReal.coe_rpow, ← NNReal.coe_mul, NNReal.summable_coe, ← NNReal.mul_rpow] at this ⊢ refine NNReal.summable_of_le ?_ this intro i gcongr apply nnnorm_smul_le #align mem_ℓp.const_smul Memℓp.const_smul theorem const_mul {f : α → 𝕜} (hf : Memℓp f p) (c : 𝕜) : Memℓp (fun x => c * f x) p := @Memℓp.const_smul α (fun _ => 𝕜) _ _ 𝕜 _ _ (fun i => by infer_instance) _ hf c #align mem_ℓp.const_mul Memℓp.const_mul end BoundedSMul end Memℓp /-! ### lp space The space of elements of `∀ i, E i` satisfying the predicate `Memℓp`. -/ /-- We define `PreLp E` to be a type synonym for `∀ i, E i` which, importantly, does not inherit the `pi` topology on `∀ i, E i` (otherwise this topology would descend to `lp E p` and conflict with the normed group topology we will later equip it with.) We choose to deal with this issue by making a type synonym for `∀ i, E i` rather than for the `lp` subgroup itself, because this allows all the spaces `lp E p` (for varying `p`) to be subgroups of the same ambient group, which permits lemma statements like `lp.monotone` (below). -/ @[nolint unusedArguments] def PreLp (E : α → Type*) [∀ i, NormedAddCommGroup (E i)] : Type _ := ∀ i, E i --deriving AddCommGroup #align pre_lp PreLp instance : AddCommGroup (PreLp E) := by unfold PreLp; infer_instance instance PreLp.unique [IsEmpty α] : Unique (PreLp E) := Pi.uniqueOfIsEmpty E #align pre_lp.unique PreLp.unique /-- lp space -/ def lp (E : α → Type*) [∀ i, NormedAddCommGroup (E i)] (p : ℝ≥0∞) : AddSubgroup (PreLp E) where carrier := { f | Memℓp f p } zero_mem' := zero_memℓp add_mem' := Memℓp.add neg_mem' := Memℓp.neg #align lp lp @[inherit_doc] scoped[lp] notation "ℓ^∞(" ι ", " E ")" => lp (fun i : ι => E) ∞ @[inherit_doc] scoped[lp] notation "ℓ^∞(" ι ")" => lp (fun i : ι => ℝ) ∞ namespace lp -- Porting note: was `Coe` instance : CoeOut (lp E p) (∀ i, E i) := ⟨Subtype.val (α := ∀ i, E i)⟩ -- Porting note: Originally `coeSubtype` instance coeFun : CoeFun (lp E p) fun _ => ∀ i, E i := ⟨fun f => (f : ∀ i, E i)⟩ @[ext] theorem ext {f g : lp E p} (h : (f : ∀ i, E i) = g) : f = g := Subtype.ext h #align lp.ext lp.ext protected theorem ext_iff {f g : lp E p} : f = g ↔ (f : ∀ i, E i) = g := Subtype.ext_iff #align lp.ext_iff lp.ext_iff theorem eq_zero' [IsEmpty α] (f : lp E p) : f = 0 := Subsingleton.elim f 0 #align lp.eq_zero' lp.eq_zero' protected theorem monotone {p q : ℝ≥0∞} (hpq : q ≤ p) : lp E q ≤ lp E p := fun _ hf => Memℓp.of_exponent_ge hf hpq #align lp.monotone lp.monotone protected theorem memℓp (f : lp E p) : Memℓp f p := f.prop #align lp.mem_ℓp lp.memℓp variable (E p) @[simp] theorem coeFn_zero : ⇑(0 : lp E p) = 0 := rfl #align lp.coe_fn_zero lp.coeFn_zero variable {E p} @[simp] theorem coeFn_neg (f : lp E p) : ⇑(-f) = -f := rfl #align lp.coe_fn_neg lp.coeFn_neg @[simp] theorem coeFn_add (f g : lp E p) : ⇑(f + g) = f + g := rfl #align lp.coe_fn_add lp.coeFn_add -- porting note (#10618): removed `@[simp]` because `simp` can prove this
Mathlib/Analysis/NormedSpace/lpSpace.lean
378
380
theorem coeFn_sum {ι : Type*} (f : ι → lp E p) (s : Finset ι) : ⇑(∑ i ∈ s, f i) = ∑ i ∈ s, ⇑(f i) := by
simp
/- Copyright (c) 2020 Yury Kudryashov, Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Anne Baanen -/ import Mathlib.Algebra.BigOperators.Ring import Mathlib.Data.Fintype.BigOperators import Mathlib.Data.Fintype.Fin import Mathlib.GroupTheory.GroupAction.Pi import Mathlib.Logic.Equiv.Fin #align_import algebra.big_operators.fin from "leanprover-community/mathlib"@"cc5dd6244981976cc9da7afc4eee5682b037a013" /-! # Big operators and `Fin` Some results about products and sums over the type `Fin`. The most important results are the induction formulas `Fin.prod_univ_castSucc` and `Fin.prod_univ_succ`, and the formula `Fin.prod_const` for the product of a constant function. These results have variants for sums instead of products. ## Main declarations * `finFunctionFinEquiv`: An explicit equivalence between `Fin n → Fin m` and `Fin (m ^ n)`. -/ open Finset variable {α : Type*} {β : Type*} namespace Finset @[to_additive] theorem prod_range [CommMonoid β] {n : ℕ} (f : ℕ → β) : ∏ i ∈ Finset.range n, f i = ∏ i : Fin n, f i := (Fin.prod_univ_eq_prod_range _ _).symm #align finset.prod_range Finset.prod_range #align finset.sum_range Finset.sum_range end Finset namespace Fin @[to_additive] theorem prod_ofFn [CommMonoid β] {n : ℕ} (f : Fin n → β) : (List.ofFn f).prod = ∏ i, f i := by simp [prod_eq_multiset_prod] #align fin.prod_of_fn Fin.prod_ofFn #align fin.sum_of_fn Fin.sum_ofFn @[to_additive] theorem prod_univ_def [CommMonoid β] {n : ℕ} (f : Fin n → β) : ∏ i, f i = ((List.finRange n).map f).prod := by rw [← List.ofFn_eq_map, prod_ofFn] #align fin.prod_univ_def Fin.prod_univ_def #align fin.sum_univ_def Fin.sum_univ_def /-- A product of a function `f : Fin 0 → β` is `1` because `Fin 0` is empty -/ @[to_additive "A sum of a function `f : Fin 0 → β` is `0` because `Fin 0` is empty"] theorem prod_univ_zero [CommMonoid β] (f : Fin 0 → β) : ∏ i, f i = 1 := rfl #align fin.prod_univ_zero Fin.prod_univ_zero #align fin.sum_univ_zero Fin.sum_univ_zero /-- A product of a function `f : Fin (n + 1) → β` over all `Fin (n + 1)` is the product of `f x`, for some `x : Fin (n + 1)` times the remaining product -/ @[to_additive "A sum of a function `f : Fin (n + 1) → β` over all `Fin (n + 1)` is the sum of `f x`, for some `x : Fin (n + 1)` plus the remaining product"] theorem prod_univ_succAbove [CommMonoid β] {n : ℕ} (f : Fin (n + 1) → β) (x : Fin (n + 1)) : ∏ i, f i = f x * ∏ i : Fin n, f (x.succAbove i) := by rw [univ_succAbove, prod_cons, Finset.prod_map _ x.succAboveEmb] rfl #align fin.prod_univ_succ_above Fin.prod_univ_succAbove #align fin.sum_univ_succ_above Fin.sum_univ_succAbove /-- A product of a function `f : Fin (n + 1) → β` over all `Fin (n + 1)` is the product of `f 0` plus the remaining product -/ @[to_additive "A sum of a function `f : Fin (n + 1) → β` over all `Fin (n + 1)` is the sum of `f 0` plus the remaining product"] theorem prod_univ_succ [CommMonoid β] {n : ℕ} (f : Fin (n + 1) → β) : ∏ i, f i = f 0 * ∏ i : Fin n, f i.succ := prod_univ_succAbove f 0 #align fin.prod_univ_succ Fin.prod_univ_succ #align fin.sum_univ_succ Fin.sum_univ_succ /-- A product of a function `f : Fin (n + 1) → β` over all `Fin (n + 1)` is the product of `f (Fin.last n)` plus the remaining product -/ @[to_additive "A sum of a function `f : Fin (n + 1) → β` over all `Fin (n + 1)` is the sum of `f (Fin.last n)` plus the remaining sum"] theorem prod_univ_castSucc [CommMonoid β] {n : ℕ} (f : Fin (n + 1) → β) : ∏ i, f i = (∏ i : Fin n, f (Fin.castSucc i)) * f (last n) := by simpa [mul_comm] using prod_univ_succAbove f (last n) #align fin.prod_univ_cast_succ Fin.prod_univ_castSucc #align fin.sum_univ_cast_succ Fin.sum_univ_castSucc @[to_additive (attr := simp)] theorem prod_univ_get [CommMonoid α] (l : List α) : ∏ i, l.get i = l.prod := by simp [Finset.prod_eq_multiset_prod] @[to_additive (attr := simp)] theorem prod_univ_get' [CommMonoid β] (l : List α) (f : α → β) : ∏ i, f (l.get i) = (l.map f).prod := by simp [Finset.prod_eq_multiset_prod] @[to_additive] theorem prod_cons [CommMonoid β] {n : ℕ} (x : β) (f : Fin n → β) : (∏ i : Fin n.succ, (cons x f : Fin n.succ → β) i) = x * ∏ i : Fin n, f i := by simp_rw [prod_univ_succ, cons_zero, cons_succ] #align fin.prod_cons Fin.prod_cons #align fin.sum_cons Fin.sum_cons @[to_additive sum_univ_one] theorem prod_univ_one [CommMonoid β] (f : Fin 1 → β) : ∏ i, f i = f 0 := by simp #align fin.prod_univ_one Fin.prod_univ_one #align fin.sum_univ_one Fin.sum_univ_one @[to_additive (attr := simp)] theorem prod_univ_two [CommMonoid β] (f : Fin 2 → β) : ∏ i, f i = f 0 * f 1 := by simp [prod_univ_succ] #align fin.prod_univ_two Fin.prod_univ_two #align fin.sum_univ_two Fin.sum_univ_two @[to_additive] theorem prod_univ_two' [CommMonoid β] (f : α → β) (a b : α) : ∏ i, f (![a, b] i) = f a * f b := prod_univ_two _ @[to_additive] theorem prod_univ_three [CommMonoid β] (f : Fin 3 → β) : ∏ i, f i = f 0 * f 1 * f 2 := by rw [prod_univ_castSucc, prod_univ_two] rfl #align fin.prod_univ_three Fin.prod_univ_three #align fin.sum_univ_three Fin.sum_univ_three @[to_additive] theorem prod_univ_four [CommMonoid β] (f : Fin 4 → β) : ∏ i, f i = f 0 * f 1 * f 2 * f 3 := by rw [prod_univ_castSucc, prod_univ_three] rfl #align fin.prod_univ_four Fin.prod_univ_four #align fin.sum_univ_four Fin.sum_univ_four @[to_additive] theorem prod_univ_five [CommMonoid β] (f : Fin 5 → β) : ∏ i, f i = f 0 * f 1 * f 2 * f 3 * f 4 := by rw [prod_univ_castSucc, prod_univ_four] rfl #align fin.prod_univ_five Fin.prod_univ_five #align fin.sum_univ_five Fin.sum_univ_five @[to_additive] theorem prod_univ_six [CommMonoid β] (f : Fin 6 → β) : ∏ i, f i = f 0 * f 1 * f 2 * f 3 * f 4 * f 5 := by rw [prod_univ_castSucc, prod_univ_five] rfl #align fin.prod_univ_six Fin.prod_univ_six #align fin.sum_univ_six Fin.sum_univ_six @[to_additive] theorem prod_univ_seven [CommMonoid β] (f : Fin 7 → β) : ∏ i, f i = f 0 * f 1 * f 2 * f 3 * f 4 * f 5 * f 6 := by rw [prod_univ_castSucc, prod_univ_six] rfl #align fin.prod_univ_seven Fin.prod_univ_seven #align fin.sum_univ_seven Fin.sum_univ_seven @[to_additive] theorem prod_univ_eight [CommMonoid β] (f : Fin 8 → β) : ∏ i, f i = f 0 * f 1 * f 2 * f 3 * f 4 * f 5 * f 6 * f 7 := by rw [prod_univ_castSucc, prod_univ_seven] rfl #align fin.prod_univ_eight Fin.prod_univ_eight #align fin.sum_univ_eight Fin.sum_univ_eight theorem sum_pow_mul_eq_add_pow {n : ℕ} {R : Type*} [CommSemiring R] (a b : R) : (∑ s : Finset (Fin n), a ^ s.card * b ^ (n - s.card)) = (a + b) ^ n := by simpa using Fintype.sum_pow_mul_eq_add_pow (Fin n) a b #align fin.sum_pow_mul_eq_add_pow Fin.sum_pow_mul_eq_add_pow theorem prod_const [CommMonoid α] (n : ℕ) (x : α) : ∏ _i : Fin n, x = x ^ n := by simp #align fin.prod_const Fin.prod_const theorem sum_const [AddCommMonoid α] (n : ℕ) (x : α) : ∑ _i : Fin n, x = n • x := by simp #align fin.sum_const Fin.sum_const @[to_additive]
Mathlib/Algebra/BigOperators/Fin.lean
186
188
theorem prod_Ioi_zero {M : Type*} [CommMonoid M] {n : ℕ} {v : Fin n.succ → M} : ∏ i ∈ Ioi 0, v i = ∏ j : Fin n, v j.succ := by
rw [Ioi_zero_eq_map, Finset.prod_map, val_succEmb]
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.Topology.Category.TopCat.Opens import Mathlib.Data.Set.Subsingleton #align_import topology.category.Top.open_nhds from "leanprover-community/mathlib"@"1ec4876214bf9f1ddfbf97ae4b0d777ebd5d6938" /-! # The category of open neighborhoods of a point Given an object `X` of the category `TopCat` of topological spaces and a point `x : X`, this file builds the type `OpenNhds x` of open neighborhoods of `x` in `X` and endows it with the partial order given by inclusion and the corresponding category structure (as a full subcategory of the poset category `Set X`). This is used in `Topology.Sheaves.Stalks` to build the stalk of a sheaf at `x` as a limit over `OpenNhds x`. ## Main declarations Besides `OpenNhds`, the main constructions here are: * `inclusion (x : X)`: the obvious functor `OpenNhds x ⥤ Opens X` * `functorNhds`: An open map `f : X ⟶ Y` induces a functor `OpenNhds x ⥤ OpenNhds (f x)` * `adjunctionNhds`: An open map `f : X ⟶ Y` induces an adjunction between `OpenNhds x` and `OpenNhds (f x)`. -/ open CategoryTheory TopologicalSpace Opposite universe u variable {X Y : TopCat.{u}} (f : X ⟶ Y) namespace TopologicalSpace /-- The type of open neighbourhoods of a point `x` in a (bundled) topological space. -/ def OpenNhds (x : X) := FullSubcategory fun U : Opens X => x ∈ U #align topological_space.open_nhds TopologicalSpace.OpenNhds namespace OpenNhds instance partialOrder (x : X) : PartialOrder (OpenNhds x) where le U V := U.1 ≤ V.1 le_refl _ := by dsimp [LE.le]; exact le_rfl le_trans _ _ _ := by dsimp [LE.le]; exact le_trans le_antisymm _ _ i j := FullSubcategory.ext _ _ <| le_antisymm i j instance (x : X) : Lattice (OpenNhds x) := { OpenNhds.partialOrder x with inf := fun U V => ⟨U.1 ⊓ V.1, ⟨U.2, V.2⟩⟩ le_inf := fun U V W => @le_inf _ _ U.1.1 V.1.1 W.1.1 inf_le_left := fun U V => @inf_le_left _ _ U.1.1 V.1.1 inf_le_right := fun U V => @inf_le_right _ _ U.1.1 V.1.1 sup := fun U V => ⟨U.1 ⊔ V.1, Set.mem_union_left V.1.1 U.2⟩ sup_le := fun U V W => @sup_le _ _ U.1.1 V.1.1 W.1.1 le_sup_left := fun U V => @le_sup_left _ _ U.1.1 V.1.1 le_sup_right := fun U V => @le_sup_right _ _ U.1.1 V.1.1 } instance (x : X) : OrderTop (OpenNhds x) where top := ⟨⊤, trivial⟩ le_top _ := by dsimp [LE.le]; exact le_top instance (x : X) : Inhabited (OpenNhds x) := ⟨⊤⟩ instance openNhdsCategory (x : X) : Category.{u} (OpenNhds x) := inferInstance #align topological_space.open_nhds.open_nhds_category TopologicalSpace.OpenNhds.openNhdsCategory instance opensNhdsHomHasCoeToFun {x : X} {U V : OpenNhds x} : CoeFun (U ⟶ V) fun _ => U.1 → V.1 := ⟨fun f x => ⟨x, f.le x.2⟩⟩ #align topological_space.open_nhds.opens_nhds_hom_has_coe_to_fun TopologicalSpace.OpenNhds.opensNhdsHomHasCoeToFun /-- The inclusion `U ⊓ V ⟶ U` as a morphism in the category of open sets. -/ def infLELeft {x : X} (U V : OpenNhds x) : U ⊓ V ⟶ U := homOfLE inf_le_left #align topological_space.open_nhds.inf_le_left TopologicalSpace.OpenNhds.infLELeft /-- The inclusion `U ⊓ V ⟶ V` as a morphism in the category of open sets. -/ def infLERight {x : X} (U V : OpenNhds x) : U ⊓ V ⟶ V := homOfLE inf_le_right #align topological_space.open_nhds.inf_le_right TopologicalSpace.OpenNhds.infLERight /-- The inclusion functor from open neighbourhoods of `x` to open sets in the ambient topological space. -/ def inclusion (x : X) : OpenNhds x ⥤ Opens X := fullSubcategoryInclusion _ #align topological_space.open_nhds.inclusion TopologicalSpace.OpenNhds.inclusion @[simp] theorem inclusion_obj (x : X) (U) (p) : (inclusion x).obj ⟨U, p⟩ = U := rfl #align topological_space.open_nhds.inclusion_obj TopologicalSpace.OpenNhds.inclusion_obj theorem openEmbedding {x : X} (U : OpenNhds x) : OpenEmbedding U.1.inclusion := U.1.openEmbedding #align topological_space.open_nhds.open_embedding TopologicalSpace.OpenNhds.openEmbedding /-- The preimage functor from neighborhoods of `f x` to neighborhoods of `x`. -/ def map (x : X) : OpenNhds (f x) ⥤ OpenNhds x where obj U := ⟨(Opens.map f).obj U.1, U.2⟩ map i := (Opens.map f).map i #align topological_space.open_nhds.map TopologicalSpace.OpenNhds.map -- Porting note: Changed `⟨(Opens.map f).obj U, by tidy⟩` to `⟨(Opens.map f).obj U, q⟩` @[simp] theorem map_obj (x : X) (U) (q) : (map f x).obj ⟨U, q⟩ = ⟨(Opens.map f).obj U, q⟩ := rfl #align topological_space.open_nhds.map_obj TopologicalSpace.OpenNhds.map_obj @[simp] theorem map_id_obj (x : X) (U) : (map (𝟙 X) x).obj U = U := rfl #align topological_space.open_nhds.map_id_obj TopologicalSpace.OpenNhds.map_id_obj @[simp] theorem map_id_obj' (x : X) (U) (p) (q) : (map (𝟙 X) x).obj ⟨⟨U, p⟩, q⟩ = ⟨⟨U, p⟩, q⟩ := rfl #align topological_space.open_nhds.map_id_obj' TopologicalSpace.OpenNhds.map_id_obj' @[simp]
Mathlib/Topology/Category/TopCat/OpenNhds.lean
124
125
theorem map_id_obj_unop (x : X) (U : (OpenNhds x)ᵒᵖ) : (map (𝟙 X) x).obj (unop U) = unop U := by
simp
/- Copyright (c) 2022 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Probability.Variance #align_import probability.moments from "leanprover-community/mathlib"@"85453a2a14be8da64caf15ca50930cf4c6e5d8de" /-! # Moments and moment generating function ## Main definitions * `ProbabilityTheory.moment X p μ`: `p`th moment of a real random variable `X` with respect to measure `μ`, `μ[X^p]` * `ProbabilityTheory.centralMoment X p μ`:`p`th central moment of `X` with respect to measure `μ`, `μ[(X - μ[X])^p]` * `ProbabilityTheory.mgf X μ t`: moment generating function of `X` with respect to measure `μ`, `μ[exp(t*X)]` * `ProbabilityTheory.cgf X μ t`: cumulant generating function, logarithm of the moment generating function ## Main results * `ProbabilityTheory.IndepFun.mgf_add`: if two real random variables `X` and `Y` are independent and their mgfs are defined at `t`, then `mgf (X + Y) μ t = mgf X μ t * mgf Y μ t` * `ProbabilityTheory.IndepFun.cgf_add`: if two real random variables `X` and `Y` are independent and their cgfs are defined at `t`, then `cgf (X + Y) μ t = cgf X μ t + cgf Y μ t` * `ProbabilityTheory.measure_ge_le_exp_cgf` and `ProbabilityTheory.measure_le_le_exp_cgf`: Chernoff bound on the upper (resp. lower) tail of a random variable. For `t` nonnegative such that the cgf exists, `ℙ(ε ≤ X) ≤ exp(- t*ε + cgf X ℙ t)`. See also `ProbabilityTheory.measure_ge_le_exp_mul_mgf` and `ProbabilityTheory.measure_le_le_exp_mul_mgf` for versions of these results using `mgf` instead of `cgf`. -/ open MeasureTheory Filter Finset Real noncomputable section open scoped MeasureTheory ProbabilityTheory ENNReal NNReal namespace ProbabilityTheory variable {Ω ι : Type*} {m : MeasurableSpace Ω} {X : Ω → ℝ} {p : ℕ} {μ : Measure Ω} /-- Moment of a real random variable, `μ[X ^ p]`. -/ def moment (X : Ω → ℝ) (p : ℕ) (μ : Measure Ω) : ℝ := μ[X ^ p] #align probability_theory.moment ProbabilityTheory.moment /-- Central moment of a real random variable, `μ[(X - μ[X]) ^ p]`. -/ def centralMoment (X : Ω → ℝ) (p : ℕ) (μ : Measure Ω) : ℝ := by have m := fun (x : Ω) => μ[X] -- Porting note: Lean deems `μ[(X - fun x => μ[X]) ^ p]` ambiguous exact μ[(X - m) ^ p] #align probability_theory.central_moment ProbabilityTheory.centralMoment @[simp] theorem moment_zero (hp : p ≠ 0) : moment 0 p μ = 0 := by simp only [moment, hp, zero_pow, Ne, not_false_iff, Pi.zero_apply, integral_const, smul_eq_mul, mul_zero, integral_zero] #align probability_theory.moment_zero ProbabilityTheory.moment_zero @[simp] theorem centralMoment_zero (hp : p ≠ 0) : centralMoment 0 p μ = 0 := by simp only [centralMoment, hp, Pi.zero_apply, integral_const, smul_eq_mul, mul_zero, zero_sub, Pi.pow_apply, Pi.neg_apply, neg_zero, zero_pow, Ne, not_false_iff] #align probability_theory.central_moment_zero ProbabilityTheory.centralMoment_zero theorem centralMoment_one' [IsFiniteMeasure μ] (h_int : Integrable X μ) : centralMoment X 1 μ = (1 - (μ Set.univ).toReal) * μ[X] := by simp only [centralMoment, Pi.sub_apply, pow_one] rw [integral_sub h_int (integrable_const _)] simp only [sub_mul, integral_const, smul_eq_mul, one_mul] #align probability_theory.central_moment_one' ProbabilityTheory.centralMoment_one' @[simp] theorem centralMoment_one [IsProbabilityMeasure μ] : centralMoment X 1 μ = 0 := by by_cases h_int : Integrable X μ · rw [centralMoment_one' h_int] simp only [measure_univ, ENNReal.one_toReal, sub_self, zero_mul] · simp only [centralMoment, Pi.sub_apply, pow_one] have : ¬Integrable (fun x => X x - integral μ X) μ := by refine fun h_sub => h_int ?_ have h_add : X = (fun x => X x - integral μ X) + fun _ => integral μ X := by ext1 x; simp rw [h_add] exact h_sub.add (integrable_const _) rw [integral_undef this] #align probability_theory.central_moment_one ProbabilityTheory.centralMoment_one theorem centralMoment_two_eq_variance [IsFiniteMeasure μ] (hX : Memℒp X 2 μ) : centralMoment X 2 μ = variance X μ := by rw [hX.variance_eq]; rfl #align probability_theory.central_moment_two_eq_variance ProbabilityTheory.centralMoment_two_eq_variance section MomentGeneratingFunction variable {t : ℝ} /-- Moment generating function of a real random variable `X`: `fun t => μ[exp(t*X)]`. -/ def mgf (X : Ω → ℝ) (μ : Measure Ω) (t : ℝ) : ℝ := μ[fun ω => exp (t * X ω)] #align probability_theory.mgf ProbabilityTheory.mgf /-- Cumulant generating function of a real random variable `X`: `fun t => log μ[exp(t*X)]`. -/ def cgf (X : Ω → ℝ) (μ : Measure Ω) (t : ℝ) : ℝ := log (mgf X μ t) #align probability_theory.cgf ProbabilityTheory.cgf @[simp] theorem mgf_zero_fun : mgf 0 μ t = (μ Set.univ).toReal := by simp only [mgf, Pi.zero_apply, mul_zero, exp_zero, integral_const, smul_eq_mul, mul_one] #align probability_theory.mgf_zero_fun ProbabilityTheory.mgf_zero_fun @[simp] theorem cgf_zero_fun : cgf 0 μ t = log (μ Set.univ).toReal := by simp only [cgf, mgf_zero_fun] #align probability_theory.cgf_zero_fun ProbabilityTheory.cgf_zero_fun @[simp] theorem mgf_zero_measure : mgf X (0 : Measure Ω) t = 0 := by simp only [mgf, integral_zero_measure] #align probability_theory.mgf_zero_measure ProbabilityTheory.mgf_zero_measure @[simp] theorem cgf_zero_measure : cgf X (0 : Measure Ω) t = 0 := by simp only [cgf, log_zero, mgf_zero_measure] #align probability_theory.cgf_zero_measure ProbabilityTheory.cgf_zero_measure @[simp] theorem mgf_const' (c : ℝ) : mgf (fun _ => c) μ t = (μ Set.univ).toReal * exp (t * c) := by simp only [mgf, integral_const, smul_eq_mul] #align probability_theory.mgf_const' ProbabilityTheory.mgf_const' -- @[simp] -- Porting note: `simp only` already proves this theorem mgf_const (c : ℝ) [IsProbabilityMeasure μ] : mgf (fun _ => c) μ t = exp (t * c) := by simp only [mgf_const', measure_univ, ENNReal.one_toReal, one_mul] #align probability_theory.mgf_const ProbabilityTheory.mgf_const @[simp] theorem cgf_const' [IsFiniteMeasure μ] (hμ : μ ≠ 0) (c : ℝ) : cgf (fun _ => c) μ t = log (μ Set.univ).toReal + t * c := by simp only [cgf, mgf_const'] rw [log_mul _ (exp_pos _).ne'] · rw [log_exp _] · rw [Ne, ENNReal.toReal_eq_zero_iff, Measure.measure_univ_eq_zero] simp only [hμ, measure_ne_top μ Set.univ, or_self_iff, not_false_iff] #align probability_theory.cgf_const' ProbabilityTheory.cgf_const' @[simp] theorem cgf_const [IsProbabilityMeasure μ] (c : ℝ) : cgf (fun _ => c) μ t = t * c := by simp only [cgf, mgf_const, log_exp] #align probability_theory.cgf_const ProbabilityTheory.cgf_const @[simp] theorem mgf_zero' : mgf X μ 0 = (μ Set.univ).toReal := by simp only [mgf, zero_mul, exp_zero, integral_const, smul_eq_mul, mul_one] #align probability_theory.mgf_zero' ProbabilityTheory.mgf_zero' -- @[simp] -- Porting note: `simp only` already proves this theorem mgf_zero [IsProbabilityMeasure μ] : mgf X μ 0 = 1 := by simp only [mgf_zero', measure_univ, ENNReal.one_toReal] #align probability_theory.mgf_zero ProbabilityTheory.mgf_zero @[simp] theorem cgf_zero' : cgf X μ 0 = log (μ Set.univ).toReal := by simp only [cgf, mgf_zero'] #align probability_theory.cgf_zero' ProbabilityTheory.cgf_zero' -- @[simp] -- Porting note: `simp only` already proves this theorem cgf_zero [IsProbabilityMeasure μ] : cgf X μ 0 = 0 := by simp only [cgf_zero', measure_univ, ENNReal.one_toReal, log_one] #align probability_theory.cgf_zero ProbabilityTheory.cgf_zero theorem mgf_undef (hX : ¬Integrable (fun ω => exp (t * X ω)) μ) : mgf X μ t = 0 := by simp only [mgf, integral_undef hX] #align probability_theory.mgf_undef ProbabilityTheory.mgf_undef theorem cgf_undef (hX : ¬Integrable (fun ω => exp (t * X ω)) μ) : cgf X μ t = 0 := by simp only [cgf, mgf_undef hX, log_zero] #align probability_theory.cgf_undef ProbabilityTheory.cgf_undef theorem mgf_nonneg : 0 ≤ mgf X μ t := by unfold mgf; positivity #align probability_theory.mgf_nonneg ProbabilityTheory.mgf_nonneg theorem mgf_pos' (hμ : μ ≠ 0) (h_int_X : Integrable (fun ω => exp (t * X ω)) μ) : 0 < mgf X μ t := by simp_rw [mgf] have : ∫ x : Ω, exp (t * X x) ∂μ = ∫ x : Ω in Set.univ, exp (t * X x) ∂μ := by simp only [Measure.restrict_univ] rw [this, setIntegral_pos_iff_support_of_nonneg_ae _ _] · have h_eq_univ : (Function.support fun x : Ω => exp (t * X x)) = Set.univ := by ext1 x simp only [Function.mem_support, Set.mem_univ, iff_true_iff] exact (exp_pos _).ne' rw [h_eq_univ, Set.inter_univ _] refine Ne.bot_lt ?_ simp only [hμ, ENNReal.bot_eq_zero, Ne, Measure.measure_univ_eq_zero, not_false_iff] · filter_upwards with x rw [Pi.zero_apply] exact (exp_pos _).le · rwa [integrableOn_univ] #align probability_theory.mgf_pos' ProbabilityTheory.mgf_pos' theorem mgf_pos [IsProbabilityMeasure μ] (h_int_X : Integrable (fun ω => exp (t * X ω)) μ) : 0 < mgf X μ t := mgf_pos' (IsProbabilityMeasure.ne_zero μ) h_int_X #align probability_theory.mgf_pos ProbabilityTheory.mgf_pos theorem mgf_neg : mgf (-X) μ t = mgf X μ (-t) := by simp_rw [mgf, Pi.neg_apply, mul_neg, neg_mul] #align probability_theory.mgf_neg ProbabilityTheory.mgf_neg theorem cgf_neg : cgf (-X) μ t = cgf X μ (-t) := by simp_rw [cgf, mgf_neg] #align probability_theory.cgf_neg ProbabilityTheory.cgf_neg /-- This is a trivial application of `IndepFun.comp` but it will come up frequently. -/ theorem IndepFun.exp_mul {X Y : Ω → ℝ} (h_indep : IndepFun X Y μ) (s t : ℝ) : IndepFun (fun ω => exp (s * X ω)) (fun ω => exp (t * Y ω)) μ := by have h_meas : ∀ t, Measurable fun x => exp (t * x) := fun t => (measurable_id'.const_mul t).exp change IndepFun ((fun x => exp (s * x)) ∘ X) ((fun x => exp (t * x)) ∘ Y) μ exact IndepFun.comp h_indep (h_meas s) (h_meas t) #align probability_theory.indep_fun.exp_mul ProbabilityTheory.IndepFun.exp_mul
Mathlib/Probability/Moments.lean
224
229
theorem IndepFun.mgf_add {X Y : Ω → ℝ} (h_indep : IndepFun X Y μ) (hX : AEStronglyMeasurable (fun ω => exp (t * X ω)) μ) (hY : AEStronglyMeasurable (fun ω => exp (t * Y ω)) μ) : mgf (X + Y) μ t = mgf X μ t * mgf Y μ t := by
simp_rw [mgf, Pi.add_apply, mul_add, exp_add] exact (h_indep.exp_mul t t).integral_mul hX hY
/- Copyright (c) 2023 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.MeasureTheory.Constructions.Pi import Mathlib.Probability.Kernel.Basic /-! # Independence with respect to a kernel and a measure A family of sets of sets `π : ι → Set (Set Ω)` is independent with respect to a kernel `κ : kernel α Ω` and a measure `μ` on `α` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`, then for `μ`-almost every `a : α`, `κ a (⋂ i in s, f i) = ∏ i ∈ s, κ a (f i)`. This notion of independence is a generalization of both independence and conditional independence. For conditional independence, `κ` is the conditional kernel `ProbabilityTheory.condexpKernel` and `μ` is the ambiant measure. For (non-conditional) independence, `κ = kernel.const Unit μ` and the measure is the Dirac measure on `Unit`. The main purpose of this file is to prove only once the properties that hold for both conditional and non-conditional independence. ## Main definitions * `ProbabilityTheory.kernel.iIndepSets`: independence of a family of sets of sets. Variant for two sets of sets: `ProbabilityTheory.kernel.IndepSets`. * `ProbabilityTheory.kernel.iIndep`: independence of a family of σ-algebras. Variant for two σ-algebras: `Indep`. * `ProbabilityTheory.kernel.iIndepSet`: independence of a family of sets. Variant for two sets: `ProbabilityTheory.kernel.IndepSet`. * `ProbabilityTheory.kernel.iIndepFun`: independence of a family of functions (random variables). Variant for two functions: `ProbabilityTheory.kernel.IndepFun`. See the file `Mathlib/Probability/Kernel/Basic.lean` for a more detailed discussion of these definitions in the particular case of the usual independence notion. ## Main statements * `ProbabilityTheory.kernel.iIndepSets.iIndep`: if π-systems are independent as sets of sets, then the measurable space structures they generate are independent. * `ProbabilityTheory.kernel.IndepSets.Indep`: variant with two π-systems. -/ open MeasureTheory MeasurableSpace open scoped MeasureTheory ENNReal namespace ProbabilityTheory.kernel variable {α Ω ι : Type*} section Definitions variable {_mα : MeasurableSpace α} /-- A family of sets of sets `π : ι → Set (Set Ω)` is independent with respect to a kernel `κ` and a measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`, then `∀ᵐ a ∂μ, κ a (⋂ i in s, f i) = ∏ i ∈ s, κ a (f i)`. It will be used for families of pi_systems. -/ def iIndepSets {_mΩ : MeasurableSpace Ω} (π : ι → Set (Set Ω)) (κ : kernel α Ω) (μ : Measure α := by volume_tac) : Prop := ∀ (s : Finset ι) {f : ι → Set Ω} (_H : ∀ i, i ∈ s → f i ∈ π i), ∀ᵐ a ∂μ, κ a (⋂ i ∈ s, f i) = ∏ i ∈ s, κ a (f i) /-- Two sets of sets `s₁, s₂` are independent with respect to a kernel `κ` and a measure `μ` if for any sets `t₁ ∈ s₁, t₂ ∈ s₂`, then `∀ᵐ a ∂μ, κ a (t₁ ∩ t₂) = κ a (t₁) * κ a (t₂)` -/ def IndepSets {_mΩ : MeasurableSpace Ω} (s1 s2 : Set (Set Ω)) (κ : kernel α Ω) (μ : Measure α := by volume_tac) : Prop := ∀ t1 t2 : Set Ω, t1 ∈ s1 → t2 ∈ s2 → (∀ᵐ a ∂μ, κ a (t1 ∩ t2) = κ a t1 * κ a t2) /-- A family of measurable space structures (i.e. of σ-algebras) is independent with respect to a kernel `κ` and a measure `μ` if the family of sets of measurable sets they define is independent. -/ def iIndep (m : ι → MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (κ : kernel α Ω) (μ : Measure α := by volume_tac) : Prop := iIndepSets (fun x ↦ {s | MeasurableSet[m x] s}) κ μ /-- Two measurable space structures (or σ-algebras) `m₁, m₂` are independent with respect to a kernel `κ` and a measure `μ` if for any sets `t₁ ∈ m₁, t₂ ∈ m₂`, `∀ᵐ a ∂μ, κ a (t₁ ∩ t₂) = κ a (t₁) * κ a (t₂)` -/ def Indep (m₁ m₂ : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (κ : kernel α Ω) (μ : Measure α := by volume_tac) : Prop := IndepSets {s | MeasurableSet[m₁] s} {s | MeasurableSet[m₂] s} κ μ /-- A family of sets is independent if the family of measurable space structures they generate is independent. For a set `s`, the generated measurable space has measurable sets `∅, s, sᶜ, univ`. -/ def iIndepSet {_mΩ : MeasurableSpace Ω} (s : ι → Set Ω) (κ : kernel α Ω) (μ : Measure α := by volume_tac) : Prop := iIndep (fun i ↦ generateFrom {s i}) κ μ /-- Two sets are independent if the two measurable space structures they generate are independent. For a set `s`, the generated measurable space structure has measurable sets `∅, s, sᶜ, univ`. -/ def IndepSet {_mΩ : MeasurableSpace Ω} (s t : Set Ω) (κ : kernel α Ω) (μ : Measure α := by volume_tac) : Prop := Indep (generateFrom {s}) (generateFrom {t}) κ μ /-- A family of functions defined on the same space `Ω` and taking values in possibly different spaces, each with a measurable space structure, is independent if the family of measurable space structures they generate on `Ω` is independent. For a function `g` with codomain having measurable space structure `m`, the generated measurable space structure is `MeasurableSpace.comap g m`. -/ def iIndepFun {_mΩ : MeasurableSpace Ω} {β : ι → Type*} (m : ∀ x : ι, MeasurableSpace (β x)) (f : ∀ x : ι, Ω → β x) (κ : kernel α Ω) (μ : Measure α := by volume_tac) : Prop := iIndep (fun x ↦ MeasurableSpace.comap (f x) (m x)) κ μ /-- Two functions are independent if the two measurable space structures they generate are independent. For a function `f` with codomain having measurable space structure `m`, the generated measurable space structure is `MeasurableSpace.comap f m`. -/ def IndepFun {β γ} {_mΩ : MeasurableSpace Ω} [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ] (f : Ω → β) (g : Ω → γ) (κ : kernel α Ω) (μ : Measure α := by volume_tac) : Prop := Indep (MeasurableSpace.comap f mβ) (MeasurableSpace.comap g mγ) κ μ end Definitions section ByDefinition variable {β : ι → Type*} {mβ : ∀ i, MeasurableSpace (β i)} {_mα : MeasurableSpace α} {m : ι → MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} {π : ι → Set (Set Ω)} {s : ι → Set Ω} {S : Finset ι} {f : ∀ x : ι, Ω → β x} lemma iIndepSets.meas_biInter (h : iIndepSets π κ μ) (s : Finset ι) {f : ι → Set Ω} (hf : ∀ i, i ∈ s → f i ∈ π i) : ∀ᵐ a ∂μ, κ a (⋂ i ∈ s, f i) = ∏ i ∈ s, κ a (f i) := h s hf lemma iIndepSets.meas_iInter [Fintype ι] (h : iIndepSets π κ μ) (hs : ∀ i, s i ∈ π i) : ∀ᵐ a ∂μ, κ a (⋂ i, s i) = ∏ i, κ a (s i) := by filter_upwards [h.meas_biInter Finset.univ (fun _i _ ↦ hs _)] with a ha using by simp [← ha] lemma iIndep.iIndepSets' (hμ : iIndep m κ μ) : iIndepSets (fun x ↦ {s | MeasurableSet[m x] s}) κ μ := hμ lemma iIndep.meas_biInter (hμ : iIndep m κ μ) (hs : ∀ i, i ∈ S → MeasurableSet[m i] (s i)) : ∀ᵐ a ∂μ, κ a (⋂ i ∈ S, s i) = ∏ i ∈ S, κ a (s i) := hμ _ hs lemma iIndep.meas_iInter [Fintype ι] (h : iIndep m κ μ) (hs : ∀ i, MeasurableSet[m i] (s i)) : ∀ᵐ a ∂μ, κ a (⋂ i, s i) = ∏ i, κ a (s i) := by filter_upwards [h.meas_biInter (fun i (_ : i ∈ Finset.univ) ↦ hs _)] with a ha simp [← ha] protected lemma iIndepFun.iIndep (hf : iIndepFun mβ f κ μ) : iIndep (fun x ↦ (mβ x).comap (f x)) κ μ := hf lemma iIndepFun.meas_biInter (hf : iIndepFun mβ f κ μ) (hs : ∀ i, i ∈ S → MeasurableSet[(mβ i).comap (f i)] (s i)) : ∀ᵐ a ∂μ, κ a (⋂ i ∈ S, s i) = ∏ i ∈ S, κ a (s i) := hf.iIndep.meas_biInter hs lemma iIndepFun.meas_iInter [Fintype ι] (hf : iIndepFun mβ f κ μ) (hs : ∀ i, MeasurableSet[(mβ i).comap (f i)] (s i)) : ∀ᵐ a ∂μ, κ a (⋂ i, s i) = ∏ i, κ a (s i) := hf.iIndep.meas_iInter hs lemma IndepFun.meas_inter {β γ : Type*} [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ] {f : Ω → β} {g : Ω → γ} (hfg : IndepFun f g κ μ) {s t : Set Ω} (hs : MeasurableSet[mβ.comap f] s) (ht : MeasurableSet[mγ.comap g] t) : ∀ᵐ a ∂μ, κ a (s ∩ t) = κ a s * κ a t := hfg _ _ hs ht end ByDefinition section Indep variable {_mα : MeasurableSpace α} @[symm] theorem IndepSets.symm {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} {s₁ s₂ : Set (Set Ω)} (h : IndepSets s₁ s₂ κ μ) : IndepSets s₂ s₁ κ μ := by intros t1 t2 ht1 ht2 filter_upwards [h t2 t1 ht2 ht1] with a ha rwa [Set.inter_comm, mul_comm] @[symm] theorem Indep.symm {m₁ m₂ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} (h : Indep m₁ m₂ κ μ) : Indep m₂ m₁ κ μ := IndepSets.symm h theorem indep_bot_right (m' : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} [IsMarkovKernel κ] : Indep m' ⊥ κ μ := by intros s t _ ht rw [Set.mem_setOf_eq, MeasurableSpace.measurableSet_bot_iff] at ht refine Filter.eventually_of_forall (fun a ↦ ?_) cases' ht with ht ht · rw [ht, Set.inter_empty, measure_empty, mul_zero] · rw [ht, Set.inter_univ, measure_univ, mul_one] theorem indep_bot_left (m' : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} [IsMarkovKernel κ] : Indep ⊥ m' κ μ := (indep_bot_right m').symm theorem indepSet_empty_right {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} [IsMarkovKernel κ] (s : Set Ω) : IndepSet s ∅ κ μ := by simp only [IndepSet, generateFrom_singleton_empty]; exact indep_bot_right _ theorem indepSet_empty_left {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} [IsMarkovKernel κ] (s : Set Ω) : IndepSet ∅ s κ μ := (indepSet_empty_right s).symm theorem indepSets_of_indepSets_of_le_left {s₁ s₂ s₃ : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} (h_indep : IndepSets s₁ s₂ κ μ) (h31 : s₃ ⊆ s₁) : IndepSets s₃ s₂ κ μ := fun t1 t2 ht1 ht2 => h_indep t1 t2 (Set.mem_of_subset_of_mem h31 ht1) ht2 theorem indepSets_of_indepSets_of_le_right {s₁ s₂ s₃ : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} (h_indep : IndepSets s₁ s₂ κ μ) (h32 : s₃ ⊆ s₂) : IndepSets s₁ s₃ κ μ := fun t1 t2 ht1 ht2 => h_indep t1 t2 ht1 (Set.mem_of_subset_of_mem h32 ht2) theorem indep_of_indep_of_le_left {m₁ m₂ m₃ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} (h_indep : Indep m₁ m₂ κ μ) (h31 : m₃ ≤ m₁) : Indep m₃ m₂ κ μ := fun t1 t2 ht1 ht2 => h_indep t1 t2 (h31 _ ht1) ht2 theorem indep_of_indep_of_le_right {m₁ m₂ m₃ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} (h_indep : Indep m₁ m₂ κ μ) (h32 : m₃ ≤ m₂) : Indep m₁ m₃ κ μ := fun t1 t2 ht1 ht2 => h_indep t1 t2 ht1 (h32 _ ht2) theorem IndepSets.union {s₁ s₂ s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} (h₁ : IndepSets s₁ s' κ μ) (h₂ : IndepSets s₂ s' κ μ) : IndepSets (s₁ ∪ s₂) s' κ μ := by intro t1 t2 ht1 ht2 cases' (Set.mem_union _ _ _).mp ht1 with ht1₁ ht1₂ · exact h₁ t1 t2 ht1₁ ht2 · exact h₂ t1 t2 ht1₂ ht2 @[simp] theorem IndepSets.union_iff {s₁ s₂ s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} : IndepSets (s₁ ∪ s₂) s' κ μ ↔ IndepSets s₁ s' κ μ ∧ IndepSets s₂ s' κ μ := ⟨fun h => ⟨indepSets_of_indepSets_of_le_left h Set.subset_union_left, indepSets_of_indepSets_of_le_left h Set.subset_union_right⟩, fun h => IndepSets.union h.left h.right⟩ theorem IndepSets.iUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} (hyp : ∀ n, IndepSets (s n) s' κ μ) : IndepSets (⋃ n, s n) s' κ μ := by intro t1 t2 ht1 ht2 rw [Set.mem_iUnion] at ht1 cases' ht1 with n ht1 exact hyp n t1 t2 ht1 ht2 theorem IndepSets.bUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} {u : Set ι} (hyp : ∀ n ∈ u, IndepSets (s n) s' κ μ) : IndepSets (⋃ n ∈ u, s n) s' κ μ := by intro t1 t2 ht1 ht2 simp_rw [Set.mem_iUnion] at ht1 rcases ht1 with ⟨n, hpn, ht1⟩ exact hyp n hpn t1 t2 ht1 ht2 theorem IndepSets.inter {s₁ s' : Set (Set Ω)} (s₂ : Set (Set Ω)) {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} (h₁ : IndepSets s₁ s' κ μ) : IndepSets (s₁ ∩ s₂) s' κ μ := fun t1 t2 ht1 ht2 => h₁ t1 t2 ((Set.mem_inter_iff _ _ _).mp ht1).left ht2 theorem IndepSets.iInter {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} (h : ∃ n, IndepSets (s n) s' κ μ) : IndepSets (⋂ n, s n) s' κ μ := by intro t1 t2 ht1 ht2; cases' h with n h; exact h t1 t2 (Set.mem_iInter.mp ht1 n) ht2 theorem IndepSets.bInter {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} {u : Set ι} (h : ∃ n ∈ u, IndepSets (s n) s' κ μ) : IndepSets (⋂ n ∈ u, s n) s' κ μ := by intro t1 t2 ht1 ht2 rcases h with ⟨n, hn, h⟩ exact h t1 t2 (Set.biInter_subset_of_mem hn ht1) ht2 theorem iIndep_comap_mem_iff {f : ι → Set Ω} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} : iIndep (fun i => MeasurableSpace.comap (· ∈ f i) ⊤) κ μ ↔ iIndepSet f κ μ := by simp_rw [← generateFrom_singleton, iIndepSet] theorem iIndepSets_singleton_iff {s : ι → Set Ω} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} : iIndepSets (fun i ↦ {s i}) κ μ ↔ ∀ S : Finset ι, ∀ᵐ a ∂μ, κ a (⋂ i ∈ S, s i) = ∏ i ∈ S, κ a (s i) := by refine ⟨fun h S ↦ h S (fun i _ ↦ rfl), fun h S f hf ↦ ?_⟩ filter_upwards [h S] with a ha have : ∀ i ∈ S, κ a (f i) = κ a (s i) := fun i hi ↦ by rw [hf i hi] rwa [Finset.prod_congr rfl this, Set.iInter₂_congr hf] theorem indepSets_singleton_iff {s t : Set Ω} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} : IndepSets {s} {t} κ μ ↔ ∀ᵐ a ∂μ, κ a (s ∩ t) = κ a s * κ a t := ⟨fun h ↦ h s t rfl rfl, fun h s1 t1 hs1 ht1 ↦ by rwa [Set.mem_singleton_iff.mp hs1, Set.mem_singleton_iff.mp ht1]⟩ end Indep /-! ### Deducing `Indep` from `iIndep` -/ section FromiIndepToIndep variable {_mα : MeasurableSpace α} theorem iIndepSets.indepSets {s : ι → Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} (h_indep : iIndepSets s κ μ) {i j : ι} (hij : i ≠ j) : IndepSets (s i) (s j) κ μ := by classical intro t₁ t₂ ht₁ ht₂ have hf_m : ∀ x : ι, x ∈ ({i, j} : Finset ι) → ite (x = i) t₁ t₂ ∈ s x := by intro x hx cases' Finset.mem_insert.mp hx with hx hx · simp [hx, ht₁] · simp [Finset.mem_singleton.mp hx, hij.symm, ht₂] have h1 : t₁ = ite (i = i) t₁ t₂ := by simp only [if_true, eq_self_iff_true] have h2 : t₂ = ite (j = i) t₁ t₂ := by simp only [hij.symm, if_false] have h_inter : ⋂ (t : ι) (_ : t ∈ ({i, j} : Finset ι)), ite (t = i) t₁ t₂ = ite (i = i) t₁ t₂ ∩ ite (j = i) t₁ t₂ := by simp only [Finset.set_biInter_singleton, Finset.set_biInter_insert] filter_upwards [h_indep {i, j} hf_m] with a h_indep' have h_prod : (∏ t ∈ ({i, j} : Finset ι), κ a (ite (t = i) t₁ t₂)) = κ a (ite (i = i) t₁ t₂) * κ a (ite (j = i) t₁ t₂) := by simp only [hij, Finset.prod_singleton, Finset.prod_insert, not_false_iff, Finset.mem_singleton] rw [h1] nth_rw 2 [h2] nth_rw 4 [h2] rw [← h_inter, ← h_prod, h_indep'] theorem iIndep.indep {m : ι → MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} (h_indep : iIndep m κ μ) {i j : ι} (hij : i ≠ j) : Indep (m i) (m j) κ μ := iIndepSets.indepSets h_indep hij theorem iIndepFun.indepFun {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} {β : ι → Type*} {m : ∀ x, MeasurableSpace (β x)} {f : ∀ i, Ω → β i} (hf_Indep : iIndepFun m f κ μ) {i j : ι} (hij : i ≠ j) : IndepFun (f i) (f j) κ μ := hf_Indep.indep hij end FromiIndepToIndep /-! ## π-system lemma Independence of measurable spaces is equivalent to independence of generating π-systems. -/ section FromMeasurableSpacesToSetsOfSets /-! ### Independence of measurable space structures implies independence of generating π-systems -/ variable {_mα : MeasurableSpace α} theorem iIndep.iIndepSets {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} {m : ι → MeasurableSpace Ω} {s : ι → Set (Set Ω)} (hms : ∀ n, m n = generateFrom (s n)) (h_indep : iIndep m κ μ) : iIndepSets s κ μ := fun S f hfs => h_indep S fun x hxS => ((hms x).symm ▸ measurableSet_generateFrom (hfs x hxS) : MeasurableSet[m x] (f x)) theorem Indep.indepSets {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} {s1 s2 : Set (Set Ω)} (h_indep : Indep (generateFrom s1) (generateFrom s2) κ μ) : IndepSets s1 s2 κ μ := fun t1 t2 ht1 ht2 => h_indep t1 t2 (measurableSet_generateFrom ht1) (measurableSet_generateFrom ht2) end FromMeasurableSpacesToSetsOfSets section FromPiSystemsToMeasurableSpaces /-! ### Independence of generating π-systems implies independence of measurable space structures -/ variable {_mα : MeasurableSpace α} theorem IndepSets.indep_aux {m₂ m : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} [IsMarkovKernel κ] {p1 p2 : Set (Set Ω)} (h2 : m₂ ≤ m) (hp2 : IsPiSystem p2) (hpm2 : m₂ = generateFrom p2) (hyp : IndepSets p1 p2 κ μ) {t1 t2 : Set Ω} (ht1 : t1 ∈ p1) (ht1m : MeasurableSet[m] t1) (ht2m : MeasurableSet[m₂] t2) : ∀ᵐ a ∂μ, κ a (t1 ∩ t2) = κ a t1 * κ a t2 := by refine @induction_on_inter _ (fun t ↦ ∀ᵐ a ∂μ, κ a (t1 ∩ t) = κ a t1 * κ a t) _ m₂ hpm2 hp2 ?_ ?_ ?_ ?_ t2 ht2m · simp only [Set.inter_empty, measure_empty, mul_zero, eq_self_iff_true, Filter.eventually_true] · exact fun t ht_mem_p2 ↦ hyp t1 t ht1 ht_mem_p2 · intros t ht h filter_upwards [h] with a ha have : t1 ∩ tᶜ = t1 \ (t1 ∩ t) := by rw [Set.diff_self_inter, Set.diff_eq_compl_inter, Set.inter_comm] rw [this, measure_diff Set.inter_subset_left (ht1m.inter (h2 _ ht)) (measure_ne_top (κ a) _), measure_compl (h2 _ ht) (measure_ne_top (κ a) t), measure_univ, ENNReal.mul_sub (fun _ _ ↦ measure_ne_top (κ a) _), mul_one, ha] · intros f hf_disj hf_meas h rw [← ae_all_iff] at h filter_upwards [h] with a ha rw [Set.inter_iUnion, measure_iUnion] · rw [measure_iUnion hf_disj (fun i ↦ h2 _ (hf_meas i))] rw [← ENNReal.tsum_mul_left] congr with i rw [ha i] · intros i j hij rw [Function.onFun, Set.inter_comm t1, Set.inter_comm t1] exact Disjoint.inter_left _ (Disjoint.inter_right _ (hf_disj hij)) · exact fun i ↦ ht1m.inter (h2 _ (hf_meas i)) /-- The measurable space structures generated by independent pi-systems are independent. -/ theorem IndepSets.indep {m1 m2 m : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} [IsMarkovKernel κ] {p1 p2 : Set (Set Ω)} (h1 : m1 ≤ m) (h2 : m2 ≤ m) (hp1 : IsPiSystem p1) (hp2 : IsPiSystem p2) (hpm1 : m1 = generateFrom p1) (hpm2 : m2 = generateFrom p2) (hyp : IndepSets p1 p2 κ μ) : Indep m1 m2 κ μ := by intros t1 t2 ht1 ht2 refine @induction_on_inter _ (fun t ↦ ∀ᵐ (a : α) ∂μ, κ a (t ∩ t2) = κ a t * κ a t2) _ m1 hpm1 hp1 ?_ ?_ ?_ ?_ _ ht1 · simp only [Set.empty_inter, measure_empty, zero_mul, eq_self_iff_true, Filter.eventually_true] · intros t ht_mem_p1 have ht1 : MeasurableSet[m] t := by refine h1 _ ?_ rw [hpm1] exact measurableSet_generateFrom ht_mem_p1 exact IndepSets.indep_aux h2 hp2 hpm2 hyp ht_mem_p1 ht1 ht2 · intros t ht h filter_upwards [h] with a ha have : tᶜ ∩ t2 = t2 \ (t ∩ t2) := by rw [Set.inter_comm t, Set.diff_self_inter, Set.diff_eq_compl_inter] rw [this, Set.inter_comm t t2, measure_diff Set.inter_subset_left ((h2 _ ht2).inter (h1 _ ht)) (measure_ne_top (κ a) _), Set.inter_comm, ha, measure_compl (h1 _ ht) (measure_ne_top (κ a) t), measure_univ, mul_comm (1 - κ a t), ENNReal.mul_sub (fun _ _ ↦ measure_ne_top (κ a) _), mul_one, mul_comm] · intros f hf_disj hf_meas h rw [← ae_all_iff] at h filter_upwards [h] with a ha rw [Set.inter_comm, Set.inter_iUnion, measure_iUnion] · rw [measure_iUnion hf_disj (fun i ↦ h1 _ (hf_meas i))] rw [← ENNReal.tsum_mul_right] congr 1 with i rw [Set.inter_comm t2, ha i] · intros i j hij rw [Function.onFun, Set.inter_comm t2, Set.inter_comm t2] exact Disjoint.inter_left _ (Disjoint.inter_right _ (hf_disj hij)) · exact fun i ↦ (h2 _ ht2).inter (h1 _ (hf_meas i)) theorem IndepSets.indep' {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} [IsMarkovKernel κ] {p1 p2 : Set (Set Ω)} (hp1m : ∀ s ∈ p1, MeasurableSet s) (hp2m : ∀ s ∈ p2, MeasurableSet s) (hp1 : IsPiSystem p1) (hp2 : IsPiSystem p2) (hyp : IndepSets p1 p2 κ μ) : Indep (generateFrom p1) (generateFrom p2) κ μ := hyp.indep (generateFrom_le hp1m) (generateFrom_le hp2m) hp1 hp2 rfl rfl variable {_mΩ : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} theorem indepSets_piiUnionInter_of_disjoint [IsMarkovKernel κ] {s : ι → Set (Set Ω)} {S T : Set ι} (h_indep : iIndepSets s κ μ) (hST : Disjoint S T) : IndepSets (piiUnionInter s S) (piiUnionInter s T) κ μ := by rintro t1 t2 ⟨p1, hp1, f1, ht1_m, ht1_eq⟩ ⟨p2, hp2, f2, ht2_m, ht2_eq⟩ classical let g i := ite (i ∈ p1) (f1 i) Set.univ ∩ ite (i ∈ p2) (f2 i) Set.univ have h_P_inter : ∀ᵐ a ∂μ, κ a (t1 ∩ t2) = ∏ n ∈ p1 ∪ p2, κ a (g n) := by have hgm : ∀ i ∈ p1 ∪ p2, g i ∈ s i := by intro i hi_mem_union rw [Finset.mem_union] at hi_mem_union cases' hi_mem_union with hi1 hi2 · have hi2 : i ∉ p2 := fun hip2 => Set.disjoint_left.mp hST (hp1 hi1) (hp2 hip2) simp_rw [g, if_pos hi1, if_neg hi2, Set.inter_univ] exact ht1_m i hi1 · have hi1 : i ∉ p1 := fun hip1 => Set.disjoint_right.mp hST (hp2 hi2) (hp1 hip1) simp_rw [g, if_neg hi1, if_pos hi2, Set.univ_inter] exact ht2_m i hi2 have h_p1_inter_p2 : ((⋂ x ∈ p1, f1 x) ∩ ⋂ x ∈ p2, f2 x) = ⋂ i ∈ p1 ∪ p2, ite (i ∈ p1) (f1 i) Set.univ ∩ ite (i ∈ p2) (f2 i) Set.univ := by ext1 x simp only [Set.mem_ite_univ_right, Set.mem_inter_iff, Set.mem_iInter, Finset.mem_union] exact ⟨fun h i _ => ⟨h.1 i, h.2 i⟩, fun h => ⟨fun i hi => (h i (Or.inl hi)).1 hi, fun i hi => (h i (Or.inr hi)).2 hi⟩⟩ filter_upwards [h_indep _ hgm] with a ha rw [ht1_eq, ht2_eq, h_p1_inter_p2, ← ha] filter_upwards [h_P_inter, h_indep p1 ht1_m, h_indep p2 ht2_m] with a h_P_inter ha1 ha2 have h_μg : ∀ n, κ a (g n) = (ite (n ∈ p1) (κ a (f1 n)) 1) * (ite (n ∈ p2) (κ a (f2 n)) 1) := by intro n dsimp only [g] split_ifs with h1 h2 · exact absurd rfl (Set.disjoint_iff_forall_ne.mp hST (hp1 h1) (hp2 h2)) all_goals simp only [measure_univ, one_mul, mul_one, Set.inter_univ, Set.univ_inter] simp_rw [h_P_inter, h_μg, Finset.prod_mul_distrib, Finset.prod_ite_mem (p1 ∪ p2) p1 (fun x ↦ κ a (f1 x)), Finset.union_inter_cancel_left, Finset.prod_ite_mem (p1 ∪ p2) p2 (fun x => κ a (f2 x)), Finset.union_inter_cancel_right, ht1_eq, ← ha1, ht2_eq, ← ha2] theorem iIndepSet.indep_generateFrom_of_disjoint [IsMarkovKernel κ] {s : ι → Set Ω} (hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s κ μ) (S T : Set ι) (hST : Disjoint S T) : Indep (generateFrom { t | ∃ n ∈ S, s n = t }) (generateFrom { t | ∃ k ∈ T, s k = t }) κ μ := by rw [← generateFrom_piiUnionInter_singleton_left, ← generateFrom_piiUnionInter_singleton_left] refine IndepSets.indep' (fun t ht => generateFrom_piiUnionInter_le _ ?_ _ _ (measurableSet_generateFrom ht)) (fun t ht => generateFrom_piiUnionInter_le _ ?_ _ _ (measurableSet_generateFrom ht)) ?_ ?_ ?_ · exact fun k => generateFrom_le fun t ht => (Set.mem_singleton_iff.1 ht).symm ▸ hsm k · exact fun k => generateFrom_le fun t ht => (Set.mem_singleton_iff.1 ht).symm ▸ hsm k · exact isPiSystem_piiUnionInter _ (fun k => IsPiSystem.singleton _) _ · exact isPiSystem_piiUnionInter _ (fun k => IsPiSystem.singleton _) _ · classical exact indepSets_piiUnionInter_of_disjoint (iIndep.iIndepSets (fun n => rfl) hs) hST theorem indep_iSup_of_disjoint [IsMarkovKernel κ] {m : ι → MeasurableSpace Ω} (h_le : ∀ i, m i ≤ _mΩ) (h_indep : iIndep m κ μ) {S T : Set ι} (hST : Disjoint S T) : Indep (⨆ i ∈ S, m i) (⨆ i ∈ T, m i) κ μ := by refine IndepSets.indep (iSup₂_le fun i _ => h_le i) (iSup₂_le fun i _ => h_le i) ?_ ?_ (generateFrom_piiUnionInter_measurableSet m S).symm (generateFrom_piiUnionInter_measurableSet m T).symm ?_ · exact isPiSystem_piiUnionInter _ (fun n => @isPiSystem_measurableSet Ω (m n)) _ · exact isPiSystem_piiUnionInter _ (fun n => @isPiSystem_measurableSet Ω (m n)) _ · classical exact indepSets_piiUnionInter_of_disjoint h_indep hST theorem indep_iSup_of_directed_le {Ω} {m : ι → MeasurableSpace Ω} {m' m0 : MeasurableSpace Ω} {κ : kernel α Ω} {μ : Measure α} [IsMarkovKernel κ] (h_indep : ∀ i, Indep (m i) m' κ μ) (h_le : ∀ i, m i ≤ m0) (h_le' : m' ≤ m0) (hm : Directed (· ≤ ·) m) : Indep (⨆ i, m i) m' κ μ := by let p : ι → Set (Set Ω) := fun n => { t | MeasurableSet[m n] t } have hp : ∀ n, IsPiSystem (p n) := fun n => @isPiSystem_measurableSet Ω (m n) have h_gen_n : ∀ n, m n = generateFrom (p n) := fun n => (@generateFrom_measurableSet Ω (m n)).symm have hp_supr_pi : IsPiSystem (⋃ n, p n) := isPiSystem_iUnion_of_directed_le p hp hm let p' := { t : Set Ω | MeasurableSet[m'] t } have hp'_pi : IsPiSystem p' := @isPiSystem_measurableSet Ω m' have h_gen' : m' = generateFrom p' := (@generateFrom_measurableSet Ω m').symm -- the π-systems defined are independent have h_pi_system_indep : IndepSets (⋃ n, p n) p' κ μ := by refine IndepSets.iUnion ?_ conv at h_indep => intro i rw [h_gen_n i, h_gen'] exact fun n => (h_indep n).indepSets -- now go from π-systems to σ-algebras refine IndepSets.indep (iSup_le h_le) h_le' hp_supr_pi hp'_pi ?_ h_gen' h_pi_system_indep exact (generateFrom_iUnion_measurableSet _).symm
Mathlib/Probability/Independence/Kernel.lean
544
549
theorem iIndepSet.indep_generateFrom_lt [Preorder ι] [IsMarkovKernel κ] {s : ι → Set Ω} (hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s κ μ) (i : ι) : Indep (generateFrom {s i}) (generateFrom { t | ∃ j < i, s j = t }) κ μ := by
convert iIndepSet.indep_generateFrom_of_disjoint hsm hs {i} { j | j < i } (Set.disjoint_singleton_left.mpr (lt_irrefl _)) simp only [Set.mem_singleton_iff, exists_prop, exists_eq_left, Set.setOf_eq_eq_singleton']
/- Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta Hernández Palacios -/ import Mathlib.Order.SuccPred.Basic import Mathlib.Order.BoundedOrder #align_import order.succ_pred.limit from "leanprover-community/mathlib"@"1e05171a5e8cf18d98d9cf7b207540acb044acae" /-! # Successor and predecessor limits We define the predicate `Order.IsSuccLimit` for "successor limits", values that don't cover any others. They are so named since they can't be the successors of anything smaller. We define `Order.IsPredLimit` analogously, and prove basic results. ## Todo The plan is to eventually replace `Ordinal.IsLimit` and `Cardinal.IsLimit` with the common predicate `Order.IsSuccLimit`. -/ variable {α : Type*} namespace Order open Function Set OrderDual /-! ### Successor limits -/ section LT variable [LT α] /-- A successor limit is a value that doesn't cover any other. It's so named because in a successor order, a successor limit can't be the successor of anything smaller. -/ def IsSuccLimit (a : α) : Prop := ∀ b, ¬b ⋖ a #align order.is_succ_limit Order.IsSuccLimit theorem not_isSuccLimit_iff_exists_covBy (a : α) : ¬IsSuccLimit a ↔ ∃ b, b ⋖ a := by simp [IsSuccLimit] #align order.not_is_succ_limit_iff_exists_covby Order.not_isSuccLimit_iff_exists_covBy @[simp] theorem isSuccLimit_of_dense [DenselyOrdered α] (a : α) : IsSuccLimit a := fun _ => not_covBy #align order.is_succ_limit_of_dense Order.isSuccLimit_of_dense end LT section Preorder variable [Preorder α] {a : α} protected theorem _root_.IsMin.isSuccLimit : IsMin a → IsSuccLimit a := fun h _ hab => not_isMin_of_lt hab.lt h #align is_min.is_succ_limit IsMin.isSuccLimit theorem isSuccLimit_bot [OrderBot α] : IsSuccLimit (⊥ : α) := IsMin.isSuccLimit isMin_bot #align order.is_succ_limit_bot Order.isSuccLimit_bot variable [SuccOrder α] protected theorem IsSuccLimit.isMax (h : IsSuccLimit (succ a)) : IsMax a := by by_contra H exact h a (covBy_succ_of_not_isMax H) #align order.is_succ_limit.is_max Order.IsSuccLimit.isMax theorem not_isSuccLimit_succ_of_not_isMax (ha : ¬IsMax a) : ¬IsSuccLimit (succ a) := by contrapose! ha exact ha.isMax #align order.not_is_succ_limit_succ_of_not_is_max Order.not_isSuccLimit_succ_of_not_isMax section NoMaxOrder variable [NoMaxOrder α] theorem IsSuccLimit.succ_ne (h : IsSuccLimit a) (b : α) : succ b ≠ a := by rintro rfl exact not_isMax _ h.isMax #align order.is_succ_limit.succ_ne Order.IsSuccLimit.succ_ne @[simp] theorem not_isSuccLimit_succ (a : α) : ¬IsSuccLimit (succ a) := fun h => h.succ_ne _ rfl #align order.not_is_succ_limit_succ Order.not_isSuccLimit_succ end NoMaxOrder section IsSuccArchimedean variable [IsSuccArchimedean α] theorem IsSuccLimit.isMin_of_noMax [NoMaxOrder α] (h : IsSuccLimit a) : IsMin a := fun b hb => by rcases hb.exists_succ_iterate with ⟨_ | n, rfl⟩ · exact le_rfl · rw [iterate_succ_apply'] at h exact (not_isSuccLimit_succ _ h).elim #align order.is_succ_limit.is_min_of_no_max Order.IsSuccLimit.isMin_of_noMax @[simp] theorem isSuccLimit_iff_of_noMax [NoMaxOrder α] : IsSuccLimit a ↔ IsMin a := ⟨IsSuccLimit.isMin_of_noMax, IsMin.isSuccLimit⟩ #align order.is_succ_limit_iff_of_no_max Order.isSuccLimit_iff_of_noMax theorem not_isSuccLimit_of_noMax [NoMinOrder α] [NoMaxOrder α] : ¬IsSuccLimit a := by simp #align order.not_is_succ_limit_of_no_max Order.not_isSuccLimit_of_noMax end IsSuccArchimedean end Preorder section PartialOrder variable [PartialOrder α] [SuccOrder α] {a b : α} {C : α → Sort*} theorem isSuccLimit_of_succ_ne (h : ∀ b, succ b ≠ a) : IsSuccLimit a := fun b hba => h b (CovBy.succ_eq hba) #align order.is_succ_limit_of_succ_ne Order.isSuccLimit_of_succ_ne theorem not_isSuccLimit_iff : ¬IsSuccLimit a ↔ ∃ b, ¬IsMax b ∧ succ b = a := by rw [not_isSuccLimit_iff_exists_covBy] refine exists_congr fun b => ⟨fun hba => ⟨hba.lt.not_isMax, (CovBy.succ_eq hba)⟩, ?_⟩ rintro ⟨h, rfl⟩ exact covBy_succ_of_not_isMax h #align order.not_is_succ_limit_iff Order.not_isSuccLimit_iff /-- See `not_isSuccLimit_iff` for a version that states that `a` is a successor of a value other than itself. -/ theorem mem_range_succ_of_not_isSuccLimit (h : ¬IsSuccLimit a) : a ∈ range (@succ α _ _) := by cases' not_isSuccLimit_iff.1 h with b hb exact ⟨b, hb.2⟩ #align order.mem_range_succ_of_not_is_succ_limit Order.mem_range_succ_of_not_isSuccLimit theorem isSuccLimit_of_succ_lt (H : ∀ a < b, succ a < b) : IsSuccLimit b := fun a hab => (H a hab.lt).ne (CovBy.succ_eq hab) #align order.is_succ_limit_of_succ_lt Order.isSuccLimit_of_succ_lt theorem IsSuccLimit.succ_lt (hb : IsSuccLimit b) (ha : a < b) : succ a < b := by by_cases h : IsMax a · rwa [h.succ_eq] · rw [lt_iff_le_and_ne, succ_le_iff_of_not_isMax h] refine ⟨ha, fun hab => ?_⟩ subst hab exact (h hb.isMax).elim #align order.is_succ_limit.succ_lt Order.IsSuccLimit.succ_lt theorem IsSuccLimit.succ_lt_iff (hb : IsSuccLimit b) : succ a < b ↔ a < b := ⟨fun h => (le_succ a).trans_lt h, hb.succ_lt⟩ #align order.is_succ_limit.succ_lt_iff Order.IsSuccLimit.succ_lt_iff theorem isSuccLimit_iff_succ_lt : IsSuccLimit b ↔ ∀ a < b, succ a < b := ⟨fun hb _ => hb.succ_lt, isSuccLimit_of_succ_lt⟩ #align order.is_succ_limit_iff_succ_lt Order.isSuccLimit_iff_succ_lt /-- A value can be built by building it on successors and successor limits. -/ @[elab_as_elim] noncomputable def isSuccLimitRecOn (b : α) (hs : ∀ a, ¬IsMax a → C (succ a)) (hl : ∀ a, IsSuccLimit a → C a) : C b := by by_cases hb : IsSuccLimit b · exact hl b hb · have H := Classical.choose_spec (not_isSuccLimit_iff.1 hb) rw [← H.2] exact hs _ H.1 #align order.is_succ_limit_rec_on Order.isSuccLimitRecOn theorem isSuccLimitRecOn_limit (hs : ∀ a, ¬IsMax a → C (succ a)) (hl : ∀ a, IsSuccLimit a → C a) (hb : IsSuccLimit b) : @isSuccLimitRecOn α _ _ C b hs hl = hl b hb := by classical exact dif_pos hb #align order.is_succ_limit_rec_on_limit Order.isSuccLimitRecOn_limit theorem isSuccLimitRecOn_succ' (hs : ∀ a, ¬IsMax a → C (succ a)) (hl : ∀ a, IsSuccLimit a → C a) {b : α} (hb : ¬IsMax b) : @isSuccLimitRecOn α _ _ C (succ b) hs hl = hs b hb := by have hb' := not_isSuccLimit_succ_of_not_isMax hb have H := Classical.choose_spec (not_isSuccLimit_iff.1 hb') rw [isSuccLimitRecOn] simp only [cast_eq_iff_heq, hb', not_false_iff, eq_mpr_eq_cast, dif_neg] congr 1 <;> first | exact (succ_eq_succ_iff_of_not_isMax H.left hb).mp H.right | exact proof_irrel_heq H.left hb #align order.is_succ_limit_rec_on_succ' Order.isSuccLimitRecOn_succ' section limitRecOn variable [WellFoundedLT α] (H_succ : ∀ a, ¬IsMax a → C a → C (succ a)) (H_lim : ∀ a, IsSuccLimit a → (∀ b < a, C b) → C a) open scoped Classical in variable (a) in /-- Recursion principle on a well-founded partial `SuccOrder`. -/ @[elab_as_elim] noncomputable def _root_.SuccOrder.limitRecOn : C a := wellFounded_lt.fix (fun a IH ↦ if h : IsSuccLimit a then H_lim a h IH else let x := Classical.indefiniteDescription _ (not_isSuccLimit_iff.mp h) x.2.2 ▸ H_succ x x.2.1 (IH x <| x.2.2.subst <| lt_succ_of_not_isMax x.2.1)) a @[simp] theorem _root_.SuccOrder.limitRecOn_succ (ha : ¬ IsMax a) : SuccOrder.limitRecOn (succ a) H_succ H_lim = H_succ a ha (SuccOrder.limitRecOn a H_succ H_lim) := by have h := not_isSuccLimit_succ_of_not_isMax ha rw [SuccOrder.limitRecOn, WellFounded.fix_eq, dif_neg h] have {b c hb hc} {x : ∀ a, C a} (h : b = c) : congr_arg succ h ▸ H_succ b hb (x b) = H_succ c hc (x c) := by subst h; rfl let x := Classical.indefiniteDescription _ (not_isSuccLimit_iff.mp h) exact this ((succ_eq_succ_iff_of_not_isMax x.2.1 ha).mp x.2.2) @[simp] theorem _root_.SuccOrder.limitRecOn_limit (ha : IsSuccLimit a) : SuccOrder.limitRecOn a H_succ H_lim = H_lim a ha fun x _ ↦ SuccOrder.limitRecOn x H_succ H_lim := by rw [SuccOrder.limitRecOn, WellFounded.fix_eq, dif_pos ha]; rfl end limitRecOn section NoMaxOrder variable [NoMaxOrder α] @[simp] theorem isSuccLimitRecOn_succ (hs : ∀ a, ¬IsMax a → C (succ a)) (hl : ∀ a, IsSuccLimit a → C a) (b : α) : @isSuccLimitRecOn α _ _ C (succ b) hs hl = hs b (not_isMax b) := isSuccLimitRecOn_succ' _ _ _ #align order.is_succ_limit_rec_on_succ Order.isSuccLimitRecOn_succ theorem isSuccLimit_iff_succ_ne : IsSuccLimit a ↔ ∀ b, succ b ≠ a := ⟨IsSuccLimit.succ_ne, isSuccLimit_of_succ_ne⟩ #align order.is_succ_limit_iff_succ_ne Order.isSuccLimit_iff_succ_ne theorem not_isSuccLimit_iff' : ¬IsSuccLimit a ↔ a ∈ range (@succ α _ _) := by simp_rw [isSuccLimit_iff_succ_ne, not_forall, not_ne_iff] rfl #align order.not_is_succ_limit_iff' Order.not_isSuccLimit_iff' end NoMaxOrder section IsSuccArchimedean variable [IsSuccArchimedean α] protected theorem IsSuccLimit.isMin (h : IsSuccLimit a) : IsMin a := fun b hb => by revert h refine Succ.rec (fun _ => le_rfl) (fun c _ H hc => ?_) hb have := hc.isMax.succ_eq rw [this] at hc ⊢ exact H hc #align order.is_succ_limit.is_min Order.IsSuccLimit.isMin @[simp] theorem isSuccLimit_iff : IsSuccLimit a ↔ IsMin a := ⟨IsSuccLimit.isMin, IsMin.isSuccLimit⟩ #align order.is_succ_limit_iff Order.isSuccLimit_iff theorem not_isSuccLimit [NoMinOrder α] : ¬IsSuccLimit a := by simp #align order.not_is_succ_limit Order.not_isSuccLimit end IsSuccArchimedean end PartialOrder /-! ### Predecessor limits -/ section LT variable [LT α] {a : α} /-- A predecessor limit is a value that isn't covered by any other. It's so named because in a predecessor order, a predecessor limit can't be the predecessor of anything greater. -/ def IsPredLimit (a : α) : Prop := ∀ b, ¬a ⋖ b #align order.is_pred_limit Order.IsPredLimit theorem not_isPredLimit_iff_exists_covBy (a : α) : ¬IsPredLimit a ↔ ∃ b, a ⋖ b := by simp [IsPredLimit] #align order.not_is_pred_limit_iff_exists_covby Order.not_isPredLimit_iff_exists_covBy theorem isPredLimit_of_dense [DenselyOrdered α] (a : α) : IsPredLimit a := fun _ => not_covBy #align order.is_pred_limit_of_dense Order.isPredLimit_of_dense @[simp] theorem isSuccLimit_toDual_iff : IsSuccLimit (toDual a) ↔ IsPredLimit a := by simp [IsSuccLimit, IsPredLimit] #align order.is_succ_limit_to_dual_iff Order.isSuccLimit_toDual_iff @[simp] theorem isPredLimit_toDual_iff : IsPredLimit (toDual a) ↔ IsSuccLimit a := by simp [IsSuccLimit, IsPredLimit] #align order.is_pred_limit_to_dual_iff Order.isPredLimit_toDual_iff alias ⟨_, isPredLimit.dual⟩ := isSuccLimit_toDual_iff #align order.is_pred_limit.dual Order.isPredLimit.dual alias ⟨_, isSuccLimit.dual⟩ := isPredLimit_toDual_iff #align order.is_succ_limit.dual Order.isSuccLimit.dual end LT section Preorder variable [Preorder α] {a : α} protected theorem _root_.IsMax.isPredLimit : IsMax a → IsPredLimit a := fun h _ hab => not_isMax_of_lt hab.lt h #align is_max.is_pred_limit IsMax.isPredLimit theorem isPredLimit_top [OrderTop α] : IsPredLimit (⊤ : α) := IsMax.isPredLimit isMax_top #align order.is_pred_limit_top Order.isPredLimit_top variable [PredOrder α] protected theorem IsPredLimit.isMin (h : IsPredLimit (pred a)) : IsMin a := by by_contra H exact h a (pred_covBy_of_not_isMin H) #align order.is_pred_limit.is_min Order.IsPredLimit.isMin
Mathlib/Order/SuccPred/Limit.lean
327
329
theorem not_isPredLimit_pred_of_not_isMin (ha : ¬IsMin a) : ¬IsPredLimit (pred a) := by
contrapose! ha exact ha.isMin
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Jens Wagemaker -/ import Mathlib.Algebra.Group.Even import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.GroupWithZero.Hom import Mathlib.Algebra.Group.Commute.Units import Mathlib.Algebra.Group.Units.Hom import Mathlib.Algebra.Order.Monoid.Canonical.Defs import Mathlib.Algebra.Ring.Units #align_import algebra.associated from "leanprover-community/mathlib"@"2f3994e1b117b1e1da49bcfb67334f33460c3ce4" /-! # Associated, prime, and irreducible elements. In this file we define the predicate `Prime p` saying that an element of a commutative monoid with zero is prime. Namely, `Prime p` means that `p` isn't zero, it isn't a unit, and `p ∣ a * b → p ∣ a ∨ p ∣ b` for all `a`, `b`; In decomposition monoids (e.g., `ℕ`, `ℤ`), this predicate is equivalent to `Irreducible`, however this is not true in general. We also define an equivalence relation `Associated` saying that two elements of a monoid differ by a multiplication by a unit. Then we show that the quotient type `Associates` is a monoid and prove basic properties of this quotient. -/ variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} section Prime variable [CommMonoidWithZero α] /-- An element `p` of a commutative monoid with zero (e.g., a ring) is called *prime*, if it's not zero, not a unit, and `p ∣ a * b → p ∣ a ∨ p ∣ b` for all `a`, `b`. -/ def Prime (p : α) : Prop := p ≠ 0 ∧ ¬IsUnit p ∧ ∀ a b, p ∣ a * b → p ∣ a ∨ p ∣ b #align prime Prime namespace Prime variable {p : α} (hp : Prime p) theorem ne_zero : p ≠ 0 := hp.1 #align prime.ne_zero Prime.ne_zero theorem not_unit : ¬IsUnit p := hp.2.1 #align prime.not_unit Prime.not_unit theorem not_dvd_one : ¬p ∣ 1 := mt (isUnit_of_dvd_one ·) hp.not_unit #align prime.not_dvd_one Prime.not_dvd_one theorem ne_one : p ≠ 1 := fun h => hp.2.1 (h.symm ▸ isUnit_one) #align prime.ne_one Prime.ne_one theorem dvd_or_dvd (hp : Prime p) {a b : α} (h : p ∣ a * b) : p ∣ a ∨ p ∣ b := hp.2.2 a b h #align prime.dvd_or_dvd Prime.dvd_or_dvd theorem dvd_mul {a b : α} : p ∣ a * b ↔ p ∣ a ∨ p ∣ b := ⟨hp.dvd_or_dvd, (Or.elim · (dvd_mul_of_dvd_left · _) (dvd_mul_of_dvd_right · _))⟩ theorem isPrimal (hp : Prime p) : IsPrimal p := fun _a _b dvd ↦ (hp.dvd_or_dvd dvd).elim (fun h ↦ ⟨p, 1, h, one_dvd _, (mul_one p).symm⟩) fun h ↦ ⟨1, p, one_dvd _, h, (one_mul p).symm⟩ theorem not_dvd_mul {a b : α} (ha : ¬ p ∣ a) (hb : ¬ p ∣ b) : ¬ p ∣ a * b := hp.dvd_mul.not.mpr <| not_or.mpr ⟨ha, hb⟩
Mathlib/Algebra/Associated.lean
77
86
theorem dvd_of_dvd_pow (hp : Prime p) {a : α} {n : ℕ} (h : p ∣ a ^ n) : p ∣ a := by
induction' n with n ih · rw [pow_zero] at h have := isUnit_of_dvd_one h have := not_unit hp contradiction rw [pow_succ'] at h cases' dvd_or_dvd hp h with dvd_a dvd_pow · assumption exact ih dvd_pow
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Johan Commelin, Patrick Massot -/ import Mathlib.Algebra.Group.WithOne.Defs import Mathlib.Algebra.GroupWithZero.InjSurj import Mathlib.Algebra.GroupWithZero.Units.Equiv import Mathlib.Algebra.GroupWithZero.WithZero import Mathlib.Algebra.Order.Group.Units import Mathlib.Algebra.Order.GroupWithZero.Synonym import Mathlib.Algebra.Order.Monoid.Basic import Mathlib.Algebra.Order.Monoid.OrderDual import Mathlib.Algebra.Order.Monoid.TypeTags import Mathlib.Algebra.Order.ZeroLEOne #align_import algebra.order.monoid.with_zero.defs from "leanprover-community/mathlib"@"4dc134b97a3de65ef2ed881f3513d56260971562" #align_import algebra.order.monoid.with_zero.basic from "leanprover-community/mathlib"@"dad7ecf9a1feae63e6e49f07619b7087403fb8d4" #align_import algebra.order.with_zero from "leanprover-community/mathlib"@"655994e298904d7e5bbd1e18c95defd7b543eb94" /-! # Linearly ordered commutative groups and monoids with a zero element adjoined This file sets up a special class of linearly ordered commutative monoids that show up as the target of so-called “valuations” in algebraic number theory. Usually, in the informal literature, these objects are constructed by taking a linearly ordered commutative group Γ and formally adjoining a zero element: Γ ∪ {0}. The disadvantage is that a type such as `NNReal` is not of that form, whereas it is a very common target for valuations. The solutions is to use a typeclass, and that is exactly what we do in this file. -/ variable {α : Type*} /-- A linearly ordered commutative monoid with a zero element. -/ class LinearOrderedCommMonoidWithZero (α : Type*) extends LinearOrderedCommMonoid α, CommMonoidWithZero α where /-- `0 ≤ 1` in any linearly ordered commutative monoid. -/ zero_le_one : (0 : α) ≤ 1 #align linear_ordered_comm_monoid_with_zero LinearOrderedCommMonoidWithZero /-- A linearly ordered commutative group with a zero element. -/ class LinearOrderedCommGroupWithZero (α : Type*) extends LinearOrderedCommMonoidWithZero α, CommGroupWithZero α #align linear_ordered_comm_group_with_zero LinearOrderedCommGroupWithZero instance (priority := 100) LinearOrderedCommMonoidWithZero.toZeroLeOneClass [LinearOrderedCommMonoidWithZero α] : ZeroLEOneClass α := { ‹LinearOrderedCommMonoidWithZero α› with } #align linear_ordered_comm_monoid_with_zero.to_zero_le_one_class LinearOrderedCommMonoidWithZero.toZeroLeOneClass instance (priority := 100) canonicallyOrderedAddCommMonoid.toZeroLeOneClass [CanonicallyOrderedAddCommMonoid α] [One α] : ZeroLEOneClass α := ⟨zero_le 1⟩ #align canonically_ordered_add_monoid.to_zero_le_one_class canonicallyOrderedAddCommMonoid.toZeroLeOneClass section LinearOrderedCommMonoidWithZero variable [LinearOrderedCommMonoidWithZero α] {a b c d x y z : α} {n : ℕ} /- The following facts are true more generally in a (linearly) ordered commutative monoid. -/ /-- Pullback a `LinearOrderedCommMonoidWithZero` under an injective map. See note [reducible non-instances]. -/ abbrev Function.Injective.linearOrderedCommMonoidWithZero {β : Type*} [Zero β] [One β] [Mul β] [Pow β ℕ] [Sup β] [Inf β] (f : β → α) (hf : Function.Injective f) (zero : f 0 = 0) (one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (hsup : ∀ x y, f (x ⊔ y) = max (f x) (f y)) (hinf : ∀ x y, f (x ⊓ y) = min (f x) (f y)) : LinearOrderedCommMonoidWithZero β := { LinearOrder.lift f hf hsup hinf, hf.orderedCommMonoid f one mul npow, hf.commMonoidWithZero f zero one mul npow with zero_le_one := show f 0 ≤ f 1 by simp only [zero, one, LinearOrderedCommMonoidWithZero.zero_le_one] } #align function.injective.linear_ordered_comm_monoid_with_zero Function.Injective.linearOrderedCommMonoidWithZero @[simp] lemma zero_le' : 0 ≤ a := by simpa only [mul_zero, mul_one] using mul_le_mul_left' (zero_le_one' α) a #align zero_le' zero_le' @[simp] theorem not_lt_zero' : ¬a < 0 := not_lt_of_le zero_le' #align not_lt_zero' not_lt_zero' @[simp] theorem le_zero_iff : a ≤ 0 ↔ a = 0 := ⟨fun h ↦ le_antisymm h zero_le', fun h ↦ h ▸ le_rfl⟩ #align le_zero_iff le_zero_iff theorem zero_lt_iff : 0 < a ↔ a ≠ 0 := ⟨ne_of_gt, fun h ↦ lt_of_le_of_ne zero_le' h.symm⟩ #align zero_lt_iff zero_lt_iff theorem ne_zero_of_lt (h : b < a) : a ≠ 0 := fun h1 ↦ not_lt_zero' <| show b < 0 from h1 ▸ h #align ne_zero_of_lt ne_zero_of_lt instance instLinearOrderedAddCommMonoidWithTopAdditiveOrderDual : LinearOrderedAddCommMonoidWithTop (Additive αᵒᵈ) := { Additive.orderedAddCommMonoid, Additive.linearOrder with top := (0 : α) top_add' := fun a ↦ zero_mul (Additive.toMul a) le_top := fun _ ↦ zero_le' } #align additive.linear_ordered_add_comm_monoid_with_top instLinearOrderedAddCommMonoidWithTopAdditiveOrderDual variable [NoZeroDivisors α] lemma pow_pos_iff (hn : n ≠ 0) : 0 < a ^ n ↔ 0 < a := by simp_rw [zero_lt_iff, pow_ne_zero_iff hn] #align pow_pos_iff pow_pos_iff end LinearOrderedCommMonoidWithZero section LinearOrderedCommGroupWithZero variable [LinearOrderedCommGroupWithZero α] {a b c d : α} {m n : ℕ} -- TODO: Do we really need the following two? /-- Alias of `mul_le_one'` for unification. -/ theorem mul_le_one₀ (ha : a ≤ 1) (hb : b ≤ 1) : a * b ≤ 1 := mul_le_one' ha hb #align mul_le_one₀ mul_le_one₀ /-- Alias of `one_le_mul'` for unification. -/ theorem one_le_mul₀ (ha : 1 ≤ a) (hb : 1 ≤ b) : 1 ≤ a * b := one_le_mul ha hb #align one_le_mul₀ one_le_mul₀ theorem le_of_le_mul_right (h : c ≠ 0) (hab : a * c ≤ b * c) : a ≤ b := by simpa only [mul_inv_cancel_right₀ h] using mul_le_mul_right' hab c⁻¹ #align le_of_le_mul_right le_of_le_mul_right theorem le_mul_inv_of_mul_le (h : c ≠ 0) (hab : a * c ≤ b) : a ≤ b * c⁻¹ := le_of_le_mul_right h (by simpa [h] using hab) #align le_mul_inv_of_mul_le le_mul_inv_of_mul_le theorem mul_inv_le_of_le_mul (hab : a ≤ b * c) : a * c⁻¹ ≤ b := by by_cases h : c = 0 · simp [h] · exact le_of_le_mul_right h (by simpa [h] using hab) #align mul_inv_le_of_le_mul mul_inv_le_of_le_mul theorem inv_le_one₀ (ha : a ≠ 0) : a⁻¹ ≤ 1 ↔ 1 ≤ a := @inv_le_one' _ _ _ _ <| Units.mk0 a ha #align inv_le_one₀ inv_le_one₀ theorem one_le_inv₀ (ha : a ≠ 0) : 1 ≤ a⁻¹ ↔ a ≤ 1 := @one_le_inv' _ _ _ _ <| Units.mk0 a ha #align one_le_inv₀ one_le_inv₀ theorem le_mul_inv_iff₀ (hc : c ≠ 0) : a ≤ b * c⁻¹ ↔ a * c ≤ b := ⟨fun h ↦ inv_inv c ▸ mul_inv_le_of_le_mul h, le_mul_inv_of_mul_le hc⟩ #align le_mul_inv_iff₀ le_mul_inv_iff₀ theorem mul_inv_le_iff₀ (hc : c ≠ 0) : a * c⁻¹ ≤ b ↔ a ≤ b * c := ⟨fun h ↦ inv_inv c ▸ le_mul_inv_of_mul_le (inv_ne_zero hc) h, mul_inv_le_of_le_mul⟩ #align mul_inv_le_iff₀ mul_inv_le_iff₀ theorem div_le_div₀ (a b c d : α) (hb : b ≠ 0) (hd : d ≠ 0) : a * b⁻¹ ≤ c * d⁻¹ ↔ a * d ≤ c * b := by rw [mul_inv_le_iff₀ hb, mul_right_comm, le_mul_inv_iff₀ hd] #align div_le_div₀ div_le_div₀ @[simp] theorem Units.zero_lt (u : αˣ) : (0 : α) < u := zero_lt_iff.2 <| u.ne_zero #align units.zero_lt Units.zero_lt theorem mul_lt_mul_of_lt_of_le₀ (hab : a ≤ b) (hb : b ≠ 0) (hcd : c < d) : a * c < b * d := have hd : d ≠ 0 := ne_zero_of_lt hcd if ha : a = 0 then by rw [ha, zero_mul, zero_lt_iff] exact mul_ne_zero hb hd else if hc : c = 0 then by rw [hc, mul_zero, zero_lt_iff] exact mul_ne_zero hb hd else show Units.mk0 a ha * Units.mk0 c hc < Units.mk0 b hb * Units.mk0 d hd from mul_lt_mul_of_le_of_lt hab hcd #align mul_lt_mul_of_lt_of_le₀ mul_lt_mul_of_lt_of_le₀ theorem mul_lt_mul₀ (hab : a < b) (hcd : c < d) : a * c < b * d := mul_lt_mul_of_lt_of_le₀ hab.le (ne_zero_of_lt hab) hcd #align mul_lt_mul₀ mul_lt_mul₀ theorem mul_inv_lt_of_lt_mul₀ (h : a < b * c) : a * c⁻¹ < b := by contrapose! h simpa only [inv_inv] using mul_inv_le_of_le_mul h #align mul_inv_lt_of_lt_mul₀ mul_inv_lt_of_lt_mul₀ theorem inv_mul_lt_of_lt_mul₀ (h : a < b * c) : b⁻¹ * a < c := by rw [mul_comm] at * exact mul_inv_lt_of_lt_mul₀ h #align inv_mul_lt_of_lt_mul₀ inv_mul_lt_of_lt_mul₀ theorem mul_lt_right₀ (c : α) (h : a < b) (hc : c ≠ 0) : a * c < b * c := by contrapose! h exact le_of_le_mul_right hc h #align mul_lt_right₀ mul_lt_right₀ theorem inv_lt_one₀ (ha : a ≠ 0) : a⁻¹ < 1 ↔ 1 < a := @inv_lt_one' _ _ _ _ <| Units.mk0 a ha theorem one_lt_inv₀ (ha : a ≠ 0) : 1 < a⁻¹ ↔ a < 1 := @one_lt_inv' _ _ _ _ <| Units.mk0 a ha theorem inv_lt_inv₀ (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ < b⁻¹ ↔ b < a := show (Units.mk0 a ha)⁻¹ < (Units.mk0 b hb)⁻¹ ↔ Units.mk0 b hb < Units.mk0 a ha from have : CovariantClass αˣ αˣ (· * ·) (· < ·) := IsLeftCancelMul.covariant_mul_lt_of_covariant_mul_le αˣ inv_lt_inv_iff #align inv_lt_inv₀ inv_lt_inv₀ theorem inv_le_inv₀ (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ ≤ b⁻¹ ↔ b ≤ a := show (Units.mk0 a ha)⁻¹ ≤ (Units.mk0 b hb)⁻¹ ↔ Units.mk0 b hb ≤ Units.mk0 a ha from inv_le_inv_iff #align inv_le_inv₀ inv_le_inv₀ theorem lt_of_mul_lt_mul_of_le₀ (h : a * b < c * d) (hc : 0 < c) (hh : c ≤ a) : b < d := by have ha : a ≠ 0 := ne_of_gt (lt_of_lt_of_le hc hh) simp_rw [← inv_le_inv₀ ha (ne_of_gt hc)] at hh have := mul_lt_mul_of_lt_of_le₀ hh (inv_ne_zero (ne_of_gt hc)) h simpa [inv_mul_cancel_left₀ ha, inv_mul_cancel_left₀ (ne_of_gt hc)] using this #align lt_of_mul_lt_mul_of_le₀ lt_of_mul_lt_mul_of_le₀ theorem mul_le_mul_right₀ (hc : c ≠ 0) : a * c ≤ b * c ↔ a ≤ b := ⟨le_of_le_mul_right hc, fun hab ↦ mul_le_mul_right' hab _⟩ #align mul_le_mul_right₀ mul_le_mul_right₀ theorem mul_le_mul_left₀ (ha : a ≠ 0) : a * b ≤ a * c ↔ b ≤ c := by simp only [mul_comm a] exact mul_le_mul_right₀ ha #align mul_le_mul_left₀ mul_le_mul_left₀
Mathlib/Algebra/Order/GroupWithZero/Canonical.lean
235
236
theorem div_le_div_right₀ (hc : c ≠ 0) : a / c ≤ b / c ↔ a ≤ b := by
rw [div_eq_mul_inv, div_eq_mul_inv, mul_le_mul_right₀ (inv_ne_zero hc)]
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Jens Wagemaker -/ import Mathlib.Algebra.Group.Even import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.GroupWithZero.Hom import Mathlib.Algebra.Group.Commute.Units import Mathlib.Algebra.Group.Units.Hom import Mathlib.Algebra.Order.Monoid.Canonical.Defs import Mathlib.Algebra.Ring.Units #align_import algebra.associated from "leanprover-community/mathlib"@"2f3994e1b117b1e1da49bcfb67334f33460c3ce4" /-! # Associated, prime, and irreducible elements. In this file we define the predicate `Prime p` saying that an element of a commutative monoid with zero is prime. Namely, `Prime p` means that `p` isn't zero, it isn't a unit, and `p ∣ a * b → p ∣ a ∨ p ∣ b` for all `a`, `b`; In decomposition monoids (e.g., `ℕ`, `ℤ`), this predicate is equivalent to `Irreducible`, however this is not true in general. We also define an equivalence relation `Associated` saying that two elements of a monoid differ by a multiplication by a unit. Then we show that the quotient type `Associates` is a monoid and prove basic properties of this quotient. -/ variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} section Prime variable [CommMonoidWithZero α] /-- An element `p` of a commutative monoid with zero (e.g., a ring) is called *prime*, if it's not zero, not a unit, and `p ∣ a * b → p ∣ a ∨ p ∣ b` for all `a`, `b`. -/ def Prime (p : α) : Prop := p ≠ 0 ∧ ¬IsUnit p ∧ ∀ a b, p ∣ a * b → p ∣ a ∨ p ∣ b #align prime Prime namespace Prime variable {p : α} (hp : Prime p) theorem ne_zero : p ≠ 0 := hp.1 #align prime.ne_zero Prime.ne_zero theorem not_unit : ¬IsUnit p := hp.2.1 #align prime.not_unit Prime.not_unit theorem not_dvd_one : ¬p ∣ 1 := mt (isUnit_of_dvd_one ·) hp.not_unit #align prime.not_dvd_one Prime.not_dvd_one theorem ne_one : p ≠ 1 := fun h => hp.2.1 (h.symm ▸ isUnit_one) #align prime.ne_one Prime.ne_one theorem dvd_or_dvd (hp : Prime p) {a b : α} (h : p ∣ a * b) : p ∣ a ∨ p ∣ b := hp.2.2 a b h #align prime.dvd_or_dvd Prime.dvd_or_dvd theorem dvd_mul {a b : α} : p ∣ a * b ↔ p ∣ a ∨ p ∣ b := ⟨hp.dvd_or_dvd, (Or.elim · (dvd_mul_of_dvd_left · _) (dvd_mul_of_dvd_right · _))⟩ theorem isPrimal (hp : Prime p) : IsPrimal p := fun _a _b dvd ↦ (hp.dvd_or_dvd dvd).elim (fun h ↦ ⟨p, 1, h, one_dvd _, (mul_one p).symm⟩) fun h ↦ ⟨1, p, one_dvd _, h, (one_mul p).symm⟩ theorem not_dvd_mul {a b : α} (ha : ¬ p ∣ a) (hb : ¬ p ∣ b) : ¬ p ∣ a * b := hp.dvd_mul.not.mpr <| not_or.mpr ⟨ha, hb⟩ theorem dvd_of_dvd_pow (hp : Prime p) {a : α} {n : ℕ} (h : p ∣ a ^ n) : p ∣ a := by induction' n with n ih · rw [pow_zero] at h have := isUnit_of_dvd_one h have := not_unit hp contradiction rw [pow_succ'] at h cases' dvd_or_dvd hp h with dvd_a dvd_pow · assumption exact ih dvd_pow #align prime.dvd_of_dvd_pow Prime.dvd_of_dvd_pow theorem dvd_pow_iff_dvd {a : α} {n : ℕ} (hn : n ≠ 0) : p ∣ a ^ n ↔ p ∣ a := ⟨hp.dvd_of_dvd_pow, (dvd_pow · hn)⟩ end Prime @[simp] theorem not_prime_zero : ¬Prime (0 : α) := fun h => h.ne_zero rfl #align not_prime_zero not_prime_zero @[simp] theorem not_prime_one : ¬Prime (1 : α) := fun h => h.not_unit isUnit_one #align not_prime_one not_prime_one section Map variable [CommMonoidWithZero β] {F : Type*} {G : Type*} [FunLike F α β] variable [MonoidWithZeroHomClass F α β] [FunLike G β α] [MulHomClass G β α] variable (f : F) (g : G) {p : α} theorem comap_prime (hinv : ∀ a, g (f a : β) = a) (hp : Prime (f p)) : Prime p := ⟨fun h => hp.1 <| by simp [h], fun h => hp.2.1 <| h.map f, fun a b h => by refine (hp.2.2 (f a) (f b) <| by convert map_dvd f h simp).imp ?_ ?_ <;> · intro h convert ← map_dvd g h <;> apply hinv⟩ #align comap_prime comap_prime theorem MulEquiv.prime_iff (e : α ≃* β) : Prime p ↔ Prime (e p) := ⟨fun h => (comap_prime e.symm e fun a => by simp) <| (e.symm_apply_apply p).substr h, comap_prime e e.symm fun a => by simp⟩ #align mul_equiv.prime_iff MulEquiv.prime_iff end Map end Prime theorem Prime.left_dvd_or_dvd_right_of_dvd_mul [CancelCommMonoidWithZero α] {p : α} (hp : Prime p) {a b : α} : a ∣ p * b → p ∣ a ∨ a ∣ b := by rintro ⟨c, hc⟩ rcases hp.2.2 a c (hc ▸ dvd_mul_right _ _) with (h | ⟨x, rfl⟩) · exact Or.inl h · rw [mul_left_comm, mul_right_inj' hp.ne_zero] at hc exact Or.inr (hc.symm ▸ dvd_mul_right _ _) #align prime.left_dvd_or_dvd_right_of_dvd_mul Prime.left_dvd_or_dvd_right_of_dvd_mul theorem Prime.pow_dvd_of_dvd_mul_left [CancelCommMonoidWithZero α] {p a b : α} (hp : Prime p) (n : ℕ) (h : ¬p ∣ a) (h' : p ^ n ∣ a * b) : p ^ n ∣ b := by induction' n with n ih · rw [pow_zero] exact one_dvd b · obtain ⟨c, rfl⟩ := ih (dvd_trans (pow_dvd_pow p n.le_succ) h') rw [pow_succ] apply mul_dvd_mul_left _ ((hp.dvd_or_dvd _).resolve_left h) rwa [← mul_dvd_mul_iff_left (pow_ne_zero n hp.ne_zero), ← pow_succ, mul_left_comm] #align prime.pow_dvd_of_dvd_mul_left Prime.pow_dvd_of_dvd_mul_left theorem Prime.pow_dvd_of_dvd_mul_right [CancelCommMonoidWithZero α] {p a b : α} (hp : Prime p) (n : ℕ) (h : ¬p ∣ b) (h' : p ^ n ∣ a * b) : p ^ n ∣ a := by rw [mul_comm] at h' exact hp.pow_dvd_of_dvd_mul_left n h h' #align prime.pow_dvd_of_dvd_mul_right Prime.pow_dvd_of_dvd_mul_right theorem Prime.dvd_of_pow_dvd_pow_mul_pow_of_square_not_dvd [CancelCommMonoidWithZero α] {p a b : α} {n : ℕ} (hp : Prime p) (hpow : p ^ n.succ ∣ a ^ n.succ * b ^ n) (hb : ¬p ^ 2 ∣ b) : p ∣ a := by -- Suppose `p ∣ b`, write `b = p * x` and `hy : a ^ n.succ * b ^ n = p ^ n.succ * y`. cases' hp.dvd_or_dvd ((dvd_pow_self p (Nat.succ_ne_zero n)).trans hpow) with H hbdiv · exact hp.dvd_of_dvd_pow H obtain ⟨x, rfl⟩ := hp.dvd_of_dvd_pow hbdiv obtain ⟨y, hy⟩ := hpow -- Then we can divide out a common factor of `p ^ n` from the equation `hy`. have : a ^ n.succ * x ^ n = p * y := by refine mul_left_cancel₀ (pow_ne_zero n hp.ne_zero) ?_ rw [← mul_assoc _ p, ← pow_succ, ← hy, mul_pow, ← mul_assoc (a ^ n.succ), mul_comm _ (p ^ n), mul_assoc] -- So `p ∣ a` (and we're done) or `p ∣ x`, which can't be the case since it implies `p^2 ∣ b`. refine hp.dvd_of_dvd_pow ((hp.dvd_or_dvd ⟨_, this⟩).resolve_right fun hdvdx => hb ?_) obtain ⟨z, rfl⟩ := hp.dvd_of_dvd_pow hdvdx rw [pow_two, ← mul_assoc] exact dvd_mul_right _ _ #align prime.dvd_of_pow_dvd_pow_mul_pow_of_square_not_dvd Prime.dvd_of_pow_dvd_pow_mul_pow_of_square_not_dvd theorem prime_pow_succ_dvd_mul {α : Type*} [CancelCommMonoidWithZero α] {p x y : α} (h : Prime p) {i : ℕ} (hxy : p ^ (i + 1) ∣ x * y) : p ^ (i + 1) ∣ x ∨ p ∣ y := by rw [or_iff_not_imp_right] intro hy induction' i with i ih generalizing x · rw [pow_one] at hxy ⊢ exact (h.dvd_or_dvd hxy).resolve_right hy rw [pow_succ'] at hxy ⊢ obtain ⟨x', rfl⟩ := (h.dvd_or_dvd (dvd_of_mul_right_dvd hxy)).resolve_right hy rw [mul_assoc] at hxy exact mul_dvd_mul_left p (ih ((mul_dvd_mul_iff_left h.ne_zero).mp hxy)) #align prime_pow_succ_dvd_mul prime_pow_succ_dvd_mul /-- `Irreducible p` states that `p` is non-unit and only factors into units. We explicitly avoid stating that `p` is non-zero, this would require a semiring. Assuming only a monoid allows us to reuse irreducible for associated elements. -/ structure Irreducible [Monoid α] (p : α) : Prop where /-- `p` is not a unit -/ not_unit : ¬IsUnit p /-- if `p` factors then one factor is a unit -/ isUnit_or_isUnit' : ∀ a b, p = a * b → IsUnit a ∨ IsUnit b #align irreducible Irreducible namespace Irreducible theorem not_dvd_one [CommMonoid α] {p : α} (hp : Irreducible p) : ¬p ∣ 1 := mt (isUnit_of_dvd_one ·) hp.not_unit #align irreducible.not_dvd_one Irreducible.not_dvd_one theorem isUnit_or_isUnit [Monoid α] {p : α} (hp : Irreducible p) {a b : α} (h : p = a * b) : IsUnit a ∨ IsUnit b := hp.isUnit_or_isUnit' a b h #align irreducible.is_unit_or_is_unit Irreducible.isUnit_or_isUnit end Irreducible theorem irreducible_iff [Monoid α] {p : α} : Irreducible p ↔ ¬IsUnit p ∧ ∀ a b, p = a * b → IsUnit a ∨ IsUnit b := ⟨fun h => ⟨h.1, h.2⟩, fun h => ⟨h.1, h.2⟩⟩ #align irreducible_iff irreducible_iff @[simp] theorem not_irreducible_one [Monoid α] : ¬Irreducible (1 : α) := by simp [irreducible_iff] #align not_irreducible_one not_irreducible_one theorem Irreducible.ne_one [Monoid α] : ∀ {p : α}, Irreducible p → p ≠ 1 | _, hp, rfl => not_irreducible_one hp #align irreducible.ne_one Irreducible.ne_one @[simp] theorem not_irreducible_zero [MonoidWithZero α] : ¬Irreducible (0 : α) | ⟨hn0, h⟩ => have : IsUnit (0 : α) ∨ IsUnit (0 : α) := h 0 0 (mul_zero 0).symm this.elim hn0 hn0 #align not_irreducible_zero not_irreducible_zero theorem Irreducible.ne_zero [MonoidWithZero α] : ∀ {p : α}, Irreducible p → p ≠ 0 | _, hp, rfl => not_irreducible_zero hp #align irreducible.ne_zero Irreducible.ne_zero theorem of_irreducible_mul {α} [Monoid α] {x y : α} : Irreducible (x * y) → IsUnit x ∨ IsUnit y | ⟨_, h⟩ => h _ _ rfl #align of_irreducible_mul of_irreducible_mul theorem not_irreducible_pow {α} [Monoid α] {x : α} {n : ℕ} (hn : n ≠ 1) : ¬ Irreducible (x ^ n) := by cases n with | zero => simp | succ n => intro ⟨h₁, h₂⟩ have := h₂ _ _ (pow_succ _ _) rw [isUnit_pow_iff (Nat.succ_ne_succ.mp hn), or_self] at this exact h₁ (this.pow _) #noalign of_irreducible_pow theorem irreducible_or_factor {α} [Monoid α] (x : α) (h : ¬IsUnit x) : Irreducible x ∨ ∃ a b, ¬IsUnit a ∧ ¬IsUnit b ∧ a * b = x := by haveI := Classical.dec refine or_iff_not_imp_right.2 fun H => ?_ simp? [h, irreducible_iff] at H ⊢ says simp only [exists_and_left, not_exists, not_and, irreducible_iff, h, not_false_eq_true, true_and] at H ⊢ refine fun a b h => by_contradiction fun o => ?_ simp? [not_or] at o says simp only [not_or] at o exact H _ o.1 _ o.2 h.symm #align irreducible_or_factor irreducible_or_factor /-- If `p` and `q` are irreducible, then `p ∣ q` implies `q ∣ p`. -/ theorem Irreducible.dvd_symm [Monoid α] {p q : α} (hp : Irreducible p) (hq : Irreducible q) : p ∣ q → q ∣ p := by rintro ⟨q', rfl⟩ rw [IsUnit.mul_right_dvd (Or.resolve_left (of_irreducible_mul hq) hp.not_unit)] #align irreducible.dvd_symm Irreducible.dvd_symm theorem Irreducible.dvd_comm [Monoid α] {p q : α} (hp : Irreducible p) (hq : Irreducible q) : p ∣ q ↔ q ∣ p := ⟨hp.dvd_symm hq, hq.dvd_symm hp⟩ #align irreducible.dvd_comm Irreducible.dvd_comm section variable [Monoid α] theorem irreducible_units_mul (a : αˣ) (b : α) : Irreducible (↑a * b) ↔ Irreducible b := by simp only [irreducible_iff, Units.isUnit_units_mul, and_congr_right_iff] refine fun _ => ⟨fun h A B HAB => ?_, fun h A B HAB => ?_⟩ · rw [← a.isUnit_units_mul] apply h rw [mul_assoc, ← HAB] · rw [← a⁻¹.isUnit_units_mul] apply h rw [mul_assoc, ← HAB, Units.inv_mul_cancel_left] #align irreducible_units_mul irreducible_units_mul theorem irreducible_isUnit_mul {a b : α} (h : IsUnit a) : Irreducible (a * b) ↔ Irreducible b := let ⟨a, ha⟩ := h ha ▸ irreducible_units_mul a b #align irreducible_is_unit_mul irreducible_isUnit_mul theorem irreducible_mul_units (a : αˣ) (b : α) : Irreducible (b * ↑a) ↔ Irreducible b := by simp only [irreducible_iff, Units.isUnit_mul_units, and_congr_right_iff] refine fun _ => ⟨fun h A B HAB => ?_, fun h A B HAB => ?_⟩ · rw [← Units.isUnit_mul_units B a] apply h rw [← mul_assoc, ← HAB] · rw [← Units.isUnit_mul_units B a⁻¹] apply h rw [← mul_assoc, ← HAB, Units.mul_inv_cancel_right] #align irreducible_mul_units irreducible_mul_units theorem irreducible_mul_isUnit {a b : α} (h : IsUnit a) : Irreducible (b * a) ↔ Irreducible b := let ⟨a, ha⟩ := h ha ▸ irreducible_mul_units a b #align irreducible_mul_is_unit irreducible_mul_isUnit theorem irreducible_mul_iff {a b : α} : Irreducible (a * b) ↔ Irreducible a ∧ IsUnit b ∨ Irreducible b ∧ IsUnit a := by constructor · refine fun h => Or.imp (fun h' => ⟨?_, h'⟩) (fun h' => ⟨?_, h'⟩) (h.isUnit_or_isUnit rfl).symm · rwa [irreducible_mul_isUnit h'] at h · rwa [irreducible_isUnit_mul h'] at h · rintro (⟨ha, hb⟩ | ⟨hb, ha⟩) · rwa [irreducible_mul_isUnit hb] · rwa [irreducible_isUnit_mul ha] #align irreducible_mul_iff irreducible_mul_iff end section CommMonoid variable [CommMonoid α] {a : α} theorem Irreducible.not_square (ha : Irreducible a) : ¬IsSquare a := by rw [isSquare_iff_exists_sq] rintro ⟨b, rfl⟩ exact not_irreducible_pow (by decide) ha #align irreducible.not_square Irreducible.not_square theorem IsSquare.not_irreducible (ha : IsSquare a) : ¬Irreducible a := fun h => h.not_square ha #align is_square.not_irreducible IsSquare.not_irreducible end CommMonoid section CommMonoidWithZero variable [CommMonoidWithZero α] theorem Irreducible.prime_of_isPrimal {a : α} (irr : Irreducible a) (primal : IsPrimal a) : Prime a := ⟨irr.ne_zero, irr.not_unit, fun a b dvd ↦ by obtain ⟨d₁, d₂, h₁, h₂, rfl⟩ := primal dvd exact (of_irreducible_mul irr).symm.imp (·.mul_right_dvd.mpr h₁) (·.mul_left_dvd.mpr h₂)⟩ theorem Irreducible.prime [DecompositionMonoid α] {a : α} (irr : Irreducible a) : Prime a := irr.prime_of_isPrimal (DecompositionMonoid.primal a) end CommMonoidWithZero section CancelCommMonoidWithZero variable [CancelCommMonoidWithZero α] {a p : α} protected theorem Prime.irreducible (hp : Prime p) : Irreducible p := ⟨hp.not_unit, fun a b ↦ by rintro rfl exact (hp.dvd_or_dvd dvd_rfl).symm.imp (isUnit_of_dvd_one <| (mul_dvd_mul_iff_right <| right_ne_zero_of_mul hp.ne_zero).mp <| dvd_mul_of_dvd_right · _) (isUnit_of_dvd_one <| (mul_dvd_mul_iff_left <| left_ne_zero_of_mul hp.ne_zero).mp <| dvd_mul_of_dvd_left · _)⟩ #align prime.irreducible Prime.irreducible theorem irreducible_iff_prime [DecompositionMonoid α] {a : α} : Irreducible a ↔ Prime a := ⟨Irreducible.prime, Prime.irreducible⟩ theorem succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul (hp : Prime p) {a b : α} {k l : ℕ} : p ^ k ∣ a → p ^ l ∣ b → p ^ (k + l + 1) ∣ a * b → p ^ (k + 1) ∣ a ∨ p ^ (l + 1) ∣ b := fun ⟨x, hx⟩ ⟨y, hy⟩ ⟨z, hz⟩ => have h : p ^ (k + l) * (x * y) = p ^ (k + l) * (p * z) := by simpa [mul_comm, pow_add, hx, hy, mul_assoc, mul_left_comm] using hz have hp0 : p ^ (k + l) ≠ 0 := pow_ne_zero _ hp.ne_zero have hpd : p ∣ x * y := ⟨z, by rwa [mul_right_inj' hp0] at h⟩ (hp.dvd_or_dvd hpd).elim (fun ⟨d, hd⟩ => Or.inl ⟨d, by simp [*, pow_succ, mul_comm, mul_left_comm, mul_assoc]⟩) fun ⟨d, hd⟩ => Or.inr ⟨d, by simp [*, pow_succ, mul_comm, mul_left_comm, mul_assoc]⟩ #align succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul theorem Prime.not_square (hp : Prime p) : ¬IsSquare p := hp.irreducible.not_square #align prime.not_square Prime.not_square theorem IsSquare.not_prime (ha : IsSquare a) : ¬Prime a := fun h => h.not_square ha #align is_square.not_prime IsSquare.not_prime theorem not_prime_pow {n : ℕ} (hn : n ≠ 1) : ¬Prime (a ^ n) := fun hp => not_irreducible_pow hn hp.irreducible #align pow_not_prime not_prime_pow end CancelCommMonoidWithZero /-- Two elements of a `Monoid` are `Associated` if one of them is another one multiplied by a unit on the right. -/ def Associated [Monoid α] (x y : α) : Prop := ∃ u : αˣ, x * u = y #align associated Associated /-- Notation for two elements of a monoid are associated, i.e. if one of them is another one multiplied by a unit on the right. -/ local infixl:50 " ~ᵤ " => Associated namespace Associated @[refl] protected theorem refl [Monoid α] (x : α) : x ~ᵤ x := ⟨1, by simp⟩ #align associated.refl Associated.refl protected theorem rfl [Monoid α] {x : α} : x ~ᵤ x := .refl x instance [Monoid α] : IsRefl α Associated := ⟨Associated.refl⟩ @[symm] protected theorem symm [Monoid α] : ∀ {x y : α}, x ~ᵤ y → y ~ᵤ x | x, _, ⟨u, rfl⟩ => ⟨u⁻¹, by rw [mul_assoc, Units.mul_inv, mul_one]⟩ #align associated.symm Associated.symm instance [Monoid α] : IsSymm α Associated := ⟨fun _ _ => Associated.symm⟩ protected theorem comm [Monoid α] {x y : α} : x ~ᵤ y ↔ y ~ᵤ x := ⟨Associated.symm, Associated.symm⟩ #align associated.comm Associated.comm @[trans] protected theorem trans [Monoid α] : ∀ {x y z : α}, x ~ᵤ y → y ~ᵤ z → x ~ᵤ z | x, _, _, ⟨u, rfl⟩, ⟨v, rfl⟩ => ⟨u * v, by rw [Units.val_mul, mul_assoc]⟩ #align associated.trans Associated.trans instance [Monoid α] : IsTrans α Associated := ⟨fun _ _ _ => Associated.trans⟩ /-- The setoid of the relation `x ~ᵤ y` iff there is a unit `u` such that `x * u = y` -/ protected def setoid (α : Type*) [Monoid α] : Setoid α where r := Associated iseqv := ⟨Associated.refl, Associated.symm, Associated.trans⟩ #align associated.setoid Associated.setoid theorem map {M N : Type*} [Monoid M] [Monoid N] {F : Type*} [FunLike F M N] [MonoidHomClass F M N] (f : F) {x y : M} (ha : Associated x y) : Associated (f x) (f y) := by obtain ⟨u, ha⟩ := ha exact ⟨Units.map f u, by rw [← ha, map_mul, Units.coe_map, MonoidHom.coe_coe]⟩ end Associated attribute [local instance] Associated.setoid theorem unit_associated_one [Monoid α] {u : αˣ} : (u : α) ~ᵤ 1 := ⟨u⁻¹, Units.mul_inv u⟩ #align unit_associated_one unit_associated_one @[simp] theorem associated_one_iff_isUnit [Monoid α] {a : α} : (a : α) ~ᵤ 1 ↔ IsUnit a := Iff.intro (fun h => let ⟨c, h⟩ := h.symm h ▸ ⟨c, (one_mul _).symm⟩) fun ⟨c, h⟩ => Associated.symm ⟨c, by simp [h]⟩ #align associated_one_iff_is_unit associated_one_iff_isUnit @[simp] theorem associated_zero_iff_eq_zero [MonoidWithZero α] (a : α) : a ~ᵤ 0 ↔ a = 0 := Iff.intro (fun h => by let ⟨u, h⟩ := h.symm simpa using h.symm) fun h => h ▸ Associated.refl a #align associated_zero_iff_eq_zero associated_zero_iff_eq_zero theorem associated_one_of_mul_eq_one [CommMonoid α] {a : α} (b : α) (hab : a * b = 1) : a ~ᵤ 1 := show (Units.mkOfMulEqOne a b hab : α) ~ᵤ 1 from unit_associated_one #align associated_one_of_mul_eq_one associated_one_of_mul_eq_one theorem associated_one_of_associated_mul_one [CommMonoid α] {a b : α} : a * b ~ᵤ 1 → a ~ᵤ 1 | ⟨u, h⟩ => associated_one_of_mul_eq_one (b * u) <| by simpa [mul_assoc] using h #align associated_one_of_associated_mul_one associated_one_of_associated_mul_one theorem associated_mul_unit_left {β : Type*} [Monoid β] (a u : β) (hu : IsUnit u) : Associated (a * u) a := let ⟨u', hu⟩ := hu ⟨u'⁻¹, hu ▸ Units.mul_inv_cancel_right _ _⟩ #align associated_mul_unit_left associated_mul_unit_left theorem associated_unit_mul_left {β : Type*} [CommMonoid β] (a u : β) (hu : IsUnit u) : Associated (u * a) a := by rw [mul_comm] exact associated_mul_unit_left _ _ hu #align associated_unit_mul_left associated_unit_mul_left theorem associated_mul_unit_right {β : Type*} [Monoid β] (a u : β) (hu : IsUnit u) : Associated a (a * u) := (associated_mul_unit_left a u hu).symm #align associated_mul_unit_right associated_mul_unit_right theorem associated_unit_mul_right {β : Type*} [CommMonoid β] (a u : β) (hu : IsUnit u) : Associated a (u * a) := (associated_unit_mul_left a u hu).symm #align associated_unit_mul_right associated_unit_mul_right theorem associated_mul_isUnit_left_iff {β : Type*} [Monoid β] {a u b : β} (hu : IsUnit u) : Associated (a * u) b ↔ Associated a b := ⟨(associated_mul_unit_right _ _ hu).trans, (associated_mul_unit_left _ _ hu).trans⟩ #align associated_mul_is_unit_left_iff associated_mul_isUnit_left_iff theorem associated_isUnit_mul_left_iff {β : Type*} [CommMonoid β] {u a b : β} (hu : IsUnit u) : Associated (u * a) b ↔ Associated a b := by rw [mul_comm] exact associated_mul_isUnit_left_iff hu #align associated_is_unit_mul_left_iff associated_isUnit_mul_left_iff theorem associated_mul_isUnit_right_iff {β : Type*} [Monoid β] {a b u : β} (hu : IsUnit u) : Associated a (b * u) ↔ Associated a b := Associated.comm.trans <| (associated_mul_isUnit_left_iff hu).trans Associated.comm #align associated_mul_is_unit_right_iff associated_mul_isUnit_right_iff theorem associated_isUnit_mul_right_iff {β : Type*} [CommMonoid β] {a u b : β} (hu : IsUnit u) : Associated a (u * b) ↔ Associated a b := Associated.comm.trans <| (associated_isUnit_mul_left_iff hu).trans Associated.comm #align associated_is_unit_mul_right_iff associated_isUnit_mul_right_iff @[simp] theorem associated_mul_unit_left_iff {β : Type*} [Monoid β] {a b : β} {u : Units β} : Associated (a * u) b ↔ Associated a b := associated_mul_isUnit_left_iff u.isUnit #align associated_mul_unit_left_iff associated_mul_unit_left_iff @[simp] theorem associated_unit_mul_left_iff {β : Type*} [CommMonoid β] {a b : β} {u : Units β} : Associated (↑u * a) b ↔ Associated a b := associated_isUnit_mul_left_iff u.isUnit #align associated_unit_mul_left_iff associated_unit_mul_left_iff @[simp] theorem associated_mul_unit_right_iff {β : Type*} [Monoid β] {a b : β} {u : Units β} : Associated a (b * u) ↔ Associated a b := associated_mul_isUnit_right_iff u.isUnit #align associated_mul_unit_right_iff associated_mul_unit_right_iff @[simp] theorem associated_unit_mul_right_iff {β : Type*} [CommMonoid β] {a b : β} {u : Units β} : Associated a (↑u * b) ↔ Associated a b := associated_isUnit_mul_right_iff u.isUnit #align associated_unit_mul_right_iff associated_unit_mul_right_iff theorem Associated.mul_left [Monoid α] (a : α) {b c : α} (h : b ~ᵤ c) : a * b ~ᵤ a * c := by obtain ⟨d, rfl⟩ := h; exact ⟨d, mul_assoc _ _ _⟩ #align associated.mul_left Associated.mul_left theorem Associated.mul_right [CommMonoid α] {a b : α} (h : a ~ᵤ b) (c : α) : a * c ~ᵤ b * c := by obtain ⟨d, rfl⟩ := h; exact ⟨d, mul_right_comm _ _ _⟩ #align associated.mul_right Associated.mul_right theorem Associated.mul_mul [CommMonoid α] {a₁ a₂ b₁ b₂ : α} (h₁ : a₁ ~ᵤ b₁) (h₂ : a₂ ~ᵤ b₂) : a₁ * a₂ ~ᵤ b₁ * b₂ := (h₁.mul_right _).trans (h₂.mul_left _) #align associated.mul_mul Associated.mul_mul theorem Associated.pow_pow [CommMonoid α] {a b : α} {n : ℕ} (h : a ~ᵤ b) : a ^ n ~ᵤ b ^ n := by induction' n with n ih · simp [Associated.refl] convert h.mul_mul ih <;> rw [pow_succ'] #align associated.pow_pow Associated.pow_pow protected theorem Associated.dvd [Monoid α] {a b : α} : a ~ᵤ b → a ∣ b := fun ⟨u, hu⟩ => ⟨u, hu.symm⟩ #align associated.dvd Associated.dvd protected theorem Associated.dvd' [Monoid α] {a b : α} (h : a ~ᵤ b) : b ∣ a := h.symm.dvd protected theorem Associated.dvd_dvd [Monoid α] {a b : α} (h : a ~ᵤ b) : a ∣ b ∧ b ∣ a := ⟨h.dvd, h.symm.dvd⟩ #align associated.dvd_dvd Associated.dvd_dvd theorem associated_of_dvd_dvd [CancelMonoidWithZero α] {a b : α} (hab : a ∣ b) (hba : b ∣ a) : a ~ᵤ b := by rcases hab with ⟨c, rfl⟩ rcases hba with ⟨d, a_eq⟩ by_cases ha0 : a = 0 · simp_all have hac0 : a * c ≠ 0 := by intro con rw [con, zero_mul] at a_eq apply ha0 a_eq have : a * (c * d) = a * 1 := by rw [← mul_assoc, ← a_eq, mul_one] have hcd : c * d = 1 := mul_left_cancel₀ ha0 this have : a * c * (d * c) = a * c * 1 := by rw [← mul_assoc, ← a_eq, mul_one] have hdc : d * c = 1 := mul_left_cancel₀ hac0 this exact ⟨⟨c, d, hcd, hdc⟩, rfl⟩ #align associated_of_dvd_dvd associated_of_dvd_dvd theorem dvd_dvd_iff_associated [CancelMonoidWithZero α] {a b : α} : a ∣ b ∧ b ∣ a ↔ a ~ᵤ b := ⟨fun ⟨h1, h2⟩ => associated_of_dvd_dvd h1 h2, Associated.dvd_dvd⟩ #align dvd_dvd_iff_associated dvd_dvd_iff_associated instance [CancelMonoidWithZero α] [DecidableRel ((· ∣ ·) : α → α → Prop)] : DecidableRel ((· ~ᵤ ·) : α → α → Prop) := fun _ _ => decidable_of_iff _ dvd_dvd_iff_associated theorem Associated.dvd_iff_dvd_left [Monoid α] {a b c : α} (h : a ~ᵤ b) : a ∣ c ↔ b ∣ c := let ⟨_, hu⟩ := h hu ▸ Units.mul_right_dvd.symm #align associated.dvd_iff_dvd_left Associated.dvd_iff_dvd_left theorem Associated.dvd_iff_dvd_right [Monoid α] {a b c : α} (h : b ~ᵤ c) : a ∣ b ↔ a ∣ c := let ⟨_, hu⟩ := h hu ▸ Units.dvd_mul_right.symm #align associated.dvd_iff_dvd_right Associated.dvd_iff_dvd_right theorem Associated.eq_zero_iff [MonoidWithZero α] {a b : α} (h : a ~ᵤ b) : a = 0 ↔ b = 0 := by obtain ⟨u, rfl⟩ := h rw [← Units.eq_mul_inv_iff_mul_eq, zero_mul] #align associated.eq_zero_iff Associated.eq_zero_iff theorem Associated.ne_zero_iff [MonoidWithZero α] {a b : α} (h : a ~ᵤ b) : a ≠ 0 ↔ b ≠ 0 := not_congr h.eq_zero_iff #align associated.ne_zero_iff Associated.ne_zero_iff theorem Associated.neg_left [Monoid α] [HasDistribNeg α] {a b : α} (h : Associated a b) : Associated (-a) b := let ⟨u, hu⟩ := h; ⟨-u, by simp [hu]⟩ theorem Associated.neg_right [Monoid α] [HasDistribNeg α] {a b : α} (h : Associated a b) : Associated a (-b) := h.symm.neg_left.symm theorem Associated.neg_neg [Monoid α] [HasDistribNeg α] {a b : α} (h : Associated a b) : Associated (-a) (-b) := h.neg_left.neg_right protected theorem Associated.prime [CommMonoidWithZero α] {p q : α} (h : p ~ᵤ q) (hp : Prime p) : Prime q := ⟨h.ne_zero_iff.1 hp.ne_zero, let ⟨u, hu⟩ := h ⟨fun ⟨v, hv⟩ => hp.not_unit ⟨v * u⁻¹, by simp [hv, hu.symm]⟩, hu ▸ by simp only [IsUnit.mul_iff, Units.isUnit, and_true, IsUnit.mul_right_dvd] intro a b exact hp.dvd_or_dvd⟩⟩ #align associated.prime Associated.prime theorem prime_mul_iff [CancelCommMonoidWithZero α] {x y : α} : Prime (x * y) ↔ (Prime x ∧ IsUnit y) ∨ (IsUnit x ∧ Prime y) := by refine ⟨fun h ↦ ?_, ?_⟩ · rcases of_irreducible_mul h.irreducible with hx | hy · exact Or.inr ⟨hx, (associated_unit_mul_left y x hx).prime h⟩ · exact Or.inl ⟨(associated_mul_unit_left x y hy).prime h, hy⟩ · rintro (⟨hx, hy⟩ | ⟨hx, hy⟩) · exact (associated_mul_unit_left x y hy).symm.prime hx · exact (associated_unit_mul_right y x hx).prime hy @[simp] lemma prime_pow_iff [CancelCommMonoidWithZero α] {p : α} {n : ℕ} : Prime (p ^ n) ↔ Prime p ∧ n = 1 := by refine ⟨fun hp ↦ ?_, fun ⟨hp, hn⟩ ↦ by simpa [hn]⟩ suffices n = 1 by aesop cases' n with n · simp at hp · rw [Nat.succ.injEq] rw [pow_succ', prime_mul_iff] at hp rcases hp with ⟨hp, hpn⟩ | ⟨hp, hpn⟩ · by_contra contra rw [isUnit_pow_iff contra] at hpn exact hp.not_unit hpn · exfalso exact hpn.not_unit (hp.pow n) theorem Irreducible.dvd_iff [Monoid α] {x y : α} (hx : Irreducible x) : y ∣ x ↔ IsUnit y ∨ Associated x y := by constructor · rintro ⟨z, hz⟩ obtain (h|h) := hx.isUnit_or_isUnit hz · exact Or.inl h · rw [hz] exact Or.inr (associated_mul_unit_left _ _ h) · rintro (hy|h) · exact hy.dvd · exact h.symm.dvd theorem Irreducible.associated_of_dvd [Monoid α] {p q : α} (p_irr : Irreducible p) (q_irr : Irreducible q) (dvd : p ∣ q) : Associated p q := ((q_irr.dvd_iff.mp dvd).resolve_left p_irr.not_unit).symm #align irreducible.associated_of_dvd Irreducible.associated_of_dvdₓ theorem Irreducible.dvd_irreducible_iff_associated [Monoid α] {p q : α} (pp : Irreducible p) (qp : Irreducible q) : p ∣ q ↔ Associated p q := ⟨Irreducible.associated_of_dvd pp qp, Associated.dvd⟩ #align irreducible.dvd_irreducible_iff_associated Irreducible.dvd_irreducible_iff_associated theorem Prime.associated_of_dvd [CancelCommMonoidWithZero α] {p q : α} (p_prime : Prime p) (q_prime : Prime q) (dvd : p ∣ q) : Associated p q := p_prime.irreducible.associated_of_dvd q_prime.irreducible dvd #align prime.associated_of_dvd Prime.associated_of_dvd theorem Prime.dvd_prime_iff_associated [CancelCommMonoidWithZero α] {p q : α} (pp : Prime p) (qp : Prime q) : p ∣ q ↔ Associated p q := pp.irreducible.dvd_irreducible_iff_associated qp.irreducible #align prime.dvd_prime_iff_associated Prime.dvd_prime_iff_associated theorem Associated.prime_iff [CommMonoidWithZero α] {p q : α} (h : p ~ᵤ q) : Prime p ↔ Prime q := ⟨h.prime, h.symm.prime⟩ #align associated.prime_iff Associated.prime_iff protected theorem Associated.isUnit [Monoid α] {a b : α} (h : a ~ᵤ b) : IsUnit a → IsUnit b := let ⟨u, hu⟩ := h fun ⟨v, hv⟩ => ⟨v * u, by simp [hv, hu.symm]⟩ #align associated.is_unit Associated.isUnit theorem Associated.isUnit_iff [Monoid α] {a b : α} (h : a ~ᵤ b) : IsUnit a ↔ IsUnit b := ⟨h.isUnit, h.symm.isUnit⟩ #align associated.is_unit_iff Associated.isUnit_iff theorem Irreducible.isUnit_iff_not_associated_of_dvd [Monoid α] {x y : α} (hx : Irreducible x) (hy : y ∣ x) : IsUnit y ↔ ¬ Associated x y := ⟨fun hy hxy => hx.1 (hxy.symm.isUnit hy), (hx.dvd_iff.mp hy).resolve_right⟩ protected theorem Associated.irreducible [Monoid α] {p q : α} (h : p ~ᵤ q) (hp : Irreducible p) : Irreducible q := ⟨mt h.symm.isUnit hp.1, let ⟨u, hu⟩ := h fun a b hab => have hpab : p = a * (b * (u⁻¹ : αˣ)) := calc p = p * u * (u⁻¹ : αˣ) := by simp _ = _ := by rw [hu]; simp [hab, mul_assoc] (hp.isUnit_or_isUnit hpab).elim Or.inl fun ⟨v, hv⟩ => Or.inr ⟨v * u, by simp [hv]⟩⟩ #align associated.irreducible Associated.irreducible protected theorem Associated.irreducible_iff [Monoid α] {p q : α} (h : p ~ᵤ q) : Irreducible p ↔ Irreducible q := ⟨h.irreducible, h.symm.irreducible⟩ #align associated.irreducible_iff Associated.irreducible_iff theorem Associated.of_mul_left [CancelCommMonoidWithZero α] {a b c d : α} (h : a * b ~ᵤ c * d) (h₁ : a ~ᵤ c) (ha : a ≠ 0) : b ~ᵤ d := let ⟨u, hu⟩ := h let ⟨v, hv⟩ := Associated.symm h₁ ⟨u * (v : αˣ), mul_left_cancel₀ ha (by rw [← hv, mul_assoc c (v : α) d, mul_left_comm c, ← hu] simp [hv.symm, mul_assoc, mul_comm, mul_left_comm])⟩ #align associated.of_mul_left Associated.of_mul_left theorem Associated.of_mul_right [CancelCommMonoidWithZero α] {a b c d : α} : a * b ~ᵤ c * d → b ~ᵤ d → b ≠ 0 → a ~ᵤ c := by rw [mul_comm a, mul_comm c]; exact Associated.of_mul_left #align associated.of_mul_right Associated.of_mul_right
Mathlib/Algebra/Associated.lean
755
761
theorem Associated.of_pow_associated_of_prime [CancelCommMonoidWithZero α] {p₁ p₂ : α} {k₁ k₂ : ℕ} (hp₁ : Prime p₁) (hp₂ : Prime p₂) (hk₁ : 0 < k₁) (h : p₁ ^ k₁ ~ᵤ p₂ ^ k₂) : p₁ ~ᵤ p₂ := by
have : p₁ ∣ p₂ ^ k₂ := by rw [← h.dvd_iff_dvd_right] apply dvd_pow_self _ hk₁.ne' rw [← hp₁.dvd_prime_iff_associated hp₂] exact hp₁.dvd_of_dvd_pow this
/- 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, Mitchell Lee -/ import Mathlib.Topology.Algebra.InfiniteSum.Defs import Mathlib.Data.Fintype.BigOperators import Mathlib.Topology.Algebra.Monoid /-! # Lemmas on infinite sums and products in topological monoids This file contains many simple lemmas on `tsum`, `HasSum` etc, which are placed here in order to keep the basic file of definitions as short as possible. Results requiring a group (rather than monoid) structure on the target should go in `Group.lean`. -/ noncomputable section open Filter Finset Function open scoped Topology variable {α β γ δ : Type*} section HasProd variable [CommMonoid α] [TopologicalSpace α] variable {f g : β → α} {a b : α} {s : Finset β} /-- Constant one function has product `1` -/ @[to_additive "Constant zero function has sum `0`"] theorem hasProd_one : HasProd (fun _ ↦ 1 : β → α) 1 := by simp [HasProd, tendsto_const_nhds] #align has_sum_zero hasSum_zero @[to_additive] theorem hasProd_empty [IsEmpty β] : HasProd f 1 := by convert @hasProd_one α β _ _ #align has_sum_empty hasSum_empty @[to_additive] theorem multipliable_one : Multipliable (fun _ ↦ 1 : β → α) := hasProd_one.multipliable #align summable_zero summable_zero @[to_additive] theorem multipliable_empty [IsEmpty β] : Multipliable f := hasProd_empty.multipliable #align summable_empty summable_empty @[to_additive] theorem multipliable_congr (hfg : ∀ b, f b = g b) : Multipliable f ↔ Multipliable g := iff_of_eq (congr_arg Multipliable <| funext hfg) #align summable_congr summable_congr @[to_additive] theorem Multipliable.congr (hf : Multipliable f) (hfg : ∀ b, f b = g b) : Multipliable g := (multipliable_congr hfg).mp hf #align summable.congr Summable.congr @[to_additive] lemma HasProd.congr_fun (hf : HasProd f a) (h : ∀ x : β, g x = f x) : HasProd g a := (funext h : g = f) ▸ hf @[to_additive] theorem HasProd.hasProd_of_prod_eq {g : γ → α} (h_eq : ∀ u : Finset γ, ∃ v : Finset β, ∀ v', v ⊆ v' → ∃ u', u ⊆ u' ∧ ∏ x ∈ u', g x = ∏ b ∈ v', f b) (hf : HasProd g a) : HasProd f a := le_trans (map_atTop_finset_prod_le_of_prod_eq h_eq) hf #align has_sum.has_sum_of_sum_eq HasSum.hasSum_of_sum_eq @[to_additive] theorem hasProd_iff_hasProd {g : γ → α} (h₁ : ∀ u : Finset γ, ∃ v : Finset β, ∀ v', v ⊆ v' → ∃ u', u ⊆ u' ∧ ∏ x ∈ u', g x = ∏ b ∈ v', f b) (h₂ : ∀ v : Finset β, ∃ u : Finset γ, ∀ u', u ⊆ u' → ∃ v', v ⊆ v' ∧ ∏ b ∈ v', f b = ∏ x ∈ u', g x) : HasProd f a ↔ HasProd g a := ⟨HasProd.hasProd_of_prod_eq h₂, HasProd.hasProd_of_prod_eq h₁⟩ #align has_sum_iff_has_sum hasSum_iff_hasSum @[to_additive] theorem Function.Injective.multipliable_iff {g : γ → β} (hg : Injective g) (hf : ∀ x ∉ Set.range g, f x = 1) : Multipliable (f ∘ g) ↔ Multipliable f := exists_congr fun _ ↦ hg.hasProd_iff hf #align function.injective.summable_iff Function.Injective.summable_iff @[to_additive (attr := simp)] theorem hasProd_extend_one {g : β → γ} (hg : Injective g) : HasProd (extend g f 1) a ↔ HasProd f a := by rw [← hg.hasProd_iff, extend_comp hg] exact extend_apply' _ _ @[to_additive (attr := simp)] theorem multipliable_extend_one {g : β → γ} (hg : Injective g) : Multipliable (extend g f 1) ↔ Multipliable f := exists_congr fun _ ↦ hasProd_extend_one hg @[to_additive]
Mathlib/Topology/Algebra/InfiniteSum/Basic.lean
101
104
theorem hasProd_subtype_iff_mulIndicator {s : Set β} : HasProd (f ∘ (↑) : s → α) a ↔ HasProd (s.mulIndicator f) a := by
rw [← Set.mulIndicator_range_comp, Subtype.range_coe, hasProd_subtype_iff_of_mulSupport_subset Set.mulSupport_mulIndicator_subset]
/- 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, Johan Commelin, Mario Carneiro -/ import Mathlib.Algebra.MvPolynomial.Degrees #align_import data.mv_polynomial.variables from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Variables of polynomials This file establishes many results about the variable sets of a multivariate polynomial. The *variable set* of a polynomial $P \in R[X]$ is a `Finset` containing each $x \in X$ that appears in a monomial in $P$. ## Main declarations * `MvPolynomial.vars p` : the finset of variables occurring in `p`. For example if `p = x⁴y+yz` then `vars p = {x, y, z}` ## Notation As in other polynomial files, we typically use the notation: + `σ τ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `r : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` -/ noncomputable section open Set Function Finsupp AddMonoidAlgebra universe u v w variable {R : Type u} {S : Type v} namespace MvPolynomial variable {σ τ : Type*} {r : R} {e : ℕ} {n m : σ} {s : σ →₀ ℕ} section CommSemiring variable [CommSemiring R] {p q : MvPolynomial σ R} section Vars /-! ### `vars` -/ /-- `vars p` is the set of variables appearing in the polynomial `p` -/ def vars (p : MvPolynomial σ R) : Finset σ := letI := Classical.decEq σ p.degrees.toFinset #align mv_polynomial.vars MvPolynomial.vars theorem vars_def [DecidableEq σ] (p : MvPolynomial σ R) : p.vars = p.degrees.toFinset := by rw [vars] convert rfl #align mv_polynomial.vars_def MvPolynomial.vars_def @[simp] theorem vars_0 : (0 : MvPolynomial σ R).vars = ∅ := by classical rw [vars_def, degrees_zero, Multiset.toFinset_zero] #align mv_polynomial.vars_0 MvPolynomial.vars_0 @[simp] theorem vars_monomial (h : r ≠ 0) : (monomial s r).vars = s.support := by classical rw [vars_def, degrees_monomial_eq _ _ h, Finsupp.toFinset_toMultiset] #align mv_polynomial.vars_monomial MvPolynomial.vars_monomial @[simp] theorem vars_C : (C r : MvPolynomial σ R).vars = ∅ := by classical rw [vars_def, degrees_C, Multiset.toFinset_zero] set_option linter.uppercaseLean3 false in #align mv_polynomial.vars_C MvPolynomial.vars_C @[simp] theorem vars_X [Nontrivial R] : (X n : MvPolynomial σ R).vars = {n} := by rw [X, vars_monomial (one_ne_zero' R), Finsupp.support_single_ne_zero _ (one_ne_zero' ℕ)] set_option linter.uppercaseLean3 false in #align mv_polynomial.vars_X MvPolynomial.vars_X theorem mem_vars (i : σ) : i ∈ p.vars ↔ ∃ d ∈ p.support, i ∈ d.support := by classical simp only [vars_def, Multiset.mem_toFinset, mem_degrees, mem_support_iff, exists_prop] #align mv_polynomial.mem_vars MvPolynomial.mem_vars theorem mem_support_not_mem_vars_zero {f : MvPolynomial σ R} {x : σ →₀ ℕ} (H : x ∈ f.support) {v : σ} (h : v ∉ vars f) : x v = 0 := by contrapose! h exact (mem_vars v).mpr ⟨x, H, Finsupp.mem_support_iff.mpr h⟩ #align mv_polynomial.mem_support_not_mem_vars_zero MvPolynomial.mem_support_not_mem_vars_zero theorem vars_add_subset [DecidableEq σ] (p q : MvPolynomial σ R) : (p + q).vars ⊆ p.vars ∪ q.vars := by intro x hx simp only [vars_def, Finset.mem_union, Multiset.mem_toFinset] at hx ⊢ simpa using Multiset.mem_of_le (degrees_add _ _) hx #align mv_polynomial.vars_add_subset MvPolynomial.vars_add_subset theorem vars_add_of_disjoint [DecidableEq σ] (h : Disjoint p.vars q.vars) : (p + q).vars = p.vars ∪ q.vars := by refine (vars_add_subset p q).antisymm fun x hx => ?_ simp only [vars_def, Multiset.disjoint_toFinset] at h hx ⊢ rwa [degrees_add_of_disjoint h, Multiset.toFinset_union] #align mv_polynomial.vars_add_of_disjoint MvPolynomial.vars_add_of_disjoint section Mul theorem vars_mul [DecidableEq σ] (φ ψ : MvPolynomial σ R) : (φ * ψ).vars ⊆ φ.vars ∪ ψ.vars := by simp_rw [vars_def, ← Multiset.toFinset_add, Multiset.toFinset_subset] exact Multiset.subset_of_le (degrees_mul φ ψ) #align mv_polynomial.vars_mul MvPolynomial.vars_mul @[simp] theorem vars_one : (1 : MvPolynomial σ R).vars = ∅ := vars_C #align mv_polynomial.vars_one MvPolynomial.vars_one theorem vars_pow (φ : MvPolynomial σ R) (n : ℕ) : (φ ^ n).vars ⊆ φ.vars := by classical induction' n with n ih · simp · rw [pow_succ'] apply Finset.Subset.trans (vars_mul _ _) exact Finset.union_subset (Finset.Subset.refl _) ih #align mv_polynomial.vars_pow MvPolynomial.vars_pow /-- The variables of the product of a family of polynomials are a subset of the union of the sets of variables of each polynomial. -/
Mathlib/Algebra/MvPolynomial/Variables.lean
146
154
theorem vars_prod {ι : Type*} [DecidableEq σ] {s : Finset ι} (f : ι → MvPolynomial σ R) : (∏ i ∈ s, f i).vars ⊆ s.biUnion fun i => (f i).vars := by
classical induction s using Finset.induction_on with | empty => simp | insert hs hsub => simp only [hs, Finset.biUnion_insert, Finset.prod_insert, not_false_iff] apply Finset.Subset.trans (vars_mul _ _) exact Finset.union_subset_union (Finset.Subset.refl _) hsub
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Order.CompleteLattice import Mathlib.Order.Cover import Mathlib.Order.Iterate import Mathlib.Order.WellFounded #align_import order.succ_pred.basic from "leanprover-community/mathlib"@"0111834459f5d7400215223ea95ae38a1265a907" /-! # Successor and predecessor This file defines successor and predecessor orders. `succ a`, the successor of an element `a : α` is the least element greater than `a`. `pred a` is the greatest element less than `a`. Typical examples include `ℕ`, `ℤ`, `ℕ+`, `Fin n`, but also `ENat`, the lexicographic order of a successor/predecessor order... ## Typeclasses * `SuccOrder`: Order equipped with a sensible successor function. * `PredOrder`: Order equipped with a sensible predecessor function. * `IsSuccArchimedean`: `SuccOrder` where `succ` iterated to an element gives all the greater ones. * `IsPredArchimedean`: `PredOrder` where `pred` iterated to an element gives all the smaller ones. ## Implementation notes Maximal elements don't have a sensible successor. Thus the naïve typeclass ```lean class NaiveSuccOrder (α : Type*) [Preorder α] := (succ : α → α) (succ_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b) (lt_succ_iff : ∀ {a b}, a < succ b ↔ a ≤ b) ``` can't apply to an `OrderTop` because plugging in `a = b = ⊤` into either of `succ_le_iff` and `lt_succ_iff` yields `⊤ < ⊤` (or more generally `m < m` for a maximal element `m`). The solution taken here is to remove the implications `≤ → <` and instead require that `a < succ a` for all non maximal elements (enforced by the combination of `le_succ` and the contrapositive of `max_of_succ_le`). The stricter condition of every element having a sensible successor can be obtained through the combination of `SuccOrder α` and `NoMaxOrder α`. ## TODO Is `GaloisConnection pred succ` always true? If not, we should introduce ```lean class SuccPredOrder (α : Type*) [Preorder α] extends SuccOrder α, PredOrder α := (pred_succ_gc : GaloisConnection (pred : α → α) succ) ``` `CovBy` should help here. -/ open Function OrderDual Set variable {α β : Type*} /-- Order equipped with a sensible successor function. -/ @[ext] class SuccOrder (α : Type*) [Preorder α] where /-- Successor function-/ succ : α → α /-- Proof of basic ordering with respect to `succ`-/ le_succ : ∀ a, a ≤ succ a /-- Proof of interaction between `succ` and maximal element-/ max_of_succ_le {a} : succ a ≤ a → IsMax a /-- Proof that `succ` satisfies ordering invariants between `LT` and `LE`-/ succ_le_of_lt {a b} : a < b → succ a ≤ b /-- Proof that `succ` satisfies ordering invariants between `LE` and `LT`-/ le_of_lt_succ {a b} : a < succ b → a ≤ b #align succ_order SuccOrder #align succ_order.ext_iff SuccOrder.ext_iff #align succ_order.ext SuccOrder.ext /-- Order equipped with a sensible predecessor function. -/ @[ext] class PredOrder (α : Type*) [Preorder α] where /-- Predecessor function-/ pred : α → α /-- Proof of basic ordering with respect to `pred`-/ pred_le : ∀ a, pred a ≤ a /-- Proof of interaction between `pred` and minimal element-/ min_of_le_pred {a} : a ≤ pred a → IsMin a /-- Proof that `pred` satisfies ordering invariants between `LT` and `LE`-/ le_pred_of_lt {a b} : a < b → a ≤ pred b /-- Proof that `pred` satisfies ordering invariants between `LE` and `LT`-/ le_of_pred_lt {a b} : pred a < b → a ≤ b #align pred_order PredOrder #align pred_order.ext PredOrder.ext #align pred_order.ext_iff PredOrder.ext_iff instance [Preorder α] [SuccOrder α] : PredOrder αᵒᵈ where pred := toDual ∘ SuccOrder.succ ∘ ofDual pred_le := by simp only [comp, OrderDual.forall, ofDual_toDual, toDual_le_toDual, SuccOrder.le_succ, implies_true] min_of_le_pred h := by apply SuccOrder.max_of_succ_le h le_pred_of_lt := by intro a b h; exact SuccOrder.succ_le_of_lt h le_of_pred_lt := SuccOrder.le_of_lt_succ instance [Preorder α] [PredOrder α] : SuccOrder αᵒᵈ where succ := toDual ∘ PredOrder.pred ∘ ofDual le_succ := by simp only [comp, OrderDual.forall, ofDual_toDual, toDual_le_toDual, PredOrder.pred_le, implies_true] max_of_succ_le h := by apply PredOrder.min_of_le_pred h succ_le_of_lt := by intro a b h; exact PredOrder.le_pred_of_lt h le_of_lt_succ := PredOrder.le_of_pred_lt section Preorder variable [Preorder α] /-- A constructor for `SuccOrder α` usable when `α` has no maximal element. -/ def SuccOrder.ofSuccLeIffOfLeLtSucc (succ : α → α) (hsucc_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b) (hle_of_lt_succ : ∀ {a b}, a < succ b → a ≤ b) : SuccOrder α := { succ le_succ := fun _ => (hsucc_le_iff.1 le_rfl).le max_of_succ_le := fun ha => (lt_irrefl _ <| hsucc_le_iff.1 ha).elim succ_le_of_lt := fun h => hsucc_le_iff.2 h le_of_lt_succ := fun h => hle_of_lt_succ h} #align succ_order.of_succ_le_iff_of_le_lt_succ SuccOrder.ofSuccLeIffOfLeLtSucc /-- A constructor for `PredOrder α` usable when `α` has no minimal element. -/ def PredOrder.ofLePredIffOfPredLePred (pred : α → α) (hle_pred_iff : ∀ {a b}, a ≤ pred b ↔ a < b) (hle_of_pred_lt : ∀ {a b}, pred a < b → a ≤ b) : PredOrder α := { pred pred_le := fun _ => (hle_pred_iff.1 le_rfl).le min_of_le_pred := fun ha => (lt_irrefl _ <| hle_pred_iff.1 ha).elim le_pred_of_lt := fun h => hle_pred_iff.2 h le_of_pred_lt := fun h => hle_of_pred_lt h } #align pred_order.of_le_pred_iff_of_pred_le_pred PredOrder.ofLePredIffOfPredLePred end Preorder section LinearOrder variable [LinearOrder α] /-- A constructor for `SuccOrder α` for `α` a linear order. -/ @[simps] def SuccOrder.ofCore (succ : α → α) (hn : ∀ {a}, ¬IsMax a → ∀ b, a < b ↔ succ a ≤ b) (hm : ∀ a, IsMax a → succ a = a) : SuccOrder α := { succ succ_le_of_lt := fun {a b} => by_cases (fun h hab => (hm a h).symm ▸ hab.le) fun h => (hn h b).mp le_succ := fun a => by_cases (fun h => (hm a h).symm.le) fun h => le_of_lt <| by simpa using (hn h a).not le_of_lt_succ := fun {a b} hab => by_cases (fun h => hm b h ▸ hab.le) fun h => by simpa [hab] using (hn h a).not max_of_succ_le := fun {a} => not_imp_not.mp fun h => by simpa using (hn h a).not } #align succ_order.of_core SuccOrder.ofCore #align succ_order.of_core_succ SuccOrder.ofCore_succ /-- A constructor for `PredOrder α` for `α` a linear order. -/ @[simps] def PredOrder.ofCore {α} [LinearOrder α] (pred : α → α) (hn : ∀ {a}, ¬IsMin a → ∀ b, b ≤ pred a ↔ b < a) (hm : ∀ a, IsMin a → pred a = a) : PredOrder α := { pred le_pred_of_lt := fun {a b} => by_cases (fun h hab => (hm b h).symm ▸ hab.le) fun h => (hn h a).mpr pred_le := fun a => by_cases (fun h => (hm a h).le) fun h => le_of_lt <| by simpa using (hn h a).not le_of_pred_lt := fun {a b} hab => by_cases (fun h => hm a h ▸ hab.le) fun h => by simpa [hab] using (hn h b).not min_of_le_pred := fun {a} => not_imp_not.mp fun h => by simpa using (hn h a).not } #align pred_order.of_core PredOrder.ofCore #align pred_order.of_core_pred PredOrder.ofCore_pred /-- A constructor for `SuccOrder α` usable when `α` is a linear order with no maximal element. -/ def SuccOrder.ofSuccLeIff (succ : α → α) (hsucc_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b) : SuccOrder α := { succ le_succ := fun _ => (hsucc_le_iff.1 le_rfl).le max_of_succ_le := fun ha => (lt_irrefl _ <| hsucc_le_iff.1 ha).elim succ_le_of_lt := fun h => hsucc_le_iff.2 h le_of_lt_succ := fun {_ _} h => le_of_not_lt ((not_congr hsucc_le_iff).1 h.not_le) } #align succ_order.of_succ_le_iff SuccOrder.ofSuccLeIff /-- A constructor for `PredOrder α` usable when `α` is a linear order with no minimal element. -/ def PredOrder.ofLePredIff (pred : α → α) (hle_pred_iff : ∀ {a b}, a ≤ pred b ↔ a < b) : PredOrder α := { pred pred_le := fun _ => (hle_pred_iff.1 le_rfl).le min_of_le_pred := fun ha => (lt_irrefl _ <| hle_pred_iff.1 ha).elim le_pred_of_lt := fun h => hle_pred_iff.2 h le_of_pred_lt := fun {_ _} h => le_of_not_lt ((not_congr hle_pred_iff).1 h.not_le) } #align pred_order.of_le_pred_iff PredOrder.ofLePredIff open scoped Classical variable (α) /-- A well-order is a `SuccOrder`. -/ noncomputable def SuccOrder.ofLinearWellFoundedLT [WellFoundedLT α] : SuccOrder α := ofCore (fun a ↦ if h : (Ioi a).Nonempty then wellFounded_lt.min _ h else a) (fun ha _ ↦ by rw [not_isMax_iff] at ha simp_rw [Set.Nonempty, mem_Ioi, dif_pos ha] exact ⟨(wellFounded_lt.min_le · ha), lt_of_lt_of_le (wellFounded_lt.min_mem _ ha)⟩) fun a ha ↦ dif_neg (not_not_intro ha <| not_isMax_iff.mpr ·) /-- A linear order with well-founded greater-than relation is a `PredOrder`. -/ noncomputable def PredOrder.ofLinearWellFoundedGT (α) [LinearOrder α] [WellFoundedGT α] : PredOrder α := letI := SuccOrder.ofLinearWellFoundedLT αᵒᵈ; inferInstanceAs (PredOrder αᵒᵈᵒᵈ) end LinearOrder /-! ### Successor order -/ namespace Order section Preorder variable [Preorder α] [SuccOrder α] {a b : α} /-- The successor of an element. If `a` is not maximal, then `succ a` is the least element greater than `a`. If `a` is maximal, then `succ a = a`. -/ def succ : α → α := SuccOrder.succ #align order.succ Order.succ theorem le_succ : ∀ a : α, a ≤ succ a := SuccOrder.le_succ #align order.le_succ Order.le_succ theorem max_of_succ_le {a : α} : succ a ≤ a → IsMax a := SuccOrder.max_of_succ_le #align order.max_of_succ_le Order.max_of_succ_le theorem succ_le_of_lt {a b : α} : a < b → succ a ≤ b := SuccOrder.succ_le_of_lt #align order.succ_le_of_lt Order.succ_le_of_lt theorem le_of_lt_succ {a b : α} : a < succ b → a ≤ b := SuccOrder.le_of_lt_succ #align order.le_of_lt_succ Order.le_of_lt_succ @[simp] theorem succ_le_iff_isMax : succ a ≤ a ↔ IsMax a := ⟨max_of_succ_le, fun h => h <| le_succ _⟩ #align order.succ_le_iff_is_max Order.succ_le_iff_isMax @[simp] theorem lt_succ_iff_not_isMax : a < succ a ↔ ¬IsMax a := ⟨not_isMax_of_lt, fun ha => (le_succ a).lt_of_not_le fun h => ha <| max_of_succ_le h⟩ #align order.lt_succ_iff_not_is_max Order.lt_succ_iff_not_isMax alias ⟨_, lt_succ_of_not_isMax⟩ := lt_succ_iff_not_isMax #align order.lt_succ_of_not_is_max Order.lt_succ_of_not_isMax theorem wcovBy_succ (a : α) : a ⩿ succ a := ⟨le_succ a, fun _ hb => (succ_le_of_lt hb).not_lt⟩ #align order.wcovby_succ Order.wcovBy_succ theorem covBy_succ_of_not_isMax (h : ¬IsMax a) : a ⋖ succ a := (wcovBy_succ a).covBy_of_lt <| lt_succ_of_not_isMax h #align order.covby_succ_of_not_is_max Order.covBy_succ_of_not_isMax theorem lt_succ_iff_of_not_isMax (ha : ¬IsMax a) : b < succ a ↔ b ≤ a := ⟨le_of_lt_succ, fun h => h.trans_lt <| lt_succ_of_not_isMax ha⟩ #align order.lt_succ_iff_of_not_is_max Order.lt_succ_iff_of_not_isMax theorem succ_le_iff_of_not_isMax (ha : ¬IsMax a) : succ a ≤ b ↔ a < b := ⟨(lt_succ_of_not_isMax ha).trans_le, succ_le_of_lt⟩ #align order.succ_le_iff_of_not_is_max Order.succ_le_iff_of_not_isMax lemma succ_lt_succ_of_not_isMax (h : a < b) (hb : ¬ IsMax b) : succ a < succ b := (lt_succ_iff_of_not_isMax hb).2 <| succ_le_of_lt h theorem succ_lt_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) : succ a < succ b ↔ a < b := by rw [lt_succ_iff_of_not_isMax hb, succ_le_iff_of_not_isMax ha] #align order.succ_lt_succ_iff_of_not_is_max Order.succ_lt_succ_iff_of_not_isMax theorem succ_le_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) : succ a ≤ succ b ↔ a ≤ b := by rw [succ_le_iff_of_not_isMax ha, lt_succ_iff_of_not_isMax hb] #align order.succ_le_succ_iff_of_not_is_max Order.succ_le_succ_iff_of_not_isMax @[simp, mono] theorem succ_le_succ (h : a ≤ b) : succ a ≤ succ b := by by_cases hb : IsMax b · by_cases hba : b ≤ a · exact (hb <| hba.trans <| le_succ _).trans (le_succ _) · exact succ_le_of_lt ((h.lt_of_not_le hba).trans_le <| le_succ b) · rwa [succ_le_iff_of_not_isMax fun ha => hb <| ha.mono h, lt_succ_iff_of_not_isMax hb] #align order.succ_le_succ Order.succ_le_succ theorem succ_mono : Monotone (succ : α → α) := fun _ _ => succ_le_succ #align order.succ_mono Order.succ_mono theorem le_succ_iterate (k : ℕ) (x : α) : x ≤ succ^[k] x := by conv_lhs => rw [(by simp only [Function.iterate_id, id] : x = id^[k] x)] exact Monotone.le_iterate_of_le succ_mono le_succ k x #align order.le_succ_iterate Order.le_succ_iterate theorem isMax_iterate_succ_of_eq_of_lt {n m : ℕ} (h_eq : succ^[n] a = succ^[m] a) (h_lt : n < m) : IsMax (succ^[n] a) := by refine max_of_succ_le (le_trans ?_ h_eq.symm.le) have : succ (succ^[n] a) = succ^[n + 1] a := by rw [Function.iterate_succ', comp] rw [this] have h_le : n + 1 ≤ m := Nat.succ_le_of_lt h_lt exact Monotone.monotone_iterate_of_le_map succ_mono (le_succ a) h_le #align order.is_max_iterate_succ_of_eq_of_lt Order.isMax_iterate_succ_of_eq_of_lt theorem isMax_iterate_succ_of_eq_of_ne {n m : ℕ} (h_eq : succ^[n] a = succ^[m] a) (h_ne : n ≠ m) : IsMax (succ^[n] a) := by rcases le_total n m with h | h · exact isMax_iterate_succ_of_eq_of_lt h_eq (lt_of_le_of_ne h h_ne) · rw [h_eq] exact isMax_iterate_succ_of_eq_of_lt h_eq.symm (lt_of_le_of_ne h h_ne.symm) #align order.is_max_iterate_succ_of_eq_of_ne Order.isMax_iterate_succ_of_eq_of_ne theorem Iio_succ_of_not_isMax (ha : ¬IsMax a) : Iio (succ a) = Iic a := Set.ext fun _ => lt_succ_iff_of_not_isMax ha #align order.Iio_succ_of_not_is_max Order.Iio_succ_of_not_isMax theorem Ici_succ_of_not_isMax (ha : ¬IsMax a) : Ici (succ a) = Ioi a := Set.ext fun _ => succ_le_iff_of_not_isMax ha #align order.Ici_succ_of_not_is_max Order.Ici_succ_of_not_isMax theorem Ico_succ_right_of_not_isMax (hb : ¬IsMax b) : Ico a (succ b) = Icc a b := by rw [← Ici_inter_Iio, Iio_succ_of_not_isMax hb, Ici_inter_Iic] #align order.Ico_succ_right_of_not_is_max Order.Ico_succ_right_of_not_isMax theorem Ioo_succ_right_of_not_isMax (hb : ¬IsMax b) : Ioo a (succ b) = Ioc a b := by rw [← Ioi_inter_Iio, Iio_succ_of_not_isMax hb, Ioi_inter_Iic] #align order.Ioo_succ_right_of_not_is_max Order.Ioo_succ_right_of_not_isMax theorem Icc_succ_left_of_not_isMax (ha : ¬IsMax a) : Icc (succ a) b = Ioc a b := by rw [← Ici_inter_Iic, Ici_succ_of_not_isMax ha, Ioi_inter_Iic] #align order.Icc_succ_left_of_not_is_max Order.Icc_succ_left_of_not_isMax theorem Ico_succ_left_of_not_isMax (ha : ¬IsMax a) : Ico (succ a) b = Ioo a b := by rw [← Ici_inter_Iio, Ici_succ_of_not_isMax ha, Ioi_inter_Iio] #align order.Ico_succ_left_of_not_is_max Order.Ico_succ_left_of_not_isMax section NoMaxOrder variable [NoMaxOrder α] theorem lt_succ (a : α) : a < succ a := lt_succ_of_not_isMax <| not_isMax a #align order.lt_succ Order.lt_succ @[simp] theorem lt_succ_iff : a < succ b ↔ a ≤ b := lt_succ_iff_of_not_isMax <| not_isMax b #align order.lt_succ_iff Order.lt_succ_iff @[simp] theorem succ_le_iff : succ a ≤ b ↔ a < b := succ_le_iff_of_not_isMax <| not_isMax a #align order.succ_le_iff Order.succ_le_iff theorem succ_le_succ_iff : succ a ≤ succ b ↔ a ≤ b := by simp #align order.succ_le_succ_iff Order.succ_le_succ_iff theorem succ_lt_succ_iff : succ a < succ b ↔ a < b := by simp #align order.succ_lt_succ_iff Order.succ_lt_succ_iff alias ⟨le_of_succ_le_succ, _⟩ := succ_le_succ_iff #align order.le_of_succ_le_succ Order.le_of_succ_le_succ alias ⟨lt_of_succ_lt_succ, succ_lt_succ⟩ := succ_lt_succ_iff #align order.lt_of_succ_lt_succ Order.lt_of_succ_lt_succ #align order.succ_lt_succ Order.succ_lt_succ theorem succ_strictMono : StrictMono (succ : α → α) := fun _ _ => succ_lt_succ #align order.succ_strict_mono Order.succ_strictMono theorem covBy_succ (a : α) : a ⋖ succ a := covBy_succ_of_not_isMax <| not_isMax a #align order.covby_succ Order.covBy_succ @[simp] theorem Iio_succ (a : α) : Iio (succ a) = Iic a := Iio_succ_of_not_isMax <| not_isMax _ #align order.Iio_succ Order.Iio_succ @[simp] theorem Ici_succ (a : α) : Ici (succ a) = Ioi a := Ici_succ_of_not_isMax <| not_isMax _ #align order.Ici_succ Order.Ici_succ @[simp] theorem Ico_succ_right (a b : α) : Ico a (succ b) = Icc a b := Ico_succ_right_of_not_isMax <| not_isMax _ #align order.Ico_succ_right Order.Ico_succ_right @[simp] theorem Ioo_succ_right (a b : α) : Ioo a (succ b) = Ioc a b := Ioo_succ_right_of_not_isMax <| not_isMax _ #align order.Ioo_succ_right Order.Ioo_succ_right @[simp] theorem Icc_succ_left (a b : α) : Icc (succ a) b = Ioc a b := Icc_succ_left_of_not_isMax <| not_isMax _ #align order.Icc_succ_left Order.Icc_succ_left @[simp] theorem Ico_succ_left (a b : α) : Ico (succ a) b = Ioo a b := Ico_succ_left_of_not_isMax <| not_isMax _ #align order.Ico_succ_left Order.Ico_succ_left end NoMaxOrder end Preorder section PartialOrder variable [PartialOrder α] [SuccOrder α] {a b : α} @[simp] theorem succ_eq_iff_isMax : succ a = a ↔ IsMax a := ⟨fun h => max_of_succ_le h.le, fun h => h.eq_of_ge <| le_succ _⟩ #align order.succ_eq_iff_is_max Order.succ_eq_iff_isMax alias ⟨_, _root_.IsMax.succ_eq⟩ := succ_eq_iff_isMax #align is_max.succ_eq IsMax.succ_eq theorem succ_eq_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) : succ a = succ b ↔ a = b := by rw [eq_iff_le_not_lt, eq_iff_le_not_lt, succ_le_succ_iff_of_not_isMax ha hb, succ_lt_succ_iff_of_not_isMax ha hb] #align order.succ_eq_succ_iff_of_not_is_max Order.succ_eq_succ_iff_of_not_isMax theorem le_le_succ_iff : a ≤ b ∧ b ≤ succ a ↔ b = a ∨ b = succ a := by refine ⟨fun h => or_iff_not_imp_left.2 fun hba : b ≠ a => h.2.antisymm (succ_le_of_lt <| h.1.lt_of_ne <| hba.symm), ?_⟩ rintro (rfl | rfl) · exact ⟨le_rfl, le_succ b⟩ · exact ⟨le_succ a, le_rfl⟩ #align order.le_le_succ_iff Order.le_le_succ_iff theorem _root_.CovBy.succ_eq (h : a ⋖ b) : succ a = b := (succ_le_of_lt h.lt).eq_of_not_lt fun h' => h.2 (lt_succ_of_not_isMax h.lt.not_isMax) h' #align covby.succ_eq CovBy.succ_eq theorem _root_.WCovBy.le_succ (h : a ⩿ b) : b ≤ succ a := by obtain h | rfl := h.covBy_or_eq · exact (CovBy.succ_eq h).ge · exact le_succ _ #align wcovby.le_succ WCovBy.le_succ theorem le_succ_iff_eq_or_le : a ≤ succ b ↔ a = succ b ∨ a ≤ b := by by_cases hb : IsMax b · rw [hb.succ_eq, or_iff_right_of_imp le_of_eq] · rw [← lt_succ_iff_of_not_isMax hb, le_iff_eq_or_lt] #align order.le_succ_iff_eq_or_le Order.le_succ_iff_eq_or_le theorem lt_succ_iff_eq_or_lt_of_not_isMax (hb : ¬IsMax b) : a < succ b ↔ a = b ∨ a < b := (lt_succ_iff_of_not_isMax hb).trans le_iff_eq_or_lt #align order.lt_succ_iff_eq_or_lt_of_not_is_max Order.lt_succ_iff_eq_or_lt_of_not_isMax theorem Iic_succ (a : α) : Iic (succ a) = insert (succ a) (Iic a) := ext fun _ => le_succ_iff_eq_or_le #align order.Iic_succ Order.Iic_succ theorem Icc_succ_right (h : a ≤ succ b) : Icc a (succ b) = insert (succ b) (Icc a b) := by simp_rw [← Ici_inter_Iic, Iic_succ, inter_insert_of_mem (mem_Ici.2 h)] #align order.Icc_succ_right Order.Icc_succ_right theorem Ioc_succ_right (h : a < succ b) : Ioc a (succ b) = insert (succ b) (Ioc a b) := by simp_rw [← Ioi_inter_Iic, Iic_succ, inter_insert_of_mem (mem_Ioi.2 h)] #align order.Ioc_succ_right Order.Ioc_succ_right theorem Iio_succ_eq_insert_of_not_isMax (h : ¬IsMax a) : Iio (succ a) = insert a (Iio a) := ext fun _ => lt_succ_iff_eq_or_lt_of_not_isMax h #align order.Iio_succ_eq_insert_of_not_is_max Order.Iio_succ_eq_insert_of_not_isMax theorem Ico_succ_right_eq_insert_of_not_isMax (h₁ : a ≤ b) (h₂ : ¬IsMax b) : Ico a (succ b) = insert b (Ico a b) := by simp_rw [← Iio_inter_Ici, Iio_succ_eq_insert_of_not_isMax h₂, insert_inter_of_mem (mem_Ici.2 h₁)] #align order.Ico_succ_right_eq_insert_of_not_is_max Order.Ico_succ_right_eq_insert_of_not_isMax theorem Ioo_succ_right_eq_insert_of_not_isMax (h₁ : a < b) (h₂ : ¬IsMax b) : Ioo a (succ b) = insert b (Ioo a b) := by simp_rw [← Iio_inter_Ioi, Iio_succ_eq_insert_of_not_isMax h₂, insert_inter_of_mem (mem_Ioi.2 h₁)] #align order.Ioo_succ_right_eq_insert_of_not_is_max Order.Ioo_succ_right_eq_insert_of_not_isMax section NoMaxOrder variable [NoMaxOrder α] @[simp] theorem succ_eq_succ_iff : succ a = succ b ↔ a = b := succ_eq_succ_iff_of_not_isMax (not_isMax a) (not_isMax b) #align order.succ_eq_succ_iff Order.succ_eq_succ_iff theorem succ_injective : Injective (succ : α → α) := fun _ _ => succ_eq_succ_iff.1 #align order.succ_injective Order.succ_injective theorem succ_ne_succ_iff : succ a ≠ succ b ↔ a ≠ b := succ_injective.ne_iff #align order.succ_ne_succ_iff Order.succ_ne_succ_iff alias ⟨_, succ_ne_succ⟩ := succ_ne_succ_iff #align order.succ_ne_succ Order.succ_ne_succ theorem lt_succ_iff_eq_or_lt : a < succ b ↔ a = b ∨ a < b := lt_succ_iff.trans le_iff_eq_or_lt #align order.lt_succ_iff_eq_or_lt Order.lt_succ_iff_eq_or_lt theorem succ_eq_iff_covBy : succ a = b ↔ a ⋖ b := ⟨by rintro rfl exact covBy_succ _, CovBy.succ_eq⟩ #align order.succ_eq_iff_covby Order.succ_eq_iff_covBy theorem Iio_succ_eq_insert (a : α) : Iio (succ a) = insert a (Iio a) := Iio_succ_eq_insert_of_not_isMax <| not_isMax a #align order.Iio_succ_eq_insert Order.Iio_succ_eq_insert theorem Ico_succ_right_eq_insert (h : a ≤ b) : Ico a (succ b) = insert b (Ico a b) := Ico_succ_right_eq_insert_of_not_isMax h <| not_isMax b #align order.Ico_succ_right_eq_insert Order.Ico_succ_right_eq_insert theorem Ioo_succ_right_eq_insert (h : a < b) : Ioo a (succ b) = insert b (Ioo a b) := Ioo_succ_right_eq_insert_of_not_isMax h <| not_isMax b #align order.Ioo_succ_right_eq_insert Order.Ioo_succ_right_eq_insert end NoMaxOrder section OrderTop variable [OrderTop α] @[simp] theorem succ_top : succ (⊤ : α) = ⊤ := by rw [succ_eq_iff_isMax, isMax_iff_eq_top] #align order.succ_top Order.succ_top -- Porting note (#10618): removing @[simp],`simp` can prove it theorem succ_le_iff_eq_top : succ a ≤ a ↔ a = ⊤ := succ_le_iff_isMax.trans isMax_iff_eq_top #align order.succ_le_iff_eq_top Order.succ_le_iff_eq_top -- Porting note (#10618): removing @[simp],`simp` can prove it theorem lt_succ_iff_ne_top : a < succ a ↔ a ≠ ⊤ := lt_succ_iff_not_isMax.trans not_isMax_iff_ne_top #align order.lt_succ_iff_ne_top Order.lt_succ_iff_ne_top end OrderTop section OrderBot variable [OrderBot α] -- Porting note (#10618): removing @[simp],`simp` can prove it theorem lt_succ_bot_iff [NoMaxOrder α] : a < succ ⊥ ↔ a = ⊥ := by rw [lt_succ_iff, le_bot_iff] #align order.lt_succ_bot_iff Order.lt_succ_bot_iff theorem le_succ_bot_iff : a ≤ succ ⊥ ↔ a = ⊥ ∨ a = succ ⊥ := by rw [le_succ_iff_eq_or_le, le_bot_iff, or_comm] #align order.le_succ_bot_iff Order.le_succ_bot_iff variable [Nontrivial α] theorem bot_lt_succ (a : α) : ⊥ < succ a := (lt_succ_of_not_isMax not_isMax_bot).trans_le <| succ_mono bot_le #align order.bot_lt_succ Order.bot_lt_succ theorem succ_ne_bot (a : α) : succ a ≠ ⊥ := (bot_lt_succ a).ne' #align order.succ_ne_bot Order.succ_ne_bot end OrderBot end PartialOrder /-- There is at most one way to define the successors in a `PartialOrder`. -/ instance [PartialOrder α] : Subsingleton (SuccOrder α) := ⟨by intro h₀ h₁ ext a by_cases ha : IsMax a · exact (@IsMax.succ_eq _ _ h₀ _ ha).trans ha.succ_eq.symm · exact @CovBy.succ_eq _ _ h₀ _ _ (covBy_succ_of_not_isMax ha)⟩ section CompleteLattice variable [CompleteLattice α] [SuccOrder α] theorem succ_eq_iInf (a : α) : succ a = ⨅ (b) (_ : a < b), b := by refine le_antisymm (le_iInf fun b => le_iInf succ_le_of_lt) ?_ obtain rfl | ha := eq_or_ne a ⊤ · rw [succ_top] exact le_top exact iInf₂_le _ (lt_succ_iff_ne_top.2 ha) #align order.succ_eq_infi Order.succ_eq_iInf end CompleteLattice /-! ### Predecessor order -/ section Preorder variable [Preorder α] [PredOrder α] {a b : α} /-- The predecessor of an element. If `a` is not minimal, then `pred a` is the greatest element less than `a`. If `a` is minimal, then `pred a = a`. -/ def pred : α → α := PredOrder.pred #align order.pred Order.pred theorem pred_le : ∀ a : α, pred a ≤ a := PredOrder.pred_le #align order.pred_le Order.pred_le theorem min_of_le_pred {a : α} : a ≤ pred a → IsMin a := PredOrder.min_of_le_pred #align order.min_of_le_pred Order.min_of_le_pred theorem le_pred_of_lt {a b : α} : a < b → a ≤ pred b := PredOrder.le_pred_of_lt #align order.le_pred_of_lt Order.le_pred_of_lt theorem le_of_pred_lt {a b : α} : pred a < b → a ≤ b := PredOrder.le_of_pred_lt #align order.le_of_pred_lt Order.le_of_pred_lt @[simp] theorem le_pred_iff_isMin : a ≤ pred a ↔ IsMin a := ⟨min_of_le_pred, fun h => h <| pred_le _⟩ #align order.le_pred_iff_is_min Order.le_pred_iff_isMin @[simp] theorem pred_lt_iff_not_isMin : pred a < a ↔ ¬IsMin a := ⟨not_isMin_of_lt, fun ha => (pred_le a).lt_of_not_le fun h => ha <| min_of_le_pred h⟩ #align order.pred_lt_iff_not_is_min Order.pred_lt_iff_not_isMin alias ⟨_, pred_lt_of_not_isMin⟩ := pred_lt_iff_not_isMin #align order.pred_lt_of_not_is_min Order.pred_lt_of_not_isMin theorem pred_wcovBy (a : α) : pred a ⩿ a := ⟨pred_le a, fun _ hb => (le_of_pred_lt hb).not_lt⟩ #align order.pred_wcovby Order.pred_wcovBy theorem pred_covBy_of_not_isMin (h : ¬IsMin a) : pred a ⋖ a := (pred_wcovBy a).covBy_of_lt <| pred_lt_of_not_isMin h #align order.pred_covby_of_not_is_min Order.pred_covBy_of_not_isMin theorem pred_lt_iff_of_not_isMin (ha : ¬IsMin a) : pred a < b ↔ a ≤ b := ⟨le_of_pred_lt, (pred_lt_of_not_isMin ha).trans_le⟩ #align order.pred_lt_iff_of_not_is_min Order.pred_lt_iff_of_not_isMin theorem le_pred_iff_of_not_isMin (ha : ¬IsMin a) : b ≤ pred a ↔ b < a := ⟨fun h => h.trans_lt <| pred_lt_of_not_isMin ha, le_pred_of_lt⟩ #align order.le_pred_iff_of_not_is_min Order.le_pred_iff_of_not_isMin lemma pred_lt_pred_of_not_isMin (h : a < b) (ha : ¬ IsMin a) : pred a < pred b := (pred_lt_iff_of_not_isMin ha).2 <| le_pred_of_lt h theorem pred_lt_pred_iff_of_not_isMin (ha : ¬IsMin a) (hb : ¬IsMin b) : pred a < pred b ↔ a < b := by rw [pred_lt_iff_of_not_isMin ha, le_pred_iff_of_not_isMin hb] theorem pred_le_pred_iff_of_not_isMin (ha : ¬IsMin a) (hb : ¬IsMin b) : pred a ≤ pred b ↔ a ≤ b := by rw [le_pred_iff_of_not_isMin hb, pred_lt_iff_of_not_isMin ha] @[simp, mono] theorem pred_le_pred {a b : α} (h : a ≤ b) : pred a ≤ pred b := succ_le_succ h.dual #align order.pred_le_pred Order.pred_le_pred theorem pred_mono : Monotone (pred : α → α) := fun _ _ => pred_le_pred #align order.pred_mono Order.pred_mono theorem pred_iterate_le (k : ℕ) (x : α) : pred^[k] x ≤ x := by conv_rhs => rw [(by simp only [Function.iterate_id, id] : x = id^[k] x)] exact Monotone.iterate_le_of_le pred_mono pred_le k x #align order.pred_iterate_le Order.pred_iterate_le theorem isMin_iterate_pred_of_eq_of_lt {n m : ℕ} (h_eq : pred^[n] a = pred^[m] a) (h_lt : n < m) : IsMin (pred^[n] a) := @isMax_iterate_succ_of_eq_of_lt αᵒᵈ _ _ _ _ _ h_eq h_lt #align order.is_min_iterate_pred_of_eq_of_lt Order.isMin_iterate_pred_of_eq_of_lt theorem isMin_iterate_pred_of_eq_of_ne {n m : ℕ} (h_eq : pred^[n] a = pred^[m] a) (h_ne : n ≠ m) : IsMin (pred^[n] a) := @isMax_iterate_succ_of_eq_of_ne αᵒᵈ _ _ _ _ _ h_eq h_ne #align order.is_min_iterate_pred_of_eq_of_ne Order.isMin_iterate_pred_of_eq_of_ne theorem Ioi_pred_of_not_isMin (ha : ¬IsMin a) : Ioi (pred a) = Ici a := Set.ext fun _ => pred_lt_iff_of_not_isMin ha #align order.Ioi_pred_of_not_is_min Order.Ioi_pred_of_not_isMin theorem Iic_pred_of_not_isMin (ha : ¬IsMin a) : Iic (pred a) = Iio a := Set.ext fun _ => le_pred_iff_of_not_isMin ha #align order.Iic_pred_of_not_is_min Order.Iic_pred_of_not_isMin theorem Ioc_pred_left_of_not_isMin (ha : ¬IsMin a) : Ioc (pred a) b = Icc a b := by rw [← Ioi_inter_Iic, Ioi_pred_of_not_isMin ha, Ici_inter_Iic] #align order.Ioc_pred_left_of_not_is_min Order.Ioc_pred_left_of_not_isMin theorem Ioo_pred_left_of_not_isMin (ha : ¬IsMin a) : Ioo (pred a) b = Ico a b := by rw [← Ioi_inter_Iio, Ioi_pred_of_not_isMin ha, Ici_inter_Iio] #align order.Ioo_pred_left_of_not_is_min Order.Ioo_pred_left_of_not_isMin theorem Icc_pred_right_of_not_isMin (ha : ¬IsMin b) : Icc a (pred b) = Ico a b := by rw [← Ici_inter_Iic, Iic_pred_of_not_isMin ha, Ici_inter_Iio] #align order.Icc_pred_right_of_not_is_min Order.Icc_pred_right_of_not_isMin theorem Ioc_pred_right_of_not_isMin (ha : ¬IsMin b) : Ioc a (pred b) = Ioo a b := by rw [← Ioi_inter_Iic, Iic_pred_of_not_isMin ha, Ioi_inter_Iio] #align order.Ioc_pred_right_of_not_is_min Order.Ioc_pred_right_of_not_isMin section NoMinOrder variable [NoMinOrder α] theorem pred_lt (a : α) : pred a < a := pred_lt_of_not_isMin <| not_isMin a #align order.pred_lt Order.pred_lt @[simp] theorem pred_lt_iff : pred a < b ↔ a ≤ b := pred_lt_iff_of_not_isMin <| not_isMin a #align order.pred_lt_iff Order.pred_lt_iff @[simp] theorem le_pred_iff : a ≤ pred b ↔ a < b := le_pred_iff_of_not_isMin <| not_isMin b #align order.le_pred_iff Order.le_pred_iff
Mathlib/Order/SuccPred/Basic.lean
740
740
theorem pred_le_pred_iff : pred a ≤ pred b ↔ a ≤ b := by
simp
/- Copyright (c) 2020 Yury Kudryashov, Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Anne Baanen -/ import Mathlib.Algebra.BigOperators.Ring import Mathlib.Data.Fintype.BigOperators import Mathlib.Data.Fintype.Fin import Mathlib.GroupTheory.GroupAction.Pi import Mathlib.Logic.Equiv.Fin #align_import algebra.big_operators.fin from "leanprover-community/mathlib"@"cc5dd6244981976cc9da7afc4eee5682b037a013" /-! # Big operators and `Fin` Some results about products and sums over the type `Fin`. The most important results are the induction formulas `Fin.prod_univ_castSucc` and `Fin.prod_univ_succ`, and the formula `Fin.prod_const` for the product of a constant function. These results have variants for sums instead of products. ## Main declarations * `finFunctionFinEquiv`: An explicit equivalence between `Fin n → Fin m` and `Fin (m ^ n)`. -/ open Finset variable {α : Type*} {β : Type*} namespace Finset @[to_additive] theorem prod_range [CommMonoid β] {n : ℕ} (f : ℕ → β) : ∏ i ∈ Finset.range n, f i = ∏ i : Fin n, f i := (Fin.prod_univ_eq_prod_range _ _).symm #align finset.prod_range Finset.prod_range #align finset.sum_range Finset.sum_range end Finset namespace Fin @[to_additive] theorem prod_ofFn [CommMonoid β] {n : ℕ} (f : Fin n → β) : (List.ofFn f).prod = ∏ i, f i := by simp [prod_eq_multiset_prod] #align fin.prod_of_fn Fin.prod_ofFn #align fin.sum_of_fn Fin.sum_ofFn @[to_additive] theorem prod_univ_def [CommMonoid β] {n : ℕ} (f : Fin n → β) : ∏ i, f i = ((List.finRange n).map f).prod := by rw [← List.ofFn_eq_map, prod_ofFn] #align fin.prod_univ_def Fin.prod_univ_def #align fin.sum_univ_def Fin.sum_univ_def /-- A product of a function `f : Fin 0 → β` is `1` because `Fin 0` is empty -/ @[to_additive "A sum of a function `f : Fin 0 → β` is `0` because `Fin 0` is empty"] theorem prod_univ_zero [CommMonoid β] (f : Fin 0 → β) : ∏ i, f i = 1 := rfl #align fin.prod_univ_zero Fin.prod_univ_zero #align fin.sum_univ_zero Fin.sum_univ_zero /-- A product of a function `f : Fin (n + 1) → β` over all `Fin (n + 1)` is the product of `f x`, for some `x : Fin (n + 1)` times the remaining product -/ @[to_additive "A sum of a function `f : Fin (n + 1) → β` over all `Fin (n + 1)` is the sum of `f x`, for some `x : Fin (n + 1)` plus the remaining product"] theorem prod_univ_succAbove [CommMonoid β] {n : ℕ} (f : Fin (n + 1) → β) (x : Fin (n + 1)) : ∏ i, f i = f x * ∏ i : Fin n, f (x.succAbove i) := by rw [univ_succAbove, prod_cons, Finset.prod_map _ x.succAboveEmb] rfl #align fin.prod_univ_succ_above Fin.prod_univ_succAbove #align fin.sum_univ_succ_above Fin.sum_univ_succAbove /-- A product of a function `f : Fin (n + 1) → β` over all `Fin (n + 1)` is the product of `f 0` plus the remaining product -/ @[to_additive "A sum of a function `f : Fin (n + 1) → β` over all `Fin (n + 1)` is the sum of `f 0` plus the remaining product"] theorem prod_univ_succ [CommMonoid β] {n : ℕ} (f : Fin (n + 1) → β) : ∏ i, f i = f 0 * ∏ i : Fin n, f i.succ := prod_univ_succAbove f 0 #align fin.prod_univ_succ Fin.prod_univ_succ #align fin.sum_univ_succ Fin.sum_univ_succ /-- A product of a function `f : Fin (n + 1) → β` over all `Fin (n + 1)` is the product of `f (Fin.last n)` plus the remaining product -/ @[to_additive "A sum of a function `f : Fin (n + 1) → β` over all `Fin (n + 1)` is the sum of `f (Fin.last n)` plus the remaining sum"] theorem prod_univ_castSucc [CommMonoid β] {n : ℕ} (f : Fin (n + 1) → β) : ∏ i, f i = (∏ i : Fin n, f (Fin.castSucc i)) * f (last n) := by simpa [mul_comm] using prod_univ_succAbove f (last n) #align fin.prod_univ_cast_succ Fin.prod_univ_castSucc #align fin.sum_univ_cast_succ Fin.sum_univ_castSucc @[to_additive (attr := simp)] theorem prod_univ_get [CommMonoid α] (l : List α) : ∏ i, l.get i = l.prod := by simp [Finset.prod_eq_multiset_prod] @[to_additive (attr := simp)]
Mathlib/Algebra/BigOperators/Fin.lean
101
103
theorem prod_univ_get' [CommMonoid β] (l : List α) (f : α → β) : ∏ i, f (l.get i) = (l.map f).prod := by
simp [Finset.prod_eq_multiset_prod]
/- Copyright (c) 2020 Jannis Limperg. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jannis Limperg -/ import Mathlib.Data.List.OfFn import Mathlib.Data.List.Range #align_import data.list.indexes from "leanprover-community/mathlib"@"8631e2d5ea77f6c13054d9151d82b83069680cb1" /-! # Lemmas about List.*Idx functions. Some specification lemmas for `List.mapIdx`, `List.mapIdxM`, `List.foldlIdx` and `List.foldrIdx`. -/ assert_not_exists MonoidWithZero universe u v open Function namespace List variable {α : Type u} {β : Type v} section MapIdx -- Porting note: Add back old definition because it's easier for writing proofs. /-- Lean3 `map_with_index` helper function -/ protected def oldMapIdxCore (f : ℕ → α → β) : ℕ → List α → List β | _, [] => [] | k, a :: as => f k a :: List.oldMapIdxCore f (k + 1) as /-- Given a function `f : ℕ → α → β` and `as : List α`, `as = [a₀, a₁, ...]`, returns the list `[f 0 a₀, f 1 a₁, ...]`. -/ protected def oldMapIdx (f : ℕ → α → β) (as : List α) : List β := List.oldMapIdxCore f 0 as @[simp] theorem mapIdx_nil {α β} (f : ℕ → α → β) : mapIdx f [] = [] := rfl #align list.map_with_index_nil List.mapIdx_nil -- Porting note (#10756): new theorem. protected theorem oldMapIdxCore_eq (l : List α) (f : ℕ → α → β) (n : ℕ) : l.oldMapIdxCore f n = l.oldMapIdx fun i a ↦ f (i + n) a := by induction' l with hd tl hl generalizing f n · rfl · rw [List.oldMapIdx] simp only [List.oldMapIdxCore, hl, Nat.add_left_comm, Nat.add_comm, Nat.add_zero] #noalign list.map_with_index_core_eq -- Porting note: convert new definition to old definition. -- A few new theorems are added to achieve this -- 1. Prove that `oldMapIdxCore f (l ++ [e]) = oldMapIdxCore f l ++ [f l.length e]` -- 2. Prove that `oldMapIdx f (l ++ [e]) = oldMapIdx f l ++ [f l.length e]` -- 3. Prove list induction using `∀ l e, p [] → (p l → p (l ++ [e])) → p l` -- Porting note (#10756): new theorem. theorem list_reverse_induction (p : List α → Prop) (base : p []) (ind : ∀ (l : List α) (e : α), p l → p (l ++ [e])) : (∀ (l : List α), p l) := by let q := fun l ↦ p (reverse l) have pq : ∀ l, p (reverse l) → q l := by simp only [q, reverse_reverse]; intro; exact id have qp : ∀ l, q (reverse l) → p l := by simp only [q, reverse_reverse]; intro; exact id intro l apply qp generalize (reverse l) = l induction' l with head tail ih · apply pq; simp only [reverse_nil, base] · apply pq; simp only [reverse_cons]; apply ind; apply qp; rw [reverse_reverse]; exact ih -- Porting note (#10756): new theorem. protected theorem oldMapIdxCore_append : ∀ (f : ℕ → α → β) (n : ℕ) (l₁ l₂ : List α), List.oldMapIdxCore f n (l₁ ++ l₂) = List.oldMapIdxCore f n l₁ ++ List.oldMapIdxCore f (n + l₁.length) l₂ := by intros f n l₁ l₂ generalize e : (l₁ ++ l₂).length = len revert n l₁ l₂ induction' len with len ih <;> intros n l₁ l₂ h · have l₁_nil : l₁ = [] := by cases l₁ · rfl · contradiction have l₂_nil : l₂ = [] := by cases l₂ · rfl · rw [List.length_append] at h; contradiction simp only [l₁_nil, l₂_nil]; rfl · cases' l₁ with head tail · rfl · simp only [List.oldMapIdxCore, List.append_eq, length_cons, cons_append,cons.injEq, true_and] suffices n + Nat.succ (length tail) = n + 1 + tail.length by rw [this] apply ih (n + 1) _ _ _ simp only [cons_append, length_cons, length_append, Nat.succ.injEq] at h simp only [length_append, h] rw [Nat.add_assoc]; simp only [Nat.add_comm] -- Porting note (#10756): new theorem. protected theorem oldMapIdx_append : ∀ (f : ℕ → α → β) (l : List α) (e : α), List.oldMapIdx f (l ++ [e]) = List.oldMapIdx f l ++ [f l.length e] := by intros f l e unfold List.oldMapIdx rw [List.oldMapIdxCore_append f 0 l [e]] simp only [Nat.zero_add]; rfl -- Porting note (#10756): new theorem. theorem mapIdxGo_append : ∀ (f : ℕ → α → β) (l₁ l₂ : List α) (arr : Array β), mapIdx.go f (l₁ ++ l₂) arr = mapIdx.go f l₂ (List.toArray (mapIdx.go f l₁ arr)) := by intros f l₁ l₂ arr generalize e : (l₁ ++ l₂).length = len revert l₁ l₂ arr induction' len with len ih <;> intros l₁ l₂ arr h · have l₁_nil : l₁ = [] := by cases l₁ · rfl · contradiction have l₂_nil : l₂ = [] := by cases l₂ · rfl · rw [List.length_append] at h; contradiction rw [l₁_nil, l₂_nil]; simp only [mapIdx.go, Array.toList_eq, Array.toArray_data] · cases' l₁ with head tail <;> simp only [mapIdx.go] · simp only [nil_append, Array.toList_eq, Array.toArray_data] · simp only [List.append_eq] rw [ih] · simp only [cons_append, length_cons, length_append, Nat.succ.injEq] at h simp only [length_append, h] -- Porting note (#10756): new theorem. theorem mapIdxGo_length : ∀ (f : ℕ → α → β) (l : List α) (arr : Array β), length (mapIdx.go f l arr) = length l + arr.size := by intro f l induction' l with head tail ih · intro; simp only [mapIdx.go, Array.toList_eq, length_nil, Nat.zero_add] · intro; simp only [mapIdx.go]; rw [ih]; simp only [Array.size_push, length_cons]; simp only [Nat.add_succ, add_zero, Nat.add_comm] -- Porting note (#10756): new theorem. theorem mapIdx_append_one : ∀ (f : ℕ → α → β) (l : List α) (e : α), mapIdx f (l ++ [e]) = mapIdx f l ++ [f l.length e] := by intros f l e unfold mapIdx rw [mapIdxGo_append f l [e]] simp only [mapIdx.go, Array.size_toArray, mapIdxGo_length, length_nil, Nat.add_zero, Array.toList_eq, Array.push_data, Array.data_toArray] -- Porting note (#10756): new theorem. protected theorem new_def_eq_old_def : ∀ (f : ℕ → α → β) (l : List α), l.mapIdx f = List.oldMapIdx f l := by intro f apply list_reverse_induction · rfl · intro l e h rw [List.oldMapIdx_append, mapIdx_append_one, h] @[local simp] theorem map_enumFrom_eq_zipWith : ∀ (l : List α) (n : ℕ) (f : ℕ → α → β), map (uncurry f) (enumFrom n l) = zipWith (fun i ↦ f (i + n)) (range (length l)) l := by intro l generalize e : l.length = len revert l induction' len with len ih <;> intros l e n f · have : l = [] := by cases l · rfl · contradiction rw [this]; rfl · cases' l with head tail · contradiction · simp only [map, uncurry_apply_pair, range_succ_eq_map, zipWith, Nat.zero_add, zipWith_map_left] rw [ih] · suffices (fun i ↦ f (i + (n + 1))) = ((fun i ↦ f (i + n)) ∘ Nat.succ) by rw [this] rfl funext n' a simp only [comp, Nat.add_assoc, Nat.add_comm, Nat.add_succ] simp only [length_cons, Nat.succ.injEq] at e; exact e theorem mapIdx_eq_enum_map (l : List α) (f : ℕ → α → β) : l.mapIdx f = l.enum.map (Function.uncurry f) := by rw [List.new_def_eq_old_def] induction' l with hd tl hl generalizing f · rfl · rw [List.oldMapIdx, List.oldMapIdxCore, List.oldMapIdxCore_eq, hl] simp [map, enum_eq_zip_range, map_uncurry_zip_eq_zipWith] #align list.map_with_index_eq_enum_map List.mapIdx_eq_enum_map @[simp] theorem mapIdx_cons (l : List α) (f : ℕ → α → β) (a : α) : mapIdx f (a :: l) = f 0 a :: mapIdx (fun i ↦ f (i + 1)) l := by simp [mapIdx_eq_enum_map, enum_eq_zip_range, map_uncurry_zip_eq_zipWith, range_succ_eq_map, zipWith_map_left] #align list.map_with_index_cons List.mapIdx_cons theorem mapIdx_append (K L : List α) (f : ℕ → α → β) : (K ++ L).mapIdx f = K.mapIdx f ++ L.mapIdx fun i a ↦ f (i + K.length) a := by induction' K with a J IH generalizing f · rfl · simp [IH fun i ↦ f (i + 1), Nat.add_assoc, Nat.succ_eq_add_one] #align list.map_with_index_append List.mapIdx_append @[simp] theorem length_mapIdx (l : List α) (f : ℕ → α → β) : (l.mapIdx f).length = l.length := by induction' l with hd tl IH generalizing f · rfl · simp [IH] #align list.length_map_with_index List.length_mapIdx @[simp] theorem mapIdx_eq_nil {f : ℕ → α → β} {l : List α} : List.mapIdx f l = [] ↔ l = [] := by rw [List.mapIdx_eq_enum_map, List.map_eq_nil, List.enum_eq_nil] set_option linter.deprecated false in @[simp, deprecated (since := "2023-02-11")] theorem nthLe_mapIdx (l : List α) (f : ℕ → α → β) (i : ℕ) (h : i < l.length) (h' : i < (l.mapIdx f).length := h.trans_le (l.length_mapIdx f).ge) : (l.mapIdx f).nthLe i h' = f i (l.nthLe i h) := by simp [mapIdx_eq_enum_map, enum_eq_zip_range] #align list.nth_le_map_with_index List.nthLe_mapIdx theorem mapIdx_eq_ofFn (l : List α) (f : ℕ → α → β) : l.mapIdx f = ofFn fun i : Fin l.length ↦ f (i : ℕ) (l.get i) := by induction l generalizing f with | nil => simp | cons _ _ IH => simp [IH] #align list.map_with_index_eq_of_fn List.mapIdx_eq_ofFn end MapIdx section FoldrIdx -- Porting note: Changed argument order of `foldrIdxSpec` to align better with `foldrIdx`. /-- Specification of `foldrIdx`. -/ def foldrIdxSpec (f : ℕ → α → β → β) (b : β) (as : List α) (start : ℕ) : β := foldr (uncurry f) b <| enumFrom start as #align list.foldr_with_index_aux_spec List.foldrIdxSpecₓ theorem foldrIdxSpec_cons (f : ℕ → α → β → β) (b a as start) : foldrIdxSpec f b (a :: as) start = f start a (foldrIdxSpec f b as (start + 1)) := rfl #align list.foldr_with_index_aux_spec_cons List.foldrIdxSpec_consₓ theorem foldrIdx_eq_foldrIdxSpec (f : ℕ → α → β → β) (b as start) : foldrIdx f b as start = foldrIdxSpec f b as start := by induction as generalizing start · rfl · simp only [foldrIdx, foldrIdxSpec_cons, *] #align list.foldr_with_index_aux_eq_foldr_with_index_aux_spec List.foldrIdx_eq_foldrIdxSpecₓ theorem foldrIdx_eq_foldr_enum (f : ℕ → α → β → β) (b : β) (as : List α) : foldrIdx f b as = foldr (uncurry f) b (enum as) := by simp only [foldrIdx, foldrIdxSpec, foldrIdx_eq_foldrIdxSpec, enum] #align list.foldr_with_index_eq_foldr_enum List.foldrIdx_eq_foldr_enum end FoldrIdx theorem indexesValues_eq_filter_enum (p : α → Prop) [DecidablePred p] (as : List α) : indexesValues p as = filter (p ∘ Prod.snd) (enum as) := by simp (config := { unfoldPartialApp := true }) [indexesValues, foldrIdx_eq_foldr_enum, uncurry, filter_eq_foldr, cond_eq_if] #align list.indexes_values_eq_filter_enum List.indexesValues_eq_filter_enum theorem findIdxs_eq_map_indexesValues (p : α → Prop) [DecidablePred p] (as : List α) : findIdxs p as = map Prod.fst (indexesValues p as) := by simp (config := { unfoldPartialApp := true }) only [indexesValues_eq_filter_enum, map_filter_eq_foldr, findIdxs, uncurry, foldrIdx_eq_foldr_enum, decide_eq_true_eq, comp_apply, Bool.cond_decide] #align list.find_indexes_eq_map_indexes_values List.findIdxs_eq_map_indexesValues section FindIdx -- TODO: upstream to Batteries theorem findIdx_eq_length {p : α → Bool} {xs : List α} : xs.findIdx p = xs.length ↔ ∀ x ∈ xs, ¬p x := by induction xs with | nil => simp_all | cons x xs ih => rw [findIdx_cons, length_cons] constructor <;> intro h · have : ¬p x := by contrapose h; simp_all simp_all · simp_rw [h x (mem_cons_self x xs), cond_false, Nat.succ.injEq, ih] exact fun y hy ↦ h y <| mem_cons.mpr (Or.inr hy) theorem findIdx_le_length (p : α → Bool) {xs : List α} : xs.findIdx p ≤ xs.length := by by_cases e : ∃ x ∈ xs, p x · exact (findIdx_lt_length_of_exists e).le · push_neg at e; exact (findIdx_eq_length.mpr e).le theorem findIdx_lt_length {p : α → Bool} {xs : List α} : xs.findIdx p < xs.length ↔ ∃ x ∈ xs, p x := by rw [← not_iff_not, not_lt] have := @le_antisymm_iff _ _ (xs.findIdx p) xs.length simp only [findIdx_le_length, true_and] at this rw [← this, findIdx_eq_length, not_exists] simp only [Bool.not_eq_true, not_and] /-- `p` does not hold for elements with indices less than `xs.findIdx p`. -/ theorem not_of_lt_findIdx {p : α → Bool} {xs : List α} {i : ℕ} (h : i < xs.findIdx p) : ¬p (xs.get ⟨i, h.trans_le (findIdx_le_length p)⟩) := by revert i induction xs with | nil => intro i h; rw [findIdx_nil] at h; omega | cons x xs ih => intro i h have ho := h rw [findIdx_cons] at h have npx : ¬p x := by by_contra y; rw [y, cond_true] at h; omega simp_rw [npx, cond_false] at h cases' i.eq_zero_or_pos with e e · simpa only [e, Fin.zero_eta, get_cons_zero] · have ipm := Nat.succ_pred_eq_of_pos e have ilt := ho.trans_le (findIdx_le_length p) rw [(Fin.mk_eq_mk (h' := ipm ▸ ilt)).mpr ipm.symm, get_cons_succ] rw [← ipm, Nat.succ_lt_succ_iff] at h exact ih h theorem le_findIdx_of_not {p : α → Bool} {xs : List α} {i : ℕ} (h : i < xs.length) (h2 : ∀ j (hji : j < i), ¬p (xs.get ⟨j, hji.trans h⟩)) : i ≤ xs.findIdx p := by by_contra! f exact absurd (@findIdx_get _ p xs (f.trans h)) (h2 (xs.findIdx p) f) theorem lt_findIdx_of_not {p : α → Bool} {xs : List α} {i : ℕ} (h : i < xs.length) (h2 : ∀ j (hji : j ≤ i), ¬p (xs.get ⟨j, hji.trans_lt h⟩)) : i < xs.findIdx p := by by_contra! f exact absurd (@findIdx_get _ p xs (f.trans_lt h)) (h2 (xs.findIdx p) f) theorem findIdx_eq {p : α → Bool} {xs : List α} {i : ℕ} (h : i < xs.length) : xs.findIdx p = i ↔ p (xs.get ⟨i, h⟩) ∧ ∀ j (hji : j < i), ¬p (xs.get ⟨j, hji.trans h⟩) := by refine ⟨fun f ↦ ⟨f ▸ (@findIdx_get _ p xs (f ▸ h)), fun _ hji ↦ not_of_lt_findIdx (f ▸ hji)⟩, fun ⟨h1, h2⟩ ↦ ?_⟩ apply Nat.le_antisymm _ (le_findIdx_of_not h h2) contrapose! h1 exact not_of_lt_findIdx h1 end FindIdx section FoldlIdx -- Porting note: Changed argument order of `foldlIdxSpec` to align better with `foldlIdx`. /-- Specification of `foldlIdx`. -/ def foldlIdxSpec (f : ℕ → α → β → α) (a : α) (bs : List β) (start : ℕ) : α := foldl (fun a p ↦ f p.fst a p.snd) a <| enumFrom start bs #align list.foldl_with_index_aux_spec List.foldlIdxSpecₓ theorem foldlIdxSpec_cons (f : ℕ → α → β → α) (a b bs start) : foldlIdxSpec f a (b :: bs) start = foldlIdxSpec f (f start a b) bs (start + 1) := rfl #align list.foldl_with_index_aux_spec_cons List.foldlIdxSpec_consₓ theorem foldlIdx_eq_foldlIdxSpec (f : ℕ → α → β → α) (a bs start) : foldlIdx f a bs start = foldlIdxSpec f a bs start := by induction bs generalizing start a · rfl · simp [foldlIdxSpec, *] #align list.foldl_with_index_aux_eq_foldl_with_index_aux_spec List.foldlIdx_eq_foldlIdxSpecₓ theorem foldlIdx_eq_foldl_enum (f : ℕ → α → β → α) (a : α) (bs : List β) : foldlIdx f a bs = foldl (fun a p ↦ f p.fst a p.snd) a (enum bs) := by simp only [foldlIdx, foldlIdxSpec, foldlIdx_eq_foldlIdxSpec, enum] #align list.foldl_with_index_eq_foldl_enum List.foldlIdx_eq_foldl_enum end FoldlIdx section FoldIdxM -- Porting note: `foldrM_eq_foldr` now depends on `[LawfulMonad m]` variable {m : Type u → Type v} [Monad m] theorem foldrIdxM_eq_foldrM_enum {β} (f : ℕ → α → β → m β) (b : β) (as : List α) [LawfulMonad m] : foldrIdxM f b as = foldrM (uncurry f) b (enum as) := by simp (config := { unfoldPartialApp := true }) only [foldrIdxM, foldrM_eq_foldr, foldrIdx_eq_foldr_enum, uncurry] #align list.mfoldr_with_index_eq_mfoldr_enum List.foldrIdxM_eq_foldrM_enum theorem foldlIdxM_eq_foldlM_enum [LawfulMonad m] {β} (f : ℕ → β → α → m β) (b : β) (as : List α) : foldlIdxM f b as = List.foldlM (fun b p ↦ f p.fst b p.snd) b (enum as) := by rw [foldlIdxM, foldlM_eq_foldl, foldlIdx_eq_foldl_enum] #align list.mfoldl_with_index_eq_mfoldl_enum List.foldlIdxM_eq_foldlM_enum end FoldIdxM section MapIdxM -- Porting note: `[Applicative m]` replaced by `[Monad m] [LawfulMonad m]` variable {m : Type u → Type v} [Monad m] [LawfulMonad m] /-- Specification of `mapIdxMAux`. -/ def mapIdxMAuxSpec {β} (f : ℕ → α → m β) (start : ℕ) (as : List α) : m (List β) := List.traverse (uncurry f) <| enumFrom start as #align list.mmap_with_index_aux_spec List.mapIdxMAuxSpec -- Note: `traverse` the class method would require a less universe-polymorphic -- `m : Type u → Type u`. theorem mapIdxMAuxSpec_cons {β} (f : ℕ → α → m β) (start : ℕ) (a : α) (as : List α) : mapIdxMAuxSpec f start (a :: as) = cons <$> f start a <*> mapIdxMAuxSpec f (start + 1) as := rfl #align list.mmap_with_index_aux_spec_cons List.mapIdxMAuxSpec_cons
Mathlib/Data/List/Indexes.lean
402
422
theorem mapIdxMGo_eq_mapIdxMAuxSpec {β} (f : ℕ → α → m β) (arr : Array β) (as : List α) : mapIdxM.go f as arr = (arr.toList ++ ·) <$> mapIdxMAuxSpec f arr.size as := by
generalize e : as.length = len revert as arr induction' len with len ih <;> intro arr as h · have : as = [] := by cases as · rfl · contradiction simp only [this, mapIdxM.go, mapIdxMAuxSpec, List.traverse, map_pure, append_nil] · match as with | nil => contradiction | cons head tail => simp only [length_cons, Nat.succ.injEq] at h simp only [mapIdxM.go, mapIdxMAuxSpec_cons, map_eq_pure_bind, seq_eq_bind_map, LawfulMonad.bind_assoc, pure_bind] congr conv => { lhs; intro x; rw [ih _ _ h]; } funext x simp only [Array.toList_eq, Array.push_data, append_assoc, singleton_append, Array.size_push, map_eq_pure_bind]
/- 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, Floris van Doorn -/ import Mathlib.Data.Finsupp.Multiset import Mathlib.Order.Bounded import Mathlib.SetTheory.Cardinal.PartENat import Mathlib.SetTheory.Ordinal.Principal import Mathlib.Tactic.Linarith #align_import set_theory.cardinal.ordinal from "leanprover-community/mathlib"@"7c2ce0c2da15516b4e65d0c9e254bb6dc93abd1f" /-! # Cardinals and ordinals Relationships between cardinals and ordinals, properties of cardinals that are proved using ordinals. ## Main definitions * The function `Cardinal.aleph'` gives the cardinals listed by their ordinal index, and is the inverse of `Cardinal.aleph/idx`. `aleph' n = n`, `aleph' ω = ℵ₀`, `aleph' (ω + 1) = succ ℵ₀`, etc. It is an order isomorphism between ordinals and cardinals. * The function `Cardinal.aleph` gives the infinite cardinals listed by their ordinal index. `aleph 0 = ℵ₀`, `aleph 1 = succ ℵ₀` is the first uncountable cardinal, and so on. The notation `ω_` combines the latter with `Cardinal.ord`, giving an enumeration of (infinite) initial ordinals. Thus `ω_ 0 = ω` and `ω₁ = ω_ 1` is the first uncountable ordinal. * The function `Cardinal.beth` enumerates the Beth cardinals. `beth 0 = ℵ₀`, `beth (succ o) = 2 ^ beth o`, and for a limit ordinal `o`, `beth o` is the supremum of `beth a` for `a < o`. ## Main Statements * `Cardinal.mul_eq_max` and `Cardinal.add_eq_max` state that the product (resp. sum) of two infinite cardinals is just their maximum. Several variations around this fact are also given. * `Cardinal.mk_list_eq_mk` : when `α` is infinite, `α` and `List α` have the same cardinality. * simp lemmas for inequalities between `bit0 a` and `bit1 b` are registered, making `simp` able to prove inequalities about numeral cardinals. ## Tags cardinal arithmetic (for infinite cardinals) -/ noncomputable section open Function Set Cardinal Equiv Order Ordinal open scoped Classical universe u v w namespace Cardinal section UsingOrdinals theorem ord_isLimit {c} (co : ℵ₀ ≤ c) : (ord c).IsLimit := by refine ⟨fun h => aleph0_ne_zero ?_, fun a => lt_imp_lt_of_le_imp_le fun h => ?_⟩ · rw [← Ordinal.le_zero, ord_le] at h simpa only [card_zero, nonpos_iff_eq_zero] using co.trans h · rw [ord_le] at h ⊢ rwa [← @add_one_of_aleph0_le (card a), ← card_succ] rw [← ord_le, ← le_succ_of_isLimit, ord_le] · exact co.trans h · rw [ord_aleph0] exact omega_isLimit #align cardinal.ord_is_limit Cardinal.ord_isLimit theorem noMaxOrder {c} (h : ℵ₀ ≤ c) : NoMaxOrder c.ord.out.α := Ordinal.out_no_max_of_succ_lt (ord_isLimit h).2 /-! ### Aleph cardinals -/ section aleph /-- The `aleph'` index function, which gives the ordinal index of a cardinal. (The `aleph'` part is because unlike `aleph` this counts also the finite stages. So `alephIdx n = n`, `alephIdx ω = ω`, `alephIdx ℵ₁ = ω + 1` and so on.) In this definition, we register additionally that this function is an initial segment, i.e., it is order preserving and its range is an initial segment of the ordinals. For the basic function version, see `alephIdx`. For an upgraded version stating that the range is everything, see `AlephIdx.rel_iso`. -/ def alephIdx.initialSeg : @InitialSeg Cardinal Ordinal (· < ·) (· < ·) := @RelEmbedding.collapse Cardinal Ordinal (· < ·) (· < ·) _ Cardinal.ord.orderEmbedding.ltEmbedding #align cardinal.aleph_idx.initial_seg Cardinal.alephIdx.initialSeg /-- The `aleph'` index function, which gives the ordinal index of a cardinal. (The `aleph'` part is because unlike `aleph` this counts also the finite stages. So `alephIdx n = n`, `alephIdx ω = ω`, `alephIdx ℵ₁ = ω + 1` and so on.) For an upgraded version stating that the range is everything, see `AlephIdx.rel_iso`. -/ def alephIdx : Cardinal → Ordinal := alephIdx.initialSeg #align cardinal.aleph_idx Cardinal.alephIdx @[simp] theorem alephIdx.initialSeg_coe : (alephIdx.initialSeg : Cardinal → Ordinal) = alephIdx := rfl #align cardinal.aleph_idx.initial_seg_coe Cardinal.alephIdx.initialSeg_coe @[simp] theorem alephIdx_lt {a b} : alephIdx a < alephIdx b ↔ a < b := alephIdx.initialSeg.toRelEmbedding.map_rel_iff #align cardinal.aleph_idx_lt Cardinal.alephIdx_lt @[simp] theorem alephIdx_le {a b} : alephIdx a ≤ alephIdx b ↔ a ≤ b := by rw [← not_lt, ← not_lt, alephIdx_lt] #align cardinal.aleph_idx_le Cardinal.alephIdx_le theorem alephIdx.init {a b} : b < alephIdx a → ∃ c, alephIdx c = b := alephIdx.initialSeg.init #align cardinal.aleph_idx.init Cardinal.alephIdx.init /-- The `aleph'` index function, which gives the ordinal index of a cardinal. (The `aleph'` part is because unlike `aleph` this counts also the finite stages. So `alephIdx n = n`, `alephIdx ℵ₀ = ω`, `alephIdx ℵ₁ = ω + 1` and so on.) In this version, we register additionally that this function is an order isomorphism between cardinals and ordinals. For the basic function version, see `alephIdx`. -/ def alephIdx.relIso : @RelIso Cardinal.{u} Ordinal.{u} (· < ·) (· < ·) := @RelIso.ofSurjective Cardinal.{u} Ordinal.{u} (· < ·) (· < ·) alephIdx.initialSeg.{u} <| (InitialSeg.eq_or_principal alephIdx.initialSeg.{u}).resolve_right fun ⟨o, e⟩ => by have : ∀ c, alephIdx c < o := fun c => (e _).2 ⟨_, rfl⟩ refine Ordinal.inductionOn o ?_ this; intro α r _ h let s := ⨆ a, invFun alephIdx (Ordinal.typein r a) apply (lt_succ s).not_le have I : Injective.{u+2, u+2} alephIdx := alephIdx.initialSeg.toEmbedding.injective simpa only [typein_enum, leftInverse_invFun I (succ s)] using le_ciSup (Cardinal.bddAbove_range.{u, u} fun a : α => invFun alephIdx (Ordinal.typein r a)) (Ordinal.enum r _ (h (succ s))) #align cardinal.aleph_idx.rel_iso Cardinal.alephIdx.relIso @[simp] theorem alephIdx.relIso_coe : (alephIdx.relIso : Cardinal → Ordinal) = alephIdx := rfl #align cardinal.aleph_idx.rel_iso_coe Cardinal.alephIdx.relIso_coe @[simp] theorem type_cardinal : @type Cardinal (· < ·) _ = Ordinal.univ.{u, u + 1} := by rw [Ordinal.univ_id]; exact Quotient.sound ⟨alephIdx.relIso⟩ #align cardinal.type_cardinal Cardinal.type_cardinal @[simp] theorem mk_cardinal : #Cardinal = univ.{u, u + 1} := by simpa only [card_type, card_univ] using congr_arg card type_cardinal #align cardinal.mk_cardinal Cardinal.mk_cardinal /-- The `aleph'` function gives the cardinals listed by their ordinal index, and is the inverse of `aleph_idx`. `aleph' n = n`, `aleph' ω = ω`, `aleph' (ω + 1) = succ ℵ₀`, etc. In this version, we register additionally that this function is an order isomorphism between ordinals and cardinals. For the basic function version, see `aleph'`. -/ def Aleph'.relIso := Cardinal.alephIdx.relIso.symm #align cardinal.aleph'.rel_iso Cardinal.Aleph'.relIso /-- The `aleph'` function gives the cardinals listed by their ordinal index, and is the inverse of `aleph_idx`. `aleph' n = n`, `aleph' ω = ω`, `aleph' (ω + 1) = succ ℵ₀`, etc. -/ def aleph' : Ordinal → Cardinal := Aleph'.relIso #align cardinal.aleph' Cardinal.aleph' @[simp] theorem aleph'.relIso_coe : (Aleph'.relIso : Ordinal → Cardinal) = aleph' := rfl #align cardinal.aleph'.rel_iso_coe Cardinal.aleph'.relIso_coe @[simp] theorem aleph'_lt {o₁ o₂ : Ordinal} : aleph' o₁ < aleph' o₂ ↔ o₁ < o₂ := Aleph'.relIso.map_rel_iff #align cardinal.aleph'_lt Cardinal.aleph'_lt @[simp] theorem aleph'_le {o₁ o₂ : Ordinal} : aleph' o₁ ≤ aleph' o₂ ↔ o₁ ≤ o₂ := le_iff_le_iff_lt_iff_lt.2 aleph'_lt #align cardinal.aleph'_le Cardinal.aleph'_le @[simp] theorem aleph'_alephIdx (c : Cardinal) : aleph' c.alephIdx = c := Cardinal.alephIdx.relIso.toEquiv.symm_apply_apply c #align cardinal.aleph'_aleph_idx Cardinal.aleph'_alephIdx @[simp] theorem alephIdx_aleph' (o : Ordinal) : (aleph' o).alephIdx = o := Cardinal.alephIdx.relIso.toEquiv.apply_symm_apply o #align cardinal.aleph_idx_aleph' Cardinal.alephIdx_aleph' @[simp] theorem aleph'_zero : aleph' 0 = 0 := by rw [← nonpos_iff_eq_zero, ← aleph'_alephIdx 0, aleph'_le] apply Ordinal.zero_le #align cardinal.aleph'_zero Cardinal.aleph'_zero @[simp] theorem aleph'_succ {o : Ordinal} : aleph' (succ o) = succ (aleph' o) := by apply (succ_le_of_lt <| aleph'_lt.2 <| lt_succ o).antisymm' (Cardinal.alephIdx_le.1 <| _) rw [alephIdx_aleph', succ_le_iff, ← aleph'_lt, aleph'_alephIdx] apply lt_succ #align cardinal.aleph'_succ Cardinal.aleph'_succ @[simp] theorem aleph'_nat : ∀ n : ℕ, aleph' n = n | 0 => aleph'_zero | n + 1 => show aleph' (succ n) = n.succ by rw [aleph'_succ, aleph'_nat n, nat_succ] #align cardinal.aleph'_nat Cardinal.aleph'_nat theorem aleph'_le_of_limit {o : Ordinal} (l : o.IsLimit) {c} : aleph' o ≤ c ↔ ∀ o' < o, aleph' o' ≤ c := ⟨fun h o' h' => (aleph'_le.2 <| h'.le).trans h, fun h => by rw [← aleph'_alephIdx c, aleph'_le, limit_le l] intro x h' rw [← aleph'_le, aleph'_alephIdx] exact h _ h'⟩ #align cardinal.aleph'_le_of_limit Cardinal.aleph'_le_of_limit theorem aleph'_limit {o : Ordinal} (ho : o.IsLimit) : aleph' o = ⨆ a : Iio o, aleph' a := by refine le_antisymm ?_ (ciSup_le' fun i => aleph'_le.2 (le_of_lt i.2)) rw [aleph'_le_of_limit ho] exact fun a ha => le_ciSup (bddAbove_of_small _) (⟨a, ha⟩ : Iio o) #align cardinal.aleph'_limit Cardinal.aleph'_limit @[simp] theorem aleph'_omega : aleph' ω = ℵ₀ := eq_of_forall_ge_iff fun c => by simp only [aleph'_le_of_limit omega_isLimit, lt_omega, exists_imp, aleph0_le] exact forall_swap.trans (forall_congr' fun n => by simp only [forall_eq, aleph'_nat]) #align cardinal.aleph'_omega Cardinal.aleph'_omega /-- `aleph'` and `aleph_idx` form an equivalence between `Ordinal` and `Cardinal` -/ @[simp] def aleph'Equiv : Ordinal ≃ Cardinal := ⟨aleph', alephIdx, alephIdx_aleph', aleph'_alephIdx⟩ #align cardinal.aleph'_equiv Cardinal.aleph'Equiv /-- The `aleph` function gives the infinite cardinals listed by their ordinal index. `aleph 0 = ℵ₀`, `aleph 1 = succ ℵ₀` is the first uncountable cardinal, and so on. -/ def aleph (o : Ordinal) : Cardinal := aleph' (ω + o) #align cardinal.aleph Cardinal.aleph @[simp] theorem aleph_lt {o₁ o₂ : Ordinal} : aleph o₁ < aleph o₂ ↔ o₁ < o₂ := aleph'_lt.trans (add_lt_add_iff_left _) #align cardinal.aleph_lt Cardinal.aleph_lt @[simp] theorem aleph_le {o₁ o₂ : Ordinal} : aleph o₁ ≤ aleph o₂ ↔ o₁ ≤ o₂ := le_iff_le_iff_lt_iff_lt.2 aleph_lt #align cardinal.aleph_le Cardinal.aleph_le @[simp] theorem max_aleph_eq (o₁ o₂ : Ordinal) : max (aleph o₁) (aleph o₂) = aleph (max o₁ o₂) := by rcases le_total (aleph o₁) (aleph o₂) with h | h · rw [max_eq_right h, max_eq_right (aleph_le.1 h)] · rw [max_eq_left h, max_eq_left (aleph_le.1 h)] #align cardinal.max_aleph_eq Cardinal.max_aleph_eq @[simp] theorem aleph_succ {o : Ordinal} : aleph (succ o) = succ (aleph o) := by rw [aleph, add_succ, aleph'_succ, aleph] #align cardinal.aleph_succ Cardinal.aleph_succ @[simp] theorem aleph_zero : aleph 0 = ℵ₀ := by rw [aleph, add_zero, aleph'_omega] #align cardinal.aleph_zero Cardinal.aleph_zero theorem aleph_limit {o : Ordinal} (ho : o.IsLimit) : aleph o = ⨆ a : Iio o, aleph a := by apply le_antisymm _ (ciSup_le' _) · rw [aleph, aleph'_limit (ho.add _)] refine ciSup_mono' (bddAbove_of_small _) ?_ rintro ⟨i, hi⟩ cases' lt_or_le i ω with h h · rcases lt_omega.1 h with ⟨n, rfl⟩ use ⟨0, ho.pos⟩ simpa using (nat_lt_aleph0 n).le · exact ⟨⟨_, (sub_lt_of_le h).2 hi⟩, aleph'_le.2 (le_add_sub _ _)⟩ · exact fun i => aleph_le.2 (le_of_lt i.2) #align cardinal.aleph_limit Cardinal.aleph_limit theorem aleph0_le_aleph' {o : Ordinal} : ℵ₀ ≤ aleph' o ↔ ω ≤ o := by rw [← aleph'_omega, aleph'_le] #align cardinal.aleph_0_le_aleph' Cardinal.aleph0_le_aleph' theorem aleph0_le_aleph (o : Ordinal) : ℵ₀ ≤ aleph o := by rw [aleph, aleph0_le_aleph'] apply Ordinal.le_add_right #align cardinal.aleph_0_le_aleph Cardinal.aleph0_le_aleph theorem aleph'_pos {o : Ordinal} (ho : 0 < o) : 0 < aleph' o := by rwa [← aleph'_zero, aleph'_lt] #align cardinal.aleph'_pos Cardinal.aleph'_pos theorem aleph_pos (o : Ordinal) : 0 < aleph o := aleph0_pos.trans_le (aleph0_le_aleph o) #align cardinal.aleph_pos Cardinal.aleph_pos @[simp] theorem aleph_toNat (o : Ordinal) : toNat (aleph o) = 0 := toNat_apply_of_aleph0_le <| aleph0_le_aleph o #align cardinal.aleph_to_nat Cardinal.aleph_toNat @[simp] theorem aleph_toPartENat (o : Ordinal) : toPartENat (aleph o) = ⊤ := toPartENat_apply_of_aleph0_le <| aleph0_le_aleph o #align cardinal.aleph_to_part_enat Cardinal.aleph_toPartENat instance nonempty_out_aleph (o : Ordinal) : Nonempty (aleph o).ord.out.α := by rw [out_nonempty_iff_ne_zero, ← ord_zero] exact fun h => (ord_injective h).not_gt (aleph_pos o) #align cardinal.nonempty_out_aleph Cardinal.nonempty_out_aleph theorem ord_aleph_isLimit (o : Ordinal) : (aleph o).ord.IsLimit := ord_isLimit <| aleph0_le_aleph _ #align cardinal.ord_aleph_is_limit Cardinal.ord_aleph_isLimit instance (o : Ordinal) : NoMaxOrder (aleph o).ord.out.α := out_no_max_of_succ_lt (ord_aleph_isLimit o).2 theorem exists_aleph {c : Cardinal} : ℵ₀ ≤ c ↔ ∃ o, c = aleph o := ⟨fun h => ⟨alephIdx c - ω, by rw [aleph, Ordinal.add_sub_cancel_of_le, aleph'_alephIdx] rwa [← aleph0_le_aleph', aleph'_alephIdx]⟩, fun ⟨o, e⟩ => e.symm ▸ aleph0_le_aleph _⟩ #align cardinal.exists_aleph Cardinal.exists_aleph theorem aleph'_isNormal : IsNormal (ord ∘ aleph') := ⟨fun o => ord_lt_ord.2 <| aleph'_lt.2 <| lt_succ o, fun o l a => by simp [ord_le, aleph'_le_of_limit l]⟩ #align cardinal.aleph'_is_normal Cardinal.aleph'_isNormal theorem aleph_isNormal : IsNormal (ord ∘ aleph) := aleph'_isNormal.trans <| add_isNormal ω #align cardinal.aleph_is_normal Cardinal.aleph_isNormal theorem succ_aleph0 : succ ℵ₀ = aleph 1 := by rw [← aleph_zero, ← aleph_succ, Ordinal.succ_zero] #align cardinal.succ_aleph_0 Cardinal.succ_aleph0 theorem aleph0_lt_aleph_one : ℵ₀ < aleph 1 := by rw [← succ_aleph0] apply lt_succ #align cardinal.aleph_0_lt_aleph_one Cardinal.aleph0_lt_aleph_one theorem countable_iff_lt_aleph_one {α : Type*} (s : Set α) : s.Countable ↔ #s < aleph 1 := by rw [← succ_aleph0, lt_succ_iff, le_aleph0_iff_set_countable] #align cardinal.countable_iff_lt_aleph_one Cardinal.countable_iff_lt_aleph_one /-- Ordinals that are cardinals are unbounded. -/ theorem ord_card_unbounded : Unbounded (· < ·) { b : Ordinal | b.card.ord = b } := unbounded_lt_iff.2 fun a => ⟨_, ⟨by dsimp rw [card_ord], (lt_ord_succ_card a).le⟩⟩ #align cardinal.ord_card_unbounded Cardinal.ord_card_unbounded theorem eq_aleph'_of_eq_card_ord {o : Ordinal} (ho : o.card.ord = o) : ∃ a, (aleph' a).ord = o := ⟨Cardinal.alephIdx.relIso o.card, by simpa using ho⟩ #align cardinal.eq_aleph'_of_eq_card_ord Cardinal.eq_aleph'_of_eq_card_ord /-- `ord ∘ aleph'` enumerates the ordinals that are cardinals. -/ theorem ord_aleph'_eq_enum_card : ord ∘ aleph' = enumOrd { b : Ordinal | b.card.ord = b } := by rw [← eq_enumOrd _ ord_card_unbounded, range_eq_iff] exact ⟨aleph'_isNormal.strictMono, ⟨fun a => by dsimp rw [card_ord], fun b hb => eq_aleph'_of_eq_card_ord hb⟩⟩ #align cardinal.ord_aleph'_eq_enum_card Cardinal.ord_aleph'_eq_enum_card /-- Infinite ordinals that are cardinals are unbounded. -/ theorem ord_card_unbounded' : Unbounded (· < ·) { b : Ordinal | b.card.ord = b ∧ ω ≤ b } := (unbounded_lt_inter_le ω).2 ord_card_unbounded #align cardinal.ord_card_unbounded' Cardinal.ord_card_unbounded' theorem eq_aleph_of_eq_card_ord {o : Ordinal} (ho : o.card.ord = o) (ho' : ω ≤ o) : ∃ a, (aleph a).ord = o := by cases' eq_aleph'_of_eq_card_ord ho with a ha use a - ω unfold aleph rwa [Ordinal.add_sub_cancel_of_le] rwa [← aleph0_le_aleph', ← ord_le_ord, ha, ord_aleph0] #align cardinal.eq_aleph_of_eq_card_ord Cardinal.eq_aleph_of_eq_card_ord /-- `ord ∘ aleph` enumerates the infinite ordinals that are cardinals. -/ theorem ord_aleph_eq_enum_card : ord ∘ aleph = enumOrd { b : Ordinal | b.card.ord = b ∧ ω ≤ b } := by rw [← eq_enumOrd _ ord_card_unbounded'] use aleph_isNormal.strictMono rw [range_eq_iff] refine ⟨fun a => ⟨?_, ?_⟩, fun b hb => eq_aleph_of_eq_card_ord hb.1 hb.2⟩ · rw [Function.comp_apply, card_ord] · rw [← ord_aleph0, Function.comp_apply, ord_le_ord] exact aleph0_le_aleph _ #align cardinal.ord_aleph_eq_enum_card Cardinal.ord_aleph_eq_enum_card end aleph /-! ### Beth cardinals -/ section beth /-- Beth numbers are defined so that `beth 0 = ℵ₀`, `beth (succ o) = 2 ^ (beth o)`, and when `o` is a limit ordinal, `beth o` is the supremum of `beth o'` for `o' < o`. Assuming the generalized continuum hypothesis, which is undecidable in ZFC, `beth o = aleph o` for every `o`. -/ def beth (o : Ordinal.{u}) : Cardinal.{u} := limitRecOn o aleph0 (fun _ x => (2 : Cardinal) ^ x) fun a _ IH => ⨆ b : Iio a, IH b.1 b.2 #align cardinal.beth Cardinal.beth @[simp] theorem beth_zero : beth 0 = aleph0 := limitRecOn_zero _ _ _ #align cardinal.beth_zero Cardinal.beth_zero @[simp] theorem beth_succ (o : Ordinal) : beth (succ o) = 2 ^ beth o := limitRecOn_succ _ _ _ _ #align cardinal.beth_succ Cardinal.beth_succ theorem beth_limit {o : Ordinal} : o.IsLimit → beth o = ⨆ a : Iio o, beth a := limitRecOn_limit _ _ _ _ #align cardinal.beth_limit Cardinal.beth_limit theorem beth_strictMono : StrictMono beth := by intro a b induction' b using Ordinal.induction with b IH generalizing a intro h rcases zero_or_succ_or_limit b with (rfl | ⟨c, rfl⟩ | hb) · exact (Ordinal.not_lt_zero a h).elim · rw [lt_succ_iff] at h rw [beth_succ] apply lt_of_le_of_lt _ (cantor _) rcases eq_or_lt_of_le h with (rfl | h) · rfl exact (IH c (lt_succ c) h).le · apply (cantor _).trans_le rw [beth_limit hb, ← beth_succ] exact le_ciSup (bddAbove_of_small _) (⟨_, hb.succ_lt h⟩ : Iio b) #align cardinal.beth_strict_mono Cardinal.beth_strictMono theorem beth_mono : Monotone beth := beth_strictMono.monotone #align cardinal.beth_mono Cardinal.beth_mono @[simp] theorem beth_lt {o₁ o₂ : Ordinal} : beth o₁ < beth o₂ ↔ o₁ < o₂ := beth_strictMono.lt_iff_lt #align cardinal.beth_lt Cardinal.beth_lt @[simp] theorem beth_le {o₁ o₂ : Ordinal} : beth o₁ ≤ beth o₂ ↔ o₁ ≤ o₂ := beth_strictMono.le_iff_le #align cardinal.beth_le Cardinal.beth_le theorem aleph_le_beth (o : Ordinal) : aleph o ≤ beth o := by induction o using limitRecOn with | H₁ => simp | H₂ o h => rw [aleph_succ, beth_succ, succ_le_iff] exact (cantor _).trans_le (power_le_power_left two_ne_zero h) | H₃ o ho IH => rw [aleph_limit ho, beth_limit ho] exact ciSup_mono (bddAbove_of_small _) fun x => IH x.1 x.2 #align cardinal.aleph_le_beth Cardinal.aleph_le_beth theorem aleph0_le_beth (o : Ordinal) : ℵ₀ ≤ beth o := (aleph0_le_aleph o).trans <| aleph_le_beth o #align cardinal.aleph_0_le_beth Cardinal.aleph0_le_beth theorem beth_pos (o : Ordinal) : 0 < beth o := aleph0_pos.trans_le <| aleph0_le_beth o #align cardinal.beth_pos Cardinal.beth_pos theorem beth_ne_zero (o : Ordinal) : beth o ≠ 0 := (beth_pos o).ne' #align cardinal.beth_ne_zero Cardinal.beth_ne_zero theorem beth_normal : IsNormal.{u} fun o => (beth o).ord := (isNormal_iff_strictMono_limit _).2 ⟨ord_strictMono.comp beth_strictMono, fun o ho a ha => by rw [beth_limit ho, ord_le] exact ciSup_le' fun b => ord_le.1 (ha _ b.2)⟩ #align cardinal.beth_normal Cardinal.beth_normal end beth /-! ### Properties of `mul` -/ section mulOrdinals /-- If `α` is an infinite type, then `α × α` and `α` have the same cardinality. -/ theorem mul_eq_self {c : Cardinal} (h : ℵ₀ ≤ c) : c * c = c := by refine le_antisymm ?_ (by simpa only [mul_one] using mul_le_mul_left' (one_le_aleph0.trans h) c) -- the only nontrivial part is `c * c ≤ c`. We prove it inductively. refine Acc.recOn (Cardinal.lt_wf.apply c) (fun c _ => Quotient.inductionOn c fun α IH ol => ?_) h -- consider the minimal well-order `r` on `α` (a type with cardinality `c`). rcases ord_eq α with ⟨r, wo, e⟩ letI := linearOrderOfSTO r haveI : IsWellOrder α (· < ·) := wo -- Define an order `s` on `α × α` by writing `(a, b) < (c, d)` if `max a b < max c d`, or -- the max are equal and `a < c`, or the max are equal and `a = c` and `b < d`. let g : α × α → α := fun p => max p.1 p.2 let f : α × α ↪ Ordinal × α × α := ⟨fun p : α × α => (typein (· < ·) (g p), p), fun p q => congr_arg Prod.snd⟩ let s := f ⁻¹'o Prod.Lex (· < ·) (Prod.Lex (· < ·) (· < ·)) -- this is a well order on `α × α`. haveI : IsWellOrder _ s := (RelEmbedding.preimage _ _).isWellOrder /- it suffices to show that this well order is smaller than `r` if it were larger, then `r` would be a strict prefix of `s`. It would be contained in `β × β` for some `β` of cardinality `< c`. By the inductive assumption, this set has the same cardinality as `β` (or it is finite if `β` is finite), so it is `< c`, which is a contradiction. -/ suffices type s ≤ type r by exact card_le_card this refine le_of_forall_lt fun o h => ?_ rcases typein_surj s h with ⟨p, rfl⟩ rw [← e, lt_ord] refine lt_of_le_of_lt (?_ : _ ≤ card (succ (typein (· < ·) (g p))) * card (succ (typein (· < ·) (g p)))) ?_ · have : { q | s q p } ⊆ insert (g p) { x | x < g p } ×ˢ insert (g p) { x | x < g p } := by intro q h simp only [s, f, Preimage, ge_iff_le, Embedding.coeFn_mk, Prod.lex_def, typein_lt_typein, typein_inj, mem_setOf_eq] at h exact max_le_iff.1 (le_iff_lt_or_eq.2 <| h.imp_right And.left) suffices H : (insert (g p) { x | r x (g p) } : Set α) ≃ Sum { x | r x (g p) } PUnit from ⟨(Set.embeddingOfSubset _ _ this).trans ((Equiv.Set.prod _ _).trans (H.prodCongr H)).toEmbedding⟩ refine (Equiv.Set.insert ?_).trans ((Equiv.refl _).sumCongr punitEquivPUnit) apply @irrefl _ r cases' lt_or_le (card (succ (typein (· < ·) (g p)))) ℵ₀ with qo qo · exact (mul_lt_aleph0 qo qo).trans_le ol · suffices (succ (typein LT.lt (g p))).card < ⟦α⟧ from (IH _ this qo).trans_lt this rw [← lt_ord] apply (ord_isLimit ol).2 rw [mk'_def, e] apply typein_lt_type #align cardinal.mul_eq_self Cardinal.mul_eq_self end mulOrdinals end UsingOrdinals /-! Properties of `mul`, not requiring ordinals -/ section mul /-- If `α` and `β` are infinite types, then the cardinality of `α × β` is the maximum of the cardinalities of `α` and `β`. -/ theorem mul_eq_max {a b : Cardinal} (ha : ℵ₀ ≤ a) (hb : ℵ₀ ≤ b) : a * b = max a b := le_antisymm (mul_eq_self (ha.trans (le_max_left a b)) ▸ mul_le_mul' (le_max_left _ _) (le_max_right _ _)) <| max_le (by simpa only [mul_one] using mul_le_mul_left' (one_le_aleph0.trans hb) a) (by simpa only [one_mul] using mul_le_mul_right' (one_le_aleph0.trans ha) b) #align cardinal.mul_eq_max Cardinal.mul_eq_max @[simp] theorem mul_mk_eq_max {α β : Type u} [Infinite α] [Infinite β] : #α * #β = max #α #β := mul_eq_max (aleph0_le_mk α) (aleph0_le_mk β) #align cardinal.mul_mk_eq_max Cardinal.mul_mk_eq_max @[simp] theorem aleph_mul_aleph (o₁ o₂ : Ordinal) : aleph o₁ * aleph o₂ = aleph (max o₁ o₂) := by rw [Cardinal.mul_eq_max (aleph0_le_aleph o₁) (aleph0_le_aleph o₂), max_aleph_eq] #align cardinal.aleph_mul_aleph Cardinal.aleph_mul_aleph @[simp] theorem aleph0_mul_eq {a : Cardinal} (ha : ℵ₀ ≤ a) : ℵ₀ * a = a := (mul_eq_max le_rfl ha).trans (max_eq_right ha) #align cardinal.aleph_0_mul_eq Cardinal.aleph0_mul_eq @[simp] theorem mul_aleph0_eq {a : Cardinal} (ha : ℵ₀ ≤ a) : a * ℵ₀ = a := (mul_eq_max ha le_rfl).trans (max_eq_left ha) #align cardinal.mul_aleph_0_eq Cardinal.mul_aleph0_eq -- Porting note (#10618): removed `simp`, `simp` can prove it theorem aleph0_mul_mk_eq {α : Type*} [Infinite α] : ℵ₀ * #α = #α := aleph0_mul_eq (aleph0_le_mk α) #align cardinal.aleph_0_mul_mk_eq Cardinal.aleph0_mul_mk_eq -- Porting note (#10618): removed `simp`, `simp` can prove it theorem mk_mul_aleph0_eq {α : Type*} [Infinite α] : #α * ℵ₀ = #α := mul_aleph0_eq (aleph0_le_mk α) #align cardinal.mk_mul_aleph_0_eq Cardinal.mk_mul_aleph0_eq @[simp] theorem aleph0_mul_aleph (o : Ordinal) : ℵ₀ * aleph o = aleph o := aleph0_mul_eq (aleph0_le_aleph o) #align cardinal.aleph_0_mul_aleph Cardinal.aleph0_mul_aleph @[simp] theorem aleph_mul_aleph0 (o : Ordinal) : aleph o * ℵ₀ = aleph o := mul_aleph0_eq (aleph0_le_aleph o) #align cardinal.aleph_mul_aleph_0 Cardinal.aleph_mul_aleph0 theorem mul_lt_of_lt {a b c : Cardinal} (hc : ℵ₀ ≤ c) (h1 : a < c) (h2 : b < c) : a * b < c := (mul_le_mul' (le_max_left a b) (le_max_right a b)).trans_lt <| (lt_or_le (max a b) ℵ₀).elim (fun h => (mul_lt_aleph0 h h).trans_le hc) fun h => by rw [mul_eq_self h] exact max_lt h1 h2 #align cardinal.mul_lt_of_lt Cardinal.mul_lt_of_lt theorem mul_le_max_of_aleph0_le_left {a b : Cardinal} (h : ℵ₀ ≤ a) : a * b ≤ max a b := by convert mul_le_mul' (le_max_left a b) (le_max_right a b) using 1 rw [mul_eq_self] exact h.trans (le_max_left a b) #align cardinal.mul_le_max_of_aleph_0_le_left Cardinal.mul_le_max_of_aleph0_le_left theorem mul_eq_max_of_aleph0_le_left {a b : Cardinal} (h : ℵ₀ ≤ a) (h' : b ≠ 0) : a * b = max a b := by rcases le_or_lt ℵ₀ b with hb | hb · exact mul_eq_max h hb refine (mul_le_max_of_aleph0_le_left h).antisymm ?_ have : b ≤ a := hb.le.trans h rw [max_eq_left this] convert mul_le_mul_left' (one_le_iff_ne_zero.mpr h') a rw [mul_one] #align cardinal.mul_eq_max_of_aleph_0_le_left Cardinal.mul_eq_max_of_aleph0_le_left theorem mul_le_max_of_aleph0_le_right {a b : Cardinal} (h : ℵ₀ ≤ b) : a * b ≤ max a b := by simpa only [mul_comm b, max_comm b] using mul_le_max_of_aleph0_le_left h #align cardinal.mul_le_max_of_aleph_0_le_right Cardinal.mul_le_max_of_aleph0_le_right theorem mul_eq_max_of_aleph0_le_right {a b : Cardinal} (h' : a ≠ 0) (h : ℵ₀ ≤ b) : a * b = max a b := by rw [mul_comm, max_comm] exact mul_eq_max_of_aleph0_le_left h h' #align cardinal.mul_eq_max_of_aleph_0_le_right Cardinal.mul_eq_max_of_aleph0_le_right theorem mul_eq_max' {a b : Cardinal} (h : ℵ₀ ≤ a * b) : a * b = max a b := by rcases aleph0_le_mul_iff.mp h with ⟨ha, hb, ha' | hb'⟩ · exact mul_eq_max_of_aleph0_le_left ha' hb · exact mul_eq_max_of_aleph0_le_right ha hb' #align cardinal.mul_eq_max' Cardinal.mul_eq_max' theorem mul_le_max (a b : Cardinal) : a * b ≤ max (max a b) ℵ₀ := by rcases eq_or_ne a 0 with (rfl | ha0); · simp rcases eq_or_ne b 0 with (rfl | hb0); · simp rcases le_or_lt ℵ₀ a with ha | ha · rw [mul_eq_max_of_aleph0_le_left ha hb0] exact le_max_left _ _ · rcases le_or_lt ℵ₀ b with hb | hb · rw [mul_comm, mul_eq_max_of_aleph0_le_left hb ha0, max_comm] exact le_max_left _ _ · exact le_max_of_le_right (mul_lt_aleph0 ha hb).le #align cardinal.mul_le_max Cardinal.mul_le_max theorem mul_eq_left {a b : Cardinal} (ha : ℵ₀ ≤ a) (hb : b ≤ a) (hb' : b ≠ 0) : a * b = a := by rw [mul_eq_max_of_aleph0_le_left ha hb', max_eq_left hb] #align cardinal.mul_eq_left Cardinal.mul_eq_left theorem mul_eq_right {a b : Cardinal} (hb : ℵ₀ ≤ b) (ha : a ≤ b) (ha' : a ≠ 0) : a * b = b := by rw [mul_comm, mul_eq_left hb ha ha'] #align cardinal.mul_eq_right Cardinal.mul_eq_right theorem le_mul_left {a b : Cardinal} (h : b ≠ 0) : a ≤ b * a := by convert mul_le_mul_right' (one_le_iff_ne_zero.mpr h) a rw [one_mul] #align cardinal.le_mul_left Cardinal.le_mul_left theorem le_mul_right {a b : Cardinal} (h : b ≠ 0) : a ≤ a * b := by rw [mul_comm] exact le_mul_left h #align cardinal.le_mul_right Cardinal.le_mul_right theorem mul_eq_left_iff {a b : Cardinal} : a * b = a ↔ max ℵ₀ b ≤ a ∧ b ≠ 0 ∨ b = 1 ∨ a = 0 := by rw [max_le_iff] refine ⟨fun h => ?_, ?_⟩ · rcases le_or_lt ℵ₀ a with ha | ha · have : a ≠ 0 := by rintro rfl exact ha.not_lt aleph0_pos left rw [and_assoc] use ha constructor · rw [← not_lt] exact fun hb => ne_of_gt (hb.trans_le (le_mul_left this)) h · rintro rfl apply this rw [mul_zero] at h exact h.symm right by_cases h2a : a = 0 · exact Or.inr h2a have hb : b ≠ 0 := by rintro rfl apply h2a rw [mul_zero] at h exact h.symm left rw [← h, mul_lt_aleph0_iff, lt_aleph0, lt_aleph0] at ha rcases ha with (rfl | rfl | ⟨⟨n, rfl⟩, ⟨m, rfl⟩⟩) · contradiction · contradiction rw [← Ne] at h2a rw [← one_le_iff_ne_zero] at h2a hb norm_cast at h2a hb h ⊢ apply le_antisymm _ hb rw [← not_lt] apply fun h2b => ne_of_gt _ h conv_rhs => left; rw [← mul_one n] rw [mul_lt_mul_left] · exact id apply Nat.lt_of_succ_le h2a · rintro (⟨⟨ha, hab⟩, hb⟩ | rfl | rfl) · rw [mul_eq_max_of_aleph0_le_left ha hb, max_eq_left hab] all_goals simp #align cardinal.mul_eq_left_iff Cardinal.mul_eq_left_iff end mul /-! ### Properties of `add` -/ section add /-- If `α` is an infinite type, then `α ⊕ α` and `α` have the same cardinality. -/ theorem add_eq_self {c : Cardinal} (h : ℵ₀ ≤ c) : c + c = c := le_antisymm (by convert mul_le_mul_right' ((nat_lt_aleph0 2).le.trans h) c using 1 <;> simp [two_mul, mul_eq_self h]) (self_le_add_left c c) #align cardinal.add_eq_self Cardinal.add_eq_self /-- If `α` is an infinite type, then the cardinality of `α ⊕ β` is the maximum of the cardinalities of `α` and `β`. -/ theorem add_eq_max {a b : Cardinal} (ha : ℵ₀ ≤ a) : a + b = max a b := le_antisymm (add_eq_self (ha.trans (le_max_left a b)) ▸ add_le_add (le_max_left _ _) (le_max_right _ _)) <| max_le (self_le_add_right _ _) (self_le_add_left _ _) #align cardinal.add_eq_max Cardinal.add_eq_max theorem add_eq_max' {a b : Cardinal} (ha : ℵ₀ ≤ b) : a + b = max a b := by rw [add_comm, max_comm, add_eq_max ha] #align cardinal.add_eq_max' Cardinal.add_eq_max' @[simp] theorem add_mk_eq_max {α β : Type u} [Infinite α] : #α + #β = max #α #β := add_eq_max (aleph0_le_mk α) #align cardinal.add_mk_eq_max Cardinal.add_mk_eq_max @[simp] theorem add_mk_eq_max' {α β : Type u} [Infinite β] : #α + #β = max #α #β := add_eq_max' (aleph0_le_mk β) #align cardinal.add_mk_eq_max' Cardinal.add_mk_eq_max' theorem add_le_max (a b : Cardinal) : a + b ≤ max (max a b) ℵ₀ := by rcases le_or_lt ℵ₀ a with ha | ha · rw [add_eq_max ha] exact le_max_left _ _ · rcases le_or_lt ℵ₀ b with hb | hb · rw [add_comm, add_eq_max hb, max_comm] exact le_max_left _ _ · exact le_max_of_le_right (add_lt_aleph0 ha hb).le #align cardinal.add_le_max Cardinal.add_le_max theorem add_le_of_le {a b c : Cardinal} (hc : ℵ₀ ≤ c) (h1 : a ≤ c) (h2 : b ≤ c) : a + b ≤ c := (add_le_add h1 h2).trans <| le_of_eq <| add_eq_self hc #align cardinal.add_le_of_le Cardinal.add_le_of_le theorem add_lt_of_lt {a b c : Cardinal} (hc : ℵ₀ ≤ c) (h1 : a < c) (h2 : b < c) : a + b < c := (add_le_add (le_max_left a b) (le_max_right a b)).trans_lt <| (lt_or_le (max a b) ℵ₀).elim (fun h => (add_lt_aleph0 h h).trans_le hc) fun h => by rw [add_eq_self h]; exact max_lt h1 h2 #align cardinal.add_lt_of_lt Cardinal.add_lt_of_lt theorem eq_of_add_eq_of_aleph0_le {a b c : Cardinal} (h : a + b = c) (ha : a < c) (hc : ℵ₀ ≤ c) : b = c := by apply le_antisymm · rw [← h] apply self_le_add_left rw [← not_lt]; intro hb have : a + b < c := add_lt_of_lt hc ha hb simp [h, lt_irrefl] at this #align cardinal.eq_of_add_eq_of_aleph_0_le Cardinal.eq_of_add_eq_of_aleph0_le theorem add_eq_left {a b : Cardinal} (ha : ℵ₀ ≤ a) (hb : b ≤ a) : a + b = a := by rw [add_eq_max ha, max_eq_left hb] #align cardinal.add_eq_left Cardinal.add_eq_left theorem add_eq_right {a b : Cardinal} (hb : ℵ₀ ≤ b) (ha : a ≤ b) : a + b = b := by rw [add_comm, add_eq_left hb ha] #align cardinal.add_eq_right Cardinal.add_eq_right theorem add_eq_left_iff {a b : Cardinal} : a + b = a ↔ max ℵ₀ b ≤ a ∨ b = 0 := by rw [max_le_iff] refine ⟨fun h => ?_, ?_⟩ · rcases le_or_lt ℵ₀ a with ha | ha · left use ha rw [← not_lt] apply fun hb => ne_of_gt _ h intro hb exact hb.trans_le (self_le_add_left b a) right rw [← h, add_lt_aleph0_iff, lt_aleph0, lt_aleph0] at ha rcases ha with ⟨⟨n, rfl⟩, ⟨m, rfl⟩⟩ norm_cast at h ⊢ rw [← add_right_inj, h, add_zero] · rintro (⟨h1, h2⟩ | h3) · rw [add_eq_max h1, max_eq_left h2] · rw [h3, add_zero] #align cardinal.add_eq_left_iff Cardinal.add_eq_left_iff theorem add_eq_right_iff {a b : Cardinal} : a + b = b ↔ max ℵ₀ a ≤ b ∨ a = 0 := by rw [add_comm, add_eq_left_iff] #align cardinal.add_eq_right_iff Cardinal.add_eq_right_iff theorem add_nat_eq {a : Cardinal} (n : ℕ) (ha : ℵ₀ ≤ a) : a + n = a := add_eq_left ha ((nat_lt_aleph0 _).le.trans ha) #align cardinal.add_nat_eq Cardinal.add_nat_eq theorem nat_add_eq {a : Cardinal} (n : ℕ) (ha : ℵ₀ ≤ a) : n + a = a := by rw [add_comm, add_nat_eq n ha] theorem add_one_eq {a : Cardinal} (ha : ℵ₀ ≤ a) : a + 1 = a := add_one_of_aleph0_le ha #align cardinal.add_one_eq Cardinal.add_one_eq -- Porting note (#10618): removed `simp`, `simp` can prove it theorem mk_add_one_eq {α : Type*} [Infinite α] : #α + 1 = #α := add_one_eq (aleph0_le_mk α) #align cardinal.mk_add_one_eq Cardinal.mk_add_one_eq protected theorem eq_of_add_eq_add_left {a b c : Cardinal} (h : a + b = a + c) (ha : a < ℵ₀) : b = c := by rcases le_or_lt ℵ₀ b with hb | hb · have : a < b := ha.trans_le hb rw [add_eq_right hb this.le, eq_comm] at h rw [eq_of_add_eq_of_aleph0_le h this hb] · have hc : c < ℵ₀ := by rw [← not_le] intro hc apply lt_irrefl ℵ₀ apply (hc.trans (self_le_add_left _ a)).trans_lt rw [← h] apply add_lt_aleph0 ha hb rw [lt_aleph0] at * rcases ha with ⟨n, rfl⟩ rcases hb with ⟨m, rfl⟩ rcases hc with ⟨k, rfl⟩ norm_cast at h ⊢ apply add_left_cancel h #align cardinal.eq_of_add_eq_add_left Cardinal.eq_of_add_eq_add_left protected theorem eq_of_add_eq_add_right {a b c : Cardinal} (h : a + b = c + b) (hb : b < ℵ₀) : a = c := by rw [add_comm a b, add_comm c b] at h exact Cardinal.eq_of_add_eq_add_left h hb #align cardinal.eq_of_add_eq_add_right Cardinal.eq_of_add_eq_add_right end add section ciSup variable {ι : Type u} {ι' : Type w} (f : ι → Cardinal.{v}) section add variable [Nonempty ι] [Nonempty ι'] (hf : BddAbove (range f)) protected theorem ciSup_add (c : Cardinal.{v}) : (⨆ i, f i) + c = ⨆ i, f i + c := by have : ∀ i, f i + c ≤ (⨆ i, f i) + c := fun i ↦ add_le_add_right (le_ciSup hf i) c refine le_antisymm ?_ (ciSup_le' this) have bdd : BddAbove (range (f · + c)) := ⟨_, forall_mem_range.mpr this⟩ obtain hs | hs := lt_or_le (⨆ i, f i) ℵ₀ · obtain ⟨i, hi⟩ := exists_eq_of_iSup_eq_of_not_isLimit f hf _ (fun h ↦ hs.not_le h.aleph0_le) rfl exact hi ▸ le_ciSup bdd i rw [add_eq_max hs, max_le_iff] exact ⟨ciSup_mono bdd fun i ↦ self_le_add_right _ c, (self_le_add_left _ _).trans (le_ciSup bdd <| Classical.arbitrary ι)⟩ protected theorem add_ciSup (c : Cardinal.{v}) : c + (⨆ i, f i) = ⨆ i, c + f i := by rw [add_comm, Cardinal.ciSup_add f hf]; simp_rw [add_comm] protected theorem ciSup_add_ciSup (g : ι' → Cardinal.{v}) (hg : BddAbove (range g)) : (⨆ i, f i) + (⨆ j, g j) = ⨆ (i) (j), f i + g j := by simp_rw [Cardinal.ciSup_add f hf, Cardinal.add_ciSup g hg] end add protected theorem ciSup_mul (c : Cardinal.{v}) : (⨆ i, f i) * c = ⨆ i, f i * c := by cases isEmpty_or_nonempty ι; · simp obtain rfl | h0 := eq_or_ne c 0; · simp by_cases hf : BddAbove (range f); swap · have hfc : ¬ BddAbove (range (f · * c)) := fun bdd ↦ hf ⟨⨆ i, f i * c, forall_mem_range.mpr fun i ↦ (le_mul_right h0).trans (le_ciSup bdd i)⟩ simp [iSup, csSup_of_not_bddAbove, hf, hfc] have : ∀ i, f i * c ≤ (⨆ i, f i) * c := fun i ↦ mul_le_mul_right' (le_ciSup hf i) c refine le_antisymm ?_ (ciSup_le' this) have bdd : BddAbove (range (f · * c)) := ⟨_, forall_mem_range.mpr this⟩ obtain hs | hs := lt_or_le (⨆ i, f i) ℵ₀ · obtain ⟨i, hi⟩ := exists_eq_of_iSup_eq_of_not_isLimit f hf _ (fun h ↦ hs.not_le h.aleph0_le) rfl exact hi ▸ le_ciSup bdd i rw [mul_eq_max_of_aleph0_le_left hs h0, max_le_iff] obtain ⟨i, hi⟩ := exists_lt_of_lt_ciSup' (one_lt_aleph0.trans_le hs) exact ⟨ciSup_mono bdd fun i ↦ le_mul_right h0, (le_mul_left (zero_lt_one.trans hi).ne').trans (le_ciSup bdd i)⟩ protected theorem mul_ciSup (c : Cardinal.{v}) : c * (⨆ i, f i) = ⨆ i, c * f i := by rw [mul_comm, Cardinal.ciSup_mul f]; simp_rw [mul_comm] protected theorem ciSup_mul_ciSup (g : ι' → Cardinal.{v}) : (⨆ i, f i) * (⨆ j, g j) = ⨆ (i) (j), f i * g j := by simp_rw [Cardinal.ciSup_mul f, Cardinal.mul_ciSup g] end ciSup @[simp] theorem aleph_add_aleph (o₁ o₂ : Ordinal) : aleph o₁ + aleph o₂ = aleph (max o₁ o₂) := by rw [Cardinal.add_eq_max (aleph0_le_aleph o₁), max_aleph_eq] #align cardinal.aleph_add_aleph Cardinal.aleph_add_aleph theorem principal_add_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Ordinal.Principal (· + ·) c.ord := fun a b ha hb => by rw [lt_ord, Ordinal.card_add] at * exact add_lt_of_lt hc ha hb #align cardinal.principal_add_ord Cardinal.principal_add_ord theorem principal_add_aleph (o : Ordinal) : Ordinal.Principal (· + ·) (aleph o).ord := principal_add_ord <| aleph0_le_aleph o #align cardinal.principal_add_aleph Cardinal.principal_add_aleph theorem add_right_inj_of_lt_aleph0 {α β γ : Cardinal} (γ₀ : γ < aleph0) : α + γ = β + γ ↔ α = β := ⟨fun h => Cardinal.eq_of_add_eq_add_right h γ₀, fun h => congr_arg (· + γ) h⟩ #align cardinal.add_right_inj_of_lt_aleph_0 Cardinal.add_right_inj_of_lt_aleph0 @[simp] theorem add_nat_inj {α β : Cardinal} (n : ℕ) : α + n = β + n ↔ α = β := add_right_inj_of_lt_aleph0 (nat_lt_aleph0 _) #align cardinal.add_nat_inj Cardinal.add_nat_inj @[simp] theorem add_one_inj {α β : Cardinal} : α + 1 = β + 1 ↔ α = β := add_right_inj_of_lt_aleph0 one_lt_aleph0 #align cardinal.add_one_inj Cardinal.add_one_inj theorem add_le_add_iff_of_lt_aleph0 {α β γ : Cardinal} (γ₀ : γ < Cardinal.aleph0) : α + γ ≤ β + γ ↔ α ≤ β := by refine ⟨fun h => ?_, fun h => add_le_add_right h γ⟩ contrapose h rw [not_le, lt_iff_le_and_ne, Ne] at h ⊢ exact ⟨add_le_add_right h.1 γ, mt (add_right_inj_of_lt_aleph0 γ₀).1 h.2⟩ #align cardinal.add_le_add_iff_of_lt_aleph_0 Cardinal.add_le_add_iff_of_lt_aleph0 @[simp] theorem add_nat_le_add_nat_iff {α β : Cardinal} (n : ℕ) : α + n ≤ β + n ↔ α ≤ β := add_le_add_iff_of_lt_aleph0 (nat_lt_aleph0 n) #align cardinal.add_nat_le_add_nat_iff_of_lt_aleph_0 Cardinal.add_nat_le_add_nat_iff @[deprecated (since := "2024-02-12")] alias add_nat_le_add_nat_iff_of_lt_aleph_0 := add_nat_le_add_nat_iff @[simp] theorem add_one_le_add_one_iff {α β : Cardinal} : α + 1 ≤ β + 1 ↔ α ≤ β := add_le_add_iff_of_lt_aleph0 one_lt_aleph0 #align cardinal.add_one_le_add_one_iff_of_lt_aleph_0 Cardinal.add_one_le_add_one_iff @[deprecated (since := "2024-02-12")] alias add_one_le_add_one_iff_of_lt_aleph_0 := add_one_le_add_one_iff /-! ### Properties about power -/ section pow theorem pow_le {κ μ : Cardinal.{u}} (H1 : ℵ₀ ≤ κ) (H2 : μ < ℵ₀) : κ ^ μ ≤ κ := let ⟨n, H3⟩ := lt_aleph0.1 H2 H3.symm ▸ Quotient.inductionOn κ (fun α H1 => Nat.recOn n (lt_of_lt_of_le (by rw [Nat.cast_zero, power_zero] exact one_lt_aleph0) H1).le fun n ih => le_of_le_of_eq (by rw [Nat.cast_succ, power_add, power_one] exact mul_le_mul_right' ih _) (mul_eq_self H1)) H1 #align cardinal.pow_le Cardinal.pow_le theorem pow_eq {κ μ : Cardinal.{u}} (H1 : ℵ₀ ≤ κ) (H2 : 1 ≤ μ) (H3 : μ < ℵ₀) : κ ^ μ = κ := (pow_le H1 H3).antisymm <| self_le_power κ H2 #align cardinal.pow_eq Cardinal.pow_eq theorem power_self_eq {c : Cardinal} (h : ℵ₀ ≤ c) : c ^ c = 2 ^ c := by apply ((power_le_power_right <| (cantor c).le).trans _).antisymm · exact power_le_power_right ((nat_lt_aleph0 2).le.trans h) · rw [← power_mul, mul_eq_self h] #align cardinal.power_self_eq Cardinal.power_self_eq theorem prod_eq_two_power {ι : Type u} [Infinite ι] {c : ι → Cardinal.{v}} (h₁ : ∀ i, 2 ≤ c i) (h₂ : ∀ i, lift.{u} (c i) ≤ lift.{v} #ι) : prod c = 2 ^ lift.{v} #ι := by rw [← lift_id'.{u, v} (prod.{u, v} c), lift_prod, ← lift_two_power] apply le_antisymm · refine (prod_le_prod _ _ h₂).trans_eq ?_ rw [prod_const, lift_lift, ← lift_power, power_self_eq (aleph0_le_mk ι), lift_umax.{u, v}] · rw [← prod_const', lift_prod] refine prod_le_prod _ _ fun i => ?_ rw [lift_two, ← lift_two.{u, v}, lift_le] exact h₁ i #align cardinal.prod_eq_two_power Cardinal.prod_eq_two_power theorem power_eq_two_power {c₁ c₂ : Cardinal} (h₁ : ℵ₀ ≤ c₁) (h₂ : 2 ≤ c₂) (h₂' : c₂ ≤ c₁) : c₂ ^ c₁ = 2 ^ c₁ := le_antisymm (power_self_eq h₁ ▸ power_le_power_right h₂') (power_le_power_right h₂) #align cardinal.power_eq_two_power Cardinal.power_eq_two_power theorem nat_power_eq {c : Cardinal.{u}} (h : ℵ₀ ≤ c) {n : ℕ} (hn : 2 ≤ n) : (n : Cardinal.{u}) ^ c = 2 ^ c := power_eq_two_power h (by assumption_mod_cast) ((nat_lt_aleph0 n).le.trans h) #align cardinal.nat_power_eq Cardinal.nat_power_eq theorem power_nat_le {c : Cardinal.{u}} {n : ℕ} (h : ℵ₀ ≤ c) : c ^ n ≤ c := pow_le h (nat_lt_aleph0 n) #align cardinal.power_nat_le Cardinal.power_nat_le theorem power_nat_eq {c : Cardinal.{u}} {n : ℕ} (h1 : ℵ₀ ≤ c) (h2 : 1 ≤ n) : c ^ n = c := pow_eq h1 (mod_cast h2) (nat_lt_aleph0 n) #align cardinal.power_nat_eq Cardinal.power_nat_eq theorem power_nat_le_max {c : Cardinal.{u}} {n : ℕ} : c ^ (n : Cardinal.{u}) ≤ max c ℵ₀ := by rcases le_or_lt ℵ₀ c with hc | hc · exact le_max_of_le_left (power_nat_le hc) · exact le_max_of_le_right (power_lt_aleph0 hc (nat_lt_aleph0 _)).le #align cardinal.power_nat_le_max Cardinal.power_nat_le_max theorem powerlt_aleph0 {c : Cardinal} (h : ℵ₀ ≤ c) : c ^< ℵ₀ = c := by apply le_antisymm · rw [powerlt_le] intro c' rw [lt_aleph0] rintro ⟨n, rfl⟩ apply power_nat_le h convert le_powerlt c one_lt_aleph0; rw [power_one] #align cardinal.powerlt_aleph_0 Cardinal.powerlt_aleph0 theorem powerlt_aleph0_le (c : Cardinal) : c ^< ℵ₀ ≤ max c ℵ₀ := by rcases le_or_lt ℵ₀ c with h | h · rw [powerlt_aleph0 h] apply le_max_left rw [powerlt_le] exact fun c' hc' => (power_lt_aleph0 h hc').le.trans (le_max_right _ _) #align cardinal.powerlt_aleph_0_le Cardinal.powerlt_aleph0_le end pow /-! ### Computing cardinality of various types -/ section computing section Function variable {α β : Type u} {β' : Type v} theorem mk_equiv_eq_zero_iff_lift_ne : #(α ≃ β') = 0 ↔ lift.{v} #α ≠ lift.{u} #β' := by rw [mk_eq_zero_iff, ← not_nonempty_iff, ← lift_mk_eq'] theorem mk_equiv_eq_zero_iff_ne : #(α ≃ β) = 0 ↔ #α ≠ #β := by rw [mk_equiv_eq_zero_iff_lift_ne, lift_id, lift_id] /-- This lemma makes lemmas assuming `Infinite α` applicable to the situation where we have `Infinite β` instead. -/ theorem mk_equiv_comm : #(α ≃ β') = #(β' ≃ α) := (ofBijective _ symm_bijective).cardinal_eq theorem mk_embedding_eq_zero_iff_lift_lt : #(α ↪ β') = 0 ↔ lift.{u} #β' < lift.{v} #α := by rw [mk_eq_zero_iff, ← not_nonempty_iff, ← lift_mk_le', not_le] theorem mk_embedding_eq_zero_iff_lt : #(α ↪ β) = 0 ↔ #β < #α := by rw [mk_embedding_eq_zero_iff_lift_lt, lift_lt] theorem mk_arrow_eq_zero_iff : #(α → β') = 0 ↔ #α ≠ 0 ∧ #β' = 0 := by simp_rw [mk_eq_zero_iff, mk_ne_zero_iff, isEmpty_fun] theorem mk_surjective_eq_zero_iff_lift : #{f : α → β' | Surjective f} = 0 ↔ lift.{v} #α < lift.{u} #β' ∨ (#α ≠ 0 ∧ #β' = 0) := by rw [← not_iff_not, not_or, not_lt, lift_mk_le', ← Ne, not_and_or, not_ne_iff, and_comm] simp_rw [mk_ne_zero_iff, mk_eq_zero_iff, nonempty_coe_sort, Set.Nonempty, mem_setOf, exists_surjective_iff, nonempty_fun] theorem mk_surjective_eq_zero_iff : #{f : α → β | Surjective f} = 0 ↔ #α < #β ∨ (#α ≠ 0 ∧ #β = 0) := by rw [mk_surjective_eq_zero_iff_lift, lift_lt] variable (α β') theorem mk_equiv_le_embedding : #(α ≃ β') ≤ #(α ↪ β') := ⟨⟨_, Equiv.toEmbedding_injective⟩⟩ theorem mk_embedding_le_arrow : #(α ↪ β') ≤ #(α → β') := ⟨⟨_, DFunLike.coe_injective⟩⟩ variable [Infinite α] {α β'} theorem mk_perm_eq_self_power : #(Equiv.Perm α) = #α ^ #α := ((mk_equiv_le_embedding α α).trans (mk_embedding_le_arrow α α)).antisymm <| by suffices Nonempty ((α → Bool) ↪ Equiv.Perm (α × Bool)) by obtain ⟨e⟩ : Nonempty (α ≃ α × Bool) := by erw [← Cardinal.eq, mk_prod, lift_uzero, mk_bool, lift_natCast, mul_two, add_eq_self (aleph0_le_mk α)] erw [← le_def, mk_arrow, lift_uzero, mk_bool, lift_natCast 2] at this rwa [← power_def, power_self_eq (aleph0_le_mk α), e.permCongr.cardinal_eq] refine ⟨⟨fun f ↦ Involutive.toPerm (fun x ↦ ⟨x.1, xor (f x.1) x.2⟩) fun x ↦ ?_, fun f g h ↦ ?_⟩⟩ · simp_rw [← Bool.xor_assoc, Bool.xor_self, Bool.false_xor] · ext a; rw [← (f a).xor_false, ← (g a).xor_false]; exact congr(($h ⟨a, false⟩).2) theorem mk_perm_eq_two_power : #(Equiv.Perm α) = 2 ^ #α := by rw [mk_perm_eq_self_power, power_self_eq (aleph0_le_mk α)] variable (leq : lift.{v} #α = lift.{u} #β') (eq : #α = #β) theorem mk_equiv_eq_arrow_of_lift_eq : #(α ≃ β') = #(α → β') := by obtain ⟨e⟩ := lift_mk_eq'.mp leq have e₁ := lift_mk_eq'.mpr ⟨.equivCongr (.refl α) e⟩ have e₂ := lift_mk_eq'.mpr ⟨.arrowCongr (.refl α) e⟩ rw [lift_id'.{u,v}] at e₁ e₂ rw [← e₁, ← e₂, lift_inj, mk_perm_eq_self_power, power_def] theorem mk_equiv_eq_arrow_of_eq : #(α ≃ β) = #(α → β) := mk_equiv_eq_arrow_of_lift_eq congr(lift $eq) theorem mk_equiv_of_lift_eq : #(α ≃ β') = 2 ^ lift.{v} #α := by erw [← (lift_mk_eq'.2 ⟨.equivCongr (.refl α) (lift_mk_eq'.1 leq).some⟩).trans (lift_id'.{u,v} _), lift_umax.{u,v}, mk_perm_eq_two_power, lift_power, lift_natCast]; rfl theorem mk_equiv_of_eq : #(α ≃ β) = 2 ^ #α := by rw [mk_equiv_of_lift_eq (lift_inj.mpr eq), lift_id] variable (lle : lift.{u} #β' ≤ lift.{v} #α) (le : #β ≤ #α) theorem mk_embedding_eq_arrow_of_lift_le : #(β' ↪ α) = #(β' → α) := (mk_embedding_le_arrow _ _).antisymm <| by conv_rhs => rw [← (Equiv.embeddingCongr (.refl _) (Cardinal.eq.mp <| mul_eq_self <| aleph0_le_mk α).some).cardinal_eq] obtain ⟨e⟩ := lift_mk_le'.mp lle exact ⟨⟨fun f ↦ ⟨fun b ↦ ⟨e b, f b⟩, fun _ _ h ↦ e.injective congr(Prod.fst $h)⟩, fun f g h ↦ funext fun b ↦ congr(Prod.snd <| $h b)⟩⟩ theorem mk_embedding_eq_arrow_of_le : #(β ↪ α) = #(β → α) := mk_embedding_eq_arrow_of_lift_le (lift_le.mpr le) theorem mk_surjective_eq_arrow_of_lift_le : #{f : α → β' | Surjective f} = #(α → β') := (mk_set_le _).antisymm <| have ⟨e⟩ : Nonempty (α ≃ α ⊕ β') := by simp_rw [← lift_mk_eq', mk_sum, lift_add, lift_lift]; rw [lift_umax.{u,v}, eq_comm] exact add_eq_left (aleph0_le_lift.mpr <| aleph0_le_mk α) lle ⟨⟨fun f ↦ ⟨fun a ↦ (e a).elim f id, fun b ↦ ⟨e.symm (.inr b), congr_arg _ (e.right_inv _)⟩⟩, fun f g h ↦ funext fun a ↦ by simpa only [e.apply_symm_apply] using congr_fun (Subtype.ext_iff.mp h) (e.symm <| .inl a)⟩⟩ theorem mk_surjective_eq_arrow_of_le : #{f : α → β | Surjective f} = #(α → β) := mk_surjective_eq_arrow_of_lift_le (lift_le.mpr le) end Function @[simp] theorem mk_list_eq_mk (α : Type u) [Infinite α] : #(List α) = #α := have H1 : ℵ₀ ≤ #α := aleph0_le_mk α Eq.symm <| le_antisymm ((le_def _ _).2 ⟨⟨fun a => [a], fun _ => by simp⟩⟩) <| calc #(List α) = sum fun n : ℕ => #α ^ (n : Cardinal.{u}) := mk_list_eq_sum_pow α _ ≤ sum fun _ : ℕ => #α := sum_le_sum _ _ fun n => pow_le H1 <| nat_lt_aleph0 n _ = #α := by simp [H1] #align cardinal.mk_list_eq_mk Cardinal.mk_list_eq_mk theorem mk_list_eq_aleph0 (α : Type u) [Countable α] [Nonempty α] : #(List α) = ℵ₀ := mk_le_aleph0.antisymm (aleph0_le_mk _) #align cardinal.mk_list_eq_aleph_0 Cardinal.mk_list_eq_aleph0 theorem mk_list_eq_max_mk_aleph0 (α : Type u) [Nonempty α] : #(List α) = max #α ℵ₀ := by cases finite_or_infinite α · rw [mk_list_eq_aleph0, eq_comm, max_eq_right] exact mk_le_aleph0 · rw [mk_list_eq_mk, eq_comm, max_eq_left] exact aleph0_le_mk α #align cardinal.mk_list_eq_max_mk_aleph_0 Cardinal.mk_list_eq_max_mk_aleph0 theorem mk_list_le_max (α : Type u) : #(List α) ≤ max ℵ₀ #α := by cases finite_or_infinite α · exact mk_le_aleph0.trans (le_max_left _ _) · rw [mk_list_eq_mk] apply le_max_right #align cardinal.mk_list_le_max Cardinal.mk_list_le_max @[simp] theorem mk_finset_of_infinite (α : Type u) [Infinite α] : #(Finset α) = #α := Eq.symm <| le_antisymm (mk_le_of_injective fun _ _ => Finset.singleton_inj.1) <| calc #(Finset α) ≤ #(List α) := mk_le_of_surjective List.toFinset_surjective _ = #α := mk_list_eq_mk α #align cardinal.mk_finset_of_infinite Cardinal.mk_finset_of_infinite @[simp] theorem mk_finsupp_lift_of_infinite (α : Type u) (β : Type v) [Infinite α] [Zero β] [Nontrivial β] : #(α →₀ β) = max (lift.{v} #α) (lift.{u} #β) := by apply le_antisymm · calc #(α →₀ β) ≤ #(Finset (α × β)) := mk_le_of_injective (Finsupp.graph_injective α β) _ = #(α × β) := mk_finset_of_infinite _ _ = max (lift.{v} #α) (lift.{u} #β) := by rw [mk_prod, mul_eq_max_of_aleph0_le_left] <;> simp · apply max_le <;> rw [← lift_id #(α →₀ β), ← lift_umax] · cases' exists_ne (0 : β) with b hb exact lift_mk_le.{v}.2 ⟨⟨_, Finsupp.single_left_injective hb⟩⟩ · inhabit α exact lift_mk_le.{u}.2 ⟨⟨_, Finsupp.single_injective default⟩⟩ #align cardinal.mk_finsupp_lift_of_infinite Cardinal.mk_finsupp_lift_of_infinite theorem mk_finsupp_of_infinite (α β : Type u) [Infinite α] [Zero β] [Nontrivial β] : #(α →₀ β) = max #α #β := by simp #align cardinal.mk_finsupp_of_infinite Cardinal.mk_finsupp_of_infinite @[simp] theorem mk_finsupp_lift_of_infinite' (α : Type u) (β : Type v) [Nonempty α] [Zero β] [Infinite β] : #(α →₀ β) = max (lift.{v} #α) (lift.{u} #β) := by cases fintypeOrInfinite α · rw [mk_finsupp_lift_of_fintype] have : ℵ₀ ≤ (#β).lift := aleph0_le_lift.2 (aleph0_le_mk β) rw [max_eq_right (le_trans _ this), power_nat_eq this] exacts [Fintype.card_pos, lift_le_aleph0.2 (lt_aleph0_of_finite _).le] · apply mk_finsupp_lift_of_infinite #align cardinal.mk_finsupp_lift_of_infinite' Cardinal.mk_finsupp_lift_of_infinite' theorem mk_finsupp_of_infinite' (α β : Type u) [Nonempty α] [Zero β] [Infinite β] : #(α →₀ β) = max #α #β := by simp #align cardinal.mk_finsupp_of_infinite' Cardinal.mk_finsupp_of_infinite' theorem mk_finsupp_nat (α : Type u) [Nonempty α] : #(α →₀ ℕ) = max #α ℵ₀ := by simp #align cardinal.mk_finsupp_nat Cardinal.mk_finsupp_nat @[simp] theorem mk_multiset_of_nonempty (α : Type u) [Nonempty α] : #(Multiset α) = max #α ℵ₀ := Multiset.toFinsupp.toEquiv.cardinal_eq.trans (mk_finsupp_nat α) #align cardinal.mk_multiset_of_nonempty Cardinal.mk_multiset_of_nonempty theorem mk_multiset_of_infinite (α : Type u) [Infinite α] : #(Multiset α) = #α := by simp #align cardinal.mk_multiset_of_infinite Cardinal.mk_multiset_of_infinite theorem mk_multiset_of_isEmpty (α : Type u) [IsEmpty α] : #(Multiset α) = 1 := Multiset.toFinsupp.toEquiv.cardinal_eq.trans (by simp) #align cardinal.mk_multiset_of_is_empty Cardinal.mk_multiset_of_isEmpty theorem mk_multiset_of_countable (α : Type u) [Countable α] [Nonempty α] : #(Multiset α) = ℵ₀ := Multiset.toFinsupp.toEquiv.cardinal_eq.trans (by simp) #align cardinal.mk_multiset_of_countable Cardinal.mk_multiset_of_countable theorem mk_bounded_set_le_of_infinite (α : Type u) [Infinite α] (c : Cardinal) : #{ t : Set α // #t ≤ c } ≤ #α ^ c := by refine le_trans ?_ (by rw [← add_one_eq (aleph0_le_mk α)]) induction' c using Cardinal.inductionOn with β fapply mk_le_of_surjective · intro f use Sum.inl ⁻¹' range f refine le_trans (mk_preimage_of_injective _ _ fun x y => Sum.inl.inj) ?_ apply mk_range_le rintro ⟨s, ⟨g⟩⟩ use fun y => if h : ∃ x : s, g x = y then Sum.inl (Classical.choose h).val else Sum.inr (ULift.up 0) apply Subtype.eq; ext x constructor · rintro ⟨y, h⟩ dsimp only at h by_cases h' : ∃ z : s, g z = y · rw [dif_pos h'] at h cases Sum.inl.inj h exact (Classical.choose h').2 · rw [dif_neg h'] at h cases h · intro h have : ∃ z : s, g z = g ⟨x, h⟩ := ⟨⟨x, h⟩, rfl⟩ use g ⟨x, h⟩ dsimp only rw [dif_pos this] congr suffices Classical.choose this = ⟨x, h⟩ from congr_arg Subtype.val this apply g.2 exact Classical.choose_spec this #align cardinal.mk_bounded_set_le_of_infinite Cardinal.mk_bounded_set_le_of_infinite theorem mk_bounded_set_le (α : Type u) (c : Cardinal) : #{ t : Set α // #t ≤ c } ≤ max #α ℵ₀ ^ c := by trans #{ t : Set (Sum (ULift.{u} ℕ) α) // #t ≤ c } · refine ⟨Embedding.subtypeMap ?_ ?_⟩ · apply Embedding.image use Sum.inr apply Sum.inr.inj intro s hs exact mk_image_le.trans hs apply (mk_bounded_set_le_of_infinite (Sum (ULift.{u} ℕ) α) c).trans rw [max_comm, ← add_eq_max] <;> rfl #align cardinal.mk_bounded_set_le Cardinal.mk_bounded_set_le theorem mk_bounded_subset_le {α : Type u} (s : Set α) (c : Cardinal.{u}) : #{ t : Set α // t ⊆ s ∧ #t ≤ c } ≤ max #s ℵ₀ ^ c := by refine le_trans ?_ (mk_bounded_set_le s c) refine ⟨Embedding.codRestrict _ ?_ ?_⟩ · use fun t => (↑) ⁻¹' t.1 rintro ⟨t, ht1, ht2⟩ ⟨t', h1t', h2t'⟩ h apply Subtype.eq dsimp only at h ⊢ refine (preimage_eq_preimage' ?_ ?_).1 h <;> rw [Subtype.range_coe] <;> assumption rintro ⟨t, _, h2t⟩; exact (mk_preimage_of_injective _ _ Subtype.val_injective).trans h2t #align cardinal.mk_bounded_subset_le Cardinal.mk_bounded_subset_le end computing /-! ### Properties of `compl` -/ section compl theorem mk_compl_of_infinite {α : Type*} [Infinite α] (s : Set α) (h2 : #s < #α) : #(sᶜ : Set α) = #α := by refine eq_of_add_eq_of_aleph0_le ?_ h2 (aleph0_le_mk α) exact mk_sum_compl s #align cardinal.mk_compl_of_infinite Cardinal.mk_compl_of_infinite theorem mk_compl_finset_of_infinite {α : Type*} [Infinite α] (s : Finset α) : #((↑s)ᶜ : Set α) = #α := by apply mk_compl_of_infinite exact (finset_card_lt_aleph0 s).trans_le (aleph0_le_mk α) #align cardinal.mk_compl_finset_of_infinite Cardinal.mk_compl_finset_of_infinite theorem mk_compl_eq_mk_compl_infinite {α : Type*} [Infinite α] {s t : Set α} (hs : #s < #α) (ht : #t < #α) : #(sᶜ : Set α) = #(tᶜ : Set α) := by rw [mk_compl_of_infinite s hs, mk_compl_of_infinite t ht] #align cardinal.mk_compl_eq_mk_compl_infinite Cardinal.mk_compl_eq_mk_compl_infinite theorem mk_compl_eq_mk_compl_finite_lift {α : Type u} {β : Type v} [Finite α] {s : Set α} {t : Set β} (h1 : (lift.{max v w, u} #α) = (lift.{max u w, v} #β)) (h2 : lift.{max v w, u} #s = lift.{max u w, v} #t) : lift.{max v w} #(sᶜ : Set α) = lift.{max u w} #(tᶜ : Set β) := by cases nonempty_fintype α rcases lift_mk_eq.{u, v, w}.1 h1 with ⟨e⟩; letI : Fintype β := Fintype.ofEquiv α e replace h1 : Fintype.card α = Fintype.card β := (Fintype.ofEquiv_card _).symm classical lift s to Finset α using s.toFinite lift t to Finset β using t.toFinite simp only [Finset.coe_sort_coe, mk_fintype, Fintype.card_coe, lift_natCast, Nat.cast_inj] at h2 simp only [← Finset.coe_compl, Finset.coe_sort_coe, mk_coe_finset, Finset.card_compl, lift_natCast, Nat.cast_inj, h1, h2] #align cardinal.mk_compl_eq_mk_compl_finite_lift Cardinal.mk_compl_eq_mk_compl_finite_lift theorem mk_compl_eq_mk_compl_finite {α β : Type u} [Finite α] {s : Set α} {t : Set β} (h1 : #α = #β) (h : #s = #t) : #(sᶜ : Set α) = #(tᶜ : Set β) := by rw [← lift_inj.{u, max u v}] apply mk_compl_eq_mk_compl_finite_lift.{u, u, max u v} <;> rwa [lift_inj] #align cardinal.mk_compl_eq_mk_compl_finite Cardinal.mk_compl_eq_mk_compl_finite theorem mk_compl_eq_mk_compl_finite_same {α : Type u} [Finite α] {s t : Set α} (h : #s = #t) : #(sᶜ : Set α) = #(tᶜ : Set α) := mk_compl_eq_mk_compl_finite.{u, u} rfl h #align cardinal.mk_compl_eq_mk_compl_finite_same Cardinal.mk_compl_eq_mk_compl_finite_same end compl /-! ### Extending an injection to an equiv -/
Mathlib/SetTheory/Cardinal/Ordinal.lean
1,371
1,377
theorem extend_function {α β : Type*} {s : Set α} (f : s ↪ β) (h : Nonempty ((sᶜ : Set α) ≃ ((range f)ᶜ : Set β))) : ∃ g : α ≃ β, ∀ x : s, g x = f x := by
have := h; cases' this with g let h : α ≃ β := (Set.sumCompl (s : Set α)).symm.trans ((sumCongr (Equiv.ofInjective f f.2) g).trans (Set.sumCompl (range f))) refine ⟨h, ?_⟩; rintro ⟨x, hx⟩; simp [h, Set.sumCompl_symm_apply_of_mem, hx]
/- 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, Floris van Doorn -/ import Mathlib.Analysis.Calculus.ContDiff.Defs import Mathlib.Analysis.Calculus.FDeriv.Add import Mathlib.Analysis.Calculus.FDeriv.Mul import Mathlib.Analysis.Calculus.Deriv.Inverse #align_import analysis.calculus.cont_diff from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # Higher differentiability of usual operations We prove that the usual operations (addition, multiplication, difference, composition, and so on) preserve `C^n` functions. We also expand the API around `C^n` functions. ## Main results * `ContDiff.comp` states that the composition of two `C^n` functions is `C^n`. Similar results are given for `C^n` functions on domains. ## Notations We use the notation `E [×n]→L[𝕜] F` for the space of continuous multilinear maps on `E^n` with values in `F`. This is the space in which the `n`-th derivative of a function from `E` to `F` lives. In this file, we denote `⊤ : ℕ∞` with `∞`. ## Tags derivative, differentiability, higher derivative, `C^n`, multilinear, Taylor series, formal series -/ noncomputable section open scoped Classical NNReal Nat local notation "∞" => (⊤ : ℕ∞) universe u v w uD uE uF uG attribute [local instance 1001] NormedAddCommGroup.toAddCommGroup NormedSpace.toModule' AddCommGroup.toAddCommMonoid open Set Fin Filter Function open scoped Topology variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {D : Type uD} [NormedAddCommGroup D] [NormedSpace 𝕜 D] {E : Type uE} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type uF} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type uG} [NormedAddCommGroup G] [NormedSpace 𝕜 G] {X : Type*} [NormedAddCommGroup X] [NormedSpace 𝕜 X] {s s₁ t u : Set E} {f f₁ : E → F} {g : F → G} {x x₀ : E} {c : F} {b : E × F → G} {m n : ℕ∞} {p : E → FormalMultilinearSeries 𝕜 E F} /-! ### Constants -/ @[simp] theorem iteratedFDerivWithin_zero_fun (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) {i : ℕ} : iteratedFDerivWithin 𝕜 i (fun _ : E ↦ (0 : F)) s x = 0 := by induction i generalizing x with | zero => ext; simp | succ i IH => ext m rw [iteratedFDerivWithin_succ_apply_left, fderivWithin_congr (fun _ ↦ IH) (IH hx)] rw [fderivWithin_const_apply _ (hs x hx)] rfl @[simp] theorem iteratedFDeriv_zero_fun {n : ℕ} : (iteratedFDeriv 𝕜 n fun _ : E ↦ (0 : F)) = 0 := funext fun x ↦ by simpa [← iteratedFDerivWithin_univ] using iteratedFDerivWithin_zero_fun uniqueDiffOn_univ (mem_univ x) #align iterated_fderiv_zero_fun iteratedFDeriv_zero_fun theorem contDiff_zero_fun : ContDiff 𝕜 n fun _ : E => (0 : F) := contDiff_of_differentiable_iteratedFDeriv fun m _ => by rw [iteratedFDeriv_zero_fun] exact differentiable_const (0 : E[×m]→L[𝕜] F) #align cont_diff_zero_fun contDiff_zero_fun /-- Constants are `C^∞`. -/ theorem contDiff_const {c : F} : ContDiff 𝕜 n fun _ : E => c := by suffices h : ContDiff 𝕜 ∞ fun _ : E => c from h.of_le le_top rw [contDiff_top_iff_fderiv] refine ⟨differentiable_const c, ?_⟩ rw [fderiv_const] exact contDiff_zero_fun #align cont_diff_const contDiff_const theorem contDiffOn_const {c : F} {s : Set E} : ContDiffOn 𝕜 n (fun _ : E => c) s := contDiff_const.contDiffOn #align cont_diff_on_const contDiffOn_const theorem contDiffAt_const {c : F} : ContDiffAt 𝕜 n (fun _ : E => c) x := contDiff_const.contDiffAt #align cont_diff_at_const contDiffAt_const theorem contDiffWithinAt_const {c : F} : ContDiffWithinAt 𝕜 n (fun _ : E => c) s x := contDiffAt_const.contDiffWithinAt #align cont_diff_within_at_const contDiffWithinAt_const @[nontriviality] theorem contDiff_of_subsingleton [Subsingleton F] : ContDiff 𝕜 n f := by rw [Subsingleton.elim f fun _ => 0]; exact contDiff_const #align cont_diff_of_subsingleton contDiff_of_subsingleton @[nontriviality] theorem contDiffAt_of_subsingleton [Subsingleton F] : ContDiffAt 𝕜 n f x := by rw [Subsingleton.elim f fun _ => 0]; exact contDiffAt_const #align cont_diff_at_of_subsingleton contDiffAt_of_subsingleton @[nontriviality] theorem contDiffWithinAt_of_subsingleton [Subsingleton F] : ContDiffWithinAt 𝕜 n f s x := by rw [Subsingleton.elim f fun _ => 0]; exact contDiffWithinAt_const #align cont_diff_within_at_of_subsingleton contDiffWithinAt_of_subsingleton @[nontriviality] theorem contDiffOn_of_subsingleton [Subsingleton F] : ContDiffOn 𝕜 n f s := by rw [Subsingleton.elim f fun _ => 0]; exact contDiffOn_const #align cont_diff_on_of_subsingleton contDiffOn_of_subsingleton theorem iteratedFDerivWithin_succ_const (n : ℕ) (c : F) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : iteratedFDerivWithin 𝕜 (n + 1) (fun _ : E ↦ c) s x = 0 := by ext m rw [iteratedFDerivWithin_succ_apply_right hs hx] rw [iteratedFDerivWithin_congr (fun y hy ↦ fderivWithin_const_apply c (hs y hy)) hx] rw [iteratedFDerivWithin_zero_fun hs hx] simp [ContinuousMultilinearMap.zero_apply (R := 𝕜)] theorem iteratedFDeriv_succ_const (n : ℕ) (c : F) : (iteratedFDeriv 𝕜 (n + 1) fun _ : E ↦ c) = 0 := funext fun x ↦ by simpa [← iteratedFDerivWithin_univ] using iteratedFDerivWithin_succ_const n c uniqueDiffOn_univ (mem_univ x) #align iterated_fderiv_succ_const iteratedFDeriv_succ_const theorem iteratedFDerivWithin_const_of_ne {n : ℕ} (hn : n ≠ 0) (c : F) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : iteratedFDerivWithin 𝕜 n (fun _ : E ↦ c) s x = 0 := by cases n with | zero => contradiction | succ n => exact iteratedFDerivWithin_succ_const n c hs hx theorem iteratedFDeriv_const_of_ne {n : ℕ} (hn : n ≠ 0) (c : F) : (iteratedFDeriv 𝕜 n fun _ : E ↦ c) = 0 := funext fun x ↦ by simpa [← iteratedFDerivWithin_univ] using iteratedFDerivWithin_const_of_ne hn c uniqueDiffOn_univ (mem_univ x) #align iterated_fderiv_const_of_ne iteratedFDeriv_const_of_ne /-! ### Smoothness of linear functions -/ /-- Unbundled bounded linear functions are `C^∞`. -/ theorem IsBoundedLinearMap.contDiff (hf : IsBoundedLinearMap 𝕜 f) : ContDiff 𝕜 n f := by suffices h : ContDiff 𝕜 ∞ f from h.of_le le_top rw [contDiff_top_iff_fderiv] refine ⟨hf.differentiable, ?_⟩ simp_rw [hf.fderiv] exact contDiff_const #align is_bounded_linear_map.cont_diff IsBoundedLinearMap.contDiff theorem ContinuousLinearMap.contDiff (f : E →L[𝕜] F) : ContDiff 𝕜 n f := f.isBoundedLinearMap.contDiff #align continuous_linear_map.cont_diff ContinuousLinearMap.contDiff theorem ContinuousLinearEquiv.contDiff (f : E ≃L[𝕜] F) : ContDiff 𝕜 n f := (f : E →L[𝕜] F).contDiff #align continuous_linear_equiv.cont_diff ContinuousLinearEquiv.contDiff theorem LinearIsometry.contDiff (f : E →ₗᵢ[𝕜] F) : ContDiff 𝕜 n f := f.toContinuousLinearMap.contDiff #align linear_isometry.cont_diff LinearIsometry.contDiff theorem LinearIsometryEquiv.contDiff (f : E ≃ₗᵢ[𝕜] F) : ContDiff 𝕜 n f := (f : E →L[𝕜] F).contDiff #align linear_isometry_equiv.cont_diff LinearIsometryEquiv.contDiff /-- The identity is `C^∞`. -/ theorem contDiff_id : ContDiff 𝕜 n (id : E → E) := IsBoundedLinearMap.id.contDiff #align cont_diff_id contDiff_id theorem contDiffWithinAt_id {s x} : ContDiffWithinAt 𝕜 n (id : E → E) s x := contDiff_id.contDiffWithinAt #align cont_diff_within_at_id contDiffWithinAt_id theorem contDiffAt_id {x} : ContDiffAt 𝕜 n (id : E → E) x := contDiff_id.contDiffAt #align cont_diff_at_id contDiffAt_id theorem contDiffOn_id {s} : ContDiffOn 𝕜 n (id : E → E) s := contDiff_id.contDiffOn #align cont_diff_on_id contDiffOn_id /-- Bilinear functions are `C^∞`. -/ theorem IsBoundedBilinearMap.contDiff (hb : IsBoundedBilinearMap 𝕜 b) : ContDiff 𝕜 n b := by suffices h : ContDiff 𝕜 ∞ b from h.of_le le_top rw [contDiff_top_iff_fderiv] refine ⟨hb.differentiable, ?_⟩ simp only [hb.fderiv] exact hb.isBoundedLinearMap_deriv.contDiff #align is_bounded_bilinear_map.cont_diff IsBoundedBilinearMap.contDiff /-- If `f` admits a Taylor series `p` in a set `s`, and `g` is linear, then `g ∘ f` admits a Taylor series whose `k`-th term is given by `g ∘ (p k)`. -/ theorem HasFTaylorSeriesUpToOn.continuousLinearMap_comp (g : F →L[𝕜] G) (hf : HasFTaylorSeriesUpToOn n f p s) : HasFTaylorSeriesUpToOn n (g ∘ f) (fun x k => g.compContinuousMultilinearMap (p x k)) s where zero_eq x hx := congr_arg g (hf.zero_eq x hx) fderivWithin m hm x hx := (ContinuousLinearMap.compContinuousMultilinearMapL 𝕜 (fun _ : Fin m => E) F G g).hasFDerivAt.comp_hasFDerivWithinAt x (hf.fderivWithin m hm x hx) cont m hm := (ContinuousLinearMap.compContinuousMultilinearMapL 𝕜 (fun _ : Fin m => E) F G g).continuous.comp_continuousOn (hf.cont m hm) #align has_ftaylor_series_up_to_on.continuous_linear_map_comp HasFTaylorSeriesUpToOn.continuousLinearMap_comp /-- Composition by continuous linear maps on the left preserves `C^n` functions in a domain at a point. -/ theorem ContDiffWithinAt.continuousLinearMap_comp (g : F →L[𝕜] G) (hf : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n (g ∘ f) s x := fun m hm ↦ by rcases hf m hm with ⟨u, hu, p, hp⟩ exact ⟨u, hu, _, hp.continuousLinearMap_comp g⟩ #align cont_diff_within_at.continuous_linear_map_comp ContDiffWithinAt.continuousLinearMap_comp /-- Composition by continuous linear maps on the left preserves `C^n` functions in a domain at a point. -/ theorem ContDiffAt.continuousLinearMap_comp (g : F →L[𝕜] G) (hf : ContDiffAt 𝕜 n f x) : ContDiffAt 𝕜 n (g ∘ f) x := ContDiffWithinAt.continuousLinearMap_comp g hf #align cont_diff_at.continuous_linear_map_comp ContDiffAt.continuousLinearMap_comp /-- Composition by continuous linear maps on the left preserves `C^n` functions on domains. -/ theorem ContDiffOn.continuousLinearMap_comp (g : F →L[𝕜] G) (hf : ContDiffOn 𝕜 n f s) : ContDiffOn 𝕜 n (g ∘ f) s := fun x hx => (hf x hx).continuousLinearMap_comp g #align cont_diff_on.continuous_linear_map_comp ContDiffOn.continuousLinearMap_comp /-- Composition by continuous linear maps on the left preserves `C^n` functions. -/ theorem ContDiff.continuousLinearMap_comp {f : E → F} (g : F →L[𝕜] G) (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x => g (f x) := contDiffOn_univ.1 <| ContDiffOn.continuousLinearMap_comp _ (contDiffOn_univ.2 hf) #align cont_diff.continuous_linear_map_comp ContDiff.continuousLinearMap_comp /-- The iterated derivative within a set of the composition with a linear map on the left is obtained by applying the linear map to the iterated derivative. -/ theorem ContinuousLinearMap.iteratedFDerivWithin_comp_left {f : E → F} (g : F →L[𝕜] G) (hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) {i : ℕ} (hi : (i : ℕ∞) ≤ n) : iteratedFDerivWithin 𝕜 i (g ∘ f) s x = g.compContinuousMultilinearMap (iteratedFDerivWithin 𝕜 i f s x) := (((hf.ftaylorSeriesWithin hs).continuousLinearMap_comp g).eq_iteratedFDerivWithin_of_uniqueDiffOn hi hs hx).symm #align continuous_linear_map.iterated_fderiv_within_comp_left ContinuousLinearMap.iteratedFDerivWithin_comp_left /-- The iterated derivative of the composition with a linear map on the left is obtained by applying the linear map to the iterated derivative. -/ theorem ContinuousLinearMap.iteratedFDeriv_comp_left {f : E → F} (g : F →L[𝕜] G) (hf : ContDiff 𝕜 n f) (x : E) {i : ℕ} (hi : (i : ℕ∞) ≤ n) : iteratedFDeriv 𝕜 i (g ∘ f) x = g.compContinuousMultilinearMap (iteratedFDeriv 𝕜 i f x) := by simp only [← iteratedFDerivWithin_univ] exact g.iteratedFDerivWithin_comp_left hf.contDiffOn uniqueDiffOn_univ (mem_univ x) hi #align continuous_linear_map.iterated_fderiv_comp_left ContinuousLinearMap.iteratedFDeriv_comp_left /-- The iterated derivative within a set of the composition with a linear equiv on the left is obtained by applying the linear equiv to the iterated derivative. This is true without differentiability assumptions. -/ theorem ContinuousLinearEquiv.iteratedFDerivWithin_comp_left (g : F ≃L[𝕜] G) (f : E → F) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (i : ℕ) : iteratedFDerivWithin 𝕜 i (g ∘ f) s x = (g : F →L[𝕜] G).compContinuousMultilinearMap (iteratedFDerivWithin 𝕜 i f s x) := by induction' i with i IH generalizing x · ext1 m simp only [Nat.zero_eq, iteratedFDerivWithin_zero_apply, comp_apply, ContinuousLinearMap.compContinuousMultilinearMap_coe, coe_coe] · ext1 m rw [iteratedFDerivWithin_succ_apply_left] have Z : fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 i (g ∘ f) s) s x = fderivWithin 𝕜 (g.compContinuousMultilinearMapL (fun _ : Fin i => E) ∘ iteratedFDerivWithin 𝕜 i f s) s x := fderivWithin_congr' (@IH) hx simp_rw [Z] rw [(g.compContinuousMultilinearMapL fun _ : Fin i => E).comp_fderivWithin (hs x hx)] simp only [ContinuousLinearMap.coe_comp', ContinuousLinearEquiv.coe_coe, comp_apply, ContinuousLinearEquiv.compContinuousMultilinearMapL_apply, ContinuousLinearMap.compContinuousMultilinearMap_coe, EmbeddingLike.apply_eq_iff_eq] rw [iteratedFDerivWithin_succ_apply_left] #align continuous_linear_equiv.iterated_fderiv_within_comp_left ContinuousLinearEquiv.iteratedFDerivWithin_comp_left /-- Composition with a linear isometry on the left preserves the norm of the iterated derivative within a set. -/ theorem LinearIsometry.norm_iteratedFDerivWithin_comp_left {f : E → F} (g : F →ₗᵢ[𝕜] G) (hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) {i : ℕ} (hi : (i : ℕ∞) ≤ n) : ‖iteratedFDerivWithin 𝕜 i (g ∘ f) s x‖ = ‖iteratedFDerivWithin 𝕜 i f s x‖ := by have : iteratedFDerivWithin 𝕜 i (g ∘ f) s x = g.toContinuousLinearMap.compContinuousMultilinearMap (iteratedFDerivWithin 𝕜 i f s x) := g.toContinuousLinearMap.iteratedFDerivWithin_comp_left hf hs hx hi rw [this] apply LinearIsometry.norm_compContinuousMultilinearMap #align linear_isometry.norm_iterated_fderiv_within_comp_left LinearIsometry.norm_iteratedFDerivWithin_comp_left /-- Composition with a linear isometry on the left preserves the norm of the iterated derivative. -/ theorem LinearIsometry.norm_iteratedFDeriv_comp_left {f : E → F} (g : F →ₗᵢ[𝕜] G) (hf : ContDiff 𝕜 n f) (x : E) {i : ℕ} (hi : (i : ℕ∞) ≤ n) : ‖iteratedFDeriv 𝕜 i (g ∘ f) x‖ = ‖iteratedFDeriv 𝕜 i f x‖ := by simp only [← iteratedFDerivWithin_univ] exact g.norm_iteratedFDerivWithin_comp_left hf.contDiffOn uniqueDiffOn_univ (mem_univ x) hi #align linear_isometry.norm_iterated_fderiv_comp_left LinearIsometry.norm_iteratedFDeriv_comp_left /-- Composition with a linear isometry equiv on the left preserves the norm of the iterated derivative within a set. -/ theorem LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_left (g : F ≃ₗᵢ[𝕜] G) (f : E → F) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (i : ℕ) : ‖iteratedFDerivWithin 𝕜 i (g ∘ f) s x‖ = ‖iteratedFDerivWithin 𝕜 i f s x‖ := by have : iteratedFDerivWithin 𝕜 i (g ∘ f) s x = (g : F →L[𝕜] G).compContinuousMultilinearMap (iteratedFDerivWithin 𝕜 i f s x) := g.toContinuousLinearEquiv.iteratedFDerivWithin_comp_left f hs hx i rw [this] apply LinearIsometry.norm_compContinuousMultilinearMap g.toLinearIsometry #align linear_isometry_equiv.norm_iterated_fderiv_within_comp_left LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_left /-- Composition with a linear isometry equiv on the left preserves the norm of the iterated derivative. -/ theorem LinearIsometryEquiv.norm_iteratedFDeriv_comp_left (g : F ≃ₗᵢ[𝕜] G) (f : E → F) (x : E) (i : ℕ) : ‖iteratedFDeriv 𝕜 i (g ∘ f) x‖ = ‖iteratedFDeriv 𝕜 i f x‖ := by rw [← iteratedFDerivWithin_univ, ← iteratedFDerivWithin_univ] apply g.norm_iteratedFDerivWithin_comp_left f uniqueDiffOn_univ (mem_univ x) i #align linear_isometry_equiv.norm_iterated_fderiv_comp_left LinearIsometryEquiv.norm_iteratedFDeriv_comp_left /-- Composition by continuous linear equivs on the left respects higher differentiability at a point in a domain. -/ theorem ContinuousLinearEquiv.comp_contDiffWithinAt_iff (e : F ≃L[𝕜] G) : ContDiffWithinAt 𝕜 n (e ∘ f) s x ↔ ContDiffWithinAt 𝕜 n f s x := ⟨fun H => by simpa only [(· ∘ ·), e.symm.coe_coe, e.symm_apply_apply] using H.continuousLinearMap_comp (e.symm : G →L[𝕜] F), fun H => H.continuousLinearMap_comp (e : F →L[𝕜] G)⟩ #align continuous_linear_equiv.comp_cont_diff_within_at_iff ContinuousLinearEquiv.comp_contDiffWithinAt_iff /-- Composition by continuous linear equivs on the left respects higher differentiability at a point. -/ theorem ContinuousLinearEquiv.comp_contDiffAt_iff (e : F ≃L[𝕜] G) : ContDiffAt 𝕜 n (e ∘ f) x ↔ ContDiffAt 𝕜 n f x := by simp only [← contDiffWithinAt_univ, e.comp_contDiffWithinAt_iff] #align continuous_linear_equiv.comp_cont_diff_at_iff ContinuousLinearEquiv.comp_contDiffAt_iff /-- Composition by continuous linear equivs on the left respects higher differentiability on domains. -/ theorem ContinuousLinearEquiv.comp_contDiffOn_iff (e : F ≃L[𝕜] G) : ContDiffOn 𝕜 n (e ∘ f) s ↔ ContDiffOn 𝕜 n f s := by simp [ContDiffOn, e.comp_contDiffWithinAt_iff] #align continuous_linear_equiv.comp_cont_diff_on_iff ContinuousLinearEquiv.comp_contDiffOn_iff /-- Composition by continuous linear equivs on the left respects higher differentiability. -/ theorem ContinuousLinearEquiv.comp_contDiff_iff (e : F ≃L[𝕜] G) : ContDiff 𝕜 n (e ∘ f) ↔ ContDiff 𝕜 n f := by simp only [← contDiffOn_univ, e.comp_contDiffOn_iff] #align continuous_linear_equiv.comp_cont_diff_iff ContinuousLinearEquiv.comp_contDiff_iff /-- If `f` admits a Taylor series `p` in a set `s`, and `g` is linear, then `f ∘ g` admits a Taylor series in `g ⁻¹' s`, whose `k`-th term is given by `p k (g v₁, ..., g vₖ)` . -/ theorem HasFTaylorSeriesUpToOn.compContinuousLinearMap (hf : HasFTaylorSeriesUpToOn n f p s) (g : G →L[𝕜] E) : HasFTaylorSeriesUpToOn n (f ∘ g) (fun x k => (p (g x) k).compContinuousLinearMap fun _ => g) (g ⁻¹' s) := by let A : ∀ m : ℕ, (E[×m]→L[𝕜] F) → G[×m]→L[𝕜] F := fun m h => h.compContinuousLinearMap fun _ => g have hA : ∀ m, IsBoundedLinearMap 𝕜 (A m) := fun m => isBoundedLinearMap_continuousMultilinearMap_comp_linear g constructor · intro x hx simp only [(hf.zero_eq (g x) hx).symm, Function.comp_apply] change (p (g x) 0 fun _ : Fin 0 => g 0) = p (g x) 0 0 rw [ContinuousLinearMap.map_zero] rfl · intro m hm x hx convert (hA m).hasFDerivAt.comp_hasFDerivWithinAt x ((hf.fderivWithin m hm (g x) hx).comp x g.hasFDerivWithinAt (Subset.refl _)) ext y v change p (g x) (Nat.succ m) (g ∘ cons y v) = p (g x) m.succ (cons (g y) (g ∘ v)) rw [comp_cons] · intro m hm exact (hA m).continuous.comp_continuousOn <| (hf.cont m hm).comp g.continuous.continuousOn <| Subset.refl _ #align has_ftaylor_series_up_to_on.comp_continuous_linear_map HasFTaylorSeriesUpToOn.compContinuousLinearMap /-- Composition by continuous linear maps on the right preserves `C^n` functions at a point on a domain. -/ theorem ContDiffWithinAt.comp_continuousLinearMap {x : G} (g : G →L[𝕜] E) (hf : ContDiffWithinAt 𝕜 n f s (g x)) : ContDiffWithinAt 𝕜 n (f ∘ g) (g ⁻¹' s) x := by intro m hm rcases hf m hm with ⟨u, hu, p, hp⟩ refine ⟨g ⁻¹' u, ?_, _, hp.compContinuousLinearMap g⟩ refine g.continuous.continuousWithinAt.tendsto_nhdsWithin ?_ hu exact (mapsTo_singleton.2 <| mem_singleton _).union_union (mapsTo_preimage _ _) #align cont_diff_within_at.comp_continuous_linear_map ContDiffWithinAt.comp_continuousLinearMap /-- Composition by continuous linear maps on the right preserves `C^n` functions on domains. -/ theorem ContDiffOn.comp_continuousLinearMap (hf : ContDiffOn 𝕜 n f s) (g : G →L[𝕜] E) : ContDiffOn 𝕜 n (f ∘ g) (g ⁻¹' s) := fun x hx => (hf (g x) hx).comp_continuousLinearMap g #align cont_diff_on.comp_continuous_linear_map ContDiffOn.comp_continuousLinearMap /-- Composition by continuous linear maps on the right preserves `C^n` functions. -/ theorem ContDiff.comp_continuousLinearMap {f : E → F} {g : G →L[𝕜] E} (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n (f ∘ g) := contDiffOn_univ.1 <| ContDiffOn.comp_continuousLinearMap (contDiffOn_univ.2 hf) _ #align cont_diff.comp_continuous_linear_map ContDiff.comp_continuousLinearMap /-- The iterated derivative within a set of the composition with a linear map on the right is obtained by composing the iterated derivative with the linear map. -/ theorem ContinuousLinearMap.iteratedFDerivWithin_comp_right {f : E → F} (g : G →L[𝕜] E) (hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (h's : UniqueDiffOn 𝕜 (g ⁻¹' s)) {x : G} (hx : g x ∈ s) {i : ℕ} (hi : (i : ℕ∞) ≤ n) : iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s) x = (iteratedFDerivWithin 𝕜 i f s (g x)).compContinuousLinearMap fun _ => g := (((hf.ftaylorSeriesWithin hs).compContinuousLinearMap g).eq_iteratedFDerivWithin_of_uniqueDiffOn hi h's hx).symm #align continuous_linear_map.iterated_fderiv_within_comp_right ContinuousLinearMap.iteratedFDerivWithin_comp_right /-- The iterated derivative within a set of the composition with a linear equiv on the right is obtained by composing the iterated derivative with the linear equiv. -/ theorem ContinuousLinearEquiv.iteratedFDerivWithin_comp_right (g : G ≃L[𝕜] E) (f : E → F) (hs : UniqueDiffOn 𝕜 s) {x : G} (hx : g x ∈ s) (i : ℕ) : iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s) x = (iteratedFDerivWithin 𝕜 i f s (g x)).compContinuousLinearMap fun _ => g := by induction' i with i IH generalizing x · ext1 simp only [Nat.zero_eq, iteratedFDerivWithin_zero_apply, comp_apply, ContinuousMultilinearMap.compContinuousLinearMap_apply] · ext1 m simp only [ContinuousMultilinearMap.compContinuousLinearMap_apply, ContinuousLinearEquiv.coe_coe, iteratedFDerivWithin_succ_apply_left] have : fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s)) (g ⁻¹' s) x = fderivWithin 𝕜 (ContinuousMultilinearMap.compContinuousLinearMapEquivL _ (fun _x : Fin i => g) ∘ (iteratedFDerivWithin 𝕜 i f s ∘ g)) (g ⁻¹' s) x := fderivWithin_congr' (@IH) hx rw [this, ContinuousLinearEquiv.comp_fderivWithin _ (g.uniqueDiffOn_preimage_iff.2 hs x hx)] simp only [ContinuousLinearMap.coe_comp', ContinuousLinearEquiv.coe_coe, comp_apply, ContinuousMultilinearMap.compContinuousLinearMapEquivL_apply, ContinuousMultilinearMap.compContinuousLinearMap_apply] rw [ContinuousLinearEquiv.comp_right_fderivWithin _ (g.uniqueDiffOn_preimage_iff.2 hs x hx), ContinuousLinearMap.coe_comp', coe_coe, comp_apply, tail_def, tail_def] #align continuous_linear_equiv.iterated_fderiv_within_comp_right ContinuousLinearEquiv.iteratedFDerivWithin_comp_right /-- The iterated derivative of the composition with a linear map on the right is obtained by composing the iterated derivative with the linear map. -/ theorem ContinuousLinearMap.iteratedFDeriv_comp_right (g : G →L[𝕜] E) {f : E → F} (hf : ContDiff 𝕜 n f) (x : G) {i : ℕ} (hi : (i : ℕ∞) ≤ n) : iteratedFDeriv 𝕜 i (f ∘ g) x = (iteratedFDeriv 𝕜 i f (g x)).compContinuousLinearMap fun _ => g := by simp only [← iteratedFDerivWithin_univ] exact g.iteratedFDerivWithin_comp_right hf.contDiffOn uniqueDiffOn_univ uniqueDiffOn_univ (mem_univ _) hi #align continuous_linear_map.iterated_fderiv_comp_right ContinuousLinearMap.iteratedFDeriv_comp_right /-- Composition with a linear isometry on the right preserves the norm of the iterated derivative within a set. -/ theorem LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_right (g : G ≃ₗᵢ[𝕜] E) (f : E → F) (hs : UniqueDiffOn 𝕜 s) {x : G} (hx : g x ∈ s) (i : ℕ) : ‖iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s) x‖ = ‖iteratedFDerivWithin 𝕜 i f s (g x)‖ := by have : iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s) x = (iteratedFDerivWithin 𝕜 i f s (g x)).compContinuousLinearMap fun _ => g := g.toContinuousLinearEquiv.iteratedFDerivWithin_comp_right f hs hx i rw [this, ContinuousMultilinearMap.norm_compContinuous_linearIsometryEquiv] #align linear_isometry_equiv.norm_iterated_fderiv_within_comp_right LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_right /-- Composition with a linear isometry on the right preserves the norm of the iterated derivative within a set. -/ theorem LinearIsometryEquiv.norm_iteratedFDeriv_comp_right (g : G ≃ₗᵢ[𝕜] E) (f : E → F) (x : G) (i : ℕ) : ‖iteratedFDeriv 𝕜 i (f ∘ g) x‖ = ‖iteratedFDeriv 𝕜 i f (g x)‖ := by simp only [← iteratedFDerivWithin_univ] apply g.norm_iteratedFDerivWithin_comp_right f uniqueDiffOn_univ (mem_univ (g x)) i #align linear_isometry_equiv.norm_iterated_fderiv_comp_right LinearIsometryEquiv.norm_iteratedFDeriv_comp_right /-- Composition by continuous linear equivs on the right respects higher differentiability at a point in a domain. -/ theorem ContinuousLinearEquiv.contDiffWithinAt_comp_iff (e : G ≃L[𝕜] E) : ContDiffWithinAt 𝕜 n (f ∘ e) (e ⁻¹' s) (e.symm x) ↔ ContDiffWithinAt 𝕜 n f s x := by constructor · intro H simpa [← preimage_comp, (· ∘ ·)] using H.comp_continuousLinearMap (e.symm : E →L[𝕜] G) · intro H rw [← e.apply_symm_apply x, ← e.coe_coe] at H exact H.comp_continuousLinearMap _ #align continuous_linear_equiv.cont_diff_within_at_comp_iff ContinuousLinearEquiv.contDiffWithinAt_comp_iff /-- Composition by continuous linear equivs on the right respects higher differentiability at a point. -/ theorem ContinuousLinearEquiv.contDiffAt_comp_iff (e : G ≃L[𝕜] E) : ContDiffAt 𝕜 n (f ∘ e) (e.symm x) ↔ ContDiffAt 𝕜 n f x := by rw [← contDiffWithinAt_univ, ← contDiffWithinAt_univ, ← preimage_univ] exact e.contDiffWithinAt_comp_iff #align continuous_linear_equiv.cont_diff_at_comp_iff ContinuousLinearEquiv.contDiffAt_comp_iff /-- Composition by continuous linear equivs on the right respects higher differentiability on domains. -/ theorem ContinuousLinearEquiv.contDiffOn_comp_iff (e : G ≃L[𝕜] E) : ContDiffOn 𝕜 n (f ∘ e) (e ⁻¹' s) ↔ ContDiffOn 𝕜 n f s := ⟨fun H => by simpa [(· ∘ ·)] using H.comp_continuousLinearMap (e.symm : E →L[𝕜] G), fun H => H.comp_continuousLinearMap (e : G →L[𝕜] E)⟩ #align continuous_linear_equiv.cont_diff_on_comp_iff ContinuousLinearEquiv.contDiffOn_comp_iff /-- Composition by continuous linear equivs on the right respects higher differentiability. -/
Mathlib/Analysis/Calculus/ContDiff/Basic.lean
508
511
theorem ContinuousLinearEquiv.contDiff_comp_iff (e : G ≃L[𝕜] E) : ContDiff 𝕜 n (f ∘ e) ↔ ContDiff 𝕜 n f := by
rw [← contDiffOn_univ, ← contDiffOn_univ, ← preimage_univ] exact e.contDiffOn_comp_iff
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl, Patrick Massot -/ import Mathlib.Data.Set.Image import Mathlib.Data.SProd #align_import data.set.prod from "leanprover-community/mathlib"@"48fb5b5280e7c81672afc9524185ae994553ebf4" /-! # Sets in product and pi types This file defines the product of sets in `α × β` and in `Π i, α i` along with the diagonal of a type. ## Main declarations * `Set.prod`: Binary product of sets. For `s : Set α`, `t : Set β`, we have `s.prod t : Set (α × β)`. * `Set.diagonal`: Diagonal of a type. `Set.diagonal α = {(x, x) | x : α}`. * `Set.offDiag`: Off-diagonal. `s ×ˢ s` without the diagonal. * `Set.pi`: Arbitrary product of sets. -/ open Function namespace Set /-! ### Cartesian binary product of sets -/ section Prod variable {α β γ δ : Type*} {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {a : α} {b : β} theorem Subsingleton.prod (hs : s.Subsingleton) (ht : t.Subsingleton) : (s ×ˢ t).Subsingleton := fun _x hx _y hy ↦ Prod.ext (hs hx.1 hy.1) (ht hx.2 hy.2) noncomputable instance decidableMemProd [DecidablePred (· ∈ s)] [DecidablePred (· ∈ t)] : DecidablePred (· ∈ s ×ˢ t) := fun _ => And.decidable #align set.decidable_mem_prod Set.decidableMemProd @[gcongr] theorem prod_mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : s₁ ×ˢ t₁ ⊆ s₂ ×ˢ t₂ := fun _ ⟨h₁, h₂⟩ => ⟨hs h₁, ht h₂⟩ #align set.prod_mono Set.prod_mono @[gcongr] theorem prod_mono_left (hs : s₁ ⊆ s₂) : s₁ ×ˢ t ⊆ s₂ ×ˢ t := prod_mono hs Subset.rfl #align set.prod_mono_left Set.prod_mono_left @[gcongr] theorem prod_mono_right (ht : t₁ ⊆ t₂) : s ×ˢ t₁ ⊆ s ×ˢ t₂ := prod_mono Subset.rfl ht #align set.prod_mono_right Set.prod_mono_right @[simp] theorem prod_self_subset_prod_self : s₁ ×ˢ s₁ ⊆ s₂ ×ˢ s₂ ↔ s₁ ⊆ s₂ := ⟨fun h _ hx => (h (mk_mem_prod hx hx)).1, fun h _ hx => ⟨h hx.1, h hx.2⟩⟩ #align set.prod_self_subset_prod_self Set.prod_self_subset_prod_self @[simp] theorem prod_self_ssubset_prod_self : s₁ ×ˢ s₁ ⊂ s₂ ×ˢ s₂ ↔ s₁ ⊂ s₂ := and_congr prod_self_subset_prod_self <| not_congr prod_self_subset_prod_self #align set.prod_self_ssubset_prod_self Set.prod_self_ssubset_prod_self theorem prod_subset_iff {P : Set (α × β)} : s ×ˢ t ⊆ P ↔ ∀ x ∈ s, ∀ y ∈ t, (x, y) ∈ P := ⟨fun h _ hx _ hy => h (mk_mem_prod hx hy), fun h ⟨_, _⟩ hp => h _ hp.1 _ hp.2⟩ #align set.prod_subset_iff Set.prod_subset_iff theorem forall_prod_set {p : α × β → Prop} : (∀ x ∈ s ×ˢ t, p x) ↔ ∀ x ∈ s, ∀ y ∈ t, p (x, y) := prod_subset_iff #align set.forall_prod_set Set.forall_prod_set theorem exists_prod_set {p : α × β → Prop} : (∃ x ∈ s ×ˢ t, p x) ↔ ∃ x ∈ s, ∃ y ∈ t, p (x, y) := by simp [and_assoc] #align set.exists_prod_set Set.exists_prod_set @[simp] theorem prod_empty : s ×ˢ (∅ : Set β) = ∅ := by ext exact and_false_iff _ #align set.prod_empty Set.prod_empty @[simp] theorem empty_prod : (∅ : Set α) ×ˢ t = ∅ := by ext exact false_and_iff _ #align set.empty_prod Set.empty_prod @[simp, mfld_simps] theorem univ_prod_univ : @univ α ×ˢ @univ β = univ := by ext exact true_and_iff _ #align set.univ_prod_univ Set.univ_prod_univ theorem univ_prod {t : Set β} : (univ : Set α) ×ˢ t = Prod.snd ⁻¹' t := by simp [prod_eq] #align set.univ_prod Set.univ_prod theorem prod_univ {s : Set α} : s ×ˢ (univ : Set β) = Prod.fst ⁻¹' s := by simp [prod_eq] #align set.prod_univ Set.prod_univ @[simp] lemma prod_eq_univ [Nonempty α] [Nonempty β] : s ×ˢ t = univ ↔ s = univ ∧ t = univ := by simp [eq_univ_iff_forall, forall_and] @[simp] theorem singleton_prod : ({a} : Set α) ×ˢ t = Prod.mk a '' t := by ext ⟨x, y⟩ simp [and_left_comm, eq_comm] #align set.singleton_prod Set.singleton_prod @[simp] theorem prod_singleton : s ×ˢ ({b} : Set β) = (fun a => (a, b)) '' s := by ext ⟨x, y⟩ simp [and_left_comm, eq_comm] #align set.prod_singleton Set.prod_singleton theorem singleton_prod_singleton : ({a} : Set α) ×ˢ ({b} : Set β) = {(a, b)} := by simp #align set.singleton_prod_singleton Set.singleton_prod_singleton @[simp] theorem union_prod : (s₁ ∪ s₂) ×ˢ t = s₁ ×ˢ t ∪ s₂ ×ˢ t := by ext ⟨x, y⟩ simp [or_and_right] #align set.union_prod Set.union_prod @[simp] theorem prod_union : s ×ˢ (t₁ ∪ t₂) = s ×ˢ t₁ ∪ s ×ˢ t₂ := by ext ⟨x, y⟩ simp [and_or_left] #align set.prod_union Set.prod_union theorem inter_prod : (s₁ ∩ s₂) ×ˢ t = s₁ ×ˢ t ∩ s₂ ×ˢ t := by ext ⟨x, y⟩ simp only [← and_and_right, mem_inter_iff, mem_prod] #align set.inter_prod Set.inter_prod theorem prod_inter : s ×ˢ (t₁ ∩ t₂) = s ×ˢ t₁ ∩ s ×ˢ t₂ := by ext ⟨x, y⟩ simp only [← and_and_left, mem_inter_iff, mem_prod] #align set.prod_inter Set.prod_inter @[mfld_simps] theorem prod_inter_prod : s₁ ×ˢ t₁ ∩ s₂ ×ˢ t₂ = (s₁ ∩ s₂) ×ˢ (t₁ ∩ t₂) := by ext ⟨x, y⟩ simp [and_assoc, and_left_comm] #align set.prod_inter_prod Set.prod_inter_prod lemma compl_prod_eq_union {α β : Type*} (s : Set α) (t : Set β) : (s ×ˢ t)ᶜ = (sᶜ ×ˢ univ) ∪ (univ ×ˢ tᶜ) := by ext p simp only [mem_compl_iff, mem_prod, not_and, mem_union, mem_univ, and_true, true_and] constructor <;> intro h · by_cases fst_in_s : p.fst ∈ s · exact Or.inr (h fst_in_s) · exact Or.inl fst_in_s · intro fst_in_s simpa only [fst_in_s, not_true, false_or] using h @[simp] theorem disjoint_prod : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) ↔ Disjoint s₁ s₂ ∨ Disjoint t₁ t₂ := by simp_rw [disjoint_left, mem_prod, not_and_or, Prod.forall, and_imp, ← @forall_or_right α, ← @forall_or_left β, ← @forall_or_right (_ ∈ s₁), ← @forall_or_left (_ ∈ t₁)] #align set.disjoint_prod Set.disjoint_prod theorem Disjoint.set_prod_left (hs : Disjoint s₁ s₂) (t₁ t₂ : Set β) : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) := disjoint_left.2 fun ⟨_a, _b⟩ ⟨ha₁, _⟩ ⟨ha₂, _⟩ => disjoint_left.1 hs ha₁ ha₂ #align set.disjoint.set_prod_left Set.Disjoint.set_prod_left theorem Disjoint.set_prod_right (ht : Disjoint t₁ t₂) (s₁ s₂ : Set α) : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) := disjoint_left.2 fun ⟨_a, _b⟩ ⟨_, hb₁⟩ ⟨_, hb₂⟩ => disjoint_left.1 ht hb₁ hb₂ #align set.disjoint.set_prod_right Set.Disjoint.set_prod_right theorem insert_prod : insert a s ×ˢ t = Prod.mk a '' t ∪ s ×ˢ t := by ext ⟨x, y⟩ simp (config := { contextual := true }) [image, iff_def, or_imp] #align set.insert_prod Set.insert_prod theorem prod_insert : s ×ˢ insert b t = (fun a => (a, b)) '' s ∪ s ×ˢ t := by ext ⟨x, y⟩ -- porting note (#10745): -- was `simp (config := { contextual := true }) [image, iff_def, or_imp, Imp.swap]` simp only [mem_prod, mem_insert_iff, image, mem_union, mem_setOf_eq, Prod.mk.injEq] refine ⟨fun h => ?_, fun h => ?_⟩ · obtain ⟨hx, rfl|hy⟩ := h · exact Or.inl ⟨x, hx, rfl, rfl⟩ · exact Or.inr ⟨hx, hy⟩ · obtain ⟨x, hx, rfl, rfl⟩|⟨hx, hy⟩ := h · exact ⟨hx, Or.inl rfl⟩ · exact ⟨hx, Or.inr hy⟩ #align set.prod_insert Set.prod_insert theorem prod_preimage_eq {f : γ → α} {g : δ → β} : (f ⁻¹' s) ×ˢ (g ⁻¹' t) = (fun p : γ × δ => (f p.1, g p.2)) ⁻¹' s ×ˢ t := rfl #align set.prod_preimage_eq Set.prod_preimage_eq theorem prod_preimage_left {f : γ → α} : (f ⁻¹' s) ×ˢ t = (fun p : γ × β => (f p.1, p.2)) ⁻¹' s ×ˢ t := rfl #align set.prod_preimage_left Set.prod_preimage_left theorem prod_preimage_right {g : δ → β} : s ×ˢ (g ⁻¹' t) = (fun p : α × δ => (p.1, g p.2)) ⁻¹' s ×ˢ t := rfl #align set.prod_preimage_right Set.prod_preimage_right theorem preimage_prod_map_prod (f : α → β) (g : γ → δ) (s : Set β) (t : Set δ) : Prod.map f g ⁻¹' s ×ˢ t = (f ⁻¹' s) ×ˢ (g ⁻¹' t) := rfl #align set.preimage_prod_map_prod Set.preimage_prod_map_prod theorem mk_preimage_prod (f : γ → α) (g : γ → β) : (fun x => (f x, g x)) ⁻¹' s ×ˢ t = f ⁻¹' s ∩ g ⁻¹' t := rfl #align set.mk_preimage_prod Set.mk_preimage_prod @[simp] theorem mk_preimage_prod_left (hb : b ∈ t) : (fun a => (a, b)) ⁻¹' s ×ˢ t = s := by ext a simp [hb] #align set.mk_preimage_prod_left Set.mk_preimage_prod_left @[simp] theorem mk_preimage_prod_right (ha : a ∈ s) : Prod.mk a ⁻¹' s ×ˢ t = t := by ext b simp [ha] #align set.mk_preimage_prod_right Set.mk_preimage_prod_right @[simp] theorem mk_preimage_prod_left_eq_empty (hb : b ∉ t) : (fun a => (a, b)) ⁻¹' s ×ˢ t = ∅ := by ext a simp [hb] #align set.mk_preimage_prod_left_eq_empty Set.mk_preimage_prod_left_eq_empty @[simp] theorem mk_preimage_prod_right_eq_empty (ha : a ∉ s) : Prod.mk a ⁻¹' s ×ˢ t = ∅ := by ext b simp [ha] #align set.mk_preimage_prod_right_eq_empty Set.mk_preimage_prod_right_eq_empty theorem mk_preimage_prod_left_eq_if [DecidablePred (· ∈ t)] : (fun a => (a, b)) ⁻¹' s ×ˢ t = if b ∈ t then s else ∅ := by split_ifs with h <;> simp [h] #align set.mk_preimage_prod_left_eq_if Set.mk_preimage_prod_left_eq_if theorem mk_preimage_prod_right_eq_if [DecidablePred (· ∈ s)] : Prod.mk a ⁻¹' s ×ˢ t = if a ∈ s then t else ∅ := by split_ifs with h <;> simp [h] #align set.mk_preimage_prod_right_eq_if Set.mk_preimage_prod_right_eq_if theorem mk_preimage_prod_left_fn_eq_if [DecidablePred (· ∈ t)] (f : γ → α) : (fun a => (f a, b)) ⁻¹' s ×ˢ t = if b ∈ t then f ⁻¹' s else ∅ := by rw [← mk_preimage_prod_left_eq_if, prod_preimage_left, preimage_preimage] #align set.mk_preimage_prod_left_fn_eq_if Set.mk_preimage_prod_left_fn_eq_if theorem mk_preimage_prod_right_fn_eq_if [DecidablePred (· ∈ s)] (g : δ → β) : (fun b => (a, g b)) ⁻¹' s ×ˢ t = if a ∈ s then g ⁻¹' t else ∅ := by rw [← mk_preimage_prod_right_eq_if, prod_preimage_right, preimage_preimage] #align set.mk_preimage_prod_right_fn_eq_if Set.mk_preimage_prod_right_fn_eq_if @[simp] theorem preimage_swap_prod (s : Set α) (t : Set β) : Prod.swap ⁻¹' s ×ˢ t = t ×ˢ s := by ext ⟨x, y⟩ simp [and_comm] #align set.preimage_swap_prod Set.preimage_swap_prod @[simp] theorem image_swap_prod (s : Set α) (t : Set β) : Prod.swap '' s ×ˢ t = t ×ˢ s := by rw [image_swap_eq_preimage_swap, preimage_swap_prod] #align set.image_swap_prod Set.image_swap_prod theorem prod_image_image_eq {m₁ : α → γ} {m₂ : β → δ} : (m₁ '' s) ×ˢ (m₂ '' t) = (fun p : α × β => (m₁ p.1, m₂ p.2)) '' s ×ˢ t := ext <| by simp [-exists_and_right, exists_and_right.symm, and_left_comm, and_assoc, and_comm] #align set.prod_image_image_eq Set.prod_image_image_eq theorem prod_range_range_eq {m₁ : α → γ} {m₂ : β → δ} : range m₁ ×ˢ range m₂ = range fun p : α × β => (m₁ p.1, m₂ p.2) := ext <| by simp [range] #align set.prod_range_range_eq Set.prod_range_range_eq @[simp, mfld_simps] theorem range_prod_map {m₁ : α → γ} {m₂ : β → δ} : range (Prod.map m₁ m₂) = range m₁ ×ˢ range m₂ := prod_range_range_eq.symm #align set.range_prod_map Set.range_prod_map theorem prod_range_univ_eq {m₁ : α → γ} : range m₁ ×ˢ (univ : Set β) = range fun p : α × β => (m₁ p.1, p.2) := ext <| by simp [range] #align set.prod_range_univ_eq Set.prod_range_univ_eq theorem prod_univ_range_eq {m₂ : β → δ} : (univ : Set α) ×ˢ range m₂ = range fun p : α × β => (p.1, m₂ p.2) := ext <| by simp [range] #align set.prod_univ_range_eq Set.prod_univ_range_eq theorem range_pair_subset (f : α → β) (g : α → γ) : (range fun x => (f x, g x)) ⊆ range f ×ˢ range g := by have : (fun x => (f x, g x)) = Prod.map f g ∘ fun x => (x, x) := funext fun x => rfl rw [this, ← range_prod_map] apply range_comp_subset_range #align set.range_pair_subset Set.range_pair_subset theorem Nonempty.prod : s.Nonempty → t.Nonempty → (s ×ˢ t).Nonempty := fun ⟨x, hx⟩ ⟨y, hy⟩ => ⟨(x, y), ⟨hx, hy⟩⟩ #align set.nonempty.prod Set.Nonempty.prod theorem Nonempty.fst : (s ×ˢ t).Nonempty → s.Nonempty := fun ⟨x, hx⟩ => ⟨x.1, hx.1⟩ #align set.nonempty.fst Set.Nonempty.fst theorem Nonempty.snd : (s ×ˢ t).Nonempty → t.Nonempty := fun ⟨x, hx⟩ => ⟨x.2, hx.2⟩ #align set.nonempty.snd Set.Nonempty.snd @[simp] theorem prod_nonempty_iff : (s ×ˢ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := ⟨fun h => ⟨h.fst, h.snd⟩, fun h => h.1.prod h.2⟩ #align set.prod_nonempty_iff Set.prod_nonempty_iff @[simp] theorem prod_eq_empty_iff : s ×ˢ t = ∅ ↔ s = ∅ ∨ t = ∅ := by simp only [not_nonempty_iff_eq_empty.symm, prod_nonempty_iff, not_and_or] #align set.prod_eq_empty_iff Set.prod_eq_empty_iff theorem prod_sub_preimage_iff {W : Set γ} {f : α × β → γ} : s ×ˢ t ⊆ f ⁻¹' W ↔ ∀ a b, a ∈ s → b ∈ t → f (a, b) ∈ W := by simp [subset_def] #align set.prod_sub_preimage_iff Set.prod_sub_preimage_iff theorem image_prod_mk_subset_prod {f : α → β} {g : α → γ} {s : Set α} : (fun x => (f x, g x)) '' s ⊆ (f '' s) ×ˢ (g '' s) := by rintro _ ⟨x, hx, rfl⟩ exact mk_mem_prod (mem_image_of_mem f hx) (mem_image_of_mem g hx) #align set.image_prod_mk_subset_prod Set.image_prod_mk_subset_prod theorem image_prod_mk_subset_prod_left (hb : b ∈ t) : (fun a => (a, b)) '' s ⊆ s ×ˢ t := by rintro _ ⟨a, ha, rfl⟩ exact ⟨ha, hb⟩ #align set.image_prod_mk_subset_prod_left Set.image_prod_mk_subset_prod_left theorem image_prod_mk_subset_prod_right (ha : a ∈ s) : Prod.mk a '' t ⊆ s ×ˢ t := by rintro _ ⟨b, hb, rfl⟩ exact ⟨ha, hb⟩ #align set.image_prod_mk_subset_prod_right Set.image_prod_mk_subset_prod_right theorem prod_subset_preimage_fst (s : Set α) (t : Set β) : s ×ˢ t ⊆ Prod.fst ⁻¹' s := inter_subset_left #align set.prod_subset_preimage_fst Set.prod_subset_preimage_fst theorem fst_image_prod_subset (s : Set α) (t : Set β) : Prod.fst '' s ×ˢ t ⊆ s := image_subset_iff.2 <| prod_subset_preimage_fst s t #align set.fst_image_prod_subset Set.fst_image_prod_subset theorem fst_image_prod (s : Set β) {t : Set α} (ht : t.Nonempty) : Prod.fst '' s ×ˢ t = s := (fst_image_prod_subset _ _).antisymm fun y hy => let ⟨x, hx⟩ := ht ⟨(y, x), ⟨hy, hx⟩, rfl⟩ #align set.fst_image_prod Set.fst_image_prod theorem prod_subset_preimage_snd (s : Set α) (t : Set β) : s ×ˢ t ⊆ Prod.snd ⁻¹' t := inter_subset_right #align set.prod_subset_preimage_snd Set.prod_subset_preimage_snd theorem snd_image_prod_subset (s : Set α) (t : Set β) : Prod.snd '' s ×ˢ t ⊆ t := image_subset_iff.2 <| prod_subset_preimage_snd s t #align set.snd_image_prod_subset Set.snd_image_prod_subset theorem snd_image_prod {s : Set α} (hs : s.Nonempty) (t : Set β) : Prod.snd '' s ×ˢ t = t := (snd_image_prod_subset _ _).antisymm fun y y_in => let ⟨x, x_in⟩ := hs ⟨(x, y), ⟨x_in, y_in⟩, rfl⟩ #align set.snd_image_prod Set.snd_image_prod theorem prod_diff_prod : s ×ˢ t \ s₁ ×ˢ t₁ = s ×ˢ (t \ t₁) ∪ (s \ s₁) ×ˢ t := by ext x by_cases h₁ : x.1 ∈ s₁ <;> by_cases h₂ : x.2 ∈ t₁ <;> simp [*] #align set.prod_diff_prod Set.prod_diff_prod /-- A product set is included in a product set if and only factors are included, or a factor of the first set is empty. -/ theorem prod_subset_prod_iff : s ×ˢ t ⊆ s₁ ×ˢ t₁ ↔ s ⊆ s₁ ∧ t ⊆ t₁ ∨ s = ∅ ∨ t = ∅ := by rcases (s ×ˢ t).eq_empty_or_nonempty with h | h · simp [h, prod_eq_empty_iff.1 h] have st : s.Nonempty ∧ t.Nonempty := by rwa [prod_nonempty_iff] at h refine ⟨fun H => Or.inl ⟨?_, ?_⟩, ?_⟩ · have := image_subset (Prod.fst : α × β → α) H rwa [fst_image_prod _ st.2, fst_image_prod _ (h.mono H).snd] at this · have := image_subset (Prod.snd : α × β → β) H rwa [snd_image_prod st.1, snd_image_prod (h.mono H).fst] at this · intro H simp only [st.1.ne_empty, st.2.ne_empty, or_false_iff] at H exact prod_mono H.1 H.2 #align set.prod_subset_prod_iff Set.prod_subset_prod_iff theorem prod_eq_prod_iff_of_nonempty (h : (s ×ˢ t).Nonempty) : s ×ˢ t = s₁ ×ˢ t₁ ↔ s = s₁ ∧ t = t₁ := by constructor · intro heq have h₁ : (s₁ ×ˢ t₁ : Set _).Nonempty := by rwa [← heq] rw [prod_nonempty_iff] at h h₁ rw [← fst_image_prod s h.2, ← fst_image_prod s₁ h₁.2, heq, eq_self_iff_true, true_and_iff, ← snd_image_prod h.1 t, ← snd_image_prod h₁.1 t₁, heq] · rintro ⟨rfl, rfl⟩ rfl #align set.prod_eq_prod_iff_of_nonempty Set.prod_eq_prod_iff_of_nonempty theorem prod_eq_prod_iff : s ×ˢ t = s₁ ×ˢ t₁ ↔ s = s₁ ∧ t = t₁ ∨ (s = ∅ ∨ t = ∅) ∧ (s₁ = ∅ ∨ t₁ = ∅) := by symm rcases eq_empty_or_nonempty (s ×ˢ t) with h | h · simp_rw [h, @eq_comm _ ∅, prod_eq_empty_iff, prod_eq_empty_iff.mp h, true_and_iff, or_iff_right_iff_imp] rintro ⟨rfl, rfl⟩ exact prod_eq_empty_iff.mp h rw [prod_eq_prod_iff_of_nonempty h] rw [nonempty_iff_ne_empty, Ne, prod_eq_empty_iff] at h simp_rw [h, false_and_iff, or_false_iff] #align set.prod_eq_prod_iff Set.prod_eq_prod_iff @[simp] theorem prod_eq_iff_eq (ht : t.Nonempty) : s ×ˢ t = s₁ ×ˢ t ↔ s = s₁ := by simp_rw [prod_eq_prod_iff, ht.ne_empty, and_true_iff, or_iff_left_iff_imp, or_false_iff] rintro ⟨rfl, rfl⟩ rfl #align set.prod_eq_iff_eq Set.prod_eq_iff_eq section Mono variable [Preorder α] {f : α → Set β} {g : α → Set γ} theorem _root_.Monotone.set_prod (hf : Monotone f) (hg : Monotone g) : Monotone fun x => f x ×ˢ g x := fun _ _ h => prod_mono (hf h) (hg h) #align monotone.set_prod Monotone.set_prod theorem _root_.Antitone.set_prod (hf : Antitone f) (hg : Antitone g) : Antitone fun x => f x ×ˢ g x := fun _ _ h => prod_mono (hf h) (hg h) #align antitone.set_prod Antitone.set_prod theorem _root_.MonotoneOn.set_prod (hf : MonotoneOn f s) (hg : MonotoneOn g s) : MonotoneOn (fun x => f x ×ˢ g x) s := fun _ ha _ hb h => prod_mono (hf ha hb h) (hg ha hb h) #align monotone_on.set_prod MonotoneOn.set_prod theorem _root_.AntitoneOn.set_prod (hf : AntitoneOn f s) (hg : AntitoneOn g s) : AntitoneOn (fun x => f x ×ˢ g x) s := fun _ ha _ hb h => prod_mono (hf ha hb h) (hg ha hb h) #align antitone_on.set_prod AntitoneOn.set_prod end Mono end Prod /-! ### Diagonal In this section we prove some lemmas about the diagonal set `{p | p.1 = p.2}` and the diagonal map `fun x ↦ (x, x)`. -/ section Diagonal variable {α : Type*} {s t : Set α} lemma diagonal_nonempty [Nonempty α] : (diagonal α).Nonempty := Nonempty.elim ‹_› fun x => ⟨_, mem_diagonal x⟩ #align set.diagonal_nonempty Set.diagonal_nonempty instance decidableMemDiagonal [h : DecidableEq α] (x : α × α) : Decidable (x ∈ diagonal α) := h x.1 x.2 #align set.decidable_mem_diagonal Set.decidableMemDiagonal theorem preimage_coe_coe_diagonal (s : Set α) : Prod.map (fun x : s => (x : α)) (fun x : s => (x : α)) ⁻¹' diagonal α = diagonal s := by ext ⟨⟨x, hx⟩, ⟨y, hy⟩⟩ simp [Set.diagonal] #align set.preimage_coe_coe_diagonal Set.preimage_coe_coe_diagonal @[simp] theorem range_diag : (range fun x => (x, x)) = diagonal α := by ext ⟨x, y⟩ simp [diagonal, eq_comm] #align set.range_diag Set.range_diag theorem diagonal_subset_iff {s} : diagonal α ⊆ s ↔ ∀ x, (x, x) ∈ s := by rw [← range_diag, range_subset_iff] #align set.diagonal_subset_iff Set.diagonal_subset_iff @[simp] theorem prod_subset_compl_diagonal_iff_disjoint : s ×ˢ t ⊆ (diagonal α)ᶜ ↔ Disjoint s t := prod_subset_iff.trans disjoint_iff_forall_ne.symm #align set.prod_subset_compl_diagonal_iff_disjoint Set.prod_subset_compl_diagonal_iff_disjoint @[simp] theorem diag_preimage_prod (s t : Set α) : (fun x => (x, x)) ⁻¹' s ×ˢ t = s ∩ t := rfl #align set.diag_preimage_prod Set.diag_preimage_prod theorem diag_preimage_prod_self (s : Set α) : (fun x => (x, x)) ⁻¹' s ×ˢ s = s := inter_self s #align set.diag_preimage_prod_self Set.diag_preimage_prod_self theorem diag_image (s : Set α) : (fun x => (x, x)) '' s = diagonal α ∩ s ×ˢ s := by rw [← range_diag, ← image_preimage_eq_range_inter, diag_preimage_prod_self] #align set.diag_image Set.diag_image theorem diagonal_eq_univ_iff : diagonal α = univ ↔ Subsingleton α := by simp only [subsingleton_iff, eq_univ_iff_forall, Prod.forall, mem_diagonal_iff] theorem diagonal_eq_univ [Subsingleton α] : diagonal α = univ := diagonal_eq_univ_iff.2 ‹_› end Diagonal /-- A function is `Function.const α a` for some `a` if and only if `∀ x y, f x = f y`. -/ theorem range_const_eq_diagonal {α β : Type*} [hβ : Nonempty β] : range (const α) = {f : α → β | ∀ x y, f x = f y} := by refine (range_eq_iff _ _).mpr ⟨fun _ _ _ ↦ rfl, fun f hf ↦ ?_⟩ rcases isEmpty_or_nonempty α with h|⟨⟨a⟩⟩ · exact hβ.elim fun b ↦ ⟨b, Subsingleton.elim _ _⟩ · exact ⟨f a, funext fun x ↦ hf _ _⟩ end Set section Pullback open Set variable {X Y Z} /-- The fiber product $X \times_Y Z$. -/ abbrev Function.Pullback (f : X → Y) (g : Z → Y) := {p : X × Z // f p.1 = g p.2} /-- The fiber product $X \times_Y X$. -/ abbrev Function.PullbackSelf (f : X → Y) := f.Pullback f /-- The projection from the fiber product to the first factor. -/ def Function.Pullback.fst {f : X → Y} {g : Z → Y} (p : f.Pullback g) : X := p.val.1 /-- The projection from the fiber product to the second factor. -/ def Function.Pullback.snd {f : X → Y} {g : Z → Y} (p : f.Pullback g) : Z := p.val.2 open Function.Pullback in lemma Function.pullback_comm_sq (f : X → Y) (g : Z → Y) : f ∘ @fst X Y Z f g = g ∘ @snd X Y Z f g := funext fun p ↦ p.2 /-- The diagonal map $\Delta: X \to X \times_Y X$. -/ def toPullbackDiag (f : X → Y) (x : X) : f.Pullback f := ⟨(x, x), rfl⟩ /-- The diagonal $\Delta(X) \subseteq X \times_Y X$. -/ def Function.pullbackDiagonal (f : X → Y) : Set (f.Pullback f) := {p | p.fst = p.snd} /-- Three functions between the three pairs of spaces $X_i, Y_i, Z_i$ that are compatible induce a function $X_1 \times_{Y_1} Z_1 \to X_2 \times_{Y_2} Z_2$. -/ def Function.mapPullback {X₁ X₂ Y₁ Y₂ Z₁ Z₂} {f₁ : X₁ → Y₁} {g₁ : Z₁ → Y₁} {f₂ : X₂ → Y₂} {g₂ : Z₂ → Y₂} (mapX : X₁ → X₂) (mapY : Y₁ → Y₂) (mapZ : Z₁ → Z₂) (commX : f₂ ∘ mapX = mapY ∘ f₁) (commZ : g₂ ∘ mapZ = mapY ∘ g₁) (p : f₁.Pullback g₁) : f₂.Pullback g₂ := ⟨(mapX p.fst, mapZ p.snd), (congr_fun commX _).trans <| (congr_arg mapY p.2).trans <| congr_fun commZ.symm _⟩ open Function.Pullback in /-- The projection $(X \times_Y Z) \times_Z (X \times_Y Z) \to X \times_Y X$. -/ def Function.PullbackSelf.map_fst {f : X → Y} {g : Z → Y} : (@snd X Y Z f g).PullbackSelf → f.PullbackSelf := mapPullback fst g fst (pullback_comm_sq f g) (pullback_comm_sq f g) open Function.Pullback in /-- The projection $(X \times_Y Z) \times_X (X \times_Y Z) \to Z \times_Y Z$. -/ def Function.PullbackSelf.map_snd {f : X → Y} {g : Z → Y} : (@fst X Y Z f g).PullbackSelf → g.PullbackSelf := mapPullback snd f snd (pullback_comm_sq f g).symm (pullback_comm_sq f g).symm open Function.PullbackSelf Function.Pullback theorem preimage_map_fst_pullbackDiagonal {f : X → Y} {g : Z → Y} : @map_fst X Y Z f g ⁻¹' pullbackDiagonal f = pullbackDiagonal (@snd X Y Z f g) := by ext ⟨⟨p₁, p₂⟩, he⟩ simp_rw [pullbackDiagonal, mem_setOf, Subtype.ext_iff, Prod.ext_iff] exact (and_iff_left he).symm theorem Function.Injective.preimage_pullbackDiagonal {f : X → Y} {g : Z → X} (inj : g.Injective) : mapPullback g id g (by rfl) (by rfl) ⁻¹' pullbackDiagonal f = pullbackDiagonal (f ∘ g) := ext fun _ ↦ inj.eq_iff theorem image_toPullbackDiag (f : X → Y) (s : Set X) : toPullbackDiag f '' s = pullbackDiagonal f ∩ Subtype.val ⁻¹' s ×ˢ s := by ext x constructor · rintro ⟨x, hx, rfl⟩ exact ⟨rfl, hx, hx⟩ · obtain ⟨⟨x, y⟩, h⟩ := x rintro ⟨rfl : x = y, h2x⟩ exact mem_image_of_mem _ h2x.1 theorem range_toPullbackDiag (f : X → Y) : range (toPullbackDiag f) = pullbackDiagonal f := by rw [← image_univ, image_toPullbackDiag, univ_prod_univ, preimage_univ, inter_univ] theorem injective_toPullbackDiag (f : X → Y) : (toPullbackDiag f).Injective := fun _ _ h ↦ congr_arg Prod.fst (congr_arg Subtype.val h) end Pullback namespace Set section OffDiag variable {α : Type*} {s t : Set α} {x : α × α} {a : α} theorem offDiag_mono : Monotone (offDiag : Set α → Set (α × α)) := fun _ _ h _ => And.imp (@h _) <| And.imp_left <| @h _ #align set.off_diag_mono Set.offDiag_mono @[simp] theorem offDiag_nonempty : s.offDiag.Nonempty ↔ s.Nontrivial := by simp [offDiag, Set.Nonempty, Set.Nontrivial] #align set.off_diag_nonempty Set.offDiag_nonempty @[simp] theorem offDiag_eq_empty : s.offDiag = ∅ ↔ s.Subsingleton := by rw [← not_nonempty_iff_eq_empty, ← not_nontrivial_iff, offDiag_nonempty.not] #align set.off_diag_eq_empty Set.offDiag_eq_empty alias ⟨_, Nontrivial.offDiag_nonempty⟩ := offDiag_nonempty #align set.nontrivial.off_diag_nonempty Set.Nontrivial.offDiag_nonempty alias ⟨_, Subsingleton.offDiag_eq_empty⟩ := offDiag_nonempty #align set.subsingleton.off_diag_eq_empty Set.Subsingleton.offDiag_eq_empty variable (s t) theorem offDiag_subset_prod : s.offDiag ⊆ s ×ˢ s := fun _ hx => ⟨hx.1, hx.2.1⟩ #align set.off_diag_subset_prod Set.offDiag_subset_prod theorem offDiag_eq_sep_prod : s.offDiag = { x ∈ s ×ˢ s | x.1 ≠ x.2 } := ext fun _ => and_assoc.symm #align set.off_diag_eq_sep_prod Set.offDiag_eq_sep_prod @[simp] theorem offDiag_empty : (∅ : Set α).offDiag = ∅ := by simp #align set.off_diag_empty Set.offDiag_empty @[simp] theorem offDiag_singleton (a : α) : ({a} : Set α).offDiag = ∅ := by simp #align set.off_diag_singleton Set.offDiag_singleton @[simp] theorem offDiag_univ : (univ : Set α).offDiag = (diagonal α)ᶜ := ext <| by simp #align set.off_diag_univ Set.offDiag_univ @[simp] theorem prod_sdiff_diagonal : s ×ˢ s \ diagonal α = s.offDiag := ext fun _ => and_assoc #align set.prod_sdiff_diagonal Set.prod_sdiff_diagonal @[simp] theorem disjoint_diagonal_offDiag : Disjoint (diagonal α) s.offDiag := disjoint_left.mpr fun _ hd ho => ho.2.2 hd #align set.disjoint_diagonal_off_diag Set.disjoint_diagonal_offDiag theorem offDiag_inter : (s ∩ t).offDiag = s.offDiag ∩ t.offDiag := ext fun x => by simp only [mem_offDiag, mem_inter_iff] tauto #align set.off_diag_inter Set.offDiag_inter variable {s t} theorem offDiag_union (h : Disjoint s t) : (s ∪ t).offDiag = s.offDiag ∪ t.offDiag ∪ s ×ˢ t ∪ t ×ˢ s := by ext x simp only [mem_offDiag, mem_union, ne_eq, mem_prod] constructor · rintro ⟨h0|h0, h1|h1, h2⟩ <;> simp [h0, h1, h2] · rintro (((⟨h0, h1, h2⟩|⟨h0, h1, h2⟩)|⟨h0, h1⟩)|⟨h0, h1⟩) <;> simp [*] · rintro h3 rw [h3] at h0 exact Set.disjoint_left.mp h h0 h1 · rintro h3 rw [h3] at h0 exact (Set.disjoint_right.mp h h0 h1).elim #align set.off_diag_union Set.offDiag_union
Mathlib/Data/Set/Prod.lean
688
692
theorem offDiag_insert (ha : a ∉ s) : (insert a s).offDiag = s.offDiag ∪ {a} ×ˢ s ∪ s ×ˢ {a} := by
rw [insert_eq, union_comm, offDiag_union, offDiag_singleton, union_empty, union_right_comm] rw [disjoint_left] rintro b hb (rfl : b = a) exact ha hb
/- Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Analysis.Convex.Topology import Mathlib.Analysis.NormedSpace.Pointwise import Mathlib.Analysis.Seminorm import Mathlib.Analysis.LocallyConvex.Bounded import Mathlib.Analysis.RCLike.Basic #align_import analysis.convex.gauge from "leanprover-community/mathlib"@"373b03b5b9d0486534edbe94747f23cb3712f93d" /-! # The Minkowski functional This file defines the Minkowski functional, aka gauge. The Minkowski functional of a set `s` is the function which associates each point to how much you need to scale `s` for `x` to be inside it. When `s` is symmetric, convex and absorbent, its gauge is a seminorm. Reciprocally, any seminorm arises as the gauge of some set, namely its unit ball. This induces the equivalence of seminorms and locally convex topological vector spaces. ## Main declarations For a real vector space, * `gauge`: Aka Minkowski functional. `gauge s x` is the least (actually, an infimum) `r` such that `x ∈ r • s`. * `gaugeSeminorm`: The Minkowski functional as a seminorm, when `s` is symmetric, convex and absorbent. ## References * [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966] ## Tags Minkowski functional, gauge -/ open NormedField Set open scoped Pointwise Topology NNReal noncomputable section variable {𝕜 E F : Type*} section AddCommGroup variable [AddCommGroup E] [Module ℝ E] /-- The Minkowski functional. Given a set `s` in a real vector space, `gauge s` is the functional which sends `x : E` to the smallest `r : ℝ` such that `x` is in `s` scaled by `r`. -/ def gauge (s : Set E) (x : E) : ℝ := sInf { r : ℝ | 0 < r ∧ x ∈ r • s } #align gauge gauge variable {s t : Set E} {x : E} {a : ℝ} theorem gauge_def : gauge s x = sInf ({ r ∈ Set.Ioi (0 : ℝ) | x ∈ r • s }) := rfl #align gauge_def gauge_def /-- An alternative definition of the gauge using scalar multiplication on the element rather than on the set. -/ theorem gauge_def' : gauge s x = sInf {r ∈ Set.Ioi (0 : ℝ) | r⁻¹ • x ∈ s} := by congrm sInf {r | ?_} exact and_congr_right fun hr => mem_smul_set_iff_inv_smul_mem₀ hr.ne' _ _ #align gauge_def' gauge_def' private theorem gauge_set_bddBelow : BddBelow { r : ℝ | 0 < r ∧ x ∈ r • s } := ⟨0, fun _ hr => hr.1.le⟩ /-- If the given subset is `Absorbent` then the set we take an infimum over in `gauge` is nonempty, which is useful for proving many properties about the gauge. -/ theorem Absorbent.gauge_set_nonempty (absorbs : Absorbent ℝ s) : { r : ℝ | 0 < r ∧ x ∈ r • s }.Nonempty := let ⟨r, hr₁, hr₂⟩ := (absorbs x).exists_pos ⟨r, hr₁, hr₂ r (Real.norm_of_nonneg hr₁.le).ge rfl⟩ #align absorbent.gauge_set_nonempty Absorbent.gauge_set_nonempty theorem gauge_mono (hs : Absorbent ℝ s) (h : s ⊆ t) : gauge t ≤ gauge s := fun _ => csInf_le_csInf gauge_set_bddBelow hs.gauge_set_nonempty fun _ hr => ⟨hr.1, smul_set_mono h hr.2⟩ #align gauge_mono gauge_mono theorem exists_lt_of_gauge_lt (absorbs : Absorbent ℝ s) (h : gauge s x < a) : ∃ b, 0 < b ∧ b < a ∧ x ∈ b • s := by obtain ⟨b, ⟨hb, hx⟩, hba⟩ := exists_lt_of_csInf_lt absorbs.gauge_set_nonempty h exact ⟨b, hb, hba, hx⟩ #align exists_lt_of_gauge_lt exists_lt_of_gauge_lt /-- The gauge evaluated at `0` is always zero (mathematically this requires `0` to be in the set `s` but, the real infimum of the empty set in Lean being defined as `0`, it holds unconditionally). -/ @[simp] theorem gauge_zero : gauge s 0 = 0 := by rw [gauge_def'] by_cases h : (0 : E) ∈ s · simp only [smul_zero, sep_true, h, csInf_Ioi] · simp only [smul_zero, sep_false, h, Real.sInf_empty] #align gauge_zero gauge_zero @[simp] theorem gauge_zero' : gauge (0 : Set E) = 0 := by ext x rw [gauge_def'] obtain rfl | hx := eq_or_ne x 0 · simp only [csInf_Ioi, mem_zero, Pi.zero_apply, eq_self_iff_true, sep_true, smul_zero] · simp only [mem_zero, Pi.zero_apply, inv_eq_zero, smul_eq_zero] convert Real.sInf_empty exact eq_empty_iff_forall_not_mem.2 fun r hr => hr.2.elim (ne_of_gt hr.1) hx #align gauge_zero' gauge_zero' @[simp] theorem gauge_empty : gauge (∅ : Set E) = 0 := by ext simp only [gauge_def', Real.sInf_empty, mem_empty_iff_false, Pi.zero_apply, sep_false] #align gauge_empty gauge_empty theorem gauge_of_subset_zero (h : s ⊆ 0) : gauge s = 0 := by obtain rfl | rfl := subset_singleton_iff_eq.1 h exacts [gauge_empty, gauge_zero'] #align gauge_of_subset_zero gauge_of_subset_zero /-- The gauge is always nonnegative. -/ theorem gauge_nonneg (x : E) : 0 ≤ gauge s x := Real.sInf_nonneg _ fun _ hx => hx.1.le #align gauge_nonneg gauge_nonneg theorem gauge_neg (symmetric : ∀ x ∈ s, -x ∈ s) (x : E) : gauge s (-x) = gauge s x := by have : ∀ x, -x ∈ s ↔ x ∈ s := fun x => ⟨fun h => by simpa using symmetric _ h, symmetric x⟩ simp_rw [gauge_def', smul_neg, this] #align gauge_neg gauge_neg theorem gauge_neg_set_neg (x : E) : gauge (-s) (-x) = gauge s x := by simp_rw [gauge_def', smul_neg, neg_mem_neg] #align gauge_neg_set_neg gauge_neg_set_neg theorem gauge_neg_set_eq_gauge_neg (x : E) : gauge (-s) x = gauge s (-x) := by rw [← gauge_neg_set_neg, neg_neg] #align gauge_neg_set_eq_gauge_neg gauge_neg_set_eq_gauge_neg theorem gauge_le_of_mem (ha : 0 ≤ a) (hx : x ∈ a • s) : gauge s x ≤ a := by obtain rfl | ha' := ha.eq_or_lt · rw [mem_singleton_iff.1 (zero_smul_set_subset _ hx), gauge_zero] · exact csInf_le gauge_set_bddBelow ⟨ha', hx⟩ #align gauge_le_of_mem gauge_le_of_mem theorem gauge_le_eq (hs₁ : Convex ℝ s) (hs₀ : (0 : E) ∈ s) (hs₂ : Absorbent ℝ s) (ha : 0 ≤ a) : { x | gauge s x ≤ a } = ⋂ (r : ℝ) (_ : a < r), r • s := by ext x simp_rw [Set.mem_iInter, Set.mem_setOf_eq] refine ⟨fun h r hr => ?_, fun h => le_of_forall_pos_lt_add fun ε hε => ?_⟩ · have hr' := ha.trans_lt hr rw [mem_smul_set_iff_inv_smul_mem₀ hr'.ne'] obtain ⟨δ, δ_pos, hδr, hδ⟩ := exists_lt_of_gauge_lt hs₂ (h.trans_lt hr) suffices (r⁻¹ * δ) • δ⁻¹ • x ∈ s by rwa [smul_smul, mul_inv_cancel_right₀ δ_pos.ne'] at this rw [mem_smul_set_iff_inv_smul_mem₀ δ_pos.ne'] at hδ refine hs₁.smul_mem_of_zero_mem hs₀ hδ ⟨by positivity, ?_⟩ rw [inv_mul_le_iff hr', mul_one] exact hδr.le · have hε' := (lt_add_iff_pos_right a).2 (half_pos hε) exact (gauge_le_of_mem (ha.trans hε'.le) <| h _ hε').trans_lt (add_lt_add_left (half_lt_self hε) _) #align gauge_le_eq gauge_le_eq theorem gauge_lt_eq' (absorbs : Absorbent ℝ s) (a : ℝ) : { x | gauge s x < a } = ⋃ (r : ℝ) (_ : 0 < r) (_ : r < a), r • s := by ext simp_rw [mem_setOf, mem_iUnion, exists_prop] exact ⟨exists_lt_of_gauge_lt absorbs, fun ⟨r, hr₀, hr₁, hx⟩ => (gauge_le_of_mem hr₀.le hx).trans_lt hr₁⟩ #align gauge_lt_eq' gauge_lt_eq' theorem gauge_lt_eq (absorbs : Absorbent ℝ s) (a : ℝ) : { x | gauge s x < a } = ⋃ r ∈ Set.Ioo 0 (a : ℝ), r • s := by ext simp_rw [mem_setOf, mem_iUnion, exists_prop, mem_Ioo, and_assoc] exact ⟨exists_lt_of_gauge_lt absorbs, fun ⟨r, hr₀, hr₁, hx⟩ => (gauge_le_of_mem hr₀.le hx).trans_lt hr₁⟩ #align gauge_lt_eq gauge_lt_eq theorem mem_openSegment_of_gauge_lt_one (absorbs : Absorbent ℝ s) (hgauge : gauge s x < 1) : ∃ y ∈ s, x ∈ openSegment ℝ 0 y := by rcases exists_lt_of_gauge_lt absorbs hgauge with ⟨r, hr₀, hr₁, y, hy, rfl⟩ refine ⟨y, hy, 1 - r, r, ?_⟩ simp [*] theorem gauge_lt_one_subset_self (hs : Convex ℝ s) (h₀ : (0 : E) ∈ s) (absorbs : Absorbent ℝ s) : { x | gauge s x < 1 } ⊆ s := fun _x hx ↦ let ⟨_y, hys, hx⟩ := mem_openSegment_of_gauge_lt_one absorbs hx hs.openSegment_subset h₀ hys hx #align gauge_lt_one_subset_self gauge_lt_one_subset_self theorem gauge_le_one_of_mem {x : E} (hx : x ∈ s) : gauge s x ≤ 1 := gauge_le_of_mem zero_le_one <| by rwa [one_smul] #align gauge_le_one_of_mem gauge_le_one_of_mem /-- Gauge is subadditive. -/ theorem gauge_add_le (hs : Convex ℝ s) (absorbs : Absorbent ℝ s) (x y : E) : gauge s (x + y) ≤ gauge s x + gauge s y := by refine le_of_forall_pos_lt_add fun ε hε => ?_ obtain ⟨a, ha, ha', x, hx, rfl⟩ := exists_lt_of_gauge_lt absorbs (lt_add_of_pos_right (gauge s x) (half_pos hε)) obtain ⟨b, hb, hb', y, hy, rfl⟩ := exists_lt_of_gauge_lt absorbs (lt_add_of_pos_right (gauge s y) (half_pos hε)) calc gauge s (a • x + b • y) ≤ a + b := gauge_le_of_mem (by positivity) <| by rw [hs.add_smul ha.le hb.le] exact add_mem_add (smul_mem_smul_set hx) (smul_mem_smul_set hy) _ < gauge s (a • x) + gauge s (b • y) + ε := by linarith #align gauge_add_le gauge_add_le theorem self_subset_gauge_le_one : s ⊆ { x | gauge s x ≤ 1 } := fun _ => gauge_le_one_of_mem #align self_subset_gauge_le_one self_subset_gauge_le_one theorem Convex.gauge_le (hs : Convex ℝ s) (h₀ : (0 : E) ∈ s) (absorbs : Absorbent ℝ s) (a : ℝ) : Convex ℝ { x | gauge s x ≤ a } := by by_cases ha : 0 ≤ a · rw [gauge_le_eq hs h₀ absorbs ha] exact convex_iInter fun i => convex_iInter fun _ => hs.smul _ · -- Porting note: `convert` needed help convert convex_empty (𝕜 := ℝ) (E := E) exact eq_empty_iff_forall_not_mem.2 fun x hx => ha <| (gauge_nonneg _).trans hx #align convex.gauge_le Convex.gauge_le theorem Balanced.starConvex (hs : Balanced ℝ s) : StarConvex ℝ 0 s := starConvex_zero_iff.2 fun x hx a ha₀ ha₁ => hs _ (by rwa [Real.norm_of_nonneg ha₀]) (smul_mem_smul_set hx) #align balanced.star_convex Balanced.starConvex theorem le_gauge_of_not_mem (hs₀ : StarConvex ℝ 0 s) (hs₂ : Absorbs ℝ s {x}) (hx : x ∉ a • s) : a ≤ gauge s x := by rw [starConvex_zero_iff] at hs₀ obtain ⟨r, hr, h⟩ := hs₂.exists_pos refine le_csInf ⟨r, hr, singleton_subset_iff.1 <| h _ (Real.norm_of_nonneg hr.le).ge⟩ ?_ rintro b ⟨hb, x, hx', rfl⟩ refine not_lt.1 fun hba => hx ?_ have ha := hb.trans hba refine ⟨(a⁻¹ * b) • x, hs₀ hx' (by positivity) ?_, ?_⟩ · rw [← div_eq_inv_mul] exact div_le_one_of_le hba.le ha.le · dsimp only rw [← mul_smul, mul_inv_cancel_left₀ ha.ne'] #align le_gauge_of_not_mem le_gauge_of_not_mem theorem one_le_gauge_of_not_mem (hs₁ : StarConvex ℝ 0 s) (hs₂ : Absorbs ℝ s {x}) (hx : x ∉ s) : 1 ≤ gauge s x := le_gauge_of_not_mem hs₁ hs₂ <| by rwa [one_smul] #align one_le_gauge_of_not_mem one_le_gauge_of_not_mem section LinearOrderedField variable {α : Type*} [LinearOrderedField α] [MulActionWithZero α ℝ] [OrderedSMul α ℝ] theorem gauge_smul_of_nonneg [MulActionWithZero α E] [IsScalarTower α ℝ (Set E)] {s : Set E} {a : α} (ha : 0 ≤ a) (x : E) : gauge s (a • x) = a • gauge s x := by obtain rfl | ha' := ha.eq_or_lt · rw [zero_smul, gauge_zero, zero_smul] rw [gauge_def', gauge_def', ← Real.sInf_smul_of_nonneg ha] congr 1 ext r simp_rw [Set.mem_smul_set, Set.mem_sep_iff] constructor · rintro ⟨hr, hx⟩ simp_rw [mem_Ioi] at hr ⊢ rw [← mem_smul_set_iff_inv_smul_mem₀ hr.ne'] at hx have := smul_pos (inv_pos.2 ha') hr refine ⟨a⁻¹ • r, ⟨this, ?_⟩, smul_inv_smul₀ ha'.ne' _⟩ rwa [← mem_smul_set_iff_inv_smul_mem₀ this.ne', smul_assoc, mem_smul_set_iff_inv_smul_mem₀ (inv_ne_zero ha'.ne'), inv_inv] · rintro ⟨r, ⟨hr, hx⟩, rfl⟩ rw [mem_Ioi] at hr ⊢ rw [← mem_smul_set_iff_inv_smul_mem₀ hr.ne'] at hx have := smul_pos ha' hr refine ⟨this, ?_⟩ rw [← mem_smul_set_iff_inv_smul_mem₀ this.ne', smul_assoc] exact smul_mem_smul_set hx #align gauge_smul_of_nonneg gauge_smul_of_nonneg theorem gauge_smul_left_of_nonneg [MulActionWithZero α E] [SMulCommClass α ℝ ℝ] [IsScalarTower α ℝ ℝ] [IsScalarTower α ℝ E] {s : Set E} {a : α} (ha : 0 ≤ a) : gauge (a • s) = a⁻¹ • gauge s := by obtain rfl | ha' := ha.eq_or_lt · rw [inv_zero, zero_smul, gauge_of_subset_zero (zero_smul_set_subset _)] ext x rw [gauge_def', Pi.smul_apply, gauge_def', ← Real.sInf_smul_of_nonneg (inv_nonneg.2 ha)] congr 1 ext r simp_rw [Set.mem_smul_set, Set.mem_sep_iff] constructor · rintro ⟨hr, y, hy, h⟩ simp_rw [mem_Ioi] at hr ⊢ refine ⟨a • r, ⟨smul_pos ha' hr, ?_⟩, inv_smul_smul₀ ha'.ne' _⟩ rwa [smul_inv₀, smul_assoc, ← h, inv_smul_smul₀ ha'.ne'] · rintro ⟨r, ⟨hr, hx⟩, rfl⟩ rw [mem_Ioi] at hr ⊢ refine ⟨smul_pos (inv_pos.2 ha') hr, r⁻¹ • x, hx, ?_⟩ rw [smul_inv₀, smul_assoc, inv_inv] #align gauge_smul_left_of_nonneg gauge_smul_left_of_nonneg theorem gauge_smul_left [Module α E] [SMulCommClass α ℝ ℝ] [IsScalarTower α ℝ ℝ] [IsScalarTower α ℝ E] {s : Set E} (symmetric : ∀ x ∈ s, -x ∈ s) (a : α) : gauge (a • s) = |a|⁻¹ • gauge s := by rw [← gauge_smul_left_of_nonneg (abs_nonneg a)] obtain h | h := abs_choice a · rw [h] · rw [h, Set.neg_smul_set, ← Set.smul_set_neg] -- Porting note: was congr apply congr_arg apply congr_arg ext y refine ⟨symmetric _, fun hy => ?_⟩ rw [← neg_neg y] exact symmetric _ hy #align gauge_smul_left gauge_smul_left end LinearOrderedField section RCLike variable [RCLike 𝕜] [Module 𝕜 E] [IsScalarTower ℝ 𝕜 E] theorem gauge_norm_smul (hs : Balanced 𝕜 s) (r : 𝕜) (x : E) : gauge s (‖r‖ • x) = gauge s (r • x) := by unfold gauge congr with θ rw [@RCLike.real_smul_eq_coe_smul 𝕜] refine and_congr_right fun hθ => (hs.smul _).smul_mem_iff ?_ rw [RCLike.norm_ofReal, abs_norm] #align gauge_norm_smul gauge_norm_smul /-- If `s` is balanced, then the Minkowski functional is ℂ-homogeneous. -/ theorem gauge_smul (hs : Balanced 𝕜 s) (r : 𝕜) (x : E) : gauge s (r • x) = ‖r‖ * gauge s x := by rw [← smul_eq_mul, ← gauge_smul_of_nonneg (norm_nonneg r), gauge_norm_smul hs] #align gauge_smul gauge_smul end RCLike open Filter section TopologicalSpace variable [TopologicalSpace E] theorem comap_gauge_nhds_zero_le (ha : Absorbent ℝ s) (hb : Bornology.IsVonNBounded ℝ s) : comap (gauge s) (𝓝 0) ≤ 𝓝 0 := fun u hu ↦ by rcases (hb hu).exists_pos with ⟨r, hr₀, hr⟩ filter_upwards [preimage_mem_comap (gt_mem_nhds (inv_pos.2 hr₀))] with x (hx : gauge s x < r⁻¹) rcases exists_lt_of_gauge_lt ha hx with ⟨c, hc₀, hcr, y, hy, rfl⟩ have hrc := (lt_inv hr₀ hc₀).2 hcr rcases hr c⁻¹ (hrc.le.trans (le_abs_self _)) hy with ⟨z, hz, rfl⟩ simpa only [smul_inv_smul₀ hc₀.ne'] variable [T1Space E] theorem gauge_eq_zero (hs : Absorbent ℝ s) (hb : Bornology.IsVonNBounded ℝ s) : gauge s x = 0 ↔ x = 0 := by refine ⟨fun h₀ ↦ by_contra fun (hne : x ≠ 0) ↦ ?_, fun h ↦ h.symm ▸ gauge_zero⟩ have : {x}ᶜ ∈ comap (gauge s) (𝓝 0) := comap_gauge_nhds_zero_le hs hb (isOpen_compl_singleton.mem_nhds hne.symm) rcases ((nhds_basis_zero_abs_sub_lt _).comap _).mem_iff.1 this with ⟨r, hr₀, hr⟩ exact hr (by simpa [h₀]) rfl theorem gauge_pos (hs : Absorbent ℝ s) (hb : Bornology.IsVonNBounded ℝ s) : 0 < gauge s x ↔ x ≠ 0 := by simp only [(gauge_nonneg _).gt_iff_ne, Ne, gauge_eq_zero hs hb] end TopologicalSpace section ContinuousSMul variable [TopologicalSpace E] [ContinuousSMul ℝ E] open Filter in theorem interior_subset_gauge_lt_one (s : Set E) : interior s ⊆ { x | gauge s x < 1 } := by intro x hx have H₁ : Tendsto (fun r : ℝ ↦ r⁻¹ • x) (𝓝[<] 1) (𝓝 ((1 : ℝ)⁻¹ • x)) := ((tendsto_id.inv₀ one_ne_zero).smul tendsto_const_nhds).mono_left inf_le_left rw [inv_one, one_smul] at H₁ have H₂ : ∀ᶠ r in 𝓝[<] (1 : ℝ), x ∈ r • s ∧ 0 < r ∧ r < 1 := by filter_upwards [H₁ (mem_interior_iff_mem_nhds.1 hx), Ioo_mem_nhdsWithin_Iio' one_pos] intro r h₁ h₂ exact ⟨(mem_smul_set_iff_inv_smul_mem₀ h₂.1.ne' _ _).2 h₁, h₂⟩ rcases H₂.exists with ⟨r, hxr, hr₀, hr₁⟩ exact (gauge_le_of_mem hr₀.le hxr).trans_lt hr₁ #align interior_subset_gauge_lt_one interior_subset_gauge_lt_one
Mathlib/Analysis/Convex/Gauge.lean
390
394
theorem gauge_lt_one_eq_self_of_isOpen (hs₁ : Convex ℝ s) (hs₀ : (0 : E) ∈ s) (hs₂ : IsOpen s) : { x | gauge s x < 1 } = s := by
refine (gauge_lt_one_subset_self hs₁ ‹_› <| absorbent_nhds_zero <| hs₂.mem_nhds hs₀).antisymm ?_ convert interior_subset_gauge_lt_one s exact hs₂.interior_eq.symm
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kevin Kappelmann -/ import Mathlib.Algebra.CharZero.Lemmas import Mathlib.Algebra.Order.Interval.Set.Group import Mathlib.Algebra.Group.Int import Mathlib.Data.Int.Lemmas import Mathlib.Data.Set.Subsingleton import Mathlib.Init.Data.Nat.Lemmas import Mathlib.Order.GaloisConnection import Mathlib.Tactic.Abel import Mathlib.Tactic.Linarith import Mathlib.Tactic.Positivity #align_import algebra.order.floor from "leanprover-community/mathlib"@"afdb43429311b885a7988ea15d0bac2aac80f69c" /-! # Floor and ceil ## Summary We define the natural- and integer-valued floor and ceil functions on linearly ordered rings. ## Main Definitions * `FloorSemiring`: An ordered semiring with natural-valued floor and ceil. * `Nat.floor a`: Greatest natural `n` such that `n ≤ a`. Equal to `0` if `a < 0`. * `Nat.ceil a`: Least natural `n` such that `a ≤ n`. * `FloorRing`: A linearly ordered ring with integer-valued floor and ceil. * `Int.floor a`: Greatest integer `z` such that `z ≤ a`. * `Int.ceil a`: Least integer `z` such that `a ≤ z`. * `Int.fract a`: Fractional part of `a`, defined as `a - floor a`. * `round a`: Nearest integer to `a`. It rounds halves towards infinity. ## Notations * `⌊a⌋₊` is `Nat.floor a`. * `⌈a⌉₊` is `Nat.ceil a`. * `⌊a⌋` is `Int.floor a`. * `⌈a⌉` is `Int.ceil a`. The index `₊` in the notations for `Nat.floor` and `Nat.ceil` is used in analogy to the notation for `nnnorm`. ## TODO `LinearOrderedRing`/`LinearOrderedSemiring` can be relaxed to `OrderedRing`/`OrderedSemiring` in many lemmas. ## Tags rounding, floor, ceil -/ open Set variable {F α β : Type*} /-! ### Floor semiring -/ /-- A `FloorSemiring` is an ordered semiring over `α` with a function `floor : α → ℕ` satisfying `∀ (n : ℕ) (x : α), n ≤ ⌊x⌋ ↔ (n : α) ≤ x)`. Note that many lemmas require a `LinearOrder`. Please see the above `TODO`. -/ class FloorSemiring (α) [OrderedSemiring α] where /-- `FloorSemiring.floor a` computes the greatest natural `n` such that `(n : α) ≤ a`. -/ floor : α → ℕ /-- `FloorSemiring.ceil a` computes the least natural `n` such that `a ≤ (n : α)`. -/ ceil : α → ℕ /-- `FloorSemiring.floor` of a negative element is zero. -/ floor_of_neg {a : α} (ha : a < 0) : floor a = 0 /-- A natural number `n` is smaller than `FloorSemiring.floor a` iff its coercion to `α` is smaller than `a`. -/ gc_floor {a : α} {n : ℕ} (ha : 0 ≤ a) : n ≤ floor a ↔ (n : α) ≤ a /-- `FloorSemiring.ceil` is the lower adjoint of the coercion `↑ : ℕ → α`. -/ gc_ceil : GaloisConnection ceil (↑) #align floor_semiring FloorSemiring instance : FloorSemiring ℕ where floor := id ceil := id floor_of_neg ha := (Nat.not_lt_zero _ ha).elim gc_floor _ := by rw [Nat.cast_id] rfl gc_ceil n a := by rw [Nat.cast_id] rfl namespace Nat section OrderedSemiring variable [OrderedSemiring α] [FloorSemiring α] {a : α} {n : ℕ} /-- `⌊a⌋₊` is the greatest natural `n` such that `n ≤ a`. If `a` is negative, then `⌊a⌋₊ = 0`. -/ def floor : α → ℕ := FloorSemiring.floor #align nat.floor Nat.floor /-- `⌈a⌉₊` is the least natural `n` such that `a ≤ n` -/ def ceil : α → ℕ := FloorSemiring.ceil #align nat.ceil Nat.ceil @[simp] theorem floor_nat : (Nat.floor : ℕ → ℕ) = id := rfl #align nat.floor_nat Nat.floor_nat @[simp] theorem ceil_nat : (Nat.ceil : ℕ → ℕ) = id := rfl #align nat.ceil_nat Nat.ceil_nat @[inherit_doc] notation "⌊" a "⌋₊" => Nat.floor a @[inherit_doc] notation "⌈" a "⌉₊" => Nat.ceil a end OrderedSemiring section LinearOrderedSemiring variable [LinearOrderedSemiring α] [FloorSemiring α] {a : α} {n : ℕ} theorem le_floor_iff (ha : 0 ≤ a) : n ≤ ⌊a⌋₊ ↔ (n : α) ≤ a := FloorSemiring.gc_floor ha #align nat.le_floor_iff Nat.le_floor_iff theorem le_floor (h : (n : α) ≤ a) : n ≤ ⌊a⌋₊ := (le_floor_iff <| n.cast_nonneg.trans h).2 h #align nat.le_floor Nat.le_floor theorem floor_lt (ha : 0 ≤ a) : ⌊a⌋₊ < n ↔ a < n := lt_iff_lt_of_le_iff_le <| le_floor_iff ha #align nat.floor_lt Nat.floor_lt theorem floor_lt_one (ha : 0 ≤ a) : ⌊a⌋₊ < 1 ↔ a < 1 := (floor_lt ha).trans <| by rw [Nat.cast_one] #align nat.floor_lt_one Nat.floor_lt_one theorem lt_of_floor_lt (h : ⌊a⌋₊ < n) : a < n := lt_of_not_le fun h' => (le_floor h').not_lt h #align nat.lt_of_floor_lt Nat.lt_of_floor_lt theorem lt_one_of_floor_lt_one (h : ⌊a⌋₊ < 1) : a < 1 := mod_cast lt_of_floor_lt h #align nat.lt_one_of_floor_lt_one Nat.lt_one_of_floor_lt_one theorem floor_le (ha : 0 ≤ a) : (⌊a⌋₊ : α) ≤ a := (le_floor_iff ha).1 le_rfl #align nat.floor_le Nat.floor_le theorem lt_succ_floor (a : α) : a < ⌊a⌋₊.succ := lt_of_floor_lt <| Nat.lt_succ_self _ #align nat.lt_succ_floor Nat.lt_succ_floor theorem lt_floor_add_one (a : α) : a < ⌊a⌋₊ + 1 := by simpa using lt_succ_floor a #align nat.lt_floor_add_one Nat.lt_floor_add_one @[simp] theorem floor_natCast (n : ℕ) : ⌊(n : α)⌋₊ = n := eq_of_forall_le_iff fun a => by rw [le_floor_iff, Nat.cast_le] exact n.cast_nonneg #align nat.floor_coe Nat.floor_natCast @[deprecated (since := "2024-06-08")] alias floor_coe := floor_natCast @[simp] theorem floor_zero : ⌊(0 : α)⌋₊ = 0 := by rw [← Nat.cast_zero, floor_natCast] #align nat.floor_zero Nat.floor_zero @[simp] theorem floor_one : ⌊(1 : α)⌋₊ = 1 := by rw [← Nat.cast_one, floor_natCast] #align nat.floor_one Nat.floor_one -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_ofNat (n : ℕ) [n.AtLeastTwo] : ⌊no_index (OfNat.ofNat n : α)⌋₊ = n := Nat.floor_natCast _ theorem floor_of_nonpos (ha : a ≤ 0) : ⌊a⌋₊ = 0 := ha.lt_or_eq.elim FloorSemiring.floor_of_neg <| by rintro rfl exact floor_zero #align nat.floor_of_nonpos Nat.floor_of_nonpos theorem floor_mono : Monotone (floor : α → ℕ) := fun a b h => by obtain ha | ha := le_total a 0 · rw [floor_of_nonpos ha] exact Nat.zero_le _ · exact le_floor ((floor_le ha).trans h) #align nat.floor_mono Nat.floor_mono @[gcongr] theorem floor_le_floor : ∀ x y : α, x ≤ y → ⌊x⌋₊ ≤ ⌊y⌋₊ := floor_mono theorem le_floor_iff' (hn : n ≠ 0) : n ≤ ⌊a⌋₊ ↔ (n : α) ≤ a := by obtain ha | ha := le_total a 0 · rw [floor_of_nonpos ha] exact iff_of_false (Nat.pos_of_ne_zero hn).not_le (not_le_of_lt <| ha.trans_lt <| cast_pos.2 <| Nat.pos_of_ne_zero hn) · exact le_floor_iff ha #align nat.le_floor_iff' Nat.le_floor_iff' @[simp] theorem one_le_floor_iff (x : α) : 1 ≤ ⌊x⌋₊ ↔ 1 ≤ x := mod_cast @le_floor_iff' α _ _ x 1 one_ne_zero #align nat.one_le_floor_iff Nat.one_le_floor_iff theorem floor_lt' (hn : n ≠ 0) : ⌊a⌋₊ < n ↔ a < n := lt_iff_lt_of_le_iff_le <| le_floor_iff' hn #align nat.floor_lt' Nat.floor_lt' theorem floor_pos : 0 < ⌊a⌋₊ ↔ 1 ≤ a := by -- Porting note: broken `convert le_floor_iff' Nat.one_ne_zero` rw [Nat.lt_iff_add_one_le, zero_add, le_floor_iff' Nat.one_ne_zero, cast_one] #align nat.floor_pos Nat.floor_pos theorem pos_of_floor_pos (h : 0 < ⌊a⌋₊) : 0 < a := (le_or_lt a 0).resolve_left fun ha => lt_irrefl 0 <| by rwa [floor_of_nonpos ha] at h #align nat.pos_of_floor_pos Nat.pos_of_floor_pos theorem lt_of_lt_floor (h : n < ⌊a⌋₊) : ↑n < a := (Nat.cast_lt.2 h).trans_le <| floor_le (pos_of_floor_pos <| (Nat.zero_le n).trans_lt h).le #align nat.lt_of_lt_floor Nat.lt_of_lt_floor theorem floor_le_of_le (h : a ≤ n) : ⌊a⌋₊ ≤ n := le_imp_le_iff_lt_imp_lt.2 lt_of_lt_floor h #align nat.floor_le_of_le Nat.floor_le_of_le theorem floor_le_one_of_le_one (h : a ≤ 1) : ⌊a⌋₊ ≤ 1 := floor_le_of_le <| h.trans_eq <| Nat.cast_one.symm #align nat.floor_le_one_of_le_one Nat.floor_le_one_of_le_one @[simp] theorem floor_eq_zero : ⌊a⌋₊ = 0 ↔ a < 1 := by rw [← lt_one_iff, ← @cast_one α] exact floor_lt' Nat.one_ne_zero #align nat.floor_eq_zero Nat.floor_eq_zero theorem floor_eq_iff (ha : 0 ≤ a) : ⌊a⌋₊ = n ↔ ↑n ≤ a ∧ a < ↑n + 1 := by rw [← le_floor_iff ha, ← Nat.cast_one, ← Nat.cast_add, ← floor_lt ha, Nat.lt_add_one_iff, le_antisymm_iff, and_comm] #align nat.floor_eq_iff Nat.floor_eq_iff theorem floor_eq_iff' (hn : n ≠ 0) : ⌊a⌋₊ = n ↔ ↑n ≤ a ∧ a < ↑n + 1 := by rw [← le_floor_iff' hn, ← Nat.cast_one, ← Nat.cast_add, ← floor_lt' (Nat.add_one_ne_zero n), Nat.lt_add_one_iff, le_antisymm_iff, and_comm] #align nat.floor_eq_iff' Nat.floor_eq_iff' theorem floor_eq_on_Ico (n : ℕ) : ∀ a ∈ (Set.Ico n (n + 1) : Set α), ⌊a⌋₊ = n := fun _ ⟨h₀, h₁⟩ => (floor_eq_iff <| n.cast_nonneg.trans h₀).mpr ⟨h₀, h₁⟩ #align nat.floor_eq_on_Ico Nat.floor_eq_on_Ico theorem floor_eq_on_Ico' (n : ℕ) : ∀ a ∈ (Set.Ico n (n + 1) : Set α), (⌊a⌋₊ : α) = n := fun x hx => mod_cast floor_eq_on_Ico n x hx #align nat.floor_eq_on_Ico' Nat.floor_eq_on_Ico' @[simp] theorem preimage_floor_zero : (floor : α → ℕ) ⁻¹' {0} = Iio 1 := ext fun _ => floor_eq_zero #align nat.preimage_floor_zero Nat.preimage_floor_zero -- Porting note: in mathlib3 there was no need for the type annotation in `(n:α)` theorem preimage_floor_of_ne_zero {n : ℕ} (hn : n ≠ 0) : (floor : α → ℕ) ⁻¹' {n} = Ico (n:α) (n + 1) := ext fun _ => floor_eq_iff' hn #align nat.preimage_floor_of_ne_zero Nat.preimage_floor_of_ne_zero /-! #### Ceil -/ theorem gc_ceil_coe : GaloisConnection (ceil : α → ℕ) (↑) := FloorSemiring.gc_ceil #align nat.gc_ceil_coe Nat.gc_ceil_coe @[simp] theorem ceil_le : ⌈a⌉₊ ≤ n ↔ a ≤ n := gc_ceil_coe _ _ #align nat.ceil_le Nat.ceil_le theorem lt_ceil : n < ⌈a⌉₊ ↔ (n : α) < a := lt_iff_lt_of_le_iff_le ceil_le #align nat.lt_ceil Nat.lt_ceil -- porting note (#10618): simp can prove this -- @[simp] theorem add_one_le_ceil_iff : n + 1 ≤ ⌈a⌉₊ ↔ (n : α) < a := by rw [← Nat.lt_ceil, Nat.add_one_le_iff] #align nat.add_one_le_ceil_iff Nat.add_one_le_ceil_iff @[simp] theorem one_le_ceil_iff : 1 ≤ ⌈a⌉₊ ↔ 0 < a := by rw [← zero_add 1, Nat.add_one_le_ceil_iff, Nat.cast_zero] #align nat.one_le_ceil_iff Nat.one_le_ceil_iff theorem ceil_le_floor_add_one (a : α) : ⌈a⌉₊ ≤ ⌊a⌋₊ + 1 := by rw [ceil_le, Nat.cast_add, Nat.cast_one] exact (lt_floor_add_one a).le #align nat.ceil_le_floor_add_one Nat.ceil_le_floor_add_one theorem le_ceil (a : α) : a ≤ ⌈a⌉₊ := ceil_le.1 le_rfl #align nat.le_ceil Nat.le_ceil @[simp] theorem ceil_intCast {α : Type*} [LinearOrderedRing α] [FloorSemiring α] (z : ℤ) : ⌈(z : α)⌉₊ = z.toNat := eq_of_forall_ge_iff fun a => by simp only [ceil_le, Int.toNat_le] norm_cast #align nat.ceil_int_cast Nat.ceil_intCast @[simp] theorem ceil_natCast (n : ℕ) : ⌈(n : α)⌉₊ = n := eq_of_forall_ge_iff fun a => by rw [ceil_le, cast_le] #align nat.ceil_nat_cast Nat.ceil_natCast theorem ceil_mono : Monotone (ceil : α → ℕ) := gc_ceil_coe.monotone_l #align nat.ceil_mono Nat.ceil_mono @[gcongr] theorem ceil_le_ceil : ∀ x y : α, x ≤ y → ⌈x⌉₊ ≤ ⌈y⌉₊ := ceil_mono @[simp] theorem ceil_zero : ⌈(0 : α)⌉₊ = 0 := by rw [← Nat.cast_zero, ceil_natCast] #align nat.ceil_zero Nat.ceil_zero @[simp] theorem ceil_one : ⌈(1 : α)⌉₊ = 1 := by rw [← Nat.cast_one, ceil_natCast] #align nat.ceil_one Nat.ceil_one -- See note [no_index around OfNat.ofNat] @[simp] theorem ceil_ofNat (n : ℕ) [n.AtLeastTwo] : ⌈no_index (OfNat.ofNat n : α)⌉₊ = n := ceil_natCast n @[simp] theorem ceil_eq_zero : ⌈a⌉₊ = 0 ↔ a ≤ 0 := by rw [← Nat.le_zero, ceil_le, Nat.cast_zero] #align nat.ceil_eq_zero Nat.ceil_eq_zero @[simp] theorem ceil_pos : 0 < ⌈a⌉₊ ↔ 0 < a := by rw [lt_ceil, cast_zero] #align nat.ceil_pos Nat.ceil_pos theorem lt_of_ceil_lt (h : ⌈a⌉₊ < n) : a < n := (le_ceil a).trans_lt (Nat.cast_lt.2 h) #align nat.lt_of_ceil_lt Nat.lt_of_ceil_lt theorem le_of_ceil_le (h : ⌈a⌉₊ ≤ n) : a ≤ n := (le_ceil a).trans (Nat.cast_le.2 h) #align nat.le_of_ceil_le Nat.le_of_ceil_le theorem floor_le_ceil (a : α) : ⌊a⌋₊ ≤ ⌈a⌉₊ := by obtain ha | ha := le_total a 0 · rw [floor_of_nonpos ha] exact Nat.zero_le _ · exact cast_le.1 ((floor_le ha).trans <| le_ceil _) #align nat.floor_le_ceil Nat.floor_le_ceil theorem floor_lt_ceil_of_lt_of_pos {a b : α} (h : a < b) (h' : 0 < b) : ⌊a⌋₊ < ⌈b⌉₊ := by rcases le_or_lt 0 a with (ha | ha) · rw [floor_lt ha] exact h.trans_le (le_ceil _) · rwa [floor_of_nonpos ha.le, lt_ceil, Nat.cast_zero] #align nat.floor_lt_ceil_of_lt_of_pos Nat.floor_lt_ceil_of_lt_of_pos theorem ceil_eq_iff (hn : n ≠ 0) : ⌈a⌉₊ = n ↔ ↑(n - 1) < a ∧ a ≤ n := by rw [← ceil_le, ← not_le, ← ceil_le, not_le, tsub_lt_iff_right (Nat.add_one_le_iff.2 (pos_iff_ne_zero.2 hn)), Nat.lt_add_one_iff, le_antisymm_iff, and_comm] #align nat.ceil_eq_iff Nat.ceil_eq_iff @[simp] theorem preimage_ceil_zero : (Nat.ceil : α → ℕ) ⁻¹' {0} = Iic 0 := ext fun _ => ceil_eq_zero #align nat.preimage_ceil_zero Nat.preimage_ceil_zero -- Porting note: in mathlib3 there was no need for the type annotation in `(↑(n - 1))` theorem preimage_ceil_of_ne_zero (hn : n ≠ 0) : (Nat.ceil : α → ℕ) ⁻¹' {n} = Ioc (↑(n - 1) : α) n := ext fun _ => ceil_eq_iff hn #align nat.preimage_ceil_of_ne_zero Nat.preimage_ceil_of_ne_zero /-! #### Intervals -/ -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Ioo {a b : α} (ha : 0 ≤ a) : (Nat.cast : ℕ → α) ⁻¹' Set.Ioo a b = Set.Ioo ⌊a⌋₊ ⌈b⌉₊ := by ext simp [floor_lt, lt_ceil, ha] #align nat.preimage_Ioo Nat.preimage_Ioo -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Ico {a b : α} : (Nat.cast : ℕ → α) ⁻¹' Set.Ico a b = Set.Ico ⌈a⌉₊ ⌈b⌉₊ := by ext simp [ceil_le, lt_ceil] #align nat.preimage_Ico Nat.preimage_Ico -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Ioc {a b : α} (ha : 0 ≤ a) (hb : 0 ≤ b) : (Nat.cast : ℕ → α) ⁻¹' Set.Ioc a b = Set.Ioc ⌊a⌋₊ ⌊b⌋₊ := by ext simp [floor_lt, le_floor_iff, hb, ha] #align nat.preimage_Ioc Nat.preimage_Ioc -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Icc {a b : α} (hb : 0 ≤ b) : (Nat.cast : ℕ → α) ⁻¹' Set.Icc a b = Set.Icc ⌈a⌉₊ ⌊b⌋₊ := by ext simp [ceil_le, hb, le_floor_iff] #align nat.preimage_Icc Nat.preimage_Icc -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Ioi {a : α} (ha : 0 ≤ a) : (Nat.cast : ℕ → α) ⁻¹' Set.Ioi a = Set.Ioi ⌊a⌋₊ := by ext simp [floor_lt, ha] #align nat.preimage_Ioi Nat.preimage_Ioi -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Ici {a : α} : (Nat.cast : ℕ → α) ⁻¹' Set.Ici a = Set.Ici ⌈a⌉₊ := by ext simp [ceil_le] #align nat.preimage_Ici Nat.preimage_Ici -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Iio {a : α} : (Nat.cast : ℕ → α) ⁻¹' Set.Iio a = Set.Iio ⌈a⌉₊ := by ext simp [lt_ceil] #align nat.preimage_Iio Nat.preimage_Iio -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Iic {a : α} (ha : 0 ≤ a) : (Nat.cast : ℕ → α) ⁻¹' Set.Iic a = Set.Iic ⌊a⌋₊ := by ext simp [le_floor_iff, ha] #align nat.preimage_Iic Nat.preimage_Iic theorem floor_add_nat (ha : 0 ≤ a) (n : ℕ) : ⌊a + n⌋₊ = ⌊a⌋₊ + n := eq_of_forall_le_iff fun b => by rw [le_floor_iff (add_nonneg ha n.cast_nonneg)] obtain hb | hb := le_total n b · obtain ⟨d, rfl⟩ := exists_add_of_le hb rw [Nat.cast_add, add_comm n, add_comm (n : α), add_le_add_iff_right, add_le_add_iff_right, le_floor_iff ha] · obtain ⟨d, rfl⟩ := exists_add_of_le hb rw [Nat.cast_add, add_left_comm _ b, add_left_comm _ (b : α)] refine iff_of_true ?_ le_self_add exact le_add_of_nonneg_right <| ha.trans <| le_add_of_nonneg_right d.cast_nonneg #align nat.floor_add_nat Nat.floor_add_nat theorem floor_add_one (ha : 0 ≤ a) : ⌊a + 1⌋₊ = ⌊a⌋₊ + 1 := by -- Porting note: broken `convert floor_add_nat ha 1` rw [← cast_one, floor_add_nat ha 1] #align nat.floor_add_one Nat.floor_add_one -- See note [no_index around OfNat.ofNat] theorem floor_add_ofNat (ha : 0 ≤ a) (n : ℕ) [n.AtLeastTwo] : ⌊a + (no_index (OfNat.ofNat n))⌋₊ = ⌊a⌋₊ + OfNat.ofNat n := floor_add_nat ha n @[simp] theorem floor_sub_nat [Sub α] [OrderedSub α] [ExistsAddOfLE α] (a : α) (n : ℕ) : ⌊a - n⌋₊ = ⌊a⌋₊ - n := by obtain ha | ha := le_total a 0 · rw [floor_of_nonpos ha, floor_of_nonpos (tsub_nonpos_of_le (ha.trans n.cast_nonneg)), zero_tsub] rcases le_total a n with h | h · rw [floor_of_nonpos (tsub_nonpos_of_le h), eq_comm, tsub_eq_zero_iff_le] exact Nat.cast_le.1 ((Nat.floor_le ha).trans h) · rw [eq_tsub_iff_add_eq_of_le (le_floor h), ← floor_add_nat _, tsub_add_cancel_of_le h] exact le_tsub_of_add_le_left ((add_zero _).trans_le h) #align nat.floor_sub_nat Nat.floor_sub_nat @[simp] theorem floor_sub_one [Sub α] [OrderedSub α] [ExistsAddOfLE α] (a : α) : ⌊a - 1⌋₊ = ⌊a⌋₊ - 1 := mod_cast floor_sub_nat a 1 -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_sub_ofNat [Sub α] [OrderedSub α] [ExistsAddOfLE α] (a : α) (n : ℕ) [n.AtLeastTwo] : ⌊a - (no_index (OfNat.ofNat n))⌋₊ = ⌊a⌋₊ - OfNat.ofNat n := floor_sub_nat a n theorem ceil_add_nat (ha : 0 ≤ a) (n : ℕ) : ⌈a + n⌉₊ = ⌈a⌉₊ + n := eq_of_forall_ge_iff fun b => by rw [← not_lt, ← not_lt, not_iff_not, lt_ceil] obtain hb | hb := le_or_lt n b · obtain ⟨d, rfl⟩ := exists_add_of_le hb rw [Nat.cast_add, add_comm n, add_comm (n : α), add_lt_add_iff_right, add_lt_add_iff_right, lt_ceil] · exact iff_of_true (lt_add_of_nonneg_of_lt ha <| cast_lt.2 hb) (Nat.lt_add_left _ hb) #align nat.ceil_add_nat Nat.ceil_add_nat theorem ceil_add_one (ha : 0 ≤ a) : ⌈a + 1⌉₊ = ⌈a⌉₊ + 1 := by -- Porting note: broken `convert ceil_add_nat ha 1` rw [cast_one.symm, ceil_add_nat ha 1] #align nat.ceil_add_one Nat.ceil_add_one -- See note [no_index around OfNat.ofNat] theorem ceil_add_ofNat (ha : 0 ≤ a) (n : ℕ) [n.AtLeastTwo] : ⌈a + (no_index (OfNat.ofNat n))⌉₊ = ⌈a⌉₊ + OfNat.ofNat n := ceil_add_nat ha n theorem ceil_lt_add_one (ha : 0 ≤ a) : (⌈a⌉₊ : α) < a + 1 := lt_ceil.1 <| (Nat.lt_succ_self _).trans_le (ceil_add_one ha).ge #align nat.ceil_lt_add_one Nat.ceil_lt_add_one theorem ceil_add_le (a b : α) : ⌈a + b⌉₊ ≤ ⌈a⌉₊ + ⌈b⌉₊ := by rw [ceil_le, Nat.cast_add] exact _root_.add_le_add (le_ceil _) (le_ceil _) #align nat.ceil_add_le Nat.ceil_add_le end LinearOrderedSemiring section LinearOrderedRing variable [LinearOrderedRing α] [FloorSemiring α] theorem sub_one_lt_floor (a : α) : a - 1 < ⌊a⌋₊ := sub_lt_iff_lt_add.2 <| lt_floor_add_one a #align nat.sub_one_lt_floor Nat.sub_one_lt_floor end LinearOrderedRing section LinearOrderedSemifield variable [LinearOrderedSemifield α] [FloorSemiring α] -- TODO: should these lemmas be `simp`? `norm_cast`? theorem floor_div_nat (a : α) (n : ℕ) : ⌊a / n⌋₊ = ⌊a⌋₊ / n := by rcases le_total a 0 with ha | ha · rw [floor_of_nonpos, floor_of_nonpos ha] · simp apply div_nonpos_of_nonpos_of_nonneg ha n.cast_nonneg obtain rfl | hn := n.eq_zero_or_pos · rw [cast_zero, div_zero, Nat.div_zero, floor_zero] refine (floor_eq_iff ?_).2 ?_ · exact div_nonneg ha n.cast_nonneg constructor · exact cast_div_le.trans (div_le_div_of_nonneg_right (floor_le ha) n.cast_nonneg) rw [div_lt_iff, add_mul, one_mul, ← cast_mul, ← cast_add, ← floor_lt ha] · exact lt_div_mul_add hn · exact cast_pos.2 hn #align nat.floor_div_nat Nat.floor_div_nat -- See note [no_index around OfNat.ofNat] theorem floor_div_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : ⌊a / (no_index (OfNat.ofNat n))⌋₊ = ⌊a⌋₊ / OfNat.ofNat n := floor_div_nat a n /-- Natural division is the floor of field division. -/ theorem floor_div_eq_div (m n : ℕ) : ⌊(m : α) / n⌋₊ = m / n := by convert floor_div_nat (m : α) n rw [m.floor_natCast] #align nat.floor_div_eq_div Nat.floor_div_eq_div end LinearOrderedSemifield end Nat /-- There exists at most one `FloorSemiring` structure on a linear ordered semiring. -/ theorem subsingleton_floorSemiring {α} [LinearOrderedSemiring α] : Subsingleton (FloorSemiring α) := by refine ⟨fun H₁ H₂ => ?_⟩ have : H₁.ceil = H₂.ceil := funext fun a => (H₁.gc_ceil.l_unique H₂.gc_ceil) fun n => rfl have : H₁.floor = H₂.floor := by ext a cases' lt_or_le a 0 with h h · rw [H₁.floor_of_neg, H₂.floor_of_neg] <;> exact h · refine eq_of_forall_le_iff fun n => ?_ rw [H₁.gc_floor, H₂.gc_floor] <;> exact h cases H₁ cases H₂ congr #align subsingleton_floor_semiring subsingleton_floorSemiring /-! ### Floor rings -/ /-- A `FloorRing` is a linear ordered ring over `α` with a function `floor : α → ℤ` satisfying `∀ (z : ℤ) (a : α), z ≤ floor a ↔ (z : α) ≤ a)`. -/ class FloorRing (α) [LinearOrderedRing α] where /-- `FloorRing.floor a` computes the greatest integer `z` such that `(z : α) ≤ a`. -/ floor : α → ℤ /-- `FloorRing.ceil a` computes the least integer `z` such that `a ≤ (z : α)`. -/ ceil : α → ℤ /-- `FloorRing.ceil` is the upper adjoint of the coercion `↑ : ℤ → α`. -/ gc_coe_floor : GaloisConnection (↑) floor /-- `FloorRing.ceil` is the lower adjoint of the coercion `↑ : ℤ → α`. -/ gc_ceil_coe : GaloisConnection ceil (↑) #align floor_ring FloorRing instance : FloorRing ℤ where floor := id ceil := id gc_coe_floor a b := by rw [Int.cast_id] rfl gc_ceil_coe a b := by rw [Int.cast_id] rfl /-- A `FloorRing` constructor from the `floor` function alone. -/ def FloorRing.ofFloor (α) [LinearOrderedRing α] (floor : α → ℤ) (gc_coe_floor : GaloisConnection (↑) floor) : FloorRing α := { floor ceil := fun a => -floor (-a) gc_coe_floor gc_ceil_coe := fun a z => by rw [neg_le, ← gc_coe_floor, Int.cast_neg, neg_le_neg_iff] } #align floor_ring.of_floor FloorRing.ofFloor /-- A `FloorRing` constructor from the `ceil` function alone. -/ def FloorRing.ofCeil (α) [LinearOrderedRing α] (ceil : α → ℤ) (gc_ceil_coe : GaloisConnection ceil (↑)) : FloorRing α := { floor := fun a => -ceil (-a) ceil gc_coe_floor := fun a z => by rw [le_neg, gc_ceil_coe, Int.cast_neg, neg_le_neg_iff] gc_ceil_coe } #align floor_ring.of_ceil FloorRing.ofCeil namespace Int variable [LinearOrderedRing α] [FloorRing α] {z : ℤ} {a : α} /-- `Int.floor a` is the greatest integer `z` such that `z ≤ a`. It is denoted with `⌊a⌋`. -/ def floor : α → ℤ := FloorRing.floor #align int.floor Int.floor /-- `Int.ceil a` is the smallest integer `z` such that `a ≤ z`. It is denoted with `⌈a⌉`. -/ def ceil : α → ℤ := FloorRing.ceil #align int.ceil Int.ceil /-- `Int.fract a`, the fractional part of `a`, is `a` minus its floor. -/ def fract (a : α) : α := a - floor a #align int.fract Int.fract @[simp] theorem floor_int : (Int.floor : ℤ → ℤ) = id := rfl #align int.floor_int Int.floor_int @[simp] theorem ceil_int : (Int.ceil : ℤ → ℤ) = id := rfl #align int.ceil_int Int.ceil_int @[simp] theorem fract_int : (Int.fract : ℤ → ℤ) = 0 := funext fun x => by simp [fract] #align int.fract_int Int.fract_int @[inherit_doc] notation "⌊" a "⌋" => Int.floor a @[inherit_doc] notation "⌈" a "⌉" => Int.ceil a -- Mathematical notation for `fract a` is usually `{a}`. Let's not even go there. @[simp] theorem floorRing_floor_eq : @FloorRing.floor = @Int.floor := rfl #align int.floor_ring_floor_eq Int.floorRing_floor_eq @[simp] theorem floorRing_ceil_eq : @FloorRing.ceil = @Int.ceil := rfl #align int.floor_ring_ceil_eq Int.floorRing_ceil_eq /-! #### Floor -/ theorem gc_coe_floor : GaloisConnection ((↑) : ℤ → α) floor := FloorRing.gc_coe_floor #align int.gc_coe_floor Int.gc_coe_floor theorem le_floor : z ≤ ⌊a⌋ ↔ (z : α) ≤ a := (gc_coe_floor z a).symm #align int.le_floor Int.le_floor theorem floor_lt : ⌊a⌋ < z ↔ a < z := lt_iff_lt_of_le_iff_le le_floor #align int.floor_lt Int.floor_lt theorem floor_le (a : α) : (⌊a⌋ : α) ≤ a := gc_coe_floor.l_u_le a #align int.floor_le Int.floor_le theorem floor_nonneg : 0 ≤ ⌊a⌋ ↔ 0 ≤ a := by rw [le_floor, Int.cast_zero] #align int.floor_nonneg Int.floor_nonneg @[simp] theorem floor_le_sub_one_iff : ⌊a⌋ ≤ z - 1 ↔ a < z := by rw [← floor_lt, le_sub_one_iff] #align int.floor_le_sub_one_iff Int.floor_le_sub_one_iff @[simp] theorem floor_le_neg_one_iff : ⌊a⌋ ≤ -1 ↔ a < 0 := by rw [← zero_sub (1 : ℤ), floor_le_sub_one_iff, cast_zero] #align int.floor_le_neg_one_iff Int.floor_le_neg_one_iff theorem floor_nonpos (ha : a ≤ 0) : ⌊a⌋ ≤ 0 := by rw [← @cast_le α, Int.cast_zero] exact (floor_le a).trans ha #align int.floor_nonpos Int.floor_nonpos theorem lt_succ_floor (a : α) : a < ⌊a⌋.succ := floor_lt.1 <| Int.lt_succ_self _ #align int.lt_succ_floor Int.lt_succ_floor @[simp] theorem lt_floor_add_one (a : α) : a < ⌊a⌋ + 1 := by simpa only [Int.succ, Int.cast_add, Int.cast_one] using lt_succ_floor a #align int.lt_floor_add_one Int.lt_floor_add_one @[simp] theorem sub_one_lt_floor (a : α) : a - 1 < ⌊a⌋ := sub_lt_iff_lt_add.2 (lt_floor_add_one a) #align int.sub_one_lt_floor Int.sub_one_lt_floor @[simp] theorem floor_intCast (z : ℤ) : ⌊(z : α)⌋ = z := eq_of_forall_le_iff fun a => by rw [le_floor, Int.cast_le] #align int.floor_int_cast Int.floor_intCast @[simp] theorem floor_natCast (n : ℕ) : ⌊(n : α)⌋ = n := eq_of_forall_le_iff fun a => by rw [le_floor, ← cast_natCast, cast_le] #align int.floor_nat_cast Int.floor_natCast @[simp] theorem floor_zero : ⌊(0 : α)⌋ = 0 := by rw [← cast_zero, floor_intCast] #align int.floor_zero Int.floor_zero @[simp] theorem floor_one : ⌊(1 : α)⌋ = 1 := by rw [← cast_one, floor_intCast] #align int.floor_one Int.floor_one -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_ofNat (n : ℕ) [n.AtLeastTwo] : ⌊(no_index (OfNat.ofNat n : α))⌋ = n := floor_natCast n @[mono] theorem floor_mono : Monotone (floor : α → ℤ) := gc_coe_floor.monotone_u #align int.floor_mono Int.floor_mono @[gcongr] theorem floor_le_floor : ∀ x y : α, x ≤ y → ⌊x⌋ ≤ ⌊y⌋ := floor_mono theorem floor_pos : 0 < ⌊a⌋ ↔ 1 ≤ a := by -- Porting note: broken `convert le_floor` rw [Int.lt_iff_add_one_le, zero_add, le_floor, cast_one] #align int.floor_pos Int.floor_pos @[simp] theorem floor_add_int (a : α) (z : ℤ) : ⌊a + z⌋ = ⌊a⌋ + z := eq_of_forall_le_iff fun a => by rw [le_floor, ← sub_le_iff_le_add, ← sub_le_iff_le_add, le_floor, Int.cast_sub] #align int.floor_add_int Int.floor_add_int @[simp] theorem floor_add_one (a : α) : ⌊a + 1⌋ = ⌊a⌋ + 1 := by -- Porting note: broken `convert floor_add_int a 1` rw [← cast_one, floor_add_int] #align int.floor_add_one Int.floor_add_one theorem le_floor_add (a b : α) : ⌊a⌋ + ⌊b⌋ ≤ ⌊a + b⌋ := by rw [le_floor, Int.cast_add] exact add_le_add (floor_le _) (floor_le _) #align int.le_floor_add Int.le_floor_add theorem le_floor_add_floor (a b : α) : ⌊a + b⌋ - 1 ≤ ⌊a⌋ + ⌊b⌋ := by rw [← sub_le_iff_le_add, le_floor, Int.cast_sub, sub_le_comm, Int.cast_sub, Int.cast_one] refine le_trans ?_ (sub_one_lt_floor _).le rw [sub_le_iff_le_add', ← add_sub_assoc, sub_le_sub_iff_right] exact floor_le _ #align int.le_floor_add_floor Int.le_floor_add_floor @[simp] theorem floor_int_add (z : ℤ) (a : α) : ⌊↑z + a⌋ = z + ⌊a⌋ := by simpa only [add_comm] using floor_add_int a z #align int.floor_int_add Int.floor_int_add @[simp] theorem floor_add_nat (a : α) (n : ℕ) : ⌊a + n⌋ = ⌊a⌋ + n := by rw [← Int.cast_natCast, floor_add_int] #align int.floor_add_nat Int.floor_add_nat -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_add_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : ⌊a + (no_index (OfNat.ofNat n))⌋ = ⌊a⌋ + OfNat.ofNat n := floor_add_nat a n @[simp] theorem floor_nat_add (n : ℕ) (a : α) : ⌊↑n + a⌋ = n + ⌊a⌋ := by rw [← Int.cast_natCast, floor_int_add] #align int.floor_nat_add Int.floor_nat_add -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_ofNat_add (n : ℕ) [n.AtLeastTwo] (a : α) : ⌊(no_index (OfNat.ofNat n)) + a⌋ = OfNat.ofNat n + ⌊a⌋ := floor_nat_add n a @[simp] theorem floor_sub_int (a : α) (z : ℤ) : ⌊a - z⌋ = ⌊a⌋ - z := Eq.trans (by rw [Int.cast_neg, sub_eq_add_neg]) (floor_add_int _ _) #align int.floor_sub_int Int.floor_sub_int @[simp] theorem floor_sub_nat (a : α) (n : ℕ) : ⌊a - n⌋ = ⌊a⌋ - n := by rw [← Int.cast_natCast, floor_sub_int] #align int.floor_sub_nat Int.floor_sub_nat @[simp] theorem floor_sub_one (a : α) : ⌊a - 1⌋ = ⌊a⌋ - 1 := mod_cast floor_sub_nat a 1 -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_sub_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : ⌊a - (no_index (OfNat.ofNat n))⌋ = ⌊a⌋ - OfNat.ofNat n := floor_sub_nat a n theorem abs_sub_lt_one_of_floor_eq_floor {α : Type*} [LinearOrderedCommRing α] [FloorRing α] {a b : α} (h : ⌊a⌋ = ⌊b⌋) : |a - b| < 1 := by have : a < ⌊a⌋ + 1 := lt_floor_add_one a have : b < ⌊b⌋ + 1 := lt_floor_add_one b have : (⌊a⌋ : α) = ⌊b⌋ := Int.cast_inj.2 h have : (⌊a⌋ : α) ≤ a := floor_le a have : (⌊b⌋ : α) ≤ b := floor_le b exact abs_sub_lt_iff.2 ⟨by linarith, by linarith⟩ #align int.abs_sub_lt_one_of_floor_eq_floor Int.abs_sub_lt_one_of_floor_eq_floor theorem floor_eq_iff : ⌊a⌋ = z ↔ ↑z ≤ a ∧ a < z + 1 := by rw [le_antisymm_iff, le_floor, ← Int.lt_add_one_iff, floor_lt, Int.cast_add, Int.cast_one, and_comm] #align int.floor_eq_iff Int.floor_eq_iff @[simp] theorem floor_eq_zero_iff : ⌊a⌋ = 0 ↔ a ∈ Ico (0 : α) 1 := by simp [floor_eq_iff] #align int.floor_eq_zero_iff Int.floor_eq_zero_iff theorem floor_eq_on_Ico (n : ℤ) : ∀ a ∈ Set.Ico (n : α) (n + 1), ⌊a⌋ = n := fun _ ⟨h₀, h₁⟩ => floor_eq_iff.mpr ⟨h₀, h₁⟩ #align int.floor_eq_on_Ico Int.floor_eq_on_Ico theorem floor_eq_on_Ico' (n : ℤ) : ∀ a ∈ Set.Ico (n : α) (n + 1), (⌊a⌋ : α) = n := fun a ha => congr_arg _ <| floor_eq_on_Ico n a ha #align int.floor_eq_on_Ico' Int.floor_eq_on_Ico' -- Porting note: in mathlib3 there was no need for the type annotation in `(m:α)` @[simp] theorem preimage_floor_singleton (m : ℤ) : (floor : α → ℤ) ⁻¹' {m} = Ico (m : α) (m + 1) := ext fun _ => floor_eq_iff #align int.preimage_floor_singleton Int.preimage_floor_singleton /-! #### Fractional part -/ @[simp] theorem self_sub_floor (a : α) : a - ⌊a⌋ = fract a := rfl #align int.self_sub_floor Int.self_sub_floor @[simp] theorem floor_add_fract (a : α) : (⌊a⌋ : α) + fract a = a := add_sub_cancel _ _ #align int.floor_add_fract Int.floor_add_fract @[simp] theorem fract_add_floor (a : α) : fract a + ⌊a⌋ = a := sub_add_cancel _ _ #align int.fract_add_floor Int.fract_add_floor @[simp] theorem fract_add_int (a : α) (m : ℤ) : fract (a + m) = fract a := by rw [fract] simp #align int.fract_add_int Int.fract_add_int @[simp] theorem fract_add_nat (a : α) (m : ℕ) : fract (a + m) = fract a := by rw [fract] simp #align int.fract_add_nat Int.fract_add_nat @[simp] theorem fract_add_one (a : α) : fract (a + 1) = fract a := mod_cast fract_add_nat a 1 -- See note [no_index around OfNat.ofNat] @[simp] theorem fract_add_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : fract (a + (no_index (OfNat.ofNat n))) = fract a := fract_add_nat a n @[simp] theorem fract_int_add (m : ℤ) (a : α) : fract (↑m + a) = fract a := by rw [add_comm, fract_add_int] #align int.fract_int_add Int.fract_int_add @[simp] theorem fract_nat_add (n : ℕ) (a : α) : fract (↑n + a) = fract a := by rw [add_comm, fract_add_nat] @[simp] theorem fract_one_add (a : α) : fract (1 + a) = fract a := mod_cast fract_nat_add 1 a -- See note [no_index around OfNat.ofNat] @[simp] theorem fract_ofNat_add (n : ℕ) [n.AtLeastTwo] (a : α) : fract ((no_index (OfNat.ofNat n)) + a) = fract a := fract_nat_add n a @[simp] theorem fract_sub_int (a : α) (m : ℤ) : fract (a - m) = fract a := by rw [fract] simp #align int.fract_sub_int Int.fract_sub_int @[simp] theorem fract_sub_nat (a : α) (n : ℕ) : fract (a - n) = fract a := by rw [fract] simp #align int.fract_sub_nat Int.fract_sub_nat @[simp] theorem fract_sub_one (a : α) : fract (a - 1) = fract a := mod_cast fract_sub_nat a 1 -- See note [no_index around OfNat.ofNat] @[simp] theorem fract_sub_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : fract (a - (no_index (OfNat.ofNat n))) = fract a := fract_sub_nat a n -- Was a duplicate lemma under a bad name #align int.fract_int_nat Int.fract_int_add theorem fract_add_le (a b : α) : fract (a + b) ≤ fract a + fract b := by rw [fract, fract, fract, sub_add_sub_comm, sub_le_sub_iff_left, ← Int.cast_add, Int.cast_le] exact le_floor_add _ _ #align int.fract_add_le Int.fract_add_le theorem fract_add_fract_le (a b : α) : fract a + fract b ≤ fract (a + b) + 1 := by rw [fract, fract, fract, sub_add_sub_comm, sub_add, sub_le_sub_iff_left] exact mod_cast le_floor_add_floor a b #align int.fract_add_fract_le Int.fract_add_fract_le @[simp] theorem self_sub_fract (a : α) : a - fract a = ⌊a⌋ := sub_sub_cancel _ _ #align int.self_sub_fract Int.self_sub_fract @[simp] theorem fract_sub_self (a : α) : fract a - a = -⌊a⌋ := sub_sub_cancel_left _ _ #align int.fract_sub_self Int.fract_sub_self @[simp] theorem fract_nonneg (a : α) : 0 ≤ fract a := sub_nonneg.2 <| floor_le _ #align int.fract_nonneg Int.fract_nonneg /-- The fractional part of `a` is positive if and only if `a ≠ ⌊a⌋`. -/ lemma fract_pos : 0 < fract a ↔ a ≠ ⌊a⌋ := (fract_nonneg a).lt_iff_ne.trans <| ne_comm.trans sub_ne_zero #align int.fract_pos Int.fract_pos theorem fract_lt_one (a : α) : fract a < 1 := sub_lt_comm.1 <| sub_one_lt_floor _ #align int.fract_lt_one Int.fract_lt_one @[simp] theorem fract_zero : fract (0 : α) = 0 := by rw [fract, floor_zero, cast_zero, sub_self] #align int.fract_zero Int.fract_zero @[simp] theorem fract_one : fract (1 : α) = 0 := by simp [fract] #align int.fract_one Int.fract_one theorem abs_fract : |fract a| = fract a := abs_eq_self.mpr <| fract_nonneg a #align int.abs_fract Int.abs_fract @[simp] theorem abs_one_sub_fract : |1 - fract a| = 1 - fract a := abs_eq_self.mpr <| sub_nonneg.mpr (fract_lt_one a).le #align int.abs_one_sub_fract Int.abs_one_sub_fract @[simp] theorem fract_intCast (z : ℤ) : fract (z : α) = 0 := by unfold fract rw [floor_intCast] exact sub_self _ #align int.fract_int_cast Int.fract_intCast @[simp] theorem fract_natCast (n : ℕ) : fract (n : α) = 0 := by simp [fract] #align int.fract_nat_cast Int.fract_natCast -- See note [no_index around OfNat.ofNat] @[simp] theorem fract_ofNat (n : ℕ) [n.AtLeastTwo] : fract ((no_index (OfNat.ofNat n)) : α) = 0 := fract_natCast n -- porting note (#10618): simp can prove this -- @[simp] theorem fract_floor (a : α) : fract (⌊a⌋ : α) = 0 := fract_intCast _ #align int.fract_floor Int.fract_floor @[simp] theorem floor_fract (a : α) : ⌊fract a⌋ = 0 := by rw [floor_eq_iff, Int.cast_zero, zero_add]; exact ⟨fract_nonneg _, fract_lt_one _⟩ #align int.floor_fract Int.floor_fract theorem fract_eq_iff {a b : α} : fract a = b ↔ 0 ≤ b ∧ b < 1 ∧ ∃ z : ℤ, a - b = z := ⟨fun h => by rw [← h] exact ⟨fract_nonneg _, fract_lt_one _, ⟨⌊a⌋, sub_sub_cancel _ _⟩⟩, by rintro ⟨h₀, h₁, z, hz⟩ rw [← self_sub_floor, eq_comm, eq_sub_iff_add_eq, add_comm, ← eq_sub_iff_add_eq, hz, Int.cast_inj, floor_eq_iff, ← hz] constructor <;> simpa [sub_eq_add_neg, add_assoc] ⟩ #align int.fract_eq_iff Int.fract_eq_iff theorem fract_eq_fract {a b : α} : fract a = fract b ↔ ∃ z : ℤ, a - b = z := ⟨fun h => ⟨⌊a⌋ - ⌊b⌋, by unfold fract at h; rw [Int.cast_sub, sub_eq_sub_iff_sub_eq_sub.1 h]⟩, by rintro ⟨z, hz⟩ refine fract_eq_iff.2 ⟨fract_nonneg _, fract_lt_one _, z + ⌊b⌋, ?_⟩ rw [eq_add_of_sub_eq hz, add_comm, Int.cast_add] exact add_sub_sub_cancel _ _ _⟩ #align int.fract_eq_fract Int.fract_eq_fract @[simp] theorem fract_eq_self {a : α} : fract a = a ↔ 0 ≤ a ∧ a < 1 := fract_eq_iff.trans <| and_assoc.symm.trans <| and_iff_left ⟨0, by simp⟩ #align int.fract_eq_self Int.fract_eq_self @[simp] theorem fract_fract (a : α) : fract (fract a) = fract a := fract_eq_self.2 ⟨fract_nonneg _, fract_lt_one _⟩ #align int.fract_fract Int.fract_fract theorem fract_add (a b : α) : ∃ z : ℤ, fract (a + b) - fract a - fract b = z := ⟨⌊a⌋ + ⌊b⌋ - ⌊a + b⌋, by unfold fract simp only [sub_eq_add_neg, neg_add_rev, neg_neg, cast_add, cast_neg] abel⟩ #align int.fract_add Int.fract_add theorem fract_neg {x : α} (hx : fract x ≠ 0) : fract (-x) = 1 - fract x := by rw [fract_eq_iff] constructor · rw [le_sub_iff_add_le, zero_add] exact (fract_lt_one x).le refine ⟨sub_lt_self _ (lt_of_le_of_ne' (fract_nonneg x) hx), -⌊x⌋ - 1, ?_⟩ simp only [sub_sub_eq_add_sub, cast_sub, cast_neg, cast_one, sub_left_inj] conv in -x => rw [← floor_add_fract x] simp [-floor_add_fract] #align int.fract_neg Int.fract_neg @[simp] theorem fract_neg_eq_zero {x : α} : fract (-x) = 0 ↔ fract x = 0 := by simp only [fract_eq_iff, le_refl, zero_lt_one, tsub_zero, true_and_iff] constructor <;> rintro ⟨z, hz⟩ <;> use -z <;> simp [← hz] #align int.fract_neg_eq_zero Int.fract_neg_eq_zero theorem fract_mul_nat (a : α) (b : ℕ) : ∃ z : ℤ, fract a * b - fract (a * b) = z := by induction' b with c hc · use 0; simp · rcases hc with ⟨z, hz⟩ rw [Nat.cast_add, mul_add, mul_add, Nat.cast_one, mul_one, mul_one] rcases fract_add (a * c) a with ⟨y, hy⟩ use z - y rw [Int.cast_sub, ← hz, ← hy] abel #align int.fract_mul_nat Int.fract_mul_nat -- Porting note: in mathlib3 there was no need for the type annotation in `(m:α)` theorem preimage_fract (s : Set α) : fract ⁻¹' s = ⋃ m : ℤ, (fun x => x - (m:α)) ⁻¹' (s ∩ Ico (0 : α) 1) := by ext x simp only [mem_preimage, mem_iUnion, mem_inter_iff] refine ⟨fun h => ⟨⌊x⌋, h, fract_nonneg x, fract_lt_one x⟩, ?_⟩ rintro ⟨m, hms, hm0, hm1⟩ obtain rfl : ⌊x⌋ = m := floor_eq_iff.2 ⟨sub_nonneg.1 hm0, sub_lt_iff_lt_add'.1 hm1⟩ exact hms #align int.preimage_fract Int.preimage_fract theorem image_fract (s : Set α) : fract '' s = ⋃ m : ℤ, (fun x : α => x - m) '' s ∩ Ico 0 1 := by ext x simp only [mem_image, mem_inter_iff, mem_iUnion]; constructor · rintro ⟨y, hy, rfl⟩ exact ⟨⌊y⌋, ⟨y, hy, rfl⟩, fract_nonneg y, fract_lt_one y⟩ · rintro ⟨m, ⟨y, hys, rfl⟩, h0, h1⟩ obtain rfl : ⌊y⌋ = m := floor_eq_iff.2 ⟨sub_nonneg.1 h0, sub_lt_iff_lt_add'.1 h1⟩ exact ⟨y, hys, rfl⟩ #align int.image_fract Int.image_fract section LinearOrderedField variable {k : Type*} [LinearOrderedField k] [FloorRing k] {b : k} theorem fract_div_mul_self_mem_Ico (a b : k) (ha : 0 < a) : fract (b / a) * a ∈ Ico 0 a := ⟨(mul_nonneg_iff_of_pos_right ha).2 (fract_nonneg (b / a)), (mul_lt_iff_lt_one_left ha).2 (fract_lt_one (b / a))⟩ #align int.fract_div_mul_self_mem_Ico Int.fract_div_mul_self_mem_Ico theorem fract_div_mul_self_add_zsmul_eq (a b : k) (ha : a ≠ 0) : fract (b / a) * a + ⌊b / a⌋ • a = b := by rw [zsmul_eq_mul, ← add_mul, fract_add_floor, div_mul_cancel₀ b ha] #align int.fract_div_mul_self_add_zsmul_eq Int.fract_div_mul_self_add_zsmul_eq theorem sub_floor_div_mul_nonneg (a : k) (hb : 0 < b) : 0 ≤ a - ⌊a / b⌋ * b := sub_nonneg_of_le <| (le_div_iff hb).1 <| floor_le _ #align int.sub_floor_div_mul_nonneg Int.sub_floor_div_mul_nonneg theorem sub_floor_div_mul_lt (a : k) (hb : 0 < b) : a - ⌊a / b⌋ * b < b := sub_lt_iff_lt_add.2 <| by -- Porting note: `← one_add_mul` worked in mathlib3 without the argument rw [← one_add_mul _ b, ← div_lt_iff hb, add_comm] exact lt_floor_add_one _ #align int.sub_floor_div_mul_lt Int.sub_floor_div_mul_lt theorem fract_div_natCast_eq_div_natCast_mod {m n : ℕ} : fract ((m : k) / n) = ↑(m % n) / n := by rcases n.eq_zero_or_pos with (rfl | hn) · simp have hn' : 0 < (n : k) := by norm_cast refine fract_eq_iff.mpr ⟨?_, ?_, m / n, ?_⟩ · positivity · simpa only [div_lt_one hn', Nat.cast_lt] using m.mod_lt hn · rw [sub_eq_iff_eq_add', ← mul_right_inj' hn'.ne', mul_div_cancel₀ _ hn'.ne', mul_add, mul_div_cancel₀ _ hn'.ne'] norm_cast rw [← Nat.cast_add, Nat.mod_add_div m n] #align int.fract_div_nat_cast_eq_div_nat_cast_mod Int.fract_div_natCast_eq_div_natCast_mod -- TODO Generalise this to allow `n : ℤ` using `Int.fmod` instead of `Int.mod`. theorem fract_div_intCast_eq_div_intCast_mod {m : ℤ} {n : ℕ} : fract ((m : k) / n) = ↑(m % n) / n := by rcases n.eq_zero_or_pos with (rfl | hn) · simp replace hn : 0 < (n : k) := by norm_cast have : ∀ {l : ℤ}, 0 ≤ l → fract ((l : k) / n) = ↑(l % n) / n := by intros l hl obtain ⟨l₀, rfl | rfl⟩ := l.eq_nat_or_neg · rw [cast_natCast, ← natCast_mod, cast_natCast, fract_div_natCast_eq_div_natCast_mod] · rw [Right.nonneg_neg_iff, natCast_nonpos_iff] at hl simp [hl, zero_mod] obtain ⟨m₀, rfl | rfl⟩ := m.eq_nat_or_neg · exact this (ofNat_nonneg m₀) let q := ⌈↑m₀ / (n : k)⌉ let m₁ := q * ↑n - (↑m₀ : ℤ) have hm₁ : 0 ≤ m₁ := by simpa [m₁, ← @cast_le k, ← div_le_iff hn] using FloorRing.gc_ceil_coe.le_u_l _ calc fract ((Int.cast (-(m₀ : ℤ)) : k) / (n : k)) -- Porting note: the `rw [cast_neg, cast_natCast]` was `push_cast` = fract (-(m₀ : k) / n) := by rw [cast_neg, cast_natCast] _ = fract ((m₁ : k) / n) := ?_ _ = Int.cast (m₁ % (n : ℤ)) / Nat.cast n := this hm₁ _ = Int.cast (-(↑m₀ : ℤ) % ↑n) / Nat.cast n := ?_ · rw [← fract_int_add q, ← mul_div_cancel_right₀ (q : k) hn.ne', ← add_div, ← sub_eq_add_neg] -- Porting note: the `simp` was `push_cast` simp [m₁] · congr 2 change (q * ↑n - (↑m₀ : ℤ)) % ↑n = _ rw [sub_eq_add_neg, add_comm (q * ↑n), add_mul_emod_self] #align int.fract_div_int_cast_eq_div_int_cast_mod Int.fract_div_intCast_eq_div_intCast_mod end LinearOrderedField /-! #### Ceil -/ theorem gc_ceil_coe : GaloisConnection ceil ((↑) : ℤ → α) := FloorRing.gc_ceil_coe #align int.gc_ceil_coe Int.gc_ceil_coe theorem ceil_le : ⌈a⌉ ≤ z ↔ a ≤ z := gc_ceil_coe a z #align int.ceil_le Int.ceil_le theorem floor_neg : ⌊-a⌋ = -⌈a⌉ := eq_of_forall_le_iff fun z => by rw [le_neg, ceil_le, le_floor, Int.cast_neg, le_neg] #align int.floor_neg Int.floor_neg theorem ceil_neg : ⌈-a⌉ = -⌊a⌋ := eq_of_forall_ge_iff fun z => by rw [neg_le, ceil_le, le_floor, Int.cast_neg, neg_le] #align int.ceil_neg Int.ceil_neg theorem lt_ceil : z < ⌈a⌉ ↔ (z : α) < a := lt_iff_lt_of_le_iff_le ceil_le #align int.lt_ceil Int.lt_ceil @[simp] theorem add_one_le_ceil_iff : z + 1 ≤ ⌈a⌉ ↔ (z : α) < a := by rw [← lt_ceil, add_one_le_iff] #align int.add_one_le_ceil_iff Int.add_one_le_ceil_iff @[simp] theorem one_le_ceil_iff : 1 ≤ ⌈a⌉ ↔ 0 < a := by rw [← zero_add (1 : ℤ), add_one_le_ceil_iff, cast_zero] #align int.one_le_ceil_iff Int.one_le_ceil_iff theorem ceil_le_floor_add_one (a : α) : ⌈a⌉ ≤ ⌊a⌋ + 1 := by rw [ceil_le, Int.cast_add, Int.cast_one] exact (lt_floor_add_one a).le #align int.ceil_le_floor_add_one Int.ceil_le_floor_add_one theorem le_ceil (a : α) : a ≤ ⌈a⌉ := gc_ceil_coe.le_u_l a #align int.le_ceil Int.le_ceil @[simp] theorem ceil_intCast (z : ℤ) : ⌈(z : α)⌉ = z := eq_of_forall_ge_iff fun a => by rw [ceil_le, Int.cast_le] #align int.ceil_int_cast Int.ceil_intCast @[simp] theorem ceil_natCast (n : ℕ) : ⌈(n : α)⌉ = n := eq_of_forall_ge_iff fun a => by rw [ceil_le, ← cast_natCast, cast_le] #align int.ceil_nat_cast Int.ceil_natCast -- See note [no_index around OfNat.ofNat] @[simp] theorem ceil_ofNat (n : ℕ) [n.AtLeastTwo] : ⌈(no_index (OfNat.ofNat n : α))⌉ = n := ceil_natCast n theorem ceil_mono : Monotone (ceil : α → ℤ) := gc_ceil_coe.monotone_l #align int.ceil_mono Int.ceil_mono @[gcongr] theorem ceil_le_ceil : ∀ x y : α, x ≤ y → ⌈x⌉ ≤ ⌈y⌉ := ceil_mono @[simp] theorem ceil_add_int (a : α) (z : ℤ) : ⌈a + z⌉ = ⌈a⌉ + z := by rw [← neg_inj, neg_add', ← floor_neg, ← floor_neg, neg_add', floor_sub_int] #align int.ceil_add_int Int.ceil_add_int @[simp] theorem ceil_add_nat (a : α) (n : ℕ) : ⌈a + n⌉ = ⌈a⌉ + n := by rw [← Int.cast_natCast, ceil_add_int] #align int.ceil_add_nat Int.ceil_add_nat @[simp] theorem ceil_add_one (a : α) : ⌈a + 1⌉ = ⌈a⌉ + 1 := by -- Porting note: broken `convert ceil_add_int a (1 : ℤ)` rw [← ceil_add_int a (1 : ℤ), cast_one] #align int.ceil_add_one Int.ceil_add_one -- See note [no_index around OfNat.ofNat] @[simp] theorem ceil_add_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : ⌈a + (no_index (OfNat.ofNat n))⌉ = ⌈a⌉ + OfNat.ofNat n := ceil_add_nat a n @[simp] theorem ceil_sub_int (a : α) (z : ℤ) : ⌈a - z⌉ = ⌈a⌉ - z := Eq.trans (by rw [Int.cast_neg, sub_eq_add_neg]) (ceil_add_int _ _) #align int.ceil_sub_int Int.ceil_sub_int @[simp] theorem ceil_sub_nat (a : α) (n : ℕ) : ⌈a - n⌉ = ⌈a⌉ - n := by convert ceil_sub_int a n using 1 simp #align int.ceil_sub_nat Int.ceil_sub_nat @[simp] theorem ceil_sub_one (a : α) : ⌈a - 1⌉ = ⌈a⌉ - 1 := by rw [eq_sub_iff_add_eq, ← ceil_add_one, sub_add_cancel] #align int.ceil_sub_one Int.ceil_sub_one -- See note [no_index around OfNat.ofNat] @[simp] theorem ceil_sub_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : ⌈a - (no_index (OfNat.ofNat n))⌉ = ⌈a⌉ - OfNat.ofNat n := ceil_sub_nat a n theorem ceil_lt_add_one (a : α) : (⌈a⌉ : α) < a + 1 := by rw [← lt_ceil, ← Int.cast_one, ceil_add_int] apply lt_add_one #align int.ceil_lt_add_one Int.ceil_lt_add_one theorem ceil_add_le (a b : α) : ⌈a + b⌉ ≤ ⌈a⌉ + ⌈b⌉ := by rw [ceil_le, Int.cast_add] exact add_le_add (le_ceil _) (le_ceil _) #align int.ceil_add_le Int.ceil_add_le theorem ceil_add_ceil_le (a b : α) : ⌈a⌉ + ⌈b⌉ ≤ ⌈a + b⌉ + 1 := by rw [← le_sub_iff_add_le, ceil_le, Int.cast_sub, Int.cast_add, Int.cast_one, le_sub_comm] refine (ceil_lt_add_one _).le.trans ?_ rw [le_sub_iff_add_le', ← add_assoc, add_le_add_iff_right] exact le_ceil _ #align int.ceil_add_ceil_le Int.ceil_add_ceil_le @[simp] theorem ceil_pos : 0 < ⌈a⌉ ↔ 0 < a := by rw [lt_ceil, cast_zero] #align int.ceil_pos Int.ceil_pos @[simp] theorem ceil_zero : ⌈(0 : α)⌉ = 0 := by rw [← cast_zero, ceil_intCast] #align int.ceil_zero Int.ceil_zero @[simp] theorem ceil_one : ⌈(1 : α)⌉ = 1 := by rw [← cast_one, ceil_intCast] #align int.ceil_one Int.ceil_one theorem ceil_nonneg (ha : 0 ≤ a) : 0 ≤ ⌈a⌉ := mod_cast ha.trans (le_ceil a) #align int.ceil_nonneg Int.ceil_nonneg theorem ceil_eq_iff : ⌈a⌉ = z ↔ ↑z - 1 < a ∧ a ≤ z := by rw [← ceil_le, ← Int.cast_one, ← Int.cast_sub, ← lt_ceil, Int.sub_one_lt_iff, le_antisymm_iff, and_comm] #align int.ceil_eq_iff Int.ceil_eq_iff @[simp] theorem ceil_eq_zero_iff : ⌈a⌉ = 0 ↔ a ∈ Ioc (-1 : α) 0 := by simp [ceil_eq_iff] #align int.ceil_eq_zero_iff Int.ceil_eq_zero_iff theorem ceil_eq_on_Ioc (z : ℤ) : ∀ a ∈ Set.Ioc (z - 1 : α) z, ⌈a⌉ = z := fun _ ⟨h₀, h₁⟩ => ceil_eq_iff.mpr ⟨h₀, h₁⟩ #align int.ceil_eq_on_Ioc Int.ceil_eq_on_Ioc theorem ceil_eq_on_Ioc' (z : ℤ) : ∀ a ∈ Set.Ioc (z - 1 : α) z, (⌈a⌉ : α) = z := fun a ha => mod_cast ceil_eq_on_Ioc z a ha #align int.ceil_eq_on_Ioc' Int.ceil_eq_on_Ioc' theorem floor_le_ceil (a : α) : ⌊a⌋ ≤ ⌈a⌉ := cast_le.1 <| (floor_le _).trans <| le_ceil _ #align int.floor_le_ceil Int.floor_le_ceil theorem floor_lt_ceil_of_lt {a b : α} (h : a < b) : ⌊a⌋ < ⌈b⌉ := cast_lt.1 <| (floor_le a).trans_lt <| h.trans_le <| le_ceil b #align int.floor_lt_ceil_of_lt Int.floor_lt_ceil_of_lt -- Porting note: in mathlib3 there was no need for the type annotation in `(m : α)` @[simp] theorem preimage_ceil_singleton (m : ℤ) : (ceil : α → ℤ) ⁻¹' {m} = Ioc ((m : α) - 1) m := ext fun _ => ceil_eq_iff #align int.preimage_ceil_singleton Int.preimage_ceil_singleton theorem fract_eq_zero_or_add_one_sub_ceil (a : α) : fract a = 0 ∨ fract a = a + 1 - (⌈a⌉ : α) := by rcases eq_or_ne (fract a) 0 with ha | ha · exact Or.inl ha right suffices (⌈a⌉ : α) = ⌊a⌋ + 1 by rw [this, ← self_sub_fract] abel norm_cast rw [ceil_eq_iff] refine ⟨?_, _root_.le_of_lt <| by simp⟩ rw [cast_add, cast_one, add_tsub_cancel_right, ← self_sub_fract a, sub_lt_self_iff] exact ha.symm.lt_of_le (fract_nonneg a) #align int.fract_eq_zero_or_add_one_sub_ceil Int.fract_eq_zero_or_add_one_sub_ceil theorem ceil_eq_add_one_sub_fract (ha : fract a ≠ 0) : (⌈a⌉ : α) = a + 1 - fract a := by rw [(or_iff_right ha).mp (fract_eq_zero_or_add_one_sub_ceil a)] abel #align int.ceil_eq_add_one_sub_fract Int.ceil_eq_add_one_sub_fract theorem ceil_sub_self_eq (ha : fract a ≠ 0) : (⌈a⌉ : α) - a = 1 - fract a := by rw [(or_iff_right ha).mp (fract_eq_zero_or_add_one_sub_ceil a)] abel #align int.ceil_sub_self_eq Int.ceil_sub_self_eq /-! #### Intervals -/ @[simp] theorem preimage_Ioo {a b : α} : ((↑) : ℤ → α) ⁻¹' Set.Ioo a b = Set.Ioo ⌊a⌋ ⌈b⌉ := by ext simp [floor_lt, lt_ceil] #align int.preimage_Ioo Int.preimage_Ioo @[simp] theorem preimage_Ico {a b : α} : ((↑) : ℤ → α) ⁻¹' Set.Ico a b = Set.Ico ⌈a⌉ ⌈b⌉ := by ext simp [ceil_le, lt_ceil] #align int.preimage_Ico Int.preimage_Ico @[simp] theorem preimage_Ioc {a b : α} : ((↑) : ℤ → α) ⁻¹' Set.Ioc a b = Set.Ioc ⌊a⌋ ⌊b⌋ := by ext simp [floor_lt, le_floor] #align int.preimage_Ioc Int.preimage_Ioc @[simp] theorem preimage_Icc {a b : α} : ((↑) : ℤ → α) ⁻¹' Set.Icc a b = Set.Icc ⌈a⌉ ⌊b⌋ := by ext simp [ceil_le, le_floor] #align int.preimage_Icc Int.preimage_Icc @[simp] theorem preimage_Ioi : ((↑) : ℤ → α) ⁻¹' Set.Ioi a = Set.Ioi ⌊a⌋ := by ext simp [floor_lt] #align int.preimage_Ioi Int.preimage_Ioi @[simp] theorem preimage_Ici : ((↑) : ℤ → α) ⁻¹' Set.Ici a = Set.Ici ⌈a⌉ := by ext simp [ceil_le] #align int.preimage_Ici Int.preimage_Ici @[simp] theorem preimage_Iio : ((↑) : ℤ → α) ⁻¹' Set.Iio a = Set.Iio ⌈a⌉ := by ext simp [lt_ceil] #align int.preimage_Iio Int.preimage_Iio @[simp] theorem preimage_Iic : ((↑) : ℤ → α) ⁻¹' Set.Iic a = Set.Iic ⌊a⌋ := by ext simp [le_floor] #align int.preimage_Iic Int.preimage_Iic end Int open Int /-! ### Round -/ section round section LinearOrderedRing variable [LinearOrderedRing α] [FloorRing α] /-- `round` rounds a number to the nearest integer. `round (1 / 2) = 1` -/ def round (x : α) : ℤ := if 2 * fract x < 1 then ⌊x⌋ else ⌈x⌉ #align round round @[simp] theorem round_zero : round (0 : α) = 0 := by simp [round] #align round_zero round_zero @[simp] theorem round_one : round (1 : α) = 1 := by simp [round] #align round_one round_one @[simp] theorem round_natCast (n : ℕ) : round (n : α) = n := by simp [round] #align round_nat_cast round_natCast -- See note [no_index around OfNat.ofNat] @[simp] theorem round_ofNat (n : ℕ) [n.AtLeastTwo] : round (no_index (OfNat.ofNat n : α)) = n := round_natCast n @[simp] theorem round_intCast (n : ℤ) : round (n : α) = n := by simp [round] #align round_int_cast round_intCast @[simp] theorem round_add_int (x : α) (y : ℤ) : round (x + y) = round x + y := by rw [round, round, Int.fract_add_int, Int.floor_add_int, Int.ceil_add_int, ← apply_ite₂, ite_self] #align round_add_int round_add_int @[simp] theorem round_add_one (a : α) : round (a + 1) = round a + 1 := by -- Porting note: broken `convert round_add_int a 1` rw [← round_add_int a 1, cast_one] #align round_add_one round_add_one @[simp] theorem round_sub_int (x : α) (y : ℤ) : round (x - y) = round x - y := by rw [sub_eq_add_neg] norm_cast rw [round_add_int, sub_eq_add_neg] #align round_sub_int round_sub_int @[simp] theorem round_sub_one (a : α) : round (a - 1) = round a - 1 := by -- Porting note: broken `convert round_sub_int a 1` rw [← round_sub_int a 1, cast_one] #align round_sub_one round_sub_one @[simp] theorem round_add_nat (x : α) (y : ℕ) : round (x + y) = round x + y := mod_cast round_add_int x y #align round_add_nat round_add_nat -- See note [no_index around OfNat.ofNat] @[simp] theorem round_add_ofNat (x : α) (n : ℕ) [n.AtLeastTwo] : round (x + (no_index (OfNat.ofNat n))) = round x + OfNat.ofNat n := round_add_nat x n @[simp] theorem round_sub_nat (x : α) (y : ℕ) : round (x - y) = round x - y := mod_cast round_sub_int x y #align round_sub_nat round_sub_nat -- See note [no_index around OfNat.ofNat] @[simp] theorem round_sub_ofNat (x : α) (n : ℕ) [n.AtLeastTwo] : round (x - (no_index (OfNat.ofNat n))) = round x - OfNat.ofNat n := round_sub_nat x n @[simp] theorem round_int_add (x : α) (y : ℤ) : round ((y : α) + x) = y + round x := by rw [add_comm, round_add_int, add_comm] #align round_int_add round_int_add @[simp] theorem round_nat_add (x : α) (y : ℕ) : round ((y : α) + x) = y + round x := by rw [add_comm, round_add_nat, add_comm] #align round_nat_add round_nat_add -- See note [no_index around OfNat.ofNat] @[simp] theorem round_ofNat_add (n : ℕ) [n.AtLeastTwo] (x : α) : round ((no_index (OfNat.ofNat n)) + x) = OfNat.ofNat n + round x := round_nat_add x n
Mathlib/Algebra/Order/Floor.lean
1,535
1,543
theorem abs_sub_round_eq_min (x : α) : |x - round x| = min (fract x) (1 - fract x) := by
simp_rw [round, min_def_lt, two_mul, ← lt_tsub_iff_left] cases' lt_or_ge (fract x) (1 - fract x) with hx hx · rw [if_pos hx, if_pos hx, self_sub_floor, abs_fract] · have : 0 < fract x := by replace hx : 0 < fract x + fract x := lt_of_lt_of_le zero_lt_one (tsub_le_iff_left.mp hx) simpa only [← two_mul, mul_pos_iff_of_pos_left, zero_lt_two] using hx rw [if_neg (not_lt.mpr hx), if_neg (not_lt.mpr hx), abs_sub_comm, ceil_sub_self_eq this.ne.symm, abs_one_sub_fract]
/- 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, Kevin Buzzard, Yury Kudryashov, Eric Wieser -/ import Mathlib.Algebra.Algebra.Prod import Mathlib.LinearAlgebra.Basic import Mathlib.LinearAlgebra.Span import Mathlib.Order.PartialSups #align_import linear_algebra.prod from "leanprover-community/mathlib"@"cd391184c85986113f8c00844cfe6dda1d34be3d" /-! ### Products of modules This file defines constructors for linear maps whose domains or codomains are products. It contains theorems relating these to each other, as well as to `Submodule.prod`, `Submodule.map`, `Submodule.comap`, `LinearMap.range`, and `LinearMap.ker`. ## Main definitions - products in the domain: - `LinearMap.fst` - `LinearMap.snd` - `LinearMap.coprod` - `LinearMap.prod_ext` - products in the codomain: - `LinearMap.inl` - `LinearMap.inr` - `LinearMap.prod` - products in both domain and codomain: - `LinearMap.prodMap` - `LinearEquiv.prodMap` - `LinearEquiv.skewProd` -/ universe u v w x y z u' v' w' y' variable {R : Type u} {K : Type u'} {M : Type v} {V : Type v'} {M₂ : Type w} {V₂ : Type w'} variable {M₃ : Type y} {V₃ : Type y'} {M₄ : Type z} {ι : Type x} variable {M₅ M₆ : Type*} section Prod namespace LinearMap variable (S : Type*) [Semiring R] [Semiring S] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M₄] variable [AddCommMonoid M₅] [AddCommMonoid M₆] variable [Module R M] [Module R M₂] [Module R M₃] [Module R M₄] variable [Module R M₅] [Module R M₆] variable (f : M →ₗ[R] M₂) section variable (R M M₂) /-- The first projection of a product is a linear map. -/ def fst : M × M₂ →ₗ[R] M where toFun := Prod.fst map_add' _x _y := rfl map_smul' _x _y := rfl #align linear_map.fst LinearMap.fst /-- The second projection of a product is a linear map. -/ def snd : M × M₂ →ₗ[R] M₂ where toFun := Prod.snd map_add' _x _y := rfl map_smul' _x _y := rfl #align linear_map.snd LinearMap.snd end @[simp] theorem fst_apply (x : M × M₂) : fst R M M₂ x = x.1 := rfl #align linear_map.fst_apply LinearMap.fst_apply @[simp] theorem snd_apply (x : M × M₂) : snd R M M₂ x = x.2 := rfl #align linear_map.snd_apply LinearMap.snd_apply theorem fst_surjective : Function.Surjective (fst R M M₂) := fun x => ⟨(x, 0), rfl⟩ #align linear_map.fst_surjective LinearMap.fst_surjective theorem snd_surjective : Function.Surjective (snd R M M₂) := fun x => ⟨(0, x), rfl⟩ #align linear_map.snd_surjective LinearMap.snd_surjective /-- The prod of two linear maps is a linear map. -/ @[simps] def prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : M →ₗ[R] M₂ × M₃ where toFun := Pi.prod f g map_add' x y := by simp only [Pi.prod, Prod.mk_add_mk, map_add] map_smul' c x := by simp only [Pi.prod, Prod.smul_mk, map_smul, RingHom.id_apply] #align linear_map.prod LinearMap.prod theorem coe_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : ⇑(f.prod g) = Pi.prod f g := rfl #align linear_map.coe_prod LinearMap.coe_prod @[simp] theorem fst_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : (fst R M₂ M₃).comp (prod f g) = f := rfl #align linear_map.fst_prod LinearMap.fst_prod @[simp] theorem snd_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : (snd R M₂ M₃).comp (prod f g) = g := rfl #align linear_map.snd_prod LinearMap.snd_prod @[simp] theorem pair_fst_snd : prod (fst R M M₂) (snd R M M₂) = LinearMap.id := rfl #align linear_map.pair_fst_snd LinearMap.pair_fst_snd theorem prod_comp (f : M₂ →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) (h : M →ₗ[R] M₂) : (f.prod g).comp h = (f.comp h).prod (g.comp h) := rfl /-- Taking the product of two maps with the same domain is equivalent to taking the product of their codomains. See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/ @[simps] def prodEquiv [Module S M₂] [Module S M₃] [SMulCommClass R S M₂] [SMulCommClass R S M₃] : ((M →ₗ[R] M₂) × (M →ₗ[R] M₃)) ≃ₗ[S] M →ₗ[R] M₂ × M₃ where toFun f := f.1.prod f.2 invFun f := ((fst _ _ _).comp f, (snd _ _ _).comp f) left_inv f := by ext <;> rfl right_inv f := by ext <;> rfl map_add' a b := rfl map_smul' r a := rfl #align linear_map.prod_equiv LinearMap.prodEquiv section variable (R M M₂) /-- The left injection into a product is a linear map. -/ def inl : M →ₗ[R] M × M₂ := prod LinearMap.id 0 #align linear_map.inl LinearMap.inl /-- The right injection into a product is a linear map. -/ def inr : M₂ →ₗ[R] M × M₂ := prod 0 LinearMap.id #align linear_map.inr LinearMap.inr theorem range_inl : range (inl R M M₂) = ker (snd R M M₂) := by ext x simp only [mem_ker, mem_range] constructor · rintro ⟨y, rfl⟩ rfl · intro h exact ⟨x.fst, Prod.ext rfl h.symm⟩ #align linear_map.range_inl LinearMap.range_inl theorem ker_snd : ker (snd R M M₂) = range (inl R M M₂) := Eq.symm <| range_inl R M M₂ #align linear_map.ker_snd LinearMap.ker_snd theorem range_inr : range (inr R M M₂) = ker (fst R M M₂) := by ext x simp only [mem_ker, mem_range] constructor · rintro ⟨y, rfl⟩ rfl · intro h exact ⟨x.snd, Prod.ext h.symm rfl⟩ #align linear_map.range_inr LinearMap.range_inr theorem ker_fst : ker (fst R M M₂) = range (inr R M M₂) := Eq.symm <| range_inr R M M₂ #align linear_map.ker_fst LinearMap.ker_fst @[simp] theorem fst_comp_inl : fst R M M₂ ∘ₗ inl R M M₂ = id := rfl @[simp] theorem snd_comp_inl : snd R M M₂ ∘ₗ inl R M M₂ = 0 := rfl @[simp] theorem fst_comp_inr : fst R M M₂ ∘ₗ inr R M M₂ = 0 := rfl @[simp] theorem snd_comp_inr : snd R M M₂ ∘ₗ inr R M M₂ = id := rfl end @[simp] theorem coe_inl : (inl R M M₂ : M → M × M₂) = fun x => (x, 0) := rfl #align linear_map.coe_inl LinearMap.coe_inl theorem inl_apply (x : M) : inl R M M₂ x = (x, 0) := rfl #align linear_map.inl_apply LinearMap.inl_apply @[simp] theorem coe_inr : (inr R M M₂ : M₂ → M × M₂) = Prod.mk 0 := rfl #align linear_map.coe_inr LinearMap.coe_inr theorem inr_apply (x : M₂) : inr R M M₂ x = (0, x) := rfl #align linear_map.inr_apply LinearMap.inr_apply theorem inl_eq_prod : inl R M M₂ = prod LinearMap.id 0 := rfl #align linear_map.inl_eq_prod LinearMap.inl_eq_prod theorem inr_eq_prod : inr R M M₂ = prod 0 LinearMap.id := rfl #align linear_map.inr_eq_prod LinearMap.inr_eq_prod theorem inl_injective : Function.Injective (inl R M M₂) := fun _ => by simp #align linear_map.inl_injective LinearMap.inl_injective theorem inr_injective : Function.Injective (inr R M M₂) := fun _ => by simp #align linear_map.inr_injective LinearMap.inr_injective /-- The coprod function `x : M × M₂ ↦ f x.1 + g x.2` is a linear map. -/ def coprod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : M × M₂ →ₗ[R] M₃ := f.comp (fst _ _ _) + g.comp (snd _ _ _) #align linear_map.coprod LinearMap.coprod @[simp] theorem coprod_apply (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (x : M × M₂) : coprod f g x = f x.1 + g x.2 := rfl #align linear_map.coprod_apply LinearMap.coprod_apply @[simp] theorem coprod_inl (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : (coprod f g).comp (inl R M M₂) = f := by ext; simp only [map_zero, add_zero, coprod_apply, inl_apply, comp_apply] #align linear_map.coprod_inl LinearMap.coprod_inl @[simp] theorem coprod_inr (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : (coprod f g).comp (inr R M M₂) = g := by ext; simp only [map_zero, coprod_apply, inr_apply, zero_add, comp_apply] #align linear_map.coprod_inr LinearMap.coprod_inr @[simp] theorem coprod_inl_inr : coprod (inl R M M₂) (inr R M M₂) = LinearMap.id := by ext <;> simp only [Prod.mk_add_mk, add_zero, id_apply, coprod_apply, inl_apply, inr_apply, zero_add] #align linear_map.coprod_inl_inr LinearMap.coprod_inl_inr theorem coprod_zero_left (g : M₂ →ₗ[R] M₃) : (0 : M →ₗ[R] M₃).coprod g = g.comp (snd R M M₂) := zero_add _ theorem coprod_zero_right (f : M →ₗ[R] M₃) : f.coprod (0 : M₂ →ₗ[R] M₃) = f.comp (fst R M M₂) := add_zero _ theorem comp_coprod (f : M₃ →ₗ[R] M₄) (g₁ : M →ₗ[R] M₃) (g₂ : M₂ →ₗ[R] M₃) : f.comp (g₁.coprod g₂) = (f.comp g₁).coprod (f.comp g₂) := ext fun x => f.map_add (g₁ x.1) (g₂ x.2) #align linear_map.comp_coprod LinearMap.comp_coprod theorem fst_eq_coprod : fst R M M₂ = coprod LinearMap.id 0 := by ext; simp #align linear_map.fst_eq_coprod LinearMap.fst_eq_coprod theorem snd_eq_coprod : snd R M M₂ = coprod 0 LinearMap.id := by ext; simp #align linear_map.snd_eq_coprod LinearMap.snd_eq_coprod @[simp] theorem coprod_comp_prod (f : M₂ →ₗ[R] M₄) (g : M₃ →ₗ[R] M₄) (f' : M →ₗ[R] M₂) (g' : M →ₗ[R] M₃) : (f.coprod g).comp (f'.prod g') = f.comp f' + g.comp g' := rfl #align linear_map.coprod_comp_prod LinearMap.coprod_comp_prod @[simp] theorem coprod_map_prod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (S : Submodule R M) (S' : Submodule R M₂) : (Submodule.prod S S').map (LinearMap.coprod f g) = S.map f ⊔ S'.map g := SetLike.coe_injective <| by simp only [LinearMap.coprod_apply, Submodule.coe_sup, Submodule.map_coe] rw [← Set.image2_add, Set.image2_image_left, Set.image2_image_right] exact Set.image_prod fun m m₂ => f m + g m₂ #align linear_map.coprod_map_prod LinearMap.coprod_map_prod /-- Taking the product of two maps with the same codomain is equivalent to taking the product of their domains. See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/ @[simps] def coprodEquiv [Module S M₃] [SMulCommClass R S M₃] : ((M →ₗ[R] M₃) × (M₂ →ₗ[R] M₃)) ≃ₗ[S] M × M₂ →ₗ[R] M₃ where toFun f := f.1.coprod f.2 invFun f := (f.comp (inl _ _ _), f.comp (inr _ _ _)) left_inv f := by simp only [coprod_inl, coprod_inr] right_inv f := by simp only [← comp_coprod, comp_id, coprod_inl_inr] map_add' a b := by ext simp only [Prod.snd_add, add_apply, coprod_apply, Prod.fst_add, add_add_add_comm] map_smul' r a := by dsimp ext simp only [smul_add, smul_apply, Prod.smul_snd, Prod.smul_fst, coprod_apply] #align linear_map.coprod_equiv LinearMap.coprodEquiv theorem prod_ext_iff {f g : M × M₂ →ₗ[R] M₃} : f = g ↔ f.comp (inl _ _ _) = g.comp (inl _ _ _) ∧ f.comp (inr _ _ _) = g.comp (inr _ _ _) := (coprodEquiv ℕ).symm.injective.eq_iff.symm.trans Prod.ext_iff #align linear_map.prod_ext_iff LinearMap.prod_ext_iff /-- Split equality of linear maps from a product into linear maps over each component, to allow `ext` to apply lemmas specific to `M →ₗ M₃` and `M₂ →ₗ M₃`. See note [partially-applied ext lemmas]. -/ @[ext 1100] theorem prod_ext {f g : M × M₂ →ₗ[R] M₃} (hl : f.comp (inl _ _ _) = g.comp (inl _ _ _)) (hr : f.comp (inr _ _ _) = g.comp (inr _ _ _)) : f = g := prod_ext_iff.2 ⟨hl, hr⟩ #align linear_map.prod_ext LinearMap.prod_ext /-- `prod.map` of two linear maps. -/ def prodMap (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) : M × M₂ →ₗ[R] M₃ × M₄ := (f.comp (fst R M M₂)).prod (g.comp (snd R M M₂)) #align linear_map.prod_map LinearMap.prodMap theorem coe_prodMap (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) : ⇑(f.prodMap g) = Prod.map f g := rfl #align linear_map.coe_prod_map LinearMap.coe_prodMap @[simp] theorem prodMap_apply (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) (x) : f.prodMap g x = (f x.1, g x.2) := rfl #align linear_map.prod_map_apply LinearMap.prodMap_apply theorem prodMap_comap_prod (f : M →ₗ[R] M₂) (g : M₃ →ₗ[R] M₄) (S : Submodule R M₂) (S' : Submodule R M₄) : (Submodule.prod S S').comap (LinearMap.prodMap f g) = (S.comap f).prod (S'.comap g) := SetLike.coe_injective <| Set.preimage_prod_map_prod f g _ _ #align linear_map.prod_map_comap_prod LinearMap.prodMap_comap_prod theorem ker_prodMap (f : M →ₗ[R] M₂) (g : M₃ →ₗ[R] M₄) : ker (LinearMap.prodMap f g) = Submodule.prod (ker f) (ker g) := by dsimp only [ker] rw [← prodMap_comap_prod, Submodule.prod_bot] #align linear_map.ker_prod_map LinearMap.ker_prodMap @[simp] theorem prodMap_id : (id : M →ₗ[R] M).prodMap (id : M₂ →ₗ[R] M₂) = id := rfl #align linear_map.prod_map_id LinearMap.prodMap_id @[simp] theorem prodMap_one : (1 : M →ₗ[R] M).prodMap (1 : M₂ →ₗ[R] M₂) = 1 := rfl #align linear_map.prod_map_one LinearMap.prodMap_one theorem prodMap_comp (f₁₂ : M →ₗ[R] M₂) (f₂₃ : M₂ →ₗ[R] M₃) (g₁₂ : M₄ →ₗ[R] M₅) (g₂₃ : M₅ →ₗ[R] M₆) : f₂₃.prodMap g₂₃ ∘ₗ f₁₂.prodMap g₁₂ = (f₂₃ ∘ₗ f₁₂).prodMap (g₂₃ ∘ₗ g₁₂) := rfl #align linear_map.prod_map_comp LinearMap.prodMap_comp theorem prodMap_mul (f₁₂ : M →ₗ[R] M) (f₂₃ : M →ₗ[R] M) (g₁₂ : M₂ →ₗ[R] M₂) (g₂₃ : M₂ →ₗ[R] M₂) : f₂₃.prodMap g₂₃ * f₁₂.prodMap g₁₂ = (f₂₃ * f₁₂).prodMap (g₂₃ * g₁₂) := rfl #align linear_map.prod_map_mul LinearMap.prodMap_mul theorem prodMap_add (f₁ : M →ₗ[R] M₃) (f₂ : M →ₗ[R] M₃) (g₁ : M₂ →ₗ[R] M₄) (g₂ : M₂ →ₗ[R] M₄) : (f₁ + f₂).prodMap (g₁ + g₂) = f₁.prodMap g₁ + f₂.prodMap g₂ := rfl #align linear_map.prod_map_add LinearMap.prodMap_add @[simp] theorem prodMap_zero : (0 : M →ₗ[R] M₂).prodMap (0 : M₃ →ₗ[R] M₄) = 0 := rfl #align linear_map.prod_map_zero LinearMap.prodMap_zero @[simp] theorem prodMap_smul [Module S M₃] [Module S M₄] [SMulCommClass R S M₃] [SMulCommClass R S M₄] (s : S) (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₄) : prodMap (s • f) (s • g) = s • prodMap f g := rfl #align linear_map.prod_map_smul LinearMap.prodMap_smul variable (R M M₂ M₃ M₄) /-- `LinearMap.prodMap` as a `LinearMap` -/ @[simps] def prodMapLinear [Module S M₃] [Module S M₄] [SMulCommClass R S M₃] [SMulCommClass R S M₄] : (M →ₗ[R] M₃) × (M₂ →ₗ[R] M₄) →ₗ[S] M × M₂ →ₗ[R] M₃ × M₄ where toFun f := prodMap f.1 f.2 map_add' _ _ := rfl map_smul' _ _ := rfl #align linear_map.prod_map_linear LinearMap.prodMapLinear /-- `LinearMap.prodMap` as a `RingHom` -/ @[simps] def prodMapRingHom : (M →ₗ[R] M) × (M₂ →ₗ[R] M₂) →+* M × M₂ →ₗ[R] M × M₂ where toFun f := prodMap f.1 f.2 map_one' := prodMap_one map_zero' := rfl map_add' _ _ := rfl map_mul' _ _ := rfl #align linear_map.prod_map_ring_hom LinearMap.prodMapRingHom variable {R M M₂ M₃ M₄} section map_mul variable {A : Type*} [NonUnitalNonAssocSemiring A] [Module R A] variable {B : Type*} [NonUnitalNonAssocSemiring B] [Module R B] theorem inl_map_mul (a₁ a₂ : A) : LinearMap.inl R A B (a₁ * a₂) = LinearMap.inl R A B a₁ * LinearMap.inl R A B a₂ := Prod.ext rfl (by simp) #align linear_map.inl_map_mul LinearMap.inl_map_mul theorem inr_map_mul (b₁ b₂ : B) : LinearMap.inr R A B (b₁ * b₂) = LinearMap.inr R A B b₁ * LinearMap.inr R A B b₂ := Prod.ext (by simp) rfl #align linear_map.inr_map_mul LinearMap.inr_map_mul end map_mul end LinearMap end Prod namespace LinearMap variable (R M M₂) variable [CommSemiring R] variable [AddCommMonoid M] [AddCommMonoid M₂] variable [Module R M] [Module R M₂] /-- `LinearMap.prodMap` as an `AlgHom` -/ @[simps!] def prodMapAlgHom : Module.End R M × Module.End R M₂ →ₐ[R] Module.End R (M × M₂) := { prodMapRingHom R M M₂ with commutes' := fun _ => rfl } #align linear_map.prod_map_alg_hom LinearMap.prodMapAlgHom end LinearMap namespace LinearMap open Submodule variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M₄] [Module R M] [Module R M₂] [Module R M₃] [Module R M₄] theorem range_coprod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : range (f.coprod g) = range f ⊔ range g := Submodule.ext fun x => by simp [mem_sup] #align linear_map.range_coprod LinearMap.range_coprod theorem isCompl_range_inl_inr : IsCompl (range <| inl R M M₂) (range <| inr R M M₂) := by constructor · rw [disjoint_def] rintro ⟨_, _⟩ ⟨x, hx⟩ ⟨y, hy⟩ simp only [Prod.ext_iff, inl_apply, inr_apply, mem_bot] at hx hy ⊢ exact ⟨hy.1.symm, hx.2.symm⟩ · rw [codisjoint_iff_le_sup] rintro ⟨x, y⟩ - simp only [mem_sup, mem_range, exists_prop] refine ⟨(x, 0), ⟨x, rfl⟩, (0, y), ⟨y, rfl⟩, ?_⟩ simp #align linear_map.is_compl_range_inl_inr LinearMap.isCompl_range_inl_inr theorem sup_range_inl_inr : (range <| inl R M M₂) ⊔ (range <| inr R M M₂) = ⊤ := IsCompl.sup_eq_top isCompl_range_inl_inr #align linear_map.sup_range_inl_inr LinearMap.sup_range_inl_inr theorem disjoint_inl_inr : Disjoint (range <| inl R M M₂) (range <| inr R M M₂) := by simp (config := { contextual := true }) [disjoint_def, @eq_comm M 0, @eq_comm M₂ 0] #align linear_map.disjoint_inl_inr LinearMap.disjoint_inl_inr theorem map_coprod_prod (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (p : Submodule R M) (q : Submodule R M₂) : map (coprod f g) (p.prod q) = map f p ⊔ map g q := by refine le_antisymm ?_ (sup_le (map_le_iff_le_comap.2 ?_) (map_le_iff_le_comap.2 ?_)) · rw [SetLike.le_def] rintro _ ⟨x, ⟨h₁, h₂⟩, rfl⟩ exact mem_sup.2 ⟨_, ⟨_, h₁, rfl⟩, _, ⟨_, h₂, rfl⟩, rfl⟩ · exact fun x hx => ⟨(x, 0), by simp [hx]⟩ · exact fun x hx => ⟨(0, x), by simp [hx]⟩ #align linear_map.map_coprod_prod LinearMap.map_coprod_prod theorem comap_prod_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) (p : Submodule R M₂) (q : Submodule R M₃) : comap (prod f g) (p.prod q) = comap f p ⊓ comap g q := Submodule.ext fun _x => Iff.rfl #align linear_map.comap_prod_prod LinearMap.comap_prod_prod theorem prod_eq_inf_comap (p : Submodule R M) (q : Submodule R M₂) : p.prod q = p.comap (LinearMap.fst R M M₂) ⊓ q.comap (LinearMap.snd R M M₂) := Submodule.ext fun _x => Iff.rfl #align linear_map.prod_eq_inf_comap LinearMap.prod_eq_inf_comap theorem prod_eq_sup_map (p : Submodule R M) (q : Submodule R M₂) : p.prod q = p.map (LinearMap.inl R M M₂) ⊔ q.map (LinearMap.inr R M M₂) := by rw [← map_coprod_prod, coprod_inl_inr, map_id] #align linear_map.prod_eq_sup_map LinearMap.prod_eq_sup_map theorem span_inl_union_inr {s : Set M} {t : Set M₂} : span R (inl R M M₂ '' s ∪ inr R M M₂ '' t) = (span R s).prod (span R t) := by rw [span_union, prod_eq_sup_map, ← span_image, ← span_image] #align linear_map.span_inl_union_inr LinearMap.span_inl_union_inr @[simp] theorem ker_prod (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : ker (prod f g) = ker f ⊓ ker g := by rw [ker, ← prod_bot, comap_prod_prod]; rfl #align linear_map.ker_prod LinearMap.ker_prod theorem range_prod_le (f : M →ₗ[R] M₂) (g : M →ₗ[R] M₃) : range (prod f g) ≤ (range f).prod (range g) := by simp only [SetLike.le_def, prod_apply, mem_range, SetLike.mem_coe, mem_prod, exists_imp] rintro _ x rfl exact ⟨⟨x, rfl⟩, ⟨x, rfl⟩⟩ #align linear_map.range_prod_le LinearMap.range_prod_le theorem ker_prod_ker_le_ker_coprod {M₂ : Type*} [AddCommGroup M₂] [Module R M₂] {M₃ : Type*} [AddCommGroup M₃] [Module R M₃] (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) : (ker f).prod (ker g) ≤ ker (f.coprod g) := by rintro ⟨y, z⟩ simp (config := { contextual := true }) #align linear_map.ker_prod_ker_le_ker_coprod LinearMap.ker_prod_ker_le_ker_coprod theorem ker_coprod_of_disjoint_range {M₂ : Type*} [AddCommGroup M₂] [Module R M₂] {M₃ : Type*} [AddCommGroup M₃] [Module R M₃] (f : M →ₗ[R] M₃) (g : M₂ →ₗ[R] M₃) (hd : Disjoint (range f) (range g)) : ker (f.coprod g) = (ker f).prod (ker g) := by apply le_antisymm _ (ker_prod_ker_le_ker_coprod f g) rintro ⟨y, z⟩ h simp only [mem_ker, mem_prod, coprod_apply] at h ⊢ have : f y ∈ (range f) ⊓ (range g) := by simp only [true_and_iff, mem_range, mem_inf, exists_apply_eq_apply] use -z rwa [eq_comm, map_neg, ← sub_eq_zero, sub_neg_eq_add] rw [hd.eq_bot, mem_bot] at this rw [this] at h simpa [this] using h #align linear_map.ker_coprod_of_disjoint_range LinearMap.ker_coprod_of_disjoint_range end LinearMap namespace Submodule open LinearMap variable [Semiring R] variable [AddCommMonoid M] [AddCommMonoid M₂] variable [Module R M] [Module R M₂] theorem sup_eq_range (p q : Submodule R M) : p ⊔ q = range (p.subtype.coprod q.subtype) := Submodule.ext fun x => by simp [Submodule.mem_sup, SetLike.exists] #align submodule.sup_eq_range Submodule.sup_eq_range variable (p : Submodule R M) (q : Submodule R M₂) @[simp] theorem map_inl : p.map (inl R M M₂) = prod p ⊥ := by ext ⟨x, y⟩ simp only [and_left_comm, eq_comm, mem_map, Prod.mk.inj_iff, inl_apply, mem_bot, exists_eq_left', mem_prod] #align submodule.map_inl Submodule.map_inl @[simp] theorem map_inr : q.map (inr R M M₂) = prod ⊥ q := by ext ⟨x, y⟩; simp [and_left_comm, eq_comm, and_comm] #align submodule.map_inr Submodule.map_inr @[simp] theorem comap_fst : p.comap (fst R M M₂) = prod p ⊤ := by ext ⟨x, y⟩; simp #align submodule.comap_fst Submodule.comap_fst @[simp] theorem comap_snd : q.comap (snd R M M₂) = prod ⊤ q := by ext ⟨x, y⟩; simp #align submodule.comap_snd Submodule.comap_snd @[simp]
Mathlib/LinearAlgebra/Prod.lean
568
568
theorem prod_comap_inl : (prod p q).comap (inl R M M₂) = p := by
ext; simp
/- Copyright (c) 2022 María Inés de Frutos-Fernández. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: María Inés de Frutos-Fernández -/ import Mathlib.RingTheory.DedekindDomain.Ideal #align_import ring_theory.dedekind_domain.factorization from "leanprover-community/mathlib"@"2f588be38bb5bec02f218ba14f82fc82eb663f87" /-! # Factorization of ideals and fractional ideals of Dedekind domains Every nonzero ideal `I` of a Dedekind domain `R` can be factored as a product `∏_v v^{n_v}` over the maximal ideals of `R`, where the exponents `n_v` are natural numbers. Similarly, every nonzero fractional ideal `I` of a Dedekind domain `R` can be factored as a product `∏_v v^{n_v}` over the maximal ideals of `R`, where the exponents `n_v` are integers. We define `FractionalIdeal.count K v I` (abbreviated as `val_v(I)` in the documentation) to be `n_v`, and we prove some of its properties. If `I = 0`, we define `val_v(I) = 0`. ## Main definitions - `FractionalIdeal.count` : If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`, then we define `val_v(I)` as `(val_v(J) - val_v(a))`. If `I = 0`, we set `val_v(I) = 0`. ## Main results - `Ideal.finite_factors` : Only finitely many maximal ideals of `R` divide a given nonzero ideal. - `Ideal.finprod_heightOneSpectrum_factorization` : The ideal `I` equals the finprod `∏_v v^(val_v(I))`, where `val_v(I)` denotes the multiplicity of `v` in the factorization of `I` and `v` runs over the maximal ideals of `R`. - `FractionalIdeal.finprod_heightOneSpectrum_factorization` : If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`, then `I` is equal to the product `∏_v v^(val_v(J) - val_v(a))`. - `FractionalIdeal.finprod_heightOneSpectrum_factorization'` : If `I` is a nonzero fractional ideal, then `I` is equal to the product `∏_v v^(val_v(I))`. - `FractionalIdeal.finprod_heightOneSpectrum_factorization_principal` : For a nonzero `k = r/s ∈ K`, the fractional ideal `(k)` is equal to the product `∏_v v^(val_v(r) - val_v(s))`. - `FractionalIdeal.finite_factors` : If `I ≠ 0`, then `val_v(I) = 0` for all but finitely many maximal ideals of `R`. ## Implementation notes Since we are only interested in the factorization of nonzero fractional ideals, we define `val_v(0) = 0` so that every `val_v` is in `ℤ` and we can avoid having to use `WithTop ℤ`. ## Tags dedekind domain, fractional ideal, ideal, factorization -/ noncomputable section open scoped Classical nonZeroDivisors open Set Function UniqueFactorizationMonoid IsDedekindDomain IsDedekindDomain.HeightOneSpectrum Classical variable {R : Type*} [CommRing R] {K : Type*} [Field K] [Algebra R K] [IsFractionRing R K] /-! ### Factorization of ideals of Dedekind domains -/ variable [IsDedekindDomain R] (v : HeightOneSpectrum R) /-- Given a maximal ideal `v` and an ideal `I` of `R`, `maxPowDividing` returns the maximal power of `v` dividing `I`. -/ def IsDedekindDomain.HeightOneSpectrum.maxPowDividing (I : Ideal R) : Ideal R := v.asIdeal ^ (Associates.mk v.asIdeal).count (Associates.mk I).factors #align is_dedekind_domain.height_one_spectrum.max_pow_dividing IsDedekindDomain.HeightOneSpectrum.maxPowDividing /-- Only finitely many maximal ideals of `R` divide a given nonzero ideal. -/ theorem Ideal.finite_factors {I : Ideal R} (hI : I ≠ 0) : {v : HeightOneSpectrum R | v.asIdeal ∣ I}.Finite := by rw [← Set.finite_coe_iff, Set.coe_setOf] haveI h_fin := fintypeSubtypeDvd I hI refine Finite.of_injective (fun v => (⟨(v : HeightOneSpectrum R).asIdeal, v.2⟩ : { x // x ∣ I })) ?_ intro v w hvw simp? at hvw says simp only [Subtype.mk.injEq] at hvw exact Subtype.coe_injective ((HeightOneSpectrum.ext_iff (R := R) ↑v ↑w).mpr hvw) #align ideal.finite_factors Ideal.finite_factors /-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that the multiplicity of `v` in the factorization of `I`, denoted `val_v(I)`, is nonzero. -/ theorem Associates.finite_factors {I : Ideal R} (hI : I ≠ 0) : ∀ᶠ v : HeightOneSpectrum R in Filter.cofinite, ((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ) = 0 := by have h_supp : {v : HeightOneSpectrum R | ¬((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ) = 0} = {v : HeightOneSpectrum R | v.asIdeal ∣ I} := by ext v simp_rw [Int.natCast_eq_zero] exact Associates.count_ne_zero_iff_dvd hI v.irreducible rw [Filter.eventually_cofinite, h_supp] exact Ideal.finite_factors hI #align associates.finite_factors Associates.finite_factors namespace Ideal /-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that `v^(val_v(I))` is not the unit ideal. -/ theorem finite_mulSupport {I : Ideal R} (hI : I ≠ 0) : (mulSupport fun v : HeightOneSpectrum R => v.maxPowDividing I).Finite := haveI h_subset : {v : HeightOneSpectrum R | v.maxPowDividing I ≠ 1} ⊆ {v : HeightOneSpectrum R | ((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ) ≠ 0} := by intro v hv h_zero have hv' : v.maxPowDividing I = 1 := by rw [IsDedekindDomain.HeightOneSpectrum.maxPowDividing, Int.natCast_eq_zero.mp h_zero, pow_zero _] exact hv hv' Finite.subset (Filter.eventually_cofinite.mp (Associates.finite_factors hI)) h_subset #align ideal.finite_mul_support Ideal.finite_mulSupport /-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that `v^(val_v(I))`, regarded as a fractional ideal, is not `(1)`. -/ theorem finite_mulSupport_coe {I : Ideal R} (hI : I ≠ 0) : (mulSupport fun v : HeightOneSpectrum R => (v.asIdeal : FractionalIdeal R⁰ K) ^ ((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ)).Finite := by rw [mulSupport] simp_rw [Ne, zpow_natCast, ← FractionalIdeal.coeIdeal_pow, FractionalIdeal.coeIdeal_eq_one] exact finite_mulSupport hI #align ideal.finite_mul_support_coe Ideal.finite_mulSupport_coe /-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that `v^-(val_v(I))` is not the unit ideal. -/ theorem finite_mulSupport_inv {I : Ideal R} (hI : I ≠ 0) : (mulSupport fun v : HeightOneSpectrum R => (v.asIdeal : FractionalIdeal R⁰ K) ^ (-((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ))).Finite := by rw [mulSupport] simp_rw [zpow_neg, Ne, inv_eq_one] exact finite_mulSupport_coe hI #align ideal.finite_mul_support_inv Ideal.finite_mulSupport_inv /-- For every nonzero ideal `I` of `v`, `v^(val_v(I) + 1)` does not divide `∏_v v^(val_v(I))`. -/ theorem finprod_not_dvd (I : Ideal R) (hI : I ≠ 0) : ¬v.asIdeal ^ ((Associates.mk v.asIdeal).count (Associates.mk I).factors + 1) ∣ ∏ᶠ v : HeightOneSpectrum R, v.maxPowDividing I := by have hf := finite_mulSupport hI have h_ne_zero : v.maxPowDividing I ≠ 0 := pow_ne_zero _ v.ne_bot rw [← mul_finprod_cond_ne v hf, pow_add, pow_one, finprod_cond_ne _ _ hf] intro h_contr have hv_prime : Prime v.asIdeal := Ideal.prime_of_isPrime v.ne_bot v.isPrime obtain ⟨w, hw, hvw'⟩ := Prime.exists_mem_finset_dvd hv_prime ((mul_dvd_mul_iff_left h_ne_zero).mp h_contr) have hw_prime : Prime w.asIdeal := Ideal.prime_of_isPrime w.ne_bot w.isPrime have hvw := Prime.dvd_of_dvd_pow hv_prime hvw' rw [Prime.dvd_prime_iff_associated hv_prime hw_prime, associated_iff_eq] at hvw exact (Finset.mem_erase.mp hw).1 (HeightOneSpectrum.ext w v (Eq.symm hvw)) #align ideal.finprod_not_dvd Ideal.finprod_not_dvd end Ideal theorem Associates.finprod_ne_zero (I : Ideal R) : Associates.mk (∏ᶠ v : HeightOneSpectrum R, v.maxPowDividing I) ≠ 0 := by rw [Associates.mk_ne_zero, finprod_def] split_ifs · rw [Finset.prod_ne_zero_iff] intro v _ apply pow_ne_zero _ v.ne_bot · exact one_ne_zero #align associates.finprod_ne_zero Associates.finprod_ne_zero namespace Ideal /-- The multiplicity of `v` in `∏_v v^(val_v(I))` equals `val_v(I)`. -/ theorem finprod_count (I : Ideal R) (hI : I ≠ 0) : (Associates.mk v.asIdeal).count (Associates.mk (∏ᶠ v : HeightOneSpectrum R, v.maxPowDividing I)).factors = (Associates.mk v.asIdeal).count (Associates.mk I).factors := by have h_ne_zero := Associates.finprod_ne_zero I have hv : Irreducible (Associates.mk v.asIdeal) := v.associates_irreducible have h_dvd := finprod_mem_dvd v (Ideal.finite_mulSupport hI) have h_not_dvd := Ideal.finprod_not_dvd v I hI simp only [IsDedekindDomain.HeightOneSpectrum.maxPowDividing] at h_dvd h_ne_zero h_not_dvd rw [← Associates.mk_dvd_mk] at h_dvd h_not_dvd simp only [Associates.dvd_eq_le] at h_dvd h_not_dvd rw [Associates.mk_pow, Associates.prime_pow_dvd_iff_le h_ne_zero hv] at h_dvd h_not_dvd rw [not_le] at h_not_dvd apply Nat.eq_of_le_of_lt_succ h_dvd h_not_dvd #align ideal.finprod_count Ideal.finprod_count /-- The ideal `I` equals the finprod `∏_v v^(val_v(I))`. -/ theorem finprod_heightOneSpectrum_factorization {I : Ideal R} (hI : I ≠ 0) : ∏ᶠ v : HeightOneSpectrum R, v.maxPowDividing I = I := by rw [← associated_iff_eq, ← Associates.mk_eq_mk_iff_associated] apply Associates.eq_of_eq_counts · apply Associates.finprod_ne_zero I · apply Associates.mk_ne_zero.mpr hI intro v hv obtain ⟨J, hJv⟩ := Associates.exists_rep v rw [← hJv, Associates.irreducible_mk] at hv rw [← hJv] apply Ideal.finprod_count ⟨J, Ideal.isPrime_of_prime (irreducible_iff_prime.mp hv), Irreducible.ne_zero hv⟩ I hI #align ideal.finprod_height_one_spectrum_factorization Ideal.finprod_heightOneSpectrum_factorization variable (K) /-- The ideal `I` equals the finprod `∏_v v^(val_v(I))`, when both sides are regarded as fractional ideals of `R`. -/ theorem finprod_heightOneSpectrum_factorization_coe {I : Ideal R} (hI : I ≠ 0) : (∏ᶠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^ ((Associates.mk v.asIdeal).count (Associates.mk I).factors : ℤ)) = I := by conv_rhs => rw [← Ideal.finprod_heightOneSpectrum_factorization hI] rw [FractionalIdeal.coeIdeal_finprod R⁰ K (le_refl _)] simp_rw [IsDedekindDomain.HeightOneSpectrum.maxPowDividing, FractionalIdeal.coeIdeal_pow, zpow_natCast] #align ideal.finprod_height_one_spectrum_factorization_coe Ideal.finprod_heightOneSpectrum_factorization_coe end Ideal /-! ### Factorization of fractional ideals of Dedekind domains -/ namespace FractionalIdeal open Int IsLocalization /-- If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`, then `I` is equal to the product `∏_v v^(val_v(J) - val_v(a))`. -/ theorem finprod_heightOneSpectrum_factorization {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) {a : R} {J : Ideal R} (haJ : I = spanSingleton R⁰ ((algebraMap R K) a)⁻¹ * ↑J) : ∏ᶠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^ ((Associates.mk v.asIdeal).count (Associates.mk J).factors - (Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {a})).factors : ℤ) = I := by have hJ_ne_zero : J ≠ 0 := ideal_factor_ne_zero hI haJ have hJ := Ideal.finprod_heightOneSpectrum_factorization_coe K hJ_ne_zero have ha_ne_zero : Ideal.span {a} ≠ 0 := constant_factor_ne_zero hI haJ have ha := Ideal.finprod_heightOneSpectrum_factorization_coe K ha_ne_zero rw [haJ, ← div_spanSingleton, div_eq_mul_inv, ← coeIdeal_span_singleton, ← hJ, ← ha, ← finprod_inv_distrib] simp_rw [← zpow_neg] rw [← finprod_mul_distrib (Ideal.finite_mulSupport_coe hJ_ne_zero) (Ideal.finite_mulSupport_inv ha_ne_zero)] apply finprod_congr intro v rw [← zpow_add₀ ((@coeIdeal_ne_zero R _ K _ _ _ _).mpr v.ne_bot), sub_eq_add_neg] /-- For a nonzero `k = r/s ∈ K`, the fractional ideal `(k)` is equal to the product `∏_v v^(val_v(r) - val_v(s))`. -/ theorem finprod_heightOneSpectrum_factorization_principal_fraction {n : R} (hn : n ≠ 0) (d : ↥R⁰) : ∏ᶠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^ ((Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {n} : Ideal R)).factors - (Associates.mk v.asIdeal).count (Associates.mk ((Ideal.span {(↑d : R)}) : Ideal R)).factors : ℤ) = spanSingleton R⁰ (mk' K n d) := by have hd_ne_zero : (algebraMap R K) (d : R) ≠ 0 := map_ne_zero_of_mem_nonZeroDivisors _ (IsFractionRing.injective R K) d.property have h0 : spanSingleton R⁰ (mk' K n d) ≠ 0 := by rw [spanSingleton_ne_zero_iff, IsFractionRing.mk'_eq_div, ne_eq, div_eq_zero_iff, not_or] exact ⟨(map_ne_zero_iff (algebraMap R K) (IsFractionRing.injective R K)).mpr hn, hd_ne_zero⟩ have hI : spanSingleton R⁰ (mk' K n d) = spanSingleton R⁰ ((algebraMap R K) d)⁻¹ * ↑(Ideal.span {n} : Ideal R) := by rw [coeIdeal_span_singleton, spanSingleton_mul_spanSingleton] apply congr_arg rw [IsFractionRing.mk'_eq_div, div_eq_mul_inv, mul_comm] exact finprod_heightOneSpectrum_factorization h0 hI /-- For a nonzero `k = r/s ∈ K`, the fractional ideal `(k)` is equal to the product `∏_v v^(val_v(r) - val_v(s))`. -/ theorem finprod_heightOneSpectrum_factorization_principal {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) (k : K) (hk : I = spanSingleton R⁰ k) : ∏ᶠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^ ((Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {choose (mk'_surjective R⁰ k)} : Ideal R)).factors - (Associates.mk v.asIdeal).count (Associates.mk ((Ideal.span {(↑(choose (choose_spec (mk'_surjective R⁰ k)) : ↥R⁰) : R)}) : Ideal R)).factors : ℤ) = I := by set n : R := choose (mk'_surjective R⁰ k) set d : ↥R⁰ := choose (choose_spec (mk'_surjective R⁰ k)) have hnd : mk' K n d = k := choose_spec (choose_spec (mk'_surjective R⁰ k)) have hn0 : n ≠ 0 := by by_contra h rw [← hnd, h, IsFractionRing.mk'_eq_div, _root_.map_zero, zero_div, spanSingleton_zero] at hk exact hI hk rw [finprod_heightOneSpectrum_factorization_principal_fraction hn0 d, hk, hnd] variable (K) /-- If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`, then we define `val_v(I)` as `(val_v(J) - val_v(a))`. If `I = 0`, we set `val_v(I) = 0`. -/ def count (I : FractionalIdeal R⁰ K) : ℤ := dite (I = 0) (fun _ : I = 0 => 0) fun _ : ¬I = 0 => let a := choose (exists_eq_spanSingleton_mul I) let J := choose (choose_spec (exists_eq_spanSingleton_mul I)) ((Associates.mk v.asIdeal).count (Associates.mk J).factors - (Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {a})).factors : ℤ) /-- val_v(0) = 0. -/ lemma count_zero : count K v (0 : FractionalIdeal R⁰ K) = 0 := by simp only [count, dif_pos] lemma count_ne_zero {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) : count K v I = ((Associates.mk v.asIdeal).count (Associates.mk (choose (choose_spec (exists_eq_spanSingleton_mul I)))).factors - (Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {choose (exists_eq_spanSingleton_mul I)})).factors : ℤ) := by simp only [count, dif_neg hI] /-- `val_v(I)` does not depend on the choice of `a` and `J` used to represent `I`. -/
Mathlib/RingTheory/DedekindDomain/Factorization.lean
293
325
theorem count_well_defined {I : FractionalIdeal R⁰ K} (hI : I ≠ 0) {a : R} {J : Ideal R} (h_aJ : I = spanSingleton R⁰ ((algebraMap R K) a)⁻¹ * ↑J) : count K v I = ((Associates.mk v.asIdeal).count (Associates.mk J).factors - (Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {a})).factors : ℤ) := by
set a₁ := choose (exists_eq_spanSingleton_mul I) set J₁ := choose (choose_spec (exists_eq_spanSingleton_mul I)) have h_a₁J₁ : I = spanSingleton R⁰ ((algebraMap R K) a₁)⁻¹ * ↑J₁ := (choose_spec (choose_spec (exists_eq_spanSingleton_mul I))).2 have h_a₁_ne_zero : a₁ ≠ 0 := (choose_spec (choose_spec (exists_eq_spanSingleton_mul I))).1 have h_J₁_ne_zero : J₁ ≠ 0 := ideal_factor_ne_zero hI h_a₁J₁ have h_a_ne_zero : Ideal.span {a} ≠ 0 := constant_factor_ne_zero hI h_aJ have h_J_ne_zero : J ≠ 0 := ideal_factor_ne_zero hI h_aJ have h_a₁' : spanSingleton R⁰ ((algebraMap R K) a₁) ≠ 0 := by rw [ne_eq, spanSingleton_eq_zero_iff, ← (algebraMap R K).map_zero, Injective.eq_iff (IsLocalization.injective K (le_refl R⁰))] exact h_a₁_ne_zero have h_a' : spanSingleton R⁰ ((algebraMap R K) a) ≠ 0 := by rw [ne_eq, spanSingleton_eq_zero_iff, ← (algebraMap R K).map_zero, Injective.eq_iff (IsLocalization.injective K (le_refl R⁰))] rw [ne_eq, Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot] at h_a_ne_zero exact h_a_ne_zero have hv : Irreducible (Associates.mk v.asIdeal) := by exact Associates.irreducible_mk.mpr v.irreducible rw [h_a₁J₁, ← div_spanSingleton, ← div_spanSingleton, div_eq_div_iff h_a₁' h_a', ← coeIdeal_span_singleton, ← coeIdeal_span_singleton, ← coeIdeal_mul, ← coeIdeal_mul] at h_aJ rw [count, dif_neg hI, sub_eq_sub_iff_add_eq_add, ← ofNat_add, ← ofNat_add, natCast_inj, ← Associates.count_mul _ _ hv, ← Associates.count_mul _ _ hv, Associates.mk_mul_mk, Associates.mk_mul_mk, coeIdeal_injective h_aJ] · rw [ne_eq, Associates.mk_eq_zero]; exact h_J_ne_zero · rw [ne_eq, Associates.mk_eq_zero, Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot] exact h_a₁_ne_zero · rw [ne_eq, Associates.mk_eq_zero]; exact h_J₁_ne_zero · rw [ne_eq, Associates.mk_eq_zero]; exact h_a_ne_zero
/- Copyright (c) 2022 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Joël Riou -/ import Mathlib.CategoryTheory.CommSq import Mathlib.CategoryTheory.Limits.Opposites import Mathlib.CategoryTheory.Limits.Shapes.Biproducts import Mathlib.CategoryTheory.Limits.Shapes.ZeroMorphisms import Mathlib.CategoryTheory.Limits.Constructions.BinaryProducts import Mathlib.CategoryTheory.Limits.Constructions.ZeroObjects #align_import category_theory.limits.shapes.comm_sq from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a" /-! # Pullback and pushout squares, and bicartesian squares We provide another API for pullbacks and pushouts. `IsPullback fst snd f g` is the proposition that ``` P --fst--> X | | snd f | | v v Y ---g---> Z ``` is a pullback square. (And similarly for `IsPushout`.) We provide the glue to go back and forth to the usual `IsLimit` API for pullbacks, and prove `IsPullback (pullback.fst : pullback f g ⟶ X) (pullback.snd : pullback f g ⟶ Y) f g` for the usual `pullback f g` provided by the `HasLimit` API. We don't attempt to restate everything we know about pullbacks in this language, but do restate the pasting lemmas. We define bicartesian squares, and show that the pullback and pushout squares for a biproduct are bicartesian. -/ noncomputable section open CategoryTheory open CategoryTheory.Limits universe v₁ v₂ u₁ u₂ namespace CategoryTheory variable {C : Type u₁} [Category.{v₁} C] attribute [simp] CommSq.mk namespace CommSq variable {W X Y Z : C} {f : W ⟶ X} {g : W ⟶ Y} {h : X ⟶ Z} {i : Y ⟶ Z} /-- The (not necessarily limiting) `PullbackCone h i` implicit in the statement that we have `CommSq f g h i`. -/ def cone (s : CommSq f g h i) : PullbackCone h i := PullbackCone.mk _ _ s.w #align category_theory.comm_sq.cone CategoryTheory.CommSq.cone /-- The (not necessarily limiting) `PushoutCocone f g` implicit in the statement that we have `CommSq f g h i`. -/ def cocone (s : CommSq f g h i) : PushoutCocone f g := PushoutCocone.mk _ _ s.w #align category_theory.comm_sq.cocone CategoryTheory.CommSq.cocone @[simp] theorem cone_fst (s : CommSq f g h i) : s.cone.fst = f := rfl #align category_theory.comm_sq.cone_fst CategoryTheory.CommSq.cone_fst @[simp] theorem cone_snd (s : CommSq f g h i) : s.cone.snd = g := rfl #align category_theory.comm_sq.cone_snd CategoryTheory.CommSq.cone_snd @[simp] theorem cocone_inl (s : CommSq f g h i) : s.cocone.inl = h := rfl #align category_theory.comm_sq.cocone_inl CategoryTheory.CommSq.cocone_inl @[simp] theorem cocone_inr (s : CommSq f g h i) : s.cocone.inr = i := rfl #align category_theory.comm_sq.cocone_inr CategoryTheory.CommSq.cocone_inr /-- The pushout cocone in the opposite category associated to the cone of a commutative square identifies to the cocone of the flipped commutative square in the opposite category -/ def coneOp (p : CommSq f g h i) : p.cone.op ≅ p.flip.op.cocone := PushoutCocone.ext (Iso.refl _) (by aesop_cat) (by aesop_cat) #align category_theory.comm_sq.cone_op CategoryTheory.CommSq.coneOp /-- The pullback cone in the opposite category associated to the cocone of a commutative square identifies to the cone of the flipped commutative square in the opposite category -/ def coconeOp (p : CommSq f g h i) : p.cocone.op ≅ p.flip.op.cone := PullbackCone.ext (Iso.refl _) (by aesop_cat) (by aesop_cat) #align category_theory.comm_sq.cocone_op CategoryTheory.CommSq.coconeOp /-- The pushout cocone obtained from the pullback cone associated to a commutative square in the opposite category identifies to the cocone associated to the flipped square. -/ def coneUnop {W X Y Z : Cᵒᵖ} {f : W ⟶ X} {g : W ⟶ Y} {h : X ⟶ Z} {i : Y ⟶ Z} (p : CommSq f g h i) : p.cone.unop ≅ p.flip.unop.cocone := PushoutCocone.ext (Iso.refl _) (by aesop_cat) (by aesop_cat) #align category_theory.comm_sq.cone_unop CategoryTheory.CommSq.coneUnop /-- The pullback cone obtained from the pushout cone associated to a commutative square in the opposite category identifies to the cone associated to the flipped square. -/ def coconeUnop {W X Y Z : Cᵒᵖ} {f : W ⟶ X} {g : W ⟶ Y} {h : X ⟶ Z} {i : Y ⟶ Z} (p : CommSq f g h i) : p.cocone.unop ≅ p.flip.unop.cone := PullbackCone.ext (Iso.refl _) (by aesop_cat) (by aesop_cat) #align category_theory.comm_sq.cocone_unop CategoryTheory.CommSq.coconeUnop end CommSq /-- The proposition that a square ``` P --fst--> X | | snd f | | v v Y ---g---> Z ``` is a pullback square. (Also known as a fibered product or cartesian square.) -/ structure IsPullback {P X Y Z : C} (fst : P ⟶ X) (snd : P ⟶ Y) (f : X ⟶ Z) (g : Y ⟶ Z) extends CommSq fst snd f g : Prop where /-- the pullback cone is a limit -/ isLimit' : Nonempty (IsLimit (PullbackCone.mk _ _ w)) #align category_theory.is_pullback CategoryTheory.IsPullback /-- The proposition that a square ``` Z ---f---> X | | g inl | | v v Y --inr--> P ``` is a pushout square. (Also known as a fiber coproduct or cocartesian square.) -/ structure IsPushout {Z X Y P : C} (f : Z ⟶ X) (g : Z ⟶ Y) (inl : X ⟶ P) (inr : Y ⟶ P) extends CommSq f g inl inr : Prop where /-- the pushout cocone is a colimit -/ isColimit' : Nonempty (IsColimit (PushoutCocone.mk _ _ w)) #align category_theory.is_pushout CategoryTheory.IsPushout section /-- A *bicartesian* square is a commutative square ``` W ---f---> X | | g h | | v v Y ---i---> Z ``` that is both a pullback square and a pushout square. -/ structure BicartesianSq {W X Y Z : C} (f : W ⟶ X) (g : W ⟶ Y) (h : X ⟶ Z) (i : Y ⟶ Z) extends IsPullback f g h i, IsPushout f g h i : Prop #align category_theory.bicartesian_sq CategoryTheory.BicartesianSq -- Lean should make these parent projections as `lemma`, not `def`. attribute [nolint defLemma docBlame] BicartesianSq.toIsPullback BicartesianSq.toIsPushout end /-! We begin by providing some glue between `IsPullback` and the `IsLimit` and `HasLimit` APIs. (And similarly for `IsPushout`.) -/ namespace IsPullback variable {P X Y Z : C} {fst : P ⟶ X} {snd : P ⟶ Y} {f : X ⟶ Z} {g : Y ⟶ Z} /-- The (limiting) `PullbackCone f g` implicit in the statement that we have an `IsPullback fst snd f g`. -/ def cone (h : IsPullback fst snd f g) : PullbackCone f g := h.toCommSq.cone #align category_theory.is_pullback.cone CategoryTheory.IsPullback.cone @[simp] theorem cone_fst (h : IsPullback fst snd f g) : h.cone.fst = fst := rfl #align category_theory.is_pullback.cone_fst CategoryTheory.IsPullback.cone_fst @[simp] theorem cone_snd (h : IsPullback fst snd f g) : h.cone.snd = snd := rfl #align category_theory.is_pullback.cone_snd CategoryTheory.IsPullback.cone_snd /-- The cone obtained from `IsPullback fst snd f g` is a limit cone. -/ noncomputable def isLimit (h : IsPullback fst snd f g) : IsLimit h.cone := h.isLimit'.some #align category_theory.is_pullback.is_limit CategoryTheory.IsPullback.isLimit /-- If `c` is a limiting pullback cone, then we have an `IsPullback c.fst c.snd f g`. -/ theorem of_isLimit {c : PullbackCone f g} (h : Limits.IsLimit c) : IsPullback c.fst c.snd f g := { w := c.condition isLimit' := ⟨IsLimit.ofIsoLimit h (Limits.PullbackCone.ext (Iso.refl _) (by aesop_cat) (by aesop_cat))⟩ } #align category_theory.is_pullback.of_is_limit CategoryTheory.IsPullback.of_isLimit /-- A variant of `of_isLimit` that is more useful with `apply`. -/ theorem of_isLimit' (w : CommSq fst snd f g) (h : Limits.IsLimit w.cone) : IsPullback fst snd f g := of_isLimit h #align category_theory.is_pullback.of_is_limit' CategoryTheory.IsPullback.of_isLimit' /-- The pullback provided by `HasPullback f g` fits into an `IsPullback`. -/ theorem of_hasPullback (f : X ⟶ Z) (g : Y ⟶ Z) [HasPullback f g] : IsPullback (pullback.fst : pullback f g ⟶ X) (pullback.snd : pullback f g ⟶ Y) f g := of_isLimit (limit.isLimit (cospan f g)) #align category_theory.is_pullback.of_has_pullback CategoryTheory.IsPullback.of_hasPullback /-- If `c` is a limiting binary product cone, and we have a terminal object, then we have `IsPullback c.fst c.snd 0 0` (where each `0` is the unique morphism to the terminal object). -/ theorem of_is_product {c : BinaryFan X Y} (h : Limits.IsLimit c) (t : IsTerminal Z) : IsPullback c.fst c.snd (t.from _) (t.from _) := of_isLimit (isPullbackOfIsTerminalIsProduct _ _ _ _ t (IsLimit.ofIsoLimit h (Limits.Cones.ext (Iso.refl c.pt) (by rintro ⟨⟨⟩⟩ <;> · dsimp simp)))) #align category_theory.is_pullback.of_is_product CategoryTheory.IsPullback.of_is_product /-- A variant of `of_is_product` that is more useful with `apply`. -/ theorem of_is_product' (h : Limits.IsLimit (BinaryFan.mk fst snd)) (t : IsTerminal Z) : IsPullback fst snd (t.from _) (t.from _) := of_is_product h t #align category_theory.is_pullback.of_is_product' CategoryTheory.IsPullback.of_is_product' variable (X Y) theorem of_hasBinaryProduct' [HasBinaryProduct X Y] [HasTerminal C] : IsPullback Limits.prod.fst Limits.prod.snd (terminal.from X) (terminal.from Y) := of_is_product (limit.isLimit _) terminalIsTerminal #align category_theory.is_pullback.of_has_binary_product' CategoryTheory.IsPullback.of_hasBinaryProduct' open ZeroObject theorem of_hasBinaryProduct [HasBinaryProduct X Y] [HasZeroObject C] [HasZeroMorphisms C] : IsPullback Limits.prod.fst Limits.prod.snd (0 : X ⟶ 0) (0 : Y ⟶ 0) := by convert @of_is_product _ _ X Y 0 _ (limit.isLimit _) HasZeroObject.zeroIsTerminal <;> apply Subsingleton.elim #align category_theory.is_pullback.of_has_binary_product CategoryTheory.IsPullback.of_hasBinaryProduct variable {X Y} /-- Any object at the top left of a pullback square is isomorphic to the pullback provided by the `HasLimit` API. -/ noncomputable def isoPullback (h : IsPullback fst snd f g) [HasPullback f g] : P ≅ pullback f g := (limit.isoLimitCone ⟨_, h.isLimit⟩).symm #align category_theory.is_pullback.iso_pullback CategoryTheory.IsPullback.isoPullback @[simp] theorem isoPullback_hom_fst (h : IsPullback fst snd f g) [HasPullback f g] : h.isoPullback.hom ≫ pullback.fst = fst := by dsimp [isoPullback, cone, CommSq.cone] simp #align category_theory.is_pullback.iso_pullback_hom_fst CategoryTheory.IsPullback.isoPullback_hom_fst @[simp] theorem isoPullback_hom_snd (h : IsPullback fst snd f g) [HasPullback f g] : h.isoPullback.hom ≫ pullback.snd = snd := by dsimp [isoPullback, cone, CommSq.cone] simp #align category_theory.is_pullback.iso_pullback_hom_snd CategoryTheory.IsPullback.isoPullback_hom_snd @[simp] theorem isoPullback_inv_fst (h : IsPullback fst snd f g) [HasPullback f g] : h.isoPullback.inv ≫ fst = pullback.fst := by simp [Iso.inv_comp_eq] #align category_theory.is_pullback.iso_pullback_inv_fst CategoryTheory.IsPullback.isoPullback_inv_fst @[simp] theorem isoPullback_inv_snd (h : IsPullback fst snd f g) [HasPullback f g] : h.isoPullback.inv ≫ snd = pullback.snd := by simp [Iso.inv_comp_eq] #align category_theory.is_pullback.iso_pullback_inv_snd CategoryTheory.IsPullback.isoPullback_inv_snd theorem of_iso_pullback (h : CommSq fst snd f g) [HasPullback f g] (i : P ≅ pullback f g) (w₁ : i.hom ≫ pullback.fst = fst) (w₂ : i.hom ≫ pullback.snd = snd) : IsPullback fst snd f g := of_isLimit' h (Limits.IsLimit.ofIsoLimit (limit.isLimit _) (@PullbackCone.ext _ _ _ _ _ _ _ (PullbackCone.mk _ _ _) _ i w₁.symm w₂.symm).symm) #align category_theory.is_pullback.of_iso_pullback CategoryTheory.IsPullback.of_iso_pullback theorem of_horiz_isIso [IsIso fst] [IsIso g] (sq : CommSq fst snd f g) : IsPullback fst snd f g := of_isLimit' sq (by refine PullbackCone.IsLimit.mk _ (fun s => s.fst ≫ inv fst) (by aesop_cat) (fun s => ?_) (by aesop_cat) simp only [← cancel_mono g, Category.assoc, ← sq.w, IsIso.inv_hom_id_assoc, s.condition]) #align category_theory.is_pullback.of_horiz_is_iso CategoryTheory.IsPullback.of_horiz_isIso end IsPullback namespace IsPushout variable {Z X Y P : C} {f : Z ⟶ X} {g : Z ⟶ Y} {inl : X ⟶ P} {inr : Y ⟶ P} /-- The (colimiting) `PushoutCocone f g` implicit in the statement that we have an `IsPushout f g inl inr`. -/ def cocone (h : IsPushout f g inl inr) : PushoutCocone f g := h.toCommSq.cocone #align category_theory.is_pushout.cocone CategoryTheory.IsPushout.cocone @[simp] theorem cocone_inl (h : IsPushout f g inl inr) : h.cocone.inl = inl := rfl #align category_theory.is_pushout.cocone_inl CategoryTheory.IsPushout.cocone_inl @[simp] theorem cocone_inr (h : IsPushout f g inl inr) : h.cocone.inr = inr := rfl #align category_theory.is_pushout.cocone_inr CategoryTheory.IsPushout.cocone_inr /-- The cocone obtained from `IsPushout f g inl inr` is a colimit cocone. -/ noncomputable def isColimit (h : IsPushout f g inl inr) : IsColimit h.cocone := h.isColimit'.some #align category_theory.is_pushout.is_colimit CategoryTheory.IsPushout.isColimit /-- If `c` is a colimiting pushout cocone, then we have an `IsPushout f g c.inl c.inr`. -/ theorem of_isColimit {c : PushoutCocone f g} (h : Limits.IsColimit c) : IsPushout f g c.inl c.inr := { w := c.condition isColimit' := ⟨IsColimit.ofIsoColimit h (Limits.PushoutCocone.ext (Iso.refl _) (by aesop_cat) (by aesop_cat))⟩ } #align category_theory.is_pushout.of_is_colimit CategoryTheory.IsPushout.of_isColimit /-- A variant of `of_isColimit` that is more useful with `apply`. -/ theorem of_isColimit' (w : CommSq f g inl inr) (h : Limits.IsColimit w.cocone) : IsPushout f g inl inr := of_isColimit h #align category_theory.is_pushout.of_is_colimit' CategoryTheory.IsPushout.of_isColimit' /-- The pushout provided by `HasPushout f g` fits into an `IsPushout`. -/ theorem of_hasPushout (f : Z ⟶ X) (g : Z ⟶ Y) [HasPushout f g] : IsPushout f g (pushout.inl : X ⟶ pushout f g) (pushout.inr : Y ⟶ pushout f g) := of_isColimit (colimit.isColimit (span f g)) #align category_theory.is_pushout.of_has_pushout CategoryTheory.IsPushout.of_hasPushout /-- If `c` is a colimiting binary coproduct cocone, and we have an initial object, then we have `IsPushout 0 0 c.inl c.inr` (where each `0` is the unique morphism from the initial object). -/ theorem of_is_coproduct {c : BinaryCofan X Y} (h : Limits.IsColimit c) (t : IsInitial Z) : IsPushout (t.to _) (t.to _) c.inl c.inr := of_isColimit (isPushoutOfIsInitialIsCoproduct _ _ _ _ t (IsColimit.ofIsoColimit h (Limits.Cocones.ext (Iso.refl c.pt) (by rintro ⟨⟨⟩⟩ <;> · dsimp simp)))) #align category_theory.is_pushout.of_is_coproduct CategoryTheory.IsPushout.of_is_coproduct /-- A variant of `of_is_coproduct` that is more useful with `apply`. -/ theorem of_is_coproduct' (h : Limits.IsColimit (BinaryCofan.mk inl inr)) (t : IsInitial Z) : IsPushout (t.to _) (t.to _) inl inr := of_is_coproduct h t #align category_theory.is_pushout.of_is_coproduct' CategoryTheory.IsPushout.of_is_coproduct' variable (X Y) theorem of_hasBinaryCoproduct' [HasBinaryCoproduct X Y] [HasInitial C] : IsPushout (initial.to _) (initial.to _) (coprod.inl : X ⟶ _) (coprod.inr : Y ⟶ _) := of_is_coproduct (colimit.isColimit _) initialIsInitial #align category_theory.is_pushout.of_has_binary_coproduct' CategoryTheory.IsPushout.of_hasBinaryCoproduct' open ZeroObject theorem of_hasBinaryCoproduct [HasBinaryCoproduct X Y] [HasZeroObject C] [HasZeroMorphisms C] : IsPushout (0 : 0 ⟶ X) (0 : 0 ⟶ Y) coprod.inl coprod.inr := by convert @of_is_coproduct _ _ 0 X Y _ (colimit.isColimit _) HasZeroObject.zeroIsInitial <;> apply Subsingleton.elim #align category_theory.is_pushout.of_has_binary_coproduct CategoryTheory.IsPushout.of_hasBinaryCoproduct variable {X Y} /-- Any object at the top left of a pullback square is isomorphic to the pullback provided by the `HasLimit` API. -/ noncomputable def isoPushout (h : IsPushout f g inl inr) [HasPushout f g] : P ≅ pushout f g := (colimit.isoColimitCocone ⟨_, h.isColimit⟩).symm #align category_theory.is_pushout.iso_pushout CategoryTheory.IsPushout.isoPushout @[simp] theorem inl_isoPushout_inv (h : IsPushout f g inl inr) [HasPushout f g] : pushout.inl ≫ h.isoPushout.inv = inl := by dsimp [isoPushout, cocone, CommSq.cocone] simp #align category_theory.is_pushout.inl_iso_pushout_inv CategoryTheory.IsPushout.inl_isoPushout_inv @[simp] theorem inr_isoPushout_inv (h : IsPushout f g inl inr) [HasPushout f g] : pushout.inr ≫ h.isoPushout.inv = inr := by dsimp [isoPushout, cocone, CommSq.cocone] simp #align category_theory.is_pushout.inr_iso_pushout_inv CategoryTheory.IsPushout.inr_isoPushout_inv @[simp] theorem inl_isoPushout_hom (h : IsPushout f g inl inr) [HasPushout f g] : inl ≫ h.isoPushout.hom = pushout.inl := by simp [← Iso.eq_comp_inv] #align category_theory.is_pushout.inl_iso_pushout_hom CategoryTheory.IsPushout.inl_isoPushout_hom @[simp] theorem inr_isoPushout_hom (h : IsPushout f g inl inr) [HasPushout f g] : inr ≫ h.isoPushout.hom = pushout.inr := by simp [← Iso.eq_comp_inv] #align category_theory.is_pushout.inr_iso_pushout_hom CategoryTheory.IsPushout.inr_isoPushout_hom theorem of_iso_pushout (h : CommSq f g inl inr) [HasPushout f g] (i : P ≅ pushout f g) (w₁ : inl ≫ i.hom = pushout.inl) (w₂ : inr ≫ i.hom = pushout.inr) : IsPushout f g inl inr := of_isColimit' h (Limits.IsColimit.ofIsoColimit (colimit.isColimit _) (PushoutCocone.ext (s := PushoutCocone.mk ..) i w₁ w₂).symm) #align category_theory.is_pushout.of_iso_pushout CategoryTheory.IsPushout.of_iso_pushout end IsPushout namespace IsPullback variable {P X Y Z : C} {fst : P ⟶ X} {snd : P ⟶ Y} {f : X ⟶ Z} {g : Y ⟶ Z} theorem flip (h : IsPullback fst snd f g) : IsPullback snd fst g f := of_isLimit (PullbackCone.flipIsLimit h.isLimit) #align category_theory.is_pullback.flip CategoryTheory.IsPullback.flip theorem flip_iff : IsPullback fst snd f g ↔ IsPullback snd fst g f := ⟨flip, flip⟩ #align category_theory.is_pullback.flip_iff CategoryTheory.IsPullback.flip_iff section variable [HasZeroObject C] [HasZeroMorphisms C] open ZeroObject /-- The square with `0 : 0 ⟶ 0` on the left and `𝟙 X` on the right is a pullback square. -/ @[simp] theorem zero_left (X : C) : IsPullback (0 : 0 ⟶ X) (0 : (0 : C) ⟶ 0) (𝟙 X) (0 : 0 ⟶ X) := { w := by simp isLimit' := ⟨{ lift := fun s => 0 fac := fun s => by simpa [eq_iff_true_of_subsingleton] using @PullbackCone.equalizer_ext _ _ _ _ _ _ _ s _ 0 (𝟙 _) (by simpa using (PullbackCone.condition s).symm) }⟩ } #align category_theory.is_pullback.zero_left CategoryTheory.IsPullback.zero_left /-- The square with `0 : 0 ⟶ 0` on the top and `𝟙 X` on the bottom is a pullback square. -/ @[simp] theorem zero_top (X : C) : IsPullback (0 : (0 : C) ⟶ 0) (0 : 0 ⟶ X) (0 : 0 ⟶ X) (𝟙 X) := (zero_left X).flip #align category_theory.is_pullback.zero_top CategoryTheory.IsPullback.zero_top /-- The square with `0 : 0 ⟶ 0` on the right and `𝟙 X` on the left is a pullback square. -/ @[simp] theorem zero_right (X : C) : IsPullback (0 : X ⟶ 0) (𝟙 X) (0 : (0 : C) ⟶ 0) (0 : X ⟶ 0) := of_iso_pullback (by simp) ((zeroProdIso X).symm ≪≫ (pullbackZeroZeroIso _ _).symm) (by simp [eq_iff_true_of_subsingleton]) (by simp) #align category_theory.is_pullback.zero_right CategoryTheory.IsPullback.zero_right /-- The square with `0 : 0 ⟶ 0` on the bottom and `𝟙 X` on the top is a pullback square. -/ @[simp] theorem zero_bot (X : C) : IsPullback (𝟙 X) (0 : X ⟶ 0) (0 : X ⟶ 0) (0 : (0 : C) ⟶ 0) := (zero_right X).flip #align category_theory.is_pullback.zero_bot CategoryTheory.IsPullback.zero_bot end -- Objects here are arranged in a 3x2 grid, and indexed by their xy coordinates. -- Morphisms are named `hᵢⱼ` for a horizontal morphism starting at `(i,j)`, -- and `vᵢⱼ` for a vertical morphism starting at `(i,j)`. /-- Paste two pullback squares "vertically" to obtain another pullback square. -/ theorem paste_vert {X₁₁ X₁₂ X₂₁ X₂₂ X₃₁ X₃₂ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₂₁ : X₂₁ ⟶ X₂₂} {h₃₁ : X₃₁ ⟶ X₃₂} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₂₁ : X₂₁ ⟶ X₃₁} {v₂₂ : X₂₂ ⟶ X₃₂} (s : IsPullback h₁₁ v₁₁ v₁₂ h₂₁) (t : IsPullback h₂₁ v₂₁ v₂₂ h₃₁) : IsPullback h₁₁ (v₁₁ ≫ v₂₁) (v₁₂ ≫ v₂₂) h₃₁ := of_isLimit (bigSquareIsPullback _ _ _ _ _ _ _ s.w t.w t.isLimit s.isLimit) #align category_theory.is_pullback.paste_vert CategoryTheory.IsPullback.paste_vert /-- Paste two pullback squares "horizontally" to obtain another pullback square. -/ theorem paste_horiz {X₁₁ X₁₂ X₁₃ X₂₁ X₂₂ X₂₃ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₁₂ : X₁₂ ⟶ X₁₃} {h₂₁ : X₂₁ ⟶ X₂₂} {h₂₂ : X₂₂ ⟶ X₂₃} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₁₃ : X₁₃ ⟶ X₂₃} (s : IsPullback h₁₁ v₁₁ v₁₂ h₂₁) (t : IsPullback h₁₂ v₁₂ v₁₃ h₂₂) : IsPullback (h₁₁ ≫ h₁₂) v₁₁ v₁₃ (h₂₁ ≫ h₂₂) := (paste_vert s.flip t.flip).flip #align category_theory.is_pullback.paste_horiz CategoryTheory.IsPullback.paste_horiz /-- Given a pullback square assembled from a commuting square on the top and a pullback square on the bottom, the top square is a pullback square. -/ theorem of_bot {X₁₁ X₁₂ X₂₁ X₂₂ X₃₁ X₃₂ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₂₁ : X₂₁ ⟶ X₂₂} {h₃₁ : X₃₁ ⟶ X₃₂} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₂₁ : X₂₁ ⟶ X₃₁} {v₂₂ : X₂₂ ⟶ X₃₂} (s : IsPullback h₁₁ (v₁₁ ≫ v₂₁) (v₁₂ ≫ v₂₂) h₃₁) (p : h₁₁ ≫ v₁₂ = v₁₁ ≫ h₂₁) (t : IsPullback h₂₁ v₂₁ v₂₂ h₃₁) : IsPullback h₁₁ v₁₁ v₁₂ h₂₁ := of_isLimit (leftSquareIsPullback _ _ _ _ _ _ _ p t.w t.isLimit s.isLimit) #align category_theory.is_pullback.of_bot CategoryTheory.IsPullback.of_bot /-- Given a pullback square assembled from a commuting square on the left and a pullback square on the right, the left square is a pullback square. -/ theorem of_right {X₁₁ X₁₂ X₁₃ X₂₁ X₂₂ X₂₃ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₁₂ : X₁₂ ⟶ X₁₃} {h₂₁ : X₂₁ ⟶ X₂₂} {h₂₂ : X₂₂ ⟶ X₂₃} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₁₃ : X₁₃ ⟶ X₂₃} (s : IsPullback (h₁₁ ≫ h₁₂) v₁₁ v₁₃ (h₂₁ ≫ h₂₂)) (p : h₁₁ ≫ v₁₂ = v₁₁ ≫ h₂₁) (t : IsPullback h₁₂ v₁₂ v₁₃ h₂₂) : IsPullback h₁₁ v₁₁ v₁₂ h₂₁ := (of_bot s.flip p.symm t.flip).flip #align category_theory.is_pullback.of_right CategoryTheory.IsPullback.of_right theorem paste_vert_iff {X₁₁ X₁₂ X₂₁ X₂₂ X₃₁ X₃₂ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₂₁ : X₂₁ ⟶ X₂₂} {h₃₁ : X₃₁ ⟶ X₃₂} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₂₁ : X₂₁ ⟶ X₃₁} {v₂₂ : X₂₂ ⟶ X₃₂} (s : IsPullback h₂₁ v₂₁ v₂₂ h₃₁) (e : h₁₁ ≫ v₁₂ = v₁₁ ≫ h₂₁) : IsPullback h₁₁ (v₁₁ ≫ v₂₁) (v₁₂ ≫ v₂₂) h₃₁ ↔ IsPullback h₁₁ v₁₁ v₁₂ h₂₁ := ⟨fun h => h.of_bot e s, fun h => h.paste_vert s⟩ #align category_theory.is_pullback.paste_vert_iff CategoryTheory.IsPullback.paste_vert_iff theorem paste_horiz_iff {X₁₁ X₁₂ X₁₃ X₂₁ X₂₂ X₂₃ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₁₂ : X₁₂ ⟶ X₁₃} {h₂₁ : X₂₁ ⟶ X₂₂} {h₂₂ : X₂₂ ⟶ X₂₃} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₁₃ : X₁₃ ⟶ X₂₃} (s : IsPullback h₁₂ v₁₂ v₁₃ h₂₂) (e : h₁₁ ≫ v₁₂ = v₁₁ ≫ h₂₁) : IsPullback (h₁₁ ≫ h₁₂) v₁₁ v₁₃ (h₂₁ ≫ h₂₂) ↔ IsPullback h₁₁ v₁₁ v₁₂ h₂₁ := ⟨fun h => h.of_right e s, fun h => h.paste_horiz s⟩ #align category_theory.is_pullback.paste_horiz_iff CategoryTheory.IsPullback.paste_horiz_iff section variable [HasZeroObject C] [HasZeroMorphisms C] open ZeroObject theorem of_isBilimit {b : BinaryBicone X Y} (h : b.IsBilimit) : IsPullback b.fst b.snd (0 : X ⟶ 0) (0 : Y ⟶ 0) := by convert IsPullback.of_is_product' h.isLimit HasZeroObject.zeroIsTerminal <;> apply Subsingleton.elim #align category_theory.is_pullback.of_is_bilimit CategoryTheory.IsPullback.of_isBilimit @[simp] theorem of_has_biproduct (X Y : C) [HasBinaryBiproduct X Y] : IsPullback biprod.fst biprod.snd (0 : X ⟶ 0) (0 : Y ⟶ 0) := of_isBilimit (BinaryBiproduct.isBilimit X Y) #align category_theory.is_pullback.of_has_biproduct CategoryTheory.IsPullback.of_has_biproduct theorem inl_snd' {b : BinaryBicone X Y} (h : b.IsBilimit) : IsPullback b.inl (0 : X ⟶ 0) b.snd (0 : 0 ⟶ Y) := by refine of_right ?_ (by simp) (of_isBilimit h) simp #align category_theory.is_pullback.inl_snd' CategoryTheory.IsPullback.inl_snd' /-- The square ``` X --inl--> X ⊞ Y | | 0 snd | | v v 0 ---0-----> Y ``` is a pullback square. -/ @[simp] theorem inl_snd (X Y : C) [HasBinaryBiproduct X Y] : IsPullback biprod.inl (0 : X ⟶ 0) biprod.snd (0 : 0 ⟶ Y) := inl_snd' (BinaryBiproduct.isBilimit X Y) #align category_theory.is_pullback.inl_snd CategoryTheory.IsPullback.inl_snd theorem inr_fst' {b : BinaryBicone X Y} (h : b.IsBilimit) : IsPullback b.inr (0 : Y ⟶ 0) b.fst (0 : 0 ⟶ X) := by apply flip refine of_bot ?_ (by simp) (of_isBilimit h) simp #align category_theory.is_pullback.inr_fst' CategoryTheory.IsPullback.inr_fst' /-- The square ``` Y --inr--> X ⊞ Y | | 0 fst | | v v 0 ---0-----> X ``` is a pullback square. -/ @[simp] theorem inr_fst (X Y : C) [HasBinaryBiproduct X Y] : IsPullback biprod.inr (0 : Y ⟶ 0) biprod.fst (0 : 0 ⟶ X) := inr_fst' (BinaryBiproduct.isBilimit X Y) #align category_theory.is_pullback.inr_fst CategoryTheory.IsPullback.inr_fst theorem of_is_bilimit' {b : BinaryBicone X Y} (h : b.IsBilimit) : IsPullback (0 : 0 ⟶ X) (0 : 0 ⟶ Y) b.inl b.inr := by refine IsPullback.of_right ?_ (by simp) (IsPullback.inl_snd' h).flip simp #align category_theory.is_pullback.of_is_bilimit' CategoryTheory.IsPullback.of_is_bilimit' theorem of_hasBinaryBiproduct (X Y : C) [HasBinaryBiproduct X Y] : IsPullback (0 : 0 ⟶ X) (0 : 0 ⟶ Y) biprod.inl biprod.inr := of_is_bilimit' (BinaryBiproduct.isBilimit X Y) #align category_theory.is_pullback.of_has_binary_biproduct CategoryTheory.IsPullback.of_hasBinaryBiproduct instance hasPullback_biprod_fst_biprod_snd [HasBinaryBiproduct X Y] : HasPullback (biprod.inl : X ⟶ _) (biprod.inr : Y ⟶ _) := HasLimit.mk ⟨_, (of_hasBinaryBiproduct X Y).isLimit⟩ #align category_theory.is_pullback.has_pullback_biprod_fst_biprod_snd CategoryTheory.IsPullback.hasPullback_biprod_fst_biprod_snd /-- The pullback of `biprod.inl` and `biprod.inr` is the zero object. -/ def pullbackBiprodInlBiprodInr [HasBinaryBiproduct X Y] : pullback (biprod.inl : X ⟶ _) (biprod.inr : Y ⟶ _) ≅ 0 := limit.isoLimitCone ⟨_, (of_hasBinaryBiproduct X Y).isLimit⟩ #align category_theory.is_pullback.pullback_biprod_inl_biprod_inr CategoryTheory.IsPullback.pullbackBiprodInlBiprodInr end theorem op (h : IsPullback fst snd f g) : IsPushout g.op f.op snd.op fst.op := IsPushout.of_isColimit (IsColimit.ofIsoColimit (Limits.PullbackCone.isLimitEquivIsColimitOp h.flip.cone h.flip.isLimit) h.toCommSq.flip.coneOp) #align category_theory.is_pullback.op CategoryTheory.IsPullback.op theorem unop {P X Y Z : Cᵒᵖ} {fst : P ⟶ X} {snd : P ⟶ Y} {f : X ⟶ Z} {g : Y ⟶ Z} (h : IsPullback fst snd f g) : IsPushout g.unop f.unop snd.unop fst.unop := IsPushout.of_isColimit (IsColimit.ofIsoColimit (Limits.PullbackCone.isLimitEquivIsColimitUnop h.flip.cone h.flip.isLimit) h.toCommSq.flip.coneUnop) #align category_theory.is_pullback.unop CategoryTheory.IsPullback.unop theorem of_vert_isIso [IsIso snd] [IsIso f] (sq : CommSq fst snd f g) : IsPullback fst snd f g := IsPullback.flip (of_horiz_isIso sq.flip) #align category_theory.is_pullback.of_vert_is_iso CategoryTheory.IsPullback.of_vert_isIso end IsPullback namespace IsPushout variable {Z X Y P : C} {f : Z ⟶ X} {g : Z ⟶ Y} {inl : X ⟶ P} {inr : Y ⟶ P} theorem flip (h : IsPushout f g inl inr) : IsPushout g f inr inl := of_isColimit (PushoutCocone.flipIsColimit h.isColimit) #align category_theory.is_pushout.flip CategoryTheory.IsPushout.flip theorem flip_iff : IsPushout f g inl inr ↔ IsPushout g f inr inl := ⟨flip, flip⟩ #align category_theory.is_pushout.flip_iff CategoryTheory.IsPushout.flip_iff section variable [HasZeroObject C] [HasZeroMorphisms C] open ZeroObject /-- The square with `0 : 0 ⟶ 0` on the right and `𝟙 X` on the left is a pushout square. -/ @[simp] theorem zero_right (X : C) : IsPushout (0 : X ⟶ 0) (𝟙 X) (0 : (0 : C) ⟶ 0) (0 : X ⟶ 0) := { w := by simp isColimit' := ⟨{ desc := fun s => 0 fac := fun s => by have c := @PushoutCocone.coequalizer_ext _ _ _ _ _ _ _ s _ 0 (𝟙 _) (by simp [eq_iff_true_of_subsingleton]) (by simpa using PushoutCocone.condition s) dsimp at c simpa using c }⟩ } #align category_theory.is_pushout.zero_right CategoryTheory.IsPushout.zero_right /-- The square with `0 : 0 ⟶ 0` on the bottom and `𝟙 X` on the top is a pushout square. -/ @[simp] theorem zero_bot (X : C) : IsPushout (𝟙 X) (0 : X ⟶ 0) (0 : X ⟶ 0) (0 : (0 : C) ⟶ 0) := (zero_right X).flip #align category_theory.is_pushout.zero_bot CategoryTheory.IsPushout.zero_bot /-- The square with `0 : 0 ⟶ 0` on the right left `𝟙 X` on the right is a pushout square. -/ @[simp] theorem zero_left (X : C) : IsPushout (0 : 0 ⟶ X) (0 : (0 : C) ⟶ 0) (𝟙 X) (0 : 0 ⟶ X) := of_iso_pushout (by simp) ((coprodZeroIso X).symm ≪≫ (pushoutZeroZeroIso _ _).symm) (by simp) (by simp [eq_iff_true_of_subsingleton]) #align category_theory.is_pushout.zero_left CategoryTheory.IsPushout.zero_left /-- The square with `0 : 0 ⟶ 0` on the top and `𝟙 X` on the bottom is a pushout square. -/ @[simp] theorem zero_top (X : C) : IsPushout (0 : (0 : C) ⟶ 0) (0 : 0 ⟶ X) (0 : 0 ⟶ X) (𝟙 X) := (zero_left X).flip #align category_theory.is_pushout.zero_top CategoryTheory.IsPushout.zero_top end -- Objects here are arranged in a 3x2 grid, and indexed by their xy coordinates. -- Morphisms are named `hᵢⱼ` for a horizontal morphism starting at `(i,j)`, -- and `vᵢⱼ` for a vertical morphism starting at `(i,j)`. /-- Paste two pushout squares "vertically" to obtain another pushout square. -/ theorem paste_vert {X₁₁ X₁₂ X₂₁ X₂₂ X₃₁ X₃₂ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₂₁ : X₂₁ ⟶ X₂₂} {h₃₁ : X₃₁ ⟶ X₃₂} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₂₁ : X₂₁ ⟶ X₃₁} {v₂₂ : X₂₂ ⟶ X₃₂} (s : IsPushout h₁₁ v₁₁ v₁₂ h₂₁) (t : IsPushout h₂₁ v₂₁ v₂₂ h₃₁) : IsPushout h₁₁ (v₁₁ ≫ v₂₁) (v₁₂ ≫ v₂₂) h₃₁ := of_isColimit (bigSquareIsPushout _ _ _ _ _ _ _ s.w t.w t.isColimit s.isColimit) #align category_theory.is_pushout.paste_vert CategoryTheory.IsPushout.paste_vert /-- Paste two pushout squares "horizontally" to obtain another pushout square. -/ theorem paste_horiz {X₁₁ X₁₂ X₁₃ X₂₁ X₂₂ X₂₃ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₁₂ : X₁₂ ⟶ X₁₃} {h₂₁ : X₂₁ ⟶ X₂₂} {h₂₂ : X₂₂ ⟶ X₂₃} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₁₃ : X₁₃ ⟶ X₂₃} (s : IsPushout h₁₁ v₁₁ v₁₂ h₂₁) (t : IsPushout h₁₂ v₁₂ v₁₃ h₂₂) : IsPushout (h₁₁ ≫ h₁₂) v₁₁ v₁₃ (h₂₁ ≫ h₂₂) := (paste_vert s.flip t.flip).flip #align category_theory.is_pushout.paste_horiz CategoryTheory.IsPushout.paste_horiz /-- Given a pushout square assembled from a pushout square on the top and a commuting square on the bottom, the bottom square is a pushout square. -/ theorem of_bot {X₁₁ X₁₂ X₂₁ X₂₂ X₃₁ X₃₂ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₂₁ : X₂₁ ⟶ X₂₂} {h₃₁ : X₃₁ ⟶ X₃₂} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₂₁ : X₂₁ ⟶ X₃₁} {v₂₂ : X₂₂ ⟶ X₃₂} (s : IsPushout h₁₁ (v₁₁ ≫ v₂₁) (v₁₂ ≫ v₂₂) h₃₁) (p : h₂₁ ≫ v₂₂ = v₂₁ ≫ h₃₁) (t : IsPushout h₁₁ v₁₁ v₁₂ h₂₁) : IsPushout h₂₁ v₂₁ v₂₂ h₃₁ := of_isColimit (rightSquareIsPushout _ _ _ _ _ _ _ t.w p t.isColimit s.isColimit) #align category_theory.is_pushout.of_bot CategoryTheory.IsPushout.of_bot /-- Given a pushout square assembled from a pushout square on the left and a commuting square on the right, the right square is a pushout square. -/ theorem of_right {X₁₁ X₁₂ X₁₃ X₂₁ X₂₂ X₂₃ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₁₂ : X₁₂ ⟶ X₁₃} {h₂₁ : X₂₁ ⟶ X₂₂} {h₂₂ : X₂₂ ⟶ X₂₃} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₁₃ : X₁₃ ⟶ X₂₃} (s : IsPushout (h₁₁ ≫ h₁₂) v₁₁ v₁₃ (h₂₁ ≫ h₂₂)) (p : h₁₂ ≫ v₁₃ = v₁₂ ≫ h₂₂) (t : IsPushout h₁₁ v₁₁ v₁₂ h₂₁) : IsPushout h₁₂ v₁₂ v₁₃ h₂₂ := (of_bot s.flip p.symm t.flip).flip #align category_theory.is_pushout.of_right CategoryTheory.IsPushout.of_right theorem paste_vert_iff {X₁₁ X₁₂ X₂₁ X₂₂ X₃₁ X₃₂ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₂₁ : X₂₁ ⟶ X₂₂} {h₃₁ : X₃₁ ⟶ X₃₂} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₂₁ : X₂₁ ⟶ X₃₁} {v₂₂ : X₂₂ ⟶ X₃₂} (s : IsPushout h₁₁ v₁₁ v₁₂ h₂₁) (e : h₂₁ ≫ v₂₂ = v₂₁ ≫ h₃₁) : IsPushout h₁₁ (v₁₁ ≫ v₂₁) (v₁₂ ≫ v₂₂) h₃₁ ↔ IsPushout h₂₁ v₂₁ v₂₂ h₃₁ := ⟨fun h => h.of_bot e s, s.paste_vert⟩ #align category_theory.is_pushout.paste_vert_iff CategoryTheory.IsPushout.paste_vert_iff theorem paste_horiz_iff {X₁₁ X₁₂ X₁₃ X₂₁ X₂₂ X₂₃ : C} {h₁₁ : X₁₁ ⟶ X₁₂} {h₁₂ : X₁₂ ⟶ X₁₃} {h₂₁ : X₂₁ ⟶ X₂₂} {h₂₂ : X₂₂ ⟶ X₂₃} {v₁₁ : X₁₁ ⟶ X₂₁} {v₁₂ : X₁₂ ⟶ X₂₂} {v₁₃ : X₁₃ ⟶ X₂₃} (s : IsPushout h₁₁ v₁₁ v₁₂ h₂₁) (e : h₁₂ ≫ v₁₃ = v₁₂ ≫ h₂₂) : IsPushout (h₁₁ ≫ h₁₂) v₁₁ v₁₃ (h₂₁ ≫ h₂₂) ↔ IsPushout h₁₂ v₁₂ v₁₃ h₂₂ := ⟨fun h => h.of_right e s, s.paste_horiz⟩ #align category_theory.is_pushout.paste_horiz_iff CategoryTheory.IsPushout.paste_horiz_iff section variable [HasZeroObject C] [HasZeroMorphisms C] open ZeroObject
Mathlib/CategoryTheory/Limits/Shapes/CommSq.lean
772
775
theorem of_isBilimit {b : BinaryBicone X Y} (h : b.IsBilimit) : IsPushout (0 : 0 ⟶ X) (0 : 0 ⟶ Y) b.inl b.inr := by
convert IsPushout.of_is_coproduct' h.isColimit HasZeroObject.zeroIsInitial <;> apply Subsingleton.elim
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov Some proofs and docs came from `algebra/commute` (c) Neil Strickland -/ import Mathlib.Algebra.Group.Defs import Mathlib.Init.Logic import Mathlib.Tactic.Cases #align_import algebra.group.semiconj from "leanprover-community/mathlib"@"a148d797a1094ab554ad4183a4ad6f130358ef64" /-! # Semiconjugate elements of a semigroup ## Main definitions We say that `x` is semiconjugate to `y` by `a` (`SemiconjBy a x y`), if `a * x = y * a`. In this file we provide operations on `SemiconjBy _ _ _`. In the names of these operations, we treat `a` as the “left” argument, and both `x` and `y` as “right” arguments. This way most names in this file agree with the names of the corresponding lemmas for `Commute a b = SemiconjBy a b b`. As a side effect, some lemmas have only `_right` version. Lean does not immediately recognise these terms as equations, so for rewriting we need syntax like `rw [(h.pow_right 5).eq]` rather than just `rw [h.pow_right 5]`. This file provides only basic operations (`mul_left`, `mul_right`, `inv_right` etc). Other operations (`pow_right`, field inverse etc) are in the files that define corresponding notions. -/ assert_not_exists MonoidWithZero assert_not_exists DenselyOrdered variable {S M G : Type*} /-- `x` is semiconjugate to `y` by `a`, if `a * x = y * a`. -/ @[to_additive "`x` is additive semiconjugate to `y` by `a` if `a + x = y + a`"] def SemiconjBy [Mul M] (a x y : M) : Prop := a * x = y * a #align semiconj_by SemiconjBy #align add_semiconj_by AddSemiconjBy namespace SemiconjBy /-- Equality behind `SemiconjBy a x y`; useful for rewriting. -/ @[to_additive "Equality behind `AddSemiconjBy a x y`; useful for rewriting."] protected theorem eq [Mul S] {a x y : S} (h : SemiconjBy a x y) : a * x = y * a := h #align semiconj_by.eq SemiconjBy.eq #align add_semiconj_by.eq AddSemiconjBy.eq section Semigroup variable [Semigroup S] {a b x y z x' y' : S} /-- If `a` semiconjugates `x` to `y` and `x'` to `y'`, then it semiconjugates `x * x'` to `y * y'`. -/ @[to_additive (attr := simp) "If `a` semiconjugates `x` to `y` and `x'` to `y'`, then it semiconjugates `x + x'` to `y + y'`."] theorem mul_right (h : SemiconjBy a x y) (h' : SemiconjBy a x' y') : SemiconjBy a (x * x') (y * y') := by unfold SemiconjBy -- TODO this could be done using `assoc_rw` if/when this is ported to mathlib4 rw [← mul_assoc, h.eq, mul_assoc, h'.eq, ← mul_assoc] #align semiconj_by.mul_right SemiconjBy.mul_right #align add_semiconj_by.add_right AddSemiconjBy.add_right /-- If `b` semiconjugates `x` to `y` and `a` semiconjugates `y` to `z`, then `a * b` semiconjugates `x` to `z`. -/ @[to_additive "If `b` semiconjugates `x` to `y` and `a` semiconjugates `y` to `z`, then `a + b` semiconjugates `x` to `z`."]
Mathlib/Algebra/Group/Semiconj/Defs.lean
74
76
theorem mul_left (ha : SemiconjBy a y z) (hb : SemiconjBy b x y) : SemiconjBy (a * b) x z := by
unfold SemiconjBy rw [mul_assoc, hb.eq, ← mul_assoc, ha.eq, mul_assoc]
/- Copyright (c) 2022 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov, Yaël Dillies -/ import Mathlib.MeasureTheory.Integral.SetIntegral #align_import measure_theory.integral.average from "leanprover-community/mathlib"@"c14c8fcde993801fca8946b0d80131a1a81d1520" /-! # Integral average of a function In this file we define `MeasureTheory.average μ f` (notation: `⨍ x, f x ∂μ`) to be the average value of `f` with respect to measure `μ`. It is defined as `∫ x, f x ∂((μ univ)⁻¹ • μ)`, so it is equal to zero if `f` is not integrable or if `μ` is an infinite measure. If `μ` is a probability measure, then the average of any function is equal to its integral. For the average on a set, we use `⨍ x in s, f x ∂μ` (notation for `⨍ x, f x ∂(μ.restrict s)`). For average w.r.t. the volume, one can omit `∂volume`. Both have a version for the Lebesgue integral rather than Bochner. We prove several version of the first moment method: An integrable function is below/above its average on a set of positive measure. ## Implementation notes The average is defined as an integral over `(μ univ)⁻¹ • μ` so that all theorems about Bochner integrals work for the average without modifications. For theorems that require integrability of a function, we provide a convenience lemma `MeasureTheory.Integrable.to_average`. ## TODO Provide the first moment method for the Lebesgue integral as well. A draft is available on branch `first_moment_lintegral` in mathlib3 repository. ## Tags integral, center mass, average value -/ open ENNReal MeasureTheory MeasureTheory.Measure Metric Set Filter TopologicalSpace Function open scoped Topology ENNReal Convex variable {α E F : Type*} {m0 : MeasurableSpace α} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] [NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F] {μ ν : Measure α} {s t : Set α} /-! ### Average value of a function w.r.t. a measure The (Bochner, Lebesgue) average value of a function `f` w.r.t. a measure `μ` (notation: `⨍ x, f x ∂μ`, `⨍⁻ x, f x ∂μ`) is defined as the (Bochner, Lebesgue) integral divided by the total measure, so it is equal to zero if `μ` is an infinite measure, and (typically) equal to infinity if `f` is not integrable. If `μ` is a probability measure, then the average of any function is equal to its integral. -/ namespace MeasureTheory section ENNReal variable (μ) {f g : α → ℝ≥0∞} /-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ`, denoted `⨍⁻ x, f x ∂μ`. It is equal to `(μ univ)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `μ` is an infinite measure. If `μ` is a probability measure, then the average of any function is equal to its integral. For the average on a set, use `⨍⁻ x in s, f x ∂μ`, defined as `⨍⁻ x, f x ∂(μ.restrict s)`. For the average w.r.t. the volume, one can omit `∂volume`. -/ noncomputable def laverage (f : α → ℝ≥0∞) := ∫⁻ x, f x ∂(μ univ)⁻¹ • μ #align measure_theory.laverage MeasureTheory.laverage /-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ`. It is equal to `(μ univ)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `μ` is an infinite measure. If `μ` is a probability measure, then the average of any function is equal to its integral. For the average on a set, use `⨍⁻ x in s, f x ∂μ`, defined as `⨍⁻ x, f x ∂(μ.restrict s)`. For the average w.r.t. the volume, one can omit `∂volume`. -/ notation3 "⨍⁻ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => laverage μ r /-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. to the standard measure. It is equal to `(volume univ)⁻¹ * ∫⁻ x, f x`, so it takes value zero if the space has infinite measure. In a probability space, the average of any function is equal to its integral. For the average on a set, use `⨍⁻ x in s, f x`, defined as `⨍⁻ x, f x ∂(volume.restrict s)`. -/ notation3 "⨍⁻ "(...)", "r:60:(scoped f => laverage volume f) => r /-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ` on a set `s`. It is equal to `(μ s)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `s` has infinite measure. If `s` has measure `1`, then the average of any function is equal to its integral. For the average w.r.t. the volume, one can omit `∂volume`. -/ notation3 "⨍⁻ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => laverage (Measure.restrict μ s) r /-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. to the standard measure on a set `s`. It is equal to `(volume s)⁻¹ * ∫⁻ x, f x`, so it takes value zero if `s` has infinite measure. If `s` has measure `1`, then the average of any function is equal to its integral. -/ notation3 (prettyPrint := false) "⨍⁻ "(...)" in "s", "r:60:(scoped f => laverage Measure.restrict volume s f) => r @[simp] theorem laverage_zero : ⨍⁻ _x, (0 : ℝ≥0∞) ∂μ = 0 := by rw [laverage, lintegral_zero] #align measure_theory.laverage_zero MeasureTheory.laverage_zero @[simp] theorem laverage_zero_measure (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂(0 : Measure α) = 0 := by simp [laverage] #align measure_theory.laverage_zero_measure MeasureTheory.laverage_zero_measure theorem laverage_eq' (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂(μ univ)⁻¹ • μ := rfl #align measure_theory.laverage_eq' MeasureTheory.laverage_eq' theorem laverage_eq (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂μ = (∫⁻ x, f x ∂μ) / μ univ := by rw [laverage_eq', lintegral_smul_measure, ENNReal.div_eq_inv_mul] #align measure_theory.laverage_eq MeasureTheory.laverage_eq theorem laverage_eq_lintegral [IsProbabilityMeasure μ] (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂μ := by rw [laverage, measure_univ, inv_one, one_smul] #align measure_theory.laverage_eq_lintegral MeasureTheory.laverage_eq_lintegral @[simp] theorem measure_mul_laverage [IsFiniteMeasure μ] (f : α → ℝ≥0∞) : μ univ * ⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂μ := by rcases eq_or_ne μ 0 with hμ | hμ · rw [hμ, lintegral_zero_measure, laverage_zero_measure, mul_zero] · rw [laverage_eq, ENNReal.mul_div_cancel' (measure_univ_ne_zero.2 hμ) (measure_ne_top _ _)] #align measure_theory.measure_mul_laverage MeasureTheory.measure_mul_laverage theorem setLaverage_eq (f : α → ℝ≥0∞) (s : Set α) : ⨍⁻ x in s, f x ∂μ = (∫⁻ x in s, f x ∂μ) / μ s := by rw [laverage_eq, restrict_apply_univ] #align measure_theory.set_laverage_eq MeasureTheory.setLaverage_eq theorem setLaverage_eq' (f : α → ℝ≥0∞) (s : Set α) : ⨍⁻ x in s, f x ∂μ = ∫⁻ x, f x ∂(μ s)⁻¹ • μ.restrict s := by simp only [laverage_eq', restrict_apply_univ] #align measure_theory.set_laverage_eq' MeasureTheory.setLaverage_eq' variable {μ} theorem laverage_congr {f g : α → ℝ≥0∞} (h : f =ᵐ[μ] g) : ⨍⁻ x, f x ∂μ = ⨍⁻ x, g x ∂μ := by simp only [laverage_eq, lintegral_congr_ae h] #align measure_theory.laverage_congr MeasureTheory.laverage_congr theorem setLaverage_congr (h : s =ᵐ[μ] t) : ⨍⁻ x in s, f x ∂μ = ⨍⁻ x in t, f x ∂μ := by simp only [setLaverage_eq, set_lintegral_congr h, measure_congr h] #align measure_theory.set_laverage_congr MeasureTheory.setLaverage_congr theorem setLaverage_congr_fun (hs : MeasurableSet s) (h : ∀ᵐ x ∂μ, x ∈ s → f x = g x) : ⨍⁻ x in s, f x ∂μ = ⨍⁻ x in s, g x ∂μ := by simp only [laverage_eq, set_lintegral_congr_fun hs h] #align measure_theory.set_laverage_congr_fun MeasureTheory.setLaverage_congr_fun theorem laverage_lt_top (hf : ∫⁻ x, f x ∂μ ≠ ∞) : ⨍⁻ x, f x ∂μ < ∞ := by obtain rfl | hμ := eq_or_ne μ 0 · simp · rw [laverage_eq] exact div_lt_top hf (measure_univ_ne_zero.2 hμ) #align measure_theory.laverage_lt_top MeasureTheory.laverage_lt_top theorem setLaverage_lt_top : ∫⁻ x in s, f x ∂μ ≠ ∞ → ⨍⁻ x in s, f x ∂μ < ∞ := laverage_lt_top #align measure_theory.set_laverage_lt_top MeasureTheory.setLaverage_lt_top theorem laverage_add_measure : ⨍⁻ x, f x ∂(μ + ν) = μ univ / (μ univ + ν univ) * ⨍⁻ x, f x ∂μ + ν univ / (μ univ + ν univ) * ⨍⁻ x, f x ∂ν := by by_cases hμ : IsFiniteMeasure μ; swap · rw [not_isFiniteMeasure_iff] at hμ simp [laverage_eq, hμ] by_cases hν : IsFiniteMeasure ν; swap · rw [not_isFiniteMeasure_iff] at hν simp [laverage_eq, hν] haveI := hμ; haveI := hν simp only [← ENNReal.mul_div_right_comm, measure_mul_laverage, ← ENNReal.add_div, ← lintegral_add_measure, ← Measure.add_apply, ← laverage_eq] #align measure_theory.laverage_add_measure MeasureTheory.laverage_add_measure theorem measure_mul_setLaverage (f : α → ℝ≥0∞) (h : μ s ≠ ∞) : μ s * ⨍⁻ x in s, f x ∂μ = ∫⁻ x in s, f x ∂μ := by have := Fact.mk h.lt_top rw [← measure_mul_laverage, restrict_apply_univ] #align measure_theory.measure_mul_set_laverage MeasureTheory.measure_mul_setLaverage theorem laverage_union (hd : AEDisjoint μ s t) (ht : NullMeasurableSet t μ) : ⨍⁻ x in s ∪ t, f x ∂μ = μ s / (μ s + μ t) * ⨍⁻ x in s, f x ∂μ + μ t / (μ s + μ t) * ⨍⁻ x in t, f x ∂μ := by rw [restrict_union₀ hd ht, laverage_add_measure, restrict_apply_univ, restrict_apply_univ] #align measure_theory.laverage_union MeasureTheory.laverage_union theorem laverage_union_mem_openSegment (hd : AEDisjoint μ s t) (ht : NullMeasurableSet t μ) (hs₀ : μ s ≠ 0) (ht₀ : μ t ≠ 0) (hsμ : μ s ≠ ∞) (htμ : μ t ≠ ∞) : ⨍⁻ x in s ∪ t, f x ∂μ ∈ openSegment ℝ≥0∞ (⨍⁻ x in s, f x ∂μ) (⨍⁻ x in t, f x ∂μ) := by refine ⟨μ s / (μ s + μ t), μ t / (μ s + μ t), ENNReal.div_pos hs₀ <| add_ne_top.2 ⟨hsμ, htμ⟩, ENNReal.div_pos ht₀ <| add_ne_top.2 ⟨hsμ, htμ⟩, ?_, (laverage_union hd ht).symm⟩ rw [← ENNReal.add_div, ENNReal.div_self (add_eq_zero.not.2 fun h => hs₀ h.1) (add_ne_top.2 ⟨hsμ, htμ⟩)] #align measure_theory.laverage_union_mem_open_segment MeasureTheory.laverage_union_mem_openSegment theorem laverage_union_mem_segment (hd : AEDisjoint μ s t) (ht : NullMeasurableSet t μ) (hsμ : μ s ≠ ∞) (htμ : μ t ≠ ∞) : ⨍⁻ x in s ∪ t, f x ∂μ ∈ [⨍⁻ x in s, f x ∂μ -[ℝ≥0∞] ⨍⁻ x in t, f x ∂μ] := by by_cases hs₀ : μ s = 0 · rw [← ae_eq_empty] at hs₀ rw [restrict_congr_set (hs₀.union EventuallyEq.rfl), empty_union] exact right_mem_segment _ _ _ · refine ⟨μ s / (μ s + μ t), μ t / (μ s + μ t), zero_le _, zero_le _, ?_, (laverage_union hd ht).symm⟩ rw [← ENNReal.add_div, ENNReal.div_self (add_eq_zero.not.2 fun h => hs₀ h.1) (add_ne_top.2 ⟨hsμ, htμ⟩)] #align measure_theory.laverage_union_mem_segment MeasureTheory.laverage_union_mem_segment theorem laverage_mem_openSegment_compl_self [IsFiniteMeasure μ] (hs : NullMeasurableSet s μ) (hs₀ : μ s ≠ 0) (hsc₀ : μ sᶜ ≠ 0) : ⨍⁻ x, f x ∂μ ∈ openSegment ℝ≥0∞ (⨍⁻ x in s, f x ∂μ) (⨍⁻ x in sᶜ, f x ∂μ) := by simpa only [union_compl_self, restrict_univ] using laverage_union_mem_openSegment aedisjoint_compl_right hs.compl hs₀ hsc₀ (measure_ne_top _ _) (measure_ne_top _ _) #align measure_theory.laverage_mem_open_segment_compl_self MeasureTheory.laverage_mem_openSegment_compl_self @[simp] theorem laverage_const (μ : Measure α) [IsFiniteMeasure μ] [h : NeZero μ] (c : ℝ≥0∞) : ⨍⁻ _x, c ∂μ = c := by simp only [laverage, lintegral_const, measure_univ, mul_one] #align measure_theory.laverage_const MeasureTheory.laverage_const theorem setLaverage_const (hs₀ : μ s ≠ 0) (hs : μ s ≠ ∞) (c : ℝ≥0∞) : ⨍⁻ _x in s, c ∂μ = c := by simp only [setLaverage_eq, lintegral_const, Measure.restrict_apply, MeasurableSet.univ, univ_inter, div_eq_mul_inv, mul_assoc, ENNReal.mul_inv_cancel hs₀ hs, mul_one] #align measure_theory.set_laverage_const MeasureTheory.setLaverage_const theorem laverage_one [IsFiniteMeasure μ] [NeZero μ] : ⨍⁻ _x, (1 : ℝ≥0∞) ∂μ = 1 := laverage_const _ _ #align measure_theory.laverage_one MeasureTheory.laverage_one theorem setLaverage_one (hs₀ : μ s ≠ 0) (hs : μ s ≠ ∞) : ⨍⁻ _x in s, (1 : ℝ≥0∞) ∂μ = 1 := setLaverage_const hs₀ hs _ #align measure_theory.set_laverage_one MeasureTheory.setLaverage_one -- Porting note: Dropped `simp` because of `simp` seeing through `1 : α → ℝ≥0∞` and applying -- `lintegral_const`. This is suboptimal. theorem lintegral_laverage (μ : Measure α) [IsFiniteMeasure μ] (f : α → ℝ≥0∞) : ∫⁻ _x, ⨍⁻ a, f a ∂μ ∂μ = ∫⁻ x, f x ∂μ := by obtain rfl | hμ := eq_or_ne μ 0 · simp · rw [lintegral_const, laverage_eq, ENNReal.div_mul_cancel (measure_univ_ne_zero.2 hμ) (measure_ne_top _ _)] #align measure_theory.lintegral_laverage MeasureTheory.lintegral_laverage theorem setLintegral_setLaverage (μ : Measure α) [IsFiniteMeasure μ] (f : α → ℝ≥0∞) (s : Set α) : ∫⁻ _x in s, ⨍⁻ a in s, f a ∂μ ∂μ = ∫⁻ x in s, f x ∂μ := lintegral_laverage _ _ #align measure_theory.set_lintegral_set_laverage MeasureTheory.setLintegral_setLaverage end ENNReal section NormedAddCommGroup variable (μ) variable {f g : α → E} /-- Average value of a function `f` w.r.t. a measure `μ`, denoted `⨍ x, f x ∂μ`. It is equal to `(μ univ).toReal⁻¹ • ∫ x, f x ∂μ`, so it takes value zero if `f` is not integrable or if `μ` is an infinite measure. If `μ` is a probability measure, then the average of any function is equal to its integral. For the average on a set, use `⨍ x in s, f x ∂μ`, defined as `⨍ x, f x ∂(μ.restrict s)`. For the average w.r.t. the volume, one can omit `∂volume`. -/ noncomputable def average (f : α → E) := ∫ x, f x ∂(μ univ)⁻¹ • μ #align measure_theory.average MeasureTheory.average /-- Average value of a function `f` w.r.t. a measure `μ`. It is equal to `(μ univ).toReal⁻¹ • ∫ x, f x ∂μ`, so it takes value zero if `f` is not integrable or if `μ` is an infinite measure. If `μ` is a probability measure, then the average of any function is equal to its integral. For the average on a set, use `⨍ x in s, f x ∂μ`, defined as `⨍ x, f x ∂(μ.restrict s)`. For the average w.r.t. the volume, one can omit `∂volume`. -/ notation3 "⨍ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => average μ r /-- Average value of a function `f` w.r.t. to the standard measure. It is equal to `(volume univ).toReal⁻¹ * ∫ x, f x`, so it takes value zero if `f` is not integrable or if the space has infinite measure. In a probability space, the average of any function is equal to its integral. For the average on a set, use `⨍ x in s, f x`, defined as `⨍ x, f x ∂(volume.restrict s)`. -/ notation3 "⨍ "(...)", "r:60:(scoped f => average volume f) => r /-- Average value of a function `f` w.r.t. a measure `μ` on a set `s`. It is equal to `(μ s).toReal⁻¹ * ∫ x, f x ∂μ`, so it takes value zero if `f` is not integrable on `s` or if `s` has infinite measure. If `s` has measure `1`, then the average of any function is equal to its integral. For the average w.r.t. the volume, one can omit `∂volume`. -/ notation3 "⨍ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => average (Measure.restrict μ s) r /-- Average value of a function `f` w.r.t. to the standard measure on a set `s`. It is equal to `(volume s).toReal⁻¹ * ∫ x, f x`, so it takes value zero `f` is not integrable on `s` or if `s` has infinite measure. If `s` has measure `1`, then the average of any function is equal to its integral. -/ notation3 "⨍ "(...)" in "s", "r:60:(scoped f => average (Measure.restrict volume s) f) => r @[simp] theorem average_zero : ⨍ _, (0 : E) ∂μ = 0 := by rw [average, integral_zero] #align measure_theory.average_zero MeasureTheory.average_zero @[simp] theorem average_zero_measure (f : α → E) : ⨍ x, f x ∂(0 : Measure α) = 0 := by rw [average, smul_zero, integral_zero_measure] #align measure_theory.average_zero_measure MeasureTheory.average_zero_measure @[simp] theorem average_neg (f : α → E) : ⨍ x, -f x ∂μ = -⨍ x, f x ∂μ := integral_neg f #align measure_theory.average_neg MeasureTheory.average_neg theorem average_eq' (f : α → E) : ⨍ x, f x ∂μ = ∫ x, f x ∂(μ univ)⁻¹ • μ := rfl #align measure_theory.average_eq' MeasureTheory.average_eq' theorem average_eq (f : α → E) : ⨍ x, f x ∂μ = (μ univ).toReal⁻¹ • ∫ x, f x ∂μ := by rw [average_eq', integral_smul_measure, ENNReal.toReal_inv] #align measure_theory.average_eq MeasureTheory.average_eq theorem average_eq_integral [IsProbabilityMeasure μ] (f : α → E) : ⨍ x, f x ∂μ = ∫ x, f x ∂μ := by rw [average, measure_univ, inv_one, one_smul] #align measure_theory.average_eq_integral MeasureTheory.average_eq_integral @[simp] theorem measure_smul_average [IsFiniteMeasure μ] (f : α → E) : (μ univ).toReal • ⨍ x, f x ∂μ = ∫ x, f x ∂μ := by rcases eq_or_ne μ 0 with hμ | hμ · rw [hμ, integral_zero_measure, average_zero_measure, smul_zero] · rw [average_eq, smul_inv_smul₀] refine (ENNReal.toReal_pos ?_ <| measure_ne_top _ _).ne' rwa [Ne, measure_univ_eq_zero] #align measure_theory.measure_smul_average MeasureTheory.measure_smul_average theorem setAverage_eq (f : α → E) (s : Set α) : ⨍ x in s, f x ∂μ = (μ s).toReal⁻¹ • ∫ x in s, f x ∂μ := by rw [average_eq, restrict_apply_univ] #align measure_theory.set_average_eq MeasureTheory.setAverage_eq theorem setAverage_eq' (f : α → E) (s : Set α) : ⨍ x in s, f x ∂μ = ∫ x, f x ∂(μ s)⁻¹ • μ.restrict s := by simp only [average_eq', restrict_apply_univ] #align measure_theory.set_average_eq' MeasureTheory.setAverage_eq' variable {μ} theorem average_congr {f g : α → E} (h : f =ᵐ[μ] g) : ⨍ x, f x ∂μ = ⨍ x, g x ∂μ := by simp only [average_eq, integral_congr_ae h] #align measure_theory.average_congr MeasureTheory.average_congr theorem setAverage_congr (h : s =ᵐ[μ] t) : ⨍ x in s, f x ∂μ = ⨍ x in t, f x ∂μ := by simp only [setAverage_eq, setIntegral_congr_set_ae h, measure_congr h] #align measure_theory.set_average_congr MeasureTheory.setAverage_congr theorem setAverage_congr_fun (hs : MeasurableSet s) (h : ∀ᵐ x ∂μ, x ∈ s → f x = g x) : ⨍ x in s, f x ∂μ = ⨍ x in s, g x ∂μ := by simp only [average_eq, setIntegral_congr_ae hs h] #align measure_theory.set_average_congr_fun MeasureTheory.setAverage_congr_fun
Mathlib/MeasureTheory/Integral/Average.lean
373
380
theorem average_add_measure [IsFiniteMeasure μ] {ν : Measure α} [IsFiniteMeasure ν] {f : α → E} (hμ : Integrable f μ) (hν : Integrable f ν) : ⨍ x, f x ∂(μ + ν) = ((μ univ).toReal / ((μ univ).toReal + (ν univ).toReal)) • ⨍ x, f x ∂μ + ((ν univ).toReal / ((μ univ).toReal + (ν univ).toReal)) • ⨍ x, f x ∂ν := by
simp only [div_eq_inv_mul, mul_smul, measure_smul_average, ← smul_add, ← integral_add_measure hμ hν, ← ENNReal.toReal_add (measure_ne_top μ _) (measure_ne_top ν _)] rw [average_eq, Measure.add_apply]
/- Copyright (c) 2023 Peter Nelson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Peter Nelson -/ import Mathlib.SetTheory.Cardinal.Finite #align_import data.set.ncard from "leanprover-community/mathlib"@"74c2af38a828107941029b03839882c5c6f87a04" /-! # Noncomputable Set Cardinality We define the cardinality of set `s` as a term `Set.encard s : ℕ∞` and a term `Set.ncard s : ℕ`. The latter takes the junk value of zero if `s` is infinite. Both functions are noncomputable, and are defined in terms of `PartENat.card` (which takes a type as its argument); this file can be seen as an API for the same function in the special case where the type is a coercion of a `Set`, allowing for smoother interactions with the `Set` API. `Set.encard` never takes junk values, so is more mathematically natural than `Set.ncard`, even though it takes values in a less convenient type. It is probably the right choice in settings where one is concerned with the cardinalities of sets that may or may not be infinite. `Set.ncard` has a nicer codomain, but when using it, `Set.Finite` hypotheses are normally needed to make sure its values are meaningful. More generally, `Set.ncard` is intended to be used over the obvious alternative `Finset.card` when finiteness is 'propositional' rather than 'structural'. When working with sets that are finite by virtue of their definition, then `Finset.card` probably makes more sense. One setting where `Set.ncard` works nicely is in a type `α` with `[Finite α]`, where every set is automatically finite. In this setting, we use default arguments and a simple tactic so that finiteness goals are discharged automatically in `Set.ncard` theorems. ## Main Definitions * `Set.encard s` is the cardinality of the set `s` as an extended natural number, with value `⊤` if `s` is infinite. * `Set.ncard s` is the cardinality of the set `s` as a natural number, provided `s` is Finite. If `s` is Infinite, then `Set.ncard s = 0`. * `toFinite_tac` is a tactic that tries to synthesize a `Set.Finite s` argument with `Set.toFinite`. This will work for `s : Set α` where there is a `Finite α` instance. ## Implementation Notes The theorems in this file are very similar to those in `Data.Finset.Card`, but with `Set` operations instead of `Finset`. We first prove all the theorems for `Set.encard`, and then derive most of the `Set.ncard` results as a consequence. Things are done this way to avoid reliance on the `Finset` API for theorems about infinite sets, and to allow for a refactor that removes or modifies `Set.ncard` in the future. Nearly all the theorems for `Set.ncard` require finiteness of one or more of their arguments. We provide this assumption with a default argument of the form `(hs : s.Finite := by toFinite_tac)`, where `toFinite_tac` will find an `s.Finite` term in the cases where `s` is a set in a `Finite` type. Often, where there are two set arguments `s` and `t`, the finiteness of one follows from the other in the context of the theorem, in which case we only include the ones that are needed, and derive the other inside the proof. A few of the theorems, such as `ncard_union_le` do not require finiteness arguments; they are true by coincidence due to junk values. -/ namespace Set variable {α β : Type*} {s t : Set α} /-- The cardinality of a set as a term in `ℕ∞` -/ noncomputable def encard (s : Set α) : ℕ∞ := PartENat.withTopEquiv (PartENat.card s) @[simp] theorem encard_univ_coe (s : Set α) : encard (univ : Set s) = encard s := by rw [encard, encard, PartENat.card_congr (Equiv.Set.univ ↑s)] theorem encard_univ (α : Type*) : encard (univ : Set α) = PartENat.withTopEquiv (PartENat.card α) := by rw [encard, PartENat.card_congr (Equiv.Set.univ α)] theorem Finite.encard_eq_coe_toFinset_card (h : s.Finite) : s.encard = h.toFinset.card := by have := h.fintype rw [encard, PartENat.card_eq_coe_fintype_card, PartENat.withTopEquiv_natCast, toFinite_toFinset, toFinset_card] theorem encard_eq_coe_toFinset_card (s : Set α) [Fintype s] : encard s = s.toFinset.card := by have h := toFinite s rw [h.encard_eq_coe_toFinset_card, toFinite_toFinset] theorem encard_coe_eq_coe_finsetCard (s : Finset α) : encard (s : Set α) = s.card := by rw [Finite.encard_eq_coe_toFinset_card (Finset.finite_toSet s)]; simp theorem Infinite.encard_eq {s : Set α} (h : s.Infinite) : s.encard = ⊤ := by have := h.to_subtype rw [encard, ← PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply, PartENat.withTopEquiv_symm_top, PartENat.card_eq_top_of_infinite] @[simp] theorem encard_eq_zero : s.encard = 0 ↔ s = ∅ := by rw [encard, ← PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply, PartENat.withTopEquiv_symm_zero, PartENat.card_eq_zero_iff_empty, isEmpty_subtype, eq_empty_iff_forall_not_mem] @[simp] theorem encard_empty : (∅ : Set α).encard = 0 := by rw [encard_eq_zero] theorem nonempty_of_encard_ne_zero (h : s.encard ≠ 0) : s.Nonempty := by rwa [nonempty_iff_ne_empty, Ne, ← encard_eq_zero] theorem encard_ne_zero : s.encard ≠ 0 ↔ s.Nonempty := by rw [ne_eq, encard_eq_zero, nonempty_iff_ne_empty] @[simp] theorem encard_pos : 0 < s.encard ↔ s.Nonempty := by rw [pos_iff_ne_zero, encard_ne_zero] @[simp] theorem encard_singleton (e : α) : ({e} : Set α).encard = 1 := by rw [encard, ← PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply, PartENat.card_eq_coe_fintype_card, Fintype.card_ofSubsingleton, Nat.cast_one]; rfl theorem encard_union_eq (h : Disjoint s t) : (s ∪ t).encard = s.encard + t.encard := by classical have e := (Equiv.Set.union (by rwa [subset_empty_iff, ← disjoint_iff_inter_eq_empty])).symm simp [encard, ← PartENat.card_congr e, PartENat.card_sum, PartENat.withTopEquiv] theorem encard_insert_of_not_mem {a : α} (has : a ∉ s) : (insert a s).encard = s.encard + 1 := by rw [← union_singleton, encard_union_eq (by simpa), encard_singleton] theorem Finite.encard_lt_top (h : s.Finite) : s.encard < ⊤ := by refine h.induction_on (by simp) ?_ rintro a t hat _ ht' rw [encard_insert_of_not_mem hat] exact lt_tsub_iff_right.1 ht' theorem Finite.encard_eq_coe (h : s.Finite) : s.encard = ENat.toNat s.encard := (ENat.coe_toNat h.encard_lt_top.ne).symm theorem Finite.exists_encard_eq_coe (h : s.Finite) : ∃ (n : ℕ), s.encard = n := ⟨_, h.encard_eq_coe⟩ @[simp] theorem encard_lt_top_iff : s.encard < ⊤ ↔ s.Finite := ⟨fun h ↦ by_contra fun h' ↦ h.ne (Infinite.encard_eq h'), Finite.encard_lt_top⟩ @[simp] theorem encard_eq_top_iff : s.encard = ⊤ ↔ s.Infinite := by rw [← not_iff_not, ← Ne, ← lt_top_iff_ne_top, encard_lt_top_iff, not_infinite] theorem encard_ne_top_iff : s.encard ≠ ⊤ ↔ s.Finite := by simp theorem finite_of_encard_le_coe {k : ℕ} (h : s.encard ≤ k) : s.Finite := by rw [← encard_lt_top_iff]; exact h.trans_lt (WithTop.coe_lt_top _) theorem finite_of_encard_eq_coe {k : ℕ} (h : s.encard = k) : s.Finite := finite_of_encard_le_coe h.le theorem encard_le_coe_iff {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ ∃ (n₀ : ℕ), s.encard = n₀ ∧ n₀ ≤ k := ⟨fun h ↦ ⟨finite_of_encard_le_coe h, by rwa [ENat.le_coe_iff] at h⟩, fun ⟨_,⟨n₀,hs, hle⟩⟩ ↦ by rwa [hs, Nat.cast_le]⟩ section Lattice theorem encard_le_card (h : s ⊆ t) : s.encard ≤ t.encard := by rw [← union_diff_cancel h, encard_union_eq disjoint_sdiff_right]; exact le_self_add theorem encard_mono {α : Type*} : Monotone (encard : Set α → ℕ∞) := fun _ _ ↦ encard_le_card theorem encard_diff_add_encard_of_subset (h : s ⊆ t) : (t \ s).encard + s.encard = t.encard := by rw [← encard_union_eq disjoint_sdiff_left, diff_union_self, union_eq_self_of_subset_right h] @[simp] theorem one_le_encard_iff_nonempty : 1 ≤ s.encard ↔ s.Nonempty := by rw [nonempty_iff_ne_empty, Ne, ← encard_eq_zero, ENat.one_le_iff_ne_zero] theorem encard_diff_add_encard_inter (s t : Set α) : (s \ t).encard + (s ∩ t).encard = s.encard := by rw [← encard_union_eq (disjoint_of_subset_right inter_subset_right disjoint_sdiff_left), diff_union_inter] theorem encard_union_add_encard_inter (s t : Set α) : (s ∪ t).encard + (s ∩ t).encard = s.encard + t.encard := by rw [← diff_union_self, encard_union_eq disjoint_sdiff_left, add_right_comm, encard_diff_add_encard_inter] theorem encard_eq_encard_iff_encard_diff_eq_encard_diff (h : (s ∩ t).Finite) : s.encard = t.encard ↔ (s \ t).encard = (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_right_cancel_iff h.encard_lt_top.ne] theorem encard_le_encard_iff_encard_diff_le_encard_diff (h : (s ∩ t).Finite) : s.encard ≤ t.encard ↔ (s \ t).encard ≤ (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_le_add_iff_right h.encard_lt_top.ne] theorem encard_lt_encard_iff_encard_diff_lt_encard_diff (h : (s ∩ t).Finite) : s.encard < t.encard ↔ (s \ t).encard < (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_lt_add_iff_right h.encard_lt_top.ne] theorem encard_union_le (s t : Set α) : (s ∪ t).encard ≤ s.encard + t.encard := by rw [← encard_union_add_encard_inter]; exact le_self_add theorem finite_iff_finite_of_encard_eq_encard (h : s.encard = t.encard) : s.Finite ↔ t.Finite := by rw [← encard_lt_top_iff, ← encard_lt_top_iff, h] theorem infinite_iff_infinite_of_encard_eq_encard (h : s.encard = t.encard) : s.Infinite ↔ t.Infinite := by rw [← encard_eq_top_iff, h, encard_eq_top_iff] theorem Finite.finite_of_encard_le {s : Set α} {t : Set β} (hs : s.Finite) (h : t.encard ≤ s.encard) : t.Finite := encard_lt_top_iff.1 (h.trans_lt hs.encard_lt_top) theorem Finite.eq_of_subset_of_encard_le (ht : t.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) : s = t := by rw [← zero_add (a := encard s), ← encard_diff_add_encard_of_subset hst] at hts have hdiff := WithTop.le_of_add_le_add_right (ht.subset hst).encard_lt_top.ne hts rw [nonpos_iff_eq_zero, encard_eq_zero, diff_eq_empty] at hdiff exact hst.antisymm hdiff theorem Finite.eq_of_subset_of_encard_le' (hs : s.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) : s = t := (hs.finite_of_encard_le hts).eq_of_subset_of_encard_le hst hts theorem Finite.encard_lt_encard (ht : t.Finite) (h : s ⊂ t) : s.encard < t.encard := (encard_mono h.subset).lt_of_ne (fun he ↦ h.ne (ht.eq_of_subset_of_encard_le h.subset he.symm.le)) theorem encard_strictMono [Finite α] : StrictMono (encard : Set α → ℕ∞) := fun _ _ h ↦ (toFinite _).encard_lt_encard h theorem encard_diff_add_encard (s t : Set α) : (s \ t).encard + t.encard = (s ∪ t).encard := by rw [← encard_union_eq disjoint_sdiff_left, diff_union_self] theorem encard_le_encard_diff_add_encard (s t : Set α) : s.encard ≤ (s \ t).encard + t.encard := (encard_mono subset_union_left).trans_eq (encard_diff_add_encard _ _).symm theorem tsub_encard_le_encard_diff (s t : Set α) : s.encard - t.encard ≤ (s \ t).encard := by rw [tsub_le_iff_left, add_comm]; apply encard_le_encard_diff_add_encard theorem encard_add_encard_compl (s : Set α) : s.encard + sᶜ.encard = (univ : Set α).encard := by rw [← encard_union_eq disjoint_compl_right, union_compl_self] end Lattice section InsertErase variable {a b : α} theorem encard_insert_le (s : Set α) (x : α) : (insert x s).encard ≤ s.encard + 1 := by rw [← union_singleton, ← encard_singleton x]; apply encard_union_le theorem encard_singleton_inter (s : Set α) (x : α) : ({x} ∩ s).encard ≤ 1 := by rw [← encard_singleton x]; exact encard_le_card inter_subset_left theorem encard_diff_singleton_add_one (h : a ∈ s) : (s \ {a}).encard + 1 = s.encard := by rw [← encard_insert_of_not_mem (fun h ↦ h.2 rfl), insert_diff_singleton, insert_eq_of_mem h] theorem encard_diff_singleton_of_mem (h : a ∈ s) : (s \ {a}).encard = s.encard - 1 := by rw [← encard_diff_singleton_add_one h, ← WithTop.add_right_cancel_iff WithTop.one_ne_top, tsub_add_cancel_of_le (self_le_add_left _ _)] theorem encard_tsub_one_le_encard_diff_singleton (s : Set α) (x : α) : s.encard - 1 ≤ (s \ {x}).encard := by rw [← encard_singleton x]; apply tsub_encard_le_encard_diff theorem encard_exchange (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).encard = s.encard := by rw [encard_insert_of_not_mem, encard_diff_singleton_add_one hb] simp_all only [not_true, mem_diff, mem_singleton_iff, false_and, not_false_eq_true] theorem encard_exchange' (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).encard = s.encard := by rw [← insert_diff_singleton_comm (by rintro rfl; exact ha hb), encard_exchange ha hb] theorem encard_eq_add_one_iff {k : ℕ∞} : s.encard = k + 1 ↔ (∃ a t, ¬a ∈ t ∧ insert a t = s ∧ t.encard = k) := by refine ⟨fun h ↦ ?_, ?_⟩ · obtain ⟨a, ha⟩ := nonempty_of_encard_ne_zero (s := s) (by simp [h]) refine ⟨a, s \ {a}, fun h ↦ h.2 rfl, by rwa [insert_diff_singleton, insert_eq_of_mem], ?_⟩ rw [← WithTop.add_right_cancel_iff WithTop.one_ne_top, ← h, encard_diff_singleton_add_one ha] rintro ⟨a, t, h, rfl, rfl⟩ rw [encard_insert_of_not_mem h] /-- Every set is either empty, infinite, or can have its `encard` reduced by a removal. Intended for well-founded induction on the value of `encard`. -/ theorem eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt (s : Set α) : s = ∅ ∨ s.encard = ⊤ ∨ ∃ a ∈ s, (s \ {a}).encard < s.encard := by refine s.eq_empty_or_nonempty.elim Or.inl (Or.inr ∘ fun ⟨a,ha⟩ ↦ (s.finite_or_infinite.elim (fun hfin ↦ Or.inr ⟨a, ha, ?_⟩) (Or.inl ∘ Infinite.encard_eq))) rw [← encard_diff_singleton_add_one ha]; nth_rw 1 [← add_zero (encard _)] exact WithTop.add_lt_add_left (hfin.diff _).encard_lt_top.ne zero_lt_one end InsertErase section SmallSets theorem encard_pair {x y : α} (hne : x ≠ y) : ({x, y} : Set α).encard = 2 := by rw [encard_insert_of_not_mem (by simpa), ← one_add_one_eq_two, WithTop.add_right_cancel_iff WithTop.one_ne_top, encard_singleton] theorem encard_eq_one : s.encard = 1 ↔ ∃ x, s = {x} := by refine ⟨fun h ↦ ?_, fun ⟨x, hx⟩ ↦ by rw [hx, encard_singleton]⟩ obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp) exact ⟨x, ((finite_singleton x).eq_of_subset_of_encard_le' (by simpa) (by simp [h])).symm⟩ theorem encard_le_one_iff_eq : s.encard ≤ 1 ↔ s = ∅ ∨ ∃ x, s = {x} := by rw [le_iff_lt_or_eq, lt_iff_not_le, ENat.one_le_iff_ne_zero, not_not, encard_eq_zero, encard_eq_one] theorem encard_le_one_iff : s.encard ≤ 1 ↔ ∀ a b, a ∈ s → b ∈ s → a = b := by rw [encard_le_one_iff_eq, or_iff_not_imp_left, ← Ne, ← nonempty_iff_ne_empty] refine ⟨fun h a b has hbs ↦ ?_, fun h ⟨x, hx⟩ ↦ ⟨x, ((singleton_subset_iff.2 hx).antisymm' (fun y hy ↦ h _ _ hy hx))⟩⟩ obtain ⟨x, rfl⟩ := h ⟨_, has⟩ rw [(has : a = x), (hbs : b = x)] theorem one_lt_encard_iff : 1 < s.encard ↔ ∃ a b, a ∈ s ∧ b ∈ s ∧ a ≠ b := by rw [← not_iff_not, not_exists, not_lt, encard_le_one_iff]; aesop theorem exists_ne_of_one_lt_encard (h : 1 < s.encard) (a : α) : ∃ b ∈ s, b ≠ a := by by_contra! h' obtain ⟨b, b', hb, hb', hne⟩ := one_lt_encard_iff.1 h apply hne rw [h' b hb, h' b' hb'] theorem encard_eq_two : s.encard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by refine ⟨fun h ↦ ?_, fun ⟨x, y, hne, hs⟩ ↦ by rw [hs, encard_pair hne]⟩ obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp) rw [← insert_eq_of_mem hx, ← insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl), ← one_add_one_eq_two, WithTop.add_right_cancel_iff (WithTop.one_ne_top), encard_eq_one] at h obtain ⟨y, h⟩ := h refine ⟨x, y, by rintro rfl; exact (h.symm.subset rfl).2 rfl, ?_⟩ rw [← h, insert_diff_singleton, insert_eq_of_mem hx] theorem encard_eq_three {α : Type u_1} {s : Set α} : encard s = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by refine ⟨fun h ↦ ?_, fun ⟨x, y, z, hxy, hyz, hxz, hs⟩ ↦ ?_⟩ · obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp) rw [← insert_eq_of_mem hx, ← insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl), (by exact rfl : (3 : ℕ∞) = 2 + 1), WithTop.add_right_cancel_iff WithTop.one_ne_top, encard_eq_two] at h obtain ⟨y, z, hne, hs⟩ := h refine ⟨x, y, z, ?_, ?_, hne, ?_⟩ · rintro rfl; exact (hs.symm.subset (Or.inl rfl)).2 rfl · rintro rfl; exact (hs.symm.subset (Or.inr rfl)).2 rfl rw [← hs, insert_diff_singleton, insert_eq_of_mem hx] rw [hs, encard_insert_of_not_mem, encard_insert_of_not_mem, encard_singleton] <;> aesop theorem Nat.encard_range (k : ℕ) : {i | i < k}.encard = k := by convert encard_coe_eq_coe_finsetCard (Finset.range k) using 1 · rw [Finset.coe_range, Iio_def] rw [Finset.card_range] end SmallSets theorem Finite.eq_insert_of_subset_of_encard_eq_succ (hs : s.Finite) (h : s ⊆ t) (hst : t.encard = s.encard + 1) : ∃ a, t = insert a s := by rw [← encard_diff_add_encard_of_subset h, add_comm, WithTop.add_left_cancel_iff hs.encard_lt_top.ne, encard_eq_one] at hst obtain ⟨x, hx⟩ := hst; use x; rw [← diff_union_of_subset h, hx, singleton_union] theorem exists_subset_encard_eq {k : ℕ∞} (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by revert hk refine ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ ?_) ?_ · obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by simp) hle) simp only [Nat.cast_succ] at * have hne : t₀ ≠ s := by rintro rfl; rw [ht₀, ← Nat.cast_one, ← Nat.cast_add, Nat.cast_le] at hle; simp at hle obtain ⟨x, hx⟩ := exists_of_ssubset (ht₀s.ssubset_of_ne hne) exact ⟨insert x t₀, insert_subset hx.1 ht₀s, by rw [encard_insert_of_not_mem hx.2, ht₀]⟩ simp only [top_le_iff, encard_eq_top_iff] exact fun _ hi ↦ ⟨s, Subset.rfl, hi⟩ theorem exists_superset_subset_encard_eq {k : ℕ∞} (hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.encard) : ∃ r, s ⊆ r ∧ r ⊆ t ∧ r.encard = k := by obtain (hs | hs) := eq_or_ne s.encard ⊤ · rw [hs, top_le_iff] at hsk; subst hsk; exact ⟨s, Subset.rfl, hst, hs⟩ obtain ⟨k, rfl⟩ := exists_add_of_le hsk obtain ⟨k', hk'⟩ := exists_add_of_le hkt have hk : k ≤ encard (t \ s) := by rw [← encard_diff_add_encard_of_subset hst, add_comm] at hkt exact WithTop.le_of_add_le_add_right hs hkt obtain ⟨r', hr', rfl⟩ := exists_subset_encard_eq hk refine ⟨s ∪ r', subset_union_left, union_subset hst (hr'.trans diff_subset), ?_⟩ rw [encard_union_eq (disjoint_of_subset_right hr' disjoint_sdiff_right)] section Function variable {s : Set α} {t : Set β} {f : α → β} theorem InjOn.encard_image (h : InjOn f s) : (f '' s).encard = s.encard := by rw [encard, PartENat.card_image_of_injOn h, encard] theorem encard_congr (e : s ≃ t) : s.encard = t.encard := by rw [← encard_univ_coe, ← encard_univ_coe t, encard_univ, encard_univ, PartENat.card_congr e] theorem _root_.Function.Injective.encard_image (hf : f.Injective) (s : Set α) : (f '' s).encard = s.encard := hf.injOn.encard_image theorem _root_.Function.Embedding.enccard_le (e : s ↪ t) : s.encard ≤ t.encard := by rw [← encard_univ_coe, ← e.injective.encard_image, ← Subtype.coe_injective.encard_image] exact encard_mono (by simp) theorem encard_image_le (f : α → β) (s : Set α) : (f '' s).encard ≤ s.encard := by obtain (h | h) := isEmpty_or_nonempty α · rw [s.eq_empty_of_isEmpty]; simp rw [← (f.invFunOn_injOn_image s).encard_image] apply encard_le_card exact f.invFunOn_image_image_subset s
Mathlib/Data/Set/Card.lean
402
408
theorem Finite.injOn_of_encard_image_eq (hs : s.Finite) (h : (f '' s).encard = s.encard) : InjOn f s := by
obtain (h' | hne) := isEmpty_or_nonempty α · rw [s.eq_empty_of_isEmpty]; simp rw [← (f.invFunOn_injOn_image s).encard_image] at h rw [injOn_iff_invFunOn_image_image_eq_self] exact hs.eq_of_subset_of_encard_le (f.invFunOn_image_image_subset s) h.symm.le
/- Copyright (c) 2022 Thomas Browning. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning -/ import Mathlib.Algebra.Polynomial.Mirror import Mathlib.Analysis.Complex.Polynomial #align_import data.polynomial.unit_trinomial from "leanprover-community/mathlib"@"302eab4f46abb63de520828de78c04cb0f9b5836" /-! # Unit Trinomials This file defines irreducible trinomials and proves an irreducibility criterion. ## Main definitions - `Polynomial.IsUnitTrinomial` ## Main results - `Polynomial.IsUnitTrinomial.irreducible_of_coprime`: An irreducibility criterion for unit trinomials. -/ namespace Polynomial open scoped Polynomial open Finset section Semiring variable {R : Type*} [Semiring R] (k m n : ℕ) (u v w : R) /-- Shorthand for a trinomial -/ noncomputable def trinomial := C u * X ^ k + C v * X ^ m + C w * X ^ n #align polynomial.trinomial Polynomial.trinomial theorem trinomial_def : trinomial k m n u v w = C u * X ^ k + C v * X ^ m + C w * X ^ n := rfl #align polynomial.trinomial_def Polynomial.trinomial_def variable {k m n u v w} theorem trinomial_leading_coeff' (hkm : k < m) (hmn : m < n) : (trinomial k m n u v w).coeff n = w := by rw [trinomial_def, coeff_add, coeff_add, coeff_C_mul_X_pow, coeff_C_mul_X_pow, coeff_C_mul_X_pow, if_neg (hkm.trans hmn).ne', if_neg hmn.ne', if_pos rfl, zero_add, zero_add] #align polynomial.trinomial_leading_coeff' Polynomial.trinomial_leading_coeff' theorem trinomial_middle_coeff (hkm : k < m) (hmn : m < n) : (trinomial k m n u v w).coeff m = v := by rw [trinomial_def, coeff_add, coeff_add, coeff_C_mul_X_pow, coeff_C_mul_X_pow, coeff_C_mul_X_pow, if_neg hkm.ne', if_pos rfl, if_neg hmn.ne, zero_add, add_zero] #align polynomial.trinomial_middle_coeff Polynomial.trinomial_middle_coeff theorem trinomial_trailing_coeff' (hkm : k < m) (hmn : m < n) : (trinomial k m n u v w).coeff k = u := by rw [trinomial_def, coeff_add, coeff_add, coeff_C_mul_X_pow, coeff_C_mul_X_pow, coeff_C_mul_X_pow, if_pos rfl, if_neg hkm.ne, if_neg (hkm.trans hmn).ne, add_zero, add_zero] #align polynomial.trinomial_trailing_coeff' Polynomial.trinomial_trailing_coeff' theorem trinomial_natDegree (hkm : k < m) (hmn : m < n) (hw : w ≠ 0) : (trinomial k m n u v w).natDegree = n := by refine natDegree_eq_of_degree_eq_some ((Finset.sup_le fun i h => ?_).antisymm <| le_degree_of_ne_zero <| by rwa [trinomial_leading_coeff' hkm hmn]) replace h := support_trinomial' k m n u v w h rw [mem_insert, mem_insert, mem_singleton] at h rcases h with (rfl | rfl | rfl) · exact WithBot.coe_le_coe.mpr (hkm.trans hmn).le · exact WithBot.coe_le_coe.mpr hmn.le · exact le_rfl #align polynomial.trinomial_nat_degree Polynomial.trinomial_natDegree theorem trinomial_natTrailingDegree (hkm : k < m) (hmn : m < n) (hu : u ≠ 0) : (trinomial k m n u v w).natTrailingDegree = k := by refine natTrailingDegree_eq_of_trailingDegree_eq_some ((Finset.le_inf fun i h => ?_).antisymm <| trailingDegree_le_of_ne_zero <| by rwa [trinomial_trailing_coeff' hkm hmn]).symm replace h := support_trinomial' k m n u v w h rw [mem_insert, mem_insert, mem_singleton] at h rcases h with (rfl | rfl | rfl) · exact le_rfl · exact WithTop.coe_le_coe.mpr hkm.le · exact WithTop.coe_le_coe.mpr (hkm.trans hmn).le #align polynomial.trinomial_nat_trailing_degree Polynomial.trinomial_natTrailingDegree theorem trinomial_leadingCoeff (hkm : k < m) (hmn : m < n) (hw : w ≠ 0) : (trinomial k m n u v w).leadingCoeff = w := by rw [leadingCoeff, trinomial_natDegree hkm hmn hw, trinomial_leading_coeff' hkm hmn] #align polynomial.trinomial_leading_coeff Polynomial.trinomial_leadingCoeff theorem trinomial_trailingCoeff (hkm : k < m) (hmn : m < n) (hu : u ≠ 0) : (trinomial k m n u v w).trailingCoeff = u := by rw [trailingCoeff, trinomial_natTrailingDegree hkm hmn hu, trinomial_trailing_coeff' hkm hmn] #align polynomial.trinomial_trailing_coeff Polynomial.trinomial_trailingCoeff theorem trinomial_monic (hkm : k < m) (hmn : m < n) : (trinomial k m n u v 1).Monic := by nontriviality R exact trinomial_leadingCoeff hkm hmn one_ne_zero #align polynomial.trinomial_monic Polynomial.trinomial_monic theorem trinomial_mirror (hkm : k < m) (hmn : m < n) (hu : u ≠ 0) (hw : w ≠ 0) : (trinomial k m n u v w).mirror = trinomial k (n - m + k) n w v u := by rw [mirror, trinomial_natTrailingDegree hkm hmn hu, reverse, trinomial_natDegree hkm hmn hw, trinomial_def, reflect_add, reflect_add, reflect_C_mul_X_pow, reflect_C_mul_X_pow, reflect_C_mul_X_pow, revAt_le (hkm.trans hmn).le, revAt_le hmn.le, revAt_le le_rfl, add_mul, add_mul, mul_assoc, mul_assoc, mul_assoc, ← pow_add, ← pow_add, ← pow_add, Nat.sub_add_cancel (hkm.trans hmn).le, Nat.sub_self, zero_add, add_comm, add_comm (C u * X ^ n), ← add_assoc, ← trinomial_def] #align polynomial.trinomial_mirror Polynomial.trinomial_mirror theorem trinomial_support (hkm : k < m) (hmn : m < n) (hu : u ≠ 0) (hv : v ≠ 0) (hw : w ≠ 0) : (trinomial k m n u v w).support = {k, m, n} := support_trinomial hkm hmn hu hv hw #align polynomial.trinomial_support Polynomial.trinomial_support end Semiring variable (p q : ℤ[X]) /-- A unit trinomial is a trinomial with unit coefficients. -/ def IsUnitTrinomial := ∃ (k m n : ℕ) (_ : k < m) (_ : m < n) (u v w : Units ℤ), p = trinomial k m n (u : ℤ) v w #align polynomial.is_unit_trinomial Polynomial.IsUnitTrinomial variable {p q} namespace IsUnitTrinomial
Mathlib/Algebra/Polynomial/UnitTrinomial.lean
138
143
theorem not_isUnit (hp : p.IsUnitTrinomial) : ¬IsUnit p := by
obtain ⟨k, m, n, hkm, hmn, u, v, w, rfl⟩ := hp exact fun h => ne_zero_of_lt hmn ((trinomial_natDegree hkm hmn w.ne_zero).symm.trans (natDegree_eq_of_degree_eq_some (degree_eq_zero_of_isUnit h)))
/- 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, Jeremy Avigad -/ import Mathlib.Order.Filter.Lift import Mathlib.Topology.Defs.Filter #align_import topology.basic from "leanprover-community/mathlib"@"e354e865255654389cc46e6032160238df2e0f40" /-! # Basic theory of topological spaces. The main definition is the type class `TopologicalSpace X` which endows a type `X` with a topology. Then `Set X` gets predicates `IsOpen`, `IsClosed` and functions `interior`, `closure` and `frontier`. Each point `x` of `X` gets a neighborhood filter `𝓝 x`. A filter `F` on `X` has `x` as a cluster point if `ClusterPt x F : 𝓝 x ⊓ F ≠ ⊥`. A map `f : α → X` clusters at `x` along `F : Filter α` if `MapClusterPt x F f : ClusterPt x (map f F)`. In particular the notion of cluster point of a sequence `u` is `MapClusterPt x atTop u`. For topological spaces `X` and `Y`, a function `f : X → Y` and a point `x : X`, `ContinuousAt f x` means `f` is continuous at `x`, and global continuity is `Continuous f`. There is also a version of continuity `PContinuous` for partially defined functions. ## Notation The following notation is introduced elsewhere and it heavily used in this file. * `𝓝 x`: the filter `nhds x` of neighborhoods of a point `x`; * `𝓟 s`: the principal filter of a set `s`; * `𝓝[s] x`: the filter `nhdsWithin x s` of neighborhoods of a point `x` within a set `s`; * `𝓝[≠] x`: the filter `nhdsWithin x {x}ᶜ` of punctured neighborhoods of `x`. ## Implementation notes Topology in mathlib heavily uses filters (even more than in Bourbaki). See explanations in <https://leanprover-community.github.io/theories/topology.html>. ## References * [N. Bourbaki, *General Topology*][bourbaki1966] * [I. M. James, *Topologies and Uniformities*][james1999] ## Tags topological space, interior, closure, frontier, neighborhood, continuity, continuous function -/ noncomputable section open Set Filter universe u v w x /-! ### Topological spaces -/ /-- A constructor for topologies by specifying the closed sets, and showing that they satisfy the appropriate conditions. -/ def TopologicalSpace.ofClosed {X : Type u} (T : Set (Set X)) (empty_mem : ∅ ∈ T) (sInter_mem : ∀ A, A ⊆ T → ⋂₀ A ∈ T) (union_mem : ∀ A, A ∈ T → ∀ B, B ∈ T → A ∪ B ∈ T) : TopologicalSpace X where IsOpen X := Xᶜ ∈ T isOpen_univ := by simp [empty_mem] isOpen_inter s t hs ht := by simpa only [compl_inter] using union_mem sᶜ hs tᶜ ht isOpen_sUnion s hs := by simp only [Set.compl_sUnion] exact sInter_mem (compl '' s) fun z ⟨y, hy, hz⟩ => hz ▸ hs y hy #align topological_space.of_closed TopologicalSpace.ofClosed section TopologicalSpace variable {X : Type u} {Y : Type v} {ι : Sort w} {α β : Type*} {x : X} {s s₁ s₂ t : Set X} {p p₁ p₂ : X → Prop} open Topology lemma isOpen_mk {p h₁ h₂ h₃} : IsOpen[⟨p, h₁, h₂, h₃⟩] s ↔ p s := Iff.rfl #align is_open_mk isOpen_mk @[ext] protected theorem TopologicalSpace.ext : ∀ {f g : TopologicalSpace X}, IsOpen[f] = IsOpen[g] → f = g | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl #align topological_space_eq TopologicalSpace.ext section variable [TopologicalSpace X] end protected theorem TopologicalSpace.ext_iff {t t' : TopologicalSpace X} : t = t' ↔ ∀ s, IsOpen[t] s ↔ IsOpen[t'] s := ⟨fun h s => h ▸ Iff.rfl, fun h => by ext; exact h _⟩ #align topological_space_eq_iff TopologicalSpace.ext_iff theorem isOpen_fold {t : TopologicalSpace X} : t.IsOpen s = IsOpen[t] s := rfl #align is_open_fold isOpen_fold variable [TopologicalSpace X] theorem isOpen_iUnion {f : ι → Set X} (h : ∀ i, IsOpen (f i)) : IsOpen (⋃ i, f i) := isOpen_sUnion (forall_mem_range.2 h) #align is_open_Union isOpen_iUnion theorem isOpen_biUnion {s : Set α} {f : α → Set X} (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋃ i ∈ s, f i) := isOpen_iUnion fun i => isOpen_iUnion fun hi => h i hi #align is_open_bUnion isOpen_biUnion theorem IsOpen.union (h₁ : IsOpen s₁) (h₂ : IsOpen s₂) : IsOpen (s₁ ∪ s₂) := by rw [union_eq_iUnion]; exact isOpen_iUnion (Bool.forall_bool.2 ⟨h₂, h₁⟩) #align is_open.union IsOpen.union lemma isOpen_iff_of_cover {f : α → Set X} (ho : ∀ i, IsOpen (f i)) (hU : (⋃ i, f i) = univ) : IsOpen s ↔ ∀ i, IsOpen (f i ∩ s) := by refine ⟨fun h i ↦ (ho i).inter h, fun h ↦ ?_⟩ rw [← s.inter_univ, inter_comm, ← hU, iUnion_inter] exact isOpen_iUnion fun i ↦ h i @[simp] theorem isOpen_empty : IsOpen (∅ : Set X) := by rw [← sUnion_empty]; exact isOpen_sUnion fun a => False.elim #align is_open_empty isOpen_empty theorem Set.Finite.isOpen_sInter {s : Set (Set X)} (hs : s.Finite) : (∀ t ∈ s, IsOpen t) → IsOpen (⋂₀ s) := Finite.induction_on hs (fun _ => by rw [sInter_empty]; exact isOpen_univ) fun _ _ ih h => by simp only [sInter_insert, forall_mem_insert] at h ⊢ exact h.1.inter (ih h.2) #align is_open_sInter Set.Finite.isOpen_sInter theorem Set.Finite.isOpen_biInter {s : Set α} {f : α → Set X} (hs : s.Finite) (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋂ i ∈ s, f i) := sInter_image f s ▸ (hs.image _).isOpen_sInter (forall_mem_image.2 h) #align is_open_bInter Set.Finite.isOpen_biInter theorem isOpen_iInter_of_finite [Finite ι] {s : ι → Set X} (h : ∀ i, IsOpen (s i)) : IsOpen (⋂ i, s i) := (finite_range _).isOpen_sInter (forall_mem_range.2 h) #align is_open_Inter isOpen_iInter_of_finite theorem isOpen_biInter_finset {s : Finset α} {f : α → Set X} (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋂ i ∈ s, f i) := s.finite_toSet.isOpen_biInter h #align is_open_bInter_finset isOpen_biInter_finset @[simp] -- Porting note: added `simp` theorem isOpen_const {p : Prop} : IsOpen { _x : X | p } := by by_cases p <;> simp [*] #align is_open_const isOpen_const theorem IsOpen.and : IsOpen { x | p₁ x } → IsOpen { x | p₂ x } → IsOpen { x | p₁ x ∧ p₂ x } := IsOpen.inter #align is_open.and IsOpen.and @[simp] theorem isOpen_compl_iff : IsOpen sᶜ ↔ IsClosed s := ⟨fun h => ⟨h⟩, fun h => h.isOpen_compl⟩ #align is_open_compl_iff isOpen_compl_iff theorem TopologicalSpace.ext_iff_isClosed {t₁ t₂ : TopologicalSpace X} : t₁ = t₂ ↔ ∀ s, IsClosed[t₁] s ↔ IsClosed[t₂] s := by rw [TopologicalSpace.ext_iff, compl_surjective.forall] simp only [@isOpen_compl_iff _ _ t₁, @isOpen_compl_iff _ _ t₂] alias ⟨_, TopologicalSpace.ext_isClosed⟩ := TopologicalSpace.ext_iff_isClosed -- Porting note (#10756): new lemma theorem isClosed_const {p : Prop} : IsClosed { _x : X | p } := ⟨isOpen_const (p := ¬p)⟩ @[simp] theorem isClosed_empty : IsClosed (∅ : Set X) := isClosed_const #align is_closed_empty isClosed_empty @[simp] theorem isClosed_univ : IsClosed (univ : Set X) := isClosed_const #align is_closed_univ isClosed_univ theorem IsClosed.union : IsClosed s₁ → IsClosed s₂ → IsClosed (s₁ ∪ s₂) := by simpa only [← isOpen_compl_iff, compl_union] using IsOpen.inter #align is_closed.union IsClosed.union theorem isClosed_sInter {s : Set (Set X)} : (∀ t ∈ s, IsClosed t) → IsClosed (⋂₀ s) := by simpa only [← isOpen_compl_iff, compl_sInter, sUnion_image] using isOpen_biUnion #align is_closed_sInter isClosed_sInter theorem isClosed_iInter {f : ι → Set X} (h : ∀ i, IsClosed (f i)) : IsClosed (⋂ i, f i) := isClosed_sInter <| forall_mem_range.2 h #align is_closed_Inter isClosed_iInter theorem isClosed_biInter {s : Set α} {f : α → Set X} (h : ∀ i ∈ s, IsClosed (f i)) : IsClosed (⋂ i ∈ s, f i) := isClosed_iInter fun i => isClosed_iInter <| h i #align is_closed_bInter isClosed_biInter @[simp] theorem isClosed_compl_iff {s : Set X} : IsClosed sᶜ ↔ IsOpen s := by rw [← isOpen_compl_iff, compl_compl] #align is_closed_compl_iff isClosed_compl_iff alias ⟨_, IsOpen.isClosed_compl⟩ := isClosed_compl_iff #align is_open.is_closed_compl IsOpen.isClosed_compl theorem IsOpen.sdiff (h₁ : IsOpen s) (h₂ : IsClosed t) : IsOpen (s \ t) := IsOpen.inter h₁ h₂.isOpen_compl #align is_open.sdiff IsOpen.sdiff theorem IsClosed.inter (h₁ : IsClosed s₁) (h₂ : IsClosed s₂) : IsClosed (s₁ ∩ s₂) := by rw [← isOpen_compl_iff] at * rw [compl_inter] exact IsOpen.union h₁ h₂ #align is_closed.inter IsClosed.inter theorem IsClosed.sdiff (h₁ : IsClosed s) (h₂ : IsOpen t) : IsClosed (s \ t) := IsClosed.inter h₁ (isClosed_compl_iff.mpr h₂) #align is_closed.sdiff IsClosed.sdiff theorem Set.Finite.isClosed_biUnion {s : Set α} {f : α → Set X} (hs : s.Finite) (h : ∀ i ∈ s, IsClosed (f i)) : IsClosed (⋃ i ∈ s, f i) := by simp only [← isOpen_compl_iff, compl_iUnion] at * exact hs.isOpen_biInter h #align is_closed_bUnion Set.Finite.isClosed_biUnion lemma isClosed_biUnion_finset {s : Finset α} {f : α → Set X} (h : ∀ i ∈ s, IsClosed (f i)) : IsClosed (⋃ i ∈ s, f i) := s.finite_toSet.isClosed_biUnion h theorem isClosed_iUnion_of_finite [Finite ι] {s : ι → Set X} (h : ∀ i, IsClosed (s i)) : IsClosed (⋃ i, s i) := by simp only [← isOpen_compl_iff, compl_iUnion] at * exact isOpen_iInter_of_finite h #align is_closed_Union isClosed_iUnion_of_finite theorem isClosed_imp {p q : X → Prop} (hp : IsOpen { x | p x }) (hq : IsClosed { x | q x }) : IsClosed { x | p x → q x } := by simpa only [imp_iff_not_or] using hp.isClosed_compl.union hq #align is_closed_imp isClosed_imp theorem IsClosed.not : IsClosed { a | p a } → IsOpen { a | ¬p a } := isOpen_compl_iff.mpr #align is_closed.not IsClosed.not /-! ### Interior of a set -/ theorem mem_interior : x ∈ interior s ↔ ∃ t ⊆ s, IsOpen t ∧ x ∈ t := by simp only [interior, mem_sUnion, mem_setOf_eq, and_assoc, and_left_comm] #align mem_interior mem_interiorₓ @[simp] theorem isOpen_interior : IsOpen (interior s) := isOpen_sUnion fun _ => And.left #align is_open_interior isOpen_interior theorem interior_subset : interior s ⊆ s := sUnion_subset fun _ => And.right #align interior_subset interior_subset theorem interior_maximal (h₁ : t ⊆ s) (h₂ : IsOpen t) : t ⊆ interior s := subset_sUnion_of_mem ⟨h₂, h₁⟩ #align interior_maximal interior_maximal theorem IsOpen.interior_eq (h : IsOpen s) : interior s = s := interior_subset.antisymm (interior_maximal (Subset.refl s) h) #align is_open.interior_eq IsOpen.interior_eq theorem interior_eq_iff_isOpen : interior s = s ↔ IsOpen s := ⟨fun h => h ▸ isOpen_interior, IsOpen.interior_eq⟩ #align interior_eq_iff_is_open interior_eq_iff_isOpen theorem subset_interior_iff_isOpen : s ⊆ interior s ↔ IsOpen s := by simp only [interior_eq_iff_isOpen.symm, Subset.antisymm_iff, interior_subset, true_and] #align subset_interior_iff_is_open subset_interior_iff_isOpen theorem IsOpen.subset_interior_iff (h₁ : IsOpen s) : s ⊆ interior t ↔ s ⊆ t := ⟨fun h => Subset.trans h interior_subset, fun h₂ => interior_maximal h₂ h₁⟩ #align is_open.subset_interior_iff IsOpen.subset_interior_iff theorem subset_interior_iff : t ⊆ interior s ↔ ∃ U, IsOpen U ∧ t ⊆ U ∧ U ⊆ s := ⟨fun h => ⟨interior s, isOpen_interior, h, interior_subset⟩, fun ⟨_U, hU, htU, hUs⟩ => htU.trans (interior_maximal hUs hU)⟩ #align subset_interior_iff subset_interior_iff lemma interior_subset_iff : interior s ⊆ t ↔ ∀ U, IsOpen U → U ⊆ s → U ⊆ t := by simp [interior] @[mono, gcongr] theorem interior_mono (h : s ⊆ t) : interior s ⊆ interior t := interior_maximal (Subset.trans interior_subset h) isOpen_interior #align interior_mono interior_mono @[simp] theorem interior_empty : interior (∅ : Set X) = ∅ := isOpen_empty.interior_eq #align interior_empty interior_empty @[simp] theorem interior_univ : interior (univ : Set X) = univ := isOpen_univ.interior_eq #align interior_univ interior_univ @[simp] theorem interior_eq_univ : interior s = univ ↔ s = univ := ⟨fun h => univ_subset_iff.mp <| h.symm.trans_le interior_subset, fun h => h.symm ▸ interior_univ⟩ #align interior_eq_univ interior_eq_univ @[simp] theorem interior_interior : interior (interior s) = interior s := isOpen_interior.interior_eq #align interior_interior interior_interior @[simp] theorem interior_inter : interior (s ∩ t) = interior s ∩ interior t := (Monotone.map_inf_le (fun _ _ ↦ interior_mono) s t).antisymm <| interior_maximal (inter_subset_inter interior_subset interior_subset) <| isOpen_interior.inter isOpen_interior #align interior_inter interior_inter theorem Set.Finite.interior_biInter {ι : Type*} {s : Set ι} (hs : s.Finite) (f : ι → Set X) : interior (⋂ i ∈ s, f i) = ⋂ i ∈ s, interior (f i) := hs.induction_on (by simp) <| by intros; simp [*] theorem Set.Finite.interior_sInter {S : Set (Set X)} (hS : S.Finite) : interior (⋂₀ S) = ⋂ s ∈ S, interior s := by rw [sInter_eq_biInter, hS.interior_biInter] @[simp] theorem Finset.interior_iInter {ι : Type*} (s : Finset ι) (f : ι → Set X) : interior (⋂ i ∈ s, f i) = ⋂ i ∈ s, interior (f i) := s.finite_toSet.interior_biInter f #align finset.interior_Inter Finset.interior_iInter @[simp] theorem interior_iInter_of_finite [Finite ι] (f : ι → Set X) : interior (⋂ i, f i) = ⋂ i, interior (f i) := by rw [← sInter_range, (finite_range f).interior_sInter, biInter_range] #align interior_Inter interior_iInter_of_finite theorem interior_union_isClosed_of_interior_empty (h₁ : IsClosed s) (h₂ : interior t = ∅) : interior (s ∪ t) = interior s := have : interior (s ∪ t) ⊆ s := fun x ⟨u, ⟨(hu₁ : IsOpen u), (hu₂ : u ⊆ s ∪ t)⟩, (hx₁ : x ∈ u)⟩ => by_contradiction fun hx₂ : x ∉ s => have : u \ s ⊆ t := fun x ⟨h₁, h₂⟩ => Or.resolve_left (hu₂ h₁) h₂ have : u \ s ⊆ interior t := by rwa [(IsOpen.sdiff hu₁ h₁).subset_interior_iff] have : u \ s ⊆ ∅ := by rwa [h₂] at this this ⟨hx₁, hx₂⟩ Subset.antisymm (interior_maximal this isOpen_interior) (interior_mono subset_union_left) #align interior_union_is_closed_of_interior_empty interior_union_isClosed_of_interior_empty theorem isOpen_iff_forall_mem_open : IsOpen s ↔ ∀ x ∈ s, ∃ t, t ⊆ s ∧ IsOpen t ∧ x ∈ t := by rw [← subset_interior_iff_isOpen] simp only [subset_def, mem_interior] #align is_open_iff_forall_mem_open isOpen_iff_forall_mem_open theorem interior_iInter_subset (s : ι → Set X) : interior (⋂ i, s i) ⊆ ⋂ i, interior (s i) := subset_iInter fun _ => interior_mono <| iInter_subset _ _ #align interior_Inter_subset interior_iInter_subset theorem interior_iInter₂_subset (p : ι → Sort*) (s : ∀ i, p i → Set X) : interior (⋂ (i) (j), s i j) ⊆ ⋂ (i) (j), interior (s i j) := (interior_iInter_subset _).trans <| iInter_mono fun _ => interior_iInter_subset _ #align interior_Inter₂_subset interior_iInter₂_subset theorem interior_sInter_subset (S : Set (Set X)) : interior (⋂₀ S) ⊆ ⋂ s ∈ S, interior s := calc interior (⋂₀ S) = interior (⋂ s ∈ S, s) := by rw [sInter_eq_biInter] _ ⊆ ⋂ s ∈ S, interior s := interior_iInter₂_subset _ _ #align interior_sInter_subset interior_sInter_subset theorem Filter.HasBasis.lift'_interior {l : Filter X} {p : ι → Prop} {s : ι → Set X} (h : l.HasBasis p s) : (l.lift' interior).HasBasis p fun i => interior (s i) := h.lift' fun _ _ ↦ interior_mono theorem Filter.lift'_interior_le (l : Filter X) : l.lift' interior ≤ l := fun _s hs ↦ mem_of_superset (mem_lift' hs) interior_subset theorem Filter.HasBasis.lift'_interior_eq_self {l : Filter X} {p : ι → Prop} {s : ι → Set X} (h : l.HasBasis p s) (ho : ∀ i, p i → IsOpen (s i)) : l.lift' interior = l := le_antisymm l.lift'_interior_le <| h.lift'_interior.ge_iff.2 fun i hi ↦ by simpa only [(ho i hi).interior_eq] using h.mem_of_mem hi /-! ### Closure of a set -/ @[simp] theorem isClosed_closure : IsClosed (closure s) := isClosed_sInter fun _ => And.left #align is_closed_closure isClosed_closure theorem subset_closure : s ⊆ closure s := subset_sInter fun _ => And.right #align subset_closure subset_closure theorem not_mem_of_not_mem_closure {P : X} (hP : P ∉ closure s) : P ∉ s := fun h => hP (subset_closure h) #align not_mem_of_not_mem_closure not_mem_of_not_mem_closure theorem closure_minimal (h₁ : s ⊆ t) (h₂ : IsClosed t) : closure s ⊆ t := sInter_subset_of_mem ⟨h₂, h₁⟩ #align closure_minimal closure_minimal theorem Disjoint.closure_left (hd : Disjoint s t) (ht : IsOpen t) : Disjoint (closure s) t := disjoint_compl_left.mono_left <| closure_minimal hd.subset_compl_right ht.isClosed_compl #align disjoint.closure_left Disjoint.closure_left theorem Disjoint.closure_right (hd : Disjoint s t) (hs : IsOpen s) : Disjoint s (closure t) := (hd.symm.closure_left hs).symm #align disjoint.closure_right Disjoint.closure_right theorem IsClosed.closure_eq (h : IsClosed s) : closure s = s := Subset.antisymm (closure_minimal (Subset.refl s) h) subset_closure #align is_closed.closure_eq IsClosed.closure_eq theorem IsClosed.closure_subset (hs : IsClosed s) : closure s ⊆ s := closure_minimal (Subset.refl _) hs #align is_closed.closure_subset IsClosed.closure_subset theorem IsClosed.closure_subset_iff (h₁ : IsClosed t) : closure s ⊆ t ↔ s ⊆ t := ⟨Subset.trans subset_closure, fun h => closure_minimal h h₁⟩ #align is_closed.closure_subset_iff IsClosed.closure_subset_iff theorem IsClosed.mem_iff_closure_subset (hs : IsClosed s) : x ∈ s ↔ closure ({x} : Set X) ⊆ s := (hs.closure_subset_iff.trans Set.singleton_subset_iff).symm #align is_closed.mem_iff_closure_subset IsClosed.mem_iff_closure_subset @[mono, gcongr] theorem closure_mono (h : s ⊆ t) : closure s ⊆ closure t := closure_minimal (Subset.trans h subset_closure) isClosed_closure #align closure_mono closure_mono theorem monotone_closure (X : Type*) [TopologicalSpace X] : Monotone (@closure X _) := fun _ _ => closure_mono #align monotone_closure monotone_closure theorem diff_subset_closure_iff : s \ t ⊆ closure t ↔ s ⊆ closure t := by rw [diff_subset_iff, union_eq_self_of_subset_left subset_closure] #align diff_subset_closure_iff diff_subset_closure_iff theorem closure_inter_subset_inter_closure (s t : Set X) : closure (s ∩ t) ⊆ closure s ∩ closure t := (monotone_closure X).map_inf_le s t #align closure_inter_subset_inter_closure closure_inter_subset_inter_closure theorem isClosed_of_closure_subset (h : closure s ⊆ s) : IsClosed s := by rw [subset_closure.antisymm h]; exact isClosed_closure #align is_closed_of_closure_subset isClosed_of_closure_subset theorem closure_eq_iff_isClosed : closure s = s ↔ IsClosed s := ⟨fun h => h ▸ isClosed_closure, IsClosed.closure_eq⟩ #align closure_eq_iff_is_closed closure_eq_iff_isClosed theorem closure_subset_iff_isClosed : closure s ⊆ s ↔ IsClosed s := ⟨isClosed_of_closure_subset, IsClosed.closure_subset⟩ #align closure_subset_iff_is_closed closure_subset_iff_isClosed @[simp] theorem closure_empty : closure (∅ : Set X) = ∅ := isClosed_empty.closure_eq #align closure_empty closure_empty @[simp] theorem closure_empty_iff (s : Set X) : closure s = ∅ ↔ s = ∅ := ⟨subset_eq_empty subset_closure, fun h => h.symm ▸ closure_empty⟩ #align closure_empty_iff closure_empty_iff @[simp] theorem closure_nonempty_iff : (closure s).Nonempty ↔ s.Nonempty := by simp only [nonempty_iff_ne_empty, Ne, closure_empty_iff] #align closure_nonempty_iff closure_nonempty_iff alias ⟨Set.Nonempty.of_closure, Set.Nonempty.closure⟩ := closure_nonempty_iff #align set.nonempty.of_closure Set.Nonempty.of_closure #align set.nonempty.closure Set.Nonempty.closure @[simp] theorem closure_univ : closure (univ : Set X) = univ := isClosed_univ.closure_eq #align closure_univ closure_univ @[simp] theorem closure_closure : closure (closure s) = closure s := isClosed_closure.closure_eq #align closure_closure closure_closure theorem closure_eq_compl_interior_compl : closure s = (interior sᶜ)ᶜ := by rw [interior, closure, compl_sUnion, compl_image_set_of] simp only [compl_subset_compl, isOpen_compl_iff] #align closure_eq_compl_interior_compl closure_eq_compl_interior_compl @[simp] theorem closure_union : closure (s ∪ t) = closure s ∪ closure t := by simp [closure_eq_compl_interior_compl, compl_inter] #align closure_union closure_union theorem Set.Finite.closure_biUnion {ι : Type*} {s : Set ι} (hs : s.Finite) (f : ι → Set X) : closure (⋃ i ∈ s, f i) = ⋃ i ∈ s, closure (f i) := by simp [closure_eq_compl_interior_compl, hs.interior_biInter]
Mathlib/Topology/Basic.lean
506
508
theorem Set.Finite.closure_sUnion {S : Set (Set X)} (hS : S.Finite) : closure (⋃₀ S) = ⋃ s ∈ S, closure s := by
rw [sUnion_eq_biUnion, hS.closure_biUnion]
/- Copyright (c) 2022 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Analysis.Asymptotics.Asymptotics import Mathlib.Analysis.NormedSpace.Basic #align_import analysis.asymptotics.theta from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Asymptotic equivalence up to a constant In this file we define `Asymptotics.IsTheta l f g` (notation: `f =Θ[l] g`) as `f =O[l] g ∧ g =O[l] f`, then prove basic properties of this equivalence relation. -/ open Filter open Topology namespace Asymptotics set_option linter.uppercaseLean3 false -- is_Theta variable {α : Type*} {β : Type*} {E : Type*} {F : Type*} {G : Type*} {E' : Type*} {F' : Type*} {G' : Type*} {E'' : Type*} {F'' : Type*} {G'' : Type*} {R : Type*} {R' : Type*} {𝕜 : Type*} {𝕜' : Type*} variable [Norm E] [Norm F] [Norm G] variable [SeminormedAddCommGroup E'] [SeminormedAddCommGroup F'] [SeminormedAddCommGroup G'] [NormedAddCommGroup E''] [NormedAddCommGroup F''] [NormedAddCommGroup G''] [SeminormedRing R] [SeminormedRing R'] variable [NormedField 𝕜] [NormedField 𝕜'] variable {c c' c₁ c₂ : ℝ} {f : α → E} {g : α → F} {k : α → G} variable {f' : α → E'} {g' : α → F'} {k' : α → G'} variable {f'' : α → E''} {g'' : α → F''} variable {l l' : Filter α} /-- We say that `f` is `Θ(g)` along a filter `l` (notation: `f =Θ[l] g`) if `f =O[l] g` and `g =O[l] f`. -/ def IsTheta (l : Filter α) (f : α → E) (g : α → F) : Prop := IsBigO l f g ∧ IsBigO l g f #align asymptotics.is_Theta Asymptotics.IsTheta @[inherit_doc] notation:100 f " =Θ[" l "] " g:100 => IsTheta l f g theorem IsBigO.antisymm (h₁ : f =O[l] g) (h₂ : g =O[l] f) : f =Θ[l] g := ⟨h₁, h₂⟩ #align asymptotics.is_O.antisymm Asymptotics.IsBigO.antisymm lemma IsTheta.isBigO (h : f =Θ[l] g) : f =O[l] g := h.1 lemma IsTheta.isBigO_symm (h : f =Θ[l] g) : g =O[l] f := h.2 @[refl] theorem isTheta_refl (f : α → E) (l : Filter α) : f =Θ[l] f := ⟨isBigO_refl _ _, isBigO_refl _ _⟩ #align asymptotics.is_Theta_refl Asymptotics.isTheta_refl theorem isTheta_rfl : f =Θ[l] f := isTheta_refl _ _ #align asymptotics.is_Theta_rfl Asymptotics.isTheta_rfl @[symm] nonrec theorem IsTheta.symm (h : f =Θ[l] g) : g =Θ[l] f := h.symm #align asymptotics.is_Theta.symm Asymptotics.IsTheta.symm theorem isTheta_comm : f =Θ[l] g ↔ g =Θ[l] f := ⟨fun h ↦ h.symm, fun h ↦ h.symm⟩ #align asymptotics.is_Theta_comm Asymptotics.isTheta_comm @[trans] theorem IsTheta.trans {f : α → E} {g : α → F'} {k : α → G} (h₁ : f =Θ[l] g) (h₂ : g =Θ[l] k) : f =Θ[l] k := ⟨h₁.1.trans h₂.1, h₂.2.trans h₁.2⟩ #align asymptotics.is_Theta.trans Asymptotics.IsTheta.trans -- Porting note (#10754): added instance instance : Trans (α := α → E) (β := α → F') (γ := α → G) (IsTheta l) (IsTheta l) (IsTheta l) := ⟨IsTheta.trans⟩ @[trans] theorem IsBigO.trans_isTheta {f : α → E} {g : α → F'} {k : α → G} (h₁ : f =O[l] g) (h₂ : g =Θ[l] k) : f =O[l] k := h₁.trans h₂.1 #align asymptotics.is_O.trans_is_Theta Asymptotics.IsBigO.trans_isTheta -- Porting note (#10754): added instance instance : Trans (α := α → E) (β := α → F') (γ := α → G) (IsBigO l) (IsTheta l) (IsBigO l) := ⟨IsBigO.trans_isTheta⟩ @[trans] theorem IsTheta.trans_isBigO {f : α → E} {g : α → F'} {k : α → G} (h₁ : f =Θ[l] g) (h₂ : g =O[l] k) : f =O[l] k := h₁.1.trans h₂ #align asymptotics.is_Theta.trans_is_O Asymptotics.IsTheta.trans_isBigO -- Porting note (#10754): added instance instance : Trans (α := α → E) (β := α → F') (γ := α → G) (IsTheta l) (IsBigO l) (IsBigO l) := ⟨IsTheta.trans_isBigO⟩ @[trans] theorem IsLittleO.trans_isTheta {f : α → E} {g : α → F} {k : α → G'} (h₁ : f =o[l] g) (h₂ : g =Θ[l] k) : f =o[l] k := h₁.trans_isBigO h₂.1 #align asymptotics.is_o.trans_is_Theta Asymptotics.IsLittleO.trans_isTheta -- Porting note (#10754): added instance instance : Trans (α := α → E) (β := α → F') (γ := α → G') (IsLittleO l) (IsTheta l) (IsLittleO l) := ⟨IsLittleO.trans_isTheta⟩ @[trans] theorem IsTheta.trans_isLittleO {f : α → E} {g : α → F'} {k : α → G} (h₁ : f =Θ[l] g) (h₂ : g =o[l] k) : f =o[l] k := h₁.1.trans_isLittleO h₂ #align asymptotics.is_Theta.trans_is_o Asymptotics.IsTheta.trans_isLittleO -- Porting note (#10754): added instance instance : Trans (α := α → E) (β := α → F') (γ := α → G) (IsTheta l) (IsLittleO l) (IsLittleO l) := ⟨IsTheta.trans_isLittleO⟩ @[trans] theorem IsTheta.trans_eventuallyEq {f : α → E} {g₁ g₂ : α → F} (h : f =Θ[l] g₁) (hg : g₁ =ᶠ[l] g₂) : f =Θ[l] g₂ := ⟨h.1.trans_eventuallyEq hg, hg.symm.trans_isBigO h.2⟩ #align asymptotics.is_Theta.trans_eventually_eq Asymptotics.IsTheta.trans_eventuallyEq -- Porting note (#10754): added instance instance : Trans (α := α → E) (β := α → F) (γ := α → F) (IsTheta l) (EventuallyEq l) (IsTheta l) := ⟨IsTheta.trans_eventuallyEq⟩ @[trans] theorem _root_.Filter.EventuallyEq.trans_isTheta {f₁ f₂ : α → E} {g : α → F} (hf : f₁ =ᶠ[l] f₂) (h : f₂ =Θ[l] g) : f₁ =Θ[l] g := ⟨hf.trans_isBigO h.1, h.2.trans_eventuallyEq hf.symm⟩ #align filter.eventually_eq.trans_is_Theta Filter.EventuallyEq.trans_isTheta -- Porting note (#10754): added instance instance : Trans (α := α → E) (β := α → E) (γ := α → F) (EventuallyEq l) (IsTheta l) (IsTheta l) := ⟨EventuallyEq.trans_isTheta⟩ lemma _root_.Filter.EventuallyEq.isTheta {f g : α → E} (h : f =ᶠ[l] g) : f =Θ[l] g := h.trans_isTheta isTheta_rfl @[simp] theorem isTheta_norm_left : (fun x ↦ ‖f' x‖) =Θ[l] g ↔ f' =Θ[l] g := by simp [IsTheta] #align asymptotics.is_Theta_norm_left Asymptotics.isTheta_norm_left @[simp] theorem isTheta_norm_right : (f =Θ[l] fun x ↦ ‖g' x‖) ↔ f =Θ[l] g' := by simp [IsTheta] #align asymptotics.is_Theta_norm_right Asymptotics.isTheta_norm_right alias ⟨IsTheta.of_norm_left, IsTheta.norm_left⟩ := isTheta_norm_left #align asymptotics.is_Theta.of_norm_left Asymptotics.IsTheta.of_norm_left #align asymptotics.is_Theta.norm_left Asymptotics.IsTheta.norm_left alias ⟨IsTheta.of_norm_right, IsTheta.norm_right⟩ := isTheta_norm_right #align asymptotics.is_Theta.of_norm_right Asymptotics.IsTheta.of_norm_right #align asymptotics.is_Theta.norm_right Asymptotics.IsTheta.norm_right theorem isTheta_of_norm_eventuallyEq (h : (fun x ↦ ‖f x‖) =ᶠ[l] fun x ↦ ‖g x‖) : f =Θ[l] g := ⟨IsBigO.of_bound 1 <| by simpa only [one_mul] using h.le, IsBigO.of_bound 1 <| by simpa only [one_mul] using h.symm.le⟩ #align asymptotics.is_Theta_of_norm_eventually_eq Asymptotics.isTheta_of_norm_eventuallyEq theorem isTheta_of_norm_eventuallyEq' {g : α → ℝ} (h : (fun x ↦ ‖f' x‖) =ᶠ[l] g) : f' =Θ[l] g := isTheta_of_norm_eventuallyEq <| h.mono fun x hx ↦ by simp only [← hx, norm_norm] #align asymptotics.is_Theta_of_norm_eventually_eq' Asymptotics.isTheta_of_norm_eventuallyEq' theorem IsTheta.isLittleO_congr_left (h : f' =Θ[l] g') : f' =o[l] k ↔ g' =o[l] k := ⟨h.symm.trans_isLittleO, h.trans_isLittleO⟩ #align asymptotics.is_Theta.is_o_congr_left Asymptotics.IsTheta.isLittleO_congr_left theorem IsTheta.isLittleO_congr_right (h : g' =Θ[l] k') : f =o[l] g' ↔ f =o[l] k' := ⟨fun H ↦ H.trans_isTheta h, fun H ↦ H.trans_isTheta h.symm⟩ #align asymptotics.is_Theta.is_o_congr_right Asymptotics.IsTheta.isLittleO_congr_right theorem IsTheta.isBigO_congr_left (h : f' =Θ[l] g') : f' =O[l] k ↔ g' =O[l] k := ⟨h.symm.trans_isBigO, h.trans_isBigO⟩ #align asymptotics.is_Theta.is_O_congr_left Asymptotics.IsTheta.isBigO_congr_left theorem IsTheta.isBigO_congr_right (h : g' =Θ[l] k') : f =O[l] g' ↔ f =O[l] k' := ⟨fun H ↦ H.trans_isTheta h, fun H ↦ H.trans_isTheta h.symm⟩ #align asymptotics.is_Theta.is_O_congr_right Asymptotics.IsTheta.isBigO_congr_right lemma IsTheta.isTheta_congr_left (h : f' =Θ[l] g') : f' =Θ[l] k ↔ g' =Θ[l] k := h.isBigO_congr_left.and h.isBigO_congr_right lemma IsTheta.isTheta_congr_right (h : f' =Θ[l] g') : k =Θ[l] f' ↔ k =Θ[l] g' := h.isBigO_congr_right.and h.isBigO_congr_left theorem IsTheta.mono (h : f =Θ[l] g) (hl : l' ≤ l) : f =Θ[l'] g := ⟨h.1.mono hl, h.2.mono hl⟩ #align asymptotics.is_Theta.mono Asymptotics.IsTheta.mono theorem IsTheta.sup (h : f' =Θ[l] g') (h' : f' =Θ[l'] g') : f' =Θ[l ⊔ l'] g' := ⟨h.1.sup h'.1, h.2.sup h'.2⟩ #align asymptotics.is_Theta.sup Asymptotics.IsTheta.sup @[simp] theorem isTheta_sup : f' =Θ[l ⊔ l'] g' ↔ f' =Θ[l] g' ∧ f' =Θ[l'] g' := ⟨fun h ↦ ⟨h.mono le_sup_left, h.mono le_sup_right⟩, fun h ↦ h.1.sup h.2⟩ #align asymptotics.is_Theta_sup Asymptotics.isTheta_sup theorem IsTheta.eq_zero_iff (h : f'' =Θ[l] g'') : ∀ᶠ x in l, f'' x = 0 ↔ g'' x = 0 := h.1.eq_zero_imp.mp <| h.2.eq_zero_imp.mono fun _ ↦ Iff.intro #align asymptotics.is_Theta.eq_zero_iff Asymptotics.IsTheta.eq_zero_iff theorem IsTheta.tendsto_zero_iff (h : f'' =Θ[l] g'') : Tendsto f'' l (𝓝 0) ↔ Tendsto g'' l (𝓝 0) := by simp only [← isLittleO_one_iff ℝ, h.isLittleO_congr_left] #align asymptotics.is_Theta.tendsto_zero_iff Asymptotics.IsTheta.tendsto_zero_iff theorem IsTheta.tendsto_norm_atTop_iff (h : f' =Θ[l] g') : Tendsto (norm ∘ f') l atTop ↔ Tendsto (norm ∘ g') l atTop := by simp only [Function.comp, ← isLittleO_const_left_of_ne (one_ne_zero' ℝ), h.isLittleO_congr_right] #align asymptotics.is_Theta.tendsto_norm_at_top_iff Asymptotics.IsTheta.tendsto_norm_atTop_iff theorem IsTheta.isBoundedUnder_le_iff (h : f' =Θ[l] g') : IsBoundedUnder (· ≤ ·) l (norm ∘ f') ↔ IsBoundedUnder (· ≤ ·) l (norm ∘ g') := by simp only [← isBigO_const_of_ne (one_ne_zero' ℝ), h.isBigO_congr_left] #align asymptotics.is_Theta.is_bounded_under_le_iff Asymptotics.IsTheta.isBoundedUnder_le_iff theorem IsTheta.smul [NormedSpace 𝕜 E'] [NormedSpace 𝕜' F'] {f₁ : α → 𝕜} {f₂ : α → 𝕜'} {g₁ : α → E'} {g₂ : α → F'} (hf : f₁ =Θ[l] f₂) (hg : g₁ =Θ[l] g₂) : (fun x ↦ f₁ x • g₁ x) =Θ[l] fun x ↦ f₂ x • g₂ x := ⟨hf.1.smul hg.1, hf.2.smul hg.2⟩ #align asymptotics.is_Theta.smul Asymptotics.IsTheta.smul theorem IsTheta.mul {f₁ f₂ : α → 𝕜} {g₁ g₂ : α → 𝕜'} (h₁ : f₁ =Θ[l] g₁) (h₂ : f₂ =Θ[l] g₂) : (fun x ↦ f₁ x * f₂ x) =Θ[l] fun x ↦ g₁ x * g₂ x := h₁.smul h₂ #align asymptotics.is_Theta.mul Asymptotics.IsTheta.mul theorem IsTheta.inv {f : α → 𝕜} {g : α → 𝕜'} (h : f =Θ[l] g) : (fun x ↦ (f x)⁻¹) =Θ[l] fun x ↦ (g x)⁻¹ := ⟨h.2.inv_rev h.1.eq_zero_imp, h.1.inv_rev h.2.eq_zero_imp⟩ #align asymptotics.is_Theta.inv Asymptotics.IsTheta.inv @[simp] theorem isTheta_inv {f : α → 𝕜} {g : α → 𝕜'} : ((fun x ↦ (f x)⁻¹) =Θ[l] fun x ↦ (g x)⁻¹) ↔ f =Θ[l] g := ⟨fun h ↦ by simpa only [inv_inv] using h.inv, IsTheta.inv⟩ #align asymptotics.is_Theta_inv Asymptotics.isTheta_inv theorem IsTheta.div {f₁ f₂ : α → 𝕜} {g₁ g₂ : α → 𝕜'} (h₁ : f₁ =Θ[l] g₁) (h₂ : f₂ =Θ[l] g₂) : (fun x ↦ f₁ x / f₂ x) =Θ[l] fun x ↦ g₁ x / g₂ x := by simpa only [div_eq_mul_inv] using h₁.mul h₂.inv #align asymptotics.is_Theta.div Asymptotics.IsTheta.div theorem IsTheta.pow {f : α → 𝕜} {g : α → 𝕜'} (h : f =Θ[l] g) (n : ℕ) : (fun x ↦ f x ^ n) =Θ[l] fun x ↦ g x ^ n := ⟨h.1.pow n, h.2.pow n⟩ #align asymptotics.is_Theta.pow Asymptotics.IsTheta.pow
Mathlib/Analysis/Asymptotics/Theta.lean
261
265
theorem IsTheta.zpow {f : α → 𝕜} {g : α → 𝕜'} (h : f =Θ[l] g) (n : ℤ) : (fun x ↦ f x ^ n) =Θ[l] fun x ↦ g x ^ n := by
cases n · simpa only [Int.ofNat_eq_coe, zpow_natCast] using h.pow _ · simpa only [zpow_negSucc] using (h.pow _).inv
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Ring.Divisibility.Lemmas import Mathlib.Algebra.Lie.Nilpotent import Mathlib.Algebra.Lie.Engel import Mathlib.LinearAlgebra.Eigenspace.Triangularizable import Mathlib.RingTheory.Artinian import Mathlib.LinearAlgebra.Trace import Mathlib.LinearAlgebra.FreeModule.PID #align_import algebra.lie.weights from "leanprover-community/mathlib"@"6b0169218d01f2837d79ea2784882009a0da1aa1" /-! # Weight spaces of Lie modules of nilpotent Lie algebras Just as a key tool when studying the behaviour of a linear operator is to decompose the space on which it acts into a sum of (generalised) eigenspaces, a key tool when studying a representation `M` of Lie algebra `L` is to decompose `M` into a sum of simultaneous eigenspaces of `x` as `x` ranges over `L`. These simultaneous generalised eigenspaces are known as the weight spaces of `M`. When `L` is nilpotent, it follows from the binomial theorem that weight spaces are Lie submodules. Basic definitions and properties of the above ideas are provided in this file. ## Main definitions * `LieModule.weightSpaceOf` * `LieModule.weightSpace` * `LieModule.Weight` * `LieModule.posFittingCompOf` * `LieModule.posFittingComp` * `LieModule.iSup_ucs_eq_weightSpace_zero` * `LieModule.iInf_lowerCentralSeries_eq_posFittingComp` * `LieModule.isCompl_weightSpace_zero_posFittingComp` * `LieModule.independent_weightSpace` * `LieModule.iSup_weightSpace_eq_top` ## References * [N. Bourbaki, *Lie Groups and Lie Algebras, Chapters 7--9*](bourbaki1975b) ## Tags lie character, eigenvalue, eigenspace, weight, weight vector, root, root vector -/ variable {K R L M : Type*} [CommRing R] [LieRing L] [LieAlgebra R L] [LieAlgebra.IsNilpotent R L] [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] namespace LieModule open Set Function LieAlgebra TensorProduct TensorProduct.LieModule open scoped TensorProduct section notation_weightSpaceOf /-- Until we define `LieModule.weightSpaceOf`, it is useful to have some notation as follows: -/ local notation3 "𝕎("M", " χ", " x")" => (toEnd R L M x).maxGenEigenspace χ /-- See also `bourbaki1975b` Chapter VII §1.1, Proposition 2 (ii). -/ protected theorem weight_vector_multiplication (M₁ M₂ M₃ : Type*) [AddCommGroup M₁] [Module R M₁] [LieRingModule L M₁] [LieModule R L M₁] [AddCommGroup M₂] [Module R M₂] [LieRingModule L M₂] [LieModule R L M₂] [AddCommGroup M₃] [Module R M₃] [LieRingModule L M₃] [LieModule R L M₃] (g : M₁ ⊗[R] M₂ →ₗ⁅R,L⁆ M₃) (χ₁ χ₂ : R) (x : L) : LinearMap.range ((g : M₁ ⊗[R] M₂ →ₗ[R] M₃).comp (mapIncl 𝕎(M₁, χ₁, x) 𝕎(M₂, χ₂, x))) ≤ 𝕎(M₃, χ₁ + χ₂, x) := by -- Unpack the statement of the goal. intro m₃ simp only [TensorProduct.mapIncl, LinearMap.mem_range, LinearMap.coe_comp, LieModuleHom.coe_toLinearMap, Function.comp_apply, Pi.add_apply, exists_imp, Module.End.mem_maxGenEigenspace] rintro t rfl -- Set up some notation. let F : Module.End R M₃ := toEnd R L M₃ x - (χ₁ + χ₂) • ↑1 -- The goal is linear in `t` so use induction to reduce to the case that `t` is a pure tensor. refine t.induction_on ?_ ?_ ?_ · use 0; simp only [LinearMap.map_zero, LieModuleHom.map_zero] swap · rintro t₁ t₂ ⟨k₁, hk₁⟩ ⟨k₂, hk₂⟩; use max k₁ k₂ simp only [LieModuleHom.map_add, LinearMap.map_add, LinearMap.pow_map_zero_of_le (le_max_left k₁ k₂) hk₁, LinearMap.pow_map_zero_of_le (le_max_right k₁ k₂) hk₂, add_zero] -- Now the main argument: pure tensors. rintro ⟨m₁, hm₁⟩ ⟨m₂, hm₂⟩ change ∃ k, (F ^ k) ((g : M₁ ⊗[R] M₂ →ₗ[R] M₃) (m₁ ⊗ₜ m₂)) = (0 : M₃) -- Eliminate `g` from the picture. let f₁ : Module.End R (M₁ ⊗[R] M₂) := (toEnd R L M₁ x - χ₁ • ↑1).rTensor M₂ let f₂ : Module.End R (M₁ ⊗[R] M₂) := (toEnd R L M₂ x - χ₂ • ↑1).lTensor M₁ have h_comm_square : F ∘ₗ ↑g = (g : M₁ ⊗[R] M₂ →ₗ[R] M₃).comp (f₁ + f₂) := by ext m₁ m₂; simp only [f₁, f₂, F, ← g.map_lie x (m₁ ⊗ₜ m₂), add_smul, sub_tmul, tmul_sub, smul_tmul, lie_tmul_right, tmul_smul, toEnd_apply_apply, LieModuleHom.map_smul, LinearMap.one_apply, LieModuleHom.coe_toLinearMap, LinearMap.smul_apply, Function.comp_apply, LinearMap.coe_comp, LinearMap.rTensor_tmul, LieModuleHom.map_add, LinearMap.add_apply, LieModuleHom.map_sub, LinearMap.sub_apply, LinearMap.lTensor_tmul, AlgebraTensorModule.curry_apply, TensorProduct.curry_apply, LinearMap.toFun_eq_coe, LinearMap.coe_restrictScalars] abel rsuffices ⟨k, hk⟩ : ∃ k : ℕ, ((f₁ + f₂) ^ k) (m₁ ⊗ₜ m₂) = 0 · use k change (F ^ k) (g.toLinearMap (m₁ ⊗ₜ[R] m₂)) = 0 rw [← LinearMap.comp_apply, LinearMap.commute_pow_left_of_commute h_comm_square, LinearMap.comp_apply, hk, LinearMap.map_zero] -- Unpack the information we have about `m₁`, `m₂`. simp only [Module.End.mem_maxGenEigenspace] at hm₁ hm₂ obtain ⟨k₁, hk₁⟩ := hm₁ obtain ⟨k₂, hk₂⟩ := hm₂ have hf₁ : (f₁ ^ k₁) (m₁ ⊗ₜ m₂) = 0 := by simp only [f₁, hk₁, zero_tmul, LinearMap.rTensor_tmul, LinearMap.rTensor_pow] have hf₂ : (f₂ ^ k₂) (m₁ ⊗ₜ m₂) = 0 := by simp only [f₂, hk₂, tmul_zero, LinearMap.lTensor_tmul, LinearMap.lTensor_pow] -- It's now just an application of the binomial theorem. use k₁ + k₂ - 1 have hf_comm : Commute f₁ f₂ := by ext m₁ m₂ simp only [f₁, f₂, LinearMap.mul_apply, LinearMap.rTensor_tmul, LinearMap.lTensor_tmul, AlgebraTensorModule.curry_apply, LinearMap.toFun_eq_coe, LinearMap.lTensor_tmul, TensorProduct.curry_apply, LinearMap.coe_restrictScalars] rw [hf_comm.add_pow'] simp only [TensorProduct.mapIncl, Submodule.subtype_apply, Finset.sum_apply, Submodule.coe_mk, LinearMap.coeFn_sum, TensorProduct.map_tmul, LinearMap.smul_apply] -- The required sum is zero because each individual term is zero. apply Finset.sum_eq_zero rintro ⟨i, j⟩ hij -- Eliminate the binomial coefficients from the picture. suffices (f₁ ^ i * f₂ ^ j) (m₁ ⊗ₜ m₂) = 0 by rw [this]; apply smul_zero -- Finish off with appropriate case analysis. cases' Nat.le_or_le_of_add_eq_add_pred (Finset.mem_antidiagonal.mp hij) with hi hj · rw [(hf_comm.pow_pow i j).eq, LinearMap.mul_apply, LinearMap.pow_map_zero_of_le hi hf₁, LinearMap.map_zero] · rw [LinearMap.mul_apply, LinearMap.pow_map_zero_of_le hj hf₂, LinearMap.map_zero] lemma lie_mem_maxGenEigenspace_toEnd {χ₁ χ₂ : R} {x y : L} {m : M} (hy : y ∈ 𝕎(L, χ₁, x)) (hm : m ∈ 𝕎(M, χ₂, x)) : ⁅y, m⁆ ∈ 𝕎(M, χ₁ + χ₂, x) := by apply LieModule.weight_vector_multiplication L M M (toModuleHom R L M) χ₁ χ₂ simp only [LieModuleHom.coe_toLinearMap, Function.comp_apply, LinearMap.coe_comp, TensorProduct.mapIncl, LinearMap.mem_range] use ⟨y, hy⟩ ⊗ₜ ⟨m, hm⟩ simp only [Submodule.subtype_apply, toModuleHom_apply, TensorProduct.map_tmul] variable (M) /-- If `M` is a representation of a nilpotent Lie algebra `L`, `χ` is a scalar, and `x : L`, then `weightSpaceOf M χ x` is the maximal generalized `χ`-eigenspace of the action of `x` on `M`. It is a Lie submodule because `L` is nilpotent. -/ def weightSpaceOf (χ : R) (x : L) : LieSubmodule R L M := { 𝕎(M, χ, x) with lie_mem := by intro y m hm simp only [AddSubsemigroup.mem_carrier, AddSubmonoid.mem_toSubsemigroup, Submodule.mem_toAddSubmonoid] at hm ⊢ rw [← zero_add χ] exact lie_mem_maxGenEigenspace_toEnd (by simp) hm } end notation_weightSpaceOf variable (M) theorem mem_weightSpaceOf (χ : R) (x : L) (m : M) : m ∈ weightSpaceOf M χ x ↔ ∃ k : ℕ, ((toEnd R L M x - χ • ↑1) ^ k) m = 0 := by simp [weightSpaceOf] theorem coe_weightSpaceOf_zero (x : L) : ↑(weightSpaceOf M (0 : R) x) = ⨆ k, LinearMap.ker (toEnd R L M x ^ k) := by simp [weightSpaceOf, Module.End.maxGenEigenspace] /-- If `M` is a representation of a nilpotent Lie algebra `L` and `χ : L → R` is a family of scalars, then `weightSpace M χ` is the intersection of the maximal generalized `χ x`-eigenspaces of the action of `x` on `M` as `x` ranges over `L`. It is a Lie submodule because `L` is nilpotent. -/ def weightSpace (χ : L → R) : LieSubmodule R L M := ⨅ x, weightSpaceOf M (χ x) x theorem mem_weightSpace (χ : L → R) (m : M) : m ∈ weightSpace M χ ↔ ∀ x, ∃ k : ℕ, ((toEnd R L M x - χ x • ↑1) ^ k) m = 0 := by simp [weightSpace, mem_weightSpaceOf] lemma weightSpace_le_weightSpaceOf (x : L) (χ : L → R) : weightSpace M χ ≤ weightSpaceOf M (χ x) x := iInf_le _ x variable (R L) in /-- A weight of a Lie module is a map `L → R` such that the corresponding weight space is non-trivial. -/ structure Weight where /-- The family of eigenvalues corresponding to a weight. -/ toFun : L → R weightSpace_ne_bot' : weightSpace M toFun ≠ ⊥ namespace Weight instance instFunLike : FunLike (Weight R L M) L R where coe χ := χ.1 coe_injective' χ₁ χ₂ h := by cases χ₁; cases χ₂; simp_all @[simp] lemma coe_weight_mk (χ : L → R) (h) : (↑(⟨χ, h⟩ : Weight R L M) : L → R) = χ := rfl lemma weightSpace_ne_bot (χ : Weight R L M) : weightSpace M χ ≠ ⊥ := χ.weightSpace_ne_bot' variable {M} @[ext] lemma ext {χ₁ χ₂ : Weight R L M} (h : ∀ x, χ₁ x = χ₂ x) : χ₁ = χ₂ := by cases' χ₁ with f₁ _; cases' χ₂ with f₂ _; aesop lemma ext_iff {χ₁ χ₂ : Weight R L M} : (χ₁ : L → R) = χ₂ ↔ χ₁ = χ₂ := by aesop lemma exists_ne_zero (χ : Weight R L M) : ∃ x ∈ weightSpace M χ, x ≠ 0 := by simpa [LieSubmodule.eq_bot_iff] using χ.weightSpace_ne_bot instance [Subsingleton M] : IsEmpty (Weight R L M) := ⟨fun h ↦ h.2 (Subsingleton.elim _ _)⟩ instance [Nontrivial (weightSpace M (0 : L → R))] : Zero (Weight R L M) := ⟨0, fun e ↦ not_nontrivial (⊥ : LieSubmodule R L M) (e ▸ ‹_›)⟩ @[simp] lemma coe_zero [Nontrivial (weightSpace M (0 : L → R))] : ((0 : Weight R L M) : L → R) = 0 := rfl lemma zero_apply [Nontrivial (weightSpace M (0 : L → R))] (x) : (0 : Weight R L M) x = 0 := rfl /-- The proposition that a weight of a Lie module is zero. We make this definition because we cannot define a `Zero (Weight R L M)` instance since the weight space of the zero function can be trivial. -/ def IsZero (χ : Weight R L M) := (χ : L → R) = 0 @[simp] lemma IsZero.eq {χ : Weight R L M} (hχ : χ.IsZero) : (χ : L → R) = 0 := hχ @[simp] lemma coe_eq_zero_iff (χ : Weight R L M) : (χ : L → R) = 0 ↔ χ.IsZero := Iff.rfl lemma isZero_iff_eq_zero [Nontrivial (weightSpace M (0 : L → R))] {χ : Weight R L M} : χ.IsZero ↔ χ = 0 := ext_iff (χ₂ := 0) lemma isZero_zero [Nontrivial (weightSpace M (0 : L → R))] : IsZero (0 : Weight R L M) := rfl /-- The proposition that a weight of a Lie module is non-zero. -/ abbrev IsNonZero (χ : Weight R L M) := ¬ IsZero (χ : Weight R L M) lemma isNonZero_iff_ne_zero [Nontrivial (weightSpace M (0 : L → R))] {χ : Weight R L M} : χ.IsNonZero ↔ χ ≠ 0 := isZero_iff_eq_zero.not variable (R L M) in /-- The set of weights is equivalent to a subtype. -/ def equivSetOf : Weight R L M ≃ {χ : L → R | weightSpace M χ ≠ ⊥} where toFun w := ⟨w.1, w.2⟩ invFun w := ⟨w.1, w.2⟩ left_inv w := by simp right_inv w := by simp lemma weightSpaceOf_ne_bot (χ : Weight R L M) (x : L) : weightSpaceOf M (χ x) x ≠ ⊥ := by have : ⨅ x, weightSpaceOf M (χ x) x ≠ ⊥ := χ.weightSpace_ne_bot contrapose! this rw [eq_bot_iff] exact le_of_le_of_eq (iInf_le _ _) this lemma hasEigenvalueAt (χ : Weight R L M) (x : L) : (toEnd R L M x).HasEigenvalue (χ x) := by obtain ⟨k : ℕ, hk : (toEnd R L M x).genEigenspace (χ x) k ≠ ⊥⟩ := by simpa [Module.End.maxGenEigenspace, weightSpaceOf] using χ.weightSpaceOf_ne_bot x exact Module.End.hasEigenvalue_of_hasGenEigenvalue hk lemma apply_eq_zero_of_isNilpotent [NoZeroSMulDivisors R M] [IsReduced R] (x : L) (h : _root_.IsNilpotent (toEnd R L M x)) (χ : Weight R L M) : χ x = 0 := ((χ.hasEigenvalueAt x).isNilpotent_of_isNilpotent h).eq_zero end Weight /-- See also the more useful form `LieModule.zero_weightSpace_eq_top_of_nilpotent`. -/ @[simp] theorem zero_weightSpace_eq_top_of_nilpotent' [IsNilpotent R L M] : weightSpace M (0 : L → R) = ⊤ := by ext simp [weightSpace, weightSpaceOf] #align lie_module.zero_weight_space_eq_top_of_nilpotent' LieModule.zero_weightSpace_eq_top_of_nilpotent'
Mathlib/Algebra/Lie/Weights/Basic.lean
287
292
theorem coe_weightSpace_of_top (χ : L → R) : (weightSpace M (χ ∘ (⊤ : LieSubalgebra R L).incl) : Submodule R M) = weightSpace M χ := by
ext m simp only [mem_weightSpace, LieSubmodule.mem_coeSubmodule, Subtype.forall] apply forall_congr' simp
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Data.Multiset.Nodup #align_import data.multiset.sum from "leanprover-community/mathlib"@"9003f28797c0664a49e4179487267c494477d853" /-! # Disjoint sum of multisets This file defines the disjoint sum of two multisets as `Multiset (α ⊕ β)`. Beware not to confuse with the `Multiset.sum` operation which computes the additive sum. ## Main declarations * `Multiset.disjSum`: `s.disjSum t` is the disjoint sum of `s` and `t`. -/ open Sum namespace Multiset variable {α β : Type*} (s : Multiset α) (t : Multiset β) /-- Disjoint sum of multisets. -/ def disjSum : Multiset (Sum α β) := s.map inl + t.map inr #align multiset.disj_sum Multiset.disjSum @[simp] theorem zero_disjSum : (0 : Multiset α).disjSum t = t.map inr := zero_add _ #align multiset.zero_disj_sum Multiset.zero_disjSum @[simp] theorem disjSum_zero : s.disjSum (0 : Multiset β) = s.map inl := add_zero _ #align multiset.disj_sum_zero Multiset.disjSum_zero @[simp]
Mathlib/Data/Multiset/Sum.lean
44
45
theorem card_disjSum : Multiset.card (s.disjSum t) = Multiset.card s + Multiset.card t := by
rw [disjSum, card_add, card_map, card_map]
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Julian Kuelshammer, Heather Macbeth, Mitchell Lee -/ import Mathlib.Algebra.Polynomial.Derivative import Mathlib.Tactic.LinearCombination #align_import ring_theory.polynomial.chebyshev from "leanprover-community/mathlib"@"d774451114d6045faeb6751c396bea1eb9058946" /-! # Chebyshev polynomials The Chebyshev polynomials are families of polynomials indexed by `ℤ`, with integral coefficients. ## Main definitions * `Polynomial.Chebyshev.T`: the Chebyshev polynomials of the first kind. * `Polynomial.Chebyshev.U`: the Chebyshev polynomials of the second kind. ## Main statements * The formal derivative of the Chebyshev polynomials of the first kind is a scalar multiple of the Chebyshev polynomials of the second kind. * `Polynomial.Chebyshev.mul_T`, twice the product of the `m`-th and `k`-th Chebyshev polynomials of the first kind is the sum of the `m + k`-th and `m - k`-th Chebyshev polynomials of the first kind. * `Polynomial.Chebyshev.T_mul`, the `(m * n)`-th Chebyshev polynomial of the first kind is the composition of the `m`-th and `n`-th Chebyshev polynomials of the first kind. ## Implementation details Since Chebyshev polynomials have interesting behaviour over the complex numbers and modulo `p`, we define them to have coefficients in an arbitrary commutative ring, even though technically `ℤ` would suffice. The benefit of allowing arbitrary coefficient rings, is that the statements afterwards are clean, and do not have `map (Int.castRingHom R)` interfering all the time. ## References [Lionel Ponton, _Roots of the Chebyshev polynomials: A purely algebraic approach_] [ponton2020chebyshev] ## TODO * Redefine and/or relate the definition of Chebyshev polynomials to `LinearRecurrence`. * Add explicit formula involving square roots for Chebyshev polynomials * Compute zeroes and extrema of Chebyshev polynomials. * Prove that the roots of the Chebyshev polynomials (except 0) are irrational. * Prove minimax properties of Chebyshev polynomials. -/ namespace Polynomial.Chebyshev set_option linter.uppercaseLean3 false -- `T` `U` `X` open Polynomial variable (R S : Type*) [CommRing R] [CommRing S] /-- `T n` is the `n`-th Chebyshev polynomial of the first kind. -/ -- Well-founded definitions are now irreducible by default; -- as this was implemented before this change, -- we just set it back to semireducible to avoid needing to change any proofs. @[semireducible] noncomputable def T : ℤ → R[X] | 0 => 1 | 1 => X | (n : ℕ) + 2 => 2 * X * T (n + 1) - T n | -((n : ℕ) + 1) => 2 * X * T (-n) - T (-n + 1) termination_by n => Int.natAbs n + Int.natAbs (n - 1) #align polynomial.chebyshev.T Polynomial.Chebyshev.T /-- Induction principle used for proving facts about Chebyshev polynomials. -/ @[elab_as_elim] protected theorem induct (motive : ℤ → Prop) (zero : motive 0) (one : motive 1) (add_two : ∀ (n : ℕ), motive (↑n + 1) → motive ↑n → motive (↑n + 2)) (neg_add_one : ∀ (n : ℕ), motive (-↑n) → motive (-↑n + 1) → motive (-↑n - 1)) : ∀ (a : ℤ), motive a := T.induct Unit motive zero one add_two fun n hn hnm => by simpa only [Int.negSucc_eq, neg_add] using neg_add_one n hn hnm @[simp] theorem T_add_two : ∀ n, T R (n + 2) = 2 * X * T R (n + 1) - T R n | (k : ℕ) => T.eq_3 R k | -(k + 1 : ℕ) => by linear_combination (norm := (simp [Int.negSucc_eq]; ring_nf)) T.eq_4 R k #align polynomial.chebyshev.T_add_two Polynomial.Chebyshev.T_add_two theorem T_add_one (n : ℤ) : T R (n + 1) = 2 * X * T R n - T R (n - 1) := by linear_combination (norm := ring_nf) T_add_two R (n - 1) theorem T_sub_two (n : ℤ) : T R (n - 2) = 2 * X * T R (n - 1) - T R n := by linear_combination (norm := ring_nf) T_add_two R (n - 2) theorem T_sub_one (n : ℤ) : T R (n - 1) = 2 * X * T R n - T R (n + 1) := by linear_combination (norm := ring_nf) T_add_two R (n - 1) theorem T_eq (n : ℤ) : T R n = 2 * X * T R (n - 1) - T R (n - 2) := by linear_combination (norm := ring_nf) T_add_two R (n - 2) #align polynomial.chebyshev.T_of_two_le Polynomial.Chebyshev.T_eq @[simp] theorem T_zero : T R 0 = 1 := rfl #align polynomial.chebyshev.T_zero Polynomial.Chebyshev.T_zero @[simp] theorem T_one : T R 1 = X := rfl #align polynomial.chebyshev.T_one Polynomial.Chebyshev.T_one theorem T_neg_one : T R (-1) = X := (by ring : 2 * X * 1 - X = X) theorem T_two : T R 2 = 2 * X ^ 2 - 1 := by simpa [pow_two, mul_assoc] using T_add_two R 0 #align polynomial.chebyshev.T_two Polynomial.Chebyshev.T_two @[simp] theorem T_neg (n : ℤ) : T R (-n) = T R n := by induction n using Polynomial.Chebyshev.induct with | zero => rfl | one => show 2 * X * 1 - X = X; ring | add_two n ih1 ih2 => have h₁ := T_add_two R n have h₂ := T_sub_two R (-n) linear_combination (norm := ring_nf) (2 * (X:R[X])) * ih1 - ih2 - h₁ + h₂ | neg_add_one n ih1 ih2 => have h₁ := T_add_one R n have h₂ := T_sub_one R (-n) linear_combination (norm := ring_nf) (2 * (X:R[X])) * ih1 - ih2 + h₁ - h₂
Mathlib/RingTheory/Polynomial/Chebyshev.lean
131
132
theorem T_natAbs (n : ℤ) : T R n.natAbs = T R n := by
obtain h | h := Int.natAbs_eq n <;> nth_rw 2 [h]; simp
/- Copyright (c) 2022 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.ModelTheory.Substructures #align_import model_theory.finitely_generated from "leanprover-community/mathlib"@"0602c59878ff3d5f71dea69c2d32ccf2e93e5398" /-! # Finitely Generated First-Order Structures This file defines what it means for a first-order (sub)structure to be finitely or countably generated, similarly to other finitely-generated objects in the algebra library. ## Main Definitions * `FirstOrder.Language.Substructure.FG` indicates that a substructure is finitely generated. * `FirstOrder.Language.Structure.FG` indicates that a structure is finitely generated. * `FirstOrder.Language.Substructure.CG` indicates that a substructure is countably generated. * `FirstOrder.Language.Structure.CG` indicates that a structure is countably generated. ## TODO Develop a more unified definition of finite generation using the theory of closure operators, or use this definition of finite generation to define the others. -/ open FirstOrder Set namespace FirstOrder namespace Language open Structure variable {L : Language} {M : Type*} [L.Structure M] namespace Substructure /-- A substructure of `M` is finitely generated if it is the closure of a finite subset of `M`. -/ def FG (N : L.Substructure M) : Prop := ∃ S : Finset M, closure L S = N #align first_order.language.substructure.fg FirstOrder.Language.Substructure.FG theorem fg_def {N : L.Substructure M} : N.FG ↔ ∃ S : Set M, S.Finite ∧ closure L S = N := ⟨fun ⟨t, h⟩ => ⟨_, Finset.finite_toSet t, h⟩, by rintro ⟨t', h, rfl⟩ rcases Finite.exists_finset_coe h with ⟨t, rfl⟩ exact ⟨t, rfl⟩⟩ #align first_order.language.substructure.fg_def FirstOrder.Language.Substructure.fg_def theorem fg_iff_exists_fin_generating_family {N : L.Substructure M} : N.FG ↔ ∃ (n : ℕ) (s : Fin n → M), closure L (range s) = N := by rw [fg_def] constructor · rintro ⟨S, Sfin, hS⟩ obtain ⟨n, f, rfl⟩ := Sfin.fin_embedding exact ⟨n, f, hS⟩ · rintro ⟨n, s, hs⟩ exact ⟨range s, finite_range s, hs⟩ #align first_order.language.substructure.fg_iff_exists_fin_generating_family FirstOrder.Language.Substructure.fg_iff_exists_fin_generating_family theorem fg_bot : (⊥ : L.Substructure M).FG := ⟨∅, by rw [Finset.coe_empty, closure_empty]⟩ #align first_order.language.substructure.fg_bot FirstOrder.Language.Substructure.fg_bot theorem fg_closure {s : Set M} (hs : s.Finite) : FG (closure L s) := ⟨hs.toFinset, by rw [hs.coe_toFinset]⟩ #align first_order.language.substructure.fg_closure FirstOrder.Language.Substructure.fg_closure theorem fg_closure_singleton (x : M) : FG (closure L ({x} : Set M)) := fg_closure (finite_singleton x) #align first_order.language.substructure.fg_closure_singleton FirstOrder.Language.Substructure.fg_closure_singleton theorem FG.sup {N₁ N₂ : L.Substructure M} (hN₁ : N₁.FG) (hN₂ : N₂.FG) : (N₁ ⊔ N₂).FG := let ⟨t₁, ht₁⟩ := fg_def.1 hN₁ let ⟨t₂, ht₂⟩ := fg_def.1 hN₂ fg_def.2 ⟨t₁ ∪ t₂, ht₁.1.union ht₂.1, by rw [closure_union, ht₁.2, ht₂.2]⟩ #align first_order.language.substructure.fg.sup FirstOrder.Language.Substructure.FG.sup theorem FG.map {N : Type*} [L.Structure N] (f : M →[L] N) {s : L.Substructure M} (hs : s.FG) : (s.map f).FG := let ⟨t, ht⟩ := fg_def.1 hs fg_def.2 ⟨f '' t, ht.1.image _, by rw [closure_image, ht.2]⟩ #align first_order.language.substructure.fg.map FirstOrder.Language.Substructure.FG.map
Mathlib/ModelTheory/FinitelyGenerated.lean
87
98
theorem FG.of_map_embedding {N : Type*} [L.Structure N] (f : M ↪[L] N) {s : L.Substructure M} (hs : (s.map f.toHom).FG) : s.FG := by
rcases hs with ⟨t, h⟩ rw [fg_def] refine ⟨f ⁻¹' t, t.finite_toSet.preimage f.injective.injOn, ?_⟩ have hf : Function.Injective f.toHom := f.injective refine map_injective_of_injective hf ?_ rw [← h, map_closure, Embedding.coe_toHom, image_preimage_eq_of_subset] intro x hx have h' := subset_closure (L := L) hx rw [h] at h' exact Hom.map_le_range h'