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, Andrew Yang -/ import Mathlib.CategoryTheory.Monoidal.Functor #align_import category_theory.monoidal.End from "leanprover-community/mathlib"@"85075bccb68ab7fa49fb05db816233fb790e4fe9" /-! # Endofunctors as a monoidal category. We give the monoidal category structure on `C ⥤ C`, and show that when `C` itself is monoidal, it embeds via a monoidal functor into `C ⥤ C`. ## TODO Can we use this to show coherence results, e.g. a cheap proof that `λ_ (𝟙_ C) = ρ_ (𝟙_ C)`? I suspect this is harder than is usually made out. -/ universe v u namespace CategoryTheory variable (C : Type u) [Category.{v} C] /-- The category of endofunctors of any category is a monoidal category, with tensor product given by composition of functors (and horizontal composition of natural transformations). -/ def endofunctorMonoidalCategory : MonoidalCategory (C ⥤ C) where tensorObj F G := F ⋙ G whiskerLeft X _ _ F := whiskerLeft X F whiskerRight F X := whiskerRight F X tensorHom α β := α ◫ β tensorUnit := 𝟭 C associator F G H := Functor.associator F G H leftUnitor F := Functor.leftUnitor F rightUnitor F := Functor.rightUnitor F #align category_theory.endofunctor_monoidal_category CategoryTheory.endofunctorMonoidalCategory open CategoryTheory.MonoidalCategory attribute [local instance] endofunctorMonoidalCategory @[simp] theorem endofunctorMonoidalCategory_tensorUnit_obj (X : C) : (𝟙_ (C ⥤ C)).obj X = X := rfl @[simp] theorem endofunctorMonoidalCategory_tensorUnit_map {X Y : C} (f : X ⟶ Y) : (𝟙_ (C ⥤ C)).map f = f := rfl @[simp] theorem endofunctorMonoidalCategory_tensorObj_obj (F G : C ⥤ C) (X : C) : (F ⊗ G).obj X = G.obj (F.obj X) := rfl @[simp] theorem endofunctorMonoidalCategory_tensorObj_map (F G : C ⥤ C) {X Y : C} (f : X ⟶ Y) : (F ⊗ G).map f = G.map (F.map f) := rfl @[simp] theorem endofunctorMonoidalCategory_tensorMap_app {F G H K : C ⥤ C} {α : F ⟶ G} {β : H ⟶ K} (X : C) : (α ⊗ β).app X = β.app (F.obj X) ≫ K.map (α.app X) := rfl @[simp] theorem endofunctorMonoidalCategory_whiskerLeft_app {F H K : C ⥤ C} {β : H ⟶ K} (X : C) : (F ◁ β).app X = β.app (F.obj X) := rfl @[simp] theorem endofunctorMonoidalCategory_whiskerRight_app {F G H : C ⥤ C} {α : F ⟶ G} (X : C) : (α ▷ H).app X = H.map (α.app X) := rfl @[simp] theorem endofunctorMonoidalCategory_associator_hom_app (F G H : C ⥤ C) (X : C) : (α_ F G H).hom.app X = 𝟙 _ := rfl @[simp] theorem endofunctorMonoidalCategory_associator_inv_app (F G H : C ⥤ C) (X : C) : (α_ F G H).inv.app X = 𝟙 _ := rfl @[simp] theorem endofunctorMonoidalCategory_leftUnitor_hom_app (F : C ⥤ C) (X : C) : (λ_ F).hom.app X = 𝟙 _ := rfl @[simp] theorem endofunctorMonoidalCategory_leftUnitor_inv_app (F : C ⥤ C) (X : C) : (λ_ F).inv.app X = 𝟙 _ := rfl @[simp] theorem endofunctorMonoidalCategory_rightUnitor_hom_app (F : C ⥤ C) (X : C) : (ρ_ F).hom.app X = 𝟙 _ := rfl @[simp] theorem endofunctorMonoidalCategory_rightUnitor_inv_app (F : C ⥤ C) (X : C) : (ρ_ F).inv.app X = 𝟙 _ := rfl /-- Tensoring on the right gives a monoidal functor from `C` into endofunctors of `C`. -/ @[simps!] def tensoringRightMonoidal [MonoidalCategory.{v} C] : MonoidalFunctor C (C ⥤ C) := { tensoringRight C with ε := (rightUnitorNatIso C).inv μ := fun X Y => (isoWhiskerRight (curriedAssociatorNatIso C) ((evaluation C (C ⥤ C)).obj X ⋙ (evaluation C C).obj Y)).hom } #align category_theory.tensoring_right_monoidal CategoryTheory.tensoringRightMonoidal variable {C} variable {M : Type*} [Category M] [MonoidalCategory M] (F : MonoidalFunctor M (C ⥤ C)) @[reassoc (attr := simp)] theorem μ_hom_inv_app (i j : M) (X : C) : (F.μ i j).app X ≫ (F.μIso i j).inv.app X = 𝟙 _ := (F.μIso i j).hom_inv_id_app X #align category_theory.μ_hom_inv_app CategoryTheory.μ_hom_inv_app @[reassoc (attr := simp)] theorem μ_inv_hom_app (i j : M) (X : C) : (F.μIso i j).inv.app X ≫ (F.μ i j).app X = 𝟙 _ := (F.μIso i j).inv_hom_id_app X #align category_theory.μ_inv_hom_app CategoryTheory.μ_inv_hom_app @[reassoc (attr := simp)] theorem ε_hom_inv_app (X : C) : F.ε.app X ≫ F.εIso.inv.app X = 𝟙 _ := F.εIso.hom_inv_id_app X #align category_theory.ε_hom_inv_app CategoryTheory.ε_hom_inv_app @[reassoc (attr := simp)] theorem ε_inv_hom_app (X : C) : F.εIso.inv.app X ≫ F.ε.app X = 𝟙 _ := F.εIso.inv_hom_id_app X #align category_theory.ε_inv_hom_app CategoryTheory.ε_inv_hom_app @[reassoc (attr := simp)] theorem ε_naturality {X Y : C} (f : X ⟶ Y) : F.ε.app X ≫ (F.obj (𝟙_ M)).map f = f ≫ F.ε.app Y := (F.ε.naturality f).symm #align category_theory.ε_naturality CategoryTheory.ε_naturality @[reassoc (attr := simp)]
Mathlib/CategoryTheory/Monoidal/End.lean
129
131
theorem ε_inv_naturality {X Y : C} (f : X ⟶ Y) : (MonoidalFunctor.εIso F).inv.app X ≫ (𝟙_ (C ⥤ C)).map f = F.εIso.inv.app X ≫ f := by
aesop_cat
/- 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, Violeta Hernández Palacios, Grayson Burton, Floris van Doorn -/ import Mathlib.Order.Interval.Set.OrdConnected import Mathlib.Order.Antisymmetrization #align_import order.cover from "leanprover-community/mathlib"@"207cfac9fcd06138865b5d04f7091e46d9320432" /-! # The covering relation This file defines the covering relation in an order. `b` is said to cover `a` if `a < b` and there is no element in between. We say that `b` weakly covers `a` if `a ≤ b` and there is no element between `a` and `b`. In a partial order this is equivalent to `a ⋖ b ∨ a = b`, in a preorder this is equivalent to `a ⋖ b ∨ (a ≤ b ∧ b ≤ a)` ## Notation * `a ⋖ b` means that `b` covers `a`. * `a ⩿ b` means that `b` weakly covers `a`. -/ open Set OrderDual variable {α β : Type*} section WeaklyCovers section Preorder variable [Preorder α] [Preorder β] {a b c : α} /-- `WCovBy a b` means that `a = b` or `b` covers `a`. This means that `a ≤ b` and there is no element in between. -/ def WCovBy (a b : α) : Prop := a ≤ b ∧ ∀ ⦃c⦄, a < c → ¬c < b #align wcovby WCovBy /-- Notation for `WCovBy a b`. -/ infixl:50 " ⩿ " => WCovBy theorem WCovBy.le (h : a ⩿ b) : a ≤ b := h.1 #align wcovby.le WCovBy.le theorem WCovBy.refl (a : α) : a ⩿ a := ⟨le_rfl, fun _ hc => hc.not_lt⟩ #align wcovby.refl WCovBy.refl @[simp] lemma WCovBy.rfl : a ⩿ a := WCovBy.refl a #align wcovby.rfl WCovBy.rfl protected theorem Eq.wcovBy (h : a = b) : a ⩿ b := h ▸ WCovBy.rfl #align eq.wcovby Eq.wcovBy theorem wcovBy_of_le_of_le (h1 : a ≤ b) (h2 : b ≤ a) : a ⩿ b := ⟨h1, fun _ hac hcb => (hac.trans hcb).not_le h2⟩ #align wcovby_of_le_of_le wcovBy_of_le_of_le alias LE.le.wcovBy_of_le := wcovBy_of_le_of_le theorem AntisymmRel.wcovBy (h : AntisymmRel (· ≤ ·) a b) : a ⩿ b := wcovBy_of_le_of_le h.1 h.2 #align antisymm_rel.wcovby AntisymmRel.wcovBy theorem WCovBy.wcovBy_iff_le (hab : a ⩿ b) : b ⩿ a ↔ b ≤ a := ⟨fun h => h.le, fun h => h.wcovBy_of_le hab.le⟩ #align wcovby.wcovby_iff_le WCovBy.wcovBy_iff_le theorem wcovBy_of_eq_or_eq (hab : a ≤ b) (h : ∀ c, a ≤ c → c ≤ b → c = a ∨ c = b) : a ⩿ b := ⟨hab, fun c ha hb => (h c ha.le hb.le).elim ha.ne' hb.ne⟩ #align wcovby_of_eq_or_eq wcovBy_of_eq_or_eq theorem AntisymmRel.trans_wcovBy (hab : AntisymmRel (· ≤ ·) a b) (hbc : b ⩿ c) : a ⩿ c := ⟨hab.1.trans hbc.le, fun _ had hdc => hbc.2 (hab.2.trans_lt had) hdc⟩ #align antisymm_rel.trans_wcovby AntisymmRel.trans_wcovBy theorem wcovBy_congr_left (hab : AntisymmRel (· ≤ ·) a b) : a ⩿ c ↔ b ⩿ c := ⟨hab.symm.trans_wcovBy, hab.trans_wcovBy⟩ #align wcovby_congr_left wcovBy_congr_left theorem WCovBy.trans_antisymm_rel (hab : a ⩿ b) (hbc : AntisymmRel (· ≤ ·) b c) : a ⩿ c := ⟨hab.le.trans hbc.1, fun _ had hdc => hab.2 had <| hdc.trans_le hbc.2⟩ #align wcovby.trans_antisymm_rel WCovBy.trans_antisymm_rel theorem wcovBy_congr_right (hab : AntisymmRel (· ≤ ·) a b) : c ⩿ a ↔ c ⩿ b := ⟨fun h => h.trans_antisymm_rel hab, fun h => h.trans_antisymm_rel hab.symm⟩ #align wcovby_congr_right wcovBy_congr_right /-- If `a ≤ b`, then `b` does not cover `a` iff there's an element in between. -/ theorem not_wcovBy_iff (h : a ≤ b) : ¬a ⩿ b ↔ ∃ c, a < c ∧ c < b := by simp_rw [WCovBy, h, true_and_iff, not_forall, exists_prop, not_not] #align not_wcovby_iff not_wcovBy_iff instance WCovBy.isRefl : IsRefl α (· ⩿ ·) := ⟨WCovBy.refl⟩ #align wcovby.is_refl WCovBy.isRefl theorem WCovBy.Ioo_eq (h : a ⩿ b) : Ioo a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ hx => h.2 hx.1 hx.2 #align wcovby.Ioo_eq WCovBy.Ioo_eq theorem wcovBy_iff_Ioo_eq : a ⩿ b ↔ a ≤ b ∧ Ioo a b = ∅ := and_congr_right' <| by simp [eq_empty_iff_forall_not_mem] #align wcovby_iff_Ioo_eq wcovBy_iff_Ioo_eq lemma WCovBy.of_le_of_le (hac : a ⩿ c) (hab : a ≤ b) (hbc : b ≤ c) : b ⩿ c := ⟨hbc, fun _x hbx hxc ↦ hac.2 (hab.trans_lt hbx) hxc⟩ lemma WCovBy.of_le_of_le' (hac : a ⩿ c) (hab : a ≤ b) (hbc : b ≤ c) : a ⩿ b := ⟨hab, fun _x hax hxb ↦ hac.2 hax <| hxb.trans_le hbc⟩ theorem WCovBy.of_image (f : α ↪o β) (h : f a ⩿ f b) : a ⩿ b := ⟨f.le_iff_le.mp h.le, fun _ hac hcb => h.2 (f.lt_iff_lt.mpr hac) (f.lt_iff_lt.mpr hcb)⟩ #align wcovby.of_image WCovBy.of_image
Mathlib/Order/Cover.lean
122
126
theorem WCovBy.image (f : α ↪o β) (hab : a ⩿ b) (h : (range f).OrdConnected) : f a ⩿ f b := by
refine ⟨f.monotone hab.le, fun c ha hb => ?_⟩ obtain ⟨c, rfl⟩ := h.out (mem_range_self _) (mem_range_self _) ⟨ha.le, hb.le⟩ rw [f.lt_iff_lt] at ha hb exact hab.2 ha hb
/- Copyright (c) 2023 Ali Ramsey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ali Ramsey, Eric Wieser -/ import Mathlib.LinearAlgebra.Finsupp import Mathlib.LinearAlgebra.Prod import Mathlib.LinearAlgebra.TensorProduct.Basic /-! # Coalgebras In this file we define `Coalgebra`, and provide instances for: * Commutative semirings: `CommSemiring.toCoalgebra` * Binary products: `Prod.instCoalgebra` * Finitely supported functions: `Finsupp.instCoalgebra` ## References * <https://en.wikipedia.org/wiki/Coalgebra> -/ suppress_compilation universe u v w open scoped TensorProduct /-- Data fields for `Coalgebra`, to allow API to be constructed before proving `Coalgebra.coassoc`. See `Coalgebra` for documentation. -/ class CoalgebraStruct (R : Type u) (A : Type v) [CommSemiring R] [AddCommMonoid A] [Module R A] where /-- The comultiplication of the coalgebra -/ comul : A →ₗ[R] A ⊗[R] A /-- The counit of the coalgebra -/ counit : A →ₗ[R] R namespace Coalgebra export CoalgebraStruct (comul counit) end Coalgebra /-- A coalgebra over a commutative (semi)ring `R` is an `R`-module equipped with a coassociative comultiplication `Δ` and a counit `ε` obeying the left and right counitality laws. -/ class Coalgebra (R : Type u) (A : Type v) [CommSemiring R] [AddCommMonoid A] [Module R A] extends CoalgebraStruct R A where /-- The comultiplication is coassociative -/ coassoc : TensorProduct.assoc R A A A ∘ₗ comul.rTensor A ∘ₗ comul = comul.lTensor A ∘ₗ comul /-- The counit satisfies the left counitality law -/ rTensor_counit_comp_comul : counit.rTensor A ∘ₗ comul = TensorProduct.mk R _ _ 1 /-- The counit satisfies the right counitality law -/ lTensor_counit_comp_comul : counit.lTensor A ∘ₗ comul = (TensorProduct.mk R _ _).flip 1 namespace Coalgebra variable {R : Type u} {A : Type v} variable [CommSemiring R] [AddCommMonoid A] [Module R A] [Coalgebra R A] @[simp] theorem coassoc_apply (a : A) : TensorProduct.assoc R A A A (comul.rTensor A (comul a)) = comul.lTensor A (comul a) := LinearMap.congr_fun coassoc a @[simp] theorem coassoc_symm_apply (a : A) : (TensorProduct.assoc R A A A).symm (comul.lTensor A (comul a)) = comul.rTensor A (comul a) := by rw [(TensorProduct.assoc R A A A).symm_apply_eq, coassoc_apply a] @[simp] theorem coassoc_symm : (TensorProduct.assoc R A A A).symm ∘ₗ comul.lTensor A ∘ₗ comul = comul.rTensor A ∘ₗ (comul (R := R)) := LinearMap.ext coassoc_symm_apply @[simp] theorem rTensor_counit_comul (a : A) : counit.rTensor A (comul a) = 1 ⊗ₜ[R] a := LinearMap.congr_fun rTensor_counit_comp_comul a @[simp] theorem lTensor_counit_comul (a : A) : counit.lTensor A (comul a) = a ⊗ₜ[R] 1 := LinearMap.congr_fun lTensor_counit_comp_comul a end Coalgebra section CommSemiring open Coalgebra namespace CommSemiring variable (R : Type u) [CommSemiring R] /-- Every commutative (semi)ring is a coalgebra over itself, with `Δ r = 1 ⊗ₜ r`. -/ instance toCoalgebra : Coalgebra R R where comul := (TensorProduct.mk R R R) 1 counit := .id coassoc := rfl rTensor_counit_comp_comul := by ext; rfl lTensor_counit_comp_comul := by ext; rfl @[simp] theorem comul_apply (r : R) : comul r = 1 ⊗ₜ[R] r := rfl @[simp] theorem counit_apply (r : R) : counit r = r := rfl end CommSemiring namespace Prod variable (R : Type u) (A : Type v) (B : Type w) variable [CommSemiring R] [AddCommMonoid A] [AddCommMonoid B] [Module R A] [Module R B] variable [Coalgebra R A] [Coalgebra R B] open LinearMap instance instCoalgebraStruct : CoalgebraStruct R (A × B) where comul := .coprod (TensorProduct.map (.inl R A B) (.inl R A B) ∘ₗ comul) (TensorProduct.map (.inr R A B) (.inr R A B) ∘ₗ comul) counit := .coprod counit counit @[simp] theorem comul_apply (r : A × B) : comul r = TensorProduct.map (.inl R A B) (.inl R A B) (comul r.1) + TensorProduct.map (.inr R A B) (.inr R A B) (comul r.2) := rfl @[simp] theorem counit_apply (r : A × B) : (counit r : R) = counit r.1 + counit r.2 := rfl
Mathlib/RingTheory/Coalgebra/Basic.lean
129
131
theorem comul_comp_inl : comul ∘ₗ inl R A B = TensorProduct.map (.inl R A B) (.inl R A B) ∘ₗ comul := by
ext; simp
/- Copyright (c) 2022 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.Order.Interval.Set.Monotone import Mathlib.Probability.Process.HittingTime import Mathlib.Probability.Martingale.Basic import Mathlib.Tactic.AdaptationNote #align_import probability.martingale.upcrossing from "leanprover-community/mathlib"@"2c1d8ca2812b64f88992a5294ea3dba144755cd1" /-! # Doob's upcrossing estimate Given a discrete real-valued submartingale $(f_n)_{n \in \mathbb{N}}$, denoting by $U_N(a, b)$ the number of times $f_n$ crossed from below $a$ to above $b$ before time $N$, Doob's upcrossing estimate (also known as Doob's inequality) states that $$(b - a) \mathbb{E}[U_N(a, b)] \le \mathbb{E}[(f_N - a)^+].$$ Doob's upcrossing estimate is an important inequality and is central in proving the martingale convergence theorems. ## Main definitions * `MeasureTheory.upperCrossingTime a b f N n`: is the stopping time corresponding to `f` crossing above `b` the `n`-th time before time `N` (if this does not occur then the value is taken to be `N`). * `MeasureTheory.lowerCrossingTime a b f N n`: is the stopping time corresponding to `f` crossing below `a` the `n`-th time before time `N` (if this does not occur then the value is taken to be `N`). * `MeasureTheory.upcrossingStrat a b f N`: is the predictable process which is 1 if `n` is between a consecutive pair of lower and upper crossings and is 0 otherwise. Intuitively one might think of the `upcrossingStrat` as the strategy of buying 1 share whenever the process crosses below `a` for the first time after selling and selling 1 share whenever the process crosses above `b` for the first time after buying. * `MeasureTheory.upcrossingsBefore a b f N`: is the number of times `f` crosses from below `a` to above `b` before time `N`. * `MeasureTheory.upcrossings a b f`: is the number of times `f` crosses from below `a` to above `b`. This takes value in `ℝ≥0∞` and so is allowed to be `∞`. ## Main results * `MeasureTheory.Adapted.isStoppingTime_upperCrossingTime`: `upperCrossingTime` is a stopping time whenever the process it is associated to is adapted. * `MeasureTheory.Adapted.isStoppingTime_lowerCrossingTime`: `lowerCrossingTime` is a stopping time whenever the process it is associated to is adapted. * `MeasureTheory.Submartingale.mul_integral_upcrossingsBefore_le_integral_pos_part`: Doob's upcrossing estimate. * `MeasureTheory.Submartingale.mul_lintegral_upcrossings_le_lintegral_pos_part`: the inequality obtained by taking the supremum on both sides of Doob's upcrossing estimate. ### References We mostly follow the proof from [Kallenberg, *Foundations of modern probability*][kallenberg2021] -/ open TopologicalSpace Filter open scoped NNReal ENNReal MeasureTheory ProbabilityTheory Topology namespace MeasureTheory variable {Ω ι : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} /-! ## Proof outline In this section, we will denote by $U_N(a, b)$ the number of upcrossings of $(f_n)$ from below $a$ to above $b$ before time $N$. To define $U_N(a, b)$, we will construct two stopping times corresponding to when $(f_n)$ crosses below $a$ and above $b$. Namely, we define $$ \sigma_n := \inf \{n \ge \tau_n \mid f_n \le a\} \wedge N; $$ $$ \tau_{n + 1} := \inf \{n \ge \sigma_n \mid f_n \ge b\} \wedge N. $$ These are `lowerCrossingTime` and `upperCrossingTime` in our formalization which are defined using `MeasureTheory.hitting` allowing us to specify a starting and ending time. Then, we may simply define $U_N(a, b) := \sup \{n \mid \tau_n < N\}$. Fixing $a < b \in \mathbb{R}$, we will first prove the theorem in the special case that $0 \le f_0$ and $a \le f_N$. In particular, we will show $$ (b - a) \mathbb{E}[U_N(a, b)] \le \mathbb{E}[f_N]. $$ This is `MeasureTheory.integral_mul_upcrossingsBefore_le_integral` in our formalization. To prove this, we use the fact that given a non-negative, bounded, predictable process $(C_n)$ (i.e. $(C_{n + 1})$ is adapted), $(C \bullet f)_n := \sum_{k \le n} C_{k + 1}(f_{k + 1} - f_k)$ is a submartingale if $(f_n)$ is. Define $C_n := \sum_{k \le n} \mathbf{1}_{[\sigma_k, \tau_{k + 1})}(n)$. It is easy to see that $(1 - C_n)$ is non-negative, bounded and predictable, and hence, given a submartingale $(f_n)$, $(1 - C) \bullet f$ is also a submartingale. Thus, by the submartingale property, $0 \le \mathbb{E}[((1 - C) \bullet f)_0] \le \mathbb{E}[((1 - C) \bullet f)_N]$ implying $$ \mathbb{E}[(C \bullet f)_N] \le \mathbb{E}[(1 \bullet f)_N] = \mathbb{E}[f_N] - \mathbb{E}[f_0]. $$ Furthermore, \begin{align} (C \bullet f)_N & = \sum_{n \le N} \sum_{k \le N} \mathbf{1}_{[\sigma_k, \tau_{k + 1})}(n)(f_{n + 1} - f_n)\\ & = \sum_{k \le N} \sum_{n \le N} \mathbf{1}_{[\sigma_k, \tau_{k + 1})}(n)(f_{n + 1} - f_n)\\ & = \sum_{k \le N} (f_{\sigma_k + 1} - f_{\sigma_k} + f_{\sigma_k + 2} - f_{\sigma_k + 1} + \cdots + f_{\tau_{k + 1}} - f_{\tau_{k + 1} - 1})\\ & = \sum_{k \le N} (f_{\tau_{k + 1}} - f_{\sigma_k}) \ge \sum_{k < U_N(a, b)} (b - a) = (b - a) U_N(a, b) \end{align} where the inequality follows since for all $k < U_N(a, b)$, $f_{\tau_{k + 1}} - f_{\sigma_k} \ge b - a$ while for all $k > U_N(a, b)$, $f_{\tau_{k + 1}} = f_{\sigma_k} = f_N$ and $f_{\tau_{U_N(a, b) + 1}} - f_{\sigma_{U_N(a, b)}} = f_N - a \ge 0$. Hence, we have $$ (b - a) \mathbb{E}[U_N(a, b)] \le \mathbb{E}[(C \bullet f)_N] \le \mathbb{E}[f_N] - \mathbb{E}[f_0] \le \mathbb{E}[f_N], $$ as required. To obtain the general case, we simply apply the above to $((f_n - a)^+)_n$. -/ /-- `lowerCrossingTimeAux a f c N` is the first time `f` reached below `a` after time `c` before time `N`. -/ noncomputable def lowerCrossingTimeAux [Preorder ι] [InfSet ι] (a : ℝ) (f : ι → Ω → ℝ) (c N : ι) : Ω → ι := hitting f (Set.Iic a) c N #align measure_theory.lower_crossing_time_aux MeasureTheory.lowerCrossingTimeAux /-- `upperCrossingTime a b f N n` is the first time before time `N`, `f` reaches above `b` after `f` reached below `a` for the `n - 1`-th time. -/ noncomputable def upperCrossingTime [Preorder ι] [OrderBot ι] [InfSet ι] (a b : ℝ) (f : ι → Ω → ℝ) (N : ι) : ℕ → Ω → ι | 0 => ⊥ | n + 1 => fun ω => hitting f (Set.Ici b) (lowerCrossingTimeAux a f (upperCrossingTime a b f N n ω) N ω) N ω #align measure_theory.upper_crossing_time MeasureTheory.upperCrossingTime /-- `lowerCrossingTime a b f N n` is the first time before time `N`, `f` reaches below `a` after `f` reached above `b` for the `n`-th time. -/ noncomputable def lowerCrossingTime [Preorder ι] [OrderBot ι] [InfSet ι] (a b : ℝ) (f : ι → Ω → ℝ) (N : ι) (n : ℕ) : Ω → ι := fun ω => hitting f (Set.Iic a) (upperCrossingTime a b f N n ω) N ω #align measure_theory.lower_crossing_time MeasureTheory.lowerCrossingTime section variable [Preorder ι] [OrderBot ι] [InfSet ι] variable {a b : ℝ} {f : ι → Ω → ℝ} {N : ι} {n m : ℕ} {ω : Ω} @[simp] theorem upperCrossingTime_zero : upperCrossingTime a b f N 0 = ⊥ := rfl #align measure_theory.upper_crossing_time_zero MeasureTheory.upperCrossingTime_zero @[simp] theorem lowerCrossingTime_zero : lowerCrossingTime a b f N 0 = hitting f (Set.Iic a) ⊥ N := rfl #align measure_theory.lower_crossing_time_zero MeasureTheory.lowerCrossingTime_zero theorem upperCrossingTime_succ : upperCrossingTime a b f N (n + 1) ω = hitting f (Set.Ici b) (lowerCrossingTimeAux a f (upperCrossingTime a b f N n ω) N ω) N ω := by rw [upperCrossingTime] #align measure_theory.upper_crossing_time_succ MeasureTheory.upperCrossingTime_succ theorem upperCrossingTime_succ_eq (ω : Ω) : upperCrossingTime a b f N (n + 1) ω = hitting f (Set.Ici b) (lowerCrossingTime a b f N n ω) N ω := by simp only [upperCrossingTime_succ] rfl #align measure_theory.upper_crossing_time_succ_eq MeasureTheory.upperCrossingTime_succ_eq end section ConditionallyCompleteLinearOrderBot variable [ConditionallyCompleteLinearOrderBot ι] variable {a b : ℝ} {f : ι → Ω → ℝ} {N : ι} {n m : ℕ} {ω : Ω} theorem upperCrossingTime_le : upperCrossingTime a b f N n ω ≤ N := by cases n · simp only [upperCrossingTime_zero, Pi.bot_apply, bot_le, Nat.zero_eq] · simp only [upperCrossingTime_succ, hitting_le] #align measure_theory.upper_crossing_time_le MeasureTheory.upperCrossingTime_le @[simp] theorem upperCrossingTime_zero' : upperCrossingTime a b f ⊥ n ω = ⊥ := eq_bot_iff.2 upperCrossingTime_le #align measure_theory.upper_crossing_time_zero' MeasureTheory.upperCrossingTime_zero' theorem lowerCrossingTime_le : lowerCrossingTime a b f N n ω ≤ N := by simp only [lowerCrossingTime, hitting_le ω] #align measure_theory.lower_crossing_time_le MeasureTheory.lowerCrossingTime_le theorem upperCrossingTime_le_lowerCrossingTime : upperCrossingTime a b f N n ω ≤ lowerCrossingTime a b f N n ω := by simp only [lowerCrossingTime, le_hitting upperCrossingTime_le ω] #align measure_theory.upper_crossing_time_le_lower_crossing_time MeasureTheory.upperCrossingTime_le_lowerCrossingTime theorem lowerCrossingTime_le_upperCrossingTime_succ : lowerCrossingTime a b f N n ω ≤ upperCrossingTime a b f N (n + 1) ω := by rw [upperCrossingTime_succ] exact le_hitting lowerCrossingTime_le ω #align measure_theory.lower_crossing_time_le_upper_crossing_time_succ MeasureTheory.lowerCrossingTime_le_upperCrossingTime_succ theorem lowerCrossingTime_mono (hnm : n ≤ m) : lowerCrossingTime a b f N n ω ≤ lowerCrossingTime a b f N m ω := by suffices Monotone fun n => lowerCrossingTime a b f N n ω by exact this hnm exact monotone_nat_of_le_succ fun n => le_trans lowerCrossingTime_le_upperCrossingTime_succ upperCrossingTime_le_lowerCrossingTime #align measure_theory.lower_crossing_time_mono MeasureTheory.lowerCrossingTime_mono theorem upperCrossingTime_mono (hnm : n ≤ m) : upperCrossingTime a b f N n ω ≤ upperCrossingTime a b f N m ω := by suffices Monotone fun n => upperCrossingTime a b f N n ω by exact this hnm exact monotone_nat_of_le_succ fun n => le_trans upperCrossingTime_le_lowerCrossingTime lowerCrossingTime_le_upperCrossingTime_succ #align measure_theory.upper_crossing_time_mono MeasureTheory.upperCrossingTime_mono end ConditionallyCompleteLinearOrderBot variable {a b : ℝ} {f : ℕ → Ω → ℝ} {N : ℕ} {n m : ℕ} {ω : Ω} theorem stoppedValue_lowerCrossingTime (h : lowerCrossingTime a b f N n ω ≠ N) : stoppedValue f (lowerCrossingTime a b f N n) ω ≤ a := by obtain ⟨j, hj₁, hj₂⟩ := (hitting_le_iff_of_lt _ (lt_of_le_of_ne lowerCrossingTime_le h)).1 le_rfl exact stoppedValue_hitting_mem ⟨j, ⟨hj₁.1, le_trans hj₁.2 lowerCrossingTime_le⟩, hj₂⟩ #align measure_theory.stopped_value_lower_crossing_time MeasureTheory.stoppedValue_lowerCrossingTime theorem stoppedValue_upperCrossingTime (h : upperCrossingTime a b f N (n + 1) ω ≠ N) : b ≤ stoppedValue f (upperCrossingTime a b f N (n + 1)) ω := by obtain ⟨j, hj₁, hj₂⟩ := (hitting_le_iff_of_lt _ (lt_of_le_of_ne upperCrossingTime_le h)).1 le_rfl exact stoppedValue_hitting_mem ⟨j, ⟨hj₁.1, le_trans hj₁.2 (hitting_le _)⟩, hj₂⟩ #align measure_theory.stopped_value_upper_crossing_time MeasureTheory.stoppedValue_upperCrossingTime theorem upperCrossingTime_lt_lowerCrossingTime (hab : a < b) (hn : lowerCrossingTime a b f N (n + 1) ω ≠ N) : upperCrossingTime a b f N (n + 1) ω < lowerCrossingTime a b f N (n + 1) ω := by refine lt_of_le_of_ne upperCrossingTime_le_lowerCrossingTime fun h => not_le.2 hab <| le_trans ?_ (stoppedValue_lowerCrossingTime hn) simp only [stoppedValue] rw [← h] exact stoppedValue_upperCrossingTime (h.symm ▸ hn) #align measure_theory.upper_crossing_time_lt_lower_crossing_time MeasureTheory.upperCrossingTime_lt_lowerCrossingTime theorem lowerCrossingTime_lt_upperCrossingTime (hab : a < b) (hn : upperCrossingTime a b f N (n + 1) ω ≠ N) : lowerCrossingTime a b f N n ω < upperCrossingTime a b f N (n + 1) ω := by refine lt_of_le_of_ne lowerCrossingTime_le_upperCrossingTime_succ fun h => not_le.2 hab <| le_trans (stoppedValue_upperCrossingTime hn) ?_ simp only [stoppedValue] rw [← h] exact stoppedValue_lowerCrossingTime (h.symm ▸ hn) #align measure_theory.lower_crossing_time_lt_upper_crossing_time MeasureTheory.lowerCrossingTime_lt_upperCrossingTime theorem upperCrossingTime_lt_succ (hab : a < b) (hn : upperCrossingTime a b f N (n + 1) ω ≠ N) : upperCrossingTime a b f N n ω < upperCrossingTime a b f N (n + 1) ω := lt_of_le_of_lt upperCrossingTime_le_lowerCrossingTime (lowerCrossingTime_lt_upperCrossingTime hab hn) #align measure_theory.upper_crossing_time_lt_succ MeasureTheory.upperCrossingTime_lt_succ theorem lowerCrossingTime_stabilize (hnm : n ≤ m) (hn : lowerCrossingTime a b f N n ω = N) : lowerCrossingTime a b f N m ω = N := le_antisymm lowerCrossingTime_le (le_trans (le_of_eq hn.symm) (lowerCrossingTime_mono hnm)) #align measure_theory.lower_crossing_time_stabilize MeasureTheory.lowerCrossingTime_stabilize theorem upperCrossingTime_stabilize (hnm : n ≤ m) (hn : upperCrossingTime a b f N n ω = N) : upperCrossingTime a b f N m ω = N := le_antisymm upperCrossingTime_le (le_trans (le_of_eq hn.symm) (upperCrossingTime_mono hnm)) #align measure_theory.upper_crossing_time_stabilize MeasureTheory.upperCrossingTime_stabilize theorem lowerCrossingTime_stabilize' (hnm : n ≤ m) (hn : N ≤ lowerCrossingTime a b f N n ω) : lowerCrossingTime a b f N m ω = N := lowerCrossingTime_stabilize hnm (le_antisymm lowerCrossingTime_le hn) #align measure_theory.lower_crossing_time_stabilize' MeasureTheory.lowerCrossingTime_stabilize' theorem upperCrossingTime_stabilize' (hnm : n ≤ m) (hn : N ≤ upperCrossingTime a b f N n ω) : upperCrossingTime a b f N m ω = N := upperCrossingTime_stabilize hnm (le_antisymm upperCrossingTime_le hn) #align measure_theory.upper_crossing_time_stabilize' MeasureTheory.upperCrossingTime_stabilize' -- `upperCrossingTime_bound_eq` provides an explicit bound theorem exists_upperCrossingTime_eq (f : ℕ → Ω → ℝ) (N : ℕ) (ω : Ω) (hab : a < b) : ∃ n, upperCrossingTime a b f N n ω = N := by by_contra h; push_neg at h have : StrictMono fun n => upperCrossingTime a b f N n ω := strictMono_nat_of_lt_succ fun n => upperCrossingTime_lt_succ hab (h _) obtain ⟨_, ⟨k, rfl⟩, hk⟩ : ∃ (m : _) (_ : m ∈ Set.range fun n => upperCrossingTime a b f N n ω), N < m := ⟨upperCrossingTime a b f N (N + 1) ω, ⟨N + 1, rfl⟩, lt_of_lt_of_le N.lt_succ_self (StrictMono.id_le this (N + 1))⟩ exact not_le.2 hk upperCrossingTime_le #align measure_theory.exists_upper_crossing_time_eq MeasureTheory.exists_upperCrossingTime_eq theorem upperCrossingTime_lt_bddAbove (hab : a < b) : BddAbove {n | upperCrossingTime a b f N n ω < N} := by obtain ⟨k, hk⟩ := exists_upperCrossingTime_eq f N ω hab refine ⟨k, fun n (hn : upperCrossingTime a b f N n ω < N) => ?_⟩ by_contra hn' exact hn.ne (upperCrossingTime_stabilize (not_le.1 hn').le hk) #align measure_theory.upper_crossing_time_lt_bdd_above MeasureTheory.upperCrossingTime_lt_bddAbove theorem upperCrossingTime_lt_nonempty (hN : 0 < N) : {n | upperCrossingTime a b f N n ω < N}.Nonempty := ⟨0, hN⟩ #align measure_theory.upper_crossing_time_lt_nonempty MeasureTheory.upperCrossingTime_lt_nonempty theorem upperCrossingTime_bound_eq (f : ℕ → Ω → ℝ) (N : ℕ) (ω : Ω) (hab : a < b) : upperCrossingTime a b f N N ω = N := by by_cases hN' : N < Nat.find (exists_upperCrossingTime_eq f N ω hab) · refine le_antisymm upperCrossingTime_le ?_ have hmono : StrictMonoOn (fun n => upperCrossingTime a b f N n ω) (Set.Iic (Nat.find (exists_upperCrossingTime_eq f N ω hab)).pred) := by refine strictMonoOn_Iic_of_lt_succ fun m hm => upperCrossingTime_lt_succ hab ?_ rw [Nat.lt_pred_iff] at hm convert Nat.find_min _ hm convert StrictMonoOn.Iic_id_le hmono N (Nat.le_sub_one_of_lt hN') · rw [not_lt] at hN' exact upperCrossingTime_stabilize hN' (Nat.find_spec (exists_upperCrossingTime_eq f N ω hab)) #align measure_theory.upper_crossing_time_bound_eq MeasureTheory.upperCrossingTime_bound_eq theorem upperCrossingTime_eq_of_bound_le (hab : a < b) (hn : N ≤ n) : upperCrossingTime a b f N n ω = N := le_antisymm upperCrossingTime_le (le_trans (upperCrossingTime_bound_eq f N ω hab).symm.le (upperCrossingTime_mono hn)) #align measure_theory.upper_crossing_time_eq_of_bound_le MeasureTheory.upperCrossingTime_eq_of_bound_le variable {ℱ : Filtration ℕ m0}
Mathlib/Probability/Martingale/Upcrossing.lean
336
351
theorem Adapted.isStoppingTime_crossing (hf : Adapted ℱ f) : IsStoppingTime ℱ (upperCrossingTime a b f N n) ∧ IsStoppingTime ℱ (lowerCrossingTime a b f N n) := by
induction' n with k ih · refine ⟨isStoppingTime_const _ 0, ?_⟩ simp [hitting_isStoppingTime hf measurableSet_Iic] · obtain ⟨_, ih₂⟩ := ih have : IsStoppingTime ℱ (upperCrossingTime a b f N (k + 1)) := by intro n simp_rw [upperCrossingTime_succ_eq] exact isStoppingTime_hitting_isStoppingTime ih₂ (fun _ => lowerCrossingTime_le) measurableSet_Ici hf _ refine ⟨this, ?_⟩ intro n exact isStoppingTime_hitting_isStoppingTime this (fun _ => upperCrossingTime_le) measurableSet_Iic hf _
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Polynomial.Expand import Mathlib.LinearAlgebra.FiniteDimensional import Mathlib.LinearAlgebra.Matrix.Charpoly.LinearMap import Mathlib.RingTheory.Adjoin.FG import Mathlib.RingTheory.FiniteType import Mathlib.RingTheory.Polynomial.ScaleRoots import Mathlib.RingTheory.Polynomial.Tower import Mathlib.RingTheory.TensorProduct.Basic #align_import ring_theory.integral_closure from "leanprover-community/mathlib"@"641b6a82006416ec431b2987b354af9311fed4f2" /-! # Integral closure of a subring. If A is an R-algebra then `a : A` is integral over R if it is a root of a monic polynomial with coefficients in R. Enough theory is developed to prove that integral elements form a sub-R-algebra of A. ## Main definitions Let `R` be a `CommRing` and let `A` be an R-algebra. * `RingHom.IsIntegralElem (f : R →+* A) (x : A)` : `x` is integral with respect to the map `f`, * `IsIntegral (x : A)` : `x` is integral over `R`, i.e., is a root of a monic polynomial with coefficients in `R`. * `integralClosure R A` : the integral closure of `R` in `A`, regarded as a sub-`R`-algebra of `A`. -/ open scoped Classical open Polynomial Submodule section Ring variable {R S A : Type*} variable [CommRing R] [Ring A] [Ring S] (f : R →+* S) /-- An element `x` of `A` is said to be integral over `R` with respect to `f` if it is a root of a monic polynomial `p : R[X]` evaluated under `f` -/ def RingHom.IsIntegralElem (f : R →+* A) (x : A) := ∃ p : R[X], Monic p ∧ eval₂ f x p = 0 #align ring_hom.is_integral_elem RingHom.IsIntegralElem /-- A ring homomorphism `f : R →+* A` is said to be integral if every element `A` is integral with respect to the map `f` -/ def RingHom.IsIntegral (f : R →+* A) := ∀ x : A, f.IsIntegralElem x #align ring_hom.is_integral RingHom.IsIntegral variable [Algebra R A] (R) /-- An element `x` of an algebra `A` over a commutative ring `R` is said to be *integral*, if it is a root of some monic polynomial `p : R[X]`. Equivalently, the element is integral over `R` with respect to the induced `algebraMap` -/ def IsIntegral (x : A) : Prop := (algebraMap R A).IsIntegralElem x #align is_integral IsIntegral variable (A) /-- An algebra is integral if every element of the extension is integral over the base ring -/ protected class Algebra.IsIntegral : Prop := isIntegral : ∀ x : A, IsIntegral R x #align algebra.is_integral Algebra.IsIntegral variable {R A} lemma Algebra.isIntegral_def : Algebra.IsIntegral R A ↔ ∀ x : A, IsIntegral R x := ⟨fun ⟨h⟩ ↦ h, fun h ↦ ⟨h⟩⟩ theorem RingHom.isIntegralElem_map {x : R} : f.IsIntegralElem (f x) := ⟨X - C x, monic_X_sub_C _, by simp⟩ #align ring_hom.is_integral_map RingHom.isIntegralElem_map theorem isIntegral_algebraMap {x : R} : IsIntegral R (algebraMap R A x) := (algebraMap R A).isIntegralElem_map #align is_integral_algebra_map isIntegral_algebraMap end Ring section variable {R A B S : Type*} variable [CommRing R] [CommRing A] [Ring B] [CommRing S] variable [Algebra R A] [Algebra R B] (f : R →+* S) theorem IsIntegral.map {B C F : Type*} [Ring B] [Ring C] [Algebra R B] [Algebra A B] [Algebra R C] [IsScalarTower R A B] [Algebra A C] [IsScalarTower R A C] {b : B} [FunLike F B C] [AlgHomClass F A B C] (f : F) (hb : IsIntegral R b) : IsIntegral R (f b) := by obtain ⟨P, hP⟩ := hb refine ⟨P, hP.1, ?_⟩ rw [← aeval_def, ← aeval_map_algebraMap A, aeval_algHom_apply, aeval_map_algebraMap, aeval_def, hP.2, _root_.map_zero] #align map_is_integral IsIntegral.map theorem IsIntegral.map_of_comp_eq {R S T U : Type*} [CommRing R] [Ring S] [CommRing T] [Ring U] [Algebra R S] [Algebra T U] (φ : R →+* T) (ψ : S →+* U) (h : (algebraMap T U).comp φ = ψ.comp (algebraMap R S)) {a : S} (ha : IsIntegral R a) : IsIntegral T (ψ a) := let ⟨p, hp⟩ := ha ⟨p.map φ, hp.1.map _, by rw [← eval_map, map_map, h, ← map_map, eval_map, eval₂_at_apply, eval_map, hp.2, ψ.map_zero]⟩ #align is_integral_map_of_comp_eq_of_is_integral IsIntegral.map_of_comp_eq section variable {A B : Type*} [Ring A] [Ring B] [Algebra R A] [Algebra R B] variable (f : A →ₐ[R] B) (hf : Function.Injective f) theorem isIntegral_algHom_iff {x : A} : IsIntegral R (f x) ↔ IsIntegral R x := by refine ⟨fun ⟨p, hp, hx⟩ ↦ ⟨p, hp, ?_⟩, IsIntegral.map f⟩ rwa [← f.comp_algebraMap, ← AlgHom.coe_toRingHom, ← hom_eval₂, AlgHom.coe_toRingHom, map_eq_zero_iff f hf] at hx #align is_integral_alg_hom_iff isIntegral_algHom_iff theorem Algebra.IsIntegral.of_injective [Algebra.IsIntegral R B] : Algebra.IsIntegral R A := ⟨fun _ ↦ (isIntegral_algHom_iff f hf).mp (isIntegral _)⟩ end @[simp] theorem isIntegral_algEquiv {A B : Type*} [Ring A] [Ring B] [Algebra R A] [Algebra R B] (f : A ≃ₐ[R] B) {x : A} : IsIntegral R (f x) ↔ IsIntegral R x := ⟨fun h ↦ by simpa using h.map f.symm, IsIntegral.map f⟩ #align is_integral_alg_equiv isIntegral_algEquiv /-- If `R → A → B` is an algebra tower, then if the entire tower is an integral extension so is `A → B`. -/ theorem IsIntegral.tower_top [Algebra A B] [IsScalarTower R A B] {x : B} (hx : IsIntegral R x) : IsIntegral A x := let ⟨p, hp, hpx⟩ := hx ⟨p.map <| algebraMap R A, hp.map _, by rw [← aeval_def, aeval_map_algebraMap, aeval_def, hpx]⟩ #align is_integral_of_is_scalar_tower IsIntegral.tower_top #align is_integral_tower_top_of_is_integral IsIntegral.tower_top theorem map_isIntegral_int {B C F : Type*} [Ring B] [Ring C] {b : B} [FunLike F B C] [RingHomClass F B C] (f : F) (hb : IsIntegral ℤ b) : IsIntegral ℤ (f b) := hb.map (f : B →+* C).toIntAlgHom #align map_is_integral_int map_isIntegral_int theorem IsIntegral.of_subring {x : B} (T : Subring R) (hx : IsIntegral T x) : IsIntegral R x := hx.tower_top #align is_integral_of_subring IsIntegral.of_subring protected theorem IsIntegral.algebraMap [Algebra A B] [IsScalarTower R A B] {x : A} (h : IsIntegral R x) : IsIntegral R (algebraMap A B x) := by rcases h with ⟨f, hf, hx⟩ use f, hf rw [IsScalarTower.algebraMap_eq R A B, ← hom_eval₂, hx, RingHom.map_zero] #align is_integral.algebra_map IsIntegral.algebraMap theorem isIntegral_algebraMap_iff [Algebra A B] [IsScalarTower R A B] {x : A} (hAB : Function.Injective (algebraMap A B)) : IsIntegral R (algebraMap A B x) ↔ IsIntegral R x := isIntegral_algHom_iff (IsScalarTower.toAlgHom R A B) hAB #align is_integral_algebra_map_iff isIntegral_algebraMap_iff theorem isIntegral_iff_isIntegral_closure_finite {r : B} : IsIntegral R r ↔ ∃ s : Set R, s.Finite ∧ IsIntegral (Subring.closure s) r := by constructor <;> intro hr · rcases hr with ⟨p, hmp, hpr⟩ refine ⟨_, Finset.finite_toSet _, p.restriction, monic_restriction.2 hmp, ?_⟩ rw [← aeval_def, ← aeval_map_algebraMap R r p.restriction, map_restriction, aeval_def, hpr] rcases hr with ⟨s, _, hsr⟩ exact hsr.of_subring _ #align is_integral_iff_is_integral_closure_finite isIntegral_iff_isIntegral_closure_finite theorem Submodule.span_range_natDegree_eq_adjoin {R A} [CommRing R] [Semiring A] [Algebra R A] {x : A} {f : R[X]} (hf : f.Monic) (hfx : aeval x f = 0) : span R (Finset.image (x ^ ·) (Finset.range (natDegree f))) = Subalgebra.toSubmodule (Algebra.adjoin R {x}) := by nontriviality A have hf1 : f ≠ 1 := by rintro rfl; simp [one_ne_zero' A] at hfx refine (span_le.mpr fun s hs ↦ ?_).antisymm fun r hr ↦ ?_ · rcases Finset.mem_image.1 hs with ⟨k, -, rfl⟩ exact (Algebra.adjoin R {x}).pow_mem (Algebra.subset_adjoin rfl) k rw [Subalgebra.mem_toSubmodule, Algebra.adjoin_singleton_eq_range_aeval] at hr rcases (aeval x).mem_range.mp hr with ⟨p, rfl⟩ rw [← modByMonic_add_div p hf, map_add, map_mul, hfx, zero_mul, add_zero, ← sum_C_mul_X_pow_eq (p %ₘ f), aeval_def, eval₂_sum, sum_def] refine sum_mem fun k hkq ↦ ?_ rw [C_mul_X_pow_eq_monomial, eval₂_monomial, ← Algebra.smul_def] exact smul_mem _ _ (subset_span <| Finset.mem_image_of_mem _ <| Finset.mem_range.mpr <| (le_natDegree_of_mem_supp _ hkq).trans_lt <| natDegree_modByMonic_lt p hf hf1) theorem IsIntegral.fg_adjoin_singleton {x : B} (hx : IsIntegral R x) : (Algebra.adjoin R {x}).toSubmodule.FG := by rcases hx with ⟨f, hfm, hfx⟩ use (Finset.range <| f.natDegree).image (x ^ ·) exact span_range_natDegree_eq_adjoin hfm (by rwa [aeval_def]) theorem fg_adjoin_of_finite {s : Set A} (hfs : s.Finite) (his : ∀ x ∈ s, IsIntegral R x) : (Algebra.adjoin R s).toSubmodule.FG := Set.Finite.induction_on hfs (fun _ => ⟨{1}, Submodule.ext fun x => by rw [Algebra.adjoin_empty, Finset.coe_singleton, ← one_eq_span, Algebra.toSubmodule_bot]⟩) (fun {a s} _ _ ih his => by rw [← Set.union_singleton, Algebra.adjoin_union_coe_submodule] exact FG.mul (ih fun i hi => his i <| Set.mem_insert_of_mem a hi) (his a <| Set.mem_insert a s).fg_adjoin_singleton) his #align fg_adjoin_of_finite fg_adjoin_of_finite theorem isNoetherian_adjoin_finset [IsNoetherianRing R] (s : Finset A) (hs : ∀ x ∈ s, IsIntegral R x) : IsNoetherian R (Algebra.adjoin R (s : Set A)) := isNoetherian_of_fg_of_noetherian _ (fg_adjoin_of_finite s.finite_toSet hs) #align is_noetherian_adjoin_finset isNoetherian_adjoin_finset instance Module.End.isIntegral {M : Type*} [AddCommGroup M] [Module R M] [Module.Finite R M] : Algebra.IsIntegral R (Module.End R M) := ⟨LinearMap.exists_monic_and_aeval_eq_zero R⟩ #align module.End.is_integral Module.End.isIntegral variable (R) theorem IsIntegral.of_finite [Module.Finite R B] (x : B) : IsIntegral R x := (isIntegral_algHom_iff (Algebra.lmul R B) Algebra.lmul_injective).mp (Algebra.IsIntegral.isIntegral _) variable (B) instance Algebra.IsIntegral.of_finite [Module.Finite R B] : Algebra.IsIntegral R B := ⟨.of_finite R⟩ #align algebra.is_integral.of_finite Algebra.IsIntegral.of_finite variable {R B} /-- If `S` is a sub-`R`-algebra of `A` and `S` is finitely-generated as an `R`-module, then all elements of `S` are integral over `R`. -/ theorem IsIntegral.of_mem_of_fg {A} [Ring A] [Algebra R A] (S : Subalgebra R A) (HS : S.toSubmodule.FG) (x : A) (hx : x ∈ S) : IsIntegral R x := have : Module.Finite R S := ⟨(fg_top _).mpr HS⟩ (isIntegral_algHom_iff S.val Subtype.val_injective).mpr (.of_finite R (⟨x, hx⟩ : S)) #align is_integral_of_mem_of_fg IsIntegral.of_mem_of_fg theorem isIntegral_of_noetherian (_ : IsNoetherian R B) (x : B) : IsIntegral R x := .of_finite R x #align is_integral_of_noetherian isIntegral_of_noetherian theorem isIntegral_of_submodule_noetherian (S : Subalgebra R B) (H : IsNoetherian R (Subalgebra.toSubmodule S)) (x : B) (hx : x ∈ S) : IsIntegral R x := .of_mem_of_fg _ ((fg_top _).mp <| H.noetherian _) _ hx #align is_integral_of_submodule_noetherian isIntegral_of_submodule_noetherian /-- Suppose `A` is an `R`-algebra, `M` is an `A`-module such that `a • m ≠ 0` for all non-zero `a` and `m`. If `x : A` fixes a nontrivial f.g. `R`-submodule `N` of `M`, then `x` is `R`-integral. -/ theorem isIntegral_of_smul_mem_submodule {M : Type*} [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors A M] (N : Submodule R M) (hN : N ≠ ⊥) (hN' : N.FG) (x : A) (hx : ∀ n ∈ N, x • n ∈ N) : IsIntegral R x := by let A' : Subalgebra R A := { carrier := { x | ∀ n ∈ N, x • n ∈ N } mul_mem' := fun {a b} ha hb n hn => smul_smul a b n ▸ ha _ (hb _ hn) one_mem' := fun n hn => (one_smul A n).symm ▸ hn add_mem' := fun {a b} ha hb n hn => (add_smul a b n).symm ▸ N.add_mem (ha _ hn) (hb _ hn) zero_mem' := fun n _hn => (zero_smul A n).symm ▸ N.zero_mem algebraMap_mem' := fun r n hn => (algebraMap_smul A r n).symm ▸ N.smul_mem r hn } let f : A' →ₐ[R] Module.End R N := AlgHom.ofLinearMap { toFun := fun x => (DistribMulAction.toLinearMap R M x).restrict x.prop -- Porting note: was -- `fun x y => LinearMap.ext fun n => Subtype.ext <| add_smul x y n` map_add' := by intros x y; ext; exact add_smul _ _ _ -- Porting note: was -- `fun r s => LinearMap.ext fun n => Subtype.ext <| smul_assoc r s n` map_smul' := by intros r s; ext; apply smul_assoc } -- Porting note: the next two lines were --`(LinearMap.ext fun n => Subtype.ext <| one_smul _ _) fun x y =>` --`LinearMap.ext fun n => Subtype.ext <| mul_smul x y n` (by ext; apply one_smul) (by intros x y; ext; apply mul_smul) obtain ⟨a, ha₁, ha₂⟩ : ∃ a ∈ N, a ≠ (0 : M) := by by_contra! h' apply hN rwa [eq_bot_iff] have : Function.Injective f := by show Function.Injective f.toLinearMap rw [← LinearMap.ker_eq_bot, eq_bot_iff] intro s hs have : s.1 • a = 0 := congr_arg Subtype.val (LinearMap.congr_fun hs ⟨a, ha₁⟩) exact Subtype.ext ((eq_zero_or_eq_zero_of_smul_eq_zero this).resolve_right ha₂) show IsIntegral R (A'.val ⟨x, hx⟩) rw [isIntegral_algHom_iff A'.val Subtype.val_injective, ← isIntegral_algHom_iff f this] haveI : Module.Finite R N := by rwa [Module.finite_def, Submodule.fg_top] apply Algebra.IsIntegral.isIntegral #align is_integral_of_smul_mem_submodule isIntegral_of_smul_mem_submodule variable {f} theorem RingHom.Finite.to_isIntegral (h : f.Finite) : f.IsIntegral := letI := f.toAlgebra fun _ ↦ IsIntegral.of_mem_of_fg ⊤ h.1 _ trivial #align ring_hom.finite.to_is_integral RingHom.Finite.to_isIntegral alias RingHom.IsIntegral.of_finite := RingHom.Finite.to_isIntegral #align ring_hom.is_integral.of_finite RingHom.IsIntegral.of_finite /-- The [Kurosh problem](https://en.wikipedia.org/wiki/Kurosh_problem) asks to show that this is still true when `A` is not necessarily commutative and `R` is a field, but it has been solved in the negative. See https://arxiv.org/pdf/1706.02383.pdf for criteria for a finitely generated algebraic (= integral) algebra over a field to be finite dimensional. This could be an `instance`, but we tend to go from `Module.Finite` to `IsIntegral`/`IsAlgebraic`, and making it an instance will cause the search to be complicated a lot. -/ theorem Algebra.IsIntegral.finite [Algebra.IsIntegral R A] [h' : Algebra.FiniteType R A] : Module.Finite R A := have ⟨s, hs⟩ := h' ⟨by apply hs ▸ fg_adjoin_of_finite s.finite_toSet fun x _ ↦ Algebra.IsIntegral.isIntegral x⟩ #align algebra.is_integral.finite Algebra.IsIntegral.finite /-- finite = integral + finite type -/ theorem Algebra.finite_iff_isIntegral_and_finiteType : Module.Finite R A ↔ Algebra.IsIntegral R A ∧ Algebra.FiniteType R A := ⟨fun _ ↦ ⟨⟨.of_finite R⟩, inferInstance⟩, fun ⟨h, _⟩ ↦ h.finite⟩ #align algebra.finite_iff_is_integral_and_finite_type Algebra.finite_iff_isIntegral_and_finiteType theorem RingHom.IsIntegral.to_finite (h : f.IsIntegral) (h' : f.FiniteType) : f.Finite := let _ := f.toAlgebra let _ : Algebra.IsIntegral R S := ⟨h⟩ Algebra.IsIntegral.finite (h' := h') #align ring_hom.is_integral.to_finite RingHom.IsIntegral.to_finite alias RingHom.Finite.of_isIntegral_of_finiteType := RingHom.IsIntegral.to_finite #align ring_hom.finite.of_is_integral_of_finite_type RingHom.Finite.of_isIntegral_of_finiteType /-- finite = integral + finite type -/ theorem RingHom.finite_iff_isIntegral_and_finiteType : f.Finite ↔ f.IsIntegral ∧ f.FiniteType := ⟨fun h ↦ ⟨h.to_isIntegral, h.to_finiteType⟩, fun ⟨h, h'⟩ ↦ h.to_finite h'⟩ #align ring_hom.finite_iff_is_integral_and_finite_type RingHom.finite_iff_isIntegral_and_finiteType variable (f) theorem RingHom.IsIntegralElem.of_mem_closure {x y z : S} (hx : f.IsIntegralElem x) (hy : f.IsIntegralElem y) (hz : z ∈ Subring.closure ({x, y} : Set S)) : f.IsIntegralElem z := by letI : Algebra R S := f.toAlgebra have := (IsIntegral.fg_adjoin_singleton hx).mul (IsIntegral.fg_adjoin_singleton hy) rw [← Algebra.adjoin_union_coe_submodule, Set.singleton_union] at this exact IsIntegral.of_mem_of_fg (Algebra.adjoin R {x, y}) this z (Algebra.mem_adjoin_iff.2 <| Subring.closure_mono Set.subset_union_right hz) #align ring_hom.is_integral_of_mem_closure RingHom.IsIntegralElem.of_mem_closure nonrec theorem IsIntegral.of_mem_closure {x y z : A} (hx : IsIntegral R x) (hy : IsIntegral R y) (hz : z ∈ Subring.closure ({x, y} : Set A)) : IsIntegral R z := hx.of_mem_closure (algebraMap R A) hy hz #align is_integral_of_mem_closure IsIntegral.of_mem_closure variable (f : R →+* B) theorem RingHom.isIntegralElem_zero : f.IsIntegralElem 0 := f.map_zero ▸ f.isIntegralElem_map #align ring_hom.is_integral_zero RingHom.isIntegralElem_zero theorem isIntegral_zero : IsIntegral R (0 : B) := (algebraMap R B).isIntegralElem_zero #align is_integral_zero isIntegral_zero theorem RingHom.isIntegralElem_one : f.IsIntegralElem 1 := f.map_one ▸ f.isIntegralElem_map #align ring_hom.is_integral_one RingHom.isIntegralElem_one theorem isIntegral_one : IsIntegral R (1 : B) := (algebraMap R B).isIntegralElem_one #align is_integral_one isIntegral_one theorem RingHom.IsIntegralElem.add (f : R →+* S) {x y : S} (hx : f.IsIntegralElem x) (hy : f.IsIntegralElem y) : f.IsIntegralElem (x + y) := hx.of_mem_closure f hy <| Subring.add_mem _ (Subring.subset_closure (Or.inl rfl)) (Subring.subset_closure (Or.inr rfl)) #align ring_hom.is_integral_add RingHom.IsIntegralElem.add nonrec theorem IsIntegral.add {x y : A} (hx : IsIntegral R x) (hy : IsIntegral R y) : IsIntegral R (x + y) := hx.add (algebraMap R A) hy #align is_integral_add IsIntegral.add variable (f : R →+* S) -- can be generalized to noncommutative S. theorem RingHom.IsIntegralElem.neg {x : S} (hx : f.IsIntegralElem x) : f.IsIntegralElem (-x) := hx.of_mem_closure f hx (Subring.neg_mem _ (Subring.subset_closure (Or.inl rfl))) #align ring_hom.is_integral_neg RingHom.IsIntegralElem.neg theorem IsIntegral.neg {x : B} (hx : IsIntegral R x) : IsIntegral R (-x) := .of_mem_of_fg _ hx.fg_adjoin_singleton _ (Subalgebra.neg_mem _ <| Algebra.subset_adjoin rfl) #align is_integral_neg IsIntegral.neg theorem RingHom.IsIntegralElem.sub {x y : S} (hx : f.IsIntegralElem x) (hy : f.IsIntegralElem y) : f.IsIntegralElem (x - y) := by simpa only [sub_eq_add_neg] using hx.add f (hy.neg f) #align ring_hom.is_integral_sub RingHom.IsIntegralElem.sub nonrec theorem IsIntegral.sub {x y : A} (hx : IsIntegral R x) (hy : IsIntegral R y) : IsIntegral R (x - y) := hx.sub (algebraMap R A) hy #align is_integral_sub IsIntegral.sub theorem RingHom.IsIntegralElem.mul {x y : S} (hx : f.IsIntegralElem x) (hy : f.IsIntegralElem y) : f.IsIntegralElem (x * y) := hx.of_mem_closure f hy (Subring.mul_mem _ (Subring.subset_closure (Or.inl rfl)) (Subring.subset_closure (Or.inr rfl))) #align ring_hom.is_integral_mul RingHom.IsIntegralElem.mul nonrec theorem IsIntegral.mul {x y : A} (hx : IsIntegral R x) (hy : IsIntegral R y) : IsIntegral R (x * y) := hx.mul (algebraMap R A) hy #align is_integral_mul IsIntegral.mul theorem IsIntegral.smul {R} [CommSemiring R] [CommRing S] [Algebra R B] [Algebra S B] [Algebra R S] [IsScalarTower R S B] {x : B} (r : R)(hx : IsIntegral S x) : IsIntegral S (r • x) := .of_mem_of_fg _ hx.fg_adjoin_singleton _ <| by rw [← algebraMap_smul S]; apply Subalgebra.smul_mem; exact Algebra.subset_adjoin rfl #align is_integral_smul IsIntegral.smul theorem IsIntegral.of_pow {x : B} {n : ℕ} (hn : 0 < n) (hx : IsIntegral R <| x ^ n) : IsIntegral R x := by rcases hx with ⟨p, hmonic, heval⟩ exact ⟨expand R n p, hmonic.expand hn, by rwa [← aeval_def, expand_aeval]⟩ #align is_integral_of_pow IsIntegral.of_pow variable (R A) /-- The integral closure of R in an R-algebra A. -/ def integralClosure : Subalgebra R A where carrier := { r | IsIntegral R r } zero_mem' := isIntegral_zero one_mem' := isIntegral_one add_mem' := IsIntegral.add mul_mem' := IsIntegral.mul algebraMap_mem' _ := isIntegral_algebraMap #align integral_closure integralClosure theorem mem_integralClosure_iff_mem_fg {r : A} : r ∈ integralClosure R A ↔ ∃ M : Subalgebra R A, M.toSubmodule.FG ∧ r ∈ M := ⟨fun hr => ⟨Algebra.adjoin R {r}, hr.fg_adjoin_singleton, Algebra.subset_adjoin rfl⟩, fun ⟨M, Hf, hrM⟩ => .of_mem_of_fg M Hf _ hrM⟩ #align mem_integral_closure_iff_mem_fg mem_integralClosure_iff_mem_fg variable {R A} theorem adjoin_le_integralClosure {x : A} (hx : IsIntegral R x) : Algebra.adjoin R {x} ≤ integralClosure R A := by rw [Algebra.adjoin_le_iff] simp only [SetLike.mem_coe, Set.singleton_subset_iff] exact hx #align adjoin_le_integral_closure adjoin_le_integralClosure theorem le_integralClosure_iff_isIntegral {S : Subalgebra R A} : S ≤ integralClosure R A ↔ Algebra.IsIntegral R S := SetLike.forall.symm.trans <| (forall_congr' fun x => show IsIntegral R (algebraMap S A x) ↔ IsIntegral R x from isIntegral_algebraMap_iff Subtype.coe_injective).trans Algebra.isIntegral_def.symm #align le_integral_closure_iff_is_integral le_integralClosure_iff_isIntegral theorem Algebra.isIntegral_sup {S T : Subalgebra R A} : Algebra.IsIntegral R (S ⊔ T : Subalgebra R A) ↔ Algebra.IsIntegral R S ∧ Algebra.IsIntegral R T := by simp only [← le_integralClosure_iff_isIntegral, sup_le_iff] #align is_integral_sup Algebra.isIntegral_sup /-- Mapping an integral closure along an `AlgEquiv` gives the integral closure. -/ theorem integralClosure_map_algEquiv [Algebra R S] (f : A ≃ₐ[R] S) : (integralClosure R A).map (f : A →ₐ[R] S) = integralClosure R S := by ext y rw [Subalgebra.mem_map] constructor · rintro ⟨x, hx, rfl⟩ exact hx.map f · intro hy use f.symm y, hy.map (f.symm : S →ₐ[R] A) simp #align integral_closure_map_alg_equiv integralClosure_map_algEquiv /-- An `AlgHom` between two rings restrict to an `AlgHom` between the integral closures inside them. -/ def AlgHom.mapIntegralClosure [Algebra R S] (f : A →ₐ[R] S) : integralClosure R A →ₐ[R] integralClosure R S := (f.restrictDomain (integralClosure R A)).codRestrict (integralClosure R S) (fun ⟨_, h⟩ => h.map f) @[simp] theorem AlgHom.coe_mapIntegralClosure [Algebra R S] (f : A →ₐ[R] S) (x : integralClosure R A) : (f.mapIntegralClosure x : S) = f (x : A) := rfl /-- An `AlgEquiv` between two rings restrict to an `AlgEquiv` between the integral closures inside them. -/ def AlgEquiv.mapIntegralClosure [Algebra R S] (f : A ≃ₐ[R] S) : integralClosure R A ≃ₐ[R] integralClosure R S := AlgEquiv.ofAlgHom (f : A →ₐ[R] S).mapIntegralClosure (f.symm : S →ₐ[R] A).mapIntegralClosure (AlgHom.ext fun _ ↦ Subtype.ext (f.right_inv _)) (AlgHom.ext fun _ ↦ Subtype.ext (f.left_inv _)) @[simp] theorem AlgEquiv.coe_mapIntegralClosure [Algebra R S] (f : A ≃ₐ[R] S) (x : integralClosure R A) : (f.mapIntegralClosure x : S) = f (x : A) := rfl theorem integralClosure.isIntegral (x : integralClosure R A) : IsIntegral R x := let ⟨p, hpm, hpx⟩ := x.2 ⟨p, hpm, Subtype.eq <| by rwa [← aeval_def, ← Subalgebra.val_apply, aeval_algHom_apply] at hpx⟩ #align integral_closure.is_integral integralClosure.isIntegral instance integralClosure.AlgebraIsIntegral : Algebra.IsIntegral R (integralClosure R A) := ⟨integralClosure.isIntegral⟩ theorem IsIntegral.of_mul_unit {x y : B} {r : R} (hr : algebraMap R B r * y = 1) (hx : IsIntegral R (x * y)) : IsIntegral R x := by obtain ⟨p, p_monic, hp⟩ := hx refine ⟨scaleRoots p r, (monic_scaleRoots_iff r).2 p_monic, ?_⟩ convert scaleRoots_aeval_eq_zero hp rw [Algebra.commutes] at hr ⊢ rw [mul_assoc, hr, mul_one]; rfl #align is_integral_of_is_integral_mul_unit IsIntegral.of_mul_unit theorem RingHom.IsIntegralElem.of_mul_unit (x y : S) (r : R) (hr : f r * y = 1) (hx : f.IsIntegralElem (x * y)) : f.IsIntegralElem x := letI : Algebra R S := f.toAlgebra IsIntegral.of_mul_unit hr hx #align ring_hom.is_integral_of_is_integral_mul_unit RingHom.IsIntegralElem.of_mul_unit /-- Generalization of `IsIntegral.of_mem_closure` bootstrapped up from that lemma -/ theorem IsIntegral.of_mem_closure' (G : Set A) (hG : ∀ x ∈ G, IsIntegral R x) : ∀ x ∈ Subring.closure G, IsIntegral R x := fun _ hx ↦ Subring.closure_induction hx hG isIntegral_zero isIntegral_one (fun _ _ ↦ IsIntegral.add) (fun _ ↦ IsIntegral.neg) fun _ _ ↦ IsIntegral.mul #align is_integral_of_mem_closure' IsIntegral.of_mem_closure' theorem IsIntegral.of_mem_closure'' {S : Type*} [CommRing S] {f : R →+* S} (G : Set S) (hG : ∀ x ∈ G, f.IsIntegralElem x) : ∀ x ∈ Subring.closure G, f.IsIntegralElem x := fun x hx => @IsIntegral.of_mem_closure' R S _ _ f.toAlgebra G hG x hx #align is_integral_of_mem_closure'' IsIntegral.of_mem_closure'' theorem IsIntegral.pow {x : B} (h : IsIntegral R x) (n : ℕ) : IsIntegral R (x ^ n) := .of_mem_of_fg _ h.fg_adjoin_singleton _ <| Subalgebra.pow_mem _ (by exact Algebra.subset_adjoin rfl) _ #align is_integral.pow IsIntegral.pow theorem IsIntegral.nsmul {x : B} (h : IsIntegral R x) (n : ℕ) : IsIntegral R (n • x) := h.smul n #align is_integral.nsmul IsIntegral.nsmul theorem IsIntegral.zsmul {x : B} (h : IsIntegral R x) (n : ℤ) : IsIntegral R (n • x) := h.smul n #align is_integral.zsmul IsIntegral.zsmul theorem IsIntegral.multiset_prod {s : Multiset A} (h : ∀ x ∈ s, IsIntegral R x) : IsIntegral R s.prod := (integralClosure R A).multiset_prod_mem h #align is_integral.multiset_prod IsIntegral.multiset_prod theorem IsIntegral.multiset_sum {s : Multiset A} (h : ∀ x ∈ s, IsIntegral R x) : IsIntegral R s.sum := (integralClosure R A).multiset_sum_mem h #align is_integral.multiset_sum IsIntegral.multiset_sum theorem IsIntegral.prod {α : Type*} {s : Finset α} (f : α → A) (h : ∀ x ∈ s, IsIntegral R (f x)) : IsIntegral R (∏ x ∈ s, f x) := (integralClosure R A).prod_mem h #align is_integral.prod IsIntegral.prod theorem IsIntegral.sum {α : Type*} {s : Finset α} (f : α → A) (h : ∀ x ∈ s, IsIntegral R (f x)) : IsIntegral R (∑ x ∈ s, f x) := (integralClosure R A).sum_mem h #align is_integral.sum IsIntegral.sum theorem IsIntegral.det {n : Type*} [Fintype n] [DecidableEq n] {M : Matrix n n A} (h : ∀ i j, IsIntegral R (M i j)) : IsIntegral R M.det := by rw [Matrix.det_apply] exact IsIntegral.sum _ fun σ _hσ ↦ (IsIntegral.prod _ fun i _hi => h _ _).zsmul _ #align is_integral.det IsIntegral.det @[simp] theorem IsIntegral.pow_iff {x : A} {n : ℕ} (hn : 0 < n) : IsIntegral R (x ^ n) ↔ IsIntegral R x := ⟨IsIntegral.of_pow hn, fun hx ↦ hx.pow n⟩ #align is_integral.pow_iff IsIntegral.pow_iff open TensorProduct theorem IsIntegral.tmul (x : A) {y : B} (h : IsIntegral R y) : IsIntegral A (x ⊗ₜ[R] y) := by rw [← mul_one x, ← smul_eq_mul, ← smul_tmul'] exact smul _ (h.map_of_comp_eq (algebraMap R A) (Algebra.TensorProduct.includeRight (R := R) (A := A) (B := B)).toRingHom Algebra.TensorProduct.includeLeftRingHom_comp_algebraMap) #align is_integral.tmul IsIntegral.tmul section variable (p : R[X]) (x : S) /-- The monic polynomial whose roots are `p.leadingCoeff * x` for roots `x` of `p`. -/ noncomputable def normalizeScaleRoots (p : R[X]) : R[X] := ∑ i ∈ p.support, monomial i (if i = p.natDegree then 1 else p.coeff i * p.leadingCoeff ^ (p.natDegree - 1 - i)) #align normalize_scale_roots normalizeScaleRoots theorem normalizeScaleRoots_coeff_mul_leadingCoeff_pow (i : ℕ) (hp : 1 ≤ natDegree p) : (normalizeScaleRoots p).coeff i * p.leadingCoeff ^ i = p.coeff i * p.leadingCoeff ^ (p.natDegree - 1) := by simp only [normalizeScaleRoots, finset_sum_coeff, coeff_monomial, Finset.sum_ite_eq', one_mul, zero_mul, mem_support_iff, ite_mul, Ne, ite_not] split_ifs with h₁ h₂ · simp [h₁] · rw [h₂, leadingCoeff, ← pow_succ', tsub_add_cancel_of_le hp] · rw [mul_assoc, ← pow_add, tsub_add_cancel_of_le] apply Nat.le_sub_one_of_lt rw [lt_iff_le_and_ne] exact ⟨le_natDegree_of_ne_zero h₁, h₂⟩ #align normalize_scale_roots_coeff_mul_leading_coeff_pow normalizeScaleRoots_coeff_mul_leadingCoeff_pow theorem leadingCoeff_smul_normalizeScaleRoots (p : R[X]) : p.leadingCoeff • normalizeScaleRoots p = scaleRoots p p.leadingCoeff := by ext simp only [coeff_scaleRoots, normalizeScaleRoots, coeff_monomial, coeff_smul, Finset.smul_sum, Ne, Finset.sum_ite_eq', finset_sum_coeff, smul_ite, smul_zero, mem_support_iff] -- Porting note: added the following `simp only` simp only [ge_iff_le, tsub_le_iff_right, smul_eq_mul, mul_ite, mul_one, mul_zero, Finset.sum_ite_eq', mem_support_iff, ne_eq, ite_not] split_ifs with h₁ h₂ · simp [*] · simp [*] · rw [mul_comm, mul_assoc, ← pow_succ, tsub_right_comm, tsub_add_cancel_of_le] rw [Nat.succ_le_iff] exact tsub_pos_of_lt (lt_of_le_of_ne (le_natDegree_of_ne_zero h₁) h₂) #align leading_coeff_smul_normalize_scale_roots leadingCoeff_smul_normalizeScaleRoots
Mathlib/RingTheory/IntegralClosure.lean
640
646
theorem normalizeScaleRoots_support : (normalizeScaleRoots p).support ≤ p.support := by
intro x contrapose simp only [not_mem_support_iff, normalizeScaleRoots, finset_sum_coeff, coeff_monomial, Finset.sum_ite_eq', mem_support_iff, Ne, Classical.not_not, ite_eq_right_iff] intro h₁ h₂ exact (h₂ h₁).elim
/- 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.Algebra.Order.Ring.Nat import Mathlib.Combinatorics.SetFamily.Compression.Down import Mathlib.Order.UpperLower.Basic import Mathlib.Data.Fintype.Powerset #align_import combinatorics.set_family.harris_kleitman from "leanprover-community/mathlib"@"b363547b3113d350d053abdf2884e9850a56b205" /-! # Harris-Kleitman inequality This file proves the Harris-Kleitman inequality. This relates `𝒜.card * ℬ.card` and `2 ^ card α * (𝒜 ∩ ℬ).card` where `𝒜` and `ℬ` are upward- or downcard-closed finite families of finsets. This can be interpreted as saying that any two lower sets (resp. any two upper sets) correlate in the uniform measure. ## Main declarations * `IsLowerSet.le_card_inter_finset`: One form of the Harris-Kleitman inequality. ## References * [D. J. Kleitman, *Families of non-disjoint subsets*][kleitman1966] -/ open Finset variable {α : Type*} [DecidableEq α] {𝒜 ℬ : Finset (Finset α)} {s : Finset α} {a : α} theorem IsLowerSet.nonMemberSubfamily (h : IsLowerSet (𝒜 : Set (Finset α))) : IsLowerSet (𝒜.nonMemberSubfamily a : Set (Finset α)) := fun s t hts => by simp_rw [mem_coe, mem_nonMemberSubfamily] exact And.imp (h hts) (mt <| @hts _) #align is_lower_set.non_member_subfamily IsLowerSet.nonMemberSubfamily
Mathlib/Combinatorics/SetFamily/HarrisKleitman.lean
41
45
theorem IsLowerSet.memberSubfamily (h : IsLowerSet (𝒜 : Set (Finset α))) : IsLowerSet (𝒜.memberSubfamily a : Set (Finset α)) := by
rintro s t hts simp_rw [mem_coe, mem_memberSubfamily] exact And.imp (h <| insert_subset_insert _ hts) (mt <| @hts _)
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl -/ import Mathlib.Dynamics.Ergodic.MeasurePreserving import Mathlib.MeasureTheory.Function.SimpleFunc import Mathlib.MeasureTheory.Measure.MutuallySingular import Mathlib.MeasureTheory.Measure.Count import Mathlib.Topology.IndicatorConstPointwise import Mathlib.MeasureTheory.Constructions.BorelSpace.Real #align_import measure_theory.integral.lebesgue from "leanprover-community/mathlib"@"c14c8fcde993801fca8946b0d80131a1a81d1520" /-! # Lower Lebesgue integral for `ℝ≥0∞`-valued functions We define the lower Lebesgue integral of an `ℝ≥0∞`-valued function. ## Notation We introduce the following notation for the lower Lebesgue integral of a function `f : α → ℝ≥0∞`. * `∫⁻ x, f x ∂μ`: integral of a function `f : α → ℝ≥0∞` with respect to a measure `μ`; * `∫⁻ x, f x`: integral of a function `f : α → ℝ≥0∞` with respect to the canonical measure `volume` on `α`; * `∫⁻ x in s, f x ∂μ`: integral of a function `f : α → ℝ≥0∞` over a set `s` with respect to a measure `μ`, defined as `∫⁻ x, f x ∂(μ.restrict s)`; * `∫⁻ x in s, f x`: integral of a function `f : α → ℝ≥0∞` over a set `s` with respect to the canonical measure `volume`, defined as `∫⁻ x, f x ∂(volume.restrict s)`. -/ assert_not_exists NormedSpace set_option autoImplicit true noncomputable section open Set hiding restrict restrict_apply open Filter ENNReal open Function (support) open scoped Classical open Topology NNReal ENNReal MeasureTheory namespace MeasureTheory local infixr:25 " →ₛ " => SimpleFunc variable {α β γ δ : Type*} section Lintegral open SimpleFunc variable {m : MeasurableSpace α} {μ ν : Measure α} /-- The **lower Lebesgue integral** of a function `f` with respect to a measure `μ`. -/ irreducible_def lintegral {_ : MeasurableSpace α} (μ : Measure α) (f : α → ℝ≥0∞) : ℝ≥0∞ := ⨆ (g : α →ₛ ℝ≥0∞) (_ : ⇑g ≤ f), g.lintegral μ #align measure_theory.lintegral MeasureTheory.lintegral /-! In the notation for integrals, an expression like `∫⁻ x, g ‖x‖ ∂μ` will not be parsed correctly, and needs parentheses. We do not set the binding power of `r` to `0`, because then `∫⁻ x, f x = 0` will be parsed incorrectly. -/ @[inherit_doc MeasureTheory.lintegral] notation3 "∫⁻ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => lintegral μ r @[inherit_doc MeasureTheory.lintegral] notation3 "∫⁻ "(...)", "r:60:(scoped f => lintegral volume f) => r @[inherit_doc MeasureTheory.lintegral] notation3"∫⁻ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => lintegral (Measure.restrict μ s) r @[inherit_doc MeasureTheory.lintegral] notation3"∫⁻ "(...)" in "s", "r:60:(scoped f => lintegral (Measure.restrict volume s) f) => r theorem SimpleFunc.lintegral_eq_lintegral {m : MeasurableSpace α} (f : α →ₛ ℝ≥0∞) (μ : Measure α) : ∫⁻ a, f a ∂μ = f.lintegral μ := by rw [MeasureTheory.lintegral] exact le_antisymm (iSup₂_le fun g hg => lintegral_mono hg <| le_rfl) (le_iSup₂_of_le f le_rfl le_rfl) #align measure_theory.simple_func.lintegral_eq_lintegral MeasureTheory.SimpleFunc.lintegral_eq_lintegral @[mono] theorem lintegral_mono' {m : MeasurableSpace α} ⦃μ ν : Measure α⦄ (hμν : μ ≤ ν) ⦃f g : α → ℝ≥0∞⦄ (hfg : f ≤ g) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂ν := by rw [lintegral, lintegral] exact iSup_mono fun φ => iSup_mono' fun hφ => ⟨le_trans hφ hfg, lintegral_mono (le_refl φ) hμν⟩ #align measure_theory.lintegral_mono' MeasureTheory.lintegral_mono' -- workaround for the known eta-reduction issue with `@[gcongr]` @[gcongr] theorem lintegral_mono_fn' ⦃f g : α → ℝ≥0∞⦄ (hfg : ∀ x, f x ≤ g x) (h2 : μ ≤ ν) : lintegral μ f ≤ lintegral ν g := lintegral_mono' h2 hfg theorem lintegral_mono ⦃f g : α → ℝ≥0∞⦄ (hfg : f ≤ g) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂μ := lintegral_mono' (le_refl μ) hfg #align measure_theory.lintegral_mono MeasureTheory.lintegral_mono -- workaround for the known eta-reduction issue with `@[gcongr]` @[gcongr] theorem lintegral_mono_fn ⦃f g : α → ℝ≥0∞⦄ (hfg : ∀ x, f x ≤ g x) : lintegral μ f ≤ lintegral μ g := lintegral_mono hfg theorem lintegral_mono_nnreal {f g : α → ℝ≥0} (h : f ≤ g) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂μ := lintegral_mono fun a => ENNReal.coe_le_coe.2 (h a) #align measure_theory.lintegral_mono_nnreal MeasureTheory.lintegral_mono_nnreal theorem iSup_lintegral_measurable_le_eq_lintegral (f : α → ℝ≥0∞) : ⨆ (g : α → ℝ≥0∞) (_ : Measurable g) (_ : g ≤ f), ∫⁻ a, g a ∂μ = ∫⁻ a, f a ∂μ := by apply le_antisymm · exact iSup_le fun i => iSup_le fun _ => iSup_le fun h'i => lintegral_mono h'i · rw [lintegral] refine iSup₂_le fun i hi => le_iSup₂_of_le i i.measurable <| le_iSup_of_le hi ?_ exact le_of_eq (i.lintegral_eq_lintegral _).symm #align measure_theory.supr_lintegral_measurable_le_eq_lintegral MeasureTheory.iSup_lintegral_measurable_le_eq_lintegral theorem lintegral_mono_set {_ : MeasurableSpace α} ⦃μ : Measure α⦄ {s t : Set α} {f : α → ℝ≥0∞} (hst : s ⊆ t) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in t, f x ∂μ := lintegral_mono' (Measure.restrict_mono hst (le_refl μ)) (le_refl f) #align measure_theory.lintegral_mono_set MeasureTheory.lintegral_mono_set theorem lintegral_mono_set' {_ : MeasurableSpace α} ⦃μ : Measure α⦄ {s t : Set α} {f : α → ℝ≥0∞} (hst : s ≤ᵐ[μ] t) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in t, f x ∂μ := lintegral_mono' (Measure.restrict_mono' hst (le_refl μ)) (le_refl f) #align measure_theory.lintegral_mono_set' MeasureTheory.lintegral_mono_set' theorem monotone_lintegral {_ : MeasurableSpace α} (μ : Measure α) : Monotone (lintegral μ) := lintegral_mono #align measure_theory.monotone_lintegral MeasureTheory.monotone_lintegral @[simp] theorem lintegral_const (c : ℝ≥0∞) : ∫⁻ _, c ∂μ = c * μ univ := by rw [← SimpleFunc.const_lintegral, ← SimpleFunc.lintegral_eq_lintegral, SimpleFunc.coe_const] rfl #align measure_theory.lintegral_const MeasureTheory.lintegral_const theorem lintegral_zero : ∫⁻ _ : α, 0 ∂μ = 0 := by simp #align measure_theory.lintegral_zero MeasureTheory.lintegral_zero theorem lintegral_zero_fun : lintegral μ (0 : α → ℝ≥0∞) = 0 := lintegral_zero #align measure_theory.lintegral_zero_fun MeasureTheory.lintegral_zero_fun -- @[simp] -- Porting note (#10618): simp can prove this theorem lintegral_one : ∫⁻ _, (1 : ℝ≥0∞) ∂μ = μ univ := by rw [lintegral_const, one_mul] #align measure_theory.lintegral_one MeasureTheory.lintegral_one theorem set_lintegral_const (s : Set α) (c : ℝ≥0∞) : ∫⁻ _ in s, c ∂μ = c * μ s := by rw [lintegral_const, Measure.restrict_apply_univ] #align measure_theory.set_lintegral_const MeasureTheory.set_lintegral_const theorem set_lintegral_one (s) : ∫⁻ _ in s, 1 ∂μ = μ s := by rw [set_lintegral_const, one_mul] #align measure_theory.set_lintegral_one MeasureTheory.set_lintegral_one theorem set_lintegral_const_lt_top [IsFiniteMeasure μ] (s : Set α) {c : ℝ≥0∞} (hc : c ≠ ∞) : ∫⁻ _ in s, c ∂μ < ∞ := by rw [lintegral_const] exact ENNReal.mul_lt_top hc (measure_ne_top (μ.restrict s) univ) #align measure_theory.set_lintegral_const_lt_top MeasureTheory.set_lintegral_const_lt_top theorem lintegral_const_lt_top [IsFiniteMeasure μ] {c : ℝ≥0∞} (hc : c ≠ ∞) : ∫⁻ _, c ∂μ < ∞ := by simpa only [Measure.restrict_univ] using set_lintegral_const_lt_top (univ : Set α) hc #align measure_theory.lintegral_const_lt_top MeasureTheory.lintegral_const_lt_top section variable (μ) /-- For any function `f : α → ℝ≥0∞`, there exists a measurable function `g ≤ f` with the same integral. -/ theorem exists_measurable_le_lintegral_eq (f : α → ℝ≥0∞) : ∃ g : α → ℝ≥0∞, Measurable g ∧ g ≤ f ∧ ∫⁻ a, f a ∂μ = ∫⁻ a, g a ∂μ := by rcases eq_or_ne (∫⁻ a, f a ∂μ) 0 with h₀ | h₀ · exact ⟨0, measurable_zero, zero_le f, h₀.trans lintegral_zero.symm⟩ rcases exists_seq_strictMono_tendsto' h₀.bot_lt with ⟨L, _, hLf, hL_tendsto⟩ have : ∀ n, ∃ g : α → ℝ≥0∞, Measurable g ∧ g ≤ f ∧ L n < ∫⁻ a, g a ∂μ := by intro n simpa only [← iSup_lintegral_measurable_le_eq_lintegral f, lt_iSup_iff, exists_prop] using (hLf n).2 choose g hgm hgf hLg using this refine ⟨fun x => ⨆ n, g n x, measurable_iSup hgm, fun x => iSup_le fun n => hgf n x, le_antisymm ?_ ?_⟩ · refine le_of_tendsto' hL_tendsto fun n => (hLg n).le.trans <| lintegral_mono fun x => ?_ exact le_iSup (fun n => g n x) n · exact lintegral_mono fun x => iSup_le fun n => hgf n x #align measure_theory.exists_measurable_le_lintegral_eq MeasureTheory.exists_measurable_le_lintegral_eq end /-- `∫⁻ a in s, f a ∂μ` is defined as the supremum of integrals of simple functions `φ : α →ₛ ℝ≥0∞` such that `φ ≤ f`. This lemma says that it suffices to take functions `φ : α →ₛ ℝ≥0`. -/ theorem lintegral_eq_nnreal {m : MeasurableSpace α} (f : α → ℝ≥0∞) (μ : Measure α) : ∫⁻ a, f a ∂μ = ⨆ (φ : α →ₛ ℝ≥0) (_ : ∀ x, ↑(φ x) ≤ f x), (φ.map ((↑) : ℝ≥0 → ℝ≥0∞)).lintegral μ := by rw [lintegral] refine le_antisymm (iSup₂_le fun φ hφ => ?_) (iSup_mono' fun φ => ⟨φ.map ((↑) : ℝ≥0 → ℝ≥0∞), le_rfl⟩) by_cases h : ∀ᵐ a ∂μ, φ a ≠ ∞ · let ψ := φ.map ENNReal.toNNReal replace h : ψ.map ((↑) : ℝ≥0 → ℝ≥0∞) =ᵐ[μ] φ := h.mono fun a => ENNReal.coe_toNNReal have : ∀ x, ↑(ψ x) ≤ f x := fun x => le_trans ENNReal.coe_toNNReal_le_self (hφ x) exact le_iSup_of_le (φ.map ENNReal.toNNReal) (le_iSup_of_le this (ge_of_eq <| lintegral_congr h)) · have h_meas : μ (φ ⁻¹' {∞}) ≠ 0 := mt measure_zero_iff_ae_nmem.1 h refine le_trans le_top (ge_of_eq <| (iSup_eq_top _).2 fun b hb => ?_) obtain ⟨n, hn⟩ : ∃ n : ℕ, b < n * μ (φ ⁻¹' {∞}) := exists_nat_mul_gt h_meas (ne_of_lt hb) use (const α (n : ℝ≥0)).restrict (φ ⁻¹' {∞}) simp only [lt_iSup_iff, exists_prop, coe_restrict, φ.measurableSet_preimage, coe_const, ENNReal.coe_indicator, map_coe_ennreal_restrict, SimpleFunc.map_const, ENNReal.coe_natCast, restrict_const_lintegral] refine ⟨indicator_le fun x hx => le_trans ?_ (hφ _), hn⟩ simp only [mem_preimage, mem_singleton_iff] at hx simp only [hx, le_top] #align measure_theory.lintegral_eq_nnreal MeasureTheory.lintegral_eq_nnreal theorem exists_simpleFunc_forall_lintegral_sub_lt_of_pos {f : α → ℝ≥0∞} (h : ∫⁻ x, f x ∂μ ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ φ : α →ₛ ℝ≥0, (∀ x, ↑(φ x) ≤ f x) ∧ ∀ ψ : α →ₛ ℝ≥0, (∀ x, ↑(ψ x) ≤ f x) → (map (↑) (ψ - φ)).lintegral μ < ε := by rw [lintegral_eq_nnreal] at h have := ENNReal.lt_add_right h hε erw [ENNReal.biSup_add] at this <;> [skip; exact ⟨0, fun x => zero_le _⟩] simp_rw [lt_iSup_iff, iSup_lt_iff, iSup_le_iff] at this rcases this with ⟨φ, hle : ∀ x, ↑(φ x) ≤ f x, b, hbφ, hb⟩ refine ⟨φ, hle, fun ψ hψ => ?_⟩ have : (map (↑) φ).lintegral μ ≠ ∞ := ne_top_of_le_ne_top h (by exact le_iSup₂ (α := ℝ≥0∞) φ hle) rw [← ENNReal.add_lt_add_iff_left this, ← add_lintegral, ← SimpleFunc.map_add @ENNReal.coe_add] refine (hb _ fun x => le_trans ?_ (max_le (hle x) (hψ x))).trans_lt hbφ norm_cast simp only [add_apply, sub_apply, add_tsub_eq_max] rfl #align measure_theory.exists_simple_func_forall_lintegral_sub_lt_of_pos MeasureTheory.exists_simpleFunc_forall_lintegral_sub_lt_of_pos theorem iSup_lintegral_le {ι : Sort*} (f : ι → α → ℝ≥0∞) : ⨆ i, ∫⁻ a, f i a ∂μ ≤ ∫⁻ a, ⨆ i, f i a ∂μ := by simp only [← iSup_apply] exact (monotone_lintegral μ).le_map_iSup #align measure_theory.supr_lintegral_le MeasureTheory.iSup_lintegral_le theorem iSup₂_lintegral_le {ι : Sort*} {ι' : ι → Sort*} (f : ∀ i, ι' i → α → ℝ≥0∞) : ⨆ (i) (j), ∫⁻ a, f i j a ∂μ ≤ ∫⁻ a, ⨆ (i) (j), f i j a ∂μ := by convert (monotone_lintegral μ).le_map_iSup₂ f with a simp only [iSup_apply] #align measure_theory.supr₂_lintegral_le MeasureTheory.iSup₂_lintegral_le theorem le_iInf_lintegral {ι : Sort*} (f : ι → α → ℝ≥0∞) : ∫⁻ a, ⨅ i, f i a ∂μ ≤ ⨅ i, ∫⁻ a, f i a ∂μ := by simp only [← iInf_apply] exact (monotone_lintegral μ).map_iInf_le #align measure_theory.le_infi_lintegral MeasureTheory.le_iInf_lintegral theorem le_iInf₂_lintegral {ι : Sort*} {ι' : ι → Sort*} (f : ∀ i, ι' i → α → ℝ≥0∞) : ∫⁻ a, ⨅ (i) (h : ι' i), f i h a ∂μ ≤ ⨅ (i) (h : ι' i), ∫⁻ a, f i h a ∂μ := by convert (monotone_lintegral μ).map_iInf₂_le f with a simp only [iInf_apply] #align measure_theory.le_infi₂_lintegral MeasureTheory.le_iInf₂_lintegral theorem lintegral_mono_ae {f g : α → ℝ≥0∞} (h : ∀ᵐ a ∂μ, f a ≤ g a) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂μ := by rcases exists_measurable_superset_of_null h with ⟨t, hts, ht, ht0⟩ have : ∀ᵐ x ∂μ, x ∉ t := measure_zero_iff_ae_nmem.1 ht0 rw [lintegral, lintegral] refine iSup_le fun s => iSup_le fun hfs => le_iSup_of_le (s.restrict tᶜ) <| le_iSup_of_le ?_ ?_ · intro a by_cases h : a ∈ t <;> simp only [restrict_apply s ht.compl, mem_compl_iff, h, not_true, not_false_eq_true, indicator_of_not_mem, zero_le, not_false_eq_true, indicator_of_mem] exact le_trans (hfs a) (_root_.by_contradiction fun hnfg => h (hts hnfg)) · refine le_of_eq (SimpleFunc.lintegral_congr <| this.mono fun a hnt => ?_) by_cases hat : a ∈ t <;> simp only [restrict_apply s ht.compl, mem_compl_iff, hat, not_true, not_false_eq_true, indicator_of_not_mem, not_false_eq_true, indicator_of_mem] exact (hnt hat).elim #align measure_theory.lintegral_mono_ae MeasureTheory.lintegral_mono_ae theorem set_lintegral_mono_ae {s : Set α} {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) (hfg : ∀ᵐ x ∂μ, x ∈ s → f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ := lintegral_mono_ae <| (ae_restrict_iff <| measurableSet_le hf hg).2 hfg #align measure_theory.set_lintegral_mono_ae MeasureTheory.set_lintegral_mono_ae theorem set_lintegral_mono {s : Set α} {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) (hfg : ∀ x ∈ s, f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ := set_lintegral_mono_ae hf hg (ae_of_all _ hfg) #align measure_theory.set_lintegral_mono MeasureTheory.set_lintegral_mono theorem set_lintegral_mono_ae' {s : Set α} {f g : α → ℝ≥0∞} (hs : MeasurableSet s) (hfg : ∀ᵐ x ∂μ, x ∈ s → f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ := lintegral_mono_ae <| (ae_restrict_iff' hs).2 hfg theorem set_lintegral_mono' {s : Set α} {f g : α → ℝ≥0∞} (hs : MeasurableSet s) (hfg : ∀ x ∈ s, f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ := set_lintegral_mono_ae' hs (ae_of_all _ hfg) theorem set_lintegral_le_lintegral (s : Set α) (f : α → ℝ≥0∞) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x, f x ∂μ := lintegral_mono' Measure.restrict_le_self le_rfl theorem lintegral_congr_ae {f g : α → ℝ≥0∞} (h : f =ᵐ[μ] g) : ∫⁻ a, f a ∂μ = ∫⁻ a, g a ∂μ := le_antisymm (lintegral_mono_ae <| h.le) (lintegral_mono_ae <| h.symm.le) #align measure_theory.lintegral_congr_ae MeasureTheory.lintegral_congr_ae theorem lintegral_congr {f g : α → ℝ≥0∞} (h : ∀ a, f a = g a) : ∫⁻ a, f a ∂μ = ∫⁻ a, g a ∂μ := by simp only [h] #align measure_theory.lintegral_congr MeasureTheory.lintegral_congr theorem set_lintegral_congr {f : α → ℝ≥0∞} {s t : Set α} (h : s =ᵐ[μ] t) : ∫⁻ x in s, f x ∂μ = ∫⁻ x in t, f x ∂μ := by rw [Measure.restrict_congr_set h] #align measure_theory.set_lintegral_congr MeasureTheory.set_lintegral_congr theorem set_lintegral_congr_fun {f g : α → ℝ≥0∞} {s : Set α} (hs : MeasurableSet s) (hfg : ∀ᵐ x ∂μ, x ∈ s → f x = g x) : ∫⁻ x in s, f x ∂μ = ∫⁻ x in s, g x ∂μ := by rw [lintegral_congr_ae] rw [EventuallyEq] rwa [ae_restrict_iff' hs] #align measure_theory.set_lintegral_congr_fun MeasureTheory.set_lintegral_congr_fun theorem lintegral_ofReal_le_lintegral_nnnorm (f : α → ℝ) : ∫⁻ x, ENNReal.ofReal (f x) ∂μ ≤ ∫⁻ x, ‖f x‖₊ ∂μ := by simp_rw [← ofReal_norm_eq_coe_nnnorm] refine lintegral_mono fun x => ENNReal.ofReal_le_ofReal ?_ rw [Real.norm_eq_abs] exact le_abs_self (f x) #align measure_theory.lintegral_of_real_le_lintegral_nnnorm MeasureTheory.lintegral_ofReal_le_lintegral_nnnorm theorem lintegral_nnnorm_eq_of_ae_nonneg {f : α → ℝ} (h_nonneg : 0 ≤ᵐ[μ] f) : ∫⁻ x, ‖f x‖₊ ∂μ = ∫⁻ x, ENNReal.ofReal (f x) ∂μ := by apply lintegral_congr_ae filter_upwards [h_nonneg] with x hx rw [Real.nnnorm_of_nonneg hx, ENNReal.ofReal_eq_coe_nnreal hx] #align measure_theory.lintegral_nnnorm_eq_of_ae_nonneg MeasureTheory.lintegral_nnnorm_eq_of_ae_nonneg theorem lintegral_nnnorm_eq_of_nonneg {f : α → ℝ} (h_nonneg : 0 ≤ f) : ∫⁻ x, ‖f x‖₊ ∂μ = ∫⁻ x, ENNReal.ofReal (f x) ∂μ := lintegral_nnnorm_eq_of_ae_nonneg (Filter.eventually_of_forall h_nonneg) #align measure_theory.lintegral_nnnorm_eq_of_nonneg MeasureTheory.lintegral_nnnorm_eq_of_nonneg /-- **Monotone convergence theorem** -- sometimes called **Beppo-Levi convergence**. See `lintegral_iSup_directed` for a more general form. -/ theorem lintegral_iSup {f : ℕ → α → ℝ≥0∞} (hf : ∀ n, Measurable (f n)) (h_mono : Monotone f) : ∫⁻ a, ⨆ n, f n a ∂μ = ⨆ n, ∫⁻ a, f n a ∂μ := by set c : ℝ≥0 → ℝ≥0∞ := (↑) set F := fun a : α => ⨆ n, f n a refine le_antisymm ?_ (iSup_lintegral_le _) rw [lintegral_eq_nnreal] refine iSup_le fun s => iSup_le fun hsf => ?_ refine ENNReal.le_of_forall_lt_one_mul_le fun a ha => ?_ rcases ENNReal.lt_iff_exists_coe.1 ha with ⟨r, rfl, _⟩ have ha : r < 1 := ENNReal.coe_lt_coe.1 ha let rs := s.map fun a => r * a have eq_rs : rs.map c = (const α r : α →ₛ ℝ≥0∞) * map c s := rfl have eq : ∀ p, rs.map c ⁻¹' {p} = ⋃ n, rs.map c ⁻¹' {p} ∩ { a | p ≤ f n a } := by intro p rw [← inter_iUnion]; nth_rw 1 [← inter_univ (map c rs ⁻¹' {p})] refine Set.ext fun x => and_congr_right fun hx => true_iff_iff.2 ?_ by_cases p_eq : p = 0 · simp [p_eq] simp only [coe_map, mem_preimage, Function.comp_apply, mem_singleton_iff] at hx subst hx have : r * s x ≠ 0 := by rwa [Ne, ← ENNReal.coe_eq_zero] have : s x ≠ 0 := right_ne_zero_of_mul this have : (rs.map c) x < ⨆ n : ℕ, f n x := by refine lt_of_lt_of_le (ENNReal.coe_lt_coe.2 ?_) (hsf x) suffices r * s x < 1 * s x by simpa exact mul_lt_mul_of_pos_right ha (pos_iff_ne_zero.2 this) rcases lt_iSup_iff.1 this with ⟨i, hi⟩ exact mem_iUnion.2 ⟨i, le_of_lt hi⟩ have mono : ∀ r : ℝ≥0∞, Monotone fun n => rs.map c ⁻¹' {r} ∩ { a | r ≤ f n a } := by intro r i j h refine inter_subset_inter_right _ ?_ simp_rw [subset_def, mem_setOf] intro x hx exact le_trans hx (h_mono h x) have h_meas : ∀ n, MeasurableSet {a : α | map c rs a ≤ f n a} := fun n => measurableSet_le (SimpleFunc.measurable _) (hf n) calc (r : ℝ≥0∞) * (s.map c).lintegral μ = ∑ r ∈ (rs.map c).range, r * μ (rs.map c ⁻¹' {r}) := by rw [← const_mul_lintegral, eq_rs, SimpleFunc.lintegral] _ = ∑ r ∈ (rs.map c).range, r * μ (⋃ n, rs.map c ⁻¹' {r} ∩ { a | r ≤ f n a }) := by simp only [(eq _).symm] _ = ∑ r ∈ (rs.map c).range, ⨆ n, r * μ (rs.map c ⁻¹' {r} ∩ { a | r ≤ f n a }) := (Finset.sum_congr rfl fun x _ => by rw [measure_iUnion_eq_iSup (mono x).directed_le, ENNReal.mul_iSup]) _ = ⨆ n, ∑ r ∈ (rs.map c).range, r * μ (rs.map c ⁻¹' {r} ∩ { a | r ≤ f n a }) := by refine ENNReal.finset_sum_iSup_nat fun p i j h ↦ ?_ gcongr _ * μ ?_ exact mono p h _ ≤ ⨆ n : ℕ, ((rs.map c).restrict { a | (rs.map c) a ≤ f n a }).lintegral μ := by gcongr with n rw [restrict_lintegral _ (h_meas n)] refine le_of_eq (Finset.sum_congr rfl fun r _ => ?_) congr 2 with a refine and_congr_right ?_ simp (config := { contextual := true }) _ ≤ ⨆ n, ∫⁻ a, f n a ∂μ := by simp only [← SimpleFunc.lintegral_eq_lintegral] gcongr with n a simp only [map_apply] at h_meas simp only [coe_map, restrict_apply _ (h_meas _), (· ∘ ·)] exact indicator_apply_le id #align measure_theory.lintegral_supr MeasureTheory.lintegral_iSup /-- Monotone convergence theorem -- sometimes called Beppo-Levi convergence. Version with ae_measurable functions. -/ theorem lintegral_iSup' {f : ℕ → α → ℝ≥0∞} (hf : ∀ n, AEMeasurable (f n) μ) (h_mono : ∀ᵐ x ∂μ, Monotone fun n => f n x) : ∫⁻ a, ⨆ n, f n a ∂μ = ⨆ n, ∫⁻ a, f n a ∂μ := by simp_rw [← iSup_apply] let p : α → (ℕ → ℝ≥0∞) → Prop := fun _ f' => Monotone f' have hp : ∀ᵐ x ∂μ, p x fun i => f i x := h_mono have h_ae_seq_mono : Monotone (aeSeq hf p) := by intro n m hnm x by_cases hx : x ∈ aeSeqSet hf p · exact aeSeq.prop_of_mem_aeSeqSet hf hx hnm · simp only [aeSeq, hx, if_false, le_rfl] rw [lintegral_congr_ae (aeSeq.iSup hf hp).symm] simp_rw [iSup_apply] rw [lintegral_iSup (aeSeq.measurable hf p) h_ae_seq_mono] congr with n exact lintegral_congr_ae (aeSeq.aeSeq_n_eq_fun_n_ae hf hp n) #align measure_theory.lintegral_supr' MeasureTheory.lintegral_iSup' /-- Monotone convergence theorem expressed with limits -/ theorem lintegral_tendsto_of_tendsto_of_monotone {f : ℕ → α → ℝ≥0∞} {F : α → ℝ≥0∞} (hf : ∀ n, AEMeasurable (f n) μ) (h_mono : ∀ᵐ x ∂μ, Monotone fun n => f n x) (h_tendsto : ∀ᵐ x ∂μ, Tendsto (fun n => f n x) atTop (𝓝 <| F x)) : Tendsto (fun n => ∫⁻ x, f n x ∂μ) atTop (𝓝 <| ∫⁻ x, F x ∂μ) := by have : Monotone fun n => ∫⁻ x, f n x ∂μ := fun i j hij => lintegral_mono_ae (h_mono.mono fun x hx => hx hij) suffices key : ∫⁻ x, F x ∂μ = ⨆ n, ∫⁻ x, f n x ∂μ by rw [key] exact tendsto_atTop_iSup this rw [← lintegral_iSup' hf h_mono] refine lintegral_congr_ae ?_ filter_upwards [h_mono, h_tendsto] with _ hx_mono hx_tendsto using tendsto_nhds_unique hx_tendsto (tendsto_atTop_iSup hx_mono) #align measure_theory.lintegral_tendsto_of_tendsto_of_monotone MeasureTheory.lintegral_tendsto_of_tendsto_of_monotone theorem lintegral_eq_iSup_eapprox_lintegral {f : α → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a, f a ∂μ = ⨆ n, (eapprox f n).lintegral μ := calc ∫⁻ a, f a ∂μ = ∫⁻ a, ⨆ n, (eapprox f n : α → ℝ≥0∞) a ∂μ := by congr; ext a; rw [iSup_eapprox_apply f hf] _ = ⨆ n, ∫⁻ a, (eapprox f n : α → ℝ≥0∞) a ∂μ := by apply lintegral_iSup · measurability · intro i j h exact monotone_eapprox f h _ = ⨆ n, (eapprox f n).lintegral μ := by congr; ext n; rw [(eapprox f n).lintegral_eq_lintegral] #align measure_theory.lintegral_eq_supr_eapprox_lintegral MeasureTheory.lintegral_eq_iSup_eapprox_lintegral /-- If `f` has finite integral, then `∫⁻ x in s, f x ∂μ` is absolutely continuous in `s`: it tends to zero as `μ s` tends to zero. This lemma states this fact in terms of `ε` and `δ`. -/ theorem exists_pos_set_lintegral_lt_of_measure_lt {f : α → ℝ≥0∞} (h : ∫⁻ x, f x ∂μ ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ δ > 0, ∀ s, μ s < δ → ∫⁻ x in s, f x ∂μ < ε := by rcases exists_between (pos_iff_ne_zero.mpr hε) with ⟨ε₂, hε₂0, hε₂ε⟩ rcases exists_between hε₂0 with ⟨ε₁, hε₁0, hε₁₂⟩ rcases exists_simpleFunc_forall_lintegral_sub_lt_of_pos h hε₁0.ne' with ⟨φ, _, hφ⟩ rcases φ.exists_forall_le with ⟨C, hC⟩ use (ε₂ - ε₁) / C, ENNReal.div_pos_iff.2 ⟨(tsub_pos_iff_lt.2 hε₁₂).ne', ENNReal.coe_ne_top⟩ refine fun s hs => lt_of_le_of_lt ?_ hε₂ε simp only [lintegral_eq_nnreal, iSup_le_iff] intro ψ hψ calc (map (↑) ψ).lintegral (μ.restrict s) ≤ (map (↑) φ).lintegral (μ.restrict s) + (map (↑) (ψ - φ)).lintegral (μ.restrict s) := by rw [← SimpleFunc.add_lintegral, ← SimpleFunc.map_add @ENNReal.coe_add] refine SimpleFunc.lintegral_mono (fun x => ?_) le_rfl simp only [add_tsub_eq_max, le_max_right, coe_map, Function.comp_apply, SimpleFunc.coe_add, SimpleFunc.coe_sub, Pi.add_apply, Pi.sub_apply, ENNReal.coe_max (φ x) (ψ x)] _ ≤ (map (↑) φ).lintegral (μ.restrict s) + ε₁ := by gcongr refine le_trans ?_ (hφ _ hψ).le exact SimpleFunc.lintegral_mono le_rfl Measure.restrict_le_self _ ≤ (SimpleFunc.const α (C : ℝ≥0∞)).lintegral (μ.restrict s) + ε₁ := by gcongr exact SimpleFunc.lintegral_mono (fun x ↦ ENNReal.coe_le_coe.2 (hC x)) le_rfl _ = C * μ s + ε₁ := by simp only [← SimpleFunc.lintegral_eq_lintegral, coe_const, lintegral_const, Measure.restrict_apply, MeasurableSet.univ, univ_inter, Function.const] _ ≤ C * ((ε₂ - ε₁) / C) + ε₁ := by gcongr _ ≤ ε₂ - ε₁ + ε₁ := by gcongr; apply mul_div_le _ = ε₂ := tsub_add_cancel_of_le hε₁₂.le #align measure_theory.exists_pos_set_lintegral_lt_of_measure_lt MeasureTheory.exists_pos_set_lintegral_lt_of_measure_lt /-- If `f` has finite integral, then `∫⁻ x in s, f x ∂μ` is absolutely continuous in `s`: it tends to zero as `μ s` tends to zero. -/ theorem tendsto_set_lintegral_zero {ι} {f : α → ℝ≥0∞} (h : ∫⁻ x, f x ∂μ ≠ ∞) {l : Filter ι} {s : ι → Set α} (hl : Tendsto (μ ∘ s) l (𝓝 0)) : Tendsto (fun i => ∫⁻ x in s i, f x ∂μ) l (𝓝 0) := by simp only [ENNReal.nhds_zero, tendsto_iInf, tendsto_principal, mem_Iio, ← pos_iff_ne_zero] at hl ⊢ intro ε ε0 rcases exists_pos_set_lintegral_lt_of_measure_lt h ε0.ne' with ⟨δ, δ0, hδ⟩ exact (hl δ δ0).mono fun i => hδ _ #align measure_theory.tendsto_set_lintegral_zero MeasureTheory.tendsto_set_lintegral_zero /-- The sum of the lower Lebesgue integrals of two functions is less than or equal to the integral of their sum. The other inequality needs one of these functions to be (a.e.-)measurable. -/ theorem le_lintegral_add (f g : α → ℝ≥0∞) : ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ ≤ ∫⁻ a, f a + g a ∂μ := by simp only [lintegral] refine ENNReal.biSup_add_biSup_le' (p := fun h : α →ₛ ℝ≥0∞ => h ≤ f) (q := fun h : α →ₛ ℝ≥0∞ => h ≤ g) ⟨0, zero_le f⟩ ⟨0, zero_le g⟩ fun f' hf' g' hg' => ?_ exact le_iSup₂_of_le (f' + g') (add_le_add hf' hg') (add_lintegral _ _).ge #align measure_theory.le_lintegral_add MeasureTheory.le_lintegral_add -- Use stronger lemmas `lintegral_add_left`/`lintegral_add_right` instead theorem lintegral_add_aux {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) : ∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := calc ∫⁻ a, f a + g a ∂μ = ∫⁻ a, (⨆ n, (eapprox f n : α → ℝ≥0∞) a) + ⨆ n, (eapprox g n : α → ℝ≥0∞) a ∂μ := by simp only [iSup_eapprox_apply, hf, hg] _ = ∫⁻ a, ⨆ n, (eapprox f n + eapprox g n : α → ℝ≥0∞) a ∂μ := by congr; funext a rw [ENNReal.iSup_add_iSup_of_monotone] · simp only [Pi.add_apply] · intro i j h exact monotone_eapprox _ h a · intro i j h exact monotone_eapprox _ h a _ = ⨆ n, (eapprox f n).lintegral μ + (eapprox g n).lintegral μ := by rw [lintegral_iSup] · congr funext n rw [← SimpleFunc.add_lintegral, ← SimpleFunc.lintegral_eq_lintegral] simp only [Pi.add_apply, SimpleFunc.coe_add] · measurability · intro i j h a dsimp gcongr <;> exact monotone_eapprox _ h _ _ = (⨆ n, (eapprox f n).lintegral μ) + ⨆ n, (eapprox g n).lintegral μ := by refine (ENNReal.iSup_add_iSup_of_monotone ?_ ?_).symm <;> · intro i j h exact SimpleFunc.lintegral_mono (monotone_eapprox _ h) le_rfl _ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := by rw [lintegral_eq_iSup_eapprox_lintegral hf, lintegral_eq_iSup_eapprox_lintegral hg] #align measure_theory.lintegral_add_aux MeasureTheory.lintegral_add_aux /-- If `f g : α → ℝ≥0∞` are two functions and one of them is (a.e.) measurable, then the Lebesgue integral of `f + g` equals the sum of integrals. This lemma assumes that `f` is integrable, see also `MeasureTheory.lintegral_add_right` and primed versions of these lemmas. -/ @[simp] theorem lintegral_add_left {f : α → ℝ≥0∞} (hf : Measurable f) (g : α → ℝ≥0∞) : ∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := by refine le_antisymm ?_ (le_lintegral_add _ _) rcases exists_measurable_le_lintegral_eq μ fun a => f a + g a with ⟨φ, hφm, hφ_le, hφ_eq⟩ calc ∫⁻ a, f a + g a ∂μ = ∫⁻ a, φ a ∂μ := hφ_eq _ ≤ ∫⁻ a, f a + (φ a - f a) ∂μ := lintegral_mono fun a => le_add_tsub _ = ∫⁻ a, f a ∂μ + ∫⁻ a, φ a - f a ∂μ := lintegral_add_aux hf (hφm.sub hf) _ ≤ ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := add_le_add_left (lintegral_mono fun a => tsub_le_iff_left.2 <| hφ_le a) _ #align measure_theory.lintegral_add_left MeasureTheory.lintegral_add_left theorem lintegral_add_left' {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) (g : α → ℝ≥0∞) : ∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := by rw [lintegral_congr_ae hf.ae_eq_mk, ← lintegral_add_left hf.measurable_mk, lintegral_congr_ae (hf.ae_eq_mk.add (ae_eq_refl g))] #align measure_theory.lintegral_add_left' MeasureTheory.lintegral_add_left' theorem lintegral_add_right' (f : α → ℝ≥0∞) {g : α → ℝ≥0∞} (hg : AEMeasurable g μ) : ∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := by simpa only [add_comm] using lintegral_add_left' hg f #align measure_theory.lintegral_add_right' MeasureTheory.lintegral_add_right' /-- If `f g : α → ℝ≥0∞` are two functions and one of them is (a.e.) measurable, then the Lebesgue integral of `f + g` equals the sum of integrals. This lemma assumes that `g` is integrable, see also `MeasureTheory.lintegral_add_left` and primed versions of these lemmas. -/ @[simp] theorem lintegral_add_right (f : α → ℝ≥0∞) {g : α → ℝ≥0∞} (hg : Measurable g) : ∫⁻ a, f a + g a ∂μ = ∫⁻ a, f a ∂μ + ∫⁻ a, g a ∂μ := lintegral_add_right' f hg.aemeasurable #align measure_theory.lintegral_add_right MeasureTheory.lintegral_add_right @[simp] theorem lintegral_smul_measure (c : ℝ≥0∞) (f : α → ℝ≥0∞) : ∫⁻ a, f a ∂c • μ = c * ∫⁻ a, f a ∂μ := by simp only [lintegral, iSup_subtype', SimpleFunc.lintegral_smul, ENNReal.mul_iSup, smul_eq_mul] #align measure_theory.lintegral_smul_measure MeasureTheory.lintegral_smul_measure lemma set_lintegral_smul_measure (c : ℝ≥0∞) (f : α → ℝ≥0∞) (s : Set α) : ∫⁻ a in s, f a ∂(c • μ) = c * ∫⁻ a in s, f a ∂μ := by rw [Measure.restrict_smul, lintegral_smul_measure] @[simp] theorem lintegral_sum_measure {m : MeasurableSpace α} {ι} (f : α → ℝ≥0∞) (μ : ι → Measure α) : ∫⁻ a, f a ∂Measure.sum μ = ∑' i, ∫⁻ a, f a ∂μ i := by simp only [lintegral, iSup_subtype', SimpleFunc.lintegral_sum, ENNReal.tsum_eq_iSup_sum] rw [iSup_comm] congr; funext s induction' s using Finset.induction_on with i s hi hs · simp simp only [Finset.sum_insert hi, ← hs] refine (ENNReal.iSup_add_iSup ?_).symm intro φ ψ exact ⟨⟨φ ⊔ ψ, fun x => sup_le (φ.2 x) (ψ.2 x)⟩, add_le_add (SimpleFunc.lintegral_mono le_sup_left le_rfl) (Finset.sum_le_sum fun j _ => SimpleFunc.lintegral_mono le_sup_right le_rfl)⟩ #align measure_theory.lintegral_sum_measure MeasureTheory.lintegral_sum_measure theorem hasSum_lintegral_measure {ι} {_ : MeasurableSpace α} (f : α → ℝ≥0∞) (μ : ι → Measure α) : HasSum (fun i => ∫⁻ a, f a ∂μ i) (∫⁻ a, f a ∂Measure.sum μ) := (lintegral_sum_measure f μ).symm ▸ ENNReal.summable.hasSum #align measure_theory.has_sum_lintegral_measure MeasureTheory.hasSum_lintegral_measure @[simp] theorem lintegral_add_measure {m : MeasurableSpace α} (f : α → ℝ≥0∞) (μ ν : Measure α) : ∫⁻ a, f a ∂(μ + ν) = ∫⁻ a, f a ∂μ + ∫⁻ a, f a ∂ν := by simpa [tsum_fintype] using lintegral_sum_measure f fun b => cond b μ ν #align measure_theory.lintegral_add_measure MeasureTheory.lintegral_add_measure @[simp] theorem lintegral_finset_sum_measure {ι} {m : MeasurableSpace α} (s : Finset ι) (f : α → ℝ≥0∞) (μ : ι → Measure α) : ∫⁻ a, f a ∂(∑ i ∈ s, μ i) = ∑ i ∈ s, ∫⁻ a, f a ∂μ i := by rw [← Measure.sum_coe_finset, lintegral_sum_measure, ← Finset.tsum_subtype'] simp only [Finset.coe_sort_coe] #align measure_theory.lintegral_finset_sum_measure MeasureTheory.lintegral_finset_sum_measure @[simp] theorem lintegral_zero_measure {m : MeasurableSpace α} (f : α → ℝ≥0∞) : ∫⁻ a, f a ∂(0 : Measure α) = 0 := by simp [lintegral] #align measure_theory.lintegral_zero_measure MeasureTheory.lintegral_zero_measure @[simp] theorem lintegral_of_isEmpty {α} [MeasurableSpace α] [IsEmpty α] (μ : Measure α) (f : α → ℝ≥0∞) : ∫⁻ x, f x ∂μ = 0 := by have : Subsingleton (Measure α) := inferInstance convert lintegral_zero_measure f theorem set_lintegral_empty (f : α → ℝ≥0∞) : ∫⁻ x in ∅, f x ∂μ = 0 := by rw [Measure.restrict_empty, lintegral_zero_measure] #align measure_theory.set_lintegral_empty MeasureTheory.set_lintegral_empty theorem set_lintegral_univ (f : α → ℝ≥0∞) : ∫⁻ x in univ, f x ∂μ = ∫⁻ x, f x ∂μ := by rw [Measure.restrict_univ] #align measure_theory.set_lintegral_univ MeasureTheory.set_lintegral_univ theorem set_lintegral_measure_zero (s : Set α) (f : α → ℝ≥0∞) (hs' : μ s = 0) : ∫⁻ x in s, f x ∂μ = 0 := by convert lintegral_zero_measure _ exact Measure.restrict_eq_zero.2 hs' #align measure_theory.set_lintegral_measure_zero MeasureTheory.set_lintegral_measure_zero theorem lintegral_finset_sum' (s : Finset β) {f : β → α → ℝ≥0∞} (hf : ∀ b ∈ s, AEMeasurable (f b) μ) : ∫⁻ a, ∑ b ∈ s, f b a ∂μ = ∑ b ∈ s, ∫⁻ a, f b a ∂μ := by induction' s using Finset.induction_on with a s has ih · simp · simp only [Finset.sum_insert has] rw [Finset.forall_mem_insert] at hf rw [lintegral_add_left' hf.1, ih hf.2] #align measure_theory.lintegral_finset_sum' MeasureTheory.lintegral_finset_sum' theorem lintegral_finset_sum (s : Finset β) {f : β → α → ℝ≥0∞} (hf : ∀ b ∈ s, Measurable (f b)) : ∫⁻ a, ∑ b ∈ s, f b a ∂μ = ∑ b ∈ s, ∫⁻ a, f b a ∂μ := lintegral_finset_sum' s fun b hb => (hf b hb).aemeasurable #align measure_theory.lintegral_finset_sum MeasureTheory.lintegral_finset_sum @[simp] theorem lintegral_const_mul (r : ℝ≥0∞) {f : α → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a, r * f a ∂μ = r * ∫⁻ a, f a ∂μ := calc ∫⁻ a, r * f a ∂μ = ∫⁻ a, ⨆ n, (const α r * eapprox f n) a ∂μ := by congr funext a rw [← iSup_eapprox_apply f hf, ENNReal.mul_iSup] simp _ = ⨆ n, r * (eapprox f n).lintegral μ := by rw [lintegral_iSup] · congr funext n rw [← SimpleFunc.const_mul_lintegral, ← SimpleFunc.lintegral_eq_lintegral] · intro n exact SimpleFunc.measurable _ · intro i j h a exact mul_le_mul_left' (monotone_eapprox _ h _) _ _ = r * ∫⁻ a, f a ∂μ := by rw [← ENNReal.mul_iSup, lintegral_eq_iSup_eapprox_lintegral hf] #align measure_theory.lintegral_const_mul MeasureTheory.lintegral_const_mul theorem lintegral_const_mul'' (r : ℝ≥0∞) {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) : ∫⁻ a, r * f a ∂μ = r * ∫⁻ a, f a ∂μ := by have A : ∫⁻ a, f a ∂μ = ∫⁻ a, hf.mk f a ∂μ := lintegral_congr_ae hf.ae_eq_mk have B : ∫⁻ a, r * f a ∂μ = ∫⁻ a, r * hf.mk f a ∂μ := lintegral_congr_ae (EventuallyEq.fun_comp hf.ae_eq_mk _) rw [A, B, lintegral_const_mul _ hf.measurable_mk] #align measure_theory.lintegral_const_mul'' MeasureTheory.lintegral_const_mul'' theorem lintegral_const_mul_le (r : ℝ≥0∞) (f : α → ℝ≥0∞) : r * ∫⁻ a, f a ∂μ ≤ ∫⁻ a, r * f a ∂μ := by rw [lintegral, ENNReal.mul_iSup] refine iSup_le fun s => ?_ rw [ENNReal.mul_iSup, iSup_le_iff] intro hs rw [← SimpleFunc.const_mul_lintegral, lintegral] refine le_iSup_of_le (const α r * s) (le_iSup_of_le (fun x => ?_) le_rfl) exact mul_le_mul_left' (hs x) _ #align measure_theory.lintegral_const_mul_le MeasureTheory.lintegral_const_mul_le theorem lintegral_const_mul' (r : ℝ≥0∞) (f : α → ℝ≥0∞) (hr : r ≠ ∞) : ∫⁻ a, r * f a ∂μ = r * ∫⁻ a, f a ∂μ := by by_cases h : r = 0 · simp [h] apply le_antisymm _ (lintegral_const_mul_le r f) have rinv : r * r⁻¹ = 1 := ENNReal.mul_inv_cancel h hr have rinv' : r⁻¹ * r = 1 := by rw [mul_comm] exact rinv have := lintegral_const_mul_le (μ := μ) r⁻¹ fun x => r * f x simp? [(mul_assoc _ _ _).symm, rinv'] at this says simp only [(mul_assoc _ _ _).symm, rinv', one_mul] at this simpa [(mul_assoc _ _ _).symm, rinv] using mul_le_mul_left' this r #align measure_theory.lintegral_const_mul' MeasureTheory.lintegral_const_mul' theorem lintegral_mul_const (r : ℝ≥0∞) {f : α → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a, f a * r ∂μ = (∫⁻ a, f a ∂μ) * r := by simp_rw [mul_comm, lintegral_const_mul r hf] #align measure_theory.lintegral_mul_const MeasureTheory.lintegral_mul_const theorem lintegral_mul_const'' (r : ℝ≥0∞) {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) : ∫⁻ a, f a * r ∂μ = (∫⁻ a, f a ∂μ) * r := by simp_rw [mul_comm, lintegral_const_mul'' r hf] #align measure_theory.lintegral_mul_const'' MeasureTheory.lintegral_mul_const'' theorem lintegral_mul_const_le (r : ℝ≥0∞) (f : α → ℝ≥0∞) : (∫⁻ a, f a ∂μ) * r ≤ ∫⁻ a, f a * r ∂μ := by simp_rw [mul_comm, lintegral_const_mul_le r f] #align measure_theory.lintegral_mul_const_le MeasureTheory.lintegral_mul_const_le theorem lintegral_mul_const' (r : ℝ≥0∞) (f : α → ℝ≥0∞) (hr : r ≠ ∞) : ∫⁻ a, f a * r ∂μ = (∫⁻ a, f a ∂μ) * r := by simp_rw [mul_comm, lintegral_const_mul' r f hr] #align measure_theory.lintegral_mul_const' MeasureTheory.lintegral_mul_const' /- A double integral of a product where each factor contains only one variable is a product of integrals -/ theorem lintegral_lintegral_mul {β} [MeasurableSpace β] {ν : Measure β} {f : α → ℝ≥0∞} {g : β → ℝ≥0∞} (hf : AEMeasurable f μ) (hg : AEMeasurable g ν) : ∫⁻ x, ∫⁻ y, f x * g y ∂ν ∂μ = (∫⁻ x, f x ∂μ) * ∫⁻ y, g y ∂ν := by simp [lintegral_const_mul'' _ hg, lintegral_mul_const'' _ hf] #align measure_theory.lintegral_lintegral_mul MeasureTheory.lintegral_lintegral_mul -- TODO: Need a better way of rewriting inside of an integral theorem lintegral_rw₁ {f f' : α → β} (h : f =ᵐ[μ] f') (g : β → ℝ≥0∞) : ∫⁻ a, g (f a) ∂μ = ∫⁻ a, g (f' a) ∂μ := lintegral_congr_ae <| h.mono fun a h => by dsimp only; rw [h] #align measure_theory.lintegral_rw₁ MeasureTheory.lintegral_rw₁ -- TODO: Need a better way of rewriting inside of an integral theorem lintegral_rw₂ {f₁ f₁' : α → β} {f₂ f₂' : α → γ} (h₁ : f₁ =ᵐ[μ] f₁') (h₂ : f₂ =ᵐ[μ] f₂') (g : β → γ → ℝ≥0∞) : ∫⁻ a, g (f₁ a) (f₂ a) ∂μ = ∫⁻ a, g (f₁' a) (f₂' a) ∂μ := lintegral_congr_ae <| h₁.mp <| h₂.mono fun _ h₂ h₁ => by dsimp only; rw [h₁, h₂] #align measure_theory.lintegral_rw₂ MeasureTheory.lintegral_rw₂ theorem lintegral_indicator_le (f : α → ℝ≥0∞) (s : Set α) : ∫⁻ a, s.indicator f a ∂μ ≤ ∫⁻ a in s, f a ∂μ := by simp only [lintegral] apply iSup_le (fun g ↦ (iSup_le (fun hg ↦ ?_))) have : g ≤ f := hg.trans (indicator_le_self s f) refine le_iSup_of_le g (le_iSup_of_le this (le_of_eq ?_)) rw [lintegral_restrict, SimpleFunc.lintegral] congr with t by_cases H : t = 0 · simp [H] congr with x simp only [mem_preimage, mem_singleton_iff, mem_inter_iff, iff_self_and] rintro rfl contrapose! H simpa [H] using hg x @[simp] theorem lintegral_indicator (f : α → ℝ≥0∞) {s : Set α} (hs : MeasurableSet s) : ∫⁻ a, s.indicator f a ∂μ = ∫⁻ a in s, f a ∂μ := by apply le_antisymm (lintegral_indicator_le f s) simp only [lintegral, ← restrict_lintegral_eq_lintegral_restrict _ hs, iSup_subtype'] refine iSup_mono' (Subtype.forall.2 fun φ hφ => ?_) refine ⟨⟨φ.restrict s, fun x => ?_⟩, le_rfl⟩ simp [hφ x, hs, indicator_le_indicator] #align measure_theory.lintegral_indicator MeasureTheory.lintegral_indicator theorem lintegral_indicator₀ (f : α → ℝ≥0∞) {s : Set α} (hs : NullMeasurableSet s μ) : ∫⁻ a, s.indicator f a ∂μ = ∫⁻ a in s, f a ∂μ := by rw [← lintegral_congr_ae (indicator_ae_eq_of_ae_eq_set hs.toMeasurable_ae_eq), lintegral_indicator _ (measurableSet_toMeasurable _ _), Measure.restrict_congr_set hs.toMeasurable_ae_eq] #align measure_theory.lintegral_indicator₀ MeasureTheory.lintegral_indicator₀ theorem lintegral_indicator_const_le (s : Set α) (c : ℝ≥0∞) : ∫⁻ a, s.indicator (fun _ => c) a ∂μ ≤ c * μ s := (lintegral_indicator_le _ _).trans (set_lintegral_const s c).le theorem lintegral_indicator_const₀ {s : Set α} (hs : NullMeasurableSet s μ) (c : ℝ≥0∞) : ∫⁻ a, s.indicator (fun _ => c) a ∂μ = c * μ s := by rw [lintegral_indicator₀ _ hs, set_lintegral_const] theorem lintegral_indicator_const {s : Set α} (hs : MeasurableSet s) (c : ℝ≥0∞) : ∫⁻ a, s.indicator (fun _ => c) a ∂μ = c * μ s := lintegral_indicator_const₀ hs.nullMeasurableSet c #align measure_theory.lintegral_indicator_const MeasureTheory.lintegral_indicator_const theorem set_lintegral_eq_const {f : α → ℝ≥0∞} (hf : Measurable f) (r : ℝ≥0∞) : ∫⁻ x in { x | f x = r }, f x ∂μ = r * μ { x | f x = r } := by have : ∀ᵐ x ∂μ, x ∈ { x | f x = r } → f x = r := ae_of_all μ fun _ hx => hx rw [set_lintegral_congr_fun _ this] · rw [lintegral_const, Measure.restrict_apply MeasurableSet.univ, Set.univ_inter] · exact hf (measurableSet_singleton r) #align measure_theory.set_lintegral_eq_const MeasureTheory.set_lintegral_eq_const theorem lintegral_indicator_one_le (s : Set α) : ∫⁻ a, s.indicator 1 a ∂μ ≤ μ s := (lintegral_indicator_const_le _ _).trans <| (one_mul _).le @[simp] theorem lintegral_indicator_one₀ (hs : NullMeasurableSet s μ) : ∫⁻ a, s.indicator 1 a ∂μ = μ s := (lintegral_indicator_const₀ hs _).trans <| one_mul _ @[simp] theorem lintegral_indicator_one (hs : MeasurableSet s) : ∫⁻ a, s.indicator 1 a ∂μ = μ s := (lintegral_indicator_const hs _).trans <| one_mul _ #align measure_theory.lintegral_indicator_one MeasureTheory.lintegral_indicator_one /-- A version of **Markov's inequality** for two functions. It doesn't follow from the standard Markov's inequality because we only assume measurability of `g`, not `f`. -/ theorem lintegral_add_mul_meas_add_le_le_lintegral {f g : α → ℝ≥0∞} (hle : f ≤ᵐ[μ] g) (hg : AEMeasurable g μ) (ε : ℝ≥0∞) : ∫⁻ a, f a ∂μ + ε * μ { x | f x + ε ≤ g x } ≤ ∫⁻ a, g a ∂μ := by rcases exists_measurable_le_lintegral_eq μ f with ⟨φ, hφm, hφ_le, hφ_eq⟩ calc ∫⁻ x, f x ∂μ + ε * μ { x | f x + ε ≤ g x } = ∫⁻ x, φ x ∂μ + ε * μ { x | f x + ε ≤ g x } := by rw [hφ_eq] _ ≤ ∫⁻ x, φ x ∂μ + ε * μ { x | φ x + ε ≤ g x } := by gcongr exact fun x => (add_le_add_right (hφ_le _) _).trans _ = ∫⁻ x, φ x + indicator { x | φ x + ε ≤ g x } (fun _ => ε) x ∂μ := by rw [lintegral_add_left hφm, lintegral_indicator₀, set_lintegral_const] exact measurableSet_le (hφm.nullMeasurable.measurable'.add_const _) hg.nullMeasurable _ ≤ ∫⁻ x, g x ∂μ := lintegral_mono_ae (hle.mono fun x hx₁ => ?_) simp only [indicator_apply]; split_ifs with hx₂ exacts [hx₂, (add_zero _).trans_le <| (hφ_le x).trans hx₁] #align measure_theory.lintegral_add_mul_meas_add_le_le_lintegral MeasureTheory.lintegral_add_mul_meas_add_le_le_lintegral /-- **Markov's inequality** also known as **Chebyshev's first inequality**. -/ theorem mul_meas_ge_le_lintegral₀ {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) (ε : ℝ≥0∞) : ε * μ { x | ε ≤ f x } ≤ ∫⁻ a, f a ∂μ := by simpa only [lintegral_zero, zero_add] using lintegral_add_mul_meas_add_le_le_lintegral (ae_of_all _ fun x => zero_le (f x)) hf ε #align measure_theory.mul_meas_ge_le_lintegral₀ MeasureTheory.mul_meas_ge_le_lintegral₀ /-- **Markov's inequality** also known as **Chebyshev's first inequality**. For a version assuming `AEMeasurable`, see `mul_meas_ge_le_lintegral₀`. -/ theorem mul_meas_ge_le_lintegral {f : α → ℝ≥0∞} (hf : Measurable f) (ε : ℝ≥0∞) : ε * μ { x | ε ≤ f x } ≤ ∫⁻ a, f a ∂μ := mul_meas_ge_le_lintegral₀ hf.aemeasurable ε #align measure_theory.mul_meas_ge_le_lintegral MeasureTheory.mul_meas_ge_le_lintegral lemma meas_le_lintegral₀ {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) {s : Set α} (hs : ∀ x ∈ s, 1 ≤ f x) : μ s ≤ ∫⁻ a, f a ∂μ := by apply le_trans _ (mul_meas_ge_le_lintegral₀ hf 1) rw [one_mul] exact measure_mono hs lemma lintegral_le_meas {s : Set α} {f : α → ℝ≥0∞} (hf : ∀ a, f a ≤ 1) (h'f : ∀ a ∈ sᶜ, f a = 0) : ∫⁻ a, f a ∂μ ≤ μ s := by apply (lintegral_mono (fun x ↦ ?_)).trans (lintegral_indicator_one_le s) by_cases hx : x ∈ s · simpa [hx] using hf x · simpa [hx] using h'f x hx theorem lintegral_eq_top_of_measure_eq_top_ne_zero {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hμf : μ {x | f x = ∞} ≠ 0) : ∫⁻ x, f x ∂μ = ∞ := eq_top_iff.mpr <| calc ∞ = ∞ * μ { x | ∞ ≤ f x } := by simp [mul_eq_top, hμf] _ ≤ ∫⁻ x, f x ∂μ := mul_meas_ge_le_lintegral₀ hf ∞ #align measure_theory.lintegral_eq_top_of_measure_eq_top_ne_zero MeasureTheory.lintegral_eq_top_of_measure_eq_top_ne_zero theorem setLintegral_eq_top_of_measure_eq_top_ne_zero (hf : AEMeasurable f (μ.restrict s)) (hμf : μ ({x ∈ s | f x = ∞}) ≠ 0) : ∫⁻ x in s, f x ∂μ = ∞ := lintegral_eq_top_of_measure_eq_top_ne_zero hf <| mt (eq_bot_mono <| by rw [← setOf_inter_eq_sep]; exact Measure.le_restrict_apply _ _) hμf #align measure_theory.set_lintegral_eq_top_of_measure_eq_top_ne_zero MeasureTheory.setLintegral_eq_top_of_measure_eq_top_ne_zero theorem measure_eq_top_of_lintegral_ne_top (hf : AEMeasurable f μ) (hμf : ∫⁻ x, f x ∂μ ≠ ∞) : μ {x | f x = ∞} = 0 := of_not_not fun h => hμf <| lintegral_eq_top_of_measure_eq_top_ne_zero hf h #align measure_theory.measure_eq_top_of_lintegral_ne_top MeasureTheory.measure_eq_top_of_lintegral_ne_top theorem measure_eq_top_of_setLintegral_ne_top (hf : AEMeasurable f (μ.restrict s)) (hμf : ∫⁻ x in s, f x ∂μ ≠ ∞) : μ ({x ∈ s | f x = ∞}) = 0 := of_not_not fun h => hμf <| setLintegral_eq_top_of_measure_eq_top_ne_zero hf h #align measure_theory.measure_eq_top_of_set_lintegral_ne_top MeasureTheory.measure_eq_top_of_setLintegral_ne_top /-- **Markov's inequality** also known as **Chebyshev's first inequality**. -/ theorem meas_ge_le_lintegral_div {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) {ε : ℝ≥0∞} (hε : ε ≠ 0) (hε' : ε ≠ ∞) : μ { x | ε ≤ f x } ≤ (∫⁻ a, f a ∂μ) / ε := (ENNReal.le_div_iff_mul_le (Or.inl hε) (Or.inl hε')).2 <| by rw [mul_comm] exact mul_meas_ge_le_lintegral₀ hf ε #align measure_theory.meas_ge_le_lintegral_div MeasureTheory.meas_ge_le_lintegral_div theorem ae_eq_of_ae_le_of_lintegral_le {f g : α → ℝ≥0∞} (hfg : f ≤ᵐ[μ] g) (hf : ∫⁻ x, f x ∂μ ≠ ∞) (hg : AEMeasurable g μ) (hgf : ∫⁻ x, g x ∂μ ≤ ∫⁻ x, f x ∂μ) : f =ᵐ[μ] g := by have : ∀ n : ℕ, ∀ᵐ x ∂μ, g x < f x + (n : ℝ≥0∞)⁻¹ := by intro n simp only [ae_iff, not_lt] have : ∫⁻ x, f x ∂μ + (↑n)⁻¹ * μ { x : α | f x + (n : ℝ≥0∞)⁻¹ ≤ g x } ≤ ∫⁻ x, f x ∂μ := (lintegral_add_mul_meas_add_le_le_lintegral hfg hg n⁻¹).trans hgf rw [(ENNReal.cancel_of_ne hf).add_le_iff_nonpos_right, nonpos_iff_eq_zero, mul_eq_zero] at this exact this.resolve_left (ENNReal.inv_ne_zero.2 (ENNReal.natCast_ne_top _)) refine hfg.mp ((ae_all_iff.2 this).mono fun x hlt hle => hle.antisymm ?_) suffices Tendsto (fun n : ℕ => f x + (n : ℝ≥0∞)⁻¹) atTop (𝓝 (f x)) from ge_of_tendsto' this fun i => (hlt i).le simpa only [inv_top, add_zero] using tendsto_const_nhds.add (ENNReal.tendsto_inv_iff.2 ENNReal.tendsto_nat_nhds_top) #align measure_theory.ae_eq_of_ae_le_of_lintegral_le MeasureTheory.ae_eq_of_ae_le_of_lintegral_le @[simp] theorem lintegral_eq_zero_iff' {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) : ∫⁻ a, f a ∂μ = 0 ↔ f =ᵐ[μ] 0 := have : ∫⁻ _ : α, 0 ∂μ ≠ ∞ := by simp [lintegral_zero, zero_ne_top] ⟨fun h => (ae_eq_of_ae_le_of_lintegral_le (ae_of_all _ <| zero_le f) this hf (h.trans lintegral_zero.symm).le).symm, fun h => (lintegral_congr_ae h).trans lintegral_zero⟩ #align measure_theory.lintegral_eq_zero_iff' MeasureTheory.lintegral_eq_zero_iff' @[simp] theorem lintegral_eq_zero_iff {f : α → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a, f a ∂μ = 0 ↔ f =ᵐ[μ] 0 := lintegral_eq_zero_iff' hf.aemeasurable #align measure_theory.lintegral_eq_zero_iff MeasureTheory.lintegral_eq_zero_iff theorem lintegral_pos_iff_support {f : α → ℝ≥0∞} (hf : Measurable f) : (0 < ∫⁻ a, f a ∂μ) ↔ 0 < μ (Function.support f) := by simp [pos_iff_ne_zero, hf, Filter.EventuallyEq, ae_iff, Function.support] #align measure_theory.lintegral_pos_iff_support MeasureTheory.lintegral_pos_iff_support theorem setLintegral_pos_iff {f : α → ℝ≥0∞} (hf : Measurable f) {s : Set α} : 0 < ∫⁻ a in s, f a ∂μ ↔ 0 < μ (Function.support f ∩ s) := by rw [lintegral_pos_iff_support hf, Measure.restrict_apply (measurableSet_support hf)] /-- Weaker version of the monotone convergence theorem-/ theorem lintegral_iSup_ae {f : ℕ → α → ℝ≥0∞} (hf : ∀ n, Measurable (f n)) (h_mono : ∀ n, ∀ᵐ a ∂μ, f n a ≤ f n.succ a) : ∫⁻ a, ⨆ n, f n a ∂μ = ⨆ n, ∫⁻ a, f n a ∂μ := by let ⟨s, hs⟩ := exists_measurable_superset_of_null (ae_iff.1 (ae_all_iff.2 h_mono)) let g n a := if a ∈ s then 0 else f n a have g_eq_f : ∀ᵐ a ∂μ, ∀ n, g n a = f n a := (measure_zero_iff_ae_nmem.1 hs.2.2).mono fun a ha n => if_neg ha calc ∫⁻ a, ⨆ n, f n a ∂μ = ∫⁻ a, ⨆ n, g n a ∂μ := lintegral_congr_ae <| g_eq_f.mono fun a ha => by simp only [ha] _ = ⨆ n, ∫⁻ a, g n a ∂μ := (lintegral_iSup (fun n => measurable_const.piecewise hs.2.1 (hf n)) (monotone_nat_of_le_succ fun n a => ?_)) _ = ⨆ n, ∫⁻ a, f n a ∂μ := by simp only [lintegral_congr_ae (g_eq_f.mono fun _a ha => ha _)] simp only [g] split_ifs with h · rfl · have := Set.not_mem_subset hs.1 h simp only [not_forall, not_le, mem_setOf_eq, not_exists, not_lt] at this exact this n #align measure_theory.lintegral_supr_ae MeasureTheory.lintegral_iSup_ae theorem lintegral_sub' {f g : α → ℝ≥0∞} (hg : AEMeasurable g μ) (hg_fin : ∫⁻ a, g a ∂μ ≠ ∞) (h_le : g ≤ᵐ[μ] f) : ∫⁻ a, f a - g a ∂μ = ∫⁻ a, f a ∂μ - ∫⁻ a, g a ∂μ := by refine ENNReal.eq_sub_of_add_eq hg_fin ?_ rw [← lintegral_add_right' _ hg] exact lintegral_congr_ae (h_le.mono fun x hx => tsub_add_cancel_of_le hx) #align measure_theory.lintegral_sub' MeasureTheory.lintegral_sub' theorem lintegral_sub {f g : α → ℝ≥0∞} (hg : Measurable g) (hg_fin : ∫⁻ a, g a ∂μ ≠ ∞) (h_le : g ≤ᵐ[μ] f) : ∫⁻ a, f a - g a ∂μ = ∫⁻ a, f a ∂μ - ∫⁻ a, g a ∂μ := lintegral_sub' hg.aemeasurable hg_fin h_le #align measure_theory.lintegral_sub MeasureTheory.lintegral_sub theorem lintegral_sub_le' (f g : α → ℝ≥0∞) (hf : AEMeasurable f μ) : ∫⁻ x, g x ∂μ - ∫⁻ x, f x ∂μ ≤ ∫⁻ x, g x - f x ∂μ := by rw [tsub_le_iff_right] by_cases hfi : ∫⁻ x, f x ∂μ = ∞ · rw [hfi, add_top] exact le_top · rw [← lintegral_add_right' _ hf] gcongr exact le_tsub_add #align measure_theory.lintegral_sub_le' MeasureTheory.lintegral_sub_le' theorem lintegral_sub_le (f g : α → ℝ≥0∞) (hf : Measurable f) : ∫⁻ x, g x ∂μ - ∫⁻ x, f x ∂μ ≤ ∫⁻ x, g x - f x ∂μ := lintegral_sub_le' f g hf.aemeasurable #align measure_theory.lintegral_sub_le MeasureTheory.lintegral_sub_le theorem lintegral_strict_mono_of_ae_le_of_frequently_ae_lt {f g : α → ℝ≥0∞} (hg : AEMeasurable g μ) (hfi : ∫⁻ x, f x ∂μ ≠ ∞) (h_le : f ≤ᵐ[μ] g) (h : ∃ᵐ x ∂μ, f x ≠ g x) : ∫⁻ x, f x ∂μ < ∫⁻ x, g x ∂μ := by contrapose! h simp only [not_frequently, Ne, Classical.not_not] exact ae_eq_of_ae_le_of_lintegral_le h_le hfi hg h #align measure_theory.lintegral_strict_mono_of_ae_le_of_frequently_ae_lt MeasureTheory.lintegral_strict_mono_of_ae_le_of_frequently_ae_lt theorem lintegral_strict_mono_of_ae_le_of_ae_lt_on {f g : α → ℝ≥0∞} (hg : AEMeasurable g μ) (hfi : ∫⁻ x, f x ∂μ ≠ ∞) (h_le : f ≤ᵐ[μ] g) {s : Set α} (hμs : μ s ≠ 0) (h : ∀ᵐ x ∂μ, x ∈ s → f x < g x) : ∫⁻ x, f x ∂μ < ∫⁻ x, g x ∂μ := lintegral_strict_mono_of_ae_le_of_frequently_ae_lt hg hfi h_le <| ((frequently_ae_mem_iff.2 hμs).and_eventually h).mono fun _x hx => (hx.2 hx.1).ne #align measure_theory.lintegral_strict_mono_of_ae_le_of_ae_lt_on MeasureTheory.lintegral_strict_mono_of_ae_le_of_ae_lt_on theorem lintegral_strict_mono {f g : α → ℝ≥0∞} (hμ : μ ≠ 0) (hg : AEMeasurable g μ) (hfi : ∫⁻ x, f x ∂μ ≠ ∞) (h : ∀ᵐ x ∂μ, f x < g x) : ∫⁻ x, f x ∂μ < ∫⁻ x, g x ∂μ := by rw [Ne, ← Measure.measure_univ_eq_zero] at hμ refine lintegral_strict_mono_of_ae_le_of_ae_lt_on hg hfi (ae_le_of_ae_lt h) hμ ?_ simpa using h #align measure_theory.lintegral_strict_mono MeasureTheory.lintegral_strict_mono theorem set_lintegral_strict_mono {f g : α → ℝ≥0∞} {s : Set α} (hsm : MeasurableSet s) (hs : μ s ≠ 0) (hg : Measurable g) (hfi : ∫⁻ x in s, f x ∂μ ≠ ∞) (h : ∀ᵐ x ∂μ, x ∈ s → f x < g x) : ∫⁻ x in s, f x ∂μ < ∫⁻ x in s, g x ∂μ := lintegral_strict_mono (by simp [hs]) hg.aemeasurable hfi ((ae_restrict_iff' hsm).mpr h) #align measure_theory.set_lintegral_strict_mono MeasureTheory.set_lintegral_strict_mono /-- Monotone convergence theorem for nonincreasing sequences of functions -/ theorem lintegral_iInf_ae {f : ℕ → α → ℝ≥0∞} (h_meas : ∀ n, Measurable (f n)) (h_mono : ∀ n : ℕ, f n.succ ≤ᵐ[μ] f n) (h_fin : ∫⁻ a, f 0 a ∂μ ≠ ∞) : ∫⁻ a, ⨅ n, f n a ∂μ = ⨅ n, ∫⁻ a, f n a ∂μ := have fn_le_f0 : ∫⁻ a, ⨅ n, f n a ∂μ ≤ ∫⁻ a, f 0 a ∂μ := lintegral_mono fun a => iInf_le_of_le 0 le_rfl have fn_le_f0' : ⨅ n, ∫⁻ a, f n a ∂μ ≤ ∫⁻ a, f 0 a ∂μ := iInf_le_of_le 0 le_rfl (ENNReal.sub_right_inj h_fin fn_le_f0 fn_le_f0').1 <| show ∫⁻ a, f 0 a ∂μ - ∫⁻ a, ⨅ n, f n a ∂μ = ∫⁻ a, f 0 a ∂μ - ⨅ n, ∫⁻ a, f n a ∂μ from calc ∫⁻ a, f 0 a ∂μ - ∫⁻ a, ⨅ n, f n a ∂μ = ∫⁻ a, f 0 a - ⨅ n, f n a ∂μ := (lintegral_sub (measurable_iInf h_meas) (ne_top_of_le_ne_top h_fin <| lintegral_mono fun a => iInf_le _ _) (ae_of_all _ fun a => iInf_le _ _)).symm _ = ∫⁻ a, ⨆ n, f 0 a - f n a ∂μ := congr rfl (funext fun a => ENNReal.sub_iInf) _ = ⨆ n, ∫⁻ a, f 0 a - f n a ∂μ := (lintegral_iSup_ae (fun n => (h_meas 0).sub (h_meas n)) fun n => (h_mono n).mono fun a ha => tsub_le_tsub le_rfl ha) _ = ⨆ n, ∫⁻ a, f 0 a ∂μ - ∫⁻ a, f n a ∂μ := (have h_mono : ∀ᵐ a ∂μ, ∀ n : ℕ, f n.succ a ≤ f n a := ae_all_iff.2 h_mono have h_mono : ∀ n, ∀ᵐ a ∂μ, f n a ≤ f 0 a := fun n => h_mono.mono fun a h => by induction' n with n ih · exact le_rfl · exact le_trans (h n) ih congr_arg iSup <| funext fun n => lintegral_sub (h_meas _) (ne_top_of_le_ne_top h_fin <| lintegral_mono_ae <| h_mono n) (h_mono n)) _ = ∫⁻ a, f 0 a ∂μ - ⨅ n, ∫⁻ a, f n a ∂μ := ENNReal.sub_iInf.symm #align measure_theory.lintegral_infi_ae MeasureTheory.lintegral_iInf_ae /-- Monotone convergence theorem for nonincreasing sequences of functions -/ theorem lintegral_iInf {f : ℕ → α → ℝ≥0∞} (h_meas : ∀ n, Measurable (f n)) (h_anti : Antitone f) (h_fin : ∫⁻ a, f 0 a ∂μ ≠ ∞) : ∫⁻ a, ⨅ n, f n a ∂μ = ⨅ n, ∫⁻ a, f n a ∂μ := lintegral_iInf_ae h_meas (fun n => ae_of_all _ <| h_anti n.le_succ) h_fin #align measure_theory.lintegral_infi MeasureTheory.lintegral_iInf theorem lintegral_iInf' {f : ℕ → α → ℝ≥0∞} (h_meas : ∀ n, AEMeasurable (f n) μ) (h_anti : ∀ᵐ a ∂μ, Antitone (fun i ↦ f i a)) (h_fin : ∫⁻ a, f 0 a ∂μ ≠ ∞) : ∫⁻ a, ⨅ n, f n a ∂μ = ⨅ n, ∫⁻ a, f n a ∂μ := by simp_rw [← iInf_apply] let p : α → (ℕ → ℝ≥0∞) → Prop := fun _ f' => Antitone f' have hp : ∀ᵐ x ∂μ, p x fun i => f i x := h_anti have h_ae_seq_mono : Antitone (aeSeq h_meas p) := by intro n m hnm x by_cases hx : x ∈ aeSeqSet h_meas p · exact aeSeq.prop_of_mem_aeSeqSet h_meas hx hnm · simp only [aeSeq, hx, if_false] exact le_rfl rw [lintegral_congr_ae (aeSeq.iInf h_meas hp).symm] simp_rw [iInf_apply] rw [lintegral_iInf (aeSeq.measurable h_meas p) h_ae_seq_mono] · congr exact funext fun n ↦ lintegral_congr_ae (aeSeq.aeSeq_n_eq_fun_n_ae h_meas hp n) · rwa [lintegral_congr_ae (aeSeq.aeSeq_n_eq_fun_n_ae h_meas hp 0)] /-- Monotone convergence for an infimum over a directed family and indexed by a countable type -/ theorem lintegral_iInf_directed_of_measurable {mα : MeasurableSpace α} [Countable β] {f : β → α → ℝ≥0∞} {μ : Measure α} (hμ : μ ≠ 0) (hf : ∀ b, Measurable (f b)) (hf_int : ∀ b, ∫⁻ a, f b a ∂μ ≠ ∞) (h_directed : Directed (· ≥ ·) f) : ∫⁻ a, ⨅ b, f b a ∂μ = ⨅ b, ∫⁻ a, f b a ∂μ := by cases nonempty_encodable β cases isEmpty_or_nonempty β · simp only [iInf_of_empty, lintegral_const, ENNReal.top_mul (Measure.measure_univ_ne_zero.mpr hμ)] inhabit β have : ∀ a, ⨅ b, f b a = ⨅ n, f (h_directed.sequence f n) a := by refine fun a => le_antisymm (le_iInf fun n => iInf_le _ _) (le_iInf fun b => iInf_le_of_le (Encodable.encode b + 1) ?_) exact h_directed.sequence_le b a -- Porting note: used `∘` below to deal with its reduced reducibility calc ∫⁻ a, ⨅ b, f b a ∂μ _ = ∫⁻ a, ⨅ n, (f ∘ h_directed.sequence f) n a ∂μ := by simp only [this, Function.comp_apply] _ = ⨅ n, ∫⁻ a, (f ∘ h_directed.sequence f) n a ∂μ := by rw [lintegral_iInf ?_ h_directed.sequence_anti] · exact hf_int _ · exact fun n => hf _ _ = ⨅ b, ∫⁻ a, f b a ∂μ := by refine le_antisymm (le_iInf fun b => ?_) (le_iInf fun n => ?_) · exact iInf_le_of_le (Encodable.encode b + 1) (lintegral_mono <| h_directed.sequence_le b) · exact iInf_le (fun b => ∫⁻ a, f b a ∂μ) _ #align lintegral_infi_directed_of_measurable MeasureTheory.lintegral_iInf_directed_of_measurable /-- Known as Fatou's lemma, version with `AEMeasurable` functions -/ theorem lintegral_liminf_le' {f : ℕ → α → ℝ≥0∞} (h_meas : ∀ n, AEMeasurable (f n) μ) : ∫⁻ a, liminf (fun n => f n a) atTop ∂μ ≤ liminf (fun n => ∫⁻ a, f n a ∂μ) atTop := calc ∫⁻ a, liminf (fun n => f n a) atTop ∂μ = ∫⁻ a, ⨆ n : ℕ, ⨅ i ≥ n, f i a ∂μ := by simp only [liminf_eq_iSup_iInf_of_nat] _ = ⨆ n : ℕ, ∫⁻ a, ⨅ i ≥ n, f i a ∂μ := (lintegral_iSup' (fun n => aemeasurable_biInf _ (to_countable _) (fun i _ ↦ h_meas i)) (ae_of_all μ fun a n m hnm => iInf_le_iInf_of_subset fun i hi => le_trans hnm hi)) _ ≤ ⨆ n : ℕ, ⨅ i ≥ n, ∫⁻ a, f i a ∂μ := iSup_mono fun n => le_iInf₂_lintegral _ _ = atTop.liminf fun n => ∫⁻ a, f n a ∂μ := Filter.liminf_eq_iSup_iInf_of_nat.symm #align measure_theory.lintegral_liminf_le' MeasureTheory.lintegral_liminf_le' /-- Known as Fatou's lemma -/ theorem lintegral_liminf_le {f : ℕ → α → ℝ≥0∞} (h_meas : ∀ n, Measurable (f n)) : ∫⁻ a, liminf (fun n => f n a) atTop ∂μ ≤ liminf (fun n => ∫⁻ a, f n a ∂μ) atTop := lintegral_liminf_le' fun n => (h_meas n).aemeasurable #align measure_theory.lintegral_liminf_le MeasureTheory.lintegral_liminf_le theorem limsup_lintegral_le {f : ℕ → α → ℝ≥0∞} {g : α → ℝ≥0∞} (hf_meas : ∀ n, Measurable (f n)) (h_bound : ∀ n, f n ≤ᵐ[μ] g) (h_fin : ∫⁻ a, g a ∂μ ≠ ∞) : limsup (fun n => ∫⁻ a, f n a ∂μ) atTop ≤ ∫⁻ a, limsup (fun n => f n a) atTop ∂μ := calc limsup (fun n => ∫⁻ a, f n a ∂μ) atTop = ⨅ n : ℕ, ⨆ i ≥ n, ∫⁻ a, f i a ∂μ := limsup_eq_iInf_iSup_of_nat _ ≤ ⨅ n : ℕ, ∫⁻ a, ⨆ i ≥ n, f i a ∂μ := iInf_mono fun n => iSup₂_lintegral_le _ _ = ∫⁻ a, ⨅ n : ℕ, ⨆ i ≥ n, f i a ∂μ := by refine (lintegral_iInf ?_ ?_ ?_).symm · intro n exact measurable_biSup _ (to_countable _) (fun i _ ↦ hf_meas i) · intro n m hnm a exact iSup_le_iSup_of_subset fun i hi => le_trans hnm hi · refine ne_top_of_le_ne_top h_fin (lintegral_mono_ae ?_) refine (ae_all_iff.2 h_bound).mono fun n hn => ?_ exact iSup_le fun i => iSup_le fun _ => hn i _ = ∫⁻ a, limsup (fun n => f n a) atTop ∂μ := by simp only [limsup_eq_iInf_iSup_of_nat] #align measure_theory.limsup_lintegral_le MeasureTheory.limsup_lintegral_le /-- Dominated convergence theorem for nonnegative functions -/ theorem tendsto_lintegral_of_dominated_convergence {F : ℕ → α → ℝ≥0∞} {f : α → ℝ≥0∞} (bound : α → ℝ≥0∞) (hF_meas : ∀ n, Measurable (F n)) (h_bound : ∀ n, F n ≤ᵐ[μ] bound) (h_fin : ∫⁻ a, bound a ∂μ ≠ ∞) (h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => F n a) atTop (𝓝 (f a))) : Tendsto (fun n => ∫⁻ a, F n a ∂μ) atTop (𝓝 (∫⁻ a, f a ∂μ)) := tendsto_of_le_liminf_of_limsup_le (calc ∫⁻ a, f a ∂μ = ∫⁻ a, liminf (fun n : ℕ => F n a) atTop ∂μ := lintegral_congr_ae <| h_lim.mono fun a h => h.liminf_eq.symm _ ≤ liminf (fun n => ∫⁻ a, F n a ∂μ) atTop := lintegral_liminf_le hF_meas ) (calc limsup (fun n : ℕ => ∫⁻ a, F n a ∂μ) atTop ≤ ∫⁻ a, limsup (fun n => F n a) atTop ∂μ := limsup_lintegral_le hF_meas h_bound h_fin _ = ∫⁻ a, f a ∂μ := lintegral_congr_ae <| h_lim.mono fun a h => h.limsup_eq ) #align measure_theory.tendsto_lintegral_of_dominated_convergence MeasureTheory.tendsto_lintegral_of_dominated_convergence /-- Dominated convergence theorem for nonnegative functions which are just almost everywhere measurable. -/ theorem tendsto_lintegral_of_dominated_convergence' {F : ℕ → α → ℝ≥0∞} {f : α → ℝ≥0∞} (bound : α → ℝ≥0∞) (hF_meas : ∀ n, AEMeasurable (F n) μ) (h_bound : ∀ n, F n ≤ᵐ[μ] bound) (h_fin : ∫⁻ a, bound a ∂μ ≠ ∞) (h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => F n a) atTop (𝓝 (f a))) : Tendsto (fun n => ∫⁻ a, F n a ∂μ) atTop (𝓝 (∫⁻ a, f a ∂μ)) := by have : ∀ n, ∫⁻ a, F n a ∂μ = ∫⁻ a, (hF_meas n).mk (F n) a ∂μ := fun n => lintegral_congr_ae (hF_meas n).ae_eq_mk simp_rw [this] apply tendsto_lintegral_of_dominated_convergence bound (fun n => (hF_meas n).measurable_mk) _ h_fin · have : ∀ n, ∀ᵐ a ∂μ, (hF_meas n).mk (F n) a = F n a := fun n => (hF_meas n).ae_eq_mk.symm have : ∀ᵐ a ∂μ, ∀ n, (hF_meas n).mk (F n) a = F n a := ae_all_iff.mpr this filter_upwards [this, h_lim] with a H H' simp_rw [H] exact H' · intro n filter_upwards [h_bound n, (hF_meas n).ae_eq_mk] with a H H' rwa [H'] at H #align measure_theory.tendsto_lintegral_of_dominated_convergence' MeasureTheory.tendsto_lintegral_of_dominated_convergence' /-- Dominated convergence theorem for filters with a countable basis -/ theorem tendsto_lintegral_filter_of_dominated_convergence {ι} {l : Filter ι} [l.IsCountablyGenerated] {F : ι → α → ℝ≥0∞} {f : α → ℝ≥0∞} (bound : α → ℝ≥0∞) (hF_meas : ∀ᶠ n in l, Measurable (F n)) (h_bound : ∀ᶠ n in l, ∀ᵐ a ∂μ, F n a ≤ bound a) (h_fin : ∫⁻ a, bound a ∂μ ≠ ∞) (h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => F n a) l (𝓝 (f a))) : Tendsto (fun n => ∫⁻ a, F n a ∂μ) l (𝓝 <| ∫⁻ a, f a ∂μ) := by rw [tendsto_iff_seq_tendsto] intro x xl have hxl := by rw [tendsto_atTop'] at xl exact xl have h := inter_mem hF_meas h_bound replace h := hxl _ h rcases h with ⟨k, h⟩ rw [← tendsto_add_atTop_iff_nat k] refine tendsto_lintegral_of_dominated_convergence ?_ ?_ ?_ ?_ ?_ · exact bound · intro refine (h _ ?_).1 exact Nat.le_add_left _ _ · intro refine (h _ ?_).2 exact Nat.le_add_left _ _ · assumption · refine h_lim.mono fun a h_lim => ?_ apply @Tendsto.comp _ _ _ (fun n => x (n + k)) fun n => F n a · assumption rw [tendsto_add_atTop_iff_nat] assumption #align measure_theory.tendsto_lintegral_filter_of_dominated_convergence MeasureTheory.tendsto_lintegral_filter_of_dominated_convergence theorem lintegral_tendsto_of_tendsto_of_antitone {f : ℕ → α → ℝ≥0∞} {F : α → ℝ≥0∞} (hf : ∀ n, AEMeasurable (f n) μ) (h_anti : ∀ᵐ x ∂μ, Antitone fun n ↦ f n x) (h0 : ∫⁻ a, f 0 a ∂μ ≠ ∞) (h_tendsto : ∀ᵐ x ∂μ, Tendsto (fun n ↦ f n x) atTop (𝓝 (F x))) : Tendsto (fun n ↦ ∫⁻ x, f n x ∂μ) atTop (𝓝 (∫⁻ x, F x ∂μ)) := by have : Antitone fun n ↦ ∫⁻ x, f n x ∂μ := fun i j hij ↦ lintegral_mono_ae (h_anti.mono fun x hx ↦ hx hij) suffices key : ∫⁻ x, F x ∂μ = ⨅ n, ∫⁻ x, f n x ∂μ by rw [key] exact tendsto_atTop_iInf this rw [← lintegral_iInf' hf h_anti h0] refine lintegral_congr_ae ?_ filter_upwards [h_anti, h_tendsto] with _ hx_anti hx_tendsto using tendsto_nhds_unique hx_tendsto (tendsto_atTop_iInf hx_anti) section open Encodable /-- Monotone convergence for a supremum over a directed family and indexed by a countable type -/ theorem lintegral_iSup_directed_of_measurable [Countable β] {f : β → α → ℝ≥0∞} (hf : ∀ b, Measurable (f b)) (h_directed : Directed (· ≤ ·) f) : ∫⁻ a, ⨆ b, f b a ∂μ = ⨆ b, ∫⁻ a, f b a ∂μ := by cases nonempty_encodable β cases isEmpty_or_nonempty β · simp [iSup_of_empty] inhabit β have : ∀ a, ⨆ b, f b a = ⨆ n, f (h_directed.sequence f n) a := by intro a refine le_antisymm (iSup_le fun b => ?_) (iSup_le fun n => le_iSup (fun n => f n a) _) exact le_iSup_of_le (encode b + 1) (h_directed.le_sequence b a) calc ∫⁻ a, ⨆ b, f b a ∂μ = ∫⁻ a, ⨆ n, f (h_directed.sequence f n) a ∂μ := by simp only [this] _ = ⨆ n, ∫⁻ a, f (h_directed.sequence f n) a ∂μ := (lintegral_iSup (fun n => hf _) h_directed.sequence_mono) _ = ⨆ b, ∫⁻ a, f b a ∂μ := by refine le_antisymm (iSup_le fun n => ?_) (iSup_le fun b => ?_) · exact le_iSup (fun b => ∫⁻ a, f b a ∂μ) _ · exact le_iSup_of_le (encode b + 1) (lintegral_mono <| h_directed.le_sequence b) #align measure_theory.lintegral_supr_directed_of_measurable MeasureTheory.lintegral_iSup_directed_of_measurable /-- Monotone convergence for a supremum over a directed family and indexed by a countable type. -/ theorem lintegral_iSup_directed [Countable β] {f : β → α → ℝ≥0∞} (hf : ∀ b, AEMeasurable (f b) μ) (h_directed : Directed (· ≤ ·) f) : ∫⁻ a, ⨆ b, f b a ∂μ = ⨆ b, ∫⁻ a, f b a ∂μ := by simp_rw [← iSup_apply] let p : α → (β → ENNReal) → Prop := fun x f' => Directed LE.le f' have hp : ∀ᵐ x ∂μ, p x fun i => f i x := by filter_upwards [] with x i j obtain ⟨z, hz₁, hz₂⟩ := h_directed i j exact ⟨z, hz₁ x, hz₂ x⟩ have h_ae_seq_directed : Directed LE.le (aeSeq hf p) := by intro b₁ b₂ obtain ⟨z, hz₁, hz₂⟩ := h_directed b₁ b₂ refine ⟨z, ?_, ?_⟩ <;> · intro x by_cases hx : x ∈ aeSeqSet hf p · repeat rw [aeSeq.aeSeq_eq_fun_of_mem_aeSeqSet hf hx] apply_rules [hz₁, hz₂] · simp only [aeSeq, hx, if_false] exact le_rfl convert lintegral_iSup_directed_of_measurable (aeSeq.measurable hf p) h_ae_seq_directed using 1 · simp_rw [← iSup_apply] rw [lintegral_congr_ae (aeSeq.iSup hf hp).symm] · congr 1 ext1 b rw [lintegral_congr_ae] apply EventuallyEq.symm exact aeSeq.aeSeq_n_eq_fun_n_ae hf hp _ #align measure_theory.lintegral_supr_directed MeasureTheory.lintegral_iSup_directed end theorem lintegral_tsum [Countable β] {f : β → α → ℝ≥0∞} (hf : ∀ i, AEMeasurable (f i) μ) : ∫⁻ a, ∑' i, f i a ∂μ = ∑' i, ∫⁻ a, f i a ∂μ := by simp only [ENNReal.tsum_eq_iSup_sum] rw [lintegral_iSup_directed] · simp [lintegral_finset_sum' _ fun i _ => hf i] · intro b exact Finset.aemeasurable_sum _ fun i _ => hf i · intro s t use s ∪ t constructor · exact fun a => Finset.sum_le_sum_of_subset Finset.subset_union_left · exact fun a => Finset.sum_le_sum_of_subset Finset.subset_union_right #align measure_theory.lintegral_tsum MeasureTheory.lintegral_tsum open Measure theorem lintegral_iUnion₀ [Countable β] {s : β → Set α} (hm : ∀ i, NullMeasurableSet (s i) μ) (hd : Pairwise (AEDisjoint μ on s)) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ i, s i, f a ∂μ = ∑' i, ∫⁻ a in s i, f a ∂μ := by simp only [Measure.restrict_iUnion_ae hd hm, lintegral_sum_measure] #align measure_theory.lintegral_Union₀ MeasureTheory.lintegral_iUnion₀ theorem lintegral_iUnion [Countable β] {s : β → Set α} (hm : ∀ i, MeasurableSet (s i)) (hd : Pairwise (Disjoint on s)) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ i, s i, f a ∂μ = ∑' i, ∫⁻ a in s i, f a ∂μ := lintegral_iUnion₀ (fun i => (hm i).nullMeasurableSet) hd.aedisjoint f #align measure_theory.lintegral_Union MeasureTheory.lintegral_iUnion theorem lintegral_biUnion₀ {t : Set β} {s : β → Set α} (ht : t.Countable) (hm : ∀ i ∈ t, NullMeasurableSet (s i) μ) (hd : t.Pairwise (AEDisjoint μ on s)) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ i ∈ t, s i, f a ∂μ = ∑' i : t, ∫⁻ a in s i, f a ∂μ := by haveI := ht.toEncodable rw [biUnion_eq_iUnion, lintegral_iUnion₀ (SetCoe.forall'.1 hm) (hd.subtype _ _)] #align measure_theory.lintegral_bUnion₀ MeasureTheory.lintegral_biUnion₀ theorem lintegral_biUnion {t : Set β} {s : β → Set α} (ht : t.Countable) (hm : ∀ i ∈ t, MeasurableSet (s i)) (hd : t.PairwiseDisjoint s) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ i ∈ t, s i, f a ∂μ = ∑' i : t, ∫⁻ a in s i, f a ∂μ := lintegral_biUnion₀ ht (fun i hi => (hm i hi).nullMeasurableSet) hd.aedisjoint f #align measure_theory.lintegral_bUnion MeasureTheory.lintegral_biUnion theorem lintegral_biUnion_finset₀ {s : Finset β} {t : β → Set α} (hd : Set.Pairwise (↑s) (AEDisjoint μ on t)) (hm : ∀ b ∈ s, NullMeasurableSet (t b) μ) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ b ∈ s, t b, f a ∂μ = ∑ b ∈ s, ∫⁻ a in t b, f a ∂μ := by simp only [← Finset.mem_coe, lintegral_biUnion₀ s.countable_toSet hm hd, ← Finset.tsum_subtype'] #align measure_theory.lintegral_bUnion_finset₀ MeasureTheory.lintegral_biUnion_finset₀ theorem lintegral_biUnion_finset {s : Finset β} {t : β → Set α} (hd : Set.PairwiseDisjoint (↑s) t) (hm : ∀ b ∈ s, MeasurableSet (t b)) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ b ∈ s, t b, f a ∂μ = ∑ b ∈ s, ∫⁻ a in t b, f a ∂μ := lintegral_biUnion_finset₀ hd.aedisjoint (fun b hb => (hm b hb).nullMeasurableSet) f #align measure_theory.lintegral_bUnion_finset MeasureTheory.lintegral_biUnion_finset theorem lintegral_iUnion_le [Countable β] (s : β → Set α) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ i, s i, f a ∂μ ≤ ∑' i, ∫⁻ a in s i, f a ∂μ := by rw [← lintegral_sum_measure] exact lintegral_mono' restrict_iUnion_le le_rfl #align measure_theory.lintegral_Union_le MeasureTheory.lintegral_iUnion_le theorem lintegral_union {f : α → ℝ≥0∞} {A B : Set α} (hB : MeasurableSet B) (hAB : Disjoint A B) : ∫⁻ a in A ∪ B, f a ∂μ = ∫⁻ a in A, f a ∂μ + ∫⁻ a in B, f a ∂μ := by rw [restrict_union hAB hB, lintegral_add_measure] #align measure_theory.lintegral_union MeasureTheory.lintegral_union theorem lintegral_union_le (f : α → ℝ≥0∞) (s t : Set α) : ∫⁻ a in s ∪ t, f a ∂μ ≤ ∫⁻ a in s, f a ∂μ + ∫⁻ a in t, f a ∂μ := by rw [← lintegral_add_measure] exact lintegral_mono' (restrict_union_le _ _) le_rfl theorem lintegral_inter_add_diff {B : Set α} (f : α → ℝ≥0∞) (A : Set α) (hB : MeasurableSet B) : ∫⁻ x in A ∩ B, f x ∂μ + ∫⁻ x in A \ B, f x ∂μ = ∫⁻ x in A, f x ∂μ := by rw [← lintegral_add_measure, restrict_inter_add_diff _ hB] #align measure_theory.lintegral_inter_add_diff MeasureTheory.lintegral_inter_add_diff
Mathlib/MeasureTheory/Integral/Lebesgue.lean
1,363
1,365
theorem lintegral_add_compl (f : α → ℝ≥0∞) {A : Set α} (hA : MeasurableSet A) : ∫⁻ x in A, f x ∂μ + ∫⁻ x in Aᶜ, f x ∂μ = ∫⁻ x, f x ∂μ := by
rw [← lintegral_add_measure, Measure.restrict_add_restrict_compl hA]
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser, Kevin Buzzard, Jujian Zhang -/ import Mathlib.Algebra.Algebra.Operations import Mathlib.Algebra.Algebra.Subalgebra.Basic import Mathlib.Algebra.DirectSum.Algebra #align_import algebra.direct_sum.internal from "leanprover-community/mathlib"@"9936c3dfc04e5876f4368aeb2e60f8d8358d095a" /-! # Internally graded rings and algebras This module provides `DirectSum.GSemiring` and `DirectSum.GCommSemiring` instances for a collection of subobjects `A` when a `SetLike.GradedMonoid` instance is available: * `SetLike.gnonUnitalNonAssocSemiring` * `SetLike.gsemiring` * `SetLike.gcommSemiring` With these instances in place, it provides the bundled canonical maps out of a direct sum of subobjects into their carrier type: * `DirectSum.coeRingHom` (a `RingHom` version of `DirectSum.coeAddMonoidHom`) * `DirectSum.coeAlgHom` (an `AlgHom` version of `DirectSum.coeLinearMap`) Strictly the definitions in this file are not sufficient to fully define an "internal" direct sum; to represent this case, `(h : DirectSum.IsInternal A) [SetLike.GradedMonoid A]` is needed. In the future there will likely be a data-carrying, constructive, typeclass version of `DirectSum.IsInternal` for providing an explicit decomposition function. When `CompleteLattice.Independent (Set.range A)` (a weaker condition than `DirectSum.IsInternal A`), these provide a grading of `⨆ i, A i`, and the mapping `⨁ i, A i →+ ⨆ i, A i` can be obtained as `DirectSum.toAddMonoid (fun i ↦ AddSubmonoid.inclusion <| le_iSup A i)`. ## Tags internally graded ring -/ open DirectSum variable {ι : Type*} {σ S R : Type*} instance AddCommMonoid.ofSubmonoidOnSemiring [Semiring R] [SetLike σ R] [AddSubmonoidClass σ R] (A : ι → σ) : ∀ i, AddCommMonoid (A i) := fun i => by infer_instance #align add_comm_monoid.of_submonoid_on_semiring AddCommMonoid.ofSubmonoidOnSemiring instance AddCommGroup.ofSubgroupOnRing [Ring R] [SetLike σ R] [AddSubgroupClass σ R] (A : ι → σ) : ∀ i, AddCommGroup (A i) := fun i => by infer_instance #align add_comm_group.of_subgroup_on_ring AddCommGroup.ofSubgroupOnRing theorem SetLike.algebraMap_mem_graded [Zero ι] [CommSemiring S] [Semiring R] [Algebra S R] (A : ι → Submodule S R) [SetLike.GradedOne A] (s : S) : algebraMap S R s ∈ A 0 := by rw [Algebra.algebraMap_eq_smul_one] exact (A 0).smul_mem s <| SetLike.one_mem_graded _ #align set_like.algebra_map_mem_graded SetLike.algebraMap_mem_graded theorem SetLike.natCast_mem_graded [Zero ι] [AddMonoidWithOne R] [SetLike σ R] [AddSubmonoidClass σ R] (A : ι → σ) [SetLike.GradedOne A] (n : ℕ) : (n : R) ∈ A 0 := by induction' n with _ n_ih · rw [Nat.cast_zero] exact zero_mem (A 0) · rw [Nat.cast_succ] exact add_mem n_ih (SetLike.one_mem_graded _) #align set_like.nat_cast_mem_graded SetLike.natCast_mem_graded @[deprecated (since := "2024-04-17")] alias SetLike.nat_cast_mem_graded := SetLike.natCast_mem_graded theorem SetLike.intCast_mem_graded [Zero ι] [AddGroupWithOne R] [SetLike σ R] [AddSubgroupClass σ R] (A : ι → σ) [SetLike.GradedOne A] (z : ℤ) : (z : R) ∈ A 0 := by induction z · rw [Int.ofNat_eq_coe, Int.cast_natCast] exact SetLike.natCast_mem_graded _ _ · rw [Int.cast_negSucc] exact neg_mem (SetLike.natCast_mem_graded _ _) #align set_like.int_cast_mem_graded SetLike.intCast_mem_graded @[deprecated (since := "2024-04-17")] alias SetLike.int_cast_mem_graded := SetLike.intCast_mem_graded section DirectSum variable [DecidableEq ι] /-! #### From `AddSubmonoid`s and `AddSubgroup`s -/ namespace SetLike /-- Build a `DirectSum.GNonUnitalNonAssocSemiring` instance for a collection of additive submonoids. -/ instance gnonUnitalNonAssocSemiring [Add ι] [NonUnitalNonAssocSemiring R] [SetLike σ R] [AddSubmonoidClass σ R] (A : ι → σ) [SetLike.GradedMul A] : DirectSum.GNonUnitalNonAssocSemiring fun i => A i := { SetLike.gMul A with mul_zero := fun _ => Subtype.ext (mul_zero _) zero_mul := fun _ => Subtype.ext (zero_mul _) mul_add := fun _ _ _ => Subtype.ext (mul_add _ _ _) add_mul := fun _ _ _ => Subtype.ext (add_mul _ _ _) } #align set_like.gnon_unital_non_assoc_semiring SetLike.gnonUnitalNonAssocSemiring /-- Build a `DirectSum.GSemiring` instance for a collection of additive submonoids. -/ instance gsemiring [AddMonoid ι] [Semiring R] [SetLike σ R] [AddSubmonoidClass σ R] (A : ι → σ) [SetLike.GradedMonoid A] : DirectSum.GSemiring fun i => A i := { SetLike.gMonoid A with mul_zero := fun _ => Subtype.ext (mul_zero _) zero_mul := fun _ => Subtype.ext (zero_mul _) mul_add := fun _ _ _ => Subtype.ext (mul_add _ _ _) add_mul := fun _ _ _ => Subtype.ext (add_mul _ _ _) natCast := fun n => ⟨n, SetLike.natCast_mem_graded _ _⟩ natCast_zero := Subtype.ext Nat.cast_zero natCast_succ := fun n => Subtype.ext (Nat.cast_succ n) } #align set_like.gsemiring SetLike.gsemiring /-- Build a `DirectSum.GCommSemiring` instance for a collection of additive submonoids. -/ instance gcommSemiring [AddCommMonoid ι] [CommSemiring R] [SetLike σ R] [AddSubmonoidClass σ R] (A : ι → σ) [SetLike.GradedMonoid A] : DirectSum.GCommSemiring fun i => A i := { SetLike.gCommMonoid A, SetLike.gsemiring A with } #align set_like.gcomm_semiring SetLike.gcommSemiring /-- Build a `DirectSum.GRing` instance for a collection of additive subgroups. -/ instance gring [AddMonoid ι] [Ring R] [SetLike σ R] [AddSubgroupClass σ R] (A : ι → σ) [SetLike.GradedMonoid A] : DirectSum.GRing fun i => A i := { SetLike.gsemiring A with intCast := fun z => ⟨z, SetLike.intCast_mem_graded _ _⟩ intCast_ofNat := fun _n => Subtype.ext <| Int.cast_natCast _ intCast_negSucc_ofNat := fun n => Subtype.ext <| Int.cast_negSucc n } #align set_like.gring SetLike.gring /-- Build a `DirectSum.GCommRing` instance for a collection of additive submonoids. -/ instance gcommRing [AddCommMonoid ι] [CommRing R] [SetLike σ R] [AddSubgroupClass σ R] (A : ι → σ) [SetLike.GradedMonoid A] : DirectSum.GCommRing fun i => A i := { SetLike.gCommMonoid A, SetLike.gring A with } #align set_like.gcomm_ring SetLike.gcommRing end SetLike namespace DirectSum section coe variable [Semiring R] [SetLike σ R] [AddSubmonoidClass σ R] (A : ι → σ) /-- The canonical ring isomorphism between `⨁ i, A i` and `R`-/ def coeRingHom [AddMonoid ι] [SetLike.GradedMonoid A] : (⨁ i, A i) →+* R := DirectSum.toSemiring (fun i => AddSubmonoidClass.subtype (A i)) rfl fun _ _ => rfl #align direct_sum.coe_ring_hom DirectSum.coeRingHom /-- The canonical ring isomorphism between `⨁ i, A i` and `R`-/ @[simp] theorem coeRingHom_of [AddMonoid ι] [SetLike.GradedMonoid A] (i : ι) (x : A i) : (coeRingHom A : _ →+* R) (of (fun i => A i) i x) = x := DirectSum.toSemiring_of _ _ _ _ _ #align direct_sum.coe_ring_hom_of DirectSum.coeRingHom_of theorem coe_mul_apply [AddMonoid ι] [SetLike.GradedMonoid A] [∀ (i : ι) (x : A i), Decidable (x ≠ 0)] (r r' : ⨁ i, A i) (n : ι) : ((r * r') n : R) = ∑ ij ∈ (r.support ×ˢ r'.support).filter (fun ij : ι × ι => ij.1 + ij.2 = n), (r ij.1 * r' ij.2 : R) := by rw [mul_eq_sum_support_ghas_mul, DFinsupp.finset_sum_apply, AddSubmonoidClass.coe_finset_sum] simp_rw [coe_of_apply, apply_ite, ZeroMemClass.coe_zero, ← Finset.sum_filter, SetLike.coe_gMul] #align direct_sum.coe_mul_apply DirectSum.coe_mul_apply theorem coe_mul_apply_eq_dfinsupp_sum [AddMonoid ι] [SetLike.GradedMonoid A] [∀ (i : ι) (x : A i), Decidable (x ≠ 0)] (r r' : ⨁ i, A i) (n : ι) : ((r * r') n : R) = r.sum fun i ri => r'.sum fun j rj => if i + j = n then (ri * rj : R) else 0 := by rw [mul_eq_dfinsupp_sum] iterate 2 rw [DFinsupp.sum_apply, DFinsupp.sum, AddSubmonoidClass.coe_finset_sum]; congr; ext dsimp only split_ifs with h · subst h rw [of_eq_same] rfl · rw [of_eq_of_ne _ _ _ _ h] rfl #align direct_sum.coe_mul_apply_eq_dfinsupp_sum DirectSum.coe_mul_apply_eq_dfinsupp_sum theorem coe_of_mul_apply_aux [AddMonoid ι] [SetLike.GradedMonoid A] {i : ι} (r : A i) (r' : ⨁ i, A i) {j n : ι} (H : ∀ x : ι, i + x = n ↔ x = j) : ((of (fun i => A i) i r * r') n : R) = r * r' j := by classical rw [coe_mul_apply_eq_dfinsupp_sum] apply (DFinsupp.sum_single_index _).trans swap · simp_rw [ZeroMemClass.coe_zero, zero_mul, ite_self] exact DFinsupp.sum_zero simp_rw [DFinsupp.sum, H, Finset.sum_ite_eq'] split_ifs with h · rfl rw [DFinsupp.not_mem_support_iff.mp h, ZeroMemClass.coe_zero, mul_zero] #align direct_sum.coe_of_mul_apply_aux DirectSum.coe_of_mul_apply_aux theorem coe_mul_of_apply_aux [AddMonoid ι] [SetLike.GradedMonoid A] (r : ⨁ i, A i) {i : ι} (r' : A i) {j n : ι} (H : ∀ x : ι, x + i = n ↔ x = j) : ((r * of (fun i => A i) i r') n : R) = r j * r' := by classical rw [coe_mul_apply_eq_dfinsupp_sum, DFinsupp.sum_comm] apply (DFinsupp.sum_single_index _).trans swap · simp_rw [ZeroMemClass.coe_zero, mul_zero, ite_self] exact DFinsupp.sum_zero simp_rw [DFinsupp.sum, H, Finset.sum_ite_eq'] split_ifs with h · rfl rw [DFinsupp.not_mem_support_iff.mp h, ZeroMemClass.coe_zero, zero_mul] #align direct_sum.coe_mul_of_apply_aux DirectSum.coe_mul_of_apply_aux theorem coe_of_mul_apply_add [AddLeftCancelMonoid ι] [SetLike.GradedMonoid A] {i : ι} (r : A i) (r' : ⨁ i, A i) (j : ι) : ((of (fun i => A i) i r * r') (i + j) : R) = r * r' j := coe_of_mul_apply_aux _ _ _ fun _x => ⟨fun h => add_left_cancel h, fun h => h ▸ rfl⟩ #align direct_sum.coe_of_mul_apply_add DirectSum.coe_of_mul_apply_add theorem coe_mul_of_apply_add [AddRightCancelMonoid ι] [SetLike.GradedMonoid A] (r : ⨁ i, A i) {i : ι} (r' : A i) (j : ι) : ((r * of (fun i => A i) i r') (j + i) : R) = r j * r' := coe_mul_of_apply_aux _ _ _ fun _x => ⟨fun h => add_right_cancel h, fun h => h ▸ rfl⟩ #align direct_sum.coe_mul_of_apply_add DirectSum.coe_mul_of_apply_add end coe section CanonicallyOrderedAddCommMonoid variable [Semiring R] [SetLike σ R] [AddSubmonoidClass σ R] (A : ι → σ) variable [CanonicallyOrderedAddCommMonoid ι] [SetLike.GradedMonoid A] theorem coe_of_mul_apply_of_not_le {i : ι} (r : A i) (r' : ⨁ i, A i) (n : ι) (h : ¬i ≤ n) : ((of (fun i => A i) i r * r') n : R) = 0 := by classical rw [coe_mul_apply_eq_dfinsupp_sum] apply (DFinsupp.sum_single_index _).trans swap · simp_rw [ZeroMemClass.coe_zero, zero_mul, ite_self] exact DFinsupp.sum_zero · rw [DFinsupp.sum, Finset.sum_ite_of_false _ _ fun x _ H => _, Finset.sum_const_zero] exact fun x _ H => h ((self_le_add_right i x).trans_eq H) #align direct_sum.coe_of_mul_apply_of_not_le DirectSum.coe_of_mul_apply_of_not_le theorem coe_mul_of_apply_of_not_le (r : ⨁ i, A i) {i : ι} (r' : A i) (n : ι) (h : ¬i ≤ n) : ((r * of (fun i => A i) i r') n : R) = 0 := by classical rw [coe_mul_apply_eq_dfinsupp_sum, DFinsupp.sum_comm] apply (DFinsupp.sum_single_index _).trans swap · simp_rw [ZeroMemClass.coe_zero, mul_zero, ite_self] exact DFinsupp.sum_zero · rw [DFinsupp.sum, Finset.sum_ite_of_false _ _ fun x _ H => _, Finset.sum_const_zero] exact fun x _ H => h ((self_le_add_left i x).trans_eq H) #align direct_sum.coe_mul_of_apply_of_not_le DirectSum.coe_mul_of_apply_of_not_le variable [Sub ι] [OrderedSub ι] [ContravariantClass ι ι (· + ·) (· ≤ ·)] /- The following two lemmas only require the same hypotheses as `eq_tsub_iff_add_eq_of_le`, but we state them for `CanonicallyOrderedAddCommMonoid` + the above three typeclasses for convenience. -/ theorem coe_mul_of_apply_of_le (r : ⨁ i, A i) {i : ι} (r' : A i) (n : ι) (h : i ≤ n) : ((r * of (fun i => A i) i r') n : R) = r (n - i) * r' := coe_mul_of_apply_aux _ _ _ fun _x => (eq_tsub_iff_add_eq_of_le h).symm #align direct_sum.coe_mul_of_apply_of_le DirectSum.coe_mul_of_apply_of_le theorem coe_of_mul_apply_of_le {i : ι} (r : A i) (r' : ⨁ i, A i) (n : ι) (h : i ≤ n) : ((of (fun i => A i) i r * r') n : R) = r * r' (n - i) := coe_of_mul_apply_aux _ _ _ fun x => by rw [eq_tsub_iff_add_eq_of_le h, add_comm] #align direct_sum.coe_of_mul_apply_of_le DirectSum.coe_of_mul_apply_of_le theorem coe_mul_of_apply (r : ⨁ i, A i) {i : ι} (r' : A i) (n : ι) [Decidable (i ≤ n)] : ((r * of (fun i => A i) i r') n : R) = if i ≤ n then (r (n - i) : R) * r' else 0 := by split_ifs with h exacts [coe_mul_of_apply_of_le _ _ _ n h, coe_mul_of_apply_of_not_le _ _ _ n h] #align direct_sum.coe_mul_of_apply DirectSum.coe_mul_of_apply
Mathlib/Algebra/DirectSum/Internal.lean
276
279
theorem coe_of_mul_apply {i : ι} (r : A i) (r' : ⨁ i, A i) (n : ι) [Decidable (i ≤ n)] : ((of (fun i => A i) i r * r') n : R) = if i ≤ n then (r * r' (n - i) : R) else 0 := by
split_ifs with h exacts [coe_of_mul_apply_of_le _ _ _ n h, coe_of_mul_apply_of_not_le _ _ _ n h]
/- Copyright (c) 2018 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import Mathlib.Order.CompleteLattice import Mathlib.Order.GaloisConnection import Mathlib.Data.Set.Lattice import Mathlib.Tactic.AdaptationNote #align_import data.rel from "leanprover-community/mathlib"@"706d88f2b8fdfeb0b22796433d7a6c1a010af9f2" /-! # Relations This file defines bundled relations. A relation between `α` and `β` is a function `α → β → Prop`. Relations are also known as set-valued functions, or partial multifunctions. ## Main declarations * `Rel α β`: Relation between `α` and `β`. * `Rel.inv`: `r.inv` is the `Rel β α` obtained by swapping the arguments of `r`. * `Rel.dom`: Domain of a relation. `x ∈ r.dom` iff there exists `y` such that `r x y`. * `Rel.codom`: Codomain, aka range, of a relation. `y ∈ r.codom` iff there exists `x` such that `r x y`. * `Rel.comp`: Relation composition. Note that the arguments order follows the `CategoryTheory/` one, so `r.comp s x z ↔ ∃ y, r x y ∧ s y z`. * `Rel.image`: Image of a set under a relation. `r.image s` is the set of `f x` over all `x ∈ s`. * `Rel.preimage`: Preimage of a set under a relation. Note that `r.preimage = r.inv.image`. * `Rel.core`: Core of a set. For `s : Set β`, `r.core s` is the set of `x : α` such that all `y` related to `x` are in `s`. * `Rel.restrict_domain`: Domain-restriction of a relation to a subtype. * `Function.graph`: Graph of a function as a relation. ## TODOs The `Rel.comp` function uses the notation `r • s`, rather than the more common `r ∘ s` for things named `comp`. This is because the latter is already used for function composition, and causes a clash. A better notation should be found, perhaps a variant of `r ∘r s` or `r; s`. -/ variable {α β γ : Type*} /-- A relation on `α` and `β`, aka a set-valued function, aka a partial multifunction -/ def Rel (α β : Type*) := α → β → Prop -- deriving CompleteLattice, Inhabited #align rel Rel -- Porting note: `deriving` above doesn't work. instance : CompleteLattice (Rel α β) := show CompleteLattice (α → β → Prop) from inferInstance instance : Inhabited (Rel α β) := show Inhabited (α → β → Prop) from inferInstance namespace Rel variable (r : Rel α β) -- Porting note: required for later theorems. @[ext] theorem ext {r s : Rel α β} : (∀ a, r a = s a) → r = s := funext /-- The inverse relation : `r.inv x y ↔ r y x`. Note that this is *not* a groupoid inverse. -/ def inv : Rel β α := flip r #align rel.inv Rel.inv theorem inv_def (x : α) (y : β) : r.inv y x ↔ r x y := Iff.rfl #align rel.inv_def Rel.inv_def theorem inv_inv : inv (inv r) = r := by ext x y rfl #align rel.inv_inv Rel.inv_inv /-- Domain of a relation -/ def dom := { x | ∃ y, r x y } #align rel.dom Rel.dom theorem dom_mono {r s : Rel α β} (h : r ≤ s) : dom r ⊆ dom s := fun a ⟨b, hx⟩ => ⟨b, h a b hx⟩ #align rel.dom_mono Rel.dom_mono /-- Codomain aka range of a relation -/ def codom := { y | ∃ x, r x y } #align rel.codom Rel.codom theorem codom_inv : r.inv.codom = r.dom := by ext x rfl #align rel.codom_inv Rel.codom_inv theorem dom_inv : r.inv.dom = r.codom := by ext x rfl #align rel.dom_inv Rel.dom_inv /-- Composition of relation; note that it follows the `CategoryTheory/` order of arguments. -/ def comp (r : Rel α β) (s : Rel β γ) : Rel α γ := fun x z => ∃ y, r x y ∧ s y z #align rel.comp Rel.comp -- Porting note: the original `∘` syntax can't be overloaded here, lean considers it ambiguous. /-- Local syntax for composition of relations. -/ local infixr:90 " • " => Rel.comp theorem comp_assoc {δ : Type*} (r : Rel α β) (s : Rel β γ) (t : Rel γ δ) : (r • s) • t = r • (s • t) := by unfold comp; ext (x w); constructor · rintro ⟨z, ⟨y, rxy, syz⟩, tzw⟩; exact ⟨y, rxy, z, syz, tzw⟩ · rintro ⟨y, rxy, z, syz, tzw⟩; exact ⟨z, ⟨y, rxy, syz⟩, tzw⟩ #align rel.comp_assoc Rel.comp_assoc @[simp] theorem comp_right_id (r : Rel α β) : r • @Eq β = r := by unfold comp ext y simp #align rel.comp_right_id Rel.comp_right_id @[simp] theorem comp_left_id (r : Rel α β) : @Eq α • r = r := by unfold comp ext x simp #align rel.comp_left_id Rel.comp_left_id @[simp] theorem comp_right_bot (r : Rel α β) : r • (⊥ : Rel β γ) = ⊥ := by ext x y simp [comp, Bot.bot] @[simp] theorem comp_left_bot (r : Rel α β) : (⊥ : Rel γ α) • r = ⊥ := by ext x y simp [comp, Bot.bot] @[simp] theorem comp_right_top (r : Rel α β) : r • (⊤ : Rel β γ) = fun x _ ↦ x ∈ r.dom := by ext x z simp [comp, Top.top, dom] @[simp] theorem comp_left_top (r : Rel α β) : (⊤ : Rel γ α) • r = fun _ y ↦ y ∈ r.codom := by ext x z simp [comp, Top.top, codom] theorem inv_id : inv (@Eq α) = @Eq α := by ext x y constructor <;> apply Eq.symm #align rel.inv_id Rel.inv_id theorem inv_comp (r : Rel α β) (s : Rel β γ) : inv (r • s) = inv s • inv r := by ext x z simp [comp, inv, flip, and_comm] #align rel.inv_comp Rel.inv_comp @[simp] theorem inv_bot : (⊥ : Rel α β).inv = (⊥ : Rel β α) := by #adaptation_note /-- nightly-2024-03-16: simp was `simp [Bot.bot, inv, flip]` -/ simp [Bot.bot, inv, Function.flip_def] @[simp] theorem inv_top : (⊤ : Rel α β).inv = (⊤ : Rel β α) := by #adaptation_note /-- nightly-2024-03-16: simp was `simp [Top.top, inv, flip]` -/ simp [Top.top, inv, Function.flip_def] /-- Image of a set under a relation -/ def image (s : Set α) : Set β := { y | ∃ x ∈ s, r x y } #align rel.image Rel.image theorem mem_image (y : β) (s : Set α) : y ∈ image r s ↔ ∃ x ∈ s, r x y := Iff.rfl #align rel.mem_image Rel.mem_image theorem image_subset : ((· ⊆ ·) ⇒ (· ⊆ ·)) r.image r.image := fun _ _ h _ ⟨x, xs, rxy⟩ => ⟨x, h xs, rxy⟩ #align rel.image_subset Rel.image_subset theorem image_mono : Monotone r.image := r.image_subset #align rel.image_mono Rel.image_mono theorem image_inter (s t : Set α) : r.image (s ∩ t) ⊆ r.image s ∩ r.image t := r.image_mono.map_inf_le s t #align rel.image_inter Rel.image_inter theorem image_union (s t : Set α) : r.image (s ∪ t) = r.image s ∪ r.image t := le_antisymm (fun _y ⟨x, xst, rxy⟩ => xst.elim (fun xs => Or.inl ⟨x, ⟨xs, rxy⟩⟩) fun xt => Or.inr ⟨x, ⟨xt, rxy⟩⟩) (r.image_mono.le_map_sup s t) #align rel.image_union Rel.image_union @[simp] theorem image_id (s : Set α) : image (@Eq α) s = s := by ext x simp [mem_image] #align rel.image_id Rel.image_id theorem image_comp (s : Rel β γ) (t : Set α) : image (r • s) t = image s (image r t) := by ext z; simp only [mem_image]; constructor · rintro ⟨x, xt, y, rxy, syz⟩; exact ⟨y, ⟨x, xt, rxy⟩, syz⟩ · rintro ⟨y, ⟨x, xt, rxy⟩, syz⟩; exact ⟨x, xt, y, rxy, syz⟩ #align rel.image_comp Rel.image_comp theorem image_univ : r.image Set.univ = r.codom := by ext y simp [mem_image, codom] #align rel.image_univ Rel.image_univ @[simp]
Mathlib/Data/Rel.lean
210
212
theorem image_empty : r.image ∅ = ∅ := by
ext x simp [mem_image]
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.MeasureTheory.Constructions.Prod.Basic import Mathlib.MeasureTheory.Integral.DominatedConvergence import Mathlib.MeasureTheory.Integral.SetIntegral #align_import measure_theory.constructions.prod.integral from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844" /-! # Integration with respect to the product measure In this file we prove Fubini's theorem. ## Main results * `MeasureTheory.integrable_prod_iff` states that a binary function is integrable iff both * `y ↦ f (x, y)` is integrable for almost every `x`, and * the function `x ↦ ∫ ‖f (x, y)‖ dy` is integrable. * `MeasureTheory.integral_prod`: Fubini's theorem. It states that for an integrable function `α × β → E` (where `E` is a second countable Banach space) we have `∫ z, f z ∂(μ.prod ν) = ∫ x, ∫ y, f (x, y) ∂ν ∂μ`. This theorem has the same variants as Tonelli's theorem (see `MeasureTheory.lintegral_prod`). The lemma `MeasureTheory.Integrable.integral_prod_right` states that the inner integral of the right-hand side is integrable. * `MeasureTheory.integral_integral_swap_of_hasCompactSupport`: a version of Fubini theorem for continuous functions with compact support, which does not assume that the measures are σ-finite contrary to all the usual versions of Fubini. ## Tags product measure, Fubini's theorem, Fubini-Tonelli theorem -/ noncomputable section open scoped Classical Topology ENNReal MeasureTheory open Set Function Real ENNReal open MeasureTheory MeasurableSpace MeasureTheory.Measure open TopologicalSpace open Filter hiding prod_eq map variable {α α' β β' γ E : Type*} variable [MeasurableSpace α] [MeasurableSpace α'] [MeasurableSpace β] [MeasurableSpace β'] variable [MeasurableSpace γ] variable {μ μ' : Measure α} {ν ν' : Measure β} {τ : Measure γ} variable [NormedAddCommGroup E] /-! ### Measurability Before we define the product measure, we can talk about the measurability of operations on binary functions. We show that if `f` is a binary measurable function, then the function that integrates along one of the variables (using either the Lebesgue or Bochner integral) is measurable. -/ theorem measurableSet_integrable [SigmaFinite ν] ⦃f : α → β → E⦄ (hf : StronglyMeasurable (uncurry f)) : MeasurableSet {x | Integrable (f x) ν} := by simp_rw [Integrable, hf.of_uncurry_left.aestronglyMeasurable, true_and_iff] exact measurableSet_lt (Measurable.lintegral_prod_right hf.ennnorm) measurable_const #align measurable_set_integrable measurableSet_integrable section variable [NormedSpace ℝ E] /-- The Bochner integral is measurable. This shows that the integrand of (the right-hand-side of) Fubini's theorem is measurable. This version has `f` in curried form. -/ theorem MeasureTheory.StronglyMeasurable.integral_prod_right [SigmaFinite ν] ⦃f : α → β → E⦄ (hf : StronglyMeasurable (uncurry f)) : StronglyMeasurable fun x => ∫ y, f x y ∂ν := by by_cases hE : CompleteSpace E; swap; · simp [integral, hE, stronglyMeasurable_const] borelize E haveI : SeparableSpace (range (uncurry f) ∪ {0} : Set E) := hf.separableSpace_range_union_singleton let s : ℕ → SimpleFunc (α × β) E := SimpleFunc.approxOn _ hf.measurable (range (uncurry f) ∪ {0}) 0 (by simp) let s' : ℕ → α → SimpleFunc β E := fun n x => (s n).comp (Prod.mk x) measurable_prod_mk_left let f' : ℕ → α → E := fun n => {x | Integrable (f x) ν}.indicator fun x => (s' n x).integral ν have hf' : ∀ n, StronglyMeasurable (f' n) := by intro n; refine StronglyMeasurable.indicator ?_ (measurableSet_integrable hf) have : ∀ x, ((s' n x).range.filter fun x => x ≠ 0) ⊆ (s n).range := by intro x; refine Finset.Subset.trans (Finset.filter_subset _ _) ?_; intro y simp_rw [SimpleFunc.mem_range]; rintro ⟨z, rfl⟩; exact ⟨(x, z), rfl⟩ simp only [SimpleFunc.integral_eq_sum_of_subset (this _)] refine Finset.stronglyMeasurable_sum _ fun x _ => ?_ refine (Measurable.ennreal_toReal ?_).stronglyMeasurable.smul_const _ simp only [s', SimpleFunc.coe_comp, preimage_comp] apply measurable_measure_prod_mk_left exact (s n).measurableSet_fiber x have h2f' : Tendsto f' atTop (𝓝 fun x : α => ∫ y : β, f x y ∂ν) := by rw [tendsto_pi_nhds]; intro x by_cases hfx : Integrable (f x) ν · have (n) : Integrable (s' n x) ν := by apply (hfx.norm.add hfx.norm).mono' (s' n x).aestronglyMeasurable filter_upwards with y simp_rw [s', SimpleFunc.coe_comp]; exact SimpleFunc.norm_approxOn_zero_le _ _ (x, y) n simp only [f', hfx, SimpleFunc.integral_eq_integral _ (this _), indicator_of_mem, mem_setOf_eq] refine tendsto_integral_of_dominated_convergence (fun y => ‖f x y‖ + ‖f x y‖) (fun n => (s' n x).aestronglyMeasurable) (hfx.norm.add hfx.norm) ?_ ?_ · refine fun n => eventually_of_forall fun y => SimpleFunc.norm_approxOn_zero_le ?_ ?_ (x, y) n -- Porting note: Lean 3 solved the following two subgoals on its own · exact hf.measurable · simp · refine eventually_of_forall fun y => SimpleFunc.tendsto_approxOn ?_ ?_ ?_ -- Porting note: Lean 3 solved the following two subgoals on its own · exact hf.measurable.of_uncurry_left · simp apply subset_closure simp [-uncurry_apply_pair] · simp [f', hfx, integral_undef] exact stronglyMeasurable_of_tendsto _ hf' h2f' #align measure_theory.strongly_measurable.integral_prod_right MeasureTheory.StronglyMeasurable.integral_prod_right /-- The Bochner integral is measurable. This shows that the integrand of (the right-hand-side of) Fubini's theorem is measurable. -/
Mathlib/MeasureTheory/Constructions/Prod/Integral.lean
127
129
theorem MeasureTheory.StronglyMeasurable.integral_prod_right' [SigmaFinite ν] ⦃f : α × β → E⦄ (hf : StronglyMeasurable f) : StronglyMeasurable fun x => ∫ y, f (x, y) ∂ν := by
rw [← uncurry_curry f] at hf; exact hf.integral_prod_right
/- 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]
Mathlib/Analysis/NormedSpace/AddTorsor.lean
193
195
theorem dist_right_midpoint (p₁ p₂ : P) : dist p₂ (midpoint 𝕜 p₁ p₂) = ‖(2 : 𝕜)‖⁻¹ * dist p₁ p₂ := by
rw [dist_comm, dist_midpoint_right]
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Group.Subgroup.MulOpposite import Mathlib.Algebra.Group.Submonoid.Pointwise import Mathlib.GroupTheory.GroupAction.ConjAct #align_import group_theory.subgroup.pointwise from "leanprover-community/mathlib"@"e655e4ea5c6d02854696f97494997ba4c31be802" /-! # Pointwise instances on `Subgroup` and `AddSubgroup`s This file provides the actions * `Subgroup.pointwiseMulAction` * `AddSubgroup.pointwiseMulAction` which matches the action of `Set.mulActionSet`. These actions are available in the `Pointwise` locale. ## Implementation notes The pointwise section of this file is almost identical to the file `Mathlib.Algebra.Group.Submonoid.Pointwise`. Where possible, try to keep them in sync. -/ open Set open Pointwise variable {α G A S : Type*} @[to_additive (attr := simp, norm_cast)] theorem inv_coe_set [InvolutiveInv G] [SetLike S G] [InvMemClass S G] {H : S} : (H : Set G)⁻¹ = H := Set.ext fun _ => inv_mem_iff #align inv_coe_set inv_coe_set #align neg_coe_set neg_coe_set @[to_additive (attr := simp)] lemma smul_coe_set [Group G] [SetLike S G] [SubgroupClass S G] {s : S} {a : G} (ha : a ∈ s) : a • (s : Set G) = s := by ext; simp [Set.mem_smul_set_iff_inv_smul_mem, mul_mem_cancel_left, ha] @[to_additive (attr := simp)] lemma op_smul_coe_set [Group G] [SetLike S G] [SubgroupClass S G] {s : S} {a : G} (ha : a ∈ s) : MulOpposite.op a • (s : Set G) = s := by ext; simp [Set.mem_smul_set_iff_inv_smul_mem, mul_mem_cancel_right, ha] @[to_additive (attr := simp, norm_cast)] lemma coe_mul_coe [SetLike S G] [DivInvMonoid G] [SubgroupClass S G] (H : S) : H * H = (H : Set G) := by aesop (add simp mem_mul) @[to_additive (attr := simp, norm_cast)] lemma coe_div_coe [SetLike S G] [DivisionMonoid G] [SubgroupClass S G] (H : S) : H / H = (H : Set G) := by simp [div_eq_mul_inv] variable [Group G] [AddGroup A] {s : Set G} namespace Subgroup @[to_additive (attr := simp)] theorem inv_subset_closure (S : Set G) : S⁻¹ ⊆ closure S := fun s hs => by rw [SetLike.mem_coe, ← Subgroup.inv_mem_iff] exact subset_closure (mem_inv.mp hs) #align subgroup.inv_subset_closure Subgroup.inv_subset_closure #align add_subgroup.neg_subset_closure AddSubgroup.neg_subset_closure @[to_additive] theorem closure_toSubmonoid (S : Set G) : (closure S).toSubmonoid = Submonoid.closure (S ∪ S⁻¹) := by refine le_antisymm (fun x hx => ?_) (Submonoid.closure_le.2 ?_) · refine closure_induction hx (fun x hx => Submonoid.closure_mono subset_union_left (Submonoid.subset_closure hx)) (Submonoid.one_mem _) (fun x y hx hy => Submonoid.mul_mem _ hx hy) fun x hx => ?_ rwa [← Submonoid.mem_closure_inv, Set.union_inv, inv_inv, Set.union_comm] · simp only [true_and_iff, coe_toSubmonoid, union_subset_iff, subset_closure, inv_subset_closure] #align subgroup.closure_to_submonoid Subgroup.closure_toSubmonoid #align add_subgroup.closure_to_add_submonoid AddSubgroup.closure_toAddSubmonoid /-- For subgroups generated by a single element, see the simpler `zpow_induction_left`. -/ @[to_additive (attr := elab_as_elim) "For additive subgroups generated by a single element, see the simpler `zsmul_induction_left`."] theorem closure_induction_left {p : (x : G) → x ∈ closure s → Prop} (one : p 1 (one_mem _)) (mul_left : ∀ x (hx : x ∈ s), ∀ (y) hy, p y hy → p (x * y) (mul_mem (subset_closure hx) hy)) (mul_left_inv : ∀ x (hx : x ∈ s), ∀ (y) hy, p y hy → p (x⁻¹ * y) (mul_mem (inv_mem (subset_closure hx)) hy)) {x : G} (h : x ∈ closure s) : p x h := by revert h simp_rw [← mem_toSubmonoid, closure_toSubmonoid] at * intro h induction h using Submonoid.closure_induction_left with | one => exact one | mul_left x hx y hy ih => cases hx with | inl hx => exact mul_left _ hx _ hy ih | inr hx => simpa only [inv_inv] using mul_left_inv _ hx _ hy ih #align subgroup.closure_induction_left Subgroup.closure_induction_left #align add_subgroup.closure_induction_left AddSubgroup.closure_induction_left /-- For subgroups generated by a single element, see the simpler `zpow_induction_right`. -/ @[to_additive (attr := elab_as_elim) "For additive subgroups generated by a single element, see the simpler `zsmul_induction_right`."] theorem closure_induction_right {p : (x : G) → x ∈ closure s → Prop} (one : p 1 (one_mem _)) (mul_right : ∀ (x) hx, ∀ y (hy : y ∈ s), p x hx → p (x * y) (mul_mem hx (subset_closure hy))) (mul_right_inv : ∀ (x) hx, ∀ y (hy : y ∈ s), p x hx → p (x * y⁻¹) (mul_mem hx (inv_mem (subset_closure hy)))) {x : G} (h : x ∈ closure s) : p x h := closure_induction_left (s := MulOpposite.unop ⁻¹' s) (p := fun m hm => p m.unop <| by rwa [← op_closure] at hm) one (fun _x hx _y hy => mul_right _ _ _ hx) (fun _x hx _y hy => mul_right_inv _ _ _ hx) (by rwa [← op_closure]) #align subgroup.closure_induction_right Subgroup.closure_induction_right #align add_subgroup.closure_induction_right AddSubgroup.closure_induction_right @[to_additive (attr := simp)] theorem closure_inv (s : Set G) : closure s⁻¹ = closure s := by simp only [← toSubmonoid_eq, closure_toSubmonoid, inv_inv, union_comm] #align subgroup.closure_inv Subgroup.closure_inv #align add_subgroup.closure_neg AddSubgroup.closure_neg /-- An induction principle for closure membership. If `p` holds for `1` and all elements of `k` and their inverse, and is preserved under multiplication, 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 their negation, and is preserved under addition, then `p` holds for all elements of the additive closure of `k`."] theorem closure_induction'' {p : (g : G) → g ∈ closure s → Prop} (mem : ∀ x (hx : x ∈ s), p x (subset_closure hx)) (inv_mem : ∀ x (hx : x ∈ s), p x⁻¹ (inv_mem (subset_closure hx))) (one : p 1 (one_mem _)) (mul : ∀ x y hx hy, p x hx → p y hy → p (x * y) (mul_mem hx hy)) {x} (h : x ∈ closure s) : p x h := closure_induction_left one (fun x hx y _ hy => mul x y _ _ (mem x hx) hy) (fun x hx y _ => mul x⁻¹ y _ _ <| inv_mem x hx) h #align subgroup.closure_induction'' Subgroup.closure_induction'' #align add_subgroup.closure_induction'' AddSubgroup.closure_induction'' /-- An induction principle for elements of `⨆ i, S i`. If `C` holds for `1` and all elements of `S i` for all `i`, and is preserved under multiplication, then it holds for all elements of the supremum of `S`. -/ @[to_additive (attr := elab_as_elim) " An induction principle for elements of `⨆ i, S i`. If `C` holds for `0` and all elements of `S i` for all `i`, and is preserved under addition, then it holds for all elements of the supremum of `S`. "] theorem iSup_induction {ι : Sort*} (S : ι → Subgroup G) {C : G → Prop} {x : G} (hx : x ∈ ⨆ i, S i) (mem : ∀ (i), ∀ x ∈ S i, C x) (one : C 1) (mul : ∀ x y, C x → C y → C (x * y)) : C x := by rw [iSup_eq_closure] at hx induction hx using closure_induction'' with | one => exact one | mem x hx => obtain ⟨i, hi⟩ := Set.mem_iUnion.mp hx exact mem _ _ hi | inv_mem x hx => obtain ⟨i, hi⟩ := Set.mem_iUnion.mp hx exact mem _ _ (inv_mem hi) | mul x y _ _ ihx ihy => exact mul x y ihx ihy #align subgroup.supr_induction Subgroup.iSup_induction #align add_subgroup.supr_induction AddSubgroup.iSup_induction /-- A dependent version of `Subgroup.iSup_induction`. -/ @[to_additive (attr := elab_as_elim) "A dependent version of `AddSubgroup.iSup_induction`. "]
Mathlib/Algebra/Group/Subgroup/Pointwise.lean
171
180
theorem iSup_induction' {ι : Sort*} (S : ι → Subgroup G) {C : ∀ x, (x ∈ ⨆ i, S i) → Prop} (hp : ∀ (i), ∀ x (hx : x ∈ S i), C x (mem_iSup_of_mem i hx)) (h1 : C 1 (one_mem _)) (hmul : ∀ x y hx hy, C x hx → C y hy → C (x * y) (mul_mem ‹_› ‹_›)) {x : G} (hx : x ∈ ⨆ i, S i) : C x hx := by
suffices ∃ h, C x h from this.snd refine iSup_induction S (C := fun x => ∃ h, C x h) hx (fun i x hx => ?_) ?_ fun x y => ?_ · exact ⟨_, hp i _ hx⟩ · exact ⟨_, h1⟩ · rintro ⟨_, Cx⟩ ⟨_, Cy⟩ exact ⟨_, hmul _ _ _ _ Cx Cy⟩
/- 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.Algebra.Polynomial.Taylor import Mathlib.FieldTheory.RatFunc.AsPolynomial #align_import field_theory.laurent from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a" /-! # Laurent expansions of rational functions ## Main declarations * `RatFunc.laurent`: the Laurent expansion of the rational function `f` at `r`, as an `AlgHom`. * `RatFunc.laurent_injective`: the Laurent expansion at `r` is unique ## Implementation details Implemented as the quotient of two Taylor expansions, over domains. An auxiliary definition is provided first to make the construction of the `AlgHom` easier, which works on `CommRing` which are not necessarily domains. -/ universe u namespace RatFunc noncomputable section open Polynomial open scoped Classical nonZeroDivisors Polynomial variable {R : Type u} [CommRing R] [hdomain : IsDomain R] (r s : R) (p q : R[X]) (f : RatFunc R) theorem taylor_mem_nonZeroDivisors (hp : p ∈ R[X]⁰) : taylor r p ∈ R[X]⁰ := by rw [mem_nonZeroDivisors_iff] intro x hx have : x = taylor (r - r) x := by simp rwa [this, sub_eq_add_neg, ← taylor_taylor, ← taylor_mul, LinearMap.map_eq_zero_iff _ (taylor_injective _), mul_right_mem_nonZeroDivisors_eq_zero_iff hp, LinearMap.map_eq_zero_iff _ (taylor_injective _)] at hx #align ratfunc.taylor_mem_non_zero_divisors RatFunc.taylor_mem_nonZeroDivisors /-- The Laurent expansion of rational functions about a value. Auxiliary definition, usage when over integral domains should prefer `RatFunc.laurent`. -/ def laurentAux : RatFunc R →+* RatFunc R := RatFunc.mapRingHom ( { toFun := taylor r map_add' := map_add (taylor r) map_mul' := taylor_mul _ map_zero' := map_zero (taylor r) map_one' := taylor_one r } : R[X] →+* R[X]) (taylor_mem_nonZeroDivisors _) #align ratfunc.laurent_aux RatFunc.laurentAux theorem laurentAux_ofFractionRing_mk (q : R[X]⁰) : laurentAux r (ofFractionRing (Localization.mk p q)) = ofFractionRing (.mk (taylor r p) ⟨taylor r q, taylor_mem_nonZeroDivisors r q q.prop⟩) := map_apply_ofFractionRing_mk _ _ _ _ #align ratfunc.laurent_aux_of_fraction_ring_mk RatFunc.laurentAux_ofFractionRing_mk theorem laurentAux_div : laurentAux r (algebraMap _ _ p / algebraMap _ _ q) = algebraMap _ _ (taylor r p) / algebraMap _ _ (taylor r q) := -- Porting note: added `by exact taylor_mem_nonZeroDivisors r` map_apply_div _ (by exact taylor_mem_nonZeroDivisors r) _ _ #align ratfunc.laurent_aux_div RatFunc.laurentAux_div @[simp]
Mathlib/FieldTheory/Laurent.lean
74
75
theorem laurentAux_algebraMap : laurentAux r (algebraMap _ _ p) = algebraMap _ _ (taylor r p) := by
rw [← mk_one, ← mk_one, mk_eq_div, laurentAux_div, mk_eq_div, taylor_one, map_one, map_one]
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Mathlib.Data.Stream.Defs import Mathlib.Logic.Function.Basic import Mathlib.Init.Data.List.Basic import Mathlib.Data.List.Basic #align_import data.stream.init from "leanprover-community/mathlib"@"207cfac9fcd06138865b5d04f7091e46d9320432" /-! # Streams a.k.a. infinite lists a.k.a. infinite sequences Porting note: This file used to be in the core library. It was moved to `mathlib` and renamed to `init` to avoid name clashes. -/ set_option autoImplicit true open Nat Function Option namespace Stream' variable {α : Type u} {β : Type v} {δ : Type w} instance [Inhabited α] : Inhabited (Stream' α) := ⟨Stream'.const default⟩ protected theorem eta (s : Stream' α) : (head s::tail s) = s := funext fun i => by cases i <;> rfl #align stream.eta Stream'.eta @[ext] protected theorem ext {s₁ s₂ : Stream' α} : (∀ n, get s₁ n = get s₂ n) → s₁ = s₂ := fun h => funext h #align stream.ext Stream'.ext @[simp] theorem get_zero_cons (a : α) (s : Stream' α) : get (a::s) 0 = a := rfl #align stream.nth_zero_cons Stream'.get_zero_cons @[simp] theorem head_cons (a : α) (s : Stream' α) : head (a::s) = a := rfl #align stream.head_cons Stream'.head_cons @[simp] theorem tail_cons (a : α) (s : Stream' α) : tail (a::s) = s := rfl #align stream.tail_cons Stream'.tail_cons @[simp] theorem get_drop (n m : Nat) (s : Stream' α) : get (drop m s) n = get s (n + m) := rfl #align stream.nth_drop Stream'.get_drop theorem tail_eq_drop (s : Stream' α) : tail s = drop 1 s := rfl #align stream.tail_eq_drop Stream'.tail_eq_drop @[simp] theorem drop_drop (n m : Nat) (s : Stream' α) : drop n (drop m s) = drop (n + m) s := by ext; simp [Nat.add_assoc] #align stream.drop_drop Stream'.drop_drop @[simp] theorem get_tail {s : Stream' α} : s.tail.get n = s.get (n + 1) := rfl @[simp] theorem tail_drop' {s : Stream' α} : tail (drop i s) = s.drop (i+1) := by ext; simp [Nat.add_comm, Nat.add_assoc, Nat.add_left_comm] @[simp] theorem drop_tail' {s : Stream' α} : drop i (tail s) = s.drop (i+1) := rfl theorem tail_drop (n : Nat) (s : Stream' α) : tail (drop n s) = drop n (tail s) := by simp #align stream.tail_drop Stream'.tail_drop theorem get_succ (n : Nat) (s : Stream' α) : get s (succ n) = get (tail s) n := rfl #align stream.nth_succ Stream'.get_succ @[simp] theorem get_succ_cons (n : Nat) (s : Stream' α) (x : α) : get (x::s) n.succ = get s n := rfl #align stream.nth_succ_cons Stream'.get_succ_cons @[simp] theorem drop_zero {s : Stream' α} : s.drop 0 = s := rfl theorem drop_succ (n : Nat) (s : Stream' α) : drop (succ n) s = drop n (tail s) := rfl #align stream.drop_succ Stream'.drop_succ theorem head_drop (a : Stream' α) (n : ℕ) : (a.drop n).head = a.get n := by simp #align stream.head_drop Stream'.head_drop theorem cons_injective2 : Function.Injective2 (cons : α → Stream' α → Stream' α) := fun x y s t h => ⟨by rw [← get_zero_cons x s, h, get_zero_cons], Stream'.ext fun n => by rw [← get_succ_cons n _ x, h, get_succ_cons]⟩ #align stream.cons_injective2 Stream'.cons_injective2 theorem cons_injective_left (s : Stream' α) : Function.Injective fun x => cons x s := cons_injective2.left _ #align stream.cons_injective_left Stream'.cons_injective_left theorem cons_injective_right (x : α) : Function.Injective (cons x) := cons_injective2.right _ #align stream.cons_injective_right Stream'.cons_injective_right theorem all_def (p : α → Prop) (s : Stream' α) : All p s = ∀ n, p (get s n) := rfl #align stream.all_def Stream'.all_def theorem any_def (p : α → Prop) (s : Stream' α) : Any p s = ∃ n, p (get s n) := rfl #align stream.any_def Stream'.any_def @[simp] theorem mem_cons (a : α) (s : Stream' α) : a ∈ a::s := Exists.intro 0 rfl #align stream.mem_cons Stream'.mem_cons theorem mem_cons_of_mem {a : α} {s : Stream' α} (b : α) : a ∈ s → a ∈ b::s := fun ⟨n, h⟩ => Exists.intro (succ n) (by rw [get_succ, tail_cons, h]) #align stream.mem_cons_of_mem Stream'.mem_cons_of_mem theorem eq_or_mem_of_mem_cons {a b : α} {s : Stream' α} : (a ∈ b::s) → a = b ∨ a ∈ s := fun ⟨n, h⟩ => by cases' n with n' · left exact h · right rw [get_succ, tail_cons] at h exact ⟨n', h⟩ #align stream.eq_or_mem_of_mem_cons Stream'.eq_or_mem_of_mem_cons theorem mem_of_get_eq {n : Nat} {s : Stream' α} {a : α} : a = get s n → a ∈ s := fun h => Exists.intro n h #align stream.mem_of_nth_eq Stream'.mem_of_get_eq section Map variable (f : α → β) theorem drop_map (n : Nat) (s : Stream' α) : drop n (map f s) = map f (drop n s) := Stream'.ext fun _ => rfl #align stream.drop_map Stream'.drop_map @[simp] theorem get_map (n : Nat) (s : Stream' α) : get (map f s) n = f (get s n) := rfl #align stream.nth_map Stream'.get_map theorem tail_map (s : Stream' α) : tail (map f s) = map f (tail s) := rfl #align stream.tail_map Stream'.tail_map @[simp] theorem head_map (s : Stream' α) : head (map f s) = f (head s) := rfl #align stream.head_map Stream'.head_map theorem map_eq (s : Stream' α) : map f s = f (head s)::map f (tail s) := by rw [← Stream'.eta (map f s), tail_map, head_map] #align stream.map_eq Stream'.map_eq theorem map_cons (a : α) (s : Stream' α) : map f (a::s) = f a::map f s := by rw [← Stream'.eta (map f (a::s)), map_eq]; rfl #align stream.map_cons Stream'.map_cons @[simp] theorem map_id (s : Stream' α) : map id s = s := rfl #align stream.map_id Stream'.map_id @[simp] theorem map_map (g : β → δ) (f : α → β) (s : Stream' α) : map g (map f s) = map (g ∘ f) s := rfl #align stream.map_map Stream'.map_map @[simp] theorem map_tail (s : Stream' α) : map f (tail s) = tail (map f s) := rfl #align stream.map_tail Stream'.map_tail theorem mem_map {a : α} {s : Stream' α} : a ∈ s → f a ∈ map f s := fun ⟨n, h⟩ => Exists.intro n (by rw [get_map, h]) #align stream.mem_map Stream'.mem_map theorem exists_of_mem_map {f} {b : β} {s : Stream' α} : b ∈ map f s → ∃ a, a ∈ s ∧ f a = b := fun ⟨n, h⟩ => ⟨get s n, ⟨n, rfl⟩, h.symm⟩ #align stream.exists_of_mem_map Stream'.exists_of_mem_map end Map section Zip variable (f : α → β → δ) theorem drop_zip (n : Nat) (s₁ : Stream' α) (s₂ : Stream' β) : drop n (zip f s₁ s₂) = zip f (drop n s₁) (drop n s₂) := Stream'.ext fun _ => rfl #align stream.drop_zip Stream'.drop_zip @[simp] theorem get_zip (n : Nat) (s₁ : Stream' α) (s₂ : Stream' β) : get (zip f s₁ s₂) n = f (get s₁ n) (get s₂ n) := rfl #align stream.nth_zip Stream'.get_zip theorem head_zip (s₁ : Stream' α) (s₂ : Stream' β) : head (zip f s₁ s₂) = f (head s₁) (head s₂) := rfl #align stream.head_zip Stream'.head_zip theorem tail_zip (s₁ : Stream' α) (s₂ : Stream' β) : tail (zip f s₁ s₂) = zip f (tail s₁) (tail s₂) := rfl #align stream.tail_zip Stream'.tail_zip theorem zip_eq (s₁ : Stream' α) (s₂ : Stream' β) : zip f s₁ s₂ = f (head s₁) (head s₂)::zip f (tail s₁) (tail s₂) := by rw [← Stream'.eta (zip f s₁ s₂)]; rfl #align stream.zip_eq Stream'.zip_eq @[simp] theorem get_enum (s : Stream' α) (n : ℕ) : get (enum s) n = (n, s.get n) := rfl #align stream.nth_enum Stream'.get_enum theorem enum_eq_zip (s : Stream' α) : enum s = zip Prod.mk nats s := rfl #align stream.enum_eq_zip Stream'.enum_eq_zip end Zip @[simp] theorem mem_const (a : α) : a ∈ const a := Exists.intro 0 rfl #align stream.mem_const Stream'.mem_const theorem const_eq (a : α) : const a = a::const a := by apply Stream'.ext; intro n cases n <;> rfl #align stream.const_eq Stream'.const_eq @[simp] theorem tail_const (a : α) : tail (const a) = const a := suffices tail (a::const a) = const a by rwa [← const_eq] at this rfl #align stream.tail_const Stream'.tail_const @[simp] theorem map_const (f : α → β) (a : α) : map f (const a) = const (f a) := rfl #align stream.map_const Stream'.map_const @[simp] theorem get_const (n : Nat) (a : α) : get (const a) n = a := rfl #align stream.nth_const Stream'.get_const @[simp] theorem drop_const (n : Nat) (a : α) : drop n (const a) = const a := Stream'.ext fun _ => rfl #align stream.drop_const Stream'.drop_const @[simp] theorem head_iterate (f : α → α) (a : α) : head (iterate f a) = a := rfl #align stream.head_iterate Stream'.head_iterate theorem get_succ_iterate' (n : Nat) (f : α → α) (a : α) : get (iterate f a) (succ n) = f (get (iterate f a) n) := rfl theorem tail_iterate (f : α → α) (a : α) : tail (iterate f a) = iterate f (f a) := by ext n rw [get_tail] induction' n with n' ih · rfl · rw [get_succ_iterate', ih, get_succ_iterate'] #align stream.tail_iterate Stream'.tail_iterate theorem iterate_eq (f : α → α) (a : α) : iterate f a = a::iterate f (f a) := by rw [← Stream'.eta (iterate f a)] rw [tail_iterate]; rfl #align stream.iterate_eq Stream'.iterate_eq @[simp] theorem get_zero_iterate (f : α → α) (a : α) : get (iterate f a) 0 = a := rfl #align stream.nth_zero_iterate Stream'.get_zero_iterate theorem get_succ_iterate (n : Nat) (f : α → α) (a : α) : get (iterate f a) (succ n) = get (iterate f (f a)) n := by rw [get_succ, tail_iterate] #align stream.nth_succ_iterate Stream'.get_succ_iterate section Bisim variable (R : Stream' α → Stream' α → Prop) /-- equivalence relation -/ local infixl:50 " ~ " => R /-- Streams `s₁` and `s₂` are defined to be bisimulations if their heads are equal and tails are bisimulations. -/ def IsBisimulation := ∀ ⦃s₁ s₂⦄, s₁ ~ s₂ → head s₁ = head s₂ ∧ tail s₁ ~ tail s₂ #align stream.is_bisimulation Stream'.IsBisimulation theorem get_of_bisim (bisim : IsBisimulation R) : ∀ {s₁ s₂} (n), s₁ ~ s₂ → get s₁ n = get s₂ n ∧ drop (n + 1) s₁ ~ drop (n + 1) s₂ | _, _, 0, h => bisim h | _, _, n + 1, h => match bisim h with | ⟨_, trel⟩ => get_of_bisim bisim n trel #align stream.nth_of_bisim Stream'.get_of_bisim -- If two streams are bisimilar, then they are equal theorem eq_of_bisim (bisim : IsBisimulation R) : ∀ {s₁ s₂}, s₁ ~ s₂ → s₁ = s₂ := fun r => Stream'.ext fun n => And.left (get_of_bisim R bisim n r) #align stream.eq_of_bisim Stream'.eq_of_bisim end Bisim theorem bisim_simple (s₁ s₂ : Stream' α) : head s₁ = head s₂ → s₁ = tail s₁ → s₂ = tail s₂ → s₁ = s₂ := fun hh ht₁ ht₂ => eq_of_bisim (fun s₁ s₂ => head s₁ = head s₂ ∧ s₁ = tail s₁ ∧ s₂ = tail s₂) (fun s₁ s₂ ⟨h₁, h₂, h₃⟩ => by constructor · exact h₁ rw [← h₂, ← h₃] (repeat' constructor) <;> assumption) (And.intro hh (And.intro ht₁ ht₂)) #align stream.bisim_simple Stream'.bisim_simple theorem coinduction {s₁ s₂ : Stream' α} : head s₁ = head s₂ → (∀ (β : Type u) (fr : Stream' α → β), fr s₁ = fr s₂ → fr (tail s₁) = fr (tail s₂)) → s₁ = s₂ := fun hh ht => eq_of_bisim (fun s₁ s₂ => head s₁ = head s₂ ∧ ∀ (β : Type u) (fr : Stream' α → β), fr s₁ = fr s₂ → fr (tail s₁) = fr (tail s₂)) (fun s₁ s₂ h => have h₁ : head s₁ = head s₂ := And.left h have h₂ : head (tail s₁) = head (tail s₂) := And.right h α (@head α) h₁ have h₃ : ∀ (β : Type u) (fr : Stream' α → β), fr (tail s₁) = fr (tail s₂) → fr (tail (tail s₁)) = fr (tail (tail s₂)) := fun β fr => And.right h β fun s => fr (tail s) And.intro h₁ (And.intro h₂ h₃)) (And.intro hh ht) #align stream.coinduction Stream'.coinduction @[simp] theorem iterate_id (a : α) : iterate id a = const a := coinduction rfl fun β fr ch => by rw [tail_iterate, tail_const]; exact ch #align stream.iterate_id Stream'.iterate_id theorem map_iterate (f : α → α) (a : α) : iterate f (f a) = map f (iterate f a) := by funext n induction' n with n' ih · rfl · unfold map iterate get rw [map, get] at ih rw [iterate] exact congrArg f ih #align stream.map_iterate Stream'.map_iterate section Corec theorem corec_def (f : α → β) (g : α → α) (a : α) : corec f g a = map f (iterate g a) := rfl #align stream.corec_def Stream'.corec_def theorem corec_eq (f : α → β) (g : α → α) (a : α) : corec f g a = f a::corec f g (g a) := by rw [corec_def, map_eq, head_iterate, tail_iterate]; rfl #align stream.corec_eq Stream'.corec_eq theorem corec_id_id_eq_const (a : α) : corec id id a = const a := by rw [corec_def, map_id, iterate_id] #align stream.corec_id_id_eq_const Stream'.corec_id_id_eq_const theorem corec_id_f_eq_iterate (f : α → α) (a : α) : corec id f a = iterate f a := rfl #align stream.corec_id_f_eq_iterate Stream'.corec_id_f_eq_iterate end Corec section Corec' theorem corec'_eq (f : α → β × α) (a : α) : corec' f a = (f a).1::corec' f (f a).2 := corec_eq _ _ _ #align stream.corec'_eq Stream'.corec'_eq end Corec' theorem unfolds_eq (g : α → β) (f : α → α) (a : α) : unfolds g f a = g a::unfolds g f (f a) := by unfold unfolds; rw [corec_eq] #align stream.unfolds_eq Stream'.unfolds_eq theorem get_unfolds_head_tail : ∀ (n : Nat) (s : Stream' α), get (unfolds head tail s) n = get s n := by intro n; induction' n with n' ih · intro s rfl · intro s rw [get_succ, get_succ, unfolds_eq, tail_cons, ih] #align stream.nth_unfolds_head_tail Stream'.get_unfolds_head_tail theorem unfolds_head_eq : ∀ s : Stream' α, unfolds head tail s = s := fun s => Stream'.ext fun n => get_unfolds_head_tail n s #align stream.unfolds_head_eq Stream'.unfolds_head_eq theorem interleave_eq (s₁ s₂ : Stream' α) : s₁ ⋈ s₂ = head s₁::head s₂::(tail s₁ ⋈ tail s₂) := by let t := tail s₁ ⋈ tail s₂ show s₁ ⋈ s₂ = head s₁::head s₂::t unfold interleave; unfold corecOn; rw [corec_eq]; dsimp; rw [corec_eq]; rfl #align stream.interleave_eq Stream'.interleave_eq theorem tail_interleave (s₁ s₂ : Stream' α) : tail (s₁ ⋈ s₂) = s₂ ⋈ tail s₁ := by unfold interleave corecOn; rw [corec_eq]; rfl #align stream.tail_interleave Stream'.tail_interleave theorem interleave_tail_tail (s₁ s₂ : Stream' α) : tail s₁ ⋈ tail s₂ = tail (tail (s₁ ⋈ s₂)) := by rw [interleave_eq s₁ s₂]; rfl #align stream.interleave_tail_tail Stream'.interleave_tail_tail theorem get_interleave_left : ∀ (n : Nat) (s₁ s₂ : Stream' α), get (s₁ ⋈ s₂) (2 * n) = get s₁ n | 0, s₁, s₂ => rfl | n + 1, s₁, s₂ => by change get (s₁ ⋈ s₂) (succ (succ (2 * n))) = get s₁ (succ n) rw [get_succ, get_succ, interleave_eq, tail_cons, tail_cons] rw [get_interleave_left n (tail s₁) (tail s₂)] rfl #align stream.nth_interleave_left Stream'.get_interleave_left theorem get_interleave_right : ∀ (n : Nat) (s₁ s₂ : Stream' α), get (s₁ ⋈ s₂) (2 * n + 1) = get s₂ n | 0, s₁, s₂ => rfl | n + 1, s₁, s₂ => by change get (s₁ ⋈ s₂) (succ (succ (2 * n + 1))) = get s₂ (succ n) rw [get_succ, get_succ, interleave_eq, tail_cons, tail_cons, get_interleave_right n (tail s₁) (tail s₂)] rfl #align stream.nth_interleave_right Stream'.get_interleave_right theorem mem_interleave_left {a : α} {s₁ : Stream' α} (s₂ : Stream' α) : a ∈ s₁ → a ∈ s₁ ⋈ s₂ := fun ⟨n, h⟩ => Exists.intro (2 * n) (by rw [h, get_interleave_left]) #align stream.mem_interleave_left Stream'.mem_interleave_left theorem mem_interleave_right {a : α} {s₁ : Stream' α} (s₂ : Stream' α) : a ∈ s₂ → a ∈ s₁ ⋈ s₂ := fun ⟨n, h⟩ => Exists.intro (2 * n + 1) (by rw [h, get_interleave_right]) #align stream.mem_interleave_right Stream'.mem_interleave_right theorem odd_eq (s : Stream' α) : odd s = even (tail s) := rfl #align stream.odd_eq Stream'.odd_eq @[simp] theorem head_even (s : Stream' α) : head (even s) = head s := rfl #align stream.head_even Stream'.head_even theorem tail_even (s : Stream' α) : tail (even s) = even (tail (tail s)) := by unfold even rw [corec_eq] rfl #align stream.tail_even Stream'.tail_even theorem even_cons_cons (a₁ a₂ : α) (s : Stream' α) : even (a₁::a₂::s) = a₁::even s := by unfold even rw [corec_eq]; rfl #align stream.even_cons_cons Stream'.even_cons_cons theorem even_tail (s : Stream' α) : even (tail s) = odd s := rfl #align stream.even_tail Stream'.even_tail theorem even_interleave (s₁ s₂ : Stream' α) : even (s₁ ⋈ s₂) = s₁ := eq_of_bisim (fun s₁' s₁ => ∃ s₂, s₁' = even (s₁ ⋈ s₂)) (fun s₁' s₁ ⟨s₂, h₁⟩ => by rw [h₁] constructor · rfl · exact ⟨tail s₂, by rw [interleave_eq, even_cons_cons, tail_cons]⟩) (Exists.intro s₂ rfl) #align stream.even_interleave Stream'.even_interleave theorem interleave_even_odd (s₁ : Stream' α) : even s₁ ⋈ odd s₁ = s₁ := eq_of_bisim (fun s' s => s' = even s ⋈ odd s) (fun s' s (h : s' = even s ⋈ odd s) => by rw [h]; constructor · rfl · simp [odd_eq, odd_eq, tail_interleave, tail_even]) rfl #align stream.interleave_even_odd Stream'.interleave_even_odd theorem get_even : ∀ (n : Nat) (s : Stream' α), get (even s) n = get s (2 * n) | 0, s => rfl | succ n, s => by change get (even s) (succ n) = get s (succ (succ (2 * n))) rw [get_succ, get_succ, tail_even, get_even n]; rfl #align stream.nth_even Stream'.get_even theorem get_odd : ∀ (n : Nat) (s : Stream' α), get (odd s) n = get s (2 * n + 1) := fun n s => by rw [odd_eq, get_even]; rfl #align stream.nth_odd Stream'.get_odd theorem mem_of_mem_even (a : α) (s : Stream' α) : a ∈ even s → a ∈ s := fun ⟨n, h⟩ => Exists.intro (2 * n) (by rw [h, get_even]) #align stream.mem_of_mem_even Stream'.mem_of_mem_even theorem mem_of_mem_odd (a : α) (s : Stream' α) : a ∈ odd s → a ∈ s := fun ⟨n, h⟩ => Exists.intro (2 * n + 1) (by rw [h, get_odd]) #align stream.mem_of_mem_odd Stream'.mem_of_mem_odd theorem nil_append_stream (s : Stream' α) : appendStream' [] s = s := rfl #align stream.nil_append_stream Stream'.nil_append_stream theorem cons_append_stream (a : α) (l : List α) (s : Stream' α) : appendStream' (a::l) s = a::appendStream' l s := rfl #align stream.cons_append_stream Stream'.cons_append_stream theorem append_append_stream : ∀ (l₁ l₂ : List α) (s : Stream' α), l₁ ++ l₂ ++ₛ s = l₁ ++ₛ (l₂ ++ₛ s) | [], l₂, s => rfl | List.cons a l₁, l₂, s => by rw [List.cons_append, cons_append_stream, cons_append_stream, append_append_stream l₁] #align stream.append_append_stream Stream'.append_append_stream theorem map_append_stream (f : α → β) : ∀ (l : List α) (s : Stream' α), map f (l ++ₛ s) = List.map f l ++ₛ map f s | [], s => rfl | List.cons a l, s => by rw [cons_append_stream, List.map_cons, map_cons, cons_append_stream, map_append_stream f l] #align stream.map_append_stream Stream'.map_append_stream theorem drop_append_stream : ∀ (l : List α) (s : Stream' α), drop l.length (l ++ₛ s) = s | [], s => by rfl | List.cons a l, s => by rw [List.length_cons, drop_succ, cons_append_stream, tail_cons, drop_append_stream l s] #align stream.drop_append_stream Stream'.drop_append_stream theorem append_stream_head_tail (s : Stream' α) : [head s] ++ₛ tail s = s := by rw [cons_append_stream, nil_append_stream, Stream'.eta] #align stream.append_stream_head_tail Stream'.append_stream_head_tail theorem mem_append_stream_right : ∀ {a : α} (l : List α) {s : Stream' α}, a ∈ s → a ∈ l ++ₛ s | _, [], _, h => h | a, List.cons _ l, s, h => have ih : a ∈ l ++ₛ s := mem_append_stream_right l h mem_cons_of_mem _ ih #align stream.mem_append_stream_right Stream'.mem_append_stream_right theorem mem_append_stream_left : ∀ {a : α} {l : List α} (s : Stream' α), a ∈ l → a ∈ l ++ₛ s | _, [], _, h => absurd h (List.not_mem_nil _) | a, List.cons b l, s, h => Or.elim (List.eq_or_mem_of_mem_cons h) (fun aeqb : a = b => Exists.intro 0 aeqb) fun ainl : a ∈ l => mem_cons_of_mem b (mem_append_stream_left s ainl) #align stream.mem_append_stream_left Stream'.mem_append_stream_left @[simp] theorem take_zero (s : Stream' α) : take 0 s = [] := rfl #align stream.take_zero Stream'.take_zero -- This lemma used to be simp, but we removed it from the simp set because: -- 1) It duplicates the (often large) `s` term, resulting in large tactic states. -- 2) It conflicts with the very useful `dropLast_take` lemma below (causing nonconfluence). theorem take_succ (n : Nat) (s : Stream' α) : take (succ n) s = head s::take n (tail s) := rfl #align stream.take_succ Stream'.take_succ @[simp] theorem take_succ_cons (n : Nat) (s : Stream' α) : take (n+1) (a::s) = a :: take n s := rfl theorem take_succ' {s : Stream' α} : ∀ n, s.take (n+1) = s.take n ++ [s.get n] | 0 => rfl | n+1 => by rw [take_succ, take_succ' n, ← List.cons_append, ← take_succ, get_tail] @[simp] theorem length_take (n : ℕ) (s : Stream' α) : (take n s).length = n := by induction n generalizing s <;> simp [*, take_succ] #align stream.length_take Stream'.length_take @[simp] theorem take_take {s : Stream' α} : ∀ {m n}, (s.take n).take m = s.take (min n m) | 0, n => by rw [Nat.min_zero, List.take_zero, take_zero] | m, 0 => by rw [Nat.zero_min, take_zero, List.take_nil] | m+1, n+1 => by rw [take_succ, List.take_cons, Nat.succ_min_succ, take_succ, take_take] @[simp] theorem concat_take_get {s : Stream' α} : s.take n ++ [s.get n] = s.take (n+1) := (take_succ' n).symm theorem get?_take {s : Stream' α} : ∀ {k n}, k < n → (s.take n).get? k = s.get k | 0, n+1, _ => rfl | k+1, n+1, h => by rw [take_succ, List.get?, get?_take (Nat.lt_of_succ_lt_succ h), get_succ] theorem get?_take_succ (n : Nat) (s : Stream' α) : List.get? (take (succ n) s) n = some (get s n) := get?_take (Nat.lt_succ_self n) #align stream.nth_take_succ Stream'.get?_take_succ @[simp] theorem dropLast_take {xs : Stream' α} : (Stream'.take n xs).dropLast = Stream'.take (n-1) xs := by cases n with | zero => simp | succ n => rw [take_succ', List.dropLast_concat, Nat.add_one_sub_one] @[simp] theorem append_take_drop : ∀ (n : Nat) (s : Stream' α), appendStream' (take n s) (drop n s) = s := by intro n induction' n with n' ih · intro s rfl · intro s rw [take_succ, drop_succ, cons_append_stream, ih (tail s), Stream'.eta] #align stream.append_take_drop Stream'.append_take_drop -- Take theorem reduces a proof of equality of infinite streams to an -- induction over all their finite approximations. theorem take_theorem (s₁ s₂ : Stream' α) : (∀ n : Nat, take n s₁ = take n s₂) → s₁ = s₂ := by intro h; apply Stream'.ext; intro n induction' n with n _ · have aux := h 1 simp? [take] at aux says simp only [take, List.cons.injEq, and_true] at aux exact aux · have h₁ : some (get s₁ (succ n)) = some (get s₂ (succ n)) := by rw [← get?_take_succ, ← get?_take_succ, h (succ (succ n))] injection h₁ #align stream.take_theorem Stream'.take_theorem protected theorem cycle_g_cons (a : α) (a₁ : α) (l₁ : List α) (a₀ : α) (l₀ : List α) : Stream'.cycleG (a, a₁::l₁, a₀, l₀) = (a₁, l₁, a₀, l₀) := rfl #align stream.cycle_g_cons Stream'.cycle_g_cons theorem cycle_eq : ∀ (l : List α) (h : l ≠ []), cycle l h = l ++ₛ cycle l h | [], h => absurd rfl h | List.cons a l, _ => have gen : ∀ l' a', corec Stream'.cycleF Stream'.cycleG (a', l', a, l) = (a'::l') ++ₛ corec Stream'.cycleF Stream'.cycleG (a, l, a, l) := by intro l' induction' l' with a₁ l₁ ih · intros rw [corec_eq] rfl · intros rw [corec_eq, Stream'.cycle_g_cons, ih a₁] rfl gen l a #align stream.cycle_eq Stream'.cycle_eq theorem mem_cycle {a : α} {l : List α} : ∀ h : l ≠ [], a ∈ l → a ∈ cycle l h := fun h ainl => by rw [cycle_eq]; exact mem_append_stream_left _ ainl #align stream.mem_cycle Stream'.mem_cycle @[simp] theorem cycle_singleton (a : α) : cycle [a] (by simp) = const a := coinduction rfl fun β fr ch => by rwa [cycle_eq, const_eq] #align stream.cycle_singleton Stream'.cycle_singleton theorem tails_eq (s : Stream' α) : tails s = tail s::tails (tail s) := by unfold tails; rw [corec_eq]; rfl #align stream.tails_eq Stream'.tails_eq @[simp] theorem get_tails : ∀ (n : Nat) (s : Stream' α), get (tails s) n = drop n (tail s) := by intro n; induction' n with n' ih · intros rfl · intro s rw [get_succ, drop_succ, tails_eq, tail_cons, ih] #align stream.nth_tails Stream'.get_tails theorem tails_eq_iterate (s : Stream' α) : tails s = iterate tail (tail s) := rfl #align stream.tails_eq_iterate Stream'.tails_eq_iterate
Mathlib/Data/Stream/Init.lean
686
689
theorem inits_core_eq (l : List α) (s : Stream' α) : initsCore l s = l::initsCore (l ++ [head s]) (tail s) := by
unfold initsCore corecOn rw [corec_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, Alexander Bentkamp -/ import Mathlib.LinearAlgebra.Basis import Mathlib.LinearAlgebra.FreeModule.Basic import Mathlib.LinearAlgebra.LinearPMap import Mathlib.LinearAlgebra.Projection #align_import linear_algebra.basis from "leanprover-community/mathlib"@"13bce9a6b6c44f6b4c91ac1c1d2a816e2533d395" /-! # Bases in a vector space This file provides results for bases of a vector space. Some of these results should be merged with the results on free modules. We state these results in a separate file to the results on modules to avoid an import cycle. ## Main statements * `Basis.ofVectorSpace` states that every vector space has a basis. * `Module.Free.of_divisionRing` states that every vector space is a free module. ## Tags basis, bases -/ open Function Set Submodule set_option autoImplicit false variable {ι : Type*} {ι' : Type*} {K : Type*} {V : Type*} {V' : Type*} section DivisionRing variable [DivisionRing K] [AddCommGroup V] [AddCommGroup V'] [Module K V] [Module K V'] variable {v : ι → V} {s t : Set V} {x y z : V} open Submodule namespace Basis section ExistsBasis /-- If `s` is a linear independent set of vectors, we can extend it to a basis. -/ noncomputable def extend (hs : LinearIndependent K ((↑) : s → V)) : Basis (hs.extend (subset_univ s)) K V := Basis.mk (@LinearIndependent.restrict_of_comp_subtype _ _ _ id _ _ _ _ (hs.linearIndependent_extend _)) (SetLike.coe_subset_coe.mp <| by simpa using hs.subset_span_extend (subset_univ s)) #align basis.extend Basis.extend theorem extend_apply_self (hs : LinearIndependent K ((↑) : s → V)) (x : hs.extend _) : Basis.extend hs x = x := Basis.mk_apply _ _ _ #align basis.extend_apply_self Basis.extend_apply_self @[simp] theorem coe_extend (hs : LinearIndependent K ((↑) : s → V)) : ⇑(Basis.extend hs) = ((↑) : _ → _) := funext (extend_apply_self hs) #align basis.coe_extend Basis.coe_extend theorem range_extend (hs : LinearIndependent K ((↑) : s → V)) : range (Basis.extend hs) = hs.extend (subset_univ _) := by rw [coe_extend, Subtype.range_coe_subtype, setOf_mem_eq] #align basis.range_extend Basis.range_extend -- Porting note: adding this to make the statement of `subExtend` more readable /-- Auxiliary definition: the index for the new basis vectors in `Basis.sumExtend`. The specific value of this definition should be considered an implementation detail. -/ def sumExtendIndex (hs : LinearIndependent K v) : Set V := LinearIndependent.extend hs.to_subtype_range (subset_univ _) \ range v /-- If `v` is a linear independent family of vectors, extend it to a basis indexed by a sum type. -/ noncomputable def sumExtend (hs : LinearIndependent K v) : Basis (ι ⊕ sumExtendIndex hs) K V := let s := Set.range v let e : ι ≃ s := Equiv.ofInjective v hs.injective let b := hs.to_subtype_range.extend (subset_univ (Set.range v)) (Basis.extend hs.to_subtype_range).reindex <| Equiv.symm <| calc Sum ι (b \ s : Set V) ≃ Sum s (b \ s : Set V) := Equiv.sumCongr e (Equiv.refl _) _ ≃ b := haveI := Classical.decPred (· ∈ s) Equiv.Set.sumDiffSubset (hs.to_subtype_range.subset_extend _) #align basis.sum_extend Basis.sumExtend theorem subset_extend {s : Set V} (hs : LinearIndependent K ((↑) : s → V)) : s ⊆ hs.extend (Set.subset_univ _) := hs.subset_extend _ #align basis.subset_extend Basis.subset_extend section variable (K V) /-- A set used to index `Basis.ofVectorSpace`. -/ noncomputable def ofVectorSpaceIndex : Set V := (linearIndependent_empty K V).extend (subset_univ _) #align basis.of_vector_space_index Basis.ofVectorSpaceIndex /-- Each vector space has a basis. -/ noncomputable def ofVectorSpace : Basis (ofVectorSpaceIndex K V) K V := Basis.extend (linearIndependent_empty K V) #align basis.of_vector_space Basis.ofVectorSpace instance (priority := 100) _root_.Module.Free.of_divisionRing : Module.Free K V := Module.Free.of_basis (ofVectorSpace K V) #align module.free.of_division_ring Module.Free.of_divisionRing theorem ofVectorSpace_apply_self (x : ofVectorSpaceIndex K V) : ofVectorSpace K V x = x := by unfold ofVectorSpace exact Basis.mk_apply _ _ _ #align basis.of_vector_space_apply_self Basis.ofVectorSpace_apply_self @[simp] theorem coe_ofVectorSpace : ⇑(ofVectorSpace K V) = ((↑) : _ → _ ) := funext fun x => ofVectorSpace_apply_self K V x #align basis.coe_of_vector_space Basis.coe_ofVectorSpace theorem ofVectorSpaceIndex.linearIndependent : LinearIndependent K ((↑) : ofVectorSpaceIndex K V → V) := by convert (ofVectorSpace K V).linearIndependent ext x rw [ofVectorSpace_apply_self] #align basis.of_vector_space_index.linear_independent Basis.ofVectorSpaceIndex.linearIndependent theorem range_ofVectorSpace : range (ofVectorSpace K V) = ofVectorSpaceIndex K V := range_extend _ #align basis.range_of_vector_space Basis.range_ofVectorSpace theorem exists_basis : ∃ s : Set V, Nonempty (Basis s K V) := ⟨ofVectorSpaceIndex K V, ⟨ofVectorSpace K V⟩⟩ #align basis.exists_basis Basis.exists_basis end end ExistsBasis end Basis open Fintype variable (K V)
Mathlib/LinearAlgebra/Basis/VectorSpace.lean
152
154
theorem VectorSpace.card_fintype [Fintype K] [Fintype V] : ∃ n : ℕ, card V = card K ^ n := by
classical exact ⟨card (Basis.ofVectorSpaceIndex K V), Module.card_fintype (Basis.ofVectorSpace K V)⟩
/- 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.Interval.Finset.Nat #align_import data.fin.interval from "leanprover-community/mathlib"@"1d29de43a5ba4662dd33b5cfeecfc2a27a5a8a29" /-! # Finite intervals in `Fin n` This file proves that `Fin n` is a `LocallyFiniteOrder` and calculates the cardinality of its intervals as Finsets and Fintypes. -/ assert_not_exists MonoidWithZero namespace Fin variable {n : ℕ} (a b : Fin n) @[simp, norm_cast] theorem coe_sup : ↑(a ⊔ b) = (a ⊔ b : ℕ) := rfl #align fin.coe_sup Fin.coe_sup @[simp, norm_cast] theorem coe_inf : ↑(a ⊓ b) = (a ⊓ b : ℕ) := rfl #align fin.coe_inf Fin.coe_inf @[simp, norm_cast] theorem coe_max : ↑(max a b) = (max a b : ℕ) := rfl #align fin.coe_max Fin.coe_max @[simp, norm_cast] theorem coe_min : ↑(min a b) = (min a b : ℕ) := rfl #align fin.coe_min Fin.coe_min end Fin open Finset Fin Function namespace Fin variable (n : ℕ) instance instLocallyFiniteOrder : LocallyFiniteOrder (Fin n) := OrderIso.locallyFiniteOrder Fin.orderIsoSubtype instance instLocallyFiniteOrderBot : LocallyFiniteOrderBot (Fin n) := OrderIso.locallyFiniteOrderBot Fin.orderIsoSubtype instance instLocallyFiniteOrderTop : ∀ n, LocallyFiniteOrderTop (Fin n) | 0 => IsEmpty.toLocallyFiniteOrderTop | _ + 1 => inferInstance variable {n} (a b : Fin n) theorem Icc_eq_finset_subtype : Icc a b = (Icc (a : ℕ) b).fin n := rfl #align fin.Icc_eq_finset_subtype Fin.Icc_eq_finset_subtype theorem Ico_eq_finset_subtype : Ico a b = (Ico (a : ℕ) b).fin n := rfl #align fin.Ico_eq_finset_subtype Fin.Ico_eq_finset_subtype theorem Ioc_eq_finset_subtype : Ioc a b = (Ioc (a : ℕ) b).fin n := rfl #align fin.Ioc_eq_finset_subtype Fin.Ioc_eq_finset_subtype theorem Ioo_eq_finset_subtype : Ioo a b = (Ioo (a : ℕ) b).fin n := rfl #align fin.Ioo_eq_finset_subtype Fin.Ioo_eq_finset_subtype theorem uIcc_eq_finset_subtype : uIcc a b = (uIcc (a : ℕ) b).fin n := rfl #align fin.uIcc_eq_finset_subtype Fin.uIcc_eq_finset_subtype @[simp] theorem map_valEmbedding_Icc : (Icc a b).map Fin.valEmbedding = Icc ↑a ↑b := by simp [Icc_eq_finset_subtype, Finset.fin, Finset.map_map, Icc_filter_lt_of_lt_right] #align fin.map_subtype_embedding_Icc Fin.map_valEmbedding_Icc @[simp] theorem map_valEmbedding_Ico : (Ico a b).map Fin.valEmbedding = Ico ↑a ↑b := by simp [Ico_eq_finset_subtype, Finset.fin, Finset.map_map] #align fin.map_subtype_embedding_Ico Fin.map_valEmbedding_Ico @[simp] theorem map_valEmbedding_Ioc : (Ioc a b).map Fin.valEmbedding = Ioc ↑a ↑b := by simp [Ioc_eq_finset_subtype, Finset.fin, Finset.map_map, Ioc_filter_lt_of_lt_right] #align fin.map_subtype_embedding_Ioc Fin.map_valEmbedding_Ioc @[simp] theorem map_valEmbedding_Ioo : (Ioo a b).map Fin.valEmbedding = Ioo ↑a ↑b := by simp [Ioo_eq_finset_subtype, Finset.fin, Finset.map_map] #align fin.map_subtype_embedding_Ioo Fin.map_valEmbedding_Ioo @[simp] theorem map_subtype_embedding_uIcc : (uIcc a b).map valEmbedding = uIcc ↑a ↑b := map_valEmbedding_Icc _ _ #align fin.map_subtype_embedding_uIcc Fin.map_subtype_embedding_uIcc @[simp] theorem card_Icc : (Icc a b).card = b + 1 - a := by rw [← Nat.card_Icc, ← map_valEmbedding_Icc, card_map] #align fin.card_Icc Fin.card_Icc @[simp] theorem card_Ico : (Ico a b).card = b - a := by rw [← Nat.card_Ico, ← map_valEmbedding_Ico, card_map] #align fin.card_Ico Fin.card_Ico @[simp] theorem card_Ioc : (Ioc a b).card = b - a := by rw [← Nat.card_Ioc, ← map_valEmbedding_Ioc, card_map] #align fin.card_Ioc Fin.card_Ioc @[simp]
Mathlib/Order/Interval/Finset/Fin.lean
119
120
theorem card_Ioo : (Ioo a b).card = b - a - 1 := by
rw [← Nat.card_Ioo, ← map_valEmbedding_Ioo, card_map]
/- 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.MFDeriv.Defs #align_import geometry.manifold.mfderiv from "leanprover-community/mathlib"@"e473c3198bb41f68560cab68a0529c854b618833" /-! # Basic properties of the manifold Fréchet derivative In this file, we show various properties of the manifold Fréchet derivative, mimicking the API for Fréchet derivatives. - basic properties of unique differentiability sets - various general lemmas about the manifold Fréchet derivative - deducing differentiability from smoothness, - deriving continuity from differentiability on manifolds, - congruence lemmas for derivatives on manifolds - composition lemmas and the chain rule -/ noncomputable section open scoped Topology Manifold open Set Bundle section DerivativesProperties /-! ### Unique differentiability sets in manifolds -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) {M : Type*} [TopologicalSpace M] [ChartedSpace H M] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners 𝕜 E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] {E'' : Type*} [NormedAddCommGroup E''] [NormedSpace 𝕜 E''] {H'' : Type*} [TopologicalSpace H''] {I'' : ModelWithCorners 𝕜 E'' H''} {M'' : Type*} [TopologicalSpace M''] [ChartedSpace H'' M''] {f f₀ f₁ : M → M'} {x : M} {s t : Set M} {g : M' → M''} {u : Set M'} theorem uniqueMDiffWithinAt_univ : UniqueMDiffWithinAt I univ x := by unfold UniqueMDiffWithinAt simp only [preimage_univ, univ_inter] exact I.unique_diff _ (mem_range_self _) #align unique_mdiff_within_at_univ uniqueMDiffWithinAt_univ variable {I} theorem uniqueMDiffWithinAt_iff {s : Set M} {x : M} : UniqueMDiffWithinAt I s x ↔ UniqueDiffWithinAt 𝕜 ((extChartAt I x).symm ⁻¹' s ∩ (extChartAt I x).target) ((extChartAt I x) x) := by apply uniqueDiffWithinAt_congr rw [nhdsWithin_inter, nhdsWithin_inter, nhdsWithin_extChartAt_target_eq] #align unique_mdiff_within_at_iff uniqueMDiffWithinAt_iff nonrec theorem UniqueMDiffWithinAt.mono_nhds {s t : Set M} {x : M} (hs : UniqueMDiffWithinAt I s x) (ht : 𝓝[s] x ≤ 𝓝[t] x) : UniqueMDiffWithinAt I t x := hs.mono_nhds <| by simpa only [← map_extChartAt_nhdsWithin] using Filter.map_mono ht theorem UniqueMDiffWithinAt.mono_of_mem {s t : Set M} {x : M} (hs : UniqueMDiffWithinAt I s x) (ht : t ∈ 𝓝[s] x) : UniqueMDiffWithinAt I t x := hs.mono_nhds (nhdsWithin_le_iff.2 ht) theorem UniqueMDiffWithinAt.mono (h : UniqueMDiffWithinAt I s x) (st : s ⊆ t) : UniqueMDiffWithinAt I t x := UniqueDiffWithinAt.mono h <| inter_subset_inter (preimage_mono st) (Subset.refl _) #align unique_mdiff_within_at.mono UniqueMDiffWithinAt.mono theorem UniqueMDiffWithinAt.inter' (hs : UniqueMDiffWithinAt I s x) (ht : t ∈ 𝓝[s] x) : UniqueMDiffWithinAt I (s ∩ t) x := hs.mono_of_mem (Filter.inter_mem self_mem_nhdsWithin ht) #align unique_mdiff_within_at.inter' UniqueMDiffWithinAt.inter' theorem UniqueMDiffWithinAt.inter (hs : UniqueMDiffWithinAt I s x) (ht : t ∈ 𝓝 x) : UniqueMDiffWithinAt I (s ∩ t) x := hs.inter' (nhdsWithin_le_nhds ht) #align unique_mdiff_within_at.inter UniqueMDiffWithinAt.inter theorem IsOpen.uniqueMDiffWithinAt (hs : IsOpen s) (xs : x ∈ s) : UniqueMDiffWithinAt I s x := (uniqueMDiffWithinAt_univ I).mono_of_mem <| nhdsWithin_le_nhds <| hs.mem_nhds xs #align is_open.unique_mdiff_within_at IsOpen.uniqueMDiffWithinAt theorem UniqueMDiffOn.inter (hs : UniqueMDiffOn I s) (ht : IsOpen t) : UniqueMDiffOn I (s ∩ t) := fun _x hx => UniqueMDiffWithinAt.inter (hs _ hx.1) (ht.mem_nhds hx.2) #align unique_mdiff_on.inter UniqueMDiffOn.inter theorem IsOpen.uniqueMDiffOn (hs : IsOpen s) : UniqueMDiffOn I s := fun _x hx => hs.uniqueMDiffWithinAt hx #align is_open.unique_mdiff_on IsOpen.uniqueMDiffOn theorem uniqueMDiffOn_univ : UniqueMDiffOn I (univ : Set M) := isOpen_univ.uniqueMDiffOn #align unique_mdiff_on_univ uniqueMDiffOn_univ /- We name the typeclass variables related to `SmoothManifoldWithCorners` structure as they are necessary in lemmas mentioning the derivative, but not in lemmas about differentiability, so we want to include them or omit them when necessary. -/ variable [Is : SmoothManifoldWithCorners I M] [I's : SmoothManifoldWithCorners I' M'] [I''s : SmoothManifoldWithCorners I'' M''] {f' f₀' f₁' : TangentSpace I x →L[𝕜] TangentSpace I' (f x)} {g' : TangentSpace I' (f x) →L[𝕜] TangentSpace I'' (g (f x))} /-- `UniqueMDiffWithinAt` achieves its goal: it implies the uniqueness of the derivative. -/ nonrec theorem UniqueMDiffWithinAt.eq (U : UniqueMDiffWithinAt I s x) (h : HasMFDerivWithinAt I I' f s x f') (h₁ : HasMFDerivWithinAt I I' f s x f₁') : f' = f₁' := by -- Porting note: didn't need `convert` because of finding instances by unification convert U.eq h.2 h₁.2 #align unique_mdiff_within_at.eq UniqueMDiffWithinAt.eq theorem UniqueMDiffOn.eq (U : UniqueMDiffOn I s) (hx : x ∈ s) (h : HasMFDerivWithinAt I I' f s x f') (h₁ : HasMFDerivWithinAt I I' f s x f₁') : f' = f₁' := UniqueMDiffWithinAt.eq (U _ hx) h h₁ #align unique_mdiff_on.eq UniqueMDiffOn.eq nonrec theorem UniqueMDiffWithinAt.prod {x : M} {y : M'} {s t} (hs : UniqueMDiffWithinAt I s x) (ht : UniqueMDiffWithinAt I' t y) : UniqueMDiffWithinAt (I.prod I') (s ×ˢ t) (x, y) := by refine (hs.prod ht).mono ?_ rw [ModelWithCorners.range_prod, ← prod_inter_prod] rfl theorem UniqueMDiffOn.prod {s : Set M} {t : Set M'} (hs : UniqueMDiffOn I s) (ht : UniqueMDiffOn I' t) : UniqueMDiffOn (I.prod I') (s ×ˢ t) := fun x h ↦ (hs x.1 h.1).prod (ht x.2 h.2) /-! ### General lemmas on derivatives of functions between manifolds We mimick the API for functions between vector spaces -/ theorem mdifferentiableWithinAt_iff {f : M → M'} {s : Set M} {x : M} : MDifferentiableWithinAt I I' f s x ↔ ContinuousWithinAt f s x ∧ DifferentiableWithinAt 𝕜 (writtenInExtChartAt I I' x f) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s) ((extChartAt I x) x) := by rw [mdifferentiableWithinAt_iff'] refine and_congr Iff.rfl (exists_congr fun f' => ?_) rw [inter_comm] simp only [HasFDerivWithinAt, nhdsWithin_inter, nhdsWithin_extChartAt_target_eq] #align mdifferentiable_within_at_iff mdifferentiableWithinAt_iff /-- One can reformulate differentiability within a set at a point as continuity within this set at this point, and differentiability in any chart containing that point. -/ theorem mdifferentiableWithinAt_iff_of_mem_source {x' : M} {y : M'} (hx : x' ∈ (chartAt H x).source) (hy : f x' ∈ (chartAt H' y).source) : MDifferentiableWithinAt I I' f s x' ↔ ContinuousWithinAt f s x' ∧ DifferentiableWithinAt 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm) ((extChartAt I x).symm ⁻¹' s ∩ Set.range I) ((extChartAt I x) x') := (differentiable_within_at_localInvariantProp I I').liftPropWithinAt_indep_chart (StructureGroupoid.chart_mem_maximalAtlas _ x) hx (StructureGroupoid.chart_mem_maximalAtlas _ y) hy #align mdifferentiable_within_at_iff_of_mem_source mdifferentiableWithinAt_iff_of_mem_source theorem mfderivWithin_zero_of_not_mdifferentiableWithinAt (h : ¬MDifferentiableWithinAt I I' f s x) : mfderivWithin I I' f s x = 0 := by simp only [mfderivWithin, h, if_neg, not_false_iff] #align mfderiv_within_zero_of_not_mdifferentiable_within_at mfderivWithin_zero_of_not_mdifferentiableWithinAt theorem mfderiv_zero_of_not_mdifferentiableAt (h : ¬MDifferentiableAt I I' f x) : mfderiv I I' f x = 0 := by simp only [mfderiv, h, if_neg, not_false_iff] #align mfderiv_zero_of_not_mdifferentiable_at mfderiv_zero_of_not_mdifferentiableAt theorem HasMFDerivWithinAt.mono (h : HasMFDerivWithinAt I I' f t x f') (hst : s ⊆ t) : HasMFDerivWithinAt I I' f s x f' := ⟨ContinuousWithinAt.mono h.1 hst, HasFDerivWithinAt.mono h.2 (inter_subset_inter (preimage_mono hst) (Subset.refl _))⟩ #align has_mfderiv_within_at.mono HasMFDerivWithinAt.mono theorem HasMFDerivAt.hasMFDerivWithinAt (h : HasMFDerivAt I I' f x f') : HasMFDerivWithinAt I I' f s x f' := ⟨ContinuousAt.continuousWithinAt h.1, HasFDerivWithinAt.mono h.2 inter_subset_right⟩ #align has_mfderiv_at.has_mfderiv_within_at HasMFDerivAt.hasMFDerivWithinAt theorem HasMFDerivWithinAt.mdifferentiableWithinAt (h : HasMFDerivWithinAt I I' f s x f') : MDifferentiableWithinAt I I' f s x := ⟨h.1, ⟨f', h.2⟩⟩ #align has_mfderiv_within_at.mdifferentiable_within_at HasMFDerivWithinAt.mdifferentiableWithinAt theorem HasMFDerivAt.mdifferentiableAt (h : HasMFDerivAt I I' f x f') : MDifferentiableAt I I' f x := by rw [mdifferentiableAt_iff] exact ⟨h.1, ⟨f', h.2⟩⟩ #align has_mfderiv_at.mdifferentiable_at HasMFDerivAt.mdifferentiableAt @[simp, mfld_simps] theorem hasMFDerivWithinAt_univ : HasMFDerivWithinAt I I' f univ x f' ↔ HasMFDerivAt I I' f x f' := by simp only [HasMFDerivWithinAt, HasMFDerivAt, continuousWithinAt_univ, mfld_simps] #align has_mfderiv_within_at_univ hasMFDerivWithinAt_univ theorem hasMFDerivAt_unique (h₀ : HasMFDerivAt I I' f x f₀') (h₁ : HasMFDerivAt I I' f x f₁') : f₀' = f₁' := by rw [← hasMFDerivWithinAt_univ] at h₀ h₁ exact (uniqueMDiffWithinAt_univ I).eq h₀ h₁ #align has_mfderiv_at_unique hasMFDerivAt_unique theorem hasMFDerivWithinAt_inter' (h : t ∈ 𝓝[s] x) : HasMFDerivWithinAt I I' f (s ∩ t) x f' ↔ HasMFDerivWithinAt I I' f s x f' := by rw [HasMFDerivWithinAt, HasMFDerivWithinAt, extChartAt_preimage_inter_eq, hasFDerivWithinAt_inter', continuousWithinAt_inter' h] exact extChartAt_preimage_mem_nhdsWithin I h #align has_mfderiv_within_at_inter' hasMFDerivWithinAt_inter' theorem hasMFDerivWithinAt_inter (h : t ∈ 𝓝 x) : HasMFDerivWithinAt I I' f (s ∩ t) x f' ↔ HasMFDerivWithinAt I I' f s x f' := by rw [HasMFDerivWithinAt, HasMFDerivWithinAt, extChartAt_preimage_inter_eq, hasFDerivWithinAt_inter, continuousWithinAt_inter h] exact extChartAt_preimage_mem_nhds I h #align has_mfderiv_within_at_inter hasMFDerivWithinAt_inter theorem HasMFDerivWithinAt.union (hs : HasMFDerivWithinAt I I' f s x f') (ht : HasMFDerivWithinAt I I' f t x f') : HasMFDerivWithinAt I I' f (s ∪ t) x f' := by constructor · exact ContinuousWithinAt.union hs.1 ht.1 · convert HasFDerivWithinAt.union hs.2 ht.2 using 1 simp only [union_inter_distrib_right, preimage_union] #align has_mfderiv_within_at.union HasMFDerivWithinAt.union theorem HasMFDerivWithinAt.mono_of_mem (h : HasMFDerivWithinAt I I' f s x f') (ht : s ∈ 𝓝[t] x) : HasMFDerivWithinAt I I' f t x f' := (hasMFDerivWithinAt_inter' ht).1 (h.mono inter_subset_right) #align has_mfderiv_within_at.nhds_within HasMFDerivWithinAt.mono_of_mem theorem HasMFDerivWithinAt.hasMFDerivAt (h : HasMFDerivWithinAt I I' f s x f') (hs : s ∈ 𝓝 x) : HasMFDerivAt I I' f x f' := by rwa [← univ_inter s, hasMFDerivWithinAt_inter hs, hasMFDerivWithinAt_univ] at h #align has_mfderiv_within_at.has_mfderiv_at HasMFDerivWithinAt.hasMFDerivAt theorem MDifferentiableWithinAt.hasMFDerivWithinAt (h : MDifferentiableWithinAt I I' f s x) : HasMFDerivWithinAt I I' f s x (mfderivWithin I I' f s x) := by refine ⟨h.1, ?_⟩ simp only [mfderivWithin, h, if_pos, mfld_simps] exact DifferentiableWithinAt.hasFDerivWithinAt h.2 #align mdifferentiable_within_at.has_mfderiv_within_at MDifferentiableWithinAt.hasMFDerivWithinAt protected theorem MDifferentiableWithinAt.mfderivWithin (h : MDifferentiableWithinAt I I' f s x) : mfderivWithin I I' f s x = fderivWithin 𝕜 (writtenInExtChartAt I I' x f : _) ((extChartAt I x).symm ⁻¹' s ∩ range I) ((extChartAt I x) x) := by simp only [mfderivWithin, h, if_pos] #align mdifferentiable_within_at.mfderiv_within MDifferentiableWithinAt.mfderivWithin theorem MDifferentiableAt.hasMFDerivAt (h : MDifferentiableAt I I' f x) : HasMFDerivAt I I' f x (mfderiv I I' f x) := by refine ⟨h.continuousAt, ?_⟩ simp only [mfderiv, h, if_pos, mfld_simps] exact DifferentiableWithinAt.hasFDerivWithinAt h.differentiableWithinAt_writtenInExtChartAt #align mdifferentiable_at.has_mfderiv_at MDifferentiableAt.hasMFDerivAt protected theorem MDifferentiableAt.mfderiv (h : MDifferentiableAt I I' f x) : mfderiv I I' f x = fderivWithin 𝕜 (writtenInExtChartAt I I' x f : _) (range I) ((extChartAt I x) x) := by simp only [mfderiv, h, if_pos] #align mdifferentiable_at.mfderiv MDifferentiableAt.mfderiv protected theorem HasMFDerivAt.mfderiv (h : HasMFDerivAt I I' f x f') : mfderiv I I' f x = f' := (hasMFDerivAt_unique h h.mdifferentiableAt.hasMFDerivAt).symm #align has_mfderiv_at.mfderiv HasMFDerivAt.mfderiv theorem HasMFDerivWithinAt.mfderivWithin (h : HasMFDerivWithinAt I I' f s x f') (hxs : UniqueMDiffWithinAt I s x) : mfderivWithin I I' f s x = f' := by ext rw [hxs.eq h h.mdifferentiableWithinAt.hasMFDerivWithinAt] #align has_mfderiv_within_at.mfderiv_within HasMFDerivWithinAt.mfderivWithin theorem MDifferentiable.mfderivWithin (h : MDifferentiableAt I I' f x) (hxs : UniqueMDiffWithinAt I s x) : mfderivWithin I I' f s x = mfderiv I I' f x := by apply HasMFDerivWithinAt.mfderivWithin _ hxs exact h.hasMFDerivAt.hasMFDerivWithinAt #align mdifferentiable.mfderiv_within MDifferentiable.mfderivWithin theorem mfderivWithin_subset (st : s ⊆ t) (hs : UniqueMDiffWithinAt I s x) (h : MDifferentiableWithinAt I I' f t x) : mfderivWithin I I' f s x = mfderivWithin I I' f t x := ((MDifferentiableWithinAt.hasMFDerivWithinAt h).mono st).mfderivWithin hs #align mfderiv_within_subset mfderivWithin_subset theorem MDifferentiableWithinAt.mono (hst : s ⊆ t) (h : MDifferentiableWithinAt I I' f t x) : MDifferentiableWithinAt I I' f s x := ⟨ContinuousWithinAt.mono h.1 hst, DifferentiableWithinAt.mono h.differentiableWithinAt_writtenInExtChartAt (inter_subset_inter_left _ (preimage_mono hst))⟩ #align mdifferentiable_within_at.mono MDifferentiableWithinAt.mono
Mathlib/Geometry/Manifold/MFDeriv/Basic.lean
292
294
theorem mdifferentiableWithinAt_univ : MDifferentiableWithinAt I I' f univ x ↔ MDifferentiableAt I I' f x := by
simp_rw [MDifferentiableWithinAt, MDifferentiableAt, ChartedSpace.LiftPropAt]
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.Data.Fin.Tuple.Basic import Mathlib.Data.List.Range #align_import data.fin.vec_notation from "leanprover-community/mathlib"@"2445c98ae4b87eabebdde552593519b9b6dc350c" /-! # Matrix and vector notation This file defines notation for vectors and matrices. Given `a b c d : α`, the notation allows us to write `![a, b, c, d] : Fin 4 → α`. Nesting vectors gives coefficients of a matrix, so `![![a, b], ![c, d]] : Fin 2 → Fin 2 → α`. In later files we introduce `!![a, b; c, d]` as notation for `Matrix.of ![![a, b], ![c, d]]`. ## Main definitions * `vecEmpty` is the empty vector (or `0` by `n` matrix) `![]` * `vecCons` prepends an entry to a vector, so `![a, b]` is `vecCons a (vecCons b vecEmpty)` ## Implementation notes The `simp` lemmas require that one of the arguments is of the form `vecCons _ _`. This ensures `simp` works with entries only when (some) entries are already given. In other words, this notation will only appear in the output of `simp` if it already appears in the input. ## Notations The main new notation is `![a, b]`, which gets expanded to `vecCons a (vecCons b vecEmpty)`. ## Examples Examples of usage can be found in the `test/matrix.lean` file. -/ namespace Matrix universe u variable {α : Type u} section MatrixNotation /-- `![]` is the vector with no entries. -/ def vecEmpty : Fin 0 → α := Fin.elim0 #align matrix.vec_empty Matrix.vecEmpty /-- `vecCons h t` prepends an entry `h` to a vector `t`. The inverse functions are `vecHead` and `vecTail`. The notation `![a, b, ...]` expands to `vecCons a (vecCons b ...)`. -/ def vecCons {n : ℕ} (h : α) (t : Fin n → α) : Fin n.succ → α := Fin.cons h t #align matrix.vec_cons Matrix.vecCons /-- `![...]` notation is used to construct a vector `Fin n → α` using `Matrix.vecEmpty` and `Matrix.vecCons`. For instance, `![a, b, c] : Fin 3` is syntax for `vecCons a (vecCons b (vecCons c vecEmpty))`. Note that this should not be used as syntax for `Matrix` as it generates a term with the wrong type. The `!![a, b; c, d]` syntax (provided by `Matrix.matrixNotation`) should be used instead. -/ syntax (name := vecNotation) "![" term,* "]" : term macro_rules | `(![$term:term, $terms:term,*]) => `(vecCons $term ![$terms,*]) | `(![$term:term]) => `(vecCons $term ![]) | `(![]) => `(vecEmpty) /-- Unexpander for the `![x, y, ...]` notation. -/ @[app_unexpander vecCons] def vecConsUnexpander : Lean.PrettyPrinter.Unexpander | `($_ $term ![$term2, $terms,*]) => `(![$term, $term2, $terms,*]) | `($_ $term ![$term2]) => `(![$term, $term2]) | `($_ $term ![]) => `(![$term]) | _ => throw () /-- Unexpander for the `![]` notation. -/ @[app_unexpander vecEmpty] def vecEmptyUnexpander : Lean.PrettyPrinter.Unexpander | `($_:ident) => `(![]) | _ => throw () /-- `vecHead v` gives the first entry of the vector `v` -/ def vecHead {n : ℕ} (v : Fin n.succ → α) : α := v 0 #align matrix.vec_head Matrix.vecHead /-- `vecTail v` gives a vector consisting of all entries of `v` except the first -/ def vecTail {n : ℕ} (v : Fin n.succ → α) : Fin n → α := v ∘ Fin.succ #align matrix.vec_tail Matrix.vecTail variable {m n : ℕ} /-- Use `![...]` notation for displaying a vector `Fin n → α`, for example: ``` #eval ![1, 2] + ![3, 4] -- ![4, 6] ``` -/ instance _root_.PiFin.hasRepr [Repr α] : Repr (Fin n → α) where reprPrec f _ := Std.Format.bracket "![" (Std.Format.joinSep ((List.finRange n).map fun n => repr (f n)) ("," ++ Std.Format.line)) "]" #align pi_fin.has_repr PiFin.hasRepr end MatrixNotation variable {m n o : ℕ} {m' n' o' : Type*} theorem empty_eq (v : Fin 0 → α) : v = ![] := Subsingleton.elim _ _ #align matrix.empty_eq Matrix.empty_eq section Val @[simp] theorem head_fin_const (a : α) : (vecHead fun _ : Fin (n + 1) => a) = a := rfl #align matrix.head_fin_const Matrix.head_fin_const @[simp] theorem cons_val_zero (x : α) (u : Fin m → α) : vecCons x u 0 = x := rfl #align matrix.cons_val_zero Matrix.cons_val_zero theorem cons_val_zero' (h : 0 < m.succ) (x : α) (u : Fin m → α) : vecCons x u ⟨0, h⟩ = x := rfl #align matrix.cons_val_zero' Matrix.cons_val_zero' @[simp] theorem cons_val_succ (x : α) (u : Fin m → α) (i : Fin m) : vecCons x u i.succ = u i := by simp [vecCons] #align matrix.cons_val_succ Matrix.cons_val_succ @[simp] theorem cons_val_succ' {i : ℕ} (h : i.succ < m.succ) (x : α) (u : Fin m → α) : vecCons x u ⟨i.succ, h⟩ = u ⟨i, Nat.lt_of_succ_lt_succ h⟩ := by simp only [vecCons, Fin.cons, Fin.cases_succ'] #align matrix.cons_val_succ' Matrix.cons_val_succ' @[simp] theorem head_cons (x : α) (u : Fin m → α) : vecHead (vecCons x u) = x := rfl #align matrix.head_cons Matrix.head_cons @[simp] theorem tail_cons (x : α) (u : Fin m → α) : vecTail (vecCons x u) = u := by ext simp [vecTail] #align matrix.tail_cons Matrix.tail_cons @[simp] theorem empty_val' {n' : Type*} (j : n') : (fun i => (![] : Fin 0 → n' → α) i j) = ![] := empty_eq _ #align matrix.empty_val' Matrix.empty_val' @[simp] theorem cons_head_tail (u : Fin m.succ → α) : vecCons (vecHead u) (vecTail u) = u := Fin.cons_self_tail _ #align matrix.cons_head_tail Matrix.cons_head_tail @[simp] theorem range_cons (x : α) (u : Fin n → α) : Set.range (vecCons x u) = {x} ∪ Set.range u := Set.ext fun y => by simp [Fin.exists_fin_succ, eq_comm] #align matrix.range_cons Matrix.range_cons @[simp] theorem range_empty (u : Fin 0 → α) : Set.range u = ∅ := Set.range_eq_empty _ #align matrix.range_empty Matrix.range_empty -- @[simp] -- Porting note (#10618): simp can prove this theorem range_cons_empty (x : α) (u : Fin 0 → α) : Set.range (Matrix.vecCons x u) = {x} := by rw [range_cons, range_empty, Set.union_empty] #align matrix.range_cons_empty Matrix.range_cons_empty -- @[simp] -- Porting note (#10618): simp can prove this (up to commutativity) theorem range_cons_cons_empty (x y : α) (u : Fin 0 → α) : Set.range (vecCons x <| vecCons y u) = {x, y} := by rw [range_cons, range_cons_empty, Set.singleton_union] #align matrix.range_cons_cons_empty Matrix.range_cons_cons_empty @[simp] theorem vecCons_const (a : α) : (vecCons a fun _ : Fin n => a) = fun _ => a := funext <| Fin.forall_fin_succ.2 ⟨rfl, cons_val_succ _ _⟩ #align matrix.vec_cons_const Matrix.vecCons_const theorem vec_single_eq_const (a : α) : ![a] = fun _ => a := let _ : Unique (Fin 1) := inferInstance funext <| Unique.forall_iff.2 rfl #align matrix.vec_single_eq_const Matrix.vec_single_eq_const /-- `![a, b, ...] 1` is equal to `b`. The simplifier needs a special lemma for length `≥ 2`, in addition to `cons_val_succ`, because `1 : Fin 1 = 0 : Fin 1`. -/ @[simp] theorem cons_val_one (x : α) (u : Fin m.succ → α) : vecCons x u 1 = vecHead u := rfl #align matrix.cons_val_one Matrix.cons_val_one @[simp] theorem cons_val_two (x : α) (u : Fin m.succ.succ → α) : vecCons x u 2 = vecHead (vecTail u) := rfl @[simp] lemma cons_val_three (x : α) (u : Fin m.succ.succ.succ → α) : vecCons x u 3 = vecHead (vecTail (vecTail u)) := rfl @[simp] lemma cons_val_four (x : α) (u : Fin m.succ.succ.succ.succ → α) : vecCons x u 4 = vecHead (vecTail (vecTail (vecTail u))) := rfl @[simp] theorem cons_val_fin_one (x : α) (u : Fin 0 → α) : ∀ (i : Fin 1), vecCons x u i = x := by rw [Fin.forall_fin_one] rfl #align matrix.cons_val_fin_one Matrix.cons_val_fin_one theorem cons_fin_one (x : α) (u : Fin 0 → α) : vecCons x u = fun _ => x := funext (cons_val_fin_one x u) #align matrix.cons_fin_one Matrix.cons_fin_one open Lean in open Qq in protected instance _root_.PiFin.toExpr [ToLevel.{u}] [ToExpr α] (n : ℕ) : ToExpr (Fin n → α) := have lu := toLevel.{u} have eα : Q(Type $lu) := toTypeExpr α have toTypeExpr := q(Fin $n → $eα) match n with | 0 => { toTypeExpr, toExpr := fun _ => q(@vecEmpty $eα) } | n + 1 => { toTypeExpr, toExpr := fun v => have := PiFin.toExpr n have eh : Q($eα) := toExpr (vecHead v) have et : Q(Fin $n → $eα) := toExpr (vecTail v) q(vecCons $eh $et) } #align pi_fin.reflect PiFin.toExpr -- Porting note: the next decl is commented out. TODO(eric-wieser) -- /-- Convert a vector of pexprs to the pexpr constructing that vector. -/ -- unsafe def _root_.pi_fin.to_pexpr : ∀ {n}, (Fin n → pexpr) → pexpr -- | 0, v => ``(![]) -- | n + 1, v => ``(vecCons $(v 0) $(_root_.pi_fin.to_pexpr <| vecTail v)) -- #align pi_fin.to_pexpr pi_fin.to_pexpr /-! ### `bit0` and `bit1` indices The following definitions and `simp` lemmas are used to allow numeral-indexed element of a vector given with matrix notation to be extracted by `simp` in Lean 3 (even when the numeral is larger than the number of elements in the vector, which is taken modulo that number of elements by virtue of the semantics of `bit0` and `bit1` and of addition on `Fin n`). -/ /-- `vecAppend ho u v` appends two vectors of lengths `m` and `n` to produce one of length `o = m + n`. This is a variant of `Fin.append` with an additional `ho` argument, which provides control of definitional equality for the vector length. This turns out to be helpful when providing simp lemmas to reduce `![a, b, c] n`, and also means that `vecAppend ho u v 0` is valid. `Fin.append u v 0` is not valid in this case because there is no `Zero (Fin (m + n))` instance. -/ def vecAppend {α : Type*} {o : ℕ} (ho : o = m + n) (u : Fin m → α) (v : Fin n → α) : Fin o → α := Fin.append u v ∘ Fin.cast ho #align matrix.vec_append Matrix.vecAppend theorem vecAppend_eq_ite {α : Type*} {o : ℕ} (ho : o = m + n) (u : Fin m → α) (v : Fin n → α) : vecAppend ho u v = fun i : Fin o => if h : (i : ℕ) < m then u ⟨i, h⟩ else v ⟨(i : ℕ) - m, by omega⟩ := by ext i rw [vecAppend, Fin.append, Function.comp_apply, Fin.addCases] congr with hi simp only [eq_rec_constant] rfl #align matrix.vec_append_eq_ite Matrix.vecAppend_eq_ite -- Porting note: proof was `rfl`, so this is no longer a `dsimp`-lemma -- Could become one again with change to `Nat.ble`: -- https://github.com/leanprover-community/mathlib4/pull/1741/files/#r1083902351 @[simp] theorem vecAppend_apply_zero {α : Type*} {o : ℕ} (ho : o + 1 = m + 1 + n) (u : Fin (m + 1) → α) (v : Fin n → α) : vecAppend ho u v 0 = u 0 := dif_pos _ #align matrix.vec_append_apply_zero Matrix.vecAppend_apply_zero @[simp] theorem empty_vecAppend (v : Fin n → α) : vecAppend n.zero_add.symm ![] v = v := by ext simp [vecAppend_eq_ite] #align matrix.empty_vec_append Matrix.empty_vecAppend @[simp] theorem cons_vecAppend (ho : o + 1 = m + 1 + n) (x : α) (u : Fin m → α) (v : Fin n → α) : vecAppend ho (vecCons x u) v = vecCons x (vecAppend (by omega) u v) := by ext i simp_rw [vecAppend_eq_ite] split_ifs with h · rcases i with ⟨⟨⟩ | i, hi⟩ · simp · simp only [Nat.add_lt_add_iff_right, Fin.val_mk] at h simp [h] · rcases i with ⟨⟨⟩ | i, hi⟩ · simp at h · rw [not_lt, Fin.val_mk, Nat.add_le_add_iff_right] at h simp [h, not_lt.2 h] #align matrix.cons_vec_append Matrix.cons_vecAppend /-- `vecAlt0 v` gives a vector with half the length of `v`, with only alternate elements (even-numbered). -/ def vecAlt0 (hm : m = n + n) (v : Fin m → α) (k : Fin n) : α := v ⟨(k : ℕ) + k, by omega⟩ #align matrix.vec_alt0 Matrix.vecAlt0 /-- `vecAlt1 v` gives a vector with half the length of `v`, with only alternate elements (odd-numbered). -/ def vecAlt1 (hm : m = n + n) (v : Fin m → α) (k : Fin n) : α := v ⟨(k : ℕ) + k + 1, hm.symm ▸ Nat.add_succ_lt_add k.2 k.2⟩ #align matrix.vec_alt1 Matrix.vecAlt1 section bits set_option linter.deprecated false theorem vecAlt0_vecAppend (v : Fin n → α) : vecAlt0 rfl (vecAppend rfl v v) = v ∘ bit0 := by ext i simp_rw [Function.comp, bit0, vecAlt0, vecAppend_eq_ite] split_ifs with h <;> congr · rw [Fin.val_mk] at h exact (Nat.mod_eq_of_lt h).symm · rw [Fin.val_mk, not_lt] at h simp only [Fin.ext_iff, Fin.val_add, Fin.val_mk, Nat.mod_eq_sub_mod h] refine (Nat.mod_eq_of_lt ?_).symm omega #align matrix.vec_alt0_vec_append Matrix.vecAlt0_vecAppend theorem vecAlt1_vecAppend (v : Fin (n + 1) → α) : vecAlt1 rfl (vecAppend rfl v v) = v ∘ bit1 := by ext i simp_rw [Function.comp, vecAlt1, vecAppend_eq_ite] cases n with | zero => cases' i with i hi simp only [Nat.zero_eq, Nat.zero_add, Nat.lt_one_iff] at hi; subst i; rfl | succ n => split_ifs with h <;> simp_rw [bit1, bit0] <;> congr · simp [Nat.mod_eq_of_lt, h] · rw [Fin.val_mk, not_lt] at h simp only [Fin.ext_iff, Fin.val_add, Fin.val_mk, Nat.mod_add_mod, Fin.val_one, Nat.mod_eq_sub_mod h, show 1 % (n + 2) = 1 from Nat.mod_eq_of_lt (by omega)] refine (Nat.mod_eq_of_lt ?_).symm omega #align matrix.vec_alt1_vec_append Matrix.vecAlt1_vecAppend @[simp] theorem vecHead_vecAlt0 (hm : m + 2 = n + 1 + (n + 1)) (v : Fin (m + 2) → α) : vecHead (vecAlt0 hm v) = v 0 := rfl #align matrix.vec_head_vec_alt0 Matrix.vecHead_vecAlt0 @[simp] theorem vecHead_vecAlt1 (hm : m + 2 = n + 1 + (n + 1)) (v : Fin (m + 2) → α) : vecHead (vecAlt1 hm v) = v 1 := by simp [vecHead, vecAlt1] #align matrix.vec_head_vec_alt1 Matrix.vecHead_vecAlt1 @[simp] theorem cons_vec_bit0_eq_alt0 (x : α) (u : Fin n → α) (i : Fin (n + 1)) : vecCons x u (bit0 i) = vecAlt0 rfl (vecAppend rfl (vecCons x u) (vecCons x u)) i := by rw [vecAlt0_vecAppend]; rfl #align matrix.cons_vec_bit0_eq_alt0 Matrix.cons_vec_bit0_eq_alt0 @[simp] theorem cons_vec_bit1_eq_alt1 (x : α) (u : Fin n → α) (i : Fin (n + 1)) : vecCons x u (bit1 i) = vecAlt1 rfl (vecAppend rfl (vecCons x u) (vecCons x u)) i := by rw [vecAlt1_vecAppend]; rfl #align matrix.cons_vec_bit1_eq_alt1 Matrix.cons_vec_bit1_eq_alt1 end bits @[simp] theorem cons_vecAlt0 (h : m + 1 + 1 = n + 1 + (n + 1)) (x y : α) (u : Fin m → α) : vecAlt0 h (vecCons x (vecCons y u)) = vecCons x (vecAlt0 (by omega) u) := by ext i simp_rw [vecAlt0] rcases i with ⟨⟨⟩ | i, hi⟩ · rfl · simp [vecAlt0, Nat.add_right_comm, ← Nat.add_assoc] #align matrix.cons_vec_alt0 Matrix.cons_vecAlt0 -- Although proved by simp, extracting element 8 of a five-element -- vector does not work by simp unless this lemma is present. @[simp] theorem empty_vecAlt0 (α) {h} : vecAlt0 h (![] : Fin 0 → α) = ![] := by simp [eq_iff_true_of_subsingleton] #align matrix.empty_vec_alt0 Matrix.empty_vecAlt0 @[simp] theorem cons_vecAlt1 (h : m + 1 + 1 = n + 1 + (n + 1)) (x y : α) (u : Fin m → α) : vecAlt1 h (vecCons x (vecCons y u)) = vecCons y (vecAlt1 (by omega) u) := by ext i simp_rw [vecAlt1] rcases i with ⟨⟨⟩ | i, hi⟩ · rfl · simp [vecAlt1, Nat.add_right_comm, ← Nat.add_assoc] #align matrix.cons_vec_alt1 Matrix.cons_vecAlt1 -- Although proved by simp, extracting element 9 of a five-element -- vector does not work by simp unless this lemma is present. @[simp] theorem empty_vecAlt1 (α) {h} : vecAlt1 h (![] : Fin 0 → α) = ![] := by simp [eq_iff_true_of_subsingleton] #align matrix.empty_vec_alt1 Matrix.empty_vecAlt1 end Val section SMul variable {M : Type*} [SMul M α] @[simp] theorem smul_empty (x : M) (v : Fin 0 → α) : x • v = ![] := empty_eq _ #align matrix.smul_empty Matrix.smul_empty @[simp] theorem smul_cons (x : M) (y : α) (v : Fin n → α) : x • vecCons y v = vecCons (x • y) (x • v) := by ext i refine Fin.cases ?_ ?_ i <;> simp #align matrix.smul_cons Matrix.smul_cons end SMul section Add variable [Add α] @[simp] theorem empty_add_empty (v w : Fin 0 → α) : v + w = ![] := empty_eq _ #align matrix.empty_add_empty Matrix.empty_add_empty @[simp] theorem cons_add (x : α) (v : Fin n → α) (w : Fin n.succ → α) : vecCons x v + w = vecCons (x + vecHead w) (v + vecTail w) := by ext i refine Fin.cases ?_ ?_ i <;> simp [vecHead, vecTail] #align matrix.cons_add Matrix.cons_add @[simp] theorem add_cons (v : Fin n.succ → α) (y : α) (w : Fin n → α) : v + vecCons y w = vecCons (vecHead v + y) (vecTail v + w) := by ext i refine Fin.cases ?_ ?_ i <;> simp [vecHead, vecTail] #align matrix.add_cons Matrix.add_cons -- @[simp] -- Porting note (#10618): simp can prove this
Mathlib/Data/Fin/VecNotation.lean
469
470
theorem cons_add_cons (x : α) (v : Fin n → α) (y : α) (w : Fin n → α) : vecCons x v + vecCons y w = vecCons (x + y) (v + w) := by
simp
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Data.Nat.Multiplicity import Mathlib.Data.ZMod.Algebra import Mathlib.RingTheory.WittVector.Basic import Mathlib.RingTheory.WittVector.IsPoly import Mathlib.FieldTheory.Perfect #align_import ring_theory.witt_vector.frobenius from "leanprover-community/mathlib"@"0723536a0522d24fc2f159a096fb3304bef77472" /-! ## The Frobenius operator If `R` has characteristic `p`, then there is a ring endomorphism `frobenius R p` that raises `r : R` to the power `p`. By applying `WittVector.map` to `frobenius R p`, we obtain a ring endomorphism `𝕎 R →+* 𝕎 R`. It turns out that this endomorphism can be described by polynomials over `ℤ` that do not depend on `R` or the fact that it has characteristic `p`. In this way, we obtain a Frobenius endomorphism `WittVector.frobeniusFun : 𝕎 R → 𝕎 R` for every commutative ring `R`. Unfortunately, the aforementioned polynomials can not be obtained using the machinery of `wittStructureInt` that was developed in `StructurePolynomial.lean`. We therefore have to define the polynomials by hand, and check that they have the required property. In case `R` has characteristic `p`, we show in `frobenius_eq_map_frobenius` that `WittVector.frobeniusFun` is equal to `WittVector.map (frobenius R p)`. ### Main definitions and results * `frobeniusPoly`: the polynomials that describe the coefficients of `frobeniusFun`; * `frobeniusFun`: the Frobenius endomorphism on Witt vectors; * `frobeniusFun_isPoly`: the tautological assertion that Frobenius is a polynomial function; * `frobenius_eq_map_frobenius`: the fact that in characteristic `p`, Frobenius is equal to `WittVector.map (frobenius R p)`. TODO: Show that `WittVector.frobeniusFun` is a ring homomorphism, and bundle it into `WittVector.frobenius`. ## References * [Hazewinkel, *Witt Vectors*][Haze09] * [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21] -/ namespace WittVector variable {p : ℕ} {R S : Type*} [hp : Fact p.Prime] [CommRing R] [CommRing S] local notation "𝕎" => WittVector p -- type as `\bbW` noncomputable section open MvPolynomial Finset variable (p) /-- The rational polynomials that give the coefficients of `frobenius x`, in terms of the coefficients of `x`. These polynomials actually have integral coefficients, see `frobeniusPoly` and `map_frobeniusPoly`. -/ def frobeniusPolyRat (n : ℕ) : MvPolynomial ℕ ℚ := bind₁ (wittPolynomial p ℚ ∘ fun n => n + 1) (xInTermsOfW p ℚ n) #align witt_vector.frobenius_poly_rat WittVector.frobeniusPolyRat
Mathlib/RingTheory/WittVector/Frobenius.lean
71
74
theorem bind₁_frobeniusPolyRat_wittPolynomial (n : ℕ) : bind₁ (frobeniusPolyRat p) (wittPolynomial p ℚ n) = wittPolynomial p ℚ (n + 1) := by
delta frobeniusPolyRat rw [← bind₁_bind₁, bind₁_xInTermsOfW_wittPolynomial, bind₁_X_right, Function.comp_apply]
/- 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, Peter Pfaffelhuber -/ import Mathlib.MeasureTheory.PiSystem import Mathlib.Order.OmegaCompletePartialOrder import Mathlib.Topology.Constructions import Mathlib.MeasureTheory.MeasurableSpace.Basic /-! # π-systems of cylinders and square cylinders The instance `MeasurableSpace.pi` on `∀ i, α i`, where each `α i` has a `MeasurableSpace` `m i`, is defined as `⨆ i, (m i).comap (fun a => a i)`. That is, a function `g : β → ∀ i, α i` is measurable iff for all `i`, the function `b ↦ g b i` is measurable. We define two π-systems generating `MeasurableSpace.pi`, cylinders and square cylinders. ## Main definitions Given a finite set `s` of indices, a cylinder is the product of a set of `∀ i : s, α i` and of `univ` on the other indices. A square cylinder is a cylinder for which the set on `∀ i : s, α i` is a product set. * `cylinder s S`: cylinder with base set `S : Set (∀ i : s, α i)` where `s` is a `Finset` * `squareCylinders C` with `C : ∀ i, Set (Set (α i))`: set of all square cylinders such that for all `i` in the finset defining the box, the projection to `α i` belongs to `C i`. The main application of this is with `C i = {s : Set (α i) | MeasurableSet s}`. * `measurableCylinders`: set of all cylinders with measurable base sets. ## Main statements * `generateFrom_squareCylinders`: square cylinders formed from measurable sets generate the product σ-algebra * `generateFrom_measurableCylinders`: cylinders formed from measurable sets generate the product σ-algebra -/ open Set namespace MeasureTheory variable {ι : Type _} {α : ι → Type _} section squareCylinders /-- Given a finite set `s` of indices, a square cylinder is the product of a set `S` of `∀ i : s, α i` and of `univ` on the other indices. The set `S` is a product of sets `t i` such that for all `i : s`, `t i ∈ C i`. `squareCylinders` is the set of all such squareCylinders. -/ def squareCylinders (C : ∀ i, Set (Set (α i))) : Set (Set (∀ i, α i)) := {S | ∃ s : Finset ι, ∃ t ∈ univ.pi C, S = (s : Set ι).pi t} theorem squareCylinders_eq_iUnion_image (C : ∀ i, Set (Set (α i))) : squareCylinders C = ⋃ s : Finset ι, (fun t ↦ (s : Set ι).pi t) '' univ.pi C := by ext1 f simp only [squareCylinders, mem_iUnion, mem_image, mem_univ_pi, exists_prop, mem_setOf_eq, eq_comm (a := f)] theorem isPiSystem_squareCylinders {C : ∀ i, Set (Set (α i))} (hC : ∀ i, IsPiSystem (C i)) (hC_univ : ∀ i, univ ∈ C i) : IsPiSystem (squareCylinders C) := by rintro S₁ ⟨s₁, t₁, h₁, rfl⟩ S₂ ⟨s₂, t₂, h₂, rfl⟩ hst_nonempty classical let t₁' := s₁.piecewise t₁ (fun i ↦ univ) let t₂' := s₂.piecewise t₂ (fun i ↦ univ) have h1 : ∀ i ∈ (s₁ : Set ι), t₁ i = t₁' i := fun i hi ↦ (Finset.piecewise_eq_of_mem _ _ _ hi).symm have h1' : ∀ i ∉ (s₁ : Set ι), t₁' i = univ := fun i hi ↦ Finset.piecewise_eq_of_not_mem _ _ _ hi have h2 : ∀ i ∈ (s₂ : Set ι), t₂ i = t₂' i := fun i hi ↦ (Finset.piecewise_eq_of_mem _ _ _ hi).symm have h2' : ∀ i ∉ (s₂ : Set ι), t₂' i = univ := fun i hi ↦ Finset.piecewise_eq_of_not_mem _ _ _ hi rw [Set.pi_congr rfl h1, Set.pi_congr rfl h2, ← union_pi_inter h1' h2'] refine ⟨s₁ ∪ s₂, fun i ↦ t₁' i ∩ t₂' i, ?_, ?_⟩ · rw [mem_univ_pi] intro i have : (t₁' i ∩ t₂' i).Nonempty := by obtain ⟨f, hf⟩ := hst_nonempty rw [Set.pi_congr rfl h1, Set.pi_congr rfl h2, mem_inter_iff, mem_pi, mem_pi] at hf refine ⟨f i, ⟨?_, ?_⟩⟩ · by_cases hi₁ : i ∈ s₁ · exact hf.1 i hi₁ · rw [h1' i hi₁] exact mem_univ _ · by_cases hi₂ : i ∈ s₂ · exact hf.2 i hi₂ · rw [h2' i hi₂] exact mem_univ _ refine hC i _ ?_ _ ?_ this · by_cases hi₁ : i ∈ s₁ · rw [← h1 i hi₁] exact h₁ i (mem_univ _) · rw [h1' i hi₁] exact hC_univ i · by_cases hi₂ : i ∈ s₂ · rw [← h2 i hi₂] exact h₂ i (mem_univ _) · rw [h2' i hi₂] exact hC_univ i · rw [Finset.coe_union] theorem comap_eval_le_generateFrom_squareCylinders_singleton (α : ι → Type*) [m : ∀ i, MeasurableSpace (α i)] (i : ι) : MeasurableSpace.comap (Function.eval i) (m i) ≤ MeasurableSpace.generateFrom ((fun t ↦ ({i} : Set ι).pi t) '' univ.pi fun i ↦ {s : Set (α i) | MeasurableSet s}) := by simp only [Function.eval, singleton_pi, ge_iff_le] rw [MeasurableSpace.comap_eq_generateFrom] refine MeasurableSpace.generateFrom_mono fun S ↦ ?_ simp only [mem_setOf_eq, mem_image, mem_univ_pi, forall_exists_index, and_imp] intro t ht h classical refine ⟨fun j ↦ if hji : j = i then by convert t else univ, fun j ↦ ?_, ?_⟩ · by_cases hji : j = i · simp only [hji, eq_self_iff_true, eq_mpr_eq_cast, dif_pos] convert ht simp only [id_eq, cast_heq] · simp only [hji, not_false_iff, dif_neg, MeasurableSet.univ] · simp only [id_eq, eq_mpr_eq_cast, ← h] ext1 x simp only [singleton_pi, Function.eval, cast_eq, dite_eq_ite, ite_true, mem_preimage] /-- The square cylinders formed from measurable sets generate the product σ-algebra. -/ theorem generateFrom_squareCylinders [∀ i, MeasurableSpace (α i)] : MeasurableSpace.generateFrom (squareCylinders fun i ↦ {s : Set (α i) | MeasurableSet s}) = MeasurableSpace.pi := by apply le_antisymm · rw [MeasurableSpace.generateFrom_le_iff] rintro S ⟨s, t, h, rfl⟩ simp only [mem_univ_pi, mem_setOf_eq] at h exact MeasurableSet.pi (Finset.countable_toSet _) (fun i _ ↦ h i) · refine iSup_le fun i ↦ ?_ refine (comap_eval_le_generateFrom_squareCylinders_singleton α i).trans ?_ refine MeasurableSpace.generateFrom_mono ?_ rw [← Finset.coe_singleton, squareCylinders_eq_iUnion_image] exact subset_iUnion (fun (s : Finset ι) ↦ (fun t : ∀ i, Set (α i) ↦ (s : Set ι).pi t) '' univ.pi (fun i ↦ setOf MeasurableSet)) ({i} : Finset ι) end squareCylinders section cylinder /-- Given a finite set `s` of indices, a cylinder is the preimage of a set `S` of `∀ i : s, α i` by the projection from `∀ i, α i` to `∀ i : s, α i`. -/ def cylinder (s : Finset ι) (S : Set (∀ i : s, α i)) : Set (∀ i, α i) := (fun (f : ∀ i, α i) (i : s) ↦ f i) ⁻¹' S @[simp] theorem mem_cylinder (s : Finset ι) (S : Set (∀ i : s, α i)) (f : ∀ i, α i) : f ∈ cylinder s S ↔ (fun i : s ↦ f i) ∈ S := mem_preimage @[simp] theorem cylinder_empty (s : Finset ι) : cylinder s (∅ : Set (∀ i : s, α i)) = ∅ := by rw [cylinder, preimage_empty] @[simp] theorem cylinder_univ (s : Finset ι) : cylinder s (univ : Set (∀ i : s, α i)) = univ := by rw [cylinder, preimage_univ] @[simp] theorem cylinder_eq_empty_iff [h_nonempty : Nonempty (∀ i, α i)] (s : Finset ι) (S : Set (∀ i : s, α i)) : cylinder s S = ∅ ↔ S = ∅ := by refine ⟨fun h ↦ ?_, fun h ↦ by (rw [h]; exact cylinder_empty _)⟩ by_contra hS rw [← Ne, ← nonempty_iff_ne_empty] at hS let f := hS.some have hf : f ∈ S := hS.choose_spec classical let f' : ∀ i, α i := fun i ↦ if hi : i ∈ s then f ⟨i, hi⟩ else h_nonempty.some i have hf' : f' ∈ cylinder s S := by rw [mem_cylinder] simpa only [f', Finset.coe_mem, dif_pos] rw [h] at hf' exact not_mem_empty _ hf' theorem inter_cylinder (s₁ s₂ : Finset ι) (S₁ : Set (∀ i : s₁, α i)) (S₂ : Set (∀ i : s₂, α i)) [DecidableEq ι] : cylinder s₁ S₁ ∩ cylinder s₂ S₂ = cylinder (s₁ ∪ s₂) ((fun f ↦ fun j : s₁ ↦ f ⟨j, Finset.mem_union_left s₂ j.prop⟩) ⁻¹' S₁ ∩ (fun f ↦ fun j : s₂ ↦ f ⟨j, Finset.mem_union_right s₁ j.prop⟩) ⁻¹' S₂) := by ext1 f; simp only [mem_inter_iff, mem_cylinder, mem_setOf_eq]; rfl theorem inter_cylinder_same (s : Finset ι) (S₁ : Set (∀ i : s, α i)) (S₂ : Set (∀ i : s, α i)) : cylinder s S₁ ∩ cylinder s S₂ = cylinder s (S₁ ∩ S₂) := by classical rw [inter_cylinder]; rfl theorem union_cylinder (s₁ s₂ : Finset ι) (S₁ : Set (∀ i : s₁, α i)) (S₂ : Set (∀ i : s₂, α i)) [DecidableEq ι] : cylinder s₁ S₁ ∪ cylinder s₂ S₂ = cylinder (s₁ ∪ s₂) ((fun f ↦ fun j : s₁ ↦ f ⟨j, Finset.mem_union_left s₂ j.prop⟩) ⁻¹' S₁ ∪ (fun f ↦ fun j : s₂ ↦ f ⟨j, Finset.mem_union_right s₁ j.prop⟩) ⁻¹' S₂) := by ext1 f; simp only [mem_union, mem_cylinder, mem_setOf_eq]; rfl theorem union_cylinder_same (s : Finset ι) (S₁ : Set (∀ i : s, α i)) (S₂ : Set (∀ i : s, α i)) : cylinder s S₁ ∪ cylinder s S₂ = cylinder s (S₁ ∪ S₂) := by classical rw [union_cylinder]; rfl theorem compl_cylinder (s : Finset ι) (S : Set (∀ i : s, α i)) : (cylinder s S)ᶜ = cylinder s (Sᶜ) := by ext1 f; simp only [mem_compl_iff, mem_cylinder] theorem diff_cylinder_same (s : Finset ι) (S T : Set (∀ i : s, α i)) : cylinder s S \ cylinder s T = cylinder s (S \ T) := by ext1 f; simp only [mem_diff, mem_cylinder] theorem eq_of_cylinder_eq_of_subset [h_nonempty : Nonempty (∀ i, α i)] {I J : Finset ι} {S : Set (∀ i : I, α i)} {T : Set (∀ i : J, α i)} (h_eq : cylinder I S = cylinder J T) (hJI : J ⊆ I) : S = (fun f : ∀ i : I, α i ↦ fun j : J ↦ f ⟨j, hJI j.prop⟩) ⁻¹' T := by rw [Set.ext_iff] at h_eq simp only [mem_cylinder] at h_eq ext1 f simp only [mem_preimage] classical specialize h_eq fun i ↦ if hi : i ∈ I then f ⟨i, hi⟩ else h_nonempty.some i have h_mem : ∀ j : J, ↑j ∈ I := fun j ↦ hJI j.prop simp only [Finset.coe_mem, dite_true, h_mem] at h_eq exact h_eq theorem cylinder_eq_cylinder_union [DecidableEq ι] (I : Finset ι) (S : Set (∀ i : I, α i)) (J : Finset ι) : cylinder I S = cylinder (I ∪ J) ((fun f ↦ fun j : I ↦ f ⟨j, Finset.mem_union_left J j.prop⟩) ⁻¹' S) := by ext1 f; simp only [mem_cylinder, mem_preimage] theorem disjoint_cylinder_iff [Nonempty (∀ i, α i)] {s t : Finset ι} {S : Set (∀ i : s, α i)} {T : Set (∀ i : t, α i)} [DecidableEq ι] : Disjoint (cylinder s S) (cylinder t T) ↔ Disjoint ((fun f : ∀ i : (s ∪ t : Finset ι), α i ↦ fun j : s ↦ f ⟨j, Finset.mem_union_left t j.prop⟩) ⁻¹' S) ((fun f ↦ fun j : t ↦ f ⟨j, Finset.mem_union_right s j.prop⟩) ⁻¹' T) := by simp_rw [Set.disjoint_iff, subset_empty_iff, inter_cylinder, cylinder_eq_empty_iff] theorem IsClosed.cylinder [∀ i, TopologicalSpace (α i)] (s : Finset ι) {S : Set (∀ i : s, α i)} (hs : IsClosed S) : IsClosed (cylinder s S) := hs.preimage (continuous_pi fun _ ↦ continuous_apply _) theorem _root_.MeasurableSet.cylinder [∀ i, MeasurableSpace (α i)] (s : Finset ι) {S : Set (∀ i : s, α i)} (hS : MeasurableSet S) : MeasurableSet (cylinder s S) := measurable_pi_lambda _ (fun _ ↦ measurable_pi_apply _) hS end cylinder section cylinders /-- Given a finite set `s` of indices, a cylinder is the preimage of a set `S` of `∀ i : s, α i` by the projection from `∀ i, α i` to `∀ i : s, α i`. `measurableCylinders` is the set of all cylinders with measurable base `S`. -/ def measurableCylinders (α : ι → Type*) [∀ i, MeasurableSpace (α i)] : Set (Set (∀ i, α i)) := ⋃ (s) (S) (_ : MeasurableSet S), {cylinder s S} theorem empty_mem_measurableCylinders (α : ι → Type*) [∀ i, MeasurableSpace (α i)] : ∅ ∈ measurableCylinders α := by simp_rw [measurableCylinders, mem_iUnion, mem_singleton_iff] exact ⟨∅, ∅, MeasurableSet.empty, (cylinder_empty _).symm⟩ variable [∀ i, MeasurableSpace (α i)] {s t : Set (∀ i, α i)} @[simp] theorem mem_measurableCylinders (t : Set (∀ i, α i)) : t ∈ measurableCylinders α ↔ ∃ s S, MeasurableSet S ∧ t = cylinder s S := by simp_rw [measurableCylinders, mem_iUnion, exists_prop, mem_singleton_iff] /-- A finset `s` such that `t = cylinder s S`. `S` is given by `measurableCylinders.set`. -/ noncomputable def measurableCylinders.finset (ht : t ∈ measurableCylinders α) : Finset ι := ((mem_measurableCylinders t).mp ht).choose /-- A set `S` such that `t = cylinder s S`. `s` is given by `measurableCylinders.finset`. -/ def measurableCylinders.set (ht : t ∈ measurableCylinders α) : Set (∀ i : measurableCylinders.finset ht, α i) := ((mem_measurableCylinders t).mp ht).choose_spec.choose theorem measurableCylinders.measurableSet (ht : t ∈ measurableCylinders α) : MeasurableSet (measurableCylinders.set ht) := ((mem_measurableCylinders t).mp ht).choose_spec.choose_spec.left theorem measurableCylinders.eq_cylinder (ht : t ∈ measurableCylinders α) : t = cylinder (measurableCylinders.finset ht) (measurableCylinders.set ht) := ((mem_measurableCylinders t).mp ht).choose_spec.choose_spec.right theorem cylinder_mem_measurableCylinders (s : Finset ι) (S : Set (∀ i : s, α i)) (hS : MeasurableSet S) : cylinder s S ∈ measurableCylinders α := by rw [mem_measurableCylinders]; exact ⟨s, S, hS, rfl⟩ theorem inter_mem_measurableCylinders (hs : s ∈ measurableCylinders α) (ht : t ∈ measurableCylinders α) : s ∩ t ∈ measurableCylinders α := by rw [mem_measurableCylinders] at * obtain ⟨s₁, S₁, hS₁, rfl⟩ := hs obtain ⟨s₂, S₂, hS₂, rfl⟩ := ht classical refine ⟨s₁ ∪ s₂, (fun f ↦ (fun i ↦ f ⟨i, Finset.mem_union_left s₂ i.prop⟩ : ∀ i : s₁, α i)) ⁻¹' S₁ ∩ {f | (fun i ↦ f ⟨i, Finset.mem_union_right s₁ i.prop⟩ : ∀ i : s₂, α i) ∈ S₂}, ?_, ?_⟩ · refine MeasurableSet.inter ?_ ?_ · exact measurable_pi_lambda _ (fun _ ↦ measurable_pi_apply _) hS₁ · exact measurable_pi_lambda _ (fun _ ↦ measurable_pi_apply _) hS₂ · exact inter_cylinder _ _ _ _ theorem isPiSystem_measurableCylinders : IsPiSystem (measurableCylinders α) := fun _ hS _ hT _ ↦ inter_mem_measurableCylinders hS hT theorem compl_mem_measurableCylinders (hs : s ∈ measurableCylinders α) : sᶜ ∈ measurableCylinders α := by rw [mem_measurableCylinders] at hs ⊢ obtain ⟨s, S, hS, rfl⟩ := hs refine ⟨s, Sᶜ, hS.compl, ?_⟩ rw [compl_cylinder] theorem univ_mem_measurableCylinders (α : ι → Type*) [∀ i, MeasurableSpace (α i)] : Set.univ ∈ measurableCylinders α := by rw [← compl_empty]; exact compl_mem_measurableCylinders (empty_mem_measurableCylinders α) theorem union_mem_measurableCylinders (hs : s ∈ measurableCylinders α) (ht : t ∈ measurableCylinders α) : s ∪ t ∈ measurableCylinders α := by rw [union_eq_compl_compl_inter_compl] exact compl_mem_measurableCylinders (inter_mem_measurableCylinders (compl_mem_measurableCylinders hs) (compl_mem_measurableCylinders ht))
Mathlib/MeasureTheory/Constructions/Cylinders.lean
335
339
theorem diff_mem_measurableCylinders (hs : s ∈ measurableCylinders α) (ht : t ∈ measurableCylinders α) : s \ t ∈ measurableCylinders α := by
rw [diff_eq_compl_inter] exact inter_mem_measurableCylinders (compl_mem_measurableCylinders ht) hs
/- Copyright (c) 2020 Alexander Bentkamp, Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp, Sébastien Gouëzel, Eric Wieser -/ import Mathlib.Algebra.CharP.Invertible import Mathlib.Algebra.Order.Module.OrderedSMul import Mathlib.Data.Complex.Cardinality import Mathlib.Data.Fin.VecNotation import Mathlib.LinearAlgebra.FiniteDimensional #align_import data.complex.module from "leanprover-community/mathlib"@"c7bce2818663f456335892ddbdd1809f111a5b72" /-! # Complex number as a vector space over `ℝ` This file contains the following instances: * Any `•`-structure (`SMul`, `MulAction`, `DistribMulAction`, `Module`, `Algebra`) on `ℝ` imbues a corresponding structure on `ℂ`. This includes the statement that `ℂ` is an `ℝ` algebra. * any complex vector space is a real vector space; * any finite dimensional complex vector space is a finite dimensional real vector space; * the space of `ℝ`-linear maps from a real vector space to a complex vector space is a complex vector space. It also defines bundled versions of four standard maps (respectively, the real part, the imaginary part, the embedding of `ℝ` in `ℂ`, and the complex conjugate): * `Complex.reLm` (`ℝ`-linear map); * `Complex.imLm` (`ℝ`-linear map); * `Complex.ofRealAm` (`ℝ`-algebra (homo)morphism); * `Complex.conjAe` (`ℝ`-algebra equivalence). It also provides a universal property of the complex numbers `Complex.lift`, which constructs a `ℂ →ₐ[ℝ] A` into any `ℝ`-algebra `A` given a square root of `-1`. In addition, this file provides a decomposition into `realPart` and `imaginaryPart` for any element of a `StarModule` over `ℂ`. ## Notation * `ℜ` and `ℑ` for the `realPart` and `imaginaryPart`, respectively, in the locale `ComplexStarModule`. -/ namespace Complex open ComplexConjugate open scoped SMul variable {R : Type*} {S : Type*} attribute [local ext] Complex.ext -- Test that the `SMul ℚ ℂ` instance is correct. example : (Complex.SMul.instSMulRealComplex : SMul ℚ ℂ) = (Algebra.toSMul : SMul ℚ ℂ) := rfl /- The priority of the following instances has been manually lowered, as when they don't apply they lead Lean to a very costly path, and most often they don't apply (most actions on `ℂ` don't come from actions on `ℝ`). See #11980-/ -- priority manually adjusted in #11980 instance (priority := 90) [SMul R ℝ] [SMul S ℝ] [SMulCommClass R S ℝ] : SMulCommClass R S ℂ where smul_comm r s x := by ext <;> simp [smul_re, smul_im, smul_comm] -- priority manually adjusted in #11980 instance (priority := 90) [SMul R S] [SMul R ℝ] [SMul S ℝ] [IsScalarTower R S ℝ] : IsScalarTower R S ℂ where smul_assoc r s x := by ext <;> simp [smul_re, smul_im, smul_assoc] -- priority manually adjusted in #11980 instance (priority := 90) [SMul R ℝ] [SMul Rᵐᵒᵖ ℝ] [IsCentralScalar R ℝ] : IsCentralScalar R ℂ where op_smul_eq_smul r x := by ext <;> simp [smul_re, smul_im, op_smul_eq_smul] -- priority manually adjusted in #11980 instance (priority := 90) mulAction [Monoid R] [MulAction R ℝ] : MulAction R ℂ where one_smul x := by ext <;> simp [smul_re, smul_im, one_smul] mul_smul r s x := by ext <;> simp [smul_re, smul_im, mul_smul] -- priority manually adjusted in #11980 instance (priority := 90) distribSMul [DistribSMul R ℝ] : DistribSMul R ℂ where smul_add r x y := by ext <;> simp [smul_re, smul_im, smul_add] smul_zero r := by ext <;> simp [smul_re, smul_im, smul_zero] -- priority manually adjusted in #11980 instance (priority := 90) [Semiring R] [DistribMulAction R ℝ] : DistribMulAction R ℂ := { Complex.distribSMul, Complex.mulAction with } -- priority manually adjusted in #11980 instance (priority := 100) instModule [Semiring R] [Module R ℝ] : Module R ℂ where add_smul r s x := by ext <;> simp [smul_re, smul_im, add_smul] zero_smul r := by ext <;> simp [smul_re, smul_im, zero_smul] -- priority manually adjusted in #11980 instance (priority := 95) instAlgebraOfReal [CommSemiring R] [Algebra R ℝ] : Algebra R ℂ := { Complex.ofReal.comp (algebraMap R ℝ) with smul := (· • ·) smul_def' := fun r x => by ext <;> simp [smul_re, smul_im, Algebra.smul_def] commutes' := fun r ⟨xr, xi⟩ => by ext <;> simp [smul_re, smul_im, Algebra.commutes] } instance : StarModule ℝ ℂ := ⟨fun r x => by simp only [star_def, star_trivial, real_smul, map_mul, conj_ofReal]⟩ @[simp] theorem coe_algebraMap : (algebraMap ℝ ℂ : ℝ → ℂ) = ((↑) : ℝ → ℂ) := rfl #align complex.coe_algebra_map Complex.coe_algebraMap section variable {A : Type*} [Semiring A] [Algebra ℝ A] /-- We need this lemma since `Complex.coe_algebraMap` diverts the simp-normal form away from `AlgHom.commutes`. -/ @[simp] theorem _root_.AlgHom.map_coe_real_complex (f : ℂ →ₐ[ℝ] A) (x : ℝ) : f x = algebraMap ℝ A x := f.commutes x #align alg_hom.map_coe_real_complex AlgHom.map_coe_real_complex /-- Two `ℝ`-algebra homomorphisms from `ℂ` are equal if they agree on `Complex.I`. -/ @[ext] theorem algHom_ext ⦃f g : ℂ →ₐ[ℝ] A⦄ (h : f I = g I) : f = g := by ext ⟨x, y⟩ simp only [mk_eq_add_mul_I, AlgHom.map_add, AlgHom.map_coe_real_complex, AlgHom.map_mul, h] #align complex.alg_hom_ext Complex.algHom_ext end open Submodule FiniteDimensional /-- `ℂ` has a basis over `ℝ` given by `1` and `I`. -/ noncomputable def basisOneI : Basis (Fin 2) ℝ ℂ := Basis.ofEquivFun { toFun := fun z => ![z.re, z.im] invFun := fun c => c 0 + c 1 • I left_inv := fun z => by simp right_inv := fun c => by ext i fin_cases i <;> simp map_add' := fun z z' => by simp map_smul' := fun c z => by simp } set_option linter.uppercaseLean3 false in #align complex.basis_one_I Complex.basisOneI @[simp] theorem coe_basisOneI_repr (z : ℂ) : ⇑(basisOneI.repr z) = ![z.re, z.im] := rfl set_option linter.uppercaseLean3 false in #align complex.coe_basis_one_I_repr Complex.coe_basisOneI_repr @[simp] theorem coe_basisOneI : ⇑basisOneI = ![1, I] := funext fun i => Basis.apply_eq_iff.mpr <| Finsupp.ext fun j => by fin_cases i <;> fin_cases j <;> -- Porting note: removed `only`, consider squeezing again simp [coe_basisOneI_repr, Finsupp.single_eq_of_ne, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.head_cons, Fin.one_eq_zero_iff, Ne, not_false_iff, I_re, Nat.succ_succ_ne_one, one_im, I_im, one_re, Finsupp.single_eq_same, Fin.zero_eq_one_iff] set_option linter.uppercaseLean3 false in #align complex.coe_basis_one_I Complex.coe_basisOneI instance : FiniteDimensional ℝ ℂ := of_fintype_basis basisOneI @[simp] theorem finrank_real_complex : FiniteDimensional.finrank ℝ ℂ = 2 := by rw [finrank_eq_card_basis basisOneI, Fintype.card_fin] #align complex.finrank_real_complex Complex.finrank_real_complex @[simp] theorem rank_real_complex : Module.rank ℝ ℂ = 2 := by simp [← finrank_eq_rank, finrank_real_complex] #align complex.rank_real_complex Complex.rank_real_complex theorem rank_real_complex'.{u} : Cardinal.lift.{u} (Module.rank ℝ ℂ) = 2 := by rw [← finrank_eq_rank, finrank_real_complex, Cardinal.lift_natCast, Nat.cast_ofNat] #align complex.rank_real_complex' Complex.rank_real_complex' /-- `Fact` version of the dimension of `ℂ` over `ℝ`, locally useful in the definition of the circle. -/ theorem finrank_real_complex_fact : Fact (finrank ℝ ℂ = 2) := ⟨finrank_real_complex⟩ #align complex.finrank_real_complex_fact Complex.finrank_real_complex_fact end Complex /- Register as an instance (with low priority) the fact that a complex vector space is also a real vector space. -/ instance (priority := 900) Module.complexToReal (E : Type*) [AddCommGroup E] [Module ℂ E] : Module ℝ E := RestrictScalars.module ℝ ℂ E #align module.complex_to_real Module.complexToReal /- Register as an instance (with low priority) the fact that a complex algebra is also a real algebra. -/ instance (priority := 900) Algebra.complexToReal {A : Type*} [Semiring A] [Algebra ℂ A] : Algebra ℝ A := RestrictScalars.algebra ℝ ℂ A -- try to make sure we're not introducing diamonds but we will need -- `reducible_and_instances` which currently fails #10906 example : Prod.algebra ℝ ℂ ℂ = (Prod.algebra ℂ ℂ ℂ).complexToReal := rfl -- try to make sure we're not introducing diamonds but we will need -- `reducible_and_instances` which currently fails #10906 example {ι : Type*} [Fintype ι] : Pi.algebra (R := ℝ) ι (fun _ ↦ ℂ) = (Pi.algebra (R := ℂ) ι (fun _ ↦ ℂ)).complexToReal := rfl example {A : Type*} [Ring A] [inst : Algebra ℂ A] : (inst.complexToReal).toModule = (inst.toModule).complexToReal := by with_reducible_and_instances rfl @[simp, norm_cast] theorem Complex.coe_smul {E : Type*} [AddCommGroup E] [Module ℂ E] (x : ℝ) (y : E) : (x : ℂ) • y = x • y := rfl #align complex.coe_smul Complex.coe_smul /-- The scalar action of `ℝ` on a `ℂ`-module `E` induced by `Module.complexToReal` commutes with another scalar action of `M` on `E` whenever the action of `ℂ` commutes with the action of `M`. -/ instance (priority := 900) SMulCommClass.complexToReal {M E : Type*} [AddCommGroup E] [Module ℂ E] [SMul M E] [SMulCommClass ℂ M E] : SMulCommClass ℝ M E where smul_comm r _ _ := (smul_comm (r : ℂ) _ _ : _) #align smul_comm_class.complex_to_real SMulCommClass.complexToReal /-- The scalar action of `ℝ` on a `ℂ`-module `E` induced by `Module.complexToReal` associates with another scalar action of `M` on `E` whenever the action of `ℂ` associates with the action of `M`. -/ instance IsScalarTower.complexToReal {M E : Type*} [AddCommGroup M] [Module ℂ M] [AddCommGroup E] [Module ℂ E] [SMul M E] [IsScalarTower ℂ M E] : IsScalarTower ℝ M E where smul_assoc r _ _ := (smul_assoc (r : ℂ) _ _ : _) #align module.real_complex_tower IsScalarTower.complexToReal -- check that the following instance is implied by the one above. example (E : Type*) [AddCommGroup E] [Module ℂ E] : IsScalarTower ℝ ℂ E := inferInstance instance (priority := 100) FiniteDimensional.complexToReal (E : Type*) [AddCommGroup E] [Module ℂ E] [FiniteDimensional ℂ E] : FiniteDimensional ℝ E := FiniteDimensional.trans ℝ ℂ E #align finite_dimensional.complex_to_real FiniteDimensional.complexToReal theorem rank_real_of_complex (E : Type*) [AddCommGroup E] [Module ℂ E] : Module.rank ℝ E = 2 * Module.rank ℂ E := Cardinal.lift_inj.1 <| by rw [← lift_rank_mul_lift_rank ℝ ℂ E, Complex.rank_real_complex'] simp only [Cardinal.lift_id'] #align rank_real_of_complex rank_real_of_complex theorem finrank_real_of_complex (E : Type*) [AddCommGroup E] [Module ℂ E] : FiniteDimensional.finrank ℝ E = 2 * FiniteDimensional.finrank ℂ E := by rw [← FiniteDimensional.finrank_mul_finrank ℝ ℂ E, Complex.finrank_real_complex] #align finrank_real_of_complex finrank_real_of_complex instance (priority := 900) StarModule.complexToReal {E : Type*} [AddCommGroup E] [Star E] [Module ℂ E] [StarModule ℂ E] : StarModule ℝ E := ⟨fun r a => by rw [← smul_one_smul ℂ r a, star_smul, star_smul, star_one, smul_one_smul]⟩ #align star_module.complex_to_real StarModule.complexToReal namespace Complex open ComplexConjugate /-- Linear map version of the real part function, from `ℂ` to `ℝ`. -/ def reLm : ℂ →ₗ[ℝ] ℝ where toFun x := x.re map_add' := add_re map_smul' := by simp #align complex.re_lm Complex.reLm @[simp] theorem reLm_coe : ⇑reLm = re := rfl #align complex.re_lm_coe Complex.reLm_coe /-- Linear map version of the imaginary part function, from `ℂ` to `ℝ`. -/ def imLm : ℂ →ₗ[ℝ] ℝ where toFun x := x.im map_add' := add_im map_smul' := by simp #align complex.im_lm Complex.imLm @[simp] theorem imLm_coe : ⇑imLm = im := rfl #align complex.im_lm_coe Complex.imLm_coe /-- `ℝ`-algebra morphism version of the canonical embedding of `ℝ` in `ℂ`. -/ def ofRealAm : ℝ →ₐ[ℝ] ℂ := Algebra.ofId ℝ ℂ #align complex.of_real_am Complex.ofRealAm @[simp] theorem ofRealAm_coe : ⇑ofRealAm = ((↑) : ℝ → ℂ) := rfl #align complex.of_real_am_coe Complex.ofRealAm_coe /-- `ℝ`-algebra isomorphism version of the complex conjugation function from `ℂ` to `ℂ` -/ def conjAe : ℂ ≃ₐ[ℝ] ℂ := { conj with invFun := conj left_inv := star_star right_inv := star_star commutes' := conj_ofReal } #align complex.conj_ae Complex.conjAe @[simp] theorem conjAe_coe : ⇑conjAe = conj := rfl #align complex.conj_ae_coe Complex.conjAe_coe /-- The matrix representation of `conjAe`. -/ @[simp]
Mathlib/Data/Complex/Module.lean
317
321
theorem toMatrix_conjAe : LinearMap.toMatrix basisOneI basisOneI conjAe.toLinearMap = !![1, 0; 0, -1] := by
ext i j -- Porting note: replaced non-terminal `simp [LinearMap.toMatrix_apply]` fin_cases i <;> fin_cases j <;> simp [LinearMap.toMatrix_apply]
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Bhavik Mehta, Stuart Presnell -/ import Mathlib.Data.Nat.Factorial.Basic import Mathlib.Order.Monotone.Basic #align_import data.nat.choose.basic from "leanprover-community/mathlib"@"2f3994e1b117b1e1da49bcfb67334f33460c3ce4" /-! # Binomial coefficients This file defines binomial coefficients and proves simple lemmas (i.e. those not requiring more imports). ## Main definition and results * `Nat.choose`: binomial coefficients, defined inductively * `Nat.choose_eq_factorial_div_factorial`: a proof that `choose n k = n! / (k! * (n - k)!)` * `Nat.choose_symm`: symmetry of binomial coefficients * `Nat.choose_le_succ_of_lt_half_left`: `choose n k` is increasing for small values of `k` * `Nat.choose_le_middle`: `choose n r` is maximised when `r` is `n/2` * `Nat.descFactorial_eq_factorial_mul_choose`: Relates binomial coefficients to the descending factorial. This is used to prove `Nat.choose_le_pow` and variants. We provide similar statements for the ascending factorial. * `Nat.multichoose`: whereas `choose` counts combinations, `multichoose` counts multicombinations. The fact that this is indeed the correct counting function for multisets is proved in `Sym.card_sym_eq_multichoose` in `Data.Sym.Card`. * `Nat.multichoose_eq` : a proof that `multichoose n k = (n + k - 1).choose k`. This is central to the "stars and bars" technique in informal mathematics, where we switch between counting multisets of size `k` over an alphabet of size `n` to counting strings of `k` elements ("stars") separated by `n-1` dividers ("bars"). See `Data.Sym.Card` for more detail. ## Tags binomial coefficient, combination, multicombination, stars and bars -/ open Nat namespace Nat /-- `choose n k` is the number of `k`-element subsets in an `n`-element set. Also known as binomial coefficients. -/ def choose : ℕ → ℕ → ℕ | _, 0 => 1 | 0, _ + 1 => 0 | n + 1, k + 1 => choose n k + choose n (k + 1) #align nat.choose Nat.choose @[simp] theorem choose_zero_right (n : ℕ) : choose n 0 = 1 := by cases n <;> rfl #align nat.choose_zero_right Nat.choose_zero_right @[simp] theorem choose_zero_succ (k : ℕ) : choose 0 (succ k) = 0 := rfl #align nat.choose_zero_succ Nat.choose_zero_succ theorem choose_succ_succ (n k : ℕ) : choose (succ n) (succ k) = choose n k + choose n (succ k) := rfl #align nat.choose_succ_succ Nat.choose_succ_succ theorem choose_succ_succ' (n k : ℕ) : choose (n + 1) (k + 1) = choose n k + choose n (k + 1) := rfl theorem choose_eq_zero_of_lt : ∀ {n k}, n < k → choose n k = 0 | _, 0, hk => absurd hk (Nat.not_lt_zero _) | 0, k + 1, _ => choose_zero_succ _ | n + 1, k + 1, hk => by have hnk : n < k := lt_of_succ_lt_succ hk have hnk1 : n < k + 1 := lt_of_succ_lt hk rw [choose_succ_succ, choose_eq_zero_of_lt hnk, choose_eq_zero_of_lt hnk1] #align nat.choose_eq_zero_of_lt Nat.choose_eq_zero_of_lt @[simp] theorem choose_self (n : ℕ) : choose n n = 1 := by induction n <;> simp [*, choose, choose_eq_zero_of_lt (lt_succ_self _)] #align nat.choose_self Nat.choose_self @[simp] theorem choose_succ_self (n : ℕ) : choose n (succ n) = 0 := choose_eq_zero_of_lt (lt_succ_self _) #align nat.choose_succ_self Nat.choose_succ_self @[simp] lemma choose_one_right (n : ℕ) : choose n 1 = n := by induction n <;> simp [*, choose, Nat.add_comm] #align nat.choose_one_right Nat.choose_one_right -- The `n+1`-st triangle number is `n` more than the `n`-th triangle number theorem triangle_succ (n : ℕ) : (n + 1) * (n + 1 - 1) / 2 = n * (n - 1) / 2 + n := by rw [← add_mul_div_left, Nat.mul_comm 2 n, ← Nat.mul_add, Nat.add_sub_cancel, Nat.mul_comm] cases n <;> rfl; apply zero_lt_succ #align nat.triangle_succ Nat.triangle_succ /-- `choose n 2` is the `n`-th triangle number. -/ theorem choose_two_right (n : ℕ) : choose n 2 = n * (n - 1) / 2 := by induction' n with n ih · simp · rw [triangle_succ n, choose, ih] simp [Nat.add_comm] #align nat.choose_two_right Nat.choose_two_right theorem choose_pos : ∀ {n k}, k ≤ n → 0 < choose n k | 0, _, hk => by rw [Nat.eq_zero_of_le_zero hk]; decide | n + 1, 0, _ => by simp | n + 1, k + 1, hk => Nat.add_pos_left (choose_pos (le_of_succ_le_succ hk)) _ #align nat.choose_pos Nat.choose_pos theorem choose_eq_zero_iff {n k : ℕ} : n.choose k = 0 ↔ n < k := ⟨fun h => lt_of_not_ge (mt Nat.choose_pos h.symm.not_lt), Nat.choose_eq_zero_of_lt⟩ #align nat.choose_eq_zero_iff Nat.choose_eq_zero_iff theorem succ_mul_choose_eq : ∀ n k, succ n * choose n k = choose (succ n) (succ k) * succ k | 0, 0 => by decide | 0, k + 1 => by simp [choose] | n + 1, 0 => by simp [choose, mul_succ, succ_eq_add_one, Nat.add_comm] | n + 1, k + 1 => by rw [choose_succ_succ (succ n) (succ k), Nat.add_mul, ← succ_mul_choose_eq n, mul_succ, ← succ_mul_choose_eq n, Nat.add_right_comm, ← Nat.mul_add, ← choose_succ_succ, ← succ_mul] #align nat.succ_mul_choose_eq Nat.succ_mul_choose_eq theorem choose_mul_factorial_mul_factorial : ∀ {n k}, k ≤ n → choose n k * k ! * (n - k)! = n ! | 0, _, hk => by simp [Nat.eq_zero_of_le_zero hk] | n + 1, 0, _ => by simp | n + 1, succ k, hk => by rcases lt_or_eq_of_le hk with hk₁ | hk₁ · have h : choose n k * k.succ ! * (n - k)! = (k + 1) * n ! := by rw [← choose_mul_factorial_mul_factorial (le_of_succ_le_succ hk)] simp [factorial_succ, Nat.mul_comm, Nat.mul_left_comm, Nat.mul_assoc] have h₁ : (n - k)! = (n - k) * (n - k.succ)! := by rw [← succ_sub_succ, succ_sub (le_of_lt_succ hk₁), factorial_succ] have h₂ : choose n (succ k) * k.succ ! * ((n - k) * (n - k.succ)!) = (n - k) * n ! := by rw [← choose_mul_factorial_mul_factorial (le_of_lt_succ hk₁)] simp [factorial_succ, Nat.mul_comm, Nat.mul_left_comm, Nat.mul_assoc] have h₃ : k * n ! ≤ n * n ! := Nat.mul_le_mul_right _ (le_of_succ_le_succ hk) rw [choose_succ_succ, Nat.add_mul, Nat.add_mul, succ_sub_succ, h, h₁, h₂, Nat.add_mul, Nat.mul_sub_right_distrib, factorial_succ, ← Nat.add_sub_assoc h₃, Nat.add_assoc, ← Nat.add_mul, Nat.add_sub_cancel_left, Nat.add_comm] · rw [hk₁]; simp [hk₁, Nat.mul_comm, choose, Nat.sub_self] #align nat.choose_mul_factorial_mul_factorial Nat.choose_mul_factorial_mul_factorial theorem choose_mul {n k s : ℕ} (hkn : k ≤ n) (hsk : s ≤ k) : n.choose k * k.choose s = n.choose s * (n - s).choose (k - s) := have h : 0 < (n - k)! * (k - s)! * s ! := by apply_rules [factorial_pos, Nat.mul_pos] Nat.mul_right_cancel h <| calc n.choose k * k.choose s * ((n - k)! * (k - s)! * s !) = n.choose k * (k.choose s * s ! * (k - s)!) * (n - k)! := by rw [Nat.mul_assoc, Nat.mul_assoc, Nat.mul_assoc, Nat.mul_assoc _ s !, Nat.mul_assoc, Nat.mul_comm (n - k)!, Nat.mul_comm s !] _ = n ! := by rw [choose_mul_factorial_mul_factorial hsk, choose_mul_factorial_mul_factorial hkn] _ = n.choose s * s ! * ((n - s).choose (k - s) * (k - s)! * (n - s - (k - s))!) := by rw [choose_mul_factorial_mul_factorial (Nat.sub_le_sub_right hkn _), choose_mul_factorial_mul_factorial (hsk.trans hkn)] _ = n.choose s * (n - s).choose (k - s) * ((n - k)! * (k - s)! * s !) := by rw [Nat.sub_sub_sub_cancel_right hsk, Nat.mul_assoc, Nat.mul_left_comm s !, Nat.mul_assoc, Nat.mul_comm (k - s)!, Nat.mul_comm s !, Nat.mul_right_comm, ← Nat.mul_assoc] #align nat.choose_mul Nat.choose_mul theorem choose_eq_factorial_div_factorial {n k : ℕ} (hk : k ≤ n) : choose n k = n ! / (k ! * (n - k)!) := by rw [← choose_mul_factorial_mul_factorial hk, Nat.mul_assoc] exact (mul_div_left _ (Nat.mul_pos (factorial_pos _) (factorial_pos _))).symm #align nat.choose_eq_factorial_div_factorial Nat.choose_eq_factorial_div_factorial theorem add_choose (i j : ℕ) : (i + j).choose j = (i + j)! / (i ! * j !) := by rw [choose_eq_factorial_div_factorial (Nat.le_add_left j i), Nat.add_sub_cancel_right, Nat.mul_comm] #align nat.add_choose Nat.add_choose theorem add_choose_mul_factorial_mul_factorial (i j : ℕ) : (i + j).choose j * i ! * j ! = (i + j)! := by rw [← choose_mul_factorial_mul_factorial (Nat.le_add_left _ _), Nat.add_sub_cancel_right, Nat.mul_right_comm] #align nat.add_choose_mul_factorial_mul_factorial Nat.add_choose_mul_factorial_mul_factorial theorem factorial_mul_factorial_dvd_factorial {n k : ℕ} (hk : k ≤ n) : k ! * (n - k)! ∣ n ! := by rw [← choose_mul_factorial_mul_factorial hk, Nat.mul_assoc]; exact Nat.dvd_mul_left _ _ #align nat.factorial_mul_factorial_dvd_factorial Nat.factorial_mul_factorial_dvd_factorial theorem factorial_mul_factorial_dvd_factorial_add (i j : ℕ) : i ! * j ! ∣ (i + j)! := by suffices i ! * (i + j - i) ! ∣ (i + j)! by rwa [Nat.add_sub_cancel_left i j] at this exact factorial_mul_factorial_dvd_factorial (Nat.le_add_right _ _) #align nat.factorial_mul_factorial_dvd_factorial_add Nat.factorial_mul_factorial_dvd_factorial_add @[simp] theorem choose_symm {n k : ℕ} (hk : k ≤ n) : choose n (n - k) = choose n k := by rw [choose_eq_factorial_div_factorial hk, choose_eq_factorial_div_factorial (Nat.sub_le _ _), Nat.sub_sub_self hk, Nat.mul_comm] #align nat.choose_symm Nat.choose_symm theorem choose_symm_of_eq_add {n a b : ℕ} (h : n = a + b) : Nat.choose n a = Nat.choose n b := by suffices choose n (n - b) = choose n b by rw [h, Nat.add_sub_cancel_right] at this; rwa [h] exact choose_symm (h ▸ le_add_left _ _) #align nat.choose_symm_of_eq_add Nat.choose_symm_of_eq_add theorem choose_symm_add {a b : ℕ} : choose (a + b) a = choose (a + b) b := choose_symm_of_eq_add rfl #align nat.choose_symm_add Nat.choose_symm_add theorem choose_symm_half (m : ℕ) : choose (2 * m + 1) (m + 1) = choose (2 * m + 1) m := by apply choose_symm_of_eq_add rw [Nat.add_comm m 1, Nat.add_assoc 1 m m, Nat.add_comm (2 * m) 1, Nat.two_mul m] #align nat.choose_symm_half Nat.choose_symm_half theorem choose_succ_right_eq (n k : ℕ) : choose n (k + 1) * (k + 1) = choose n k * (n - k) := by have e : (n + 1) * choose n k = choose n (k + 1) * (k + 1) + choose n k * (k + 1) := by rw [← Nat.add_mul, Nat.add_comm (choose _ _), ← choose_succ_succ, succ_mul_choose_eq] rw [← Nat.sub_eq_of_eq_add e, Nat.mul_comm, ← Nat.mul_sub_left_distrib, Nat.add_sub_add_right] #align nat.choose_succ_right_eq Nat.choose_succ_right_eq @[simp] theorem choose_succ_self_right : ∀ n : ℕ, (n + 1).choose n = n + 1 | 0 => rfl | n + 1 => by rw [choose_succ_succ, choose_succ_self_right n, choose_self] #align nat.choose_succ_self_right Nat.choose_succ_self_right theorem choose_mul_succ_eq (n k : ℕ) : n.choose k * (n + 1) = (n + 1).choose k * (n + 1 - k) := by cases k with | zero => simp | succ k => obtain hk | hk := le_or_lt (k + 1) (n + 1) · rw [choose_succ_succ, Nat.add_mul, succ_sub_succ, ← choose_succ_right_eq, ← succ_sub_succ, Nat.mul_sub_left_distrib, Nat.add_sub_cancel' (Nat.mul_le_mul_left _ hk)] · rw [choose_eq_zero_of_lt hk, choose_eq_zero_of_lt (n.lt_succ_self.trans hk), Nat.zero_mul, Nat.zero_mul] #align nat.choose_mul_succ_eq Nat.choose_mul_succ_eq theorem ascFactorial_eq_factorial_mul_choose (n k : ℕ) : (n + 1).ascFactorial k = k ! * (n + k).choose k := by rw [Nat.mul_comm] apply Nat.mul_right_cancel (n + k - k).factorial_pos rw [choose_mul_factorial_mul_factorial <| Nat.le_add_left k n, Nat.add_sub_cancel_right, ← factorial_mul_ascFactorial, Nat.mul_comm] #align nat.asc_factorial_eq_factorial_mul_choose Nat.ascFactorial_eq_factorial_mul_choose
Mathlib/Data/Nat/Choose/Basic.lean
243
251
theorem ascFactorial_eq_factorial_mul_choose' (n k : ℕ) : n.ascFactorial k = k ! * (n + k - 1).choose k := by
cases n · cases k · rw [ascFactorial_zero, choose_zero_right, factorial_zero, Nat.mul_one] · simp only [zero_ascFactorial, zero_eq, Nat.zero_add, succ_sub_succ_eq_sub, Nat.le_zero_eq, Nat.sub_zero, choose_succ_self, Nat.mul_zero] rw [ascFactorial_eq_factorial_mul_choose] simp only [succ_add_sub_one]
/- Copyright (c) 2022 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import Mathlib.Topology.Algebra.UniformConvergence #align_import topology.algebra.module.strong_topology from "leanprover-community/mathlib"@"8905e5ed90859939681a725b00f6063e65096d95" /-! # Strong topologies on the space of continuous linear maps In this file, we define the strong topologies on `E →L[𝕜] F` associated with a family `𝔖 : Set (Set E)` to be the topology of uniform convergence on the elements of `𝔖` (also called the topology of `𝔖`-convergence). The lemma `UniformOnFun.continuousSMul_of_image_bounded` tells us that this is a vector space topology if the continuous linear image of any element of `𝔖` is bounded (in the sense of `Bornology.IsVonNBounded`). We then declare an instance for the case where `𝔖` is exactly the set of all bounded subsets of `E`, giving us the so-called "topology of uniform convergence on bounded sets" (or "topology of bounded convergence"), which coincides with the operator norm topology in the case of `NormedSpace`s. Other useful examples include the weak-* topology (when `𝔖` is the set of finite sets or the set of singletons) and the topology of compact convergence (when `𝔖` is the set of relatively compact sets). ## Main definitions * `UniformConvergenceCLM` is a type synonym for `E →SL[σ] F` equipped with the `𝔖`-topology. * `UniformConvergenceCLM.instTopologicalSpace` is the topology mentioned above for an arbitrary `𝔖`. * `ContinuousLinearMap.topologicalSpace` is the topology of bounded convergence. This is declared as an instance. ## Main statements * `UniformConvergenceCLM.instTopologicalAddGroup` and `UniformConvergenceCLM.instContinuousSMul` show that the strong topology makes `E →L[𝕜] F` a topological vector space, with the assumptions on `𝔖` mentioned above. * `ContinuousLinearMap.topologicalAddGroup` and `ContinuousLinearMap.continuousSMul` register these facts as instances for the special case of bounded convergence. ## References * [N. Bourbaki, *Topological Vector Spaces*][bourbaki1987] ## TODO * Add convergence on compact subsets ## Tags uniform convergence, bounded convergence -/ open scoped Topology UniformConvergence section General /-! ### 𝔖-Topologies -/ variable {𝕜₁ 𝕜₂ : Type*} [NormedField 𝕜₁] [NormedField 𝕜₂] (σ : 𝕜₁ →+* 𝕜₂) {E E' F F' : Type*} [AddCommGroup E] [Module 𝕜₁ E] [AddCommGroup E'] [Module ℝ E'] [AddCommGroup F] [Module 𝕜₂ F] [AddCommGroup F'] [Module ℝ F'] [TopologicalSpace E] [TopologicalSpace E'] (F) /-- Given `E` and `F` two topological vector spaces and `𝔖 : Set (Set E)`, then `UniformConvergenceCLM σ F 𝔖` is a type synonym of `E →SL[σ] F` equipped with the "topology of uniform convergence on the elements of `𝔖`". If the continuous linear image of any element of `𝔖` is bounded, this makes `E →SL[σ] F` a topological vector space. -/ @[nolint unusedArguments] def UniformConvergenceCLM [TopologicalSpace F] [TopologicalAddGroup F] (_ : Set (Set E)) := E →SL[σ] F namespace UniformConvergenceCLM instance instFunLike [TopologicalSpace F] [TopologicalAddGroup F] (𝔖 : Set (Set E)) : FunLike (UniformConvergenceCLM σ F 𝔖) E F := ContinuousLinearMap.funLike instance instContinuousSemilinearMapClass [TopologicalSpace F] [TopologicalAddGroup F] (𝔖 : Set (Set E)) : ContinuousSemilinearMapClass (UniformConvergenceCLM σ F 𝔖) σ E F := ContinuousLinearMap.continuousSemilinearMapClass instance instTopologicalSpace [TopologicalSpace F] [TopologicalAddGroup F] (𝔖 : Set (Set E)) : TopologicalSpace (UniformConvergenceCLM σ F 𝔖) := (@UniformOnFun.topologicalSpace E F (TopologicalAddGroup.toUniformSpace F) 𝔖).induced (DFunLike.coe : (UniformConvergenceCLM σ F 𝔖) → (E →ᵤ[𝔖] F)) #align continuous_linear_map.strong_topology UniformConvergenceCLM.instTopologicalSpace theorem topologicalSpace_eq [UniformSpace F] [UniformAddGroup F] (𝔖 : Set (Set E)) : instTopologicalSpace σ F 𝔖 = TopologicalSpace.induced DFunLike.coe (UniformOnFun.topologicalSpace E F 𝔖) := by rw [instTopologicalSpace] congr exact UniformAddGroup.toUniformSpace_eq /-- The uniform structure associated with `ContinuousLinearMap.strongTopology`. We make sure that this has nice definitional properties. -/ instance instUniformSpace [UniformSpace F] [UniformAddGroup F] (𝔖 : Set (Set E)) : UniformSpace (UniformConvergenceCLM σ F 𝔖) := UniformSpace.replaceTopology ((UniformOnFun.uniformSpace E F 𝔖).comap (DFunLike.coe : (UniformConvergenceCLM σ F 𝔖) → (E →ᵤ[𝔖] F))) (by rw [UniformConvergenceCLM.instTopologicalSpace, UniformAddGroup.toUniformSpace_eq]; rfl) #align continuous_linear_map.strong_uniformity UniformConvergenceCLM.instUniformSpace theorem uniformSpace_eq [UniformSpace F] [UniformAddGroup F] (𝔖 : Set (Set E)) : instUniformSpace σ F 𝔖 = UniformSpace.comap DFunLike.coe (UniformOnFun.uniformSpace E F 𝔖) := by rw [instUniformSpace, UniformSpace.replaceTopology_eq] @[simp] theorem uniformity_toTopologicalSpace_eq [UniformSpace F] [UniformAddGroup F] (𝔖 : Set (Set E)) : (UniformConvergenceCLM.instUniformSpace σ F 𝔖).toTopologicalSpace = UniformConvergenceCLM.instTopologicalSpace σ F 𝔖 := rfl #align continuous_linear_map.strong_uniformity_topology_eq UniformConvergenceCLM.uniformity_toTopologicalSpace_eq theorem uniformEmbedding_coeFn [UniformSpace F] [UniformAddGroup F] (𝔖 : Set (Set E)) : UniformEmbedding (α := UniformConvergenceCLM σ F 𝔖) (β := E →ᵤ[𝔖] F) DFunLike.coe := ⟨⟨rfl⟩, DFunLike.coe_injective⟩ #align continuous_linear_map.strong_uniformity.uniform_embedding_coe_fn UniformConvergenceCLM.uniformEmbedding_coeFn theorem embedding_coeFn [UniformSpace F] [UniformAddGroup F] (𝔖 : Set (Set E)) : Embedding (X := UniformConvergenceCLM σ F 𝔖) (Y := E →ᵤ[𝔖] F) (UniformOnFun.ofFun 𝔖 ∘ DFunLike.coe) := UniformEmbedding.embedding (uniformEmbedding_coeFn _ _ _) #align continuous_linear_map.strong_topology.embedding_coe_fn UniformConvergenceCLM.embedding_coeFn instance instAddCommGroup [TopologicalSpace F] [TopologicalAddGroup F] (𝔖 : Set (Set E)) : AddCommGroup (UniformConvergenceCLM σ F 𝔖) := ContinuousLinearMap.addCommGroup instance instUniformAddGroup [UniformSpace F] [UniformAddGroup F] (𝔖 : Set (Set E)) : UniformAddGroup (UniformConvergenceCLM σ F 𝔖) := by let φ : (UniformConvergenceCLM σ F 𝔖) →+ E →ᵤ[𝔖] F := ⟨⟨(DFunLike.coe : (UniformConvergenceCLM σ F 𝔖) → E →ᵤ[𝔖] F), rfl⟩, fun _ _ => rfl⟩ exact (uniformEmbedding_coeFn _ _ _).uniformAddGroup φ #align continuous_linear_map.strong_uniformity.uniform_add_group UniformConvergenceCLM.instUniformAddGroup instance instTopologicalAddGroup [TopologicalSpace F] [TopologicalAddGroup F] (𝔖 : Set (Set E)) : TopologicalAddGroup (UniformConvergenceCLM σ F 𝔖) := by letI : UniformSpace F := TopologicalAddGroup.toUniformSpace F haveI : UniformAddGroup F := comm_topologicalAddGroup_is_uniform infer_instance #align continuous_linear_map.strong_topology.topological_add_group UniformConvergenceCLM.instTopologicalAddGroup theorem t2Space [TopologicalSpace F] [TopologicalAddGroup F] [T2Space F] (𝔖 : Set (Set E)) (h𝔖 : ⋃₀ 𝔖 = Set.univ) : T2Space (UniformConvergenceCLM σ F 𝔖) := by letI : UniformSpace F := TopologicalAddGroup.toUniformSpace F haveI : UniformAddGroup F := comm_topologicalAddGroup_is_uniform haveI : T2Space (E →ᵤ[𝔖] F) := UniformOnFun.t2Space_of_covering h𝔖 exact (embedding_coeFn σ F 𝔖).t2Space #align continuous_linear_map.strong_topology.t2_space UniformConvergenceCLM.t2Space instance instDistribMulAction (M : Type*) [Monoid M] [DistribMulAction M F] [SMulCommClass 𝕜₂ M F] [TopologicalSpace F] [TopologicalAddGroup F] [ContinuousConstSMul M F] (𝔖 : Set (Set E)) : DistribMulAction M (UniformConvergenceCLM σ F 𝔖) := ContinuousLinearMap.distribMulAction instance instModule (R : Type*) [Semiring R] [Module R F] [SMulCommClass 𝕜₂ R F] [TopologicalSpace F] [ContinuousConstSMul R F] [TopologicalAddGroup F] (𝔖 : Set (Set E)) : Module R (UniformConvergenceCLM σ F 𝔖) := ContinuousLinearMap.module theorem continuousSMul [RingHomSurjective σ] [RingHomIsometric σ] [TopologicalSpace F] [TopologicalAddGroup F] [ContinuousSMul 𝕜₂ F] (𝔖 : Set (Set E)) (h𝔖₃ : ∀ S ∈ 𝔖, Bornology.IsVonNBounded 𝕜₁ S) : ContinuousSMul 𝕜₂ (UniformConvergenceCLM σ F 𝔖) := by letI : UniformSpace F := TopologicalAddGroup.toUniformSpace F haveI : UniformAddGroup F := comm_topologicalAddGroup_is_uniform let φ : (UniformConvergenceCLM σ F 𝔖) →ₗ[𝕜₂] E → F := ⟨⟨DFunLike.coe, fun _ _ => rfl⟩, fun _ _ => rfl⟩ exact UniformOnFun.continuousSMul_induced_of_image_bounded 𝕜₂ E F (UniformConvergenceCLM σ F 𝔖) φ ⟨rfl⟩ fun u s hs => (h𝔖₃ s hs).image u #align continuous_linear_map.strong_topology.has_continuous_smul UniformConvergenceCLM.continuousSMul theorem hasBasis_nhds_zero_of_basis [TopologicalSpace F] [TopologicalAddGroup F] {ι : Type*} (𝔖 : Set (Set E)) (h𝔖₁ : 𝔖.Nonempty) (h𝔖₂ : DirectedOn (· ⊆ ·) 𝔖) {p : ι → Prop} {b : ι → Set F} (h : (𝓝 0 : Filter F).HasBasis p b) : (𝓝 (0 : UniformConvergenceCLM σ F 𝔖)).HasBasis (fun Si : Set E × ι => Si.1 ∈ 𝔖 ∧ p Si.2) fun Si => { f : E →SL[σ] F | ∀ x ∈ Si.1, f x ∈ b Si.2 } := by letI : UniformSpace F := TopologicalAddGroup.toUniformSpace F haveI : UniformAddGroup F := comm_topologicalAddGroup_is_uniform rw [(embedding_coeFn σ F 𝔖).toInducing.nhds_eq_comap] exact (UniformOnFun.hasBasis_nhds_zero_of_basis 𝔖 h𝔖₁ h𝔖₂ h).comap DFunLike.coe #align continuous_linear_map.strong_topology.has_basis_nhds_zero_of_basis UniformConvergenceCLM.hasBasis_nhds_zero_of_basis theorem hasBasis_nhds_zero [TopologicalSpace F] [TopologicalAddGroup F] (𝔖 : Set (Set E)) (h𝔖₁ : 𝔖.Nonempty) (h𝔖₂ : DirectedOn (· ⊆ ·) 𝔖) : (𝓝 (0 : UniformConvergenceCLM σ F 𝔖)).HasBasis (fun SV : Set E × Set F => SV.1 ∈ 𝔖 ∧ SV.2 ∈ (𝓝 0 : Filter F)) fun SV => { f : UniformConvergenceCLM σ F 𝔖 | ∀ x ∈ SV.1, f x ∈ SV.2 } := hasBasis_nhds_zero_of_basis σ F 𝔖 h𝔖₁ h𝔖₂ (𝓝 0).basis_sets #align continuous_linear_map.strong_topology.has_basis_nhds_zero UniformConvergenceCLM.hasBasis_nhds_zero instance instUniformContinuousConstSMul (M : Type*) [Monoid M] [DistribMulAction M F] [SMulCommClass 𝕜₂ M F] [UniformSpace F] [UniformAddGroup F] [UniformContinuousConstSMul M F] (𝔖 : Set (Set E)) : UniformContinuousConstSMul M (UniformConvergenceCLM σ F 𝔖) := (uniformEmbedding_coeFn σ F 𝔖).toUniformInducing.uniformContinuousConstSMul fun _ _ ↦ by rfl instance instContinuousConstSMul (M : Type*) [Monoid M] [DistribMulAction M F] [SMulCommClass 𝕜₂ M F] [TopologicalSpace F] [TopologicalAddGroup F] [ContinuousConstSMul M F] (𝔖 : Set (Set E)) : ContinuousConstSMul M (UniformConvergenceCLM σ F 𝔖) := let _ := TopologicalAddGroup.toUniformSpace F have _ : UniformAddGroup F := comm_topologicalAddGroup_is_uniform have _ := uniformContinuousConstSMul_of_continuousConstSMul M F inferInstance theorem tendsto_iff_tendstoUniformlyOn {ι : Type*} {p : Filter ι} [UniformSpace F] [UniformAddGroup F] (𝔖 : Set (Set E)) {a : ι → UniformConvergenceCLM σ F 𝔖} {a₀ : UniformConvergenceCLM σ F 𝔖} : Filter.Tendsto a p (𝓝 a₀) ↔ ∀ s ∈ 𝔖, TendstoUniformlyOn (a · ·) a₀ p s := by rw [(embedding_coeFn σ F 𝔖).tendsto_nhds_iff, UniformOnFun.tendsto_iff_tendstoUniformlyOn] rfl variable {𝔖₁ 𝔖₂ : Set (Set E)} theorem uniformSpace_mono [UniformSpace F] [UniformAddGroup F] (h : 𝔖₂ ⊆ 𝔖₁) : instUniformSpace σ F 𝔖₁ ≤ instUniformSpace σ F 𝔖₂ := by simp_rw [uniformSpace_eq] exact UniformSpace.comap_mono (UniformOnFun.mono (le_refl _) h)
Mathlib/Topology/Algebra/Module/StrongTopology.lean
229
234
theorem topologicalSpace_mono [TopologicalSpace F] [TopologicalAddGroup F] (h : 𝔖₂ ⊆ 𝔖₁) : instTopologicalSpace σ F 𝔖₁ ≤ instTopologicalSpace σ F 𝔖₂ := by
letI := TopologicalAddGroup.toUniformSpace F haveI : UniformAddGroup F := comm_topologicalAddGroup_is_uniform simp_rw [← uniformity_toTopologicalSpace_eq] exact UniformSpace.toTopologicalSpace_mono (uniformSpace_mono σ F h)
/- 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.Algebra.Order.Monoid.Unbundled.Pow import Mathlib.Data.Finset.Fold import Mathlib.Data.Finset.Option import Mathlib.Data.Finset.Pi import Mathlib.Data.Finset.Prod import Mathlib.Data.Multiset.Lattice import Mathlib.Data.Set.Lattice import Mathlib.Order.Hom.Lattice import Mathlib.Order.Nat #align_import data.finset.lattice from "leanprover-community/mathlib"@"442a83d738cb208d3600056c489be16900ba701d" /-! # Lattice operations on finsets -/ -- TODO: -- assert_not_exists OrderedCommMonoid assert_not_exists MonoidWithZero open Function Multiset OrderDual variable {F α β γ ι κ : Type*} namespace Finset /-! ### sup -/ section Sup -- TODO: define with just `[Bot α]` where some lemmas hold without requiring `[OrderBot α]` variable [SemilatticeSup α] [OrderBot α] /-- Supremum of a finite set: `sup {a, b, c} f = f a ⊔ f b ⊔ f c` -/ def sup (s : Finset β) (f : β → α) : α := s.fold (· ⊔ ·) ⊥ f #align finset.sup Finset.sup variable {s s₁ s₂ : Finset β} {f g : β → α} {a : α} theorem sup_def : s.sup f = (s.1.map f).sup := rfl #align finset.sup_def Finset.sup_def @[simp] theorem sup_empty : (∅ : Finset β).sup f = ⊥ := fold_empty #align finset.sup_empty Finset.sup_empty @[simp] theorem sup_cons {b : β} (h : b ∉ s) : (cons b s h).sup f = f b ⊔ s.sup f := fold_cons h #align finset.sup_cons Finset.sup_cons @[simp] theorem sup_insert [DecidableEq β] {b : β} : (insert b s : Finset β).sup f = f b ⊔ s.sup f := fold_insert_idem #align finset.sup_insert Finset.sup_insert @[simp] theorem sup_image [DecidableEq β] (s : Finset γ) (f : γ → β) (g : β → α) : (s.image f).sup g = s.sup (g ∘ f) := fold_image_idem #align finset.sup_image Finset.sup_image @[simp] theorem sup_map (s : Finset γ) (f : γ ↪ β) (g : β → α) : (s.map f).sup g = s.sup (g ∘ f) := fold_map #align finset.sup_map Finset.sup_map @[simp] theorem sup_singleton {b : β} : ({b} : Finset β).sup f = f b := Multiset.sup_singleton #align finset.sup_singleton Finset.sup_singleton theorem sup_sup : s.sup (f ⊔ g) = s.sup f ⊔ s.sup g := by induction s using Finset.cons_induction with | empty => rw [sup_empty, sup_empty, sup_empty, bot_sup_eq] | cons _ _ _ ih => rw [sup_cons, sup_cons, sup_cons, ih] exact sup_sup_sup_comm _ _ _ _ #align finset.sup_sup Finset.sup_sup theorem sup_congr {f g : β → α} (hs : s₁ = s₂) (hfg : ∀ a ∈ s₂, f a = g a) : s₁.sup f = s₂.sup g := by subst hs exact Finset.fold_congr hfg #align finset.sup_congr Finset.sup_congr @[simp] theorem _root_.map_finset_sup [SemilatticeSup β] [OrderBot β] [FunLike F α β] [SupBotHomClass F α β] (f : F) (s : Finset ι) (g : ι → α) : f (s.sup g) = s.sup (f ∘ g) := Finset.cons_induction_on s (map_bot f) fun i s _ h => by rw [sup_cons, sup_cons, map_sup, h, Function.comp_apply] #align map_finset_sup map_finset_sup @[simp] protected theorem sup_le_iff {a : α} : s.sup f ≤ a ↔ ∀ b ∈ s, f b ≤ a := by apply Iff.trans Multiset.sup_le simp only [Multiset.mem_map, and_imp, exists_imp] exact ⟨fun k b hb => k _ _ hb rfl, fun k a' b hb h => h ▸ k _ hb⟩ #align finset.sup_le_iff Finset.sup_le_iff protected alias ⟨_, sup_le⟩ := Finset.sup_le_iff #align finset.sup_le Finset.sup_le theorem sup_const_le : (s.sup fun _ => a) ≤ a := Finset.sup_le fun _ _ => le_rfl #align finset.sup_const_le Finset.sup_const_le theorem le_sup {b : β} (hb : b ∈ s) : f b ≤ s.sup f := Finset.sup_le_iff.1 le_rfl _ hb #align finset.le_sup Finset.le_sup theorem le_sup_of_le {b : β} (hb : b ∈ s) (h : a ≤ f b) : a ≤ s.sup f := h.trans <| le_sup hb #align finset.le_sup_of_le Finset.le_sup_of_le theorem sup_union [DecidableEq β] : (s₁ ∪ s₂).sup f = s₁.sup f ⊔ s₂.sup f := eq_of_forall_ge_iff fun c => by simp [or_imp, forall_and] #align finset.sup_union Finset.sup_union @[simp] theorem sup_biUnion [DecidableEq β] (s : Finset γ) (t : γ → Finset β) : (s.biUnion t).sup f = s.sup fun x => (t x).sup f := eq_of_forall_ge_iff fun c => by simp [@forall_swap _ β] #align finset.sup_bUnion Finset.sup_biUnion theorem sup_const {s : Finset β} (h : s.Nonempty) (c : α) : (s.sup fun _ => c) = c := eq_of_forall_ge_iff (fun _ => Finset.sup_le_iff.trans h.forall_const) #align finset.sup_const Finset.sup_const @[simp] theorem sup_bot (s : Finset β) : (s.sup fun _ => ⊥) = (⊥ : α) := by obtain rfl | hs := s.eq_empty_or_nonempty · exact sup_empty · exact sup_const hs _ #align finset.sup_bot Finset.sup_bot theorem sup_ite (p : β → Prop) [DecidablePred p] : (s.sup fun i => ite (p i) (f i) (g i)) = (s.filter p).sup f ⊔ (s.filter fun i => ¬p i).sup g := fold_ite _ #align finset.sup_ite Finset.sup_ite theorem sup_mono_fun {g : β → α} (h : ∀ b ∈ s, f b ≤ g b) : s.sup f ≤ s.sup g := Finset.sup_le fun b hb => le_trans (h b hb) (le_sup hb) #align finset.sup_mono_fun Finset.sup_mono_fun @[gcongr] theorem sup_mono (h : s₁ ⊆ s₂) : s₁.sup f ≤ s₂.sup f := Finset.sup_le (fun _ hb => le_sup (h hb)) #align finset.sup_mono Finset.sup_mono protected theorem sup_comm (s : Finset β) (t : Finset γ) (f : β → γ → α) : (s.sup fun b => t.sup (f b)) = t.sup fun c => s.sup fun b => f b c := eq_of_forall_ge_iff fun a => by simpa using forall₂_swap #align finset.sup_comm Finset.sup_comm @[simp, nolint simpNF] -- Porting note: linter claims that LHS does not simplify theorem sup_attach (s : Finset β) (f : β → α) : (s.attach.sup fun x => f x) = s.sup f := (s.attach.sup_map (Function.Embedding.subtype _) f).symm.trans <| congr_arg _ attach_map_val #align finset.sup_attach Finset.sup_attach /-- See also `Finset.product_biUnion`. -/ theorem sup_product_left (s : Finset β) (t : Finset γ) (f : β × γ → α) : (s ×ˢ t).sup f = s.sup fun i => t.sup fun i' => f ⟨i, i'⟩ := eq_of_forall_ge_iff fun a => by simp [@forall_swap _ γ] #align finset.sup_product_left Finset.sup_product_left theorem sup_product_right (s : Finset β) (t : Finset γ) (f : β × γ → α) : (s ×ˢ t).sup f = t.sup fun i' => s.sup fun i => f ⟨i, i'⟩ := by rw [sup_product_left, Finset.sup_comm] #align finset.sup_product_right Finset.sup_product_right section Prod variable {ι κ α β : Type*} [SemilatticeSup α] [SemilatticeSup β] [OrderBot α] [OrderBot β] {s : Finset ι} {t : Finset κ} @[simp] lemma sup_prodMap (hs : s.Nonempty) (ht : t.Nonempty) (f : ι → α) (g : κ → β) : sup (s ×ˢ t) (Prod.map f g) = (sup s f, sup t g) := eq_of_forall_ge_iff fun i ↦ by obtain ⟨a, ha⟩ := hs obtain ⟨b, hb⟩ := ht simp only [Prod.map, Finset.sup_le_iff, mem_product, and_imp, Prod.forall, Prod.le_def] exact ⟨fun h ↦ ⟨fun i hi ↦ (h _ _ hi hb).1, fun j hj ↦ (h _ _ ha hj).2⟩, by aesop⟩ end Prod @[simp] theorem sup_erase_bot [DecidableEq α] (s : Finset α) : (s.erase ⊥).sup id = s.sup id := by refine (sup_mono (s.erase_subset _)).antisymm (Finset.sup_le_iff.2 fun a ha => ?_) obtain rfl | ha' := eq_or_ne a ⊥ · exact bot_le · exact le_sup (mem_erase.2 ⟨ha', ha⟩) #align finset.sup_erase_bot Finset.sup_erase_bot theorem sup_sdiff_right {α β : Type*} [GeneralizedBooleanAlgebra α] (s : Finset β) (f : β → α) (a : α) : (s.sup fun b => f b \ a) = s.sup f \ a := by induction s using Finset.cons_induction with | empty => rw [sup_empty, sup_empty, bot_sdiff] | cons _ _ _ h => rw [sup_cons, sup_cons, h, sup_sdiff] #align finset.sup_sdiff_right Finset.sup_sdiff_right theorem comp_sup_eq_sup_comp [SemilatticeSup γ] [OrderBot γ] {s : Finset β} {f : β → α} (g : α → γ) (g_sup : ∀ x y, g (x ⊔ y) = g x ⊔ g y) (bot : g ⊥ = ⊥) : g (s.sup f) = s.sup (g ∘ f) := Finset.cons_induction_on s bot fun c t hc ih => by rw [sup_cons, sup_cons, g_sup, ih, Function.comp_apply] #align finset.comp_sup_eq_sup_comp Finset.comp_sup_eq_sup_comp /-- Computing `sup` in a subtype (closed under `sup`) is the same as computing it in `α`. -/ theorem sup_coe {P : α → Prop} {Pbot : P ⊥} {Psup : ∀ ⦃x y⦄, P x → P y → P (x ⊔ y)} (t : Finset β) (f : β → { x : α // P x }) : (@sup { x // P x } _ (Subtype.semilatticeSup Psup) (Subtype.orderBot Pbot) t f : α) = t.sup fun x => ↑(f x) := by letI := Subtype.semilatticeSup Psup letI := Subtype.orderBot Pbot apply comp_sup_eq_sup_comp Subtype.val <;> intros <;> rfl #align finset.sup_coe Finset.sup_coe @[simp] theorem sup_toFinset {α β} [DecidableEq β] (s : Finset α) (f : α → Multiset β) : (s.sup f).toFinset = s.sup fun x => (f x).toFinset := comp_sup_eq_sup_comp Multiset.toFinset toFinset_union rfl #align finset.sup_to_finset Finset.sup_toFinset theorem _root_.List.foldr_sup_eq_sup_toFinset [DecidableEq α] (l : List α) : l.foldr (· ⊔ ·) ⊥ = l.toFinset.sup id := by rw [← coe_fold_r, ← Multiset.fold_dedup_idem, sup_def, ← List.toFinset_coe, toFinset_val, Multiset.map_id] rfl #align list.foldr_sup_eq_sup_to_finset List.foldr_sup_eq_sup_toFinset theorem subset_range_sup_succ (s : Finset ℕ) : s ⊆ range (s.sup id).succ := fun _ hn => mem_range.2 <| Nat.lt_succ_of_le <| @le_sup _ _ _ _ _ id _ hn #align finset.subset_range_sup_succ Finset.subset_range_sup_succ theorem exists_nat_subset_range (s : Finset ℕ) : ∃ n : ℕ, s ⊆ range n := ⟨_, s.subset_range_sup_succ⟩ #align finset.exists_nat_subset_range Finset.exists_nat_subset_range theorem sup_induction {p : α → Prop} (hb : p ⊥) (hp : ∀ a₁, p a₁ → ∀ a₂, p a₂ → p (a₁ ⊔ a₂)) (hs : ∀ b ∈ s, p (f b)) : p (s.sup f) := by induction s using Finset.cons_induction with | empty => exact hb | cons _ _ _ ih => simp only [sup_cons, forall_mem_cons] at hs ⊢ exact hp _ hs.1 _ (ih hs.2) #align finset.sup_induction Finset.sup_induction theorem sup_le_of_le_directed {α : Type*} [SemilatticeSup α] [OrderBot α] (s : Set α) (hs : s.Nonempty) (hdir : DirectedOn (· ≤ ·) s) (t : Finset α) : (∀ x ∈ t, ∃ y ∈ s, x ≤ y) → ∃ x ∈ s, t.sup id ≤ x := by classical induction' t using Finset.induction_on with a r _ ih h · simpa only [forall_prop_of_true, and_true_iff, forall_prop_of_false, bot_le, not_false_iff, sup_empty, forall_true_iff, not_mem_empty] · intro h have incs : (r : Set α) ⊆ ↑(insert a r) := by rw [Finset.coe_subset] apply Finset.subset_insert -- x ∈ s is above the sup of r obtain ⟨x, ⟨hxs, hsx_sup⟩⟩ := ih fun x hx => h x <| incs hx -- y ∈ s is above a obtain ⟨y, hys, hay⟩ := h a (Finset.mem_insert_self a r) -- z ∈ s is above x and y obtain ⟨z, hzs, ⟨hxz, hyz⟩⟩ := hdir x hxs y hys use z, hzs rw [sup_insert, id, sup_le_iff] exact ⟨le_trans hay hyz, le_trans hsx_sup hxz⟩ #align finset.sup_le_of_le_directed Finset.sup_le_of_le_directed -- If we acquire sublattices -- the hypotheses should be reformulated as `s : SubsemilatticeSupBot` theorem sup_mem (s : Set α) (w₁ : ⊥ ∈ s) (w₂ : ∀ᵉ (x ∈ s) (y ∈ s), x ⊔ y ∈ s) {ι : Type*} (t : Finset ι) (p : ι → α) (h : ∀ i ∈ t, p i ∈ s) : t.sup p ∈ s := @sup_induction _ _ _ _ _ _ (· ∈ s) w₁ w₂ h #align finset.sup_mem Finset.sup_mem @[simp] protected theorem sup_eq_bot_iff (f : β → α) (S : Finset β) : S.sup f = ⊥ ↔ ∀ s ∈ S, f s = ⊥ := by classical induction' S using Finset.induction with a S _ hi <;> simp [*] #align finset.sup_eq_bot_iff Finset.sup_eq_bot_iff end Sup theorem sup_eq_iSup [CompleteLattice β] (s : Finset α) (f : α → β) : s.sup f = ⨆ a ∈ s, f a := le_antisymm (Finset.sup_le (fun a ha => le_iSup_of_le a <| le_iSup (fun _ => f a) ha)) (iSup_le fun _ => iSup_le fun ha => le_sup ha) #align finset.sup_eq_supr Finset.sup_eq_iSup theorem sup_id_eq_sSup [CompleteLattice α] (s : Finset α) : s.sup id = sSup s := by simp [sSup_eq_iSup, sup_eq_iSup] #align finset.sup_id_eq_Sup Finset.sup_id_eq_sSup theorem sup_id_set_eq_sUnion (s : Finset (Set α)) : s.sup id = ⋃₀ ↑s := sup_id_eq_sSup _ #align finset.sup_id_set_eq_sUnion Finset.sup_id_set_eq_sUnion @[simp] theorem sup_set_eq_biUnion (s : Finset α) (f : α → Set β) : s.sup f = ⋃ x ∈ s, f x := sup_eq_iSup _ _ #align finset.sup_set_eq_bUnion Finset.sup_set_eq_biUnion theorem sup_eq_sSup_image [CompleteLattice β] (s : Finset α) (f : α → β) : s.sup f = sSup (f '' s) := by classical rw [← Finset.coe_image, ← sup_id_eq_sSup, sup_image, Function.id_comp] #align finset.sup_eq_Sup_image Finset.sup_eq_sSup_image /-! ### inf -/ section Inf -- TODO: define with just `[Top α]` where some lemmas hold without requiring `[OrderTop α]` variable [SemilatticeInf α] [OrderTop α] /-- Infimum of a finite set: `inf {a, b, c} f = f a ⊓ f b ⊓ f c` -/ def inf (s : Finset β) (f : β → α) : α := s.fold (· ⊓ ·) ⊤ f #align finset.inf Finset.inf variable {s s₁ s₂ : Finset β} {f g : β → α} {a : α} theorem inf_def : s.inf f = (s.1.map f).inf := rfl #align finset.inf_def Finset.inf_def @[simp] theorem inf_empty : (∅ : Finset β).inf f = ⊤ := fold_empty #align finset.inf_empty Finset.inf_empty @[simp] theorem inf_cons {b : β} (h : b ∉ s) : (cons b s h).inf f = f b ⊓ s.inf f := @sup_cons αᵒᵈ _ _ _ _ _ _ h #align finset.inf_cons Finset.inf_cons @[simp] theorem inf_insert [DecidableEq β] {b : β} : (insert b s : Finset β).inf f = f b ⊓ s.inf f := fold_insert_idem #align finset.inf_insert Finset.inf_insert @[simp] theorem inf_image [DecidableEq β] (s : Finset γ) (f : γ → β) (g : β → α) : (s.image f).inf g = s.inf (g ∘ f) := fold_image_idem #align finset.inf_image Finset.inf_image @[simp] theorem inf_map (s : Finset γ) (f : γ ↪ β) (g : β → α) : (s.map f).inf g = s.inf (g ∘ f) := fold_map #align finset.inf_map Finset.inf_map @[simp] theorem inf_singleton {b : β} : ({b} : Finset β).inf f = f b := Multiset.inf_singleton #align finset.inf_singleton Finset.inf_singleton theorem inf_inf : s.inf (f ⊓ g) = s.inf f ⊓ s.inf g := @sup_sup αᵒᵈ _ _ _ _ _ _ #align finset.inf_inf Finset.inf_inf theorem inf_congr {f g : β → α} (hs : s₁ = s₂) (hfg : ∀ a ∈ s₂, f a = g a) : s₁.inf f = s₂.inf g := by subst hs exact Finset.fold_congr hfg #align finset.inf_congr Finset.inf_congr @[simp] theorem _root_.map_finset_inf [SemilatticeInf β] [OrderTop β] [FunLike F α β] [InfTopHomClass F α β] (f : F) (s : Finset ι) (g : ι → α) : f (s.inf g) = s.inf (f ∘ g) := Finset.cons_induction_on s (map_top f) fun i s _ h => by rw [inf_cons, inf_cons, map_inf, h, Function.comp_apply] #align map_finset_inf map_finset_inf @[simp] protected theorem le_inf_iff {a : α} : a ≤ s.inf f ↔ ∀ b ∈ s, a ≤ f b := @Finset.sup_le_iff αᵒᵈ _ _ _ _ _ _ #align finset.le_inf_iff Finset.le_inf_iff protected alias ⟨_, le_inf⟩ := Finset.le_inf_iff #align finset.le_inf Finset.le_inf theorem le_inf_const_le : a ≤ s.inf fun _ => a := Finset.le_inf fun _ _ => le_rfl #align finset.le_inf_const_le Finset.le_inf_const_le theorem inf_le {b : β} (hb : b ∈ s) : s.inf f ≤ f b := Finset.le_inf_iff.1 le_rfl _ hb #align finset.inf_le Finset.inf_le theorem inf_le_of_le {b : β} (hb : b ∈ s) (h : f b ≤ a) : s.inf f ≤ a := (inf_le hb).trans h #align finset.inf_le_of_le Finset.inf_le_of_le theorem inf_union [DecidableEq β] : (s₁ ∪ s₂).inf f = s₁.inf f ⊓ s₂.inf f := eq_of_forall_le_iff fun c ↦ by simp [or_imp, forall_and] #align finset.inf_union Finset.inf_union @[simp] theorem inf_biUnion [DecidableEq β] (s : Finset γ) (t : γ → Finset β) : (s.biUnion t).inf f = s.inf fun x => (t x).inf f := @sup_biUnion αᵒᵈ _ _ _ _ _ _ _ _ #align finset.inf_bUnion Finset.inf_biUnion theorem inf_const (h : s.Nonempty) (c : α) : (s.inf fun _ => c) = c := @sup_const αᵒᵈ _ _ _ _ h _ #align finset.inf_const Finset.inf_const @[simp] theorem inf_top (s : Finset β) : (s.inf fun _ => ⊤) = (⊤ : α) := @sup_bot αᵒᵈ _ _ _ _ #align finset.inf_top Finset.inf_top theorem inf_ite (p : β → Prop) [DecidablePred p] : (s.inf fun i ↦ ite (p i) (f i) (g i)) = (s.filter p).inf f ⊓ (s.filter fun i ↦ ¬ p i).inf g := fold_ite _ theorem inf_mono_fun {g : β → α} (h : ∀ b ∈ s, f b ≤ g b) : s.inf f ≤ s.inf g := Finset.le_inf fun b hb => le_trans (inf_le hb) (h b hb) #align finset.inf_mono_fun Finset.inf_mono_fun @[gcongr] theorem inf_mono (h : s₁ ⊆ s₂) : s₂.inf f ≤ s₁.inf f := Finset.le_inf (fun _ hb => inf_le (h hb)) #align finset.inf_mono Finset.inf_mono protected theorem inf_comm (s : Finset β) (t : Finset γ) (f : β → γ → α) : (s.inf fun b => t.inf (f b)) = t.inf fun c => s.inf fun b => f b c := @Finset.sup_comm αᵒᵈ _ _ _ _ _ _ _ #align finset.inf_comm Finset.inf_comm theorem inf_attach (s : Finset β) (f : β → α) : (s.attach.inf fun x => f x) = s.inf f := @sup_attach αᵒᵈ _ _ _ _ _ #align finset.inf_attach Finset.inf_attach theorem inf_product_left (s : Finset β) (t : Finset γ) (f : β × γ → α) : (s ×ˢ t).inf f = s.inf fun i => t.inf fun i' => f ⟨i, i'⟩ := @sup_product_left αᵒᵈ _ _ _ _ _ _ _ #align finset.inf_product_left Finset.inf_product_left theorem inf_product_right (s : Finset β) (t : Finset γ) (f : β × γ → α) : (s ×ˢ t).inf f = t.inf fun i' => s.inf fun i => f ⟨i, i'⟩ := @sup_product_right αᵒᵈ _ _ _ _ _ _ _ #align finset.inf_product_right Finset.inf_product_right section Prod variable {ι κ α β : Type*} [SemilatticeInf α] [SemilatticeInf β] [OrderTop α] [OrderTop β] {s : Finset ι} {t : Finset κ} @[simp] lemma inf_prodMap (hs : s.Nonempty) (ht : t.Nonempty) (f : ι → α) (g : κ → β) : inf (s ×ˢ t) (Prod.map f g) = (inf s f, inf t g) := sup_prodMap (α := αᵒᵈ) (β := βᵒᵈ) hs ht _ _ end Prod @[simp] theorem inf_erase_top [DecidableEq α] (s : Finset α) : (s.erase ⊤).inf id = s.inf id := @sup_erase_bot αᵒᵈ _ _ _ _ #align finset.inf_erase_top Finset.inf_erase_top theorem comp_inf_eq_inf_comp [SemilatticeInf γ] [OrderTop γ] {s : Finset β} {f : β → α} (g : α → γ) (g_inf : ∀ x y, g (x ⊓ y) = g x ⊓ g y) (top : g ⊤ = ⊤) : g (s.inf f) = s.inf (g ∘ f) := @comp_sup_eq_sup_comp αᵒᵈ _ γᵒᵈ _ _ _ _ _ _ _ g_inf top #align finset.comp_inf_eq_inf_comp Finset.comp_inf_eq_inf_comp /-- Computing `inf` in a subtype (closed under `inf`) is the same as computing it in `α`. -/ theorem inf_coe {P : α → Prop} {Ptop : P ⊤} {Pinf : ∀ ⦃x y⦄, P x → P y → P (x ⊓ y)} (t : Finset β) (f : β → { x : α // P x }) : (@inf { x // P x } _ (Subtype.semilatticeInf Pinf) (Subtype.orderTop Ptop) t f : α) = t.inf fun x => ↑(f x) := @sup_coe αᵒᵈ _ _ _ _ Ptop Pinf t f #align finset.inf_coe Finset.inf_coe theorem _root_.List.foldr_inf_eq_inf_toFinset [DecidableEq α] (l : List α) : l.foldr (· ⊓ ·) ⊤ = l.toFinset.inf id := by rw [← coe_fold_r, ← Multiset.fold_dedup_idem, inf_def, ← List.toFinset_coe, toFinset_val, Multiset.map_id] rfl #align list.foldr_inf_eq_inf_to_finset List.foldr_inf_eq_inf_toFinset theorem inf_induction {p : α → Prop} (ht : p ⊤) (hp : ∀ a₁, p a₁ → ∀ a₂, p a₂ → p (a₁ ⊓ a₂)) (hs : ∀ b ∈ s, p (f b)) : p (s.inf f) := @sup_induction αᵒᵈ _ _ _ _ _ _ ht hp hs #align finset.inf_induction Finset.inf_induction theorem inf_mem (s : Set α) (w₁ : ⊤ ∈ s) (w₂ : ∀ᵉ (x ∈ s) (y ∈ s), x ⊓ y ∈ s) {ι : Type*} (t : Finset ι) (p : ι → α) (h : ∀ i ∈ t, p i ∈ s) : t.inf p ∈ s := @inf_induction _ _ _ _ _ _ (· ∈ s) w₁ w₂ h #align finset.inf_mem Finset.inf_mem @[simp] protected theorem inf_eq_top_iff (f : β → α) (S : Finset β) : S.inf f = ⊤ ↔ ∀ s ∈ S, f s = ⊤ := @Finset.sup_eq_bot_iff αᵒᵈ _ _ _ _ _ #align finset.inf_eq_top_iff Finset.inf_eq_top_iff end Inf @[simp] theorem toDual_sup [SemilatticeSup α] [OrderBot α] (s : Finset β) (f : β → α) : toDual (s.sup f) = s.inf (toDual ∘ f) := rfl #align finset.to_dual_sup Finset.toDual_sup @[simp] theorem toDual_inf [SemilatticeInf α] [OrderTop α] (s : Finset β) (f : β → α) : toDual (s.inf f) = s.sup (toDual ∘ f) := rfl #align finset.to_dual_inf Finset.toDual_inf @[simp] theorem ofDual_sup [SemilatticeInf α] [OrderTop α] (s : Finset β) (f : β → αᵒᵈ) : ofDual (s.sup f) = s.inf (ofDual ∘ f) := rfl #align finset.of_dual_sup Finset.ofDual_sup @[simp] theorem ofDual_inf [SemilatticeSup α] [OrderBot α] (s : Finset β) (f : β → αᵒᵈ) : ofDual (s.inf f) = s.sup (ofDual ∘ f) := rfl #align finset.of_dual_inf Finset.ofDual_inf section DistribLattice variable [DistribLattice α] section OrderBot variable [OrderBot α] {s : Finset ι} {t : Finset κ} {f : ι → α} {g : κ → α} {a : α} theorem sup_inf_distrib_left (s : Finset ι) (f : ι → α) (a : α) : a ⊓ s.sup f = s.sup fun i => a ⊓ f i := by induction s using Finset.cons_induction with | empty => simp_rw [Finset.sup_empty, inf_bot_eq] | cons _ _ _ h => rw [sup_cons, sup_cons, inf_sup_left, h] #align finset.sup_inf_distrib_left Finset.sup_inf_distrib_left theorem sup_inf_distrib_right (s : Finset ι) (f : ι → α) (a : α) : s.sup f ⊓ a = s.sup fun i => f i ⊓ a := by rw [_root_.inf_comm, s.sup_inf_distrib_left] simp_rw [_root_.inf_comm] #align finset.sup_inf_distrib_right Finset.sup_inf_distrib_right protected theorem disjoint_sup_right : Disjoint a (s.sup f) ↔ ∀ ⦃i⦄, i ∈ s → Disjoint a (f i) := by simp only [disjoint_iff, sup_inf_distrib_left, Finset.sup_eq_bot_iff] #align finset.disjoint_sup_right Finset.disjoint_sup_right protected theorem disjoint_sup_left : Disjoint (s.sup f) a ↔ ∀ ⦃i⦄, i ∈ s → Disjoint (f i) a := by simp only [disjoint_iff, sup_inf_distrib_right, Finset.sup_eq_bot_iff] #align finset.disjoint_sup_left Finset.disjoint_sup_left theorem sup_inf_sup (s : Finset ι) (t : Finset κ) (f : ι → α) (g : κ → α) : s.sup f ⊓ t.sup g = (s ×ˢ t).sup fun i => f i.1 ⊓ g i.2 := by simp_rw [Finset.sup_inf_distrib_right, Finset.sup_inf_distrib_left, sup_product_left] #align finset.sup_inf_sup Finset.sup_inf_sup end OrderBot section OrderTop variable [OrderTop α] {f : ι → α} {g : κ → α} {s : Finset ι} {t : Finset κ} {a : α} theorem inf_sup_distrib_left (s : Finset ι) (f : ι → α) (a : α) : a ⊔ s.inf f = s.inf fun i => a ⊔ f i := @sup_inf_distrib_left αᵒᵈ _ _ _ _ _ _ #align finset.inf_sup_distrib_left Finset.inf_sup_distrib_left theorem inf_sup_distrib_right (s : Finset ι) (f : ι → α) (a : α) : s.inf f ⊔ a = s.inf fun i => f i ⊔ a := @sup_inf_distrib_right αᵒᵈ _ _ _ _ _ _ #align finset.inf_sup_distrib_right Finset.inf_sup_distrib_right protected theorem codisjoint_inf_right : Codisjoint a (s.inf f) ↔ ∀ ⦃i⦄, i ∈ s → Codisjoint a (f i) := @Finset.disjoint_sup_right αᵒᵈ _ _ _ _ _ _ #align finset.codisjoint_inf_right Finset.codisjoint_inf_right protected theorem codisjoint_inf_left : Codisjoint (s.inf f) a ↔ ∀ ⦃i⦄, i ∈ s → Codisjoint (f i) a := @Finset.disjoint_sup_left αᵒᵈ _ _ _ _ _ _ #align finset.codisjoint_inf_left Finset.codisjoint_inf_left theorem inf_sup_inf (s : Finset ι) (t : Finset κ) (f : ι → α) (g : κ → α) : s.inf f ⊔ t.inf g = (s ×ˢ t).inf fun i => f i.1 ⊔ g i.2 := @sup_inf_sup αᵒᵈ _ _ _ _ _ _ _ _ #align finset.inf_sup_inf Finset.inf_sup_inf end OrderTop section BoundedOrder variable [BoundedOrder α] [DecidableEq ι] --TODO: Extract out the obvious isomorphism `(insert i s).pi t ≃ t i ×ˢ s.pi t` from this proof theorem inf_sup {κ : ι → Type*} (s : Finset ι) (t : ∀ i, Finset (κ i)) (f : ∀ i, κ i → α) : (s.inf fun i => (t i).sup (f i)) = (s.pi t).sup fun g => s.attach.inf fun i => f _ <| g _ i.2 := by induction' s using Finset.induction with i s hi ih · simp rw [inf_insert, ih, attach_insert, sup_inf_sup] refine eq_of_forall_ge_iff fun c => ?_ simp only [Finset.sup_le_iff, mem_product, mem_pi, and_imp, Prod.forall, inf_insert, inf_image] refine ⟨fun h g hg => h (g i <| mem_insert_self _ _) (fun j hj => g j <| mem_insert_of_mem hj) (hg _ <| mem_insert_self _ _) fun j hj => hg _ <| mem_insert_of_mem hj, fun h a g ha hg => ?_⟩ -- TODO: This `have` must be named to prevent it being shadowed by the internal `this` in `simpa` have aux : ∀ j : { x // x ∈ s }, ↑j ≠ i := fun j : s => ne_of_mem_of_not_mem j.2 hi -- Porting note: `simpa` doesn't support placeholders in proof terms have := h (fun j hj => if hji : j = i then cast (congr_arg κ hji.symm) a else g _ <| mem_of_mem_insert_of_ne hj hji) (fun j hj => ?_) · simpa only [cast_eq, dif_pos, Function.comp, Subtype.coe_mk, dif_neg, aux] using this rw [mem_insert] at hj obtain (rfl | hj) := hj · simpa · simpa [ne_of_mem_of_not_mem hj hi] using hg _ _ #align finset.inf_sup Finset.inf_sup theorem sup_inf {κ : ι → Type*} (s : Finset ι) (t : ∀ i, Finset (κ i)) (f : ∀ i, κ i → α) : (s.sup fun i => (t i).inf (f i)) = (s.pi t).inf fun g => s.attach.sup fun i => f _ <| g _ i.2 := @inf_sup αᵒᵈ _ _ _ _ _ _ _ _ #align finset.sup_inf Finset.sup_inf end BoundedOrder end DistribLattice section BooleanAlgebra variable [BooleanAlgebra α] {s : Finset ι} theorem sup_sdiff_left (s : Finset ι) (f : ι → α) (a : α) : (s.sup fun b => a \ f b) = a \ s.inf f := by induction s using Finset.cons_induction with | empty => rw [sup_empty, inf_empty, sdiff_top] | cons _ _ _ h => rw [sup_cons, inf_cons, h, sdiff_inf] #align finset.sup_sdiff_left Finset.sup_sdiff_left theorem inf_sdiff_left (hs : s.Nonempty) (f : ι → α) (a : α) : (s.inf fun b => a \ f b) = a \ s.sup f := by induction hs using Finset.Nonempty.cons_induction with | singleton => rw [sup_singleton, inf_singleton] | cons _ _ _ _ ih => rw [sup_cons, inf_cons, ih, sdiff_sup] #align finset.inf_sdiff_left Finset.inf_sdiff_left theorem inf_sdiff_right (hs : s.Nonempty) (f : ι → α) (a : α) : (s.inf fun b => f b \ a) = s.inf f \ a := by induction hs using Finset.Nonempty.cons_induction with | singleton => rw [inf_singleton, inf_singleton] | cons _ _ _ _ ih => rw [inf_cons, inf_cons, ih, inf_sdiff] #align finset.inf_sdiff_right Finset.inf_sdiff_right theorem inf_himp_right (s : Finset ι) (f : ι → α) (a : α) : (s.inf fun b => f b ⇨ a) = s.sup f ⇨ a := @sup_sdiff_left αᵒᵈ _ _ _ _ _ #align finset.inf_himp_right Finset.inf_himp_right theorem sup_himp_right (hs : s.Nonempty) (f : ι → α) (a : α) : (s.sup fun b => f b ⇨ a) = s.inf f ⇨ a := @inf_sdiff_left αᵒᵈ _ _ _ hs _ _ #align finset.sup_himp_right Finset.sup_himp_right theorem sup_himp_left (hs : s.Nonempty) (f : ι → α) (a : α) : (s.sup fun b => a ⇨ f b) = a ⇨ s.sup f := @inf_sdiff_right αᵒᵈ _ _ _ hs _ _ #align finset.sup_himp_left Finset.sup_himp_left @[simp] protected theorem compl_sup (s : Finset ι) (f : ι → α) : (s.sup f)ᶜ = s.inf fun i => (f i)ᶜ := map_finset_sup (OrderIso.compl α) _ _ #align finset.compl_sup Finset.compl_sup @[simp] protected theorem compl_inf (s : Finset ι) (f : ι → α) : (s.inf f)ᶜ = s.sup fun i => (f i)ᶜ := map_finset_inf (OrderIso.compl α) _ _ #align finset.compl_inf Finset.compl_inf end BooleanAlgebra section LinearOrder variable [LinearOrder α] section OrderBot variable [OrderBot α] {s : Finset ι} {f : ι → α} {a : α} theorem comp_sup_eq_sup_comp_of_is_total [SemilatticeSup β] [OrderBot β] (g : α → β) (mono_g : Monotone g) (bot : g ⊥ = ⊥) : g (s.sup f) = s.sup (g ∘ f) := comp_sup_eq_sup_comp g mono_g.map_sup bot #align finset.comp_sup_eq_sup_comp_of_is_total Finset.comp_sup_eq_sup_comp_of_is_total @[simp] protected theorem le_sup_iff (ha : ⊥ < a) : a ≤ s.sup f ↔ ∃ b ∈ s, a ≤ f b := by apply Iff.intro · induction s using cons_induction with | empty => exact (absurd · (not_le_of_lt ha)) | cons c t hc ih => rw [sup_cons, le_sup_iff] exact fun | Or.inl h => ⟨c, mem_cons.2 (Or.inl rfl), h⟩ | Or.inr h => let ⟨b, hb, hle⟩ := ih h; ⟨b, mem_cons.2 (Or.inr hb), hle⟩ · exact fun ⟨b, hb, hle⟩ => le_trans hle (le_sup hb) #align finset.le_sup_iff Finset.le_sup_iff @[simp] protected theorem lt_sup_iff : a < s.sup f ↔ ∃ b ∈ s, a < f b := by apply Iff.intro · induction s using cons_induction with | empty => exact (absurd · not_lt_bot) | cons c t hc ih => rw [sup_cons, lt_sup_iff] exact fun | Or.inl h => ⟨c, mem_cons.2 (Or.inl rfl), h⟩ | Or.inr h => let ⟨b, hb, hlt⟩ := ih h; ⟨b, mem_cons.2 (Or.inr hb), hlt⟩ · exact fun ⟨b, hb, hlt⟩ => lt_of_lt_of_le hlt (le_sup hb) #align finset.lt_sup_iff Finset.lt_sup_iff @[simp] protected theorem sup_lt_iff (ha : ⊥ < a) : s.sup f < a ↔ ∀ b ∈ s, f b < a := ⟨fun hs b hb => lt_of_le_of_lt (le_sup hb) hs, Finset.cons_induction_on s (fun _ => ha) fun c t hc => by simpa only [sup_cons, sup_lt_iff, mem_cons, forall_eq_or_imp] using And.imp_right⟩ #align finset.sup_lt_iff Finset.sup_lt_iff end OrderBot section OrderTop variable [OrderTop α] {s : Finset ι} {f : ι → α} {a : α} theorem comp_inf_eq_inf_comp_of_is_total [SemilatticeInf β] [OrderTop β] (g : α → β) (mono_g : Monotone g) (top : g ⊤ = ⊤) : g (s.inf f) = s.inf (g ∘ f) := comp_inf_eq_inf_comp g mono_g.map_inf top #align finset.comp_inf_eq_inf_comp_of_is_total Finset.comp_inf_eq_inf_comp_of_is_total @[simp] protected theorem inf_le_iff (ha : a < ⊤) : s.inf f ≤ a ↔ ∃ b ∈ s, f b ≤ a := @Finset.le_sup_iff αᵒᵈ _ _ _ _ _ _ ha #align finset.inf_le_iff Finset.inf_le_iff @[simp] protected theorem inf_lt_iff : s.inf f < a ↔ ∃ b ∈ s, f b < a := @Finset.lt_sup_iff αᵒᵈ _ _ _ _ _ _ #align finset.inf_lt_iff Finset.inf_lt_iff @[simp] protected theorem lt_inf_iff (ha : a < ⊤) : a < s.inf f ↔ ∀ b ∈ s, a < f b := @Finset.sup_lt_iff αᵒᵈ _ _ _ _ _ _ ha #align finset.lt_inf_iff Finset.lt_inf_iff end OrderTop end LinearOrder theorem inf_eq_iInf [CompleteLattice β] (s : Finset α) (f : α → β) : s.inf f = ⨅ a ∈ s, f a := @sup_eq_iSup _ βᵒᵈ _ _ _ #align finset.inf_eq_infi Finset.inf_eq_iInf theorem inf_id_eq_sInf [CompleteLattice α] (s : Finset α) : s.inf id = sInf s := @sup_id_eq_sSup αᵒᵈ _ _ #align finset.inf_id_eq_Inf Finset.inf_id_eq_sInf theorem inf_id_set_eq_sInter (s : Finset (Set α)) : s.inf id = ⋂₀ ↑s := inf_id_eq_sInf _ #align finset.inf_id_set_eq_sInter Finset.inf_id_set_eq_sInter @[simp] theorem inf_set_eq_iInter (s : Finset α) (f : α → Set β) : s.inf f = ⋂ x ∈ s, f x := inf_eq_iInf _ _ #align finset.inf_set_eq_bInter Finset.inf_set_eq_iInter theorem inf_eq_sInf_image [CompleteLattice β] (s : Finset α) (f : α → β) : s.inf f = sInf (f '' s) := @sup_eq_sSup_image _ βᵒᵈ _ _ _ #align finset.inf_eq_Inf_image Finset.inf_eq_sInf_image section Sup' variable [SemilatticeSup α] theorem sup_of_mem {s : Finset β} (f : β → α) {b : β} (h : b ∈ s) : ∃ a : α, s.sup ((↑) ∘ f : β → WithBot α) = ↑a := Exists.imp (fun _ => And.left) (@le_sup (WithBot α) _ _ _ _ _ _ h (f b) rfl) #align finset.sup_of_mem Finset.sup_of_mem /-- Given nonempty finset `s` then `s.sup' H f` is the supremum of its image under `f` in (possibly unbounded) join-semilattice `α`, where `H` is a proof of nonemptiness. If `α` has a bottom element you may instead use `Finset.sup` which does not require `s` nonempty. -/ def sup' (s : Finset β) (H : s.Nonempty) (f : β → α) : α := WithBot.unbot (s.sup ((↑) ∘ f)) (by simpa using H) #align finset.sup' Finset.sup' variable {s : Finset β} (H : s.Nonempty) (f : β → α) @[simp] theorem coe_sup' : ((s.sup' H f : α) : WithBot α) = s.sup ((↑) ∘ f) := by rw [sup', WithBot.coe_unbot] #align finset.coe_sup' Finset.coe_sup' @[simp] theorem sup'_cons {b : β} {hb : b ∉ s} : (cons b s hb).sup' (nonempty_cons hb) f = f b ⊔ s.sup' H f := by rw [← WithBot.coe_eq_coe] simp [WithBot.coe_sup] #align finset.sup'_cons Finset.sup'_cons @[simp] theorem sup'_insert [DecidableEq β] {b : β} : (insert b s).sup' (insert_nonempty _ _) f = f b ⊔ s.sup' H f := by rw [← WithBot.coe_eq_coe] simp [WithBot.coe_sup] #align finset.sup'_insert Finset.sup'_insert @[simp] theorem sup'_singleton {b : β} : ({b} : Finset β).sup' (singleton_nonempty _) f = f b := rfl #align finset.sup'_singleton Finset.sup'_singleton @[simp] theorem sup'_le_iff {a : α} : s.sup' H f ≤ a ↔ ∀ b ∈ s, f b ≤ a := by simp_rw [← @WithBot.coe_le_coe α, coe_sup', Finset.sup_le_iff]; rfl #align finset.sup'_le_iff Finset.sup'_le_iff alias ⟨_, sup'_le⟩ := sup'_le_iff #align finset.sup'_le Finset.sup'_le theorem le_sup' {b : β} (h : b ∈ s) : f b ≤ s.sup' ⟨b, h⟩ f := (sup'_le_iff ⟨b, h⟩ f).1 le_rfl b h #align finset.le_sup' Finset.le_sup' theorem le_sup'_of_le {a : α} {b : β} (hb : b ∈ s) (h : a ≤ f b) : a ≤ s.sup' ⟨b, hb⟩ f := h.trans <| le_sup' _ hb #align finset.le_sup'_of_le Finset.le_sup'_of_le @[simp] theorem sup'_const (a : α) : s.sup' H (fun _ => a) = a := by apply le_antisymm · apply sup'_le intros exact le_rfl · apply le_sup' (fun _ => a) H.choose_spec #align finset.sup'_const Finset.sup'_const theorem sup'_union [DecidableEq β] {s₁ s₂ : Finset β} (h₁ : s₁.Nonempty) (h₂ : s₂.Nonempty) (f : β → α) : (s₁ ∪ s₂).sup' (h₁.mono subset_union_left) f = s₁.sup' h₁ f ⊔ s₂.sup' h₂ f := eq_of_forall_ge_iff fun a => by simp [or_imp, forall_and] #align finset.sup'_union Finset.sup'_union theorem sup'_biUnion [DecidableEq β] {s : Finset γ} (Hs : s.Nonempty) {t : γ → Finset β} (Ht : ∀ b, (t b).Nonempty) : (s.biUnion t).sup' (Hs.biUnion fun b _ => Ht b) f = s.sup' Hs (fun b => (t b).sup' (Ht b) f) := eq_of_forall_ge_iff fun c => by simp [@forall_swap _ β] #align finset.sup'_bUnion Finset.sup'_biUnion protected theorem sup'_comm {t : Finset γ} (hs : s.Nonempty) (ht : t.Nonempty) (f : β → γ → α) : (s.sup' hs fun b => t.sup' ht (f b)) = t.sup' ht fun c => s.sup' hs fun b => f b c := eq_of_forall_ge_iff fun a => by simpa using forall₂_swap #align finset.sup'_comm Finset.sup'_comm theorem sup'_product_left {t : Finset γ} (h : (s ×ˢ t).Nonempty) (f : β × γ → α) : (s ×ˢ t).sup' h f = s.sup' h.fst fun i => t.sup' h.snd fun i' => f ⟨i, i'⟩ := eq_of_forall_ge_iff fun a => by simp [@forall_swap _ γ] #align finset.sup'_product_left Finset.sup'_product_left theorem sup'_product_right {t : Finset γ} (h : (s ×ˢ t).Nonempty) (f : β × γ → α) : (s ×ˢ t).sup' h f = t.sup' h.snd fun i' => s.sup' h.fst fun i => f ⟨i, i'⟩ := by rw [sup'_product_left, Finset.sup'_comm] #align finset.sup'_product_right Finset.sup'_product_right section Prod variable {ι κ α β : Type*} [SemilatticeSup α] [SemilatticeSup β] {s : Finset ι} {t : Finset κ} /-- See also `Finset.sup'_prodMap`. -/ lemma prodMk_sup'_sup' (hs : s.Nonempty) (ht : t.Nonempty) (f : ι → α) (g : κ → β) : (sup' s hs f, sup' t ht g) = sup' (s ×ˢ t) (hs.product ht) (Prod.map f g) := eq_of_forall_ge_iff fun i ↦ by obtain ⟨a, ha⟩ := hs obtain ⟨b, hb⟩ := ht simp only [Prod.map, sup'_le_iff, mem_product, and_imp, Prod.forall, Prod.le_def] exact ⟨by aesop, fun h ↦ ⟨fun i hi ↦ (h _ _ hi hb).1, fun j hj ↦ (h _ _ ha hj).2⟩⟩ /-- See also `Finset.prodMk_sup'_sup'`. -/ -- @[simp] -- TODO: Why does `Prod.map_apply` simplify the LHS? lemma sup'_prodMap (hst : (s ×ˢ t).Nonempty) (f : ι → α) (g : κ → β) : sup' (s ×ˢ t) hst (Prod.map f g) = (sup' s hst.fst f, sup' t hst.snd g) := (prodMk_sup'_sup' _ _ _ _).symm end Prod theorem sup'_induction {p : α → Prop} (hp : ∀ a₁, p a₁ → ∀ a₂, p a₂ → p (a₁ ⊔ a₂)) (hs : ∀ b ∈ s, p (f b)) : p (s.sup' H f) := by show @WithBot.recBotCoe α (fun _ => Prop) True p ↑(s.sup' H f) rw [coe_sup'] refine sup_induction trivial (fun a₁ h₁ a₂ h₂ ↦ ?_) hs match a₁, a₂ with | ⊥, _ => rwa [bot_sup_eq] | (a₁ : α), ⊥ => rwa [sup_bot_eq] | (a₁ : α), (a₂ : α) => exact hp a₁ h₁ a₂ h₂ #align finset.sup'_induction Finset.sup'_induction theorem sup'_mem (s : Set α) (w : ∀ᵉ (x ∈ s) (y ∈ s), x ⊔ y ∈ s) {ι : Type*} (t : Finset ι) (H : t.Nonempty) (p : ι → α) (h : ∀ i ∈ t, p i ∈ s) : t.sup' H p ∈ s := sup'_induction H p w h #align finset.sup'_mem Finset.sup'_mem @[congr] theorem sup'_congr {t : Finset β} {f g : β → α} (h₁ : s = t) (h₂ : ∀ x ∈ s, f x = g x) : s.sup' H f = t.sup' (h₁ ▸ H) g := by subst s refine eq_of_forall_ge_iff fun c => ?_ simp (config := { contextual := true }) only [sup'_le_iff, h₂] #align finset.sup'_congr Finset.sup'_congr theorem comp_sup'_eq_sup'_comp [SemilatticeSup γ] {s : Finset β} (H : s.Nonempty) {f : β → α} (g : α → γ) (g_sup : ∀ x y, g (x ⊔ y) = g x ⊔ g y) : g (s.sup' H f) = s.sup' H (g ∘ f) := by refine H.cons_induction ?_ ?_ <;> intros <;> simp [*] #align finset.comp_sup'_eq_sup'_comp Finset.comp_sup'_eq_sup'_comp @[simp] theorem _root_.map_finset_sup' [SemilatticeSup β] [FunLike F α β] [SupHomClass F α β] (f : F) {s : Finset ι} (hs) (g : ι → α) : f (s.sup' hs g) = s.sup' hs (f ∘ g) := by refine hs.cons_induction ?_ ?_ <;> intros <;> simp [*] #align map_finset_sup' map_finset_sup' lemma nsmul_sup' [LinearOrderedAddCommMonoid β] {s : Finset α} (hs : s.Nonempty) (f : α → β) (n : ℕ) : s.sup' hs (fun a => n • f a) = n • s.sup' hs f := let ns : SupHom β β := { toFun := (n • ·), map_sup' := fun _ _ => (nsmul_right_mono n).map_max } (map_finset_sup' ns hs _).symm /-- To rewrite from right to left, use `Finset.sup'_comp_eq_image`. -/ @[simp] theorem sup'_image [DecidableEq β] {s : Finset γ} {f : γ → β} (hs : (s.image f).Nonempty) (g : β → α) : (s.image f).sup' hs g = s.sup' hs.of_image (g ∘ f) := by rw [← WithBot.coe_eq_coe]; simp only [coe_sup', sup_image, WithBot.coe_sup]; rfl #align finset.sup'_image Finset.sup'_image /-- A version of `Finset.sup'_image` with LHS and RHS reversed. Also, this lemma assumes that `s` is nonempty instead of assuming that its image is nonempty. -/ lemma sup'_comp_eq_image [DecidableEq β] {s : Finset γ} {f : γ → β} (hs : s.Nonempty) (g : β → α) : s.sup' hs (g ∘ f) = (s.image f).sup' (hs.image f) g := .symm <| sup'_image _ _ /-- To rewrite from right to left, use `Finset.sup'_comp_eq_map`. -/ @[simp] theorem sup'_map {s : Finset γ} {f : γ ↪ β} (g : β → α) (hs : (s.map f).Nonempty) : (s.map f).sup' hs g = s.sup' (map_nonempty.1 hs) (g ∘ f) := by rw [← WithBot.coe_eq_coe, coe_sup', sup_map, coe_sup'] rfl #align finset.sup'_map Finset.sup'_map /-- A version of `Finset.sup'_map` with LHS and RHS reversed. Also, this lemma assumes that `s` is nonempty instead of assuming that its image is nonempty. -/ lemma sup'_comp_eq_map {s : Finset γ} {f : γ ↪ β} (g : β → α) (hs : s.Nonempty) : s.sup' hs (g ∘ f) = (s.map f).sup' (map_nonempty.2 hs) g := .symm <| sup'_map _ _ theorem sup'_mono {s₁ s₂ : Finset β} (h : s₁ ⊆ s₂) (h₁ : s₁.Nonempty): s₁.sup' h₁ f ≤ s₂.sup' (h₁.mono h) f := Finset.sup'_le h₁ _ (fun _ hb => le_sup' _ (h hb)) /-- A version of `Finset.sup'_mono` acceptable for `@[gcongr]`. Instead of deducing `s₂.Nonempty` from `s₁.Nonempty` and `s₁ ⊆ s₂`, this version takes it as an argument. -/ @[gcongr] lemma _root_.GCongr.finset_sup'_le {s₁ s₂ : Finset β} (h : s₁ ⊆ s₂) {h₁ : s₁.Nonempty} {h₂ : s₂.Nonempty} : s₁.sup' h₁ f ≤ s₂.sup' h₂ f := sup'_mono f h h₁ end Sup' section Inf' variable [SemilatticeInf α] theorem inf_of_mem {s : Finset β} (f : β → α) {b : β} (h : b ∈ s) : ∃ a : α, s.inf ((↑) ∘ f : β → WithTop α) = ↑a := @sup_of_mem αᵒᵈ _ _ _ f _ h #align finset.inf_of_mem Finset.inf_of_mem /-- Given nonempty finset `s` then `s.inf' H f` is the infimum of its image under `f` in (possibly unbounded) meet-semilattice `α`, where `H` is a proof of nonemptiness. If `α` has a top element you may instead use `Finset.inf` which does not require `s` nonempty. -/ def inf' (s : Finset β) (H : s.Nonempty) (f : β → α) : α := WithTop.untop (s.inf ((↑) ∘ f)) (by simpa using H) #align finset.inf' Finset.inf' variable {s : Finset β} (H : s.Nonempty) (f : β → α) @[simp] theorem coe_inf' : ((s.inf' H f : α) : WithTop α) = s.inf ((↑) ∘ f) := @coe_sup' αᵒᵈ _ _ _ H f #align finset.coe_inf' Finset.coe_inf' @[simp] theorem inf'_cons {b : β} {hb : b ∉ s} : (cons b s hb).inf' (nonempty_cons hb) f = f b ⊓ s.inf' H f := @sup'_cons αᵒᵈ _ _ _ H f _ _ #align finset.inf'_cons Finset.inf'_cons @[simp] theorem inf'_insert [DecidableEq β] {b : β} : (insert b s).inf' (insert_nonempty _ _) f = f b ⊓ s.inf' H f := @sup'_insert αᵒᵈ _ _ _ H f _ _ #align finset.inf'_insert Finset.inf'_insert @[simp] theorem inf'_singleton {b : β} : ({b} : Finset β).inf' (singleton_nonempty _) f = f b := rfl #align finset.inf'_singleton Finset.inf'_singleton @[simp] theorem le_inf'_iff {a : α} : a ≤ s.inf' H f ↔ ∀ b ∈ s, a ≤ f b := sup'_le_iff (α := αᵒᵈ) H f #align finset.le_inf'_iff Finset.le_inf'_iff theorem le_inf' {a : α} (hs : ∀ b ∈ s, a ≤ f b) : a ≤ s.inf' H f := sup'_le (α := αᵒᵈ) H f hs #align finset.le_inf' Finset.le_inf' theorem inf'_le {b : β} (h : b ∈ s) : s.inf' ⟨b, h⟩ f ≤ f b := le_sup' (α := αᵒᵈ) f h #align finset.inf'_le Finset.inf'_le theorem inf'_le_of_le {a : α} {b : β} (hb : b ∈ s) (h : f b ≤ a) : s.inf' ⟨b, hb⟩ f ≤ a := (inf'_le _ hb).trans h #align finset.inf'_le_of_le Finset.inf'_le_of_le @[simp] theorem inf'_const (a : α) : (s.inf' H fun _ => a) = a := sup'_const (α := αᵒᵈ) H a #align finset.inf'_const Finset.inf'_const theorem inf'_union [DecidableEq β] {s₁ s₂ : Finset β} (h₁ : s₁.Nonempty) (h₂ : s₂.Nonempty) (f : β → α) : (s₁ ∪ s₂).inf' (h₁.mono subset_union_left) f = s₁.inf' h₁ f ⊓ s₂.inf' h₂ f := @sup'_union αᵒᵈ _ _ _ _ _ h₁ h₂ _ #align finset.inf'_union Finset.inf'_union theorem inf'_biUnion [DecidableEq β] {s : Finset γ} (Hs : s.Nonempty) {t : γ → Finset β} (Ht : ∀ b, (t b).Nonempty) : (s.biUnion t).inf' (Hs.biUnion fun b _ => Ht b) f = s.inf' Hs (fun b => (t b).inf' (Ht b) f) := sup'_biUnion (α := αᵒᵈ) _ Hs Ht #align finset.inf'_bUnion Finset.inf'_biUnion protected theorem inf'_comm {t : Finset γ} (hs : s.Nonempty) (ht : t.Nonempty) (f : β → γ → α) : (s.inf' hs fun b => t.inf' ht (f b)) = t.inf' ht fun c => s.inf' hs fun b => f b c := @Finset.sup'_comm αᵒᵈ _ _ _ _ _ hs ht _ #align finset.inf'_comm Finset.inf'_comm theorem inf'_product_left {t : Finset γ} (h : (s ×ˢ t).Nonempty) (f : β × γ → α) : (s ×ˢ t).inf' h f = s.inf' h.fst fun i => t.inf' h.snd fun i' => f ⟨i, i'⟩ := sup'_product_left (α := αᵒᵈ) h f #align finset.inf'_product_left Finset.inf'_product_left theorem inf'_product_right {t : Finset γ} (h : (s ×ˢ t).Nonempty) (f : β × γ → α) : (s ×ˢ t).inf' h f = t.inf' h.snd fun i' => s.inf' h.fst fun i => f ⟨i, i'⟩ := sup'_product_right (α := αᵒᵈ) h f #align finset.inf'_product_right Finset.inf'_product_right section Prod variable {ι κ α β : Type*} [SemilatticeInf α] [SemilatticeInf β] {s : Finset ι} {t : Finset κ} /-- See also `Finset.inf'_prodMap`. -/ lemma prodMk_inf'_inf' (hs : s.Nonempty) (ht : t.Nonempty) (f : ι → α) (g : κ → β) : (inf' s hs f, inf' t ht g) = inf' (s ×ˢ t) (hs.product ht) (Prod.map f g) := prodMk_sup'_sup' (α := αᵒᵈ) (β := βᵒᵈ) hs ht _ _ /-- See also `Finset.prodMk_inf'_inf'`. -/ -- @[simp] -- TODO: Why does `Prod.map_apply` simplify the LHS? lemma inf'_prodMap (hst : (s ×ˢ t).Nonempty) (f : ι → α) (g : κ → β) : inf' (s ×ˢ t) hst (Prod.map f g) = (inf' s hst.fst f, inf' t hst.snd g) := (prodMk_inf'_inf' _ _ _ _).symm end Prod theorem comp_inf'_eq_inf'_comp [SemilatticeInf γ] {s : Finset β} (H : s.Nonempty) {f : β → α} (g : α → γ) (g_inf : ∀ x y, g (x ⊓ y) = g x ⊓ g y) : g (s.inf' H f) = s.inf' H (g ∘ f) := comp_sup'_eq_sup'_comp (α := αᵒᵈ) (γ := γᵒᵈ) H g g_inf #align finset.comp_inf'_eq_inf'_comp Finset.comp_inf'_eq_inf'_comp theorem inf'_induction {p : α → Prop} (hp : ∀ a₁, p a₁ → ∀ a₂, p a₂ → p (a₁ ⊓ a₂)) (hs : ∀ b ∈ s, p (f b)) : p (s.inf' H f) := sup'_induction (α := αᵒᵈ) H f hp hs #align finset.inf'_induction Finset.inf'_induction theorem inf'_mem (s : Set α) (w : ∀ᵉ (x ∈ s) (y ∈ s), x ⊓ y ∈ s) {ι : Type*} (t : Finset ι) (H : t.Nonempty) (p : ι → α) (h : ∀ i ∈ t, p i ∈ s) : t.inf' H p ∈ s := inf'_induction H p w h #align finset.inf'_mem Finset.inf'_mem @[congr] theorem inf'_congr {t : Finset β} {f g : β → α} (h₁ : s = t) (h₂ : ∀ x ∈ s, f x = g x) : s.inf' H f = t.inf' (h₁ ▸ H) g := sup'_congr (α := αᵒᵈ) H h₁ h₂ #align finset.inf'_congr Finset.inf'_congr @[simp] theorem _root_.map_finset_inf' [SemilatticeInf β] [FunLike F α β] [InfHomClass F α β] (f : F) {s : Finset ι} (hs) (g : ι → α) : f (s.inf' hs g) = s.inf' hs (f ∘ g) := by refine hs.cons_induction ?_ ?_ <;> intros <;> simp [*] #align map_finset_inf' map_finset_inf' lemma nsmul_inf' [LinearOrderedAddCommMonoid β] {s : Finset α} (hs : s.Nonempty) (f : α → β) (n : ℕ) : s.inf' hs (fun a => n • f a) = n • s.inf' hs f := let ns : InfHom β β := { toFun := (n • ·), map_inf' := fun _ _ => (nsmul_right_mono n).map_min } (map_finset_inf' ns hs _).symm /-- To rewrite from right to left, use `Finset.inf'_comp_eq_image`. -/ @[simp] theorem inf'_image [DecidableEq β] {s : Finset γ} {f : γ → β} (hs : (s.image f).Nonempty) (g : β → α) : (s.image f).inf' hs g = s.inf' hs.of_image (g ∘ f) := @sup'_image αᵒᵈ _ _ _ _ _ _ hs _ #align finset.inf'_image Finset.inf'_image /-- A version of `Finset.inf'_image` with LHS and RHS reversed. Also, this lemma assumes that `s` is nonempty instead of assuming that its image is nonempty. -/ lemma inf'_comp_eq_image [DecidableEq β] {s : Finset γ} {f : γ → β} (hs : s.Nonempty) (g : β → α) : s.inf' hs (g ∘ f) = (s.image f).inf' (hs.image f) g := sup'_comp_eq_image (α := αᵒᵈ) hs g /-- To rewrite from right to left, use `Finset.inf'_comp_eq_map`. -/ @[simp] theorem inf'_map {s : Finset γ} {f : γ ↪ β} (g : β → α) (hs : (s.map f).Nonempty) : (s.map f).inf' hs g = s.inf' (map_nonempty.1 hs) (g ∘ f) := sup'_map (α := αᵒᵈ) _ hs #align finset.inf'_map Finset.inf'_map /-- A version of `Finset.inf'_map` with LHS and RHS reversed. Also, this lemma assumes that `s` is nonempty instead of assuming that its image is nonempty. -/ lemma inf'_comp_eq_map {s : Finset γ} {f : γ ↪ β} (g : β → α) (hs : s.Nonempty) : s.inf' hs (g ∘ f) = (s.map f).inf' (map_nonempty.2 hs) g := sup'_comp_eq_map (α := αᵒᵈ) g hs theorem inf'_mono {s₁ s₂ : Finset β} (h : s₁ ⊆ s₂) (h₁ : s₁.Nonempty) : s₂.inf' (h₁.mono h) f ≤ s₁.inf' h₁ f := Finset.le_inf' h₁ _ (fun _ hb => inf'_le _ (h hb)) /-- A version of `Finset.inf'_mono` acceptable for `@[gcongr]`. Instead of deducing `s₂.Nonempty` from `s₁.Nonempty` and `s₁ ⊆ s₂`, this version takes it as an argument. -/ @[gcongr] lemma _root_.GCongr.finset_inf'_mono {s₁ s₂ : Finset β} (h : s₁ ⊆ s₂) {h₁ : s₁.Nonempty} {h₂ : s₂.Nonempty} : s₂.inf' h₂ f ≤ s₁.inf' h₁ f := inf'_mono f h h₁ end Inf' section Sup variable [SemilatticeSup α] [OrderBot α] theorem sup'_eq_sup {s : Finset β} (H : s.Nonempty) (f : β → α) : s.sup' H f = s.sup f := le_antisymm (sup'_le H f fun _ => le_sup) (Finset.sup_le fun _ => le_sup' f) #align finset.sup'_eq_sup Finset.sup'_eq_sup theorem coe_sup_of_nonempty {s : Finset β} (h : s.Nonempty) (f : β → α) : (↑(s.sup f) : WithBot α) = s.sup ((↑) ∘ f) := by simp only [← sup'_eq_sup h, coe_sup' h] #align finset.coe_sup_of_nonempty Finset.coe_sup_of_nonempty end Sup section Inf variable [SemilatticeInf α] [OrderTop α] theorem inf'_eq_inf {s : Finset β} (H : s.Nonempty) (f : β → α) : s.inf' H f = s.inf f := sup'_eq_sup (α := αᵒᵈ) H f #align finset.inf'_eq_inf Finset.inf'_eq_inf theorem coe_inf_of_nonempty {s : Finset β} (h : s.Nonempty) (f : β → α) : (↑(s.inf f) : WithTop α) = s.inf ((↑) ∘ f) := coe_sup_of_nonempty (α := αᵒᵈ) h f #align finset.coe_inf_of_nonempty Finset.coe_inf_of_nonempty end Inf @[simp] protected theorem sup_apply {C : β → Type*} [∀ b : β, SemilatticeSup (C b)] [∀ b : β, OrderBot (C b)] (s : Finset α) (f : α → ∀ b : β, C b) (b : β) : s.sup f b = s.sup fun a => f a b := comp_sup_eq_sup_comp (fun x : ∀ b : β, C b => x b) (fun _ _ => rfl) rfl #align finset.sup_apply Finset.sup_apply @[simp] protected theorem inf_apply {C : β → Type*} [∀ b : β, SemilatticeInf (C b)] [∀ b : β, OrderTop (C b)] (s : Finset α) (f : α → ∀ b : β, C b) (b : β) : s.inf f b = s.inf fun a => f a b := Finset.sup_apply (C := fun b => (C b)ᵒᵈ) s f b #align finset.inf_apply Finset.inf_apply @[simp] protected theorem sup'_apply {C : β → Type*} [∀ b : β, SemilatticeSup (C b)] {s : Finset α} (H : s.Nonempty) (f : α → ∀ b : β, C b) (b : β) : s.sup' H f b = s.sup' H fun a => f a b := comp_sup'_eq_sup'_comp H (fun x : ∀ b : β, C b => x b) fun _ _ => rfl #align finset.sup'_apply Finset.sup'_apply @[simp] protected theorem inf'_apply {C : β → Type*} [∀ b : β, SemilatticeInf (C b)] {s : Finset α} (H : s.Nonempty) (f : α → ∀ b : β, C b) (b : β) : s.inf' H f b = s.inf' H fun a => f a b := Finset.sup'_apply (C := fun b => (C b)ᵒᵈ) H f b #align finset.inf'_apply Finset.inf'_apply @[simp] theorem toDual_sup' [SemilatticeSup α] {s : Finset ι} (hs : s.Nonempty) (f : ι → α) : toDual (s.sup' hs f) = s.inf' hs (toDual ∘ f) := rfl #align finset.to_dual_sup' Finset.toDual_sup' @[simp] theorem toDual_inf' [SemilatticeInf α] {s : Finset ι} (hs : s.Nonempty) (f : ι → α) : toDual (s.inf' hs f) = s.sup' hs (toDual ∘ f) := rfl #align finset.to_dual_inf' Finset.toDual_inf' @[simp] theorem ofDual_sup' [SemilatticeInf α] {s : Finset ι} (hs : s.Nonempty) (f : ι → αᵒᵈ) : ofDual (s.sup' hs f) = s.inf' hs (ofDual ∘ f) := rfl #align finset.of_dual_sup' Finset.ofDual_sup' @[simp] theorem ofDual_inf' [SemilatticeSup α] {s : Finset ι} (hs : s.Nonempty) (f : ι → αᵒᵈ) : ofDual (s.inf' hs f) = s.sup' hs (ofDual ∘ f) := rfl #align finset.of_dual_inf' Finset.ofDual_inf' section DistribLattice variable [DistribLattice α] {s : Finset ι} {t : Finset κ} (hs : s.Nonempty) (ht : t.Nonempty) {f : ι → α} {g : κ → α} {a : α} theorem sup'_inf_distrib_left (f : ι → α) (a : α) : a ⊓ s.sup' hs f = s.sup' hs fun i ↦ a ⊓ f i := by induction hs using Finset.Nonempty.cons_induction with | singleton => simp | cons _ _ _ hs ih => simp_rw [sup'_cons hs, inf_sup_left, ih] #align finset.sup'_inf_distrib_left Finset.sup'_inf_distrib_left theorem sup'_inf_distrib_right (f : ι → α) (a : α) : s.sup' hs f ⊓ a = s.sup' hs fun i => f i ⊓ a := by rw [inf_comm, sup'_inf_distrib_left]; simp_rw [inf_comm] #align finset.sup'_inf_distrib_right Finset.sup'_inf_distrib_right theorem sup'_inf_sup' (f : ι → α) (g : κ → α) : s.sup' hs f ⊓ t.sup' ht g = (s ×ˢ t).sup' (hs.product ht) fun i => f i.1 ⊓ g i.2 := by simp_rw [Finset.sup'_inf_distrib_right, Finset.sup'_inf_distrib_left, sup'_product_left] #align finset.sup'_inf_sup' Finset.sup'_inf_sup' theorem inf'_sup_distrib_left (f : ι → α) (a : α) : a ⊔ s.inf' hs f = s.inf' hs fun i => a ⊔ f i := @sup'_inf_distrib_left αᵒᵈ _ _ _ hs _ _ #align finset.inf'_sup_distrib_left Finset.inf'_sup_distrib_left theorem inf'_sup_distrib_right (f : ι → α) (a : α) : s.inf' hs f ⊔ a = s.inf' hs fun i => f i ⊔ a := @sup'_inf_distrib_right αᵒᵈ _ _ _ hs _ _ #align finset.inf'_sup_distrib_right Finset.inf'_sup_distrib_right theorem inf'_sup_inf' (f : ι → α) (g : κ → α) : s.inf' hs f ⊔ t.inf' ht g = (s ×ˢ t).inf' (hs.product ht) fun i => f i.1 ⊔ g i.2 := @sup'_inf_sup' αᵒᵈ _ _ _ _ _ hs ht _ _ #align finset.inf'_sup_inf' Finset.inf'_sup_inf' end DistribLattice section LinearOrder variable [LinearOrder α] {s : Finset ι} (H : s.Nonempty) {f : ι → α} {a : α} @[simp] theorem le_sup'_iff : a ≤ s.sup' H f ↔ ∃ b ∈ s, a ≤ f b := by rw [← WithBot.coe_le_coe, coe_sup', Finset.le_sup_iff (WithBot.bot_lt_coe a)] exact exists_congr (fun _ => and_congr_right' WithBot.coe_le_coe) #align finset.le_sup'_iff Finset.le_sup'_iff @[simp] theorem lt_sup'_iff : a < s.sup' H f ↔ ∃ b ∈ s, a < f b := by rw [← WithBot.coe_lt_coe, coe_sup', Finset.lt_sup_iff] exact exists_congr (fun _ => and_congr_right' WithBot.coe_lt_coe) #align finset.lt_sup'_iff Finset.lt_sup'_iff @[simp] theorem sup'_lt_iff : s.sup' H f < a ↔ ∀ i ∈ s, f i < a := by rw [← WithBot.coe_lt_coe, coe_sup', Finset.sup_lt_iff (WithBot.bot_lt_coe a)] exact forall₂_congr (fun _ _ => WithBot.coe_lt_coe) #align finset.sup'_lt_iff Finset.sup'_lt_iff @[simp] theorem inf'_le_iff : s.inf' H f ≤ a ↔ ∃ i ∈ s, f i ≤ a := le_sup'_iff (α := αᵒᵈ) H #align finset.inf'_le_iff Finset.inf'_le_iff @[simp] theorem inf'_lt_iff : s.inf' H f < a ↔ ∃ i ∈ s, f i < a := lt_sup'_iff (α := αᵒᵈ) H #align finset.inf'_lt_iff Finset.inf'_lt_iff @[simp] theorem lt_inf'_iff : a < s.inf' H f ↔ ∀ i ∈ s, a < f i := sup'_lt_iff (α := αᵒᵈ) H #align finset.lt_inf'_iff Finset.lt_inf'_iff theorem exists_mem_eq_sup' (f : ι → α) : ∃ i, i ∈ s ∧ s.sup' H f = f i := by induction H using Finset.Nonempty.cons_induction with | singleton c => exact ⟨c, mem_singleton_self c, rfl⟩ | cons c s hcs hs ih => rcases ih with ⟨b, hb, h'⟩ rw [sup'_cons hs, h'] cases le_total (f b) (f c) with | inl h => exact ⟨c, mem_cons.2 (Or.inl rfl), sup_eq_left.2 h⟩ | inr h => exact ⟨b, mem_cons.2 (Or.inr hb), sup_eq_right.2 h⟩ #align finset.exists_mem_eq_sup' Finset.exists_mem_eq_sup' theorem exists_mem_eq_inf' (f : ι → α) : ∃ i, i ∈ s ∧ s.inf' H f = f i := exists_mem_eq_sup' (α := αᵒᵈ) H f #align finset.exists_mem_eq_inf' Finset.exists_mem_eq_inf' theorem exists_mem_eq_sup [OrderBot α] (s : Finset ι) (h : s.Nonempty) (f : ι → α) : ∃ i, i ∈ s ∧ s.sup f = f i := sup'_eq_sup h f ▸ exists_mem_eq_sup' h f #align finset.exists_mem_eq_sup Finset.exists_mem_eq_sup theorem exists_mem_eq_inf [OrderTop α] (s : Finset ι) (h : s.Nonempty) (f : ι → α) : ∃ i, i ∈ s ∧ s.inf f = f i := exists_mem_eq_sup (α := αᵒᵈ) s h f #align finset.exists_mem_eq_inf Finset.exists_mem_eq_inf end LinearOrder /-! ### max and min of finite sets -/ section MaxMin variable [LinearOrder α] /-- Let `s` be a finset in a linear order. Then `s.max` is the maximum of `s` if `s` is not empty, and `⊥` otherwise. It belongs to `WithBot α`. If you want to get an element of `α`, see `s.max'`. -/ protected def max (s : Finset α) : WithBot α := sup s (↑) #align finset.max Finset.max theorem max_eq_sup_coe {s : Finset α} : s.max = s.sup (↑) := rfl #align finset.max_eq_sup_coe Finset.max_eq_sup_coe theorem max_eq_sup_withBot (s : Finset α) : s.max = sup s (↑) := rfl #align finset.max_eq_sup_with_bot Finset.max_eq_sup_withBot @[simp] theorem max_empty : (∅ : Finset α).max = ⊥ := rfl #align finset.max_empty Finset.max_empty @[simp] theorem max_insert {a : α} {s : Finset α} : (insert a s).max = max ↑a s.max := fold_insert_idem #align finset.max_insert Finset.max_insert @[simp] theorem max_singleton {a : α} : Finset.max {a} = (a : WithBot α) := by rw [← insert_emptyc_eq] exact max_insert #align finset.max_singleton Finset.max_singleton theorem max_of_mem {s : Finset α} {a : α} (h : a ∈ s) : ∃ b : α, s.max = b := by obtain ⟨b, h, _⟩ := le_sup (α := WithBot α) h _ rfl exact ⟨b, h⟩ #align finset.max_of_mem Finset.max_of_mem theorem max_of_nonempty {s : Finset α} (h : s.Nonempty) : ∃ a : α, s.max = a := let ⟨_, h⟩ := h max_of_mem h #align finset.max_of_nonempty Finset.max_of_nonempty theorem max_eq_bot {s : Finset α} : s.max = ⊥ ↔ s = ∅ := ⟨fun h ↦ s.eq_empty_or_nonempty.elim id fun H ↦ by obtain ⟨a, ha⟩ := max_of_nonempty H rw [h] at ha; cases ha; , -- the `;` is needed since the `cases` syntax allows `cases a, b` fun h ↦ h.symm ▸ max_empty⟩ #align finset.max_eq_bot Finset.max_eq_bot theorem mem_of_max {s : Finset α} : ∀ {a : α}, s.max = a → a ∈ s := by induction' s using Finset.induction_on with b s _ ih · intro _ H; cases H · intro a h by_cases p : b = a · induction p exact mem_insert_self b s · cases' max_choice (↑b) s.max with q q <;> rw [max_insert, q] at h · cases h cases p rfl · exact mem_insert_of_mem (ih h) #align finset.mem_of_max Finset.mem_of_max theorem le_max {a : α} {s : Finset α} (as : a ∈ s) : ↑a ≤ s.max := le_sup as #align finset.le_max Finset.le_max theorem not_mem_of_max_lt_coe {a : α} {s : Finset α} (h : s.max < a) : a ∉ s := mt le_max h.not_le #align finset.not_mem_of_max_lt_coe Finset.not_mem_of_max_lt_coe theorem le_max_of_eq {s : Finset α} {a b : α} (h₁ : a ∈ s) (h₂ : s.max = b) : a ≤ b := WithBot.coe_le_coe.mp <| (le_max h₁).trans h₂.le #align finset.le_max_of_eq Finset.le_max_of_eq theorem not_mem_of_max_lt {s : Finset α} {a b : α} (h₁ : b < a) (h₂ : s.max = ↑b) : a ∉ s := Finset.not_mem_of_max_lt_coe <| h₂.trans_lt <| WithBot.coe_lt_coe.mpr h₁ #align finset.not_mem_of_max_lt Finset.not_mem_of_max_lt @[gcongr] theorem max_mono {s t : Finset α} (st : s ⊆ t) : s.max ≤ t.max := sup_mono st #align finset.max_mono Finset.max_mono protected theorem max_le {M : WithBot α} {s : Finset α} (st : ∀ a ∈ s, (a : WithBot α) ≤ M) : s.max ≤ M := Finset.sup_le st #align finset.max_le Finset.max_le /-- Let `s` be a finset in a linear order. Then `s.min` is the minimum of `s` if `s` is not empty, and `⊤` otherwise. It belongs to `WithTop α`. If you want to get an element of `α`, see `s.min'`. -/ protected def min (s : Finset α) : WithTop α := inf s (↑) #align finset.min Finset.min theorem min_eq_inf_withTop (s : Finset α) : s.min = inf s (↑) := rfl #align finset.min_eq_inf_with_top Finset.min_eq_inf_withTop @[simp] theorem min_empty : (∅ : Finset α).min = ⊤ := rfl #align finset.min_empty Finset.min_empty @[simp] theorem min_insert {a : α} {s : Finset α} : (insert a s).min = min (↑a) s.min := fold_insert_idem #align finset.min_insert Finset.min_insert @[simp] theorem min_singleton {a : α} : Finset.min {a} = (a : WithTop α) := by rw [← insert_emptyc_eq] exact min_insert #align finset.min_singleton Finset.min_singleton theorem min_of_mem {s : Finset α} {a : α} (h : a ∈ s) : ∃ b : α, s.min = b := by obtain ⟨b, h, _⟩ := inf_le (α := WithTop α) h _ rfl exact ⟨b, h⟩ #align finset.min_of_mem Finset.min_of_mem theorem min_of_nonempty {s : Finset α} (h : s.Nonempty) : ∃ a : α, s.min = a := let ⟨_, h⟩ := h min_of_mem h #align finset.min_of_nonempty Finset.min_of_nonempty theorem min_eq_top {s : Finset α} : s.min = ⊤ ↔ s = ∅ := ⟨fun h => s.eq_empty_or_nonempty.elim id fun H => by let ⟨a, ha⟩ := min_of_nonempty H rw [h] at ha; cases ha; , -- Porting note: error without `done` fun h => h.symm ▸ min_empty⟩ #align finset.min_eq_top Finset.min_eq_top theorem mem_of_min {s : Finset α} : ∀ {a : α}, s.min = a → a ∈ s := @mem_of_max αᵒᵈ _ s #align finset.mem_of_min Finset.mem_of_min theorem min_le {a : α} {s : Finset α} (as : a ∈ s) : s.min ≤ a := inf_le as #align finset.min_le Finset.min_le theorem not_mem_of_coe_lt_min {a : α} {s : Finset α} (h : ↑a < s.min) : a ∉ s := mt min_le h.not_le #align finset.not_mem_of_coe_lt_min Finset.not_mem_of_coe_lt_min theorem min_le_of_eq {s : Finset α} {a b : α} (h₁ : b ∈ s) (h₂ : s.min = a) : a ≤ b := WithTop.coe_le_coe.mp <| h₂.ge.trans (min_le h₁) #align finset.min_le_of_eq Finset.min_le_of_eq theorem not_mem_of_lt_min {s : Finset α} {a b : α} (h₁ : a < b) (h₂ : s.min = ↑b) : a ∉ s := Finset.not_mem_of_coe_lt_min <| (WithTop.coe_lt_coe.mpr h₁).trans_eq h₂.symm #align finset.not_mem_of_lt_min Finset.not_mem_of_lt_min @[gcongr] theorem min_mono {s t : Finset α} (st : s ⊆ t) : t.min ≤ s.min := inf_mono st #align finset.min_mono Finset.min_mono protected theorem le_min {m : WithTop α} {s : Finset α} (st : ∀ a : α, a ∈ s → m ≤ a) : m ≤ s.min := Finset.le_inf st #align finset.le_min Finset.le_min /-- Given a nonempty finset `s` in a linear order `α`, then `s.min' h` is its minimum, as an element of `α`, where `h` is a proof of nonemptiness. Without this assumption, use instead `s.min`, taking values in `WithTop α`. -/ def min' (s : Finset α) (H : s.Nonempty) : α := inf' s H id #align finset.min' Finset.min' /-- Given a nonempty finset `s` in a linear order `α`, then `s.max' h` is its maximum, as an element of `α`, where `h` is a proof of nonemptiness. Without this assumption, use instead `s.max`, taking values in `WithBot α`. -/ def max' (s : Finset α) (H : s.Nonempty) : α := sup' s H id #align finset.max' Finset.max' variable (s : Finset α) (H : s.Nonempty) {x : α} theorem min'_mem : s.min' H ∈ s := mem_of_min <| by simp only [Finset.min, min', id_eq, coe_inf']; rfl #align finset.min'_mem Finset.min'_mem theorem min'_le (x) (H2 : x ∈ s) : s.min' ⟨x, H2⟩ ≤ x := min_le_of_eq H2 (WithTop.coe_untop _ _).symm #align finset.min'_le Finset.min'_le theorem le_min' (x) (H2 : ∀ y ∈ s, x ≤ y) : x ≤ s.min' H := H2 _ <| min'_mem _ _ #align finset.le_min' Finset.le_min' theorem isLeast_min' : IsLeast (↑s) (s.min' H) := ⟨min'_mem _ _, min'_le _⟩ #align finset.is_least_min' Finset.isLeast_min' @[simp] theorem le_min'_iff {x} : x ≤ s.min' H ↔ ∀ y ∈ s, x ≤ y := le_isGLB_iff (isLeast_min' s H).isGLB #align finset.le_min'_iff Finset.le_min'_iff /-- `{a}.min' _` is `a`. -/ @[simp] theorem min'_singleton (a : α) : ({a} : Finset α).min' (singleton_nonempty _) = a := by simp [min'] #align finset.min'_singleton Finset.min'_singleton theorem max'_mem : s.max' H ∈ s := mem_of_max <| by simp only [max', Finset.max, id_eq, coe_sup']; rfl #align finset.max'_mem Finset.max'_mem theorem le_max' (x) (H2 : x ∈ s) : x ≤ s.max' ⟨x, H2⟩ := le_max_of_eq H2 (WithBot.coe_unbot _ _).symm #align finset.le_max' Finset.le_max' theorem max'_le (x) (H2 : ∀ y ∈ s, y ≤ x) : s.max' H ≤ x := H2 _ <| max'_mem _ _ #align finset.max'_le Finset.max'_le theorem isGreatest_max' : IsGreatest (↑s) (s.max' H) := ⟨max'_mem _ _, le_max' _⟩ #align finset.is_greatest_max' Finset.isGreatest_max' @[simp] theorem max'_le_iff {x} : s.max' H ≤ x ↔ ∀ y ∈ s, y ≤ x := isLUB_le_iff (isGreatest_max' s H).isLUB #align finset.max'_le_iff Finset.max'_le_iff @[simp] theorem max'_lt_iff {x} : s.max' H < x ↔ ∀ y ∈ s, y < x := ⟨fun Hlt y hy => (s.le_max' y hy).trans_lt Hlt, fun H => H _ <| s.max'_mem _⟩ #align finset.max'_lt_iff Finset.max'_lt_iff @[simp] theorem lt_min'_iff : x < s.min' H ↔ ∀ y ∈ s, x < y := @max'_lt_iff αᵒᵈ _ _ H _ #align finset.lt_min'_iff Finset.lt_min'_iff theorem max'_eq_sup' : s.max' H = s.sup' H id := eq_of_forall_ge_iff fun _ => (max'_le_iff _ _).trans (sup'_le_iff _ _).symm #align finset.max'_eq_sup' Finset.max'_eq_sup' theorem min'_eq_inf' : s.min' H = s.inf' H id := @max'_eq_sup' αᵒᵈ _ s H #align finset.min'_eq_inf' Finset.min'_eq_inf' /-- `{a}.max' _` is `a`. -/ @[simp] theorem max'_singleton (a : α) : ({a} : Finset α).max' (singleton_nonempty _) = a := by simp [max'] #align finset.max'_singleton Finset.max'_singleton theorem min'_lt_max' {i j} (H1 : i ∈ s) (H2 : j ∈ s) (H3 : i ≠ j) : s.min' ⟨i, H1⟩ < s.max' ⟨i, H1⟩ := isGLB_lt_isLUB_of_ne (s.isLeast_min' _).isGLB (s.isGreatest_max' _).isLUB H1 H2 H3 #align finset.min'_lt_max' Finset.min'_lt_max' /-- If there's more than 1 element, the min' is less than the max'. An alternate version of `min'_lt_max'` which is sometimes more convenient. -/ theorem min'_lt_max'_of_card (h₂ : 1 < card s) : s.min' (Finset.card_pos.1 <| by omega) < s.max' (Finset.card_pos.1 <| by omega) := by rcases one_lt_card.1 h₂ with ⟨a, ha, b, hb, hab⟩ exact s.min'_lt_max' ha hb hab #align finset.min'_lt_max'_of_card Finset.min'_lt_max'_of_card theorem map_ofDual_min (s : Finset αᵒᵈ) : s.min.map ofDual = (s.image ofDual).max := by rw [max_eq_sup_withBot, sup_image] exact congr_fun Option.map_id _ #align finset.map_of_dual_min Finset.map_ofDual_min theorem map_ofDual_max (s : Finset αᵒᵈ) : s.max.map ofDual = (s.image ofDual).min := by rw [min_eq_inf_withTop, inf_image] exact congr_fun Option.map_id _ #align finset.map_of_dual_max Finset.map_ofDual_max theorem map_toDual_min (s : Finset α) : s.min.map toDual = (s.image toDual).max := by rw [max_eq_sup_withBot, sup_image] exact congr_fun Option.map_id _ #align finset.map_to_dual_min Finset.map_toDual_min theorem map_toDual_max (s : Finset α) : s.max.map toDual = (s.image toDual).min := by rw [min_eq_inf_withTop, inf_image] exact congr_fun Option.map_id _ #align finset.map_to_dual_max Finset.map_toDual_max -- Porting note: new proofs without `convert` for the next four theorems. theorem ofDual_min' {s : Finset αᵒᵈ} (hs : s.Nonempty) : ofDual (min' s hs) = max' (s.image ofDual) (hs.image _) := by rw [← WithBot.coe_eq_coe] simp only [min'_eq_inf', id_eq, ofDual_inf', Function.comp_apply, coe_sup', max'_eq_sup', sup_image] rfl #align finset.of_dual_min' Finset.ofDual_min' theorem ofDual_max' {s : Finset αᵒᵈ} (hs : s.Nonempty) : ofDual (max' s hs) = min' (s.image ofDual) (hs.image _) := by rw [← WithTop.coe_eq_coe] simp only [max'_eq_sup', id_eq, ofDual_sup', Function.comp_apply, coe_inf', min'_eq_inf', inf_image] rfl #align finset.of_dual_max' Finset.ofDual_max' theorem toDual_min' {s : Finset α} (hs : s.Nonempty) : toDual (min' s hs) = max' (s.image toDual) (hs.image _) := by rw [← WithBot.coe_eq_coe] simp only [min'_eq_inf', id_eq, toDual_inf', Function.comp_apply, coe_sup', max'_eq_sup', sup_image] rfl #align finset.to_dual_min' Finset.toDual_min' theorem toDual_max' {s : Finset α} (hs : s.Nonempty) : toDual (max' s hs) = min' (s.image toDual) (hs.image _) := by rw [← WithTop.coe_eq_coe] simp only [max'_eq_sup', id_eq, toDual_sup', Function.comp_apply, coe_inf', min'_eq_inf', inf_image] rfl #align finset.to_dual_max' Finset.toDual_max' theorem max'_subset {s t : Finset α} (H : s.Nonempty) (hst : s ⊆ t) : s.max' H ≤ t.max' (H.mono hst) := le_max' _ _ (hst (s.max'_mem H)) #align finset.max'_subset Finset.max'_subset theorem min'_subset {s t : Finset α} (H : s.Nonempty) (hst : s ⊆ t) : t.min' (H.mono hst) ≤ s.min' H := min'_le _ _ (hst (s.min'_mem H)) #align finset.min'_subset Finset.min'_subset theorem max'_insert (a : α) (s : Finset α) (H : s.Nonempty) : (insert a s).max' (s.insert_nonempty a) = max (s.max' H) a := (isGreatest_max' _ _).unique <| by rw [coe_insert, max_comm] exact (isGreatest_max' _ _).insert _ #align finset.max'_insert Finset.max'_insert theorem min'_insert (a : α) (s : Finset α) (H : s.Nonempty) : (insert a s).min' (s.insert_nonempty a) = min (s.min' H) a := (isLeast_min' _ _).unique <| by rw [coe_insert, min_comm] exact (isLeast_min' _ _).insert _ #align finset.min'_insert Finset.min'_insert theorem lt_max'_of_mem_erase_max' [DecidableEq α] {a : α} (ha : a ∈ s.erase (s.max' H)) : a < s.max' H := lt_of_le_of_ne (le_max' _ _ (mem_of_mem_erase ha)) <| ne_of_mem_of_not_mem ha <| not_mem_erase _ _ #align finset.lt_max'_of_mem_erase_max' Finset.lt_max'_of_mem_erase_max' theorem min'_lt_of_mem_erase_min' [DecidableEq α] {a : α} (ha : a ∈ s.erase (s.min' H)) : s.min' H < a := @lt_max'_of_mem_erase_max' αᵒᵈ _ s H _ a ha #align finset.min'_lt_of_mem_erase_min' Finset.min'_lt_of_mem_erase_min' /-- To rewrite from right to left, use `Monotone.map_finset_max'`. -/ @[simp] theorem max'_image [LinearOrder β] {f : α → β} (hf : Monotone f) (s : Finset α) (h : (s.image f).Nonempty) : (s.image f).max' h = f (s.max' h.of_image) := by simp only [max', sup'_image] exact .symm <| comp_sup'_eq_sup'_comp _ _ fun _ _ ↦ hf.map_max #align finset.max'_image Finset.max'_image /-- A version of `Finset.max'_image` with LHS and RHS reversed. Also, this version assumes that `s` is nonempty, not its image. -/ lemma _root_.Monotone.map_finset_max' [LinearOrder β] {f : α → β} (hf : Monotone f) {s : Finset α} (h : s.Nonempty) : f (s.max' h) = (s.image f).max' (h.image f) := .symm <| max'_image hf .. /-- To rewrite from right to left, use `Monotone.map_finset_min'`. -/ @[simp] theorem min'_image [LinearOrder β] {f : α → β} (hf : Monotone f) (s : Finset α) (h : (s.image f).Nonempty) : (s.image f).min' h = f (s.min' h.of_image) := by simp only [min', inf'_image] exact .symm <| comp_inf'_eq_inf'_comp _ _ fun _ _ ↦ hf.map_min #align finset.min'_image Finset.min'_image /-- A version of `Finset.min'_image` with LHS and RHS reversed. Also, this version assumes that `s` is nonempty, not its image. -/ lemma _root_.Monotone.map_finset_min' [LinearOrder β] {f : α → β} (hf : Monotone f) {s : Finset α} (h : s.Nonempty) : f (s.min' h) = (s.image f).min' (h.image f) := .symm <| min'_image hf .. theorem coe_max' {s : Finset α} (hs : s.Nonempty) : ↑(s.max' hs) = s.max := coe_sup' hs id #align finset.coe_max' Finset.coe_max' theorem coe_min' {s : Finset α} (hs : s.Nonempty) : ↑(s.min' hs) = s.min := coe_inf' hs id #align finset.coe_min' Finset.coe_min' theorem max_mem_image_coe {s : Finset α} (hs : s.Nonempty) : s.max ∈ (s.image (↑) : Finset (WithBot α)) := mem_image.2 ⟨max' s hs, max'_mem _ _, coe_max' hs⟩ #align finset.max_mem_image_coe Finset.max_mem_image_coe theorem min_mem_image_coe {s : Finset α} (hs : s.Nonempty) : s.min ∈ (s.image (↑) : Finset (WithTop α)) := mem_image.2 ⟨min' s hs, min'_mem _ _, coe_min' hs⟩ #align finset.min_mem_image_coe Finset.min_mem_image_coe theorem max_mem_insert_bot_image_coe (s : Finset α) : s.max ∈ (insert ⊥ (s.image (↑)) : Finset (WithBot α)) := mem_insert.2 <| s.eq_empty_or_nonempty.imp max_eq_bot.2 max_mem_image_coe #align finset.max_mem_insert_bot_image_coe Finset.max_mem_insert_bot_image_coe theorem min_mem_insert_top_image_coe (s : Finset α) : s.min ∈ (insert ⊤ (s.image (↑)) : Finset (WithTop α)) := mem_insert.2 <| s.eq_empty_or_nonempty.imp min_eq_top.2 min_mem_image_coe #align finset.min_mem_insert_top_image_coe Finset.min_mem_insert_top_image_coe theorem max'_erase_ne_self {s : Finset α} (s0 : (s.erase x).Nonempty) : (s.erase x).max' s0 ≠ x := ne_of_mem_erase (max'_mem _ s0) #align finset.max'_erase_ne_self Finset.max'_erase_ne_self theorem min'_erase_ne_self {s : Finset α} (s0 : (s.erase x).Nonempty) : (s.erase x).min' s0 ≠ x := ne_of_mem_erase (min'_mem _ s0) #align finset.min'_erase_ne_self Finset.min'_erase_ne_self theorem max_erase_ne_self {s : Finset α} : (s.erase x).max ≠ x := by by_cases s0 : (s.erase x).Nonempty · refine ne_of_eq_of_ne (coe_max' s0).symm ?_ exact WithBot.coe_eq_coe.not.mpr (max'_erase_ne_self _) · rw [not_nonempty_iff_eq_empty.mp s0, max_empty] exact WithBot.bot_ne_coe #align finset.max_erase_ne_self Finset.max_erase_ne_self theorem min_erase_ne_self {s : Finset α} : (s.erase x).min ≠ x := by -- Porting note: old proof `convert @max_erase_ne_self αᵒᵈ _ _ _` convert @max_erase_ne_self αᵒᵈ _ (toDual x) (s.map toDual.toEmbedding) using 1 apply congr_arg -- Porting note: forces unfolding to see `Finset.min` is `Finset.max` congr! ext; simp only [mem_map_equiv]; exact Iff.rfl #align finset.min_erase_ne_self Finset.min_erase_ne_self theorem exists_next_right {x : α} {s : Finset α} (h : ∃ y ∈ s, x < y) : ∃ y ∈ s, x < y ∧ ∀ z ∈ s, x < z → y ≤ z := have Hne : (s.filter (x < ·)).Nonempty := h.imp fun y hy => mem_filter.2 (by simpa) have aux := mem_filter.1 (min'_mem _ Hne) ⟨min' _ Hne, aux.1, by simp, fun z hzs hz => min'_le _ _ <| mem_filter.2 ⟨hzs, by simpa⟩⟩ #align finset.exists_next_right Finset.exists_next_right theorem exists_next_left {x : α} {s : Finset α} (h : ∃ y ∈ s, y < x) : ∃ y ∈ s, y < x ∧ ∀ z ∈ s, z < x → z ≤ y := @exists_next_right αᵒᵈ _ x s h #align finset.exists_next_left Finset.exists_next_left /-- If finsets `s` and `t` are interleaved, then `Finset.card s ≤ Finset.card t + 1`. -/ theorem card_le_of_interleaved {s t : Finset α} (h : ∀ᵉ (x ∈ s) (y ∈ s), x < y → (∀ z ∈ s, z ∉ Set.Ioo x y) → ∃ z ∈ t, x < z ∧ z < y) : s.card ≤ t.card + 1 := by replace h : ∀ᵉ (x ∈ s) (y ∈ s), x < y → ∃ z ∈ t, x < z ∧ z < y := by intro x hx y hy hxy rcases exists_next_right ⟨y, hy, hxy⟩ with ⟨a, has, hxa, ha⟩ rcases h x hx a has hxa fun z hzs hz => hz.2.not_le <| ha _ hzs hz.1 with ⟨b, hbt, hxb, hba⟩ exact ⟨b, hbt, hxb, hba.trans_le <| ha _ hy hxy⟩ set f : α → WithTop α := fun x => (t.filter fun y => x < y).min have f_mono : StrictMonoOn f s := by intro x hx y hy hxy rcases h x hx y hy hxy with ⟨a, hat, hxa, hay⟩ calc f x ≤ a := min_le (mem_filter.2 ⟨hat, by simpa⟩) _ < f y := (Finset.lt_inf_iff <| WithTop.coe_lt_top a).2 fun b hb => WithTop.coe_lt_coe.2 <| hay.trans (by simpa using (mem_filter.1 hb).2) calc s.card = (s.image f).card := (card_image_of_injOn f_mono.injOn).symm _ ≤ (insert ⊤ (t.image (↑)) : Finset (WithTop α)).card := card_mono <| image_subset_iff.2 fun x _ => insert_subset_insert _ (image_subset_image <| filter_subset _ _) (min_mem_insert_top_image_coe _) _ ≤ t.card + 1 := (card_insert_le _ _).trans (Nat.add_le_add_right card_image_le _) #align finset.card_le_of_interleaved Finset.card_le_of_interleaved /-- If finsets `s` and `t` are interleaved, then `Finset.card s ≤ Finset.card (t \ s) + 1`. -/ theorem card_le_diff_of_interleaved {s t : Finset α} (h : ∀ᵉ (x ∈ s) (y ∈ s), x < y → (∀ z ∈ s, z ∉ Set.Ioo x y) → ∃ z ∈ t, x < z ∧ z < y) : s.card ≤ (t \ s).card + 1 := card_le_of_interleaved fun x hx y hy hxy hs => let ⟨z, hzt, hxz, hzy⟩ := h x hx y hy hxy hs ⟨z, mem_sdiff.2 ⟨hzt, fun hzs => hs z hzs ⟨hxz, hzy⟩⟩, hxz, hzy⟩ #align finset.card_le_diff_of_interleaved Finset.card_le_diff_of_interleaved /-- Induction principle for `Finset`s in a linearly ordered type: a predicate is true on all `s : Finset α` provided that: * it is true on the empty `Finset`, * for every `s : Finset α` and an element `a` strictly greater than all elements of `s`, `p s` implies `p (insert a s)`. -/ @[elab_as_elim] theorem induction_on_max [DecidableEq α] {p : Finset α → Prop} (s : Finset α) (h0 : p ∅) (step : ∀ a s, (∀ x ∈ s, x < a) → p s → p (insert a s)) : p s := by induction' s using Finset.strongInductionOn with s ihs rcases s.eq_empty_or_nonempty with (rfl | hne) · exact h0 · have H : s.max' hne ∈ s := max'_mem s hne rw [← insert_erase H] exact step _ _ (fun x => s.lt_max'_of_mem_erase_max' hne) (ihs _ <| erase_ssubset H) #align finset.induction_on_max Finset.induction_on_max /-- Induction principle for `Finset`s in a linearly ordered type: a predicate is true on all `s : Finset α` provided that: * it is true on the empty `Finset`, * for every `s : Finset α` and an element `a` strictly less than all elements of `s`, `p s` implies `p (insert a s)`. -/ @[elab_as_elim] theorem induction_on_min [DecidableEq α] {p : Finset α → Prop} (s : Finset α) (h0 : p ∅) (step : ∀ a s, (∀ x ∈ s, a < x) → p s → p (insert a s)) : p s := @induction_on_max αᵒᵈ _ _ _ s h0 step #align finset.induction_on_min Finset.induction_on_min end MaxMin section MaxMinInductionValue variable [LinearOrder α] [LinearOrder β] /-- Induction principle for `Finset`s in any type from which a given function `f` maps to a linearly ordered type : a predicate is true on all `s : Finset α` provided that: * it is true on the empty `Finset`, * for every `s : Finset α` and an element `a` such that for elements of `s` denoted by `x` we have `f x ≤ f a`, `p s` implies `p (insert a s)`. -/ @[elab_as_elim] theorem induction_on_max_value [DecidableEq ι] (f : ι → α) {p : Finset ι → Prop} (s : Finset ι) (h0 : p ∅) (step : ∀ a s, a ∉ s → (∀ x ∈ s, f x ≤ f a) → p s → p (insert a s)) : p s := by induction' s using Finset.strongInductionOn with s ihs rcases (s.image f).eq_empty_or_nonempty with (hne | hne) · simp only [image_eq_empty] at hne simp only [hne, h0] · have H : (s.image f).max' hne ∈ s.image f := max'_mem (s.image f) hne simp only [mem_image, exists_prop] at H rcases H with ⟨a, has, hfa⟩ rw [← insert_erase has] refine step _ _ (not_mem_erase a s) (fun x hx => ?_) (ihs _ <| erase_ssubset has) rw [hfa] exact le_max' _ _ (mem_image_of_mem _ <| mem_of_mem_erase hx) #align finset.induction_on_max_value Finset.induction_on_max_value /-- Induction principle for `Finset`s in any type from which a given function `f` maps to a linearly ordered type : a predicate is true on all `s : Finset α` provided that: * it is true on the empty `Finset`, * for every `s : Finset α` and an element `a` such that for elements of `s` denoted by `x` we have `f a ≤ f x`, `p s` implies `p (insert a s)`. -/ @[elab_as_elim] theorem induction_on_min_value [DecidableEq ι] (f : ι → α) {p : Finset ι → Prop} (s : Finset ι) (h0 : p ∅) (step : ∀ a s, a ∉ s → (∀ x ∈ s, f a ≤ f x) → p s → p (insert a s)) : p s := @induction_on_max_value αᵒᵈ ι _ _ _ _ s h0 step #align finset.induction_on_min_value Finset.induction_on_min_value end MaxMinInductionValue section ExistsMaxMin variable [LinearOrder α] theorem exists_max_image (s : Finset β) (f : β → α) (h : s.Nonempty) : ∃ x ∈ s, ∀ x' ∈ s, f x' ≤ f x := by cases' max_of_nonempty (h.image f) with y hy rcases mem_image.mp (mem_of_max hy) with ⟨x, hx, rfl⟩ exact ⟨x, hx, fun x' hx' => le_max_of_eq (mem_image_of_mem f hx') hy⟩ #align finset.exists_max_image Finset.exists_max_image theorem exists_min_image (s : Finset β) (f : β → α) (h : s.Nonempty) : ∃ x ∈ s, ∀ x' ∈ s, f x ≤ f x' := @exists_max_image αᵒᵈ β _ s f h #align finset.exists_min_image Finset.exists_min_image end ExistsMaxMin theorem isGLB_iff_isLeast [LinearOrder α] (i : α) (s : Finset α) (hs : s.Nonempty) : IsGLB (s : Set α) i ↔ IsLeast (↑s) i := by refine ⟨fun his => ?_, IsLeast.isGLB⟩ suffices i = min' s hs by rw [this] exact isLeast_min' s hs rw [IsGLB, IsGreatest, mem_lowerBounds, mem_upperBounds] at his exact le_antisymm (his.1 (Finset.min' s hs) (Finset.min'_mem s hs)) (his.2 _ (Finset.min'_le s)) #align finset.is_glb_iff_is_least Finset.isGLB_iff_isLeast theorem isLUB_iff_isGreatest [LinearOrder α] (i : α) (s : Finset α) (hs : s.Nonempty) : IsLUB (s : Set α) i ↔ IsGreatest (↑s) i := @isGLB_iff_isLeast αᵒᵈ _ i s hs #align finset.is_lub_iff_is_greatest Finset.isLUB_iff_isGreatest theorem isGLB_mem [LinearOrder α] {i : α} (s : Finset α) (his : IsGLB (s : Set α) i) (hs : s.Nonempty) : i ∈ s := by rw [← mem_coe] exact ((isGLB_iff_isLeast i s hs).mp his).1 #align finset.is_glb_mem Finset.isGLB_mem theorem isLUB_mem [LinearOrder α] {i : α} (s : Finset α) (his : IsLUB (s : Set α) i) (hs : s.Nonempty) : i ∈ s := @isGLB_mem αᵒᵈ _ i s his hs #align finset.is_lub_mem Finset.isLUB_mem end Finset namespace Multiset theorem map_finset_sup [DecidableEq α] [DecidableEq β] (s : Finset γ) (f : γ → Multiset β) (g : β → α) (hg : Function.Injective g) : map g (s.sup f) = s.sup (map g ∘ f) := Finset.comp_sup_eq_sup_comp _ (fun _ _ => map_union hg) (map_zero _) #align multiset.map_finset_sup Multiset.map_finset_sup theorem count_finset_sup [DecidableEq β] (s : Finset α) (f : α → Multiset β) (b : β) : count b (s.sup f) = s.sup fun a => count b (f a) := by letI := Classical.decEq α refine s.induction ?_ ?_ · exact count_zero _ · intro i s _ ih rw [Finset.sup_insert, sup_eq_union, count_union, Finset.sup_insert, ih] rfl #align multiset.count_finset_sup Multiset.count_finset_sup theorem mem_sup {α β} [DecidableEq β] {s : Finset α} {f : α → Multiset β} {x : β} : x ∈ s.sup f ↔ ∃ v ∈ s, x ∈ f v := by induction s using Finset.cons_induction <;> simp [*] #align multiset.mem_sup Multiset.mem_sup end Multiset namespace Finset theorem mem_sup {α β} [DecidableEq β] {s : Finset α} {f : α → Finset β} {x : β} : x ∈ s.sup f ↔ ∃ v ∈ s, x ∈ f v := by change _ ↔ ∃ v ∈ s, x ∈ (f v).val rw [← Multiset.mem_sup, ← Multiset.mem_toFinset, sup_toFinset] simp_rw [val_toFinset] #align finset.mem_sup Finset.mem_sup theorem sup_eq_biUnion {α β} [DecidableEq β] (s : Finset α) (t : α → Finset β) : s.sup t = s.biUnion t := by ext rw [mem_sup, mem_biUnion] #align finset.sup_eq_bUnion Finset.sup_eq_biUnion @[simp] theorem sup_singleton'' [DecidableEq α] (s : Finset β) (f : β → α) : (s.sup fun b => {f b}) = s.image f := by ext a rw [mem_sup, mem_image] simp only [mem_singleton, eq_comm] #align finset.sup_singleton'' Finset.sup_singleton'' @[simp] theorem sup_singleton' [DecidableEq α] (s : Finset α) : s.sup singleton = s := (s.sup_singleton'' _).trans image_id #align finset.sup_singleton' Finset.sup_singleton' end Finset section Lattice variable {ι' : Sort*} [CompleteLattice α] /-- Supremum of `s i`, `i : ι`, is equal to the supremum over `t : Finset ι` of suprema `⨆ i ∈ t, s i`. This version assumes `ι` is a `Type*`. See `iSup_eq_iSup_finset'` for a version that works for `ι : Sort*`. -/ theorem iSup_eq_iSup_finset (s : ι → α) : ⨆ i, s i = ⨆ t : Finset ι, ⨆ i ∈ t, s i := by classical refine le_antisymm ?_ ?_ · exact iSup_le fun b => le_iSup_of_le {b} <| le_iSup_of_le b <| le_iSup_of_le (by simp) <| le_rfl · exact iSup_le fun t => iSup_le fun b => iSup_le fun _ => le_iSup _ _ #align supr_eq_supr_finset iSup_eq_iSup_finset /-- Supremum of `s i`, `i : ι`, is equal to the supremum over `t : Finset ι` of suprema `⨆ i ∈ t, s i`. This version works for `ι : Sort*`. See `iSup_eq_iSup_finset` for a version that assumes `ι : Type*` but has no `PLift`s. -/ theorem iSup_eq_iSup_finset' (s : ι' → α) : ⨆ i, s i = ⨆ t : Finset (PLift ι'), ⨆ i ∈ t, s (PLift.down i) := by rw [← iSup_eq_iSup_finset, ← Equiv.plift.surjective.iSup_comp]; rfl #align supr_eq_supr_finset' iSup_eq_iSup_finset' /-- Infimum of `s i`, `i : ι`, is equal to the infimum over `t : Finset ι` of infima `⨅ i ∈ t, s i`. This version assumes `ι` is a `Type*`. See `iInf_eq_iInf_finset'` for a version that works for `ι : Sort*`. -/ theorem iInf_eq_iInf_finset (s : ι → α) : ⨅ i, s i = ⨅ (t : Finset ι) (i ∈ t), s i := @iSup_eq_iSup_finset αᵒᵈ _ _ _ #align infi_eq_infi_finset iInf_eq_iInf_finset /-- Infimum of `s i`, `i : ι`, is equal to the infimum over `t : Finset ι` of infima `⨅ i ∈ t, s i`. This version works for `ι : Sort*`. See `iInf_eq_iInf_finset` for a version that assumes `ι : Type*` but has no `PLift`s. -/ theorem iInf_eq_iInf_finset' (s : ι' → α) : ⨅ i, s i = ⨅ t : Finset (PLift ι'), ⨅ i ∈ t, s (PLift.down i) := @iSup_eq_iSup_finset' αᵒᵈ _ _ _ #align infi_eq_infi_finset' iInf_eq_iInf_finset' end Lattice namespace Set variable {ι' : Sort*} /-- Union of an indexed family of sets `s : ι → Set α` is equal to the union of the unions of finite subfamilies. This version assumes `ι : Type*`. See also `iUnion_eq_iUnion_finset'` for a version that works for `ι : Sort*`. -/ theorem iUnion_eq_iUnion_finset (s : ι → Set α) : ⋃ i, s i = ⋃ t : Finset ι, ⋃ i ∈ t, s i := iSup_eq_iSup_finset s #align set.Union_eq_Union_finset Set.iUnion_eq_iUnion_finset /-- Union of an indexed family of sets `s : ι → Set α` is equal to the union of the unions of finite subfamilies. This version works for `ι : Sort*`. See also `iUnion_eq_iUnion_finset` for a version that assumes `ι : Type*` but avoids `PLift`s in the right hand side. -/ theorem iUnion_eq_iUnion_finset' (s : ι' → Set α) : ⋃ i, s i = ⋃ t : Finset (PLift ι'), ⋃ i ∈ t, s (PLift.down i) := iSup_eq_iSup_finset' s #align set.Union_eq_Union_finset' Set.iUnion_eq_iUnion_finset' /-- Intersection of an indexed family of sets `s : ι → Set α` is equal to the intersection of the intersections of finite subfamilies. This version assumes `ι : Type*`. See also `iInter_eq_iInter_finset'` for a version that works for `ι : Sort*`. -/ theorem iInter_eq_iInter_finset (s : ι → Set α) : ⋂ i, s i = ⋂ t : Finset ι, ⋂ i ∈ t, s i := iInf_eq_iInf_finset s #align set.Inter_eq_Inter_finset Set.iInter_eq_iInter_finset /-- Intersection of an indexed family of sets `s : ι → Set α` is equal to the intersection of the intersections of finite subfamilies. This version works for `ι : Sort*`. See also `iInter_eq_iInter_finset` for a version that assumes `ι : Type*` but avoids `PLift`s in the right hand side. -/ theorem iInter_eq_iInter_finset' (s : ι' → Set α) : ⋂ i, s i = ⋂ t : Finset (PLift ι'), ⋂ i ∈ t, s (PLift.down i) := iInf_eq_iInf_finset' s #align set.Inter_eq_Inter_finset' Set.iInter_eq_iInter_finset' end Set namespace Finset /-! ### Interaction with big lattice/set operations -/ section Lattice theorem iSup_coe [SupSet β] (f : α → β) (s : Finset α) : ⨆ x ∈ (↑s : Set α), f x = ⨆ x ∈ s, f x := rfl #align finset.supr_coe Finset.iSup_coe theorem iInf_coe [InfSet β] (f : α → β) (s : Finset α) : ⨅ x ∈ (↑s : Set α), f x = ⨅ x ∈ s, f x := rfl #align finset.infi_coe Finset.iInf_coe variable [CompleteLattice β] theorem iSup_singleton (a : α) (s : α → β) : ⨆ x ∈ ({a} : Finset α), s x = s a := by simp #align finset.supr_singleton Finset.iSup_singleton theorem iInf_singleton (a : α) (s : α → β) : ⨅ x ∈ ({a} : Finset α), s x = s a := by simp #align finset.infi_singleton Finset.iInf_singleton theorem iSup_option_toFinset (o : Option α) (f : α → β) : ⨆ x ∈ o.toFinset, f x = ⨆ x ∈ o, f x := by simp #align finset.supr_option_to_finset Finset.iSup_option_toFinset theorem iInf_option_toFinset (o : Option α) (f : α → β) : ⨅ x ∈ o.toFinset, f x = ⨅ x ∈ o, f x := @iSup_option_toFinset _ βᵒᵈ _ _ _ #align finset.infi_option_to_finset Finset.iInf_option_toFinset variable [DecidableEq α] theorem iSup_union {f : α → β} {s t : Finset α} : ⨆ x ∈ s ∪ t, f x = (⨆ x ∈ s, f x) ⊔ ⨆ x ∈ t, f x := by simp [iSup_or, iSup_sup_eq] #align finset.supr_union Finset.iSup_union theorem iInf_union {f : α → β} {s t : Finset α} : ⨅ x ∈ s ∪ t, f x = (⨅ x ∈ s, f x) ⊓ ⨅ x ∈ t, f x := @iSup_union α βᵒᵈ _ _ _ _ _ #align finset.infi_union Finset.iInf_union theorem iSup_insert (a : α) (s : Finset α) (t : α → β) : ⨆ x ∈ insert a s, t x = t a ⊔ ⨆ x ∈ s, t x := by rw [insert_eq] simp only [iSup_union, Finset.iSup_singleton] #align finset.supr_insert Finset.iSup_insert theorem iInf_insert (a : α) (s : Finset α) (t : α → β) : ⨅ x ∈ insert a s, t x = t a ⊓ ⨅ x ∈ s, t x := @iSup_insert α βᵒᵈ _ _ _ _ _ #align finset.infi_insert Finset.iInf_insert theorem iSup_finset_image {f : γ → α} {g : α → β} {s : Finset γ} : ⨆ x ∈ s.image f, g x = ⨆ y ∈ s, g (f y) := by rw [← iSup_coe, coe_image, iSup_image, iSup_coe] #align finset.supr_finset_image Finset.iSup_finset_image theorem iInf_finset_image {f : γ → α} {g : α → β} {s : Finset γ} : ⨅ x ∈ s.image f, g x = ⨅ y ∈ s, g (f y) := by rw [← iInf_coe, coe_image, iInf_image, iInf_coe] #align finset.infi_finset_image Finset.iInf_finset_image theorem iSup_insert_update {x : α} {t : Finset α} (f : α → β) {s : β} (hx : x ∉ t) : ⨆ i ∈ insert x t, Function.update f x s i = s ⊔ ⨆ i ∈ t, f i := by simp only [Finset.iSup_insert, update_same] rcongr (i hi); apply update_noteq; rintro rfl; exact hx hi #align finset.supr_insert_update Finset.iSup_insert_update theorem iInf_insert_update {x : α} {t : Finset α} (f : α → β) {s : β} (hx : x ∉ t) : ⨅ i ∈ insert x t, update f x s i = s ⊓ ⨅ i ∈ t, f i := @iSup_insert_update α βᵒᵈ _ _ _ _ f _ hx #align finset.infi_insert_update Finset.iInf_insert_update
Mathlib/Data/Finset/Lattice.lean
2,148
2,149
theorem iSup_biUnion (s : Finset γ) (t : γ → Finset α) (f : α → β) : ⨆ y ∈ s.biUnion t, f y = ⨆ (x ∈ s) (y ∈ t x), f y := by
simp [@iSup_comm _ α, iSup_and]
/- 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.AlgebraMap import Mathlib.Data.Matrix.Basis import Mathlib.Data.Matrix.DMatrix import Mathlib.RingTheory.MatrixAlgebra #align_import ring_theory.polynomial_algebra from "leanprover-community/mathlib"@"565eb991e264d0db702722b4bde52ee5173c9950" /-! # Algebra isomorphism between matrices of polynomials and polynomials of matrices Given `[CommRing R] [Ring A] [Algebra R A]` we show `A[X] ≃ₐ[R] (A ⊗[R] R[X])`. Combining this with the isomorphism `Matrix n n A ≃ₐ[R] (A ⊗[R] Matrix n n R)` proved earlier in `RingTheory.MatrixAlgebra`, we obtain the algebra isomorphism ``` def matPolyEquiv : Matrix n n R[X] ≃ₐ[R] (Matrix n n R)[X] ``` which is characterized by ``` coeff (matPolyEquiv m) k i j = coeff (m i j) k ``` We will use this algebra isomorphism to prove the Cayley-Hamilton theorem. -/ universe u v w open Polynomial TensorProduct open Algebra.TensorProduct (algHomOfLinearMapTensorProduct includeLeft) noncomputable section variable (R A : Type*) variable [CommSemiring R] variable [Semiring A] [Algebra R A] namespace PolyEquivTensor /-- (Implementation detail). The function underlying `A ⊗[R] R[X] →ₐ[R] A[X]`, as a bilinear function of two arguments. -/ -- Porting note: was `@[simps apply_apply]` @[simps! apply_apply] def toFunBilinear : A →ₗ[A] R[X] →ₗ[R] A[X] := LinearMap.toSpanSingleton A _ (aeval (Polynomial.X : A[X])).toLinearMap #align poly_equiv_tensor.to_fun_bilinear PolyEquivTensor.toFunBilinear
Mathlib/RingTheory/PolynomialAlgebra.lean
56
61
theorem toFunBilinear_apply_eq_sum (a : A) (p : R[X]) : toFunBilinear R A a p = p.sum fun n r => monomial n (a * algebraMap R A r) := by
simp only [toFunBilinear_apply_apply, aeval_def, eval₂_eq_sum, Polynomial.sum, Finset.smul_sum] congr with i : 1 rw [← Algebra.smul_def, ← C_mul', mul_smul_comm, C_mul_X_pow_eq_monomial, ← Algebra.commutes, ← Algebra.smul_def, smul_monomial]
/- Copyright (c) 2023 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.GroupTheory.CoprodI import Mathlib.GroupTheory.Coprod.Basic import Mathlib.GroupTheory.QuotientGroup import Mathlib.GroupTheory.Complement /-! ## Pushouts of Monoids and Groups This file defines wide pushouts of monoids and groups and proves some properties of the amalgamated product of groups (i.e. the special case where all the maps in the diagram are injective). ## Main definitions - `Monoid.PushoutI`: the pushout of a diagram of monoids indexed by a type `ι` - `Monoid.PushoutI.base`: the map from the amalgamating monoid to the pushout - `Monoid.PushoutI.of`: the map from each Monoid in the family to the pushout - `Monoid.PushoutI.lift`: the universal property used to define homomorphisms out of the pushout. - `Monoid.PushoutI.NormalWord`: a normal form for words in the pushout - `Monoid.PushoutI.of_injective`: if all the maps in the diagram are injective in a pushout of groups then so is `of` - `Monoid.PushoutI.Reduced.eq_empty_of_mem_range`: For any word `w` in the coproduct, if `w` is reduced (i.e none its letters are in the image of the base monoid), and nonempty, then `w` itself is not in the image of the base monoid. ## References * The normal form theorem follows these [notes](https://webspace.maths.qmul.ac.uk/i.m.chiswell/ggt/lecture_notes/lecture2.pdf) from Queen Mary University ## Tags amalgamated product, pushout, group -/ namespace Monoid open CoprodI Subgroup Coprod Function List variable {ι : Type*} {G : ι → Type*} {H : Type*} {K : Type*} [Monoid K] /-- The relation we quotient by to form the pushout -/ def PushoutI.con [∀ i, Monoid (G i)] [Monoid H] (φ : ∀ i, H →* G i) : Con (Coprod (CoprodI G) H) := conGen (fun x y : Coprod (CoprodI G) H => ∃ i x', x = inl (of (φ i x')) ∧ y = inr x') /-- The indexed pushout of monoids, which is the pushout in the category of monoids, or the category of groups. -/ def PushoutI [∀ i, Monoid (G i)] [Monoid H] (φ : ∀ i, H →* G i) : Type _ := (PushoutI.con φ).Quotient namespace PushoutI section Monoid variable [∀ i, Monoid (G i)] [Monoid H] {φ : ∀ i, H →* G i} protected instance mul : Mul (PushoutI φ) := by delta PushoutI; infer_instance protected instance one : One (PushoutI φ) := by delta PushoutI; infer_instance instance monoid : Monoid (PushoutI φ) := { Con.monoid _ with toMul := PushoutI.mul toOne := PushoutI.one } /-- The map from each indexing group into the pushout -/ def of (i : ι) : G i →* PushoutI φ := (Con.mk' _).comp <| inl.comp CoprodI.of variable (φ) in /-- The map from the base monoid into the pushout -/ def base : H →* PushoutI φ := (Con.mk' _).comp inr theorem of_comp_eq_base (i : ι) : (of i).comp (φ i) = (base φ) := by ext x apply (Con.eq _).2 refine ConGen.Rel.of _ _ ?_ simp only [MonoidHom.comp_apply, Set.mem_iUnion, Set.mem_range] exact ⟨_, _, rfl, rfl⟩ variable (φ) in theorem of_apply_eq_base (i : ι) (x : H) : of i (φ i x) = base φ x := by rw [← MonoidHom.comp_apply, of_comp_eq_base] /-- Define a homomorphism out of the pushout of monoids be defining it on each object in the diagram -/ def lift (f : ∀ i, G i →* K) (k : H →* K) (hf : ∀ i, (f i).comp (φ i) = k) : PushoutI φ →* K := Con.lift _ (Coprod.lift (CoprodI.lift f) k) <| by apply Con.conGen_le fun x y => ?_ rintro ⟨i, x', rfl, rfl⟩ simp only [DFunLike.ext_iff, MonoidHom.coe_comp, comp_apply] at hf simp [hf] @[simp] theorem lift_of (f : ∀ i, G i →* K) (k : H →* K) (hf : ∀ i, (f i).comp (φ i) = k) {i : ι} (g : G i) : (lift f k hf) (of i g : PushoutI φ) = f i g := by delta PushoutI lift of simp only [MonoidHom.coe_comp, Con.coe_mk', comp_apply, Con.lift_coe, lift_apply_inl, CoprodI.lift_of] @[simp] theorem lift_base (f : ∀ i, G i →* K) (k : H →* K) (hf : ∀ i, (f i).comp (φ i) = k) (g : H) : (lift f k hf) (base φ g : PushoutI φ) = k g := by delta PushoutI lift base simp only [MonoidHom.coe_comp, Con.coe_mk', comp_apply, Con.lift_coe, lift_apply_inr] -- `ext` attribute should be lower priority then `hom_ext_nonempty` @[ext 1199] theorem hom_ext {f g : PushoutI φ →* K} (h : ∀ i, f.comp (of i : G i →* _) = g.comp (of i : G i →* _)) (hbase : f.comp (base φ) = g.comp (base φ)) : f = g := (MonoidHom.cancel_right Con.mk'_surjective).mp <| Coprod.hom_ext (CoprodI.ext_hom _ _ h) hbase @[ext high] theorem hom_ext_nonempty [hn : Nonempty ι] {f g : PushoutI φ →* K} (h : ∀ i, f.comp (of i : G i →* _) = g.comp (of i : G i →* _)) : f = g := hom_ext h <| by cases hn with | intro i => ext rw [← of_comp_eq_base i, ← MonoidHom.comp_assoc, h, MonoidHom.comp_assoc] /-- The equivalence that is part of the universal property of the pushout. A hom out of the pushout is just a morphism out of all groups in the pushout that satisfies a commutativity condition. -/ @[simps] def homEquiv : (PushoutI φ →* K) ≃ { f : (Π i, G i →* K) × (H →* K) // ∀ i, (f.1 i).comp (φ i) = f.2 } := { toFun := fun f => ⟨(fun i => f.comp (of i), f.comp (base φ)), fun i => by rw [MonoidHom.comp_assoc, of_comp_eq_base]⟩ invFun := fun f => lift f.1.1 f.1.2 f.2, left_inv := fun _ => hom_ext (by simp [DFunLike.ext_iff]) (by simp [DFunLike.ext_iff]) right_inv := fun ⟨⟨_, _⟩, _⟩ => by simp [DFunLike.ext_iff, Function.funext_iff] } /-- The map from the coproduct into the pushout -/ def ofCoprodI : CoprodI G →* PushoutI φ := CoprodI.lift of @[simp] theorem ofCoprodI_of (i : ι) (g : G i) : (ofCoprodI (CoprodI.of g) : PushoutI φ) = of i g := by simp [ofCoprodI] theorem induction_on {motive : PushoutI φ → Prop} (x : PushoutI φ) (of : ∀ (i : ι) (g : G i), motive (of i g)) (base : ∀ h, motive (base φ h)) (mul : ∀ x y, motive x → motive y → motive (x * y)) : motive x := by delta PushoutI PushoutI.of PushoutI.base at * induction x using Con.induction_on with | H x => induction x using Coprod.induction_on with | inl g => induction g using CoprodI.induction_on with | h_of i g => exact of i g | h_mul x y ihx ihy => rw [map_mul] exact mul _ _ ihx ihy | h_one => simpa using base 1 | inr h => exact base h | mul x y ihx ihy => exact mul _ _ ihx ihy end Monoid variable [∀ i, Group (G i)] [Group H] {φ : ∀ i, H →* G i} instance : Group (PushoutI φ) := { Con.group (PushoutI.con φ) with toMonoid := PushoutI.monoid } namespace NormalWord /- In this section we show that there is a normal form for words in the amalgamated product. To have a normal form, we need to pick canonical choice of element of each right coset of the base group. The choice of element in the base group itself is `1`. Given a choice of element of each right coset, given by the type `Transversal φ` we can find a normal form. The normal form for an element is an element of the base group, multiplied by a word in the coproduct, where each letter in the word is the canonical choice of element of its coset. We then show that all groups in the diagram act faithfully on the normal form. This implies that the maps into the coproduct are injective. We demonstrate the action is faithful using the equivalence `equivPair`. We show that `G i` acts faithfully on `Pair d i` and that `Pair d i` is isomorphic to `NormalWord d`. Here, `d` is a `Transversal`. A `Pair d i` is a word in the coproduct, `Coprod G`, the `tail`, and an element of the group `G i`, the `head`. The first letter of the `tail` must not be an element of `G i`. Note that the `head` may be `1` Every letter in the `tail` must be in the transversal given by `d`. We then show that the equivalence between `NormalWord` and `PushoutI`, between the set of normal words and the elements of the amalgamated product. The key to this is the theorem `prod_smul_empty`, which says that going from `NormalWord` to `PushoutI` and back is the identity. This is proven by induction on the word using `consRecOn`. -/ variable (φ) /-- The data we need to pick a normal form for words in the pushout. We need to pick a canonical element of each coset. We also need all the maps in the diagram to be injective -/ structure Transversal : Type _ where /-- All maps in the diagram are injective -/ injective : ∀ i, Injective (φ i) /-- The underlying set, containing exactly one element of each coset of the base group -/ set : ∀ i, Set (G i) /-- The chosen element of the base group itself is the identity -/ one_mem : ∀ i, 1 ∈ set i /-- We have exactly one element of each coset of the base group -/ compl : ∀ i, IsComplement (φ i).range (set i) theorem transversal_nonempty (hφ : ∀ i, Injective (φ i)) : Nonempty (Transversal φ) := by choose t ht using fun i => (φ i).range.exists_right_transversal 1 apply Nonempty.intro exact { injective := hφ set := t one_mem := fun i => (ht i).2 compl := fun i => (ht i).1 } variable {φ} /-- The normal form for words in the pushout. Every element of the pushout is the product of an element of the base group and a word made up of letters each of which is in the transversal. -/ structure _root_.Monoid.PushoutI.NormalWord (d : Transversal φ) extends CoprodI.Word G where /-- Every `NormalWord` is the product of an element of the base group and a word made up of letters each of which is in the transversal. `head` is that element of the base group. -/ head : H /-- All letter in the word are in the transversal. -/ normalized : ∀ i g, ⟨i, g⟩ ∈ toList → g ∈ d.set i /-- A `Pair d i` is a word in the coproduct, `Coprod G`, the `tail`, and an element of the group `G i`, the `head`. The first letter of the `tail` must not be an element of `G i`. Note that the `head` may be `1` Every letter in the `tail` must be in the transversal given by `d`. Similar to `Monoid.CoprodI.Pair` except every letter must be in the transversal (not including the head letter). -/ structure Pair (d : Transversal φ) (i : ι) extends CoprodI.Word.Pair G i where /-- All letters in the word are in the transversal. -/ normalized : ∀ i g, ⟨i, g⟩ ∈ tail.toList → g ∈ d.set i variable {d : Transversal φ} /-- The empty normalized word, representing the identity element of the group. -/ @[simps!] def empty : NormalWord d := ⟨CoprodI.Word.empty, 1, fun i g => by simp [CoprodI.Word.empty]⟩ instance : Inhabited (NormalWord d) := ⟨NormalWord.empty⟩ instance (i : ι) : Inhabited (Pair d i) := ⟨{ (empty : NormalWord d) with head := 1, fstIdx_ne := fun h => by cases h }⟩ variable [DecidableEq ι] [∀ i, DecidableEq (G i)] @[ext] theorem ext {w₁ w₂ : NormalWord d} (hhead : w₁.head = w₂.head) (hlist : w₁.toList = w₂.toList) : w₁ = w₂ := by rcases w₁ with ⟨⟨_, _, _⟩, _, _⟩ rcases w₂ with ⟨⟨_, _, _⟩, _, _⟩ simp_all theorem ext_iff {w₁ w₂ : NormalWord d} : w₁ = w₂ ↔ w₁.head = w₂.head ∧ w₁.toList = w₂.toList := ⟨fun h => by simp [h], fun ⟨h₁, h₂⟩ => ext h₁ h₂⟩ open Subgroup.IsComplement /-- Given a word in `CoprodI`, if every letter is in the transversal and when we multiply by an element of the base group it still has this property, then the element of the base group we multiplied by was one. -/ theorem eq_one_of_smul_normalized (w : CoprodI.Word G) {i : ι} (h : H) (hw : ∀ i g, ⟨i, g⟩ ∈ w.toList → g ∈ d.set i) (hφw : ∀ j g, ⟨j, g⟩ ∈ (CoprodI.of (φ i h) • w).toList → g ∈ d.set j) : h = 1 := by simp only [← (d.compl _).equiv_snd_eq_self_iff_mem (one_mem _)] at hw hφw have hhead : ((d.compl i).equiv (Word.equivPair i w).head).2 = (Word.equivPair i w).head := by rw [Word.equivPair_head] split_ifs with h · rcases h with ⟨_, rfl⟩ exact hw _ _ (List.head_mem _) · rw [equiv_one (d.compl i) (one_mem _) (d.one_mem _)] by_contra hh1 have := hφw i (φ i h * (Word.equivPair i w).head) ?_ · apply hh1 rw [equiv_mul_left_of_mem (d.compl i) ⟨_, rfl⟩, hhead] at this simpa [((injective_iff_map_eq_one' _).1 (d.injective i))] using this · simp only [Word.mem_smul_iff, not_true, false_and, ne_eq, Option.mem_def, mul_right_inj, exists_eq_right', mul_right_eq_self, exists_prop, true_and, false_or] constructor · intro h apply_fun (d.compl i).equiv at h simp only [Prod.ext_iff, equiv_one (d.compl i) (one_mem _) (d.one_mem _), equiv_mul_left_of_mem (d.compl i) ⟨_, rfl⟩ , hhead, Subtype.ext_iff, Prod.ext_iff, Subgroup.coe_mul] at h rcases h with ⟨h₁, h₂⟩ rw [h₂, equiv_one (d.compl i) (one_mem _) (d.one_mem _), mul_one, ((injective_iff_map_eq_one' _).1 (d.injective i))] at h₁ contradiction · rw [Word.equivPair_head] dsimp split_ifs with hep · rcases hep with ⟨hnil, rfl⟩ rw [head?_eq_head _ hnil] simp_all · push_neg at hep by_cases hw : w.toList = [] · simp [hw, Word.fstIdx] · simp [head?_eq_head _ hw, Word.fstIdx, hep hw] theorem ext_smul {w₁ w₂ : NormalWord d} (i : ι) (h : CoprodI.of (φ i w₁.head) • w₁.toWord = CoprodI.of (φ i w₂.head) • w₂.toWord) : w₁ = w₂ := by rcases w₁ with ⟨w₁, h₁, hw₁⟩ rcases w₂ with ⟨w₂, h₂, hw₂⟩ dsimp at * rw [smul_eq_iff_eq_inv_smul, ← mul_smul] at h subst h simp only [← map_inv, ← map_mul] at hw₁ have : h₁⁻¹ * h₂ = 1 := eq_one_of_smul_normalized w₂ (h₁⁻¹ * h₂) hw₂ hw₁ rw [inv_mul_eq_one] at this; subst this simp /-- A constructor that multiplies a `NormalWord` by an element, with condition to make sure the underlying list does get longer. -/ @[simps!] noncomputable def cons {i} (g : G i) (w : NormalWord d) (hmw : w.fstIdx ≠ some i) (hgr : g ∉ (φ i).range) : NormalWord d := letI n := (d.compl i).equiv (g * (φ i w.head)) letI w' := Word.cons (n.2 : G i) w.toWord hmw (mt (coe_equiv_snd_eq_one_iff_mem _ (d.one_mem _)).1 (mt (mul_mem_cancel_right (by simp)).1 hgr)) { toWord := w' head := (MonoidHom.ofInjective (d.injective i)).symm n.1 normalized := fun i g hg => by simp only [w', Word.cons, mem_cons, Sigma.mk.inj_iff] at hg rcases hg with ⟨rfl, hg | hg⟩ · simp · exact w.normalized _ _ (by assumption) } /-- Given a pair `(head, tail)`, we can form a word by prepending `head` to `tail`, but putting head into normal form first, by making sure it is expressed as an element of the base group multiplied by an element of the transversal. -/ noncomputable def rcons (i : ι) (p : Pair d i) : NormalWord d := letI n := (d.compl i).equiv p.head let w := (Word.equivPair i).symm { p.toPair with head := n.2 } { toWord := w head := (MonoidHom.ofInjective (d.injective i)).symm n.1 normalized := fun i g hg => by dsimp [w] at hg rw [Word.equivPair_symm, Word.mem_rcons_iff] at hg rcases hg with hg | ⟨_, rfl, rfl⟩ · exact p.normalized _ _ hg · simp } theorem rcons_injective {i : ι} : Function.Injective (rcons (d := d) i) := by rintro ⟨⟨head₁, tail₁⟩, _⟩ ⟨⟨head₂, tail₂⟩, _⟩ simp only [rcons, NormalWord.mk.injEq, EmbeddingLike.apply_eq_iff_eq, Word.Pair.mk.injEq, Pair.mk.injEq, and_imp] intro h₁ h₂ h₃ subst h₂ rw [← equiv_fst_mul_equiv_snd (d.compl i) head₁, ← equiv_fst_mul_equiv_snd (d.compl i) head₂, h₁, h₃] simp /-- The equivalence between `NormalWord`s and pairs. We can turn a `NormalWord` into a pair by taking the head of the `List` if it is in `G i` and multiplying it by the element of the base group. -/ noncomputable def equivPair (i) : NormalWord d ≃ Pair d i := letI toFun : NormalWord d → Pair d i := fun w => letI p := Word.equivPair i (CoprodI.of (φ i w.head) • w.toWord) { toPair := p normalized := fun j g hg => by dsimp only [p] at hg rw [Word.of_smul_def, ← Word.equivPair_symm, Equiv.apply_symm_apply] at hg dsimp at hg exact w.normalized _ _ (Word.mem_of_mem_equivPair_tail _ hg) } haveI leftInv : Function.LeftInverse (rcons i) toFun := fun w => ext_smul i <| by simp only [rcons, Word.equivPair_symm, Word.equivPair_smul_same, Word.equivPair_tail_eq_inv_smul, Word.rcons_eq_smul, MonoidHom.apply_ofInjective_symm, equiv_fst_eq_mul_inv, mul_assoc, map_mul, map_inv, mul_smul, inv_smul_smul, smul_inv_smul] { toFun := toFun invFun := rcons i left_inv := leftInv right_inv := fun _ => rcons_injective (leftInv _) } noncomputable instance summandAction (i : ι) : MulAction (G i) (NormalWord d) := { smul := fun g w => (equivPair i).symm { equivPair i w with head := g * (equivPair i w).head } one_smul := fun _ => by dsimp [instHSMul] rw [one_mul] exact (equivPair i).symm_apply_apply _ mul_smul := fun _ _ _ => by dsimp [instHSMul] simp [mul_assoc, Equiv.apply_symm_apply, Function.End.mul_def] } instance baseAction : MulAction H (NormalWord d) := { smul := fun h w => { w with head := h * w.head }, one_smul := by simp [instHSMul] mul_smul := by simp [instHSMul, mul_assoc] } theorem base_smul_def' (h : H) (w : NormalWord d) : h • w = { w with head := h * w.head } := rfl theorem summand_smul_def' {i : ι} (g : G i) (w : NormalWord d) : g • w = (equivPair i).symm { equivPair i w with head := g * (equivPair i w).head } := rfl noncomputable instance mulAction : MulAction (PushoutI φ) (NormalWord d) := MulAction.ofEndHom <| lift (fun i => MulAction.toEndHom) MulAction.toEndHom <| by intro i simp only [MulAction.toEndHom, DFunLike.ext_iff, MonoidHom.coe_comp, MonoidHom.coe_mk, OneHom.coe_mk, comp_apply] intro h funext w apply NormalWord.ext_smul i simp only [summand_smul_def', equivPair, rcons, Word.equivPair_symm, Equiv.coe_fn_mk, Equiv.coe_fn_symm_mk, Word.equivPair_smul_same, Word.equivPair_tail_eq_inv_smul, Word.rcons_eq_smul, equiv_fst_eq_mul_inv, map_mul, map_inv, mul_smul, inv_smul_smul, smul_inv_smul, base_smul_def', MonoidHom.apply_ofInjective_symm] theorem base_smul_def (h : H) (w : NormalWord d) : base φ h • w = { w with head := h * w.head } := by dsimp [NormalWord.mulAction, instHSMul, SMul.smul] rw [lift_base] rfl theorem summand_smul_def {i : ι} (g : G i) (w : NormalWord d) : of (φ := φ) i g • w = (equivPair i).symm { equivPair i w with head := g * (equivPair i w).head } := by dsimp [NormalWord.mulAction, instHSMul, SMul.smul] rw [lift_of] rfl theorem of_smul_eq_smul {i : ι} (g : G i) (w : NormalWord d) : of (φ := φ) i g • w = g • w := by rw [summand_smul_def, summand_smul_def'] theorem base_smul_eq_smul (h : H) (w : NormalWord d) : base φ h • w = h • w := by rw [base_smul_def, base_smul_def'] /-- Induction principle for `NormalWord`, that corresponds closely to inducting on the underlying list. -/ @[elab_as_elim] noncomputable def consRecOn {motive : NormalWord d → Sort _} (w : NormalWord d) (h_empty : motive empty) (h_cons : ∀ (i : ι) (g : G i) (w : NormalWord d) (hmw : w.fstIdx ≠ some i) (_hgn : g ∈ d.set i) (hgr : g ∉ (φ i).range) (_hw1 : w.head = 1), motive w → motive (cons g w hmw hgr)) (h_base : ∀ (h : H) (w : NormalWord d), w.head = 1 → motive w → motive (base φ h • w)) : motive w := by rcases w with ⟨w, head, h3⟩ convert h_base head ⟨w, 1, h3⟩ rfl ?_ · simp [base_smul_def] · induction w using Word.consRecOn with | h_empty => exact h_empty | h_cons i g w h1 hg1 ih => convert h_cons i g ⟨w, 1, fun _ _ h => h3 _ _ (List.mem_cons_of_mem _ h)⟩ h1 (h3 _ _ (List.mem_cons_self _ _)) ?_ rfl (ih ?_) · ext simp only [Word.cons, Option.mem_def, cons, map_one, mul_one, (equiv_snd_eq_self_iff_mem (d.compl i) (one_mem _)).2 (h3 _ _ (List.mem_cons_self _ _))] · apply d.injective i simp only [cons, equiv_fst_eq_mul_inv, MonoidHom.apply_ofInjective_symm, map_one, mul_one, mul_right_inv, (equiv_snd_eq_self_iff_mem (d.compl i) (one_mem _)).2 (h3 _ _ (List.mem_cons_self _ _))] · rwa [← SetLike.mem_coe, ← coe_equiv_snd_eq_one_iff_mem (d.compl i) (d.one_mem _), (equiv_snd_eq_self_iff_mem (d.compl i) (one_mem _)).2 (h3 _ _ (List.mem_cons_self _ _))] /-- Take the product of a normal word as an element of the `PushoutI`. We show that this is bijective, in `NormalWord.equiv`. -/ def prod (w : NormalWord d) : PushoutI φ := base φ w.head * ofCoprodI (w.toWord).prod theorem cons_eq_smul {i : ι} (g : G i) (w : NormalWord d) (hmw : w.fstIdx ≠ some i) (hgr : g ∉ (φ i).range) : cons g w hmw hgr = of (φ := φ) i g • w := by apply ext_smul i simp only [cons, ne_eq, Word.cons_eq_smul, MonoidHom.apply_ofInjective_symm, equiv_fst_eq_mul_inv, mul_assoc, map_mul, map_inv, mul_smul, inv_smul_smul, summand_smul_def, equivPair, rcons, Word.equivPair_symm, Word.rcons_eq_smul, Equiv.coe_fn_mk, Word.equivPair_tail_eq_inv_smul, Equiv.coe_fn_symm_mk, smul_inv_smul] @[simp] theorem prod_summand_smul {i : ι} (g : G i) (w : NormalWord d) : (g • w).prod = of i g * w.prod := by simp only [prod, summand_smul_def', equivPair, rcons, Word.equivPair_symm, Equiv.coe_fn_mk, Equiv.coe_fn_symm_mk, Word.equivPair_smul_same, Word.equivPair_tail_eq_inv_smul, Word.rcons_eq_smul, ← of_apply_eq_base φ i, MonoidHom.apply_ofInjective_symm, equiv_fst_eq_mul_inv, mul_assoc, map_mul, map_inv, Word.prod_smul, ofCoprodI_of, inv_mul_cancel_left, mul_inv_cancel_left] @[simp] theorem prod_base_smul (h : H) (w : NormalWord d) : (h • w).prod = base φ h * w.prod := by simp only [base_smul_def', prod, map_mul, mul_assoc] @[simp] theorem prod_smul (g : PushoutI φ) (w : NormalWord d) : (g • w).prod = g * w.prod := by induction g using PushoutI.induction_on generalizing w with | of i g => rw [of_smul_eq_smul, prod_summand_smul] | base h => rw [base_smul_eq_smul, prod_base_smul] | mul x y ihx ihy => rw [mul_smul, ihx, ihy, mul_assoc] @[simp] theorem prod_empty : (empty : NormalWord d).prod = 1 := by simp [prod, empty] @[simp]
Mathlib/GroupTheory/PushoutI.lean
548
552
theorem prod_cons {i} (g : G i) (w : NormalWord d) (hmw : w.fstIdx ≠ some i) (hgr : g ∉ (φ i).range) : (cons g w hmw hgr).prod = of i g * w.prod := by
simp only [prod, cons, Word.prod, List.map, ← of_apply_eq_base φ i, equiv_fst_eq_mul_inv, mul_assoc, MonoidHom.apply_ofInjective_symm, List.prod_cons, map_mul, map_inv, ofCoprodI_of, inv_mul_cancel_left]
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Mario Carneiro -/ import Mathlib.Data.Bool.Basic import Mathlib.Data.Option.Defs import Mathlib.Data.Prod.Basic import Mathlib.Data.Sigma.Basic import Mathlib.Data.Subtype import Mathlib.Data.Sum.Basic import Mathlib.Init.Data.Sigma.Basic import Mathlib.Logic.Equiv.Defs import Mathlib.Logic.Function.Conjugate import Mathlib.Tactic.Lift import Mathlib.Tactic.Convert import Mathlib.Tactic.Contrapose import Mathlib.Tactic.GeneralizeProofs import Mathlib.Tactic.SimpRw #align_import logic.equiv.basic from "leanprover-community/mathlib"@"cd391184c85986113f8c00844cfe6dda1d34be3d" /-! # Equivalence between types In this file we continue the work on equivalences begun in `Logic/Equiv/Defs.lean`, defining * canonical isomorphisms between various types: e.g., - `Equiv.sumEquivSigmaBool` is the canonical equivalence between the sum of two types `α ⊕ β` and the sigma-type `Σ b : Bool, b.casesOn α β`; - `Equiv.prodSumDistrib : α × (β ⊕ γ) ≃ (α × β) ⊕ (α × γ)` shows that type product and type sum satisfy the distributive law up to a canonical equivalence; * operations on equivalences: e.g., - `Equiv.prodCongr ea eb : α₁ × β₁ ≃ α₂ × β₂`: combine two equivalences `ea : α₁ ≃ α₂` and `eb : β₁ ≃ β₂` using `Prod.map`. More definitions of this kind can be found in other files. E.g., `Data/Equiv/TransferInstance.lean` does it for many algebraic type classes like `Group`, `Module`, etc. ## Tags equivalence, congruence, bijective map -/ set_option autoImplicit true universe u open Function namespace Equiv /-- `PProd α β` is equivalent to `α × β` -/ @[simps apply symm_apply] def pprodEquivProd : PProd α β ≃ α × β where toFun x := (x.1, x.2) invFun x := ⟨x.1, x.2⟩ left_inv := fun _ => rfl right_inv := fun _ => rfl #align equiv.pprod_equiv_prod Equiv.pprodEquivProd #align equiv.pprod_equiv_prod_apply Equiv.pprodEquivProd_apply #align equiv.pprod_equiv_prod_symm_apply Equiv.pprodEquivProd_symm_apply /-- Product of two equivalences, in terms of `PProd`. If `α ≃ β` and `γ ≃ δ`, then `PProd α γ ≃ PProd β δ`. -/ -- Porting note: in Lean 3 this had `@[congr]` @[simps apply] def pprodCongr (e₁ : α ≃ β) (e₂ : γ ≃ δ) : PProd α γ ≃ PProd β δ where toFun x := ⟨e₁ x.1, e₂ x.2⟩ invFun x := ⟨e₁.symm x.1, e₂.symm x.2⟩ left_inv := fun ⟨x, y⟩ => by simp right_inv := fun ⟨x, y⟩ => by simp #align equiv.pprod_congr Equiv.pprodCongr #align equiv.pprod_congr_apply Equiv.pprodCongr_apply /-- Combine two equivalences using `PProd` in the domain and `Prod` in the codomain. -/ @[simps! apply symm_apply] def pprodProd (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : PProd α₁ β₁ ≃ α₂ × β₂ := (ea.pprodCongr eb).trans pprodEquivProd #align equiv.pprod_prod Equiv.pprodProd #align equiv.pprod_prod_apply Equiv.pprodProd_apply #align equiv.pprod_prod_symm_apply Equiv.pprodProd_symm_apply /-- Combine two equivalences using `PProd` in the codomain and `Prod` in the domain. -/ @[simps! apply symm_apply] def prodPProd (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : α₁ × β₁ ≃ PProd α₂ β₂ := (ea.symm.pprodProd eb.symm).symm #align equiv.prod_pprod Equiv.prodPProd #align equiv.prod_pprod_symm_apply Equiv.prodPProd_symm_apply #align equiv.prod_pprod_apply Equiv.prodPProd_apply /-- `PProd α β` is equivalent to `PLift α × PLift β` -/ @[simps! apply symm_apply] def pprodEquivProdPLift : PProd α β ≃ PLift α × PLift β := Equiv.plift.symm.pprodProd Equiv.plift.symm #align equiv.pprod_equiv_prod_plift Equiv.pprodEquivProdPLift #align equiv.pprod_equiv_prod_plift_symm_apply Equiv.pprodEquivProdPLift_symm_apply #align equiv.pprod_equiv_prod_plift_apply Equiv.pprodEquivProdPLift_apply /-- Product of two equivalences. If `α₁ ≃ α₂` and `β₁ ≃ β₂`, then `α₁ × β₁ ≃ α₂ × β₂`. This is `Prod.map` as an equivalence. -/ -- Porting note: in Lean 3 there was also a @[congr] tag @[simps (config := .asFn) apply] def prodCongr (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : α₁ × β₁ ≃ α₂ × β₂ := ⟨Prod.map e₁ e₂, Prod.map e₁.symm e₂.symm, fun ⟨a, b⟩ => by simp, fun ⟨a, b⟩ => by simp⟩ #align equiv.prod_congr Equiv.prodCongr #align equiv.prod_congr_apply Equiv.prodCongr_apply @[simp] theorem prodCongr_symm (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : (prodCongr e₁ e₂).symm = prodCongr e₁.symm e₂.symm := rfl #align equiv.prod_congr_symm Equiv.prodCongr_symm /-- Type product is commutative up to an equivalence: `α × β ≃ β × α`. This is `Prod.swap` as an equivalence. -/ def prodComm (α β) : α × β ≃ β × α := ⟨Prod.swap, Prod.swap, Prod.swap_swap, Prod.swap_swap⟩ #align equiv.prod_comm Equiv.prodComm @[simp] theorem coe_prodComm (α β) : (⇑(prodComm α β) : α × β → β × α) = Prod.swap := rfl #align equiv.coe_prod_comm Equiv.coe_prodComm @[simp] theorem prodComm_apply (x : α × β) : prodComm α β x = x.swap := rfl #align equiv.prod_comm_apply Equiv.prodComm_apply @[simp] theorem prodComm_symm (α β) : (prodComm α β).symm = prodComm β α := rfl #align equiv.prod_comm_symm Equiv.prodComm_symm /-- Type product is associative up to an equivalence. -/ @[simps] def prodAssoc (α β γ) : (α × β) × γ ≃ α × β × γ := ⟨fun p => (p.1.1, p.1.2, p.2), fun p => ((p.1, p.2.1), p.2.2), fun ⟨⟨_, _⟩, _⟩ => rfl, fun ⟨_, ⟨_, _⟩⟩ => rfl⟩ #align equiv.prod_assoc Equiv.prodAssoc #align equiv.prod_assoc_symm_apply Equiv.prodAssoc_symm_apply #align equiv.prod_assoc_apply Equiv.prodAssoc_apply /-- Four-way commutativity of `prod`. The name matches `mul_mul_mul_comm`. -/ @[simps apply] def prodProdProdComm (α β γ δ : Type*) : (α × β) × γ × δ ≃ (α × γ) × β × δ where toFun abcd := ((abcd.1.1, abcd.2.1), (abcd.1.2, abcd.2.2)) invFun acbd := ((acbd.1.1, acbd.2.1), (acbd.1.2, acbd.2.2)) left_inv := fun ⟨⟨_a, _b⟩, ⟨_c, _d⟩⟩ => rfl right_inv := fun ⟨⟨_a, _c⟩, ⟨_b, _d⟩⟩ => rfl #align equiv.prod_prod_prod_comm Equiv.prodProdProdComm @[simp] theorem prodProdProdComm_symm (α β γ δ : Type*) : (prodProdProdComm α β γ δ).symm = prodProdProdComm α γ β δ := rfl #align equiv.prod_prod_prod_comm_symm Equiv.prodProdProdComm_symm /-- `γ`-valued functions on `α × β` are equivalent to functions `α → β → γ`. -/ @[simps (config := .asFn)] def curry (α β γ) : (α × β → γ) ≃ (α → β → γ) where toFun := Function.curry invFun := uncurry left_inv := uncurry_curry right_inv := curry_uncurry #align equiv.curry Equiv.curry #align equiv.curry_symm_apply Equiv.curry_symm_apply #align equiv.curry_apply Equiv.curry_apply section /-- `PUnit` is a right identity for type product up to an equivalence. -/ @[simps] def prodPUnit (α) : α × PUnit ≃ α := ⟨fun p => p.1, fun a => (a, PUnit.unit), fun ⟨_, PUnit.unit⟩ => rfl, fun _ => rfl⟩ #align equiv.prod_punit Equiv.prodPUnit #align equiv.prod_punit_apply Equiv.prodPUnit_apply #align equiv.prod_punit_symm_apply Equiv.prodPUnit_symm_apply /-- `PUnit` is a left identity for type product up to an equivalence. -/ @[simps!] def punitProd (α) : PUnit × α ≃ α := calc PUnit × α ≃ α × PUnit := prodComm _ _ _ ≃ α := prodPUnit _ #align equiv.punit_prod Equiv.punitProd #align equiv.punit_prod_symm_apply Equiv.punitProd_symm_apply #align equiv.punit_prod_apply Equiv.punitProd_apply /-- `PUnit` is a right identity for dependent type product up to an equivalence. -/ @[simps] def sigmaPUnit (α) : (_ : α) × PUnit ≃ α := ⟨fun p => p.1, fun a => ⟨a, PUnit.unit⟩, fun ⟨_, PUnit.unit⟩ => rfl, fun _ => rfl⟩ /-- Any `Unique` type is a right identity for type product up to equivalence. -/ def prodUnique (α β) [Unique β] : α × β ≃ α := ((Equiv.refl α).prodCongr <| equivPUnit.{_,1} β).trans <| prodPUnit α #align equiv.prod_unique Equiv.prodUnique @[simp] theorem coe_prodUnique [Unique β] : (⇑(prodUnique α β) : α × β → α) = Prod.fst := rfl #align equiv.coe_prod_unique Equiv.coe_prodUnique theorem prodUnique_apply [Unique β] (x : α × β) : prodUnique α β x = x.1 := rfl #align equiv.prod_unique_apply Equiv.prodUnique_apply @[simp] theorem prodUnique_symm_apply [Unique β] (x : α) : (prodUnique α β).symm x = (x, default) := rfl #align equiv.prod_unique_symm_apply Equiv.prodUnique_symm_apply /-- Any `Unique` type is a left identity for type product up to equivalence. -/ def uniqueProd (α β) [Unique β] : β × α ≃ α := ((equivPUnit.{_,1} β).prodCongr <| Equiv.refl α).trans <| punitProd α #align equiv.unique_prod Equiv.uniqueProd @[simp] theorem coe_uniqueProd [Unique β] : (⇑(uniqueProd α β) : β × α → α) = Prod.snd := rfl #align equiv.coe_unique_prod Equiv.coe_uniqueProd theorem uniqueProd_apply [Unique β] (x : β × α) : uniqueProd α β x = x.2 := rfl #align equiv.unique_prod_apply Equiv.uniqueProd_apply @[simp] theorem uniqueProd_symm_apply [Unique β] (x : α) : (uniqueProd α β).symm x = (default, x) := rfl #align equiv.unique_prod_symm_apply Equiv.uniqueProd_symm_apply /-- Any family of `Unique` types is a right identity for dependent type product up to equivalence. -/ def sigmaUnique (α) (β : α → Type*) [∀ a, Unique (β a)] : (a : α) × (β a) ≃ α := (Equiv.sigmaCongrRight fun a ↦ equivPUnit.{_,1} (β a)).trans <| sigmaPUnit α @[simp] theorem coe_sigmaUnique {β : α → Type*} [∀ a, Unique (β a)] : (⇑(sigmaUnique α β) : (a : α) × (β a) → α) = Sigma.fst := rfl theorem sigmaUnique_apply {β : α → Type*} [∀ a, Unique (β a)] (x : (a : α) × β a) : sigmaUnique α β x = x.1 := rfl @[simp] theorem sigmaUnique_symm_apply {β : α → Type*} [∀ a, Unique (β a)] (x : α) : (sigmaUnique α β).symm x = ⟨x, default⟩ := rfl /-- `Empty` type is a right absorbing element for type product up to an equivalence. -/ def prodEmpty (α) : α × Empty ≃ Empty := equivEmpty _ #align equiv.prod_empty Equiv.prodEmpty /-- `Empty` type is a left absorbing element for type product up to an equivalence. -/ def emptyProd (α) : Empty × α ≃ Empty := equivEmpty _ #align equiv.empty_prod Equiv.emptyProd /-- `PEmpty` type is a right absorbing element for type product up to an equivalence. -/ def prodPEmpty (α) : α × PEmpty ≃ PEmpty := equivPEmpty _ #align equiv.prod_pempty Equiv.prodPEmpty /-- `PEmpty` type is a left absorbing element for type product up to an equivalence. -/ def pemptyProd (α) : PEmpty × α ≃ PEmpty := equivPEmpty _ #align equiv.pempty_prod Equiv.pemptyProd end section open Sum /-- `PSum` is equivalent to `Sum`. -/ def psumEquivSum (α β) : PSum α β ≃ Sum α β where toFun s := PSum.casesOn s inl inr invFun := Sum.elim PSum.inl PSum.inr left_inv s := by cases s <;> rfl right_inv s := by cases s <;> rfl #align equiv.psum_equiv_sum Equiv.psumEquivSum /-- If `α ≃ α'` and `β ≃ β'`, then `α ⊕ β ≃ α' ⊕ β'`. This is `Sum.map` as an equivalence. -/ @[simps apply] def sumCongr (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : Sum α₁ β₁ ≃ Sum α₂ β₂ := ⟨Sum.map ea eb, Sum.map ea.symm eb.symm, fun x => by simp, fun x => by simp⟩ #align equiv.sum_congr Equiv.sumCongr #align equiv.sum_congr_apply Equiv.sumCongr_apply /-- If `α ≃ α'` and `β ≃ β'`, then `PSum α β ≃ PSum α' β'`. -/ def psumCongr (e₁ : α ≃ β) (e₂ : γ ≃ δ) : PSum α γ ≃ PSum β δ where toFun x := PSum.casesOn x (PSum.inl ∘ e₁) (PSum.inr ∘ e₂) invFun x := PSum.casesOn x (PSum.inl ∘ e₁.symm) (PSum.inr ∘ e₂.symm) left_inv := by rintro (x | x) <;> simp right_inv := by rintro (x | x) <;> simp #align equiv.psum_congr Equiv.psumCongr /-- Combine two `Equiv`s using `PSum` in the domain and `Sum` in the codomain. -/ def psumSum (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : PSum α₁ β₁ ≃ Sum α₂ β₂ := (ea.psumCongr eb).trans (psumEquivSum _ _) #align equiv.psum_sum Equiv.psumSum /-- Combine two `Equiv`s using `Sum` in the domain and `PSum` in the codomain. -/ def sumPSum (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : Sum α₁ β₁ ≃ PSum α₂ β₂ := (ea.symm.psumSum eb.symm).symm #align equiv.sum_psum Equiv.sumPSum @[simp] theorem sumCongr_trans (e : α₁ ≃ β₁) (f : α₂ ≃ β₂) (g : β₁ ≃ γ₁) (h : β₂ ≃ γ₂) : (Equiv.sumCongr e f).trans (Equiv.sumCongr g h) = Equiv.sumCongr (e.trans g) (f.trans h) := by ext i cases i <;> rfl #align equiv.sum_congr_trans Equiv.sumCongr_trans @[simp] theorem sumCongr_symm (e : α ≃ β) (f : γ ≃ δ) : (Equiv.sumCongr e f).symm = Equiv.sumCongr e.symm f.symm := rfl #align equiv.sum_congr_symm Equiv.sumCongr_symm @[simp] theorem sumCongr_refl : Equiv.sumCongr (Equiv.refl α) (Equiv.refl β) = Equiv.refl (Sum α β) := by ext i cases i <;> rfl #align equiv.sum_congr_refl Equiv.sumCongr_refl /-- A subtype of a sum is equivalent to a sum of subtypes. -/ def subtypeSum {p : α ⊕ β → Prop} : {c // p c} ≃ {a // p (Sum.inl a)} ⊕ {b // p (Sum.inr b)} where toFun c := match h : c.1 with | Sum.inl a => Sum.inl ⟨a, h ▸ c.2⟩ | Sum.inr b => Sum.inr ⟨b, h ▸ c.2⟩ invFun c := match c with | Sum.inl a => ⟨Sum.inl a, a.2⟩ | Sum.inr b => ⟨Sum.inr b, b.2⟩ left_inv := by rintro ⟨a | b, h⟩ <;> rfl right_inv := by rintro (a | b) <;> rfl namespace Perm /-- Combine a permutation of `α` and of `β` into a permutation of `α ⊕ β`. -/ abbrev sumCongr (ea : Equiv.Perm α) (eb : Equiv.Perm β) : Equiv.Perm (Sum α β) := Equiv.sumCongr ea eb #align equiv.perm.sum_congr Equiv.Perm.sumCongr @[simp] theorem sumCongr_apply (ea : Equiv.Perm α) (eb : Equiv.Perm β) (x : Sum α β) : sumCongr ea eb x = Sum.map (⇑ea) (⇑eb) x := Equiv.sumCongr_apply ea eb x #align equiv.perm.sum_congr_apply Equiv.Perm.sumCongr_apply -- Porting note: it seems the general theorem about `Equiv` is now applied, so there's no need -- to have this version also have `@[simp]`. Similarly for below. theorem sumCongr_trans (e : Equiv.Perm α) (f : Equiv.Perm β) (g : Equiv.Perm α) (h : Equiv.Perm β) : (sumCongr e f).trans (sumCongr g h) = sumCongr (e.trans g) (f.trans h) := Equiv.sumCongr_trans e f g h #align equiv.perm.sum_congr_trans Equiv.Perm.sumCongr_trans theorem sumCongr_symm (e : Equiv.Perm α) (f : Equiv.Perm β) : (sumCongr e f).symm = sumCongr e.symm f.symm := Equiv.sumCongr_symm e f #align equiv.perm.sum_congr_symm Equiv.Perm.sumCongr_symm theorem sumCongr_refl : sumCongr (Equiv.refl α) (Equiv.refl β) = Equiv.refl (Sum α β) := Equiv.sumCongr_refl #align equiv.perm.sum_congr_refl Equiv.Perm.sumCongr_refl end Perm /-- `Bool` is equivalent the sum of two `PUnit`s. -/ def boolEquivPUnitSumPUnit : Bool ≃ Sum PUnit.{u + 1} PUnit.{v + 1} := ⟨fun b => b.casesOn (inl PUnit.unit) (inr PUnit.unit) , Sum.elim (fun _ => false) fun _ => true, fun b => by cases b <;> rfl, fun s => by rcases s with (⟨⟨⟩⟩ | ⟨⟨⟩⟩) <;> rfl⟩ #align equiv.bool_equiv_punit_sum_punit Equiv.boolEquivPUnitSumPUnit /-- Sum of types is commutative up to an equivalence. This is `Sum.swap` as an equivalence. -/ @[simps (config := .asFn) apply] def sumComm (α β) : Sum α β ≃ Sum β α := ⟨Sum.swap, Sum.swap, Sum.swap_swap, Sum.swap_swap⟩ #align equiv.sum_comm Equiv.sumComm #align equiv.sum_comm_apply Equiv.sumComm_apply @[simp] theorem sumComm_symm (α β) : (sumComm α β).symm = sumComm β α := rfl #align equiv.sum_comm_symm Equiv.sumComm_symm /-- Sum of types is associative up to an equivalence. -/ def sumAssoc (α β γ) : Sum (Sum α β) γ ≃ Sum α (Sum β γ) := ⟨Sum.elim (Sum.elim Sum.inl (Sum.inr ∘ Sum.inl)) (Sum.inr ∘ Sum.inr), Sum.elim (Sum.inl ∘ Sum.inl) <| Sum.elim (Sum.inl ∘ Sum.inr) Sum.inr, by rintro (⟨_ | _⟩ | _) <;> rfl, by rintro (_ | ⟨_ | _⟩) <;> rfl⟩ #align equiv.sum_assoc Equiv.sumAssoc @[simp] theorem sumAssoc_apply_inl_inl (a) : sumAssoc α β γ (inl (inl a)) = inl a := rfl #align equiv.sum_assoc_apply_inl_inl Equiv.sumAssoc_apply_inl_inl @[simp] theorem sumAssoc_apply_inl_inr (b) : sumAssoc α β γ (inl (inr b)) = inr (inl b) := rfl #align equiv.sum_assoc_apply_inl_inr Equiv.sumAssoc_apply_inl_inr @[simp] theorem sumAssoc_apply_inr (c) : sumAssoc α β γ (inr c) = inr (inr c) := rfl #align equiv.sum_assoc_apply_inr Equiv.sumAssoc_apply_inr @[simp] theorem sumAssoc_symm_apply_inl {α β γ} (a) : (sumAssoc α β γ).symm (inl a) = inl (inl a) := rfl #align equiv.sum_assoc_symm_apply_inl Equiv.sumAssoc_symm_apply_inl @[simp] theorem sumAssoc_symm_apply_inr_inl {α β γ} (b) : (sumAssoc α β γ).symm (inr (inl b)) = inl (inr b) := rfl #align equiv.sum_assoc_symm_apply_inr_inl Equiv.sumAssoc_symm_apply_inr_inl @[simp] theorem sumAssoc_symm_apply_inr_inr {α β γ} (c) : (sumAssoc α β γ).symm (inr (inr c)) = inr c := rfl #align equiv.sum_assoc_symm_apply_inr_inr Equiv.sumAssoc_symm_apply_inr_inr /-- Sum with `IsEmpty` is equivalent to the original type. -/ @[simps symm_apply] def sumEmpty (α β) [IsEmpty β] : Sum α β ≃ α where toFun := Sum.elim id isEmptyElim invFun := inl left_inv s := by rcases s with (_ | x) · rfl · exact isEmptyElim x right_inv _ := rfl #align equiv.sum_empty Equiv.sumEmpty #align equiv.sum_empty_symm_apply Equiv.sumEmpty_symm_apply @[simp] theorem sumEmpty_apply_inl [IsEmpty β] (a : α) : sumEmpty α β (Sum.inl a) = a := rfl #align equiv.sum_empty_apply_inl Equiv.sumEmpty_apply_inl /-- The sum of `IsEmpty` with any type is equivalent to that type. -/ @[simps! symm_apply] def emptySum (α β) [IsEmpty α] : Sum α β ≃ β := (sumComm _ _).trans <| sumEmpty _ _ #align equiv.empty_sum Equiv.emptySum #align equiv.empty_sum_symm_apply Equiv.emptySum_symm_apply @[simp] theorem emptySum_apply_inr [IsEmpty α] (b : β) : emptySum α β (Sum.inr b) = b := rfl #align equiv.empty_sum_apply_inr Equiv.emptySum_apply_inr /-- `Option α` is equivalent to `α ⊕ PUnit` -/ def optionEquivSumPUnit (α) : Option α ≃ Sum α PUnit := ⟨fun o => o.elim (inr PUnit.unit) inl, fun s => s.elim some fun _ => none, fun o => by cases o <;> rfl, fun s => by rcases s with (_ | ⟨⟨⟩⟩) <;> rfl⟩ #align equiv.option_equiv_sum_punit Equiv.optionEquivSumPUnit @[simp] theorem optionEquivSumPUnit_none : optionEquivSumPUnit α none = Sum.inr PUnit.unit := rfl #align equiv.option_equiv_sum_punit_none Equiv.optionEquivSumPUnit_none @[simp] theorem optionEquivSumPUnit_some (a) : optionEquivSumPUnit α (some a) = Sum.inl a := rfl #align equiv.option_equiv_sum_punit_some Equiv.optionEquivSumPUnit_some @[simp] theorem optionEquivSumPUnit_coe (a : α) : optionEquivSumPUnit α a = Sum.inl a := rfl #align equiv.option_equiv_sum_punit_coe Equiv.optionEquivSumPUnit_coe @[simp] theorem optionEquivSumPUnit_symm_inl (a) : (optionEquivSumPUnit α).symm (Sum.inl a) = a := rfl #align equiv.option_equiv_sum_punit_symm_inl Equiv.optionEquivSumPUnit_symm_inl @[simp] theorem optionEquivSumPUnit_symm_inr (a) : (optionEquivSumPUnit α).symm (Sum.inr a) = none := rfl #align equiv.option_equiv_sum_punit_symm_inr Equiv.optionEquivSumPUnit_symm_inr /-- The set of `x : Option α` such that `isSome x` is equivalent to `α`. -/ @[simps] def optionIsSomeEquiv (α) : { x : Option α // x.isSome } ≃ α where toFun o := Option.get _ o.2 invFun x := ⟨some x, rfl⟩ left_inv _ := Subtype.eq <| Option.some_get _ right_inv _ := Option.get_some _ _ #align equiv.option_is_some_equiv Equiv.optionIsSomeEquiv #align equiv.option_is_some_equiv_apply Equiv.optionIsSomeEquiv_apply #align equiv.option_is_some_equiv_symm_apply_coe Equiv.optionIsSomeEquiv_symm_apply_coe /-- The product over `Option α` of `β a` is the binary product of the product over `α` of `β (some α)` and `β none` -/ @[simps] def piOptionEquivProd {β : Option α → Type*} : (∀ a : Option α, β a) ≃ β none × ∀ a : α, β (some a) where toFun f := (f none, fun a => f (some a)) invFun x a := Option.casesOn a x.fst x.snd left_inv f := funext fun a => by cases a <;> rfl right_inv x := by simp #align equiv.pi_option_equiv_prod Equiv.piOptionEquivProd #align equiv.pi_option_equiv_prod_symm_apply Equiv.piOptionEquivProd_symm_apply #align equiv.pi_option_equiv_prod_apply Equiv.piOptionEquivProd_apply /-- `α ⊕ β` is equivalent to a `Sigma`-type over `Bool`. Note that this definition assumes `α` and `β` to be types from the same universe, so it cannot be used directly to transfer theorems about sigma types to theorems about sum types. In many cases one can use `ULift` to work around this difficulty. -/ def sumEquivSigmaBool (α β : Type u) : Sum α β ≃ Σ b : Bool, b.casesOn α β := ⟨fun s => s.elim (fun x => ⟨false, x⟩) fun x => ⟨true, x⟩, fun s => match s with | ⟨false, a⟩ => inl a | ⟨true, b⟩ => inr b, fun s => by cases s <;> rfl, fun s => by rcases s with ⟨_ | _, _⟩ <;> rfl⟩ #align equiv.sum_equiv_sigma_bool Equiv.sumEquivSigmaBool -- See also `Equiv.sigmaPreimageEquiv`. /-- `sigmaFiberEquiv f` for `f : α → β` is the natural equivalence between the type of all fibres of `f` and the total space `α`. -/ @[simps] def sigmaFiberEquiv {α β : Type*} (f : α → β) : (Σ y : β, { x // f x = y }) ≃ α := ⟨fun x => ↑x.2, fun x => ⟨f x, x, rfl⟩, fun ⟨_, _, rfl⟩ => rfl, fun _ => rfl⟩ #align equiv.sigma_fiber_equiv Equiv.sigmaFiberEquiv #align equiv.sigma_fiber_equiv_apply Equiv.sigmaFiberEquiv_apply #align equiv.sigma_fiber_equiv_symm_apply_fst Equiv.sigmaFiberEquiv_symm_apply_fst #align equiv.sigma_fiber_equiv_symm_apply_snd_coe Equiv.sigmaFiberEquiv_symm_apply_snd_coe /-- Inhabited types are equivalent to `Option β` for some `β` by identifying `default` with `none`. -/ def sigmaEquivOptionOfInhabited (α : Type u) [Inhabited α] [DecidableEq α] : Σ β : Type u, α ≃ Option β where fst := {a // a ≠ default} snd.toFun a := if h : a = default then none else some ⟨a, h⟩ snd.invFun := Option.elim' default (↑) snd.left_inv a := by dsimp only; split_ifs <;> simp [*] snd.right_inv | none => by simp | some ⟨a, ha⟩ => dif_neg ha #align equiv.sigma_equiv_option_of_inhabited Equiv.sigmaEquivOptionOfInhabited end section sumCompl /-- For any predicate `p` on `α`, the sum of the two subtypes `{a // p a}` and its complement `{a // ¬ p a}` is naturally equivalent to `α`. See `subtypeOrEquiv` for sum types over subtypes `{x // p x}` and `{x // q x}` that are not necessarily `IsCompl p q`. -/ def sumCompl {α : Type*} (p : α → Prop) [DecidablePred p] : Sum { a // p a } { a // ¬p a } ≃ α where toFun := Sum.elim Subtype.val Subtype.val invFun a := if h : p a then Sum.inl ⟨a, h⟩ else Sum.inr ⟨a, h⟩ left_inv := by rintro (⟨x, hx⟩ | ⟨x, hx⟩) <;> dsimp · rw [dif_pos] · rw [dif_neg] right_inv a := by dsimp split_ifs <;> rfl #align equiv.sum_compl Equiv.sumCompl @[simp] theorem sumCompl_apply_inl (p : α → Prop) [DecidablePred p] (x : { a // p a }) : sumCompl p (Sum.inl x) = x := rfl #align equiv.sum_compl_apply_inl Equiv.sumCompl_apply_inl @[simp] theorem sumCompl_apply_inr (p : α → Prop) [DecidablePred p] (x : { a // ¬p a }) : sumCompl p (Sum.inr x) = x := rfl #align equiv.sum_compl_apply_inr Equiv.sumCompl_apply_inr @[simp] theorem sumCompl_apply_symm_of_pos (p : α → Prop) [DecidablePred p] (a : α) (h : p a) : (sumCompl p).symm a = Sum.inl ⟨a, h⟩ := dif_pos h #align equiv.sum_compl_apply_symm_of_pos Equiv.sumCompl_apply_symm_of_pos @[simp] theorem sumCompl_apply_symm_of_neg (p : α → Prop) [DecidablePred p] (a : α) (h : ¬p a) : (sumCompl p).symm a = Sum.inr ⟨a, h⟩ := dif_neg h #align equiv.sum_compl_apply_symm_of_neg Equiv.sumCompl_apply_symm_of_neg /-- Combines an `Equiv` between two subtypes with an `Equiv` between their complements to form a permutation. -/ def subtypeCongr {p q : α → Prop} [DecidablePred p] [DecidablePred q] (e : { x // p x } ≃ { x // q x }) (f : { x // ¬p x } ≃ { x // ¬q x }) : Perm α := (sumCompl p).symm.trans ((sumCongr e f).trans (sumCompl q)) #align equiv.subtype_congr Equiv.subtypeCongr variable {p : ε → Prop} [DecidablePred p] variable (ep ep' : Perm { a // p a }) (en en' : Perm { a // ¬p a }) /-- Combining permutations on `ε` that permute only inside or outside the subtype split induced by `p : ε → Prop` constructs a permutation on `ε`. -/ def Perm.subtypeCongr : Equiv.Perm ε := permCongr (sumCompl p) (sumCongr ep en) #align equiv.perm.subtype_congr Equiv.Perm.subtypeCongr theorem Perm.subtypeCongr.apply (a : ε) : ep.subtypeCongr en a = if h : p a then (ep ⟨a, h⟩ : ε) else en ⟨a, h⟩ := by by_cases h : p a <;> simp [Perm.subtypeCongr, h] #align equiv.perm.subtype_congr.apply Equiv.Perm.subtypeCongr.apply @[simp] theorem Perm.subtypeCongr.left_apply {a : ε} (h : p a) : ep.subtypeCongr en a = ep ⟨a, h⟩ := by simp [Perm.subtypeCongr.apply, h] #align equiv.perm.subtype_congr.left_apply Equiv.Perm.subtypeCongr.left_apply @[simp] theorem Perm.subtypeCongr.left_apply_subtype (a : { a // p a }) : ep.subtypeCongr en a = ep a := Perm.subtypeCongr.left_apply ep en a.property #align equiv.perm.subtype_congr.left_apply_subtype Equiv.Perm.subtypeCongr.left_apply_subtype @[simp] theorem Perm.subtypeCongr.right_apply {a : ε} (h : ¬p a) : ep.subtypeCongr en a = en ⟨a, h⟩ := by simp [Perm.subtypeCongr.apply, h] #align equiv.perm.subtype_congr.right_apply Equiv.Perm.subtypeCongr.right_apply @[simp] theorem Perm.subtypeCongr.right_apply_subtype (a : { a // ¬p a }) : ep.subtypeCongr en a = en a := Perm.subtypeCongr.right_apply ep en a.property #align equiv.perm.subtype_congr.right_apply_subtype Equiv.Perm.subtypeCongr.right_apply_subtype @[simp] theorem Perm.subtypeCongr.refl : Perm.subtypeCongr (Equiv.refl { a // p a }) (Equiv.refl { a // ¬p a }) = Equiv.refl ε := by ext x by_cases h:p x <;> simp [h] #align equiv.perm.subtype_congr.refl Equiv.Perm.subtypeCongr.refl @[simp] theorem Perm.subtypeCongr.symm : (ep.subtypeCongr en).symm = Perm.subtypeCongr ep.symm en.symm := by ext x by_cases h:p x · have : p (ep.symm ⟨x, h⟩) := Subtype.property _ simp [Perm.subtypeCongr.apply, h, symm_apply_eq, this] · have : ¬p (en.symm ⟨x, h⟩) := Subtype.property (en.symm _) simp [Perm.subtypeCongr.apply, h, symm_apply_eq, this] #align equiv.perm.subtype_congr.symm Equiv.Perm.subtypeCongr.symm @[simp] theorem Perm.subtypeCongr.trans : (ep.subtypeCongr en).trans (ep'.subtypeCongr en') = Perm.subtypeCongr (ep.trans ep') (en.trans en') := by ext x by_cases h:p x · have : p (ep ⟨x, h⟩) := Subtype.property _ simp [Perm.subtypeCongr.apply, h, this] · have : ¬p (en ⟨x, h⟩) := Subtype.property (en _) simp [Perm.subtypeCongr.apply, h, symm_apply_eq, this] #align equiv.perm.subtype_congr.trans Equiv.Perm.subtypeCongr.trans end sumCompl section subtypePreimage variable (p : α → Prop) [DecidablePred p] (x₀ : { a // p a } → β) /-- For a fixed function `x₀ : {a // p a} → β` defined on a subtype of `α`, the subtype of functions `x : α → β` that agree with `x₀` on the subtype `{a // p a}` is naturally equivalent to the type of functions `{a // ¬ p a} → β`. -/ @[simps] def subtypePreimage : { x : α → β // x ∘ Subtype.val = x₀ } ≃ ({ a // ¬p a } → β) where toFun (x : { x : α → β // x ∘ Subtype.val = x₀ }) a := (x : α → β) a invFun x := ⟨fun a => if h : p a then x₀ ⟨a, h⟩ else x ⟨a, h⟩, funext fun ⟨a, h⟩ => dif_pos h⟩ left_inv := fun ⟨x, hx⟩ => Subtype.val_injective <| funext fun a => by dsimp only split_ifs · rw [← hx]; rfl · rfl right_inv x := funext fun ⟨a, h⟩ => show dite (p a) _ _ = _ by dsimp only rw [dif_neg h] #align equiv.subtype_preimage Equiv.subtypePreimage #align equiv.subtype_preimage_symm_apply_coe Equiv.subtypePreimage_symm_apply_coe #align equiv.subtype_preimage_apply Equiv.subtypePreimage_apply theorem subtypePreimage_symm_apply_coe_pos (x : { a // ¬p a } → β) (a : α) (h : p a) : ((subtypePreimage p x₀).symm x : α → β) a = x₀ ⟨a, h⟩ := dif_pos h #align equiv.subtype_preimage_symm_apply_coe_pos Equiv.subtypePreimage_symm_apply_coe_pos theorem subtypePreimage_symm_apply_coe_neg (x : { a // ¬p a } → β) (a : α) (h : ¬p a) : ((subtypePreimage p x₀).symm x : α → β) a = x ⟨a, h⟩ := dif_neg h #align equiv.subtype_preimage_symm_apply_coe_neg Equiv.subtypePreimage_symm_apply_coe_neg end subtypePreimage section /-- A family of equivalences `∀ a, β₁ a ≃ β₂ a` generates an equivalence between `∀ a, β₁ a` and `∀ a, β₂ a`. -/ def piCongrRight {β₁ β₂ : α → Sort*} (F : ∀ a, β₁ a ≃ β₂ a) : (∀ a, β₁ a) ≃ (∀ a, β₂ a) := ⟨fun H a => F a (H a), fun H a => (F a).symm (H a), fun H => funext <| by simp, fun H => funext <| by simp⟩ #align equiv.Pi_congr_right Equiv.piCongrRight /-- Given `φ : α → β → Sort*`, we have an equivalence between `∀ a b, φ a b` and `∀ b a, φ a b`. This is `Function.swap` as an `Equiv`. -/ @[simps apply] def piComm (φ : α → β → Sort*) : (∀ a b, φ a b) ≃ ∀ b a, φ a b := ⟨swap, swap, fun _ => rfl, fun _ => rfl⟩ #align equiv.Pi_comm Equiv.piComm #align equiv.Pi_comm_apply Equiv.piComm_apply @[simp] theorem piComm_symm {φ : α → β → Sort*} : (piComm φ).symm = (piComm <| swap φ) := rfl #align equiv.Pi_comm_symm Equiv.piComm_symm /-- Dependent `curry` equivalence: the type of dependent functions on `Σ i, β i` is equivalent to the type of dependent functions of two arguments (i.e., functions to the space of functions). This is `Sigma.curry` and `Sigma.uncurry` together as an equiv. -/ def piCurry {β : α → Type*} (γ : ∀ a, β a → Type*) : (∀ x : Σ i, β i, γ x.1 x.2) ≃ ∀ a b, γ a b where toFun := Sigma.curry invFun := Sigma.uncurry left_inv := Sigma.uncurry_curry right_inv := Sigma.curry_uncurry #align equiv.Pi_curry Equiv.piCurry -- `simps` overapplies these but `simps (config := .asFn)` under-applies them @[simp] theorem piCurry_apply {β : α → Type*} (γ : ∀ a, β a → Type*) (f : ∀ x : Σ i, β i, γ x.1 x.2) : piCurry γ f = Sigma.curry f := rfl @[simp] theorem piCurry_symm_apply {β : α → Type*} (γ : ∀ a, β a → Type*) (f : ∀ a b, γ a b) : (piCurry γ).symm f = Sigma.uncurry f := rfl end section prodCongr variable (e : α₁ → β₁ ≃ β₂) /-- A family of equivalences `∀ (a : α₁), β₁ ≃ β₂` generates an equivalence between `β₁ × α₁` and `β₂ × α₁`. -/ def prodCongrLeft : β₁ × α₁ ≃ β₂ × α₁ where toFun ab := ⟨e ab.2 ab.1, ab.2⟩ invFun ab := ⟨(e ab.2).symm ab.1, ab.2⟩ left_inv := by rintro ⟨a, b⟩ simp right_inv := by rintro ⟨a, b⟩ simp #align equiv.prod_congr_left Equiv.prodCongrLeft @[simp] theorem prodCongrLeft_apply (b : β₁) (a : α₁) : prodCongrLeft e (b, a) = (e a b, a) := rfl #align equiv.prod_congr_left_apply Equiv.prodCongrLeft_apply theorem prodCongr_refl_right (e : β₁ ≃ β₂) : prodCongr e (Equiv.refl α₁) = prodCongrLeft fun _ => e := by ext ⟨a, b⟩ : 1 simp #align equiv.prod_congr_refl_right Equiv.prodCongr_refl_right /-- A family of equivalences `∀ (a : α₁), β₁ ≃ β₂` generates an equivalence between `α₁ × β₁` and `α₁ × β₂`. -/ def prodCongrRight : α₁ × β₁ ≃ α₁ × β₂ where toFun ab := ⟨ab.1, e ab.1 ab.2⟩ invFun ab := ⟨ab.1, (e ab.1).symm ab.2⟩ left_inv := by rintro ⟨a, b⟩ simp right_inv := by rintro ⟨a, b⟩ simp #align equiv.prod_congr_right Equiv.prodCongrRight @[simp] theorem prodCongrRight_apply (a : α₁) (b : β₁) : prodCongrRight e (a, b) = (a, e a b) := rfl #align equiv.prod_congr_right_apply Equiv.prodCongrRight_apply theorem prodCongr_refl_left (e : β₁ ≃ β₂) : prodCongr (Equiv.refl α₁) e = prodCongrRight fun _ => e := by ext ⟨a, b⟩ : 1 simp #align equiv.prod_congr_refl_left Equiv.prodCongr_refl_left @[simp] theorem prodCongrLeft_trans_prodComm : (prodCongrLeft e).trans (prodComm _ _) = (prodComm _ _).trans (prodCongrRight e) := by ext ⟨a, b⟩ : 1 simp #align equiv.prod_congr_left_trans_prod_comm Equiv.prodCongrLeft_trans_prodComm @[simp] theorem prodCongrRight_trans_prodComm : (prodCongrRight e).trans (prodComm _ _) = (prodComm _ _).trans (prodCongrLeft e) := by ext ⟨a, b⟩ : 1 simp #align equiv.prod_congr_right_trans_prod_comm Equiv.prodCongrRight_trans_prodComm theorem sigmaCongrRight_sigmaEquivProd : (sigmaCongrRight e).trans (sigmaEquivProd α₁ β₂) = (sigmaEquivProd α₁ β₁).trans (prodCongrRight e) := by ext ⟨a, b⟩ : 1 simp #align equiv.sigma_congr_right_sigma_equiv_prod Equiv.sigmaCongrRight_sigmaEquivProd theorem sigmaEquivProd_sigmaCongrRight : (sigmaEquivProd α₁ β₁).symm.trans (sigmaCongrRight e) = (prodCongrRight e).trans (sigmaEquivProd α₁ β₂).symm := by ext ⟨a, b⟩ : 1 simp only [trans_apply, sigmaCongrRight_apply, prodCongrRight_apply] rfl #align equiv.sigma_equiv_prod_sigma_congr_right Equiv.sigmaEquivProd_sigmaCongrRight -- See also `Equiv.ofPreimageEquiv`. /-- A family of equivalences between fibers gives an equivalence between domains. -/ @[simps!] def ofFiberEquiv {f : α → γ} {g : β → γ} (e : ∀ c, { a // f a = c } ≃ { b // g b = c }) : α ≃ β := (sigmaFiberEquiv f).symm.trans <| (Equiv.sigmaCongrRight e).trans (sigmaFiberEquiv g) #align equiv.of_fiber_equiv Equiv.ofFiberEquiv #align equiv.of_fiber_equiv_apply Equiv.ofFiberEquiv_apply #align equiv.of_fiber_equiv_symm_apply Equiv.ofFiberEquiv_symm_apply theorem ofFiberEquiv_map {α β γ} {f : α → γ} {g : β → γ} (e : ∀ c, { a // f a = c } ≃ { b // g b = c }) (a : α) : g (ofFiberEquiv e a) = f a := (_ : { b // g b = _ }).property #align equiv.of_fiber_equiv_map Equiv.ofFiberEquiv_map /-- A variation on `Equiv.prodCongr` where the equivalence in the second component can depend on the first component. A typical example is a shear mapping, explaining the name of this declaration. -/ @[simps (config := .asFn)] def prodShear (e₁ : α₁ ≃ α₂) (e₂ : α₁ → β₁ ≃ β₂) : α₁ × β₁ ≃ α₂ × β₂ where toFun := fun x : α₁ × β₁ => (e₁ x.1, e₂ x.1 x.2) invFun := fun y : α₂ × β₂ => (e₁.symm y.1, (e₂ <| e₁.symm y.1).symm y.2) left_inv := by rintro ⟨x₁, y₁⟩ simp only [symm_apply_apply] right_inv := by rintro ⟨x₁, y₁⟩ simp only [apply_symm_apply] #align equiv.prod_shear Equiv.prodShear #align equiv.prod_shear_apply Equiv.prodShear_apply #align equiv.prod_shear_symm_apply Equiv.prodShear_symm_apply end prodCongr namespace Perm variable [DecidableEq α₁] (a : α₁) (e : Perm β₁) /-- `prodExtendRight a e` extends `e : Perm β` to `Perm (α × β)` by sending `(a, b)` to `(a, e b)` and keeping the other `(a', b)` fixed. -/ def prodExtendRight : Perm (α₁ × β₁) where toFun ab := if ab.fst = a then (a, e ab.snd) else ab invFun ab := if ab.fst = a then (a, e.symm ab.snd) else ab left_inv := by rintro ⟨k', x⟩ dsimp only split_ifs with h₁ h₂ · simp [h₁] · simp at h₂ · simp right_inv := by rintro ⟨k', x⟩ dsimp only split_ifs with h₁ h₂ · simp [h₁] · simp at h₂ · simp #align equiv.perm.prod_extend_right Equiv.Perm.prodExtendRight @[simp] theorem prodExtendRight_apply_eq (b : β₁) : prodExtendRight a e (a, b) = (a, e b) := if_pos rfl #align equiv.perm.prod_extend_right_apply_eq Equiv.Perm.prodExtendRight_apply_eq theorem prodExtendRight_apply_ne {a a' : α₁} (h : a' ≠ a) (b : β₁) : prodExtendRight a e (a', b) = (a', b) := if_neg h #align equiv.perm.prod_extend_right_apply_ne Equiv.Perm.prodExtendRight_apply_ne theorem eq_of_prodExtendRight_ne {e : Perm β₁} {a a' : α₁} {b : β₁} (h : prodExtendRight a e (a', b) ≠ (a', b)) : a' = a := by contrapose! h exact prodExtendRight_apply_ne _ h _ #align equiv.perm.eq_of_prod_extend_right_ne Equiv.Perm.eq_of_prodExtendRight_ne @[simp] theorem fst_prodExtendRight (ab : α₁ × β₁) : (prodExtendRight a e ab).fst = ab.fst := by rw [prodExtendRight] dsimp split_ifs with h · rw [h] · rfl #align equiv.perm.fst_prod_extend_right Equiv.Perm.fst_prodExtendRight end Perm section /-- The type of functions to a product `α × β` is equivalent to the type of pairs of functions `γ → α` and `γ → β`. -/ def arrowProdEquivProdArrow (α β γ : Type*) : (γ → α × β) ≃ (γ → α) × (γ → β) where toFun := fun f => (fun c => (f c).1, fun c => (f c).2) invFun := fun p c => (p.1 c, p.2 c) left_inv := fun f => rfl right_inv := fun p => by cases p; rfl #align equiv.arrow_prod_equiv_prod_arrow Equiv.arrowProdEquivProdArrow open Sum /-- The type of dependent functions on a sum type `ι ⊕ ι'` is equivalent to the type of pairs of functions on `ι` and on `ι'`. This is a dependent version of `Equiv.sumArrowEquivProdArrow`. -/ @[simps] def sumPiEquivProdPi (π : ι ⊕ ι' → Type*) : (∀ i, π i) ≃ (∀ i, π (inl i)) × ∀ i', π (inr i') where toFun f := ⟨fun i => f (inl i), fun i' => f (inr i')⟩ invFun g := Sum.rec g.1 g.2 left_inv f := by ext (i | i) <;> rfl right_inv g := Prod.ext rfl rfl /-- The equivalence between a product of two dependent functions types and a single dependent function type. Basically a symmetric version of `Equiv.sumPiEquivProdPi`. -/ @[simps!] def prodPiEquivSumPi (π : ι → Type u) (π' : ι' → Type u) : ((∀ i, π i) × ∀ i', π' i') ≃ ∀ i, Sum.elim π π' i := sumPiEquivProdPi (Sum.elim π π') |>.symm /-- The type of functions on a sum type `α ⊕ β` is equivalent to the type of pairs of functions on `α` and on `β`. -/ def sumArrowEquivProdArrow (α β γ : Type*) : (Sum α β → γ) ≃ (α → γ) × (β → γ) := ⟨fun f => (f ∘ inl, f ∘ inr), fun p => Sum.elim p.1 p.2, fun f => by ext ⟨⟩ <;> rfl, fun p => by cases p rfl⟩ #align equiv.sum_arrow_equiv_prod_arrow Equiv.sumArrowEquivProdArrow @[simp] theorem sumArrowEquivProdArrow_apply_fst (f : Sum α β → γ) (a : α) : (sumArrowEquivProdArrow α β γ f).1 a = f (inl a) := rfl #align equiv.sum_arrow_equiv_prod_arrow_apply_fst Equiv.sumArrowEquivProdArrow_apply_fst @[simp] theorem sumArrowEquivProdArrow_apply_snd (f : Sum α β → γ) (b : β) : (sumArrowEquivProdArrow α β γ f).2 b = f (inr b) := rfl #align equiv.sum_arrow_equiv_prod_arrow_apply_snd Equiv.sumArrowEquivProdArrow_apply_snd @[simp] theorem sumArrowEquivProdArrow_symm_apply_inl (f : α → γ) (g : β → γ) (a : α) : ((sumArrowEquivProdArrow α β γ).symm (f, g)) (inl a) = f a := rfl #align equiv.sum_arrow_equiv_prod_arrow_symm_apply_inl Equiv.sumArrowEquivProdArrow_symm_apply_inl @[simp] theorem sumArrowEquivProdArrow_symm_apply_inr (f : α → γ) (g : β → γ) (b : β) : ((sumArrowEquivProdArrow α β γ).symm (f, g)) (inr b) = g b := rfl #align equiv.sum_arrow_equiv_prod_arrow_symm_apply_inr Equiv.sumArrowEquivProdArrow_symm_apply_inr /-- Type product is right distributive with respect to type sum up to an equivalence. -/ def sumProdDistrib (α β γ) : Sum α β × γ ≃ Sum (α × γ) (β × γ) := ⟨fun p => p.1.map (fun x => (x, p.2)) fun x => (x, p.2), fun s => s.elim (Prod.map inl id) (Prod.map inr id), by rintro ⟨_ | _, _⟩ <;> rfl, by rintro (⟨_, _⟩ | ⟨_, _⟩) <;> rfl⟩ #align equiv.sum_prod_distrib Equiv.sumProdDistrib @[simp] theorem sumProdDistrib_apply_left (a : α) (c : γ) : sumProdDistrib α β γ (Sum.inl a, c) = Sum.inl (a, c) := rfl #align equiv.sum_prod_distrib_apply_left Equiv.sumProdDistrib_apply_left @[simp] theorem sumProdDistrib_apply_right (b : β) (c : γ) : sumProdDistrib α β γ (Sum.inr b, c) = Sum.inr (b, c) := rfl #align equiv.sum_prod_distrib_apply_right Equiv.sumProdDistrib_apply_right @[simp] theorem sumProdDistrib_symm_apply_left (a : α × γ) : (sumProdDistrib α β γ).symm (inl a) = (inl a.1, a.2) := rfl #align equiv.sum_prod_distrib_symm_apply_left Equiv.sumProdDistrib_symm_apply_left @[simp] theorem sumProdDistrib_symm_apply_right (b : β × γ) : (sumProdDistrib α β γ).symm (inr b) = (inr b.1, b.2) := rfl #align equiv.sum_prod_distrib_symm_apply_right Equiv.sumProdDistrib_symm_apply_right /-- Type product is left distributive with respect to type sum up to an equivalence. -/ def prodSumDistrib (α β γ) : α × Sum β γ ≃ Sum (α × β) (α × γ) := calc α × Sum β γ ≃ Sum β γ × α := prodComm _ _ _ ≃ Sum (β × α) (γ × α) := sumProdDistrib _ _ _ _ ≃ Sum (α × β) (α × γ) := sumCongr (prodComm _ _) (prodComm _ _) #align equiv.prod_sum_distrib Equiv.prodSumDistrib @[simp] theorem prodSumDistrib_apply_left (a : α) (b : β) : prodSumDistrib α β γ (a, Sum.inl b) = Sum.inl (a, b) := rfl #align equiv.prod_sum_distrib_apply_left Equiv.prodSumDistrib_apply_left @[simp] theorem prodSumDistrib_apply_right (a : α) (c : γ) : prodSumDistrib α β γ (a, Sum.inr c) = Sum.inr (a, c) := rfl #align equiv.prod_sum_distrib_apply_right Equiv.prodSumDistrib_apply_right @[simp] theorem prodSumDistrib_symm_apply_left (a : α × β) : (prodSumDistrib α β γ).symm (inl a) = (a.1, inl a.2) := rfl #align equiv.prod_sum_distrib_symm_apply_left Equiv.prodSumDistrib_symm_apply_left @[simp] theorem prodSumDistrib_symm_apply_right (a : α × γ) : (prodSumDistrib α β γ).symm (inr a) = (a.1, inr a.2) := rfl #align equiv.prod_sum_distrib_symm_apply_right Equiv.prodSumDistrib_symm_apply_right /-- An indexed sum of disjoint sums of types is equivalent to the sum of the indexed sums. -/ @[simps] def sigmaSumDistrib (α β : ι → Type*) : (Σ i, Sum (α i) (β i)) ≃ Sum (Σ i, α i) (Σ i, β i) := ⟨fun p => p.2.map (Sigma.mk p.1) (Sigma.mk p.1), Sum.elim (Sigma.map id fun _ => Sum.inl) (Sigma.map id fun _ => Sum.inr), fun p => by rcases p with ⟨i, a | b⟩ <;> rfl, fun p => by rcases p with (⟨i, a⟩ | ⟨i, b⟩) <;> rfl⟩ #align equiv.sigma_sum_distrib Equiv.sigmaSumDistrib #align equiv.sigma_sum_distrib_apply Equiv.sigmaSumDistrib_apply #align equiv.sigma_sum_distrib_symm_apply Equiv.sigmaSumDistrib_symm_apply /-- The product of an indexed sum of types (formally, a `Sigma`-type `Σ i, α i`) by a type `β` is equivalent to the sum of products `Σ i, (α i × β)`. -/ def sigmaProdDistrib (α : ι → Type*) (β : Type*) : (Σ i, α i) × β ≃ Σ i, α i × β := ⟨fun p => ⟨p.1.1, (p.1.2, p.2)⟩, fun p => (⟨p.1, p.2.1⟩, p.2.2), fun p => by rcases p with ⟨⟨_, _⟩, _⟩ rfl, fun p => by rcases p with ⟨_, ⟨_, _⟩⟩ rfl⟩ #align equiv.sigma_prod_distrib Equiv.sigmaProdDistrib /-- An equivalence that separates out the 0th fiber of `(Σ (n : ℕ), f n)`. -/ def sigmaNatSucc (f : ℕ → Type u) : (Σ n, f n) ≃ Sum (f 0) (Σ n, f (n + 1)) := ⟨fun x => @Sigma.casesOn ℕ f (fun _ => Sum (f 0) (Σn, f (n + 1))) x fun n => @Nat.casesOn (fun i => f i → Sum (f 0) (Σn : ℕ, f (n + 1))) n (fun x : f 0 => Sum.inl x) fun (n : ℕ) (x : f n.succ) => Sum.inr ⟨n, x⟩, Sum.elim (Sigma.mk 0) (Sigma.map Nat.succ fun _ => id), by rintro ⟨n | n, x⟩ <;> rfl, by rintro (x | ⟨n, x⟩) <;> rfl⟩ #align equiv.sigma_nat_succ Equiv.sigmaNatSucc /-- The product `Bool × α` is equivalent to `α ⊕ α`. -/ @[simps] def boolProdEquivSum (α) : Bool × α ≃ Sum α α where toFun p := p.1.casesOn (inl p.2) (inr p.2) invFun := Sum.elim (Prod.mk false) (Prod.mk true) left_inv := by rintro ⟨_ | _, _⟩ <;> rfl right_inv := by rintro (_ | _) <;> rfl #align equiv.bool_prod_equiv_sum Equiv.boolProdEquivSum #align equiv.bool_prod_equiv_sum_apply Equiv.boolProdEquivSum_apply #align equiv.bool_prod_equiv_sum_symm_apply Equiv.boolProdEquivSum_symm_apply /-- The function type `Bool → α` is equivalent to `α × α`. -/ @[simps] def boolArrowEquivProd (α) : (Bool → α) ≃ α × α where toFun f := (f false, f true) invFun p b := b.casesOn p.1 p.2 left_inv _ := funext <| Bool.forall_bool.2 ⟨rfl, rfl⟩ right_inv := fun _ => rfl #align equiv.bool_arrow_equiv_prod Equiv.boolArrowEquivProd #align equiv.bool_arrow_equiv_prod_apply Equiv.boolArrowEquivProd_apply #align equiv.bool_arrow_equiv_prod_symm_apply Equiv.boolArrowEquivProd_symm_apply end section open Sum Nat /-- The set of natural numbers is equivalent to `ℕ ⊕ PUnit`. -/ def natEquivNatSumPUnit : ℕ ≃ Sum ℕ PUnit where toFun n := Nat.casesOn n (inr PUnit.unit) inl invFun := Sum.elim Nat.succ fun _ => 0 left_inv n := by cases n <;> rfl right_inv := by rintro (_ | _) <;> rfl #align equiv.nat_equiv_nat_sum_punit Equiv.natEquivNatSumPUnit /-- `ℕ ⊕ PUnit` is equivalent to `ℕ`. -/ def natSumPUnitEquivNat : Sum ℕ PUnit ≃ ℕ := natEquivNatSumPUnit.symm #align equiv.nat_sum_punit_equiv_nat Equiv.natSumPUnitEquivNat /-- The type of integer numbers is equivalent to `ℕ ⊕ ℕ`. -/ def intEquivNatSumNat : ℤ ≃ Sum ℕ ℕ where toFun z := Int.casesOn z inl inr invFun := Sum.elim Int.ofNat Int.negSucc left_inv := by rintro (m | n) <;> rfl right_inv := by rintro (m | n) <;> rfl #align equiv.int_equiv_nat_sum_nat Equiv.intEquivNatSumNat end /-- An equivalence between `α` and `β` generates an equivalence between `List α` and `List β`. -/ def listEquivOfEquiv (e : α ≃ β) : List α ≃ List β where toFun := List.map e invFun := List.map e.symm left_inv l := by rw [List.map_map, e.symm_comp_self, List.map_id] right_inv l := by rw [List.map_map, e.self_comp_symm, List.map_id] #align equiv.list_equiv_of_equiv Equiv.listEquivOfEquiv /-- If `α` is equivalent to `β`, then `Unique α` is equivalent to `Unique β`. -/ def uniqueCongr (e : α ≃ β) : Unique α ≃ Unique β where toFun h := @Equiv.unique _ _ h e.symm invFun h := @Equiv.unique _ _ h e left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ #align equiv.unique_congr Equiv.uniqueCongr /-- If `α` is equivalent to `β`, then `IsEmpty α` is equivalent to `IsEmpty β`. -/ theorem isEmpty_congr (e : α ≃ β) : IsEmpty α ↔ IsEmpty β := ⟨fun h => @Function.isEmpty _ _ h e.symm, fun h => @Function.isEmpty _ _ h e⟩ #align equiv.is_empty_congr Equiv.isEmpty_congr protected theorem isEmpty (e : α ≃ β) [IsEmpty β] : IsEmpty α := e.isEmpty_congr.mpr ‹_› #align equiv.is_empty Equiv.isEmpty section open Subtype /-- If `α` is equivalent to `β` and the predicates `p : α → Prop` and `q : β → Prop` are equivalent at corresponding points, then `{a // p a}` is equivalent to `{b // q b}`. For the statement where `α = β`, that is, `e : perm α`, see `Perm.subtypePerm`. -/ def subtypeEquiv {p : α → Prop} {q : β → Prop} (e : α ≃ β) (h : ∀ a, p a ↔ q (e a)) : { a : α // p a } ≃ { b : β // q b } where toFun a := ⟨e a, (h _).mp a.property⟩ invFun b := ⟨e.symm b, (h _).mpr ((e.apply_symm_apply b).symm ▸ b.property)⟩ left_inv a := Subtype.ext <| by simp right_inv b := Subtype.ext <| by simp #align equiv.subtype_equiv Equiv.subtypeEquiv lemma coe_subtypeEquiv_eq_map {X Y : Type*} {p : X → Prop} {q : Y → Prop} (e : X ≃ Y) (h : ∀ x, p x ↔ q (e x)) : ⇑(e.subtypeEquiv h) = Subtype.map e (h · |>.mp) := rfl @[simp] theorem subtypeEquiv_refl {p : α → Prop} (h : ∀ a, p a ↔ p (Equiv.refl _ a) := fun a => Iff.rfl) : (Equiv.refl α).subtypeEquiv h = Equiv.refl { a : α // p a } := by ext rfl #align equiv.subtype_equiv_refl Equiv.subtypeEquiv_refl @[simp] theorem subtypeEquiv_symm {p : α → Prop} {q : β → Prop} (e : α ≃ β) (h : ∀ a : α, p a ↔ q (e a)) : (e.subtypeEquiv h).symm = e.symm.subtypeEquiv fun a => by convert (h <| e.symm a).symm exact (e.apply_symm_apply a).symm := rfl #align equiv.subtype_equiv_symm Equiv.subtypeEquiv_symm @[simp] theorem subtypeEquiv_trans {p : α → Prop} {q : β → Prop} {r : γ → Prop} (e : α ≃ β) (f : β ≃ γ) (h : ∀ a : α, p a ↔ q (e a)) (h' : ∀ b : β, q b ↔ r (f b)) : (e.subtypeEquiv h).trans (f.subtypeEquiv h') = (e.trans f).subtypeEquiv fun a => (h a).trans (h' <| e a) := rfl #align equiv.subtype_equiv_trans Equiv.subtypeEquiv_trans @[simp] theorem subtypeEquiv_apply {p : α → Prop} {q : β → Prop} (e : α ≃ β) (h : ∀ a : α, p a ↔ q (e a)) (x : { x // p x }) : e.subtypeEquiv h x = ⟨e x, (h _).1 x.2⟩ := rfl #align equiv.subtype_equiv_apply Equiv.subtypeEquiv_apply /-- If two predicates `p` and `q` are pointwise equivalent, then `{x // p x}` is equivalent to `{x // q x}`. -/ @[simps!] def subtypeEquivRight {p q : α → Prop} (e : ∀ x, p x ↔ q x) : { x // p x } ≃ { x // q x } := subtypeEquiv (Equiv.refl _) e #align equiv.subtype_equiv_right Equiv.subtypeEquivRight #align equiv.subtype_equiv_right_apply_coe Equiv.subtypeEquivRight_apply_coe #align equiv.subtype_equiv_right_symm_apply_coe Equiv.subtypeEquivRight_symm_apply_coe lemma subtypeEquivRight_apply {p q : α → Prop} (e : ∀ x, p x ↔ q x) (z : { x // p x }) : subtypeEquivRight e z = ⟨z, (e z.1).mp z.2⟩ := rfl lemma subtypeEquivRight_symm_apply {p q : α → Prop} (e : ∀ x, p x ↔ q x) (z : { x // q x }) : (subtypeEquivRight e).symm z = ⟨z, (e z.1).mpr z.2⟩ := rfl /-- If `α ≃ β`, then for any predicate `p : β → Prop` the subtype `{a // p (e a)}` is equivalent to the subtype `{b // p b}`. -/ def subtypeEquivOfSubtype {p : β → Prop} (e : α ≃ β) : { a : α // p (e a) } ≃ { b : β // p b } := subtypeEquiv e <| by simp #align equiv.subtype_equiv_of_subtype Equiv.subtypeEquivOfSubtype /-- If `α ≃ β`, then for any predicate `p : α → Prop` the subtype `{a // p a}` is equivalent to the subtype `{b // p (e.symm b)}`. This version is used by `equiv_rw`. -/ def subtypeEquivOfSubtype' {p : α → Prop} (e : α ≃ β) : { a : α // p a } ≃ { b : β // p (e.symm b) } := e.symm.subtypeEquivOfSubtype.symm #align equiv.subtype_equiv_of_subtype' Equiv.subtypeEquivOfSubtype' /-- If two predicates are equal, then the corresponding subtypes are equivalent. -/ def subtypeEquivProp {p q : α → Prop} (h : p = q) : Subtype p ≃ Subtype q := subtypeEquiv (Equiv.refl α) fun _ => h ▸ Iff.rfl #align equiv.subtype_equiv_prop Equiv.subtypeEquivProp /-- A subtype of a subtype is equivalent to the subtype of elements satisfying both predicates. This version allows the “inner” predicate to depend on `h : p a`. -/ @[simps] def subtypeSubtypeEquivSubtypeExists (p : α → Prop) (q : Subtype p → Prop) : Subtype q ≃ { a : α // ∃ h : p a, q ⟨a, h⟩ } := ⟨fun a => ⟨a.1, a.1.2, by rcases a with ⟨⟨a, hap⟩, haq⟩ exact haq⟩, fun a => ⟨⟨a, a.2.fst⟩, a.2.snd⟩, fun ⟨⟨a, ha⟩, h⟩ => rfl, fun ⟨a, h₁, h₂⟩ => rfl⟩ #align equiv.subtype_subtype_equiv_subtype_exists Equiv.subtypeSubtypeEquivSubtypeExists #align equiv.subtype_subtype_equiv_subtype_exists_symm_apply_coe_coe Equiv.subtypeSubtypeEquivSubtypeExists_symm_apply_coe_coe #align equiv.subtype_subtype_equiv_subtype_exists_apply_coe Equiv.subtypeSubtypeEquivSubtypeExists_apply_coe /-- A subtype of a subtype is equivalent to the subtype of elements satisfying both predicates. -/ @[simps!] def subtypeSubtypeEquivSubtypeInter {α : Type u} (p q : α → Prop) : { x : Subtype p // q x.1 } ≃ Subtype fun x => p x ∧ q x := (subtypeSubtypeEquivSubtypeExists p _).trans <| subtypeEquivRight fun x => @exists_prop (q x) (p x) #align equiv.subtype_subtype_equiv_subtype_inter Equiv.subtypeSubtypeEquivSubtypeInter #align equiv.subtype_subtype_equiv_subtype_inter_apply_coe Equiv.subtypeSubtypeEquivSubtypeInter_apply_coe #align equiv.subtype_subtype_equiv_subtype_inter_symm_apply_coe_coe Equiv.subtypeSubtypeEquivSubtypeInter_symm_apply_coe_coe /-- If the outer subtype has more restrictive predicate than the inner one, then we can drop the latter. -/ @[simps!] def subtypeSubtypeEquivSubtype {p q : α → Prop} (h : ∀ {x}, q x → p x) : { x : Subtype p // q x.1 } ≃ Subtype q := (subtypeSubtypeEquivSubtypeInter p _).trans <| subtypeEquivRight fun _ => and_iff_right_of_imp h #align equiv.subtype_subtype_equiv_subtype Equiv.subtypeSubtypeEquivSubtype #align equiv.subtype_subtype_equiv_subtype_apply_coe Equiv.subtypeSubtypeEquivSubtype_apply_coe #align equiv.subtype_subtype_equiv_subtype_symm_apply_coe_coe Equiv.subtypeSubtypeEquivSubtype_symm_apply_coe_coe /-- If a proposition holds for all elements, then the subtype is equivalent to the original type. -/ @[simps apply symm_apply] def subtypeUnivEquiv {p : α → Prop} (h : ∀ x, p x) : Subtype p ≃ α := ⟨fun x => x, fun x => ⟨x, h x⟩, fun _ => Subtype.eq rfl, fun _ => rfl⟩ #align equiv.subtype_univ_equiv Equiv.subtypeUnivEquiv #align equiv.subtype_univ_equiv_apply Equiv.subtypeUnivEquiv_apply #align equiv.subtype_univ_equiv_symm_apply Equiv.subtypeUnivEquiv_symm_apply /-- A subtype of a sigma-type is a sigma-type over a subtype. -/ def subtypeSigmaEquiv (p : α → Type v) (q : α → Prop) : { y : Sigma p // q y.1 } ≃ Σ x : Subtype q, p x.1 := ⟨fun x => ⟨⟨x.1.1, x.2⟩, x.1.2⟩, fun x => ⟨⟨x.1.1, x.2⟩, x.1.2⟩, fun _ => rfl, fun _ => rfl⟩ #align equiv.subtype_sigma_equiv Equiv.subtypeSigmaEquiv /-- A sigma type over a subtype is equivalent to the sigma set over the original type, if the fiber is empty outside of the subset -/ def sigmaSubtypeEquivOfSubset (p : α → Type v) (q : α → Prop) (h : ∀ x, p x → q x) : (Σ x : Subtype q, p x) ≃ Σ x : α, p x := (subtypeSigmaEquiv p q).symm.trans <| subtypeUnivEquiv fun x => h x.1 x.2 #align equiv.sigma_subtype_equiv_of_subset Equiv.sigmaSubtypeEquivOfSubset /-- If a predicate `p : β → Prop` is true on the range of a map `f : α → β`, then `Σ y : {y // p y}, {x // f x = y}` is equivalent to `α`. -/ def sigmaSubtypeFiberEquiv {α β : Type*} (f : α → β) (p : β → Prop) (h : ∀ x, p (f x)) : (Σ y : Subtype p, { x : α // f x = y }) ≃ α := calc _ ≃ Σy : β, { x : α // f x = y } := sigmaSubtypeEquivOfSubset _ p fun _ ⟨x, h'⟩ => h' ▸ h x _ ≃ α := sigmaFiberEquiv f #align equiv.sigma_subtype_fiber_equiv Equiv.sigmaSubtypeFiberEquiv /-- If for each `x` we have `p x ↔ q (f x)`, then `Σ y : {y // q y}, f ⁻¹' {y}` is equivalent to `{x // p x}`. -/ def sigmaSubtypeFiberEquivSubtype {α β : Type*} (f : α → β) {p : α → Prop} {q : β → Prop} (h : ∀ x, p x ↔ q (f x)) : (Σ y : Subtype q, { x : α // f x = y }) ≃ Subtype p := calc (Σy : Subtype q, { x : α // f x = y }) ≃ Σy : Subtype q, { x : Subtype p // Subtype.mk (f x) ((h x).1 x.2) = y } := by { apply sigmaCongrRight intro y apply Equiv.symm refine (subtypeSubtypeEquivSubtypeExists _ _).trans (subtypeEquivRight ?_) intro x exact ⟨fun ⟨hp, h'⟩ => congr_arg Subtype.val h', fun h' => ⟨(h x).2 (h'.symm ▸ y.2), Subtype.eq h'⟩⟩ } _ ≃ Subtype p := sigmaFiberEquiv fun x : Subtype p => (⟨f x, (h x).1 x.property⟩ : Subtype q) #align equiv.sigma_subtype_fiber_equiv_subtype Equiv.sigmaSubtypeFiberEquivSubtype /-- A sigma type over an `Option` is equivalent to the sigma set over the original type, if the fiber is empty at none. -/ def sigmaOptionEquivOfSome (p : Option α → Type v) (h : p none → False) : (Σ x : Option α, p x) ≃ Σ x : α, p (some x) := haveI h' : ∀ x, p x → x.isSome := by intro x cases x · intro n exfalso exact h n · intro _ exact rfl (sigmaSubtypeEquivOfSubset _ _ h').symm.trans (sigmaCongrLeft' (optionIsSomeEquiv α)) #align equiv.sigma_option_equiv_of_some Equiv.sigmaOptionEquivOfSome /-- The `Pi`-type `∀ i, π i` is equivalent to the type of sections `f : ι → Σ i, π i` of the `Sigma` type such that for all `i` we have `(f i).fst = i`. -/ def piEquivSubtypeSigma (ι) (π : ι → Type*) : (∀ i, π i) ≃ { f : ι → Σ i, π i // ∀ i, (f i).1 = i } where toFun := fun f => ⟨fun i => ⟨i, f i⟩, fun i => rfl⟩ invFun := fun f i => by rw [← f.2 i]; exact (f.1 i).2 left_inv := fun f => funext fun i => rfl right_inv := fun ⟨f, hf⟩ => Subtype.eq <| funext fun i => Sigma.eq (hf i).symm <| eq_of_heq <| rec_heq_of_heq _ <| by simp #align equiv.pi_equiv_subtype_sigma Equiv.piEquivSubtypeSigma /-- The type of functions `f : ∀ a, β a` such that for all `a` we have `p a (f a)` is equivalent to the type of functions `∀ a, {b : β a // p a b}`. -/ def subtypePiEquivPi {β : α → Sort v} {p : ∀ a, β a → Prop} : { f : ∀ a, β a // ∀ a, p a (f a) } ≃ ∀ a, { b : β a // p a b } where toFun := fun f a => ⟨f.1 a, f.2 a⟩ invFun := fun f => ⟨fun a => (f a).1, fun a => (f a).2⟩ left_inv := by rintro ⟨f, h⟩ rfl right_inv := by rintro f funext a exact Subtype.ext_val rfl #align equiv.subtype_pi_equiv_pi Equiv.subtypePiEquivPi /-- A subtype of a product defined by componentwise conditions is equivalent to a product of subtypes. -/ def subtypeProdEquivProd {p : α → Prop} {q : β → Prop} : { c : α × β // p c.1 ∧ q c.2 } ≃ { a // p a } × { b // q b } where toFun := fun x => ⟨⟨x.1.1, x.2.1⟩, ⟨x.1.2, x.2.2⟩⟩ invFun := fun x => ⟨⟨x.1.1, x.2.1⟩, ⟨x.1.2, x.2.2⟩⟩ left_inv := fun ⟨⟨_, _⟩, ⟨_, _⟩⟩ => rfl right_inv := fun ⟨⟨_, _⟩, ⟨_, _⟩⟩ => rfl #align equiv.subtype_prod_equiv_prod Equiv.subtypeProdEquivProd /-- A subtype of a `Prod` that depends only on the first component is equivalent to the corresponding subtype of the first type times the second type. -/ def prodSubtypeFstEquivSubtypeProd {p : α → Prop} : {s : α × β // p s.1} ≃ {a // p a} × β where toFun x := ⟨⟨x.1.1, x.2⟩, x.1.2⟩ invFun x := ⟨⟨x.1.1, x.2⟩, x.1.2⟩ left_inv _ := rfl right_inv _ := rfl /-- A subtype of a `Prod` is equivalent to a sigma type whose fibers are subtypes. -/ def subtypeProdEquivSigmaSubtype (p : α → β → Prop) : { x : α × β // p x.1 x.2 } ≃ Σa, { b : β // p a b } where toFun x := ⟨x.1.1, x.1.2, x.property⟩ invFun x := ⟨⟨x.1, x.2⟩, x.2.property⟩ left_inv x := by ext <;> rfl right_inv := fun ⟨a, b, pab⟩ => rfl #align equiv.subtype_prod_equiv_sigma_subtype Equiv.subtypeProdEquivSigmaSubtype /-- The type `∀ (i : α), β i` can be split as a product by separating the indices in `α` depending on whether they satisfy a predicate `p` or not. -/ @[simps] def piEquivPiSubtypeProd {α : Type*} (p : α → Prop) (β : α → Type*) [DecidablePred p] : (∀ i : α, β i) ≃ (∀ i : { x // p x }, β i) × ∀ i : { x // ¬p x }, β i where toFun f := (fun x => f x, fun x => f x) invFun f x := if h : p x then f.1 ⟨x, h⟩ else f.2 ⟨x, h⟩ right_inv := by rintro ⟨f, g⟩ ext1 <;> · ext y rcases y with ⟨val, property⟩ simp only [property, dif_pos, dif_neg, not_false_iff, Subtype.coe_mk] left_inv f := by ext x by_cases h:p x <;> · simp only [h, dif_neg, dif_pos, not_false_iff] #align equiv.pi_equiv_pi_subtype_prod Equiv.piEquivPiSubtypeProd #align equiv.pi_equiv_pi_subtype_prod_symm_apply Equiv.piEquivPiSubtypeProd_symm_apply #align equiv.pi_equiv_pi_subtype_prod_apply Equiv.piEquivPiSubtypeProd_apply /-- A product of types can be split as the binary product of one of the types and the product of all the remaining types. -/ @[simps] def piSplitAt {α : Type*} [DecidableEq α] (i : α) (β : α → Type*) : (∀ j, β j) ≃ β i × ∀ j : { j // j ≠ i }, β j where toFun f := ⟨f i, fun j => f j⟩ invFun f j := if h : j = i then h.symm.rec f.1 else f.2 ⟨j, h⟩ right_inv f := by ext x exacts [dif_pos rfl, (dif_neg x.2).trans (by cases x; rfl)] left_inv f := by ext x dsimp only split_ifs with h · subst h; rfl · rfl #align equiv.pi_split_at Equiv.piSplitAt #align equiv.pi_split_at_apply Equiv.piSplitAt_apply #align equiv.pi_split_at_symm_apply Equiv.piSplitAt_symm_apply /-- A product of copies of a type can be split as the binary product of one copy and the product of all the remaining copies. -/ @[simps!] def funSplitAt {α : Type*} [DecidableEq α] (i : α) (β : Type*) : (α → β) ≃ β × ({ j // j ≠ i } → β) := piSplitAt i _ #align equiv.fun_split_at Equiv.funSplitAt #align equiv.fun_split_at_symm_apply Equiv.funSplitAt_symm_apply #align equiv.fun_split_at_apply Equiv.funSplitAt_apply end section subtypeEquivCodomain variable [DecidableEq X] {x : X} /-- The type of all functions `X → Y` with prescribed values for all `x' ≠ x` is equivalent to the codomain `Y`. -/ def subtypeEquivCodomain (f : { x' // x' ≠ x } → Y) : { g : X → Y // g ∘ (↑) = f } ≃ Y := (subtypePreimage _ f).trans <| @funUnique { x' // ¬x' ≠ x } _ <| show Unique { x' // ¬x' ≠ x } from @Equiv.unique _ _ (show Unique { x' // x' = x } from { default := ⟨x, rfl⟩, uniq := fun ⟨_, h⟩ => Subtype.val_injective h }) (subtypeEquivRight fun _ => not_not) #align equiv.subtype_equiv_codomain Equiv.subtypeEquivCodomain @[simp] theorem coe_subtypeEquivCodomain (f : { x' // x' ≠ x } → Y) : (subtypeEquivCodomain f : _ → Y) = fun g : { g : X → Y // g ∘ (↑) = f } => (g : X → Y) x := rfl #align equiv.coe_subtype_equiv_codomain Equiv.coe_subtypeEquivCodomain @[simp] theorem subtypeEquivCodomain_apply (f : { x' // x' ≠ x } → Y) (g) : subtypeEquivCodomain f g = (g : X → Y) x := rfl #align equiv.subtype_equiv_codomain_apply Equiv.subtypeEquivCodomain_apply theorem coe_subtypeEquivCodomain_symm (f : { x' // x' ≠ x } → Y) : ((subtypeEquivCodomain f).symm : Y → _) = fun y => ⟨fun x' => if h : x' ≠ x then f ⟨x', h⟩ else y, by funext x' simp only [ne_eq, dite_not, comp_apply, Subtype.coe_eta, dite_eq_ite, ite_eq_right_iff] intro w exfalso exact x'.property w⟩ := rfl #align equiv.coe_subtype_equiv_codomain_symm Equiv.coe_subtypeEquivCodomain_symm @[simp] theorem subtypeEquivCodomain_symm_apply (f : { x' // x' ≠ x } → Y) (y : Y) (x' : X) : ((subtypeEquivCodomain f).symm y : X → Y) x' = if h : x' ≠ x then f ⟨x', h⟩ else y := rfl #align equiv.subtype_equiv_codomain_symm_apply Equiv.subtypeEquivCodomain_symm_apply theorem subtypeEquivCodomain_symm_apply_eq (f : { x' // x' ≠ x } → Y) (y : Y) : ((subtypeEquivCodomain f).symm y : X → Y) x = y := dif_neg (not_not.mpr rfl) #align equiv.subtype_equiv_codomain_symm_apply_eq Equiv.subtypeEquivCodomain_symm_apply_eq theorem subtypeEquivCodomain_symm_apply_ne (f : { x' // x' ≠ x } → Y) (y : Y) (x' : X) (h : x' ≠ x) : ((subtypeEquivCodomain f).symm y : X → Y) x' = f ⟨x', h⟩ := dif_pos h #align equiv.subtype_equiv_codomain_symm_apply_ne Equiv.subtypeEquivCodomain_symm_apply_ne end subtypeEquivCodomain instance : CanLift (α → β) (α ≃ β) (↑) Bijective where prf f hf := ⟨ofBijective f hf, rfl⟩ section variable {α' β' : Type*} (e : Perm α') {p : β' → Prop} [DecidablePred p] (f : α' ≃ Subtype p) /-- Extend the domain of `e : Equiv.Perm α` to one that is over `β` via `f : α → Subtype p`, where `p : β → Prop`, permuting only the `b : β` that satisfy `p b`. This can be used to extend the domain across a function `f : α → β`, keeping everything outside of `Set.range f` fixed. For this use-case `Equiv` given by `f` can be constructed by `Equiv.of_leftInverse'` or `Equiv.of_leftInverse` when there is a known inverse, or `Equiv.ofInjective` in the general case. -/ def Perm.extendDomain : Perm β' := (permCongr f e).subtypeCongr (Equiv.refl _) #align equiv.perm.extend_domain Equiv.Perm.extendDomain @[simp] theorem Perm.extendDomain_apply_image (a : α') : e.extendDomain f (f a) = f (e a) := by simp [Perm.extendDomain] #align equiv.perm.extend_domain_apply_image Equiv.Perm.extendDomain_apply_image theorem Perm.extendDomain_apply_subtype {b : β'} (h : p b) : e.extendDomain f b = f (e (f.symm ⟨b, h⟩)) := by simp [Perm.extendDomain, h] #align equiv.perm.extend_domain_apply_subtype Equiv.Perm.extendDomain_apply_subtype theorem Perm.extendDomain_apply_not_subtype {b : β'} (h : ¬p b) : e.extendDomain f b = b := by simp [Perm.extendDomain, h] #align equiv.perm.extend_domain_apply_not_subtype Equiv.Perm.extendDomain_apply_not_subtype @[simp] theorem Perm.extendDomain_refl : Perm.extendDomain (Equiv.refl _) f = Equiv.refl _ := by simp [Perm.extendDomain] #align equiv.perm.extend_domain_refl Equiv.Perm.extendDomain_refl @[simp] theorem Perm.extendDomain_symm : (e.extendDomain f).symm = Perm.extendDomain e.symm f := rfl #align equiv.perm.extend_domain_symm Equiv.Perm.extendDomain_symm theorem Perm.extendDomain_trans (e e' : Perm α') : (e.extendDomain f).trans (e'.extendDomain f) = Perm.extendDomain (e.trans e') f := by simp [Perm.extendDomain, permCongr_trans] #align equiv.perm.extend_domain_trans Equiv.Perm.extendDomain_trans end /-- Subtype of the quotient is equivalent to the quotient of the subtype. Let `α` be a setoid with equivalence relation `~`. Let `p₂` be a predicate on the quotient type `α/~`, and `p₁` be the lift of this predicate to `α`: `p₁ a ↔ p₂ ⟦a⟧`. Let `~₂` be the restriction of `~` to `{x // p₁ x}`. Then `{x // p₂ x}` is equivalent to the quotient of `{x // p₁ x}` by `~₂`. -/ def subtypeQuotientEquivQuotientSubtype (p₁ : α → Prop) {s₁ : Setoid α} {s₂ : Setoid (Subtype p₁)} (p₂ : Quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧) (h : ∀ x y : Subtype p₁, s₂.r x y ↔ s₁.r x y) : {x // p₂ x} ≃ Quotient s₂ where toFun a := Quotient.hrecOn a.1 (fun a h => ⟦⟨a, (hp₂ _).2 h⟩⟧) (fun a b hab => hfunext (by rw [Quotient.sound hab]) fun h₁ h₂ _ => heq_of_eq (Quotient.sound ((h _ _).2 hab))) a.2 invFun a := Quotient.liftOn a (fun a => (⟨⟦a.1⟧, (hp₂ _).1 a.2⟩ : { x // p₂ x })) fun a b hab => Subtype.ext_val (Quotient.sound ((h _ _).1 hab)) left_inv := by exact fun ⟨a, ha⟩ => Quotient.inductionOn a (fun b hb => rfl) ha right_inv a := Quotient.inductionOn a fun ⟨a, ha⟩ => rfl #align equiv.subtype_quotient_equiv_quotient_subtype Equiv.subtypeQuotientEquivQuotientSubtype @[simp] theorem subtypeQuotientEquivQuotientSubtype_mk (p₁ : α → Prop) [s₁ : Setoid α] [s₂ : Setoid (Subtype p₁)] (p₂ : Quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧) (h : ∀ x y : Subtype p₁, @Setoid.r _ s₂ x y ↔ (x : α) ≈ y) (x hx) : subtypeQuotientEquivQuotientSubtype p₁ p₂ hp₂ h ⟨⟦x⟧, hx⟩ = ⟦⟨x, (hp₂ _).2 hx⟩⟧ := rfl #align equiv.subtype_quotient_equiv_quotient_subtype_mk Equiv.subtypeQuotientEquivQuotientSubtype_mk @[simp] theorem subtypeQuotientEquivQuotientSubtype_symm_mk (p₁ : α → Prop) [s₁ : Setoid α] [s₂ : Setoid (Subtype p₁)] (p₂ : Quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧) (h : ∀ x y : Subtype p₁, @Setoid.r _ s₂ x y ↔ (x : α) ≈ y) (x) : (subtypeQuotientEquivQuotientSubtype p₁ p₂ hp₂ h).symm ⟦x⟧ = ⟨⟦x⟧, (hp₂ _).1 x.property⟩ := rfl #align equiv.subtype_quotient_equiv_quotient_subtype_symm_mk Equiv.subtypeQuotientEquivQuotientSubtype_symm_mk section Swap variable [DecidableEq α] /-- A helper function for `Equiv.swap`. -/ def swapCore (a b r : α) : α := if r = a then b else if r = b then a else r #align equiv.swap_core Equiv.swapCore theorem swapCore_self (r a : α) : swapCore a a r = r := by unfold swapCore split_ifs <;> simp [*] #align equiv.swap_core_self Equiv.swapCore_self theorem swapCore_swapCore (r a b : α) : swapCore a b (swapCore a b r) = r := by unfold swapCore -- Porting note: cc missing. -- `casesm` would work here, with `casesm _ = _, ¬ _ = _`, -- if it would just continue past failures on hypotheses matching the pattern split_ifs with h₁ h₂ h₃ h₄ h₅ · subst h₁; exact h₂ · subst h₁; rfl · cases h₃ rfl · exact h₄.symm · cases h₅ rfl · cases h₅ rfl · rfl #align equiv.swap_core_swap_core Equiv.swapCore_swapCore theorem swapCore_comm (r a b : α) : swapCore a b r = swapCore b a r := by unfold swapCore -- Porting note: whatever solution works for `swapCore_swapCore` will work here too. split_ifs with h₁ h₂ h₃ <;> try simp · cases h₁; cases h₂; rfl #align equiv.swap_core_comm Equiv.swapCore_comm /-- `swap a b` is the permutation that swaps `a` and `b` and leaves other values as is. -/ def swap (a b : α) : Perm α := ⟨swapCore a b, swapCore a b, fun r => swapCore_swapCore r a b, fun r => swapCore_swapCore r a b⟩ #align equiv.swap Equiv.swap @[simp] theorem swap_self (a : α) : swap a a = Equiv.refl _ := ext fun r => swapCore_self r a #align equiv.swap_self Equiv.swap_self theorem swap_comm (a b : α) : swap a b = swap b a := ext fun r => swapCore_comm r _ _ #align equiv.swap_comm Equiv.swap_comm theorem swap_apply_def (a b x : α) : swap a b x = if x = a then b else if x = b then a else x := rfl #align equiv.swap_apply_def Equiv.swap_apply_def @[simp] theorem swap_apply_left (a b : α) : swap a b a = b := if_pos rfl #align equiv.swap_apply_left Equiv.swap_apply_left @[simp] theorem swap_apply_right (a b : α) : swap a b b = a := by by_cases h:b = a <;> simp [swap_apply_def, h] #align equiv.swap_apply_right Equiv.swap_apply_right theorem swap_apply_of_ne_of_ne {a b x : α} : x ≠ a → x ≠ b → swap a b x = x := by simp (config := { contextual := true }) [swap_apply_def] #align equiv.swap_apply_of_ne_of_ne Equiv.swap_apply_of_ne_of_ne theorem eq_or_eq_of_swap_apply_ne_self {a b x : α} (h : swap a b x ≠ x) : x = a ∨ x = b := by contrapose! h exact swap_apply_of_ne_of_ne h.1 h.2 @[simp] theorem swap_swap (a b : α) : (swap a b).trans (swap a b) = Equiv.refl _ := ext fun _ => swapCore_swapCore _ _ _ #align equiv.swap_swap Equiv.swap_swap @[simp] theorem symm_swap (a b : α) : (swap a b).symm = swap a b := rfl #align equiv.symm_swap Equiv.symm_swap @[simp] theorem swap_eq_refl_iff {x y : α} : swap x y = Equiv.refl _ ↔ x = y := by refine ⟨fun h => (Equiv.refl _).injective ?_, fun h => h ▸ swap_self _⟩ rw [← h, swap_apply_left, h, refl_apply] #align equiv.swap_eq_refl_iff Equiv.swap_eq_refl_iff
Mathlib/Logic/Equiv/Basic.lean
1,685
1,688
theorem swap_comp_apply {a b x : α} (π : Perm α) : π.trans (swap a b) x = if π x = a then b else if π x = b then a else π x := by
cases π rfl
/- Copyright (c) 2018 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Topology.Algebra.InfiniteSum.Order import Mathlib.Topology.Algebra.InfiniteSum.Ring import Mathlib.Topology.Instances.Real import Mathlib.Topology.MetricSpace.Isometry #align_import topology.instances.nnreal from "leanprover-community/mathlib"@"32253a1a1071173b33dc7d6a218cf722c6feb514" /-! # Topology on `ℝ≥0` The natural topology on `ℝ≥0` (the one induced from `ℝ`), and a basic API. ## Main definitions Instances for the following typeclasses are defined: * `TopologicalSpace ℝ≥0` * `TopologicalSemiring ℝ≥0` * `SecondCountableTopology ℝ≥0` * `OrderTopology ℝ≥0` * `ProperSpace ℝ≥0` * `ContinuousSub ℝ≥0` * `HasContinuousInv₀ ℝ≥0` (continuity of `x⁻¹` away from `0`) * `ContinuousSMul ℝ≥0 α` (whenever `α` has a continuous `MulAction ℝ α`) Everything is inherited from the corresponding structures on the reals. ## Main statements Various mathematically trivial lemmas are proved about the compatibility of limits and sums in `ℝ≥0` and `ℝ`. For example * `tendsto_coe {f : Filter α} {m : α → ℝ≥0} {x : ℝ≥0} : Filter.Tendsto (fun a, (m a : ℝ)) f (𝓝 (x : ℝ)) ↔ Filter.Tendsto m f (𝓝 x)` says that the limit of a filter along a map to `ℝ≥0` is the same in `ℝ` and `ℝ≥0`, and * `coe_tsum {f : α → ℝ≥0} : ((∑'a, f a) : ℝ) = (∑'a, (f a : ℝ))` says that says that a sum of elements in `ℝ≥0` is the same in `ℝ` and `ℝ≥0`. Similarly, some mathematically trivial lemmas about infinite sums are proved, a few of which rely on the fact that subtraction is continuous. -/ noncomputable section open Set TopologicalSpace Metric Filter open Topology namespace NNReal open NNReal Filter instance : TopologicalSpace ℝ≥0 := inferInstance -- short-circuit type class inference instance : TopologicalSemiring ℝ≥0 where toContinuousAdd := continuousAdd_induced toRealHom toContinuousMul := continuousMul_induced toRealHom instance : SecondCountableTopology ℝ≥0 := inferInstanceAs (SecondCountableTopology { x : ℝ | 0 ≤ x }) instance : OrderTopology ℝ≥0 := orderTopology_of_ordConnected (t := Ici 0) instance : CompleteSpace ℝ≥0 := isClosed_Ici.completeSpace_coe instance : ContinuousStar ℝ≥0 where continuous_star := continuous_id section coe variable {α : Type*} open Filter Finset theorem _root_.continuous_real_toNNReal : Continuous Real.toNNReal := (continuous_id.max continuous_const).subtype_mk _ #align continuous_real_to_nnreal continuous_real_toNNReal /-- `Real.toNNReal` bundled as a continuous map for convenience. -/ @[simps (config := .asFn)] noncomputable def _root_.ContinuousMap.realToNNReal : C(ℝ, ℝ≥0) := .mk Real.toNNReal continuous_real_toNNReal theorem continuous_coe : Continuous ((↑) : ℝ≥0 → ℝ) := continuous_subtype_val #align nnreal.continuous_coe NNReal.continuous_coe /-- Embedding of `ℝ≥0` to `ℝ` as a bundled continuous map. -/ @[simps (config := .asFn)] def _root_.ContinuousMap.coeNNRealReal : C(ℝ≥0, ℝ) := ⟨(↑), continuous_coe⟩ #align continuous_map.coe_nnreal_real ContinuousMap.coeNNRealReal #align continuous_map.coe_nnreal_real_apply ContinuousMap.coeNNRealReal_apply instance ContinuousMap.canLift {X : Type*} [TopologicalSpace X] : CanLift C(X, ℝ) C(X, ℝ≥0) ContinuousMap.coeNNRealReal.comp fun f => ∀ x, 0 ≤ f x where prf f hf := ⟨⟨fun x => ⟨f x, hf x⟩, f.2.subtype_mk _⟩, DFunLike.ext' rfl⟩ #align nnreal.continuous_map.can_lift NNReal.ContinuousMap.canLift @[simp, norm_cast] theorem tendsto_coe {f : Filter α} {m : α → ℝ≥0} {x : ℝ≥0} : Tendsto (fun a => (m a : ℝ)) f (𝓝 (x : ℝ)) ↔ Tendsto m f (𝓝 x) := tendsto_subtype_rng.symm #align nnreal.tendsto_coe NNReal.tendsto_coe theorem tendsto_coe' {f : Filter α} [NeBot f] {m : α → ℝ≥0} {x : ℝ} : Tendsto (fun a => m a : α → ℝ) f (𝓝 x) ↔ ∃ hx : 0 ≤ x, Tendsto m f (𝓝 ⟨x, hx⟩) := ⟨fun h => ⟨ge_of_tendsto' h fun c => (m c).2, tendsto_coe.1 h⟩, fun ⟨_, hm⟩ => tendsto_coe.2 hm⟩ #align nnreal.tendsto_coe' NNReal.tendsto_coe' @[simp] theorem map_coe_atTop : map toReal atTop = atTop := map_val_Ici_atTop 0 #align nnreal.map_coe_at_top NNReal.map_coe_atTop theorem comap_coe_atTop : comap toReal atTop = atTop := (atTop_Ici_eq 0).symm #align nnreal.comap_coe_at_top NNReal.comap_coe_atTop @[simp, norm_cast] theorem tendsto_coe_atTop {f : Filter α} {m : α → ℝ≥0} : Tendsto (fun a => (m a : ℝ)) f atTop ↔ Tendsto m f atTop := tendsto_Ici_atTop.symm #align nnreal.tendsto_coe_at_top NNReal.tendsto_coe_atTop theorem _root_.tendsto_real_toNNReal {f : Filter α} {m : α → ℝ} {x : ℝ} (h : Tendsto m f (𝓝 x)) : Tendsto (fun a => Real.toNNReal (m a)) f (𝓝 (Real.toNNReal x)) := (continuous_real_toNNReal.tendsto _).comp h #align tendsto_real_to_nnreal tendsto_real_toNNReal theorem _root_.tendsto_real_toNNReal_atTop : Tendsto Real.toNNReal atTop atTop := by rw [← tendsto_coe_atTop] exact tendsto_atTop_mono Real.le_coe_toNNReal tendsto_id #align tendsto_real_to_nnreal_at_top tendsto_real_toNNReal_atTop theorem nhds_zero : 𝓝 (0 : ℝ≥0) = ⨅ (a : ℝ≥0) (_ : a ≠ 0), 𝓟 (Iio a) := nhds_bot_order.trans <| by simp only [bot_lt_iff_ne_bot]; rfl #align nnreal.nhds_zero NNReal.nhds_zero theorem nhds_zero_basis : (𝓝 (0 : ℝ≥0)).HasBasis (fun a : ℝ≥0 => 0 < a) fun a => Iio a := nhds_bot_basis #align nnreal.nhds_zero_basis NNReal.nhds_zero_basis instance : ContinuousSub ℝ≥0 := ⟨((continuous_coe.fst'.sub continuous_coe.snd').max continuous_const).subtype_mk _⟩ instance : HasContinuousInv₀ ℝ≥0 := inferInstance instance [TopologicalSpace α] [MulAction ℝ α] [ContinuousSMul ℝ α] : ContinuousSMul ℝ≥0 α where continuous_smul := continuous_induced_dom.fst'.smul continuous_snd @[norm_cast] theorem hasSum_coe {f : α → ℝ≥0} {r : ℝ≥0} : HasSum (fun a => (f a : ℝ)) (r : ℝ) ↔ HasSum f r := by simp only [HasSum, ← coe_sum, tendsto_coe] #align nnreal.has_sum_coe NNReal.hasSum_coe protected theorem _root_.HasSum.toNNReal {f : α → ℝ} {y : ℝ} (hf₀ : ∀ n, 0 ≤ f n) (hy : HasSum f y) : HasSum (fun x => Real.toNNReal (f x)) y.toNNReal := by lift y to ℝ≥0 using hy.nonneg hf₀ lift f to α → ℝ≥0 using hf₀ simpa [hasSum_coe] using hy theorem hasSum_real_toNNReal_of_nonneg {f : α → ℝ} (hf_nonneg : ∀ n, 0 ≤ f n) (hf : Summable f) : HasSum (fun n => Real.toNNReal (f n)) (Real.toNNReal (∑' n, f n)) := hf.hasSum.toNNReal hf_nonneg #align nnreal.has_sum_real_to_nnreal_of_nonneg NNReal.hasSum_real_toNNReal_of_nonneg @[norm_cast] theorem summable_coe {f : α → ℝ≥0} : (Summable fun a => (f a : ℝ)) ↔ Summable f := by constructor · exact fun ⟨a, ha⟩ => ⟨⟨a, ha.nonneg fun x => (f x).2⟩, hasSum_coe.1 ha⟩ · exact fun ⟨a, ha⟩ => ⟨a.1, hasSum_coe.2 ha⟩ #align nnreal.summable_coe NNReal.summable_coe theorem summable_mk {f : α → ℝ} (hf : ∀ n, 0 ≤ f n) : (@Summable ℝ≥0 _ _ _ fun n => ⟨f n, hf n⟩) ↔ Summable f := Iff.symm <| summable_coe (f := fun x => ⟨f x, hf x⟩) #align nnreal.summable_coe_of_nonneg NNReal.summable_mk open scoped Classical @[norm_cast] theorem coe_tsum {f : α → ℝ≥0} : ↑(∑' a, f a) = ∑' a, (f a : ℝ) := if hf : Summable f then Eq.symm <| (hasSum_coe.2 <| hf.hasSum).tsum_eq else by simp [tsum_def, hf, mt summable_coe.1 hf] #align nnreal.coe_tsum NNReal.coe_tsum theorem coe_tsum_of_nonneg {f : α → ℝ} (hf₁ : ∀ n, 0 ≤ f n) : (⟨∑' n, f n, tsum_nonneg hf₁⟩ : ℝ≥0) = (∑' n, ⟨f n, hf₁ n⟩ : ℝ≥0) := NNReal.eq <| Eq.symm <| coe_tsum (f := fun x => ⟨f x, hf₁ x⟩) #align nnreal.coe_tsum_of_nonneg NNReal.coe_tsum_of_nonneg nonrec theorem tsum_mul_left (a : ℝ≥0) (f : α → ℝ≥0) : ∑' x, a * f x = a * ∑' x, f x := NNReal.eq <| by simp only [coe_tsum, NNReal.coe_mul, tsum_mul_left] #align nnreal.tsum_mul_left NNReal.tsum_mul_left nonrec theorem tsum_mul_right (f : α → ℝ≥0) (a : ℝ≥0) : ∑' x, f x * a = (∑' x, f x) * a := NNReal.eq <| by simp only [coe_tsum, NNReal.coe_mul, tsum_mul_right] #align nnreal.tsum_mul_right NNReal.tsum_mul_right theorem summable_comp_injective {β : Type*} {f : α → ℝ≥0} (hf : Summable f) {i : β → α} (hi : Function.Injective i) : Summable (f ∘ i) := by rw [← summable_coe] at hf ⊢ exact hf.comp_injective hi #align nnreal.summable_comp_injective NNReal.summable_comp_injective theorem summable_nat_add (f : ℕ → ℝ≥0) (hf : Summable f) (k : ℕ) : Summable fun i => f (i + k) := summable_comp_injective hf <| add_left_injective k #align nnreal.summable_nat_add NNReal.summable_nat_add nonrec theorem summable_nat_add_iff {f : ℕ → ℝ≥0} (k : ℕ) : (Summable fun i => f (i + k)) ↔ Summable f := by rw [← summable_coe, ← summable_coe] exact @summable_nat_add_iff ℝ _ _ _ (fun i => (f i : ℝ)) k #align nnreal.summable_nat_add_iff NNReal.summable_nat_add_iff nonrec theorem hasSum_nat_add_iff {f : ℕ → ℝ≥0} (k : ℕ) {a : ℝ≥0} : HasSum (fun n => f (n + k)) a ↔ HasSum f (a + ∑ i ∈ range k, f i) := by rw [← hasSum_coe, hasSum_nat_add_iff (f := fun n => toReal (f n)) k]; norm_cast #align nnreal.has_sum_nat_add_iff NNReal.hasSum_nat_add_iff theorem sum_add_tsum_nat_add {f : ℕ → ℝ≥0} (k : ℕ) (hf : Summable f) : ∑' i, f i = (∑ i ∈ range k, f i) + ∑' i, f (i + k) := (sum_add_tsum_nat_add' <| (summable_nat_add_iff k).2 hf).symm #align nnreal.sum_add_tsum_nat_add NNReal.sum_add_tsum_nat_add theorem iInf_real_pos_eq_iInf_nnreal_pos [CompleteLattice α] {f : ℝ → α} : ⨅ (n : ℝ) (_ : 0 < n), f n = ⨅ (n : ℝ≥0) (_ : 0 < n), f n := le_antisymm (iInf_mono' fun r => ⟨r, le_rfl⟩) (iInf₂_mono' fun r hr => ⟨⟨r, hr.le⟩, hr, le_rfl⟩) #align nnreal.infi_real_pos_eq_infi_nnreal_pos NNReal.iInf_real_pos_eq_iInf_nnreal_pos end coe theorem tendsto_cofinite_zero_of_summable {α} {f : α → ℝ≥0} (hf : Summable f) : Tendsto f cofinite (𝓝 0) := by simp only [← summable_coe, ← tendsto_coe] at hf ⊢ exact hf.tendsto_cofinite_zero #align nnreal.tendsto_cofinite_zero_of_summable NNReal.tendsto_cofinite_zero_of_summable theorem tendsto_atTop_zero_of_summable {f : ℕ → ℝ≥0} (hf : Summable f) : Tendsto f atTop (𝓝 0) := by rw [← Nat.cofinite_eq_atTop] exact tendsto_cofinite_zero_of_summable hf #align nnreal.tendsto_at_top_zero_of_summable NNReal.tendsto_atTop_zero_of_summable /-- The sum over the complement of a finset tends to `0` when the finset grows to cover the whole space. This does not need a summability assumption, as otherwise all sums are zero. -/ nonrec theorem tendsto_tsum_compl_atTop_zero {α : Type*} (f : α → ℝ≥0) : Tendsto (fun s : Finset α => ∑' b : { x // x ∉ s }, f b) atTop (𝓝 0) := by simp_rw [← tendsto_coe, coe_tsum, NNReal.coe_zero] exact tendsto_tsum_compl_atTop_zero fun a : α => (f a : ℝ) #align nnreal.tendsto_tsum_compl_at_top_zero NNReal.tendsto_tsum_compl_atTop_zero /-- `x ↦ x ^ n` as an order isomorphism of `ℝ≥0`. -/ def powOrderIso (n : ℕ) (hn : n ≠ 0) : ℝ≥0 ≃o ℝ≥0 := StrictMono.orderIsoOfSurjective (fun x ↦ x ^ n) (fun x y h => pow_left_strictMonoOn hn (zero_le x) (zero_le y) h) <| (continuous_id.pow _).surjective (tendsto_pow_atTop hn) <| by simpa [OrderBot.atBot_eq, pos_iff_ne_zero] #align nnreal.pow_order_iso NNReal.powOrderIso section Monotone /-- A monotone, bounded above sequence `f : ℕ → ℝ` has a finite limit. -/ theorem _root_.Real.tendsto_of_bddAbove_monotone {f : ℕ → ℝ} (h_bdd : BddAbove (Set.range f)) (h_mon : Monotone f) : ∃ r : ℝ, Tendsto f atTop (𝓝 r) := by obtain ⟨B, hB⟩ := Real.exists_isLUB (Set.range_nonempty f) h_bdd exact ⟨B, tendsto_atTop_isLUB h_mon hB⟩ /-- An antitone, bounded below sequence `f : ℕ → ℝ` has a finite limit. -/ theorem _root_.Real.tendsto_of_bddBelow_antitone {f : ℕ → ℝ} (h_bdd : BddBelow (Set.range f)) (h_ant : Antitone f) : ∃ r : ℝ, Tendsto f atTop (𝓝 r) := by obtain ⟨B, hB⟩ := Real.exists_isGLB (Set.range_nonempty f) h_bdd exact ⟨B, tendsto_atTop_isGLB h_ant hB⟩ /-- An antitone sequence `f : ℕ → ℝ≥0` has a finite limit. -/
Mathlib/Topology/Instances/NNReal.lean
286
296
theorem tendsto_of_antitone {f : ℕ → ℝ≥0} (h_ant : Antitone f) : ∃ r : ℝ≥0, Tendsto f atTop (𝓝 r) := by
have h_bdd_0 : (0 : ℝ) ∈ lowerBounds (Set.range fun n : ℕ => (f n : ℝ)) := by rintro r ⟨n, hn⟩ simp_rw [← hn] exact NNReal.coe_nonneg _ obtain ⟨L, hL⟩ := Real.tendsto_of_bddBelow_antitone ⟨0, h_bdd_0⟩ h_ant have hL0 : 0 ≤ L := haveI h_glb : IsGLB (Set.range fun n => (f n : ℝ)) L := isGLB_of_tendsto_atTop h_ant hL (le_isGLB_iff h_glb).mpr h_bdd_0 exact ⟨⟨L, hL0⟩, NNReal.tendsto_coe.mp hL⟩
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Order.Filter.Basic import Mathlib.Order.ConditionallyCompleteLattice.Basic #align_import order.filter.extr from "leanprover-community/mathlib"@"1f0096e6caa61e9c849ec2adbd227e960e9dff58" /-! # Minimum and maximum w.r.t. a filter and on a set ## Main Definitions This file defines six predicates of the form `isAB`, where `A` is `Min`, `Max`, or `Extr`, and `B` is `Filter` or `On`. * `isMinFilter f l a` means that `f a ≤ f x` in some `l`-neighborhood of `a`; * `isMaxFilter f l a` means that `f x ≤ f a` in some `l`-neighborhood of `a`; * `isExtrFilter f l a` means `isMinFilter f l a` or `isMaxFilter f l a`. Similar predicates with `on` suffix are particular cases for `l = 𝓟 s`. ## Main statements ### Change of the filter (set) argument * `is*Filter.filter_mono` : replace the filter with a smaller one; * `is*Filter.filter_inf` : replace a filter `l` with `l ⊓ l'`; * `is*On.on_subset` : restrict to a smaller set; * `is*Pn.inter` : replace a set `s` with `s ∩ t`. ### Composition * `is**.comp_mono` : if `x` is an extremum for `f` and `g` is a monotone function, then `x` is an extremum for `g ∘ f`; * `is**.comp_antitone` : similarly for the case of antitone `g`; * `is**.bicomp_mono` : if `x` is an extremum of the same type for `f` and `g` and a binary operation `op` is monotone in both arguments, then `x` is an extremum of the same type for `fun x => op (f x) (g x)`. * `is*Filter.comp_tendsto` : if `g x` is an extremum for `f` w.r.t. `l'` and `Tendsto g l l'`, then `x` is an extremum for `f ∘ g` w.r.t. `l`. * `is*On.on_preimage` : if `g x` is an extremum for `f` on `s`, then `x` is an extremum for `f ∘ g` on `g ⁻¹' s`. ### Algebraic operations * `is**.add` : if `x` is an extremum of the same type for two functions, then it is an extremum of the same type for their sum; * `is**.neg` : if `x` is an extremum for `f`, then it is an extremum of the opposite type for `-f`; * `is**.sub` : if `x` is a minimum for `f` and a maximum for `g`, then it is a minimum for `f - g` and a maximum for `g - f`; * `is**.max`, `is**.min`, `is**.sup`, `is**.inf` : similarly for `is**.add` for pointwise `max`, `min`, `sup`, `inf`, respectively. ### Miscellaneous definitions * `is**_const` : any point is both a minimum and maximum for a constant function; * `isMin/Max*.isExt` : any minimum/maximum point is an extremum; * `is**.dual`, `is**.undual`: conversion between codomains `α` and `dual α`; ## Missing features (TODO) * Multiplication and division; * `is**.bicompl` : if `x` is a minimum for `f`, `y` is a minimum for `g`, and `op` is a monotone binary operation, then `(x, y)` is a minimum for `uncurry (bicompl op f g)`. From this point of view, `is**.bicomp` is a composition * It would be nice to have a tactic that specializes `comp_(anti)mono` or `bicomp_mono` based on a proof of monotonicity of a given (binary) function. The tactic should maintain a `meta` list of known (anti)monotone (binary) functions with their names, as well as a list of special types of filters, and define the missing lemmas once one of these two lists grows. -/ universe u v w x variable {α : Type u} {β : Type v} {γ : Type w} {δ : Type x} open Set Filter open Filter section Preorder variable [Preorder β] [Preorder γ] variable (f : α → β) (s : Set α) (l : Filter α) (a : α) /-! ### Definitions -/ /-- `IsMinFilter f l a` means that `f a ≤ f x` for all `x` in some `l`-neighborhood of `a` -/ def IsMinFilter : Prop := ∀ᶠ x in l, f a ≤ f x #align is_min_filter IsMinFilter /-- `is_maxFilter f l a` means that `f x ≤ f a` for all `x` in some `l`-neighborhood of `a` -/ def IsMaxFilter : Prop := ∀ᶠ x in l, f x ≤ f a #align is_max_filter IsMaxFilter /-- `IsExtrFilter f l a` means `IsMinFilter f l a` or `IsMaxFilter f l a` -/ def IsExtrFilter : Prop := IsMinFilter f l a ∨ IsMaxFilter f l a #align is_extr_filter IsExtrFilter /-- `IsMinOn f s a` means that `f a ≤ f x` for all `x ∈ s`. Note that we do not assume `a ∈ s`. -/ def IsMinOn := IsMinFilter f (𝓟 s) a #align is_min_on IsMinOn /-- `IsMaxOn f s a` means that `f x ≤ f a` for all `x ∈ s`. Note that we do not assume `a ∈ s`. -/ def IsMaxOn := IsMaxFilter f (𝓟 s) a #align is_max_on IsMaxOn /-- `IsExtrOn f s a` means `IsMinOn f s a` or `IsMaxOn f s a` -/ def IsExtrOn : Prop := IsExtrFilter f (𝓟 s) a #align is_extr_on IsExtrOn variable {f s a l} {t : Set α} {l' : Filter α} theorem IsExtrOn.elim {p : Prop} : IsExtrOn f s a → (IsMinOn f s a → p) → (IsMaxOn f s a → p) → p := Or.elim #align is_extr_on.elim IsExtrOn.elim theorem isMinOn_iff : IsMinOn f s a ↔ ∀ x ∈ s, f a ≤ f x := Iff.rfl #align is_min_on_iff isMinOn_iff theorem isMaxOn_iff : IsMaxOn f s a ↔ ∀ x ∈ s, f x ≤ f a := Iff.rfl #align is_max_on_iff isMaxOn_iff theorem isMinOn_univ_iff : IsMinOn f univ a ↔ ∀ x, f a ≤ f x := univ_subset_iff.trans eq_univ_iff_forall #align is_min_on_univ_iff isMinOn_univ_iff theorem isMaxOn_univ_iff : IsMaxOn f univ a ↔ ∀ x, f x ≤ f a := univ_subset_iff.trans eq_univ_iff_forall #align is_max_on_univ_iff isMaxOn_univ_iff theorem IsMinFilter.tendsto_principal_Ici (h : IsMinFilter f l a) : Tendsto f l (𝓟 <| Ici (f a)) := tendsto_principal.2 h #align is_min_filter.tendsto_principal_Ici IsMinFilter.tendsto_principal_Ici theorem IsMaxFilter.tendsto_principal_Iic (h : IsMaxFilter f l a) : Tendsto f l (𝓟 <| Iic (f a)) := tendsto_principal.2 h #align is_max_filter.tendsto_principal_Iic IsMaxFilter.tendsto_principal_Iic /-! ### Conversion to `IsExtr*` -/ theorem IsMinFilter.isExtr : IsMinFilter f l a → IsExtrFilter f l a := Or.inl #align is_min_filter.is_extr IsMinFilter.isExtr theorem IsMaxFilter.isExtr : IsMaxFilter f l a → IsExtrFilter f l a := Or.inr #align is_max_filter.is_extr IsMaxFilter.isExtr theorem IsMinOn.isExtr (h : IsMinOn f s a) : IsExtrOn f s a := IsMinFilter.isExtr h #align is_min_on.is_extr IsMinOn.isExtr theorem IsMaxOn.isExtr (h : IsMaxOn f s a) : IsExtrOn f s a := IsMaxFilter.isExtr h #align is_max_on.is_extr IsMaxOn.isExtr /-! ### Constant function -/ theorem isMinFilter_const {b : β} : IsMinFilter (fun _ => b) l a := univ_mem' fun _ => le_rfl #align is_min_filter_const isMinFilter_const theorem isMaxFilter_const {b : β} : IsMaxFilter (fun _ => b) l a := univ_mem' fun _ => le_rfl #align is_max_filter_const isMaxFilter_const theorem isExtrFilter_const {b : β} : IsExtrFilter (fun _ => b) l a := isMinFilter_const.isExtr #align is_extr_filter_const isExtrFilter_const theorem isMinOn_const {b : β} : IsMinOn (fun _ => b) s a := isMinFilter_const #align is_min_on_const isMinOn_const theorem isMaxOn_const {b : β} : IsMaxOn (fun _ => b) s a := isMaxFilter_const #align is_max_on_const isMaxOn_const theorem isExtrOn_const {b : β} : IsExtrOn (fun _ => b) s a := isExtrFilter_const #align is_extr_on_const isExtrOn_const /-! ### Order dual -/ open OrderDual (toDual) theorem isMinFilter_dual_iff : IsMinFilter (toDual ∘ f) l a ↔ IsMaxFilter f l a := Iff.rfl #align is_min_filter_dual_iff isMinFilter_dual_iff theorem isMaxFilter_dual_iff : IsMaxFilter (toDual ∘ f) l a ↔ IsMinFilter f l a := Iff.rfl #align is_max_filter_dual_iff isMaxFilter_dual_iff theorem isExtrFilter_dual_iff : IsExtrFilter (toDual ∘ f) l a ↔ IsExtrFilter f l a := or_comm #align is_extr_filter_dual_iff isExtrFilter_dual_iff alias ⟨IsMinFilter.undual, IsMaxFilter.dual⟩ := isMinFilter_dual_iff #align is_min_filter.undual IsMinFilter.undual #align is_max_filter.dual IsMaxFilter.dual alias ⟨IsMaxFilter.undual, IsMinFilter.dual⟩ := isMaxFilter_dual_iff #align is_max_filter.undual IsMaxFilter.undual #align is_min_filter.dual IsMinFilter.dual alias ⟨IsExtrFilter.undual, IsExtrFilter.dual⟩ := isExtrFilter_dual_iff #align is_extr_filter.undual IsExtrFilter.undual #align is_extr_filter.dual IsExtrFilter.dual theorem isMinOn_dual_iff : IsMinOn (toDual ∘ f) s a ↔ IsMaxOn f s a := Iff.rfl #align is_min_on_dual_iff isMinOn_dual_iff theorem isMaxOn_dual_iff : IsMaxOn (toDual ∘ f) s a ↔ IsMinOn f s a := Iff.rfl #align is_max_on_dual_iff isMaxOn_dual_iff theorem isExtrOn_dual_iff : IsExtrOn (toDual ∘ f) s a ↔ IsExtrOn f s a := or_comm #align is_extr_on_dual_iff isExtrOn_dual_iff alias ⟨IsMinOn.undual, IsMaxOn.dual⟩ := isMinOn_dual_iff #align is_min_on.undual IsMinOn.undual #align is_max_on.dual IsMaxOn.dual alias ⟨IsMaxOn.undual, IsMinOn.dual⟩ := isMaxOn_dual_iff #align is_max_on.undual IsMaxOn.undual #align is_min_on.dual IsMinOn.dual alias ⟨IsExtrOn.undual, IsExtrOn.dual⟩ := isExtrOn_dual_iff #align is_extr_on.undual IsExtrOn.undual #align is_extr_on.dual IsExtrOn.dual /-! ### Operations on the filter/set -/ theorem IsMinFilter.filter_mono (h : IsMinFilter f l a) (hl : l' ≤ l) : IsMinFilter f l' a := hl h #align is_min_filter.filter_mono IsMinFilter.filter_mono theorem IsMaxFilter.filter_mono (h : IsMaxFilter f l a) (hl : l' ≤ l) : IsMaxFilter f l' a := hl h #align is_max_filter.filter_mono IsMaxFilter.filter_mono theorem IsExtrFilter.filter_mono (h : IsExtrFilter f l a) (hl : l' ≤ l) : IsExtrFilter f l' a := h.elim (fun h => (h.filter_mono hl).isExtr) fun h => (h.filter_mono hl).isExtr #align is_extr_filter.filter_mono IsExtrFilter.filter_mono theorem IsMinFilter.filter_inf (h : IsMinFilter f l a) (l') : IsMinFilter f (l ⊓ l') a := h.filter_mono inf_le_left #align is_min_filter.filter_inf IsMinFilter.filter_inf theorem IsMaxFilter.filter_inf (h : IsMaxFilter f l a) (l') : IsMaxFilter f (l ⊓ l') a := h.filter_mono inf_le_left #align is_max_filter.filter_inf IsMaxFilter.filter_inf theorem IsExtrFilter.filter_inf (h : IsExtrFilter f l a) (l') : IsExtrFilter f (l ⊓ l') a := h.filter_mono inf_le_left #align is_extr_filter.filter_inf IsExtrFilter.filter_inf theorem IsMinOn.on_subset (hf : IsMinOn f t a) (h : s ⊆ t) : IsMinOn f s a := hf.filter_mono <| principal_mono.2 h #align is_min_on.on_subset IsMinOn.on_subset theorem IsMaxOn.on_subset (hf : IsMaxOn f t a) (h : s ⊆ t) : IsMaxOn f s a := hf.filter_mono <| principal_mono.2 h #align is_max_on.on_subset IsMaxOn.on_subset theorem IsExtrOn.on_subset (hf : IsExtrOn f t a) (h : s ⊆ t) : IsExtrOn f s a := hf.filter_mono <| principal_mono.2 h #align is_extr_on.on_subset IsExtrOn.on_subset theorem IsMinOn.inter (hf : IsMinOn f s a) (t) : IsMinOn f (s ∩ t) a := hf.on_subset inter_subset_left #align is_min_on.inter IsMinOn.inter theorem IsMaxOn.inter (hf : IsMaxOn f s a) (t) : IsMaxOn f (s ∩ t) a := hf.on_subset inter_subset_left #align is_max_on.inter IsMaxOn.inter theorem IsExtrOn.inter (hf : IsExtrOn f s a) (t) : IsExtrOn f (s ∩ t) a := hf.on_subset inter_subset_left #align is_extr_on.inter IsExtrOn.inter /-! ### Composition with (anti)monotone functions -/ theorem IsMinFilter.comp_mono (hf : IsMinFilter f l a) {g : β → γ} (hg : Monotone g) : IsMinFilter (g ∘ f) l a := mem_of_superset hf fun _x hx => hg hx #align is_min_filter.comp_mono IsMinFilter.comp_mono theorem IsMaxFilter.comp_mono (hf : IsMaxFilter f l a) {g : β → γ} (hg : Monotone g) : IsMaxFilter (g ∘ f) l a := mem_of_superset hf fun _x hx => hg hx #align is_max_filter.comp_mono IsMaxFilter.comp_mono theorem IsExtrFilter.comp_mono (hf : IsExtrFilter f l a) {g : β → γ} (hg : Monotone g) : IsExtrFilter (g ∘ f) l a := hf.elim (fun hf => (hf.comp_mono hg).isExtr) fun hf => (hf.comp_mono hg).isExtr #align is_extr_filter.comp_mono IsExtrFilter.comp_mono theorem IsMinFilter.comp_antitone (hf : IsMinFilter f l a) {g : β → γ} (hg : Antitone g) : IsMaxFilter (g ∘ f) l a := hf.dual.comp_mono fun _ _ h => hg h #align is_min_filter.comp_antitone IsMinFilter.comp_antitone theorem IsMaxFilter.comp_antitone (hf : IsMaxFilter f l a) {g : β → γ} (hg : Antitone g) : IsMinFilter (g ∘ f) l a := hf.dual.comp_mono fun _ _ h => hg h #align is_max_filter.comp_antitone IsMaxFilter.comp_antitone theorem IsExtrFilter.comp_antitone (hf : IsExtrFilter f l a) {g : β → γ} (hg : Antitone g) : IsExtrFilter (g ∘ f) l a := hf.dual.comp_mono fun _ _ h => hg h #align is_extr_filter.comp_antitone IsExtrFilter.comp_antitone theorem IsMinOn.comp_mono (hf : IsMinOn f s a) {g : β → γ} (hg : Monotone g) : IsMinOn (g ∘ f) s a := IsMinFilter.comp_mono hf hg #align is_min_on.comp_mono IsMinOn.comp_mono theorem IsMaxOn.comp_mono (hf : IsMaxOn f s a) {g : β → γ} (hg : Monotone g) : IsMaxOn (g ∘ f) s a := IsMaxFilter.comp_mono hf hg #align is_max_on.comp_mono IsMaxOn.comp_mono theorem IsExtrOn.comp_mono (hf : IsExtrOn f s a) {g : β → γ} (hg : Monotone g) : IsExtrOn (g ∘ f) s a := IsExtrFilter.comp_mono hf hg #align is_extr_on.comp_mono IsExtrOn.comp_mono theorem IsMinOn.comp_antitone (hf : IsMinOn f s a) {g : β → γ} (hg : Antitone g) : IsMaxOn (g ∘ f) s a := IsMinFilter.comp_antitone hf hg #align is_min_on.comp_antitone IsMinOn.comp_antitone theorem IsMaxOn.comp_antitone (hf : IsMaxOn f s a) {g : β → γ} (hg : Antitone g) : IsMinOn (g ∘ f) s a := IsMaxFilter.comp_antitone hf hg #align is_max_on.comp_antitone IsMaxOn.comp_antitone theorem IsExtrOn.comp_antitone (hf : IsExtrOn f s a) {g : β → γ} (hg : Antitone g) : IsExtrOn (g ∘ f) s a := IsExtrFilter.comp_antitone hf hg #align is_extr_on.comp_antitone IsExtrOn.comp_antitone theorem IsMinFilter.bicomp_mono [Preorder δ] {op : β → γ → δ} (hop : ((· ≤ ·) ⇒ (· ≤ ·) ⇒ (· ≤ ·)) op op) (hf : IsMinFilter f l a) {g : α → γ} (hg : IsMinFilter g l a) : IsMinFilter (fun x => op (f x) (g x)) l a := mem_of_superset (inter_mem hf hg) fun _x ⟨hfx, hgx⟩ => hop hfx hgx #align is_min_filter.bicomp_mono IsMinFilter.bicomp_mono theorem IsMaxFilter.bicomp_mono [Preorder δ] {op : β → γ → δ} (hop : ((· ≤ ·) ⇒ (· ≤ ·) ⇒ (· ≤ ·)) op op) (hf : IsMaxFilter f l a) {g : α → γ} (hg : IsMaxFilter g l a) : IsMaxFilter (fun x => op (f x) (g x)) l a := mem_of_superset (inter_mem hf hg) fun _x ⟨hfx, hgx⟩ => hop hfx hgx #align is_max_filter.bicomp_mono IsMaxFilter.bicomp_mono -- No `Extr` version because we need `hf` and `hg` to be of the same kind theorem IsMinOn.bicomp_mono [Preorder δ] {op : β → γ → δ} (hop : ((· ≤ ·) ⇒ (· ≤ ·) ⇒ (· ≤ ·)) op op) (hf : IsMinOn f s a) {g : α → γ} (hg : IsMinOn g s a) : IsMinOn (fun x => op (f x) (g x)) s a := IsMinFilter.bicomp_mono hop hf hg #align is_min_on.bicomp_mono IsMinOn.bicomp_mono theorem IsMaxOn.bicomp_mono [Preorder δ] {op : β → γ → δ} (hop : ((· ≤ ·) ⇒ (· ≤ ·) ⇒ (· ≤ ·)) op op) (hf : IsMaxOn f s a) {g : α → γ} (hg : IsMaxOn g s a) : IsMaxOn (fun x => op (f x) (g x)) s a := IsMaxFilter.bicomp_mono hop hf hg #align is_max_on.bicomp_mono IsMaxOn.bicomp_mono /-! ### Composition with `Tendsto` -/ theorem IsMinFilter.comp_tendsto {g : δ → α} {l' : Filter δ} {b : δ} (hf : IsMinFilter f l (g b)) (hg : Tendsto g l' l) : IsMinFilter (f ∘ g) l' b := hg hf #align is_min_filter.comp_tendsto IsMinFilter.comp_tendsto theorem IsMaxFilter.comp_tendsto {g : δ → α} {l' : Filter δ} {b : δ} (hf : IsMaxFilter f l (g b)) (hg : Tendsto g l' l) : IsMaxFilter (f ∘ g) l' b := hg hf #align is_max_filter.comp_tendsto IsMaxFilter.comp_tendsto theorem IsExtrFilter.comp_tendsto {g : δ → α} {l' : Filter δ} {b : δ} (hf : IsExtrFilter f l (g b)) (hg : Tendsto g l' l) : IsExtrFilter (f ∘ g) l' b := hf.elim (fun hf => (hf.comp_tendsto hg).isExtr) fun hf => (hf.comp_tendsto hg).isExtr #align is_extr_filter.comp_tendsto IsExtrFilter.comp_tendsto theorem IsMinOn.on_preimage (g : δ → α) {b : δ} (hf : IsMinOn f s (g b)) : IsMinOn (f ∘ g) (g ⁻¹' s) b := hf.comp_tendsto (tendsto_principal_principal.mpr <| Subset.refl _) #align is_min_on.on_preimage IsMinOn.on_preimage theorem IsMaxOn.on_preimage (g : δ → α) {b : δ} (hf : IsMaxOn f s (g b)) : IsMaxOn (f ∘ g) (g ⁻¹' s) b := hf.comp_tendsto (tendsto_principal_principal.mpr <| Subset.refl _) #align is_max_on.on_preimage IsMaxOn.on_preimage theorem IsExtrOn.on_preimage (g : δ → α) {b : δ} (hf : IsExtrOn f s (g b)) : IsExtrOn (f ∘ g) (g ⁻¹' s) b := hf.elim (fun hf => (hf.on_preimage g).isExtr) fun hf => (hf.on_preimage g).isExtr #align is_extr_on.on_preimage IsExtrOn.on_preimage theorem IsMinOn.comp_mapsTo {t : Set δ} {g : δ → α} {b : δ} (hf : IsMinOn f s a) (hg : MapsTo g t s) (ha : g b = a) : IsMinOn (f ∘ g) t b := fun y hy => by simpa only [ha, (· ∘ ·)] using hf (hg hy) #align is_min_on.comp_maps_to IsMinOn.comp_mapsTo theorem IsMaxOn.comp_mapsTo {t : Set δ} {g : δ → α} {b : δ} (hf : IsMaxOn f s a) (hg : MapsTo g t s) (ha : g b = a) : IsMaxOn (f ∘ g) t b := hf.dual.comp_mapsTo hg ha #align is_max_on.comp_maps_to IsMaxOn.comp_mapsTo theorem IsExtrOn.comp_mapsTo {t : Set δ} {g : δ → α} {b : δ} (hf : IsExtrOn f s a) (hg : MapsTo g t s) (ha : g b = a) : IsExtrOn (f ∘ g) t b := hf.elim (fun h => Or.inl <| h.comp_mapsTo hg ha) fun h => Or.inr <| h.comp_mapsTo hg ha #align is_extr_on.comp_maps_to IsExtrOn.comp_mapsTo end Preorder /-! ### Pointwise addition -/ section OrderedAddCommMonoid variable [OrderedAddCommMonoid β] {f g : α → β} {a : α} {s : Set α} {l : Filter α} theorem IsMinFilter.add (hf : IsMinFilter f l a) (hg : IsMinFilter g l a) : IsMinFilter (fun x => f x + g x) l a := show IsMinFilter (fun x => f x + g x) l a from hf.bicomp_mono (fun _x _x' hx _y _y' hy => add_le_add hx hy) hg #align is_min_filter.add IsMinFilter.add theorem IsMaxFilter.add (hf : IsMaxFilter f l a) (hg : IsMaxFilter g l a) : IsMaxFilter (fun x => f x + g x) l a := show IsMaxFilter (fun x => f x + g x) l a from hf.bicomp_mono (fun _x _x' hx _y _y' hy => add_le_add hx hy) hg #align is_max_filter.add IsMaxFilter.add theorem IsMinOn.add (hf : IsMinOn f s a) (hg : IsMinOn g s a) : IsMinOn (fun x => f x + g x) s a := IsMinFilter.add hf hg #align is_min_on.add IsMinOn.add theorem IsMaxOn.add (hf : IsMaxOn f s a) (hg : IsMaxOn g s a) : IsMaxOn (fun x => f x + g x) s a := IsMaxFilter.add hf hg #align is_max_on.add IsMaxOn.add end OrderedAddCommMonoid /-! ### Pointwise negation and subtraction -/ section OrderedAddCommGroup variable [OrderedAddCommGroup β] {f g : α → β} {a : α} {s : Set α} {l : Filter α} theorem IsMinFilter.neg (hf : IsMinFilter f l a) : IsMaxFilter (fun x => -f x) l a := hf.comp_antitone fun _x _y hx => neg_le_neg hx #align is_min_filter.neg IsMinFilter.neg theorem IsMaxFilter.neg (hf : IsMaxFilter f l a) : IsMinFilter (fun x => -f x) l a := hf.comp_antitone fun _x _y hx => neg_le_neg hx #align is_max_filter.neg IsMaxFilter.neg theorem IsExtrFilter.neg (hf : IsExtrFilter f l a) : IsExtrFilter (fun x => -f x) l a := hf.elim (fun hf => hf.neg.isExtr) fun hf => hf.neg.isExtr #align is_extr_filter.neg IsExtrFilter.neg theorem IsMinOn.neg (hf : IsMinOn f s a) : IsMaxOn (fun x => -f x) s a := hf.comp_antitone fun _x _y hx => neg_le_neg hx #align is_min_on.neg IsMinOn.neg theorem IsMaxOn.neg (hf : IsMaxOn f s a) : IsMinOn (fun x => -f x) s a := hf.comp_antitone fun _x _y hx => neg_le_neg hx #align is_max_on.neg IsMaxOn.neg theorem IsExtrOn.neg (hf : IsExtrOn f s a) : IsExtrOn (fun x => -f x) s a := hf.elim (fun hf => hf.neg.isExtr) fun hf => hf.neg.isExtr #align is_extr_on.neg IsExtrOn.neg theorem IsMinFilter.sub (hf : IsMinFilter f l a) (hg : IsMaxFilter g l a) : IsMinFilter (fun x => f x - g x) l a := by simpa only [sub_eq_add_neg] using hf.add hg.neg #align is_min_filter.sub IsMinFilter.sub
Mathlib/Order/Filter/Extr.lean
506
507
theorem IsMaxFilter.sub (hf : IsMaxFilter f l a) (hg : IsMinFilter g l a) : IsMaxFilter (fun x => f x - g x) l a := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
/- 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.Algebra.Order.Group.Instances import Mathlib.Algebra.Order.Group.OrderIso import Mathlib.Data.Set.Pointwise.SMul import Mathlib.Order.UpperLower.Basic #align_import algebra.order.upper_lower from "leanprover-community/mathlib"@"c0c52abb75074ed8b73a948341f50521fbf43b4c" /-! # Algebraic operations on upper/lower sets Upper/lower sets are preserved under pointwise algebraic operations in ordered groups. -/ open Function Set open Pointwise section OrderedCommMonoid variable {α : Type*} [OrderedCommMonoid α] {s : Set α} {x : α} @[to_additive] theorem IsUpperSet.smul_subset (hs : IsUpperSet s) (hx : 1 ≤ x) : x • s ⊆ s := smul_set_subset_iff.2 fun _ ↦ hs <| le_mul_of_one_le_left' hx #align is_upper_set.smul_subset IsUpperSet.smul_subset #align is_upper_set.vadd_subset IsUpperSet.vadd_subset @[to_additive] theorem IsLowerSet.smul_subset (hs : IsLowerSet s) (hx : x ≤ 1) : x • s ⊆ s := smul_set_subset_iff.2 fun _ ↦ hs <| mul_le_of_le_one_left' hx #align is_lower_set.smul_subset IsLowerSet.smul_subset #align is_lower_set.vadd_subset IsLowerSet.vadd_subset end OrderedCommMonoid section OrderedCommGroup variable {α : Type*} [OrderedCommGroup α] {s t : Set α} {a : α} @[to_additive] theorem IsUpperSet.smul (hs : IsUpperSet s) : IsUpperSet (a • s) := hs.image <| OrderIso.mulLeft _ #align is_upper_set.smul IsUpperSet.smul #align is_upper_set.vadd IsUpperSet.vadd @[to_additive] theorem IsLowerSet.smul (hs : IsLowerSet s) : IsLowerSet (a • s) := hs.image <| OrderIso.mulLeft _ #align is_lower_set.smul IsLowerSet.smul #align is_lower_set.vadd IsLowerSet.vadd @[to_additive] theorem Set.OrdConnected.smul (hs : s.OrdConnected) : (a • s).OrdConnected := by rw [← hs.upperClosure_inter_lowerClosure, smul_set_inter] exact (upperClosure _).upper.smul.ordConnected.inter (lowerClosure _).lower.smul.ordConnected #align set.ord_connected.smul Set.OrdConnected.smul #align set.ord_connected.vadd Set.OrdConnected.vadd @[to_additive]
Mathlib/Algebra/Order/UpperLower.lean
63
65
theorem IsUpperSet.mul_left (ht : IsUpperSet t) : IsUpperSet (s * t) := by
rw [← smul_eq_mul, ← Set.iUnion_smul_set] exact isUpperSet_iUnion₂ fun x _ ↦ ht.smul
/- Copyright (c) 2022 Eric Rodriguez. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Rodriguez -/ import Mathlib.Algebra.GroupWithZero.Units.Lemmas import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Data.Fintype.BigOperators #align_import data.sign from "leanprover-community/mathlib"@"2445c98ae4b87eabebdde552593519b9b6dc350c" /-! # Sign function This file defines the sign function for types with zero and a decidable less-than relation, and proves some basic theorems about it. -/ -- Porting note (#11081): cannot automatically derive Fintype, added manually /-- The type of signs. -/ inductive SignType | zero | neg | pos deriving DecidableEq, Inhabited #align sign_type SignType -- Porting note: these lemmas are autogenerated by the inductive definition and are not -- in simple form due to the below `x_eq_x` lemmas attribute [nolint simpNF] SignType.zero.sizeOf_spec attribute [nolint simpNF] SignType.neg.sizeOf_spec attribute [nolint simpNF] SignType.pos.sizeOf_spec namespace SignType -- Porting note: Added Fintype SignType manually instance : Fintype SignType := Fintype.ofMultiset (zero :: neg :: pos :: List.nil) (fun x ↦ by cases x <;> simp) instance : Zero SignType := ⟨zero⟩ instance : One SignType := ⟨pos⟩ instance : Neg SignType := ⟨fun s => match s with | neg => pos | zero => zero | pos => neg⟩ @[simp] theorem zero_eq_zero : zero = 0 := rfl #align sign_type.zero_eq_zero SignType.zero_eq_zero @[simp] theorem neg_eq_neg_one : neg = -1 := rfl #align sign_type.neg_eq_neg_one SignType.neg_eq_neg_one @[simp] theorem pos_eq_one : pos = 1 := rfl #align sign_type.pos_eq_one SignType.pos_eq_one instance : Mul SignType := ⟨fun x y => match x with | neg => -y | zero => zero | pos => y⟩ /-- The less-than-or-equal relation on signs. -/ protected inductive LE : SignType → SignType → Prop | of_neg (a) : SignType.LE neg a | zero : SignType.LE zero zero | of_pos (a) : SignType.LE a pos #align sign_type.le SignType.LE instance : LE SignType := ⟨SignType.LE⟩ instance LE.decidableRel : DecidableRel SignType.LE := fun a b => by cases a <;> cases b <;> first | exact isTrue (by constructor)| exact isFalse (by rintro ⟨_⟩) instance decidableEq : DecidableEq SignType := fun a b => by cases a <;> cases b <;> first | exact isTrue (by constructor)| exact isFalse (by rintro ⟨_⟩) private lemma mul_comm : ∀ (a b : SignType), a * b = b * a := by rintro ⟨⟩ ⟨⟩ <;> rfl private lemma mul_assoc : ∀ (a b c : SignType), (a * b) * c = a * (b * c) := by rintro ⟨⟩ ⟨⟩ ⟨⟩ <;> rfl /- We can define a `Field` instance on `SignType`, but it's not mathematically sensible, so we only define the `CommGroupWithZero`. -/ instance : CommGroupWithZero SignType where zero := 0 one := 1 mul := (· * ·) inv := id mul_zero a := by cases a <;> rfl zero_mul a := by cases a <;> rfl mul_one a := by cases a <;> rfl one_mul a := by cases a <;> rfl mul_inv_cancel a ha := by cases a <;> trivial mul_comm := mul_comm mul_assoc := mul_assoc exists_pair_ne := ⟨0, 1, by rintro ⟨_⟩⟩ inv_zero := rfl private lemma le_antisymm (a b : SignType) (_ : a ≤ b) (_: b ≤ a) : a = b := by cases a <;> cases b <;> trivial private lemma le_trans (a b c : SignType) (_ : a ≤ b) (_: b ≤ c) : a ≤ c := by cases a <;> cases b <;> cases c <;> tauto instance : LinearOrder SignType where le := (· ≤ ·) le_refl a := by cases a <;> constructor le_total a b := by cases a <;> cases b <;> first | left; constructor | right; constructor le_antisymm := le_antisymm le_trans := le_trans decidableLE := LE.decidableRel decidableEq := SignType.decidableEq instance : BoundedOrder SignType where top := 1 le_top := LE.of_pos bot := -1 bot_le := LE.of_neg instance : HasDistribNeg SignType := { neg_neg := fun x => by cases x <;> rfl neg_mul := fun x y => by cases x <;> cases y <;> rfl mul_neg := fun x y => by cases x <;> cases y <;> rfl } /-- `SignType` is equivalent to `Fin 3`. -/ def fin3Equiv : SignType ≃* Fin 3 where toFun a := match a with | 0 => ⟨0, by simp⟩ | 1 => ⟨1, by simp⟩ | -1 => ⟨2, by simp⟩ invFun a := match a with | ⟨0, _⟩ => 0 | ⟨1, _⟩ => 1 | ⟨2, _⟩ => -1 left_inv a := by cases a <;> rfl right_inv a := match a with | ⟨0, _⟩ => by simp | ⟨1, _⟩ => by simp | ⟨2, _⟩ => by simp map_mul' a b := by cases a <;> cases b <;> rfl #align sign_type.fin3_equiv SignType.fin3Equiv section CaseBashing -- Porting note: a lot of these thms used to use decide! which is not implemented yet theorem nonneg_iff {a : SignType} : 0 ≤ a ↔ a = 0 ∨ a = 1 := by cases a <;> decide #align sign_type.nonneg_iff SignType.nonneg_iff theorem nonneg_iff_ne_neg_one {a : SignType} : 0 ≤ a ↔ a ≠ -1 := by cases a <;> decide #align sign_type.nonneg_iff_ne_neg_one SignType.nonneg_iff_ne_neg_one theorem neg_one_lt_iff {a : SignType} : -1 < a ↔ 0 ≤ a := by cases a <;> decide #align sign_type.neg_one_lt_iff SignType.neg_one_lt_iff theorem nonpos_iff {a : SignType} : a ≤ 0 ↔ a = -1 ∨ a = 0 := by cases a <;> decide #align sign_type.nonpos_iff SignType.nonpos_iff theorem nonpos_iff_ne_one {a : SignType} : a ≤ 0 ↔ a ≠ 1 := by cases a <;> decide #align sign_type.nonpos_iff_ne_one SignType.nonpos_iff_ne_one theorem lt_one_iff {a : SignType} : a < 1 ↔ a ≤ 0 := by cases a <;> decide #align sign_type.lt_one_iff SignType.lt_one_iff @[simp] theorem neg_iff {a : SignType} : a < 0 ↔ a = -1 := by cases a <;> decide #align sign_type.neg_iff SignType.neg_iff @[simp] theorem le_neg_one_iff {a : SignType} : a ≤ -1 ↔ a = -1 := le_bot_iff #align sign_type.le_neg_one_iff SignType.le_neg_one_iff @[simp] theorem pos_iff {a : SignType} : 0 < a ↔ a = 1 := by cases a <;> decide #align sign_type.pos_iff SignType.pos_iff @[simp] theorem one_le_iff {a : SignType} : 1 ≤ a ↔ a = 1 := top_le_iff #align sign_type.one_le_iff SignType.one_le_iff @[simp] theorem neg_one_le (a : SignType) : -1 ≤ a := bot_le #align sign_type.neg_one_le SignType.neg_one_le @[simp] theorem le_one (a : SignType) : a ≤ 1 := le_top #align sign_type.le_one SignType.le_one @[simp] theorem not_lt_neg_one (a : SignType) : ¬a < -1 := not_lt_bot #align sign_type.not_lt_neg_one SignType.not_lt_neg_one @[simp] theorem not_one_lt (a : SignType) : ¬1 < a := not_top_lt #align sign_type.not_one_lt SignType.not_one_lt @[simp]
Mathlib/Data/Sign.lean
219
219
theorem self_eq_neg_iff (a : SignType) : a = -a ↔ a = 0 := by
cases a <;> decide
/- 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, Kyle Miller -/ import Mathlib.Data.Finset.Basic import Mathlib.Data.Finite.Basic import Mathlib.Data.Set.Functor import Mathlib.Data.Set.Lattice #align_import data.set.finite from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Finite sets This file defines predicates for finite and infinite sets and provides `Fintype` instances for many set constructions. It also proves basic facts about finite sets and gives ways to manipulate `Set.Finite` expressions. ## Main definitions * `Set.Finite : Set α → Prop` * `Set.Infinite : Set α → Prop` * `Set.toFinite` to prove `Set.Finite` for a `Set` from a `Finite` instance. * `Set.Finite.toFinset` to noncomputably produce a `Finset` from a `Set.Finite` proof. (See `Set.toFinset` for a computable version.) ## Implementation A finite set is defined to be a set whose coercion to a type has a `Finite` instance. There are two components to finiteness constructions. The first is `Fintype` instances for each construction. This gives a way to actually compute a `Finset` that represents the set, and these may be accessed using `set.toFinset`. This gets the `Finset` in the correct form, since otherwise `Finset.univ : Finset s` is a `Finset` for the subtype for `s`. The second component is "constructors" for `Set.Finite` that give proofs that `Fintype` instances exist classically given other `Set.Finite` proofs. Unlike the `Fintype` instances, these *do not* use any decidability instances since they do not compute anything. ## Tags finite sets -/ assert_not_exists OrderedRing assert_not_exists MonoidWithZero open Set Function universe u v w x variable {α : Type u} {β : Type v} {ι : Sort w} {γ : Type x} namespace Set /-- A set is finite if the corresponding `Subtype` is finite, i.e., if there exists a natural `n : ℕ` and an equivalence `s ≃ Fin n`. -/ protected def Finite (s : Set α) : Prop := Finite s #align set.finite Set.Finite -- The `protected` attribute does not take effect within the same namespace block. end Set namespace Set theorem finite_def {s : Set α} : s.Finite ↔ Nonempty (Fintype s) := finite_iff_nonempty_fintype s #align set.finite_def Set.finite_def protected alias ⟨Finite.nonempty_fintype, _⟩ := finite_def #align set.finite.nonempty_fintype Set.Finite.nonempty_fintype theorem finite_coe_iff {s : Set α} : Finite s ↔ s.Finite := .rfl #align set.finite_coe_iff Set.finite_coe_iff /-- Constructor for `Set.Finite` using a `Finite` instance. -/ theorem toFinite (s : Set α) [Finite s] : s.Finite := ‹_› #align set.to_finite Set.toFinite /-- Construct a `Finite` instance for a `Set` from a `Finset` with the same elements. -/ protected theorem Finite.ofFinset {p : Set α} (s : Finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) : p.Finite := have := Fintype.ofFinset s H; p.toFinite #align set.finite.of_finset Set.Finite.ofFinset /-- Projection of `Set.Finite` to its `Finite` instance. This is intended to be used with dot notation. See also `Set.Finite.Fintype` and `Set.Finite.nonempty_fintype`. -/ protected theorem Finite.to_subtype {s : Set α} (h : s.Finite) : Finite s := h #align set.finite.to_subtype Set.Finite.to_subtype /-- A finite set coerced to a type is a `Fintype`. This is the `Fintype` projection for a `Set.Finite`. Note that because `Finite` isn't a typeclass, this definition will not fire if it is made into an instance -/ protected noncomputable def Finite.fintype {s : Set α} (h : s.Finite) : Fintype s := h.nonempty_fintype.some #align set.finite.fintype Set.Finite.fintype /-- Using choice, get the `Finset` that represents this `Set`. -/ protected noncomputable def Finite.toFinset {s : Set α} (h : s.Finite) : Finset α := @Set.toFinset _ _ h.fintype #align set.finite.to_finset Set.Finite.toFinset theorem Finite.toFinset_eq_toFinset {s : Set α} [Fintype s] (h : s.Finite) : h.toFinset = s.toFinset := by -- Porting note: was `rw [Finite.toFinset]; congr` -- in Lean 4, a goal is left after `congr` have : h.fintype = ‹_› := Subsingleton.elim _ _ rw [Finite.toFinset, this] #align set.finite.to_finset_eq_to_finset Set.Finite.toFinset_eq_toFinset @[simp] theorem toFinite_toFinset (s : Set α) [Fintype s] : s.toFinite.toFinset = s.toFinset := s.toFinite.toFinset_eq_toFinset #align set.to_finite_to_finset Set.toFinite_toFinset theorem Finite.exists_finset {s : Set α} (h : s.Finite) : ∃ s' : Finset α, ∀ a : α, a ∈ s' ↔ a ∈ s := by cases h.nonempty_fintype exact ⟨s.toFinset, fun _ => mem_toFinset⟩ #align set.finite.exists_finset Set.Finite.exists_finset theorem Finite.exists_finset_coe {s : Set α} (h : s.Finite) : ∃ s' : Finset α, ↑s' = s := by cases h.nonempty_fintype exact ⟨s.toFinset, s.coe_toFinset⟩ #align set.finite.exists_finset_coe Set.Finite.exists_finset_coe /-- Finite sets can be lifted to finsets. -/ instance : CanLift (Set α) (Finset α) (↑) Set.Finite where prf _ hs := hs.exists_finset_coe /-- A set is infinite if it is not finite. This is protected so that it does not conflict with global `Infinite`. -/ protected def Infinite (s : Set α) : Prop := ¬s.Finite #align set.infinite Set.Infinite @[simp] theorem not_infinite {s : Set α} : ¬s.Infinite ↔ s.Finite := not_not #align set.not_infinite Set.not_infinite alias ⟨_, Finite.not_infinite⟩ := not_infinite #align set.finite.not_infinite Set.Finite.not_infinite attribute [simp] Finite.not_infinite /-- See also `finite_or_infinite`, `fintypeOrInfinite`. -/ protected theorem finite_or_infinite (s : Set α) : s.Finite ∨ s.Infinite := em _ #align set.finite_or_infinite Set.finite_or_infinite protected theorem infinite_or_finite (s : Set α) : s.Infinite ∨ s.Finite := em' _ #align set.infinite_or_finite Set.infinite_or_finite /-! ### Basic properties of `Set.Finite.toFinset` -/ namespace Finite variable {s t : Set α} {a : α} (hs : s.Finite) {ht : t.Finite} @[simp] protected theorem mem_toFinset : a ∈ hs.toFinset ↔ a ∈ s := @mem_toFinset _ _ hs.fintype _ #align set.finite.mem_to_finset Set.Finite.mem_toFinset @[simp] protected theorem coe_toFinset : (hs.toFinset : Set α) = s := @coe_toFinset _ _ hs.fintype #align set.finite.coe_to_finset Set.Finite.coe_toFinset @[simp] protected theorem toFinset_nonempty : hs.toFinset.Nonempty ↔ s.Nonempty := by rw [← Finset.coe_nonempty, Finite.coe_toFinset] #align set.finite.to_finset_nonempty Set.Finite.toFinset_nonempty /-- Note that this is an equality of types not holding definitionally. Use wisely. -/ theorem coeSort_toFinset : ↥hs.toFinset = ↥s := by rw [← Finset.coe_sort_coe _, hs.coe_toFinset] #align set.finite.coe_sort_to_finset Set.Finite.coeSort_toFinset /-- The identity map, bundled as an equivalence between the subtypes of `s : Set α` and of `h.toFinset : Finset α`, where `h` is a proof of finiteness of `s`. -/ @[simps!] def subtypeEquivToFinset : {x // x ∈ s} ≃ {x // x ∈ hs.toFinset} := (Equiv.refl α).subtypeEquiv fun _ ↦ hs.mem_toFinset.symm variable {hs} @[simp] protected theorem toFinset_inj : hs.toFinset = ht.toFinset ↔ s = t := @toFinset_inj _ _ _ hs.fintype ht.fintype #align set.finite.to_finset_inj Set.Finite.toFinset_inj @[simp] theorem toFinset_subset {t : Finset α} : hs.toFinset ⊆ t ↔ s ⊆ t := by rw [← Finset.coe_subset, Finite.coe_toFinset] #align set.finite.to_finset_subset Set.Finite.toFinset_subset @[simp] theorem toFinset_ssubset {t : Finset α} : hs.toFinset ⊂ t ↔ s ⊂ t := by rw [← Finset.coe_ssubset, Finite.coe_toFinset] #align set.finite.to_finset_ssubset Set.Finite.toFinset_ssubset @[simp] theorem subset_toFinset {s : Finset α} : s ⊆ ht.toFinset ↔ ↑s ⊆ t := by rw [← Finset.coe_subset, Finite.coe_toFinset] #align set.finite.subset_to_finset Set.Finite.subset_toFinset @[simp] theorem ssubset_toFinset {s : Finset α} : s ⊂ ht.toFinset ↔ ↑s ⊂ t := by rw [← Finset.coe_ssubset, Finite.coe_toFinset] #align set.finite.ssubset_to_finset Set.Finite.ssubset_toFinset @[mono] protected theorem toFinset_subset_toFinset : hs.toFinset ⊆ ht.toFinset ↔ s ⊆ t := by simp only [← Finset.coe_subset, Finite.coe_toFinset] #align set.finite.to_finset_subset_to_finset Set.Finite.toFinset_subset_toFinset @[mono] protected theorem toFinset_ssubset_toFinset : hs.toFinset ⊂ ht.toFinset ↔ s ⊂ t := by simp only [← Finset.coe_ssubset, Finite.coe_toFinset] #align set.finite.to_finset_ssubset_to_finset Set.Finite.toFinset_ssubset_toFinset alias ⟨_, toFinset_mono⟩ := Finite.toFinset_subset_toFinset #align set.finite.to_finset_mono Set.Finite.toFinset_mono alias ⟨_, toFinset_strictMono⟩ := Finite.toFinset_ssubset_toFinset #align set.finite.to_finset_strict_mono Set.Finite.toFinset_strictMono -- Porting note: attribute [protected] doesn't work -- attribute [protected] toFinset_mono toFinset_strictMono -- Porting note: `simp` can simplify LHS but then it simplifies something -- in the generated `Fintype {x | p x}` instance and fails to apply `Set.toFinset_setOf` @[simp high] protected theorem toFinset_setOf [Fintype α] (p : α → Prop) [DecidablePred p] (h : { x | p x }.Finite) : h.toFinset = Finset.univ.filter p := by ext -- Porting note: `simp` doesn't use the `simp` lemma `Set.toFinset_setOf` without the `_` simp [Set.toFinset_setOf _] #align set.finite.to_finset_set_of Set.Finite.toFinset_setOf @[simp] nonrec theorem disjoint_toFinset {hs : s.Finite} {ht : t.Finite} : Disjoint hs.toFinset ht.toFinset ↔ Disjoint s t := @disjoint_toFinset _ _ _ hs.fintype ht.fintype #align set.finite.disjoint_to_finset Set.Finite.disjoint_toFinset protected theorem toFinset_inter [DecidableEq α] (hs : s.Finite) (ht : t.Finite) (h : (s ∩ t).Finite) : h.toFinset = hs.toFinset ∩ ht.toFinset := by ext simp #align set.finite.to_finset_inter Set.Finite.toFinset_inter protected theorem toFinset_union [DecidableEq α] (hs : s.Finite) (ht : t.Finite) (h : (s ∪ t).Finite) : h.toFinset = hs.toFinset ∪ ht.toFinset := by ext simp #align set.finite.to_finset_union Set.Finite.toFinset_union protected theorem toFinset_diff [DecidableEq α] (hs : s.Finite) (ht : t.Finite) (h : (s \ t).Finite) : h.toFinset = hs.toFinset \ ht.toFinset := by ext simp #align set.finite.to_finset_diff Set.Finite.toFinset_diff open scoped symmDiff in protected theorem toFinset_symmDiff [DecidableEq α] (hs : s.Finite) (ht : t.Finite) (h : (s ∆ t).Finite) : h.toFinset = hs.toFinset ∆ ht.toFinset := by ext simp [mem_symmDiff, Finset.mem_symmDiff] #align set.finite.to_finset_symm_diff Set.Finite.toFinset_symmDiff protected theorem toFinset_compl [DecidableEq α] [Fintype α] (hs : s.Finite) (h : sᶜ.Finite) : h.toFinset = hs.toFinsetᶜ := by ext simp #align set.finite.to_finset_compl Set.Finite.toFinset_compl protected theorem toFinset_univ [Fintype α] (h : (Set.univ : Set α).Finite) : h.toFinset = Finset.univ := by simp #align set.finite.to_finset_univ Set.Finite.toFinset_univ @[simp] protected theorem toFinset_eq_empty {h : s.Finite} : h.toFinset = ∅ ↔ s = ∅ := @toFinset_eq_empty _ _ h.fintype #align set.finite.to_finset_eq_empty Set.Finite.toFinset_eq_empty protected theorem toFinset_empty (h : (∅ : Set α).Finite) : h.toFinset = ∅ := by simp #align set.finite.to_finset_empty Set.Finite.toFinset_empty @[simp] protected theorem toFinset_eq_univ [Fintype α] {h : s.Finite} : h.toFinset = Finset.univ ↔ s = univ := @toFinset_eq_univ _ _ _ h.fintype #align set.finite.to_finset_eq_univ Set.Finite.toFinset_eq_univ protected theorem toFinset_image [DecidableEq β] (f : α → β) (hs : s.Finite) (h : (f '' s).Finite) : h.toFinset = hs.toFinset.image f := by ext simp #align set.finite.to_finset_image Set.Finite.toFinset_image -- Porting note (#10618): now `simp` can prove it but it needs the `fintypeRange` instance -- from the next section protected theorem toFinset_range [DecidableEq α] [Fintype β] (f : β → α) (h : (range f).Finite) : h.toFinset = Finset.univ.image f := by ext simp #align set.finite.to_finset_range Set.Finite.toFinset_range end Finite /-! ### Fintype instances Every instance here should have a corresponding `Set.Finite` constructor in the next section. -/ section FintypeInstances instance fintypeUniv [Fintype α] : Fintype (@univ α) := Fintype.ofEquiv α (Equiv.Set.univ α).symm #align set.fintype_univ Set.fintypeUniv /-- If `(Set.univ : Set α)` is finite then `α` is a finite type. -/ noncomputable def fintypeOfFiniteUniv (H : (univ (α := α)).Finite) : Fintype α := @Fintype.ofEquiv _ (univ : Set α) H.fintype (Equiv.Set.univ _) #align set.fintype_of_finite_univ Set.fintypeOfFiniteUniv instance fintypeUnion [DecidableEq α] (s t : Set α) [Fintype s] [Fintype t] : Fintype (s ∪ t : Set α) := Fintype.ofFinset (s.toFinset ∪ t.toFinset) <| by simp #align set.fintype_union Set.fintypeUnion instance fintypeSep (s : Set α) (p : α → Prop) [Fintype s] [DecidablePred p] : Fintype ({ a ∈ s | p a } : Set α) := Fintype.ofFinset (s.toFinset.filter p) <| by simp #align set.fintype_sep Set.fintypeSep instance fintypeInter (s t : Set α) [DecidableEq α] [Fintype s] [Fintype t] : Fintype (s ∩ t : Set α) := Fintype.ofFinset (s.toFinset ∩ t.toFinset) <| by simp #align set.fintype_inter Set.fintypeInter /-- A `Fintype` instance for set intersection where the left set has a `Fintype` instance. -/ instance fintypeInterOfLeft (s t : Set α) [Fintype s] [DecidablePred (· ∈ t)] : Fintype (s ∩ t : Set α) := Fintype.ofFinset (s.toFinset.filter (· ∈ t)) <| by simp #align set.fintype_inter_of_left Set.fintypeInterOfLeft /-- A `Fintype` instance for set intersection where the right set has a `Fintype` instance. -/ instance fintypeInterOfRight (s t : Set α) [Fintype t] [DecidablePred (· ∈ s)] : Fintype (s ∩ t : Set α) := Fintype.ofFinset (t.toFinset.filter (· ∈ s)) <| by simp [and_comm] #align set.fintype_inter_of_right Set.fintypeInterOfRight /-- A `Fintype` structure on a set defines a `Fintype` structure on its subset. -/ def fintypeSubset (s : Set α) {t : Set α} [Fintype s] [DecidablePred (· ∈ t)] (h : t ⊆ s) : Fintype t := by rw [← inter_eq_self_of_subset_right h] apply Set.fintypeInterOfLeft #align set.fintype_subset Set.fintypeSubset instance fintypeDiff [DecidableEq α] (s t : Set α) [Fintype s] [Fintype t] : Fintype (s \ t : Set α) := Fintype.ofFinset (s.toFinset \ t.toFinset) <| by simp #align set.fintype_diff Set.fintypeDiff instance fintypeDiffLeft (s t : Set α) [Fintype s] [DecidablePred (· ∈ t)] : Fintype (s \ t : Set α) := Set.fintypeSep s (· ∈ tᶜ) #align set.fintype_diff_left Set.fintypeDiffLeft instance fintypeiUnion [DecidableEq α] [Fintype (PLift ι)] (f : ι → Set α) [∀ i, Fintype (f i)] : Fintype (⋃ i, f i) := Fintype.ofFinset (Finset.univ.biUnion fun i : PLift ι => (f i.down).toFinset) <| by simp #align set.fintype_Union Set.fintypeiUnion instance fintypesUnion [DecidableEq α] {s : Set (Set α)} [Fintype s] [H : ∀ t : s, Fintype (t : Set α)] : Fintype (⋃₀ s) := by rw [sUnion_eq_iUnion] exact @Set.fintypeiUnion _ _ _ _ _ H #align set.fintype_sUnion Set.fintypesUnion /-- A union of sets with `Fintype` structure over a set with `Fintype` structure has a `Fintype` structure. -/ def fintypeBiUnion [DecidableEq α] {ι : Type*} (s : Set ι) [Fintype s] (t : ι → Set α) (H : ∀ i ∈ s, Fintype (t i)) : Fintype (⋃ x ∈ s, t x) := haveI : ∀ i : toFinset s, Fintype (t i) := fun i => H i (mem_toFinset.1 i.2) Fintype.ofFinset (s.toFinset.attach.biUnion fun x => (t x).toFinset) fun x => by simp #align set.fintype_bUnion Set.fintypeBiUnion instance fintypeBiUnion' [DecidableEq α] {ι : Type*} (s : Set ι) [Fintype s] (t : ι → Set α) [∀ i, Fintype (t i)] : Fintype (⋃ x ∈ s, t x) := Fintype.ofFinset (s.toFinset.biUnion fun x => (t x).toFinset) <| by simp #align set.fintype_bUnion' Set.fintypeBiUnion' section monad attribute [local instance] Set.monad /-- If `s : Set α` is a set with `Fintype` instance and `f : α → Set β` is a function such that each `f a`, `a ∈ s`, has a `Fintype` structure, then `s >>= f` has a `Fintype` structure. -/ def fintypeBind {α β} [DecidableEq β] (s : Set α) [Fintype s] (f : α → Set β) (H : ∀ a ∈ s, Fintype (f a)) : Fintype (s >>= f) := Set.fintypeBiUnion s f H #align set.fintype_bind Set.fintypeBind instance fintypeBind' {α β} [DecidableEq β] (s : Set α) [Fintype s] (f : α → Set β) [∀ a, Fintype (f a)] : Fintype (s >>= f) := Set.fintypeBiUnion' s f #align set.fintype_bind' Set.fintypeBind' end monad instance fintypeEmpty : Fintype (∅ : Set α) := Fintype.ofFinset ∅ <| by simp #align set.fintype_empty Set.fintypeEmpty instance fintypeSingleton (a : α) : Fintype ({a} : Set α) := Fintype.ofFinset {a} <| by simp #align set.fintype_singleton Set.fintypeSingleton instance fintypePure : ∀ a : α, Fintype (pure a : Set α) := Set.fintypeSingleton #align set.fintype_pure Set.fintypePure /-- A `Fintype` instance for inserting an element into a `Set` using the corresponding `insert` function on `Finset`. This requires `DecidableEq α`. There is also `Set.fintypeInsert'` when `a ∈ s` is decidable. -/ instance fintypeInsert (a : α) (s : Set α) [DecidableEq α] [Fintype s] : Fintype (insert a s : Set α) := Fintype.ofFinset (insert a s.toFinset) <| by simp #align set.fintype_insert Set.fintypeInsert /-- A `Fintype` structure on `insert a s` when inserting a new element. -/ def fintypeInsertOfNotMem {a : α} (s : Set α) [Fintype s] (h : a ∉ s) : Fintype (insert a s : Set α) := Fintype.ofFinset ⟨a ::ₘ s.toFinset.1, s.toFinset.nodup.cons (by simp [h])⟩ <| by simp #align set.fintype_insert_of_not_mem Set.fintypeInsertOfNotMem /-- A `Fintype` structure on `insert a s` when inserting a pre-existing element. -/ def fintypeInsertOfMem {a : α} (s : Set α) [Fintype s] (h : a ∈ s) : Fintype (insert a s : Set α) := Fintype.ofFinset s.toFinset <| by simp [h] #align set.fintype_insert_of_mem Set.fintypeInsertOfMem /-- The `Set.fintypeInsert` instance requires decidable equality, but when `a ∈ s` is decidable for this particular `a` we can still get a `Fintype` instance by using `Set.fintypeInsertOfNotMem` or `Set.fintypeInsertOfMem`. This instance pre-dates `Set.fintypeInsert`, and it is less efficient. When `Set.decidableMemOfFintype` is made a local instance, then this instance would override `Set.fintypeInsert` if not for the fact that its priority has been adjusted. See Note [lower instance priority]. -/ instance (priority := 100) fintypeInsert' (a : α) (s : Set α) [Decidable <| a ∈ s] [Fintype s] : Fintype (insert a s : Set α) := if h : a ∈ s then fintypeInsertOfMem s h else fintypeInsertOfNotMem s h #align set.fintype_insert' Set.fintypeInsert' instance fintypeImage [DecidableEq β] (s : Set α) (f : α → β) [Fintype s] : Fintype (f '' s) := Fintype.ofFinset (s.toFinset.image f) <| by simp #align set.fintype_image Set.fintypeImage /-- If a function `f` has a partial inverse and sends a set `s` to a set with `[Fintype]` instance, then `s` has a `Fintype` structure as well. -/ def fintypeOfFintypeImage (s : Set α) {f : α → β} {g} (I : IsPartialInv f g) [Fintype (f '' s)] : Fintype s := Fintype.ofFinset ⟨_, (f '' s).toFinset.2.filterMap g <| injective_of_isPartialInv_right I⟩ fun a => by suffices (∃ b x, f x = b ∧ g b = some a ∧ x ∈ s) ↔ a ∈ s by simpa [exists_and_left.symm, and_comm, and_left_comm, and_assoc] rw [exists_swap] suffices (∃ x, x ∈ s ∧ g (f x) = some a) ↔ a ∈ s by simpa [and_comm, and_left_comm, and_assoc] simp [I _, (injective_of_isPartialInv I).eq_iff] #align set.fintype_of_fintype_image Set.fintypeOfFintypeImage instance fintypeRange [DecidableEq α] (f : ι → α) [Fintype (PLift ι)] : Fintype (range f) := Fintype.ofFinset (Finset.univ.image <| f ∘ PLift.down) <| by simp #align set.fintype_range Set.fintypeRange instance fintypeMap {α β} [DecidableEq β] : ∀ (s : Set α) (f : α → β) [Fintype s], Fintype (f <$> s) := Set.fintypeImage #align set.fintype_map Set.fintypeMap instance fintypeLTNat (n : ℕ) : Fintype { i | i < n } := Fintype.ofFinset (Finset.range n) <| by simp #align set.fintype_lt_nat Set.fintypeLTNat instance fintypeLENat (n : ℕ) : Fintype { i | i ≤ n } := by simpa [Nat.lt_succ_iff] using Set.fintypeLTNat (n + 1) #align set.fintype_le_nat Set.fintypeLENat /-- This is not an instance so that it does not conflict with the one in `Mathlib/Order/LocallyFinite.lean`. -/ def Nat.fintypeIio (n : ℕ) : Fintype (Iio n) := Set.fintypeLTNat n #align set.nat.fintype_Iio Set.Nat.fintypeIio instance fintypeProd (s : Set α) (t : Set β) [Fintype s] [Fintype t] : Fintype (s ×ˢ t : Set (α × β)) := Fintype.ofFinset (s.toFinset ×ˢ t.toFinset) <| by simp #align set.fintype_prod Set.fintypeProd instance fintypeOffDiag [DecidableEq α] (s : Set α) [Fintype s] : Fintype s.offDiag := Fintype.ofFinset s.toFinset.offDiag <| by simp #align set.fintype_off_diag Set.fintypeOffDiag /-- `image2 f s t` is `Fintype` if `s` and `t` are. -/ instance fintypeImage2 [DecidableEq γ] (f : α → β → γ) (s : Set α) (t : Set β) [hs : Fintype s] [ht : Fintype t] : Fintype (image2 f s t : Set γ) := by rw [← image_prod] apply Set.fintypeImage #align set.fintype_image2 Set.fintypeImage2 instance fintypeSeq [DecidableEq β] (f : Set (α → β)) (s : Set α) [Fintype f] [Fintype s] : Fintype (f.seq s) := by rw [seq_def] apply Set.fintypeBiUnion' #align set.fintype_seq Set.fintypeSeq instance fintypeSeq' {α β : Type u} [DecidableEq β] (f : Set (α → β)) (s : Set α) [Fintype f] [Fintype s] : Fintype (f <*> s) := Set.fintypeSeq f s #align set.fintype_seq' Set.fintypeSeq' instance fintypeMemFinset (s : Finset α) : Fintype { a | a ∈ s } := Finset.fintypeCoeSort s #align set.fintype_mem_finset Set.fintypeMemFinset end FintypeInstances end Set theorem Equiv.set_finite_iff {s : Set α} {t : Set β} (hst : s ≃ t) : s.Finite ↔ t.Finite := by simp_rw [← Set.finite_coe_iff, hst.finite_iff] #align equiv.set_finite_iff Equiv.set_finite_iff /-! ### Finset -/ namespace Finset /-- Gives a `Set.Finite` for the `Finset` coerced to a `Set`. This is a wrapper around `Set.toFinite`. -/ @[simp] theorem finite_toSet (s : Finset α) : (s : Set α).Finite := Set.toFinite _ #align finset.finite_to_set Finset.finite_toSet -- Porting note (#10618): was @[simp], now `simp` can prove it theorem finite_toSet_toFinset (s : Finset α) : s.finite_toSet.toFinset = s := by rw [toFinite_toFinset, toFinset_coe] #align finset.finite_to_set_to_finset Finset.finite_toSet_toFinset end Finset namespace Multiset @[simp] theorem finite_toSet (s : Multiset α) : { x | x ∈ s }.Finite := by classical simpa only [← Multiset.mem_toFinset] using s.toFinset.finite_toSet #align multiset.finite_to_set Multiset.finite_toSet @[simp] theorem finite_toSet_toFinset [DecidableEq α] (s : Multiset α) : s.finite_toSet.toFinset = s.toFinset := by ext x simp #align multiset.finite_to_set_to_finset Multiset.finite_toSet_toFinset end Multiset @[simp] theorem List.finite_toSet (l : List α) : { x | x ∈ l }.Finite := (show Multiset α from ⟦l⟧).finite_toSet #align list.finite_to_set List.finite_toSet /-! ### Finite instances There is seemingly some overlap between the following instances and the `Fintype` instances in `Data.Set.Finite`. While every `Fintype` instance gives a `Finite` instance, those instances that depend on `Fintype` or `Decidable` instances need an additional `Finite` instance to be able to generally apply. Some set instances do not appear here since they are consequences of others, for example `Subtype.Finite` for subsets of a finite type. -/ namespace Finite.Set open scoped Classical example {s : Set α} [Finite α] : Finite s := inferInstance example : Finite (∅ : Set α) := inferInstance example (a : α) : Finite ({a} : Set α) := inferInstance instance finite_union (s t : Set α) [Finite s] [Finite t] : Finite (s ∪ t : Set α) := by cases nonempty_fintype s cases nonempty_fintype t infer_instance #align finite.set.finite_union Finite.Set.finite_union instance finite_sep (s : Set α) (p : α → Prop) [Finite s] : Finite ({ a ∈ s | p a } : Set α) := by cases nonempty_fintype s infer_instance #align finite.set.finite_sep Finite.Set.finite_sep protected theorem subset (s : Set α) {t : Set α} [Finite s] (h : t ⊆ s) : Finite t := by rw [← sep_eq_of_subset h] infer_instance #align finite.set.subset Finite.Set.subset instance finite_inter_of_right (s t : Set α) [Finite t] : Finite (s ∩ t : Set α) := Finite.Set.subset t inter_subset_right #align finite.set.finite_inter_of_right Finite.Set.finite_inter_of_right instance finite_inter_of_left (s t : Set α) [Finite s] : Finite (s ∩ t : Set α) := Finite.Set.subset s inter_subset_left #align finite.set.finite_inter_of_left Finite.Set.finite_inter_of_left instance finite_diff (s t : Set α) [Finite s] : Finite (s \ t : Set α) := Finite.Set.subset s diff_subset #align finite.set.finite_diff Finite.Set.finite_diff instance finite_range (f : ι → α) [Finite ι] : Finite (range f) := by haveI := Fintype.ofFinite (PLift ι) infer_instance #align finite.set.finite_range Finite.Set.finite_range instance finite_iUnion [Finite ι] (f : ι → Set α) [∀ i, Finite (f i)] : Finite (⋃ i, f i) := by rw [iUnion_eq_range_psigma] apply Set.finite_range #align finite.set.finite_Union Finite.Set.finite_iUnion instance finite_sUnion {s : Set (Set α)} [Finite s] [H : ∀ t : s, Finite (t : Set α)] : Finite (⋃₀ s) := by rw [sUnion_eq_iUnion] exact @Finite.Set.finite_iUnion _ _ _ _ H #align finite.set.finite_sUnion Finite.Set.finite_sUnion theorem finite_biUnion {ι : Type*} (s : Set ι) [Finite s] (t : ι → Set α) (H : ∀ i ∈ s, Finite (t i)) : Finite (⋃ x ∈ s, t x) := by rw [biUnion_eq_iUnion] haveI : ∀ i : s, Finite (t i) := fun i => H i i.property infer_instance #align finite.set.finite_bUnion Finite.Set.finite_biUnion instance finite_biUnion' {ι : Type*} (s : Set ι) [Finite s] (t : ι → Set α) [∀ i, Finite (t i)] : Finite (⋃ x ∈ s, t x) := finite_biUnion s t fun _ _ => inferInstance #align finite.set.finite_bUnion' Finite.Set.finite_biUnion' /-- Example: `Finite (⋃ (i < n), f i)` where `f : ℕ → Set α` and `[∀ i, Finite (f i)]` (when given instances from `Order.Interval.Finset.Nat`). -/ instance finite_biUnion'' {ι : Type*} (p : ι → Prop) [h : Finite { x | p x }] (t : ι → Set α) [∀ i, Finite (t i)] : Finite (⋃ (x) (_ : p x), t x) := @Finite.Set.finite_biUnion' _ _ (setOf p) h t _ #align finite.set.finite_bUnion'' Finite.Set.finite_biUnion'' instance finite_iInter {ι : Sort*} [Nonempty ι] (t : ι → Set α) [∀ i, Finite (t i)] : Finite (⋂ i, t i) := Finite.Set.subset (t <| Classical.arbitrary ι) (iInter_subset _ _) #align finite.set.finite_Inter Finite.Set.finite_iInter instance finite_insert (a : α) (s : Set α) [Finite s] : Finite (insert a s : Set α) := Finite.Set.finite_union {a} s #align finite.set.finite_insert Finite.Set.finite_insert instance finite_image (s : Set α) (f : α → β) [Finite s] : Finite (f '' s) := by cases nonempty_fintype s infer_instance #align finite.set.finite_image Finite.Set.finite_image instance finite_replacement [Finite α] (f : α → β) : Finite {f x | x : α} := Finite.Set.finite_range f #align finite.set.finite_replacement Finite.Set.finite_replacement instance finite_prod (s : Set α) (t : Set β) [Finite s] [Finite t] : Finite (s ×ˢ t : Set (α × β)) := Finite.of_equiv _ (Equiv.Set.prod s t).symm #align finite.set.finite_prod Finite.Set.finite_prod instance finite_image2 (f : α → β → γ) (s : Set α) (t : Set β) [Finite s] [Finite t] : Finite (image2 f s t : Set γ) := by rw [← image_prod] infer_instance #align finite.set.finite_image2 Finite.Set.finite_image2 instance finite_seq (f : Set (α → β)) (s : Set α) [Finite f] [Finite s] : Finite (f.seq s) := by rw [seq_def] infer_instance #align finite.set.finite_seq Finite.Set.finite_seq end Finite.Set namespace Set /-! ### Constructors for `Set.Finite` Every constructor here should have a corresponding `Fintype` instance in the previous section (or in the `Fintype` module). The implementation of these constructors ideally should be no more than `Set.toFinite`, after possibly setting up some `Fintype` and classical `Decidable` instances. -/ section SetFiniteConstructors @[nontriviality] theorem Finite.of_subsingleton [Subsingleton α] (s : Set α) : s.Finite := s.toFinite #align set.finite.of_subsingleton Set.Finite.of_subsingleton theorem finite_univ [Finite α] : (@univ α).Finite := Set.toFinite _ #align set.finite_univ Set.finite_univ theorem finite_univ_iff : (@univ α).Finite ↔ Finite α := (Equiv.Set.univ α).finite_iff #align set.finite_univ_iff Set.finite_univ_iff alias ⟨_root_.Finite.of_finite_univ, _⟩ := finite_univ_iff #align finite.of_finite_univ Finite.of_finite_univ theorem Finite.subset {s : Set α} (hs : s.Finite) {t : Set α} (ht : t ⊆ s) : t.Finite := by have := hs.to_subtype exact Finite.Set.subset _ ht #align set.finite.subset Set.Finite.subset theorem Finite.union {s t : Set α} (hs : s.Finite) (ht : t.Finite) : (s ∪ t).Finite := by rw [Set.Finite] at hs ht apply toFinite #align set.finite.union Set.Finite.union theorem Finite.finite_of_compl {s : Set α} (hs : s.Finite) (hsc : sᶜ.Finite) : Finite α := by rw [← finite_univ_iff, ← union_compl_self s] exact hs.union hsc #align set.finite.finite_of_compl Set.Finite.finite_of_compl theorem Finite.sup {s t : Set α} : s.Finite → t.Finite → (s ⊔ t).Finite := Finite.union #align set.finite.sup Set.Finite.sup theorem Finite.sep {s : Set α} (hs : s.Finite) (p : α → Prop) : { a ∈ s | p a }.Finite := hs.subset <| sep_subset _ _ #align set.finite.sep Set.Finite.sep theorem Finite.inter_of_left {s : Set α} (hs : s.Finite) (t : Set α) : (s ∩ t).Finite := hs.subset inter_subset_left #align set.finite.inter_of_left Set.Finite.inter_of_left theorem Finite.inter_of_right {s : Set α} (hs : s.Finite) (t : Set α) : (t ∩ s).Finite := hs.subset inter_subset_right #align set.finite.inter_of_right Set.Finite.inter_of_right theorem Finite.inf_of_left {s : Set α} (h : s.Finite) (t : Set α) : (s ⊓ t).Finite := h.inter_of_left t #align set.finite.inf_of_left Set.Finite.inf_of_left theorem Finite.inf_of_right {s : Set α} (h : s.Finite) (t : Set α) : (t ⊓ s).Finite := h.inter_of_right t #align set.finite.inf_of_right Set.Finite.inf_of_right protected lemma Infinite.mono {s t : Set α} (h : s ⊆ t) : s.Infinite → t.Infinite := mt fun ht ↦ ht.subset h #align set.infinite.mono Set.Infinite.mono theorem Finite.diff {s : Set α} (hs : s.Finite) (t : Set α) : (s \ t).Finite := hs.subset diff_subset #align set.finite.diff Set.Finite.diff theorem Finite.of_diff {s t : Set α} (hd : (s \ t).Finite) (ht : t.Finite) : s.Finite := (hd.union ht).subset <| subset_diff_union _ _ #align set.finite.of_diff Set.Finite.of_diff theorem finite_iUnion [Finite ι] {f : ι → Set α} (H : ∀ i, (f i).Finite) : (⋃ i, f i).Finite := haveI := fun i => (H i).to_subtype toFinite _ #align set.finite_Union Set.finite_iUnion /-- Dependent version of `Finite.biUnion`. -/ theorem Finite.biUnion' {ι} {s : Set ι} (hs : s.Finite) {t : ∀ i ∈ s, Set α} (ht : ∀ i (hi : i ∈ s), (t i hi).Finite) : (⋃ i ∈ s, t i ‹_›).Finite := by have := hs.to_subtype rw [biUnion_eq_iUnion] apply finite_iUnion fun i : s => ht i.1 i.2 #align set.finite.bUnion' Set.Finite.biUnion' theorem Finite.biUnion {ι} {s : Set ι} (hs : s.Finite) {t : ι → Set α} (ht : ∀ i ∈ s, (t i).Finite) : (⋃ i ∈ s, t i).Finite := hs.biUnion' ht #align set.finite.bUnion Set.Finite.biUnion theorem Finite.sUnion {s : Set (Set α)} (hs : s.Finite) (H : ∀ t ∈ s, Set.Finite t) : (⋃₀ s).Finite := by simpa only [sUnion_eq_biUnion] using hs.biUnion H #align set.finite.sUnion Set.Finite.sUnion theorem Finite.sInter {α : Type*} {s : Set (Set α)} {t : Set α} (ht : t ∈ s) (hf : t.Finite) : (⋂₀ s).Finite := hf.subset (sInter_subset_of_mem ht) #align set.finite.sInter Set.Finite.sInter /-- If sets `s i` are finite for all `i` from a finite set `t` and are empty for `i ∉ t`, then the union `⋃ i, s i` is a finite set. -/ theorem Finite.iUnion {ι : Type*} {s : ι → Set α} {t : Set ι} (ht : t.Finite) (hs : ∀ i ∈ t, (s i).Finite) (he : ∀ i, i ∉ t → s i = ∅) : (⋃ i, s i).Finite := by suffices ⋃ i, s i ⊆ ⋃ i ∈ t, s i by exact (ht.biUnion hs).subset this refine iUnion_subset fun i x hx => ?_ by_cases hi : i ∈ t · exact mem_biUnion hi hx · rw [he i hi, mem_empty_iff_false] at hx contradiction #align set.finite.Union Set.Finite.iUnion section monad attribute [local instance] Set.monad theorem Finite.bind {α β} {s : Set α} {f : α → Set β} (h : s.Finite) (hf : ∀ a ∈ s, (f a).Finite) : (s >>= f).Finite := h.biUnion hf #align set.finite.bind Set.Finite.bind end monad @[simp] theorem finite_empty : (∅ : Set α).Finite := toFinite _ #align set.finite_empty Set.finite_empty protected theorem Infinite.nonempty {s : Set α} (h : s.Infinite) : s.Nonempty := nonempty_iff_ne_empty.2 <| by rintro rfl exact h finite_empty #align set.infinite.nonempty Set.Infinite.nonempty @[simp] theorem finite_singleton (a : α) : ({a} : Set α).Finite := toFinite _ #align set.finite_singleton Set.finite_singleton theorem finite_pure (a : α) : (pure a : Set α).Finite := toFinite _ #align set.finite_pure Set.finite_pure @[simp] protected theorem Finite.insert (a : α) {s : Set α} (hs : s.Finite) : (insert a s).Finite := (finite_singleton a).union hs #align set.finite.insert Set.Finite.insert theorem Finite.image {s : Set α} (f : α → β) (hs : s.Finite) : (f '' s).Finite := by have := hs.to_subtype apply toFinite #align set.finite.image Set.Finite.image theorem finite_range (f : ι → α) [Finite ι] : (range f).Finite := toFinite _ #align set.finite_range Set.finite_range lemma Finite.of_surjOn {s : Set α} {t : Set β} (f : α → β) (hf : SurjOn f s t) (hs : s.Finite) : t.Finite := (hs.image _).subset hf theorem Finite.dependent_image {s : Set α} (hs : s.Finite) (F : ∀ i ∈ s, β) : {y : β | ∃ x hx, F x hx = y}.Finite := by have := hs.to_subtype simpa [range] using finite_range fun x : s => F x x.2 #align set.finite.dependent_image Set.Finite.dependent_image theorem Finite.map {α β} {s : Set α} : ∀ f : α → β, s.Finite → (f <$> s).Finite := Finite.image #align set.finite.map Set.Finite.map theorem Finite.of_finite_image {s : Set α} {f : α → β} (h : (f '' s).Finite) (hi : Set.InjOn f s) : s.Finite := have := h.to_subtype .of_injective _ hi.bijOn_image.bijective.injective #align set.finite.of_finite_image Set.Finite.of_finite_image section preimage variable {f : α → β} {s : Set β} theorem finite_of_finite_preimage (h : (f ⁻¹' s).Finite) (hs : s ⊆ range f) : s.Finite := by rw [← image_preimage_eq_of_subset hs] exact Finite.image f h #align set.finite_of_finite_preimage Set.finite_of_finite_preimage theorem Finite.of_preimage (h : (f ⁻¹' s).Finite) (hf : Surjective f) : s.Finite := hf.image_preimage s ▸ h.image _ #align set.finite.of_preimage Set.Finite.of_preimage theorem Finite.preimage (I : Set.InjOn f (f ⁻¹' s)) (h : s.Finite) : (f ⁻¹' s).Finite := (h.subset (image_preimage_subset f s)).of_finite_image I #align set.finite.preimage Set.Finite.preimage protected lemma Infinite.preimage (hs : s.Infinite) (hf : s ⊆ range f) : (f ⁻¹' s).Infinite := fun h ↦ hs <| finite_of_finite_preimage h hf lemma Infinite.preimage' (hs : (s ∩ range f).Infinite) : (f ⁻¹' s).Infinite := (hs.preimage inter_subset_right).mono <| preimage_mono inter_subset_left theorem Finite.preimage_embedding {s : Set β} (f : α ↪ β) (h : s.Finite) : (f ⁻¹' s).Finite := h.preimage fun _ _ _ _ h' => f.injective h' #align set.finite.preimage_embedding Set.Finite.preimage_embedding end preimage theorem finite_lt_nat (n : ℕ) : Set.Finite { i | i < n } := toFinite _ #align set.finite_lt_nat Set.finite_lt_nat theorem finite_le_nat (n : ℕ) : Set.Finite { i | i ≤ n } := toFinite _ #align set.finite_le_nat Set.finite_le_nat section MapsTo variable {s : Set α} {f : α → α} (hs : s.Finite) (hm : MapsTo f s s) theorem Finite.surjOn_iff_bijOn_of_mapsTo : SurjOn f s s ↔ BijOn f s s := by refine ⟨fun h ↦ ⟨hm, ?_, h⟩, BijOn.surjOn⟩ have : Finite s := finite_coe_iff.mpr hs exact hm.restrict_inj.mp (Finite.injective_iff_surjective.mpr <| hm.restrict_surjective_iff.mpr h) theorem Finite.injOn_iff_bijOn_of_mapsTo : InjOn f s ↔ BijOn f s s := by refine ⟨fun h ↦ ⟨hm, h, ?_⟩, BijOn.injOn⟩ have : Finite s := finite_coe_iff.mpr hs exact hm.restrict_surjective_iff.mp (Finite.injective_iff_surjective.mp <| hm.restrict_inj.mpr h) end MapsTo section Prod variable {s : Set α} {t : Set β} protected theorem Finite.prod (hs : s.Finite) (ht : t.Finite) : (s ×ˢ t : Set (α × β)).Finite := by have := hs.to_subtype have := ht.to_subtype apply toFinite #align set.finite.prod Set.Finite.prod theorem Finite.of_prod_left (h : (s ×ˢ t : Set (α × β)).Finite) : t.Nonempty → s.Finite := fun ⟨b, hb⟩ => (h.image Prod.fst).subset fun a ha => ⟨(a, b), ⟨ha, hb⟩, rfl⟩ #align set.finite.of_prod_left Set.Finite.of_prod_left theorem Finite.of_prod_right (h : (s ×ˢ t : Set (α × β)).Finite) : s.Nonempty → t.Finite := fun ⟨a, ha⟩ => (h.image Prod.snd).subset fun b hb => ⟨(a, b), ⟨ha, hb⟩, rfl⟩ #align set.finite.of_prod_right Set.Finite.of_prod_right protected theorem Infinite.prod_left (hs : s.Infinite) (ht : t.Nonempty) : (s ×ˢ t).Infinite := fun h => hs <| h.of_prod_left ht #align set.infinite.prod_left Set.Infinite.prod_left protected theorem Infinite.prod_right (ht : t.Infinite) (hs : s.Nonempty) : (s ×ˢ t).Infinite := fun h => ht <| h.of_prod_right hs #align set.infinite.prod_right Set.Infinite.prod_right protected theorem infinite_prod : (s ×ˢ t).Infinite ↔ s.Infinite ∧ t.Nonempty ∨ t.Infinite ∧ s.Nonempty := by refine ⟨fun h => ?_, ?_⟩ · simp_rw [Set.Infinite, @and_comm ¬_, ← Classical.not_imp] by_contra! exact h ((this.1 h.nonempty.snd).prod <| this.2 h.nonempty.fst) · rintro (h | h) · exact h.1.prod_left h.2 · exact h.1.prod_right h.2 #align set.infinite_prod Set.infinite_prod theorem finite_prod : (s ×ˢ t).Finite ↔ (s.Finite ∨ t = ∅) ∧ (t.Finite ∨ s = ∅) := by simp only [← not_infinite, Set.infinite_prod, not_or, not_and_or, not_nonempty_iff_eq_empty] #align set.finite_prod Set.finite_prod protected theorem Finite.offDiag {s : Set α} (hs : s.Finite) : s.offDiag.Finite := (hs.prod hs).subset s.offDiag_subset_prod #align set.finite.off_diag Set.Finite.offDiag protected theorem Finite.image2 (f : α → β → γ) (hs : s.Finite) (ht : t.Finite) : (image2 f s t).Finite := by have := hs.to_subtype have := ht.to_subtype apply toFinite #align set.finite.image2 Set.Finite.image2 end Prod theorem Finite.seq {f : Set (α → β)} {s : Set α} (hf : f.Finite) (hs : s.Finite) : (f.seq s).Finite := hf.image2 _ hs #align set.finite.seq Set.Finite.seq theorem Finite.seq' {α β : Type u} {f : Set (α → β)} {s : Set α} (hf : f.Finite) (hs : s.Finite) : (f <*> s).Finite := hf.seq hs #align set.finite.seq' Set.Finite.seq' theorem finite_mem_finset (s : Finset α) : { a | a ∈ s }.Finite := toFinite _ #align set.finite_mem_finset Set.finite_mem_finset theorem Subsingleton.finite {s : Set α} (h : s.Subsingleton) : s.Finite := h.induction_on finite_empty finite_singleton #align set.subsingleton.finite Set.Subsingleton.finite theorem Infinite.nontrivial {s : Set α} (hs : s.Infinite) : s.Nontrivial := not_subsingleton_iff.1 <| mt Subsingleton.finite hs theorem finite_preimage_inl_and_inr {s : Set (Sum α β)} : (Sum.inl ⁻¹' s).Finite ∧ (Sum.inr ⁻¹' s).Finite ↔ s.Finite := ⟨fun h => image_preimage_inl_union_image_preimage_inr s ▸ (h.1.image _).union (h.2.image _), fun h => ⟨h.preimage Sum.inl_injective.injOn, h.preimage Sum.inr_injective.injOn⟩⟩ #align set.finite_preimage_inl_and_inr Set.finite_preimage_inl_and_inr theorem exists_finite_iff_finset {p : Set α → Prop} : (∃ s : Set α, s.Finite ∧ p s) ↔ ∃ s : Finset α, p ↑s := ⟨fun ⟨_, hs, hps⟩ => ⟨hs.toFinset, hs.coe_toFinset.symm ▸ hps⟩, fun ⟨s, hs⟩ => ⟨s, s.finite_toSet, hs⟩⟩ #align set.exists_finite_iff_finset Set.exists_finite_iff_finset /-- There are finitely many subsets of a given finite set -/ theorem Finite.finite_subsets {α : Type u} {a : Set α} (h : a.Finite) : { b | b ⊆ a }.Finite := by convert ((Finset.powerset h.toFinset).map Finset.coeEmb.1).finite_toSet ext s simpa [← @exists_finite_iff_finset α fun t => t ⊆ a ∧ t = s, Finite.subset_toFinset, ← and_assoc, Finset.coeEmb] using h.subset #align set.finite.finite_subsets Set.Finite.finite_subsets section Pi variable {ι : Type*} [Finite ι] {κ : ι → Type*} {t : ∀ i, Set (κ i)} /-- Finite product of finite sets is finite -/ theorem Finite.pi (ht : ∀ i, (t i).Finite) : (pi univ t).Finite := by cases nonempty_fintype ι lift t to ∀ d, Finset (κ d) using ht classical rw [← Fintype.coe_piFinset] apply Finset.finite_toSet #align set.finite.pi Set.Finite.pi /-- Finite product of finite sets is finite. Note this is a variant of `Set.Finite.pi` without the extra `i ∈ univ` binder. -/ lemma Finite.pi' (ht : ∀ i, (t i).Finite) : {f : ∀ i, κ i | ∀ i, f i ∈ t i}.Finite := by simpa [Set.pi] using Finite.pi ht end Pi /-- A finite union of finsets is finite. -/ theorem union_finset_finite_of_range_finite (f : α → Finset β) (h : (range f).Finite) : (⋃ a, (f a : Set β)).Finite := by rw [← biUnion_range] exact h.biUnion fun y _ => y.finite_toSet #align set.union_finset_finite_of_range_finite Set.union_finset_finite_of_range_finite theorem finite_range_ite {p : α → Prop} [DecidablePred p] {f g : α → β} (hf : (range f).Finite) (hg : (range g).Finite) : (range fun x => if p x then f x else g x).Finite := (hf.union hg).subset range_ite_subset #align set.finite_range_ite Set.finite_range_ite theorem finite_range_const {c : β} : (range fun _ : α => c).Finite := (finite_singleton c).subset range_const_subset #align set.finite_range_const Set.finite_range_const end SetFiniteConstructors /-! ### Properties -/ instance Finite.inhabited : Inhabited { s : Set α // s.Finite } := ⟨⟨∅, finite_empty⟩⟩ #align set.finite.inhabited Set.Finite.inhabited @[simp] theorem finite_union {s t : Set α} : (s ∪ t).Finite ↔ s.Finite ∧ t.Finite := ⟨fun h => ⟨h.subset subset_union_left, h.subset subset_union_right⟩, fun ⟨hs, ht⟩ => hs.union ht⟩ #align set.finite_union Set.finite_union theorem finite_image_iff {s : Set α} {f : α → β} (hi : InjOn f s) : (f '' s).Finite ↔ s.Finite := ⟨fun h => h.of_finite_image hi, Finite.image _⟩ #align set.finite_image_iff Set.finite_image_iff theorem univ_finite_iff_nonempty_fintype : (univ : Set α).Finite ↔ Nonempty (Fintype α) := ⟨fun h => ⟨fintypeOfFiniteUniv h⟩, fun ⟨_i⟩ => finite_univ⟩ #align set.univ_finite_iff_nonempty_fintype Set.univ_finite_iff_nonempty_fintype -- Porting note: moved `@[simp]` to `Set.toFinset_singleton` because `simp` can now simplify LHS theorem Finite.toFinset_singleton {a : α} (ha : ({a} : Set α).Finite := finite_singleton _) : ha.toFinset = {a} := Set.toFinite_toFinset _ #align set.finite.to_finset_singleton Set.Finite.toFinset_singleton @[simp] theorem Finite.toFinset_insert [DecidableEq α] {s : Set α} {a : α} (hs : (insert a s).Finite) : hs.toFinset = insert a (hs.subset <| subset_insert _ _).toFinset := Finset.ext <| by simp #align set.finite.to_finset_insert Set.Finite.toFinset_insert theorem Finite.toFinset_insert' [DecidableEq α] {a : α} {s : Set α} (hs : s.Finite) : (hs.insert a).toFinset = insert a hs.toFinset := Finite.toFinset_insert _ #align set.finite.to_finset_insert' Set.Finite.toFinset_insert' theorem Finite.toFinset_prod {s : Set α} {t : Set β} (hs : s.Finite) (ht : t.Finite) : hs.toFinset ×ˢ ht.toFinset = (hs.prod ht).toFinset := Finset.ext <| by simp #align set.finite.to_finset_prod Set.Finite.toFinset_prod theorem Finite.toFinset_offDiag {s : Set α} [DecidableEq α] (hs : s.Finite) : hs.offDiag.toFinset = hs.toFinset.offDiag := Finset.ext <| by simp #align set.finite.to_finset_off_diag Set.Finite.toFinset_offDiag theorem Finite.fin_embedding {s : Set α} (h : s.Finite) : ∃ (n : ℕ) (f : Fin n ↪ α), range f = s := ⟨_, (Fintype.equivFin (h.toFinset : Set α)).symm.asEmbedding, by simp only [Finset.coe_sort_coe, Equiv.asEmbedding_range, Finite.coe_toFinset, setOf_mem_eq]⟩ #align set.finite.fin_embedding Set.Finite.fin_embedding theorem Finite.fin_param {s : Set α} (h : s.Finite) : ∃ (n : ℕ) (f : Fin n → α), Injective f ∧ range f = s := let ⟨n, f, hf⟩ := h.fin_embedding ⟨n, f, f.injective, hf⟩ #align set.finite.fin_param Set.Finite.fin_param theorem finite_option {s : Set (Option α)} : s.Finite ↔ { x : α | some x ∈ s }.Finite := ⟨fun h => h.preimage_embedding Embedding.some, fun h => ((h.image some).insert none).subset fun x => x.casesOn (fun _ => Or.inl rfl) fun _ hx => Or.inr <| mem_image_of_mem _ hx⟩ #align set.finite_option Set.finite_option theorem finite_image_fst_and_snd_iff {s : Set (α × β)} : (Prod.fst '' s).Finite ∧ (Prod.snd '' s).Finite ↔ s.Finite := ⟨fun h => (h.1.prod h.2).subset fun _ h => ⟨mem_image_of_mem _ h, mem_image_of_mem _ h⟩, fun h => ⟨h.image _, h.image _⟩⟩ #align set.finite_image_fst_and_snd_iff Set.finite_image_fst_and_snd_iff theorem forall_finite_image_eval_iff {δ : Type*} [Finite δ] {κ : δ → Type*} {s : Set (∀ d, κ d)} : (∀ d, (eval d '' s).Finite) ↔ s.Finite := ⟨fun h => (Finite.pi h).subset <| subset_pi_eval_image _ _, fun h _ => h.image _⟩ #align set.forall_finite_image_eval_iff Set.forall_finite_image_eval_iff theorem finite_subset_iUnion {s : Set α} (hs : s.Finite) {ι} {t : ι → Set α} (h : s ⊆ ⋃ i, t i) : ∃ I : Set ι, I.Finite ∧ s ⊆ ⋃ i ∈ I, t i := by have := hs.to_subtype choose f hf using show ∀ x : s, ∃ i, x.1 ∈ t i by simpa [subset_def] using h refine ⟨range f, finite_range f, fun x hx => ?_⟩ rw [biUnion_range, mem_iUnion] exact ⟨⟨x, hx⟩, hf _⟩ #align set.finite_subset_Union Set.finite_subset_iUnion theorem eq_finite_iUnion_of_finite_subset_iUnion {ι} {s : ι → Set α} {t : Set α} (tfin : t.Finite) (h : t ⊆ ⋃ i, s i) : ∃ I : Set ι, I.Finite ∧ ∃ σ : { i | i ∈ I } → Set α, (∀ i, (σ i).Finite) ∧ (∀ i, σ i ⊆ s i) ∧ t = ⋃ i, σ i := let ⟨I, Ifin, hI⟩ := finite_subset_iUnion tfin h ⟨I, Ifin, fun x => s x ∩ t, fun i => tfin.subset inter_subset_right, fun i => inter_subset_left, by ext x rw [mem_iUnion] constructor · intro x_in rcases mem_iUnion.mp (hI x_in) with ⟨i, _, ⟨hi, rfl⟩, H⟩ exact ⟨⟨i, hi⟩, ⟨H, x_in⟩⟩ · rintro ⟨i, -, H⟩ exact H⟩ #align set.eq_finite_Union_of_finite_subset_Union Set.eq_finite_iUnion_of_finite_subset_iUnion @[elab_as_elim] theorem Finite.induction_on {C : Set α → Prop} {s : Set α} (h : s.Finite) (H0 : C ∅) (H1 : ∀ {a s}, a ∉ s → Set.Finite s → C s → C (insert a s)) : C s := by lift s to Finset α using h induction' s using Finset.cons_induction_on with a s ha hs · rwa [Finset.coe_empty] · rw [Finset.coe_cons] exact @H1 a s ha (Set.toFinite _) hs #align set.finite.induction_on Set.Finite.induction_on /-- Analogous to `Finset.induction_on'`. -/ @[elab_as_elim] theorem Finite.induction_on' {C : Set α → Prop} {S : Set α} (h : S.Finite) (H0 : C ∅) (H1 : ∀ {a s}, a ∈ S → s ⊆ S → a ∉ s → C s → C (insert a s)) : C S := by refine @Set.Finite.induction_on α (fun s => s ⊆ S → C s) S h (fun _ => H0) ?_ Subset.rfl intro a s has _ hCs haS rw [insert_subset_iff] at haS exact H1 haS.1 haS.2 has (hCs haS.2) #align set.finite.induction_on' Set.Finite.induction_on' @[elab_as_elim] theorem Finite.dinduction_on {C : ∀ s : Set α, s.Finite → Prop} (s : Set α) (h : s.Finite) (H0 : C ∅ finite_empty) (H1 : ∀ {a s}, a ∉ s → ∀ h : Set.Finite s, C s h → C (insert a s) (h.insert a)) : C s h := have : ∀ h : s.Finite, C s h := Finite.induction_on h (fun _ => H0) fun has hs ih _ => H1 has hs (ih _) this h #align set.finite.dinduction_on Set.Finite.dinduction_on /-- Induction up to a finite set `S`. -/ theorem Finite.induction_to {C : Set α → Prop} {S : Set α} (h : S.Finite) (S0 : Set α) (hS0 : S0 ⊆ S) (H0 : C S0) (H1 : ∀ s ⊂ S, C s → ∃ a ∈ S \ s, C (insert a s)) : C S := by have : Finite S := Finite.to_subtype h have : Finite {T : Set α // T ⊆ S} := Finite.of_equiv (Set S) (Equiv.Set.powerset S).symm rw [← Subtype.coe_mk (p := (· ⊆ S)) _ le_rfl] rw [← Subtype.coe_mk (p := (· ⊆ S)) _ hS0] at H0 refine Finite.to_wellFoundedGT.wf.induction_bot' (fun s hs hs' ↦ ?_) H0 obtain ⟨a, ⟨ha1, ha2⟩, ha'⟩ := H1 s (ssubset_of_ne_of_subset hs s.2) hs' exact ⟨⟨insert a s.1, insert_subset ha1 s.2⟩, Set.ssubset_insert ha2, ha'⟩ /-- Induction up to `univ`. -/ theorem Finite.induction_to_univ [Finite α] {C : Set α → Prop} (S0 : Set α) (H0 : C S0) (H1 : ∀ S ≠ univ, C S → ∃ a ∉ S, C (insert a S)) : C univ := finite_univ.induction_to S0 (subset_univ S0) H0 (by simpa [ssubset_univ_iff]) section attribute [local instance] Nat.fintypeIio /-- If `P` is some relation between terms of `γ` and sets in `γ`, such that every finite set `t : Set γ` has some `c : γ` related to it, then there is a recursively defined sequence `u` in `γ` so `u n` is related to the image of `{0, 1, ..., n-1}` under `u`. (We use this later to show sequentially compact sets are totally bounded.) -/ theorem seq_of_forall_finite_exists {γ : Type*} {P : γ → Set γ → Prop} (h : ∀ t : Set γ, t.Finite → ∃ c, P c t) : ∃ u : ℕ → γ, ∀ n, P (u n) (u '' Iio n) := by haveI : Nonempty γ := (h ∅ finite_empty).nonempty choose! c hc using h set f : (n : ℕ) → (g : (m : ℕ) → m < n → γ) → γ := fun n g => c (range fun k : Iio n => g k.1 k.2) set u : ℕ → γ := fun n => Nat.strongRecOn' n f refine ⟨u, fun n => ?_⟩ convert hc (u '' Iio n) ((finite_lt_nat _).image _) rw [image_eq_range] exact Nat.strongRecOn'_beta #align set.seq_of_forall_finite_exists Set.seq_of_forall_finite_exists end /-! ### Cardinality -/ theorem empty_card : Fintype.card (∅ : Set α) = 0 := rfl #align set.empty_card Set.empty_card theorem empty_card' {h : Fintype.{u} (∅ : Set α)} : @Fintype.card (∅ : Set α) h = 0 := by simp #align set.empty_card' Set.empty_card' theorem card_fintypeInsertOfNotMem {a : α} (s : Set α) [Fintype s] (h : a ∉ s) : @Fintype.card _ (fintypeInsertOfNotMem s h) = Fintype.card s + 1 := by simp [fintypeInsertOfNotMem, Fintype.card_ofFinset] #align set.card_fintype_insert_of_not_mem Set.card_fintypeInsertOfNotMem @[simp] theorem card_insert {a : α} (s : Set α) [Fintype s] (h : a ∉ s) {d : Fintype.{u} (insert a s : Set α)} : @Fintype.card _ d = Fintype.card s + 1 := by rw [← card_fintypeInsertOfNotMem s h]; congr; exact Subsingleton.elim _ _ #align set.card_insert Set.card_insert theorem card_image_of_inj_on {s : Set α} [Fintype s] {f : α → β} [Fintype (f '' s)] (H : ∀ x ∈ s, ∀ y ∈ s, f x = f y → x = y) : Fintype.card (f '' s) = Fintype.card s := haveI := Classical.propDecidable calc Fintype.card (f '' s) = (s.toFinset.image f).card := Fintype.card_of_finset' _ (by simp) _ = s.toFinset.card := Finset.card_image_of_injOn fun x hx y hy hxy => H x (mem_toFinset.1 hx) y (mem_toFinset.1 hy) hxy _ = Fintype.card s := (Fintype.card_of_finset' _ fun a => mem_toFinset).symm #align set.card_image_of_inj_on Set.card_image_of_inj_on theorem card_image_of_injective (s : Set α) [Fintype s] {f : α → β} [Fintype (f '' s)] (H : Function.Injective f) : Fintype.card (f '' s) = Fintype.card s := card_image_of_inj_on fun _ _ _ _ h => H h #align set.card_image_of_injective Set.card_image_of_injective @[simp] theorem card_singleton (a : α) : Fintype.card ({a} : Set α) = 1 := Fintype.card_ofSubsingleton _ #align set.card_singleton Set.card_singleton theorem card_lt_card {s t : Set α} [Fintype s] [Fintype t] (h : s ⊂ t) : Fintype.card s < Fintype.card t := Fintype.card_lt_of_injective_not_surjective (Set.inclusion h.1) (Set.inclusion_injective h.1) fun hst => (ssubset_iff_subset_ne.1 h).2 (eq_of_inclusion_surjective hst) #align set.card_lt_card Set.card_lt_card theorem card_le_card {s t : Set α} [Fintype s] [Fintype t] (hsub : s ⊆ t) : Fintype.card s ≤ Fintype.card t := Fintype.card_le_of_injective (Set.inclusion hsub) (Set.inclusion_injective hsub) #align set.card_le_card Set.card_le_card theorem eq_of_subset_of_card_le {s t : Set α} [Fintype s] [Fintype t] (hsub : s ⊆ t) (hcard : Fintype.card t ≤ Fintype.card s) : s = t := (eq_or_ssubset_of_subset hsub).elim id fun h => absurd hcard <| not_le_of_lt <| card_lt_card h #align set.eq_of_subset_of_card_le Set.eq_of_subset_of_card_le theorem card_range_of_injective [Fintype α] {f : α → β} (hf : Injective f) [Fintype (range f)] : Fintype.card (range f) = Fintype.card α := Eq.symm <| Fintype.card_congr <| Equiv.ofInjective f hf #align set.card_range_of_injective Set.card_range_of_injective theorem Finite.card_toFinset {s : Set α} [Fintype s] (h : s.Finite) : h.toFinset.card = Fintype.card s := Eq.symm <| Fintype.card_of_finset' _ fun _ ↦ h.mem_toFinset #align set.finite.card_to_finset Set.Finite.card_toFinset theorem card_ne_eq [Fintype α] (a : α) [Fintype { x : α | x ≠ a }] : Fintype.card { x : α | x ≠ a } = Fintype.card α - 1 := by haveI := Classical.decEq α rw [← toFinset_card, toFinset_setOf, Finset.filter_ne', Finset.card_erase_of_mem (Finset.mem_univ _), Finset.card_univ] #align set.card_ne_eq Set.card_ne_eq /-! ### Infinite sets -/ variable {s t : Set α} theorem infinite_univ_iff : (@univ α).Infinite ↔ Infinite α := by rw [Set.Infinite, finite_univ_iff, not_finite_iff_infinite] #align set.infinite_univ_iff Set.infinite_univ_iff theorem infinite_univ [h : Infinite α] : (@univ α).Infinite := infinite_univ_iff.2 h #align set.infinite_univ Set.infinite_univ theorem infinite_coe_iff {s : Set α} : Infinite s ↔ s.Infinite := not_finite_iff_infinite.symm.trans finite_coe_iff.not #align set.infinite_coe_iff Set.infinite_coe_iff -- Porting note: something weird happened here alias ⟨_, Infinite.to_subtype⟩ := infinite_coe_iff #align set.infinite.to_subtype Set.Infinite.to_subtype lemma Infinite.exists_not_mem_finite (hs : s.Infinite) (ht : t.Finite) : ∃ a, a ∈ s ∧ a ∉ t := by by_contra! h; exact hs <| ht.subset h lemma Infinite.exists_not_mem_finset (hs : s.Infinite) (t : Finset α) : ∃ a ∈ s, a ∉ t := hs.exists_not_mem_finite t.finite_toSet #align set.infinite.exists_not_mem_finset Set.Infinite.exists_not_mem_finset section Infinite variable [Infinite α] lemma Finite.exists_not_mem (hs : s.Finite) : ∃ a, a ∉ s := by by_contra! h; exact infinite_univ (hs.subset fun a _ ↦ h _) lemma _root_.Finset.exists_not_mem (s : Finset α) : ∃ a, a ∉ s := s.finite_toSet.exists_not_mem end Infinite /-- Embedding of `ℕ` into an infinite set. -/ noncomputable def Infinite.natEmbedding (s : Set α) (h : s.Infinite) : ℕ ↪ s := h.to_subtype.natEmbedding #align set.infinite.nat_embedding Set.Infinite.natEmbedding theorem Infinite.exists_subset_card_eq {s : Set α} (hs : s.Infinite) (n : ℕ) : ∃ t : Finset α, ↑t ⊆ s ∧ t.card = n := ⟨((Finset.range n).map (hs.natEmbedding _)).map (Embedding.subtype _), by simp⟩ #align set.infinite.exists_subset_card_eq Set.Infinite.exists_subset_card_eq theorem infinite_of_finite_compl [Infinite α] {s : Set α} (hs : sᶜ.Finite) : s.Infinite := fun h => Set.infinite_univ (by simpa using hs.union h) #align set.infinite_of_finite_compl Set.infinite_of_finite_compl theorem Finite.infinite_compl [Infinite α] {s : Set α} (hs : s.Finite) : sᶜ.Infinite := fun h => Set.infinite_univ (by simpa using hs.union h) #align set.finite.infinite_compl Set.Finite.infinite_compl theorem Infinite.diff {s t : Set α} (hs : s.Infinite) (ht : t.Finite) : (s \ t).Infinite := fun h => hs <| h.of_diff ht #align set.infinite.diff Set.Infinite.diff @[simp] theorem infinite_union {s t : Set α} : (s ∪ t).Infinite ↔ s.Infinite ∨ t.Infinite := by simp only [Set.Infinite, finite_union, not_and_or] #align set.infinite_union Set.infinite_union theorem Infinite.of_image (f : α → β) {s : Set α} (hs : (f '' s).Infinite) : s.Infinite := mt (Finite.image f) hs #align set.infinite.of_image Set.Infinite.of_image theorem infinite_image_iff {s : Set α} {f : α → β} (hi : InjOn f s) : (f '' s).Infinite ↔ s.Infinite := not_congr <| finite_image_iff hi #align set.infinite_image_iff Set.infinite_image_iff theorem infinite_range_iff {f : α → β} (hi : Injective f) : (range f).Infinite ↔ Infinite α := by rw [← image_univ, infinite_image_iff hi.injOn, infinite_univ_iff] alias ⟨_, Infinite.image⟩ := infinite_image_iff #align set.infinite.image Set.Infinite.image -- Porting note: attribute [protected] doesn't work -- attribute [protected] infinite.image section Image2 variable {f : α → β → γ} {s : Set α} {t : Set β} {a : α} {b : β} protected theorem Infinite.image2_left (hs : s.Infinite) (hb : b ∈ t) (hf : InjOn (fun a => f a b) s) : (image2 f s t).Infinite := (hs.image hf).mono <| image_subset_image2_left hb #align set.infinite.image2_left Set.Infinite.image2_left protected theorem Infinite.image2_right (ht : t.Infinite) (ha : a ∈ s) (hf : InjOn (f a) t) : (image2 f s t).Infinite := (ht.image hf).mono <| image_subset_image2_right ha #align set.infinite.image2_right Set.Infinite.image2_right
Mathlib/Data/Set/Finite.lean
1,420
1,427
theorem infinite_image2 (hfs : ∀ b ∈ t, InjOn (fun a => f a b) s) (hft : ∀ a ∈ s, InjOn (f a) t) : (image2 f s t).Infinite ↔ s.Infinite ∧ t.Nonempty ∨ t.Infinite ∧ s.Nonempty := by
refine ⟨fun h => Set.infinite_prod.1 ?_, ?_⟩ · rw [← image_uncurry_prod] at h exact h.of_image _ · rintro (⟨hs, b, hb⟩ | ⟨ht, a, ha⟩) · exact hs.image2_left hb (hfs _ hb) · exact ht.image2_right ha (hft _ ha)
/- Copyright (c) 2022 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Order.Filter.Cofinite #align_import topology.bornology.basic from "leanprover-community/mathlib"@"8631e2d5ea77f6c13054d9151d82b83069680cb1" /-! # Basic theory of bornology We develop the basic theory of bornologies. Instead of axiomatizing bounded sets and defining bornologies in terms of those, we recognize that the cobounded sets form a filter and define a bornology as a filter of cobounded sets which contains the cofinite filter. This allows us to make use of the extensive library for filters, but we also provide the relevant connecting results for bounded sets. The specification of a bornology in terms of the cobounded filter is equivalent to the standard one (e.g., see [Bourbaki, *Topological Vector Spaces*][bourbaki1987], **covering bornology**, now often called simply **bornology**) in terms of bounded sets (see `Bornology.ofBounded`, `IsBounded.union`, `IsBounded.subset`), except that we do not allow the empty bornology (that is, we require that *some* set must be bounded; equivalently, `∅` is bounded). In the literature the cobounded filter is generally referred to as the *filter at infinity*. ## Main definitions - `Bornology α`: a class consisting of `cobounded : Filter α` and a proof that this filter contains the `cofinite` filter. - `Bornology.IsCobounded`: the predicate that a set is a member of the `cobounded α` filter. For `s : Set α`, one should prefer `Bornology.IsCobounded s` over `s ∈ cobounded α`. - `bornology.IsBounded`: the predicate that states a set is bounded (i.e., the complement of a cobounded set). One should prefer `Bornology.IsBounded s` over `sᶜ ∈ cobounded α`. - `BoundedSpace α`: a class extending `Bornology α` with the condition `Bornology.IsBounded (Set.univ : Set α)` Although use of `cobounded α` is discouraged for indicating the (co)boundedness of individual sets, it is intended for regular use as a filter on `α`. -/ open Set Filter variable {ι α β : Type*} /-- A **bornology** on a type `α` is a filter of cobounded sets which contains the cofinite filter. Such spaces are equivalently specified by their bounded sets, see `Bornology.ofBounded` and `Bornology.ext_iff_isBounded`-/ class Bornology (α : Type*) where /-- The filter of cobounded sets in a bornology. This is a field of the structure, but one should always prefer `Bornology.cobounded` because it makes the `α` argument explicit. -/ cobounded' : Filter α /-- The cobounded filter in a bornology is smaller than the cofinite filter. This is a field of the structure, but one should always prefer `Bornology.le_cofinite` because it makes the `α` argument explicit. -/ le_cofinite' : cobounded' ≤ cofinite #align bornology Bornology /- porting note: Because Lean 4 doesn't accept the `[]` syntax to make arguments of structure fields explicit, we have to define these separately, prove the `ext` lemmas manually, and initialize new `simps` projections. -/ /-- The filter of cobounded sets in a bornology. -/ def Bornology.cobounded (α : Type*) [Bornology α] : Filter α := Bornology.cobounded' #align bornology.cobounded Bornology.cobounded alias Bornology.Simps.cobounded := Bornology.cobounded lemma Bornology.le_cofinite (α : Type*) [Bornology α] : cobounded α ≤ cofinite := Bornology.le_cofinite' #align bornology.le_cofinite Bornology.le_cofinite initialize_simps_projections Bornology (cobounded' → cobounded) @[ext] lemma Bornology.ext (t t' : Bornology α) (h_cobounded : @Bornology.cobounded α t = @Bornology.cobounded α t') : t = t' := by cases t cases t' congr #align bornology.ext Bornology.ext lemma Bornology.ext_iff (t t' : Bornology α) : t = t' ↔ @Bornology.cobounded α t = @Bornology.cobounded α t' := ⟨congrArg _, Bornology.ext _ _⟩ #align bornology.ext_iff Bornology.ext_iff /-- A constructor for bornologies by specifying the bounded sets, and showing that they satisfy the appropriate conditions. -/ @[simps] def Bornology.ofBounded {α : Type*} (B : Set (Set α)) (empty_mem : ∅ ∈ B) (subset_mem : ∀ s₁ ∈ B, ∀ s₂ ⊆ s₁, s₂ ∈ B) (union_mem : ∀ s₁ ∈ B, ∀ s₂ ∈ B, s₁ ∪ s₂ ∈ B) (singleton_mem : ∀ x, {x} ∈ B) : Bornology α where cobounded' := comk (· ∈ B) empty_mem subset_mem union_mem le_cofinite' := by simpa [le_cofinite_iff_compl_singleton_mem] #align bornology.of_bounded Bornology.ofBounded #align bornology.of_bounded_cobounded_sets Bornology.ofBounded_cobounded /-- A constructor for bornologies by specifying the bounded sets, and showing that they satisfy the appropriate conditions. -/ @[simps! cobounded] def Bornology.ofBounded' {α : Type*} (B : Set (Set α)) (empty_mem : ∅ ∈ B) (subset_mem : ∀ s₁ ∈ B, ∀ s₂ ⊆ s₁, s₂ ∈ B) (union_mem : ∀ s₁ ∈ B, ∀ s₂ ∈ B, s₁ ∪ s₂ ∈ B) (sUnion_univ : ⋃₀ B = univ) : Bornology α := Bornology.ofBounded B empty_mem subset_mem union_mem fun x => by rw [sUnion_eq_univ_iff] at sUnion_univ rcases sUnion_univ x with ⟨s, hs, hxs⟩ exact subset_mem s hs {x} (singleton_subset_iff.mpr hxs) #align bornology.of_bounded' Bornology.ofBounded' #align bornology.of_bounded'_cobounded_sets Bornology.ofBounded'_cobounded namespace Bornology section /-- `IsCobounded` is the predicate that `s` is in the filter of cobounded sets in the ambient bornology on `α` -/ def IsCobounded [Bornology α] (s : Set α) : Prop := s ∈ cobounded α #align bornology.is_cobounded Bornology.IsCobounded /-- `IsBounded` is the predicate that `s` is bounded relative to the ambient bornology on `α`. -/ def IsBounded [Bornology α] (s : Set α) : Prop := IsCobounded sᶜ #align bornology.is_bounded Bornology.IsBounded variable {_ : Bornology α} {s t : Set α} {x : α} theorem isCobounded_def {s : Set α} : IsCobounded s ↔ s ∈ cobounded α := Iff.rfl #align bornology.is_cobounded_def Bornology.isCobounded_def theorem isBounded_def {s : Set α} : IsBounded s ↔ sᶜ ∈ cobounded α := Iff.rfl #align bornology.is_bounded_def Bornology.isBounded_def @[simp] theorem isBounded_compl_iff : IsBounded sᶜ ↔ IsCobounded s := by rw [isBounded_def, isCobounded_def, compl_compl] #align bornology.is_bounded_compl_iff Bornology.isBounded_compl_iff @[simp] theorem isCobounded_compl_iff : IsCobounded sᶜ ↔ IsBounded s := Iff.rfl #align bornology.is_cobounded_compl_iff Bornology.isCobounded_compl_iff alias ⟨IsBounded.of_compl, IsCobounded.compl⟩ := isBounded_compl_iff #align bornology.is_bounded.of_compl Bornology.IsBounded.of_compl #align bornology.is_cobounded.compl Bornology.IsCobounded.compl alias ⟨IsCobounded.of_compl, IsBounded.compl⟩ := isCobounded_compl_iff #align bornology.is_cobounded.of_compl Bornology.IsCobounded.of_compl #align bornology.is_bounded.compl Bornology.IsBounded.compl @[simp] theorem isBounded_empty : IsBounded (∅ : Set α) := by rw [isBounded_def, compl_empty] exact univ_mem #align bornology.is_bounded_empty Bornology.isBounded_empty theorem nonempty_of_not_isBounded (h : ¬IsBounded s) : s.Nonempty := by rw [nonempty_iff_ne_empty] rintro rfl exact h isBounded_empty #align metric.nonempty_of_unbounded Bornology.nonempty_of_not_isBounded @[simp] theorem isBounded_singleton : IsBounded ({x} : Set α) := by rw [isBounded_def] exact le_cofinite _ (finite_singleton x).compl_mem_cofinite #align bornology.is_bounded_singleton Bornology.isBounded_singleton theorem isBounded_iff_forall_mem : IsBounded s ↔ ∀ x ∈ s, IsBounded s := ⟨fun h _ _ ↦ h, fun h ↦ by rcases s.eq_empty_or_nonempty with rfl | ⟨x, hx⟩ exacts [isBounded_empty, h x hx]⟩ @[simp] theorem isCobounded_univ : IsCobounded (univ : Set α) := univ_mem #align bornology.is_cobounded_univ Bornology.isCobounded_univ @[simp] theorem isCobounded_inter : IsCobounded (s ∩ t) ↔ IsCobounded s ∧ IsCobounded t := inter_mem_iff #align bornology.is_cobounded_inter Bornology.isCobounded_inter theorem IsCobounded.inter (hs : IsCobounded s) (ht : IsCobounded t) : IsCobounded (s ∩ t) := isCobounded_inter.2 ⟨hs, ht⟩ #align bornology.is_cobounded.inter Bornology.IsCobounded.inter @[simp] theorem isBounded_union : IsBounded (s ∪ t) ↔ IsBounded s ∧ IsBounded t := by simp only [← isCobounded_compl_iff, compl_union, isCobounded_inter] #align bornology.is_bounded_union Bornology.isBounded_union theorem IsBounded.union (hs : IsBounded s) (ht : IsBounded t) : IsBounded (s ∪ t) := isBounded_union.2 ⟨hs, ht⟩ #align bornology.is_bounded.union Bornology.IsBounded.union theorem IsCobounded.superset (hs : IsCobounded s) (ht : s ⊆ t) : IsCobounded t := mem_of_superset hs ht #align bornology.is_cobounded.superset Bornology.IsCobounded.superset theorem IsBounded.subset (ht : IsBounded t) (hs : s ⊆ t) : IsBounded s := ht.superset (compl_subset_compl.mpr hs) #align bornology.is_bounded.subset Bornology.IsBounded.subset @[simp] theorem sUnion_bounded_univ : ⋃₀ { s : Set α | IsBounded s } = univ := sUnion_eq_univ_iff.2 fun a => ⟨{a}, isBounded_singleton, mem_singleton a⟩ #align bornology.sUnion_bounded_univ Bornology.sUnion_bounded_univ theorem IsBounded.insert (h : IsBounded s) (x : α) : IsBounded (insert x s) := isBounded_singleton.union h @[simp] theorem isBounded_insert : IsBounded (insert x s) ↔ IsBounded s := ⟨fun h ↦ h.subset (subset_insert _ _), (.insert · x)⟩ theorem comap_cobounded_le_iff [Bornology β] {f : α → β} : (cobounded β).comap f ≤ cobounded α ↔ ∀ ⦃s⦄, IsBounded s → IsBounded (f '' s) := by refine ⟨fun h s hs => ?_, fun h t ht => ⟨(f '' tᶜ)ᶜ, h <| IsCobounded.compl ht, compl_subset_comm.1 <| subset_preimage_image _ _⟩⟩ obtain ⟨t, ht, hts⟩ := h hs.compl rw [subset_compl_comm, ← preimage_compl] at hts exact (IsCobounded.compl ht).subset ((image_subset f hts).trans <| image_preimage_subset _ _) #align bornology.comap_cobounded_le_iff Bornology.comap_cobounded_le_iff end theorem ext_iff' {t t' : Bornology α} : t = t' ↔ ∀ s, s ∈ @cobounded α t ↔ s ∈ @cobounded α t' := (Bornology.ext_iff _ _).trans Filter.ext_iff #align bornology.ext_iff' Bornology.ext_iff' theorem ext_iff_isBounded {t t' : Bornology α} : t = t' ↔ ∀ s, @IsBounded α t s ↔ @IsBounded α t' s := ext_iff'.trans compl_surjective.forall #align bornology.ext_iff_is_bounded Bornology.ext_iff_isBounded variable {s : Set α} theorem isCobounded_ofBounded_iff (B : Set (Set α)) {empty_mem subset_mem union_mem sUnion_univ} : @IsCobounded _ (ofBounded B empty_mem subset_mem union_mem sUnion_univ) s ↔ sᶜ ∈ B := Iff.rfl #align bornology.is_cobounded_of_bounded_iff Bornology.isCobounded_ofBounded_iff theorem isBounded_ofBounded_iff (B : Set (Set α)) {empty_mem subset_mem union_mem sUnion_univ} : @IsBounded _ (ofBounded B empty_mem subset_mem union_mem sUnion_univ) s ↔ s ∈ B := by rw [isBounded_def, ofBounded_cobounded, compl_mem_comk] #align bornology.is_bounded_of_bounded_iff Bornology.isBounded_ofBounded_iff variable [Bornology α] theorem isCobounded_biInter {s : Set ι} {f : ι → Set α} (hs : s.Finite) : IsCobounded (⋂ i ∈ s, f i) ↔ ∀ i ∈ s, IsCobounded (f i) := biInter_mem hs #align bornology.is_cobounded_bInter Bornology.isCobounded_biInter @[simp] theorem isCobounded_biInter_finset (s : Finset ι) {f : ι → Set α} : IsCobounded (⋂ i ∈ s, f i) ↔ ∀ i ∈ s, IsCobounded (f i) := biInter_finset_mem s #align bornology.is_cobounded_bInter_finset Bornology.isCobounded_biInter_finset @[simp] theorem isCobounded_iInter [Finite ι] {f : ι → Set α} : IsCobounded (⋂ i, f i) ↔ ∀ i, IsCobounded (f i) := iInter_mem #align bornology.is_cobounded_Inter Bornology.isCobounded_iInter theorem isCobounded_sInter {S : Set (Set α)} (hs : S.Finite) : IsCobounded (⋂₀ S) ↔ ∀ s ∈ S, IsCobounded s := sInter_mem hs #align bornology.is_cobounded_sInter Bornology.isCobounded_sInter
Mathlib/Topology/Bornology/Basic.lean
284
286
theorem isBounded_biUnion {s : Set ι} {f : ι → Set α} (hs : s.Finite) : IsBounded (⋃ i ∈ s, f i) ↔ ∀ i ∈ s, IsBounded (f i) := by
simp only [← isCobounded_compl_iff, compl_iUnion, isCobounded_biInter hs]
/- 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, Kexing Ying -/ import Mathlib.Probability.Notation import Mathlib.Probability.Integration import Mathlib.MeasureTheory.Function.L2Space #align_import probability.variance from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9" /-! # Variance of random variables We define the variance of a real-valued random variable as `Var[X] = 𝔼[(X - 𝔼[X])^2]` (in the `ProbabilityTheory` locale). ## Main definitions * `ProbabilityTheory.evariance`: the variance of a real-valued random variable as an extended non-negative real. * `ProbabilityTheory.variance`: the variance of a real-valued random variable as a real number. ## Main results * `ProbabilityTheory.variance_le_expectation_sq`: the inequality `Var[X] ≤ 𝔼[X^2]`. * `ProbabilityTheory.meas_ge_le_variance_div_sq`: Chebyshev's inequality, i.e., `ℙ {ω | c ≤ |X ω - 𝔼[X]|} ≤ ENNReal.ofReal (Var[X] / c ^ 2)`. * `ProbabilityTheory.meas_ge_le_evariance_div_sq`: Chebyshev's inequality formulated with `evariance` without requiring the random variables to be L². * `ProbabilityTheory.IndepFun.variance_add`: the variance of the sum of two independent random variables is the sum of the variances. * `ProbabilityTheory.IndepFun.variance_sum`: the variance of a finite sum of pairwise independent random variables is the sum of the variances. -/ open MeasureTheory Filter Finset noncomputable section open scoped MeasureTheory ProbabilityTheory ENNReal NNReal namespace ProbabilityTheory -- Porting note: this lemma replaces `ENNReal.toReal_bit0`, which does not exist in Lean 4 private lemma coe_two : ENNReal.toReal 2 = (2 : ℝ) := rfl -- Porting note: Consider if `evariance` or `eVariance` is better. Also, -- consider `eVariationOn` in `Mathlib.Analysis.BoundedVariation`. /-- The `ℝ≥0∞`-valued variance of a real-valued random variable defined as the Lebesgue integral of `(X - 𝔼[X])^2`. -/ def evariance {Ω : Type*} {_ : MeasurableSpace Ω} (X : Ω → ℝ) (μ : Measure Ω) : ℝ≥0∞ := ∫⁻ ω, (‖X ω - μ[X]‖₊ : ℝ≥0∞) ^ 2 ∂μ #align probability_theory.evariance ProbabilityTheory.evariance /-- The `ℝ`-valued variance of a real-valued random variable defined by applying `ENNReal.toReal` to `evariance`. -/ def variance {Ω : Type*} {_ : MeasurableSpace Ω} (X : Ω → ℝ) (μ : Measure Ω) : ℝ := (evariance X μ).toReal #align probability_theory.variance ProbabilityTheory.variance variable {Ω : Type*} {m : MeasurableSpace Ω} {X : Ω → ℝ} {μ : Measure Ω} theorem _root_.MeasureTheory.Memℒp.evariance_lt_top [IsFiniteMeasure μ] (hX : Memℒp X 2 μ) : evariance X μ < ∞ := by have := ENNReal.pow_lt_top (hX.sub <| memℒp_const <| μ[X]).2 2 rw [snorm_eq_lintegral_rpow_nnnorm two_ne_zero ENNReal.two_ne_top, ← ENNReal.rpow_two] at this simp only [coe_two, Pi.sub_apply, ENNReal.one_toReal, one_div] at this rw [← ENNReal.rpow_mul, inv_mul_cancel (two_ne_zero : (2 : ℝ) ≠ 0), ENNReal.rpow_one] at this simp_rw [ENNReal.rpow_two] at this exact this #align measure_theory.mem_ℒp.evariance_lt_top MeasureTheory.Memℒp.evariance_lt_top theorem evariance_eq_top [IsFiniteMeasure μ] (hXm : AEStronglyMeasurable X μ) (hX : ¬Memℒp X 2 μ) : evariance X μ = ∞ := by by_contra h rw [← Ne, ← lt_top_iff_ne_top] at h have : Memℒp (fun ω => X ω - μ[X]) 2 μ := by refine ⟨hXm.sub aestronglyMeasurable_const, ?_⟩ rw [snorm_eq_lintegral_rpow_nnnorm two_ne_zero ENNReal.two_ne_top] simp only [coe_two, ENNReal.one_toReal, ENNReal.rpow_two, Ne] exact ENNReal.rpow_lt_top_of_nonneg (by linarith) h.ne refine hX ?_ -- Porting note: `μ[X]` without whitespace is ambiguous as it could be GetElem, -- and `convert` cannot disambiguate based on typeclass inference failure. convert this.add (memℒp_const <| μ [X]) ext ω rw [Pi.add_apply, sub_add_cancel] #align probability_theory.evariance_eq_top ProbabilityTheory.evariance_eq_top theorem evariance_lt_top_iff_memℒp [IsFiniteMeasure μ] (hX : AEStronglyMeasurable X μ) : evariance X μ < ∞ ↔ Memℒp X 2 μ := by refine ⟨?_, MeasureTheory.Memℒp.evariance_lt_top⟩ contrapose rw [not_lt, top_le_iff] exact evariance_eq_top hX #align probability_theory.evariance_lt_top_iff_mem_ℒp ProbabilityTheory.evariance_lt_top_iff_memℒp theorem _root_.MeasureTheory.Memℒp.ofReal_variance_eq [IsFiniteMeasure μ] (hX : Memℒp X 2 μ) : ENNReal.ofReal (variance X μ) = evariance X μ := by rw [variance, ENNReal.ofReal_toReal] exact hX.evariance_lt_top.ne #align measure_theory.mem_ℒp.of_real_variance_eq MeasureTheory.Memℒp.ofReal_variance_eq theorem evariance_eq_lintegral_ofReal (X : Ω → ℝ) (μ : Measure Ω) : evariance X μ = ∫⁻ ω, ENNReal.ofReal ((X ω - μ[X]) ^ 2) ∂μ := by rw [evariance] congr ext1 ω rw [pow_two, ← ENNReal.coe_mul, ← nnnorm_mul, ← pow_two] congr exact (Real.toNNReal_eq_nnnorm_of_nonneg <| sq_nonneg _).symm #align probability_theory.evariance_eq_lintegral_of_real ProbabilityTheory.evariance_eq_lintegral_ofReal theorem _root_.MeasureTheory.Memℒp.variance_eq_of_integral_eq_zero (hX : Memℒp X 2 μ) (hXint : μ[X] = 0) : variance X μ = μ[X ^ (2 : Nat)] := by rw [variance, evariance_eq_lintegral_ofReal, ← ofReal_integral_eq_lintegral_ofReal, ENNReal.toReal_ofReal (by positivity)] <;> simp_rw [hXint, sub_zero] · rfl · convert hX.integrable_norm_rpow two_ne_zero ENNReal.two_ne_top with ω simp only [Pi.sub_apply, Real.norm_eq_abs, coe_two, ENNReal.one_toReal, Real.rpow_two, sq_abs, abs_pow] · exact ae_of_all _ fun ω => pow_two_nonneg _ #align measure_theory.mem_ℒp.variance_eq_of_integral_eq_zero MeasureTheory.Memℒp.variance_eq_of_integral_eq_zero theorem _root_.MeasureTheory.Memℒp.variance_eq [IsFiniteMeasure μ] (hX : Memℒp X 2 μ) : variance X μ = μ[(X - fun _ => μ[X] :) ^ (2 : Nat)] := by rw [variance, evariance_eq_lintegral_ofReal, ← ofReal_integral_eq_lintegral_ofReal, ENNReal.toReal_ofReal (by positivity)] · rfl · -- Porting note: `μ[X]` without whitespace is ambiguous as it could be GetElem, -- and `convert` cannot disambiguate based on typeclass inference failure. convert (hX.sub <| memℒp_const (μ [X])).integrable_norm_rpow two_ne_zero ENNReal.two_ne_top with ω simp only [Pi.sub_apply, Real.norm_eq_abs, coe_two, ENNReal.one_toReal, Real.rpow_two, sq_abs, abs_pow] · exact ae_of_all _ fun ω => pow_two_nonneg _ #align measure_theory.mem_ℒp.variance_eq MeasureTheory.Memℒp.variance_eq @[simp] theorem evariance_zero : evariance 0 μ = 0 := by simp [evariance] #align probability_theory.evariance_zero ProbabilityTheory.evariance_zero theorem evariance_eq_zero_iff (hX : AEMeasurable X μ) : evariance X μ = 0 ↔ X =ᵐ[μ] fun _ => μ[X] := by rw [evariance, lintegral_eq_zero_iff'] constructor <;> intro hX <;> filter_upwards [hX] with ω hω · simpa only [Pi.zero_apply, sq_eq_zero_iff, ENNReal.coe_eq_zero, nnnorm_eq_zero, sub_eq_zero] using hω · rw [hω] simp · exact (hX.sub_const _).ennnorm.pow_const _ -- TODO `measurability` and `fun_prop` fail #align probability_theory.evariance_eq_zero_iff ProbabilityTheory.evariance_eq_zero_iff
Mathlib/Probability/Variance.lean
157
169
theorem evariance_mul (c : ℝ) (X : Ω → ℝ) (μ : Measure Ω) : evariance (fun ω => c * X ω) μ = ENNReal.ofReal (c ^ 2) * evariance X μ := by
rw [evariance, evariance, ← lintegral_const_mul' _ _ ENNReal.ofReal_lt_top.ne] congr ext1 ω rw [ENNReal.ofReal, ← ENNReal.coe_pow, ← ENNReal.coe_pow, ← ENNReal.coe_mul] congr rw [← sq_abs, ← Real.rpow_two, Real.toNNReal_rpow_of_nonneg (abs_nonneg _), NNReal.rpow_two, ← mul_pow, Real.toNNReal_mul_nnnorm _ (abs_nonneg _)] conv_rhs => rw [← nnnorm_norm, norm_mul, norm_abs_eq_norm, ← norm_mul, nnnorm_norm, mul_sub] congr rw [mul_comm] simp_rw [← smul_eq_mul, ← integral_smul_const, smul_eq_mul, mul_comm]
/- Copyright (c) 2019 Abhimanyu Pallavi Sudhir. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Abhimanyu Pallavi Sudhir -/ import Mathlib.Order.Filter.FilterProduct import Mathlib.Analysis.SpecificLimits.Basic #align_import data.real.hyperreal from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Construction of the hyperreal numbers as an ultraproduct of real sequences. -/ open scoped Classical open Filter Germ Topology /-- Hyperreal numbers on the ultrafilter extending the cofinite filter -/ def Hyperreal : Type := Germ (hyperfilter ℕ : Filter ℕ) ℝ deriving Inhabited #align hyperreal Hyperreal namespace Hyperreal @[inherit_doc] notation "ℝ*" => Hyperreal noncomputable instance : LinearOrderedField ℝ* := inferInstanceAs (LinearOrderedField (Germ _ _)) /-- Natural embedding `ℝ → ℝ*`. -/ @[coe] def ofReal : ℝ → ℝ* := const noncomputable instance : CoeTC ℝ ℝ* := ⟨ofReal⟩ @[simp, norm_cast] theorem coe_eq_coe {x y : ℝ} : (x : ℝ*) = y ↔ x = y := Germ.const_inj #align hyperreal.coe_eq_coe Hyperreal.coe_eq_coe theorem coe_ne_coe {x y : ℝ} : (x : ℝ*) ≠ y ↔ x ≠ y := coe_eq_coe.not #align hyperreal.coe_ne_coe Hyperreal.coe_ne_coe @[simp, norm_cast] theorem coe_eq_zero {x : ℝ} : (x : ℝ*) = 0 ↔ x = 0 := coe_eq_coe #align hyperreal.coe_eq_zero Hyperreal.coe_eq_zero @[simp, norm_cast] theorem coe_eq_one {x : ℝ} : (x : ℝ*) = 1 ↔ x = 1 := coe_eq_coe #align hyperreal.coe_eq_one Hyperreal.coe_eq_one @[norm_cast] theorem coe_ne_zero {x : ℝ} : (x : ℝ*) ≠ 0 ↔ x ≠ 0 := coe_ne_coe #align hyperreal.coe_ne_zero Hyperreal.coe_ne_zero @[norm_cast] theorem coe_ne_one {x : ℝ} : (x : ℝ*) ≠ 1 ↔ x ≠ 1 := coe_ne_coe #align hyperreal.coe_ne_one Hyperreal.coe_ne_one @[simp, norm_cast] theorem coe_one : ↑(1 : ℝ) = (1 : ℝ*) := rfl #align hyperreal.coe_one Hyperreal.coe_one @[simp, norm_cast] theorem coe_zero : ↑(0 : ℝ) = (0 : ℝ*) := rfl #align hyperreal.coe_zero Hyperreal.coe_zero @[simp, norm_cast] theorem coe_inv (x : ℝ) : ↑x⁻¹ = (x⁻¹ : ℝ*) := rfl #align hyperreal.coe_inv Hyperreal.coe_inv @[simp, norm_cast] theorem coe_neg (x : ℝ) : ↑(-x) = (-x : ℝ*) := rfl #align hyperreal.coe_neg Hyperreal.coe_neg @[simp, norm_cast] theorem coe_add (x y : ℝ) : ↑(x + y) = (x + y : ℝ*) := rfl #align hyperreal.coe_add Hyperreal.coe_add #noalign hyperreal.coe_bit0 #noalign hyperreal.coe_bit1 -- See note [no_index around OfNat.ofNat] @[simp, norm_cast] theorem coe_ofNat (n : ℕ) [n.AtLeastTwo] : ((no_index (OfNat.ofNat n : ℝ)) : ℝ*) = OfNat.ofNat n := rfl @[simp, norm_cast] theorem coe_mul (x y : ℝ) : ↑(x * y) = (x * y : ℝ*) := rfl #align hyperreal.coe_mul Hyperreal.coe_mul @[simp, norm_cast] theorem coe_div (x y : ℝ) : ↑(x / y) = (x / y : ℝ*) := rfl #align hyperreal.coe_div Hyperreal.coe_div @[simp, norm_cast] theorem coe_sub (x y : ℝ) : ↑(x - y) = (x - y : ℝ*) := rfl #align hyperreal.coe_sub Hyperreal.coe_sub @[simp, norm_cast] theorem coe_le_coe {x y : ℝ} : (x : ℝ*) ≤ y ↔ x ≤ y := Germ.const_le_iff #align hyperreal.coe_le_coe Hyperreal.coe_le_coe @[simp, norm_cast] theorem coe_lt_coe {x y : ℝ} : (x : ℝ*) < y ↔ x < y := Germ.const_lt_iff #align hyperreal.coe_lt_coe Hyperreal.coe_lt_coe @[simp, norm_cast] theorem coe_nonneg {x : ℝ} : 0 ≤ (x : ℝ*) ↔ 0 ≤ x := coe_le_coe #align hyperreal.coe_nonneg Hyperreal.coe_nonneg @[simp, norm_cast] theorem coe_pos {x : ℝ} : 0 < (x : ℝ*) ↔ 0 < x := coe_lt_coe #align hyperreal.coe_pos Hyperreal.coe_pos @[simp, norm_cast] theorem coe_abs (x : ℝ) : ((|x| : ℝ) : ℝ*) = |↑x| := const_abs x #align hyperreal.coe_abs Hyperreal.coe_abs @[simp, norm_cast] theorem coe_max (x y : ℝ) : ((max x y : ℝ) : ℝ*) = max ↑x ↑y := Germ.const_max _ _ #align hyperreal.coe_max Hyperreal.coe_max @[simp, norm_cast] theorem coe_min (x y : ℝ) : ((min x y : ℝ) : ℝ*) = min ↑x ↑y := Germ.const_min _ _ #align hyperreal.coe_min Hyperreal.coe_min /-- Construct a hyperreal number from a sequence of real numbers. -/ def ofSeq (f : ℕ → ℝ) : ℝ* := (↑f : Germ (hyperfilter ℕ : Filter ℕ) ℝ) #align hyperreal.of_seq Hyperreal.ofSeq -- Porting note (#10756): new lemma theorem ofSeq_surjective : Function.Surjective ofSeq := Quot.exists_rep theorem ofSeq_lt_ofSeq {f g : ℕ → ℝ} : ofSeq f < ofSeq g ↔ ∀ᶠ n in hyperfilter ℕ, f n < g n := Germ.coe_lt /-- A sample infinitesimal hyperreal-/ noncomputable def epsilon : ℝ* := ofSeq fun n => n⁻¹ #align hyperreal.epsilon Hyperreal.epsilon /-- A sample infinite hyperreal-/ noncomputable def omega : ℝ* := ofSeq Nat.cast #align hyperreal.omega Hyperreal.omega @[inherit_doc] scoped notation "ε" => Hyperreal.epsilon @[inherit_doc] scoped notation "ω" => Hyperreal.omega @[simp] theorem inv_omega : ω⁻¹ = ε := rfl #align hyperreal.inv_omega Hyperreal.inv_omega @[simp] theorem inv_epsilon : ε⁻¹ = ω := @inv_inv _ _ ω #align hyperreal.inv_epsilon Hyperreal.inv_epsilon theorem omega_pos : 0 < ω := Germ.coe_pos.2 <| Nat.hyperfilter_le_atTop <| (eventually_gt_atTop 0).mono fun _ ↦ Nat.cast_pos.2 #align hyperreal.omega_pos Hyperreal.omega_pos theorem epsilon_pos : 0 < ε := inv_pos_of_pos omega_pos #align hyperreal.epsilon_pos Hyperreal.epsilon_pos theorem epsilon_ne_zero : ε ≠ 0 := epsilon_pos.ne' #align hyperreal.epsilon_ne_zero Hyperreal.epsilon_ne_zero theorem omega_ne_zero : ω ≠ 0 := omega_pos.ne' #align hyperreal.omega_ne_zero Hyperreal.omega_ne_zero theorem epsilon_mul_omega : ε * ω = 1 := @inv_mul_cancel _ _ ω omega_ne_zero #align hyperreal.epsilon_mul_omega Hyperreal.epsilon_mul_omega theorem lt_of_tendsto_zero_of_pos {f : ℕ → ℝ} (hf : Tendsto f atTop (𝓝 0)) : ∀ {r : ℝ}, 0 < r → ofSeq f < (r : ℝ*) := fun hr ↦ ofSeq_lt_ofSeq.2 <| (hf.eventually <| gt_mem_nhds hr).filter_mono Nat.hyperfilter_le_atTop #align hyperreal.lt_of_tendsto_zero_of_pos Hyperreal.lt_of_tendsto_zero_of_pos theorem neg_lt_of_tendsto_zero_of_pos {f : ℕ → ℝ} (hf : Tendsto f atTop (𝓝 0)) : ∀ {r : ℝ}, 0 < r → (-r : ℝ*) < ofSeq f := fun hr => have hg := hf.neg neg_lt_of_neg_lt (by rw [neg_zero] at hg; exact lt_of_tendsto_zero_of_pos hg hr) #align hyperreal.neg_lt_of_tendsto_zero_of_pos Hyperreal.neg_lt_of_tendsto_zero_of_pos theorem gt_of_tendsto_zero_of_neg {f : ℕ → ℝ} (hf : Tendsto f atTop (𝓝 0)) : ∀ {r : ℝ}, r < 0 → (r : ℝ*) < ofSeq f := fun {r} hr => by rw [← neg_neg r, coe_neg]; exact neg_lt_of_tendsto_zero_of_pos hf (neg_pos.mpr hr) #align hyperreal.gt_of_tendsto_zero_of_neg Hyperreal.gt_of_tendsto_zero_of_neg theorem epsilon_lt_pos (x : ℝ) : 0 < x → ε < x := lt_of_tendsto_zero_of_pos tendsto_inverse_atTop_nhds_zero_nat #align hyperreal.epsilon_lt_pos Hyperreal.epsilon_lt_pos /-- Standard part predicate -/ def IsSt (x : ℝ*) (r : ℝ) := ∀ δ : ℝ, 0 < δ → (r - δ : ℝ*) < x ∧ x < r + δ #align hyperreal.is_st Hyperreal.IsSt /-- Standard part function: like a "round" to ℝ instead of ℤ -/ noncomputable def st : ℝ* → ℝ := fun x => if h : ∃ r, IsSt x r then Classical.choose h else 0 #align hyperreal.st Hyperreal.st /-- A hyperreal number is infinitesimal if its standard part is 0 -/ def Infinitesimal (x : ℝ*) := IsSt x 0 #align hyperreal.infinitesimal Hyperreal.Infinitesimal /-- A hyperreal number is positive infinite if it is larger than all real numbers -/ def InfinitePos (x : ℝ*) := ∀ r : ℝ, ↑r < x #align hyperreal.infinite_pos Hyperreal.InfinitePos /-- A hyperreal number is negative infinite if it is smaller than all real numbers -/ def InfiniteNeg (x : ℝ*) := ∀ r : ℝ, x < r #align hyperreal.infinite_neg Hyperreal.InfiniteNeg /-- A hyperreal number is infinite if it is infinite positive or infinite negative -/ def Infinite (x : ℝ*) := InfinitePos x ∨ InfiniteNeg x #align hyperreal.infinite Hyperreal.Infinite /-! ### Some facts about `st` -/ theorem isSt_ofSeq_iff_tendsto {f : ℕ → ℝ} {r : ℝ} : IsSt (ofSeq f) r ↔ Tendsto f (hyperfilter ℕ) (𝓝 r) := Iff.trans (forall₂_congr fun _ _ ↦ (ofSeq_lt_ofSeq.and ofSeq_lt_ofSeq).trans eventually_and.symm) (nhds_basis_Ioo_pos _).tendsto_right_iff.symm theorem isSt_iff_tendsto {x : ℝ*} {r : ℝ} : IsSt x r ↔ x.Tendsto (𝓝 r) := by rcases ofSeq_surjective x with ⟨f, rfl⟩ exact isSt_ofSeq_iff_tendsto theorem isSt_of_tendsto {f : ℕ → ℝ} {r : ℝ} (hf : Tendsto f atTop (𝓝 r)) : IsSt (ofSeq f) r := isSt_ofSeq_iff_tendsto.2 <| hf.mono_left Nat.hyperfilter_le_atTop #align hyperreal.is_st_of_tendsto Hyperreal.isSt_of_tendsto -- Porting note: moved up, renamed protected theorem IsSt.lt {x y : ℝ*} {r s : ℝ} (hxr : IsSt x r) (hys : IsSt y s) (hrs : r < s) : x < y := by rcases ofSeq_surjective x with ⟨f, rfl⟩ rcases ofSeq_surjective y with ⟨g, rfl⟩ rw [isSt_ofSeq_iff_tendsto] at hxr hys exact ofSeq_lt_ofSeq.2 <| hxr.eventually_lt hys hrs #align hyperreal.lt_of_is_st_lt Hyperreal.IsSt.lt theorem IsSt.unique {x : ℝ*} {r s : ℝ} (hr : IsSt x r) (hs : IsSt x s) : r = s := by rcases ofSeq_surjective x with ⟨f, rfl⟩ rw [isSt_ofSeq_iff_tendsto] at hr hs exact tendsto_nhds_unique hr hs #align hyperreal.is_st_unique Hyperreal.IsSt.unique theorem IsSt.st_eq {x : ℝ*} {r : ℝ} (hxr : IsSt x r) : st x = r := by have h : ∃ r, IsSt x r := ⟨r, hxr⟩ rw [st, dif_pos h] exact (Classical.choose_spec h).unique hxr #align hyperreal.st_of_is_st Hyperreal.IsSt.st_eq theorem IsSt.not_infinite {x : ℝ*} {r : ℝ} (h : IsSt x r) : ¬Infinite x := fun hi ↦ hi.elim (fun hp ↦ lt_asymm (h 1 one_pos).2 (hp (r + 1))) fun hn ↦ lt_asymm (h 1 one_pos).1 (hn (r - 1)) theorem not_infinite_of_exists_st {x : ℝ*} : (∃ r : ℝ, IsSt x r) → ¬Infinite x := fun ⟨_r, hr⟩ => hr.not_infinite #align hyperreal.not_infinite_of_exists_st Hyperreal.not_infinite_of_exists_st theorem Infinite.st_eq {x : ℝ*} (hi : Infinite x) : st x = 0 := dif_neg fun ⟨_r, hr⟩ ↦ hr.not_infinite hi #align hyperreal.st_infinite Hyperreal.Infinite.st_eq theorem isSt_sSup {x : ℝ*} (hni : ¬Infinite x) : IsSt x (sSup { y : ℝ | (y : ℝ*) < x }) := let S : Set ℝ := { y : ℝ | (y : ℝ*) < x } let R : ℝ := sSup S let ⟨r₁, hr₁⟩ := not_forall.mp (not_or.mp hni).2 let ⟨r₂, hr₂⟩ := not_forall.mp (not_or.mp hni).1 have HR₁ : S.Nonempty := ⟨r₁ - 1, lt_of_lt_of_le (coe_lt_coe.2 <| sub_one_lt _) (not_lt.mp hr₁)⟩ have HR₂ : BddAbove S := ⟨r₂, fun _y hy => le_of_lt (coe_lt_coe.1 (lt_of_lt_of_le hy (not_lt.mp hr₂)))⟩ fun δ hδ => ⟨lt_of_not_le fun c => have hc : ∀ y ∈ S, y ≤ R - δ := fun _y hy => coe_le_coe.1 <| le_of_lt <| lt_of_lt_of_le hy c not_lt_of_le (csSup_le HR₁ hc) <| sub_lt_self R hδ, lt_of_not_le fun c => have hc : ↑(R + δ / 2) < x := lt_of_lt_of_le (add_lt_add_left (coe_lt_coe.2 (half_lt_self hδ)) R) c not_lt_of_le (le_csSup HR₂ hc) <| (lt_add_iff_pos_right _).mpr <| half_pos hδ⟩ #align hyperreal.is_st_Sup Hyperreal.isSt_sSup theorem exists_st_of_not_infinite {x : ℝ*} (hni : ¬Infinite x) : ∃ r : ℝ, IsSt x r := ⟨sSup { y : ℝ | (y : ℝ*) < x }, isSt_sSup hni⟩ #align hyperreal.exists_st_of_not_infinite Hyperreal.exists_st_of_not_infinite theorem st_eq_sSup {x : ℝ*} : st x = sSup { y : ℝ | (y : ℝ*) < x } := by rcases _root_.em (Infinite x) with (hx|hx) · rw [hx.st_eq] cases hx with | inl hx => convert Real.sSup_univ.symm exact Set.eq_univ_of_forall hx | inr hx => convert Real.sSup_empty.symm exact Set.eq_empty_of_forall_not_mem fun y hy ↦ hy.out.not_lt (hx _) · exact (isSt_sSup hx).st_eq #align hyperreal.st_eq_Sup Hyperreal.st_eq_sSup theorem exists_st_iff_not_infinite {x : ℝ*} : (∃ r : ℝ, IsSt x r) ↔ ¬Infinite x := ⟨not_infinite_of_exists_st, exists_st_of_not_infinite⟩ #align hyperreal.exists_st_iff_not_infinite Hyperreal.exists_st_iff_not_infinite theorem infinite_iff_not_exists_st {x : ℝ*} : Infinite x ↔ ¬∃ r : ℝ, IsSt x r := iff_not_comm.mp exists_st_iff_not_infinite #align hyperreal.infinite_iff_not_exists_st Hyperreal.infinite_iff_not_exists_st theorem IsSt.isSt_st {x : ℝ*} {r : ℝ} (hxr : IsSt x r) : IsSt x (st x) := by rwa [hxr.st_eq] #align hyperreal.is_st_st_of_is_st Hyperreal.IsSt.isSt_st theorem isSt_st_of_exists_st {x : ℝ*} (hx : ∃ r : ℝ, IsSt x r) : IsSt x (st x) := let ⟨_r, hr⟩ := hx; hr.isSt_st #align hyperreal.is_st_st_of_exists_st Hyperreal.isSt_st_of_exists_st theorem isSt_st' {x : ℝ*} (hx : ¬Infinite x) : IsSt x (st x) := (isSt_sSup hx).isSt_st #align hyperreal.is_st_st' Hyperreal.isSt_st' theorem isSt_st {x : ℝ*} (hx : st x ≠ 0) : IsSt x (st x) := isSt_st' <| mt Infinite.st_eq hx #align hyperreal.is_st_st Hyperreal.isSt_st theorem isSt_refl_real (r : ℝ) : IsSt r r := isSt_ofSeq_iff_tendsto.2 tendsto_const_nhds #align hyperreal.is_st_refl_real Hyperreal.isSt_refl_real theorem st_id_real (r : ℝ) : st r = r := (isSt_refl_real r).st_eq #align hyperreal.st_id_real Hyperreal.st_id_real theorem eq_of_isSt_real {r s : ℝ} : IsSt r s → r = s := (isSt_refl_real r).unique #align hyperreal.eq_of_is_st_real Hyperreal.eq_of_isSt_real theorem isSt_real_iff_eq {r s : ℝ} : IsSt r s ↔ r = s := ⟨eq_of_isSt_real, fun hrs => hrs ▸ isSt_refl_real r⟩ #align hyperreal.is_st_real_iff_eq Hyperreal.isSt_real_iff_eq theorem isSt_symm_real {r s : ℝ} : IsSt r s ↔ IsSt s r := by rw [isSt_real_iff_eq, isSt_real_iff_eq, eq_comm] #align hyperreal.is_st_symm_real Hyperreal.isSt_symm_real theorem isSt_trans_real {r s t : ℝ} : IsSt r s → IsSt s t → IsSt r t := by rw [isSt_real_iff_eq, isSt_real_iff_eq, isSt_real_iff_eq]; exact Eq.trans #align hyperreal.is_st_trans_real Hyperreal.isSt_trans_real theorem isSt_inj_real {r₁ r₂ s : ℝ} (h1 : IsSt r₁ s) (h2 : IsSt r₂ s) : r₁ = r₂ := Eq.trans (eq_of_isSt_real h1) (eq_of_isSt_real h2).symm #align hyperreal.is_st_inj_real Hyperreal.isSt_inj_real theorem isSt_iff_abs_sub_lt_delta {x : ℝ*} {r : ℝ} : IsSt x r ↔ ∀ δ : ℝ, 0 < δ → |x - ↑r| < δ := by simp only [abs_sub_lt_iff, sub_lt_iff_lt_add, IsSt, and_comm, add_comm] #align hyperreal.is_st_iff_abs_sub_lt_delta Hyperreal.isSt_iff_abs_sub_lt_delta theorem IsSt.map {x : ℝ*} {r : ℝ} (hxr : IsSt x r) {f : ℝ → ℝ} (hf : ContinuousAt f r) : IsSt (x.map f) (f r) := by rcases ofSeq_surjective x with ⟨g, rfl⟩ exact isSt_ofSeq_iff_tendsto.2 <| hf.tendsto.comp (isSt_ofSeq_iff_tendsto.1 hxr) theorem IsSt.map₂ {x y : ℝ*} {r s : ℝ} (hxr : IsSt x r) (hys : IsSt y s) {f : ℝ → ℝ → ℝ} (hf : ContinuousAt (Function.uncurry f) (r, s)) : IsSt (x.map₂ f y) (f r s) := by rcases ofSeq_surjective x with ⟨x, rfl⟩ rcases ofSeq_surjective y with ⟨y, rfl⟩ rw [isSt_ofSeq_iff_tendsto] at hxr hys exact isSt_ofSeq_iff_tendsto.2 <| hf.tendsto.comp (hxr.prod_mk_nhds hys) theorem IsSt.add {x y : ℝ*} {r s : ℝ} (hxr : IsSt x r) (hys : IsSt y s) : IsSt (x + y) (r + s) := hxr.map₂ hys continuous_add.continuousAt #align hyperreal.is_st_add Hyperreal.IsSt.add theorem IsSt.neg {x : ℝ*} {r : ℝ} (hxr : IsSt x r) : IsSt (-x) (-r) := hxr.map continuous_neg.continuousAt #align hyperreal.is_st_neg Hyperreal.IsSt.neg theorem IsSt.sub {x y : ℝ*} {r s : ℝ} (hxr : IsSt x r) (hys : IsSt y s) : IsSt (x - y) (r - s) := hxr.map₂ hys continuous_sub.continuousAt #align hyperreal.is_st_sub Hyperreal.IsSt.sub theorem IsSt.le {x y : ℝ*} {r s : ℝ} (hrx : IsSt x r) (hsy : IsSt y s) (hxy : x ≤ y) : r ≤ s := not_lt.1 fun h ↦ hxy.not_lt <| hsy.lt hrx h #align hyperreal.is_st_le_of_le Hyperreal.IsSt.le theorem st_le_of_le {x y : ℝ*} (hix : ¬Infinite x) (hiy : ¬Infinite y) : x ≤ y → st x ≤ st y := (isSt_st' hix).le (isSt_st' hiy) #align hyperreal.st_le_of_le Hyperreal.st_le_of_le theorem lt_of_st_lt {x y : ℝ*} (hix : ¬Infinite x) (hiy : ¬Infinite y) : st x < st y → x < y := (isSt_st' hix).lt (isSt_st' hiy) #align hyperreal.lt_of_st_lt Hyperreal.lt_of_st_lt /-! ### Basic lemmas about infinite -/ theorem infinitePos_def {x : ℝ*} : InfinitePos x ↔ ∀ r : ℝ, ↑r < x := Iff.rfl #align hyperreal.infinite_pos_def Hyperreal.infinitePos_def theorem infiniteNeg_def {x : ℝ*} : InfiniteNeg x ↔ ∀ r : ℝ, x < r := Iff.rfl #align hyperreal.infinite_neg_def Hyperreal.infiniteNeg_def theorem InfinitePos.pos {x : ℝ*} (hip : InfinitePos x) : 0 < x := hip 0 #align hyperreal.pos_of_infinite_pos Hyperreal.InfinitePos.pos theorem InfiniteNeg.lt_zero {x : ℝ*} : InfiniteNeg x → x < 0 := fun hin => hin 0 #align hyperreal.neg_of_infinite_neg Hyperreal.InfiniteNeg.lt_zero theorem Infinite.ne_zero {x : ℝ*} (hI : Infinite x) : x ≠ 0 := hI.elim (fun hip => hip.pos.ne') fun hin => hin.lt_zero.ne #align hyperreal.ne_zero_of_infinite Hyperreal.Infinite.ne_zero theorem not_infinite_zero : ¬Infinite 0 := fun hI => hI.ne_zero rfl #align hyperreal.not_infinite_zero Hyperreal.not_infinite_zero theorem InfiniteNeg.not_infinitePos {x : ℝ*} : InfiniteNeg x → ¬InfinitePos x := fun hn hp => (hn 0).not_lt (hp 0) #align hyperreal.not_infinite_pos_of_infinite_neg Hyperreal.InfiniteNeg.not_infinitePos theorem InfinitePos.not_infiniteNeg {x : ℝ*} (hp : InfinitePos x) : ¬InfiniteNeg x := fun hn ↦ hn.not_infinitePos hp #align hyperreal.not_infinite_neg_of_infinite_pos Hyperreal.InfinitePos.not_infiniteNeg theorem InfinitePos.neg {x : ℝ*} : InfinitePos x → InfiniteNeg (-x) := fun hp r => neg_lt.mp (hp (-r)) #align hyperreal.infinite_neg_neg_of_infinite_pos Hyperreal.InfinitePos.neg theorem InfiniteNeg.neg {x : ℝ*} : InfiniteNeg x → InfinitePos (-x) := fun hp r => lt_neg.mp (hp (-r)) #align hyperreal.infinite_pos_neg_of_infinite_neg Hyperreal.InfiniteNeg.neg -- Porting note: swapped LHS with RHS; added @[simp] @[simp] theorem infiniteNeg_neg {x : ℝ*} : InfiniteNeg (-x) ↔ InfinitePos x := ⟨fun hin => neg_neg x ▸ hin.neg, InfinitePos.neg⟩ #align hyperreal.infinite_pos_iff_infinite_neg_neg Hyperreal.infiniteNeg_negₓ -- Porting note: swapped LHS with RHS; added @[simp] @[simp] theorem infinitePos_neg {x : ℝ*} : InfinitePos (-x) ↔ InfiniteNeg x := ⟨fun hin => neg_neg x ▸ hin.neg, InfiniteNeg.neg⟩ #align hyperreal.infinite_neg_iff_infinite_pos_neg Hyperreal.infinitePos_negₓ -- Porting note: swapped LHS with RHS; added @[simp] @[simp] theorem infinite_neg {x : ℝ*} : Infinite (-x) ↔ Infinite x := or_comm.trans <| infiniteNeg_neg.or infinitePos_neg #align hyperreal.infinite_iff_infinite_neg Hyperreal.infinite_negₓ nonrec theorem Infinitesimal.not_infinite {x : ℝ*} (h : Infinitesimal x) : ¬Infinite x := h.not_infinite #align hyperreal.not_infinite_of_infinitesimal Hyperreal.Infinitesimal.not_infinite theorem Infinite.not_infinitesimal {x : ℝ*} (h : Infinite x) : ¬Infinitesimal x := fun h' ↦ h'.not_infinite h #align hyperreal.not_infinitesimal_of_infinite Hyperreal.Infinite.not_infinitesimal theorem InfinitePos.not_infinitesimal {x : ℝ*} (h : InfinitePos x) : ¬Infinitesimal x := Infinite.not_infinitesimal (Or.inl h) #align hyperreal.not_infinitesimal_of_infinite_pos Hyperreal.InfinitePos.not_infinitesimal theorem InfiniteNeg.not_infinitesimal {x : ℝ*} (h : InfiniteNeg x) : ¬Infinitesimal x := Infinite.not_infinitesimal (Or.inr h) #align hyperreal.not_infinitesimal_of_infinite_neg Hyperreal.InfiniteNeg.not_infinitesimal theorem infinitePos_iff_infinite_and_pos {x : ℝ*} : InfinitePos x ↔ Infinite x ∧ 0 < x := ⟨fun hip => ⟨Or.inl hip, hip 0⟩, fun ⟨hi, hp⟩ => hi.casesOn (fun hip => hip) fun hin => False.elim (not_lt_of_lt hp (hin 0))⟩ #align hyperreal.infinite_pos_iff_infinite_and_pos Hyperreal.infinitePos_iff_infinite_and_pos theorem infiniteNeg_iff_infinite_and_neg {x : ℝ*} : InfiniteNeg x ↔ Infinite x ∧ x < 0 := ⟨fun hip => ⟨Or.inr hip, hip 0⟩, fun ⟨hi, hp⟩ => hi.casesOn (fun hin => False.elim (not_lt_of_lt hp (hin 0))) fun hip => hip⟩ #align hyperreal.infinite_neg_iff_infinite_and_neg Hyperreal.infiniteNeg_iff_infinite_and_neg theorem infinitePos_iff_infinite_of_nonneg {x : ℝ*} (hp : 0 ≤ x) : InfinitePos x ↔ Infinite x := .symm <| or_iff_left fun h ↦ h.lt_zero.not_le hp #align hyperreal.infinite_pos_iff_infinite_of_nonneg Hyperreal.infinitePos_iff_infinite_of_nonneg theorem infinitePos_iff_infinite_of_pos {x : ℝ*} (hp : 0 < x) : InfinitePos x ↔ Infinite x := infinitePos_iff_infinite_of_nonneg hp.le #align hyperreal.infinite_pos_iff_infinite_of_pos Hyperreal.infinitePos_iff_infinite_of_pos theorem infiniteNeg_iff_infinite_of_neg {x : ℝ*} (hn : x < 0) : InfiniteNeg x ↔ Infinite x := .symm <| or_iff_right fun h ↦ h.pos.not_lt hn #align hyperreal.infinite_neg_iff_infinite_of_neg Hyperreal.infiniteNeg_iff_infinite_of_neg theorem infinitePos_abs_iff_infinite_abs {x : ℝ*} : InfinitePos |x| ↔ Infinite |x| := infinitePos_iff_infinite_of_nonneg (abs_nonneg _) #align hyperreal.infinite_pos_abs_iff_infinite_abs Hyperreal.infinitePos_abs_iff_infinite_abs -- Porting note: swapped LHS with RHS; added @[simp] @[simp] theorem infinite_abs_iff {x : ℝ*} : Infinite |x| ↔ Infinite x := by cases le_total 0 x <;> simp [*, abs_of_nonneg, abs_of_nonpos, infinite_neg] #align hyperreal.infinite_iff_infinite_abs Hyperreal.infinite_abs_iffₓ -- Porting note: swapped LHS with RHS; -- Porting note (#11215): TODO: make it a `simp` lemma @[simp] theorem infinitePos_abs_iff_infinite {x : ℝ*} : InfinitePos |x| ↔ Infinite x := infinitePos_abs_iff_infinite_abs.trans infinite_abs_iff #align hyperreal.infinite_iff_infinite_pos_abs Hyperreal.infinitePos_abs_iff_infiniteₓ theorem infinite_iff_abs_lt_abs {x : ℝ*} : Infinite x ↔ ∀ r : ℝ, (|r| : ℝ*) < |x| := infinitePos_abs_iff_infinite.symm.trans ⟨fun hI r => coe_abs r ▸ hI |r|, fun hR r => (le_abs_self _).trans_lt (hR r)⟩ #align hyperreal.infinite_iff_abs_lt_abs Hyperreal.infinite_iff_abs_lt_abs theorem infinitePos_add_not_infiniteNeg {x y : ℝ*} : InfinitePos x → ¬InfiniteNeg y → InfinitePos (x + y) := by intro hip hnin r cases' not_forall.mp hnin with r₂ hr₂ convert add_lt_add_of_lt_of_le (hip (r + -r₂)) (not_lt.mp hr₂) using 1 simp #align hyperreal.infinite_pos_add_not_infinite_neg Hyperreal.infinitePos_add_not_infiniteNeg theorem not_infiniteNeg_add_infinitePos {x y : ℝ*} : ¬InfiniteNeg x → InfinitePos y → InfinitePos (x + y) := fun hx hy => add_comm y x ▸ infinitePos_add_not_infiniteNeg hy hx #align hyperreal.not_infinite_neg_add_infinite_pos Hyperreal.not_infiniteNeg_add_infinitePos theorem infiniteNeg_add_not_infinitePos {x y : ℝ*} : InfiniteNeg x → ¬InfinitePos y → InfiniteNeg (x + y) := by rw [← infinitePos_neg, ← infinitePos_neg, ← @infiniteNeg_neg y, neg_add] exact infinitePos_add_not_infiniteNeg #align hyperreal.infinite_neg_add_not_infinite_pos Hyperreal.infiniteNeg_add_not_infinitePos theorem not_infinitePos_add_infiniteNeg {x y : ℝ*} : ¬InfinitePos x → InfiniteNeg y → InfiniteNeg (x + y) := fun hx hy => add_comm y x ▸ infiniteNeg_add_not_infinitePos hy hx #align hyperreal.not_infinite_pos_add_infinite_neg Hyperreal.not_infinitePos_add_infiniteNeg theorem infinitePos_add_infinitePos {x y : ℝ*} : InfinitePos x → InfinitePos y → InfinitePos (x + y) := fun hx hy => infinitePos_add_not_infiniteNeg hx hy.not_infiniteNeg #align hyperreal.infinite_pos_add_infinite_pos Hyperreal.infinitePos_add_infinitePos theorem infiniteNeg_add_infiniteNeg {x y : ℝ*} : InfiniteNeg x → InfiniteNeg y → InfiniteNeg (x + y) := fun hx hy => infiniteNeg_add_not_infinitePos hx hy.not_infinitePos #align hyperreal.infinite_neg_add_infinite_neg Hyperreal.infiniteNeg_add_infiniteNeg theorem infinitePos_add_not_infinite {x y : ℝ*} : InfinitePos x → ¬Infinite y → InfinitePos (x + y) := fun hx hy => infinitePos_add_not_infiniteNeg hx (not_or.mp hy).2 #align hyperreal.infinite_pos_add_not_infinite Hyperreal.infinitePos_add_not_infinite theorem infiniteNeg_add_not_infinite {x y : ℝ*} : InfiniteNeg x → ¬Infinite y → InfiniteNeg (x + y) := fun hx hy => infiniteNeg_add_not_infinitePos hx (not_or.mp hy).1 #align hyperreal.infinite_neg_add_not_infinite Hyperreal.infiniteNeg_add_not_infinite theorem infinitePos_of_tendsto_top {f : ℕ → ℝ} (hf : Tendsto f atTop atTop) : InfinitePos (ofSeq f) := fun r => have hf' := tendsto_atTop_atTop.mp hf let ⟨i, hi⟩ := hf' (r + 1) have hi' : ∀ a : ℕ, f a < r + 1 → a < i := fun a => lt_imp_lt_of_le_imp_le (hi a) have hS : { a : ℕ | r < f a }ᶜ ⊆ { a : ℕ | a ≤ i } := by simp only [Set.compl_setOf, not_lt] exact fun a har => le_of_lt (hi' a (lt_of_le_of_lt har (lt_add_one _))) Germ.coe_lt.2 <| mem_hyperfilter_of_finite_compl <| (Set.finite_le_nat _).subset hS #align hyperreal.infinite_pos_of_tendsto_top Hyperreal.infinitePos_of_tendsto_top theorem infiniteNeg_of_tendsto_bot {f : ℕ → ℝ} (hf : Tendsto f atTop atBot) : InfiniteNeg (ofSeq f) := fun r => have hf' := tendsto_atTop_atBot.mp hf let ⟨i, hi⟩ := hf' (r - 1) have hi' : ∀ a : ℕ, r - 1 < f a → a < i := fun a => lt_imp_lt_of_le_imp_le (hi a) have hS : { a : ℕ | f a < r }ᶜ ⊆ { a : ℕ | a ≤ i } := by simp only [Set.compl_setOf, not_lt] exact fun a har => le_of_lt (hi' a (lt_of_lt_of_le (sub_one_lt _) har)) Germ.coe_lt.2 <| mem_hyperfilter_of_finite_compl <| (Set.finite_le_nat _).subset hS #align hyperreal.infinite_neg_of_tendsto_bot Hyperreal.infiniteNeg_of_tendsto_bot theorem not_infinite_neg {x : ℝ*} : ¬Infinite x → ¬Infinite (-x) := mt infinite_neg.mp #align hyperreal.not_infinite_neg Hyperreal.not_infinite_neg theorem not_infinite_add {x y : ℝ*} (hx : ¬Infinite x) (hy : ¬Infinite y) : ¬Infinite (x + y) := have ⟨r, hr⟩ := exists_st_of_not_infinite hx have ⟨s, hs⟩ := exists_st_of_not_infinite hy not_infinite_of_exists_st <| ⟨r + s, hr.add hs⟩ #align hyperreal.not_infinite_add Hyperreal.not_infinite_add theorem not_infinite_iff_exist_lt_gt {x : ℝ*} : ¬Infinite x ↔ ∃ r s : ℝ, (r : ℝ*) < x ∧ x < s := ⟨fun hni ↦ let ⟨r, hr⟩ := exists_st_of_not_infinite hni; ⟨r - 1, r + 1, hr 1 one_pos⟩, fun ⟨r, s, hr, hs⟩ hi ↦ hi.elim (fun hp ↦ (hp s).not_lt hs) (fun hn ↦ (hn r).not_lt hr)⟩ #align hyperreal.not_infinite_iff_exist_lt_gt Hyperreal.not_infinite_iff_exist_lt_gt theorem not_infinite_real (r : ℝ) : ¬Infinite r := by rw [not_infinite_iff_exist_lt_gt] exact ⟨r - 1, r + 1, coe_lt_coe.2 <| sub_one_lt r, coe_lt_coe.2 <| lt_add_one r⟩ #align hyperreal.not_infinite_real Hyperreal.not_infinite_real theorem Infinite.ne_real {x : ℝ*} : Infinite x → ∀ r : ℝ, x ≠ r := fun hi r hr => not_infinite_real r <| @Eq.subst _ Infinite _ _ hr hi #align hyperreal.not_real_of_infinite Hyperreal.Infinite.ne_real /-! ### Facts about `st` that require some infinite machinery -/ theorem IsSt.mul {x y : ℝ*} {r s : ℝ} (hxr : IsSt x r) (hys : IsSt y s) : IsSt (x * y) (r * s) := hxr.map₂ hys continuous_mul.continuousAt #align hyperreal.is_st_mul Hyperreal.IsSt.mul --AN INFINITE LEMMA THAT REQUIRES SOME MORE ST MACHINERY theorem not_infinite_mul {x y : ℝ*} (hx : ¬Infinite x) (hy : ¬Infinite y) : ¬Infinite (x * y) := have ⟨_r, hr⟩ := exists_st_of_not_infinite hx have ⟨_s, hs⟩ := exists_st_of_not_infinite hy (hr.mul hs).not_infinite #align hyperreal.not_infinite_mul Hyperreal.not_infinite_mul --- theorem st_add {x y : ℝ*} (hx : ¬Infinite x) (hy : ¬Infinite y) : st (x + y) = st x + st y := (isSt_st' (not_infinite_add hx hy)).unique ((isSt_st' hx).add (isSt_st' hy)) #align hyperreal.st_add Hyperreal.st_add theorem st_neg (x : ℝ*) : st (-x) = -st x := if h : Infinite x then by rw [h.st_eq, (infinite_neg.2 h).st_eq, neg_zero] else (isSt_st' (not_infinite_neg h)).unique (isSt_st' h).neg #align hyperreal.st_neg Hyperreal.st_neg theorem st_mul {x y : ℝ*} (hx : ¬Infinite x) (hy : ¬Infinite y) : st (x * y) = st x * st y := have hx' := isSt_st' hx have hy' := isSt_st' hy have hxy := isSt_st' (not_infinite_mul hx hy) hxy.unique (hx'.mul hy') #align hyperreal.st_mul Hyperreal.st_mul /-! ### Basic lemmas about infinitesimal -/ theorem infinitesimal_def {x : ℝ*} : Infinitesimal x ↔ ∀ r : ℝ, 0 < r → -(r : ℝ*) < x ∧ x < r := by simp [Infinitesimal, IsSt] #align hyperreal.infinitesimal_def Hyperreal.infinitesimal_def theorem lt_of_pos_of_infinitesimal {x : ℝ*} : Infinitesimal x → ∀ r : ℝ, 0 < r → x < r := fun hi r hr => ((infinitesimal_def.mp hi) r hr).2 #align hyperreal.lt_of_pos_of_infinitesimal Hyperreal.lt_of_pos_of_infinitesimal theorem lt_neg_of_pos_of_infinitesimal {x : ℝ*} : Infinitesimal x → ∀ r : ℝ, 0 < r → -↑r < x := fun hi r hr => ((infinitesimal_def.mp hi) r hr).1 #align hyperreal.lt_neg_of_pos_of_infinitesimal Hyperreal.lt_neg_of_pos_of_infinitesimal theorem gt_of_neg_of_infinitesimal {x : ℝ*} (hi : Infinitesimal x) (r : ℝ) (hr : r < 0) : ↑r < x := neg_neg r ▸ (infinitesimal_def.1 hi (-r) (neg_pos.2 hr)).1 #align hyperreal.gt_of_neg_of_infinitesimal Hyperreal.gt_of_neg_of_infinitesimal theorem abs_lt_real_iff_infinitesimal {x : ℝ*} : Infinitesimal x ↔ ∀ r : ℝ, r ≠ 0 → |x| < |↑r| := ⟨fun hi r hr ↦ abs_lt.mpr (coe_abs r ▸ infinitesimal_def.mp hi |r| (abs_pos.2 hr)), fun hR ↦ infinitesimal_def.mpr fun r hr => abs_lt.mp <| (abs_of_pos <| coe_pos.2 hr) ▸ hR r <| hr.ne'⟩ #align hyperreal.abs_lt_real_iff_infinitesimal Hyperreal.abs_lt_real_iff_infinitesimal theorem infinitesimal_zero : Infinitesimal 0 := isSt_refl_real 0 #align hyperreal.infinitesimal_zero Hyperreal.infinitesimal_zero theorem Infinitesimal.eq_zero {r : ℝ} : Infinitesimal r → r = 0 := eq_of_isSt_real #align hyperreal.zero_of_infinitesimal_real Hyperreal.Infinitesimal.eq_zero -- Porting note: swapped LHS with RHS; added `@[simp]` @[simp] theorem infinitesimal_real_iff {r : ℝ} : Infinitesimal r ↔ r = 0 := isSt_real_iff_eq #align hyperreal.zero_iff_infinitesimal_real Hyperreal.infinitesimal_real_iff nonrec theorem Infinitesimal.add {x y : ℝ*} (hx : Infinitesimal x) (hy : Infinitesimal y) : Infinitesimal (x + y) := by simpa only [add_zero] using hx.add hy #align hyperreal.infinitesimal_add Hyperreal.Infinitesimal.add nonrec theorem Infinitesimal.neg {x : ℝ*} (hx : Infinitesimal x) : Infinitesimal (-x) := by simpa only [neg_zero] using hx.neg #align hyperreal.infinitesimal_neg Hyperreal.Infinitesimal.neg -- Porting note: swapped LHS and RHS, added `@[simp]` @[simp] theorem infinitesimal_neg {x : ℝ*} : Infinitesimal (-x) ↔ Infinitesimal x := ⟨fun h => neg_neg x ▸ h.neg, Infinitesimal.neg⟩ #align hyperreal.infinitesimal_neg_iff Hyperreal.infinitesimal_negₓ nonrec theorem Infinitesimal.mul {x y : ℝ*} (hx : Infinitesimal x) (hy : Infinitesimal y) : Infinitesimal (x * y) := by simpa only [mul_zero] using hx.mul hy #align hyperreal.infinitesimal_mul Hyperreal.Infinitesimal.mul theorem infinitesimal_of_tendsto_zero {f : ℕ → ℝ} (h : Tendsto f atTop (𝓝 0)) : Infinitesimal (ofSeq f) := isSt_of_tendsto h #align hyperreal.infinitesimal_of_tendsto_zero Hyperreal.infinitesimal_of_tendsto_zero theorem infinitesimal_epsilon : Infinitesimal ε := infinitesimal_of_tendsto_zero tendsto_inverse_atTop_nhds_zero_nat #align hyperreal.infinitesimal_epsilon Hyperreal.infinitesimal_epsilon theorem not_real_of_infinitesimal_ne_zero (x : ℝ*) : Infinitesimal x → x ≠ 0 → ∀ r : ℝ, x ≠ r := fun hi hx r hr => hx <| hr.trans <| coe_eq_zero.2 <| IsSt.unique (hr.symm ▸ isSt_refl_real r : IsSt x r) hi #align hyperreal.not_real_of_infinitesimal_ne_zero Hyperreal.not_real_of_infinitesimal_ne_zero theorem IsSt.infinitesimal_sub {x : ℝ*} {r : ℝ} (hxr : IsSt x r) : Infinitesimal (x - ↑r) := by simpa only [sub_self] using hxr.sub (isSt_refl_real r) #align hyperreal.infinitesimal_sub_is_st Hyperreal.IsSt.infinitesimal_sub theorem infinitesimal_sub_st {x : ℝ*} (hx : ¬Infinite x) : Infinitesimal (x - ↑(st x)) := (isSt_st' hx).infinitesimal_sub #align hyperreal.infinitesimal_sub_st Hyperreal.infinitesimal_sub_st theorem infinitePos_iff_infinitesimal_inv_pos {x : ℝ*} : InfinitePos x ↔ Infinitesimal x⁻¹ ∧ 0 < x⁻¹ := ⟨fun hip => ⟨infinitesimal_def.mpr fun r hr => ⟨lt_trans (coe_lt_coe.2 (neg_neg_of_pos hr)) (inv_pos.2 (hip 0)), (inv_lt (coe_lt_coe.2 hr) (hip 0)).mp (by convert hip r⁻¹)⟩, inv_pos.2 <| hip 0⟩, fun ⟨hi, hp⟩ r => @_root_.by_cases (r = 0) (↑r < x) (fun h => Eq.substr h (inv_pos.mp hp)) fun h => lt_of_le_of_lt (coe_le_coe.2 (le_abs_self r)) ((inv_lt_inv (inv_pos.mp hp) (coe_lt_coe.2 (abs_pos.2 h))).mp ((infinitesimal_def.mp hi) |r|⁻¹ (inv_pos.2 (abs_pos.2 h))).2)⟩ #align hyperreal.infinite_pos_iff_infinitesimal_inv_pos Hyperreal.infinitePos_iff_infinitesimal_inv_pos theorem infiniteNeg_iff_infinitesimal_inv_neg {x : ℝ*} : InfiniteNeg x ↔ Infinitesimal x⁻¹ ∧ x⁻¹ < 0 := by rw [← infinitePos_neg, infinitePos_iff_infinitesimal_inv_pos, inv_neg, neg_pos, infinitesimal_neg] #align hyperreal.infinite_neg_iff_infinitesimal_inv_neg Hyperreal.infiniteNeg_iff_infinitesimal_inv_neg theorem infinitesimal_inv_of_infinite {x : ℝ*} : Infinite x → Infinitesimal x⁻¹ := fun hi => Or.casesOn hi (fun hip => (infinitePos_iff_infinitesimal_inv_pos.mp hip).1) fun hin => (infiniteNeg_iff_infinitesimal_inv_neg.mp hin).1 #align hyperreal.infinitesimal_inv_of_infinite Hyperreal.infinitesimal_inv_of_infinite theorem infinite_of_infinitesimal_inv {x : ℝ*} (h0 : x ≠ 0) (hi : Infinitesimal x⁻¹) : Infinite x := by cases' lt_or_gt_of_ne h0 with hn hp · exact Or.inr (infiniteNeg_iff_infinitesimal_inv_neg.mpr ⟨hi, inv_lt_zero.mpr hn⟩) · exact Or.inl (infinitePos_iff_infinitesimal_inv_pos.mpr ⟨hi, inv_pos.mpr hp⟩) #align hyperreal.infinite_of_infinitesimal_inv Hyperreal.infinite_of_infinitesimal_inv theorem infinite_iff_infinitesimal_inv {x : ℝ*} (h0 : x ≠ 0) : Infinite x ↔ Infinitesimal x⁻¹ := ⟨infinitesimal_inv_of_infinite, infinite_of_infinitesimal_inv h0⟩ #align hyperreal.infinite_iff_infinitesimal_inv Hyperreal.infinite_iff_infinitesimal_inv theorem infinitesimal_pos_iff_infinitePos_inv {x : ℝ*} : InfinitePos x⁻¹ ↔ Infinitesimal x ∧ 0 < x := infinitePos_iff_infinitesimal_inv_pos.trans <| by rw [inv_inv] #align hyperreal.infinitesimal_pos_iff_infinite_pos_inv Hyperreal.infinitesimal_pos_iff_infinitePos_inv theorem infinitesimal_neg_iff_infiniteNeg_inv {x : ℝ*} : InfiniteNeg x⁻¹ ↔ Infinitesimal x ∧ x < 0 := infiniteNeg_iff_infinitesimal_inv_neg.trans <| by rw [inv_inv] #align hyperreal.infinitesimal_neg_iff_infinite_neg_inv Hyperreal.infinitesimal_neg_iff_infiniteNeg_inv theorem infinitesimal_iff_infinite_inv {x : ℝ*} (h : x ≠ 0) : Infinitesimal x ↔ Infinite x⁻¹ := Iff.trans (by rw [inv_inv]) (infinite_iff_infinitesimal_inv (inv_ne_zero h)).symm #align hyperreal.infinitesimal_iff_infinite_inv Hyperreal.infinitesimal_iff_infinite_inv /-! ### `Hyperreal.st` stuff that requires infinitesimal machinery -/ theorem IsSt.inv {x : ℝ*} {r : ℝ} (hi : ¬Infinitesimal x) (hr : IsSt x r) : IsSt x⁻¹ r⁻¹ := hr.map <| continuousAt_inv₀ <| by rintro rfl; exact hi hr #align hyperreal.is_st_inv Hyperreal.IsSt.inv theorem st_inv (x : ℝ*) : st x⁻¹ = (st x)⁻¹ := by by_cases h0 : x = 0 · rw [h0, inv_zero, ← coe_zero, st_id_real, inv_zero] by_cases h1 : Infinitesimal x · rw [((infinitesimal_iff_infinite_inv h0).mp h1).st_eq, h1.st_eq, inv_zero] by_cases h2 : Infinite x · rw [(infinitesimal_inv_of_infinite h2).st_eq, h2.st_eq, inv_zero] exact ((isSt_st' h2).inv h1).st_eq #align hyperreal.st_inv Hyperreal.st_inv /-! ### Infinite stuff that requires infinitesimal machinery -/ theorem infinitePos_omega : InfinitePos ω := infinitePos_iff_infinitesimal_inv_pos.mpr ⟨infinitesimal_epsilon, epsilon_pos⟩ #align hyperreal.infinite_pos_omega Hyperreal.infinitePos_omega theorem infinite_omega : Infinite ω := (infinite_iff_infinitesimal_inv omega_ne_zero).mpr infinitesimal_epsilon #align hyperreal.infinite_omega Hyperreal.infinite_omega theorem infinitePos_mul_of_infinitePos_not_infinitesimal_pos {x y : ℝ*} : InfinitePos x → ¬Infinitesimal y → 0 < y → InfinitePos (x * y) := fun hx hy₁ hy₂ r => by have hy₁' := not_forall.mp (mt infinitesimal_def.2 hy₁) let ⟨r₁, hy₁''⟩ := hy₁' have hyr : 0 < r₁ ∧ ↑r₁ ≤ y := by rwa [Classical.not_imp, ← abs_lt, not_lt, abs_of_pos hy₂] at hy₁'' rw [← div_mul_cancel₀ r (ne_of_gt hyr.1), coe_mul] exact mul_lt_mul (hx (r / r₁)) hyr.2 (coe_lt_coe.2 hyr.1) (le_of_lt (hx 0)) #align hyperreal.infinite_pos_mul_of_infinite_pos_not_infinitesimal_pos Hyperreal.infinitePos_mul_of_infinitePos_not_infinitesimal_pos theorem infinitePos_mul_of_not_infinitesimal_pos_infinitePos {x y : ℝ*} : ¬Infinitesimal x → 0 < x → InfinitePos y → InfinitePos (x * y) := fun hx hp hy => mul_comm y x ▸ infinitePos_mul_of_infinitePos_not_infinitesimal_pos hy hx hp #align hyperreal.infinite_pos_mul_of_not_infinitesimal_pos_infinite_pos Hyperreal.infinitePos_mul_of_not_infinitesimal_pos_infinitePos theorem infinitePos_mul_of_infiniteNeg_not_infinitesimal_neg {x y : ℝ*} : InfiniteNeg x → ¬Infinitesimal y → y < 0 → InfinitePos (x * y) := by rw [← infinitePos_neg, ← neg_pos, ← neg_mul_neg, ← infinitesimal_neg] exact infinitePos_mul_of_infinitePos_not_infinitesimal_pos #align hyperreal.infinite_pos_mul_of_infinite_neg_not_infinitesimal_neg Hyperreal.infinitePos_mul_of_infiniteNeg_not_infinitesimal_neg theorem infinitePos_mul_of_not_infinitesimal_neg_infiniteNeg {x y : ℝ*} : ¬Infinitesimal x → x < 0 → InfiniteNeg y → InfinitePos (x * y) := fun hx hp hy => mul_comm y x ▸ infinitePos_mul_of_infiniteNeg_not_infinitesimal_neg hy hx hp #align hyperreal.infinite_pos_mul_of_not_infinitesimal_neg_infinite_neg Hyperreal.infinitePos_mul_of_not_infinitesimal_neg_infiniteNeg theorem infiniteNeg_mul_of_infinitePos_not_infinitesimal_neg {x y : ℝ*} : InfinitePos x → ¬Infinitesimal y → y < 0 → InfiniteNeg (x * y) := by rw [← infinitePos_neg, ← neg_pos, neg_mul_eq_mul_neg, ← infinitesimal_neg] exact infinitePos_mul_of_infinitePos_not_infinitesimal_pos #align hyperreal.infinite_neg_mul_of_infinite_pos_not_infinitesimal_neg Hyperreal.infiniteNeg_mul_of_infinitePos_not_infinitesimal_neg theorem infiniteNeg_mul_of_not_infinitesimal_neg_infinitePos {x y : ℝ*} : ¬Infinitesimal x → x < 0 → InfinitePos y → InfiniteNeg (x * y) := fun hx hp hy => mul_comm y x ▸ infiniteNeg_mul_of_infinitePos_not_infinitesimal_neg hy hx hp #align hyperreal.infinite_neg_mul_of_not_infinitesimal_neg_infinite_pos Hyperreal.infiniteNeg_mul_of_not_infinitesimal_neg_infinitePos
Mathlib/Data/Real/Hyperreal.lean
853
856
theorem infiniteNeg_mul_of_infiniteNeg_not_infinitesimal_pos {x y : ℝ*} : InfiniteNeg x → ¬Infinitesimal y → 0 < y → InfiniteNeg (x * y) := by
rw [← infinitePos_neg, ← infinitePos_neg, neg_mul_eq_neg_mul] exact infinitePos_mul_of_infinitePos_not_infinitesimal_pos
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Yury G. Kudryashov -/ import Batteries.Data.Sum.Basic import Batteries.Logic /-! # Disjoint union of types Theorems about the definitions introduced in `Batteries.Data.Sum.Basic`. -/ open Function namespace Sum @[simp] protected theorem «forall» {p : α ⊕ β → Prop} : (∀ x, p x) ↔ (∀ a, p (inl a)) ∧ ∀ b, p (inr b) := ⟨fun h => ⟨fun _ => h _, fun _ => h _⟩, fun ⟨h₁, h₂⟩ => Sum.rec h₁ h₂⟩ @[simp] protected theorem «exists» {p : α ⊕ β → Prop} : (∃ x, p x) ↔ (∃ a, p (inl a)) ∨ ∃ b, p (inr b) := ⟨ fun | ⟨inl a, h⟩ => Or.inl ⟨a, h⟩ | ⟨inr b, h⟩ => Or.inr ⟨b, h⟩, fun | Or.inl ⟨a, h⟩ => ⟨inl a, h⟩ | Or.inr ⟨b, h⟩ => ⟨inr b, h⟩⟩ theorem forall_sum {γ : α ⊕ β → Sort _} (p : (∀ ab, γ ab) → Prop) : (∀ fab, p fab) ↔ (∀ fa fb, p (Sum.rec fa fb)) := by refine ⟨fun h fa fb => h _, fun h fab => ?_⟩ have h1 : fab = Sum.rec (fun a => fab (Sum.inl a)) (fun b => fab (Sum.inr b)) := by ext ab; cases ab <;> rfl rw [h1]; exact h _ _ section get @[simp] theorem inl_getLeft : ∀ (x : α ⊕ β) (h : x.isLeft), inl (x.getLeft h) = x | inl _, _ => rfl @[simp] theorem inr_getRight : ∀ (x : α ⊕ β) (h : x.isRight), inr (x.getRight h) = x | inr _, _ => rfl @[simp] theorem getLeft?_eq_none_iff {x : α ⊕ β} : x.getLeft? = none ↔ x.isRight := by cases x <;> simp only [getLeft?, isRight, eq_self_iff_true] @[simp] theorem getRight?_eq_none_iff {x : α ⊕ β} : x.getRight? = none ↔ x.isLeft := by cases x <;> simp only [getRight?, isLeft, eq_self_iff_true] theorem eq_left_getLeft_of_isLeft : ∀ {x : α ⊕ β} (h : x.isLeft), x = inl (x.getLeft h) | inl _, _ => rfl @[simp] theorem getLeft_eq_iff (h : x.isLeft) : x.getLeft h = a ↔ x = inl a := by cases x <;> simp at h ⊢ theorem eq_right_getRight_of_isRight : ∀ {x : α ⊕ β} (h : x.isRight), x = inr (x.getRight h) | inr _, _ => rfl @[simp] theorem getRight_eq_iff (h : x.isRight) : x.getRight h = b ↔ x = inr b := by cases x <;> simp at h ⊢ @[simp] theorem getLeft?_eq_some_iff : x.getLeft? = some a ↔ x = inl a := by cases x <;> simp only [getLeft?, Option.some.injEq, inl.injEq] @[simp] theorem getRight?_eq_some_iff : x.getRight? = some b ↔ x = inr b := by cases x <;> simp only [getRight?, Option.some.injEq, inr.injEq] @[simp] theorem bnot_isLeft (x : α ⊕ β) : !x.isLeft = x.isRight := by cases x <;> rfl @[simp] theorem isLeft_eq_false {x : α ⊕ β} : x.isLeft = false ↔ x.isRight := by cases x <;> simp theorem not_isLeft {x : α ⊕ β} : ¬x.isLeft ↔ x.isRight := by simp @[simp] theorem bnot_isRight (x : α ⊕ β) : !x.isRight = x.isLeft := by cases x <;> rfl @[simp] theorem isRight_eq_false {x : α ⊕ β} : x.isRight = false ↔ x.isLeft := by cases x <;> simp theorem not_isRight {x : α ⊕ β} : ¬x.isRight ↔ x.isLeft := by simp theorem isLeft_iff : x.isLeft ↔ ∃ y, x = Sum.inl y := by cases x <;> simp theorem isRight_iff : x.isRight ↔ ∃ y, x = Sum.inr y := by cases x <;> simp end get theorem inl.inj_iff : (inl a : α ⊕ β) = inl b ↔ a = b := ⟨inl.inj, congrArg _⟩ theorem inr.inj_iff : (inr a : α ⊕ β) = inr b ↔ a = b := ⟨inr.inj, congrArg _⟩ theorem inl_ne_inr : inl a ≠ inr b := nofun theorem inr_ne_inl : inr b ≠ inl a := nofun /-! ### `Sum.elim` -/ @[simp] theorem elim_comp_inl (f : α → γ) (g : β → γ) : Sum.elim f g ∘ inl = f := rfl @[simp] theorem elim_comp_inr (f : α → γ) (g : β → γ) : Sum.elim f g ∘ inr = g := rfl @[simp] theorem elim_inl_inr : @Sum.elim α β _ inl inr = id := funext fun x => Sum.casesOn x (fun _ => rfl) fun _ => rfl theorem comp_elim (f : γ → δ) (g : α → γ) (h : β → γ) : f ∘ Sum.elim g h = Sum.elim (f ∘ g) (f ∘ h) := funext fun x => Sum.casesOn x (fun _ => rfl) fun _ => rfl @[simp] theorem elim_comp_inl_inr (f : α ⊕ β → γ) : Sum.elim (f ∘ inl) (f ∘ inr) = f := funext fun x => Sum.casesOn x (fun _ => rfl) fun _ => rfl
.lake/packages/batteries/Batteries/Data/Sum/Lemmas.lean
116
118
theorem elim_eq_iff {u u' : α → γ} {v v' : β → γ} : Sum.elim u v = Sum.elim u' v' ↔ u = u' ∧ v = v' := by
simp [funext_iff]
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.LinearAlgebra.AffineSpace.AffineEquiv #align_import linear_algebra.affine_space.affine_subspace from "leanprover-community/mathlib"@"e96bdfbd1e8c98a09ff75f7ac6204d142debc840" /-! # Affine spaces This file defines affine subspaces (over modules) and the affine span of a set of points. ## Main definitions * `AffineSubspace k P` is the type of affine subspaces. Unlike affine spaces, affine subspaces are allowed to be empty, and lemmas that do not apply to empty affine subspaces have `Nonempty` hypotheses. There is a `CompleteLattice` structure on affine subspaces. * `AffineSubspace.direction` gives the `Submodule` spanned by the pairwise differences of points in an `AffineSubspace`. There are various lemmas relating to the set of vectors in the `direction`, and relating the lattice structure on affine subspaces to that on their directions. * `AffineSubspace.parallel`, notation `∥`, gives the property of two affine subspaces being parallel (one being a translate of the other). * `affineSpan` gives the affine subspace spanned by a set of points, with `vectorSpan` giving its direction. The `affineSpan` is defined in terms of `spanPoints`, which gives an explicit description of the points contained in the affine span; `spanPoints` itself should generally only be used when that description is required, with `affineSpan` being the main definition for other purposes. Two other descriptions of the affine span are proved equivalent: it is the `sInf` of affine subspaces containing the points, and (if `[Nontrivial k]`) it contains exactly those points that are affine combinations of points in the given set. ## Implementation notes `outParam` is used in the definition of `AddTorsor V P` to make `V` an implicit argument (deduced from `P`) in most cases. As for modules, `k` is an explicit argument rather than implied by `P` or `V`. This file only provides purely algebraic definitions and results. Those depending on analysis or topology are defined elsewhere; see `Analysis.NormedSpace.AddTorsor` and `Topology.Algebra.Affine`. ## References * https://en.wikipedia.org/wiki/Affine_space * https://en.wikipedia.org/wiki/Principal_homogeneous_space -/ noncomputable section open Affine open Set section variable (k : Type*) {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] variable [AffineSpace V P] /-- The submodule spanning the differences of a (possibly empty) set of points. -/ def vectorSpan (s : Set P) : Submodule k V := Submodule.span k (s -ᵥ s) #align vector_span vectorSpan /-- The definition of `vectorSpan`, for rewriting. -/ theorem vectorSpan_def (s : Set P) : vectorSpan k s = Submodule.span k (s -ᵥ s) := rfl #align vector_span_def vectorSpan_def /-- `vectorSpan` is monotone. -/ theorem vectorSpan_mono {s₁ s₂ : Set P} (h : s₁ ⊆ s₂) : vectorSpan k s₁ ≤ vectorSpan k s₂ := Submodule.span_mono (vsub_self_mono h) #align vector_span_mono vectorSpan_mono variable (P) /-- The `vectorSpan` of the empty set is `⊥`. -/ @[simp] theorem vectorSpan_empty : vectorSpan k (∅ : Set P) = (⊥ : Submodule k V) := by rw [vectorSpan_def, vsub_empty, Submodule.span_empty] #align vector_span_empty vectorSpan_empty variable {P} /-- The `vectorSpan` of a single point is `⊥`. -/ @[simp] theorem vectorSpan_singleton (p : P) : vectorSpan k ({p} : Set P) = ⊥ := by simp [vectorSpan_def] #align vector_span_singleton vectorSpan_singleton /-- The `s -ᵥ s` lies within the `vectorSpan k s`. -/ theorem vsub_set_subset_vectorSpan (s : Set P) : s -ᵥ s ⊆ ↑(vectorSpan k s) := Submodule.subset_span #align vsub_set_subset_vector_span vsub_set_subset_vectorSpan /-- Each pairwise difference is in the `vectorSpan`. -/ theorem vsub_mem_vectorSpan {s : Set P} {p1 p2 : P} (hp1 : p1 ∈ s) (hp2 : p2 ∈ s) : p1 -ᵥ p2 ∈ vectorSpan k s := vsub_set_subset_vectorSpan k s (vsub_mem_vsub hp1 hp2) #align vsub_mem_vector_span vsub_mem_vectorSpan /-- The points in the affine span of a (possibly empty) set of points. Use `affineSpan` instead to get an `AffineSubspace k P`. -/ def spanPoints (s : Set P) : Set P := { p | ∃ p1 ∈ s, ∃ v ∈ vectorSpan k s, p = v +ᵥ p1 } #align span_points spanPoints /-- A point in a set is in its affine span. -/ theorem mem_spanPoints (p : P) (s : Set P) : p ∈ s → p ∈ spanPoints k s | hp => ⟨p, hp, 0, Submodule.zero_mem _, (zero_vadd V p).symm⟩ #align mem_span_points mem_spanPoints /-- A set is contained in its `spanPoints`. -/ theorem subset_spanPoints (s : Set P) : s ⊆ spanPoints k s := fun p => mem_spanPoints k p s #align subset_span_points subset_spanPoints /-- The `spanPoints` of a set is nonempty if and only if that set is. -/ @[simp] theorem spanPoints_nonempty (s : Set P) : (spanPoints k s).Nonempty ↔ s.Nonempty := by constructor · contrapose rw [Set.not_nonempty_iff_eq_empty, Set.not_nonempty_iff_eq_empty] intro h simp [h, spanPoints] · exact fun h => h.mono (subset_spanPoints _ _) #align span_points_nonempty spanPoints_nonempty /-- Adding a point in the affine span and a vector in the spanning submodule produces a point in the affine span. -/ theorem vadd_mem_spanPoints_of_mem_spanPoints_of_mem_vectorSpan {s : Set P} {p : P} {v : V} (hp : p ∈ spanPoints k s) (hv : v ∈ vectorSpan k s) : v +ᵥ p ∈ spanPoints k s := by rcases hp with ⟨p2, ⟨hp2, ⟨v2, ⟨hv2, hv2p⟩⟩⟩⟩ rw [hv2p, vadd_vadd] exact ⟨p2, hp2, v + v2, (vectorSpan k s).add_mem hv hv2, rfl⟩ #align vadd_mem_span_points_of_mem_span_points_of_mem_vector_span vadd_mem_spanPoints_of_mem_spanPoints_of_mem_vectorSpan /-- Subtracting two points in the affine span produces a vector in the spanning submodule. -/ theorem vsub_mem_vectorSpan_of_mem_spanPoints_of_mem_spanPoints {s : Set P} {p1 p2 : P} (hp1 : p1 ∈ spanPoints k s) (hp2 : p2 ∈ spanPoints k s) : p1 -ᵥ p2 ∈ vectorSpan k s := by rcases hp1 with ⟨p1a, ⟨hp1a, ⟨v1, ⟨hv1, hv1p⟩⟩⟩⟩ rcases hp2 with ⟨p2a, ⟨hp2a, ⟨v2, ⟨hv2, hv2p⟩⟩⟩⟩ rw [hv1p, hv2p, vsub_vadd_eq_vsub_sub (v1 +ᵥ p1a), vadd_vsub_assoc, add_comm, add_sub_assoc] have hv1v2 : v1 - v2 ∈ vectorSpan k s := (vectorSpan k s).sub_mem hv1 hv2 refine (vectorSpan k s).add_mem ?_ hv1v2 exact vsub_mem_vectorSpan k hp1a hp2a #align vsub_mem_vector_span_of_mem_span_points_of_mem_span_points vsub_mem_vectorSpan_of_mem_spanPoints_of_mem_spanPoints end /-- An `AffineSubspace k P` is a subset of an `AffineSpace V P` that, if not empty, has an affine space structure induced by a corresponding subspace of the `Module k V`. -/ structure AffineSubspace (k : Type*) {V : Type*} (P : Type*) [Ring k] [AddCommGroup V] [Module k V] [AffineSpace V P] where /-- The affine subspace seen as a subset. -/ carrier : Set P smul_vsub_vadd_mem : ∀ (c : k) {p1 p2 p3 : P}, p1 ∈ carrier → p2 ∈ carrier → p3 ∈ carrier → c • (p1 -ᵥ p2 : V) +ᵥ p3 ∈ carrier #align affine_subspace AffineSubspace namespace Submodule variable {k V : Type*} [Ring k] [AddCommGroup V] [Module k V] /-- Reinterpret `p : Submodule k V` as an `AffineSubspace k V`. -/ def toAffineSubspace (p : Submodule k V) : AffineSubspace k V where carrier := p smul_vsub_vadd_mem _ _ _ _ h₁ h₂ h₃ := p.add_mem (p.smul_mem _ (p.sub_mem h₁ h₂)) h₃ #align submodule.to_affine_subspace Submodule.toAffineSubspace end Submodule namespace AffineSubspace variable (k : Type*) {V : Type*} (P : Type*) [Ring k] [AddCommGroup V] [Module k V] [AffineSpace V P] instance : SetLike (AffineSubspace k P) P where coe := carrier coe_injective' p q _ := by cases p; cases q; congr /-- A point is in an affine subspace coerced to a set if and only if it is in that affine subspace. -/ -- Porting note: removed `simp`, proof is `simp only [SetLike.mem_coe]` theorem mem_coe (p : P) (s : AffineSubspace k P) : p ∈ (s : Set P) ↔ p ∈ s := Iff.rfl #align affine_subspace.mem_coe AffineSubspace.mem_coe variable {k P} /-- The direction of an affine subspace is the submodule spanned by the pairwise differences of points. (Except in the case of an empty affine subspace, where the direction is the zero submodule, every vector in the direction is the difference of two points in the affine subspace.) -/ def direction (s : AffineSubspace k P) : Submodule k V := vectorSpan k (s : Set P) #align affine_subspace.direction AffineSubspace.direction /-- The direction equals the `vectorSpan`. -/ theorem direction_eq_vectorSpan (s : AffineSubspace k P) : s.direction = vectorSpan k (s : Set P) := rfl #align affine_subspace.direction_eq_vector_span AffineSubspace.direction_eq_vectorSpan /-- Alternative definition of the direction when the affine subspace is nonempty. This is defined so that the order on submodules (as used in the definition of `Submodule.span`) can be used in the proof of `coe_direction_eq_vsub_set`, and is not intended to be used beyond that proof. -/ def directionOfNonempty {s : AffineSubspace k P} (h : (s : Set P).Nonempty) : Submodule k V where carrier := (s : Set P) -ᵥ s zero_mem' := by cases' h with p hp exact vsub_self p ▸ vsub_mem_vsub hp hp add_mem' := by rintro _ _ ⟨p1, hp1, p2, hp2, rfl⟩ ⟨p3, hp3, p4, hp4, rfl⟩ rw [← vadd_vsub_assoc] refine vsub_mem_vsub ?_ hp4 convert s.smul_vsub_vadd_mem 1 hp1 hp2 hp3 rw [one_smul] smul_mem' := by rintro c _ ⟨p1, hp1, p2, hp2, rfl⟩ rw [← vadd_vsub (c • (p1 -ᵥ p2)) p2] refine vsub_mem_vsub ?_ hp2 exact s.smul_vsub_vadd_mem c hp1 hp2 hp2 #align affine_subspace.direction_of_nonempty AffineSubspace.directionOfNonempty /-- `direction_of_nonempty` gives the same submodule as `direction`. -/ theorem directionOfNonempty_eq_direction {s : AffineSubspace k P} (h : (s : Set P).Nonempty) : directionOfNonempty h = s.direction := by refine le_antisymm ?_ (Submodule.span_le.2 Set.Subset.rfl) rw [← SetLike.coe_subset_coe, directionOfNonempty, direction, Submodule.coe_set_mk, AddSubmonoid.coe_set_mk] exact vsub_set_subset_vectorSpan k _ #align affine_subspace.direction_of_nonempty_eq_direction AffineSubspace.directionOfNonempty_eq_direction /-- The set of vectors in the direction of a nonempty affine subspace is given by `vsub_set`. -/ theorem coe_direction_eq_vsub_set {s : AffineSubspace k P} (h : (s : Set P).Nonempty) : (s.direction : Set V) = (s : Set P) -ᵥ s := directionOfNonempty_eq_direction h ▸ rfl #align affine_subspace.coe_direction_eq_vsub_set AffineSubspace.coe_direction_eq_vsub_set /-- A vector is in the direction of a nonempty affine subspace if and only if it is the subtraction of two vectors in the subspace. -/ theorem mem_direction_iff_eq_vsub {s : AffineSubspace k P} (h : (s : Set P).Nonempty) (v : V) : v ∈ s.direction ↔ ∃ p1 ∈ s, ∃ p2 ∈ s, v = p1 -ᵥ p2 := by rw [← SetLike.mem_coe, coe_direction_eq_vsub_set h, Set.mem_vsub] simp only [SetLike.mem_coe, eq_comm] #align affine_subspace.mem_direction_iff_eq_vsub AffineSubspace.mem_direction_iff_eq_vsub /-- Adding a vector in the direction to a point in the subspace produces a point in the subspace. -/ theorem vadd_mem_of_mem_direction {s : AffineSubspace k P} {v : V} (hv : v ∈ s.direction) {p : P} (hp : p ∈ s) : v +ᵥ p ∈ s := by rw [mem_direction_iff_eq_vsub ⟨p, hp⟩] at hv rcases hv with ⟨p1, hp1, p2, hp2, hv⟩ rw [hv] convert s.smul_vsub_vadd_mem 1 hp1 hp2 hp rw [one_smul] exact s.mem_coe k P _ #align affine_subspace.vadd_mem_of_mem_direction AffineSubspace.vadd_mem_of_mem_direction /-- Subtracting two points in the subspace produces a vector in the direction. -/ theorem vsub_mem_direction {s : AffineSubspace k P} {p1 p2 : P} (hp1 : p1 ∈ s) (hp2 : p2 ∈ s) : p1 -ᵥ p2 ∈ s.direction := vsub_mem_vectorSpan k hp1 hp2 #align affine_subspace.vsub_mem_direction AffineSubspace.vsub_mem_direction /-- Adding a vector to a point in a subspace produces a point in the subspace if and only if the vector is in the direction. -/ theorem vadd_mem_iff_mem_direction {s : AffineSubspace k P} (v : V) {p : P} (hp : p ∈ s) : v +ᵥ p ∈ s ↔ v ∈ s.direction := ⟨fun h => by simpa using vsub_mem_direction h hp, fun h => vadd_mem_of_mem_direction h hp⟩ #align affine_subspace.vadd_mem_iff_mem_direction AffineSubspace.vadd_mem_iff_mem_direction /-- Adding a vector in the direction to a point produces a point in the subspace if and only if the original point is in the subspace. -/ theorem vadd_mem_iff_mem_of_mem_direction {s : AffineSubspace k P} {v : V} (hv : v ∈ s.direction) {p : P} : v +ᵥ p ∈ s ↔ p ∈ s := by refine ⟨fun h => ?_, fun h => vadd_mem_of_mem_direction hv h⟩ convert vadd_mem_of_mem_direction (Submodule.neg_mem _ hv) h simp #align affine_subspace.vadd_mem_iff_mem_of_mem_direction AffineSubspace.vadd_mem_iff_mem_of_mem_direction /-- Given a point in an affine subspace, the set of vectors in its direction equals the set of vectors subtracting that point on the right. -/ theorem coe_direction_eq_vsub_set_right {s : AffineSubspace k P} {p : P} (hp : p ∈ s) : (s.direction : Set V) = (· -ᵥ p) '' s := by rw [coe_direction_eq_vsub_set ⟨p, hp⟩] refine le_antisymm ?_ ?_ · rintro v ⟨p1, hp1, p2, hp2, rfl⟩ exact ⟨p1 -ᵥ p2 +ᵥ p, vadd_mem_of_mem_direction (vsub_mem_direction hp1 hp2) hp, vadd_vsub _ _⟩ · rintro v ⟨p2, hp2, rfl⟩ exact ⟨p2, hp2, p, hp, rfl⟩ #align affine_subspace.coe_direction_eq_vsub_set_right AffineSubspace.coe_direction_eq_vsub_set_right /-- Given a point in an affine subspace, the set of vectors in its direction equals the set of vectors subtracting that point on the left. -/ theorem coe_direction_eq_vsub_set_left {s : AffineSubspace k P} {p : P} (hp : p ∈ s) : (s.direction : Set V) = (p -ᵥ ·) '' s := by ext v rw [SetLike.mem_coe, ← Submodule.neg_mem_iff, ← SetLike.mem_coe, coe_direction_eq_vsub_set_right hp, Set.mem_image, Set.mem_image] conv_lhs => congr ext rw [← neg_vsub_eq_vsub_rev, neg_inj] #align affine_subspace.coe_direction_eq_vsub_set_left AffineSubspace.coe_direction_eq_vsub_set_left /-- Given a point in an affine subspace, a vector is in its direction if and only if it results from subtracting that point on the right. -/ theorem mem_direction_iff_eq_vsub_right {s : AffineSubspace k P} {p : P} (hp : p ∈ s) (v : V) : v ∈ s.direction ↔ ∃ p2 ∈ s, v = p2 -ᵥ p := by rw [← SetLike.mem_coe, coe_direction_eq_vsub_set_right hp] exact ⟨fun ⟨p2, hp2, hv⟩ => ⟨p2, hp2, hv.symm⟩, fun ⟨p2, hp2, hv⟩ => ⟨p2, hp2, hv.symm⟩⟩ #align affine_subspace.mem_direction_iff_eq_vsub_right AffineSubspace.mem_direction_iff_eq_vsub_right /-- Given a point in an affine subspace, a vector is in its direction if and only if it results from subtracting that point on the left. -/ theorem mem_direction_iff_eq_vsub_left {s : AffineSubspace k P} {p : P} (hp : p ∈ s) (v : V) : v ∈ s.direction ↔ ∃ p2 ∈ s, v = p -ᵥ p2 := by rw [← SetLike.mem_coe, coe_direction_eq_vsub_set_left hp] exact ⟨fun ⟨p2, hp2, hv⟩ => ⟨p2, hp2, hv.symm⟩, fun ⟨p2, hp2, hv⟩ => ⟨p2, hp2, hv.symm⟩⟩ #align affine_subspace.mem_direction_iff_eq_vsub_left AffineSubspace.mem_direction_iff_eq_vsub_left /-- Given a point in an affine subspace, a result of subtracting that point on the right is in the direction if and only if the other point is in the subspace. -/ theorem vsub_right_mem_direction_iff_mem {s : AffineSubspace k P} {p : P} (hp : p ∈ s) (p2 : P) : p2 -ᵥ p ∈ s.direction ↔ p2 ∈ s := by rw [mem_direction_iff_eq_vsub_right hp] simp #align affine_subspace.vsub_right_mem_direction_iff_mem AffineSubspace.vsub_right_mem_direction_iff_mem /-- Given a point in an affine subspace, a result of subtracting that point on the left is in the direction if and only if the other point is in the subspace. -/ theorem vsub_left_mem_direction_iff_mem {s : AffineSubspace k P} {p : P} (hp : p ∈ s) (p2 : P) : p -ᵥ p2 ∈ s.direction ↔ p2 ∈ s := by rw [mem_direction_iff_eq_vsub_left hp] simp #align affine_subspace.vsub_left_mem_direction_iff_mem AffineSubspace.vsub_left_mem_direction_iff_mem /-- Two affine subspaces are equal if they have the same points. -/ theorem coe_injective : Function.Injective ((↑) : AffineSubspace k P → Set P) := SetLike.coe_injective #align affine_subspace.coe_injective AffineSubspace.coe_injective @[ext] theorem ext {p q : AffineSubspace k P} (h : ∀ x, x ∈ p ↔ x ∈ q) : p = q := SetLike.ext h #align affine_subspace.ext AffineSubspace.ext -- Porting note: removed `simp`, proof is `simp only [SetLike.ext'_iff]` theorem ext_iff (s₁ s₂ : AffineSubspace k P) : (s₁ : Set P) = s₂ ↔ s₁ = s₂ := SetLike.ext'_iff.symm #align affine_subspace.ext_iff AffineSubspace.ext_iff /-- Two affine subspaces with the same direction and nonempty intersection are equal. -/ theorem ext_of_direction_eq {s1 s2 : AffineSubspace k P} (hd : s1.direction = s2.direction) (hn : ((s1 : Set P) ∩ s2).Nonempty) : s1 = s2 := by ext p have hq1 := Set.mem_of_mem_inter_left hn.some_mem have hq2 := Set.mem_of_mem_inter_right hn.some_mem constructor · intro hp rw [← vsub_vadd p hn.some] refine vadd_mem_of_mem_direction ?_ hq2 rw [← hd] exact vsub_mem_direction hp hq1 · intro hp rw [← vsub_vadd p hn.some] refine vadd_mem_of_mem_direction ?_ hq1 rw [hd] exact vsub_mem_direction hp hq2 #align affine_subspace.ext_of_direction_eq AffineSubspace.ext_of_direction_eq -- See note [reducible non instances] /-- This is not an instance because it loops with `AddTorsor.nonempty`. -/ abbrev toAddTorsor (s : AffineSubspace k P) [Nonempty s] : AddTorsor s.direction s where vadd a b := ⟨(a : V) +ᵥ (b : P), vadd_mem_of_mem_direction a.2 b.2⟩ zero_vadd := fun a => by ext exact zero_vadd _ _ add_vadd a b c := by ext apply add_vadd vsub a b := ⟨(a : P) -ᵥ (b : P), (vsub_left_mem_direction_iff_mem a.2 _).mpr b.2⟩ vsub_vadd' a b := by ext apply AddTorsor.vsub_vadd' vadd_vsub' a b := by ext apply AddTorsor.vadd_vsub' #align affine_subspace.to_add_torsor AffineSubspace.toAddTorsor attribute [local instance] toAddTorsor @[simp, norm_cast] theorem coe_vsub (s : AffineSubspace k P) [Nonempty s] (a b : s) : ↑(a -ᵥ b) = (a : P) -ᵥ (b : P) := rfl #align affine_subspace.coe_vsub AffineSubspace.coe_vsub @[simp, norm_cast] theorem coe_vadd (s : AffineSubspace k P) [Nonempty s] (a : s.direction) (b : s) : ↑(a +ᵥ b) = (a : V) +ᵥ (b : P) := rfl #align affine_subspace.coe_vadd AffineSubspace.coe_vadd /-- Embedding of an affine subspace to the ambient space, as an affine map. -/ protected def subtype (s : AffineSubspace k P) [Nonempty s] : s →ᵃ[k] P where toFun := (↑) linear := s.direction.subtype map_vadd' _ _ := rfl #align affine_subspace.subtype AffineSubspace.subtype @[simp] theorem subtype_linear (s : AffineSubspace k P) [Nonempty s] : s.subtype.linear = s.direction.subtype := rfl #align affine_subspace.subtype_linear AffineSubspace.subtype_linear theorem subtype_apply (s : AffineSubspace k P) [Nonempty s] (p : s) : s.subtype p = p := rfl #align affine_subspace.subtype_apply AffineSubspace.subtype_apply @[simp] theorem coeSubtype (s : AffineSubspace k P) [Nonempty s] : (s.subtype : s → P) = ((↑) : s → P) := rfl #align affine_subspace.coe_subtype AffineSubspace.coeSubtype theorem injective_subtype (s : AffineSubspace k P) [Nonempty s] : Function.Injective s.subtype := Subtype.coe_injective #align affine_subspace.injective_subtype AffineSubspace.injective_subtype /-- Two affine subspaces with nonempty intersection are equal if and only if their directions are equal. -/ theorem eq_iff_direction_eq_of_mem {s₁ s₂ : AffineSubspace k P} {p : P} (h₁ : p ∈ s₁) (h₂ : p ∈ s₂) : s₁ = s₂ ↔ s₁.direction = s₂.direction := ⟨fun h => h ▸ rfl, fun h => ext_of_direction_eq h ⟨p, h₁, h₂⟩⟩ #align affine_subspace.eq_iff_direction_eq_of_mem AffineSubspace.eq_iff_direction_eq_of_mem /-- Construct an affine subspace from a point and a direction. -/ def mk' (p : P) (direction : Submodule k V) : AffineSubspace k P where carrier := { q | ∃ v ∈ direction, q = v +ᵥ p } smul_vsub_vadd_mem c p1 p2 p3 hp1 hp2 hp3 := by rcases hp1 with ⟨v1, hv1, hp1⟩ rcases hp2 with ⟨v2, hv2, hp2⟩ rcases hp3 with ⟨v3, hv3, hp3⟩ use c • (v1 - v2) + v3, direction.add_mem (direction.smul_mem c (direction.sub_mem hv1 hv2)) hv3 simp [hp1, hp2, hp3, vadd_vadd] #align affine_subspace.mk' AffineSubspace.mk' /-- An affine subspace constructed from a point and a direction contains that point. -/ theorem self_mem_mk' (p : P) (direction : Submodule k V) : p ∈ mk' p direction := ⟨0, ⟨direction.zero_mem, (zero_vadd _ _).symm⟩⟩ #align affine_subspace.self_mem_mk' AffineSubspace.self_mem_mk' /-- An affine subspace constructed from a point and a direction contains the result of adding a vector in that direction to that point. -/ theorem vadd_mem_mk' {v : V} (p : P) {direction : Submodule k V} (hv : v ∈ direction) : v +ᵥ p ∈ mk' p direction := ⟨v, hv, rfl⟩ #align affine_subspace.vadd_mem_mk' AffineSubspace.vadd_mem_mk' /-- An affine subspace constructed from a point and a direction is nonempty. -/ theorem mk'_nonempty (p : P) (direction : Submodule k V) : (mk' p direction : Set P).Nonempty := ⟨p, self_mem_mk' p direction⟩ #align affine_subspace.mk'_nonempty AffineSubspace.mk'_nonempty /-- The direction of an affine subspace constructed from a point and a direction. -/ @[simp] theorem direction_mk' (p : P) (direction : Submodule k V) : (mk' p direction).direction = direction := by ext v rw [mem_direction_iff_eq_vsub (mk'_nonempty _ _)] constructor · rintro ⟨p1, ⟨v1, hv1, hp1⟩, p2, ⟨v2, hv2, hp2⟩, hv⟩ rw [hv, hp1, hp2, vadd_vsub_vadd_cancel_right] exact direction.sub_mem hv1 hv2 · exact fun hv => ⟨v +ᵥ p, vadd_mem_mk' _ hv, p, self_mem_mk' _ _, (vadd_vsub _ _).symm⟩ #align affine_subspace.direction_mk' AffineSubspace.direction_mk' /-- A point lies in an affine subspace constructed from another point and a direction if and only if their difference is in that direction. -/ theorem mem_mk'_iff_vsub_mem {p₁ p₂ : P} {direction : Submodule k V} : p₂ ∈ mk' p₁ direction ↔ p₂ -ᵥ p₁ ∈ direction := by refine ⟨fun h => ?_, fun h => ?_⟩ · rw [← direction_mk' p₁ direction] exact vsub_mem_direction h (self_mem_mk' _ _) · rw [← vsub_vadd p₂ p₁] exact vadd_mem_mk' p₁ h #align affine_subspace.mem_mk'_iff_vsub_mem AffineSubspace.mem_mk'_iff_vsub_mem /-- Constructing an affine subspace from a point in a subspace and that subspace's direction yields the original subspace. -/ @[simp] theorem mk'_eq {s : AffineSubspace k P} {p : P} (hp : p ∈ s) : mk' p s.direction = s := ext_of_direction_eq (direction_mk' p s.direction) ⟨p, Set.mem_inter (self_mem_mk' _ _) hp⟩ #align affine_subspace.mk'_eq AffineSubspace.mk'_eq /-- If an affine subspace contains a set of points, it contains the `spanPoints` of that set. -/ theorem spanPoints_subset_coe_of_subset_coe {s : Set P} {s1 : AffineSubspace k P} (h : s ⊆ s1) : spanPoints k s ⊆ s1 := by rintro p ⟨p1, hp1, v, hv, hp⟩ rw [hp] have hp1s1 : p1 ∈ (s1 : Set P) := Set.mem_of_mem_of_subset hp1 h refine vadd_mem_of_mem_direction ?_ hp1s1 have hs : vectorSpan k s ≤ s1.direction := vectorSpan_mono k h rw [SetLike.le_def] at hs rw [← SetLike.mem_coe] exact Set.mem_of_mem_of_subset hv hs #align affine_subspace.span_points_subset_coe_of_subset_coe AffineSubspace.spanPoints_subset_coe_of_subset_coe end AffineSubspace namespace Submodule variable {k V : Type*} [Ring k] [AddCommGroup V] [Module k V] @[simp] theorem mem_toAffineSubspace {p : Submodule k V} {x : V} : x ∈ p.toAffineSubspace ↔ x ∈ p := Iff.rfl @[simp] theorem toAffineSubspace_direction (s : Submodule k V) : s.toAffineSubspace.direction = s := by ext x; simp [← s.toAffineSubspace.vadd_mem_iff_mem_direction _ s.zero_mem] end Submodule theorem AffineMap.lineMap_mem {k V P : Type*} [Ring k] [AddCommGroup V] [Module k V] [AddTorsor V P] {Q : AffineSubspace k P} {p₀ p₁ : P} (c : k) (h₀ : p₀ ∈ Q) (h₁ : p₁ ∈ Q) : AffineMap.lineMap p₀ p₁ c ∈ Q := by rw [AffineMap.lineMap_apply] exact Q.smul_vsub_vadd_mem c h₁ h₀ h₀ #align affine_map.line_map_mem AffineMap.lineMap_mem section affineSpan variable (k : Type*) {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] [AffineSpace V P] /-- The affine span of a set of points is the smallest affine subspace containing those points. (Actually defined here in terms of spans in modules.) -/ def affineSpan (s : Set P) : AffineSubspace k P where carrier := spanPoints k s smul_vsub_vadd_mem c _ _ _ hp1 hp2 hp3 := vadd_mem_spanPoints_of_mem_spanPoints_of_mem_vectorSpan k hp3 ((vectorSpan k s).smul_mem c (vsub_mem_vectorSpan_of_mem_spanPoints_of_mem_spanPoints k hp1 hp2)) #align affine_span affineSpan /-- The affine span, converted to a set, is `spanPoints`. -/ @[simp] theorem coe_affineSpan (s : Set P) : (affineSpan k s : Set P) = spanPoints k s := rfl #align coe_affine_span coe_affineSpan /-- A set is contained in its affine span. -/ theorem subset_affineSpan (s : Set P) : s ⊆ affineSpan k s := subset_spanPoints k s #align subset_affine_span subset_affineSpan /-- The direction of the affine span is the `vectorSpan`. -/ theorem direction_affineSpan (s : Set P) : (affineSpan k s).direction = vectorSpan k s := by apply le_antisymm · refine Submodule.span_le.2 ?_ rintro v ⟨p1, ⟨p2, hp2, v1, hv1, hp1⟩, p3, ⟨p4, hp4, v2, hv2, hp3⟩, rfl⟩ simp only [SetLike.mem_coe] rw [hp1, hp3, vsub_vadd_eq_vsub_sub, vadd_vsub_assoc] exact (vectorSpan k s).sub_mem ((vectorSpan k s).add_mem hv1 (vsub_mem_vectorSpan k hp2 hp4)) hv2 · exact vectorSpan_mono k (subset_spanPoints k s) #align direction_affine_span direction_affineSpan /-- A point in a set is in its affine span. -/ theorem mem_affineSpan {p : P} {s : Set P} (hp : p ∈ s) : p ∈ affineSpan k s := mem_spanPoints k p s hp #align mem_affine_span mem_affineSpan end affineSpan namespace AffineSubspace variable {k : Type*} {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] [S : AffineSpace V P] instance : CompleteLattice (AffineSubspace k P) := { PartialOrder.lift ((↑) : AffineSubspace k P → Set P) coe_injective with sup := fun s1 s2 => affineSpan k (s1 ∪ s2) le_sup_left := fun s1 s2 => Set.Subset.trans Set.subset_union_left (subset_spanPoints k _) le_sup_right := fun s1 s2 => Set.Subset.trans Set.subset_union_right (subset_spanPoints k _) sup_le := fun s1 s2 s3 hs1 hs2 => spanPoints_subset_coe_of_subset_coe (Set.union_subset hs1 hs2) inf := fun s1 s2 => mk (s1 ∩ s2) fun c p1 p2 p3 hp1 hp2 hp3 => ⟨s1.smul_vsub_vadd_mem c hp1.1 hp2.1 hp3.1, s2.smul_vsub_vadd_mem c hp1.2 hp2.2 hp3.2⟩ inf_le_left := fun _ _ => Set.inter_subset_left inf_le_right := fun _ _ => Set.inter_subset_right le_sInf := fun S s1 hs1 => by -- Porting note: surely there is an easier way? refine Set.subset_sInter (t := (s1 : Set P)) ?_ rintro t ⟨s, _hs, rfl⟩ exact Set.subset_iInter (hs1 s) top := { carrier := Set.univ smul_vsub_vadd_mem := fun _ _ _ _ _ _ _ => Set.mem_univ _ } le_top := fun _ _ _ => Set.mem_univ _ bot := { carrier := ∅ smul_vsub_vadd_mem := fun _ _ _ _ => False.elim } bot_le := fun _ _ => False.elim sSup := fun s => affineSpan k (⋃ s' ∈ s, (s' : Set P)) sInf := fun s => mk (⋂ s' ∈ s, (s' : Set P)) fun c p1 p2 p3 hp1 hp2 hp3 => Set.mem_iInter₂.2 fun s2 hs2 => by rw [Set.mem_iInter₂] at * exact s2.smul_vsub_vadd_mem c (hp1 s2 hs2) (hp2 s2 hs2) (hp3 s2 hs2) le_sSup := fun _ _ h => Set.Subset.trans (Set.subset_biUnion_of_mem h) (subset_spanPoints k _) sSup_le := fun _ _ h => spanPoints_subset_coe_of_subset_coe (Set.iUnion₂_subset h) sInf_le := fun _ _ => Set.biInter_subset_of_mem le_inf := fun _ _ _ => Set.subset_inter } instance : Inhabited (AffineSubspace k P) := ⟨⊤⟩ /-- The `≤` order on subspaces is the same as that on the corresponding sets. -/ theorem le_def (s1 s2 : AffineSubspace k P) : s1 ≤ s2 ↔ (s1 : Set P) ⊆ s2 := Iff.rfl #align affine_subspace.le_def AffineSubspace.le_def /-- One subspace is less than or equal to another if and only if all its points are in the second subspace. -/ theorem le_def' (s1 s2 : AffineSubspace k P) : s1 ≤ s2 ↔ ∀ p ∈ s1, p ∈ s2 := Iff.rfl #align affine_subspace.le_def' AffineSubspace.le_def' /-- The `<` order on subspaces is the same as that on the corresponding sets. -/ theorem lt_def (s1 s2 : AffineSubspace k P) : s1 < s2 ↔ (s1 : Set P) ⊂ s2 := Iff.rfl #align affine_subspace.lt_def AffineSubspace.lt_def /-- One subspace is not less than or equal to another if and only if it has a point not in the second subspace. -/ theorem not_le_iff_exists (s1 s2 : AffineSubspace k P) : ¬s1 ≤ s2 ↔ ∃ p ∈ s1, p ∉ s2 := Set.not_subset #align affine_subspace.not_le_iff_exists AffineSubspace.not_le_iff_exists /-- If a subspace is less than another, there is a point only in the second. -/ theorem exists_of_lt {s1 s2 : AffineSubspace k P} (h : s1 < s2) : ∃ p ∈ s2, p ∉ s1 := Set.exists_of_ssubset h #align affine_subspace.exists_of_lt AffineSubspace.exists_of_lt /-- A subspace is less than another if and only if it is less than or equal to the second subspace and there is a point only in the second. -/ theorem lt_iff_le_and_exists (s1 s2 : AffineSubspace k P) : s1 < s2 ↔ s1 ≤ s2 ∧ ∃ p ∈ s2, p ∉ s1 := by rw [lt_iff_le_not_le, not_le_iff_exists] #align affine_subspace.lt_iff_le_and_exists AffineSubspace.lt_iff_le_and_exists /-- If an affine subspace is nonempty and contained in another with the same direction, they are equal. -/ theorem eq_of_direction_eq_of_nonempty_of_le {s₁ s₂ : AffineSubspace k P} (hd : s₁.direction = s₂.direction) (hn : (s₁ : Set P).Nonempty) (hle : s₁ ≤ s₂) : s₁ = s₂ := let ⟨p, hp⟩ := hn ext_of_direction_eq hd ⟨p, hp, hle hp⟩ #align affine_subspace.eq_of_direction_eq_of_nonempty_of_le AffineSubspace.eq_of_direction_eq_of_nonempty_of_le variable (k V) /-- The affine span is the `sInf` of subspaces containing the given points. -/ theorem affineSpan_eq_sInf (s : Set P) : affineSpan k s = sInf { s' : AffineSubspace k P | s ⊆ s' } := le_antisymm (spanPoints_subset_coe_of_subset_coe <| Set.subset_iInter₂ fun _ => id) (sInf_le (subset_spanPoints k _)) #align affine_subspace.affine_span_eq_Inf AffineSubspace.affineSpan_eq_sInf variable (P) /-- The Galois insertion formed by `affineSpan` and coercion back to a set. -/ protected def gi : GaloisInsertion (affineSpan k) ((↑) : AffineSubspace k P → Set P) where choice s _ := affineSpan k s gc s1 _s2 := ⟨fun h => Set.Subset.trans (subset_spanPoints k s1) h, spanPoints_subset_coe_of_subset_coe⟩ le_l_u _ := subset_spanPoints k _ choice_eq _ _ := rfl #align affine_subspace.gi AffineSubspace.gi /-- The span of the empty set is `⊥`. -/ @[simp] theorem span_empty : affineSpan k (∅ : Set P) = ⊥ := (AffineSubspace.gi k V P).gc.l_bot #align affine_subspace.span_empty AffineSubspace.span_empty /-- The span of `univ` is `⊤`. -/ @[simp] theorem span_univ : affineSpan k (Set.univ : Set P) = ⊤ := eq_top_iff.2 <| subset_spanPoints k _ #align affine_subspace.span_univ AffineSubspace.span_univ variable {k V P} theorem _root_.affineSpan_le {s : Set P} {Q : AffineSubspace k P} : affineSpan k s ≤ Q ↔ s ⊆ (Q : Set P) := (AffineSubspace.gi k V P).gc _ _ #align affine_span_le affineSpan_le variable (k V) {p₁ p₂ : P} /-- The affine span of a single point, coerced to a set, contains just that point. -/ @[simp 1001] -- Porting note: this needs to take priority over `coe_affineSpan` theorem coe_affineSpan_singleton (p : P) : (affineSpan k ({p} : Set P) : Set P) = {p} := by ext x rw [mem_coe, ← vsub_right_mem_direction_iff_mem (mem_affineSpan k (Set.mem_singleton p)) _, direction_affineSpan] simp #align affine_subspace.coe_affine_span_singleton AffineSubspace.coe_affineSpan_singleton /-- A point is in the affine span of a single point if and only if they are equal. -/ @[simp] theorem mem_affineSpan_singleton : p₁ ∈ affineSpan k ({p₂} : Set P) ↔ p₁ = p₂ := by simp [← mem_coe] #align affine_subspace.mem_affine_span_singleton AffineSubspace.mem_affineSpan_singleton @[simp] theorem preimage_coe_affineSpan_singleton (x : P) : ((↑) : affineSpan k ({x} : Set P) → P) ⁻¹' {x} = univ := eq_univ_of_forall fun y => (AffineSubspace.mem_affineSpan_singleton _ _).1 y.2 #align affine_subspace.preimage_coe_affine_span_singleton AffineSubspace.preimage_coe_affineSpan_singleton /-- The span of a union of sets is the sup of their spans. -/ theorem span_union (s t : Set P) : affineSpan k (s ∪ t) = affineSpan k s ⊔ affineSpan k t := (AffineSubspace.gi k V P).gc.l_sup #align affine_subspace.span_union AffineSubspace.span_union /-- The span of a union of an indexed family of sets is the sup of their spans. -/ theorem span_iUnion {ι : Type*} (s : ι → Set P) : affineSpan k (⋃ i, s i) = ⨆ i, affineSpan k (s i) := (AffineSubspace.gi k V P).gc.l_iSup #align affine_subspace.span_Union AffineSubspace.span_iUnion variable (P) /-- `⊤`, coerced to a set, is the whole set of points. -/ @[simp] theorem top_coe : ((⊤ : AffineSubspace k P) : Set P) = Set.univ := rfl #align affine_subspace.top_coe AffineSubspace.top_coe variable {P} /-- All points are in `⊤`. -/ @[simp] theorem mem_top (p : P) : p ∈ (⊤ : AffineSubspace k P) := Set.mem_univ p #align affine_subspace.mem_top AffineSubspace.mem_top variable (P) /-- The direction of `⊤` is the whole module as a submodule. -/ @[simp] theorem direction_top : (⊤ : AffineSubspace k P).direction = ⊤ := by cases' S.nonempty with p ext v refine ⟨imp_intro Submodule.mem_top, fun _hv => ?_⟩ have hpv : (v +ᵥ p -ᵥ p : V) ∈ (⊤ : AffineSubspace k P).direction := vsub_mem_direction (mem_top k V _) (mem_top k V _) rwa [vadd_vsub] at hpv #align affine_subspace.direction_top AffineSubspace.direction_top /-- `⊥`, coerced to a set, is the empty set. -/ @[simp] theorem bot_coe : ((⊥ : AffineSubspace k P) : Set P) = ∅ := rfl #align affine_subspace.bot_coe AffineSubspace.bot_coe theorem bot_ne_top : (⊥ : AffineSubspace k P) ≠ ⊤ := by intro contra rw [← ext_iff, bot_coe, top_coe] at contra exact Set.empty_ne_univ contra #align affine_subspace.bot_ne_top AffineSubspace.bot_ne_top instance : Nontrivial (AffineSubspace k P) := ⟨⟨⊥, ⊤, bot_ne_top k V P⟩⟩ theorem nonempty_of_affineSpan_eq_top {s : Set P} (h : affineSpan k s = ⊤) : s.Nonempty := by rw [Set.nonempty_iff_ne_empty] rintro rfl rw [AffineSubspace.span_empty] at h exact bot_ne_top k V P h #align affine_subspace.nonempty_of_affine_span_eq_top AffineSubspace.nonempty_of_affineSpan_eq_top /-- If the affine span of a set is `⊤`, then the vector span of the same set is the `⊤`. -/ theorem vectorSpan_eq_top_of_affineSpan_eq_top {s : Set P} (h : affineSpan k s = ⊤) : vectorSpan k s = ⊤ := by rw [← direction_affineSpan, h, direction_top] #align affine_subspace.vector_span_eq_top_of_affine_span_eq_top AffineSubspace.vectorSpan_eq_top_of_affineSpan_eq_top /-- For a nonempty set, the affine span is `⊤` iff its vector span is `⊤`. -/ theorem affineSpan_eq_top_iff_vectorSpan_eq_top_of_nonempty {s : Set P} (hs : s.Nonempty) : affineSpan k s = ⊤ ↔ vectorSpan k s = ⊤ := by refine ⟨vectorSpan_eq_top_of_affineSpan_eq_top k V P, ?_⟩ intro h suffices Nonempty (affineSpan k s) by obtain ⟨p, hp : p ∈ affineSpan k s⟩ := this rw [eq_iff_direction_eq_of_mem hp (mem_top k V p), direction_affineSpan, h, direction_top] obtain ⟨x, hx⟩ := hs exact ⟨⟨x, mem_affineSpan k hx⟩⟩ #align affine_subspace.affine_span_eq_top_iff_vector_span_eq_top_of_nonempty AffineSubspace.affineSpan_eq_top_iff_vectorSpan_eq_top_of_nonempty /-- For a non-trivial space, the affine span of a set is `⊤` iff its vector span is `⊤`. -/ theorem affineSpan_eq_top_iff_vectorSpan_eq_top_of_nontrivial {s : Set P} [Nontrivial P] : affineSpan k s = ⊤ ↔ vectorSpan k s = ⊤ := by rcases s.eq_empty_or_nonempty with hs | hs · simp [hs, subsingleton_iff_bot_eq_top, AddTorsor.subsingleton_iff V P, not_subsingleton] · rw [affineSpan_eq_top_iff_vectorSpan_eq_top_of_nonempty k V P hs] #align affine_subspace.affine_span_eq_top_iff_vector_span_eq_top_of_nontrivial AffineSubspace.affineSpan_eq_top_iff_vectorSpan_eq_top_of_nontrivial theorem card_pos_of_affineSpan_eq_top {ι : Type*} [Fintype ι] {p : ι → P} (h : affineSpan k (range p) = ⊤) : 0 < Fintype.card ι := by obtain ⟨-, ⟨i, -⟩⟩ := nonempty_of_affineSpan_eq_top k V P h exact Fintype.card_pos_iff.mpr ⟨i⟩ #align affine_subspace.card_pos_of_affine_span_eq_top AffineSubspace.card_pos_of_affineSpan_eq_top attribute [local instance] toAddTorsor /-- The top affine subspace is linearly equivalent to the affine space. This is the affine version of `Submodule.topEquiv`. -/ @[simps! linear apply symm_apply_coe] def topEquiv : (⊤ : AffineSubspace k P) ≃ᵃ[k] P where toEquiv := Equiv.Set.univ P linear := .ofEq _ _ (direction_top _ _ _) ≪≫ₗ Submodule.topEquiv map_vadd' _p _v := rfl variable {P} /-- No points are in `⊥`. -/ theorem not_mem_bot (p : P) : p ∉ (⊥ : AffineSubspace k P) := Set.not_mem_empty p #align affine_subspace.not_mem_bot AffineSubspace.not_mem_bot variable (P) /-- The direction of `⊥` is the submodule `⊥`. -/ @[simp] theorem direction_bot : (⊥ : AffineSubspace k P).direction = ⊥ := by rw [direction_eq_vectorSpan, bot_coe, vectorSpan_def, vsub_empty, Submodule.span_empty] #align affine_subspace.direction_bot AffineSubspace.direction_bot variable {k V P} @[simp] theorem coe_eq_bot_iff (Q : AffineSubspace k P) : (Q : Set P) = ∅ ↔ Q = ⊥ := coe_injective.eq_iff' (bot_coe _ _ _) #align affine_subspace.coe_eq_bot_iff AffineSubspace.coe_eq_bot_iff @[simp] theorem coe_eq_univ_iff (Q : AffineSubspace k P) : (Q : Set P) = univ ↔ Q = ⊤ := coe_injective.eq_iff' (top_coe _ _ _) #align affine_subspace.coe_eq_univ_iff AffineSubspace.coe_eq_univ_iff theorem nonempty_iff_ne_bot (Q : AffineSubspace k P) : (Q : Set P).Nonempty ↔ Q ≠ ⊥ := by rw [nonempty_iff_ne_empty] exact not_congr Q.coe_eq_bot_iff #align affine_subspace.nonempty_iff_ne_bot AffineSubspace.nonempty_iff_ne_bot theorem eq_bot_or_nonempty (Q : AffineSubspace k P) : Q = ⊥ ∨ (Q : Set P).Nonempty := by rw [nonempty_iff_ne_bot] apply eq_or_ne #align affine_subspace.eq_bot_or_nonempty AffineSubspace.eq_bot_or_nonempty theorem subsingleton_of_subsingleton_span_eq_top {s : Set P} (h₁ : s.Subsingleton) (h₂ : affineSpan k s = ⊤) : Subsingleton P := by obtain ⟨p, hp⟩ := AffineSubspace.nonempty_of_affineSpan_eq_top k V P h₂ have : s = {p} := Subset.antisymm (fun q hq => h₁ hq hp) (by simp [hp]) rw [this, ← AffineSubspace.ext_iff, AffineSubspace.coe_affineSpan_singleton, AffineSubspace.top_coe, eq_comm, ← subsingleton_iff_singleton (mem_univ _)] at h₂ exact subsingleton_of_univ_subsingleton h₂ #align affine_subspace.subsingleton_of_subsingleton_span_eq_top AffineSubspace.subsingleton_of_subsingleton_span_eq_top theorem eq_univ_of_subsingleton_span_eq_top {s : Set P} (h₁ : s.Subsingleton) (h₂ : affineSpan k s = ⊤) : s = (univ : Set P) := by obtain ⟨p, hp⟩ := AffineSubspace.nonempty_of_affineSpan_eq_top k V P h₂ have : s = {p} := Subset.antisymm (fun q hq => h₁ hq hp) (by simp [hp]) rw [this, eq_comm, ← subsingleton_iff_singleton (mem_univ p), subsingleton_univ_iff] exact subsingleton_of_subsingleton_span_eq_top h₁ h₂ #align affine_subspace.eq_univ_of_subsingleton_span_eq_top AffineSubspace.eq_univ_of_subsingleton_span_eq_top /-- A nonempty affine subspace is `⊤` if and only if its direction is `⊤`. -/ @[simp] theorem direction_eq_top_iff_of_nonempty {s : AffineSubspace k P} (h : (s : Set P).Nonempty) : s.direction = ⊤ ↔ s = ⊤ := by constructor · intro hd rw [← direction_top k V P] at hd refine ext_of_direction_eq hd ?_ simp [h] · rintro rfl simp #align affine_subspace.direction_eq_top_iff_of_nonempty AffineSubspace.direction_eq_top_iff_of_nonempty /-- The inf of two affine subspaces, coerced to a set, is the intersection of the two sets of points. -/ @[simp] theorem inf_coe (s1 s2 : AffineSubspace k P) : (s1 ⊓ s2 : Set P) = (s1 : Set P) ∩ s2 := rfl #align affine_subspace.inf_coe AffineSubspace.inf_coe /-- A point is in the inf of two affine subspaces if and only if it is in both of them. -/ theorem mem_inf_iff (p : P) (s1 s2 : AffineSubspace k P) : p ∈ s1 ⊓ s2 ↔ p ∈ s1 ∧ p ∈ s2 := Iff.rfl #align affine_subspace.mem_inf_iff AffineSubspace.mem_inf_iff /-- The direction of the inf of two affine subspaces is less than or equal to the inf of their directions. -/ theorem direction_inf (s1 s2 : AffineSubspace k P) : (s1 ⊓ s2).direction ≤ s1.direction ⊓ s2.direction := by simp only [direction_eq_vectorSpan, vectorSpan_def] exact le_inf (sInf_le_sInf fun p hp => trans (vsub_self_mono inter_subset_left) hp) (sInf_le_sInf fun p hp => trans (vsub_self_mono inter_subset_right) hp) #align affine_subspace.direction_inf AffineSubspace.direction_inf /-- If two affine subspaces have a point in common, the direction of their inf equals the inf of their directions. -/ theorem direction_inf_of_mem {s₁ s₂ : AffineSubspace k P} {p : P} (h₁ : p ∈ s₁) (h₂ : p ∈ s₂) : (s₁ ⊓ s₂).direction = s₁.direction ⊓ s₂.direction := by ext v rw [Submodule.mem_inf, ← vadd_mem_iff_mem_direction v h₁, ← vadd_mem_iff_mem_direction v h₂, ← vadd_mem_iff_mem_direction v ((mem_inf_iff p s₁ s₂).2 ⟨h₁, h₂⟩), mem_inf_iff] #align affine_subspace.direction_inf_of_mem AffineSubspace.direction_inf_of_mem /-- If two affine subspaces have a point in their inf, the direction of their inf equals the inf of their directions. -/ theorem direction_inf_of_mem_inf {s₁ s₂ : AffineSubspace k P} {p : P} (h : p ∈ s₁ ⊓ s₂) : (s₁ ⊓ s₂).direction = s₁.direction ⊓ s₂.direction := direction_inf_of_mem ((mem_inf_iff p s₁ s₂).1 h).1 ((mem_inf_iff p s₁ s₂).1 h).2 #align affine_subspace.direction_inf_of_mem_inf AffineSubspace.direction_inf_of_mem_inf /-- If one affine subspace is less than or equal to another, the same applies to their directions. -/ theorem direction_le {s1 s2 : AffineSubspace k P} (h : s1 ≤ s2) : s1.direction ≤ s2.direction := by simp only [direction_eq_vectorSpan, vectorSpan_def] exact vectorSpan_mono k h #align affine_subspace.direction_le AffineSubspace.direction_le /-- If one nonempty affine subspace is less than another, the same applies to their directions -/ theorem direction_lt_of_nonempty {s1 s2 : AffineSubspace k P} (h : s1 < s2) (hn : (s1 : Set P).Nonempty) : s1.direction < s2.direction := by cases' hn with p hp rw [lt_iff_le_and_exists] at h rcases h with ⟨hle, p2, hp2, hp2s1⟩ rw [SetLike.lt_iff_le_and_exists] use direction_le hle, p2 -ᵥ p, vsub_mem_direction hp2 (hle hp) intro hm rw [vsub_right_mem_direction_iff_mem hp p2] at hm exact hp2s1 hm #align affine_subspace.direction_lt_of_nonempty AffineSubspace.direction_lt_of_nonempty /-- The sup of the directions of two affine subspaces is less than or equal to the direction of their sup. -/ theorem sup_direction_le (s1 s2 : AffineSubspace k P) : s1.direction ⊔ s2.direction ≤ (s1 ⊔ s2).direction := by simp only [direction_eq_vectorSpan, vectorSpan_def] exact sup_le (sInf_le_sInf fun p hp => Set.Subset.trans (vsub_self_mono (le_sup_left : s1 ≤ s1 ⊔ s2)) hp) (sInf_le_sInf fun p hp => Set.Subset.trans (vsub_self_mono (le_sup_right : s2 ≤ s1 ⊔ s2)) hp) #align affine_subspace.sup_direction_le AffineSubspace.sup_direction_le /-- The sup of the directions of two nonempty affine subspaces with empty intersection is less than the direction of their sup. -/
Mathlib/LinearAlgebra/AffineSpace/AffineSubspace.lean
970
987
theorem sup_direction_lt_of_nonempty_of_inter_empty {s1 s2 : AffineSubspace k P} (h1 : (s1 : Set P).Nonempty) (h2 : (s2 : Set P).Nonempty) (he : (s1 ∩ s2 : Set P) = ∅) : s1.direction ⊔ s2.direction < (s1 ⊔ s2).direction := by
cases' h1 with p1 hp1 cases' h2 with p2 hp2 rw [SetLike.lt_iff_le_and_exists] use sup_direction_le s1 s2, p2 -ᵥ p1, vsub_mem_direction ((le_sup_right : s2 ≤ s1 ⊔ s2) hp2) ((le_sup_left : s1 ≤ s1 ⊔ s2) hp1) intro h rw [Submodule.mem_sup] at h rcases h with ⟨v1, hv1, v2, hv2, hv1v2⟩ rw [← sub_eq_zero, sub_eq_add_neg, neg_vsub_eq_vsub_rev, add_comm v1, add_assoc, ← vadd_vsub_assoc, ← neg_neg v2, add_comm, ← sub_eq_add_neg, ← vsub_vadd_eq_vsub_sub, vsub_eq_zero_iff_eq] at hv1v2 refine Set.Nonempty.ne_empty ?_ he use v1 +ᵥ p1, vadd_mem_of_mem_direction hv1 hp1 rw [hv1v2] exact vadd_mem_of_mem_direction (Submodule.neg_mem _ hv2) hp2
/- 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.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Field.Basic import Mathlib.Algebra.Order.Group.MinMax import Mathlib.Algebra.Ring.Pi import Mathlib.GroupTheory.GroupAction.Pi import Mathlib.GroupTheory.GroupAction.Ring import Mathlib.Init.Align import Mathlib.Tactic.GCongr import Mathlib.Tactic.Ring #align_import data.real.cau_seq from "leanprover-community/mathlib"@"9116dd6709f303dcf781632e15fdef382b0fc579" /-! # Cauchy sequences A basic theory of Cauchy sequences, used in the construction of the reals and p-adic numbers. Where applicable, lemmas that will be reused in other contexts have been stated in extra generality. There are other "versions" of Cauchyness in the library, in particular Cauchy filters in topology. This is a concrete implementation that is useful for simplicity and computability reasons. ## Important definitions * `IsCauSeq`: a predicate that says `f : ℕ → β` is Cauchy. * `CauSeq`: the type of Cauchy sequences valued in type `β` with respect to an absolute value function `abv`. ## Tags sequence, cauchy, abs val, absolute value -/ assert_not_exists Finset assert_not_exists Module assert_not_exists Submonoid assert_not_exists FloorRing variable {α β : Type*} open IsAbsoluteValue section variable [LinearOrderedField α] [Ring β] (abv : β → α) [IsAbsoluteValue abv] theorem rat_add_continuous_lemma {ε : α} (ε0 : 0 < ε) : ∃ δ > 0, ∀ {a₁ a₂ b₁ b₂ : β}, abv (a₁ - b₁) < δ → abv (a₂ - b₂) < δ → abv (a₁ + a₂ - (b₁ + b₂)) < ε := ⟨ε / 2, half_pos ε0, fun {a₁ a₂ b₁ b₂} h₁ h₂ => by simpa [add_halves, sub_eq_add_neg, add_comm, add_left_comm, add_assoc] using lt_of_le_of_lt (abv_add abv _ _) (add_lt_add h₁ h₂)⟩ #align rat_add_continuous_lemma rat_add_continuous_lemma theorem rat_mul_continuous_lemma {ε K₁ K₂ : α} (ε0 : 0 < ε) : ∃ δ > 0, ∀ {a₁ a₂ b₁ b₂ : β}, abv a₁ < K₁ → abv b₂ < K₂ → abv (a₁ - b₁) < δ → abv (a₂ - b₂) < δ → abv (a₁ * a₂ - b₁ * b₂) < ε := by have K0 : (0 : α) < max 1 (max K₁ K₂) := lt_of_lt_of_le zero_lt_one (le_max_left _ _) have εK := div_pos (half_pos ε0) K0 refine ⟨_, εK, fun {a₁ a₂ b₁ b₂} ha₁ hb₂ h₁ h₂ => ?_⟩ replace ha₁ := lt_of_lt_of_le ha₁ (le_trans (le_max_left _ K₂) (le_max_right 1 _)) replace hb₂ := lt_of_lt_of_le hb₂ (le_trans (le_max_right K₁ _) (le_max_right 1 _)) set M := max 1 (max K₁ K₂) have : abv (a₁ - b₁) * abv b₂ + abv (a₂ - b₂) * abv a₁ < ε / 2 / M * M + ε / 2 / M * M := by gcongr rw [← abv_mul abv, mul_comm, div_mul_cancel₀ _ (ne_of_gt K0), ← abv_mul abv, add_halves] at this simpa [sub_eq_add_neg, mul_add, add_mul, add_left_comm] using lt_of_le_of_lt (abv_add abv _ _) this #align rat_mul_continuous_lemma rat_mul_continuous_lemma theorem rat_inv_continuous_lemma {β : Type*} [DivisionRing β] (abv : β → α) [IsAbsoluteValue abv] {ε K : α} (ε0 : 0 < ε) (K0 : 0 < K) : ∃ δ > 0, ∀ {a b : β}, K ≤ abv a → K ≤ abv b → abv (a - b) < δ → abv (a⁻¹ - b⁻¹) < ε := by refine ⟨K * ε * K, mul_pos (mul_pos K0 ε0) K0, fun {a b} ha hb h => ?_⟩ have a0 := K0.trans_le ha have b0 := K0.trans_le hb rw [inv_sub_inv' ((abv_pos abv).1 a0) ((abv_pos abv).1 b0), abv_mul abv, abv_mul abv, abv_inv abv, abv_inv abv, abv_sub abv] refine lt_of_mul_lt_mul_left (lt_of_mul_lt_mul_right ?_ b0.le) a0.le rw [mul_assoc, inv_mul_cancel_right₀ b0.ne', ← mul_assoc, mul_inv_cancel a0.ne', one_mul] refine h.trans_le ?_ gcongr #align rat_inv_continuous_lemma rat_inv_continuous_lemma end /-- A sequence is Cauchy if the distance between its entries tends to zero. -/ def IsCauSeq {α : Type*} [LinearOrderedField α] {β : Type*} [Ring β] (abv : β → α) (f : ℕ → β) : Prop := ∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j - f i) < ε #align is_cau_seq IsCauSeq namespace IsCauSeq variable [LinearOrderedField α] [Ring β] {abv : β → α} [IsAbsoluteValue abv] {f g : ℕ → β} -- see Note [nolint_ge] --@[nolint ge_or_gt] -- Porting note: restore attribute theorem cauchy₂ (hf : IsCauSeq abv f) {ε : α} (ε0 : 0 < ε) : ∃ i, ∀ j ≥ i, ∀ k ≥ i, abv (f j - f k) < ε := by refine (hf _ (half_pos ε0)).imp fun i hi j ij k ik => ?_ rw [← add_halves ε] refine lt_of_le_of_lt (abv_sub_le abv _ _ _) (add_lt_add (hi _ ij) ?_) rw [abv_sub abv]; exact hi _ ik #align is_cau_seq.cauchy₂ IsCauSeq.cauchy₂ theorem cauchy₃ (hf : IsCauSeq abv f) {ε : α} (ε0 : 0 < ε) : ∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - f j) < ε := let ⟨i, H⟩ := hf.cauchy₂ ε0 ⟨i, fun _ ij _ jk => H _ (le_trans ij jk) _ ij⟩ #align is_cau_seq.cauchy₃ IsCauSeq.cauchy₃ lemma bounded (hf : IsCauSeq abv f) : ∃ r, ∀ i, abv (f i) < r := by obtain ⟨i, h⟩ := hf _ zero_lt_one set R : ℕ → α := @Nat.rec (fun _ => α) (abv (f 0)) fun i c => max c (abv (f i.succ)) with hR have : ∀ i, ∀ j ≤ i, abv (f j) ≤ R i := by refine Nat.rec (by simp [hR]) ?_ rintro i hi j (rfl | hj) · simp [R] · exact (hi j hj).trans (le_max_left _ _) refine ⟨R i + 1, fun j ↦ ?_⟩ obtain hji | hij := le_total j i · exact (this i _ hji).trans_lt (lt_add_one _) · simpa using (abv_add abv _ _).trans_lt $ add_lt_add_of_le_of_lt (this i _ le_rfl) (h _ hij) lemma bounded' (hf : IsCauSeq abv f) (x : α) : ∃ r > x, ∀ i, abv (f i) < r := let ⟨r, h⟩ := hf.bounded ⟨max r (x + 1), (lt_add_one x).trans_le (le_max_right _ _), fun i ↦ (h i).trans_le (le_max_left _ _)⟩ lemma const (x : β) : IsCauSeq abv fun _ ↦ x := fun ε ε0 ↦ ⟨0, fun j _ => by simpa [abv_zero] using ε0⟩ theorem add (hf : IsCauSeq abv f) (hg : IsCauSeq abv g) : IsCauSeq abv (f + g) := fun _ ε0 => let ⟨_, δ0, Hδ⟩ := rat_add_continuous_lemma abv ε0 let ⟨i, H⟩ := exists_forall_ge_and (hf.cauchy₃ δ0) (hg.cauchy₃ δ0) ⟨i, fun _ ij => let ⟨H₁, H₂⟩ := H _ le_rfl Hδ (H₁ _ ij) (H₂ _ ij)⟩ #align is_cau_seq.add IsCauSeq.add lemma mul (hf : IsCauSeq abv f) (hg : IsCauSeq abv g) : IsCauSeq abv (f * g) := fun _ ε0 => let ⟨_, _, hF⟩ := hf.bounded' 0 let ⟨_, _, hG⟩ := hg.bounded' 0 let ⟨_, δ0, Hδ⟩ := rat_mul_continuous_lemma abv ε0 let ⟨i, H⟩ := exists_forall_ge_and (hf.cauchy₃ δ0) (hg.cauchy₃ δ0) ⟨i, fun j ij => let ⟨H₁, H₂⟩ := H _ le_rfl Hδ (hF j) (hG i) (H₁ _ ij) (H₂ _ ij)⟩ @[simp] lemma _root_.isCauSeq_neg : IsCauSeq abv (-f) ↔ IsCauSeq abv f := by simp only [IsCauSeq, Pi.neg_apply, ← neg_sub', abv_neg] protected alias ⟨of_neg, neg⟩ := isCauSeq_neg end IsCauSeq /-- `CauSeq β abv` is the type of `β`-valued Cauchy sequences, with respect to the absolute value function `abv`. -/ def CauSeq {α : Type*} [LinearOrderedField α] (β : Type*) [Ring β] (abv : β → α) : Type _ := { f : ℕ → β // IsCauSeq abv f } #align cau_seq CauSeq namespace CauSeq variable [LinearOrderedField α] section Ring variable [Ring β] {abv : β → α} instance : CoeFun (CauSeq β abv) fun _ => ℕ → β := ⟨Subtype.val⟩ -- Porting note: Remove coeFn theorem /-@[simp] theorem mk_to_fun (f) (hf : IsCauSeq abv f) : @coeFn (CauSeq β abv) _ _ ⟨f, hf⟩ = f := rfl -/ #noalign cau_seq.mk_to_fun @[ext] theorem ext {f g : CauSeq β abv} (h : ∀ i, f i = g i) : f = g := Subtype.eq (funext h) #align cau_seq.ext CauSeq.ext theorem isCauSeq (f : CauSeq β abv) : IsCauSeq abv f := f.2 #align cau_seq.is_cau CauSeq.isCauSeq theorem cauchy (f : CauSeq β abv) : ∀ {ε}, 0 < ε → ∃ i, ∀ j ≥ i, abv (f j - f i) < ε := @f.2 #align cau_seq.cauchy CauSeq.cauchy /-- Given a Cauchy sequence `f`, create a Cauchy sequence from a sequence `g` with the same values as `f`. -/ def ofEq (f : CauSeq β abv) (g : ℕ → β) (e : ∀ i, f i = g i) : CauSeq β abv := ⟨g, fun ε => by rw [show g = f from (funext e).symm]; exact f.cauchy⟩ #align cau_seq.of_eq CauSeq.ofEq variable [IsAbsoluteValue abv] -- see Note [nolint_ge] -- @[nolint ge_or_gt] -- Porting note: restore attribute theorem cauchy₂ (f : CauSeq β abv) {ε} : 0 < ε → ∃ i, ∀ j ≥ i, ∀ k ≥ i, abv (f j - f k) < ε := f.2.cauchy₂ #align cau_seq.cauchy₂ CauSeq.cauchy₂ theorem cauchy₃ (f : CauSeq β abv) {ε} : 0 < ε → ∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - f j) < ε := f.2.cauchy₃ #align cau_seq.cauchy₃ CauSeq.cauchy₃ theorem bounded (f : CauSeq β abv) : ∃ r, ∀ i, abv (f i) < r := f.2.bounded #align cau_seq.bounded CauSeq.bounded theorem bounded' (f : CauSeq β abv) (x : α) : ∃ r > x, ∀ i, abv (f i) < r := f.2.bounded' x #align cau_seq.bounded' CauSeq.bounded' instance : Add (CauSeq β abv) := ⟨fun f g => ⟨f + g, f.2.add g.2⟩⟩ @[simp, norm_cast] theorem coe_add (f g : CauSeq β abv) : ⇑(f + g) = (f : ℕ → β) + g := rfl #align cau_seq.coe_add CauSeq.coe_add @[simp, norm_cast] theorem add_apply (f g : CauSeq β abv) (i : ℕ) : (f + g) i = f i + g i := rfl #align cau_seq.add_apply CauSeq.add_apply variable (abv) /-- The constant Cauchy sequence. -/ def const (x : β) : CauSeq β abv := ⟨fun _ ↦ x, IsCauSeq.const _⟩ #align cau_seq.const CauSeq.const variable {abv} /-- The constant Cauchy sequence -/ local notation "const" => const abv @[simp, norm_cast] theorem coe_const (x : β) : (const x : ℕ → β) = Function.const ℕ x := rfl #align cau_seq.coe_const CauSeq.coe_const @[simp, norm_cast] theorem const_apply (x : β) (i : ℕ) : (const x : ℕ → β) i = x := rfl #align cau_seq.const_apply CauSeq.const_apply theorem const_inj {x y : β} : (const x : CauSeq β abv) = const y ↔ x = y := ⟨fun h => congr_arg (fun f : CauSeq β abv => (f : ℕ → β) 0) h, congr_arg _⟩ #align cau_seq.const_inj CauSeq.const_inj instance : Zero (CauSeq β abv) := ⟨const 0⟩ instance : One (CauSeq β abv) := ⟨const 1⟩ instance : Inhabited (CauSeq β abv) := ⟨0⟩ @[simp, norm_cast] theorem coe_zero : ⇑(0 : CauSeq β abv) = 0 := rfl #align cau_seq.coe_zero CauSeq.coe_zero @[simp, norm_cast] theorem coe_one : ⇑(1 : CauSeq β abv) = 1 := rfl #align cau_seq.coe_one CauSeq.coe_one @[simp, norm_cast] theorem zero_apply (i) : (0 : CauSeq β abv) i = 0 := rfl #align cau_seq.zero_apply CauSeq.zero_apply @[simp, norm_cast] theorem one_apply (i) : (1 : CauSeq β abv) i = 1 := rfl #align cau_seq.one_apply CauSeq.one_apply @[simp] theorem const_zero : const 0 = 0 := rfl #align cau_seq.const_zero CauSeq.const_zero @[simp] theorem const_one : const 1 = 1 := rfl #align cau_seq.const_one CauSeq.const_one theorem const_add (x y : β) : const (x + y) = const x + const y := rfl #align cau_seq.const_add CauSeq.const_add instance : Mul (CauSeq β abv) := ⟨fun f g ↦ ⟨f * g, f.2.mul g.2⟩⟩ @[simp, norm_cast] theorem coe_mul (f g : CauSeq β abv) : ⇑(f * g) = (f : ℕ → β) * g := rfl #align cau_seq.coe_mul CauSeq.coe_mul @[simp, norm_cast] theorem mul_apply (f g : CauSeq β abv) (i : ℕ) : (f * g) i = f i * g i := rfl #align cau_seq.mul_apply CauSeq.mul_apply theorem const_mul (x y : β) : const (x * y) = const x * const y := rfl #align cau_seq.const_mul CauSeq.const_mul instance : Neg (CauSeq β abv) := ⟨fun f ↦ ⟨-f, f.2.neg⟩⟩ @[simp, norm_cast] theorem coe_neg (f : CauSeq β abv) : ⇑(-f) = -f := rfl #align cau_seq.coe_neg CauSeq.coe_neg @[simp, norm_cast] theorem neg_apply (f : CauSeq β abv) (i) : (-f) i = -f i := rfl #align cau_seq.neg_apply CauSeq.neg_apply theorem const_neg (x : β) : const (-x) = -const x := rfl #align cau_seq.const_neg CauSeq.const_neg instance : Sub (CauSeq β abv) := ⟨fun f g => ofEq (f + -g) (fun x => f x - g x) fun i => by simp [sub_eq_add_neg]⟩ @[simp, norm_cast] theorem coe_sub (f g : CauSeq β abv) : ⇑(f - g) = (f : ℕ → β) - g := rfl #align cau_seq.coe_sub CauSeq.coe_sub @[simp, norm_cast] theorem sub_apply (f g : CauSeq β abv) (i : ℕ) : (f - g) i = f i - g i := rfl #align cau_seq.sub_apply CauSeq.sub_apply theorem const_sub (x y : β) : const (x - y) = const x - const y := rfl #align cau_seq.const_sub CauSeq.const_sub section SMul variable {G : Type*} [SMul G β] [IsScalarTower G β β] instance : SMul G (CauSeq β abv) := ⟨fun a f => (ofEq (const (a • (1 : β)) * f) (a • (f : ℕ → β))) fun _ => smul_one_mul _ _⟩ @[simp, norm_cast] theorem coe_smul (a : G) (f : CauSeq β abv) : ⇑(a • f) = a • (f : ℕ → β) := rfl #align cau_seq.coe_smul CauSeq.coe_smul @[simp, norm_cast] theorem smul_apply (a : G) (f : CauSeq β abv) (i : ℕ) : (a • f) i = a • f i := rfl #align cau_seq.smul_apply CauSeq.smul_apply theorem const_smul (a : G) (x : β) : const (a • x) = a • const x := rfl #align cau_seq.const_smul CauSeq.const_smul instance : IsScalarTower G (CauSeq β abv) (CauSeq β abv) := ⟨fun a f g => Subtype.ext <| smul_assoc a (f : ℕ → β) (g : ℕ → β)⟩ end SMul instance addGroup : AddGroup (CauSeq β abv) := Function.Injective.addGroup Subtype.val Subtype.val_injective rfl coe_add coe_neg coe_sub (fun _ _ => coe_smul _ _) fun _ _ => coe_smul _ _ instance instNatCast : NatCast (CauSeq β abv) := ⟨fun n => const n⟩ instance instIntCast : IntCast (CauSeq β abv) := ⟨fun n => const n⟩ instance addGroupWithOne : AddGroupWithOne (CauSeq β abv) := Function.Injective.addGroupWithOne Subtype.val Subtype.val_injective rfl rfl coe_add coe_neg coe_sub (by intros; rfl) (by intros; rfl) (by intros; rfl) (by intros; rfl) instance : Pow (CauSeq β abv) ℕ := ⟨fun f n => (ofEq (npowRec n f) fun i => f i ^ n) <| by induction n <;> simp [*, npowRec, pow_succ]⟩ @[simp, norm_cast] theorem coe_pow (f : CauSeq β abv) (n : ℕ) : ⇑(f ^ n) = (f : ℕ → β) ^ n := rfl #align cau_seq.coe_pow CauSeq.coe_pow @[simp, norm_cast] theorem pow_apply (f : CauSeq β abv) (n i : ℕ) : (f ^ n) i = f i ^ n := rfl #align cau_seq.pow_apply CauSeq.pow_apply theorem const_pow (x : β) (n : ℕ) : const (x ^ n) = const x ^ n := rfl #align cau_seq.const_pow CauSeq.const_pow instance ring : Ring (CauSeq β abv) := Function.Injective.ring Subtype.val Subtype.val_injective rfl rfl coe_add coe_mul coe_neg coe_sub (fun _ _ => coe_smul _ _) (fun _ _ => coe_smul _ _) coe_pow (fun _ => rfl) fun _ => rfl instance {β : Type*} [CommRing β] {abv : β → α} [IsAbsoluteValue abv] : CommRing (CauSeq β abv) := { CauSeq.ring with mul_comm := fun a b => ext fun n => by simp [mul_left_comm, mul_comm] } /-- `LimZero f` holds when `f` approaches 0. -/ def LimZero {abv : β → α} (f : CauSeq β abv) : Prop := ∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j) < ε #align cau_seq.lim_zero CauSeq.LimZero theorem add_limZero {f g : CauSeq β abv} (hf : LimZero f) (hg : LimZero g) : LimZero (f + g) | ε, ε0 => (exists_forall_ge_and (hf _ <| half_pos ε0) (hg _ <| half_pos ε0)).imp fun i H j ij => by let ⟨H₁, H₂⟩ := H _ ij simpa [add_halves ε] using lt_of_le_of_lt (abv_add abv _ _) (add_lt_add H₁ H₂) #align cau_seq.add_lim_zero CauSeq.add_limZero theorem mul_limZero_right (f : CauSeq β abv) {g} (hg : LimZero g) : LimZero (f * g) | ε, ε0 => let ⟨F, F0, hF⟩ := f.bounded' 0 (hg _ <| div_pos ε0 F0).imp fun i H j ij => by have := mul_lt_mul' (le_of_lt <| hF j) (H _ ij) (abv_nonneg abv _) F0 rwa [mul_comm F, div_mul_cancel₀ _ (ne_of_gt F0), ← abv_mul] at this #align cau_seq.mul_lim_zero_right CauSeq.mul_limZero_right theorem mul_limZero_left {f} (g : CauSeq β abv) (hg : LimZero f) : LimZero (f * g) | ε, ε0 => let ⟨G, G0, hG⟩ := g.bounded' 0 (hg _ <| div_pos ε0 G0).imp fun i H j ij => by have := mul_lt_mul'' (H _ ij) (hG j) (abv_nonneg abv _) (abv_nonneg abv _) rwa [div_mul_cancel₀ _ (ne_of_gt G0), ← abv_mul] at this #align cau_seq.mul_lim_zero_left CauSeq.mul_limZero_left theorem neg_limZero {f : CauSeq β abv} (hf : LimZero f) : LimZero (-f) := by rw [← neg_one_mul f] exact mul_limZero_right _ hf #align cau_seq.neg_lim_zero CauSeq.neg_limZero theorem sub_limZero {f g : CauSeq β abv} (hf : LimZero f) (hg : LimZero g) : LimZero (f - g) := by simpa only [sub_eq_add_neg] using add_limZero hf (neg_limZero hg) #align cau_seq.sub_lim_zero CauSeq.sub_limZero
Mathlib/Algebra/Order/CauSeq/Basic.lean
455
456
theorem limZero_sub_rev {f g : CauSeq β abv} (hfg : LimZero (f - g)) : LimZero (g - f) := by
simpa using neg_limZero hfg
/- Copyright (c) 2023 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston, Joël Riou -/ import Mathlib.Algebra.Homology.ShortComplex.ModuleCat import Mathlib.RepresentationTheory.GroupCohomology.Basic import Mathlib.RepresentationTheory.Invariants /-! # The low-degree cohomology of a `k`-linear `G`-representation Let `k` be a commutative ring and `G` a group. This file gives simple expressions for the group cohomology of a `k`-linear `G`-representation `A` in degrees 0, 1 and 2. In `RepresentationTheory.GroupCohomology.Basic`, we define the `n`th group cohomology of `A` to be the cohomology of a complex `inhomogeneousCochains A`, whose objects are `(Fin n → G) → A`; this is unnecessarily unwieldy in low degree. Moreover, cohomology of a complex is defined as an abstract cokernel, whereas the definitions here are explicit quotients of cocycles by coboundaries. We also show that when the representation on `A` is trivial, `H¹(G, A) ≃ Hom(G, A)`. Given an additive or multiplicative abelian group `A` with an appropriate scalar action of `G`, we provide support for turning a function `f : G → A` satisfying the 1-cocycle identity into an element of the `oneCocycles` of the representation on `A` (or `Additive A`) corresponding to the scalar action. We also do this for 1-coboundaries, 2-cocycles and 2-coboundaries. The multiplicative case, starting with the section `IsMulCocycle`, just mirrors the additive case; unfortunately `@[to_additive]` can't deal with scalar actions. The file also contains an identification between the definitions in `RepresentationTheory.GroupCohomology.Basic`, `groupCohomology.cocycles A n` and `groupCohomology A n`, and the `nCocycles` and `Hn A` in this file, for `n = 0, 1, 2`. ## Main definitions * `groupCohomology.H0 A`: the invariants `Aᴳ` of the `G`-representation on `A`. * `groupCohomology.H1 A`: 1-cocycles (i.e. `Z¹(G, A) := Ker(d¹ : Fun(G, A) → Fun(G², A)`) modulo 1-coboundaries (i.e. `B¹(G, A) := Im(d⁰: A → Fun(G, A))`). * `groupCohomology.H2 A`: 2-cocycles (i.e. `Z²(G, A) := Ker(d² : Fun(G², A) → Fun(G³, A)`) modulo 2-coboundaries (i.e. `B²(G, A) := Im(d¹: Fun(G, A) → Fun(G², A))`). * `groupCohomology.H1LequivOfIsTrivial`: the isomorphism `H¹(G, A) ≃ Hom(G, A)` when the representation on `A` is trivial. * `groupCohomology.isoHn` for `n = 0, 1, 2`: an isomorphism `groupCohomology A n ≅ groupCohomology.Hn A`. ## TODO * The relationship between `H2` and group extensions * The inflation-restriction exact sequence * Nonabelian group cohomology -/ universe v u noncomputable section open CategoryTheory Limits Representation variable {k G : Type u} [CommRing k] [Group G] (A : Rep k G) namespace groupCohomology section Cochains /-- The 0th object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `A` as a `k`-module. -/ def zeroCochainsLequiv : (inhomogeneousCochains A).X 0 ≃ₗ[k] A := LinearEquiv.funUnique (Fin 0 → G) k A /-- The 1st object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `Fun(G, A)` as a `k`-module. -/ def oneCochainsLequiv : (inhomogeneousCochains A).X 1 ≃ₗ[k] G → A := LinearEquiv.funCongrLeft k A (Equiv.funUnique (Fin 1) G).symm /-- The 2nd object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `Fun(G², A)` as a `k`-module. -/ def twoCochainsLequiv : (inhomogeneousCochains A).X 2 ≃ₗ[k] G × G → A := LinearEquiv.funCongrLeft k A <| (piFinTwoEquiv fun _ => G).symm /-- The 3rd object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `Fun(G³, A)` as a `k`-module. -/ def threeCochainsLequiv : (inhomogeneousCochains A).X 3 ≃ₗ[k] G × G × G → A := LinearEquiv.funCongrLeft k A <| ((Equiv.piFinSucc 2 G).trans ((Equiv.refl G).prodCongr (piFinTwoEquiv fun _ => G))).symm end Cochains section Differentials /-- The 0th differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a `k`-linear map `A → Fun(G, A)`. It sends `(a, g) ↦ ρ_A(g)(a) - a.` -/ @[simps] def dZero : A →ₗ[k] G → A where toFun m g := A.ρ g m - m map_add' x y := funext fun g => by simp only [map_add, add_sub_add_comm]; rfl map_smul' r x := funext fun g => by dsimp; rw [map_smul, smul_sub] theorem dZero_ker_eq_invariants : LinearMap.ker (dZero A) = invariants A.ρ := by ext x simp only [LinearMap.mem_ker, mem_invariants, ← @sub_eq_zero _ _ _ x, Function.funext_iff] rfl @[simp] theorem dZero_eq_zero [A.IsTrivial] : dZero A = 0 := by ext simp only [dZero_apply, apply_eq_self, sub_self, LinearMap.zero_apply, Pi.zero_apply] /-- The 1st differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a `k`-linear map `Fun(G, A) → Fun(G × G, A)`. It sends `(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/ @[simps] def dOne : (G → A) →ₗ[k] G × G → A where toFun f g := A.ρ g.1 (f g.2) - f (g.1 * g.2) + f g.1 map_add' x y := funext fun g => by dsimp; rw [map_add, add_add_add_comm, add_sub_add_comm] map_smul' r x := funext fun g => by dsimp; rw [map_smul, smul_add, smul_sub] /-- The 2nd differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a `k`-linear map `Fun(G × G, A) → Fun(G × G × G, A)`. It sends `(f, (g₁, g₂, g₃)) ↦ ρ_A(g₁)(f(g₂, g₃)) - f(g₁g₂, g₃) + f(g₁, g₂g₃) - f(g₁, g₂).` -/ @[simps] def dTwo : (G × G → A) →ₗ[k] G × G × G → A where toFun f g := A.ρ g.1 (f (g.2.1, g.2.2)) - f (g.1 * g.2.1, g.2.2) + f (g.1, g.2.1 * g.2.2) - f (g.1, g.2.1) map_add' x y := funext fun g => by dsimp rw [map_add, add_sub_add_comm (A.ρ _ _), add_sub_assoc, add_sub_add_comm, add_add_add_comm, add_sub_assoc, add_sub_assoc] map_smul' r x := funext fun g => by dsimp; simp only [map_smul, smul_add, smul_sub] /-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma says `dZero` gives a simpler expression for the 0th differential: that is, the following square commutes: ``` C⁰(G, A) ---d⁰---> C¹(G, A) | | | | | | v v A ---- dZero ---> Fun(G, A) ``` where the vertical arrows are `zeroCochainsLequiv` and `oneCochainsLequiv` respectively. -/ theorem dZero_comp_eq : dZero A ∘ₗ (zeroCochainsLequiv A) = oneCochainsLequiv A ∘ₗ (inhomogeneousCochains A).d 0 1 := by ext x y show A.ρ y (x default) - x default = _ + ({0} : Finset _).sum _ simp_rw [Fin.coe_fin_one, zero_add, pow_one, neg_smul, one_smul, Finset.sum_singleton, sub_eq_add_neg] rcongr i <;> exact Fin.elim0 i /-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma says `dOne` gives a simpler expression for the 1st differential: that is, the following square commutes: ``` C¹(G, A) ---d¹-----> C²(G, A) | | | | | | v v Fun(G, A) -dOne-> Fun(G × G, A) ``` where the vertical arrows are `oneCochainsLequiv` and `twoCochainsLequiv` respectively. -/ theorem dOne_comp_eq : dOne A ∘ₗ oneCochainsLequiv A = twoCochainsLequiv A ∘ₗ (inhomogeneousCochains A).d 1 2 := by ext x y show A.ρ y.1 (x _) - x _ + x _ = _ + _ rw [Fin.sum_univ_two] simp only [Fin.val_zero, zero_add, pow_one, neg_smul, one_smul, Fin.val_one, Nat.one_add, neg_one_sq, sub_eq_add_neg, add_assoc] rcongr i <;> rw [Subsingleton.elim i 0] <;> rfl /-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma says `dTwo` gives a simpler expression for the 2nd differential: that is, the following square commutes: ``` C²(G, A) -------d²-----> C³(G, A) | | | | | | v v Fun(G × G, A) --dTwo--> Fun(G × G × G, A) ``` where the vertical arrows are `twoCochainsLequiv` and `threeCochainsLequiv` respectively. -/ theorem dTwo_comp_eq : dTwo A ∘ₗ twoCochainsLequiv A = threeCochainsLequiv A ∘ₗ (inhomogeneousCochains A).d 2 3 := by ext x y show A.ρ y.1 (x _) - x _ + x _ - x _ = _ + _ dsimp rw [Fin.sum_univ_three] simp only [sub_eq_add_neg, add_assoc, Fin.val_zero, zero_add, pow_one, neg_smul, one_smul, Fin.val_one, Fin.val_two, pow_succ' (-1 : k) 2, neg_sq, Nat.one_add, one_pow, mul_one] rcongr i <;> fin_cases i <;> rfl theorem dOne_comp_dZero : dOne A ∘ₗ dZero A = 0 := by ext x g simp only [LinearMap.coe_comp, Function.comp_apply, dOne_apply A, dZero_apply A, map_sub, map_mul, LinearMap.mul_apply, sub_sub_sub_cancel_left, sub_add_sub_cancel, sub_self] rfl
Mathlib/RepresentationTheory/GroupCohomology/LowDegree.lean
204
210
theorem dTwo_comp_dOne : dTwo A ∘ₗ dOne A = 0 := by
show ModuleCat.ofHom (dOne A) ≫ ModuleCat.ofHom (dTwo A) = _ have h1 : _ ≫ ModuleCat.ofHom (dOne A) = _ ≫ _ := congr_arg ModuleCat.ofHom (dOne_comp_eq A) have h2 : _ ≫ ModuleCat.ofHom (dTwo A) = _ ≫ _ := congr_arg ModuleCat.ofHom (dTwo_comp_eq A) simp only [← LinearEquiv.toModuleIso_hom] at h1 h2 simp only [(Iso.eq_inv_comp _).2 h2, (Iso.eq_inv_comp _).2 h1, Category.assoc, Iso.hom_inv_id_assoc, HomologicalComplex.d_comp_d_assoc, zero_comp, comp_zero]
/- Copyright (c) 2019 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Mario Carneiro, Isabel Longbottom, Scott Morrison -/ import Mathlib.Algebra.Order.ZeroLEOne import Mathlib.Data.List.InsertNth import Mathlib.Logic.Relation import Mathlib.Logic.Small.Defs import Mathlib.Order.GameAdd #align_import set_theory.game.pgame from "leanprover-community/mathlib"@"8900d545017cd21961daa2a1734bb658ef52c618" /-! # Combinatorial (pre-)games. The basic theory of combinatorial games, following Conway's book `On Numbers and Games`. We construct "pregames", define an ordering and arithmetic operations on them, then show that the operations descend to "games", defined via the equivalence relation `p ≈ q ↔ p ≤ q ∧ q ≤ p`. The surreal numbers will be built as a quotient of a subtype of pregames. A pregame (`SetTheory.PGame` below) is axiomatised via an inductive type, whose sole constructor takes two types (thought of as indexing the possible moves for the players Left and Right), and a pair of functions out of these types to `SetTheory.PGame` (thought of as describing the resulting game after making a move). Combinatorial games themselves, as a quotient of pregames, are constructed in `Game.lean`. ## Conway induction By construction, the induction principle for pregames is exactly "Conway induction". That is, to prove some predicate `SetTheory.PGame → Prop` holds for all pregames, it suffices to prove that for every pregame `g`, if the predicate holds for every game resulting from making a move, then it also holds for `g`. While it is often convenient to work "by induction" on pregames, in some situations this becomes awkward, so we also define accessor functions `SetTheory.PGame.LeftMoves`, `SetTheory.PGame.RightMoves`, `SetTheory.PGame.moveLeft` and `SetTheory.PGame.moveRight`. There is a relation `PGame.Subsequent p q`, saying that `p` can be reached by playing some non-empty sequence of moves starting from `q`, an instance `WellFounded Subsequent`, and a local tactic `pgame_wf_tac` which is helpful for discharging proof obligations in inductive proofs relying on this relation. ## Order properties Pregames have both a `≤` and a `<` relation, satisfying the usual properties of a `Preorder`. The relation `0 < x` means that `x` can always be won by Left, while `0 ≤ x` means that `x` can be won by Left as the second player. It turns out to be quite convenient to define various relations on top of these. We define the "less or fuzzy" relation `x ⧏ y` as `¬ y ≤ x`, the equivalence relation `x ≈ y` as `x ≤ y ∧ y ≤ x`, and the fuzzy relation `x ‖ y` as `x ⧏ y ∧ y ⧏ x`. If `0 ⧏ x`, then `x` can be won by Left as the first player. If `x ≈ 0`, then `x` can be won by the second player. If `x ‖ 0`, then `x` can be won by the first player. Statements like `zero_le_lf`, `zero_lf_le`, etc. unfold these definitions. The theorems `le_def` and `lf_def` give a recursive characterisation of each relation in terms of themselves two moves later. The theorems `zero_le`, `zero_lf`, etc. also take into account that `0` has no moves. Later, games will be defined as the quotient by the `≈` relation; that is to say, the `Antisymmetrization` of `SetTheory.PGame`. ## Algebraic structures We next turn to defining the operations necessary to make games into a commutative additive group. Addition is defined for $x = \{xL | xR\}$ and $y = \{yL | yR\}$ by $x + y = \{xL + y, x + yL | xR + y, x + yR\}$. Negation is defined by $\{xL | xR\} = \{-xR | -xL\}$. The order structures interact in the expected way with addition, so we have ``` theorem le_iff_sub_nonneg {x y : PGame} : x ≤ y ↔ 0 ≤ y - x := sorry theorem lt_iff_sub_pos {x y : PGame} : x < y ↔ 0 < y - x := sorry ``` We show that these operations respect the equivalence relation, and hence descend to games. At the level of games, these operations satisfy all the laws of a commutative group. To prove the necessary equivalence relations at the level of pregames, we introduce the notion of a `Relabelling` of a game, and show, for example, that there is a relabelling between `x + (y + z)` and `(x + y) + z`. ## Future work * The theory of dominated and reversible positions, and unique normal form for short games. * Analysis of basic domineering positions. * Hex. * Temperature. * The development of surreal numbers, based on this development of combinatorial games, is still quite incomplete. ## References The material here is all drawn from * [Conway, *On numbers and games*][conway2001] An interested reader may like to formalise some of the material from * [Andreas Blass, *A game semantics for linear logic*][MR1167694] * [André Joyal, *Remarques sur la théorie des jeux à deux personnes*][joyal1997] -/ set_option autoImplicit true namespace SetTheory open Function Relation -- We'd like to be able to use multi-character auto-implicits in this file. set_option relaxedAutoImplicit true /-! ### Pre-game moves -/ /-- The type of pre-games, before we have quotiented by equivalence (`PGame.Setoid`). In ZFC, a combinatorial game is constructed from two sets of combinatorial games that have been constructed at an earlier stage. To do this in type theory, we say that a pre-game is built inductively from two families of pre-games indexed over any type in Type u. The resulting type `PGame.{u}` lives in `Type (u+1)`, reflecting that it is a proper class in ZFC. -/ inductive PGame : Type (u + 1) | mk : ∀ α β : Type u, (α → PGame) → (β → PGame) → PGame #align pgame SetTheory.PGame compile_inductive% PGame namespace PGame /-- The indexing type for allowable moves by Left. -/ def LeftMoves : PGame → Type u | mk l _ _ _ => l #align pgame.left_moves SetTheory.PGame.LeftMoves /-- The indexing type for allowable moves by Right. -/ def RightMoves : PGame → Type u | mk _ r _ _ => r #align pgame.right_moves SetTheory.PGame.RightMoves /-- The new game after Left makes an allowed move. -/ def moveLeft : ∀ g : PGame, LeftMoves g → PGame | mk _l _ L _ => L #align pgame.move_left SetTheory.PGame.moveLeft /-- The new game after Right makes an allowed move. -/ def moveRight : ∀ g : PGame, RightMoves g → PGame | mk _ _r _ R => R #align pgame.move_right SetTheory.PGame.moveRight @[simp] theorem leftMoves_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).LeftMoves = xl := rfl #align pgame.left_moves_mk SetTheory.PGame.leftMoves_mk @[simp] theorem moveLeft_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).moveLeft = xL := rfl #align pgame.move_left_mk SetTheory.PGame.moveLeft_mk @[simp] theorem rightMoves_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).RightMoves = xr := rfl #align pgame.right_moves_mk SetTheory.PGame.rightMoves_mk @[simp] theorem moveRight_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).moveRight = xR := rfl #align pgame.move_right_mk SetTheory.PGame.moveRight_mk -- TODO define this at the level of games, as well, and perhaps also for finsets of games. /-- Construct a pre-game from list of pre-games describing the available moves for Left and Right. -/ def ofLists (L R : List PGame.{u}) : PGame.{u} := mk (ULift (Fin L.length)) (ULift (Fin R.length)) (fun i => L.get i.down) fun j ↦ R.get j.down #align pgame.of_lists SetTheory.PGame.ofLists theorem leftMoves_ofLists (L R : List PGame) : (ofLists L R).LeftMoves = ULift (Fin L.length) := rfl #align pgame.left_moves_of_lists SetTheory.PGame.leftMoves_ofLists theorem rightMoves_ofLists (L R : List PGame) : (ofLists L R).RightMoves = ULift (Fin R.length) := rfl #align pgame.right_moves_of_lists SetTheory.PGame.rightMoves_ofLists /-- Converts a number into a left move for `ofLists`. -/ def toOfListsLeftMoves {L R : List PGame} : Fin L.length ≃ (ofLists L R).LeftMoves := ((Equiv.cast (leftMoves_ofLists L R).symm).trans Equiv.ulift).symm #align pgame.to_of_lists_left_moves SetTheory.PGame.toOfListsLeftMoves /-- Converts a number into a right move for `ofLists`. -/ def toOfListsRightMoves {L R : List PGame} : Fin R.length ≃ (ofLists L R).RightMoves := ((Equiv.cast (rightMoves_ofLists L R).symm).trans Equiv.ulift).symm #align pgame.to_of_lists_right_moves SetTheory.PGame.toOfListsRightMoves theorem ofLists_moveLeft {L R : List PGame} (i : Fin L.length) : (ofLists L R).moveLeft (toOfListsLeftMoves i) = L.get i := rfl #align pgame.of_lists_move_left SetTheory.PGame.ofLists_moveLeft @[simp] theorem ofLists_moveLeft' {L R : List PGame} (i : (ofLists L R).LeftMoves) : (ofLists L R).moveLeft i = L.get (toOfListsLeftMoves.symm i) := rfl #align pgame.of_lists_move_left' SetTheory.PGame.ofLists_moveLeft' theorem ofLists_moveRight {L R : List PGame} (i : Fin R.length) : (ofLists L R).moveRight (toOfListsRightMoves i) = R.get i := rfl #align pgame.of_lists_move_right SetTheory.PGame.ofLists_moveRight @[simp] theorem ofLists_moveRight' {L R : List PGame} (i : (ofLists L R).RightMoves) : (ofLists L R).moveRight i = R.get (toOfListsRightMoves.symm i) := rfl #align pgame.of_lists_move_right' SetTheory.PGame.ofLists_moveRight' /-- A variant of `PGame.recOn` expressed in terms of `PGame.moveLeft` and `PGame.moveRight`. Both this and `PGame.recOn` describe Conway induction on games. -/ @[elab_as_elim] def moveRecOn {C : PGame → Sort*} (x : PGame) (IH : ∀ y : PGame, (∀ i, C (y.moveLeft i)) → (∀ j, C (y.moveRight j)) → C y) : C x := x.recOn fun yl yr yL yR => IH (mk yl yr yL yR) #align pgame.move_rec_on SetTheory.PGame.moveRecOn /-- `IsOption x y` means that `x` is either a left or right option for `y`. -/ @[mk_iff] inductive IsOption : PGame → PGame → Prop | moveLeft {x : PGame} (i : x.LeftMoves) : IsOption (x.moveLeft i) x | moveRight {x : PGame} (i : x.RightMoves) : IsOption (x.moveRight i) x #align pgame.is_option SetTheory.PGame.IsOption theorem IsOption.mk_left {xl xr : Type u} (xL : xl → PGame) (xR : xr → PGame) (i : xl) : (xL i).IsOption (mk xl xr xL xR) := @IsOption.moveLeft (mk _ _ _ _) i #align pgame.is_option.mk_left SetTheory.PGame.IsOption.mk_left theorem IsOption.mk_right {xl xr : Type u} (xL : xl → PGame) (xR : xr → PGame) (i : xr) : (xR i).IsOption (mk xl xr xL xR) := @IsOption.moveRight (mk _ _ _ _) i #align pgame.is_option.mk_right SetTheory.PGame.IsOption.mk_right theorem wf_isOption : WellFounded IsOption := ⟨fun x => moveRecOn x fun x IHl IHr => Acc.intro x fun y h => by induction' h with _ i _ j · exact IHl i · exact IHr j⟩ #align pgame.wf_is_option SetTheory.PGame.wf_isOption /-- `Subsequent x y` says that `x` can be obtained by playing some nonempty sequence of moves from `y`. It is the transitive closure of `IsOption`. -/ def Subsequent : PGame → PGame → Prop := TransGen IsOption #align pgame.subsequent SetTheory.PGame.Subsequent instance : IsTrans _ Subsequent := inferInstanceAs <| IsTrans _ (TransGen _) @[trans] theorem Subsequent.trans {x y z} : Subsequent x y → Subsequent y z → Subsequent x z := TransGen.trans #align pgame.subsequent.trans SetTheory.PGame.Subsequent.trans theorem wf_subsequent : WellFounded Subsequent := wf_isOption.transGen #align pgame.wf_subsequent SetTheory.PGame.wf_subsequent instance : WellFoundedRelation PGame := ⟨_, wf_subsequent⟩ @[simp] theorem Subsequent.moveLeft {x : PGame} (i : x.LeftMoves) : Subsequent (x.moveLeft i) x := TransGen.single (IsOption.moveLeft i) #align pgame.subsequent.move_left SetTheory.PGame.Subsequent.moveLeft @[simp] theorem Subsequent.moveRight {x : PGame} (j : x.RightMoves) : Subsequent (x.moveRight j) x := TransGen.single (IsOption.moveRight j) #align pgame.subsequent.move_right SetTheory.PGame.Subsequent.moveRight @[simp] theorem Subsequent.mk_left {xl xr} (xL : xl → PGame) (xR : xr → PGame) (i : xl) : Subsequent (xL i) (mk xl xr xL xR) := @Subsequent.moveLeft (mk _ _ _ _) i #align pgame.subsequent.mk_left SetTheory.PGame.Subsequent.mk_left @[simp] theorem Subsequent.mk_right {xl xr} (xL : xl → PGame) (xR : xr → PGame) (j : xr) : Subsequent (xR j) (mk xl xr xL xR) := @Subsequent.moveRight (mk _ _ _ _) j #align pgame.subsequent.mk_right SetTheory.PGame.Subsequent.mk_right /-- Discharges proof obligations of the form `⊢ Subsequent ..` arising in termination proofs of definitions using well-founded recursion on `PGame`. -/ macro "pgame_wf_tac" : tactic => `(tactic| solve_by_elim (config := { maxDepth := 8 }) [Prod.Lex.left, Prod.Lex.right, PSigma.Lex.left, PSigma.Lex.right, Subsequent.moveLeft, Subsequent.moveRight, Subsequent.mk_left, Subsequent.mk_right, Subsequent.trans] ) -- Register some consequences of pgame_wf_tac as simp-lemmas for convenience -- (which are applied by default for WF goals) -- This is different from mk_right from the POV of the simplifier, -- because the unifier can't solve `xr =?= RightMoves (mk xl xr xL xR)` at reducible transparency. @[simp] theorem Subsequent.mk_right' (xL : xl → PGame) (xR : xr → PGame) (j : RightMoves (mk xl xr xL xR)) : Subsequent (xR j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveRight_mk_left (xL : xl → PGame) (j) : Subsequent ((xL i).moveRight j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveRight_mk_right (xR : xr → PGame) (j) : Subsequent ((xR i).moveRight j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveLeft_mk_left (xL : xl → PGame) (j) : Subsequent ((xL i).moveLeft j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveLeft_mk_right (xR : xr → PGame) (j) : Subsequent ((xR i).moveLeft j) (mk xl xr xL xR) := by pgame_wf_tac -- Porting note: linter claims these lemmas don't simplify? open Subsequent in attribute [nolint simpNF] mk_left mk_right mk_right' moveRight_mk_left moveRight_mk_right moveLeft_mk_left moveLeft_mk_right /-! ### Basic pre-games -/ /-- The pre-game `Zero` is defined by `0 = { | }`. -/ instance : Zero PGame := ⟨⟨PEmpty, PEmpty, PEmpty.elim, PEmpty.elim⟩⟩ @[simp] theorem zero_leftMoves : LeftMoves 0 = PEmpty := rfl #align pgame.zero_left_moves SetTheory.PGame.zero_leftMoves @[simp] theorem zero_rightMoves : RightMoves 0 = PEmpty := rfl #align pgame.zero_right_moves SetTheory.PGame.zero_rightMoves instance isEmpty_zero_leftMoves : IsEmpty (LeftMoves 0) := instIsEmptyPEmpty #align pgame.is_empty_zero_left_moves SetTheory.PGame.isEmpty_zero_leftMoves instance isEmpty_zero_rightMoves : IsEmpty (RightMoves 0) := instIsEmptyPEmpty #align pgame.is_empty_zero_right_moves SetTheory.PGame.isEmpty_zero_rightMoves instance : Inhabited PGame := ⟨0⟩ /-- The pre-game `One` is defined by `1 = { 0 | }`. -/ instance instOnePGame : One PGame := ⟨⟨PUnit, PEmpty, fun _ => 0, PEmpty.elim⟩⟩ @[simp] theorem one_leftMoves : LeftMoves 1 = PUnit := rfl #align pgame.one_left_moves SetTheory.PGame.one_leftMoves @[simp] theorem one_moveLeft (x) : moveLeft 1 x = 0 := rfl #align pgame.one_move_left SetTheory.PGame.one_moveLeft @[simp] theorem one_rightMoves : RightMoves 1 = PEmpty := rfl #align pgame.one_right_moves SetTheory.PGame.one_rightMoves instance uniqueOneLeftMoves : Unique (LeftMoves 1) := PUnit.unique #align pgame.unique_one_left_moves SetTheory.PGame.uniqueOneLeftMoves instance isEmpty_one_rightMoves : IsEmpty (RightMoves 1) := instIsEmptyPEmpty #align pgame.is_empty_one_right_moves SetTheory.PGame.isEmpty_one_rightMoves /-! ### Pre-game order relations -/ /-- The less or equal relation on pre-games. If `0 ≤ x`, then Left can win `x` as the second player. -/ instance le : LE PGame := ⟨Sym2.GameAdd.fix wf_isOption fun x y le => (∀ i, ¬le y (x.moveLeft i) (Sym2.GameAdd.snd_fst <| IsOption.moveLeft i)) ∧ ∀ j, ¬le (y.moveRight j) x (Sym2.GameAdd.fst_snd <| IsOption.moveRight j)⟩ /-- The less or fuzzy relation on pre-games. If `0 ⧏ x`, then Left can win `x` as the first player. -/ def LF (x y : PGame) : Prop := ¬y ≤ x #align pgame.lf SetTheory.PGame.LF @[inherit_doc] scoped infixl:50 " ⧏ " => PGame.LF @[simp] protected theorem not_le {x y : PGame} : ¬x ≤ y ↔ y ⧏ x := Iff.rfl #align pgame.not_le SetTheory.PGame.not_le @[simp] theorem not_lf {x y : PGame} : ¬x ⧏ y ↔ y ≤ x := Classical.not_not #align pgame.not_lf SetTheory.PGame.not_lf theorem _root_.LE.le.not_gf {x y : PGame} : x ≤ y → ¬y ⧏ x := not_lf.2 #align has_le.le.not_gf LE.le.not_gf theorem LF.not_ge {x y : PGame} : x ⧏ y → ¬y ≤ x := id #align pgame.lf.not_ge SetTheory.PGame.LF.not_ge /-- Definition of `x ≤ y` on pre-games, in terms of `⧏`. The ordering here is chosen so that `And.left` refer to moves by Left, and `And.right` refer to moves by Right. -/ theorem le_iff_forall_lf {x y : PGame} : x ≤ y ↔ (∀ i, x.moveLeft i ⧏ y) ∧ ∀ j, x ⧏ y.moveRight j := by unfold LE.le le simp only rw [Sym2.GameAdd.fix_eq] rfl #align pgame.le_iff_forall_lf SetTheory.PGame.le_iff_forall_lf /-- Definition of `x ≤ y` on pre-games built using the constructor. -/ @[simp] theorem mk_le_mk {xl xr xL xR yl yr yL yR} : mk xl xr xL xR ≤ mk yl yr yL yR ↔ (∀ i, xL i ⧏ mk yl yr yL yR) ∧ ∀ j, mk xl xr xL xR ⧏ yR j := le_iff_forall_lf #align pgame.mk_le_mk SetTheory.PGame.mk_le_mk theorem le_of_forall_lf {x y : PGame} (h₁ : ∀ i, x.moveLeft i ⧏ y) (h₂ : ∀ j, x ⧏ y.moveRight j) : x ≤ y := le_iff_forall_lf.2 ⟨h₁, h₂⟩ #align pgame.le_of_forall_lf SetTheory.PGame.le_of_forall_lf /-- Definition of `x ⧏ y` on pre-games, in terms of `≤`. The ordering here is chosen so that `or.inl` refer to moves by Left, and `or.inr` refer to moves by Right. -/ theorem lf_iff_exists_le {x y : PGame} : x ⧏ y ↔ (∃ i, x ≤ y.moveLeft i) ∨ ∃ j, x.moveRight j ≤ y := by rw [LF, le_iff_forall_lf, not_and_or] simp #align pgame.lf_iff_exists_le SetTheory.PGame.lf_iff_exists_le /-- Definition of `x ⧏ y` on pre-games built using the constructor. -/ @[simp] theorem mk_lf_mk {xl xr xL xR yl yr yL yR} : mk xl xr xL xR ⧏ mk yl yr yL yR ↔ (∃ i, mk xl xr xL xR ≤ yL i) ∨ ∃ j, xR j ≤ mk yl yr yL yR := lf_iff_exists_le #align pgame.mk_lf_mk SetTheory.PGame.mk_lf_mk theorem le_or_gf (x y : PGame) : x ≤ y ∨ y ⧏ x := by rw [← PGame.not_le] apply em #align pgame.le_or_gf SetTheory.PGame.le_or_gf theorem moveLeft_lf_of_le {x y : PGame} (h : x ≤ y) (i) : x.moveLeft i ⧏ y := (le_iff_forall_lf.1 h).1 i #align pgame.move_left_lf_of_le SetTheory.PGame.moveLeft_lf_of_le alias _root_.LE.le.moveLeft_lf := moveLeft_lf_of_le #align has_le.le.move_left_lf LE.le.moveLeft_lf theorem lf_moveRight_of_le {x y : PGame} (h : x ≤ y) (j) : x ⧏ y.moveRight j := (le_iff_forall_lf.1 h).2 j #align pgame.lf_move_right_of_le SetTheory.PGame.lf_moveRight_of_le alias _root_.LE.le.lf_moveRight := lf_moveRight_of_le #align has_le.le.lf_move_right LE.le.lf_moveRight theorem lf_of_moveRight_le {x y : PGame} {j} (h : x.moveRight j ≤ y) : x ⧏ y := lf_iff_exists_le.2 <| Or.inr ⟨j, h⟩ #align pgame.lf_of_move_right_le SetTheory.PGame.lf_of_moveRight_le theorem lf_of_le_moveLeft {x y : PGame} {i} (h : x ≤ y.moveLeft i) : x ⧏ y := lf_iff_exists_le.2 <| Or.inl ⟨i, h⟩ #align pgame.lf_of_le_move_left SetTheory.PGame.lf_of_le_moveLeft theorem lf_of_le_mk {xl xr xL xR y} : mk xl xr xL xR ≤ y → ∀ i, xL i ⧏ y := moveLeft_lf_of_le #align pgame.lf_of_le_mk SetTheory.PGame.lf_of_le_mk theorem lf_of_mk_le {x yl yr yL yR} : x ≤ mk yl yr yL yR → ∀ j, x ⧏ yR j := lf_moveRight_of_le #align pgame.lf_of_mk_le SetTheory.PGame.lf_of_mk_le theorem mk_lf_of_le {xl xr y j} (xL) {xR : xr → PGame} : xR j ≤ y → mk xl xr xL xR ⧏ y := @lf_of_moveRight_le (mk _ _ _ _) y j #align pgame.mk_lf_of_le SetTheory.PGame.mk_lf_of_le theorem lf_mk_of_le {x yl yr} {yL : yl → PGame} (yR) {i} : x ≤ yL i → x ⧏ mk yl yr yL yR := @lf_of_le_moveLeft x (mk _ _ _ _) i #align pgame.lf_mk_of_le SetTheory.PGame.lf_mk_of_le /- We prove that `x ≤ y → y ≤ z → x ≤ z` inductively, by also simultaneously proving its cyclic reorderings. This auxiliary lemma is used during said induction. -/ private theorem le_trans_aux {x y z : PGame} (h₁ : ∀ {i}, y ≤ z → z ≤ x.moveLeft i → y ≤ x.moveLeft i) (h₂ : ∀ {j}, z.moveRight j ≤ x → x ≤ y → z.moveRight j ≤ y) (hxy : x ≤ y) (hyz : y ≤ z) : x ≤ z := le_of_forall_lf (fun i => PGame.not_le.1 fun h => (h₁ hyz h).not_gf <| hxy.moveLeft_lf i) fun j => PGame.not_le.1 fun h => (h₂ h hxy).not_gf <| hyz.lf_moveRight j instance : Preorder PGame := { PGame.le with le_refl := fun x => by induction' x with _ _ _ _ IHl IHr exact le_of_forall_lf (fun i => lf_of_le_moveLeft (IHl i)) fun i => lf_of_moveRight_le (IHr i) le_trans := by suffices ∀ {x y z : PGame}, (x ≤ y → y ≤ z → x ≤ z) ∧ (y ≤ z → z ≤ x → y ≤ x) ∧ (z ≤ x → x ≤ y → z ≤ y) from fun x y z => this.1 intro x y z induction' x with xl xr xL xR IHxl IHxr generalizing y z induction' y with yl yr yL yR IHyl IHyr generalizing z induction' z with zl zr zL zR IHzl IHzr exact ⟨le_trans_aux (fun {i} => (IHxl i).2.1) fun {j} => (IHzr j).2.2, le_trans_aux (fun {i} => (IHyl i).2.2) fun {j} => (IHxr j).1, le_trans_aux (fun {i} => (IHzl i).1) fun {j} => (IHyr j).2.1⟩ lt := fun x y => x ≤ y ∧ x ⧏ y } theorem lt_iff_le_and_lf {x y : PGame} : x < y ↔ x ≤ y ∧ x ⧏ y := Iff.rfl #align pgame.lt_iff_le_and_lf SetTheory.PGame.lt_iff_le_and_lf theorem lt_of_le_of_lf {x y : PGame} (h₁ : x ≤ y) (h₂ : x ⧏ y) : x < y := ⟨h₁, h₂⟩ #align pgame.lt_of_le_of_lf SetTheory.PGame.lt_of_le_of_lf theorem lf_of_lt {x y : PGame} (h : x < y) : x ⧏ y := h.2 #align pgame.lf_of_lt SetTheory.PGame.lf_of_lt alias _root_.LT.lt.lf := lf_of_lt #align has_lt.lt.lf LT.lt.lf theorem lf_irrefl (x : PGame) : ¬x ⧏ x := le_rfl.not_gf #align pgame.lf_irrefl SetTheory.PGame.lf_irrefl instance : IsIrrefl _ (· ⧏ ·) := ⟨lf_irrefl⟩ @[trans] theorem lf_of_le_of_lf {x y z : PGame} (h₁ : x ≤ y) (h₂ : y ⧏ z) : x ⧏ z := by rw [← PGame.not_le] at h₂ ⊢ exact fun h₃ => h₂ (h₃.trans h₁) #align pgame.lf_of_le_of_lf SetTheory.PGame.lf_of_le_of_lf -- Porting note (#10754): added instance instance : Trans (· ≤ ·) (· ⧏ ·) (· ⧏ ·) := ⟨lf_of_le_of_lf⟩ @[trans] theorem lf_of_lf_of_le {x y z : PGame} (h₁ : x ⧏ y) (h₂ : y ≤ z) : x ⧏ z := by rw [← PGame.not_le] at h₁ ⊢ exact fun h₃ => h₁ (h₂.trans h₃) #align pgame.lf_of_lf_of_le SetTheory.PGame.lf_of_lf_of_le -- Porting note (#10754): added instance instance : Trans (· ⧏ ·) (· ≤ ·) (· ⧏ ·) := ⟨lf_of_lf_of_le⟩ alias _root_.LE.le.trans_lf := lf_of_le_of_lf #align has_le.le.trans_lf LE.le.trans_lf alias LF.trans_le := lf_of_lf_of_le #align pgame.lf.trans_le SetTheory.PGame.LF.trans_le @[trans] theorem lf_of_lt_of_lf {x y z : PGame} (h₁ : x < y) (h₂ : y ⧏ z) : x ⧏ z := h₁.le.trans_lf h₂ #align pgame.lf_of_lt_of_lf SetTheory.PGame.lf_of_lt_of_lf @[trans] theorem lf_of_lf_of_lt {x y z : PGame} (h₁ : x ⧏ y) (h₂ : y < z) : x ⧏ z := h₁.trans_le h₂.le #align pgame.lf_of_lf_of_lt SetTheory.PGame.lf_of_lf_of_lt alias _root_.LT.lt.trans_lf := lf_of_lt_of_lf #align has_lt.lt.trans_lf LT.lt.trans_lf alias LF.trans_lt := lf_of_lf_of_lt #align pgame.lf.trans_lt SetTheory.PGame.LF.trans_lt theorem moveLeft_lf {x : PGame} : ∀ i, x.moveLeft i ⧏ x := le_rfl.moveLeft_lf #align pgame.move_left_lf SetTheory.PGame.moveLeft_lf theorem lf_moveRight {x : PGame} : ∀ j, x ⧏ x.moveRight j := le_rfl.lf_moveRight #align pgame.lf_move_right SetTheory.PGame.lf_moveRight theorem lf_mk {xl xr} (xL : xl → PGame) (xR : xr → PGame) (i) : xL i ⧏ mk xl xr xL xR := @moveLeft_lf (mk _ _ _ _) i #align pgame.lf_mk SetTheory.PGame.lf_mk theorem mk_lf {xl xr} (xL : xl → PGame) (xR : xr → PGame) (j) : mk xl xr xL xR ⧏ xR j := @lf_moveRight (mk _ _ _ _) j #align pgame.mk_lf SetTheory.PGame.mk_lf /-- This special case of `PGame.le_of_forall_lf` is useful when dealing with surreals, where `<` is preferred over `⧏`. -/ theorem le_of_forall_lt {x y : PGame} (h₁ : ∀ i, x.moveLeft i < y) (h₂ : ∀ j, x < y.moveRight j) : x ≤ y := le_of_forall_lf (fun i => (h₁ i).lf) fun i => (h₂ i).lf #align pgame.le_of_forall_lt SetTheory.PGame.le_of_forall_lt /-- The definition of `x ≤ y` on pre-games, in terms of `≤` two moves later. -/ theorem le_def {x y : PGame} : x ≤ y ↔ (∀ i, (∃ i', x.moveLeft i ≤ y.moveLeft i') ∨ ∃ j, (x.moveLeft i).moveRight j ≤ y) ∧ ∀ j, (∃ i, x ≤ (y.moveRight j).moveLeft i) ∨ ∃ j', x.moveRight j' ≤ y.moveRight j := by rw [le_iff_forall_lf] conv => lhs simp only [lf_iff_exists_le] #align pgame.le_def SetTheory.PGame.le_def /-- The definition of `x ⧏ y` on pre-games, in terms of `⧏` two moves later. -/ theorem lf_def {x y : PGame} : x ⧏ y ↔ (∃ i, (∀ i', x.moveLeft i' ⧏ y.moveLeft i) ∧ ∀ j, x ⧏ (y.moveLeft i).moveRight j) ∨ ∃ j, (∀ i, (x.moveRight j).moveLeft i ⧏ y) ∧ ∀ j', x.moveRight j ⧏ y.moveRight j' := by rw [lf_iff_exists_le] conv => lhs simp only [le_iff_forall_lf] #align pgame.lf_def SetTheory.PGame.lf_def /-- The definition of `0 ≤ x` on pre-games, in terms of `0 ⧏`. -/ theorem zero_le_lf {x : PGame} : 0 ≤ x ↔ ∀ j, 0 ⧏ x.moveRight j := by rw [le_iff_forall_lf] simp #align pgame.zero_le_lf SetTheory.PGame.zero_le_lf /-- The definition of `x ≤ 0` on pre-games, in terms of `⧏ 0`. -/ theorem le_zero_lf {x : PGame} : x ≤ 0 ↔ ∀ i, x.moveLeft i ⧏ 0 := by rw [le_iff_forall_lf] simp #align pgame.le_zero_lf SetTheory.PGame.le_zero_lf /-- The definition of `0 ⧏ x` on pre-games, in terms of `0 ≤`. -/ theorem zero_lf_le {x : PGame} : 0 ⧏ x ↔ ∃ i, 0 ≤ x.moveLeft i := by rw [lf_iff_exists_le] simp #align pgame.zero_lf_le SetTheory.PGame.zero_lf_le /-- The definition of `x ⧏ 0` on pre-games, in terms of `≤ 0`. -/ theorem lf_zero_le {x : PGame} : x ⧏ 0 ↔ ∃ j, x.moveRight j ≤ 0 := by rw [lf_iff_exists_le] simp #align pgame.lf_zero_le SetTheory.PGame.lf_zero_le /-- The definition of `0 ≤ x` on pre-games, in terms of `0 ≤` two moves later. -/ theorem zero_le {x : PGame} : 0 ≤ x ↔ ∀ j, ∃ i, 0 ≤ (x.moveRight j).moveLeft i := by rw [le_def] simp #align pgame.zero_le SetTheory.PGame.zero_le /-- The definition of `x ≤ 0` on pre-games, in terms of `≤ 0` two moves later. -/ theorem le_zero {x : PGame} : x ≤ 0 ↔ ∀ i, ∃ j, (x.moveLeft i).moveRight j ≤ 0 := by rw [le_def] simp #align pgame.le_zero SetTheory.PGame.le_zero /-- The definition of `0 ⧏ x` on pre-games, in terms of `0 ⧏` two moves later. -/ theorem zero_lf {x : PGame} : 0 ⧏ x ↔ ∃ i, ∀ j, 0 ⧏ (x.moveLeft i).moveRight j := by rw [lf_def] simp #align pgame.zero_lf SetTheory.PGame.zero_lf /-- The definition of `x ⧏ 0` on pre-games, in terms of `⧏ 0` two moves later. -/ theorem lf_zero {x : PGame} : x ⧏ 0 ↔ ∃ j, ∀ i, (x.moveRight j).moveLeft i ⧏ 0 := by rw [lf_def] simp #align pgame.lf_zero SetTheory.PGame.lf_zero @[simp] theorem zero_le_of_isEmpty_rightMoves (x : PGame) [IsEmpty x.RightMoves] : 0 ≤ x := zero_le.2 isEmptyElim #align pgame.zero_le_of_is_empty_right_moves SetTheory.PGame.zero_le_of_isEmpty_rightMoves @[simp] theorem le_zero_of_isEmpty_leftMoves (x : PGame) [IsEmpty x.LeftMoves] : x ≤ 0 := le_zero.2 isEmptyElim #align pgame.le_zero_of_is_empty_left_moves SetTheory.PGame.le_zero_of_isEmpty_leftMoves /-- Given a game won by the right player when they play second, provide a response to any move by left. -/ noncomputable def rightResponse {x : PGame} (h : x ≤ 0) (i : x.LeftMoves) : (x.moveLeft i).RightMoves := Classical.choose <| (le_zero.1 h) i #align pgame.right_response SetTheory.PGame.rightResponse /-- Show that the response for right provided by `rightResponse` preserves the right-player-wins condition. -/ theorem rightResponse_spec {x : PGame} (h : x ≤ 0) (i : x.LeftMoves) : (x.moveLeft i).moveRight (rightResponse h i) ≤ 0 := Classical.choose_spec <| (le_zero.1 h) i #align pgame.right_response_spec SetTheory.PGame.rightResponse_spec /-- Given a game won by the left player when they play second, provide a response to any move by right. -/ noncomputable def leftResponse {x : PGame} (h : 0 ≤ x) (j : x.RightMoves) : (x.moveRight j).LeftMoves := Classical.choose <| (zero_le.1 h) j #align pgame.left_response SetTheory.PGame.leftResponse /-- Show that the response for left provided by `leftResponse` preserves the left-player-wins condition. -/ theorem leftResponse_spec {x : PGame} (h : 0 ≤ x) (j : x.RightMoves) : 0 ≤ (x.moveRight j).moveLeft (leftResponse h j) := Classical.choose_spec <| (zero_le.1 h) j #align pgame.left_response_spec SetTheory.PGame.leftResponse_spec #noalign pgame.upper_bound #noalign pgame.upper_bound_right_moves_empty #noalign pgame.le_upper_bound #noalign pgame.upper_bound_mem_upper_bounds /-- A small family of pre-games is bounded above. -/ lemma bddAbove_range_of_small [Small.{u} ι] (f : ι → PGame.{u}) : BddAbove (Set.range f) := by let x : PGame.{u} := ⟨Σ i, (f $ (equivShrink.{u} ι).symm i).LeftMoves, PEmpty, fun x ↦ moveLeft _ x.2, PEmpty.elim⟩ refine ⟨x, Set.forall_mem_range.2 fun i ↦ ?_⟩ rw [← (equivShrink ι).symm_apply_apply i, le_iff_forall_lf] simpa [x] using fun j ↦ @moveLeft_lf x ⟨equivShrink ι i, j⟩ /-- A small set of pre-games is bounded above. -/ lemma bddAbove_of_small (s : Set PGame.{u}) [Small.{u} s] : BddAbove s := by simpa using bddAbove_range_of_small (Subtype.val : s → PGame.{u}) #align pgame.bdd_above_of_small SetTheory.PGame.bddAbove_of_small #noalign pgame.lower_bound #noalign pgame.lower_bound_left_moves_empty #noalign pgame.lower_bound_le #noalign pgame.lower_bound_mem_lower_bounds /-- A small family of pre-games is bounded below. -/ lemma bddBelow_range_of_small [Small.{u} ι] (f : ι → PGame.{u}) : BddBelow (Set.range f) := by let x : PGame.{u} := ⟨PEmpty, Σ i, (f $ (equivShrink.{u} ι).symm i).RightMoves, PEmpty.elim, fun x ↦ moveRight _ x.2⟩ refine ⟨x, Set.forall_mem_range.2 fun i ↦ ?_⟩ rw [← (equivShrink ι).symm_apply_apply i, le_iff_forall_lf] simpa [x] using fun j ↦ @lf_moveRight x ⟨equivShrink ι i, j⟩ /-- A small set of pre-games is bounded below. -/ lemma bddBelow_of_small (s : Set PGame.{u}) [Small.{u} s] : BddBelow s := by simpa using bddBelow_range_of_small (Subtype.val : s → PGame.{u}) #align pgame.bdd_below_of_small SetTheory.PGame.bddBelow_of_small /-- The equivalence relation on pre-games. Two pre-games `x`, `y` are equivalent if `x ≤ y` and `y ≤ x`. If `x ≈ 0`, then the second player can always win `x`. -/ def Equiv (x y : PGame) : Prop := x ≤ y ∧ y ≤ x #align pgame.equiv SetTheory.PGame.Equiv -- Porting note: deleted the scoped notation due to notation overloading with the setoid -- instance and this causes the PGame.equiv docstring to not show up on hover. instance : IsEquiv _ PGame.Equiv where refl _ := ⟨le_rfl, le_rfl⟩ trans := fun _ _ _ ⟨xy, yx⟩ ⟨yz, zy⟩ => ⟨xy.trans yz, zy.trans yx⟩ symm _ _ := And.symm -- Porting note: moved the setoid instance from Basic.lean to here instance setoid : Setoid PGame := ⟨Equiv, refl, symm, Trans.trans⟩ #align pgame.setoid SetTheory.PGame.setoid theorem Equiv.le {x y : PGame} (h : x ≈ y) : x ≤ y := h.1 #align pgame.equiv.le SetTheory.PGame.Equiv.le theorem Equiv.ge {x y : PGame} (h : x ≈ y) : y ≤ x := h.2 #align pgame.equiv.ge SetTheory.PGame.Equiv.ge @[refl, simp] theorem equiv_rfl {x : PGame} : x ≈ x := refl x #align pgame.equiv_rfl SetTheory.PGame.equiv_rfl theorem equiv_refl (x : PGame) : x ≈ x := refl x #align pgame.equiv_refl SetTheory.PGame.equiv_refl @[symm] protected theorem Equiv.symm {x y : PGame} : (x ≈ y) → (y ≈ x) := symm #align pgame.equiv.symm SetTheory.PGame.Equiv.symm @[trans] protected theorem Equiv.trans {x y z : PGame} : (x ≈ y) → (y ≈ z) → (x ≈ z) := _root_.trans #align pgame.equiv.trans SetTheory.PGame.Equiv.trans protected theorem equiv_comm {x y : PGame} : (x ≈ y) ↔ (y ≈ x) := comm #align pgame.equiv_comm SetTheory.PGame.equiv_comm theorem equiv_of_eq {x y : PGame} (h : x = y) : x ≈ y := by subst h; rfl #align pgame.equiv_of_eq SetTheory.PGame.equiv_of_eq @[trans] theorem le_of_le_of_equiv {x y z : PGame} (h₁ : x ≤ y) (h₂ : y ≈ z) : x ≤ z := h₁.trans h₂.1 #align pgame.le_of_le_of_equiv SetTheory.PGame.le_of_le_of_equiv instance : Trans ((· ≤ ·) : PGame → PGame → Prop) ((· ≈ ·) : PGame → PGame → Prop) ((· ≤ ·) : PGame → PGame → Prop) where trans := le_of_le_of_equiv @[trans] theorem le_of_equiv_of_le {x y z : PGame} (h₁ : x ≈ y) : y ≤ z → x ≤ z := h₁.1.trans #align pgame.le_of_equiv_of_le SetTheory.PGame.le_of_equiv_of_le instance : Trans ((· ≈ ·) : PGame → PGame → Prop) ((· ≤ ·) : PGame → PGame → Prop) ((· ≤ ·) : PGame → PGame → Prop) where trans := le_of_equiv_of_le theorem LF.not_equiv {x y : PGame} (h : x ⧏ y) : ¬(x ≈ y) := fun h' => h.not_ge h'.2 #align pgame.lf.not_equiv SetTheory.PGame.LF.not_equiv theorem LF.not_equiv' {x y : PGame} (h : x ⧏ y) : ¬(y ≈ x) := fun h' => h.not_ge h'.1 #align pgame.lf.not_equiv' SetTheory.PGame.LF.not_equiv' theorem LF.not_gt {x y : PGame} (h : x ⧏ y) : ¬y < x := fun h' => h.not_ge h'.le #align pgame.lf.not_gt SetTheory.PGame.LF.not_gt theorem le_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) (h : x₁ ≤ y₁) : x₂ ≤ y₂ := hx.2.trans (h.trans hy.1) #align pgame.le_congr_imp SetTheory.PGame.le_congr_imp theorem le_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ≤ y₁ ↔ x₂ ≤ y₂ := ⟨le_congr_imp hx hy, le_congr_imp (Equiv.symm hx) (Equiv.symm hy)⟩ #align pgame.le_congr SetTheory.PGame.le_congr theorem le_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ ≤ y ↔ x₂ ≤ y := le_congr hx equiv_rfl #align pgame.le_congr_left SetTheory.PGame.le_congr_left theorem le_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x ≤ y₁ ↔ x ≤ y₂ := le_congr equiv_rfl hy #align pgame.le_congr_right SetTheory.PGame.le_congr_right theorem lf_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ⧏ y₁ ↔ x₂ ⧏ y₂ := PGame.not_le.symm.trans <| (not_congr (le_congr hy hx)).trans PGame.not_le #align pgame.lf_congr SetTheory.PGame.lf_congr theorem lf_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ⧏ y₁ → x₂ ⧏ y₂ := (lf_congr hx hy).1 #align pgame.lf_congr_imp SetTheory.PGame.lf_congr_imp theorem lf_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ ⧏ y ↔ x₂ ⧏ y := lf_congr hx equiv_rfl #align pgame.lf_congr_left SetTheory.PGame.lf_congr_left theorem lf_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x ⧏ y₁ ↔ x ⧏ y₂ := lf_congr equiv_rfl hy #align pgame.lf_congr_right SetTheory.PGame.lf_congr_right @[trans] theorem lf_of_lf_of_equiv {x y z : PGame} (h₁ : x ⧏ y) (h₂ : y ≈ z) : x ⧏ z := lf_congr_imp equiv_rfl h₂ h₁ #align pgame.lf_of_lf_of_equiv SetTheory.PGame.lf_of_lf_of_equiv @[trans] theorem lf_of_equiv_of_lf {x y z : PGame} (h₁ : x ≈ y) : y ⧏ z → x ⧏ z := lf_congr_imp (Equiv.symm h₁) equiv_rfl #align pgame.lf_of_equiv_of_lf SetTheory.PGame.lf_of_equiv_of_lf @[trans] theorem lt_of_lt_of_equiv {x y z : PGame} (h₁ : x < y) (h₂ : y ≈ z) : x < z := h₁.trans_le h₂.1 #align pgame.lt_of_lt_of_equiv SetTheory.PGame.lt_of_lt_of_equiv @[trans] theorem lt_of_equiv_of_lt {x y z : PGame} (h₁ : x ≈ y) : y < z → x < z := h₁.1.trans_lt #align pgame.lt_of_equiv_of_lt SetTheory.PGame.lt_of_equiv_of_lt instance : Trans ((· ≈ ·) : PGame → PGame → Prop) ((· < ·) : PGame → PGame → Prop) ((· < ·) : PGame → PGame → Prop) where trans := lt_of_equiv_of_lt theorem lt_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) (h : x₁ < y₁) : x₂ < y₂ := hx.2.trans_lt (h.trans_le hy.1) #align pgame.lt_congr_imp SetTheory.PGame.lt_congr_imp theorem lt_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ < y₁ ↔ x₂ < y₂ := ⟨lt_congr_imp hx hy, lt_congr_imp (Equiv.symm hx) (Equiv.symm hy)⟩ #align pgame.lt_congr SetTheory.PGame.lt_congr theorem lt_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ < y ↔ x₂ < y := lt_congr hx equiv_rfl #align pgame.lt_congr_left SetTheory.PGame.lt_congr_left theorem lt_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x < y₁ ↔ x < y₂ := lt_congr equiv_rfl hy #align pgame.lt_congr_right SetTheory.PGame.lt_congr_right theorem lt_or_equiv_of_le {x y : PGame} (h : x ≤ y) : x < y ∨ (x ≈ y) := and_or_left.mp ⟨h, (em <| y ≤ x).symm.imp_left PGame.not_le.1⟩ #align pgame.lt_or_equiv_of_le SetTheory.PGame.lt_or_equiv_of_le theorem lf_or_equiv_or_gf (x y : PGame) : x ⧏ y ∨ (x ≈ y) ∨ y ⧏ x := by by_cases h : x ⧏ y · exact Or.inl h · right cases' lt_or_equiv_of_le (PGame.not_lf.1 h) with h' h' · exact Or.inr h'.lf · exact Or.inl (Equiv.symm h') #align pgame.lf_or_equiv_or_gf SetTheory.PGame.lf_or_equiv_or_gf theorem equiv_congr_left {y₁ y₂ : PGame} : (y₁ ≈ y₂) ↔ ∀ x₁, (x₁ ≈ y₁) ↔ (x₁ ≈ y₂) := ⟨fun h _ => ⟨fun h' => Equiv.trans h' h, fun h' => Equiv.trans h' (Equiv.symm h)⟩, fun h => (h y₁).1 <| equiv_rfl⟩ #align pgame.equiv_congr_left SetTheory.PGame.equiv_congr_left theorem equiv_congr_right {x₁ x₂ : PGame} : (x₁ ≈ x₂) ↔ ∀ y₁, (x₁ ≈ y₁) ↔ (x₂ ≈ y₁) := ⟨fun h _ => ⟨fun h' => Equiv.trans (Equiv.symm h) h', fun h' => Equiv.trans h h'⟩, fun h => (h x₂).2 <| equiv_rfl⟩ #align pgame.equiv_congr_right SetTheory.PGame.equiv_congr_right theorem equiv_of_mk_equiv {x y : PGame} (L : x.LeftMoves ≃ y.LeftMoves) (R : x.RightMoves ≃ y.RightMoves) (hl : ∀ i, x.moveLeft i ≈ y.moveLeft (L i)) (hr : ∀ j, x.moveRight j ≈ y.moveRight (R j)) : x ≈ y := by constructor <;> rw [le_def] · exact ⟨fun i => Or.inl ⟨_, (hl i).1⟩, fun j => Or.inr ⟨_, by simpa using (hr (R.symm j)).1⟩⟩ · exact ⟨fun i => Or.inl ⟨_, by simpa using (hl (L.symm i)).2⟩, fun j => Or.inr ⟨_, (hr j).2⟩⟩ #align pgame.equiv_of_mk_equiv SetTheory.PGame.equiv_of_mk_equiv /-- The fuzzy, confused, or incomparable relation on pre-games. If `x ‖ 0`, then the first player can always win `x`. -/ def Fuzzy (x y : PGame) : Prop := x ⧏ y ∧ y ⧏ x #align pgame.fuzzy SetTheory.PGame.Fuzzy @[inherit_doc] scoped infixl:50 " ‖ " => PGame.Fuzzy @[symm] theorem Fuzzy.swap {x y : PGame} : x ‖ y → y ‖ x := And.symm #align pgame.fuzzy.swap SetTheory.PGame.Fuzzy.swap instance : IsSymm _ (· ‖ ·) := ⟨fun _ _ => Fuzzy.swap⟩ theorem Fuzzy.swap_iff {x y : PGame} : x ‖ y ↔ y ‖ x := ⟨Fuzzy.swap, Fuzzy.swap⟩ #align pgame.fuzzy.swap_iff SetTheory.PGame.Fuzzy.swap_iff theorem fuzzy_irrefl (x : PGame) : ¬x ‖ x := fun h => lf_irrefl x h.1 #align pgame.fuzzy_irrefl SetTheory.PGame.fuzzy_irrefl instance : IsIrrefl _ (· ‖ ·) := ⟨fuzzy_irrefl⟩ theorem lf_iff_lt_or_fuzzy {x y : PGame} : x ⧏ y ↔ x < y ∨ x ‖ y := by simp only [lt_iff_le_and_lf, Fuzzy, ← PGame.not_le] tauto #align pgame.lf_iff_lt_or_fuzzy SetTheory.PGame.lf_iff_lt_or_fuzzy theorem lf_of_fuzzy {x y : PGame} (h : x ‖ y) : x ⧏ y := lf_iff_lt_or_fuzzy.2 (Or.inr h) #align pgame.lf_of_fuzzy SetTheory.PGame.lf_of_fuzzy alias Fuzzy.lf := lf_of_fuzzy #align pgame.fuzzy.lf SetTheory.PGame.Fuzzy.lf theorem lt_or_fuzzy_of_lf {x y : PGame} : x ⧏ y → x < y ∨ x ‖ y := lf_iff_lt_or_fuzzy.1 #align pgame.lt_or_fuzzy_of_lf SetTheory.PGame.lt_or_fuzzy_of_lf theorem Fuzzy.not_equiv {x y : PGame} (h : x ‖ y) : ¬(x ≈ y) := fun h' => h'.1.not_gf h.2 #align pgame.fuzzy.not_equiv SetTheory.PGame.Fuzzy.not_equiv theorem Fuzzy.not_equiv' {x y : PGame} (h : x ‖ y) : ¬(y ≈ x) := fun h' => h'.2.not_gf h.2 #align pgame.fuzzy.not_equiv' SetTheory.PGame.Fuzzy.not_equiv' theorem not_fuzzy_of_le {x y : PGame} (h : x ≤ y) : ¬x ‖ y := fun h' => h'.2.not_ge h #align pgame.not_fuzzy_of_le SetTheory.PGame.not_fuzzy_of_le theorem not_fuzzy_of_ge {x y : PGame} (h : y ≤ x) : ¬x ‖ y := fun h' => h'.1.not_ge h #align pgame.not_fuzzy_of_ge SetTheory.PGame.not_fuzzy_of_ge theorem Equiv.not_fuzzy {x y : PGame} (h : x ≈ y) : ¬x ‖ y := not_fuzzy_of_le h.1 #align pgame.equiv.not_fuzzy SetTheory.PGame.Equiv.not_fuzzy theorem Equiv.not_fuzzy' {x y : PGame} (h : x ≈ y) : ¬y ‖ x := not_fuzzy_of_le h.2 #align pgame.equiv.not_fuzzy' SetTheory.PGame.Equiv.not_fuzzy' theorem fuzzy_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ‖ y₁ ↔ x₂ ‖ y₂ := show _ ∧ _ ↔ _ ∧ _ by rw [lf_congr hx hy, lf_congr hy hx] #align pgame.fuzzy_congr SetTheory.PGame.fuzzy_congr theorem fuzzy_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ‖ y₁ → x₂ ‖ y₂ := (fuzzy_congr hx hy).1 #align pgame.fuzzy_congr_imp SetTheory.PGame.fuzzy_congr_imp theorem fuzzy_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ ‖ y ↔ x₂ ‖ y := fuzzy_congr hx equiv_rfl #align pgame.fuzzy_congr_left SetTheory.PGame.fuzzy_congr_left theorem fuzzy_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x ‖ y₁ ↔ x ‖ y₂ := fuzzy_congr equiv_rfl hy #align pgame.fuzzy_congr_right SetTheory.PGame.fuzzy_congr_right @[trans] theorem fuzzy_of_fuzzy_of_equiv {x y z : PGame} (h₁ : x ‖ y) (h₂ : y ≈ z) : x ‖ z := (fuzzy_congr_right h₂).1 h₁ #align pgame.fuzzy_of_fuzzy_of_equiv SetTheory.PGame.fuzzy_of_fuzzy_of_equiv @[trans] theorem fuzzy_of_equiv_of_fuzzy {x y z : PGame} (h₁ : x ≈ y) (h₂ : y ‖ z) : x ‖ z := (fuzzy_congr_left h₁).2 h₂ #align pgame.fuzzy_of_equiv_of_fuzzy SetTheory.PGame.fuzzy_of_equiv_of_fuzzy /-- Exactly one of the following is true (although we don't prove this here). -/ theorem lt_or_equiv_or_gt_or_fuzzy (x y : PGame) : x < y ∨ (x ≈ y) ∨ y < x ∨ x ‖ y := by cases' le_or_gf x y with h₁ h₁ <;> cases' le_or_gf y x with h₂ h₂ · right left exact ⟨h₁, h₂⟩ · left exact ⟨h₁, h₂⟩ · right right left exact ⟨h₂, h₁⟩ · right right right exact ⟨h₂, h₁⟩ #align pgame.lt_or_equiv_or_gt_or_fuzzy SetTheory.PGame.lt_or_equiv_or_gt_or_fuzzy theorem lt_or_equiv_or_gf (x y : PGame) : x < y ∨ (x ≈ y) ∨ y ⧏ x := by rw [lf_iff_lt_or_fuzzy, Fuzzy.swap_iff] exact lt_or_equiv_or_gt_or_fuzzy x y #align pgame.lt_or_equiv_or_gf SetTheory.PGame.lt_or_equiv_or_gf /-! ### Relabellings -/ /-- `Relabelling x y` says that `x` and `y` are really the same game, just dressed up differently. Specifically, there is a bijection between the moves for Left in `x` and in `y`, and similarly for Right, and under these bijections we inductively have `Relabelling`s for the consequent games. -/ inductive Relabelling : PGame.{u} → PGame.{u} → Type (u + 1) | mk : ∀ {x y : PGame} (L : x.LeftMoves ≃ y.LeftMoves) (R : x.RightMoves ≃ y.RightMoves), (∀ i, Relabelling (x.moveLeft i) (y.moveLeft (L i))) → (∀ j, Relabelling (x.moveRight j) (y.moveRight (R j))) → Relabelling x y #align pgame.relabelling SetTheory.PGame.Relabelling @[inherit_doc] scoped infixl:50 " ≡r " => PGame.Relabelling namespace Relabelling variable {x y : PGame.{u}} /-- A constructor for relabellings swapping the equivalences. -/ def mk' (L : y.LeftMoves ≃ x.LeftMoves) (R : y.RightMoves ≃ x.RightMoves) (hL : ∀ i, x.moveLeft (L i) ≡r y.moveLeft i) (hR : ∀ j, x.moveRight (R j) ≡r y.moveRight j) : x ≡r y := ⟨L.symm, R.symm, fun i => by simpa using hL (L.symm i), fun j => by simpa using hR (R.symm j)⟩ #align pgame.relabelling.mk' SetTheory.PGame.Relabelling.mk' /-- The equivalence between left moves of `x` and `y` given by the relabelling. -/ def leftMovesEquiv : x ≡r y → x.LeftMoves ≃ y.LeftMoves | ⟨L,_, _,_⟩ => L #align pgame.relabelling.left_moves_equiv SetTheory.PGame.Relabelling.leftMovesEquiv @[simp] theorem mk_leftMovesEquiv {x y L R hL hR} : (@Relabelling.mk x y L R hL hR).leftMovesEquiv = L := rfl #align pgame.relabelling.mk_left_moves_equiv SetTheory.PGame.Relabelling.mk_leftMovesEquiv @[simp] theorem mk'_leftMovesEquiv {x y L R hL hR} : (@Relabelling.mk' x y L R hL hR).leftMovesEquiv = L.symm := rfl #align pgame.relabelling.mk'_left_moves_equiv SetTheory.PGame.Relabelling.mk'_leftMovesEquiv /-- The equivalence between right moves of `x` and `y` given by the relabelling. -/ def rightMovesEquiv : x ≡r y → x.RightMoves ≃ y.RightMoves | ⟨_, R, _, _⟩ => R #align pgame.relabelling.right_moves_equiv SetTheory.PGame.Relabelling.rightMovesEquiv @[simp] theorem mk_rightMovesEquiv {x y L R hL hR} : (@Relabelling.mk x y L R hL hR).rightMovesEquiv = R := rfl #align pgame.relabelling.mk_right_moves_equiv SetTheory.PGame.Relabelling.mk_rightMovesEquiv @[simp] theorem mk'_rightMovesEquiv {x y L R hL hR} : (@Relabelling.mk' x y L R hL hR).rightMovesEquiv = R.symm := rfl #align pgame.relabelling.mk'_right_moves_equiv SetTheory.PGame.Relabelling.mk'_rightMovesEquiv /-- A left move of `x` is a relabelling of a left move of `y`. -/ def moveLeft : ∀ (r : x ≡r y) (i : x.LeftMoves), x.moveLeft i ≡r y.moveLeft (r.leftMovesEquiv i) | ⟨_, _, hL, _⟩ => hL #align pgame.relabelling.move_left SetTheory.PGame.Relabelling.moveLeft /-- A left move of `y` is a relabelling of a left move of `x`. -/ def moveLeftSymm : ∀ (r : x ≡r y) (i : y.LeftMoves), x.moveLeft (r.leftMovesEquiv.symm i) ≡r y.moveLeft i | ⟨L, R, hL, hR⟩, i => by simpa using hL (L.symm i) #align pgame.relabelling.move_left_symm SetTheory.PGame.Relabelling.moveLeftSymm /-- A right move of `x` is a relabelling of a right move of `y`. -/ def moveRight : ∀ (r : x ≡r y) (i : x.RightMoves), x.moveRight i ≡r y.moveRight (r.rightMovesEquiv i) | ⟨_, _, _, hR⟩ => hR #align pgame.relabelling.move_right SetTheory.PGame.Relabelling.moveRight /-- A right move of `y` is a relabelling of a right move of `x`. -/ def moveRightSymm : ∀ (r : x ≡r y) (i : y.RightMoves), x.moveRight (r.rightMovesEquiv.symm i) ≡r y.moveRight i | ⟨L, R, hL, hR⟩, i => by simpa using hR (R.symm i) #align pgame.relabelling.move_right_symm SetTheory.PGame.Relabelling.moveRightSymm /-- The identity relabelling. -/ @[refl] def refl (x : PGame) : x ≡r x := ⟨Equiv.refl _, Equiv.refl _, fun i => refl _, fun j => refl _⟩ termination_by x #align pgame.relabelling.refl SetTheory.PGame.Relabelling.refl instance (x : PGame) : Inhabited (x ≡r x) := ⟨refl _⟩ /-- Flip a relabelling. -/ @[symm] def symm : ∀ {x y : PGame}, x ≡r y → y ≡r x | _, _, ⟨L, R, hL, hR⟩ => mk' L R (fun i => (hL i).symm) fun j => (hR j).symm #align pgame.relabelling.symm SetTheory.PGame.Relabelling.symm theorem le {x y : PGame} (r : x ≡r y) : x ≤ y := le_def.2 ⟨fun i => Or.inl ⟨_, (r.moveLeft i).le⟩, fun j => Or.inr ⟨_, (r.moveRightSymm j).le⟩⟩ termination_by x #align pgame.relabelling.le SetTheory.PGame.Relabelling.le theorem ge {x y : PGame} (r : x ≡r y) : y ≤ x := r.symm.le #align pgame.relabelling.ge SetTheory.PGame.Relabelling.ge /-- A relabelling lets us prove equivalence of games. -/ theorem equiv (r : x ≡r y) : x ≈ y := ⟨r.le, r.ge⟩ #align pgame.relabelling.equiv SetTheory.PGame.Relabelling.equiv /-- Transitivity of relabelling. -/ @[trans] def trans : ∀ {x y z : PGame}, x ≡r y → y ≡r z → x ≡r z | _, _, _, ⟨L₁, R₁, hL₁, hR₁⟩, ⟨L₂, R₂, hL₂, hR₂⟩ => ⟨L₁.trans L₂, R₁.trans R₂, fun i => (hL₁ i).trans (hL₂ _), fun j => (hR₁ j).trans (hR₂ _)⟩ #align pgame.relabelling.trans SetTheory.PGame.Relabelling.trans /-- Any game without left or right moves is a relabelling of 0. -/ def isEmpty (x : PGame) [IsEmpty x.LeftMoves] [IsEmpty x.RightMoves] : x ≡r 0 := ⟨Equiv.equivPEmpty _, Equiv.equivOfIsEmpty _ _, isEmptyElim, isEmptyElim⟩ #align pgame.relabelling.is_empty SetTheory.PGame.Relabelling.isEmpty end Relabelling theorem Equiv.isEmpty (x : PGame) [IsEmpty x.LeftMoves] [IsEmpty x.RightMoves] : x ≈ 0 := (Relabelling.isEmpty x).equiv #align pgame.equiv.is_empty SetTheory.PGame.Equiv.isEmpty instance {x y : PGame} : Coe (x ≡r y) (x ≈ y) := ⟨Relabelling.equiv⟩ /-- Replace the types indexing the next moves for Left and Right by equivalent types. -/ def relabel {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) : PGame := ⟨xl', xr', x.moveLeft ∘ el, x.moveRight ∘ er⟩ #align pgame.relabel SetTheory.PGame.relabel @[simp] theorem relabel_moveLeft' {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) (i : xl') : moveLeft (relabel el er) i = x.moveLeft (el i) := rfl #align pgame.relabel_move_left' SetTheory.PGame.relabel_moveLeft' theorem relabel_moveLeft {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) (i : x.LeftMoves) : moveLeft (relabel el er) (el.symm i) = x.moveLeft i := by simp #align pgame.relabel_move_left SetTheory.PGame.relabel_moveLeft @[simp] theorem relabel_moveRight' {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) (j : xr') : moveRight (relabel el er) j = x.moveRight (er j) := rfl #align pgame.relabel_move_right' SetTheory.PGame.relabel_moveRight' theorem relabel_moveRight {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) (j : x.RightMoves) : moveRight (relabel el er) (er.symm j) = x.moveRight j := by simp #align pgame.relabel_move_right SetTheory.PGame.relabel_moveRight /-- The game obtained by relabelling the next moves is a relabelling of the original game. -/ def relabelRelabelling {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) : x ≡r relabel el er := -- Porting note: needed to add `rfl` Relabelling.mk' el er (fun i => by simp; rfl) (fun j => by simp; rfl) #align pgame.relabel_relabelling SetTheory.PGame.relabelRelabelling /-! ### Negation -/ /-- The negation of `{L | R}` is `{-R | -L}`. -/ def neg : PGame → PGame | ⟨l, r, L, R⟩ => ⟨r, l, fun i => neg (R i), fun i => neg (L i)⟩ #align pgame.neg SetTheory.PGame.neg instance : Neg PGame := ⟨neg⟩ @[simp] theorem neg_def {xl xr xL xR} : -mk xl xr xL xR = mk xr xl (fun j => -xR j) fun i => -xL i := rfl #align pgame.neg_def SetTheory.PGame.neg_def instance : InvolutiveNeg PGame := { inferInstanceAs (Neg PGame) with neg_neg := fun x => by induction' x with xl xr xL xR ihL ihR simp_rw [neg_def, ihL, ihR] } instance : NegZeroClass PGame := { inferInstanceAs (Zero PGame), inferInstanceAs (Neg PGame) with neg_zero := by dsimp [Zero.zero, Neg.neg, neg] congr <;> funext i <;> cases i } @[simp]
Mathlib/SetTheory/Game/PGame.lean
1,271
1,287
theorem neg_ofLists (L R : List PGame) : -ofLists L R = ofLists (R.map fun x => -x) (L.map fun x => -x) := by
simp only [ofLists, neg_def, List.get_map, mk.injEq, List.length_map, true_and] constructor all_goals apply hfunext · simp · rintro ⟨⟨a, ha⟩⟩ ⟨⟨b, hb⟩⟩ h have : ∀ {m n} (_ : m = n) {b : ULift (Fin m)} {c : ULift (Fin n)} (_ : HEq b c), (b.down : ℕ) = ↑c.down := by rintro m n rfl b c simp only [heq_eq_eq] rintro rfl rfl congr 5 exact this (List.length_map _ _).symm 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 -/ import Mathlib.Topology.Algebra.Constructions import Mathlib.Topology.Bases import Mathlib.Topology.UniformSpace.Basic #align_import topology.uniform_space.cauchy from "leanprover-community/mathlib"@"22131150f88a2d125713ffa0f4693e3355b1eb49" /-! # Theory of Cauchy filters in uniform spaces. Complete uniform spaces. Totally bounded subsets. -/ universe u v open scoped Classical open Filter TopologicalSpace Set UniformSpace Function open scoped Classical open Uniformity Topology Filter variable {α : Type u} {β : Type v} [uniformSpace : UniformSpace α] /-- A filter `f` is Cauchy if for every entourage `r`, there exists an `s ∈ f` such that `s × s ⊆ r`. This is a generalization of Cauchy sequences, because if `a : ℕ → α` then the filter of sets containing cofinitely many of the `a n` is Cauchy iff `a` is a Cauchy sequence. -/ def Cauchy (f : Filter α) := NeBot f ∧ f ×ˢ f ≤ 𝓤 α #align cauchy Cauchy /-- A set `s` is called *complete*, if any Cauchy filter `f` such that `s ∈ f` has a limit in `s` (formally, it satisfies `f ≤ 𝓝 x` for some `x ∈ s`). -/ def IsComplete (s : Set α) := ∀ f, Cauchy f → f ≤ 𝓟 s → ∃ x ∈ s, f ≤ 𝓝 x #align is_complete IsComplete theorem Filter.HasBasis.cauchy_iff {ι} {p : ι → Prop} {s : ι → Set (α × α)} (h : (𝓤 α).HasBasis p s) {f : Filter α} : Cauchy f ↔ NeBot f ∧ ∀ i, p i → ∃ t ∈ f, ∀ x ∈ t, ∀ y ∈ t, (x, y) ∈ s i := and_congr Iff.rfl <| (f.basis_sets.prod_self.le_basis_iff h).trans <| by simp only [subset_def, Prod.forall, mem_prod_eq, and_imp, id, forall_mem_comm] #align filter.has_basis.cauchy_iff Filter.HasBasis.cauchy_iff theorem cauchy_iff' {f : Filter α} : Cauchy f ↔ NeBot f ∧ ∀ s ∈ 𝓤 α, ∃ t ∈ f, ∀ x ∈ t, ∀ y ∈ t, (x, y) ∈ s := (𝓤 α).basis_sets.cauchy_iff #align cauchy_iff' cauchy_iff' theorem cauchy_iff {f : Filter α} : Cauchy f ↔ NeBot f ∧ ∀ s ∈ 𝓤 α, ∃ t ∈ f, t ×ˢ t ⊆ s := cauchy_iff'.trans <| by simp only [subset_def, Prod.forall, mem_prod_eq, and_imp, id, forall_mem_comm] #align cauchy_iff cauchy_iff lemma cauchy_iff_le {l : Filter α} [hl : l.NeBot] : Cauchy l ↔ l ×ˢ l ≤ 𝓤 α := by simp only [Cauchy, hl, true_and] theorem Cauchy.ultrafilter_of {l : Filter α} (h : Cauchy l) : Cauchy (@Ultrafilter.of _ l h.1 : Filter α) := by haveI := h.1 have := Ultrafilter.of_le l exact ⟨Ultrafilter.neBot _, (Filter.prod_mono this this).trans h.2⟩ #align cauchy.ultrafilter_of Cauchy.ultrafilter_of theorem cauchy_map_iff {l : Filter β} {f : β → α} : Cauchy (l.map f) ↔ NeBot l ∧ Tendsto (fun p : β × β => (f p.1, f p.2)) (l ×ˢ l) (𝓤 α) := by rw [Cauchy, map_neBot_iff, prod_map_map_eq, Tendsto] #align cauchy_map_iff cauchy_map_iff theorem cauchy_map_iff' {l : Filter β} [hl : NeBot l] {f : β → α} : Cauchy (l.map f) ↔ Tendsto (fun p : β × β => (f p.1, f p.2)) (l ×ˢ l) (𝓤 α) := cauchy_map_iff.trans <| and_iff_right hl #align cauchy_map_iff' cauchy_map_iff' theorem Cauchy.mono {f g : Filter α} [hg : NeBot g] (h_c : Cauchy f) (h_le : g ≤ f) : Cauchy g := ⟨hg, le_trans (Filter.prod_mono h_le h_le) h_c.right⟩ #align cauchy.mono Cauchy.mono theorem Cauchy.mono' {f g : Filter α} (h_c : Cauchy f) (_ : NeBot g) (h_le : g ≤ f) : Cauchy g := h_c.mono h_le #align cauchy.mono' Cauchy.mono' theorem cauchy_nhds {a : α} : Cauchy (𝓝 a) := ⟨nhds_neBot, nhds_prod_eq.symm.trans_le (nhds_le_uniformity a)⟩ #align cauchy_nhds cauchy_nhds theorem cauchy_pure {a : α} : Cauchy (pure a) := cauchy_nhds.mono (pure_le_nhds a) #align cauchy_pure cauchy_pure theorem Filter.Tendsto.cauchy_map {l : Filter β} [NeBot l] {f : β → α} {a : α} (h : Tendsto f l (𝓝 a)) : Cauchy (map f l) := cauchy_nhds.mono h #align filter.tendsto.cauchy_map Filter.Tendsto.cauchy_map lemma Cauchy.mono_uniformSpace {u v : UniformSpace β} {F : Filter β} (huv : u ≤ v) (hF : Cauchy (uniformSpace := u) F) : Cauchy (uniformSpace := v) F := ⟨hF.1, hF.2.trans huv⟩ lemma cauchy_inf_uniformSpace {u v : UniformSpace β} {F : Filter β} : Cauchy (uniformSpace := u ⊓ v) F ↔ Cauchy (uniformSpace := u) F ∧ Cauchy (uniformSpace := v) F := by unfold Cauchy rw [inf_uniformity (u := u), le_inf_iff, and_and_left] lemma cauchy_iInf_uniformSpace {ι : Sort*} [Nonempty ι] {u : ι → UniformSpace β} {l : Filter β} : Cauchy (uniformSpace := ⨅ i, u i) l ↔ ∀ i, Cauchy (uniformSpace := u i) l := by unfold Cauchy rw [iInf_uniformity, le_iInf_iff, forall_and, forall_const] lemma cauchy_iInf_uniformSpace' {ι : Sort*} {u : ι → UniformSpace β} {l : Filter β} [l.NeBot] : Cauchy (uniformSpace := ⨅ i, u i) l ↔ ∀ i, Cauchy (uniformSpace := u i) l := by simp_rw [cauchy_iff_le (uniformSpace := _), iInf_uniformity, le_iInf_iff] lemma cauchy_comap_uniformSpace {u : UniformSpace β} {f : α → β} {l : Filter α} : Cauchy (uniformSpace := comap f u) l ↔ Cauchy (map f l) := by simp only [Cauchy, map_neBot_iff, prod_map_map_eq, map_le_iff_le_comap] rfl lemma cauchy_prod_iff [UniformSpace β] {F : Filter (α × β)} : Cauchy F ↔ Cauchy (map Prod.fst F) ∧ Cauchy (map Prod.snd F) := by simp_rw [instUniformSpaceProd, ← cauchy_comap_uniformSpace, ← cauchy_inf_uniformSpace] theorem Cauchy.prod [UniformSpace β] {f : Filter α} {g : Filter β} (hf : Cauchy f) (hg : Cauchy g) : Cauchy (f ×ˢ g) := by have := hf.1; have := hg.1 simpa [cauchy_prod_iff, hf.1] using ⟨hf, hg⟩ #align cauchy.prod Cauchy.prod /-- The common part of the proofs of `le_nhds_of_cauchy_adhp` and `SequentiallyComplete.le_nhds_of_seq_tendsto_nhds`: if for any entourage `s` one can choose a set `t ∈ f` of diameter `s` such that it contains a point `y` with `(x, y) ∈ s`, then `f` converges to `x`. -/ theorem le_nhds_of_cauchy_adhp_aux {f : Filter α} {x : α} (adhs : ∀ s ∈ 𝓤 α, ∃ t ∈ f, t ×ˢ t ⊆ s ∧ ∃ y, (x, y) ∈ s ∧ y ∈ t) : f ≤ 𝓝 x := by -- Consider a neighborhood `s` of `x` intro s hs -- Take an entourage twice smaller than `s` rcases comp_mem_uniformity_sets (mem_nhds_uniformity_iff_right.1 hs) with ⟨U, U_mem, hU⟩ -- Take a set `t ∈ f`, `t × t ⊆ U`, and a point `y ∈ t` such that `(x, y) ∈ U` rcases adhs U U_mem with ⟨t, t_mem, ht, y, hxy, hy⟩ apply mem_of_superset t_mem -- Given a point `z ∈ t`, we have `(x, y) ∈ U` and `(y, z) ∈ t × t ⊆ U`, hence `z ∈ s` exact fun z hz => hU (prod_mk_mem_compRel hxy (ht <| mk_mem_prod hy hz)) rfl #align le_nhds_of_cauchy_adhp_aux le_nhds_of_cauchy_adhp_aux /-- If `x` is an adherent (cluster) point for a Cauchy filter `f`, then it is a limit point for `f`. -/ theorem le_nhds_of_cauchy_adhp {f : Filter α} {x : α} (hf : Cauchy f) (adhs : ClusterPt x f) : f ≤ 𝓝 x := le_nhds_of_cauchy_adhp_aux (fun s hs => by obtain ⟨t, t_mem, ht⟩ : ∃ t ∈ f, t ×ˢ t ⊆ s := (cauchy_iff.1 hf).2 s hs use t, t_mem, ht exact forall_mem_nonempty_iff_neBot.2 adhs _ (inter_mem_inf (mem_nhds_left x hs) t_mem)) #align le_nhds_of_cauchy_adhp le_nhds_of_cauchy_adhp theorem le_nhds_iff_adhp_of_cauchy {f : Filter α} {x : α} (hf : Cauchy f) : f ≤ 𝓝 x ↔ ClusterPt x f := ⟨fun h => ClusterPt.of_le_nhds' h hf.1, le_nhds_of_cauchy_adhp hf⟩ #align le_nhds_iff_adhp_of_cauchy le_nhds_iff_adhp_of_cauchy nonrec theorem Cauchy.map [UniformSpace β] {f : Filter α} {m : α → β} (hf : Cauchy f) (hm : UniformContinuous m) : Cauchy (map m f) := ⟨hf.1.map _, calc map m f ×ˢ map m f = map (Prod.map m m) (f ×ˢ f) := Filter.prod_map_map_eq _ ≤ Filter.map (Prod.map m m) (𝓤 α) := map_mono hf.right _ ≤ 𝓤 β := hm⟩ #align cauchy.map Cauchy.map nonrec theorem Cauchy.comap [UniformSpace β] {f : Filter β} {m : α → β} (hf : Cauchy f) (hm : comap (fun p : α × α => (m p.1, m p.2)) (𝓤 β) ≤ 𝓤 α) [NeBot (comap m f)] : Cauchy (comap m f) := ⟨‹_›, calc comap m f ×ˢ comap m f = comap (Prod.map m m) (f ×ˢ f) := prod_comap_comap_eq _ ≤ comap (Prod.map m m) (𝓤 β) := comap_mono hf.right _ ≤ 𝓤 α := hm⟩ #align cauchy.comap Cauchy.comap theorem Cauchy.comap' [UniformSpace β] {f : Filter β} {m : α → β} (hf : Cauchy f) (hm : Filter.comap (fun p : α × α => (m p.1, m p.2)) (𝓤 β) ≤ 𝓤 α) (_ : NeBot (Filter.comap m f)) : Cauchy (Filter.comap m f) := hf.comap hm #align cauchy.comap' Cauchy.comap' /-- Cauchy sequences. Usually defined on ℕ, but often it is also useful to say that a function defined on ℝ is Cauchy at +∞ to deduce convergence. Therefore, we define it in a type class that is general enough to cover both ℕ and ℝ, which are the main motivating examples. -/ def CauchySeq [Preorder β] (u : β → α) := Cauchy (atTop.map u) #align cauchy_seq CauchySeq theorem CauchySeq.tendsto_uniformity [Preorder β] {u : β → α} (h : CauchySeq u) : Tendsto (Prod.map u u) atTop (𝓤 α) := by simpa only [Tendsto, prod_map_map_eq', prod_atTop_atTop_eq] using h.right #align cauchy_seq.tendsto_uniformity CauchySeq.tendsto_uniformity theorem CauchySeq.nonempty [Preorder β] {u : β → α} (hu : CauchySeq u) : Nonempty β := @nonempty_of_neBot _ _ <| (map_neBot_iff _).1 hu.1 #align cauchy_seq.nonempty CauchySeq.nonempty theorem CauchySeq.mem_entourage {β : Type*} [SemilatticeSup β] {u : β → α} (h : CauchySeq u) {V : Set (α × α)} (hV : V ∈ 𝓤 α) : ∃ k₀, ∀ i j, k₀ ≤ i → k₀ ≤ j → (u i, u j) ∈ V := by haveI := h.nonempty have := h.tendsto_uniformity; rw [← prod_atTop_atTop_eq] at this simpa [MapsTo] using atTop_basis.prod_self.tendsto_left_iff.1 this V hV #align cauchy_seq.mem_entourage CauchySeq.mem_entourage theorem Filter.Tendsto.cauchySeq [SemilatticeSup β] [Nonempty β] {f : β → α} {x} (hx : Tendsto f atTop (𝓝 x)) : CauchySeq f := hx.cauchy_map #align filter.tendsto.cauchy_seq Filter.Tendsto.cauchySeq theorem cauchySeq_const [SemilatticeSup β] [Nonempty β] (x : α) : CauchySeq fun _ : β => x := tendsto_const_nhds.cauchySeq #align cauchy_seq_const cauchySeq_const theorem cauchySeq_iff_tendsto [Nonempty β] [SemilatticeSup β] {u : β → α} : CauchySeq u ↔ Tendsto (Prod.map u u) atTop (𝓤 α) := cauchy_map_iff'.trans <| by simp only [prod_atTop_atTop_eq, Prod.map_def] #align cauchy_seq_iff_tendsto cauchySeq_iff_tendsto theorem CauchySeq.comp_tendsto {γ} [Preorder β] [SemilatticeSup γ] [Nonempty γ] {f : β → α} (hf : CauchySeq f) {g : γ → β} (hg : Tendsto g atTop atTop) : CauchySeq (f ∘ g) := ⟨inferInstance, le_trans (prod_le_prod.mpr ⟨Tendsto.comp le_rfl hg, Tendsto.comp le_rfl hg⟩) hf.2⟩ #align cauchy_seq.comp_tendsto CauchySeq.comp_tendsto theorem CauchySeq.comp_injective [SemilatticeSup β] [NoMaxOrder β] [Nonempty β] {u : ℕ → α} (hu : CauchySeq u) {f : β → ℕ} (hf : Injective f) : CauchySeq (u ∘ f) := hu.comp_tendsto <| Nat.cofinite_eq_atTop ▸ hf.tendsto_cofinite.mono_left atTop_le_cofinite #align cauchy_seq.comp_injective CauchySeq.comp_injective theorem Function.Bijective.cauchySeq_comp_iff {f : ℕ → ℕ} (hf : Bijective f) (u : ℕ → α) : CauchySeq (u ∘ f) ↔ CauchySeq u := by refine ⟨fun H => ?_, fun H => H.comp_injective hf.injective⟩ lift f to ℕ ≃ ℕ using hf simpa only [(· ∘ ·), f.apply_symm_apply] using H.comp_injective f.symm.injective #align function.bijective.cauchy_seq_comp_iff Function.Bijective.cauchySeq_comp_iff theorem CauchySeq.subseq_subseq_mem {V : ℕ → Set (α × α)} (hV : ∀ n, V n ∈ 𝓤 α) {u : ℕ → α} (hu : CauchySeq u) {f g : ℕ → ℕ} (hf : Tendsto f atTop atTop) (hg : Tendsto g atTop atTop) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, ((u ∘ f ∘ φ) n, (u ∘ g ∘ φ) n) ∈ V n := by rw [cauchySeq_iff_tendsto] at hu exact ((hu.comp <| hf.prod_atTop hg).comp tendsto_atTop_diagonal).subseq_mem hV #align cauchy_seq.subseq_subseq_mem CauchySeq.subseq_subseq_mem -- todo: generalize this and other lemmas to a nonempty semilattice theorem cauchySeq_iff' {u : ℕ → α} : CauchySeq u ↔ ∀ V ∈ 𝓤 α, ∀ᶠ k in atTop, k ∈ Prod.map u u ⁻¹' V := cauchySeq_iff_tendsto #align cauchy_seq_iff' cauchySeq_iff' theorem cauchySeq_iff {u : ℕ → α} : CauchySeq u ↔ ∀ V ∈ 𝓤 α, ∃ N, ∀ k ≥ N, ∀ l ≥ N, (u k, u l) ∈ V := by simp only [cauchySeq_iff', Filter.eventually_atTop_prod_self', mem_preimage, Prod.map_apply] #align cauchy_seq_iff cauchySeq_iff theorem CauchySeq.prod_map {γ δ} [UniformSpace β] [Preorder γ] [Preorder δ] {u : γ → α} {v : δ → β} (hu : CauchySeq u) (hv : CauchySeq v) : CauchySeq (Prod.map u v) := by simpa only [CauchySeq, prod_map_map_eq', prod_atTop_atTop_eq] using hu.prod hv #align cauchy_seq.prod_map CauchySeq.prod_map theorem CauchySeq.prod {γ} [UniformSpace β] [Preorder γ] {u : γ → α} {v : γ → β} (hu : CauchySeq u) (hv : CauchySeq v) : CauchySeq fun x => (u x, v x) := haveI := hu.1.of_map (Cauchy.prod hu hv).mono (Tendsto.prod_mk le_rfl le_rfl) #align cauchy_seq.prod CauchySeq.prod theorem CauchySeq.eventually_eventually [SemilatticeSup β] {u : β → α} (hu : CauchySeq u) {V : Set (α × α)} (hV : V ∈ 𝓤 α) : ∀ᶠ k in atTop, ∀ᶠ l in atTop, (u k, u l) ∈ V := eventually_atTop_curry <| hu.tendsto_uniformity hV #align cauchy_seq.eventually_eventually CauchySeq.eventually_eventually theorem UniformContinuous.comp_cauchySeq {γ} [UniformSpace β] [Preorder γ] {f : α → β} (hf : UniformContinuous f) {u : γ → α} (hu : CauchySeq u) : CauchySeq (f ∘ u) := hu.map hf #align uniform_continuous.comp_cauchy_seq UniformContinuous.comp_cauchySeq theorem CauchySeq.subseq_mem {V : ℕ → Set (α × α)} (hV : ∀ n, V n ∈ 𝓤 α) {u : ℕ → α} (hu : CauchySeq u) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, (u <| φ (n + 1), u <| φ n) ∈ V n := by have : ∀ n, ∃ N, ∀ k ≥ N, ∀ l ≥ k, (u l, u k) ∈ V n := fun n => by rw [cauchySeq_iff] at hu rcases hu _ (hV n) with ⟨N, H⟩ exact ⟨N, fun k hk l hl => H _ (le_trans hk hl) _ hk⟩ obtain ⟨φ : ℕ → ℕ, φ_extr : StrictMono φ, hφ : ∀ n, ∀ l ≥ φ n, (u l, u <| φ n) ∈ V n⟩ := extraction_forall_of_eventually' this exact ⟨φ, φ_extr, fun n => hφ _ _ (φ_extr <| lt_add_one n).le⟩ #align cauchy_seq.subseq_mem CauchySeq.subseq_mem theorem Filter.Tendsto.subseq_mem_entourage {V : ℕ → Set (α × α)} (hV : ∀ n, V n ∈ 𝓤 α) {u : ℕ → α} {a : α} (hu : Tendsto u atTop (𝓝 a)) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ (u (φ 0), a) ∈ V 0 ∧ ∀ n, (u <| φ (n + 1), u <| φ n) ∈ V (n + 1) := by rcases mem_atTop_sets.1 (hu (ball_mem_nhds a (symm_le_uniformity <| hV 0))) with ⟨n, hn⟩ rcases (hu.comp (tendsto_add_atTop_nat n)).cauchySeq.subseq_mem fun n => hV (n + 1) with ⟨φ, φ_mono, hφV⟩ exact ⟨fun k => φ k + n, φ_mono.add_const _, hn _ le_add_self, hφV⟩ #align filter.tendsto.subseq_mem_entourage Filter.Tendsto.subseq_mem_entourage /-- If a Cauchy sequence has a convergent subsequence, then it converges. -/ theorem tendsto_nhds_of_cauchySeq_of_subseq [Preorder β] {u : β → α} (hu : CauchySeq u) {ι : Type*} {f : ι → β} {p : Filter ι} [NeBot p] (hf : Tendsto f p atTop) {a : α} (ha : Tendsto (u ∘ f) p (𝓝 a)) : Tendsto u atTop (𝓝 a) := le_nhds_of_cauchy_adhp hu (mapClusterPt_of_comp hf ha) #align tendsto_nhds_of_cauchy_seq_of_subseq tendsto_nhds_of_cauchySeq_of_subseq /-- Any shift of a Cauchy sequence is also a Cauchy sequence. -/ theorem cauchySeq_shift {u : ℕ → α} (k : ℕ) : CauchySeq (fun n ↦ u (n + k)) ↔ CauchySeq u := by constructor <;> intro h · rw [cauchySeq_iff] at h ⊢ intro V mV obtain ⟨N, h⟩ := h V mV use N + k intro a ha b hb convert h (a - k) (Nat.le_sub_of_add_le ha) (b - k) (Nat.le_sub_of_add_le hb) <;> omega · exact h.comp_tendsto (tendsto_add_atTop_nat k) theorem Filter.HasBasis.cauchySeq_iff {γ} [Nonempty β] [SemilatticeSup β] {u : β → α} {p : γ → Prop} {s : γ → Set (α × α)} (h : (𝓤 α).HasBasis p s) : CauchySeq u ↔ ∀ i, p i → ∃ N, ∀ m, N ≤ m → ∀ n, N ≤ n → (u m, u n) ∈ s i := by rw [cauchySeq_iff_tendsto, ← prod_atTop_atTop_eq] refine (atTop_basis.prod_self.tendsto_iff h).trans ?_ simp only [exists_prop, true_and_iff, MapsTo, preimage, subset_def, Prod.forall, mem_prod_eq, mem_setOf_eq, mem_Ici, and_imp, Prod.map, ge_iff_le, @forall_swap (_ ≤ _) β] #align filter.has_basis.cauchy_seq_iff Filter.HasBasis.cauchySeq_iff theorem Filter.HasBasis.cauchySeq_iff' {γ} [Nonempty β] [SemilatticeSup β] {u : β → α} {p : γ → Prop} {s : γ → Set (α × α)} (H : (𝓤 α).HasBasis p s) : CauchySeq u ↔ ∀ i, p i → ∃ N, ∀ n ≥ N, (u n, u N) ∈ s i := by refine H.cauchySeq_iff.trans ⟨fun h i hi => ?_, fun h i hi => ?_⟩ · exact (h i hi).imp fun N hN n hn => hN n hn N le_rfl · rcases comp_symm_of_uniformity (H.mem_of_mem hi) with ⟨t, ht, ht', hts⟩ rcases H.mem_iff.1 ht with ⟨j, hj, hjt⟩ refine (h j hj).imp fun N hN m hm n hn => hts ⟨u N, hjt ?_, ht' <| hjt ?_⟩ exacts [hN m hm, hN n hn] #align filter.has_basis.cauchy_seq_iff' Filter.HasBasis.cauchySeq_iff' theorem cauchySeq_of_controlled [SemilatticeSup β] [Nonempty β] (U : β → Set (α × α)) (hU : ∀ s ∈ 𝓤 α, ∃ n, U n ⊆ s) {f : β → α} (hf : ∀ ⦃N m n : β⦄, N ≤ m → N ≤ n → (f m, f n) ∈ U N) : CauchySeq f := -- Porting note: changed to semi-implicit arguments cauchySeq_iff_tendsto.2 (by intro s hs rw [mem_map, mem_atTop_sets] cases' hU s hs with N hN refine ⟨(N, N), fun mn hmn => ?_⟩ cases' mn with m n exact hN (hf hmn.1 hmn.2)) #align cauchy_seq_of_controlled cauchySeq_of_controlled theorem isComplete_iff_clusterPt {s : Set α} : IsComplete s ↔ ∀ l, Cauchy l → l ≤ 𝓟 s → ∃ x ∈ s, ClusterPt x l := forall₃_congr fun _ hl _ => exists_congr fun _ => and_congr_right fun _ => le_nhds_iff_adhp_of_cauchy hl #align is_complete_iff_cluster_pt isComplete_iff_clusterPt theorem isComplete_iff_ultrafilter {s : Set α} : IsComplete s ↔ ∀ l : Ultrafilter α, Cauchy (l : Filter α) → ↑l ≤ 𝓟 s → ∃ x ∈ s, ↑l ≤ 𝓝 x := by refine ⟨fun h l => h l, fun H => isComplete_iff_clusterPt.2 fun l hl hls => ?_⟩ haveI := hl.1 rcases H (Ultrafilter.of l) hl.ultrafilter_of ((Ultrafilter.of_le l).trans hls) with ⟨x, hxs, hxl⟩ exact ⟨x, hxs, (ClusterPt.of_le_nhds hxl).mono (Ultrafilter.of_le l)⟩ #align is_complete_iff_ultrafilter isComplete_iff_ultrafilter theorem isComplete_iff_ultrafilter' {s : Set α} : IsComplete s ↔ ∀ l : Ultrafilter α, Cauchy (l : Filter α) → s ∈ l → ∃ x ∈ s, ↑l ≤ 𝓝 x := isComplete_iff_ultrafilter.trans <| by simp only [le_principal_iff, Ultrafilter.mem_coe] #align is_complete_iff_ultrafilter' isComplete_iff_ultrafilter' protected theorem IsComplete.union {s t : Set α} (hs : IsComplete s) (ht : IsComplete t) : IsComplete (s ∪ t) := by simp only [isComplete_iff_ultrafilter', Ultrafilter.union_mem_iff, or_imp] at * exact fun l hl => ⟨fun hsl => (hs l hl hsl).imp fun x hx => ⟨Or.inl hx.1, hx.2⟩, fun htl => (ht l hl htl).imp fun x hx => ⟨Or.inr hx.1, hx.2⟩⟩ #align is_complete.union IsComplete.union theorem isComplete_iUnion_separated {ι : Sort*} {s : ι → Set α} (hs : ∀ i, IsComplete (s i)) {U : Set (α × α)} (hU : U ∈ 𝓤 α) (hd : ∀ (i j : ι), ∀ x ∈ s i, ∀ y ∈ s j, (x, y) ∈ U → i = j) : IsComplete (⋃ i, s i) := by set S := ⋃ i, s i intro l hl hls rw [le_principal_iff] at hls cases' cauchy_iff.1 hl with hl_ne hl' obtain ⟨t, htS, htl, htU⟩ : ∃ t, t ⊆ S ∧ t ∈ l ∧ t ×ˢ t ⊆ U := by rcases hl' U hU with ⟨t, htl, htU⟩ refine ⟨t ∩ S, inter_subset_right, inter_mem htl hls, Subset.trans ?_ htU⟩ gcongr <;> apply inter_subset_left obtain ⟨i, hi⟩ : ∃ i, t ⊆ s i := by rcases Filter.nonempty_of_mem htl with ⟨x, hx⟩ rcases mem_iUnion.1 (htS hx) with ⟨i, hi⟩ refine ⟨i, fun y hy => ?_⟩ rcases mem_iUnion.1 (htS hy) with ⟨j, hj⟩ rwa [hd i j x hi y hj (htU <| mk_mem_prod hx hy)] rcases hs i l hl (le_principal_iff.2 <| mem_of_superset htl hi) with ⟨x, hxs, hlx⟩ exact ⟨x, mem_iUnion.2 ⟨i, hxs⟩, hlx⟩ #align is_complete_Union_separated isComplete_iUnion_separated /-- A complete space is defined here using uniformities. A uniform space is complete if every Cauchy filter converges. -/ class CompleteSpace (α : Type u) [UniformSpace α] : Prop where /-- In a complete uniform space, every Cauchy filter converges. -/ complete : ∀ {f : Filter α}, Cauchy f → ∃ x, f ≤ 𝓝 x #align complete_space CompleteSpace theorem complete_univ {α : Type u} [UniformSpace α] [CompleteSpace α] : IsComplete (univ : Set α) := fun f hf _ => by rcases CompleteSpace.complete hf with ⟨x, hx⟩ exact ⟨x, mem_univ x, hx⟩ #align complete_univ complete_univ instance CompleteSpace.prod [UniformSpace β] [CompleteSpace α] [CompleteSpace β] : CompleteSpace (α × β) where complete hf := let ⟨x1, hx1⟩ := CompleteSpace.complete <| hf.map uniformContinuous_fst let ⟨x2, hx2⟩ := CompleteSpace.complete <| hf.map uniformContinuous_snd ⟨(x1, x2), by rw [nhds_prod_eq, le_prod]; constructor <;> assumption⟩ #align complete_space.prod CompleteSpace.prod lemma CompleteSpace.fst_of_prod [UniformSpace β] [CompleteSpace (α × β)] [h : Nonempty β] : CompleteSpace α where complete hf := let ⟨y⟩ := h let ⟨(a, b), hab⟩ := CompleteSpace.complete <| hf.prod <| cauchy_pure (a := y) ⟨a, by simpa only [map_fst_prod, nhds_prod_eq] using map_mono (m := Prod.fst) hab⟩ lemma CompleteSpace.snd_of_prod [UniformSpace β] [CompleteSpace (α × β)] [h : Nonempty α] : CompleteSpace β where complete hf := let ⟨x⟩ := h let ⟨(a, b), hab⟩ := CompleteSpace.complete <| (cauchy_pure (a := x)).prod hf ⟨b, by simpa only [map_snd_prod, nhds_prod_eq] using map_mono (m := Prod.snd) hab⟩ lemma completeSpace_prod_of_nonempty [UniformSpace β] [Nonempty α] [Nonempty β] : CompleteSpace (α × β) ↔ CompleteSpace α ∧ CompleteSpace β := ⟨fun _ ↦ ⟨.fst_of_prod (β := β), .snd_of_prod (α := α)⟩, fun ⟨_, _⟩ ↦ .prod⟩ @[to_additive] instance CompleteSpace.mulOpposite [CompleteSpace α] : CompleteSpace αᵐᵒᵖ where complete hf := MulOpposite.op_surjective.exists.mpr <| let ⟨x, hx⟩ := CompleteSpace.complete (hf.map MulOpposite.uniformContinuous_unop) ⟨x, (map_le_iff_le_comap.mp hx).trans_eq <| MulOpposite.comap_unop_nhds _⟩ #align complete_space.mul_opposite CompleteSpace.mulOpposite #align complete_space.add_opposite CompleteSpace.addOpposite /-- If `univ` is complete, the space is a complete space -/ theorem completeSpace_of_isComplete_univ (h : IsComplete (univ : Set α)) : CompleteSpace α := ⟨fun hf => let ⟨x, _, hx⟩ := h _ hf ((@principal_univ α).symm ▸ le_top); ⟨x, hx⟩⟩ #align complete_space_of_is_complete_univ completeSpace_of_isComplete_univ theorem completeSpace_iff_isComplete_univ : CompleteSpace α ↔ IsComplete (univ : Set α) := ⟨@complete_univ α _, completeSpace_of_isComplete_univ⟩ #align complete_space_iff_is_complete_univ completeSpace_iff_isComplete_univ theorem completeSpace_iff_ultrafilter : CompleteSpace α ↔ ∀ l : Ultrafilter α, Cauchy (l : Filter α) → ∃ x : α, ↑l ≤ 𝓝 x := by simp [completeSpace_iff_isComplete_univ, isComplete_iff_ultrafilter] #align complete_space_iff_ultrafilter completeSpace_iff_ultrafilter theorem cauchy_iff_exists_le_nhds [CompleteSpace α] {l : Filter α} [NeBot l] : Cauchy l ↔ ∃ x, l ≤ 𝓝 x := ⟨CompleteSpace.complete, fun ⟨_, hx⟩ => cauchy_nhds.mono hx⟩ #align cauchy_iff_exists_le_nhds cauchy_iff_exists_le_nhds theorem cauchy_map_iff_exists_tendsto [CompleteSpace α] {l : Filter β} {f : β → α} [NeBot l] : Cauchy (l.map f) ↔ ∃ x, Tendsto f l (𝓝 x) := cauchy_iff_exists_le_nhds #align cauchy_map_iff_exists_tendsto cauchy_map_iff_exists_tendsto /-- A Cauchy sequence in a complete space converges -/ theorem cauchySeq_tendsto_of_complete [Preorder β] [CompleteSpace α] {u : β → α} (H : CauchySeq u) : ∃ x, Tendsto u atTop (𝓝 x) := CompleteSpace.complete H #align cauchy_seq_tendsto_of_complete cauchySeq_tendsto_of_complete /-- If `K` is a complete subset, then any cauchy sequence in `K` converges to a point in `K` -/ theorem cauchySeq_tendsto_of_isComplete [Preorder β] {K : Set α} (h₁ : IsComplete K) {u : β → α} (h₂ : ∀ n, u n ∈ K) (h₃ : CauchySeq u) : ∃ v ∈ K, Tendsto u atTop (𝓝 v) := h₁ _ h₃ <| le_principal_iff.2 <| mem_map_iff_exists_image.2 ⟨univ, univ_mem, by rwa [image_univ, range_subset_iff]⟩ #align cauchy_seq_tendsto_of_is_complete cauchySeq_tendsto_of_isComplete theorem Cauchy.le_nhds_lim [CompleteSpace α] {f : Filter α} (hf : Cauchy f) : haveI := hf.1.nonempty; f ≤ 𝓝 (lim f) := _root_.le_nhds_lim (CompleteSpace.complete hf) set_option linter.uppercaseLean3 false in #align cauchy.le_nhds_Lim Cauchy.le_nhds_lim theorem CauchySeq.tendsto_limUnder [Preorder β] [CompleteSpace α] {u : β → α} (h : CauchySeq u) : haveI := h.1.nonempty; Tendsto u atTop (𝓝 <| limUnder atTop u) := h.le_nhds_lim #align cauchy_seq.tendsto_lim CauchySeq.tendsto_limUnder theorem IsClosed.isComplete [CompleteSpace α] {s : Set α} (h : IsClosed s) : IsComplete s := fun _ cf fs => let ⟨x, hx⟩ := CompleteSpace.complete cf ⟨x, isClosed_iff_clusterPt.mp h x (cf.left.mono (le_inf hx fs)), hx⟩ #align is_closed.is_complete IsClosed.isComplete /-- A set `s` is totally bounded if for every entourage `d` there is a finite set of points `t` such that every element of `s` is `d`-near to some element of `t`. -/ def TotallyBounded (s : Set α) : Prop := ∀ d ∈ 𝓤 α, ∃ t : Set α, t.Finite ∧ s ⊆ ⋃ y ∈ t, { x | (x, y) ∈ d } #align totally_bounded TotallyBounded theorem TotallyBounded.exists_subset {s : Set α} (hs : TotallyBounded s) {U : Set (α × α)} (hU : U ∈ 𝓤 α) : ∃ t, t ⊆ s ∧ Set.Finite t ∧ s ⊆ ⋃ y ∈ t, { x | (x, y) ∈ U } := by rcases comp_symm_of_uniformity hU with ⟨r, hr, rs, rU⟩ rcases hs r hr with ⟨k, fk, ks⟩ let u := k ∩ { y | ∃ x ∈ s, (x, y) ∈ r } choose f hfs hfr using fun x : u => x.coe_prop.2 refine ⟨range f, ?_, ?_, ?_⟩ · exact range_subset_iff.2 hfs · haveI : Fintype u := (fk.inter_of_left _).fintype exact finite_range f · intro x xs obtain ⟨y, hy, xy⟩ := mem_iUnion₂.1 (ks xs) rw [biUnion_range, mem_iUnion] set z : ↥u := ⟨y, hy, ⟨x, xs, xy⟩⟩ exact ⟨z, rU <| mem_compRel.2 ⟨y, xy, rs (hfr z)⟩⟩ #align totally_bounded.exists_subset TotallyBounded.exists_subset theorem totallyBounded_iff_subset {s : Set α} : TotallyBounded s ↔ ∀ d ∈ 𝓤 α, ∃ t, t ⊆ s ∧ Set.Finite t ∧ s ⊆ ⋃ y ∈ t, { x | (x, y) ∈ d } := ⟨fun H _ hd => H.exists_subset hd, fun H d hd => let ⟨t, _, ht⟩ := H d hd ⟨t, ht⟩⟩ #align totally_bounded_iff_subset totallyBounded_iff_subset theorem Filter.HasBasis.totallyBounded_iff {ι} {p : ι → Prop} {U : ι → Set (α × α)} (H : (𝓤 α).HasBasis p U) {s : Set α} : TotallyBounded s ↔ ∀ i, p i → ∃ t : Set α, Set.Finite t ∧ s ⊆ ⋃ y ∈ t, { x | (x, y) ∈ U i } := H.forall_iff fun _ _ hUV h => h.imp fun _ ht => ⟨ht.1, ht.2.trans <| iUnion₂_mono fun _ _ _ hy => hUV hy⟩ #align filter.has_basis.totally_bounded_iff Filter.HasBasis.totallyBounded_iff theorem totallyBounded_of_forall_symm {s : Set α} (h : ∀ V ∈ 𝓤 α, SymmetricRel V → ∃ t : Set α, Set.Finite t ∧ s ⊆ ⋃ y ∈ t, ball y V) : TotallyBounded s := UniformSpace.hasBasis_symmetric.totallyBounded_iff.2 fun V hV => by simpa only [ball_eq_of_symmetry hV.2] using h V hV.1 hV.2 #align totally_bounded_of_forall_symm totallyBounded_of_forall_symm theorem totallyBounded_subset {s₁ s₂ : Set α} (hs : s₁ ⊆ s₂) (h : TotallyBounded s₂) : TotallyBounded s₁ := fun d hd => let ⟨t, ht₁, ht₂⟩ := h d hd ⟨t, ht₁, Subset.trans hs ht₂⟩ #align totally_bounded_subset totallyBounded_subset theorem totallyBounded_empty : TotallyBounded (∅ : Set α) := fun _ _ => ⟨∅, finite_empty, empty_subset _⟩ #align totally_bounded_empty totallyBounded_empty /-- The closure of a totally bounded set is totally bounded. -/ theorem TotallyBounded.closure {s : Set α} (h : TotallyBounded s) : TotallyBounded (closure s) := uniformity_hasBasis_closed.totallyBounded_iff.2 fun V hV => let ⟨t, htf, hst⟩ := h V hV.1 ⟨t, htf, closure_minimal hst <| htf.isClosed_biUnion fun _ _ => hV.2.preimage (continuous_id.prod_mk continuous_const)⟩ #align totally_bounded.closure TotallyBounded.closure /-- The image of a totally bounded set under a uniformly continuous map is totally bounded. -/ theorem TotallyBounded.image [UniformSpace β] {f : α → β} {s : Set α} (hs : TotallyBounded s) (hf : UniformContinuous f) : TotallyBounded (f '' s) := fun t ht => have : { p : α × α | (f p.1, f p.2) ∈ t } ∈ 𝓤 α := hf ht let ⟨c, hfc, hct⟩ := hs _ this ⟨f '' c, hfc.image f, by simp only [mem_image, iUnion_exists, biUnion_and', iUnion_iUnion_eq_right, image_subset_iff, preimage_iUnion, preimage_setOf_eq] simp? [subset_def] at hct says simp only [mem_setOf_eq, subset_def, mem_iUnion, exists_prop] at hct intro x hx; simp exact hct x hx⟩ #align totally_bounded.image TotallyBounded.image theorem Ultrafilter.cauchy_of_totallyBounded {s : Set α} (f : Ultrafilter α) (hs : TotallyBounded s) (h : ↑f ≤ 𝓟 s) : Cauchy (f : Filter α) := ⟨f.neBot', fun _ ht => let ⟨t', ht'₁, ht'_symm, ht'_t⟩ := comp_symm_of_uniformity ht let ⟨i, hi, hs_union⟩ := hs t' ht'₁ have : (⋃ y ∈ i, { x | (x, y) ∈ t' }) ∈ f := mem_of_superset (le_principal_iff.mp h) hs_union have : ∃ y ∈ i, { x | (x, y) ∈ t' } ∈ f := (Ultrafilter.finite_biUnion_mem_iff hi).1 this let ⟨y, _, hif⟩ := this have : { x | (x, y) ∈ t' } ×ˢ { x | (x, y) ∈ t' } ⊆ compRel t' t' := fun ⟨_, _⟩ ⟨(h₁ : (_, y) ∈ t'), (h₂ : (_, y) ∈ t')⟩ => ⟨y, h₁, ht'_symm h₂⟩ mem_of_superset (prod_mem_prod hif hif) (Subset.trans this ht'_t)⟩ #align ultrafilter.cauchy_of_totally_bounded Ultrafilter.cauchy_of_totallyBounded theorem totallyBounded_iff_filter {s : Set α} : TotallyBounded s ↔ ∀ f, NeBot f → f ≤ 𝓟 s → ∃ c ≤ f, Cauchy c := by constructor · exact fun H f hf hfs => ⟨Ultrafilter.of f, Ultrafilter.of_le f, (Ultrafilter.of f).cauchy_of_totallyBounded H ((Ultrafilter.of_le f).trans hfs)⟩ · intro H d hd contrapose! H with hd_cover set f := ⨅ t : Finset α, 𝓟 (s \ ⋃ y ∈ t, { x | (x, y) ∈ d }) have hb : HasAntitoneBasis f fun t : Finset α ↦ s \ ⋃ y ∈ t, { x | (x, y) ∈ d } := .iInf_principal fun _ _ ↦ diff_subset_diff_right ∘ biUnion_subset_biUnion_left have : Filter.NeBot f := hb.1.neBot_iff.2 fun _ ↦ nonempty_diff.2 <| hd_cover _ (Finset.finite_toSet _) have : f ≤ 𝓟 s := iInf_le_of_le ∅ (by simp) refine ⟨f, ‹_›, ‹_›, fun c hcf hc => ?_⟩ rcases mem_prod_same_iff.1 (hc.2 hd) with ⟨m, hm, hmd⟩ rcases hc.1.nonempty_of_mem hm with ⟨y, hym⟩ have : s \ {x | (x, y) ∈ d} ∈ c := by simpa using hcf (hb.mem {y}) rcases hc.1.nonempty_of_mem (inter_mem hm this) with ⟨z, hzm, -, hyz⟩ exact hyz (hmd ⟨hzm, hym⟩) #align totally_bounded_iff_filter totallyBounded_iff_filter
Mathlib/Topology/UniformSpace/Cauchy.lean
622
626
theorem totallyBounded_iff_ultrafilter {s : Set α} : TotallyBounded s ↔ ∀ f : Ultrafilter α, ↑f ≤ 𝓟 s → Cauchy (f : Filter α) := by
refine ⟨fun hs f => f.cauchy_of_totallyBounded hs, fun H => totallyBounded_iff_filter.2 ?_⟩ intro f hf hfs exact ⟨Ultrafilter.of f, Ultrafilter.of_le f, H _ ((Ultrafilter.of_le f).trans hfs)⟩
/- Copyright (c) 2019 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Mario Carneiro -/ import Batteries.Data.List.Basic namespace Batteries /-- `AssocList α β` is "the same as" `List (α × β)`, but flattening the structure leads to one fewer pointer indirection (in the current code generator). It is mainly intended as a component of `HashMap`, but it can also be used as a plain key-value map. -/ inductive AssocList (α : Type u) (β : Type v) where /-- An empty list -/ | nil /-- Add a `key, value` pair to the list -/ | cons (key : α) (value : β) (tail : AssocList α β) deriving Inhabited namespace AssocList /-- `O(n)`. Convert an `AssocList α β` into the equivalent `List (α × β)`. This is used to give specifications for all the `AssocList` functions in terms of corresponding list functions. -/ @[simp] def toList : AssocList α β → List (α × β) | nil => [] | cons a b es => (a, b) :: es.toList instance : EmptyCollection (AssocList α β) := ⟨nil⟩ @[simp] theorem empty_eq : (∅ : AssocList α β) = nil := rfl /-- `O(1)`. Is the list empty? -/ def isEmpty : AssocList α β → Bool | nil => true | _ => false @[simp] theorem isEmpty_eq (l : AssocList α β) : isEmpty l = l.toList.isEmpty := by cases l <;> simp [*, isEmpty, List.isEmpty] /-- The number of entries in an `AssocList`. -/ def length (L : AssocList α β) : Nat := match L with | .nil => 0 | .cons _ _ t => t.length + 1 @[simp] theorem length_nil : length (nil : AssocList α β) = 0 := rfl @[simp] theorem length_cons : length (cons a b t) = length t + 1 := rfl
.lake/packages/batteries/Batteries/Data/AssocList.lean
55
56
theorem length_toList (l : AssocList α β) : l.toList.length = l.length := by
induction l <;> simp_all
/- 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.Analysis.Calculus.FDeriv.Equiv import Mathlib.Analysis.Calculus.FormalMultilinearSeries #align_import analysis.calculus.cont_diff_def from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14" /-! # Higher differentiability A function is `C^1` on a domain if it is differentiable there, and its derivative is continuous. By induction, it is `C^n` if it is `C^{n-1}` and its (n-1)-th derivative is `C^1` there or, equivalently, if it is `C^1` and its derivative is `C^{n-1}`. Finally, it is `C^∞` if it is `C^n` for all n. We formalize these notions by defining iteratively the `n+1`-th derivative of a function as the derivative of the `n`-th derivative. It is called `iteratedFDeriv 𝕜 n f x` where `𝕜` is the field, `n` is the number of iterations, `f` is the function and `x` is the point, and it is given as an `n`-multilinear map. We also define a version `iteratedFDerivWithin` relative to a domain, as well as predicates `ContDiffWithinAt`, `ContDiffAt`, `ContDiffOn` and `ContDiff` saying that the function is `C^n` within a set at a point, at a point, on a set and on the whole space respectively. To avoid the issue of choice when choosing a derivative in sets where the derivative is not necessarily unique, `ContDiffOn` is not defined directly in terms of the regularity of the specific choice `iteratedFDerivWithin 𝕜 n f s` inside `s`, but in terms of the existence of a nice sequence of derivatives, expressed with a predicate `HasFTaylorSeriesUpToOn`. We prove basic properties of these notions. ## Main definitions and results Let `f : E → F` be a map between normed vector spaces over a nontrivially normed field `𝕜`. * `HasFTaylorSeriesUpTo n f p`: expresses that the formal multilinear series `p` is a sequence of iterated derivatives of `f`, up to the `n`-th term (where `n` is a natural number or `∞`). * `HasFTaylorSeriesUpToOn n f p s`: same thing, but inside a set `s`. The notion of derivative is now taken inside `s`. In particular, derivatives don't have to be unique. * `ContDiff 𝕜 n f`: expresses that `f` is `C^n`, i.e., it admits a Taylor series up to rank `n`. * `ContDiffOn 𝕜 n f s`: expresses that `f` is `C^n` in `s`. * `ContDiffAt 𝕜 n f x`: expresses that `f` is `C^n` around `x`. * `ContDiffWithinAt 𝕜 n f s x`: expresses that `f` is `C^n` around `x` within the set `s`. * `iteratedFDerivWithin 𝕜 n f s x` is an `n`-th derivative of `f` over the field `𝕜` on the set `s` at the point `x`. It is a continuous multilinear map from `E^n` to `F`, defined as a derivative within `s` of `iteratedFDerivWithin 𝕜 (n-1) f s` if one exists, and `0` otherwise. * `iteratedFDeriv 𝕜 n f x` is the `n`-th derivative of `f` over the field `𝕜` at the point `x`. It is a continuous multilinear map from `E^n` to `F`, defined as a derivative of `iteratedFDeriv 𝕜 (n-1) f` if one exists, and `0` otherwise. In sets of unique differentiability, `ContDiffOn 𝕜 n f s` can be expressed in terms of the properties of `iteratedFDerivWithin 𝕜 m f s` for `m ≤ n`. In the whole space, `ContDiff 𝕜 n f` can be expressed in terms of the properties of `iteratedFDeriv 𝕜 m f` for `m ≤ n`. ## Implementation notes The definitions in this file are designed to work on any field `𝕜`. They are sometimes slightly more complicated than the naive definitions one would guess from the intuition over the real or complex numbers, but they are designed to circumvent the lack of gluing properties and partitions of unity in general. In the usual situations, they coincide with the usual definitions. ### Definition of `C^n` functions in domains One could define `C^n` functions in a domain `s` by fixing an arbitrary choice of derivatives (this is what we do with `iteratedFDerivWithin`) and requiring that all these derivatives up to `n` are continuous. If the derivative is not unique, this could lead to strange behavior like two `C^n` functions `f` and `g` on `s` whose sum is not `C^n`. A better definition is thus to say that a function is `C^n` inside `s` if it admits a sequence of derivatives up to `n` inside `s`. This definition still has the problem that a function which is locally `C^n` would not need to be `C^n`, as different choices of sequences of derivatives around different points might possibly not be glued together to give a globally defined sequence of derivatives. (Note that this issue can not happen over reals, thanks to partition of unity, but the behavior over a general field is not so clear, and we want a definition for general fields). Also, there are locality problems for the order parameter: one could image a function which, for each `n`, has a nice sequence of derivatives up to order `n`, but they do not coincide for varying `n` and can therefore not be glued to give rise to an infinite sequence of derivatives. This would give a function which is `C^n` for all `n`, but not `C^∞`. We solve this issue by putting locality conditions in space and order in our definition of `ContDiffWithinAt` and `ContDiffOn`. The resulting definition is slightly more complicated to work with (in fact not so much), but it gives rise to completely satisfactory theorems. For instance, with this definition, a real function which is `C^m` (but not better) on `(-1/m, 1/m)` for each natural `m` is by definition `C^∞` at `0`. There is another issue with the definition of `ContDiffWithinAt 𝕜 n f s x`. We can require the existence and good behavior of derivatives up to order `n` on a neighborhood of `x` within `s`. However, this does not imply continuity or differentiability within `s` of the function at `x` when `x` does not belong to `s`. Therefore, we require such existence and good behavior on a neighborhood of `x` within `s ∪ {x}` (which appears as `insert x s` in this file). ### Side of the composition, and universe issues With a naïve direct definition, the `n`-th derivative of a function belongs to the space `E →L[𝕜] (E →L[𝕜] (E ... F)...)))` where there are n iterations of `E →L[𝕜]`. This space may also be seen as the space of continuous multilinear functions on `n` copies of `E` with values in `F`, by uncurrying. This is the point of view that is usually adopted in textbooks, and that we also use. This means that the definition and the first proofs are slightly involved, as one has to keep track of the uncurrying operation. The uncurrying can be done from the left or from the right, amounting to defining the `n+1`-th derivative either as the derivative of the `n`-th derivative, or as the `n`-th derivative of the derivative. For proofs, it would be more convenient to use the latter approach (from the right), as it means to prove things at the `n+1`-th step we only need to understand well enough the derivative in `E →L[𝕜] F` (contrary to the approach from the left, where one would need to know enough on the `n`-th derivative to deduce things on the `n+1`-th derivative). However, the definition from the right leads to a universe polymorphism problem: if we define `iteratedFDeriv 𝕜 (n + 1) f x = iteratedFDeriv 𝕜 n (fderiv 𝕜 f) x` by induction, we need to generalize over all spaces (as `f` and `fderiv 𝕜 f` don't take values in the same space). It is only possible to generalize over all spaces in some fixed universe in an inductive definition. For `f : E → F`, then `fderiv 𝕜 f` is a map `E → (E →L[𝕜] F)`. Therefore, the definition will only work if `F` and `E →L[𝕜] F` are in the same universe. This issue does not appear with the definition from the left, where one does not need to generalize over all spaces. Therefore, we use the definition from the left. This means some proofs later on become a little bit more complicated: to prove that a function is `C^n`, the most efficient approach is to exhibit a formula for its `n`-th derivative and prove it is continuous (contrary to the inductive approach where one would prove smoothness statements without giving a formula for the derivative). In the end, this approach is still satisfactory as it is good to have formulas for the iterated derivatives in various constructions. One point where we depart from this explicit approach is in the proof of smoothness of a composition: there is a formula for the `n`-th derivative of a composition (Faà di Bruno's formula), but it is very complicated and barely usable, while the inductive proof is very simple. Thus, we give the inductive proof. As explained above, it works by generalizing over the target space, hence it only works well if all spaces belong to the same universe. To get the general version, we lift things to a common universe using a trick. ### Variables management The textbook definitions and proofs use various identifications and abuse of notations, for instance when saying that the natural space in which the derivative lives, i.e., `E →L[𝕜] (E →L[𝕜] ( ... →L[𝕜] F))`, is the same as a space of multilinear maps. When doing things formally, we need to provide explicit maps for these identifications, and chase some diagrams to see everything is compatible with the identifications. In particular, one needs to check that taking the derivative and then doing the identification, or first doing the identification and then taking the derivative, gives the same result. The key point for this is that taking the derivative commutes with continuous linear equivalences. Therefore, we need to implement all our identifications with continuous linear equivs. ## 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 open NNReal Topology Filter local notation "∞" => (⊤ : ℕ∞) /- Porting note: These lines are not required in Mathlib4. attribute [local instance 1001] NormedAddCommGroup.toAddCommGroup NormedSpace.toModule' AddCommGroup.toAddCommMonoid -/ open Set Fin Filter Function universe u uE uF uG uX variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] {E : Type uE} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type uF} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type uG} [NormedAddCommGroup G] [NormedSpace 𝕜 G] {X : Type uX} [NormedAddCommGroup X] [NormedSpace 𝕜 X] {s s₁ t u : Set E} {f f₁ : E → F} {g : F → G} {x x₀ : E} {c : F} {m n : ℕ∞} {p : E → FormalMultilinearSeries 𝕜 E F} /-! ### Functions with a Taylor series on a domain -/ /-- `HasFTaylorSeriesUpToOn n f p s` registers the fact that `p 0 = f` and `p (m+1)` is a derivative of `p m` for `m < n`, and is continuous for `m ≤ n`. This is a predicate analogous to `HasFDerivWithinAt` but for higher order derivatives. Notice that `p` does not sum up to `f` on the diagonal (`FormalMultilinearSeries.sum`), even if `f` is analytic and `n = ∞`: an additional `1/m!` factor on the `m`th term is necessary for that. -/ structure HasFTaylorSeriesUpToOn (n : ℕ∞) (f : E → F) (p : E → FormalMultilinearSeries 𝕜 E F) (s : Set E) : Prop where zero_eq : ∀ x ∈ s, (p x 0).uncurry0 = f x protected fderivWithin : ∀ m : ℕ, (m : ℕ∞) < n → ∀ x ∈ s, HasFDerivWithinAt (p · m) (p x m.succ).curryLeft s x cont : ∀ m : ℕ, (m : ℕ∞) ≤ n → ContinuousOn (p · m) s #align has_ftaylor_series_up_to_on HasFTaylorSeriesUpToOn theorem HasFTaylorSeriesUpToOn.zero_eq' (h : HasFTaylorSeriesUpToOn n f p s) {x : E} (hx : x ∈ s) : p x 0 = (continuousMultilinearCurryFin0 𝕜 E F).symm (f x) := by rw [← h.zero_eq x hx] exact (p x 0).uncurry0_curry0.symm #align has_ftaylor_series_up_to_on.zero_eq' HasFTaylorSeriesUpToOn.zero_eq' /-- If two functions coincide on a set `s`, then a Taylor series for the first one is as well a Taylor series for the second one. -/ theorem HasFTaylorSeriesUpToOn.congr (h : HasFTaylorSeriesUpToOn n f p s) (h₁ : ∀ x ∈ s, f₁ x = f x) : HasFTaylorSeriesUpToOn n f₁ p s := by refine ⟨fun x hx => ?_, h.fderivWithin, h.cont⟩ rw [h₁ x hx] exact h.zero_eq x hx #align has_ftaylor_series_up_to_on.congr HasFTaylorSeriesUpToOn.congr theorem HasFTaylorSeriesUpToOn.mono (h : HasFTaylorSeriesUpToOn n f p s) {t : Set E} (hst : t ⊆ s) : HasFTaylorSeriesUpToOn n f p t := ⟨fun x hx => h.zero_eq x (hst hx), fun m hm x hx => (h.fderivWithin m hm x (hst hx)).mono hst, fun m hm => (h.cont m hm).mono hst⟩ #align has_ftaylor_series_up_to_on.mono HasFTaylorSeriesUpToOn.mono theorem HasFTaylorSeriesUpToOn.of_le (h : HasFTaylorSeriesUpToOn n f p s) (hmn : m ≤ n) : HasFTaylorSeriesUpToOn m f p s := ⟨h.zero_eq, fun k hk x hx => h.fderivWithin k (lt_of_lt_of_le hk hmn) x hx, fun k hk => h.cont k (le_trans hk hmn)⟩ #align has_ftaylor_series_up_to_on.of_le HasFTaylorSeriesUpToOn.of_le theorem HasFTaylorSeriesUpToOn.continuousOn (h : HasFTaylorSeriesUpToOn n f p s) : ContinuousOn f s := by have := (h.cont 0 bot_le).congr fun x hx => (h.zero_eq' hx).symm rwa [← (continuousMultilinearCurryFin0 𝕜 E F).symm.comp_continuousOn_iff] #align has_ftaylor_series_up_to_on.continuous_on HasFTaylorSeriesUpToOn.continuousOn theorem hasFTaylorSeriesUpToOn_zero_iff : HasFTaylorSeriesUpToOn 0 f p s ↔ ContinuousOn f s ∧ ∀ x ∈ s, (p x 0).uncurry0 = f x := by refine ⟨fun H => ⟨H.continuousOn, H.zero_eq⟩, fun H => ⟨H.2, fun m hm => False.elim (not_le.2 hm bot_le), fun m hm ↦ ?_⟩⟩ obtain rfl : m = 0 := mod_cast hm.antisymm (zero_le _) have : EqOn (p · 0) ((continuousMultilinearCurryFin0 𝕜 E F).symm ∘ f) s := fun x hx ↦ (continuousMultilinearCurryFin0 𝕜 E F).eq_symm_apply.2 (H.2 x hx) rw [continuousOn_congr this, LinearIsometryEquiv.comp_continuousOn_iff] exact H.1 #align has_ftaylor_series_up_to_on_zero_iff hasFTaylorSeriesUpToOn_zero_iff
Mathlib/Analysis/Calculus/ContDiff/Defs.lean
240
250
theorem hasFTaylorSeriesUpToOn_top_iff : HasFTaylorSeriesUpToOn ∞ f p s ↔ ∀ n : ℕ, HasFTaylorSeriesUpToOn n f p s := by
constructor · intro H n; exact H.of_le le_top · intro H constructor · exact (H 0).zero_eq · intro m _ apply (H m.succ).fderivWithin m (WithTop.coe_lt_coe.2 (lt_add_one m)) · intro m _ apply (H m).cont m le_rfl
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne -/ import Mathlib.MeasureTheory.Integral.SetToL1 #align_import measure_theory.integral.bochner from "leanprover-community/mathlib"@"48fb5b5280e7c81672afc9524185ae994553ebf4" /-! # Bochner integral The Bochner integral extends the definition of the Lebesgue integral to functions that map from a measure space into a Banach space (complete normed vector space). It is constructed here by extending the integral on simple functions. ## Main definitions The Bochner integral is defined through the extension process described in the file `SetToL1`, which follows these steps: 1. Define the integral of the indicator of a set. This is `weightedSMul μ s x = (μ s).toReal * x`. `weightedSMul μ` is shown to be linear in the value `x` and `DominatedFinMeasAdditive` (defined in the file `SetToL1`) with respect to the set `s`. 2. Define the integral on simple functions of the type `SimpleFunc α E` (notation : `α →ₛ E`) where `E` is a real normed space. (See `SimpleFunc.integral` for details.) 3. Transfer this definition to define the integral on `L1.simpleFunc α E` (notation : `α →₁ₛ[μ] E`), see `L1.simpleFunc.integral`. Show that this integral is a continuous linear map from `α →₁ₛ[μ] E` to `E`. 4. Define the Bochner integral on L1 functions by extending the integral on integrable simple functions `α →₁ₛ[μ] E` using `ContinuousLinearMap.extend` and the fact that the embedding of `α →₁ₛ[μ] E` into `α →₁[μ] E` is dense. 5. Define the Bochner integral on functions as the Bochner integral of its equivalence class in L1 space, if it is in L1, and 0 otherwise. The result of that construction is `∫ a, f a ∂μ`, which is definitionally equal to `setToFun (dominatedFinMeasAdditive_weightedSMul μ) f`. Some basic properties of the integral (like linearity) are particular cases of the properties of `setToFun` (which are described in the file `SetToL1`). ## Main statements 1. Basic properties of the Bochner integral on functions of type `α → E`, where `α` is a measure space and `E` is a real normed space. * `integral_zero` : `∫ 0 ∂μ = 0` * `integral_add` : `∫ x, f x + g x ∂μ = ∫ x, f ∂μ + ∫ x, g x ∂μ` * `integral_neg` : `∫ x, - f x ∂μ = - ∫ x, f x ∂μ` * `integral_sub` : `∫ x, f x - g x ∂μ = ∫ x, f x ∂μ - ∫ x, g x ∂μ` * `integral_smul` : `∫ x, r • f x ∂μ = r • ∫ x, f x ∂μ` * `integral_congr_ae` : `f =ᵐ[μ] g → ∫ x, f x ∂μ = ∫ x, g x ∂μ` * `norm_integral_le_integral_norm` : `‖∫ x, f x ∂μ‖ ≤ ∫ x, ‖f x‖ ∂μ` 2. Basic properties of the Bochner integral on functions of type `α → ℝ`, where `α` is a measure space. * `integral_nonneg_of_ae` : `0 ≤ᵐ[μ] f → 0 ≤ ∫ x, f x ∂μ` * `integral_nonpos_of_ae` : `f ≤ᵐ[μ] 0 → ∫ x, f x ∂μ ≤ 0` * `integral_mono_ae` : `f ≤ᵐ[μ] g → ∫ x, f x ∂μ ≤ ∫ x, g x ∂μ` * `integral_nonneg` : `0 ≤ f → 0 ≤ ∫ x, f x ∂μ` * `integral_nonpos` : `f ≤ 0 → ∫ x, f x ∂μ ≤ 0` * `integral_mono` : `f ≤ᵐ[μ] g → ∫ x, f x ∂μ ≤ ∫ x, g x ∂μ` 3. Propositions connecting the Bochner integral with the integral on `ℝ≥0∞`-valued functions, which is called `lintegral` and has the notation `∫⁻`. * `integral_eq_lintegral_pos_part_sub_lintegral_neg_part` : `∫ x, f x ∂μ = ∫⁻ x, f⁺ x ∂μ - ∫⁻ x, f⁻ x ∂μ`, where `f⁺` is the positive part of `f` and `f⁻` is the negative part of `f`. * `integral_eq_lintegral_of_nonneg_ae` : `0 ≤ᵐ[μ] f → ∫ x, f x ∂μ = ∫⁻ x, f x ∂μ` 4. (In the file `DominatedConvergence`) `tendsto_integral_of_dominated_convergence` : the Lebesgue dominated convergence theorem 5. (In the file `SetIntegral`) integration commutes with continuous linear maps. * `ContinuousLinearMap.integral_comp_comm` * `LinearIsometry.integral_comp_comm` ## Notes Some tips on how to prove a proposition if the API for the Bochner integral is not enough so that you need to unfold the definition of the Bochner integral and go back to simple functions. One method is to use the theorem `Integrable.induction` in the file `SimpleFuncDenseLp` (or one of the related results, like `Lp.induction` for functions in `Lp`), which allows you to prove something for an arbitrary integrable function. Another method is using the following steps. See `integral_eq_lintegral_pos_part_sub_lintegral_neg_part` for a complicated example, which proves that `∫ f = ∫⁻ f⁺ - ∫⁻ f⁻`, with the first integral sign being the Bochner integral of a real-valued function `f : α → ℝ`, and second and third integral sign being the integral on `ℝ≥0∞`-valued functions (called `lintegral`). The proof of `integral_eq_lintegral_pos_part_sub_lintegral_neg_part` is scattered in sections with the name `posPart`. Here are the usual steps of proving that a property `p`, say `∫ f = ∫⁻ f⁺ - ∫⁻ f⁻`, holds for all functions : 1. First go to the `L¹` space. For example, if you see `ENNReal.toReal (∫⁻ a, ENNReal.ofReal <| ‖f a‖)`, that is the norm of `f` in `L¹` space. Rewrite using `L1.norm_of_fun_eq_lintegral_norm`. 2. Show that the set `{f ∈ L¹ | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻}` is closed in `L¹` using `isClosed_eq`. 3. Show that the property holds for all simple functions `s` in `L¹` space. Typically, you need to convert various notions to their `SimpleFunc` counterpart, using lemmas like `L1.integral_coe_eq_integral`. 4. Since simple functions are dense in `L¹`, ``` univ = closure {s simple} = closure {s simple | ∫ s = ∫⁻ s⁺ - ∫⁻ s⁻} : the property holds for all simple functions ⊆ closure {f | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻} = {f | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻} : closure of a closed set is itself ``` Use `isClosed_property` or `DenseRange.induction_on` for this argument. ## Notations * `α →ₛ E` : simple functions (defined in `MeasureTheory/Integration`) * `α →₁[μ] E` : functions in L1 space, i.e., equivalence classes of integrable functions (defined in `MeasureTheory/LpSpace`) * `α →₁ₛ[μ] E` : simple functions in L1 space, i.e., equivalence classes of integrable simple functions (defined in `MeasureTheory/SimpleFuncDense`) * `∫ a, f a ∂μ` : integral of `f` with respect to a measure `μ` * `∫ a, f a` : integral of `f` with respect to `volume`, the default measure on the ambient type We also define notations for integral on a set, which are described in the file `MeasureTheory/SetIntegral`. Note : `ₛ` is typed using `\_s`. Sometimes it shows as a box if the font is missing. ## Tags Bochner integral, simple function, function space, Lebesgue dominated convergence theorem -/ assert_not_exists Differentiable noncomputable section open scoped Topology NNReal ENNReal MeasureTheory open Set Filter TopologicalSpace ENNReal EMetric namespace MeasureTheory variable {α E F 𝕜 : Type*} section WeightedSMul open ContinuousLinearMap variable [NormedAddCommGroup F] [NormedSpace ℝ F] {m : MeasurableSpace α} {μ : Measure α} /-- Given a set `s`, return the continuous linear map `fun x => (μ s).toReal • x`. The extension of that set function through `setToL1` gives the Bochner integral of L1 functions. -/ def weightedSMul {_ : MeasurableSpace α} (μ : Measure α) (s : Set α) : F →L[ℝ] F := (μ s).toReal • ContinuousLinearMap.id ℝ F #align measure_theory.weighted_smul MeasureTheory.weightedSMul theorem weightedSMul_apply {m : MeasurableSpace α} (μ : Measure α) (s : Set α) (x : F) : weightedSMul μ s x = (μ s).toReal • x := by simp [weightedSMul] #align measure_theory.weighted_smul_apply MeasureTheory.weightedSMul_apply @[simp] theorem weightedSMul_zero_measure {m : MeasurableSpace α} : weightedSMul (0 : Measure α) = (0 : Set α → F →L[ℝ] F) := by ext1; simp [weightedSMul] #align measure_theory.weighted_smul_zero_measure MeasureTheory.weightedSMul_zero_measure @[simp] theorem weightedSMul_empty {m : MeasurableSpace α} (μ : Measure α) : weightedSMul μ ∅ = (0 : F →L[ℝ] F) := by ext1 x; rw [weightedSMul_apply]; simp #align measure_theory.weighted_smul_empty MeasureTheory.weightedSMul_empty theorem weightedSMul_add_measure {m : MeasurableSpace α} (μ ν : Measure α) {s : Set α} (hμs : μ s ≠ ∞) (hνs : ν s ≠ ∞) : (weightedSMul (μ + ν) s : F →L[ℝ] F) = weightedSMul μ s + weightedSMul ν s := by ext1 x push_cast simp_rw [Pi.add_apply, weightedSMul_apply] push_cast rw [Pi.add_apply, ENNReal.toReal_add hμs hνs, add_smul] #align measure_theory.weighted_smul_add_measure MeasureTheory.weightedSMul_add_measure
Mathlib/MeasureTheory/Integral/Bochner.lean
195
201
theorem weightedSMul_smul_measure {m : MeasurableSpace α} (μ : Measure α) (c : ℝ≥0∞) {s : Set α} : (weightedSMul (c • μ) s : F →L[ℝ] F) = c.toReal • weightedSMul μ s := by
ext1 x push_cast simp_rw [Pi.smul_apply, weightedSMul_apply] push_cast simp_rw [Pi.smul_apply, smul_eq_mul, toReal_mul, smul_smul]
/- 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.Data.Set.Lattice import Mathlib.Logic.Small.Basic import Mathlib.Logic.Function.OfArity import Mathlib.Order.WellFounded #align_import set_theory.zfc.basic from "leanprover-community/mathlib"@"f0b3759a8ef0bd8239ecdaa5e1089add5feebe1a" /-! # A model of ZFC In this file, we model Zermelo-Fraenkel set theory (+ Choice) using Lean's underlying type theory. We do this in four main steps: * Define pre-sets inductively. * Define extensional equivalence on pre-sets and give it a `setoid` instance. * Define ZFC sets by quotienting pre-sets by extensional equivalence. * Define classes as sets of ZFC sets. Then the rest is usual set theory. ## The model * `PSet`: Pre-set. A pre-set is inductively defined by its indexing type and its members, which are themselves pre-sets. * `ZFSet`: ZFC set. Defined as `PSet` quotiented by `PSet.Equiv`, the extensional equivalence. * `Class`: Class. Defined as `Set ZFSet`. * `ZFSet.choice`: Axiom of choice. Proved from Lean's axiom of choice. ## Other definitions * `PSet.Type`: Underlying type of a pre-set. * `PSet.Func`: Underlying family of pre-sets of a pre-set. * `PSet.Equiv`: Extensional equivalence of pre-sets. Defined inductively. * `PSet.omega`, `ZFSet.omega`: The von Neumann ordinal `ω` as a `PSet`, as a `Set`. * `PSet.Arity.Equiv`: Extensional equivalence of `n`-ary `PSet`-valued functions. Extension of `PSet.Equiv`. * `PSet.Resp`: Collection of `n`-ary `PSet`-valued functions that respect extensional equivalence. * `PSet.eval`: Turns a `PSet`-valued function that respect extensional equivalence into a `ZFSet`-valued function. * `Classical.allDefinable`: All functions are classically definable. * `ZFSet.IsFunc` : Predicate that a ZFC set is a subset of `x × y` that can be considered as a ZFC function `x → y`. That is, each member of `x` is related by the ZFC set to exactly one member of `y`. * `ZFSet.funs`: ZFC set of ZFC functions `x → y`. * `ZFSet.Hereditarily p x`: Predicate that every set in the transitive closure of `x` has property `p`. * `Class.iota`: Definite description operator. ## Notes To avoid confusion between the Lean `Set` and the ZFC `Set`, docstrings in this file refer to them respectively as "`Set`" and "ZFC set". ## TODO Prove `ZFSet.mapDefinableAux` computably. -/ -- Porting note: Lean 3 uses `Set` for `ZFSet`. set_option linter.uppercaseLean3 false universe u v open Function (OfArity) /-- The type of pre-sets in universe `u`. A pre-set is a family of pre-sets indexed by a type in `Type u`. The ZFC universe is defined as a quotient of this to ensure extensionality. -/ inductive PSet : Type (u + 1) | mk (α : Type u) (A : α → PSet) : PSet #align pSet PSet namespace PSet /-- The underlying type of a pre-set -/ def «Type» : PSet → Type u | ⟨α, _⟩ => α #align pSet.type PSet.Type /-- The underlying pre-set family of a pre-set -/ def Func : ∀ x : PSet, x.Type → PSet | ⟨_, A⟩ => A #align pSet.func PSet.Func @[simp] theorem mk_type (α A) : «Type» ⟨α, A⟩ = α := rfl #align pSet.mk_type PSet.mk_type @[simp] theorem mk_func (α A) : Func ⟨α, A⟩ = A := rfl #align pSet.mk_func PSet.mk_func @[simp] theorem eta : ∀ x : PSet, mk x.Type x.Func = x | ⟨_, _⟩ => rfl #align pSet.eta PSet.eta /-- Two pre-sets are extensionally equivalent if every element of the first family is extensionally equivalent to some element of the second family and vice-versa. -/ def Equiv : PSet → PSet → Prop | ⟨_, A⟩, ⟨_, B⟩ => (∀ a, ∃ b, Equiv (A a) (B b)) ∧ (∀ b, ∃ a, Equiv (A a) (B b)) #align pSet.equiv PSet.Equiv theorem equiv_iff : ∀ {x y : PSet}, Equiv x y ↔ (∀ i, ∃ j, Equiv (x.Func i) (y.Func j)) ∧ ∀ j, ∃ i, Equiv (x.Func i) (y.Func j) | ⟨_, _⟩, ⟨_, _⟩ => Iff.rfl #align pSet.equiv_iff PSet.equiv_iff theorem Equiv.exists_left {x y : PSet} (h : Equiv x y) : ∀ i, ∃ j, Equiv (x.Func i) (y.Func j) := (equiv_iff.1 h).1 #align pSet.equiv.exists_left PSet.Equiv.exists_left theorem Equiv.exists_right {x y : PSet} (h : Equiv x y) : ∀ j, ∃ i, Equiv (x.Func i) (y.Func j) := (equiv_iff.1 h).2 #align pSet.equiv.exists_right PSet.Equiv.exists_right @[refl] protected theorem Equiv.refl : ∀ x, Equiv x x | ⟨_, _⟩ => ⟨fun a => ⟨a, Equiv.refl _⟩, fun a => ⟨a, Equiv.refl _⟩⟩ #align pSet.equiv.refl PSet.Equiv.refl protected theorem Equiv.rfl {x} : Equiv x x := Equiv.refl x #align pSet.equiv.rfl PSet.Equiv.rfl protected theorem Equiv.euc : ∀ {x y z}, Equiv x y → Equiv z y → Equiv x z | ⟨_, _⟩, ⟨_, _⟩, ⟨_, _⟩, ⟨αβ, βα⟩, ⟨γβ, βγ⟩ => ⟨ fun a => let ⟨b, ab⟩ := αβ a let ⟨c, bc⟩ := βγ b ⟨c, Equiv.euc ab bc⟩, fun c => let ⟨b, cb⟩ := γβ c let ⟨a, ba⟩ := βα b ⟨a, Equiv.euc ba cb⟩ ⟩ #align pSet.equiv.euc PSet.Equiv.euc @[symm] protected theorem Equiv.symm {x y} : Equiv x y → Equiv y x := (Equiv.refl y).euc #align pSet.equiv.symm PSet.Equiv.symm protected theorem Equiv.comm {x y} : Equiv x y ↔ Equiv y x := ⟨Equiv.symm, Equiv.symm⟩ #align pSet.equiv.comm PSet.Equiv.comm @[trans] protected theorem Equiv.trans {x y z} (h1 : Equiv x y) (h2 : Equiv y z) : Equiv x z := h1.euc h2.symm #align pSet.equiv.trans PSet.Equiv.trans protected theorem equiv_of_isEmpty (x y : PSet) [IsEmpty x.Type] [IsEmpty y.Type] : Equiv x y := equiv_iff.2 <| by simp #align pSet.equiv_of_is_empty PSet.equiv_of_isEmpty instance setoid : Setoid PSet := ⟨PSet.Equiv, Equiv.refl, Equiv.symm, Equiv.trans⟩ #align pSet.setoid PSet.setoid /-- A pre-set is a subset of another pre-set if every element of the first family is extensionally equivalent to some element of the second family. -/ protected def Subset (x y : PSet) : Prop := ∀ a, ∃ b, Equiv (x.Func a) (y.Func b) #align pSet.subset PSet.Subset instance : HasSubset PSet := ⟨PSet.Subset⟩ instance : IsRefl PSet (· ⊆ ·) := ⟨fun _ a => ⟨a, Equiv.refl _⟩⟩ instance : IsTrans PSet (· ⊆ ·) := ⟨fun x y z hxy hyz a => by cases' hxy a with b hb cases' hyz b with c hc exact ⟨c, hb.trans hc⟩⟩ theorem Equiv.ext : ∀ x y : PSet, Equiv x y ↔ x ⊆ y ∧ y ⊆ x | ⟨_, _⟩, ⟨_, _⟩ => ⟨fun ⟨αβ, βα⟩ => ⟨αβ, fun b => let ⟨a, h⟩ := βα b ⟨a, Equiv.symm h⟩⟩, fun ⟨αβ, βα⟩ => ⟨αβ, fun b => let ⟨a, h⟩ := βα b ⟨a, Equiv.symm h⟩⟩⟩ #align pSet.equiv.ext PSet.Equiv.ext theorem Subset.congr_left : ∀ {x y z : PSet}, Equiv x y → (x ⊆ z ↔ y ⊆ z) | ⟨_, _⟩, ⟨_, _⟩, ⟨_, _⟩, ⟨αβ, βα⟩ => ⟨fun αγ b => let ⟨a, ba⟩ := βα b let ⟨c, ac⟩ := αγ a ⟨c, (Equiv.symm ba).trans ac⟩, fun βγ a => let ⟨b, ab⟩ := αβ a let ⟨c, bc⟩ := βγ b ⟨c, Equiv.trans ab bc⟩⟩ #align pSet.subset.congr_left PSet.Subset.congr_left theorem Subset.congr_right : ∀ {x y z : PSet}, Equiv x y → (z ⊆ x ↔ z ⊆ y) | ⟨_, _⟩, ⟨_, _⟩, ⟨_, _⟩, ⟨αβ, βα⟩ => ⟨fun γα c => let ⟨a, ca⟩ := γα c let ⟨b, ab⟩ := αβ a ⟨b, ca.trans ab⟩, fun γβ c => let ⟨b, cb⟩ := γβ c let ⟨a, ab⟩ := βα b ⟨a, cb.trans (Equiv.symm ab)⟩⟩ #align pSet.subset.congr_right PSet.Subset.congr_right /-- `x ∈ y` as pre-sets if `x` is extensionally equivalent to a member of the family `y`. -/ protected def Mem (x y : PSet.{u}) : Prop := ∃ b, Equiv x (y.Func b) #align pSet.mem PSet.Mem instance : Membership PSet PSet := ⟨PSet.Mem⟩ theorem Mem.mk {α : Type u} (A : α → PSet) (a : α) : A a ∈ mk α A := ⟨a, Equiv.refl (A a)⟩ #align pSet.mem.mk PSet.Mem.mk theorem func_mem (x : PSet) (i : x.Type) : x.Func i ∈ x := by cases x apply Mem.mk #align pSet.func_mem PSet.func_mem theorem Mem.ext : ∀ {x y : PSet.{u}}, (∀ w : PSet.{u}, w ∈ x ↔ w ∈ y) → Equiv x y | ⟨_, A⟩, ⟨_, B⟩, h => ⟨fun a => (h (A a)).1 (Mem.mk A a), fun b => let ⟨a, ha⟩ := (h (B b)).2 (Mem.mk B b) ⟨a, ha.symm⟩⟩ #align pSet.mem.ext PSet.Mem.ext theorem Mem.congr_right : ∀ {x y : PSet.{u}}, Equiv x y → ∀ {w : PSet.{u}}, w ∈ x ↔ w ∈ y | ⟨_, _⟩, ⟨_, _⟩, ⟨αβ, βα⟩, _ => ⟨fun ⟨a, ha⟩ => let ⟨b, hb⟩ := αβ a ⟨b, ha.trans hb⟩, fun ⟨b, hb⟩ => let ⟨a, ha⟩ := βα b ⟨a, hb.euc ha⟩⟩ #align pSet.mem.congr_right PSet.Mem.congr_right theorem equiv_iff_mem {x y : PSet.{u}} : Equiv x y ↔ ∀ {w : PSet.{u}}, w ∈ x ↔ w ∈ y := ⟨Mem.congr_right, match x, y with | ⟨_, A⟩, ⟨_, B⟩ => fun h => ⟨fun a => h.1 (Mem.mk A a), fun b => let ⟨a, h⟩ := h.2 (Mem.mk B b) ⟨a, h.symm⟩⟩⟩ #align pSet.equiv_iff_mem PSet.equiv_iff_mem theorem Mem.congr_left : ∀ {x y : PSet.{u}}, Equiv x y → ∀ {w : PSet.{u}}, x ∈ w ↔ y ∈ w | _, _, h, ⟨_, _⟩ => ⟨fun ⟨a, ha⟩ => ⟨a, h.symm.trans ha⟩, fun ⟨a, ha⟩ => ⟨a, h.trans ha⟩⟩ #align pSet.mem.congr_left PSet.Mem.congr_left private theorem mem_wf_aux : ∀ {x y : PSet.{u}}, Equiv x y → Acc (· ∈ ·) y | ⟨α, A⟩, ⟨β, B⟩, H => ⟨_, by rintro ⟨γ, C⟩ ⟨b, hc⟩ cases' H.exists_right b with a ha have H := ha.trans hc.symm rw [mk_func] at H exact mem_wf_aux H⟩ theorem mem_wf : @WellFounded PSet (· ∈ ·) := ⟨fun x => mem_wf_aux <| Equiv.refl x⟩ #align pSet.mem_wf PSet.mem_wf instance : WellFoundedRelation PSet := ⟨_, mem_wf⟩ instance : IsAsymm PSet (· ∈ ·) := mem_wf.isAsymm instance : IsIrrefl PSet (· ∈ ·) := mem_wf.isIrrefl theorem mem_asymm {x y : PSet} : x ∈ y → y ∉ x := asymm #align pSet.mem_asymm PSet.mem_asymm theorem mem_irrefl (x : PSet) : x ∉ x := irrefl x #align pSet.mem_irrefl PSet.mem_irrefl /-- Convert a pre-set to a `Set` of pre-sets. -/ def toSet (u : PSet.{u}) : Set PSet.{u} := { x | x ∈ u } #align pSet.to_set PSet.toSet @[simp] theorem mem_toSet (a u : PSet.{u}) : a ∈ u.toSet ↔ a ∈ u := Iff.rfl #align pSet.mem_to_set PSet.mem_toSet /-- A nonempty set is one that contains some element. -/ protected def Nonempty (u : PSet) : Prop := u.toSet.Nonempty #align pSet.nonempty PSet.Nonempty theorem nonempty_def (u : PSet) : u.Nonempty ↔ ∃ x, x ∈ u := Iff.rfl #align pSet.nonempty_def PSet.nonempty_def theorem nonempty_of_mem {x u : PSet} (h : x ∈ u) : u.Nonempty := ⟨x, h⟩ #align pSet.nonempty_of_mem PSet.nonempty_of_mem @[simp] theorem nonempty_toSet_iff {u : PSet} : u.toSet.Nonempty ↔ u.Nonempty := Iff.rfl #align pSet.nonempty_to_set_iff PSet.nonempty_toSet_iff theorem nonempty_type_iff_nonempty {x : PSet} : Nonempty x.Type ↔ PSet.Nonempty x := ⟨fun ⟨i⟩ => ⟨_, func_mem _ i⟩, fun ⟨_, j, _⟩ => ⟨j⟩⟩ #align pSet.nonempty_type_iff_nonempty PSet.nonempty_type_iff_nonempty theorem nonempty_of_nonempty_type (x : PSet) [h : Nonempty x.Type] : PSet.Nonempty x := nonempty_type_iff_nonempty.1 h #align pSet.nonempty_of_nonempty_type PSet.nonempty_of_nonempty_type /-- Two pre-sets are equivalent iff they have the same members. -/ theorem Equiv.eq {x y : PSet} : Equiv x y ↔ toSet x = toSet y := equiv_iff_mem.trans Set.ext_iff.symm #align pSet.equiv.eq PSet.Equiv.eq instance : Coe PSet (Set PSet) := ⟨toSet⟩ /-- The empty pre-set -/ protected def empty : PSet := ⟨_, PEmpty.elim⟩ #align pSet.empty PSet.empty instance : EmptyCollection PSet := ⟨PSet.empty⟩ instance : Inhabited PSet := ⟨∅⟩ instance : IsEmpty («Type» ∅) := ⟨PEmpty.elim⟩ @[simp] theorem not_mem_empty (x : PSet.{u}) : x ∉ (∅ : PSet.{u}) := IsEmpty.exists_iff.1 #align pSet.not_mem_empty PSet.not_mem_empty @[simp] theorem toSet_empty : toSet ∅ = ∅ := by simp [toSet] #align pSet.to_set_empty PSet.toSet_empty @[simp] theorem empty_subset (x : PSet.{u}) : (∅ : PSet) ⊆ x := fun x => x.elim #align pSet.empty_subset PSet.empty_subset @[simp] theorem not_nonempty_empty : ¬PSet.Nonempty ∅ := by simp [PSet.Nonempty] #align pSet.not_nonempty_empty PSet.not_nonempty_empty protected theorem equiv_empty (x : PSet) [IsEmpty x.Type] : Equiv x ∅ := PSet.equiv_of_isEmpty x _ #align pSet.equiv_empty PSet.equiv_empty /-- Insert an element into a pre-set -/ protected def insert (x y : PSet) : PSet := ⟨Option y.Type, fun o => Option.casesOn o x y.Func⟩ #align pSet.insert PSet.insert instance : Insert PSet PSet := ⟨PSet.insert⟩ instance : Singleton PSet PSet := ⟨fun s => insert s ∅⟩ instance : LawfulSingleton PSet PSet := ⟨fun _ => rfl⟩ instance (x y : PSet) : Inhabited (insert x y).Type := inferInstanceAs (Inhabited <| Option y.Type) /-- The n-th von Neumann ordinal -/ def ofNat : ℕ → PSet | 0 => ∅ | n + 1 => insert (ofNat n) (ofNat n) #align pSet.of_nat PSet.ofNat /-- The von Neumann ordinal ω -/ def omega : PSet := ⟨ULift ℕ, fun n => ofNat n.down⟩ #align pSet.omega PSet.omega /-- The pre-set separation operation `{x ∈ a | p x}` -/ protected def sep (p : PSet → Prop) (x : PSet) : PSet := ⟨{ a // p (x.Func a) }, fun y => x.Func y.1⟩ #align pSet.sep PSet.sep instance : Sep PSet PSet := ⟨PSet.sep⟩ /-- The pre-set powerset operator -/ def powerset (x : PSet) : PSet := ⟨Set x.Type, fun p => ⟨{ a // p a }, fun y => x.Func y.1⟩⟩ #align pSet.powerset PSet.powerset @[simp] theorem mem_powerset : ∀ {x y : PSet}, y ∈ powerset x ↔ y ⊆ x | ⟨_, A⟩, ⟨_, B⟩ => ⟨fun ⟨_, e⟩ => (Subset.congr_left e).2 fun ⟨a, _⟩ => ⟨a, Equiv.refl (A a)⟩, fun βα => ⟨{ a | ∃ b, Equiv (B b) (A a) }, fun b => let ⟨a, ba⟩ := βα b ⟨⟨a, b, ba⟩, ba⟩, fun ⟨_, b, ba⟩ => ⟨b, ba⟩⟩⟩ #align pSet.mem_powerset PSet.mem_powerset /-- The pre-set union operator -/ def sUnion (a : PSet) : PSet := ⟨Σx, (a.Func x).Type, fun ⟨x, y⟩ => (a.Func x).Func y⟩ #align pSet.sUnion PSet.sUnion @[inherit_doc] prefix:110 "⋃₀ " => sUnion @[simp] theorem mem_sUnion : ∀ {x y : PSet.{u}}, y ∈ ⋃₀ x ↔ ∃ z ∈ x, y ∈ z | ⟨α, A⟩, y => ⟨fun ⟨⟨a, c⟩, (e : Equiv y ((A a).Func c))⟩ => have : Func (A a) c ∈ mk (A a).Type (A a).Func := Mem.mk (A a).Func c ⟨_, Mem.mk _ _, (Mem.congr_left e).2 (by rwa [eta] at this)⟩, fun ⟨⟨β, B⟩, ⟨a, (e : Equiv (mk β B) (A a))⟩, ⟨b, yb⟩⟩ => by rw [← eta (A a)] at e exact let ⟨βt, _⟩ := e let ⟨c, bc⟩ := βt b ⟨⟨a, c⟩, yb.trans bc⟩⟩ #align pSet.mem_sUnion PSet.mem_sUnion @[simp] theorem toSet_sUnion (x : PSet.{u}) : (⋃₀ x).toSet = ⋃₀ (toSet '' x.toSet) := by ext simp #align pSet.to_set_sUnion PSet.toSet_sUnion /-- The image of a function from pre-sets to pre-sets. -/ def image (f : PSet.{u} → PSet.{u}) (x : PSet.{u}) : PSet := ⟨x.Type, f ∘ x.Func⟩ #align pSet.image PSet.image -- Porting note: H arguments made explicit. theorem mem_image {f : PSet.{u} → PSet.{u}} (H : ∀ x y, Equiv x y → Equiv (f x) (f y)) : ∀ {x y : PSet.{u}}, y ∈ image f x ↔ ∃ z ∈ x, Equiv y (f z) | ⟨_, A⟩, _ => ⟨fun ⟨a, ya⟩ => ⟨A a, Mem.mk A a, ya⟩, fun ⟨_, ⟨a, za⟩, yz⟩ => ⟨a, yz.trans <| H _ _ za⟩⟩ #align pSet.mem_image PSet.mem_image /-- Universe lift operation -/ protected def Lift : PSet.{u} → PSet.{max u v} | ⟨α, A⟩ => ⟨ULift.{v, u} α, fun ⟨x⟩ => PSet.Lift (A x)⟩ #align pSet.lift PSet.Lift -- intended to be used with explicit universe parameters /-- Embedding of one universe in another -/ @[nolint checkUnivs] def embed : PSet.{max (u + 1) v} := ⟨ULift.{v, u + 1} PSet, fun ⟨x⟩ => PSet.Lift.{u, max (u + 1) v} x⟩ #align pSet.embed PSet.embed theorem lift_mem_embed : ∀ x : PSet.{u}, PSet.Lift.{u, max (u + 1) v} x ∈ embed.{u, v} := fun x => ⟨⟨x⟩, Equiv.rfl⟩ #align pSet.lift_mem_embed PSet.lift_mem_embed /-- Function equivalence is defined so that `f ~ g` iff `∀ x y, x ~ y → f x ~ g y`. This extends to equivalence of `n`-ary functions. -/ def Arity.Equiv : ∀ {n}, OfArity PSet.{u} PSet.{u} n → OfArity PSet.{u} PSet.{u} n → Prop | 0, a, b => PSet.Equiv a b | _ + 1, a, b => ∀ x y : PSet, PSet.Equiv x y → Arity.Equiv (a x) (b y) #align pSet.arity.equiv PSet.Arity.Equiv theorem Arity.equiv_const {a : PSet.{u}} : ∀ n, Arity.Equiv (OfArity.const PSet.{u} a n) (OfArity.const PSet.{u} a n) | 0 => Equiv.rfl | _ + 1 => fun _ _ _ => Arity.equiv_const _ #align pSet.arity.equiv_const PSet.Arity.equiv_const /-- `resp n` is the collection of n-ary functions on `PSet` that respect equivalence, i.e. when the inputs are equivalent the output is as well. -/ def Resp (n) := { x : OfArity PSet.{u} PSet.{u} n // Arity.Equiv x x } #align pSet.resp PSet.Resp instance Resp.inhabited {n} : Inhabited (Resp n) := ⟨⟨OfArity.const _ default _, Arity.equiv_const _⟩⟩ #align pSet.resp.inhabited PSet.Resp.inhabited /-- The `n`-ary image of a `(n + 1)`-ary function respecting equivalence as a function respecting equivalence. -/ def Resp.f {n} (f : Resp (n + 1)) (x : PSet) : Resp n := ⟨f.1 x, f.2 _ _ <| Equiv.refl x⟩ #align pSet.resp.f PSet.Resp.f /-- Function equivalence for functions respecting equivalence. See `PSet.Arity.Equiv`. -/ def Resp.Equiv {n} (a b : Resp n) : Prop := Arity.Equiv a.1 b.1 #align pSet.resp.equiv PSet.Resp.Equiv @[refl] protected theorem Resp.Equiv.refl {n} (a : Resp n) : Resp.Equiv a a := a.2 #align pSet.resp.equiv.refl PSet.Resp.Equiv.refl protected theorem Resp.Equiv.euc : ∀ {n} {a b c : Resp n}, Resp.Equiv a b → Resp.Equiv c b → Resp.Equiv a c | 0, _, _, _, hab, hcb => PSet.Equiv.euc hab hcb | n + 1, a, b, c, hab, hcb => fun x y h => @Resp.Equiv.euc n (a.f x) (b.f y) (c.f y) (hab _ _ h) (hcb _ _ <| PSet.Equiv.refl y) #align pSet.resp.equiv.euc PSet.Resp.Equiv.euc @[symm] protected theorem Resp.Equiv.symm {n} {a b : Resp n} : Resp.Equiv a b → Resp.Equiv b a := (Resp.Equiv.refl b).euc #align pSet.resp.equiv.symm PSet.Resp.Equiv.symm @[trans] protected theorem Resp.Equiv.trans {n} {x y z : Resp n} (h1 : Resp.Equiv x y) (h2 : Resp.Equiv y z) : Resp.Equiv x z := h1.euc h2.symm #align pSet.resp.equiv.trans PSet.Resp.Equiv.trans instance Resp.setoid {n} : Setoid (Resp n) := ⟨Resp.Equiv, Resp.Equiv.refl, Resp.Equiv.symm, Resp.Equiv.trans⟩ #align pSet.resp.setoid PSet.Resp.setoid end PSet /-- The ZFC universe of sets consists of the type of pre-sets, quotiented by extensional equivalence. -/ def ZFSet : Type (u + 1) := Quotient PSet.setoid.{u} #align Set ZFSet namespace PSet namespace Resp /-- Helper function for `PSet.eval`. -/ def evalAux : ∀ {n}, { f : Resp n → OfArity ZFSet.{u} ZFSet.{u} n // ∀ a b : Resp n, Resp.Equiv a b → f a = f b } | 0 => ⟨fun a => ⟦a.1⟧, fun _ _ h => Quotient.sound h⟩ | n + 1 => let F : Resp (n + 1) → OfArity ZFSet ZFSet (n + 1) := fun a => @Quotient.lift _ _ PSet.setoid (fun x => evalAux.1 (a.f x)) fun _ _ h => evalAux.2 _ _ (a.2 _ _ h) ⟨F, fun b c h => funext <| (@Quotient.ind _ _ fun q => F b q = F c q) fun z => evalAux.2 (Resp.f b z) (Resp.f c z) (h _ _ (PSet.Equiv.refl z))⟩ #align pSet.resp.eval_aux PSet.Resp.evalAux /-- An equivalence-respecting function yields an n-ary ZFC set function. -/ def eval (n) : Resp n → OfArity ZFSet.{u} ZFSet.{u} n := evalAux.1 #align pSet.resp.eval PSet.Resp.eval theorem eval_val {n f x} : (@eval (n + 1) f : ZFSet → OfArity ZFSet ZFSet n) ⟦x⟧ = eval n (Resp.f f x) := rfl #align pSet.resp.eval_val PSet.Resp.eval_val end Resp /-- A set function is "definable" if it is the image of some n-ary pre-set function. This isn't exactly definability, but is useful as a sufficient condition for functions that have a computable image. -/ class inductive Definable (n) : OfArity ZFSet.{u} ZFSet.{u} n → Type (u + 1) | mk (f) : Definable n (Resp.eval n f) #align pSet.definable PSet.Definable attribute [instance] Definable.mk /-- The evaluation of a function respecting equivalence is definable, by that same function. -/ def Definable.EqMk {n} (f) : ∀ {s : OfArity ZFSet.{u} ZFSet.{u} n} (_ : Resp.eval _ f = s), Definable n s | _, rfl => ⟨f⟩ #align pSet.definable.eq_mk PSet.Definable.EqMk /-- Turns a definable function into a function that respects equivalence. -/ def Definable.Resp {n} : ∀ (s : OfArity ZFSet.{u} ZFSet.{u} n) [Definable n s], Resp n | _, ⟨f⟩ => f #align pSet.definable.resp PSet.Definable.Resp theorem Definable.eq {n} : ∀ (s : OfArity ZFSet.{u} ZFSet.{u} n) [H : Definable n s], (@Definable.Resp n s H).eval _ = s | _, ⟨_⟩ => rfl #align pSet.definable.eq PSet.Definable.eq end PSet namespace Classical open PSet /-- All functions are classically definable. -/ noncomputable def allDefinable : ∀ {n} (F : OfArity ZFSet ZFSet n), Definable n F | 0, F => let p := @Quotient.exists_rep PSet _ F @Definable.EqMk 0 ⟨choose p, Equiv.rfl⟩ _ (choose_spec p) | n + 1, (F : OfArity ZFSet ZFSet (n + 1)) => by have I : (x : ZFSet) → Definable n (F x) := fun x => allDefinable (F x) refine @Definable.EqMk (n + 1) ⟨fun x : PSet => (@Definable.Resp _ _ (I ⟦x⟧)).1, ?_⟩ _ ?_ · dsimp [Arity.Equiv] intro x y h rw [@Quotient.sound PSet _ _ _ h] exact (Definable.Resp (F ⟦y⟧)).2 refine funext fun q => Quotient.inductionOn q fun x => ?_ simp_rw [Resp.eval_val, Resp.f] exact @Definable.eq _ (F ⟦x⟧) (I ⟦x⟧) #align classical.all_definable Classical.allDefinable end Classical namespace ZFSet open PSet /-- Turns a pre-set into a ZFC set. -/ def mk : PSet → ZFSet := Quotient.mk'' #align Set.mk ZFSet.mk @[simp] theorem mk_eq (x : PSet) : @Eq ZFSet ⟦x⟧ (mk x) := rfl #align Set.mk_eq ZFSet.mk_eq @[simp] theorem mk_out : ∀ x : ZFSet, mk x.out = x := Quotient.out_eq #align Set.mk_out ZFSet.mk_out theorem eq {x y : PSet} : mk x = mk y ↔ Equiv x y := Quotient.eq #align Set.eq ZFSet.eq theorem sound {x y : PSet} (h : PSet.Equiv x y) : mk x = mk y := Quotient.sound h #align Set.sound ZFSet.sound theorem exact {x y : PSet} : mk x = mk y → PSet.Equiv x y := Quotient.exact #align Set.exact ZFSet.exact @[simp] theorem eval_mk {n f x} : (@Resp.eval (n + 1) f : ZFSet → OfArity ZFSet ZFSet n) (mk x) = Resp.eval n (Resp.f f x) := rfl #align Set.eval_mk ZFSet.eval_mk /-- The membership relation for ZFC sets is inherited from the membership relation for pre-sets. -/ protected def Mem : ZFSet → ZFSet → Prop := Quotient.lift₂ PSet.Mem fun _ _ _ _ hx hy => propext ((Mem.congr_left hx).trans (Mem.congr_right hy)) #align Set.mem ZFSet.Mem instance : Membership ZFSet ZFSet := ⟨ZFSet.Mem⟩ @[simp] theorem mk_mem_iff {x y : PSet} : mk x ∈ mk y ↔ x ∈ y := Iff.rfl #align Set.mk_mem_iff ZFSet.mk_mem_iff /-- Convert a ZFC set into a `Set` of ZFC sets -/ def toSet (u : ZFSet.{u}) : Set ZFSet.{u} := { x | x ∈ u } #align Set.to_set ZFSet.toSet @[simp] theorem mem_toSet (a u : ZFSet.{u}) : a ∈ u.toSet ↔ a ∈ u := Iff.rfl #align Set.mem_to_set ZFSet.mem_toSet instance small_toSet (x : ZFSet.{u}) : Small.{u} x.toSet := Quotient.inductionOn x fun a => by let f : a.Type → (mk a).toSet := fun i => ⟨mk <| a.Func i, func_mem a i⟩ suffices Function.Surjective f by exact small_of_surjective this rintro ⟨y, hb⟩ induction y using Quotient.inductionOn cases' hb with i h exact ⟨i, Subtype.coe_injective (Quotient.sound h.symm)⟩ #align Set.small_to_set ZFSet.small_toSet /-- A nonempty set is one that contains some element. -/ protected def Nonempty (u : ZFSet) : Prop := u.toSet.Nonempty #align Set.nonempty ZFSet.Nonempty theorem nonempty_def (u : ZFSet) : u.Nonempty ↔ ∃ x, x ∈ u := Iff.rfl #align Set.nonempty_def ZFSet.nonempty_def theorem nonempty_of_mem {x u : ZFSet} (h : x ∈ u) : u.Nonempty := ⟨x, h⟩ #align Set.nonempty_of_mem ZFSet.nonempty_of_mem @[simp] theorem nonempty_toSet_iff {u : ZFSet} : u.toSet.Nonempty ↔ u.Nonempty := Iff.rfl #align Set.nonempty_to_set_iff ZFSet.nonempty_toSet_iff /-- `x ⊆ y` as ZFC sets means that all members of `x` are members of `y`. -/ protected def Subset (x y : ZFSet.{u}) := ∀ ⦃z⦄, z ∈ x → z ∈ y #align Set.subset ZFSet.Subset instance hasSubset : HasSubset ZFSet := ⟨ZFSet.Subset⟩ #align Set.has_subset ZFSet.hasSubset theorem subset_def {x y : ZFSet.{u}} : x ⊆ y ↔ ∀ ⦃z⦄, z ∈ x → z ∈ y := Iff.rfl #align Set.subset_def ZFSet.subset_def instance : IsRefl ZFSet (· ⊆ ·) := ⟨fun _ _ => id⟩ instance : IsTrans ZFSet (· ⊆ ·) := ⟨fun _ _ _ hxy hyz _ ha => hyz (hxy ha)⟩ @[simp] theorem subset_iff : ∀ {x y : PSet}, mk x ⊆ mk y ↔ x ⊆ y | ⟨_, A⟩, ⟨_, _⟩ => ⟨fun h a => @h ⟦A a⟧ (Mem.mk A a), fun h z => Quotient.inductionOn z fun _ ⟨a, za⟩ => let ⟨b, ab⟩ := h a ⟨b, za.trans ab⟩⟩ #align Set.subset_iff ZFSet.subset_iff @[simp] theorem toSet_subset_iff {x y : ZFSet} : x.toSet ⊆ y.toSet ↔ x ⊆ y := by simp [subset_def, Set.subset_def] #align Set.to_set_subset_iff ZFSet.toSet_subset_iff @[ext] theorem ext {x y : ZFSet.{u}} : (∀ z : ZFSet.{u}, z ∈ x ↔ z ∈ y) → x = y := Quotient.inductionOn₂ x y fun _ _ h => Quotient.sound (Mem.ext fun w => h ⟦w⟧) #align Set.ext ZFSet.ext theorem ext_iff {x y : ZFSet.{u}} : x = y ↔ ∀ z : ZFSet.{u}, z ∈ x ↔ z ∈ y := ⟨fun h => by simp [h], ext⟩ #align Set.ext_iff ZFSet.ext_iff theorem toSet_injective : Function.Injective toSet := fun _ _ h => ext <| Set.ext_iff.1 h #align Set.to_set_injective ZFSet.toSet_injective @[simp] theorem toSet_inj {x y : ZFSet} : x.toSet = y.toSet ↔ x = y := toSet_injective.eq_iff #align Set.to_set_inj ZFSet.toSet_inj instance : IsAntisymm ZFSet (· ⊆ ·) := ⟨fun _ _ hab hba => ext fun c => ⟨@hab c, @hba c⟩⟩ /-- The empty ZFC set -/ protected def empty : ZFSet := mk ∅ #align Set.empty ZFSet.empty instance : EmptyCollection ZFSet := ⟨ZFSet.empty⟩ instance : Inhabited ZFSet := ⟨∅⟩ @[simp] theorem not_mem_empty (x) : x ∉ (∅ : ZFSet.{u}) := Quotient.inductionOn x PSet.not_mem_empty #align Set.not_mem_empty ZFSet.not_mem_empty @[simp] theorem toSet_empty : toSet ∅ = ∅ := by simp [toSet] #align Set.to_set_empty ZFSet.toSet_empty @[simp] theorem empty_subset (x : ZFSet.{u}) : (∅ : ZFSet) ⊆ x := Quotient.inductionOn x fun y => subset_iff.2 <| PSet.empty_subset y #align Set.empty_subset ZFSet.empty_subset @[simp] theorem not_nonempty_empty : ¬ZFSet.Nonempty ∅ := by simp [ZFSet.Nonempty] #align Set.not_nonempty_empty ZFSet.not_nonempty_empty @[simp] theorem nonempty_mk_iff {x : PSet} : (mk x).Nonempty ↔ x.Nonempty := by refine ⟨?_, fun ⟨a, h⟩ => ⟨mk a, h⟩⟩ rintro ⟨a, h⟩ induction a using Quotient.inductionOn exact ⟨_, h⟩ #align Set.nonempty_mk_iff ZFSet.nonempty_mk_iff theorem eq_empty (x : ZFSet.{u}) : x = ∅ ↔ ∀ y : ZFSet.{u}, y ∉ x := by rw [ext_iff] simp #align Set.eq_empty ZFSet.eq_empty theorem eq_empty_or_nonempty (u : ZFSet) : u = ∅ ∨ u.Nonempty := by rw [eq_empty, ← not_exists] apply em' #align Set.eq_empty_or_nonempty ZFSet.eq_empty_or_nonempty /-- `Insert x y` is the set `{x} ∪ y` -/ protected def Insert : ZFSet → ZFSet → ZFSet := Resp.eval 2 ⟨PSet.insert, fun _ _ uv ⟨_, _⟩ ⟨_, _⟩ ⟨αβ, βα⟩ => ⟨fun o => match o with | some a => let ⟨b, hb⟩ := αβ a ⟨some b, hb⟩ | none => ⟨none, uv⟩, fun o => match o with | some b => let ⟨a, ha⟩ := βα b ⟨some a, ha⟩ | none => ⟨none, uv⟩⟩⟩ #align Set.insert ZFSet.Insert instance : Insert ZFSet ZFSet := ⟨ZFSet.Insert⟩ instance : Singleton ZFSet ZFSet := ⟨fun x => insert x ∅⟩ instance : LawfulSingleton ZFSet ZFSet := ⟨fun _ => rfl⟩ @[simp] theorem mem_insert_iff {x y z : ZFSet.{u}} : x ∈ insert y z ↔ x = y ∨ x ∈ z := Quotient.inductionOn₃ x y z fun x y ⟨α, A⟩ => show (x ∈ PSet.mk (Option α) fun o => Option.rec y A o) ↔ mk x = mk y ∨ x ∈ PSet.mk α A from ⟨fun m => match m with | ⟨some a, ha⟩ => Or.inr ⟨a, ha⟩ | ⟨none, h⟩ => Or.inl (Quotient.sound h), fun m => match m with | Or.inr ⟨a, ha⟩ => ⟨some a, ha⟩ | Or.inl h => ⟨none, Quotient.exact h⟩⟩ #align Set.mem_insert_iff ZFSet.mem_insert_iff theorem mem_insert (x y : ZFSet) : x ∈ insert x y := mem_insert_iff.2 <| Or.inl rfl #align Set.mem_insert ZFSet.mem_insert theorem mem_insert_of_mem {y z : ZFSet} (x) (h : z ∈ y) : z ∈ insert x y := mem_insert_iff.2 <| Or.inr h #align Set.mem_insert_of_mem ZFSet.mem_insert_of_mem @[simp] theorem toSet_insert (x y : ZFSet) : (insert x y).toSet = insert x y.toSet := by ext simp #align Set.to_set_insert ZFSet.toSet_insert @[simp] theorem mem_singleton {x y : ZFSet.{u}} : x ∈ @singleton ZFSet.{u} ZFSet.{u} _ y ↔ x = y := Iff.trans mem_insert_iff ⟨fun o => Or.rec (fun h => h) (fun n => absurd n (not_mem_empty _)) o, Or.inl⟩ #align Set.mem_singleton ZFSet.mem_singleton @[simp] theorem toSet_singleton (x : ZFSet) : ({x} : ZFSet).toSet = {x} := by ext simp #align Set.to_set_singleton ZFSet.toSet_singleton theorem insert_nonempty (u v : ZFSet) : (insert u v).Nonempty := ⟨u, mem_insert u v⟩ #align Set.insert_nonempty ZFSet.insert_nonempty theorem singleton_nonempty (u : ZFSet) : ZFSet.Nonempty {u} := insert_nonempty u ∅ #align Set.singleton_nonempty ZFSet.singleton_nonempty theorem mem_pair {x y z : ZFSet.{u}} : x ∈ ({y, z} : ZFSet) ↔ x = y ∨ x = z := by simp #align Set.mem_pair ZFSet.mem_pair /-- `omega` is the first infinite von Neumann ordinal -/ def omega : ZFSet := mk PSet.omega #align Set.omega ZFSet.omega @[simp] theorem omega_zero : ∅ ∈ omega := ⟨⟨0⟩, Equiv.rfl⟩ #align Set.omega_zero ZFSet.omega_zero @[simp] theorem omega_succ {n} : n ∈ omega.{u} → insert n n ∈ omega.{u} := Quotient.inductionOn n fun x ⟨⟨n⟩, h⟩ => ⟨⟨n + 1⟩, ZFSet.exact <| show insert (mk x) (mk x) = insert (mk <| ofNat n) (mk <| ofNat n) by rw [ZFSet.sound h] rfl⟩ #align Set.omega_succ ZFSet.omega_succ /-- `{x ∈ a | p x}` is the set of elements in `a` satisfying `p` -/ protected def sep (p : ZFSet → Prop) : ZFSet → ZFSet := Resp.eval 1 ⟨PSet.sep fun y => p (mk y), fun ⟨α, A⟩ ⟨β, B⟩ ⟨αβ, βα⟩ => ⟨fun ⟨a, pa⟩ => let ⟨b, hb⟩ := αβ a ⟨⟨b, by simpa only [mk_func, ← ZFSet.sound hb]⟩, hb⟩, fun ⟨b, pb⟩ => let ⟨a, ha⟩ := βα b ⟨⟨a, by simpa only [mk_func, ZFSet.sound ha]⟩, ha⟩⟩⟩ #align Set.sep ZFSet.sep -- Porting note: the { x | p x } notation appears to be disabled in Lean 4. instance : Sep ZFSet ZFSet := ⟨ZFSet.sep⟩ @[simp] theorem mem_sep {p : ZFSet.{u} → Prop} {x y : ZFSet.{u}} : y ∈ ZFSet.sep p x ↔ y ∈ x ∧ p y := Quotient.inductionOn₂ x y fun ⟨α, A⟩ y => ⟨fun ⟨⟨a, pa⟩, h⟩ => ⟨⟨a, h⟩, by rwa [@Quotient.sound PSet _ _ _ h]⟩, fun ⟨⟨a, h⟩, pa⟩ => ⟨⟨a, by rw [mk_func] at h rwa [mk_func, ← ZFSet.sound h]⟩, h⟩⟩ #align Set.mem_sep ZFSet.mem_sep @[simp] theorem toSet_sep (a : ZFSet) (p : ZFSet → Prop) : (ZFSet.sep p a).toSet = { x ∈ a.toSet | p x } := by ext simp #align Set.to_set_sep ZFSet.toSet_sep /-- The powerset operation, the collection of subsets of a ZFC set -/ def powerset : ZFSet → ZFSet := Resp.eval 1 ⟨PSet.powerset, fun ⟨_, A⟩ ⟨_, B⟩ ⟨αβ, βα⟩ => ⟨fun p => ⟨{ b | ∃ a, p a ∧ Equiv (A a) (B b) }, fun ⟨a, pa⟩ => let ⟨b, ab⟩ := αβ a ⟨⟨b, a, pa, ab⟩, ab⟩, fun ⟨_, a, pa, ab⟩ => ⟨⟨a, pa⟩, ab⟩⟩, fun q => ⟨{ a | ∃ b, q b ∧ Equiv (A a) (B b) }, fun ⟨_, b, qb, ab⟩ => ⟨⟨b, qb⟩, ab⟩, fun ⟨b, qb⟩ => let ⟨a, ab⟩ := βα b ⟨⟨a, b, qb, ab⟩, ab⟩⟩⟩⟩ #align Set.powerset ZFSet.powerset @[simp] theorem mem_powerset {x y : ZFSet.{u}} : y ∈ powerset x ↔ y ⊆ x := Quotient.inductionOn₂ x y fun ⟨α, A⟩ ⟨β, B⟩ => show (⟨β, B⟩ : PSet.{u}) ∈ PSet.powerset.{u} ⟨α, A⟩ ↔ _ by simp [mem_powerset, subset_iff] #align Set.mem_powerset ZFSet.mem_powerset theorem sUnion_lem {α β : Type u} (A : α → PSet) (B : β → PSet) (αβ : ∀ a, ∃ b, Equiv (A a) (B b)) : ∀ a, ∃ b, Equiv ((sUnion ⟨α, A⟩).Func a) ((sUnion ⟨β, B⟩).Func b) | ⟨a, c⟩ => by let ⟨b, hb⟩ := αβ a induction' ea : A a with γ Γ induction' eb : B b with δ Δ rw [ea, eb] at hb cases' hb with γδ δγ let c : (A a).Type := c let ⟨d, hd⟩ := γδ (by rwa [ea] at c) use ⟨b, Eq.ndrec d (Eq.symm eb)⟩ change PSet.Equiv ((A a).Func c) ((B b).Func (Eq.ndrec d eb.symm)) match A a, B b, ea, eb, c, d, hd with | _, _, rfl, rfl, _, _, hd => exact hd #align Set.sUnion_lem ZFSet.sUnion_lem /-- The union operator, the collection of elements of elements of a ZFC set -/ def sUnion : ZFSet → ZFSet := Resp.eval 1 ⟨PSet.sUnion, fun ⟨_, A⟩ ⟨_, B⟩ ⟨αβ, βα⟩ => ⟨sUnion_lem A B αβ, fun a => Exists.elim (sUnion_lem B A (fun b => Exists.elim (βα b) fun c hc => ⟨c, PSet.Equiv.symm hc⟩) a) fun b hb => ⟨b, PSet.Equiv.symm hb⟩⟩⟩ #align Set.sUnion ZFSet.sUnion @[inherit_doc] prefix:110 "⋃₀ " => ZFSet.sUnion /-- The intersection operator, the collection of elements in all of the elements of a ZFC set. We special-case `⋂₀ ∅ = ∅`. -/ noncomputable def sInter (x : ZFSet) : ZFSet := by classical exact if h : x.Nonempty then ZFSet.sep (fun y => ∀ z ∈ x, y ∈ z) h.some else ∅ #align Set.sInter ZFSet.sInter @[inherit_doc] prefix:110 "⋂₀ " => ZFSet.sInter @[simp] theorem mem_sUnion {x y : ZFSet.{u}} : y ∈ ⋃₀ x ↔ ∃ z ∈ x, y ∈ z := Quotient.inductionOn₂ x y fun _ _ => Iff.trans PSet.mem_sUnion ⟨fun ⟨z, h⟩ => ⟨⟦z⟧, h⟩, fun ⟨z, h⟩ => Quotient.inductionOn z (fun z h => ⟨z, h⟩) h⟩ #align Set.mem_sUnion ZFSet.mem_sUnion theorem mem_sInter {x y : ZFSet} (h : x.Nonempty) : y ∈ ⋂₀ x ↔ ∀ z ∈ x, y ∈ z := by rw [sInter, dif_pos h] simp only [mem_toSet, mem_sep, and_iff_right_iff_imp] exact fun H => H _ h.some_mem #align Set.mem_sInter ZFSet.mem_sInter @[simp] theorem sUnion_empty : ⋃₀ (∅ : ZFSet.{u}) = ∅ := by ext simp #align Set.sUnion_empty ZFSet.sUnion_empty @[simp] theorem sInter_empty : ⋂₀ (∅ : ZFSet) = ∅ := dif_neg <| by simp #align Set.sInter_empty ZFSet.sInter_empty theorem mem_of_mem_sInter {x y z : ZFSet} (hy : y ∈ ⋂₀ x) (hz : z ∈ x) : y ∈ z := by rcases eq_empty_or_nonempty x with (rfl | hx) · exact (not_mem_empty z hz).elim · exact (mem_sInter hx).1 hy z hz #align Set.mem_of_mem_sInter ZFSet.mem_of_mem_sInter theorem mem_sUnion_of_mem {x y z : ZFSet} (hy : y ∈ z) (hz : z ∈ x) : y ∈ ⋃₀ x := mem_sUnion.2 ⟨z, hz, hy⟩ #align Set.mem_sUnion_of_mem ZFSet.mem_sUnion_of_mem theorem not_mem_sInter_of_not_mem {x y z : ZFSet} (hy : ¬y ∈ z) (hz : z ∈ x) : ¬y ∈ ⋂₀ x := fun hx => hy <| mem_of_mem_sInter hx hz #align Set.not_mem_sInter_of_not_mem ZFSet.not_mem_sInter_of_not_mem @[simp] theorem sUnion_singleton {x : ZFSet.{u}} : ⋃₀ ({x} : ZFSet) = x := ext fun y => by simp_rw [mem_sUnion, mem_singleton, exists_eq_left] #align Set.sUnion_singleton ZFSet.sUnion_singleton @[simp] theorem sInter_singleton {x : ZFSet.{u}} : ⋂₀ ({x} : ZFSet) = x := ext fun y => by simp_rw [mem_sInter (singleton_nonempty x), mem_singleton, forall_eq] #align Set.sInter_singleton ZFSet.sInter_singleton @[simp] theorem toSet_sUnion (x : ZFSet.{u}) : (⋃₀ x).toSet = ⋃₀ (toSet '' x.toSet) := by ext simp #align Set.to_set_sUnion ZFSet.toSet_sUnion theorem toSet_sInter {x : ZFSet.{u}} (h : x.Nonempty) : (⋂₀ x).toSet = ⋂₀ (toSet '' x.toSet) := by ext simp [mem_sInter h] #align Set.to_set_sInter ZFSet.toSet_sInter theorem singleton_injective : Function.Injective (@singleton ZFSet ZFSet _) := fun x y H => by let this := congr_arg sUnion H rwa [sUnion_singleton, sUnion_singleton] at this #align Set.singleton_injective ZFSet.singleton_injective @[simp] theorem singleton_inj {x y : ZFSet} : ({x} : ZFSet) = {y} ↔ x = y := singleton_injective.eq_iff #align Set.singleton_inj ZFSet.singleton_inj /-- The binary union operation -/ protected def union (x y : ZFSet.{u}) : ZFSet.{u} := ⋃₀ {x, y} #align Set.union ZFSet.union /-- The binary intersection operation -/ protected def inter (x y : ZFSet.{u}) : ZFSet.{u} := ZFSet.sep (fun z => z ∈ y) x -- { z ∈ x | z ∈ y } #align Set.inter ZFSet.inter /-- The set difference operation -/ protected def diff (x y : ZFSet.{u}) : ZFSet.{u} := ZFSet.sep (fun z => z ∉ y) x -- { z ∈ x | z ∉ y } #align Set.diff ZFSet.diff instance : Union ZFSet := ⟨ZFSet.union⟩ instance : Inter ZFSet := ⟨ZFSet.inter⟩ instance : SDiff ZFSet := ⟨ZFSet.diff⟩ @[simp] theorem toSet_union (x y : ZFSet.{u}) : (x ∪ y).toSet = x.toSet ∪ y.toSet := by change (⋃₀ {x, y}).toSet = _ simp #align Set.to_set_union ZFSet.toSet_union @[simp] theorem toSet_inter (x y : ZFSet.{u}) : (x ∩ y).toSet = x.toSet ∩ y.toSet := by change (ZFSet.sep (fun z => z ∈ y) x).toSet = _ ext simp #align Set.to_set_inter ZFSet.toSet_inter @[simp] theorem toSet_sdiff (x y : ZFSet.{u}) : (x \ y).toSet = x.toSet \ y.toSet := by change (ZFSet.sep (fun z => z ∉ y) x).toSet = _ ext simp #align Set.to_set_sdiff ZFSet.toSet_sdiff @[simp] theorem mem_union {x y z : ZFSet.{u}} : z ∈ x ∪ y ↔ z ∈ x ∨ z ∈ y := by rw [← mem_toSet] simp #align Set.mem_union ZFSet.mem_union @[simp] theorem mem_inter {x y z : ZFSet.{u}} : z ∈ x ∩ y ↔ z ∈ x ∧ z ∈ y := @mem_sep (fun z : ZFSet.{u} => z ∈ y) x z #align Set.mem_inter ZFSet.mem_inter @[simp] theorem mem_diff {x y z : ZFSet.{u}} : z ∈ x \ y ↔ z ∈ x ∧ z ∉ y := @mem_sep (fun z : ZFSet.{u} => z ∉ y) x z #align Set.mem_diff ZFSet.mem_diff @[simp] theorem sUnion_pair {x y : ZFSet.{u}} : ⋃₀ ({x, y} : ZFSet.{u}) = x ∪ y := rfl #align Set.sUnion_pair ZFSet.sUnion_pair theorem mem_wf : @WellFounded ZFSet (· ∈ ·) := (wellFounded_lift₂_iff (H := fun a b c d hx hy => propext ((@Mem.congr_left a c hx).trans (@Mem.congr_right b d hy _)))).mpr PSet.mem_wf #align Set.mem_wf ZFSet.mem_wf /-- Induction on the `∈` relation. -/ @[elab_as_elim] theorem inductionOn {p : ZFSet → Prop} (x) (h : ∀ x, (∀ y ∈ x, p y) → p x) : p x := mem_wf.induction x h #align Set.induction_on ZFSet.inductionOn instance : WellFoundedRelation ZFSet := ⟨_, mem_wf⟩ instance : IsAsymm ZFSet (· ∈ ·) := mem_wf.isAsymm -- Porting note: this can't be inferred automatically for some reason. instance : IsIrrefl ZFSet (· ∈ ·) := mem_wf.isIrrefl theorem mem_asymm {x y : ZFSet} : x ∈ y → y ∉ x := asymm #align Set.mem_asymm ZFSet.mem_asymm theorem mem_irrefl (x : ZFSet) : x ∉ x := irrefl x #align Set.mem_irrefl ZFSet.mem_irrefl theorem regularity (x : ZFSet.{u}) (h : x ≠ ∅) : ∃ y ∈ x, x ∩ y = ∅ := by_contradiction fun ne => h <| (eq_empty x).2 fun y => @inductionOn (fun z => z ∉ x) y fun z IH zx => ne ⟨z, zx, (eq_empty _).2 fun w wxz => let ⟨wx, wz⟩ := mem_inter.1 wxz IH w wz wx⟩ #align Set.regularity ZFSet.regularity /-- The image of a (definable) ZFC set function -/ def image (f : ZFSet → ZFSet) [Definable 1 f] : ZFSet → ZFSet := let ⟨r, hr⟩ := @Definable.Resp 1 f _ Resp.eval 1 ⟨PSet.image r, fun _ _ e => Mem.ext fun _ => (mem_image hr).trans <| Iff.trans ⟨fun ⟨w, h1, h2⟩ => ⟨w, (Mem.congr_right e).1 h1, h2⟩, fun ⟨w, h1, h2⟩ => ⟨w, (Mem.congr_right e).2 h1, h2⟩⟩ <| (mem_image hr).symm⟩ #align Set.image ZFSet.image theorem image.mk : ∀ (f : ZFSet.{u} → ZFSet.{u}) [H : Definable 1 f] (x) {y} (_ : y ∈ x), f y ∈ @image f H x | _, ⟨F⟩, x, y => Quotient.inductionOn₂ x y fun ⟨_, _⟩ _ ⟨a, ya⟩ => ⟨a, F.2 _ _ ya⟩ #align Set.image.mk ZFSet.image.mk @[simp] theorem mem_image : ∀ {f : ZFSet.{u} → ZFSet.{u}} [H : Definable 1 f] {x y : ZFSet.{u}}, y ∈ @image f H x ↔ ∃ z ∈ x, f z = y | _, ⟨_⟩, x, y => Quotient.inductionOn₂ x y fun ⟨_, A⟩ _ => ⟨fun ⟨a, ya⟩ => ⟨⟦A a⟧, Mem.mk A a, Eq.symm <| Quotient.sound ya⟩, fun ⟨_, hz, e⟩ => e ▸ image.mk _ _ hz⟩ #align Set.mem_image ZFSet.mem_image @[simp] theorem toSet_image (f : ZFSet → ZFSet) [H : Definable 1 f] (x : ZFSet) : (image f x).toSet = f '' x.toSet := by ext simp #align Set.to_set_image ZFSet.toSet_image /-- The range of an indexed family of sets. The universes allow for a more general index type without manual use of `ULift`. -/ noncomputable def range {α : Type u} (f : α → ZFSet.{max u v}) : ZFSet.{max u v} := ⟦⟨ULift.{v} α, Quotient.out ∘ f ∘ ULift.down⟩⟧ #align Set.range ZFSet.range @[simp] theorem mem_range {α : Type u} {f : α → ZFSet.{max u v}} {x : ZFSet.{max u v}} : x ∈ range.{u, v} f ↔ x ∈ Set.range f := Quotient.inductionOn x fun y => by constructor · rintro ⟨z, hz⟩ exact ⟨z.down, Quotient.eq_mk_iff_out.2 hz.symm⟩ · rintro ⟨z, hz⟩ use ULift.up z simpa [hz] using PSet.Equiv.symm (Quotient.mk_out y) #align Set.mem_range ZFSet.mem_range @[simp] theorem toSet_range {α : Type u} (f : α → ZFSet.{max u v}) : (range.{u, v} f).toSet = Set.range f := by ext simp #align Set.to_set_range ZFSet.toSet_range /-- Kuratowski ordered pair -/ def pair (x y : ZFSet.{u}) : ZFSet.{u} := {{x}, {x, y}} #align Set.pair ZFSet.pair @[simp] theorem toSet_pair (x y : ZFSet.{u}) : (pair x y).toSet = {{x}, {x, y}} := by simp [pair] #align Set.to_set_pair ZFSet.toSet_pair /-- A subset of pairs `{(a, b) ∈ x × y | p a b}` -/ def pairSep (p : ZFSet.{u} → ZFSet.{u} → Prop) (x y : ZFSet.{u}) : ZFSet.{u} := ZFSet.sep (fun z => ∃ a ∈ x, ∃ b ∈ y, z = pair a b ∧ p a b) (powerset (powerset (x ∪ y))) #align Set.pair_sep ZFSet.pairSep @[simp] theorem mem_pairSep {p} {x y z : ZFSet.{u}} : z ∈ pairSep p x y ↔ ∃ a ∈ x, ∃ b ∈ y, z = pair a b ∧ p a b := by refine mem_sep.trans ⟨And.right, fun e => ⟨?_, e⟩⟩ rcases e with ⟨a, ax, b, bY, rfl, pab⟩ simp only [mem_powerset, subset_def, mem_union, pair, mem_pair] rintro u (rfl | rfl) v <;> simp only [mem_singleton, mem_pair] · rintro rfl exact Or.inl ax · rintro (rfl | rfl) <;> [left; right] <;> assumption #align Set.mem_pair_sep ZFSet.mem_pairSep theorem pair_injective : Function.Injective2 pair := fun x x' y y' H => by have ae := ext_iff.1 H simp only [pair, mem_pair] at ae obtain rfl : x = x' := by cases' (ae {x}).1 (by simp) with h h · exact singleton_injective h · have m : x' ∈ ({x} : ZFSet) := by simp [h] rw [mem_singleton.mp m] have he : x = y → y = y' := by rintro rfl cases' (ae {x, y'}).2 (by simp only [eq_self_iff_true, or_true_iff]) with xy'x xy'xx · rw [eq_comm, ← mem_singleton, ← xy'x, mem_pair] exact Or.inr rfl · simpa [eq_comm] using (ext_iff.1 xy'xx y').1 (by simp) obtain xyx | xyy' := (ae {x, y}).1 (by simp) · obtain rfl := mem_singleton.mp ((ext_iff.1 xyx y).1 <| by simp) simp [he rfl] · obtain rfl | yy' := mem_pair.mp ((ext_iff.1 xyy' y).1 <| by simp) · simp [he rfl] · simp [yy'] #align Set.pair_injective ZFSet.pair_injective @[simp] theorem pair_inj {x y x' y' : ZFSet} : pair x y = pair x' y' ↔ x = x' ∧ y = y' := pair_injective.eq_iff #align Set.pair_inj ZFSet.pair_inj /-- The cartesian product, `{(a, b) | a ∈ x, b ∈ y}` -/ def prod : ZFSet.{u} → ZFSet.{u} → ZFSet.{u} := pairSep fun _ _ => True #align Set.prod ZFSet.prod @[simp] theorem mem_prod {x y z : ZFSet.{u}} : z ∈ prod x y ↔ ∃ a ∈ x, ∃ b ∈ y, z = pair a b := by simp [prod] #align Set.mem_prod ZFSet.mem_prod theorem pair_mem_prod {x y a b : ZFSet.{u}} : pair a b ∈ prod x y ↔ a ∈ x ∧ b ∈ y := by simp #align Set.pair_mem_prod ZFSet.pair_mem_prod /-- `isFunc x y f` is the assertion that `f` is a subset of `x × y` which relates to each element of `x` a unique element of `y`, so that we can consider `f` as a ZFC function `x → y`. -/ def IsFunc (x y f : ZFSet.{u}) : Prop := f ⊆ prod x y ∧ ∀ z : ZFSet.{u}, z ∈ x → ∃! w, pair z w ∈ f #align Set.is_func ZFSet.IsFunc /-- `funs x y` is `y ^ x`, the set of all set functions `x → y` -/ def funs (x y : ZFSet.{u}) : ZFSet.{u} := ZFSet.sep (IsFunc x y) (powerset (prod x y)) #align Set.funs ZFSet.funs @[simp] theorem mem_funs {x y f : ZFSet.{u}} : f ∈ funs x y ↔ IsFunc x y f := by simp [funs, IsFunc] #align Set.mem_funs ZFSet.mem_funs -- TODO(Mario): Prove this computably /- Porting note: the `Definable` argument in `mapDefinableAux` is unused, though the TODO remark suggests it shouldn't be. -/ @[nolint unusedArguments] noncomputable instance mapDefinableAux (f : ZFSet → ZFSet) [Definable 1 f] : Definable 1 fun (y : ZFSet) => pair y (f y) := @Classical.allDefinable 1 _ #align Set.map_definable_aux ZFSet.mapDefinableAux /-- Graph of a function: `map f x` is the ZFC function which maps `a ∈ x` to `f a` -/ noncomputable def map (f : ZFSet → ZFSet) [Definable 1 f] : ZFSet → ZFSet := image fun y => pair y (f y) #align Set.map ZFSet.map @[simp] theorem mem_map {f : ZFSet → ZFSet} [Definable 1 f] {x y : ZFSet} : y ∈ map f x ↔ ∃ z ∈ x, pair z (f z) = y := mem_image #align Set.mem_map ZFSet.mem_map theorem map_unique {f : ZFSet.{u} → ZFSet.{u}} [H : Definable 1 f] {x z : ZFSet.{u}} (zx : z ∈ x) : ∃! w, pair z w ∈ map f x := ⟨f z, image.mk _ _ zx, fun y yx => by let ⟨w, _, we⟩ := mem_image.1 yx let ⟨wz, fy⟩ := pair_injective we rw [← fy, wz]⟩ #align Set.map_unique ZFSet.map_unique @[simp] theorem map_isFunc {f : ZFSet → ZFSet} [Definable 1 f] {x y : ZFSet} : IsFunc x y (map f x) ↔ ∀ z ∈ x, f z ∈ y := ⟨fun ⟨ss, h⟩ z zx => let ⟨_, t1, t2⟩ := h z zx (t2 (f z) (image.mk _ _ zx)).symm ▸ (pair_mem_prod.1 (ss t1)).right, fun h => ⟨fun _ yx => let ⟨z, zx, ze⟩ := mem_image.1 yx ze ▸ pair_mem_prod.2 ⟨zx, h z zx⟩, fun _ => map_unique⟩⟩ #align Set.map_is_func ZFSet.map_isFunc /-- Given a predicate `p` on ZFC sets. `Hereditarily p x` means that `x` has property `p` and the members of `x` are all `Hereditarily p`. -/ def Hereditarily (p : ZFSet → Prop) (x : ZFSet) : Prop := p x ∧ ∀ y ∈ x, Hereditarily p y termination_by x #align Set.hereditarily ZFSet.Hereditarily section Hereditarily variable {p : ZFSet.{u} → Prop} {x y : ZFSet.{u}} theorem hereditarily_iff : Hereditarily p x ↔ p x ∧ ∀ y ∈ x, Hereditarily p y := by rw [← Hereditarily] #align Set.hereditarily_iff ZFSet.hereditarily_iff alias ⟨Hereditarily.def, _⟩ := hereditarily_iff #align Set.hereditarily.def ZFSet.Hereditarily.def theorem Hereditarily.self (h : x.Hereditarily p) : p x := h.def.1 #align Set.hereditarily.self ZFSet.Hereditarily.self theorem Hereditarily.mem (h : x.Hereditarily p) (hy : y ∈ x) : y.Hereditarily p := h.def.2 _ hy #align Set.hereditarily.mem ZFSet.Hereditarily.mem
Mathlib/SetTheory/ZFC/Basic.lean
1,395
1,400
theorem Hereditarily.empty : Hereditarily p x → p ∅ := by
apply @ZFSet.inductionOn _ x intro y IH h rcases ZFSet.eq_empty_or_nonempty y with (rfl | ⟨a, ha⟩) · exact h.self · exact IH a ha (h.mem ha)
/- 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]
Mathlib/Order/SymmDiff.lean
555
555
theorem symmDiff_eq_right : a ∆ b = b ↔ a = ⊥ := by
rw [symmDiff_comm, symmDiff_eq_left]
/- 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.Data.Set.Basic /-! # Subsingleton Defines the predicate `Subsingleton s : Prop`, saying that `s` has at most one element. Also defines `Nontrivial s : Prop` : the predicate saying that `s` has at least two distinct elements. -/ open Function universe u v namespace Set /-! ### Subsingleton -/ section Subsingleton variable {α : Type u} {a : α} {s t : Set α} /-- A set `s` is a `Subsingleton` if it has at most one element. -/ protected def Subsingleton (s : Set α) : Prop := ∀ ⦃x⦄ (_ : x ∈ s) ⦃y⦄ (_ : y ∈ s), x = y #align set.subsingleton Set.Subsingleton theorem Subsingleton.anti (ht : t.Subsingleton) (hst : s ⊆ t) : s.Subsingleton := fun _ hx _ hy => ht (hst hx) (hst hy) #align set.subsingleton.anti Set.Subsingleton.anti theorem Subsingleton.eq_singleton_of_mem (hs : s.Subsingleton) {x : α} (hx : x ∈ s) : s = {x} := ext fun _ => ⟨fun hy => hs hx hy ▸ mem_singleton _, fun hy => (eq_of_mem_singleton hy).symm ▸ hx⟩ #align set.subsingleton.eq_singleton_of_mem Set.Subsingleton.eq_singleton_of_mem @[simp] theorem subsingleton_empty : (∅ : Set α).Subsingleton := fun _ => False.elim #align set.subsingleton_empty Set.subsingleton_empty @[simp] theorem subsingleton_singleton {a} : ({a} : Set α).Subsingleton := fun _ hx _ hy => (eq_of_mem_singleton hx).symm ▸ (eq_of_mem_singleton hy).symm ▸ rfl #align set.subsingleton_singleton Set.subsingleton_singleton theorem subsingleton_of_subset_singleton (h : s ⊆ {a}) : s.Subsingleton := subsingleton_singleton.anti h #align set.subsingleton_of_subset_singleton Set.subsingleton_of_subset_singleton theorem subsingleton_of_forall_eq (a : α) (h : ∀ b ∈ s, b = a) : s.Subsingleton := fun _ hb _ hc => (h _ hb).trans (h _ hc).symm #align set.subsingleton_of_forall_eq Set.subsingleton_of_forall_eq theorem subsingleton_iff_singleton {x} (hx : x ∈ s) : s.Subsingleton ↔ s = {x} := ⟨fun h => h.eq_singleton_of_mem hx, fun h => h.symm ▸ subsingleton_singleton⟩ #align set.subsingleton_iff_singleton Set.subsingleton_iff_singleton theorem Subsingleton.eq_empty_or_singleton (hs : s.Subsingleton) : s = ∅ ∨ ∃ x, s = {x} := s.eq_empty_or_nonempty.elim Or.inl fun ⟨x, hx⟩ => Or.inr ⟨x, hs.eq_singleton_of_mem hx⟩ #align set.subsingleton.eq_empty_or_singleton Set.Subsingleton.eq_empty_or_singleton theorem Subsingleton.induction_on {p : Set α → Prop} (hs : s.Subsingleton) (he : p ∅) (h₁ : ∀ x, p {x}) : p s := by rcases hs.eq_empty_or_singleton with (rfl | ⟨x, rfl⟩) exacts [he, h₁ _] #align set.subsingleton.induction_on Set.Subsingleton.induction_on theorem subsingleton_univ [Subsingleton α] : (univ : Set α).Subsingleton := fun x _ y _ => Subsingleton.elim x y #align set.subsingleton_univ Set.subsingleton_univ theorem subsingleton_of_univ_subsingleton (h : (univ : Set α).Subsingleton) : Subsingleton α := ⟨fun a b => h (mem_univ a) (mem_univ b)⟩ #align set.subsingleton_of_univ_subsingleton Set.subsingleton_of_univ_subsingleton @[simp] theorem subsingleton_univ_iff : (univ : Set α).Subsingleton ↔ Subsingleton α := ⟨subsingleton_of_univ_subsingleton, fun h => @subsingleton_univ _ h⟩ #align set.subsingleton_univ_iff Set.subsingleton_univ_iff theorem subsingleton_of_subsingleton [Subsingleton α] {s : Set α} : Set.Subsingleton s := subsingleton_univ.anti (subset_univ s) #align set.subsingleton_of_subsingleton Set.subsingleton_of_subsingleton theorem subsingleton_isTop (α : Type*) [PartialOrder α] : Set.Subsingleton { x : α | IsTop x } := fun x hx _ hy => hx.isMax.eq_of_le (hy x) #align set.subsingleton_is_top Set.subsingleton_isTop theorem subsingleton_isBot (α : Type*) [PartialOrder α] : Set.Subsingleton { x : α | IsBot x } := fun x hx _ hy => hx.isMin.eq_of_ge (hy x) #align set.subsingleton_is_bot Set.subsingleton_isBot theorem exists_eq_singleton_iff_nonempty_subsingleton : (∃ a : α, s = {a}) ↔ s.Nonempty ∧ s.Subsingleton := by refine ⟨?_, fun h => ?_⟩ · rintro ⟨a, rfl⟩ exact ⟨singleton_nonempty a, subsingleton_singleton⟩ · exact h.2.eq_empty_or_singleton.resolve_left h.1.ne_empty #align set.exists_eq_singleton_iff_nonempty_subsingleton Set.exists_eq_singleton_iff_nonempty_subsingleton /-- `s`, coerced to a type, is a subsingleton type if and only if `s` is a subsingleton set. -/ @[simp, norm_cast]
Mathlib/Data/Set/Subsingleton.lean
109
113
theorem subsingleton_coe (s : Set α) : Subsingleton s ↔ s.Subsingleton := by
constructor · refine fun h => fun a ha b hb => ?_ exact SetCoe.ext_iff.2 (@Subsingleton.elim s h ⟨a, ha⟩ ⟨b, hb⟩) · exact fun h => Subsingleton.intro fun a b => SetCoe.ext (h a.property b.property)
/- Copyright (c) 2022 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.Algebra.Order.Field.Basic import Mathlib.Combinatorics.SimpleGraph.Basic import Mathlib.Data.Rat.Cast.Order import Mathlib.Order.Partition.Finpartition import Mathlib.Tactic.GCongr import Mathlib.Tactic.NormNum import Mathlib.Tactic.Positivity import Mathlib.Tactic.Ring #align_import combinatorics.simple_graph.density from "leanprover-community/mathlib"@"a4ec43f53b0bd44c697bcc3f5a62edd56f269ef1" /-! # Edge density This file defines the number and density of edges of a relation/graph. ## Main declarations Between two finsets of vertices, * `Rel.interedges`: Finset of edges of a relation. * `Rel.edgeDensity`: Edge density of a relation. * `SimpleGraph.interedges`: Finset of edges of a graph. * `SimpleGraph.edgeDensity`: Edge density of a graph. -/ open Finset variable {𝕜 ι κ α β : Type*} /-! ### Density of a relation -/ namespace Rel section Asymmetric variable [LinearOrderedField 𝕜] (r : α → β → Prop) [∀ a, DecidablePred (r a)] {s s₁ s₂ : Finset α} {t t₁ t₂ : Finset β} {a : α} {b : β} {δ : 𝕜} /-- Finset of edges of a relation between two finsets of vertices. -/ def interedges (s : Finset α) (t : Finset β) : Finset (α × β) := (s ×ˢ t).filter fun e ↦ r e.1 e.2 #align rel.interedges Rel.interedges /-- Edge density of a relation between two finsets of vertices. -/ def edgeDensity (s : Finset α) (t : Finset β) : ℚ := (interedges r s t).card / (s.card * t.card) #align rel.edge_density Rel.edgeDensity variable {r} theorem mem_interedges_iff {x : α × β} : x ∈ interedges r s t ↔ x.1 ∈ s ∧ x.2 ∈ t ∧ r x.1 x.2 := by rw [interedges, mem_filter, Finset.mem_product, and_assoc] #align rel.mem_interedges_iff Rel.mem_interedges_iff theorem mk_mem_interedges_iff : (a, b) ∈ interedges r s t ↔ a ∈ s ∧ b ∈ t ∧ r a b := mem_interedges_iff #align rel.mk_mem_interedges_iff Rel.mk_mem_interedges_iff @[simp] theorem interedges_empty_left (t : Finset β) : interedges r ∅ t = ∅ := by rw [interedges, Finset.empty_product, filter_empty] #align rel.interedges_empty_left Rel.interedges_empty_left theorem interedges_mono (hs : s₂ ⊆ s₁) (ht : t₂ ⊆ t₁) : interedges r s₂ t₂ ⊆ interedges r s₁ t₁ := fun x ↦ by simp_rw [mem_interedges_iff] exact fun h ↦ ⟨hs h.1, ht h.2.1, h.2.2⟩ #align rel.interedges_mono Rel.interedges_mono variable (r) theorem card_interedges_add_card_interedges_compl (s : Finset α) (t : Finset β) : (interedges r s t).card + (interedges (fun x y ↦ ¬r x y) s t).card = s.card * t.card := by classical rw [← card_product, interedges, interedges, ← card_union_of_disjoint, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ ↦ Classical.not_not.2 #align rel.card_interedges_add_card_interedges_compl Rel.card_interedges_add_card_interedges_compl theorem interedges_disjoint_left {s s' : Finset α} (hs : Disjoint s s') (t : Finset β) : Disjoint (interedges r s t) (interedges r s' t) := by rw [Finset.disjoint_left] at hs ⊢ intro _ hx hy rw [mem_interedges_iff] at hx hy exact hs hx.1 hy.1 #align rel.interedges_disjoint_left Rel.interedges_disjoint_left theorem interedges_disjoint_right (s : Finset α) {t t' : Finset β} (ht : Disjoint t t') : Disjoint (interedges r s t) (interedges r s t') := by rw [Finset.disjoint_left] at ht ⊢ intro _ hx hy rw [mem_interedges_iff] at hx hy exact ht hx.2.1 hy.2.1 #align rel.interedges_disjoint_right Rel.interedges_disjoint_right section DecidableEq variable [DecidableEq α] [DecidableEq β] lemma interedges_eq_biUnion : interedges r s t = s.biUnion (fun x ↦ (t.filter (r x)).map ⟨(x, ·), Prod.mk.inj_left x⟩) := by ext ⟨x, y⟩; simp [mem_interedges_iff] theorem interedges_biUnion_left (s : Finset ι) (t : Finset β) (f : ι → Finset α) : interedges r (s.biUnion f) t = s.biUnion fun a ↦ interedges r (f a) t := by ext simp only [mem_biUnion, mem_interedges_iff, exists_and_right, ← and_assoc] #align rel.interedges_bUnion_left Rel.interedges_biUnion_left theorem interedges_biUnion_right (s : Finset α) (t : Finset ι) (f : ι → Finset β) : interedges r s (t.biUnion f) = t.biUnion fun b ↦ interedges r s (f b) := by ext a simp only [mem_interedges_iff, mem_biUnion] exact ⟨fun ⟨x₁, ⟨x₂, x₃, x₄⟩, x₅⟩ ↦ ⟨x₂, x₃, x₁, x₄, x₅⟩, fun ⟨x₂, x₃, x₁, x₄, x₅⟩ ↦ ⟨x₁, ⟨x₂, x₃, x₄⟩, x₅⟩⟩ #align rel.interedges_bUnion_right Rel.interedges_biUnion_right theorem interedges_biUnion (s : Finset ι) (t : Finset κ) (f : ι → Finset α) (g : κ → Finset β) : interedges r (s.biUnion f) (t.biUnion g) = (s ×ˢ t).biUnion fun ab ↦ interedges r (f ab.1) (g ab.2) := by simp_rw [product_biUnion, interedges_biUnion_left, interedges_biUnion_right] #align rel.interedges_bUnion Rel.interedges_biUnion end DecidableEq theorem card_interedges_le_mul (s : Finset α) (t : Finset β) : (interedges r s t).card ≤ s.card * t.card := (card_filter_le _ _).trans (card_product _ _).le #align rel.card_interedges_le_mul Rel.card_interedges_le_mul theorem edgeDensity_nonneg (s : Finset α) (t : Finset β) : 0 ≤ edgeDensity r s t := by apply div_nonneg <;> exact mod_cast Nat.zero_le _ #align rel.edge_density_nonneg Rel.edgeDensity_nonneg theorem edgeDensity_le_one (s : Finset α) (t : Finset β) : edgeDensity r s t ≤ 1 := by apply div_le_one_of_le · exact mod_cast card_interedges_le_mul r s t · exact mod_cast Nat.zero_le _ #align rel.edge_density_le_one Rel.edgeDensity_le_one theorem edgeDensity_add_edgeDensity_compl (hs : s.Nonempty) (ht : t.Nonempty) : edgeDensity r s t + edgeDensity (fun x y ↦ ¬r x y) s t = 1 := by rw [edgeDensity, edgeDensity, div_add_div_same, div_eq_one_iff_eq] · exact mod_cast card_interedges_add_card_interedges_compl r s t · exact mod_cast (mul_pos hs.card_pos ht.card_pos).ne' #align rel.edge_density_add_edge_density_compl Rel.edgeDensity_add_edgeDensity_compl @[simp] theorem edgeDensity_empty_left (t : Finset β) : edgeDensity r ∅ t = 0 := by rw [edgeDensity, Finset.card_empty, Nat.cast_zero, zero_mul, div_zero] #align rel.edge_density_empty_left Rel.edgeDensity_empty_left @[simp] theorem edgeDensity_empty_right (s : Finset α) : edgeDensity r s ∅ = 0 := by rw [edgeDensity, Finset.card_empty, Nat.cast_zero, mul_zero, div_zero] #align rel.edge_density_empty_right Rel.edgeDensity_empty_right theorem card_interedges_finpartition_left [DecidableEq α] (P : Finpartition s) (t : Finset β) : (interedges r s t).card = ∑ a ∈ P.parts, (interedges r a t).card := by classical simp_rw [← P.biUnion_parts, interedges_biUnion_left, id] rw [card_biUnion] exact fun x hx y hy h ↦ interedges_disjoint_left r (P.disjoint hx hy h) _ #align rel.card_interedges_finpartition_left Rel.card_interedges_finpartition_left theorem card_interedges_finpartition_right [DecidableEq β] (s : Finset α) (P : Finpartition t) : (interedges r s t).card = ∑ b ∈ P.parts, (interedges r s b).card := by classical simp_rw [← P.biUnion_parts, interedges_biUnion_right, id] rw [card_biUnion] exact fun x hx y hy h ↦ interedges_disjoint_right r _ (P.disjoint hx hy h) #align rel.card_interedges_finpartition_right Rel.card_interedges_finpartition_right theorem card_interedges_finpartition [DecidableEq α] [DecidableEq β] (P : Finpartition s) (Q : Finpartition t) : (interedges r s t).card = ∑ ab ∈ P.parts ×ˢ Q.parts, (interedges r ab.1 ab.2).card := by rw [card_interedges_finpartition_left _ P, sum_product] congr; ext rw [card_interedges_finpartition_right] #align rel.card_interedges_finpartition Rel.card_interedges_finpartition
Mathlib/Combinatorics/SimpleGraph/Density.lean
187
193
theorem mul_edgeDensity_le_edgeDensity (hs : s₂ ⊆ s₁) (ht : t₂ ⊆ t₁) (hs₂ : s₂.Nonempty) (ht₂ : t₂.Nonempty) : (s₂.card : ℚ) / s₁.card * (t₂.card / t₁.card) * edgeDensity r s₂ t₂ ≤ edgeDensity r s₁ t₁ := by
have hst : (s₂.card : ℚ) * t₂.card ≠ 0 := by simp [hs₂.ne_empty, ht₂.ne_empty] rw [edgeDensity, edgeDensity, div_mul_div_comm, mul_comm, div_mul_div_cancel _ hst] gcongr exact interedges_mono hs ht
/- 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, Floris van Doorn, Yury Kudryashov, Neil Strickland -/ import Mathlib.Algebra.Group.Defs import Mathlib.Algebra.GroupWithZero.Defs import Mathlib.Data.Int.Cast.Defs import Mathlib.Tactic.Spread import Mathlib.Util.AssertExists #align_import algebra.ring.defs from "leanprover-community/mathlib"@"76de8ae01554c3b37d66544866659ff174e66e1f" /-! # Semirings and rings This file defines semirings, rings and domains. This is analogous to `Algebra.Group.Defs` and `Algebra.Group.Basic`, the difference being that the former is about `+` and `*` separately, while the present file is about their interaction. ## Main definitions * `Distrib`: Typeclass for distributivity of multiplication over addition. * `HasDistribNeg`: Typeclass for commutativity of negation and multiplication. This is useful when dealing with multiplicative submonoids which are closed under negation without being closed under addition, for example `Units`. * `(NonUnital)(NonAssoc)(Semi)Ring`: Typeclasses for possibly non-unital or non-associative rings and semirings. Some combinations are not defined yet because they haven't found use. ## Tags `Semiring`, `CommSemiring`, `Ring`, `CommRing`, domain, `IsDomain`, nonzero, units -/ universe u v w x variable {α : Type u} {β : Type v} {γ : Type w} {R : Type x} open Function /-! ### `Distrib` class -/ /-- A typeclass stating that multiplication is left and right distributive over addition. -/ class Distrib (R : Type*) extends Mul R, Add R where /-- Multiplication is left distributive over addition -/ protected left_distrib : ∀ a b c : R, a * (b + c) = a * b + a * c /-- Multiplication is right distributive over addition -/ protected right_distrib : ∀ a b c : R, (a + b) * c = a * c + b * c #align distrib Distrib /-- A typeclass stating that multiplication is left distributive over addition. -/ class LeftDistribClass (R : Type*) [Mul R] [Add R] : Prop where /-- Multiplication is left distributive over addition -/ protected left_distrib : ∀ a b c : R, a * (b + c) = a * b + a * c #align left_distrib_class LeftDistribClass /-- A typeclass stating that multiplication is right distributive over addition. -/ class RightDistribClass (R : Type*) [Mul R] [Add R] : Prop where /-- Multiplication is right distributive over addition -/ protected right_distrib : ∀ a b c : R, (a + b) * c = a * c + b * c #align right_distrib_class RightDistribClass -- see Note [lower instance priority] instance (priority := 100) Distrib.leftDistribClass (R : Type*) [Distrib R] : LeftDistribClass R := ⟨Distrib.left_distrib⟩ #align distrib.left_distrib_class Distrib.leftDistribClass -- see Note [lower instance priority] instance (priority := 100) Distrib.rightDistribClass (R : Type*) [Distrib R] : RightDistribClass R := ⟨Distrib.right_distrib⟩ #align distrib.right_distrib_class Distrib.rightDistribClass theorem left_distrib [Mul R] [Add R] [LeftDistribClass R] (a b c : R) : a * (b + c) = a * b + a * c := LeftDistribClass.left_distrib a b c #align left_distrib left_distrib alias mul_add := left_distrib #align mul_add mul_add theorem right_distrib [Mul R] [Add R] [RightDistribClass R] (a b c : R) : (a + b) * c = a * c + b * c := RightDistribClass.right_distrib a b c #align right_distrib right_distrib alias add_mul := right_distrib #align add_mul add_mul theorem distrib_three_right [Mul R] [Add R] [RightDistribClass R] (a b c d : R) : (a + b + c) * d = a * d + b * d + c * d := by simp [right_distrib] #align distrib_three_right distrib_three_right /-! ### Classes of semirings and rings We make sure that the canonical path from `NonAssocSemiring` to `Ring` passes through `Semiring`, as this is a path which is followed all the time in linear algebra where the defining semilinear map `σ : R →+* S` depends on the `NonAssocSemiring` structure of `R` and `S` while the module definition depends on the `Semiring` structure. It is not currently possible to adjust priorities by hand (see lean4#2115). Instead, the last declared instance is used, so we make sure that `Semiring` is declared after `NonAssocRing`, so that `Semiring -> NonAssocSemiring` is tried before `NonAssocRing -> NonAssocSemiring`. TODO: clean this once lean4#2115 is fixed -/ /-- A not-necessarily-unital, not-necessarily-associative semiring. -/ class NonUnitalNonAssocSemiring (α : Type u) extends AddCommMonoid α, Distrib α, MulZeroClass α #align non_unital_non_assoc_semiring NonUnitalNonAssocSemiring /-- An associative but not-necessarily unital semiring. -/ class NonUnitalSemiring (α : Type u) extends NonUnitalNonAssocSemiring α, SemigroupWithZero α #align non_unital_semiring NonUnitalSemiring /-- A unital but not-necessarily-associative semiring. -/ class NonAssocSemiring (α : Type u) extends NonUnitalNonAssocSemiring α, MulZeroOneClass α, AddCommMonoidWithOne α #align non_assoc_semiring NonAssocSemiring /-- A not-necessarily-unital, not-necessarily-associative ring. -/ class NonUnitalNonAssocRing (α : Type u) extends AddCommGroup α, NonUnitalNonAssocSemiring α #align non_unital_non_assoc_ring NonUnitalNonAssocRing /-- An associative but not-necessarily unital ring. -/ class NonUnitalRing (α : Type*) extends NonUnitalNonAssocRing α, NonUnitalSemiring α #align non_unital_ring NonUnitalRing /-- A unital but not-necessarily-associative ring. -/ class NonAssocRing (α : Type*) extends NonUnitalNonAssocRing α, NonAssocSemiring α, AddCommGroupWithOne α #align non_assoc_ring NonAssocRing /-- A `Semiring` is a type with addition, multiplication, a `0` and a `1` where addition is commutative and associative, multiplication is associative and left and right distributive over addition, and `0` and `1` are additive and multiplicative identities. -/ class Semiring (α : Type u) extends NonUnitalSemiring α, NonAssocSemiring α, MonoidWithZero α #align semiring Semiring /-- A `Ring` is a `Semiring` with negation making it an additive group. -/ class Ring (R : Type u) extends Semiring R, AddCommGroup R, AddGroupWithOne R #align ring Ring /-! ### Semirings -/ section DistribMulOneClass variable [Add α] [MulOneClass α] theorem add_one_mul [RightDistribClass α] (a b : α) : (a + 1) * b = a * b + b := by rw [add_mul, one_mul] #align add_one_mul add_one_mul theorem mul_add_one [LeftDistribClass α] (a b : α) : a * (b + 1) = a * b + a := by rw [mul_add, mul_one] #align mul_add_one mul_add_one
Mathlib/Algebra/Ring/Defs.lean
164
165
theorem one_add_mul [RightDistribClass α] (a b : α) : (1 + a) * b = b + a * b := by
rw [add_mul, one_mul]
/- 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 theorem coeFn_sum {ι : Type*} (f : ι → lp E p) (s : Finset ι) : ⇑(∑ i ∈ s, f i) = ∑ i ∈ s, ⇑(f i) := by simp #align lp.coe_fn_sum lp.coeFn_sum @[simp] theorem coeFn_sub (f g : lp E p) : ⇑(f - g) = f - g := rfl #align lp.coe_fn_sub lp.coeFn_sub instance : Norm (lp E p) where norm f := if hp : p = 0 then by subst hp exact ((lp.memℓp f).finite_dsupport.toFinset.card : ℝ) else if p = ∞ then ⨆ i, ‖f i‖ else (∑' i, ‖f i‖ ^ p.toReal) ^ (1 / p.toReal) theorem norm_eq_card_dsupport (f : lp E 0) : ‖f‖ = (lp.memℓp f).finite_dsupport.toFinset.card := dif_pos rfl #align lp.norm_eq_card_dsupport lp.norm_eq_card_dsupport theorem norm_eq_ciSup (f : lp E ∞) : ‖f‖ = ⨆ i, ‖f i‖ := by dsimp [norm] rw [dif_neg ENNReal.top_ne_zero, if_pos rfl] #align lp.norm_eq_csupr lp.norm_eq_ciSup theorem isLUB_norm [Nonempty α] (f : lp E ∞) : IsLUB (Set.range fun i => ‖f i‖) ‖f‖ := by rw [lp.norm_eq_ciSup] exact isLUB_ciSup (lp.memℓp f) #align lp.is_lub_norm lp.isLUB_norm theorem norm_eq_tsum_rpow (hp : 0 < p.toReal) (f : lp E p) : ‖f‖ = (∑' i, ‖f i‖ ^ p.toReal) ^ (1 / p.toReal) := by dsimp [norm] rw [ENNReal.toReal_pos_iff] at hp rw [dif_neg hp.1.ne', if_neg hp.2.ne] #align lp.norm_eq_tsum_rpow lp.norm_eq_tsum_rpow theorem norm_rpow_eq_tsum (hp : 0 < p.toReal) (f : lp E p) : ‖f‖ ^ p.toReal = ∑' i, ‖f i‖ ^ p.toReal := by rw [norm_eq_tsum_rpow hp, ← Real.rpow_mul] · field_simp apply tsum_nonneg intro i calc (0 : ℝ) = (0 : ℝ) ^ p.toReal := by rw [Real.zero_rpow hp.ne'] _ ≤ _ := by gcongr; apply norm_nonneg #align lp.norm_rpow_eq_tsum lp.norm_rpow_eq_tsum theorem hasSum_norm (hp : 0 < p.toReal) (f : lp E p) : HasSum (fun i => ‖f i‖ ^ p.toReal) (‖f‖ ^ p.toReal) := by rw [norm_rpow_eq_tsum hp] exact ((lp.memℓp f).summable hp).hasSum #align lp.has_sum_norm lp.hasSum_norm theorem norm_nonneg' (f : lp E p) : 0 ≤ ‖f‖ := by rcases p.trichotomy with (rfl | rfl | hp) · simp [lp.norm_eq_card_dsupport f] · cases' isEmpty_or_nonempty α with _i _i · rw [lp.norm_eq_ciSup] simp [Real.iSup_of_isEmpty] inhabit α exact (norm_nonneg (f default)).trans ((lp.isLUB_norm f).1 ⟨default, rfl⟩) · rw [lp.norm_eq_tsum_rpow hp f] refine Real.rpow_nonneg (tsum_nonneg ?_) _ exact fun i => Real.rpow_nonneg (norm_nonneg _) _ #align lp.norm_nonneg' lp.norm_nonneg' @[simp] theorem norm_zero : ‖(0 : lp E p)‖ = 0 := by rcases p.trichotomy with (rfl | rfl | hp) · simp [lp.norm_eq_card_dsupport] · simp [lp.norm_eq_ciSup] · rw [lp.norm_eq_tsum_rpow hp] have hp' : 1 / p.toReal ≠ 0 := one_div_ne_zero hp.ne' simpa [Real.zero_rpow hp.ne'] using Real.zero_rpow hp' #align lp.norm_zero lp.norm_zero theorem norm_eq_zero_iff {f : lp E p} : ‖f‖ = 0 ↔ f = 0 := by refine ⟨fun h => ?_, by rintro rfl; exact norm_zero⟩ rcases p.trichotomy with (rfl | rfl | hp) · ext i have : { i : α | ¬f i = 0 } = ∅ := by simpa [lp.norm_eq_card_dsupport f] using h have : (¬f i = 0) = False := congr_fun this i tauto · cases' isEmpty_or_nonempty α with _i _i · simp [eq_iff_true_of_subsingleton] have H : IsLUB (Set.range fun i => ‖f i‖) 0 := by simpa [h] using lp.isLUB_norm f ext i have : ‖f i‖ = 0 := le_antisymm (H.1 ⟨i, rfl⟩) (norm_nonneg _) simpa using this · have hf : HasSum (fun i : α => ‖f i‖ ^ p.toReal) 0 := by have := lp.hasSum_norm hp f rwa [h, Real.zero_rpow hp.ne'] at this have : ∀ i, 0 ≤ ‖f i‖ ^ p.toReal := fun i => Real.rpow_nonneg (norm_nonneg _) _ rw [hasSum_zero_iff_of_nonneg this] at hf ext i have : f i = 0 ∧ p.toReal ≠ 0 := by simpa [Real.rpow_eq_zero_iff_of_nonneg (norm_nonneg (f i))] using congr_fun hf i exact this.1 #align lp.norm_eq_zero_iff lp.norm_eq_zero_iff theorem eq_zero_iff_coeFn_eq_zero {f : lp E p} : f = 0 ↔ ⇑f = 0 := by rw [lp.ext_iff, coeFn_zero] #align lp.eq_zero_iff_coe_fn_eq_zero lp.eq_zero_iff_coeFn_eq_zero -- porting note (#11083): this was very slow, so I squeezed the `simp` calls @[simp] theorem norm_neg ⦃f : lp E p⦄ : ‖-f‖ = ‖f‖ := by rcases p.trichotomy with (rfl | rfl | hp) · simp only [norm_eq_card_dsupport, coeFn_neg, Pi.neg_apply, ne_eq, neg_eq_zero] · cases isEmpty_or_nonempty α · simp only [lp.eq_zero' f, neg_zero, norm_zero] apply (lp.isLUB_norm (-f)).unique simpa only [coeFn_neg, Pi.neg_apply, norm_neg] using lp.isLUB_norm f · suffices ‖-f‖ ^ p.toReal = ‖f‖ ^ p.toReal by exact Real.rpow_left_injOn hp.ne' (norm_nonneg' _) (norm_nonneg' _) this apply (lp.hasSum_norm hp (-f)).unique simpa only [coeFn_neg, Pi.neg_apply, _root_.norm_neg] using lp.hasSum_norm hp f #align lp.norm_neg lp.norm_neg instance normedAddCommGroup [hp : Fact (1 ≤ p)] : NormedAddCommGroup (lp E p) := AddGroupNorm.toNormedAddCommGroup { toFun := norm map_zero' := norm_zero neg' := norm_neg add_le' := fun f g => by rcases p.dichotomy with (rfl | hp') · cases isEmpty_or_nonempty α · simp only [lp.eq_zero' f, zero_add, norm_zero, le_refl] refine (lp.isLUB_norm (f + g)).2 ?_ rintro x ⟨i, rfl⟩ refine le_trans ?_ (add_mem_upperBounds_add (lp.isLUB_norm f).1 (lp.isLUB_norm g).1 ⟨_, ⟨i, rfl⟩, _, ⟨i, rfl⟩, rfl⟩) exact norm_add_le (f i) (g i) · have hp'' : 0 < p.toReal := zero_lt_one.trans_le hp' have hf₁ : ∀ i, 0 ≤ ‖f i‖ := fun i => norm_nonneg _ have hg₁ : ∀ i, 0 ≤ ‖g i‖ := fun i => norm_nonneg _ have hf₂ := lp.hasSum_norm hp'' f have hg₂ := lp.hasSum_norm hp'' g -- apply Minkowski's inequality obtain ⟨C, hC₁, hC₂, hCfg⟩ := Real.Lp_add_le_hasSum_of_nonneg hp' hf₁ hg₁ (norm_nonneg' _) (norm_nonneg' _) hf₂ hg₂ refine le_trans ?_ hC₂ rw [← Real.rpow_le_rpow_iff (norm_nonneg' (f + g)) hC₁ hp''] refine hasSum_le ?_ (lp.hasSum_norm hp'' (f + g)) hCfg intro i gcongr apply norm_add_le eq_zero_of_map_eq_zero' := fun f => norm_eq_zero_iff.1 } -- TODO: define an `ENNReal` version of `IsConjExponent`, and then express this inequality -- in a better version which also covers the case `p = 1, q = ∞`. /-- Hölder inequality -/ protected theorem tsum_mul_le_mul_norm {p q : ℝ≥0∞} (hpq : p.toReal.IsConjExponent q.toReal) (f : lp E p) (g : lp E q) : (Summable fun i => ‖f i‖ * ‖g i‖) ∧ ∑' i, ‖f i‖ * ‖g i‖ ≤ ‖f‖ * ‖g‖ := by have hf₁ : ∀ i, 0 ≤ ‖f i‖ := fun i => norm_nonneg _ have hg₁ : ∀ i, 0 ≤ ‖g i‖ := fun i => norm_nonneg _ have hf₂ := lp.hasSum_norm hpq.pos f have hg₂ := lp.hasSum_norm hpq.symm.pos g obtain ⟨C, -, hC', hC⟩ := Real.inner_le_Lp_mul_Lq_hasSum_of_nonneg hpq (norm_nonneg' _) (norm_nonneg' _) hf₁ hg₁ hf₂ hg₂ rw [← hC.tsum_eq] at hC' exact ⟨hC.summable, hC'⟩ #align lp.tsum_mul_le_mul_norm lp.tsum_mul_le_mul_norm protected theorem summable_mul {p q : ℝ≥0∞} (hpq : p.toReal.IsConjExponent q.toReal) (f : lp E p) (g : lp E q) : Summable fun i => ‖f i‖ * ‖g i‖ := (lp.tsum_mul_le_mul_norm hpq f g).1 #align lp.summable_mul lp.summable_mul protected theorem tsum_mul_le_mul_norm' {p q : ℝ≥0∞} (hpq : p.toReal.IsConjExponent q.toReal) (f : lp E p) (g : lp E q) : ∑' i, ‖f i‖ * ‖g i‖ ≤ ‖f‖ * ‖g‖ := (lp.tsum_mul_le_mul_norm hpq f g).2 #align lp.tsum_mul_le_mul_norm' lp.tsum_mul_le_mul_norm' section ComparePointwise theorem norm_apply_le_norm (hp : p ≠ 0) (f : lp E p) (i : α) : ‖f i‖ ≤ ‖f‖ := by rcases eq_or_ne p ∞ with (rfl | hp') · haveI : Nonempty α := ⟨i⟩ exact (isLUB_norm f).1 ⟨i, rfl⟩ have hp'' : 0 < p.toReal := ENNReal.toReal_pos hp hp' have : ∀ i, 0 ≤ ‖f i‖ ^ p.toReal := fun i => Real.rpow_nonneg (norm_nonneg _) _ rw [← Real.rpow_le_rpow_iff (norm_nonneg _) (norm_nonneg' _) hp''] convert le_hasSum (hasSum_norm hp'' f) i fun i _ => this i #align lp.norm_apply_le_norm lp.norm_apply_le_norm theorem sum_rpow_le_norm_rpow (hp : 0 < p.toReal) (f : lp E p) (s : Finset α) : ∑ i ∈ s, ‖f i‖ ^ p.toReal ≤ ‖f‖ ^ p.toReal := by rw [lp.norm_rpow_eq_tsum hp f] have : ∀ i, 0 ≤ ‖f i‖ ^ p.toReal := fun i => Real.rpow_nonneg (norm_nonneg _) _ refine sum_le_tsum _ (fun i _ => this i) ?_ exact (lp.memℓp f).summable hp #align lp.sum_rpow_le_norm_rpow lp.sum_rpow_le_norm_rpow theorem norm_le_of_forall_le' [Nonempty α] {f : lp E ∞} (C : ℝ) (hCf : ∀ i, ‖f i‖ ≤ C) : ‖f‖ ≤ C := by refine (isLUB_norm f).2 ?_ rintro - ⟨i, rfl⟩ exact hCf i #align lp.norm_le_of_forall_le' lp.norm_le_of_forall_le' theorem norm_le_of_forall_le {f : lp E ∞} {C : ℝ} (hC : 0 ≤ C) (hCf : ∀ i, ‖f i‖ ≤ C) : ‖f‖ ≤ C := by cases isEmpty_or_nonempty α · simpa [eq_zero' f] using hC · exact norm_le_of_forall_le' C hCf #align lp.norm_le_of_forall_le lp.norm_le_of_forall_le theorem norm_le_of_tsum_le (hp : 0 < p.toReal) {C : ℝ} (hC : 0 ≤ C) {f : lp E p} (hf : ∑' i, ‖f i‖ ^ p.toReal ≤ C ^ p.toReal) : ‖f‖ ≤ C := by rw [← Real.rpow_le_rpow_iff (norm_nonneg' _) hC hp, norm_rpow_eq_tsum hp] exact hf #align lp.norm_le_of_tsum_le lp.norm_le_of_tsum_le theorem norm_le_of_forall_sum_le (hp : 0 < p.toReal) {C : ℝ} (hC : 0 ≤ C) {f : lp E p} (hf : ∀ s : Finset α, ∑ i ∈ s, ‖f i‖ ^ p.toReal ≤ C ^ p.toReal) : ‖f‖ ≤ C := norm_le_of_tsum_le hp hC (tsum_le_of_sum_le ((lp.memℓp f).summable hp) hf) #align lp.norm_le_of_forall_sum_le lp.norm_le_of_forall_sum_le end ComparePointwise section BoundedSMul variable {𝕜 : Type*} {𝕜' : Type*} variable [NormedRing 𝕜] [NormedRing 𝕜'] variable [∀ i, Module 𝕜 (E i)] [∀ i, Module 𝕜' (E i)] instance : Module 𝕜 (PreLp E) := Pi.module α E 𝕜 instance [∀ i, SMulCommClass 𝕜' 𝕜 (E i)] : SMulCommClass 𝕜' 𝕜 (PreLp E) := Pi.smulCommClass instance [SMul 𝕜' 𝕜] [∀ i, IsScalarTower 𝕜' 𝕜 (E i)] : IsScalarTower 𝕜' 𝕜 (PreLp E) := Pi.isScalarTower instance [∀ i, Module 𝕜ᵐᵒᵖ (E i)] [∀ i, IsCentralScalar 𝕜 (E i)] : IsCentralScalar 𝕜 (PreLp E) := Pi.isCentralScalar variable [∀ i, BoundedSMul 𝕜 (E i)] [∀ i, BoundedSMul 𝕜' (E i)] theorem mem_lp_const_smul (c : 𝕜) (f : lp E p) : c • (f : PreLp E) ∈ lp E p := (lp.memℓp f).const_smul c #align lp.mem_lp_const_smul lp.mem_lp_const_smul variable (E p 𝕜) /-- The `𝕜`-submodule of elements of `∀ i : α, E i` whose `lp` norm is finite. This is `lp E p`, with extra structure. -/ def _root_.lpSubmodule : Submodule 𝕜 (PreLp E) := { lp E p with smul_mem' := fun c f hf => by simpa using mem_lp_const_smul c ⟨f, hf⟩ } #align lp_submodule lpSubmodule variable {E p 𝕜} theorem coe_lpSubmodule : (lpSubmodule E p 𝕜).toAddSubgroup = lp E p := rfl #align lp.coe_lp_submodule lp.coe_lpSubmodule instance : Module 𝕜 (lp E p) := { (lpSubmodule E p 𝕜).module with } @[simp] theorem coeFn_smul (c : 𝕜) (f : lp E p) : ⇑(c • f) = c • ⇑f := rfl #align lp.coe_fn_smul lp.coeFn_smul instance [∀ i, SMulCommClass 𝕜' 𝕜 (E i)] : SMulCommClass 𝕜' 𝕜 (lp E p) := ⟨fun _ _ _ => Subtype.ext <| smul_comm _ _ _⟩ instance [SMul 𝕜' 𝕜] [∀ i, IsScalarTower 𝕜' 𝕜 (E i)] : IsScalarTower 𝕜' 𝕜 (lp E p) := ⟨fun _ _ _ => Subtype.ext <| smul_assoc _ _ _⟩ instance [∀ i, Module 𝕜ᵐᵒᵖ (E i)] [∀ i, IsCentralScalar 𝕜 (E i)] : IsCentralScalar 𝕜 (lp E p) := ⟨fun _ _ => Subtype.ext <| op_smul_eq_smul _ _⟩ theorem norm_const_smul_le (hp : p ≠ 0) (c : 𝕜) (f : lp E p) : ‖c • f‖ ≤ ‖c‖ * ‖f‖ := by rcases p.trichotomy with (rfl | rfl | hp) · exact absurd rfl hp · cases isEmpty_or_nonempty α · simp [lp.eq_zero' f] have hcf := lp.isLUB_norm (c • f) have hfc := (lp.isLUB_norm f).mul_left (norm_nonneg c) simp_rw [← Set.range_comp, Function.comp] at hfc -- TODO: some `IsLUB` API should make it a one-liner from here. refine hcf.right ?_ have := hfc.left simp_rw [mem_upperBounds, Set.mem_range, forall_exists_index, forall_apply_eq_imp_iff] at this ⊢ intro a exact (norm_smul_le _ _).trans (this a) · letI inst : NNNorm (lp E p) := ⟨fun f => ⟨‖f‖, norm_nonneg' _⟩⟩ have coe_nnnorm : ∀ f : lp E p, ↑‖f‖₊ = ‖f‖ := fun _ => rfl suffices ‖c • f‖₊ ^ p.toReal ≤ (‖c‖₊ * ‖f‖₊) ^ p.toReal by rwa [NNReal.rpow_le_rpow_iff hp] at this clear_value inst rw [NNReal.mul_rpow] have hLHS := lp.hasSum_norm hp (c • f) have hRHS := (lp.hasSum_norm hp f).mul_left (‖c‖ ^ p.toReal) simp_rw [← coe_nnnorm, ← _root_.coe_nnnorm, ← NNReal.coe_rpow, ← NNReal.coe_mul, NNReal.hasSum_coe] at hRHS hLHS refine hasSum_mono hLHS hRHS fun i => ?_ dsimp only rw [← NNReal.mul_rpow] -- Porting note: added rw [lp.coeFn_smul, Pi.smul_apply] gcongr apply nnnorm_smul_le #align lp.norm_const_smul_le lp.norm_const_smul_le instance [Fact (1 ≤ p)] : BoundedSMul 𝕜 (lp E p) := BoundedSMul.of_norm_smul_le <| norm_const_smul_le (zero_lt_one.trans_le <| Fact.out).ne' end BoundedSMul section DivisionRing variable {𝕜 : Type*} variable [NormedDivisionRing 𝕜] [∀ i, Module 𝕜 (E i)] [∀ i, BoundedSMul 𝕜 (E i)] theorem norm_const_smul (hp : p ≠ 0) {c : 𝕜} (f : lp E p) : ‖c • f‖ = ‖c‖ * ‖f‖ := by obtain rfl | hc := eq_or_ne c 0 · simp refine le_antisymm (norm_const_smul_le hp c f) ?_ have := mul_le_mul_of_nonneg_left (norm_const_smul_le hp c⁻¹ (c • f)) (norm_nonneg c) rwa [inv_smul_smul₀ hc, norm_inv, mul_inv_cancel_left₀ (norm_ne_zero_iff.mpr hc)] at this #align lp.norm_const_smul lp.norm_const_smul end DivisionRing section NormedSpace variable {𝕜 : Type*} [NormedField 𝕜] [∀ i, NormedSpace 𝕜 (E i)] instance instNormedSpace [Fact (1 ≤ p)] : NormedSpace 𝕜 (lp E p) where norm_smul_le c f := norm_smul_le c f end NormedSpace section NormedStarGroup variable [∀ i, StarAddMonoid (E i)] [∀ i, NormedStarGroup (E i)]
Mathlib/Analysis/NormedSpace/lpSpace.lean
724
731
theorem _root_.Memℓp.star_mem {f : ∀ i, E i} (hf : Memℓp f p) : Memℓp (star 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
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.CategoryTheory.SingleObj import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.CategoryTheory.Pi.Basic import Mathlib.CategoryTheory.Limits.IsLimit #align_import category_theory.category.Groupoid from "leanprover-community/mathlib"@"c9c9fa15fec7ca18e9ec97306fb8764bfe988a7e" /-! # Category of groupoids This file contains the definition of the category `Grpd` of all groupoids. In this category objects are groupoids and morphisms are functors between these groupoids. We also provide two “forgetting” functors: `objects : Grpd ⥤ Type` and `forgetToCat : Grpd ⥤ Cat`. ## Implementation notes Though `Grpd` is not a concrete category, we use `Bundled` to define its carrier type. -/ universe v u namespace CategoryTheory -- intended to be used with explicit universe parameters /-- Category of groupoids -/ @[nolint checkUnivs] def Grpd := Bundled Groupoid.{v, u} set_option linter.uppercaseLean3 false in #align category_theory.Groupoid CategoryTheory.Grpd namespace Grpd instance : Inhabited Grpd := ⟨Bundled.of (SingleObj PUnit)⟩ instance str' (C : Grpd.{v, u}) : Groupoid.{v, u} C.α := C.str set_option linter.uppercaseLean3 false in #align category_theory.Groupoid.str CategoryTheory.Grpd.str' instance : CoeSort Grpd Type* := Bundled.coeSort /-- Construct a bundled `Grpd` from the underlying type and the typeclass `Groupoid`. -/ def of (C : Type u) [Groupoid.{v} C] : Grpd.{v, u} := Bundled.of C set_option linter.uppercaseLean3 false in #align category_theory.Groupoid.of CategoryTheory.Grpd.of @[simp] theorem coe_of (C : Type u) [Groupoid C] : (of C : Type u) = C := rfl set_option linter.uppercaseLean3 false in #align category_theory.Groupoid.coe_of CategoryTheory.Grpd.coe_of /-- Category structure on `Grpd` -/ instance category : LargeCategory.{max v u} Grpd.{v, u} where Hom C D := C ⥤ D id C := 𝟭 C comp F G := F ⋙ G id_comp _ := rfl comp_id _ := rfl assoc := by intros; rfl set_option linter.uppercaseLean3 false in #align category_theory.Groupoid.category CategoryTheory.Grpd.category /-- Functor that gets the set of objects of a groupoid. It is not called `forget`, because it is not a faithful functor. -/ def objects : Grpd.{v, u} ⥤ Type u where obj := Bundled.α map F := F.obj set_option linter.uppercaseLean3 false in #align category_theory.Groupoid.objects CategoryTheory.Grpd.objects /-- Forgetting functor to `Cat` -/ def forgetToCat : Grpd.{v, u} ⥤ Cat.{v, u} where obj C := Cat.of C map := id set_option linter.uppercaseLean3 false in #align category_theory.Groupoid.forget_to_Cat CategoryTheory.Grpd.forgetToCat instance forgetToCat_full : forgetToCat.Full where map_surjective f := ⟨f, rfl⟩ set_option linter.uppercaseLean3 false in #align category_theory.Groupoid.forget_to_Cat_full CategoryTheory.Grpd.forgetToCat_full instance forgetToCat_faithful : forgetToCat.Faithful where set_option linter.uppercaseLean3 false in #align category_theory.Groupoid.forget_to_Cat_faithful CategoryTheory.Grpd.forgetToCat_faithful /-- Convert arrows in the category of groupoids to functors, which sometimes helps in applying simp lemmas -/ theorem hom_to_functor {C D E : Grpd.{v, u}} (f : C ⟶ D) (g : D ⟶ E) : f ≫ g = f ⋙ g := rfl set_option linter.uppercaseLean3 false in #align category_theory.Groupoid.hom_to_functor CategoryTheory.Grpd.hom_to_functor /-- Converts identity in the category of groupoids to the functor identity -/ theorem id_to_functor {C : Grpd.{v, u}} : 𝟭 C = 𝟙 C := rfl set_option linter.uppercaseLean3 false in #align category_theory.Groupoid.id_to_functor CategoryTheory.Grpd.id_to_functor section Products /-- Construct the product over an indexed family of groupoids, as a fan. -/ def piLimitFan ⦃J : Type u⦄ (F : J → Grpd.{u, u}) : Limits.Fan F := Limits.Fan.mk (@of (∀ j : J, F j) _) fun j => CategoryTheory.Pi.eval _ j set_option linter.uppercaseLean3 false in #align category_theory.Groupoid.pi_limit_fan CategoryTheory.Grpd.piLimitFan /-- The product fan over an indexed family of groupoids, is a limit cone. -/ def piLimitFanIsLimit ⦃J : Type u⦄ (F : J → Grpd.{u, u}) : Limits.IsLimit (piLimitFan F) := Limits.mkFanLimit (piLimitFan F) (fun s => Functor.pi' fun j => s.proj j) (by intros dsimp only [piLimitFan] simp [hom_to_functor]) (by intro s m w apply Functor.pi_ext intro j; specialize w j simpa) set_option linter.uppercaseLean3 false in #align category_theory.Groupoid.pi_limit_fan_is_limit CategoryTheory.Grpd.piLimitFanIsLimit instance has_pi : Limits.HasProducts Grpd.{u, u} := Limits.hasProducts_of_limit_fans (by apply piLimitFan) (by apply piLimitFanIsLimit) set_option linter.uppercaseLean3 false in #align category_theory.Groupoid.has_pi CategoryTheory.Grpd.has_pi /-- The product of a family of groupoids is isomorphic to the product object in the category of Groupoids -/ noncomputable def piIsoPi (J : Type u) (f : J → Grpd.{u, u}) : @of (∀ j, f j) _ ≅ ∏ᶜ f := Limits.IsLimit.conePointUniqueUpToIso (piLimitFanIsLimit f) (Limits.limit.isLimit (Discrete.functor f)) set_option linter.uppercaseLean3 false in #align category_theory.Groupoid.pi_iso_pi CategoryTheory.Grpd.piIsoPi @[simp]
Mathlib/CategoryTheory/Category/Grpd.lean
152
155
theorem piIsoPi_hom_π (J : Type u) (f : J → Grpd.{u, u}) (j : J) : (piIsoPi J f).hom ≫ Limits.Pi.π f j = CategoryTheory.Pi.eval _ j := by
simp [piIsoPi] rfl
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Kenny Lau -/ import Mathlib.Algebra.CharP.Defs import Mathlib.RingTheory.Multiplicity import Mathlib.RingTheory.PowerSeries.Basic #align_import ring_theory.power_series.basic from "leanprover-community/mathlib"@"2d5739b61641ee4e7e53eca5688a08f66f2e6a60" /-! # Formal power series (in one variable) - Order The `PowerSeries.order` of a formal power series `φ` is the multiplicity of the variable `X` in `φ`. If the coefficients form an integral domain, then `PowerSeries.order` is an additive valuation (`PowerSeries.order_mul`, `PowerSeries.le_order_add`). We prove that if the commutative ring `R` of coefficients is an integral domain, then the ring `R⟦X⟧` of formal power series in one variable over `R` is an integral domain. Given a non-zero power series `f`, `divided_by_X_pow_order f` is the power series obtained by dividing out the largest power of X that divides `f`, that is its order. This is useful when proving that `R⟦X⟧` is a normalization monoid, which is done in `PowerSeries.Inverse`. -/ noncomputable section open Polynomial open Finset (antidiagonal mem_antidiagonal) namespace PowerSeries open Finsupp (single) variable {R : Type*} section OrderBasic open multiplicity variable [Semiring R] {φ : R⟦X⟧} theorem exists_coeff_ne_zero_iff_ne_zero : (∃ n : ℕ, coeff R n φ ≠ 0) ↔ φ ≠ 0 := by refine not_iff_not.mp ?_ push_neg -- FIXME: the `FunLike.coe` doesn't seem to be picked up in the expression after #8386? simp [PowerSeries.ext_iff, (coeff R _).map_zero] #align power_series.exists_coeff_ne_zero_iff_ne_zero PowerSeries.exists_coeff_ne_zero_iff_ne_zero /-- The order of a formal power series `φ` is the greatest `n : PartENat` such that `X^n` divides `φ`. The order is `⊤` if and only if `φ = 0`. -/ def order (φ : R⟦X⟧) : PartENat := letI := Classical.decEq R letI := Classical.decEq R⟦X⟧ if h : φ = 0 then ⊤ else Nat.find (exists_coeff_ne_zero_iff_ne_zero.mpr h) #align power_series.order PowerSeries.order /-- The order of the `0` power series is infinite. -/ @[simp] theorem order_zero : order (0 : R⟦X⟧) = ⊤ := dif_pos rfl #align power_series.order_zero PowerSeries.order_zero theorem order_finite_iff_ne_zero : (order φ).Dom ↔ φ ≠ 0 := by simp only [order] constructor · split_ifs with h <;> intro H · simp only [PartENat.top_eq_none, Part.not_none_dom] at H · exact h · intro h simp [h] #align power_series.order_finite_iff_ne_zero PowerSeries.order_finite_iff_ne_zero /-- If the order of a formal power series is finite, then the coefficient indexed by the order is nonzero. -/ theorem coeff_order (h : (order φ).Dom) : coeff R (φ.order.get h) φ ≠ 0 := by classical simp only [order, order_finite_iff_ne_zero.mp h, not_false_iff, dif_neg, PartENat.get_natCast'] generalize_proofs h exact Nat.find_spec h #align power_series.coeff_order PowerSeries.coeff_order /-- If the `n`th coefficient of a formal power series is nonzero, then the order of the power series is less than or equal to `n`. -/ theorem order_le (n : ℕ) (h : coeff R n φ ≠ 0) : order φ ≤ n := by classical rw [order, dif_neg] · simp only [PartENat.coe_le_coe] exact Nat.find_le h · exact exists_coeff_ne_zero_iff_ne_zero.mp ⟨n, h⟩ #align power_series.order_le PowerSeries.order_le /-- The `n`th coefficient of a formal power series is `0` if `n` is strictly smaller than the order of the power series. -/ theorem coeff_of_lt_order (n : ℕ) (h : ↑n < order φ) : coeff R n φ = 0 := by contrapose! h exact order_le _ h #align power_series.coeff_of_lt_order PowerSeries.coeff_of_lt_order /-- The `0` power series is the unique power series with infinite order. -/ @[simp] theorem order_eq_top {φ : R⟦X⟧} : φ.order = ⊤ ↔ φ = 0 := PartENat.not_dom_iff_eq_top.symm.trans order_finite_iff_ne_zero.not_left #align power_series.order_eq_top PowerSeries.order_eq_top /-- The order of a formal power series is at least `n` if the `i`th coefficient is `0` for all `i < n`. -/ theorem nat_le_order (φ : R⟦X⟧) (n : ℕ) (h : ∀ i < n, coeff R i φ = 0) : ↑n ≤ order φ := by by_contra H; rw [not_le] at H have : (order φ).Dom := PartENat.dom_of_le_natCast H.le rw [← PartENat.natCast_get this, PartENat.coe_lt_coe] at H exact coeff_order this (h _ H) #align power_series.nat_le_order PowerSeries.nat_le_order /-- The order of a formal power series is at least `n` if the `i`th coefficient is `0` for all `i < n`. -/ theorem le_order (φ : R⟦X⟧) (n : PartENat) (h : ∀ i : ℕ, ↑i < n → coeff R i φ = 0) : n ≤ order φ := by induction n using PartENat.casesOn · show _ ≤ _ rw [top_le_iff, order_eq_top] ext i exact h _ (PartENat.natCast_lt_top i) · apply nat_le_order simpa only [PartENat.coe_lt_coe] using h #align power_series.le_order PowerSeries.le_order /-- The order of a formal power series is exactly `n` if the `n`th coefficient is nonzero, and the `i`th coefficient is `0` for all `i < n`. -/ theorem order_eq_nat {φ : R⟦X⟧} {n : ℕ} : order φ = n ↔ coeff R n φ ≠ 0 ∧ ∀ i, i < n → coeff R i φ = 0 := by classical rcases eq_or_ne φ 0 with (rfl | hφ) · simpa [(coeff R _).map_zero] using (PartENat.natCast_ne_top _).symm simp [order, dif_neg hφ, Nat.find_eq_iff] #align power_series.order_eq_nat PowerSeries.order_eq_nat /-- The order of a formal power series is exactly `n` if the `n`th coefficient is nonzero, and the `i`th coefficient is `0` for all `i < n`. -/ theorem order_eq {φ : R⟦X⟧} {n : PartENat} : order φ = n ↔ (∀ i : ℕ, ↑i = n → coeff R i φ ≠ 0) ∧ ∀ i : ℕ, ↑i < n → coeff R i φ = 0 := by induction n using PartENat.casesOn · rw [order_eq_top] constructor · rintro rfl constructor <;> intros · exfalso exact PartENat.natCast_ne_top ‹_› ‹_› · exact (coeff _ _).map_zero · rintro ⟨_h₁, h₂⟩ ext i exact h₂ i (PartENat.natCast_lt_top i) · simpa [PartENat.natCast_inj] using order_eq_nat #align power_series.order_eq PowerSeries.order_eq /-- The order of the sum of two formal power series is at least the minimum of their orders. -/ theorem le_order_add (φ ψ : R⟦X⟧) : min (order φ) (order ψ) ≤ order (φ + ψ) := by refine le_order _ _ ?_ simp (config := { contextual := true }) [coeff_of_lt_order] #align power_series.le_order_add PowerSeries.le_order_add private theorem order_add_of_order_eq.aux (φ ψ : R⟦X⟧) (_h : order φ ≠ order ψ) (H : order φ < order ψ) : order (φ + ψ) ≤ order φ ⊓ order ψ := by suffices order (φ + ψ) = order φ by rw [le_inf_iff, this] exact ⟨le_rfl, le_of_lt H⟩ rw [order_eq] constructor · intro i hi rw [← hi] at H rw [(coeff _ _).map_add, coeff_of_lt_order i H, add_zero] exact (order_eq_nat.1 hi.symm).1 · intro i hi rw [(coeff _ _).map_add, coeff_of_lt_order i hi, coeff_of_lt_order i (lt_trans hi H), zero_add] -- #align power_series.order_add_of_order_eq.aux power_series.order_add_of_order_eq.aux /-- The order of the sum of two formal power series is the minimum of their orders if their orders differ. -/
Mathlib/RingTheory/PowerSeries/Order.lean
185
192
theorem order_add_of_order_eq (φ ψ : R⟦X⟧) (h : order φ ≠ order ψ) : order (φ + ψ) = order φ ⊓ order ψ := by
refine le_antisymm ?_ (le_order_add _ _) by_cases H₁ : order φ < order ψ · apply order_add_of_order_eq.aux _ _ h H₁ by_cases H₂ : order ψ < order φ · simpa only [add_comm, inf_comm] using order_add_of_order_eq.aux _ _ h.symm H₂ exfalso; exact h (le_antisymm (not_lt.1 H₂) (not_lt.1 H₁))
/- Copyright (c) 2017 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Scott Morrison, Mario Carneiro, Andrew Yang -/ import Mathlib.Topology.Category.TopCat.Limits.Products #align_import topology.category.Top.limits.pullbacks from "leanprover-community/mathlib"@"178a32653e369dce2da68dc6b2694e385d484ef1" /-! # Pullbacks and pushouts in the category of topological spaces -/ -- Porting note: every ML3 decl has an uppercase letter set_option linter.uppercaseLean3 false open TopologicalSpace open CategoryTheory open CategoryTheory.Limits universe v u w noncomputable section namespace TopCat variable {J : Type v} [SmallCategory J] section Pullback variable {X Y Z : TopCat.{u}} /-- The first projection from the pullback. -/ abbrev pullbackFst (f : X ⟶ Z) (g : Y ⟶ Z) : TopCat.of { p : X × Y // f p.1 = g p.2 } ⟶ X := ⟨Prod.fst ∘ Subtype.val, by apply Continuous.comp <;> set_option tactic.skipAssignedInstances false in continuity⟩ #align Top.pullback_fst TopCat.pullbackFst lemma pullbackFst_apply (f : X ⟶ Z) (g : Y ⟶ Z) (x) : pullbackFst f g x = x.1.1 := rfl /-- The second projection from the pullback. -/ abbrev pullbackSnd (f : X ⟶ Z) (g : Y ⟶ Z) : TopCat.of { p : X × Y // f p.1 = g p.2 } ⟶ Y := ⟨Prod.snd ∘ Subtype.val, by apply Continuous.comp <;> set_option tactic.skipAssignedInstances false in continuity⟩ #align Top.pullback_snd TopCat.pullbackSnd lemma pullbackSnd_apply (f : X ⟶ Z) (g : Y ⟶ Z) (x) : pullbackSnd f g x = x.1.2 := rfl /-- The explicit pullback cone of `X, Y` given by `{ p : X × Y // f p.1 = g p.2 }`. -/ def pullbackCone (f : X ⟶ Z) (g : Y ⟶ Z) : PullbackCone f g := PullbackCone.mk (pullbackFst f g) (pullbackSnd f g) (by dsimp [pullbackFst, pullbackSnd, Function.comp_def] ext ⟨x, h⟩ -- Next 2 lines were -- `rw [comp_apply, ContinuousMap.coe_mk, comp_apply, ContinuousMap.coe_mk]` -- `exact h` before leanprover/lean4#2644 rw [comp_apply, comp_apply] congr!) #align Top.pullback_cone TopCat.pullbackCone /-- The constructed cone is a limit. -/ def pullbackConeIsLimit (f : X ⟶ Z) (g : Y ⟶ Z) : IsLimit (pullbackCone f g) := PullbackCone.isLimitAux' _ (by intro S constructor; swap · exact { toFun := fun x => ⟨⟨S.fst x, S.snd x⟩, by simpa using ConcreteCategory.congr_hom S.condition x⟩ continuous_toFun := by apply Continuous.subtype_mk <| Continuous.prod_mk ?_ ?_ · exact (PullbackCone.fst S)|>.continuous_toFun · exact (PullbackCone.snd S)|>.continuous_toFun } refine ⟨?_, ?_, ?_⟩ · delta pullbackCone ext a -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [comp_apply, ContinuousMap.coe_mk] · delta pullbackCone ext a -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [comp_apply, ContinuousMap.coe_mk] · intro m h₁ h₂ -- Porting note: used to be ext x apply ContinuousMap.ext; intro x apply Subtype.ext apply Prod.ext · simpa using ConcreteCategory.congr_hom h₁ x · simpa using ConcreteCategory.congr_hom h₂ x) #align Top.pullback_cone_is_limit TopCat.pullbackConeIsLimit /-- The pullback of two maps can be identified as a subspace of `X × Y`. -/ def pullbackIsoProdSubtype (f : X ⟶ Z) (g : Y ⟶ Z) : pullback f g ≅ TopCat.of { p : X × Y // f p.1 = g p.2 } := (limit.isLimit _).conePointUniqueUpToIso (pullbackConeIsLimit f g) #align Top.pullback_iso_prod_subtype TopCat.pullbackIsoProdSubtype @[reassoc (attr := simp)] theorem pullbackIsoProdSubtype_inv_fst (f : X ⟶ Z) (g : Y ⟶ Z) : (pullbackIsoProdSubtype f g).inv ≫ pullback.fst = pullbackFst f g := by simp [pullbackCone, pullbackIsoProdSubtype] #align Top.pullback_iso_prod_subtype_inv_fst TopCat.pullbackIsoProdSubtype_inv_fst theorem pullbackIsoProdSubtype_inv_fst_apply (f : X ⟶ Z) (g : Y ⟶ Z) (x : { p : X × Y // f p.1 = g p.2 }) : (pullback.fst : pullback f g ⟶ _) ((pullbackIsoProdSubtype f g).inv x) = (x : X × Y).fst := ConcreteCategory.congr_hom (pullbackIsoProdSubtype_inv_fst f g) x #align Top.pullback_iso_prod_subtype_inv_fst_apply TopCat.pullbackIsoProdSubtype_inv_fst_apply @[reassoc (attr := simp)] theorem pullbackIsoProdSubtype_inv_snd (f : X ⟶ Z) (g : Y ⟶ Z) : (pullbackIsoProdSubtype f g).inv ≫ pullback.snd = pullbackSnd f g := by simp [pullbackCone, pullbackIsoProdSubtype] #align Top.pullback_iso_prod_subtype_inv_snd TopCat.pullbackIsoProdSubtype_inv_snd theorem pullbackIsoProdSubtype_inv_snd_apply (f : X ⟶ Z) (g : Y ⟶ Z) (x : { p : X × Y // f p.1 = g p.2 }) : (pullback.snd : pullback f g ⟶ _) ((pullbackIsoProdSubtype f g).inv x) = (x : X × Y).snd := ConcreteCategory.congr_hom (pullbackIsoProdSubtype_inv_snd f g) x #align Top.pullback_iso_prod_subtype_inv_snd_apply TopCat.pullbackIsoProdSubtype_inv_snd_apply
Mathlib/Topology/Category/TopCat/Limits/Pullbacks.lean
126
128
theorem pullbackIsoProdSubtype_hom_fst (f : X ⟶ Z) (g : Y ⟶ Z) : (pullbackIsoProdSubtype f g).hom ≫ pullbackFst f g = pullback.fst := by
rw [← Iso.eq_inv_comp, pullbackIsoProdSubtype_inv_fst]
/- Copyright (c) 2018 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Johannes Hölzl, Rémy Degenne -/ import Mathlib.Order.Filter.Cofinite import Mathlib.Order.Hom.CompleteLattice #align_import order.liminf_limsup from "leanprover-community/mathlib"@"ffde2d8a6e689149e44fd95fa862c23a57f8c780" /-! # liminfs and limsups of functions and filters Defines the liminf/limsup of a function taking values in a conditionally complete lattice, with respect to an arbitrary filter. We define `limsSup f` (`limsInf f`) where `f` is a filter taking values in a conditionally complete lattice. `limsSup f` is the smallest element `a` such that, eventually, `u ≤ a` (and vice versa for `limsInf f`). To work with the Limsup along a function `u` use `limsSup (map u f)`. Usually, one defines the Limsup as `inf (sup s)` where the Inf is taken over all sets in the filter. For instance, in ℕ along a function `u`, this is `inf_n (sup_{k ≥ n} u k)` (and the latter quantity decreases with `n`, so this is in fact a limit.). There is however a difficulty: it is well possible that `u` is not bounded on the whole space, only eventually (think of `limsup (fun x ↦ 1/x)` on ℝ. Then there is no guarantee that the quantity above really decreases (the value of the `sup` beforehand is not really well defined, as one can not use ∞), so that the Inf could be anything. So one can not use this `inf sup ...` definition in conditionally complete lattices, and one has to use a less tractable definition. In conditionally complete lattices, the definition is only useful for filters which are eventually bounded above (otherwise, the Limsup would morally be +∞, which does not belong to the space) and which are frequently bounded below (otherwise, the Limsup would morally be -∞, which is not in the space either). We start with definitions of these concepts for arbitrary filters, before turning to the definitions of Limsup and Liminf. In complete lattices, however, it coincides with the `Inf Sup` definition. -/ set_option autoImplicit true open Filter Set Function variable {α β γ ι ι' : Type*} namespace Filter section Relation /-- `f.IsBounded (≺)`: the filter `f` is eventually bounded w.r.t. the relation `≺`, i.e. eventually, it is bounded by some uniform bound. `r` will be usually instantiated with `≤` or `≥`. -/ def IsBounded (r : α → α → Prop) (f : Filter α) := ∃ b, ∀ᶠ x in f, r x b #align filter.is_bounded Filter.IsBounded /-- `f.IsBoundedUnder (≺) u`: the image of the filter `f` under `u` is eventually bounded w.r.t. the relation `≺`, i.e. eventually, it is bounded by some uniform bound. -/ def IsBoundedUnder (r : α → α → Prop) (f : Filter β) (u : β → α) := (map u f).IsBounded r #align filter.is_bounded_under Filter.IsBoundedUnder variable {r : α → α → Prop} {f g : Filter α} /-- `f` is eventually bounded if and only if, there exists an admissible set on which it is bounded. -/ theorem isBounded_iff : f.IsBounded r ↔ ∃ s ∈ f.sets, ∃ b, s ⊆ { x | r x b } := Iff.intro (fun ⟨b, hb⟩ => ⟨{ a | r a b }, hb, b, Subset.refl _⟩) fun ⟨_, hs, b, hb⟩ => ⟨b, mem_of_superset hs hb⟩ #align filter.is_bounded_iff Filter.isBounded_iff /-- A bounded function `u` is in particular eventually bounded. -/ theorem isBoundedUnder_of {f : Filter β} {u : β → α} : (∃ b, ∀ x, r (u x) b) → f.IsBoundedUnder r u | ⟨b, hb⟩ => ⟨b, show ∀ᶠ x in f, r (u x) b from eventually_of_forall hb⟩ #align filter.is_bounded_under_of Filter.isBoundedUnder_of theorem isBounded_bot : IsBounded r ⊥ ↔ Nonempty α := by simp [IsBounded, exists_true_iff_nonempty] #align filter.is_bounded_bot Filter.isBounded_bot theorem isBounded_top : IsBounded r ⊤ ↔ ∃ t, ∀ x, r x t := by simp [IsBounded, eq_univ_iff_forall] #align filter.is_bounded_top Filter.isBounded_top theorem isBounded_principal (s : Set α) : IsBounded r (𝓟 s) ↔ ∃ t, ∀ x ∈ s, r x t := by simp [IsBounded, subset_def] #align filter.is_bounded_principal Filter.isBounded_principal theorem isBounded_sup [IsTrans α r] [IsDirected α r] : IsBounded r f → IsBounded r g → IsBounded r (f ⊔ g) | ⟨b₁, h₁⟩, ⟨b₂, h₂⟩ => let ⟨b, rb₁b, rb₂b⟩ := directed_of r b₁ b₂ ⟨b, eventually_sup.mpr ⟨h₁.mono fun _ h => _root_.trans h rb₁b, h₂.mono fun _ h => _root_.trans h rb₂b⟩⟩ #align filter.is_bounded_sup Filter.isBounded_sup theorem IsBounded.mono (h : f ≤ g) : IsBounded r g → IsBounded r f | ⟨b, hb⟩ => ⟨b, h hb⟩ #align filter.is_bounded.mono Filter.IsBounded.mono theorem IsBoundedUnder.mono {f g : Filter β} {u : β → α} (h : f ≤ g) : g.IsBoundedUnder r u → f.IsBoundedUnder r u := fun hg => IsBounded.mono (map_mono h) hg #align filter.is_bounded_under.mono Filter.IsBoundedUnder.mono
Mathlib/Order/LiminfLimsup.lean
103
106
theorem IsBoundedUnder.mono_le [Preorder β] {l : Filter α} {u v : α → β} (hu : IsBoundedUnder (· ≤ ·) l u) (hv : v ≤ᶠ[l] u) : IsBoundedUnder (· ≤ ·) l v := by
apply hu.imp exact fun b hb => (eventually_map.1 hb).mp <| hv.mono fun x => le_trans
/- Copyright (c) 2022 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Order.ConditionallyCompleteLattice.Basic import Mathlib.Order.LatticeIntervals import Mathlib.Order.Interval.Set.OrdConnected #align_import order.complete_lattice_intervals from "leanprover-community/mathlib"@"207cfac9fcd06138865b5d04f7091e46d9320432" /-! # Subtypes of conditionally complete linear orders In this file we give conditions on a subset of a conditionally complete linear order, to ensure that the subtype is itself conditionally complete. We check that an `OrdConnected` set satisfies these conditions. ## TODO Add appropriate instances for all `Set.Ixx`. This requires a refactor that will allow different default values for `sSup` and `sInf`. -/ open scoped Classical open Set variable {ι : Sort*} {α : Type*} (s : Set α) section SupSet variable [Preorder α] [SupSet α] /-- `SupSet` structure on a nonempty subset `s` of a preorder with `SupSet`. This definition is non-canonical (it uses `default s`); it should be used only as here, as an auxiliary instance in the construction of the `ConditionallyCompleteLinearOrder` structure. -/ noncomputable def subsetSupSet [Inhabited s] : SupSet s where sSup t := if ht : t.Nonempty ∧ BddAbove t ∧ sSup ((↑) '' t : Set α) ∈ s then ⟨sSup ((↑) '' t : Set α), ht.2.2⟩ else default #align subset_has_Sup subsetSupSet attribute [local instance] subsetSupSet @[simp] theorem subset_sSup_def [Inhabited s] : @sSup s _ = fun t => if ht : t.Nonempty ∧ BddAbove t ∧ sSup ((↑) '' t : Set α) ∈ s then ⟨sSup ((↑) '' t : Set α), ht.2.2⟩ else default := rfl #align subset_Sup_def subset_sSup_def theorem subset_sSup_of_within [Inhabited s] {t : Set s} (h' : t.Nonempty) (h'' : BddAbove t) (h : sSup ((↑) '' t : Set α) ∈ s) : sSup ((↑) '' t : Set α) = (@sSup s _ t : α) := by simp [dif_pos, h, h', h''] #align subset_Sup_of_within subset_sSup_of_within theorem subset_sSup_emptyset [Inhabited s] : sSup (∅ : Set s) = default := by simp [sSup] theorem subset_sSup_of_not_bddAbove [Inhabited s] {t : Set s} (ht : ¬BddAbove t) : sSup t = default := by simp [sSup, ht] end SupSet section InfSet variable [Preorder α] [InfSet α] /-- `InfSet` structure on a nonempty subset `s` of a preorder with `InfSet`. This definition is non-canonical (it uses `default s`); it should be used only as here, as an auxiliary instance in the construction of the `ConditionallyCompleteLinearOrder` structure. -/ noncomputable def subsetInfSet [Inhabited s] : InfSet s where sInf t := if ht : t.Nonempty ∧ BddBelow t ∧ sInf ((↑) '' t : Set α) ∈ s then ⟨sInf ((↑) '' t : Set α), ht.2.2⟩ else default #align subset_has_Inf subsetInfSet attribute [local instance] subsetInfSet @[simp] theorem subset_sInf_def [Inhabited s] : @sInf s _ = fun t => if ht : t.Nonempty ∧ BddBelow t ∧ sInf ((↑) '' t : Set α) ∈ s then ⟨sInf ((↑) '' t : Set α), ht.2.2⟩ else default := rfl #align subset_Inf_def subset_sInf_def theorem subset_sInf_of_within [Inhabited s] {t : Set s} (h' : t.Nonempty) (h'' : BddBelow t) (h : sInf ((↑) '' t : Set α) ∈ s) : sInf ((↑) '' t : Set α) = (@sInf s _ t : α) := by simp [dif_pos, h, h', h''] #align subset_Inf_of_within subset_sInf_of_within
Mathlib/Order/CompleteLatticeIntervals.lean
102
104
theorem subset_sInf_emptyset [Inhabited s] : sInf (∅ : Set s) = default := by
simp [sInf]
/- Copyright (c) 2020 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Algebra.Squarefree.Basic import Mathlib.Data.Nat.Factorization.PrimePow #align_import data.nat.squarefree from "leanprover-community/mathlib"@"3c1368cac4abd5a5cbe44317ba7e87379d51ed88" /-! # Lemmas about squarefreeness of natural numbers A number is squarefree when it is not divisible by any squares except the squares of units. ## Main Results - `Nat.squarefree_iff_nodup_factors`: A positive natural number `x` is squarefree iff the list `factors x` has no duplicate factors. ## Tags squarefree, multiplicity -/ open Finset namespace Nat theorem squarefree_iff_nodup_factors {n : ℕ} (h0 : n ≠ 0) : Squarefree n ↔ n.factors.Nodup := by rw [UniqueFactorizationMonoid.squarefree_iff_nodup_normalizedFactors h0, Nat.factors_eq] simp #align nat.squarefree_iff_nodup_factors Nat.squarefree_iff_nodup_factors end Nat theorem Squarefree.nodup_factors {n : ℕ} (hn : Squarefree n) : n.factors.Nodup := (Nat.squarefree_iff_nodup_factors hn.ne_zero).mp hn namespace Nat variable {s : Finset ℕ} {m n p : ℕ} theorem squarefree_iff_prime_squarefree {n : ℕ} : Squarefree n ↔ ∀ x, Prime x → ¬x * x ∣ n := squarefree_iff_irreducible_sq_not_dvd_of_exists_irreducible ⟨_, prime_two⟩ #align nat.squarefree_iff_prime_squarefree Nat.squarefree_iff_prime_squarefree theorem _root_.Squarefree.natFactorization_le_one {n : ℕ} (p : ℕ) (hn : Squarefree n) : n.factorization p ≤ 1 := by rcases eq_or_ne n 0 with (rfl | hn') · simp rw [multiplicity.squarefree_iff_multiplicity_le_one] at hn by_cases hp : p.Prime · have := hn p simp only [multiplicity_eq_factorization hp hn', Nat.isUnit_iff, hp.ne_one, or_false_iff] at this exact mod_cast this · rw [factorization_eq_zero_of_non_prime _ hp] exact zero_le_one #align nat.squarefree.factorization_le_one Squarefree.natFactorization_le_one lemma factorization_eq_one_of_squarefree (hn : Squarefree n) (hp : p.Prime) (hpn : p ∣ n) : factorization n p = 1 := (hn.natFactorization_le_one _).antisymm <| (hp.dvd_iff_one_le_factorization hn.ne_zero).1 hpn theorem squarefree_of_factorization_le_one {n : ℕ} (hn : n ≠ 0) (hn' : ∀ p, n.factorization p ≤ 1) : Squarefree n := by rw [squarefree_iff_nodup_factors hn, List.nodup_iff_count_le_one] intro a rw [factors_count_eq] apply hn' #align nat.squarefree_of_factorization_le_one Nat.squarefree_of_factorization_le_one theorem squarefree_iff_factorization_le_one {n : ℕ} (hn : n ≠ 0) : Squarefree n ↔ ∀ p, n.factorization p ≤ 1 := ⟨fun hn => hn.natFactorization_le_one, squarefree_of_factorization_le_one hn⟩ #align nat.squarefree_iff_factorization_le_one Nat.squarefree_iff_factorization_le_one theorem Squarefree.ext_iff {n m : ℕ} (hn : Squarefree n) (hm : Squarefree m) : n = m ↔ ∀ p, Prime p → (p ∣ n ↔ p ∣ m) := by refine ⟨by rintro rfl; simp, fun h => eq_of_factorization_eq hn.ne_zero hm.ne_zero fun p => ?_⟩ by_cases hp : p.Prime · have h₁ := h _ hp rw [← not_iff_not, hp.dvd_iff_one_le_factorization hn.ne_zero, not_le, lt_one_iff, hp.dvd_iff_one_le_factorization hm.ne_zero, not_le, lt_one_iff] at h₁ have h₂ := hn.natFactorization_le_one p have h₃ := hm.natFactorization_le_one p rw [Nat.le_add_one_iff, Nat.le_zero] at h₂ h₃ cases' h₂ with h₂ h₂ · rwa [h₂, eq_comm, ← h₁] · rw [h₂, h₃.resolve_left] rw [← h₁, h₂] simp only [Nat.one_ne_zero, not_false_iff] rw [factorization_eq_zero_of_non_prime _ hp, factorization_eq_zero_of_non_prime _ hp] #align nat.squarefree.ext_iff Nat.Squarefree.ext_iff theorem squarefree_pow_iff {n k : ℕ} (hn : n ≠ 1) (hk : k ≠ 0) : Squarefree (n ^ k) ↔ Squarefree n ∧ k = 1 := by refine ⟨fun h => ?_, by rintro ⟨hn, rfl⟩; simpa⟩ rcases eq_or_ne n 0 with (rfl | -) · simp [zero_pow hk] at h refine ⟨h.squarefree_of_dvd (dvd_pow_self _ hk), by_contradiction fun h₁ => ?_⟩ have : 2 ≤ k := k.two_le_iff.mpr ⟨hk, h₁⟩ apply hn (Nat.isUnit_iff.1 (h _ _)) rw [← sq] exact pow_dvd_pow _ this #align nat.squarefree_pow_iff Nat.squarefree_pow_iff theorem squarefree_and_prime_pow_iff_prime {n : ℕ} : Squarefree n ∧ IsPrimePow n ↔ Prime n := by refine ⟨?_, fun hn => ⟨hn.squarefree, hn.isPrimePow⟩⟩ rw [isPrimePow_nat_iff] rintro ⟨h, p, k, hp, hk, rfl⟩ rw [squarefree_pow_iff hp.ne_one hk.ne'] at h rwa [h.2, pow_one] #align nat.squarefree_and_prime_pow_iff_prime Nat.squarefree_and_prime_pow_iff_prime /-- Assuming that `n` has no factors less than `k`, returns the smallest prime `p` such that `p^2 ∣ n`. -/ def minSqFacAux : ℕ → ℕ → Option ℕ | n, k => if h : n < k * k then none else have : Nat.sqrt n - k < Nat.sqrt n + 2 - k := by exact Nat.minFac_lemma n k h if k ∣ n then let n' := n / k have : Nat.sqrt n' - k < Nat.sqrt n + 2 - k := lt_of_le_of_lt (Nat.sub_le_sub_right (Nat.sqrt_le_sqrt <| Nat.div_le_self _ _) k) this if k ∣ n' then some k else minSqFacAux n' (k + 2) else minSqFacAux n (k + 2) termination_by n k => sqrt n + 2 - k #align nat.min_sq_fac_aux Nat.minSqFacAux /-- Returns the smallest prime factor `p` of `n` such that `p^2 ∣ n`, or `none` if there is no such `p` (that is, `n` is squarefree). See also `Nat.squarefree_iff_minSqFac`. -/ def minSqFac (n : ℕ) : Option ℕ := if 2 ∣ n then let n' := n / 2 if 2 ∣ n' then some 2 else minSqFacAux n' 3 else minSqFacAux n 3 #align nat.min_sq_fac Nat.minSqFac /-- The correctness property of the return value of `minSqFac`. * If `none`, then `n` is squarefree; * If `some d`, then `d` is a minimal square factor of `n` -/ def MinSqFacProp (n : ℕ) : Option ℕ → Prop | none => Squarefree n | some d => Prime d ∧ d * d ∣ n ∧ ∀ p, Prime p → p * p ∣ n → d ≤ p #align nat.min_sq_fac_prop Nat.MinSqFacProp theorem minSqFacProp_div (n) {k} (pk : Prime k) (dk : k ∣ n) (dkk : ¬k * k ∣ n) {o} (H : MinSqFacProp (n / k) o) : MinSqFacProp n o := by have : ∀ p, Prime p → p * p ∣ n → k * (p * p) ∣ n := fun p pp dp => have := (coprime_primes pk pp).2 fun e => by subst e contradiction (coprime_mul_iff_right.2 ⟨this, this⟩).mul_dvd_of_dvd_of_dvd dk dp cases' o with d · rw [MinSqFacProp, squarefree_iff_prime_squarefree] at H ⊢ exact fun p pp dp => H p pp ((dvd_div_iff dk).2 (this _ pp dp)) · obtain ⟨H1, H2, H3⟩ := H simp only [dvd_div_iff dk] at H2 H3 exact ⟨H1, dvd_trans (dvd_mul_left _ _) H2, fun p pp dp => H3 _ pp (this _ pp dp)⟩ #align nat.min_sq_fac_prop_div Nat.minSqFacProp_div theorem minSqFacAux_has_prop {n : ℕ} (k) (n0 : 0 < n) (i) (e : k = 2 * i + 3) (ih : ∀ m, Prime m → m ∣ n → k ≤ m) : MinSqFacProp n (minSqFacAux n k) := by rw [minSqFacAux] by_cases h : n < k * k <;> simp [h] · refine squarefree_iff_prime_squarefree.2 fun p pp d => ?_ have := ih p pp (dvd_trans ⟨_, rfl⟩ d) have := Nat.mul_le_mul this this exact not_le_of_lt h (le_trans this (le_of_dvd n0 d)) have k2 : 2 ≤ k := by omega have k0 : 0 < k := lt_of_lt_of_le (by decide) k2 have IH : ∀ n', n' ∣ n → ¬k ∣ n' → MinSqFacProp n' (n'.minSqFacAux (k + 2)) := by intro n' nd' nk have hn' := le_of_dvd n0 nd' refine have : Nat.sqrt n' - k < Nat.sqrt n + 2 - k := lt_of_le_of_lt (Nat.sub_le_sub_right (Nat.sqrt_le_sqrt hn') _) (Nat.minFac_lemma n k h) @minSqFacAux_has_prop n' (k + 2) (pos_of_dvd_of_pos nd' n0) (i + 1) (by simp [e, left_distrib]) fun m m2 d => ?_ rcases Nat.eq_or_lt_of_le (ih m m2 (dvd_trans d nd')) with me | ml · subst me contradiction apply (Nat.eq_or_lt_of_le ml).resolve_left intro me rw [← me, e] at d change 2 * (i + 2) ∣ n' at d have := ih _ prime_two (dvd_trans (dvd_of_mul_right_dvd d) nd') rw [e] at this exact absurd this (by omega) have pk : k ∣ n → Prime k := by refine fun dk => prime_def_minFac.2 ⟨k2, le_antisymm (minFac_le k0) ?_⟩ exact ih _ (minFac_prime (ne_of_gt k2)) (dvd_trans (minFac_dvd _) dk) split_ifs with dk dkk · exact ⟨pk dk, (Nat.dvd_div_iff dk).1 dkk, fun p pp d => ih p pp (dvd_trans ⟨_, rfl⟩ d)⟩ · specialize IH (n / k) (div_dvd_of_dvd dk) dkk exact minSqFacProp_div _ (pk dk) dk (mt (Nat.dvd_div_iff dk).2 dkk) IH · exact IH n (dvd_refl _) dk termination_by n.sqrt + 2 - k #align nat.min_sq_fac_aux_has_prop Nat.minSqFacAux_has_prop theorem minSqFac_has_prop (n : ℕ) : MinSqFacProp n (minSqFac n) := by dsimp only [minSqFac]; split_ifs with d2 d4 · exact ⟨prime_two, (dvd_div_iff d2).1 d4, fun p pp _ => pp.two_le⟩ · rcases Nat.eq_zero_or_pos n with n0 | n0 · subst n0 cases d4 (by decide) refine minSqFacProp_div _ prime_two d2 (mt (dvd_div_iff d2).2 d4) ?_ refine minSqFacAux_has_prop 3 (Nat.div_pos (le_of_dvd n0 d2) (by decide)) 0 rfl ?_ refine fun p pp dp => succ_le_of_lt (lt_of_le_of_ne pp.two_le ?_) rintro rfl contradiction · rcases Nat.eq_zero_or_pos n with n0 | n0 · subst n0 cases d2 (by decide) refine minSqFacAux_has_prop _ n0 0 rfl ?_ refine fun p pp dp => succ_le_of_lt (lt_of_le_of_ne pp.two_le ?_) rintro rfl contradiction #align nat.min_sq_fac_has_prop Nat.minSqFac_has_prop theorem minSqFac_prime {n d : ℕ} (h : n.minSqFac = some d) : Prime d := by have := minSqFac_has_prop n rw [h] at this exact this.1 #align nat.min_sq_fac_prime Nat.minSqFac_prime theorem minSqFac_dvd {n d : ℕ} (h : n.minSqFac = some d) : d * d ∣ n := by have := minSqFac_has_prop n rw [h] at this exact this.2.1 #align nat.min_sq_fac_dvd Nat.minSqFac_dvd theorem minSqFac_le_of_dvd {n d : ℕ} (h : n.minSqFac = some d) {m} (m2 : 2 ≤ m) (md : m * m ∣ n) : d ≤ m := by have := minSqFac_has_prop n; rw [h] at this have fd := minFac_dvd m exact le_trans (this.2.2 _ (minFac_prime <| ne_of_gt m2) (dvd_trans (mul_dvd_mul fd fd) md)) (minFac_le <| lt_of_lt_of_le (by decide) m2) #align nat.min_sq_fac_le_of_dvd Nat.minSqFac_le_of_dvd theorem squarefree_iff_minSqFac {n : ℕ} : Squarefree n ↔ n.minSqFac = none := by have := minSqFac_has_prop n constructor <;> intro H · cases' e : n.minSqFac with d · rfl rw [e] at this cases squarefree_iff_prime_squarefree.1 H _ this.1 this.2.1 · rwa [H] at this #align nat.squarefree_iff_min_sq_fac Nat.squarefree_iff_minSqFac instance : DecidablePred (Squarefree : ℕ → Prop) := fun _ => decidable_of_iff' _ squarefree_iff_minSqFac theorem squarefree_two : Squarefree 2 := by rw [squarefree_iff_nodup_factors] <;> simp #align nat.squarefree_two Nat.squarefree_two theorem divisors_filter_squarefree_of_squarefree {n : ℕ} (hn : Squarefree n) : n.divisors.filter Squarefree = n.divisors := Finset.ext fun d => ⟨@Finset.filter_subset _ _ _ _ d, fun hd => Finset.mem_filter.mpr ⟨hd, hn.squarefree_of_dvd (Nat.dvd_of_mem_divisors hd) ⟩⟩ open UniqueFactorizationMonoid theorem divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) : (n.divisors.filter Squarefree).val = (UniqueFactorizationMonoid.normalizedFactors n).toFinset.powerset.val.map fun x => x.val.prod := by rw [(Finset.nodup _).ext ((Finset.nodup _).map_on _)] · intro a simp only [Multiset.mem_filter, id, Multiset.mem_map, Finset.filter_val, ← Finset.mem_def, mem_divisors] constructor · rintro ⟨⟨an, h0⟩, hsq⟩ use (UniqueFactorizationMonoid.normalizedFactors a).toFinset simp only [id, Finset.mem_powerset] rcases an with ⟨b, rfl⟩ rw [mul_ne_zero_iff] at h0 rw [UniqueFactorizationMonoid.squarefree_iff_nodup_normalizedFactors h0.1] at hsq rw [Multiset.toFinset_subset, Multiset.toFinset_val, hsq.dedup, ← associated_iff_eq, normalizedFactors_mul h0.1 h0.2] exact ⟨Multiset.subset_of_le (Multiset.le_add_right _ _), normalizedFactors_prod h0.1⟩ · rintro ⟨s, hs, rfl⟩ rw [Finset.mem_powerset, ← Finset.val_le_iff, Multiset.toFinset_val] at hs have hs0 : s.val.prod ≠ 0 := by rw [Ne, Multiset.prod_eq_zero_iff] intro con apply not_irreducible_zero (irreducible_of_normalized_factor 0 (Multiset.mem_dedup.1 (Multiset.mem_of_le hs con))) rw [(normalizedFactors_prod h0).symm.dvd_iff_dvd_right] refine ⟨⟨Multiset.prod_dvd_prod_of_le (le_trans hs (Multiset.dedup_le _)), h0⟩, ?_⟩ have h := UniqueFactorizationMonoid.factors_unique irreducible_of_normalized_factor (fun x hx => irreducible_of_normalized_factor x (Multiset.mem_of_le (le_trans hs (Multiset.dedup_le _)) hx)) (normalizedFactors_prod hs0) rw [associated_eq_eq, Multiset.rel_eq] at h rw [UniqueFactorizationMonoid.squarefree_iff_nodup_normalizedFactors hs0, h] apply s.nodup · intro x hx y hy h rw [← Finset.val_inj, ← Multiset.rel_eq, ← associated_eq_eq] rw [← Finset.mem_def, Finset.mem_powerset] at hx hy apply UniqueFactorizationMonoid.factors_unique _ _ (associated_iff_eq.2 h) · intro z hz apply irreducible_of_normalized_factor z · rw [← Multiset.mem_toFinset] apply hx hz · intro z hz apply irreducible_of_normalized_factor z · rw [← Multiset.mem_toFinset] apply hy hz #align nat.divisors_filter_squarefree Nat.divisors_filter_squarefree
Mathlib/Data/Nat/Squarefree.lean
319
325
theorem sum_divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) {α : Type*} [AddCommMonoid α] {f : ℕ → α} : ∑ i ∈ n.divisors.filter Squarefree, f i = ∑ i ∈ (UniqueFactorizationMonoid.normalizedFactors n).toFinset.powerset, f i.val.prod := by
rw [Finset.sum_eq_multiset_sum, divisors_filter_squarefree h0, Multiset.map_map, Finset.sum_eq_multiset_sum] rfl
/- Copyright (c) 2024 Jz Pan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jz Pan -/ import Mathlib.LinearAlgebra.TensorProduct.Basic import Mathlib.RingTheory.Finiteness /-! # Some finiteness results of tensor product This file contains some finiteness results of tensor product. - `TensorProduct.exists_multiset`, `TensorProduct.exists_finsupp_left`, `TensorProduct.exists_finsupp_right`, `TensorProduct.exists_finset`: any element of `M ⊗[R] N` can be written as a finite sum of pure tensors. See also `TensorProduct.span_tmul_eq_top`. - `TensorProduct.exists_finite_submodule_left_of_finite`, `TensorProduct.exists_finite_submodule_right_of_finite`, `TensorProduct.exists_finite_submodule_of_finite`: any finite subset of `M ⊗[R] N` is contained in `M' ⊗[R] N`, resp. `M ⊗[R] N'`, resp. `M' ⊗[R] N'`, for some finitely generated submodules `M'` and `N'` of `M` and `N`, respectively. - `TensorProduct.exists_finite_submodule_left_of_finite'`, `TensorProduct.exists_finite_submodule_right_of_finite'`, `TensorProduct.exists_finite_submodule_of_finite'`: variation of the above results where `M` and `N` are already submodules. ## Tags tensor product, finitely generated -/ open scoped TensorProduct open Submodule variable {R M N : Type*} variable [CommSemiring R] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N] variable {M₁ M₂ : Submodule R M} {N₁ N₂ : Submodule R N} namespace TensorProduct /-- For any element `x` of `M ⊗[R] N`, there exists a (finite) multiset `{ (m_i, n_i) }` of `M × N`, such that `x` is equal to the sum of `m_i ⊗ₜ[R] n_i`. -/ theorem exists_multiset (x : M ⊗[R] N) : ∃ S : Multiset (M × N), x = (S.map fun i ↦ i.1 ⊗ₜ[R] i.2).sum := by induction x using TensorProduct.induction_on with | zero => exact ⟨0, by simp⟩ | tmul x y => exact ⟨{(x, y)}, by simp⟩ | add x y hx hy => obtain ⟨Sx, hx⟩ := hx obtain ⟨Sy, hy⟩ := hy exact ⟨Sx + Sy, by rw [Multiset.map_add, Multiset.sum_add, hx, hy]⟩ /-- For any element `x` of `M ⊗[R] N`, there exists a finite subset `{ (m_i, n_i) }` of `M × N` such that each `m_i` is distinct (we represent it as an element of `M →₀ N`), such that `x` is equal to the sum of `m_i ⊗ₜ[R] n_i`. -/ theorem exists_finsupp_left (x : M ⊗[R] N) : ∃ S : M →₀ N, x = S.sum fun m n ↦ m ⊗ₜ[R] n := by induction x using TensorProduct.induction_on with | zero => exact ⟨0, by simp⟩ | tmul x y => exact ⟨Finsupp.single x y, by simp⟩ | add x y hx hy => obtain ⟨Sx, hx⟩ := hx obtain ⟨Sy, hy⟩ := hy use Sx + Sy rw [hx, hy] exact (Finsupp.sum_add_index' (by simp) TensorProduct.tmul_add).symm /-- For any element `x` of `M ⊗[R] N`, there exists a finite subset `{ (m_i, n_i) }` of `M × N` such that each `n_i` is distinct (we represent it as an element of `N →₀ M`), such that `x` is equal to the sum of `m_i ⊗ₜ[R] n_i`. -/
Mathlib/LinearAlgebra/TensorProduct/Finiteness.lean
80
84
theorem exists_finsupp_right (x : M ⊗[R] N) : ∃ S : N →₀ M, x = S.sum fun n m ↦ m ⊗ₜ[R] n := by
obtain ⟨S, h⟩ := exists_finsupp_left (TensorProduct.comm R M N x) refine ⟨S, (TensorProduct.comm R M N).injective ?_⟩ simp_rw [h, Finsupp.sum, map_sum, comm_tmul]
/- Copyright (c) 2023 Jz Pan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jz Pan -/ import Mathlib.FieldTheory.SeparableDegree import Mathlib.FieldTheory.IsSepClosed /-! # Separable closure This file contains basics about the (relative) separable closure of a field extension. ## Main definitions - `separableClosure`: the relative separable closure of `F` in `E`, or called maximal separable subextension of `E / F`, is defined to be the intermediate field of `E / F` consisting of all separable elements. - `SeparableClosure`: the absolute separable closure, defined to be the relative separable closure inside the algebraic closure. - `Field.sepDegree F E`: the (infinite) separable degree $[E:F]_s$ of an algebraic extension `E / F` of fields, defined to be the degree of `separableClosure F E / F`. Later we will show that (`Field.finSepDegree_eq`, not in this file), if `Field.Emb F E` is finite, then this coincides with `Field.finSepDegree F E`. - `Field.insepDegree F E`: the (infinite) inseparable degree $[E:F]_i$ of an algebraic extension `E / F` of fields, defined to be the degree of `E / separableClosure F E`. - `Field.finInsepDegree F E`: the finite inseparable degree $[E:F]_i$ of an algebraic extension `E / F` of fields, defined to be the degree of `E / separableClosure F E` as a natural number. It is zero if such field extension is not finite. ## Main results - `le_separableClosure_iff`: an intermediate field of `E / F` is contained in the separable closure of `F` in `E` if and only if it is separable over `F`. - `separableClosure.normalClosure_eq_self`: the normal closure of the separable closure of `F` in `E` is equal to itself. - `separableClosure.isGalois`: the separable closure in a normal extension is Galois (namely, normal and separable). - `separableClosure.isSepClosure`: the separable closure in a separably closed extension is a separable closure of the base field. - `IntermediateField.isSeparable_adjoin_iff_separable`: `F(S) / F` is a separable extension if and only if all elements of `S` are separable elements. - `separableClosure.eq_top_iff`: the separable closure of `F` in `E` is equal to `E` if and only if `E / F` is separable. ## Tags separable degree, degree, separable closure -/ open scoped Classical Polynomial open FiniteDimensional Polynomial IntermediateField Field noncomputable section universe u v w variable (F : Type u) (E : Type v) [Field F] [Field E] [Algebra F E] variable (K : Type w) [Field K] [Algebra F K] section separableClosure /-- The (relative) separable closure of `F` in `E`, or called maximal separable subextension of `E / F`, is defined to be the intermediate field of `E / F` consisting of all separable elements. The previous results prove that these elements are closed under field operations. -/ def separableClosure : IntermediateField F E where carrier := {x | (minpoly F x).Separable} mul_mem' := separable_mul add_mem' := separable_add algebraMap_mem' := separable_algebraMap E inv_mem' := separable_inv variable {F E K} /-- An element is contained in the separable closure of `F` in `E` if and only if it is a separable element. -/ theorem mem_separableClosure_iff {x : E} : x ∈ separableClosure F E ↔ (minpoly F x).Separable := Iff.rfl /-- If `i` is an `F`-algebra homomorphism from `E` to `K`, then `i x` is contained in `separableClosure F K` if and only if `x` is contained in `separableClosure F E`. -/ theorem map_mem_separableClosure_iff (i : E →ₐ[F] K) {x : E} : i x ∈ separableClosure F K ↔ x ∈ separableClosure F E := by simp_rw [mem_separableClosure_iff, minpoly.algHom_eq i i.injective] /-- If `i` is an `F`-algebra homomorphism from `E` to `K`, then the preimage of `separableClosure F K` under the map `i` is equal to `separableClosure F E`. -/ theorem separableClosure.comap_eq_of_algHom (i : E →ₐ[F] K) : (separableClosure F K).comap i = separableClosure F E := by ext x exact map_mem_separableClosure_iff i /-- If `i` is an `F`-algebra homomorphism from `E` to `K`, then the image of `separableClosure F E` under the map `i` is contained in `separableClosure F K`. -/ theorem separableClosure.map_le_of_algHom (i : E →ₐ[F] K) : (separableClosure F E).map i ≤ separableClosure F K := map_le_iff_le_comap.2 (comap_eq_of_algHom i).ge variable (F) in /-- If `K / E / F` is a field extension tower, such that `K / E` has no non-trivial separable subextensions (when `K / E` is algebraic, this means that it is purely inseparable), then the image of `separableClosure F E` in `K` is equal to `separableClosure F K`. -/ theorem separableClosure.map_eq_of_separableClosure_eq_bot [Algebra E K] [IsScalarTower F E K] (h : separableClosure E K = ⊥) : (separableClosure F E).map (IsScalarTower.toAlgHom F E K) = separableClosure F K := by refine le_antisymm (map_le_of_algHom _) (fun x hx ↦ ?_) obtain ⟨y, rfl⟩ := mem_bot.1 <| h ▸ mem_separableClosure_iff.2 (mem_separableClosure_iff.1 hx |>.map_minpoly E) exact ⟨y, (map_mem_separableClosure_iff <| IsScalarTower.toAlgHom F E K).mp hx, rfl⟩ /-- If `i` is an `F`-algebra isomorphism of `E` and `K`, then the image of `separableClosure F E` under the map `i` is equal to `separableClosure F K`. -/ theorem separableClosure.map_eq_of_algEquiv (i : E ≃ₐ[F] K) : (separableClosure F E).map i = separableClosure F K := (map_le_of_algHom i.toAlgHom).antisymm (fun x h ↦ ⟨_, (map_mem_separableClosure_iff i.symm).2 h, by simp⟩) /-- If `E` and `K` are isomorphic as `F`-algebras, then `separableClosure F E` and `separableClosure F K` are also isomorphic as `F`-algebras. -/ def separableClosure.algEquivOfAlgEquiv (i : E ≃ₐ[F] K) : separableClosure F E ≃ₐ[F] separableClosure F K := (intermediateFieldMap i _).trans (equivOfEq (map_eq_of_algEquiv i)) alias AlgEquiv.separableClosure := separableClosure.algEquivOfAlgEquiv variable (F E K) /-- The separable closure of `F` in `E` is algebraic over `F`. -/ instance separableClosure.isAlgebraic : Algebra.IsAlgebraic F (separableClosure F E) := ⟨fun x ↦ isAlgebraic_iff.2 x.2.isIntegral.isAlgebraic⟩ /-- The separable closure of `F` in `E` is separable over `F`. -/ instance separableClosure.isSeparable : IsSeparable F (separableClosure F E) := ⟨fun x ↦ by simpa only [minpoly_eq] using x.2⟩ /-- An intermediate field of `E / F` is contained in the separable closure of `F` in `E` if all of its elements are separable over `F`. -/ theorem le_separableClosure' {L : IntermediateField F E} (hs : ∀ x : L, (minpoly F x).Separable) : L ≤ separableClosure F E := fun x h ↦ by simpa only [minpoly_eq] using hs ⟨x, h⟩ /-- An intermediate field of `E / F` is contained in the separable closure of `F` in `E` if it is separable over `F`. -/ theorem le_separableClosure (L : IntermediateField F E) [IsSeparable F L] : L ≤ separableClosure F E := le_separableClosure' F E (IsSeparable.separable F) /-- An intermediate field of `E / F` is contained in the separable closure of `F` in `E` if and only if it is separable over `F`. -/ theorem le_separableClosure_iff (L : IntermediateField F E) : L ≤ separableClosure F E ↔ IsSeparable F L := ⟨fun h ↦ ⟨fun x ↦ by simpa only [minpoly_eq] using h x.2⟩, fun _ ↦ le_separableClosure _ _ _⟩ /-- The separable closure in `E` of the separable closure of `F` in `E` is equal to itself. -/ theorem separableClosure.separableClosure_eq_bot : separableClosure (separableClosure F E) E = ⊥ := bot_unique fun x hx ↦ mem_bot.2 ⟨⟨x, mem_separableClosure_iff.1 hx |>.comap_minpoly_of_isSeparable F⟩, rfl⟩ /-- The normal closure in `E/F` of the separable closure of `F` in `E` is equal to itself. -/ theorem separableClosure.normalClosure_eq_self : normalClosure F (separableClosure F E) E = separableClosure F E := le_antisymm (normalClosure_le_iff.2 fun i ↦ haveI : IsSeparable F i.fieldRange := (AlgEquiv.ofInjectiveField i).isSeparable le_separableClosure F E _) (le_normalClosure _) /-- If `E` is normal over `F`, then the separable closure of `F` in `E` is Galois (i.e. normal and separable) over `F`. -/ instance separableClosure.isGalois [Normal F E] : IsGalois F (separableClosure F E) where to_isSeparable := separableClosure.isSeparable F E to_normal := by rw [← separableClosure.normalClosure_eq_self] exact normalClosure.normal F _ E /-- If `E / F` is a field extension and `E` is separably closed, then the separable closure of `F` in `E` is equal to `F` if and only if `F` is separably closed. -/ theorem IsSepClosed.separableClosure_eq_bot_iff [IsSepClosed E] : separableClosure F E = ⊥ ↔ IsSepClosed F := by refine ⟨fun h ↦ IsSepClosed.of_exists_root _ fun p _ hirr hsep ↦ ?_, fun _ ↦ IntermediateField.eq_bot_of_isSepClosed_of_isSeparable _⟩ obtain ⟨x, hx⟩ := IsSepClosed.exists_aeval_eq_zero E p (degree_pos_of_irreducible hirr).ne' hsep obtain ⟨x, rfl⟩ := h ▸ mem_separableClosure_iff.2 (hsep.of_dvd <| minpoly.dvd _ x hx) exact ⟨x, by simpa [Algebra.ofId_apply] using hx⟩ /-- If `E` is separably closed, then the separable closure of `F` in `E` is an absolute separable closure of `F`. -/ instance separableClosure.isSepClosure [IsSepClosed E] : IsSepClosure F (separableClosure F E) := ⟨(IsSepClosed.separableClosure_eq_bot_iff _ E).mp (separableClosure.separableClosure_eq_bot F E), isSeparable F E⟩ /-- The absolute separable closure is defined to be the relative separable closure inside the algebraic closure. It is indeed a separable closure (`IsSepClosure`) by `separableClosure.isSepClosure`, and it is Galois (`IsGalois`) by `separableClosure.isGalois` or `IsSepClosure.isGalois`, and every separable extension embeds into it (`IsSepClosed.lift`). -/ abbrev SeparableClosure : Type _ := separableClosure F (AlgebraicClosure F) /-- `F(S) / F` is a separable extension if and only if all elements of `S` are separable elements. -/ theorem IntermediateField.isSeparable_adjoin_iff_separable {S : Set E} : IsSeparable F (adjoin F S) ↔ ∀ x ∈ S, (minpoly F x).Separable := (le_separableClosure_iff F E _).symm.trans adjoin_le_iff /-- The separable closure of `F` in `E` is equal to `E` if and only if `E / F` is separable. -/ theorem separableClosure.eq_top_iff : separableClosure F E = ⊤ ↔ IsSeparable F E := ⟨fun h ↦ ⟨fun _ ↦ mem_separableClosure_iff.1 (h ▸ mem_top)⟩, fun _ ↦ top_unique fun x _ ↦ mem_separableClosure_iff.2 (IsSeparable.separable _ x)⟩ /-- If `K / E / F` is a field extension tower, then `separableClosure F K` is contained in `separableClosure E K`. -/ theorem separableClosure.le_restrictScalars [Algebra E K] [IsScalarTower F E K] : separableClosure F K ≤ (separableClosure E K).restrictScalars F := fun _ h ↦ h.map_minpoly E /-- If `K / E / F` is a field extension tower, such that `E / F` is separable, then `separableClosure F K` is equal to `separableClosure E K`. -/ theorem separableClosure.eq_restrictScalars_of_isSeparable [Algebra E K] [IsScalarTower F E K] [IsSeparable F E] : separableClosure F K = (separableClosure E K).restrictScalars F := (separableClosure.le_restrictScalars F E K).antisymm fun _ h ↦ h.comap_minpoly_of_isSeparable F /-- If `K / E / F` is a field extension tower, then `E` adjoin `separableClosure F K` is contained in `separableClosure E K`. -/ theorem separableClosure.adjoin_le [Algebra E K] [IsScalarTower F E K] : adjoin E (separableClosure F K) ≤ separableClosure E K := adjoin_le_iff.2 <| le_restrictScalars F E K /-- A compositum of two separable extensions is separable. -/ instance IntermediateField.isSeparable_sup (L1 L2 : IntermediateField F E) [h1 : IsSeparable F L1] [h2 : IsSeparable F L2] : IsSeparable F (L1 ⊔ L2 : IntermediateField F E) := by rw [← le_separableClosure_iff] at h1 h2 ⊢ exact sup_le h1 h2 /-- A compositum of separable extensions is separable. -/ instance IntermediateField.isSeparable_iSup {ι : Type*} {t : ι → IntermediateField F E} [h : ∀ i, IsSeparable F (t i)] : IsSeparable F (⨆ i, t i : IntermediateField F E) := by simp_rw [← le_separableClosure_iff] at h ⊢ exact iSup_le h end separableClosure namespace Field /-- The (infinite) separable degree for a general field extension `E / F` is defined to be the degree of `separableClosure F E / F`. -/ def sepDegree := Module.rank F (separableClosure F E) /-- The (infinite) inseparable degree for a general field extension `E / F` is defined to be the degree of `E / separableClosure F E`. -/ def insepDegree := Module.rank (separableClosure F E) E /-- The finite inseparable degree for a general field extension `E / F` is defined to be the degree of `E / separableClosure F E` as a natural number. It is defined to be zero if such field extension is infinite. -/ def finInsepDegree : ℕ := finrank (separableClosure F E) E theorem finInsepDegree_def' : finInsepDegree F E = Cardinal.toNat (insepDegree F E) := rfl instance instNeZeroSepDegree : NeZero (sepDegree F E) := ⟨rank_pos.ne'⟩ instance instNeZeroInsepDegree : NeZero (insepDegree F E) := ⟨rank_pos.ne'⟩ instance instNeZeroFinInsepDegree [FiniteDimensional F E] : NeZero (finInsepDegree F E) := ⟨finrank_pos.ne'⟩ /-- If `E` and `K` are isomorphic as `F`-algebras, then they have the same separable degree over `F`. -/ theorem lift_sepDegree_eq_of_equiv (i : E ≃ₐ[F] K) : Cardinal.lift.{w} (sepDegree F E) = Cardinal.lift.{v} (sepDegree F K) := i.separableClosure.toLinearEquiv.lift_rank_eq /-- The same-universe version of `Field.lift_sepDegree_eq_of_equiv`. -/ theorem sepDegree_eq_of_equiv (K : Type v) [Field K] [Algebra F K] (i : E ≃ₐ[F] K) : sepDegree F E = sepDegree F K := i.separableClosure.toLinearEquiv.rank_eq /-- The separable degree multiplied by the inseparable degree is equal to the (infinite) field extension degree. -/ theorem sepDegree_mul_insepDegree : sepDegree F E * insepDegree F E = Module.rank F E := rank_mul_rank F (separableClosure F E) E /-- If `E` and `K` are isomorphic as `F`-algebras, then they have the same inseparable degree over `F`. -/ theorem lift_insepDegree_eq_of_equiv (i : E ≃ₐ[F] K) : Cardinal.lift.{w} (insepDegree F E) = Cardinal.lift.{v} (insepDegree F K) := Algebra.lift_rank_eq_of_equiv_equiv i.separableClosure i rfl /-- The same-universe version of `Field.lift_insepDegree_eq_of_equiv`. -/ theorem insepDegree_eq_of_equiv (K : Type v) [Field K] [Algebra F K] (i : E ≃ₐ[F] K) : insepDegree F E = insepDegree F K := Algebra.rank_eq_of_equiv_equiv i.separableClosure i rfl /-- If `E` and `K` are isomorphic as `F`-algebras, then they have the same finite inseparable degree over `F`. -/ theorem finInsepDegree_eq_of_equiv (i : E ≃ₐ[F] K) : finInsepDegree F E = finInsepDegree F K := by simpa only [Cardinal.toNat_lift] using congr_arg Cardinal.toNat (lift_insepDegree_eq_of_equiv F E K i) @[simp] theorem sepDegree_self : sepDegree F F = 1 := by rw [sepDegree, Subsingleton.elim (separableClosure F F) ⊥, IntermediateField.rank_bot] @[simp] theorem insepDegree_self : insepDegree F F = 1 := by rw [insepDegree, Subsingleton.elim (separableClosure F F) ⊤, IntermediateField.rank_top] @[simp] theorem finInsepDegree_self : finInsepDegree F F = 1 := by rw [finInsepDegree_def', insepDegree_self, Cardinal.one_toNat] end Field namespace IntermediateField @[simp]
Mathlib/FieldTheory/SeparableClosure.lean
325
327
theorem sepDegree_bot : sepDegree F (⊥ : IntermediateField F E) = 1 := by
have := lift_sepDegree_eq_of_equiv _ _ _ (botEquiv F E) rwa [sepDegree_self, Cardinal.lift_one, ← Cardinal.lift_one.{u, v}, Cardinal.lift_inj] at this
/- Copyright (c) 2019 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Mario Carneiro, Isabel Longbottom, Scott Morrison -/ import Mathlib.Algebra.Order.ZeroLEOne import Mathlib.Data.List.InsertNth import Mathlib.Logic.Relation import Mathlib.Logic.Small.Defs import Mathlib.Order.GameAdd #align_import set_theory.game.pgame from "leanprover-community/mathlib"@"8900d545017cd21961daa2a1734bb658ef52c618" /-! # Combinatorial (pre-)games. The basic theory of combinatorial games, following Conway's book `On Numbers and Games`. We construct "pregames", define an ordering and arithmetic operations on them, then show that the operations descend to "games", defined via the equivalence relation `p ≈ q ↔ p ≤ q ∧ q ≤ p`. The surreal numbers will be built as a quotient of a subtype of pregames. A pregame (`SetTheory.PGame` below) is axiomatised via an inductive type, whose sole constructor takes two types (thought of as indexing the possible moves for the players Left and Right), and a pair of functions out of these types to `SetTheory.PGame` (thought of as describing the resulting game after making a move). Combinatorial games themselves, as a quotient of pregames, are constructed in `Game.lean`. ## Conway induction By construction, the induction principle for pregames is exactly "Conway induction". That is, to prove some predicate `SetTheory.PGame → Prop` holds for all pregames, it suffices to prove that for every pregame `g`, if the predicate holds for every game resulting from making a move, then it also holds for `g`. While it is often convenient to work "by induction" on pregames, in some situations this becomes awkward, so we also define accessor functions `SetTheory.PGame.LeftMoves`, `SetTheory.PGame.RightMoves`, `SetTheory.PGame.moveLeft` and `SetTheory.PGame.moveRight`. There is a relation `PGame.Subsequent p q`, saying that `p` can be reached by playing some non-empty sequence of moves starting from `q`, an instance `WellFounded Subsequent`, and a local tactic `pgame_wf_tac` which is helpful for discharging proof obligations in inductive proofs relying on this relation. ## Order properties Pregames have both a `≤` and a `<` relation, satisfying the usual properties of a `Preorder`. The relation `0 < x` means that `x` can always be won by Left, while `0 ≤ x` means that `x` can be won by Left as the second player. It turns out to be quite convenient to define various relations on top of these. We define the "less or fuzzy" relation `x ⧏ y` as `¬ y ≤ x`, the equivalence relation `x ≈ y` as `x ≤ y ∧ y ≤ x`, and the fuzzy relation `x ‖ y` as `x ⧏ y ∧ y ⧏ x`. If `0 ⧏ x`, then `x` can be won by Left as the first player. If `x ≈ 0`, then `x` can be won by the second player. If `x ‖ 0`, then `x` can be won by the first player. Statements like `zero_le_lf`, `zero_lf_le`, etc. unfold these definitions. The theorems `le_def` and `lf_def` give a recursive characterisation of each relation in terms of themselves two moves later. The theorems `zero_le`, `zero_lf`, etc. also take into account that `0` has no moves. Later, games will be defined as the quotient by the `≈` relation; that is to say, the `Antisymmetrization` of `SetTheory.PGame`. ## Algebraic structures We next turn to defining the operations necessary to make games into a commutative additive group. Addition is defined for $x = \{xL | xR\}$ and $y = \{yL | yR\}$ by $x + y = \{xL + y, x + yL | xR + y, x + yR\}$. Negation is defined by $\{xL | xR\} = \{-xR | -xL\}$. The order structures interact in the expected way with addition, so we have ``` theorem le_iff_sub_nonneg {x y : PGame} : x ≤ y ↔ 0 ≤ y - x := sorry theorem lt_iff_sub_pos {x y : PGame} : x < y ↔ 0 < y - x := sorry ``` We show that these operations respect the equivalence relation, and hence descend to games. At the level of games, these operations satisfy all the laws of a commutative group. To prove the necessary equivalence relations at the level of pregames, we introduce the notion of a `Relabelling` of a game, and show, for example, that there is a relabelling between `x + (y + z)` and `(x + y) + z`. ## Future work * The theory of dominated and reversible positions, and unique normal form for short games. * Analysis of basic domineering positions. * Hex. * Temperature. * The development of surreal numbers, based on this development of combinatorial games, is still quite incomplete. ## References The material here is all drawn from * [Conway, *On numbers and games*][conway2001] An interested reader may like to formalise some of the material from * [Andreas Blass, *A game semantics for linear logic*][MR1167694] * [André Joyal, *Remarques sur la théorie des jeux à deux personnes*][joyal1997] -/ set_option autoImplicit true namespace SetTheory open Function Relation -- We'd like to be able to use multi-character auto-implicits in this file. set_option relaxedAutoImplicit true /-! ### Pre-game moves -/ /-- The type of pre-games, before we have quotiented by equivalence (`PGame.Setoid`). In ZFC, a combinatorial game is constructed from two sets of combinatorial games that have been constructed at an earlier stage. To do this in type theory, we say that a pre-game is built inductively from two families of pre-games indexed over any type in Type u. The resulting type `PGame.{u}` lives in `Type (u+1)`, reflecting that it is a proper class in ZFC. -/ inductive PGame : Type (u + 1) | mk : ∀ α β : Type u, (α → PGame) → (β → PGame) → PGame #align pgame SetTheory.PGame compile_inductive% PGame namespace PGame /-- The indexing type for allowable moves by Left. -/ def LeftMoves : PGame → Type u | mk l _ _ _ => l #align pgame.left_moves SetTheory.PGame.LeftMoves /-- The indexing type for allowable moves by Right. -/ def RightMoves : PGame → Type u | mk _ r _ _ => r #align pgame.right_moves SetTheory.PGame.RightMoves /-- The new game after Left makes an allowed move. -/ def moveLeft : ∀ g : PGame, LeftMoves g → PGame | mk _l _ L _ => L #align pgame.move_left SetTheory.PGame.moveLeft /-- The new game after Right makes an allowed move. -/ def moveRight : ∀ g : PGame, RightMoves g → PGame | mk _ _r _ R => R #align pgame.move_right SetTheory.PGame.moveRight @[simp] theorem leftMoves_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).LeftMoves = xl := rfl #align pgame.left_moves_mk SetTheory.PGame.leftMoves_mk @[simp] theorem moveLeft_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).moveLeft = xL := rfl #align pgame.move_left_mk SetTheory.PGame.moveLeft_mk @[simp] theorem rightMoves_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).RightMoves = xr := rfl #align pgame.right_moves_mk SetTheory.PGame.rightMoves_mk @[simp] theorem moveRight_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).moveRight = xR := rfl #align pgame.move_right_mk SetTheory.PGame.moveRight_mk -- TODO define this at the level of games, as well, and perhaps also for finsets of games. /-- Construct a pre-game from list of pre-games describing the available moves for Left and Right. -/ def ofLists (L R : List PGame.{u}) : PGame.{u} := mk (ULift (Fin L.length)) (ULift (Fin R.length)) (fun i => L.get i.down) fun j ↦ R.get j.down #align pgame.of_lists SetTheory.PGame.ofLists theorem leftMoves_ofLists (L R : List PGame) : (ofLists L R).LeftMoves = ULift (Fin L.length) := rfl #align pgame.left_moves_of_lists SetTheory.PGame.leftMoves_ofLists theorem rightMoves_ofLists (L R : List PGame) : (ofLists L R).RightMoves = ULift (Fin R.length) := rfl #align pgame.right_moves_of_lists SetTheory.PGame.rightMoves_ofLists /-- Converts a number into a left move for `ofLists`. -/ def toOfListsLeftMoves {L R : List PGame} : Fin L.length ≃ (ofLists L R).LeftMoves := ((Equiv.cast (leftMoves_ofLists L R).symm).trans Equiv.ulift).symm #align pgame.to_of_lists_left_moves SetTheory.PGame.toOfListsLeftMoves /-- Converts a number into a right move for `ofLists`. -/ def toOfListsRightMoves {L R : List PGame} : Fin R.length ≃ (ofLists L R).RightMoves := ((Equiv.cast (rightMoves_ofLists L R).symm).trans Equiv.ulift).symm #align pgame.to_of_lists_right_moves SetTheory.PGame.toOfListsRightMoves theorem ofLists_moveLeft {L R : List PGame} (i : Fin L.length) : (ofLists L R).moveLeft (toOfListsLeftMoves i) = L.get i := rfl #align pgame.of_lists_move_left SetTheory.PGame.ofLists_moveLeft @[simp] theorem ofLists_moveLeft' {L R : List PGame} (i : (ofLists L R).LeftMoves) : (ofLists L R).moveLeft i = L.get (toOfListsLeftMoves.symm i) := rfl #align pgame.of_lists_move_left' SetTheory.PGame.ofLists_moveLeft' theorem ofLists_moveRight {L R : List PGame} (i : Fin R.length) : (ofLists L R).moveRight (toOfListsRightMoves i) = R.get i := rfl #align pgame.of_lists_move_right SetTheory.PGame.ofLists_moveRight @[simp] theorem ofLists_moveRight' {L R : List PGame} (i : (ofLists L R).RightMoves) : (ofLists L R).moveRight i = R.get (toOfListsRightMoves.symm i) := rfl #align pgame.of_lists_move_right' SetTheory.PGame.ofLists_moveRight' /-- A variant of `PGame.recOn` expressed in terms of `PGame.moveLeft` and `PGame.moveRight`. Both this and `PGame.recOn` describe Conway induction on games. -/ @[elab_as_elim] def moveRecOn {C : PGame → Sort*} (x : PGame) (IH : ∀ y : PGame, (∀ i, C (y.moveLeft i)) → (∀ j, C (y.moveRight j)) → C y) : C x := x.recOn fun yl yr yL yR => IH (mk yl yr yL yR) #align pgame.move_rec_on SetTheory.PGame.moveRecOn /-- `IsOption x y` means that `x` is either a left or right option for `y`. -/ @[mk_iff] inductive IsOption : PGame → PGame → Prop | moveLeft {x : PGame} (i : x.LeftMoves) : IsOption (x.moveLeft i) x | moveRight {x : PGame} (i : x.RightMoves) : IsOption (x.moveRight i) x #align pgame.is_option SetTheory.PGame.IsOption theorem IsOption.mk_left {xl xr : Type u} (xL : xl → PGame) (xR : xr → PGame) (i : xl) : (xL i).IsOption (mk xl xr xL xR) := @IsOption.moveLeft (mk _ _ _ _) i #align pgame.is_option.mk_left SetTheory.PGame.IsOption.mk_left theorem IsOption.mk_right {xl xr : Type u} (xL : xl → PGame) (xR : xr → PGame) (i : xr) : (xR i).IsOption (mk xl xr xL xR) := @IsOption.moveRight (mk _ _ _ _) i #align pgame.is_option.mk_right SetTheory.PGame.IsOption.mk_right theorem wf_isOption : WellFounded IsOption := ⟨fun x => moveRecOn x fun x IHl IHr => Acc.intro x fun y h => by induction' h with _ i _ j · exact IHl i · exact IHr j⟩ #align pgame.wf_is_option SetTheory.PGame.wf_isOption /-- `Subsequent x y` says that `x` can be obtained by playing some nonempty sequence of moves from `y`. It is the transitive closure of `IsOption`. -/ def Subsequent : PGame → PGame → Prop := TransGen IsOption #align pgame.subsequent SetTheory.PGame.Subsequent instance : IsTrans _ Subsequent := inferInstanceAs <| IsTrans _ (TransGen _) @[trans] theorem Subsequent.trans {x y z} : Subsequent x y → Subsequent y z → Subsequent x z := TransGen.trans #align pgame.subsequent.trans SetTheory.PGame.Subsequent.trans theorem wf_subsequent : WellFounded Subsequent := wf_isOption.transGen #align pgame.wf_subsequent SetTheory.PGame.wf_subsequent instance : WellFoundedRelation PGame := ⟨_, wf_subsequent⟩ @[simp] theorem Subsequent.moveLeft {x : PGame} (i : x.LeftMoves) : Subsequent (x.moveLeft i) x := TransGen.single (IsOption.moveLeft i) #align pgame.subsequent.move_left SetTheory.PGame.Subsequent.moveLeft @[simp] theorem Subsequent.moveRight {x : PGame} (j : x.RightMoves) : Subsequent (x.moveRight j) x := TransGen.single (IsOption.moveRight j) #align pgame.subsequent.move_right SetTheory.PGame.Subsequent.moveRight @[simp] theorem Subsequent.mk_left {xl xr} (xL : xl → PGame) (xR : xr → PGame) (i : xl) : Subsequent (xL i) (mk xl xr xL xR) := @Subsequent.moveLeft (mk _ _ _ _) i #align pgame.subsequent.mk_left SetTheory.PGame.Subsequent.mk_left @[simp] theorem Subsequent.mk_right {xl xr} (xL : xl → PGame) (xR : xr → PGame) (j : xr) : Subsequent (xR j) (mk xl xr xL xR) := @Subsequent.moveRight (mk _ _ _ _) j #align pgame.subsequent.mk_right SetTheory.PGame.Subsequent.mk_right /-- Discharges proof obligations of the form `⊢ Subsequent ..` arising in termination proofs of definitions using well-founded recursion on `PGame`. -/ macro "pgame_wf_tac" : tactic => `(tactic| solve_by_elim (config := { maxDepth := 8 }) [Prod.Lex.left, Prod.Lex.right, PSigma.Lex.left, PSigma.Lex.right, Subsequent.moveLeft, Subsequent.moveRight, Subsequent.mk_left, Subsequent.mk_right, Subsequent.trans] ) -- Register some consequences of pgame_wf_tac as simp-lemmas for convenience -- (which are applied by default for WF goals) -- This is different from mk_right from the POV of the simplifier, -- because the unifier can't solve `xr =?= RightMoves (mk xl xr xL xR)` at reducible transparency. @[simp] theorem Subsequent.mk_right' (xL : xl → PGame) (xR : xr → PGame) (j : RightMoves (mk xl xr xL xR)) : Subsequent (xR j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveRight_mk_left (xL : xl → PGame) (j) : Subsequent ((xL i).moveRight j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveRight_mk_right (xR : xr → PGame) (j) : Subsequent ((xR i).moveRight j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveLeft_mk_left (xL : xl → PGame) (j) : Subsequent ((xL i).moveLeft j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveLeft_mk_right (xR : xr → PGame) (j) : Subsequent ((xR i).moveLeft j) (mk xl xr xL xR) := by pgame_wf_tac -- Porting note: linter claims these lemmas don't simplify? open Subsequent in attribute [nolint simpNF] mk_left mk_right mk_right' moveRight_mk_left moveRight_mk_right moveLeft_mk_left moveLeft_mk_right /-! ### Basic pre-games -/ /-- The pre-game `Zero` is defined by `0 = { | }`. -/ instance : Zero PGame := ⟨⟨PEmpty, PEmpty, PEmpty.elim, PEmpty.elim⟩⟩ @[simp] theorem zero_leftMoves : LeftMoves 0 = PEmpty := rfl #align pgame.zero_left_moves SetTheory.PGame.zero_leftMoves @[simp] theorem zero_rightMoves : RightMoves 0 = PEmpty := rfl #align pgame.zero_right_moves SetTheory.PGame.zero_rightMoves instance isEmpty_zero_leftMoves : IsEmpty (LeftMoves 0) := instIsEmptyPEmpty #align pgame.is_empty_zero_left_moves SetTheory.PGame.isEmpty_zero_leftMoves instance isEmpty_zero_rightMoves : IsEmpty (RightMoves 0) := instIsEmptyPEmpty #align pgame.is_empty_zero_right_moves SetTheory.PGame.isEmpty_zero_rightMoves instance : Inhabited PGame := ⟨0⟩ /-- The pre-game `One` is defined by `1 = { 0 | }`. -/ instance instOnePGame : One PGame := ⟨⟨PUnit, PEmpty, fun _ => 0, PEmpty.elim⟩⟩ @[simp] theorem one_leftMoves : LeftMoves 1 = PUnit := rfl #align pgame.one_left_moves SetTheory.PGame.one_leftMoves @[simp] theorem one_moveLeft (x) : moveLeft 1 x = 0 := rfl #align pgame.one_move_left SetTheory.PGame.one_moveLeft @[simp] theorem one_rightMoves : RightMoves 1 = PEmpty := rfl #align pgame.one_right_moves SetTheory.PGame.one_rightMoves instance uniqueOneLeftMoves : Unique (LeftMoves 1) := PUnit.unique #align pgame.unique_one_left_moves SetTheory.PGame.uniqueOneLeftMoves instance isEmpty_one_rightMoves : IsEmpty (RightMoves 1) := instIsEmptyPEmpty #align pgame.is_empty_one_right_moves SetTheory.PGame.isEmpty_one_rightMoves /-! ### Pre-game order relations -/ /-- The less or equal relation on pre-games. If `0 ≤ x`, then Left can win `x` as the second player. -/ instance le : LE PGame := ⟨Sym2.GameAdd.fix wf_isOption fun x y le => (∀ i, ¬le y (x.moveLeft i) (Sym2.GameAdd.snd_fst <| IsOption.moveLeft i)) ∧ ∀ j, ¬le (y.moveRight j) x (Sym2.GameAdd.fst_snd <| IsOption.moveRight j)⟩ /-- The less or fuzzy relation on pre-games. If `0 ⧏ x`, then Left can win `x` as the first player. -/ def LF (x y : PGame) : Prop := ¬y ≤ x #align pgame.lf SetTheory.PGame.LF @[inherit_doc] scoped infixl:50 " ⧏ " => PGame.LF @[simp] protected theorem not_le {x y : PGame} : ¬x ≤ y ↔ y ⧏ x := Iff.rfl #align pgame.not_le SetTheory.PGame.not_le @[simp] theorem not_lf {x y : PGame} : ¬x ⧏ y ↔ y ≤ x := Classical.not_not #align pgame.not_lf SetTheory.PGame.not_lf theorem _root_.LE.le.not_gf {x y : PGame} : x ≤ y → ¬y ⧏ x := not_lf.2 #align has_le.le.not_gf LE.le.not_gf theorem LF.not_ge {x y : PGame} : x ⧏ y → ¬y ≤ x := id #align pgame.lf.not_ge SetTheory.PGame.LF.not_ge /-- Definition of `x ≤ y` on pre-games, in terms of `⧏`. The ordering here is chosen so that `And.left` refer to moves by Left, and `And.right` refer to moves by Right. -/ theorem le_iff_forall_lf {x y : PGame} : x ≤ y ↔ (∀ i, x.moveLeft i ⧏ y) ∧ ∀ j, x ⧏ y.moveRight j := by unfold LE.le le simp only rw [Sym2.GameAdd.fix_eq] rfl #align pgame.le_iff_forall_lf SetTheory.PGame.le_iff_forall_lf /-- Definition of `x ≤ y` on pre-games built using the constructor. -/ @[simp] theorem mk_le_mk {xl xr xL xR yl yr yL yR} : mk xl xr xL xR ≤ mk yl yr yL yR ↔ (∀ i, xL i ⧏ mk yl yr yL yR) ∧ ∀ j, mk xl xr xL xR ⧏ yR j := le_iff_forall_lf #align pgame.mk_le_mk SetTheory.PGame.mk_le_mk theorem le_of_forall_lf {x y : PGame} (h₁ : ∀ i, x.moveLeft i ⧏ y) (h₂ : ∀ j, x ⧏ y.moveRight j) : x ≤ y := le_iff_forall_lf.2 ⟨h₁, h₂⟩ #align pgame.le_of_forall_lf SetTheory.PGame.le_of_forall_lf /-- Definition of `x ⧏ y` on pre-games, in terms of `≤`. The ordering here is chosen so that `or.inl` refer to moves by Left, and `or.inr` refer to moves by Right. -/ theorem lf_iff_exists_le {x y : PGame} : x ⧏ y ↔ (∃ i, x ≤ y.moveLeft i) ∨ ∃ j, x.moveRight j ≤ y := by rw [LF, le_iff_forall_lf, not_and_or] simp #align pgame.lf_iff_exists_le SetTheory.PGame.lf_iff_exists_le /-- Definition of `x ⧏ y` on pre-games built using the constructor. -/ @[simp] theorem mk_lf_mk {xl xr xL xR yl yr yL yR} : mk xl xr xL xR ⧏ mk yl yr yL yR ↔ (∃ i, mk xl xr xL xR ≤ yL i) ∨ ∃ j, xR j ≤ mk yl yr yL yR := lf_iff_exists_le #align pgame.mk_lf_mk SetTheory.PGame.mk_lf_mk theorem le_or_gf (x y : PGame) : x ≤ y ∨ y ⧏ x := by rw [← PGame.not_le] apply em #align pgame.le_or_gf SetTheory.PGame.le_or_gf theorem moveLeft_lf_of_le {x y : PGame} (h : x ≤ y) (i) : x.moveLeft i ⧏ y := (le_iff_forall_lf.1 h).1 i #align pgame.move_left_lf_of_le SetTheory.PGame.moveLeft_lf_of_le alias _root_.LE.le.moveLeft_lf := moveLeft_lf_of_le #align has_le.le.move_left_lf LE.le.moveLeft_lf theorem lf_moveRight_of_le {x y : PGame} (h : x ≤ y) (j) : x ⧏ y.moveRight j := (le_iff_forall_lf.1 h).2 j #align pgame.lf_move_right_of_le SetTheory.PGame.lf_moveRight_of_le alias _root_.LE.le.lf_moveRight := lf_moveRight_of_le #align has_le.le.lf_move_right LE.le.lf_moveRight theorem lf_of_moveRight_le {x y : PGame} {j} (h : x.moveRight j ≤ y) : x ⧏ y := lf_iff_exists_le.2 <| Or.inr ⟨j, h⟩ #align pgame.lf_of_move_right_le SetTheory.PGame.lf_of_moveRight_le theorem lf_of_le_moveLeft {x y : PGame} {i} (h : x ≤ y.moveLeft i) : x ⧏ y := lf_iff_exists_le.2 <| Or.inl ⟨i, h⟩ #align pgame.lf_of_le_move_left SetTheory.PGame.lf_of_le_moveLeft theorem lf_of_le_mk {xl xr xL xR y} : mk xl xr xL xR ≤ y → ∀ i, xL i ⧏ y := moveLeft_lf_of_le #align pgame.lf_of_le_mk SetTheory.PGame.lf_of_le_mk theorem lf_of_mk_le {x yl yr yL yR} : x ≤ mk yl yr yL yR → ∀ j, x ⧏ yR j := lf_moveRight_of_le #align pgame.lf_of_mk_le SetTheory.PGame.lf_of_mk_le theorem mk_lf_of_le {xl xr y j} (xL) {xR : xr → PGame} : xR j ≤ y → mk xl xr xL xR ⧏ y := @lf_of_moveRight_le (mk _ _ _ _) y j #align pgame.mk_lf_of_le SetTheory.PGame.mk_lf_of_le theorem lf_mk_of_le {x yl yr} {yL : yl → PGame} (yR) {i} : x ≤ yL i → x ⧏ mk yl yr yL yR := @lf_of_le_moveLeft x (mk _ _ _ _) i #align pgame.lf_mk_of_le SetTheory.PGame.lf_mk_of_le /- We prove that `x ≤ y → y ≤ z → x ≤ z` inductively, by also simultaneously proving its cyclic reorderings. This auxiliary lemma is used during said induction. -/ private theorem le_trans_aux {x y z : PGame} (h₁ : ∀ {i}, y ≤ z → z ≤ x.moveLeft i → y ≤ x.moveLeft i) (h₂ : ∀ {j}, z.moveRight j ≤ x → x ≤ y → z.moveRight j ≤ y) (hxy : x ≤ y) (hyz : y ≤ z) : x ≤ z := le_of_forall_lf (fun i => PGame.not_le.1 fun h => (h₁ hyz h).not_gf <| hxy.moveLeft_lf i) fun j => PGame.not_le.1 fun h => (h₂ h hxy).not_gf <| hyz.lf_moveRight j instance : Preorder PGame := { PGame.le with le_refl := fun x => by induction' x with _ _ _ _ IHl IHr exact le_of_forall_lf (fun i => lf_of_le_moveLeft (IHl i)) fun i => lf_of_moveRight_le (IHr i) le_trans := by suffices ∀ {x y z : PGame}, (x ≤ y → y ≤ z → x ≤ z) ∧ (y ≤ z → z ≤ x → y ≤ x) ∧ (z ≤ x → x ≤ y → z ≤ y) from fun x y z => this.1 intro x y z induction' x with xl xr xL xR IHxl IHxr generalizing y z induction' y with yl yr yL yR IHyl IHyr generalizing z induction' z with zl zr zL zR IHzl IHzr exact ⟨le_trans_aux (fun {i} => (IHxl i).2.1) fun {j} => (IHzr j).2.2, le_trans_aux (fun {i} => (IHyl i).2.2) fun {j} => (IHxr j).1, le_trans_aux (fun {i} => (IHzl i).1) fun {j} => (IHyr j).2.1⟩ lt := fun x y => x ≤ y ∧ x ⧏ y } theorem lt_iff_le_and_lf {x y : PGame} : x < y ↔ x ≤ y ∧ x ⧏ y := Iff.rfl #align pgame.lt_iff_le_and_lf SetTheory.PGame.lt_iff_le_and_lf theorem lt_of_le_of_lf {x y : PGame} (h₁ : x ≤ y) (h₂ : x ⧏ y) : x < y := ⟨h₁, h₂⟩ #align pgame.lt_of_le_of_lf SetTheory.PGame.lt_of_le_of_lf theorem lf_of_lt {x y : PGame} (h : x < y) : x ⧏ y := h.2 #align pgame.lf_of_lt SetTheory.PGame.lf_of_lt alias _root_.LT.lt.lf := lf_of_lt #align has_lt.lt.lf LT.lt.lf theorem lf_irrefl (x : PGame) : ¬x ⧏ x := le_rfl.not_gf #align pgame.lf_irrefl SetTheory.PGame.lf_irrefl instance : IsIrrefl _ (· ⧏ ·) := ⟨lf_irrefl⟩ @[trans] theorem lf_of_le_of_lf {x y z : PGame} (h₁ : x ≤ y) (h₂ : y ⧏ z) : x ⧏ z := by rw [← PGame.not_le] at h₂ ⊢ exact fun h₃ => h₂ (h₃.trans h₁) #align pgame.lf_of_le_of_lf SetTheory.PGame.lf_of_le_of_lf -- Porting note (#10754): added instance instance : Trans (· ≤ ·) (· ⧏ ·) (· ⧏ ·) := ⟨lf_of_le_of_lf⟩ @[trans] theorem lf_of_lf_of_le {x y z : PGame} (h₁ : x ⧏ y) (h₂ : y ≤ z) : x ⧏ z := by rw [← PGame.not_le] at h₁ ⊢ exact fun h₃ => h₁ (h₂.trans h₃) #align pgame.lf_of_lf_of_le SetTheory.PGame.lf_of_lf_of_le -- Porting note (#10754): added instance instance : Trans (· ⧏ ·) (· ≤ ·) (· ⧏ ·) := ⟨lf_of_lf_of_le⟩ alias _root_.LE.le.trans_lf := lf_of_le_of_lf #align has_le.le.trans_lf LE.le.trans_lf alias LF.trans_le := lf_of_lf_of_le #align pgame.lf.trans_le SetTheory.PGame.LF.trans_le @[trans] theorem lf_of_lt_of_lf {x y z : PGame} (h₁ : x < y) (h₂ : y ⧏ z) : x ⧏ z := h₁.le.trans_lf h₂ #align pgame.lf_of_lt_of_lf SetTheory.PGame.lf_of_lt_of_lf @[trans] theorem lf_of_lf_of_lt {x y z : PGame} (h₁ : x ⧏ y) (h₂ : y < z) : x ⧏ z := h₁.trans_le h₂.le #align pgame.lf_of_lf_of_lt SetTheory.PGame.lf_of_lf_of_lt alias _root_.LT.lt.trans_lf := lf_of_lt_of_lf #align has_lt.lt.trans_lf LT.lt.trans_lf alias LF.trans_lt := lf_of_lf_of_lt #align pgame.lf.trans_lt SetTheory.PGame.LF.trans_lt theorem moveLeft_lf {x : PGame} : ∀ i, x.moveLeft i ⧏ x := le_rfl.moveLeft_lf #align pgame.move_left_lf SetTheory.PGame.moveLeft_lf theorem lf_moveRight {x : PGame} : ∀ j, x ⧏ x.moveRight j := le_rfl.lf_moveRight #align pgame.lf_move_right SetTheory.PGame.lf_moveRight theorem lf_mk {xl xr} (xL : xl → PGame) (xR : xr → PGame) (i) : xL i ⧏ mk xl xr xL xR := @moveLeft_lf (mk _ _ _ _) i #align pgame.lf_mk SetTheory.PGame.lf_mk theorem mk_lf {xl xr} (xL : xl → PGame) (xR : xr → PGame) (j) : mk xl xr xL xR ⧏ xR j := @lf_moveRight (mk _ _ _ _) j #align pgame.mk_lf SetTheory.PGame.mk_lf /-- This special case of `PGame.le_of_forall_lf` is useful when dealing with surreals, where `<` is preferred over `⧏`. -/ theorem le_of_forall_lt {x y : PGame} (h₁ : ∀ i, x.moveLeft i < y) (h₂ : ∀ j, x < y.moveRight j) : x ≤ y := le_of_forall_lf (fun i => (h₁ i).lf) fun i => (h₂ i).lf #align pgame.le_of_forall_lt SetTheory.PGame.le_of_forall_lt /-- The definition of `x ≤ y` on pre-games, in terms of `≤` two moves later. -/ theorem le_def {x y : PGame} : x ≤ y ↔ (∀ i, (∃ i', x.moveLeft i ≤ y.moveLeft i') ∨ ∃ j, (x.moveLeft i).moveRight j ≤ y) ∧ ∀ j, (∃ i, x ≤ (y.moveRight j).moveLeft i) ∨ ∃ j', x.moveRight j' ≤ y.moveRight j := by rw [le_iff_forall_lf] conv => lhs simp only [lf_iff_exists_le] #align pgame.le_def SetTheory.PGame.le_def /-- The definition of `x ⧏ y` on pre-games, in terms of `⧏` two moves later. -/ theorem lf_def {x y : PGame} : x ⧏ y ↔ (∃ i, (∀ i', x.moveLeft i' ⧏ y.moveLeft i) ∧ ∀ j, x ⧏ (y.moveLeft i).moveRight j) ∨ ∃ j, (∀ i, (x.moveRight j).moveLeft i ⧏ y) ∧ ∀ j', x.moveRight j ⧏ y.moveRight j' := by rw [lf_iff_exists_le] conv => lhs simp only [le_iff_forall_lf] #align pgame.lf_def SetTheory.PGame.lf_def /-- The definition of `0 ≤ x` on pre-games, in terms of `0 ⧏`. -/ theorem zero_le_lf {x : PGame} : 0 ≤ x ↔ ∀ j, 0 ⧏ x.moveRight j := by rw [le_iff_forall_lf] simp #align pgame.zero_le_lf SetTheory.PGame.zero_le_lf /-- The definition of `x ≤ 0` on pre-games, in terms of `⧏ 0`. -/ theorem le_zero_lf {x : PGame} : x ≤ 0 ↔ ∀ i, x.moveLeft i ⧏ 0 := by rw [le_iff_forall_lf] simp #align pgame.le_zero_lf SetTheory.PGame.le_zero_lf /-- The definition of `0 ⧏ x` on pre-games, in terms of `0 ≤`. -/ theorem zero_lf_le {x : PGame} : 0 ⧏ x ↔ ∃ i, 0 ≤ x.moveLeft i := by rw [lf_iff_exists_le] simp #align pgame.zero_lf_le SetTheory.PGame.zero_lf_le /-- The definition of `x ⧏ 0` on pre-games, in terms of `≤ 0`. -/ theorem lf_zero_le {x : PGame} : x ⧏ 0 ↔ ∃ j, x.moveRight j ≤ 0 := by rw [lf_iff_exists_le] simp #align pgame.lf_zero_le SetTheory.PGame.lf_zero_le /-- The definition of `0 ≤ x` on pre-games, in terms of `0 ≤` two moves later. -/ theorem zero_le {x : PGame} : 0 ≤ x ↔ ∀ j, ∃ i, 0 ≤ (x.moveRight j).moveLeft i := by rw [le_def] simp #align pgame.zero_le SetTheory.PGame.zero_le /-- The definition of `x ≤ 0` on pre-games, in terms of `≤ 0` two moves later. -/ theorem le_zero {x : PGame} : x ≤ 0 ↔ ∀ i, ∃ j, (x.moveLeft i).moveRight j ≤ 0 := by rw [le_def] simp #align pgame.le_zero SetTheory.PGame.le_zero /-- The definition of `0 ⧏ x` on pre-games, in terms of `0 ⧏` two moves later. -/ theorem zero_lf {x : PGame} : 0 ⧏ x ↔ ∃ i, ∀ j, 0 ⧏ (x.moveLeft i).moveRight j := by rw [lf_def] simp #align pgame.zero_lf SetTheory.PGame.zero_lf /-- The definition of `x ⧏ 0` on pre-games, in terms of `⧏ 0` two moves later. -/ theorem lf_zero {x : PGame} : x ⧏ 0 ↔ ∃ j, ∀ i, (x.moveRight j).moveLeft i ⧏ 0 := by rw [lf_def] simp #align pgame.lf_zero SetTheory.PGame.lf_zero @[simp] theorem zero_le_of_isEmpty_rightMoves (x : PGame) [IsEmpty x.RightMoves] : 0 ≤ x := zero_le.2 isEmptyElim #align pgame.zero_le_of_is_empty_right_moves SetTheory.PGame.zero_le_of_isEmpty_rightMoves @[simp] theorem le_zero_of_isEmpty_leftMoves (x : PGame) [IsEmpty x.LeftMoves] : x ≤ 0 := le_zero.2 isEmptyElim #align pgame.le_zero_of_is_empty_left_moves SetTheory.PGame.le_zero_of_isEmpty_leftMoves /-- Given a game won by the right player when they play second, provide a response to any move by left. -/ noncomputable def rightResponse {x : PGame} (h : x ≤ 0) (i : x.LeftMoves) : (x.moveLeft i).RightMoves := Classical.choose <| (le_zero.1 h) i #align pgame.right_response SetTheory.PGame.rightResponse /-- Show that the response for right provided by `rightResponse` preserves the right-player-wins condition. -/ theorem rightResponse_spec {x : PGame} (h : x ≤ 0) (i : x.LeftMoves) : (x.moveLeft i).moveRight (rightResponse h i) ≤ 0 := Classical.choose_spec <| (le_zero.1 h) i #align pgame.right_response_spec SetTheory.PGame.rightResponse_spec /-- Given a game won by the left player when they play second, provide a response to any move by right. -/ noncomputable def leftResponse {x : PGame} (h : 0 ≤ x) (j : x.RightMoves) : (x.moveRight j).LeftMoves := Classical.choose <| (zero_le.1 h) j #align pgame.left_response SetTheory.PGame.leftResponse /-- Show that the response for left provided by `leftResponse` preserves the left-player-wins condition. -/ theorem leftResponse_spec {x : PGame} (h : 0 ≤ x) (j : x.RightMoves) : 0 ≤ (x.moveRight j).moveLeft (leftResponse h j) := Classical.choose_spec <| (zero_le.1 h) j #align pgame.left_response_spec SetTheory.PGame.leftResponse_spec #noalign pgame.upper_bound #noalign pgame.upper_bound_right_moves_empty #noalign pgame.le_upper_bound #noalign pgame.upper_bound_mem_upper_bounds /-- A small family of pre-games is bounded above. -/ lemma bddAbove_range_of_small [Small.{u} ι] (f : ι → PGame.{u}) : BddAbove (Set.range f) := by let x : PGame.{u} := ⟨Σ i, (f $ (equivShrink.{u} ι).symm i).LeftMoves, PEmpty, fun x ↦ moveLeft _ x.2, PEmpty.elim⟩ refine ⟨x, Set.forall_mem_range.2 fun i ↦ ?_⟩ rw [← (equivShrink ι).symm_apply_apply i, le_iff_forall_lf] simpa [x] using fun j ↦ @moveLeft_lf x ⟨equivShrink ι i, j⟩ /-- A small set of pre-games is bounded above. -/ lemma bddAbove_of_small (s : Set PGame.{u}) [Small.{u} s] : BddAbove s := by simpa using bddAbove_range_of_small (Subtype.val : s → PGame.{u}) #align pgame.bdd_above_of_small SetTheory.PGame.bddAbove_of_small #noalign pgame.lower_bound #noalign pgame.lower_bound_left_moves_empty #noalign pgame.lower_bound_le #noalign pgame.lower_bound_mem_lower_bounds /-- A small family of pre-games is bounded below. -/ lemma bddBelow_range_of_small [Small.{u} ι] (f : ι → PGame.{u}) : BddBelow (Set.range f) := by let x : PGame.{u} := ⟨PEmpty, Σ i, (f $ (equivShrink.{u} ι).symm i).RightMoves, PEmpty.elim, fun x ↦ moveRight _ x.2⟩ refine ⟨x, Set.forall_mem_range.2 fun i ↦ ?_⟩ rw [← (equivShrink ι).symm_apply_apply i, le_iff_forall_lf] simpa [x] using fun j ↦ @lf_moveRight x ⟨equivShrink ι i, j⟩ /-- A small set of pre-games is bounded below. -/ lemma bddBelow_of_small (s : Set PGame.{u}) [Small.{u} s] : BddBelow s := by simpa using bddBelow_range_of_small (Subtype.val : s → PGame.{u}) #align pgame.bdd_below_of_small SetTheory.PGame.bddBelow_of_small /-- The equivalence relation on pre-games. Two pre-games `x`, `y` are equivalent if `x ≤ y` and `y ≤ x`. If `x ≈ 0`, then the second player can always win `x`. -/ def Equiv (x y : PGame) : Prop := x ≤ y ∧ y ≤ x #align pgame.equiv SetTheory.PGame.Equiv -- Porting note: deleted the scoped notation due to notation overloading with the setoid -- instance and this causes the PGame.equiv docstring to not show up on hover. instance : IsEquiv _ PGame.Equiv where refl _ := ⟨le_rfl, le_rfl⟩ trans := fun _ _ _ ⟨xy, yx⟩ ⟨yz, zy⟩ => ⟨xy.trans yz, zy.trans yx⟩ symm _ _ := And.symm -- Porting note: moved the setoid instance from Basic.lean to here instance setoid : Setoid PGame := ⟨Equiv, refl, symm, Trans.trans⟩ #align pgame.setoid SetTheory.PGame.setoid theorem Equiv.le {x y : PGame} (h : x ≈ y) : x ≤ y := h.1 #align pgame.equiv.le SetTheory.PGame.Equiv.le theorem Equiv.ge {x y : PGame} (h : x ≈ y) : y ≤ x := h.2 #align pgame.equiv.ge SetTheory.PGame.Equiv.ge @[refl, simp] theorem equiv_rfl {x : PGame} : x ≈ x := refl x #align pgame.equiv_rfl SetTheory.PGame.equiv_rfl theorem equiv_refl (x : PGame) : x ≈ x := refl x #align pgame.equiv_refl SetTheory.PGame.equiv_refl @[symm] protected theorem Equiv.symm {x y : PGame} : (x ≈ y) → (y ≈ x) := symm #align pgame.equiv.symm SetTheory.PGame.Equiv.symm @[trans] protected theorem Equiv.trans {x y z : PGame} : (x ≈ y) → (y ≈ z) → (x ≈ z) := _root_.trans #align pgame.equiv.trans SetTheory.PGame.Equiv.trans protected theorem equiv_comm {x y : PGame} : (x ≈ y) ↔ (y ≈ x) := comm #align pgame.equiv_comm SetTheory.PGame.equiv_comm theorem equiv_of_eq {x y : PGame} (h : x = y) : x ≈ y := by subst h; rfl #align pgame.equiv_of_eq SetTheory.PGame.equiv_of_eq @[trans] theorem le_of_le_of_equiv {x y z : PGame} (h₁ : x ≤ y) (h₂ : y ≈ z) : x ≤ z := h₁.trans h₂.1 #align pgame.le_of_le_of_equiv SetTheory.PGame.le_of_le_of_equiv instance : Trans ((· ≤ ·) : PGame → PGame → Prop) ((· ≈ ·) : PGame → PGame → Prop) ((· ≤ ·) : PGame → PGame → Prop) where trans := le_of_le_of_equiv @[trans] theorem le_of_equiv_of_le {x y z : PGame} (h₁ : x ≈ y) : y ≤ z → x ≤ z := h₁.1.trans #align pgame.le_of_equiv_of_le SetTheory.PGame.le_of_equiv_of_le instance : Trans ((· ≈ ·) : PGame → PGame → Prop) ((· ≤ ·) : PGame → PGame → Prop) ((· ≤ ·) : PGame → PGame → Prop) where trans := le_of_equiv_of_le theorem LF.not_equiv {x y : PGame} (h : x ⧏ y) : ¬(x ≈ y) := fun h' => h.not_ge h'.2 #align pgame.lf.not_equiv SetTheory.PGame.LF.not_equiv theorem LF.not_equiv' {x y : PGame} (h : x ⧏ y) : ¬(y ≈ x) := fun h' => h.not_ge h'.1 #align pgame.lf.not_equiv' SetTheory.PGame.LF.not_equiv' theorem LF.not_gt {x y : PGame} (h : x ⧏ y) : ¬y < x := fun h' => h.not_ge h'.le #align pgame.lf.not_gt SetTheory.PGame.LF.not_gt theorem le_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) (h : x₁ ≤ y₁) : x₂ ≤ y₂ := hx.2.trans (h.trans hy.1) #align pgame.le_congr_imp SetTheory.PGame.le_congr_imp theorem le_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ≤ y₁ ↔ x₂ ≤ y₂ := ⟨le_congr_imp hx hy, le_congr_imp (Equiv.symm hx) (Equiv.symm hy)⟩ #align pgame.le_congr SetTheory.PGame.le_congr theorem le_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ ≤ y ↔ x₂ ≤ y := le_congr hx equiv_rfl #align pgame.le_congr_left SetTheory.PGame.le_congr_left theorem le_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x ≤ y₁ ↔ x ≤ y₂ := le_congr equiv_rfl hy #align pgame.le_congr_right SetTheory.PGame.le_congr_right theorem lf_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ⧏ y₁ ↔ x₂ ⧏ y₂ := PGame.not_le.symm.trans <| (not_congr (le_congr hy hx)).trans PGame.not_le #align pgame.lf_congr SetTheory.PGame.lf_congr theorem lf_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ⧏ y₁ → x₂ ⧏ y₂ := (lf_congr hx hy).1 #align pgame.lf_congr_imp SetTheory.PGame.lf_congr_imp theorem lf_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ ⧏ y ↔ x₂ ⧏ y := lf_congr hx equiv_rfl #align pgame.lf_congr_left SetTheory.PGame.lf_congr_left theorem lf_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x ⧏ y₁ ↔ x ⧏ y₂ := lf_congr equiv_rfl hy #align pgame.lf_congr_right SetTheory.PGame.lf_congr_right @[trans] theorem lf_of_lf_of_equiv {x y z : PGame} (h₁ : x ⧏ y) (h₂ : y ≈ z) : x ⧏ z := lf_congr_imp equiv_rfl h₂ h₁ #align pgame.lf_of_lf_of_equiv SetTheory.PGame.lf_of_lf_of_equiv @[trans] theorem lf_of_equiv_of_lf {x y z : PGame} (h₁ : x ≈ y) : y ⧏ z → x ⧏ z := lf_congr_imp (Equiv.symm h₁) equiv_rfl #align pgame.lf_of_equiv_of_lf SetTheory.PGame.lf_of_equiv_of_lf @[trans] theorem lt_of_lt_of_equiv {x y z : PGame} (h₁ : x < y) (h₂ : y ≈ z) : x < z := h₁.trans_le h₂.1 #align pgame.lt_of_lt_of_equiv SetTheory.PGame.lt_of_lt_of_equiv @[trans] theorem lt_of_equiv_of_lt {x y z : PGame} (h₁ : x ≈ y) : y < z → x < z := h₁.1.trans_lt #align pgame.lt_of_equiv_of_lt SetTheory.PGame.lt_of_equiv_of_lt instance : Trans ((· ≈ ·) : PGame → PGame → Prop) ((· < ·) : PGame → PGame → Prop) ((· < ·) : PGame → PGame → Prop) where trans := lt_of_equiv_of_lt theorem lt_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) (h : x₁ < y₁) : x₂ < y₂ := hx.2.trans_lt (h.trans_le hy.1) #align pgame.lt_congr_imp SetTheory.PGame.lt_congr_imp theorem lt_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ < y₁ ↔ x₂ < y₂ := ⟨lt_congr_imp hx hy, lt_congr_imp (Equiv.symm hx) (Equiv.symm hy)⟩ #align pgame.lt_congr SetTheory.PGame.lt_congr theorem lt_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ < y ↔ x₂ < y := lt_congr hx equiv_rfl #align pgame.lt_congr_left SetTheory.PGame.lt_congr_left theorem lt_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x < y₁ ↔ x < y₂ := lt_congr equiv_rfl hy #align pgame.lt_congr_right SetTheory.PGame.lt_congr_right theorem lt_or_equiv_of_le {x y : PGame} (h : x ≤ y) : x < y ∨ (x ≈ y) := and_or_left.mp ⟨h, (em <| y ≤ x).symm.imp_left PGame.not_le.1⟩ #align pgame.lt_or_equiv_of_le SetTheory.PGame.lt_or_equiv_of_le theorem lf_or_equiv_or_gf (x y : PGame) : x ⧏ y ∨ (x ≈ y) ∨ y ⧏ x := by by_cases h : x ⧏ y · exact Or.inl h · right cases' lt_or_equiv_of_le (PGame.not_lf.1 h) with h' h' · exact Or.inr h'.lf · exact Or.inl (Equiv.symm h') #align pgame.lf_or_equiv_or_gf SetTheory.PGame.lf_or_equiv_or_gf theorem equiv_congr_left {y₁ y₂ : PGame} : (y₁ ≈ y₂) ↔ ∀ x₁, (x₁ ≈ y₁) ↔ (x₁ ≈ y₂) := ⟨fun h _ => ⟨fun h' => Equiv.trans h' h, fun h' => Equiv.trans h' (Equiv.symm h)⟩, fun h => (h y₁).1 <| equiv_rfl⟩ #align pgame.equiv_congr_left SetTheory.PGame.equiv_congr_left theorem equiv_congr_right {x₁ x₂ : PGame} : (x₁ ≈ x₂) ↔ ∀ y₁, (x₁ ≈ y₁) ↔ (x₂ ≈ y₁) := ⟨fun h _ => ⟨fun h' => Equiv.trans (Equiv.symm h) h', fun h' => Equiv.trans h h'⟩, fun h => (h x₂).2 <| equiv_rfl⟩ #align pgame.equiv_congr_right SetTheory.PGame.equiv_congr_right theorem equiv_of_mk_equiv {x y : PGame} (L : x.LeftMoves ≃ y.LeftMoves) (R : x.RightMoves ≃ y.RightMoves) (hl : ∀ i, x.moveLeft i ≈ y.moveLeft (L i)) (hr : ∀ j, x.moveRight j ≈ y.moveRight (R j)) : x ≈ y := by constructor <;> rw [le_def] · exact ⟨fun i => Or.inl ⟨_, (hl i).1⟩, fun j => Or.inr ⟨_, by simpa using (hr (R.symm j)).1⟩⟩ · exact ⟨fun i => Or.inl ⟨_, by simpa using (hl (L.symm i)).2⟩, fun j => Or.inr ⟨_, (hr j).2⟩⟩ #align pgame.equiv_of_mk_equiv SetTheory.PGame.equiv_of_mk_equiv /-- The fuzzy, confused, or incomparable relation on pre-games. If `x ‖ 0`, then the first player can always win `x`. -/ def Fuzzy (x y : PGame) : Prop := x ⧏ y ∧ y ⧏ x #align pgame.fuzzy SetTheory.PGame.Fuzzy @[inherit_doc] scoped infixl:50 " ‖ " => PGame.Fuzzy @[symm] theorem Fuzzy.swap {x y : PGame} : x ‖ y → y ‖ x := And.symm #align pgame.fuzzy.swap SetTheory.PGame.Fuzzy.swap instance : IsSymm _ (· ‖ ·) := ⟨fun _ _ => Fuzzy.swap⟩ theorem Fuzzy.swap_iff {x y : PGame} : x ‖ y ↔ y ‖ x := ⟨Fuzzy.swap, Fuzzy.swap⟩ #align pgame.fuzzy.swap_iff SetTheory.PGame.Fuzzy.swap_iff theorem fuzzy_irrefl (x : PGame) : ¬x ‖ x := fun h => lf_irrefl x h.1 #align pgame.fuzzy_irrefl SetTheory.PGame.fuzzy_irrefl instance : IsIrrefl _ (· ‖ ·) := ⟨fuzzy_irrefl⟩ theorem lf_iff_lt_or_fuzzy {x y : PGame} : x ⧏ y ↔ x < y ∨ x ‖ y := by simp only [lt_iff_le_and_lf, Fuzzy, ← PGame.not_le] tauto #align pgame.lf_iff_lt_or_fuzzy SetTheory.PGame.lf_iff_lt_or_fuzzy theorem lf_of_fuzzy {x y : PGame} (h : x ‖ y) : x ⧏ y := lf_iff_lt_or_fuzzy.2 (Or.inr h) #align pgame.lf_of_fuzzy SetTheory.PGame.lf_of_fuzzy alias Fuzzy.lf := lf_of_fuzzy #align pgame.fuzzy.lf SetTheory.PGame.Fuzzy.lf theorem lt_or_fuzzy_of_lf {x y : PGame} : x ⧏ y → x < y ∨ x ‖ y := lf_iff_lt_or_fuzzy.1 #align pgame.lt_or_fuzzy_of_lf SetTheory.PGame.lt_or_fuzzy_of_lf theorem Fuzzy.not_equiv {x y : PGame} (h : x ‖ y) : ¬(x ≈ y) := fun h' => h'.1.not_gf h.2 #align pgame.fuzzy.not_equiv SetTheory.PGame.Fuzzy.not_equiv theorem Fuzzy.not_equiv' {x y : PGame} (h : x ‖ y) : ¬(y ≈ x) := fun h' => h'.2.not_gf h.2 #align pgame.fuzzy.not_equiv' SetTheory.PGame.Fuzzy.not_equiv' theorem not_fuzzy_of_le {x y : PGame} (h : x ≤ y) : ¬x ‖ y := fun h' => h'.2.not_ge h #align pgame.not_fuzzy_of_le SetTheory.PGame.not_fuzzy_of_le theorem not_fuzzy_of_ge {x y : PGame} (h : y ≤ x) : ¬x ‖ y := fun h' => h'.1.not_ge h #align pgame.not_fuzzy_of_ge SetTheory.PGame.not_fuzzy_of_ge theorem Equiv.not_fuzzy {x y : PGame} (h : x ≈ y) : ¬x ‖ y := not_fuzzy_of_le h.1 #align pgame.equiv.not_fuzzy SetTheory.PGame.Equiv.not_fuzzy theorem Equiv.not_fuzzy' {x y : PGame} (h : x ≈ y) : ¬y ‖ x := not_fuzzy_of_le h.2 #align pgame.equiv.not_fuzzy' SetTheory.PGame.Equiv.not_fuzzy' theorem fuzzy_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ‖ y₁ ↔ x₂ ‖ y₂ := show _ ∧ _ ↔ _ ∧ _ by rw [lf_congr hx hy, lf_congr hy hx] #align pgame.fuzzy_congr SetTheory.PGame.fuzzy_congr theorem fuzzy_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ‖ y₁ → x₂ ‖ y₂ := (fuzzy_congr hx hy).1 #align pgame.fuzzy_congr_imp SetTheory.PGame.fuzzy_congr_imp theorem fuzzy_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ ‖ y ↔ x₂ ‖ y := fuzzy_congr hx equiv_rfl #align pgame.fuzzy_congr_left SetTheory.PGame.fuzzy_congr_left theorem fuzzy_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x ‖ y₁ ↔ x ‖ y₂ := fuzzy_congr equiv_rfl hy #align pgame.fuzzy_congr_right SetTheory.PGame.fuzzy_congr_right @[trans] theorem fuzzy_of_fuzzy_of_equiv {x y z : PGame} (h₁ : x ‖ y) (h₂ : y ≈ z) : x ‖ z := (fuzzy_congr_right h₂).1 h₁ #align pgame.fuzzy_of_fuzzy_of_equiv SetTheory.PGame.fuzzy_of_fuzzy_of_equiv @[trans] theorem fuzzy_of_equiv_of_fuzzy {x y z : PGame} (h₁ : x ≈ y) (h₂ : y ‖ z) : x ‖ z := (fuzzy_congr_left h₁).2 h₂ #align pgame.fuzzy_of_equiv_of_fuzzy SetTheory.PGame.fuzzy_of_equiv_of_fuzzy /-- Exactly one of the following is true (although we don't prove this here). -/ theorem lt_or_equiv_or_gt_or_fuzzy (x y : PGame) : x < y ∨ (x ≈ y) ∨ y < x ∨ x ‖ y := by cases' le_or_gf x y with h₁ h₁ <;> cases' le_or_gf y x with h₂ h₂ · right left exact ⟨h₁, h₂⟩ · left exact ⟨h₁, h₂⟩ · right right left exact ⟨h₂, h₁⟩ · right right right exact ⟨h₂, h₁⟩ #align pgame.lt_or_equiv_or_gt_or_fuzzy SetTheory.PGame.lt_or_equiv_or_gt_or_fuzzy theorem lt_or_equiv_or_gf (x y : PGame) : x < y ∨ (x ≈ y) ∨ y ⧏ x := by rw [lf_iff_lt_or_fuzzy, Fuzzy.swap_iff] exact lt_or_equiv_or_gt_or_fuzzy x y #align pgame.lt_or_equiv_or_gf SetTheory.PGame.lt_or_equiv_or_gf /-! ### Relabellings -/ /-- `Relabelling x y` says that `x` and `y` are really the same game, just dressed up differently. Specifically, there is a bijection between the moves for Left in `x` and in `y`, and similarly for Right, and under these bijections we inductively have `Relabelling`s for the consequent games. -/ inductive Relabelling : PGame.{u} → PGame.{u} → Type (u + 1) | mk : ∀ {x y : PGame} (L : x.LeftMoves ≃ y.LeftMoves) (R : x.RightMoves ≃ y.RightMoves), (∀ i, Relabelling (x.moveLeft i) (y.moveLeft (L i))) → (∀ j, Relabelling (x.moveRight j) (y.moveRight (R j))) → Relabelling x y #align pgame.relabelling SetTheory.PGame.Relabelling @[inherit_doc] scoped infixl:50 " ≡r " => PGame.Relabelling namespace Relabelling variable {x y : PGame.{u}} /-- A constructor for relabellings swapping the equivalences. -/ def mk' (L : y.LeftMoves ≃ x.LeftMoves) (R : y.RightMoves ≃ x.RightMoves) (hL : ∀ i, x.moveLeft (L i) ≡r y.moveLeft i) (hR : ∀ j, x.moveRight (R j) ≡r y.moveRight j) : x ≡r y := ⟨L.symm, R.symm, fun i => by simpa using hL (L.symm i), fun j => by simpa using hR (R.symm j)⟩ #align pgame.relabelling.mk' SetTheory.PGame.Relabelling.mk' /-- The equivalence between left moves of `x` and `y` given by the relabelling. -/ def leftMovesEquiv : x ≡r y → x.LeftMoves ≃ y.LeftMoves | ⟨L,_, _,_⟩ => L #align pgame.relabelling.left_moves_equiv SetTheory.PGame.Relabelling.leftMovesEquiv @[simp] theorem mk_leftMovesEquiv {x y L R hL hR} : (@Relabelling.mk x y L R hL hR).leftMovesEquiv = L := rfl #align pgame.relabelling.mk_left_moves_equiv SetTheory.PGame.Relabelling.mk_leftMovesEquiv @[simp] theorem mk'_leftMovesEquiv {x y L R hL hR} : (@Relabelling.mk' x y L R hL hR).leftMovesEquiv = L.symm := rfl #align pgame.relabelling.mk'_left_moves_equiv SetTheory.PGame.Relabelling.mk'_leftMovesEquiv /-- The equivalence between right moves of `x` and `y` given by the relabelling. -/ def rightMovesEquiv : x ≡r y → x.RightMoves ≃ y.RightMoves | ⟨_, R, _, _⟩ => R #align pgame.relabelling.right_moves_equiv SetTheory.PGame.Relabelling.rightMovesEquiv @[simp] theorem mk_rightMovesEquiv {x y L R hL hR} : (@Relabelling.mk x y L R hL hR).rightMovesEquiv = R := rfl #align pgame.relabelling.mk_right_moves_equiv SetTheory.PGame.Relabelling.mk_rightMovesEquiv @[simp] theorem mk'_rightMovesEquiv {x y L R hL hR} : (@Relabelling.mk' x y L R hL hR).rightMovesEquiv = R.symm := rfl #align pgame.relabelling.mk'_right_moves_equiv SetTheory.PGame.Relabelling.mk'_rightMovesEquiv /-- A left move of `x` is a relabelling of a left move of `y`. -/ def moveLeft : ∀ (r : x ≡r y) (i : x.LeftMoves), x.moveLeft i ≡r y.moveLeft (r.leftMovesEquiv i) | ⟨_, _, hL, _⟩ => hL #align pgame.relabelling.move_left SetTheory.PGame.Relabelling.moveLeft /-- A left move of `y` is a relabelling of a left move of `x`. -/ def moveLeftSymm : ∀ (r : x ≡r y) (i : y.LeftMoves), x.moveLeft (r.leftMovesEquiv.symm i) ≡r y.moveLeft i | ⟨L, R, hL, hR⟩, i => by simpa using hL (L.symm i) #align pgame.relabelling.move_left_symm SetTheory.PGame.Relabelling.moveLeftSymm /-- A right move of `x` is a relabelling of a right move of `y`. -/ def moveRight : ∀ (r : x ≡r y) (i : x.RightMoves), x.moveRight i ≡r y.moveRight (r.rightMovesEquiv i) | ⟨_, _, _, hR⟩ => hR #align pgame.relabelling.move_right SetTheory.PGame.Relabelling.moveRight /-- A right move of `y` is a relabelling of a right move of `x`. -/ def moveRightSymm : ∀ (r : x ≡r y) (i : y.RightMoves), x.moveRight (r.rightMovesEquiv.symm i) ≡r y.moveRight i | ⟨L, R, hL, hR⟩, i => by simpa using hR (R.symm i) #align pgame.relabelling.move_right_symm SetTheory.PGame.Relabelling.moveRightSymm /-- The identity relabelling. -/ @[refl] def refl (x : PGame) : x ≡r x := ⟨Equiv.refl _, Equiv.refl _, fun i => refl _, fun j => refl _⟩ termination_by x #align pgame.relabelling.refl SetTheory.PGame.Relabelling.refl instance (x : PGame) : Inhabited (x ≡r x) := ⟨refl _⟩ /-- Flip a relabelling. -/ @[symm] def symm : ∀ {x y : PGame}, x ≡r y → y ≡r x | _, _, ⟨L, R, hL, hR⟩ => mk' L R (fun i => (hL i).symm) fun j => (hR j).symm #align pgame.relabelling.symm SetTheory.PGame.Relabelling.symm theorem le {x y : PGame} (r : x ≡r y) : x ≤ y := le_def.2 ⟨fun i => Or.inl ⟨_, (r.moveLeft i).le⟩, fun j => Or.inr ⟨_, (r.moveRightSymm j).le⟩⟩ termination_by x #align pgame.relabelling.le SetTheory.PGame.Relabelling.le theorem ge {x y : PGame} (r : x ≡r y) : y ≤ x := r.symm.le #align pgame.relabelling.ge SetTheory.PGame.Relabelling.ge /-- A relabelling lets us prove equivalence of games. -/ theorem equiv (r : x ≡r y) : x ≈ y := ⟨r.le, r.ge⟩ #align pgame.relabelling.equiv SetTheory.PGame.Relabelling.equiv /-- Transitivity of relabelling. -/ @[trans] def trans : ∀ {x y z : PGame}, x ≡r y → y ≡r z → x ≡r z | _, _, _, ⟨L₁, R₁, hL₁, hR₁⟩, ⟨L₂, R₂, hL₂, hR₂⟩ => ⟨L₁.trans L₂, R₁.trans R₂, fun i => (hL₁ i).trans (hL₂ _), fun j => (hR₁ j).trans (hR₂ _)⟩ #align pgame.relabelling.trans SetTheory.PGame.Relabelling.trans /-- Any game without left or right moves is a relabelling of 0. -/ def isEmpty (x : PGame) [IsEmpty x.LeftMoves] [IsEmpty x.RightMoves] : x ≡r 0 := ⟨Equiv.equivPEmpty _, Equiv.equivOfIsEmpty _ _, isEmptyElim, isEmptyElim⟩ #align pgame.relabelling.is_empty SetTheory.PGame.Relabelling.isEmpty end Relabelling theorem Equiv.isEmpty (x : PGame) [IsEmpty x.LeftMoves] [IsEmpty x.RightMoves] : x ≈ 0 := (Relabelling.isEmpty x).equiv #align pgame.equiv.is_empty SetTheory.PGame.Equiv.isEmpty instance {x y : PGame} : Coe (x ≡r y) (x ≈ y) := ⟨Relabelling.equiv⟩ /-- Replace the types indexing the next moves for Left and Right by equivalent types. -/ def relabel {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) : PGame := ⟨xl', xr', x.moveLeft ∘ el, x.moveRight ∘ er⟩ #align pgame.relabel SetTheory.PGame.relabel @[simp] theorem relabel_moveLeft' {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) (i : xl') : moveLeft (relabel el er) i = x.moveLeft (el i) := rfl #align pgame.relabel_move_left' SetTheory.PGame.relabel_moveLeft' theorem relabel_moveLeft {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) (i : x.LeftMoves) : moveLeft (relabel el er) (el.symm i) = x.moveLeft i := by simp #align pgame.relabel_move_left SetTheory.PGame.relabel_moveLeft @[simp] theorem relabel_moveRight' {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) (j : xr') : moveRight (relabel el er) j = x.moveRight (er j) := rfl #align pgame.relabel_move_right' SetTheory.PGame.relabel_moveRight' theorem relabel_moveRight {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) (j : x.RightMoves) : moveRight (relabel el er) (er.symm j) = x.moveRight j := by simp #align pgame.relabel_move_right SetTheory.PGame.relabel_moveRight /-- The game obtained by relabelling the next moves is a relabelling of the original game. -/ def relabelRelabelling {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) : x ≡r relabel el er := -- Porting note: needed to add `rfl` Relabelling.mk' el er (fun i => by simp; rfl) (fun j => by simp; rfl) #align pgame.relabel_relabelling SetTheory.PGame.relabelRelabelling /-! ### Negation -/ /-- The negation of `{L | R}` is `{-R | -L}`. -/ def neg : PGame → PGame | ⟨l, r, L, R⟩ => ⟨r, l, fun i => neg (R i), fun i => neg (L i)⟩ #align pgame.neg SetTheory.PGame.neg instance : Neg PGame := ⟨neg⟩ @[simp] theorem neg_def {xl xr xL xR} : -mk xl xr xL xR = mk xr xl (fun j => -xR j) fun i => -xL i := rfl #align pgame.neg_def SetTheory.PGame.neg_def instance : InvolutiveNeg PGame := { inferInstanceAs (Neg PGame) with neg_neg := fun x => by induction' x with xl xr xL xR ihL ihR simp_rw [neg_def, ihL, ihR] } instance : NegZeroClass PGame := { inferInstanceAs (Zero PGame), inferInstanceAs (Neg PGame) with neg_zero := by dsimp [Zero.zero, Neg.neg, neg] congr <;> funext i <;> cases i } @[simp] theorem neg_ofLists (L R : List PGame) : -ofLists L R = ofLists (R.map fun x => -x) (L.map fun x => -x) := by simp only [ofLists, neg_def, List.get_map, mk.injEq, List.length_map, true_and] constructor all_goals apply hfunext · simp · rintro ⟨⟨a, ha⟩⟩ ⟨⟨b, hb⟩⟩ h have : ∀ {m n} (_ : m = n) {b : ULift (Fin m)} {c : ULift (Fin n)} (_ : HEq b c), (b.down : ℕ) = ↑c.down := by rintro m n rfl b c simp only [heq_eq_eq] rintro rfl rfl congr 5 exact this (List.length_map _ _).symm h #align pgame.neg_of_lists SetTheory.PGame.neg_ofLists theorem isOption_neg {x y : PGame} : IsOption x (-y) ↔ IsOption (-x) y := by rw [isOption_iff, isOption_iff, or_comm] cases y; apply or_congr <;> · apply exists_congr intro rw [neg_eq_iff_eq_neg] rfl #align pgame.is_option_neg SetTheory.PGame.isOption_neg @[simp] theorem isOption_neg_neg {x y : PGame} : IsOption (-x) (-y) ↔ IsOption x y := by rw [isOption_neg, neg_neg] #align pgame.is_option_neg_neg SetTheory.PGame.isOption_neg_neg theorem leftMoves_neg : ∀ x : PGame, (-x).LeftMoves = x.RightMoves | ⟨_, _, _, _⟩ => rfl #align pgame.left_moves_neg SetTheory.PGame.leftMoves_neg theorem rightMoves_neg : ∀ x : PGame, (-x).RightMoves = x.LeftMoves | ⟨_, _, _, _⟩ => rfl #align pgame.right_moves_neg SetTheory.PGame.rightMoves_neg /-- Turns a right move for `x` into a left move for `-x` and vice versa. Even though these types are the same (not definitionally so), this is the preferred way to convert between them. -/ def toLeftMovesNeg {x : PGame} : x.RightMoves ≃ (-x).LeftMoves := Equiv.cast (leftMoves_neg x).symm #align pgame.to_left_moves_neg SetTheory.PGame.toLeftMovesNeg /-- Turns a left move for `x` into a right move for `-x` and vice versa. Even though these types are the same (not definitionally so), this is the preferred way to convert between them. -/ def toRightMovesNeg {x : PGame} : x.LeftMoves ≃ (-x).RightMoves := Equiv.cast (rightMoves_neg x).symm #align pgame.to_right_moves_neg SetTheory.PGame.toRightMovesNeg theorem moveLeft_neg {x : PGame} (i) : (-x).moveLeft (toLeftMovesNeg i) = -x.moveRight i := by cases x rfl #align pgame.move_left_neg SetTheory.PGame.moveLeft_neg @[simp] theorem moveLeft_neg' {x : PGame} (i) : (-x).moveLeft i = -x.moveRight (toLeftMovesNeg.symm i) := by cases x rfl #align pgame.move_left_neg' SetTheory.PGame.moveLeft_neg' theorem moveRight_neg {x : PGame} (i) : (-x).moveRight (toRightMovesNeg i) = -x.moveLeft i := by cases x rfl #align pgame.move_right_neg SetTheory.PGame.moveRight_neg @[simp] theorem moveRight_neg' {x : PGame} (i) : (-x).moveRight i = -x.moveLeft (toRightMovesNeg.symm i) := by cases x rfl #align pgame.move_right_neg' SetTheory.PGame.moveRight_neg' theorem moveLeft_neg_symm {x : PGame} (i) : x.moveLeft (toRightMovesNeg.symm i) = -(-x).moveRight i := by simp #align pgame.move_left_neg_symm SetTheory.PGame.moveLeft_neg_symm theorem moveLeft_neg_symm' {x : PGame} (i) : x.moveLeft i = -(-x).moveRight (toRightMovesNeg i) := by simp #align pgame.move_left_neg_symm' SetTheory.PGame.moveLeft_neg_symm' theorem moveRight_neg_symm {x : PGame} (i) : x.moveRight (toLeftMovesNeg.symm i) = -(-x).moveLeft i := by simp #align pgame.move_right_neg_symm SetTheory.PGame.moveRight_neg_symm theorem moveRight_neg_symm' {x : PGame} (i) : x.moveRight i = -(-x).moveLeft (toLeftMovesNeg i) := by simp #align pgame.move_right_neg_symm' SetTheory.PGame.moveRight_neg_symm' /-- If `x` has the same moves as `y`, then `-x` has the same moves as `-y`. -/ def Relabelling.negCongr : ∀ {x y : PGame}, x ≡r y → -x ≡r -y | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, ⟨L, R, hL, hR⟩ => ⟨R, L, fun j => (hR j).negCongr, fun i => (hL i).negCongr⟩ #align pgame.relabelling.neg_congr SetTheory.PGame.Relabelling.negCongr private theorem neg_le_lf_neg_iff : ∀ {x y : PGame.{u}}, (-y ≤ -x ↔ x ≤ y) ∧ (-y ⧏ -x ↔ x ⧏ y) | mk xl xr xL xR, mk yl yr yL yR => by simp_rw [neg_def, mk_le_mk, mk_lf_mk, ← neg_def] constructor · rw [and_comm] apply and_congr <;> exact forall_congr' fun _ => neg_le_lf_neg_iff.2 · rw [or_comm] apply or_congr <;> exact exists_congr fun _ => neg_le_lf_neg_iff.1 termination_by x y => (x, y) @[simp] theorem neg_le_neg_iff {x y : PGame} : -y ≤ -x ↔ x ≤ y := neg_le_lf_neg_iff.1 #align pgame.neg_le_neg_iff SetTheory.PGame.neg_le_neg_iff @[simp] theorem neg_lf_neg_iff {x y : PGame} : -y ⧏ -x ↔ x ⧏ y := neg_le_lf_neg_iff.2 #align pgame.neg_lf_neg_iff SetTheory.PGame.neg_lf_neg_iff @[simp] theorem neg_lt_neg_iff {x y : PGame} : -y < -x ↔ x < y := by rw [lt_iff_le_and_lf, lt_iff_le_and_lf, neg_le_neg_iff, neg_lf_neg_iff] #align pgame.neg_lt_neg_iff SetTheory.PGame.neg_lt_neg_iff @[simp] theorem neg_equiv_neg_iff {x y : PGame} : (-x ≈ -y) ↔ (x ≈ y) := by show Equiv (-x) (-y) ↔ Equiv x y rw [Equiv, Equiv, neg_le_neg_iff, neg_le_neg_iff, and_comm] #align pgame.neg_equiv_neg_iff SetTheory.PGame.neg_equiv_neg_iff @[simp] theorem neg_fuzzy_neg_iff {x y : PGame} : -x ‖ -y ↔ x ‖ y := by rw [Fuzzy, Fuzzy, neg_lf_neg_iff, neg_lf_neg_iff, and_comm] #align pgame.neg_fuzzy_neg_iff SetTheory.PGame.neg_fuzzy_neg_iff theorem neg_le_iff {x y : PGame} : -y ≤ x ↔ -x ≤ y := by rw [← neg_neg x, neg_le_neg_iff, neg_neg] #align pgame.neg_le_iff SetTheory.PGame.neg_le_iff theorem neg_lf_iff {x y : PGame} : -y ⧏ x ↔ -x ⧏ y := by rw [← neg_neg x, neg_lf_neg_iff, neg_neg] #align pgame.neg_lf_iff SetTheory.PGame.neg_lf_iff theorem neg_lt_iff {x y : PGame} : -y < x ↔ -x < y := by rw [← neg_neg x, neg_lt_neg_iff, neg_neg] #align pgame.neg_lt_iff SetTheory.PGame.neg_lt_iff theorem neg_equiv_iff {x y : PGame} : (-x ≈ y) ↔ (x ≈ -y) := by rw [← neg_neg y, neg_equiv_neg_iff, neg_neg] #align pgame.neg_equiv_iff SetTheory.PGame.neg_equiv_iff theorem neg_fuzzy_iff {x y : PGame} : -x ‖ y ↔ x ‖ -y := by rw [← neg_neg y, neg_fuzzy_neg_iff, neg_neg] #align pgame.neg_fuzzy_iff SetTheory.PGame.neg_fuzzy_iff theorem le_neg_iff {x y : PGame} : y ≤ -x ↔ x ≤ -y := by rw [← neg_neg x, neg_le_neg_iff, neg_neg] #align pgame.le_neg_iff SetTheory.PGame.le_neg_iff theorem lf_neg_iff {x y : PGame} : y ⧏ -x ↔ x ⧏ -y := by rw [← neg_neg x, neg_lf_neg_iff, neg_neg] #align pgame.lf_neg_iff SetTheory.PGame.lf_neg_iff theorem lt_neg_iff {x y : PGame} : y < -x ↔ x < -y := by rw [← neg_neg x, neg_lt_neg_iff, neg_neg] #align pgame.lt_neg_iff SetTheory.PGame.lt_neg_iff @[simp] theorem neg_le_zero_iff {x : PGame} : -x ≤ 0 ↔ 0 ≤ x := by rw [neg_le_iff, neg_zero] #align pgame.neg_le_zero_iff SetTheory.PGame.neg_le_zero_iff @[simp] theorem zero_le_neg_iff {x : PGame} : 0 ≤ -x ↔ x ≤ 0 := by rw [le_neg_iff, neg_zero] #align pgame.zero_le_neg_iff SetTheory.PGame.zero_le_neg_iff @[simp] theorem neg_lf_zero_iff {x : PGame} : -x ⧏ 0 ↔ 0 ⧏ x := by rw [neg_lf_iff, neg_zero] #align pgame.neg_lf_zero_iff SetTheory.PGame.neg_lf_zero_iff @[simp] theorem zero_lf_neg_iff {x : PGame} : 0 ⧏ -x ↔ x ⧏ 0 := by rw [lf_neg_iff, neg_zero] #align pgame.zero_lf_neg_iff SetTheory.PGame.zero_lf_neg_iff @[simp] theorem neg_lt_zero_iff {x : PGame} : -x < 0 ↔ 0 < x := by rw [neg_lt_iff, neg_zero] #align pgame.neg_lt_zero_iff SetTheory.PGame.neg_lt_zero_iff @[simp] theorem zero_lt_neg_iff {x : PGame} : 0 < -x ↔ x < 0 := by rw [lt_neg_iff, neg_zero] #align pgame.zero_lt_neg_iff SetTheory.PGame.zero_lt_neg_iff @[simp] theorem neg_equiv_zero_iff {x : PGame} : (-x ≈ 0) ↔ (x ≈ 0) := by rw [neg_equiv_iff, neg_zero] #align pgame.neg_equiv_zero_iff SetTheory.PGame.neg_equiv_zero_iff @[simp] theorem neg_fuzzy_zero_iff {x : PGame} : -x ‖ 0 ↔ x ‖ 0 := by rw [neg_fuzzy_iff, neg_zero] #align pgame.neg_fuzzy_zero_iff SetTheory.PGame.neg_fuzzy_zero_iff @[simp] theorem zero_equiv_neg_iff {x : PGame} : (0 ≈ -x) ↔ (0 ≈ x) := by rw [← neg_equiv_iff, neg_zero] #align pgame.zero_equiv_neg_iff SetTheory.PGame.zero_equiv_neg_iff @[simp]
Mathlib/SetTheory/Game/PGame.lean
1,473
1,473
theorem zero_fuzzy_neg_iff {x : PGame} : 0 ‖ -x ↔ 0 ‖ x := by
rw [← neg_fuzzy_iff, neg_zero]
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Order.Interval.Set.Monotone import Mathlib.Topology.MetricSpace.Basic import Mathlib.Topology.MetricSpace.Bounded import Mathlib.Topology.Order.MonotoneConvergence #align_import analysis.box_integral.box.basic from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Rectangular boxes in `ℝⁿ` In this file we define rectangular boxes in `ℝⁿ`. As usual, we represent `ℝⁿ` as the type of functions `ι → ℝ` (usually `ι = Fin n` for some `n`). When we need to interpret a box `[l, u]` as a set, we use the product `{x | ∀ i, l i < x i ∧ x i ≤ u i}` of half-open intervals `(l i, u i]`. We exclude `l i` because this way boxes of a partition are disjoint as sets in `ℝⁿ`. Currently, the only use cases for these constructions are the definitions of Riemann-style integrals (Riemann, Henstock-Kurzweil, McShane). ## Main definitions We use the same structure `BoxIntegral.Box` both for ambient boxes and for elements of a partition. Each box is stored as two points `lower upper : ι → ℝ` and a proof of `∀ i, lower i < upper i`. We define instances `Membership (ι → ℝ) (Box ι)` and `CoeTC (Box ι) (Set <| ι → ℝ)` so that each box is interpreted as the set `{x | ∀ i, x i ∈ Set.Ioc (I.lower i) (I.upper i)}`. This way boxes of a partition are pairwise disjoint and their union is exactly the original box. We require boxes to be nonempty, because this way coercion to sets is injective. The empty box can be represented as `⊥ : WithBot (BoxIntegral.Box ι)`. We define the following operations on boxes: * coercion to `Set (ι → ℝ)` and `Membership (ι → ℝ) (BoxIntegral.Box ι)` as described above; * `PartialOrder` and `SemilatticeSup` instances such that `I ≤ J` is equivalent to `(I : Set (ι → ℝ)) ⊆ J`; * `Lattice` instances on `WithBot (BoxIntegral.Box ι)`; * `BoxIntegral.Box.Icc`: the closed box `Set.Icc I.lower I.upper`; defined as a bundled monotone map from `Box ι` to `Set (ι → ℝ)`; * `BoxIntegral.Box.face I i : Box (Fin n)`: a hyperface of `I : BoxIntegral.Box (Fin (n + 1))`; * `BoxIntegral.Box.distortion`: the maximal ratio of two lengths of edges of a box; defined as the supremum of `nndist I.lower I.upper / nndist (I.lower i) (I.upper i)`. We also provide a convenience constructor `BoxIntegral.Box.mk' (l u : ι → ℝ) : WithBot (Box ι)` that returns the box `⟨l, u, _⟩` if it is nonempty and `⊥` otherwise. ## Tags rectangular box -/ open Set Function Metric Filter noncomputable section open scoped Classical open NNReal Topology namespace BoxIntegral variable {ι : Type*} /-! ### Rectangular box: definition and partial order -/ /-- A nontrivial rectangular box in `ι → ℝ` with corners `lower` and `upper`. Represents the product of half-open intervals `(lower i, upper i]`. -/ structure Box (ι : Type*) where /-- coordinates of the lower and upper corners of the box -/ (lower upper : ι → ℝ) /-- Each lower coordinate is less than its upper coordinate: i.e., the box is non-empty -/ lower_lt_upper : ∀ i, lower i < upper i #align box_integral.box BoxIntegral.Box attribute [simp] Box.lower_lt_upper namespace Box variable (I J : Box ι) {x y : ι → ℝ} instance : Inhabited (Box ι) := ⟨⟨0, 1, fun _ ↦ zero_lt_one⟩⟩ theorem lower_le_upper : I.lower ≤ I.upper := fun i ↦ (I.lower_lt_upper i).le #align box_integral.box.lower_le_upper BoxIntegral.Box.lower_le_upper theorem lower_ne_upper (i) : I.lower i ≠ I.upper i := (I.lower_lt_upper i).ne #align box_integral.box.lower_ne_upper BoxIntegral.Box.lower_ne_upper instance : Membership (ι → ℝ) (Box ι) := ⟨fun x I ↦ ∀ i, x i ∈ Ioc (I.lower i) (I.upper i)⟩ -- Porting note: added /-- The set of points in this box: this is the product of half-open intervals `(lower i, upper i]`, where `lower` and `upper` are this box' corners. -/ @[coe] def toSet (I : Box ι) : Set (ι → ℝ) := { x | x ∈ I } instance : CoeTC (Box ι) (Set <| ι → ℝ) := ⟨toSet⟩ @[simp] theorem mem_mk {l u x : ι → ℝ} {H} : x ∈ mk l u H ↔ ∀ i, x i ∈ Ioc (l i) (u i) := Iff.rfl #align box_integral.box.mem_mk BoxIntegral.Box.mem_mk @[simp, norm_cast] theorem mem_coe : x ∈ (I : Set (ι → ℝ)) ↔ x ∈ I := Iff.rfl #align box_integral.box.mem_coe BoxIntegral.Box.mem_coe theorem mem_def : x ∈ I ↔ ∀ i, x i ∈ Ioc (I.lower i) (I.upper i) := Iff.rfl #align box_integral.box.mem_def BoxIntegral.Box.mem_def theorem mem_univ_Ioc {I : Box ι} : (x ∈ pi univ fun i ↦ Ioc (I.lower i) (I.upper i)) ↔ x ∈ I := mem_univ_pi #align box_integral.box.mem_univ_Ioc BoxIntegral.Box.mem_univ_Ioc theorem coe_eq_pi : (I : Set (ι → ℝ)) = pi univ fun i ↦ Ioc (I.lower i) (I.upper i) := Set.ext fun _ ↦ mem_univ_Ioc.symm #align box_integral.box.coe_eq_pi BoxIntegral.Box.coe_eq_pi @[simp] theorem upper_mem : I.upper ∈ I := fun i ↦ right_mem_Ioc.2 <| I.lower_lt_upper i #align box_integral.box.upper_mem BoxIntegral.Box.upper_mem theorem exists_mem : ∃ x, x ∈ I := ⟨_, I.upper_mem⟩ #align box_integral.box.exists_mem BoxIntegral.Box.exists_mem theorem nonempty_coe : Set.Nonempty (I : Set (ι → ℝ)) := I.exists_mem #align box_integral.box.nonempty_coe BoxIntegral.Box.nonempty_coe @[simp] theorem coe_ne_empty : (I : Set (ι → ℝ)) ≠ ∅ := I.nonempty_coe.ne_empty #align box_integral.box.coe_ne_empty BoxIntegral.Box.coe_ne_empty @[simp] theorem empty_ne_coe : ∅ ≠ (I : Set (ι → ℝ)) := I.coe_ne_empty.symm #align box_integral.box.empty_ne_coe BoxIntegral.Box.empty_ne_coe instance : LE (Box ι) := ⟨fun I J ↦ ∀ ⦃x⦄, x ∈ I → x ∈ J⟩ theorem le_def : I ≤ J ↔ ∀ x ∈ I, x ∈ J := Iff.rfl #align box_integral.box.le_def BoxIntegral.Box.le_def theorem le_TFAE : List.TFAE [I ≤ J, (I : Set (ι → ℝ)) ⊆ J, Icc I.lower I.upper ⊆ Icc J.lower J.upper, J.lower ≤ I.lower ∧ I.upper ≤ J.upper] := by tfae_have 1 ↔ 2 · exact Iff.rfl tfae_have 2 → 3 · intro h simpa [coe_eq_pi, closure_pi_set, lower_ne_upper] using closure_mono h tfae_have 3 ↔ 4 · exact Icc_subset_Icc_iff I.lower_le_upper tfae_have 4 → 2 · exact fun h x hx i ↦ Ioc_subset_Ioc (h.1 i) (h.2 i) (hx i) tfae_finish #align box_integral.box.le_tfae BoxIntegral.Box.le_TFAE variable {I J} @[simp, norm_cast] theorem coe_subset_coe : (I : Set (ι → ℝ)) ⊆ J ↔ I ≤ J := Iff.rfl #align box_integral.box.coe_subset_coe BoxIntegral.Box.coe_subset_coe theorem le_iff_bounds : I ≤ J ↔ J.lower ≤ I.lower ∧ I.upper ≤ J.upper := (le_TFAE I J).out 0 3 #align box_integral.box.le_iff_bounds BoxIntegral.Box.le_iff_bounds theorem injective_coe : Injective ((↑) : Box ι → Set (ι → ℝ)) := by rintro ⟨l₁, u₁, h₁⟩ ⟨l₂, u₂, h₂⟩ h simp only [Subset.antisymm_iff, coe_subset_coe, le_iff_bounds] at h congr exacts [le_antisymm h.2.1 h.1.1, le_antisymm h.1.2 h.2.2] #align box_integral.box.injective_coe BoxIntegral.Box.injective_coe @[simp, norm_cast] theorem coe_inj : (I : Set (ι → ℝ)) = J ↔ I = J := injective_coe.eq_iff #align box_integral.box.coe_inj BoxIntegral.Box.coe_inj @[ext] theorem ext (H : ∀ x, x ∈ I ↔ x ∈ J) : I = J := injective_coe <| Set.ext H #align box_integral.box.ext BoxIntegral.Box.ext theorem ne_of_disjoint_coe (h : Disjoint (I : Set (ι → ℝ)) J) : I ≠ J := mt coe_inj.2 <| h.ne I.coe_ne_empty #align box_integral.box.ne_of_disjoint_coe BoxIntegral.Box.ne_of_disjoint_coe instance : PartialOrder (Box ι) := { PartialOrder.lift ((↑) : Box ι → Set (ι → ℝ)) injective_coe with le := (· ≤ ·) } /-- Closed box corresponding to `I : BoxIntegral.Box ι`. -/ protected def Icc : Box ι ↪o Set (ι → ℝ) := OrderEmbedding.ofMapLEIff (fun I : Box ι ↦ Icc I.lower I.upper) fun I J ↦ (le_TFAE I J).out 2 0 #align box_integral.box.Icc BoxIntegral.Box.Icc theorem Icc_def : Box.Icc I = Icc I.lower I.upper := rfl #align box_integral.box.Icc_def BoxIntegral.Box.Icc_def @[simp] theorem upper_mem_Icc (I : Box ι) : I.upper ∈ Box.Icc I := right_mem_Icc.2 I.lower_le_upper #align box_integral.box.upper_mem_Icc BoxIntegral.Box.upper_mem_Icc @[simp] theorem lower_mem_Icc (I : Box ι) : I.lower ∈ Box.Icc I := left_mem_Icc.2 I.lower_le_upper #align box_integral.box.lower_mem_Icc BoxIntegral.Box.lower_mem_Icc protected theorem isCompact_Icc (I : Box ι) : IsCompact (Box.Icc I) := isCompact_Icc #align box_integral.box.is_compact_Icc BoxIntegral.Box.isCompact_Icc theorem Icc_eq_pi : Box.Icc I = pi univ fun i ↦ Icc (I.lower i) (I.upper i) := (pi_univ_Icc _ _).symm #align box_integral.box.Icc_eq_pi BoxIntegral.Box.Icc_eq_pi theorem le_iff_Icc : I ≤ J ↔ Box.Icc I ⊆ Box.Icc J := (le_TFAE I J).out 0 2 #align box_integral.box.le_iff_Icc BoxIntegral.Box.le_iff_Icc theorem antitone_lower : Antitone fun I : Box ι ↦ I.lower := fun _ _ H ↦ (le_iff_bounds.1 H).1 #align box_integral.box.antitone_lower BoxIntegral.Box.antitone_lower theorem monotone_upper : Monotone fun I : Box ι ↦ I.upper := fun _ _ H ↦ (le_iff_bounds.1 H).2 #align box_integral.box.monotone_upper BoxIntegral.Box.monotone_upper theorem coe_subset_Icc : ↑I ⊆ Box.Icc I := fun _ hx ↦ ⟨fun i ↦ (hx i).1.le, fun i ↦ (hx i).2⟩ #align box_integral.box.coe_subset_Icc BoxIntegral.Box.coe_subset_Icc /-! ### Supremum of two boxes -/ /-- `I ⊔ J` is the least box that includes both `I` and `J`. Since `↑I ∪ ↑J` is usually not a box, `↑(I ⊔ J)` is larger than `↑I ∪ ↑J`. -/ instance : Sup (Box ι) := ⟨fun I J ↦ ⟨I.lower ⊓ J.lower, I.upper ⊔ J.upper, fun i ↦ (min_le_left _ _).trans_lt <| (I.lower_lt_upper i).trans_le (le_max_left _ _)⟩⟩ instance : SemilatticeSup (Box ι) := { (inferInstance : PartialOrder (Box ι)), (inferInstance : Sup (Box ι)) with le_sup_left := fun _ _ ↦ le_iff_bounds.2 ⟨inf_le_left, le_sup_left⟩ le_sup_right := fun _ _ ↦ le_iff_bounds.2 ⟨inf_le_right, le_sup_right⟩ sup_le := fun _ _ _ h₁ h₂ ↦ le_iff_bounds.2 ⟨le_inf (antitone_lower h₁) (antitone_lower h₂), sup_le (monotone_upper h₁) (monotone_upper h₂)⟩ } /-! ### `WithBot (Box ι)` In this section we define coercion from `WithBot (Box ι)` to `Set (ι → ℝ)` by sending `⊥` to `∅`. -/ -- Porting note: added /-- The set underlying this box: `⊥` is mapped to `∅`. -/ @[coe] def withBotToSet (o : WithBot (Box ι)) : Set (ι → ℝ) := o.elim ∅ (↑) instance withBotCoe : CoeTC (WithBot (Box ι)) (Set (ι → ℝ)) := ⟨withBotToSet⟩ #align box_integral.box.with_bot_coe BoxIntegral.Box.withBotCoe @[simp, norm_cast] theorem coe_bot : ((⊥ : WithBot (Box ι)) : Set (ι → ℝ)) = ∅ := rfl #align box_integral.box.coe_bot BoxIntegral.Box.coe_bot @[simp, norm_cast] theorem coe_coe : ((I : WithBot (Box ι)) : Set (ι → ℝ)) = I := rfl #align box_integral.box.coe_coe BoxIntegral.Box.coe_coe theorem isSome_iff : ∀ {I : WithBot (Box ι)}, I.isSome ↔ (I : Set (ι → ℝ)).Nonempty | ⊥ => by erw [Option.isSome] simp | (I : Box ι) => by erw [Option.isSome] simp [I.nonempty_coe] #align box_integral.box.is_some_iff BoxIntegral.Box.isSome_iff theorem biUnion_coe_eq_coe (I : WithBot (Box ι)) : ⋃ (J : Box ι) (_ : ↑J = I), (J : Set (ι → ℝ)) = I := by induction I <;> simp [WithBot.coe_eq_coe] #align box_integral.box.bUnion_coe_eq_coe BoxIntegral.Box.biUnion_coe_eq_coe @[simp, norm_cast] theorem withBotCoe_subset_iff {I J : WithBot (Box ι)} : (I : Set (ι → ℝ)) ⊆ J ↔ I ≤ J := by induction I; · simp induction J; · simp [subset_empty_iff] simp [le_def] #align box_integral.box.with_bot_coe_subset_iff BoxIntegral.Box.withBotCoe_subset_iff @[simp, norm_cast] theorem withBotCoe_inj {I J : WithBot (Box ι)} : (I : Set (ι → ℝ)) = J ↔ I = J := by simp only [Subset.antisymm_iff, ← le_antisymm_iff, withBotCoe_subset_iff] #align box_integral.box.with_bot_coe_inj BoxIntegral.Box.withBotCoe_inj /-- Make a `WithBot (Box ι)` from a pair of corners `l u : ι → ℝ`. If `l i < u i` for all `i`, then the result is `⟨l, u, _⟩ : Box ι`, otherwise it is `⊥`. In any case, the result interpreted as a set in `ι → ℝ` is the set `{x : ι → ℝ | ∀ i, x i ∈ Ioc (l i) (u i)}`. -/ def mk' (l u : ι → ℝ) : WithBot (Box ι) := if h : ∀ i, l i < u i then ↑(⟨l, u, h⟩ : Box ι) else ⊥ #align box_integral.box.mk' BoxIntegral.Box.mk' @[simp] theorem mk'_eq_bot {l u : ι → ℝ} : mk' l u = ⊥ ↔ ∃ i, u i ≤ l i := by rw [mk'] split_ifs with h <;> simpa using h #align box_integral.box.mk'_eq_bot BoxIntegral.Box.mk'_eq_bot @[simp] theorem mk'_eq_coe {l u : ι → ℝ} : mk' l u = I ↔ l = I.lower ∧ u = I.upper := by cases' I with lI uI hI; rw [mk']; split_ifs with h · simp [WithBot.coe_eq_coe] · suffices l = lI → u ≠ uI by simpa rintro rfl rfl exact h hI #align box_integral.box.mk'_eq_coe BoxIntegral.Box.mk'_eq_coe @[simp]
Mathlib/Analysis/BoxIntegral/Box/Basic.lean
339
344
theorem coe_mk' (l u : ι → ℝ) : (mk' l u : Set (ι → ℝ)) = pi univ fun i ↦ Ioc (l i) (u i) := by
rw [mk']; split_ifs with h · exact coe_eq_pi _ · rcases not_forall.mp h with ⟨i, hi⟩ rw [coe_bot, univ_pi_eq_empty] exact Ioc_eq_empty hi
/- 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.FreeNonUnitalNonAssocAlgebra import Mathlib.Algebra.Lie.NonUnitalNonAssocAlgebra import Mathlib.Algebra.Lie.UniversalEnveloping import Mathlib.GroupTheory.GroupAction.Ring #align_import algebra.lie.free from "leanprover-community/mathlib"@"841ac1a3d9162bf51c6327812ecb6e5e71883ac4" /-! # Free Lie algebras Given a commutative ring `R` and a type `X` we construct the free Lie algebra on `X` with coefficients in `R` together with its universal property. ## Main definitions * `FreeLieAlgebra` * `FreeLieAlgebra.lift` * `FreeLieAlgebra.of` * `FreeLieAlgebra.universalEnvelopingEquivFreeAlgebra` ## Implementation details ### Quotient of free non-unital, non-associative algebra We follow [N. Bourbaki, *Lie Groups and Lie Algebras, Chapters 1--3*](bourbaki1975) and construct the free Lie algebra as a quotient of the free non-unital, non-associative algebra. Since we do not currently have definitions of ideals, lattices of ideals, and quotients for `NonUnitalNonAssocSemiring`, we construct our quotient using the low-level `Quot` function on an inductively-defined relation. ### Alternative construction (needs PBW) An alternative construction of the free Lie algebra on `X` is to start with the free unital associative algebra on `X`, regard it as a Lie algebra via the ring commutator, and take its smallest Lie subalgebra containing `X`. I.e.: `LieSubalgebra.lieSpan R (FreeAlgebra R X) (Set.range (FreeAlgebra.ι R))`. However with this definition there does not seem to be an easy proof that the required universal property holds, and I don't know of a proof that avoids invoking the Poincaré–Birkhoff–Witt theorem. A related MathOverflow question is [this one](https://mathoverflow.net/questions/396680/). ## Tags lie algebra, free algebra, non-unital, non-associative, universal property, forgetful functor, adjoint functor -/ universe u v w noncomputable section variable (R : Type u) (X : Type v) [CommRing R] /- We save characters by using Bourbaki's name `lib` (as in «libre») for `FreeNonUnitalNonAssocAlgebra` in this file. -/ local notation "lib" => FreeNonUnitalNonAssocAlgebra local notation "lib.lift" => FreeNonUnitalNonAssocAlgebra.lift local notation "lib.of" => FreeNonUnitalNonAssocAlgebra.of local notation "lib.lift_of_apply" => FreeNonUnitalNonAssocAlgebra.lift_of_apply local notation "lib.lift_comp_of" => FreeNonUnitalNonAssocAlgebra.lift_comp_of namespace FreeLieAlgebra /-- The quotient of `lib R X` by the equivalence relation generated by this relation will give us the free Lie algebra. -/ inductive Rel : lib R X → lib R X → Prop | lie_self (a : lib R X) : Rel (a * a) 0 | leibniz_lie (a b c : lib R X) : Rel (a * (b * c)) (a * b * c + b * (a * c)) | smul (t : R) {a b : lib R X} : Rel a b → Rel (t • a) (t • b) | add_right {a b : lib R X} (c : lib R X) : Rel a b → Rel (a + c) (b + c) | mul_left (a : lib R X) {b c : lib R X} : Rel b c → Rel (a * b) (a * c) | mul_right {a b : lib R X} (c : lib R X) : Rel a b → Rel (a * c) (b * c) #align free_lie_algebra.rel FreeLieAlgebra.Rel variable {R X}
Mathlib/Algebra/Lie/Free.lean
87
88
theorem Rel.addLeft (a : lib R X) {b c : lib R X} (h : Rel R X b c) : Rel R X (a + b) (a + c) := by
rw [add_comm _ b, add_comm _ c]; exact h.add_right _
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro -/ import Mathlib.Data.List.Count import Mathlib.Data.List.Dedup import Mathlib.Data.List.InsertNth import Mathlib.Data.List.Lattice import Mathlib.Data.List.Permutation import Mathlib.Data.Nat.Factorial.Basic #align_import data.list.perm from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # List Permutations This file introduces the `List.Perm` relation, which is true if two lists are permutations of one another. ## Notation The notation `~` is used for permutation equivalence. -/ -- Make sure we don't import algebra assert_not_exists Monoid open Nat namespace List variable {α β : Type*} {l l₁ l₂ : List α} {a : α} #align list.perm List.Perm instance : Trans (@List.Perm α) (@List.Perm α) List.Perm where trans := @List.Perm.trans α open Perm (swap) attribute [refl] Perm.refl #align list.perm.refl List.Perm.refl lemma perm_rfl : l ~ l := Perm.refl _ -- Porting note: used rec_on in mathlib3; lean4 eqn compiler still doesn't like it attribute [symm] Perm.symm #align list.perm.symm List.Perm.symm #align list.perm_comm List.perm_comm #align list.perm.swap' List.Perm.swap' attribute [trans] Perm.trans #align list.perm.eqv List.Perm.eqv #align list.is_setoid List.isSetoid #align list.perm.mem_iff List.Perm.mem_iff #align list.perm.subset List.Perm.subset theorem Perm.subset_congr_left {l₁ l₂ l₃ : List α} (h : l₁ ~ l₂) : l₁ ⊆ l₃ ↔ l₂ ⊆ l₃ := ⟨h.symm.subset.trans, h.subset.trans⟩ #align list.perm.subset_congr_left List.Perm.subset_congr_left theorem Perm.subset_congr_right {l₁ l₂ l₃ : List α} (h : l₁ ~ l₂) : l₃ ⊆ l₁ ↔ l₃ ⊆ l₂ := ⟨fun h' => h'.trans h.subset, fun h' => h'.trans h.symm.subset⟩ #align list.perm.subset_congr_right List.Perm.subset_congr_right #align list.perm.append_right List.Perm.append_right #align list.perm.append_left List.Perm.append_left #align list.perm.append List.Perm.append #align list.perm.append_cons List.Perm.append_cons #align list.perm_middle List.perm_middle #align list.perm_append_singleton List.perm_append_singleton #align list.perm_append_comm List.perm_append_comm #align list.concat_perm List.concat_perm #align list.perm.length_eq List.Perm.length_eq #align list.perm.eq_nil List.Perm.eq_nil #align list.perm.nil_eq List.Perm.nil_eq #align list.perm_nil List.perm_nil #align list.nil_perm List.nil_perm #align list.not_perm_nil_cons List.not_perm_nil_cons #align list.reverse_perm List.reverse_perm #align list.perm_cons_append_cons List.perm_cons_append_cons #align list.perm_replicate List.perm_replicate #align list.replicate_perm List.replicate_perm #align list.perm_singleton List.perm_singleton #align list.singleton_perm List.singleton_perm #align list.singleton_perm_singleton List.singleton_perm_singleton #align list.perm_cons_erase List.perm_cons_erase #align list.perm_induction_on List.Perm.recOnSwap' -- Porting note: used to be @[congr] #align list.perm.filter_map List.Perm.filterMap -- Porting note: used to be @[congr] #align list.perm.map List.Perm.map #align list.perm.pmap List.Perm.pmap #align list.perm.filter List.Perm.filter #align list.filter_append_perm List.filter_append_perm #align list.exists_perm_sublist List.exists_perm_sublist #align list.perm.sizeof_eq_sizeof List.Perm.sizeOf_eq_sizeOf section Rel open Relator variable {γ : Type*} {δ : Type*} {r : α → β → Prop} {p : γ → δ → Prop} local infixr:80 " ∘r " => Relation.Comp theorem perm_comp_perm : (Perm ∘r Perm : List α → List α → Prop) = Perm := by funext a c; apply propext constructor · exact fun ⟨b, hab, hba⟩ => Perm.trans hab hba · exact fun h => ⟨a, Perm.refl a, h⟩ #align list.perm_comp_perm List.perm_comp_perm theorem perm_comp_forall₂ {l u v} (hlu : Perm l u) (huv : Forall₂ r u v) : (Forall₂ r ∘r Perm) l v := by induction hlu generalizing v with | nil => cases huv; exact ⟨[], Forall₂.nil, Perm.nil⟩ | cons u _hlu ih => cases' huv with _ b _ v hab huv' rcases ih huv' with ⟨l₂, h₁₂, h₂₃⟩ exact ⟨b :: l₂, Forall₂.cons hab h₁₂, h₂₃.cons _⟩ | swap a₁ a₂ h₂₃ => cases' huv with _ b₁ _ l₂ h₁ hr₂₃ cases' hr₂₃ with _ b₂ _ l₂ h₂ h₁₂ exact ⟨b₂ :: b₁ :: l₂, Forall₂.cons h₂ (Forall₂.cons h₁ h₁₂), Perm.swap _ _ _⟩ | trans _ _ ih₁ ih₂ => rcases ih₂ huv with ⟨lb₂, hab₂, h₂₃⟩ rcases ih₁ hab₂ with ⟨lb₁, hab₁, h₁₂⟩ exact ⟨lb₁, hab₁, Perm.trans h₁₂ h₂₃⟩ #align list.perm_comp_forall₂ List.perm_comp_forall₂ theorem forall₂_comp_perm_eq_perm_comp_forall₂ : Forall₂ r ∘r Perm = Perm ∘r Forall₂ r := by funext l₁ l₃; apply propext constructor · intro h rcases h with ⟨l₂, h₁₂, h₂₃⟩ have : Forall₂ (flip r) l₂ l₁ := h₁₂.flip rcases perm_comp_forall₂ h₂₃.symm this with ⟨l', h₁, h₂⟩ exact ⟨l', h₂.symm, h₁.flip⟩ · exact fun ⟨l₂, h₁₂, h₂₃⟩ => perm_comp_forall₂ h₁₂ h₂₃ #align list.forall₂_comp_perm_eq_perm_comp_forall₂ List.forall₂_comp_perm_eq_perm_comp_forall₂ theorem rel_perm_imp (hr : RightUnique r) : (Forall₂ r ⇒ Forall₂ r ⇒ (· → ·)) Perm Perm := fun a b h₁ c d h₂ h => have : (flip (Forall₂ r) ∘r Perm ∘r Forall₂ r) b d := ⟨a, h₁, c, h, h₂⟩ have : ((flip (Forall₂ r) ∘r Forall₂ r) ∘r Perm) b d := by rwa [← forall₂_comp_perm_eq_perm_comp_forall₂, ← Relation.comp_assoc] at this let ⟨b', ⟨c', hbc, hcb⟩, hbd⟩ := this have : b' = b := right_unique_forall₂' hr hcb hbc this ▸ hbd #align list.rel_perm_imp List.rel_perm_imp theorem rel_perm (hr : BiUnique r) : (Forall₂ r ⇒ Forall₂ r ⇒ (· ↔ ·)) Perm Perm := fun _a _b hab _c _d hcd => Iff.intro (rel_perm_imp hr.2 hab hcd) (rel_perm_imp hr.left.flip hab.flip hcd.flip) #align list.rel_perm List.rel_perm end Rel section Subperm #align list.nil_subperm List.nil_subperm #align list.perm.subperm_left List.Perm.subperm_left #align list.perm.subperm_right List.Perm.subperm_right #align list.sublist.subperm List.Sublist.subperm #align list.perm.subperm List.Perm.subperm attribute [refl] Subperm.refl #align list.subperm.refl List.Subperm.refl attribute [trans] Subperm.trans #align list.subperm.trans List.Subperm.trans #align list.subperm.length_le List.Subperm.length_le #align list.subperm.perm_of_length_le List.Subperm.perm_of_length_le #align list.subperm.antisymm List.Subperm.antisymm #align list.subperm.subset List.Subperm.subset #align list.subperm.filter List.Subperm.filter end Subperm #align list.sublist.exists_perm_append List.Sublist.exists_perm_append lemma subperm_iff : l₁ <+~ l₂ ↔ ∃ l, l ~ l₂ ∧ l₁ <+ l := by refine ⟨?_, fun ⟨l, h₁, h₂⟩ ↦ h₂.subperm.trans h₁.subperm⟩ rintro ⟨l, h₁, h₂⟩ obtain ⟨l', h₂⟩ := h₂.exists_perm_append exact ⟨l₁ ++ l', (h₂.trans (h₁.append_right _)).symm, (prefix_append _ _).sublist⟩ #align list.subperm_singleton_iff List.singleton_subperm_iff @[simp] lemma subperm_singleton_iff : l <+~ [a] ↔ l = [] ∨ l = [a] := by constructor · rw [subperm_iff] rintro ⟨s, hla, h⟩ rwa [perm_singleton.mp hla, sublist_singleton] at h · rintro (rfl | rfl) exacts [nil_subperm, Subperm.refl _] attribute [simp] nil_subperm @[simp] theorem subperm_nil : List.Subperm l [] ↔ l = [] := match l with | [] => by simp | head :: tail => by simp only [iff_false] intro h have := h.length_le simp only [List.length_cons, List.length_nil, Nat.succ_ne_zero, ← Nat.not_lt, Nat.zero_lt_succ, not_true_eq_false] at this #align list.perm.countp_eq List.Perm.countP_eq #align list.subperm.countp_le List.Subperm.countP_le #align list.perm.countp_congr List.Perm.countP_congr #align list.countp_eq_countp_filter_add List.countP_eq_countP_filter_add lemma count_eq_count_filter_add [DecidableEq α] (P : α → Prop) [DecidablePred P] (l : List α) (a : α) : count a l = count a (l.filter P) + count a (l.filter (¬ P ·)) := by convert countP_eq_countP_filter_add l _ P simp only [decide_not] #align list.perm.count_eq List.Perm.count_eq #align list.subperm.count_le List.Subperm.count_le #align list.perm.foldl_eq' List.Perm.foldl_eq' theorem Perm.foldl_eq {f : β → α → β} {l₁ l₂ : List α} (rcomm : RightCommutative f) (p : l₁ ~ l₂) : ∀ b, foldl f b l₁ = foldl f b l₂ := p.foldl_eq' fun x _hx y _hy z => rcomm z x y #align list.perm.foldl_eq List.Perm.foldl_eq theorem Perm.foldr_eq {f : α → β → β} {l₁ l₂ : List α} (lcomm : LeftCommutative f) (p : l₁ ~ l₂) : ∀ b, foldr f b l₁ = foldr f b l₂ := by intro b induction p using Perm.recOnSwap' generalizing b with | nil => rfl | cons _ _ r => simp; rw [r b] | swap' _ _ _ r => simp; rw [lcomm, r b] | trans _ _ r₁ r₂ => exact Eq.trans (r₁ b) (r₂ b) #align list.perm.foldr_eq List.Perm.foldr_eq #align list.perm.rec_heq List.Perm.rec_heq section variable {op : α → α → α} [IA : Std.Associative op] [IC : Std.Commutative op] local notation a " * " b => op a b local notation l " <*> " a => foldl op a l theorem Perm.fold_op_eq {l₁ l₂ : List α} {a : α} (h : l₁ ~ l₂) : (l₁ <*> a) = l₂ <*> a := h.foldl_eq (right_comm _ IC.comm IA.assoc) _ #align list.perm.fold_op_eq List.Perm.fold_op_eq end #align list.perm_inv_core List.perm_inv_core #align list.perm.cons_inv List.Perm.cons_inv #align list.perm_cons List.perm_cons #align list.perm_append_left_iff List.perm_append_left_iff #align list.perm_append_right_iff List.perm_append_right_iff theorem perm_option_to_list {o₁ o₂ : Option α} : o₁.toList ~ o₂.toList ↔ o₁ = o₂ := by refine ⟨fun p => ?_, fun e => e ▸ Perm.refl _⟩ cases' o₁ with a <;> cases' o₂ with b; · rfl · cases p.length_eq · cases p.length_eq · exact Option.mem_toList.1 (p.symm.subset <| by simp) #align list.perm_option_to_list List.perm_option_to_list #align list.subperm_cons List.subperm_cons alias ⟨subperm.of_cons, subperm.cons⟩ := subperm_cons #align list.subperm.of_cons List.subperm.of_cons #align list.subperm.cons List.subperm.cons -- Porting note: commented out --attribute [protected] subperm.cons theorem cons_subperm_of_mem {a : α} {l₁ l₂ : List α} (d₁ : Nodup l₁) (h₁ : a ∉ l₁) (h₂ : a ∈ l₂) (s : l₁ <+~ l₂) : a :: l₁ <+~ l₂ := by rcases s with ⟨l, p, s⟩ induction s generalizing l₁ with | slnil => cases h₂ | @cons r₁ r₂ b s' ih => simp? at h₂ says simp only [mem_cons] at h₂ cases' h₂ with e m · subst b exact ⟨a :: r₁, p.cons a, s'.cons₂ _⟩ · rcases ih d₁ h₁ m p with ⟨t, p', s'⟩ exact ⟨t, p', s'.cons _⟩ | @cons₂ r₁ r₂ b _ ih => have bm : b ∈ l₁ := p.subset <| mem_cons_self _ _ have am : a ∈ r₂ := by simp only [find?, mem_cons] at h₂ exact h₂.resolve_left fun e => h₁ <| e.symm ▸ bm rcases append_of_mem bm with ⟨t₁, t₂, rfl⟩ have st : t₁ ++ t₂ <+ t₁ ++ b :: t₂ := by simp rcases ih (d₁.sublist st) (mt (fun x => st.subset x) h₁) am (Perm.cons_inv <| p.trans perm_middle) with ⟨t, p', s'⟩ exact ⟨b :: t, (p'.cons b).trans <| (swap _ _ _).trans (perm_middle.symm.cons a), s'.cons₂ _⟩ #align list.cons_subperm_of_mem List.cons_subperm_of_mem #align list.subperm_append_left List.subperm_append_left #align list.subperm_append_right List.subperm_append_right #align list.subperm.exists_of_length_lt List.Subperm.exists_of_length_lt protected theorem Nodup.subperm (d : Nodup l₁) (H : l₁ ⊆ l₂) : l₁ <+~ l₂ := subperm_of_subset d H #align list.nodup.subperm List.Nodup.subperm #align list.perm_ext List.perm_ext_iff_of_nodup #align list.nodup.sublist_ext List.Nodup.perm_iff_eq_of_sublist section variable [DecidableEq α] -- attribute [congr] #align list.perm.erase List.Perm.erase #align list.subperm_cons_erase List.subperm_cons_erase #align list.erase_subperm List.erase_subperm #align list.subperm.erase List.Subperm.erase #align list.perm.diff_right List.Perm.diff_right #align list.perm.diff_left List.Perm.diff_left #align list.perm.diff List.Perm.diff #align list.subperm.diff_right List.Subperm.diff_right #align list.erase_cons_subperm_cons_erase List.erase_cons_subperm_cons_erase #align list.subperm_cons_diff List.subperm_cons_diff #align list.subset_cons_diff List.subset_cons_diff theorem Perm.bagInter_right {l₁ l₂ : List α} (t : List α) (h : l₁ ~ l₂) : l₁.bagInter t ~ l₂.bagInter t := by induction' h with x _ _ _ _ x y _ _ _ _ _ _ ih_1 ih_2 generalizing t; · simp · by_cases x ∈ t <;> simp [*, Perm.cons] · by_cases h : x = y · simp [h] by_cases xt : x ∈ t <;> by_cases yt : y ∈ t · simp [xt, yt, mem_erase_of_ne h, mem_erase_of_ne (Ne.symm h), erase_comm, swap] · simp [xt, yt, mt mem_of_mem_erase, Perm.cons] · simp [xt, yt, mt mem_of_mem_erase, Perm.cons] · simp [xt, yt] · exact (ih_1 _).trans (ih_2 _) #align list.perm.bag_inter_right List.Perm.bagInter_right theorem Perm.bagInter_left (l : List α) {t₁ t₂ : List α} (p : t₁ ~ t₂) : l.bagInter t₁ = l.bagInter t₂ := by induction' l with a l IH generalizing t₁ t₂ p; · simp by_cases h : a ∈ t₁ · simp [h, p.subset h, IH (p.erase _)] · simp [h, mt p.mem_iff.2 h, IH p] #align list.perm.bag_inter_left List.Perm.bagInter_left theorem Perm.bagInter {l₁ l₂ t₁ t₂ : List α} (hl : l₁ ~ l₂) (ht : t₁ ~ t₂) : l₁.bagInter t₁ ~ l₂.bagInter t₂ := ht.bagInter_left l₂ ▸ hl.bagInter_right _ #align list.perm.bag_inter List.Perm.bagInter #align list.cons_perm_iff_perm_erase List.cons_perm_iff_perm_erase #align list.perm_iff_count List.perm_iff_count theorem perm_replicate_append_replicate {l : List α} {a b : α} {m n : ℕ} (h : a ≠ b) : l ~ replicate m a ++ replicate n b ↔ count a l = m ∧ count b l = n ∧ l ⊆ [a, b] := by rw [perm_iff_count, ← Decidable.and_forall_ne a, ← Decidable.and_forall_ne b] suffices l ⊆ [a, b] ↔ ∀ c, c ≠ b → c ≠ a → c ∉ l by simp (config := { contextual := true }) [count_replicate, h, h.symm, this, count_eq_zero] trans ∀ c, c ∈ l → c = b ∨ c = a · simp [subset_def, or_comm] · exact forall_congr' fun _ => by rw [← and_imp, ← not_or, not_imp_not] #align list.perm_replicate_append_replicate List.perm_replicate_append_replicate #align list.subperm.cons_right List.Subperm.cons_right #align list.subperm_append_diff_self_of_count_le List.subperm_append_diff_self_of_count_le #align list.subperm_ext_iff List.subperm_ext_iff #align list.decidable_subperm List.decidableSubperm #align list.subperm.cons_left List.Subperm.cons_left #align list.decidable_perm List.decidablePerm -- @[congr] theorem Perm.dedup {l₁ l₂ : List α} (p : l₁ ~ l₂) : dedup l₁ ~ dedup l₂ := perm_iff_count.2 fun a => if h : a ∈ l₁ then by simp [nodup_dedup, h, p.subset h] else by simp [h, mt p.mem_iff.2 h] #align list.perm.dedup List.Perm.dedup -- attribute [congr] #align list.perm.insert List.Perm.insert #align list.perm_insert_swap List.perm_insert_swap #align list.perm_insert_nth List.perm_insertNth #align list.perm.union_right List.Perm.union_right #align list.perm.union_left List.Perm.union_left -- @[congr] #align list.perm.union List.Perm.union #align list.perm.inter_right List.Perm.inter_right #align list.perm.inter_left List.Perm.inter_left -- @[congr] #align list.perm.inter List.Perm.inter theorem Perm.inter_append {l t₁ t₂ : List α} (h : Disjoint t₁ t₂) : l ∩ (t₁ ++ t₂) ~ l ∩ t₁ ++ l ∩ t₂ := by induction l with | nil => simp | cons x xs l_ih => by_cases h₁ : x ∈ t₁ · have h₂ : x ∉ t₂ := h h₁ simp [*] by_cases h₂ : x ∈ t₂ · simp only [*, inter_cons_of_not_mem, false_or_iff, mem_append, inter_cons_of_mem, not_false_iff] refine Perm.trans (Perm.cons _ l_ih) ?_ change [x] ++ xs ∩ t₁ ++ xs ∩ t₂ ~ xs ∩ t₁ ++ ([x] ++ xs ∩ t₂) rw [← List.append_assoc] solve_by_elim [Perm.append_right, perm_append_comm] · simp [*] #align list.perm.inter_append List.Perm.inter_append end #align list.perm.pairwise_iff List.Perm.pairwise_iff #align list.pairwise.perm List.Pairwise.perm #align list.perm.pairwise List.Perm.pairwise #align list.perm.nodup_iff List.Perm.nodup_iff #align list.perm.join List.Perm.join #align list.perm.bind_right List.Perm.bind_right #align list.perm.join_congr List.Perm.join_congr theorem Perm.bind_left (l : List α) {f g : α → List β} (h : ∀ a ∈ l, f a ~ g a) : l.bind f ~ l.bind g := Perm.join_congr <| by rwa [List.forall₂_map_right_iff, List.forall₂_map_left_iff, List.forall₂_same] #align list.perm.bind_left List.Perm.bind_left theorem bind_append_perm (l : List α) (f g : α → List β) : l.bind f ++ l.bind g ~ l.bind fun x => f x ++ g x := by induction' l with a l IH <;> simp refine (Perm.trans ?_ (IH.append_left _)).append_left _ rw [← append_assoc, ← append_assoc] exact perm_append_comm.append_right _ #align list.bind_append_perm List.bind_append_perm theorem map_append_bind_perm (l : List α) (f : α → β) (g : α → List β) : l.map f ++ l.bind g ~ l.bind fun x => f x :: g x := by simpa [← map_eq_bind] using bind_append_perm l (fun x => [f x]) g #align list.map_append_bind_perm List.map_append_bind_perm theorem Perm.product_right {l₁ l₂ : List α} (t₁ : List β) (p : l₁ ~ l₂) : product l₁ t₁ ~ product l₂ t₁ := p.bind_right _ #align list.perm.product_right List.Perm.product_right theorem Perm.product_left (l : List α) {t₁ t₂ : List β} (p : t₁ ~ t₂) : product l t₁ ~ product l t₂ := (Perm.bind_left _) fun _ _ => p.map _ #align list.perm.product_left List.Perm.product_left -- @[congr] theorem Perm.product {l₁ l₂ : List α} {t₁ t₂ : List β} (p₁ : l₁ ~ l₂) (p₂ : t₁ ~ t₂) : product l₁ t₁ ~ product l₂ t₂ := (p₁.product_right t₁).trans (p₂.product_left l₂) #align list.perm.product List.Perm.product theorem perm_lookmap (f : α → Option α) {l₁ l₂ : List α} (H : Pairwise (fun a b => ∀ c ∈ f a, ∀ d ∈ f b, a = b ∧ c = d) l₁) (p : l₁ ~ l₂) : lookmap f l₁ ~ lookmap f l₂ := by induction' p with a l₁ l₂ p IH a b l l₁ l₂ l₃ p₁ _ IH₁ IH₂; · simp · cases h : f a · simp [h] exact IH (pairwise_cons.1 H).2 · simp [lookmap_cons_some _ _ h, p] · cases' h₁ : f a with c <;> cases' h₂ : f b with d · simp [h₁, h₂] apply swap · simp [h₁, lookmap_cons_some _ _ h₂] apply swap · simp [lookmap_cons_some _ _ h₁, h₂] apply swap · simp [lookmap_cons_some _ _ h₁, lookmap_cons_some _ _ h₂] rcases (pairwise_cons.1 H).1 _ (mem_cons.2 (Or.inl rfl)) _ h₂ _ h₁ with ⟨rfl, rfl⟩ exact Perm.refl _ · refine (IH₁ H).trans (IH₂ ((p₁.pairwise_iff ?_).1 H)) intro x y h c hc d hd rw [@eq_comm _ y, @eq_comm _ c] apply h d hd c hc #align list.perm_lookmap List.perm_lookmap #align list.perm.erasep List.Perm.eraseP theorem Perm.take_inter [DecidableEq α] {xs ys : List α} (n : ℕ) (h : xs ~ ys) (h' : ys.Nodup) : xs.take n ~ ys.inter (xs.take n) := by simp only [List.inter] exact Perm.trans (show xs.take n ~ xs.filter (xs.take n).elem by conv_lhs => rw [Nodup.take_eq_filter_mem ((Perm.nodup_iff h).2 h')]) (Perm.filter _ h) #align list.perm.take_inter List.Perm.take_inter theorem Perm.drop_inter [DecidableEq α] {xs ys : List α} (n : ℕ) (h : xs ~ ys) (h' : ys.Nodup) : xs.drop n ~ ys.inter (xs.drop n) := by by_cases h'' : n ≤ xs.length · let n' := xs.length - n have h₀ : n = xs.length - n' := by rwa [Nat.sub_sub_self] have h₁ : n' ≤ xs.length := Nat.sub_le .. have h₂ : xs.drop n = (xs.reverse.take n').reverse := by rw [reverse_take _ h₁, h₀, reverse_reverse] rw [h₂] apply (reverse_perm _).trans rw [inter_reverse] apply Perm.take_inter _ _ h' apply (reverse_perm _).trans; assumption · have : drop n xs = [] := by apply eq_nil_of_length_eq_zero rw [length_drop, Nat.sub_eq_zero_iff_le] apply le_of_not_ge h'' simp [this, List.inter] #align list.perm.drop_inter List.Perm.drop_inter theorem Perm.dropSlice_inter [DecidableEq α] {xs ys : List α} (n m : ℕ) (h : xs ~ ys) (h' : ys.Nodup) : List.dropSlice n m xs ~ ys ∩ List.dropSlice n m xs := by simp only [dropSlice_eq] have : n ≤ n + m := Nat.le_add_right _ _ have h₂ := h.nodup_iff.2 h' apply Perm.trans _ (Perm.inter_append _).symm · exact Perm.append (Perm.take_inter _ h h') (Perm.drop_inter _ h h') · exact disjoint_take_drop h₂ this #align list.perm.slice_inter List.Perm.dropSlice_inter -- enumerating permutations section Permutations theorem perm_of_mem_permutationsAux : ∀ {ts is l : List α}, l ∈ permutationsAux ts is → l ~ ts ++ is := by show ∀ (ts is l : List α), l ∈ permutationsAux ts is → l ~ ts ++ is refine permutationsAux.rec (by simp) ?_ introv IH1 IH2 m rw [permutationsAux_cons, permutations, mem_foldr_permutationsAux2] at m rcases m with (m | ⟨l₁, l₂, m, _, rfl⟩) · exact (IH1 _ m).trans perm_middle · have p : l₁ ++ l₂ ~ is := by simp only [mem_cons] at m cases' m with e m · simp [e] exact is.append_nil ▸ IH2 _ m exact ((perm_middle.trans (p.cons _)).append_right _).trans (perm_append_comm.cons _) #align list.perm_of_mem_permutations_aux List.perm_of_mem_permutationsAux theorem perm_of_mem_permutations {l₁ l₂ : List α} (h : l₁ ∈ permutations l₂) : l₁ ~ l₂ := (eq_or_mem_of_mem_cons h).elim (fun e => e ▸ Perm.refl _) fun m => append_nil l₂ ▸ perm_of_mem_permutationsAux m #align list.perm_of_mem_permutations List.perm_of_mem_permutations theorem length_permutationsAux : ∀ ts is : List α, length (permutationsAux ts is) + is.length ! = (length ts + length is)! := by refine permutationsAux.rec (by simp) ?_ intro t ts is IH1 IH2 have IH2 : length (permutationsAux is nil) + 1 = is.length ! := by simpa using IH2 simp only [factorial, Nat.mul_comm, add_eq] at IH1 rw [permutationsAux_cons, length_foldr_permutationsAux2' _ _ _ _ _ fun l m => (perm_of_mem_permutations m).length_eq, permutations, length, length, IH2, Nat.succ_add, Nat.factorial_succ, Nat.mul_comm (_ + 1), ← Nat.succ_eq_add_one, ← IH1, Nat.add_comm (_ * _), Nat.add_assoc, Nat.mul_succ, Nat.mul_comm] #align list.length_permutations_aux List.length_permutationsAux theorem length_permutations (l : List α) : length (permutations l) = (length l)! := length_permutationsAux l [] #align list.length_permutations List.length_permutations theorem mem_permutations_of_perm_lemma {is l : List α} (H : l ~ [] ++ is → (∃ (ts' : _) (_ : ts' ~ []), l = ts' ++ is) ∨ l ∈ permutationsAux is []) : l ~ is → l ∈ permutations is := by simpa [permutations, perm_nil] using H #align list.mem_permutations_of_perm_lemma List.mem_permutations_of_perm_lemma theorem mem_permutationsAux_of_perm : ∀ {ts is l : List α}, l ~ is ++ ts → (∃ (is' : _) (_ : is' ~ is), l = is' ++ ts) ∨ l ∈ permutationsAux ts is := by show ∀ (ts is l : List α), l ~ is ++ ts → (∃ (is' : _) (_ : is' ~ is), l = is' ++ ts) ∨ l ∈ permutationsAux ts is refine permutationsAux.rec (by simp) ?_ intro t ts is IH1 IH2 l p rw [permutationsAux_cons, mem_foldr_permutationsAux2] rcases IH1 _ (p.trans perm_middle) with (⟨is', p', e⟩ | m) · clear p subst e rcases append_of_mem (p'.symm.subset (mem_cons_self _ _)) with ⟨l₁, l₂, e⟩ subst is' have p := (perm_middle.symm.trans p').cons_inv cases' l₂ with a l₂' · exact Or.inl ⟨l₁, by simpa using p⟩ · exact Or.inr (Or.inr ⟨l₁, a :: l₂', mem_permutations_of_perm_lemma (IH2 _) p, by simp⟩) · exact Or.inr (Or.inl m) #align list.mem_permutations_aux_of_perm List.mem_permutationsAux_of_perm @[simp] theorem mem_permutations {s t : List α} : s ∈ permutations t ↔ s ~ t := ⟨perm_of_mem_permutations, mem_permutations_of_perm_lemma mem_permutationsAux_of_perm⟩ #align list.mem_permutations List.mem_permutations -- Porting note: temporary theorem to solve diamond issue private theorem DecEq_eq [DecidableEq α] : List.instBEq = @instBEqOfDecidableEq (List α) instDecidableEqList := congr_arg BEq.mk <| by funext l₁ l₂ show (l₁ == l₂) = _ rw [Bool.eq_iff_iff, @beq_iff_eq _ (_), decide_eq_true_iff]
Mathlib/Data/List/Perm.lean
694
715
theorem perm_permutations'Aux_comm (a b : α) (l : List α) : (permutations'Aux a l).bind (permutations'Aux b) ~ (permutations'Aux b l).bind (permutations'Aux a) := by
induction' l with c l ih · simp [swap] simp only [permutations'Aux, cons_bind, map_cons, map_map, cons_append] apply Perm.swap' have : ∀ a b, (map (cons c) (permutations'Aux a l)).bind (permutations'Aux b) ~ map (cons b ∘ cons c) (permutations'Aux a l) ++ map (cons c) ((permutations'Aux a l).bind (permutations'Aux b)) := by intros a' b' simp only [map_bind, permutations'Aux] show List.bind (permutations'Aux _ l) (fun a => ([b' :: c :: a] ++ map (cons c) (permutations'Aux _ a))) ~ _ refine (bind_append_perm _ (fun x => [b' :: c :: x]) _).symm.trans ?_ rw [← map_eq_bind, ← bind_map] exact Perm.refl _ refine (((this _ _).append_left _).trans ?_).trans ((this _ _).append_left _).symm rw [← append_assoc, ← append_assoc] exact perm_append_comm.append (ih.map _)
/- 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. -/ 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 #align mv_polynomial.vars_prod MvPolynomial.vars_prod section IsDomain variable {A : Type*} [CommRing A] [IsDomain A] theorem vars_C_mul (a : A) (ha : a ≠ 0) (φ : MvPolynomial σ A) : (C a * φ : MvPolynomial σ A).vars = φ.vars := by ext1 i simp only [mem_vars, exists_prop, mem_support_iff] apply exists_congr intro d apply and_congr _ Iff.rfl rw [coeff_C_mul, mul_ne_zero_iff, eq_true ha, true_and_iff] set_option linter.uppercaseLean3 false in #align mv_polynomial.vars_C_mul MvPolynomial.vars_C_mul end IsDomain end Mul section Sum variable {ι : Type*} (t : Finset ι) (φ : ι → MvPolynomial σ R) theorem vars_sum_subset [DecidableEq σ] : (∑ i ∈ t, φ i).vars ⊆ Finset.biUnion t fun i => (φ i).vars := by classical induction t using Finset.induction_on with | empty => simp | insert has hsum => rw [Finset.biUnion_insert, Finset.sum_insert has] refine Finset.Subset.trans (vars_add_subset _ _) (Finset.union_subset_union (Finset.Subset.refl _) ?_) assumption #align mv_polynomial.vars_sum_subset MvPolynomial.vars_sum_subset theorem vars_sum_of_disjoint [DecidableEq σ] (h : Pairwise <| (Disjoint on fun i => (φ i).vars)) : (∑ i ∈ t, φ i).vars = Finset.biUnion t fun i => (φ i).vars := by classical induction t using Finset.induction_on with | empty => simp | insert has hsum => rw [Finset.biUnion_insert, Finset.sum_insert has, vars_add_of_disjoint, hsum] unfold Pairwise onFun at h rw [hsum] simp only [Finset.disjoint_iff_ne] at h ⊢ intro v hv v2 hv2 rw [Finset.mem_biUnion] at hv2 rcases hv2 with ⟨i, his, hi⟩ refine h ?_ _ hv _ hi rintro rfl contradiction #align mv_polynomial.vars_sum_of_disjoint MvPolynomial.vars_sum_of_disjoint end Sum section Map variable [CommSemiring S] (f : R →+* S) variable (p) theorem vars_map : (map f p).vars ⊆ p.vars := by classical simp [vars_def, degrees_map] #align mv_polynomial.vars_map MvPolynomial.vars_map variable {f} theorem vars_map_of_injective (hf : Injective f) : (map f p).vars = p.vars := by simp [vars, degrees_map_of_injective _ hf] #align mv_polynomial.vars_map_of_injective MvPolynomial.vars_map_of_injective theorem vars_monomial_single (i : σ) {e : ℕ} {r : R} (he : e ≠ 0) (hr : r ≠ 0) : (monomial (Finsupp.single i e) r).vars = {i} := by rw [vars_monomial hr, Finsupp.support_single_ne_zero _ he] #align mv_polynomial.vars_monomial_single MvPolynomial.vars_monomial_single
Mathlib/Algebra/MvPolynomial/Variables.lean
231
234
theorem vars_eq_support_biUnion_support [DecidableEq σ] : p.vars = p.support.biUnion Finsupp.support := by
ext i rw [mem_vars, Finset.mem_biUnion]
/- 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.Analysis.Calculus.FDeriv.Add import Mathlib.Analysis.Calculus.FDeriv.Equiv import Mathlib.Analysis.Calculus.FDeriv.Prod import Mathlib.Analysis.Calculus.Monotone import Mathlib.Data.Set.Function import Mathlib.Algebra.Group.Basic import Mathlib.Tactic.WLOG #align_import analysis.bounded_variation from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # Functions of bounded variation We study functions of bounded variation. In particular, we show that a bounded variation function is a difference of monotone functions, and differentiable almost everywhere. This implies that Lipschitz functions from the real line into finite-dimensional vector space are also differentiable almost everywhere. ## Main definitions and results * `eVariationOn f s` is the total variation of the function `f` on the set `s`, in `ℝ≥0∞`. * `BoundedVariationOn f s` registers that the variation of `f` on `s` is finite. * `LocallyBoundedVariationOn f s` registers that `f` has finite variation on any compact subinterval of `s`. * `variationOnFromTo f s a b` is the signed variation of `f` on `s ∩ Icc a b`, converted to `ℝ`. * `eVariationOn.Icc_add_Icc` states that the variation of `f` on `[a, c]` is the sum of its variations on `[a, b]` and `[b, c]`. * `LocallyBoundedVariationOn.exists_monotoneOn_sub_monotoneOn` proves that a function with locally bounded variation is the difference of two monotone functions. * `LipschitzWith.locallyBoundedVariationOn` shows that a Lipschitz function has locally bounded variation. * `LocallyBoundedVariationOn.ae_differentiableWithinAt` shows that a bounded variation function into a finite dimensional real vector space is differentiable almost everywhere. * `LipschitzOnWith.ae_differentiableWithinAt` is the same result for Lipschitz functions. We also give several variations around these results. ## Implementation We define the variation as an extended nonnegative real, to allow for infinite variation. This makes it possible to use the complete linear order structure of `ℝ≥0∞`. The proofs would be much more tedious with an `ℝ`-valued or `ℝ≥0`-valued variation, since one would always need to check that the sets one uses are nonempty and bounded above as these are only conditionally complete. -/ open scoped NNReal ENNReal Topology UniformConvergence open Set MeasureTheory Filter -- Porting note: sectioned variables because a `wlog` was broken due to extra variables in context variable {α : Type*} [LinearOrder α] {E : Type*} [PseudoEMetricSpace E] /-- The (extended real valued) variation of a function `f` on a set `s` inside a linear order is the supremum of the sum of `edist (f (u (i+1))) (f (u i))` over all finite increasing sequences `u` in `s`. -/ noncomputable def eVariationOn (f : α → E) (s : Set α) : ℝ≥0∞ := ⨆ p : ℕ × { u : ℕ → α // Monotone u ∧ ∀ i, u i ∈ s }, ∑ i ∈ Finset.range p.1, edist (f (p.2.1 (i + 1))) (f (p.2.1 i)) #align evariation_on eVariationOn /-- A function has bounded variation on a set `s` if its total variation there is finite. -/ def BoundedVariationOn (f : α → E) (s : Set α) := eVariationOn f s ≠ ∞ #align has_bounded_variation_on BoundedVariationOn /-- A function has locally bounded variation on a set `s` if, given any interval `[a, b]` with endpoints in `s`, then the function has finite variation on `s ∩ [a, b]`. -/ def LocallyBoundedVariationOn (f : α → E) (s : Set α) := ∀ a b, a ∈ s → b ∈ s → BoundedVariationOn f (s ∩ Icc a b) #align has_locally_bounded_variation_on LocallyBoundedVariationOn /-! ## Basic computations of variation -/ namespace eVariationOn theorem nonempty_monotone_mem {s : Set α} (hs : s.Nonempty) : Nonempty { u // Monotone u ∧ ∀ i : ℕ, u i ∈ s } := by obtain ⟨x, hx⟩ := hs exact ⟨⟨fun _ => x, fun i j _ => le_rfl, fun _ => hx⟩⟩ #align evariation_on.nonempty_monotone_mem eVariationOn.nonempty_monotone_mem theorem eq_of_edist_zero_on {f f' : α → E} {s : Set α} (h : ∀ ⦃x⦄, x ∈ s → edist (f x) (f' x) = 0) : eVariationOn f s = eVariationOn f' s := by dsimp only [eVariationOn] congr 1 with p : 1 congr 1 with i : 1 rw [edist_congr_right (h <| p.snd.prop.2 (i + 1)), edist_congr_left (h <| p.snd.prop.2 i)] #align evariation_on.eq_of_edist_zero_on eVariationOn.eq_of_edist_zero_on theorem eq_of_eqOn {f f' : α → E} {s : Set α} (h : EqOn f f' s) : eVariationOn f s = eVariationOn f' s := eq_of_edist_zero_on fun x xs => by rw [h xs, edist_self] #align evariation_on.eq_of_eq_on eVariationOn.eq_of_eqOn theorem sum_le (f : α → E) {s : Set α} (n : ℕ) {u : ℕ → α} (hu : Monotone u) (us : ∀ i, u i ∈ s) : (∑ i ∈ Finset.range n, edist (f (u (i + 1))) (f (u i))) ≤ eVariationOn f s := le_iSup_of_le ⟨n, u, hu, us⟩ le_rfl #align evariation_on.sum_le eVariationOn.sum_le
Mathlib/Analysis/BoundedVariation.lean
107
124
theorem sum_le_of_monotoneOn_Icc (f : α → E) {s : Set α} {m n : ℕ} {u : ℕ → α} (hu : MonotoneOn u (Icc m n)) (us : ∀ i ∈ Icc m n, u i ∈ s) : (∑ i ∈ Finset.Ico m n, edist (f (u (i + 1))) (f (u i))) ≤ eVariationOn f s := by
rcases le_total n m with hnm | hmn · simp [Finset.Ico_eq_empty_of_le hnm] let π := projIcc m n hmn let v i := u (π i) calc ∑ i ∈ Finset.Ico m n, edist (f (u (i + 1))) (f (u i)) = ∑ i ∈ Finset.Ico m n, edist (f (v (i + 1))) (f (v i)) := Finset.sum_congr rfl fun i hi ↦ by rw [Finset.mem_Ico] at hi simp only [v, π, projIcc_of_mem hmn ⟨hi.1, hi.2.le⟩, projIcc_of_mem hmn ⟨hi.1.trans i.le_succ, hi.2⟩] _ ≤ ∑ i ∈ Finset.range n, edist (f (v (i + 1))) (f (v i)) := Finset.sum_mono_set _ (Nat.Iio_eq_range ▸ Finset.Ico_subset_Iio_self) _ ≤ eVariationOn f s := sum_le _ _ (fun i j h ↦ hu (π i).2 (π j).2 (monotone_projIcc hmn h)) fun i ↦ us _ (π i).2
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Analytic.Basic import Mathlib.Analysis.Analytic.CPolynomial import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.Analysis.Calculus.ContDiff.Defs import Mathlib.Analysis.Calculus.FDeriv.Add #align_import analysis.calculus.fderiv_analytic from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # Frechet derivatives of analytic functions. A function expressible as a power series at a point has a Frechet derivative there. Also the special case in terms of `deriv` when the domain is 1-dimensional. As an application, we show that continuous multilinear maps are smooth. We also compute their iterated derivatives, in `ContinuousMultilinearMap.iteratedFDeriv_eq`. -/ open Filter Asymptotics open scoped ENNReal universe u v variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type u} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] section fderiv variable {p : FormalMultilinearSeries 𝕜 E F} {r : ℝ≥0∞} variable {f : E → F} {x : E} {s : Set E} theorem HasFPowerSeriesAt.hasStrictFDerivAt (h : HasFPowerSeriesAt f p x) : HasStrictFDerivAt f (continuousMultilinearCurryFin1 𝕜 E F (p 1)) x := by refine h.isBigO_image_sub_norm_mul_norm_sub.trans_isLittleO (IsLittleO.of_norm_right ?_) refine isLittleO_iff_exists_eq_mul.2 ⟨fun y => ‖y - (x, x)‖, ?_, EventuallyEq.rfl⟩ refine (continuous_id.sub continuous_const).norm.tendsto' _ _ ?_ rw [_root_.id, sub_self, norm_zero] #align has_fpower_series_at.has_strict_fderiv_at HasFPowerSeriesAt.hasStrictFDerivAt theorem HasFPowerSeriesAt.hasFDerivAt (h : HasFPowerSeriesAt f p x) : HasFDerivAt f (continuousMultilinearCurryFin1 𝕜 E F (p 1)) x := h.hasStrictFDerivAt.hasFDerivAt #align has_fpower_series_at.has_fderiv_at HasFPowerSeriesAt.hasFDerivAt theorem HasFPowerSeriesAt.differentiableAt (h : HasFPowerSeriesAt f p x) : DifferentiableAt 𝕜 f x := h.hasFDerivAt.differentiableAt #align has_fpower_series_at.differentiable_at HasFPowerSeriesAt.differentiableAt theorem AnalyticAt.differentiableAt : AnalyticAt 𝕜 f x → DifferentiableAt 𝕜 f x | ⟨_, hp⟩ => hp.differentiableAt #align analytic_at.differentiable_at AnalyticAt.differentiableAt theorem AnalyticAt.differentiableWithinAt (h : AnalyticAt 𝕜 f x) : DifferentiableWithinAt 𝕜 f s x := h.differentiableAt.differentiableWithinAt #align analytic_at.differentiable_within_at AnalyticAt.differentiableWithinAt theorem HasFPowerSeriesAt.fderiv_eq (h : HasFPowerSeriesAt f p x) : fderiv 𝕜 f x = continuousMultilinearCurryFin1 𝕜 E F (p 1) := h.hasFDerivAt.fderiv #align has_fpower_series_at.fderiv_eq HasFPowerSeriesAt.fderiv_eq theorem HasFPowerSeriesOnBall.differentiableOn [CompleteSpace F] (h : HasFPowerSeriesOnBall f p x r) : DifferentiableOn 𝕜 f (EMetric.ball x r) := fun _ hy => (h.analyticAt_of_mem hy).differentiableWithinAt #align has_fpower_series_on_ball.differentiable_on HasFPowerSeriesOnBall.differentiableOn theorem AnalyticOn.differentiableOn (h : AnalyticOn 𝕜 f s) : DifferentiableOn 𝕜 f s := fun y hy => (h y hy).differentiableWithinAt #align analytic_on.differentiable_on AnalyticOn.differentiableOn theorem HasFPowerSeriesOnBall.hasFDerivAt [CompleteSpace F] (h : HasFPowerSeriesOnBall f p x r) {y : E} (hy : (‖y‖₊ : ℝ≥0∞) < r) : HasFDerivAt f (continuousMultilinearCurryFin1 𝕜 E F (p.changeOrigin y 1)) (x + y) := (h.changeOrigin hy).hasFPowerSeriesAt.hasFDerivAt #align has_fpower_series_on_ball.has_fderiv_at HasFPowerSeriesOnBall.hasFDerivAt theorem HasFPowerSeriesOnBall.fderiv_eq [CompleteSpace F] (h : HasFPowerSeriesOnBall f p x r) {y : E} (hy : (‖y‖₊ : ℝ≥0∞) < r) : fderiv 𝕜 f (x + y) = continuousMultilinearCurryFin1 𝕜 E F (p.changeOrigin y 1) := (h.hasFDerivAt hy).fderiv #align has_fpower_series_on_ball.fderiv_eq HasFPowerSeriesOnBall.fderiv_eq /-- If a function has a power series on a ball, then so does its derivative. -/ theorem HasFPowerSeriesOnBall.fderiv [CompleteSpace F] (h : HasFPowerSeriesOnBall f p x r) : HasFPowerSeriesOnBall (fderiv 𝕜 f) p.derivSeries x r := by refine .congr (f := fun z ↦ continuousMultilinearCurryFin1 𝕜 E F (p.changeOrigin (z - x) 1)) ?_ fun z hz ↦ ?_ · refine continuousMultilinearCurryFin1 𝕜 E F |>.toContinuousLinearEquiv.toContinuousLinearMap.comp_hasFPowerSeriesOnBall ?_ simpa using ((p.hasFPowerSeriesOnBall_changeOrigin 1 (h.r_pos.trans_le h.r_le)).mono h.r_pos h.r_le).comp_sub x dsimp only rw [← h.fderiv_eq, add_sub_cancel] simpa only [edist_eq_coe_nnnorm_sub, EMetric.mem_ball] using hz #align has_fpower_series_on_ball.fderiv HasFPowerSeriesOnBall.fderiv /-- If a function is analytic on a set `s`, so is its Fréchet derivative. -/ theorem AnalyticOn.fderiv [CompleteSpace F] (h : AnalyticOn 𝕜 f s) : AnalyticOn 𝕜 (fderiv 𝕜 f) s := by intro y hy rcases h y hy with ⟨p, r, hp⟩ exact hp.fderiv.analyticAt #align analytic_on.fderiv AnalyticOn.fderiv /-- If a function is analytic on a set `s`, so are its successive Fréchet derivative. -/ theorem AnalyticOn.iteratedFDeriv [CompleteSpace F] (h : AnalyticOn 𝕜 f s) (n : ℕ) : AnalyticOn 𝕜 (iteratedFDeriv 𝕜 n f) s := by induction' n with n IH · rw [iteratedFDeriv_zero_eq_comp] exact ((continuousMultilinearCurryFin0 𝕜 E F).symm : F →L[𝕜] E[×0]→L[𝕜] F).comp_analyticOn h · rw [iteratedFDeriv_succ_eq_comp_left] -- Porting note: for reasons that I do not understand at all, `?g` cannot be inlined. convert ContinuousLinearMap.comp_analyticOn ?g IH.fderiv case g => exact ↑(continuousMultilinearCurryLeftEquiv 𝕜 (fun _ : Fin (n + 1) ↦ E) F) simp #align analytic_on.iterated_fderiv AnalyticOn.iteratedFDeriv /-- An analytic function is infinitely differentiable. -/ theorem AnalyticOn.contDiffOn [CompleteSpace F] (h : AnalyticOn 𝕜 f s) {n : ℕ∞} : ContDiffOn 𝕜 n f s := let t := { x | AnalyticAt 𝕜 f x } suffices ContDiffOn 𝕜 n f t from this.mono h have H : AnalyticOn 𝕜 f t := fun _x hx ↦ hx have t_open : IsOpen t := isOpen_analyticAt 𝕜 f contDiffOn_of_continuousOn_differentiableOn (fun m _ ↦ (H.iteratedFDeriv m).continuousOn.congr fun _ hx ↦ iteratedFDerivWithin_of_isOpen _ t_open hx) (fun m _ ↦ (H.iteratedFDeriv m).differentiableOn.congr fun _ hx ↦ iteratedFDerivWithin_of_isOpen _ t_open hx) #align analytic_on.cont_diff_on AnalyticOn.contDiffOn theorem AnalyticAt.contDiffAt [CompleteSpace F] (h : AnalyticAt 𝕜 f x) {n : ℕ∞} : ContDiffAt 𝕜 n f x := by obtain ⟨s, hs, hf⟩ := h.exists_mem_nhds_analyticOn exact hf.contDiffOn.contDiffAt hs end fderiv section deriv variable {p : FormalMultilinearSeries 𝕜 𝕜 F} {r : ℝ≥0∞} variable {f : 𝕜 → F} {x : 𝕜} {s : Set 𝕜} protected theorem HasFPowerSeriesAt.hasStrictDerivAt (h : HasFPowerSeriesAt f p x) : HasStrictDerivAt f (p 1 fun _ => 1) x := h.hasStrictFDerivAt.hasStrictDerivAt #align has_fpower_series_at.has_strict_deriv_at HasFPowerSeriesAt.hasStrictDerivAt protected theorem HasFPowerSeriesAt.hasDerivAt (h : HasFPowerSeriesAt f p x) : HasDerivAt f (p 1 fun _ => 1) x := h.hasStrictDerivAt.hasDerivAt #align has_fpower_series_at.has_deriv_at HasFPowerSeriesAt.hasDerivAt protected theorem HasFPowerSeriesAt.deriv (h : HasFPowerSeriesAt f p x) : deriv f x = p 1 fun _ => 1 := h.hasDerivAt.deriv #align has_fpower_series_at.deriv HasFPowerSeriesAt.deriv /-- If a function is analytic on a set `s`, so is its derivative. -/ theorem AnalyticOn.deriv [CompleteSpace F] (h : AnalyticOn 𝕜 f s) : AnalyticOn 𝕜 (deriv f) s := (ContinuousLinearMap.apply 𝕜 F (1 : 𝕜)).comp_analyticOn h.fderiv #align analytic_on.deriv AnalyticOn.deriv /-- If a function is analytic on a set `s`, so are its successive derivatives. -/ theorem AnalyticOn.iterated_deriv [CompleteSpace F] (h : AnalyticOn 𝕜 f s) (n : ℕ) : AnalyticOn 𝕜 (_root_.deriv^[n] f) s := by induction' n with n IH · exact h · simpa only [Function.iterate_succ', Function.comp_apply] using IH.deriv #align analytic_on.iterated_deriv AnalyticOn.iterated_deriv end deriv section fderiv variable {p : FormalMultilinearSeries 𝕜 E F} {r : ℝ≥0∞} {n : ℕ} variable {f : E → F} {x : E} {s : Set E} /-! The case of continuously polynomial functions. We get the same differentiability results as for analytic functions, but without the assumptions that `F` is complete. -/ theorem HasFiniteFPowerSeriesOnBall.differentiableOn (h : HasFiniteFPowerSeriesOnBall f p x n r) : DifferentiableOn 𝕜 f (EMetric.ball x r) := fun _ hy ↦ (h.cPolynomialAt_of_mem hy).analyticAt.differentiableWithinAt theorem HasFiniteFPowerSeriesOnBall.hasFDerivAt (h : HasFiniteFPowerSeriesOnBall f p x n r) {y : E} (hy : (‖y‖₊ : ℝ≥0∞) < r) : HasFDerivAt f (continuousMultilinearCurryFin1 𝕜 E F (p.changeOrigin y 1)) (x + y) := (h.changeOrigin hy).toHasFPowerSeriesOnBall.hasFPowerSeriesAt.hasFDerivAt theorem HasFiniteFPowerSeriesOnBall.fderiv_eq (h : HasFiniteFPowerSeriesOnBall f p x n r) {y : E} (hy : (‖y‖₊ : ℝ≥0∞) < r) : fderiv 𝕜 f (x + y) = continuousMultilinearCurryFin1 𝕜 E F (p.changeOrigin y 1) := (h.hasFDerivAt hy).fderiv /-- If a function has a finite power series on a ball, then so does its derivative. -/ protected theorem HasFiniteFPowerSeriesOnBall.fderiv (h : HasFiniteFPowerSeriesOnBall f p x (n + 1) r) : HasFiniteFPowerSeriesOnBall (fderiv 𝕜 f) p.derivSeries x n r := by refine .congr (f := fun z ↦ continuousMultilinearCurryFin1 𝕜 E F (p.changeOrigin (z - x) 1)) ?_ fun z hz ↦ ?_ · refine continuousMultilinearCurryFin1 𝕜 E F |>.toContinuousLinearEquiv.toContinuousLinearMap.comp_hasFiniteFPowerSeriesOnBall ?_ simpa using ((p.hasFiniteFPowerSeriesOnBall_changeOrigin 1 h.finite).mono h.r_pos le_top).comp_sub x dsimp only rw [← h.fderiv_eq, add_sub_cancel] simpa only [edist_eq_coe_nnnorm_sub, EMetric.mem_ball] using hz /-- If a function has a finite power series on a ball, then so does its derivative. This is a variant of `HasFiniteFPowerSeriesOnBall.fderiv` where the degree of `f` is `< n` and not `< n + 1`. -/ theorem HasFiniteFPowerSeriesOnBall.fderiv' (h : HasFiniteFPowerSeriesOnBall f p x n r) : HasFiniteFPowerSeriesOnBall (fderiv 𝕜 f) p.derivSeries x (n - 1) r := by obtain rfl | hn := eq_or_ne n 0 · rw [zero_tsub] refine HasFiniteFPowerSeriesOnBall.bound_zero_of_eq_zero (fun y hy ↦ ?_) h.r_pos fun n ↦ ?_ · rw [Filter.EventuallyEq.fderiv_eq (f := fun _ ↦ 0)] · rw [fderiv_const, Pi.zero_apply] · exact Filter.eventuallyEq_iff_exists_mem.mpr ⟨EMetric.ball x r, EMetric.isOpen_ball.mem_nhds hy, fun z hz ↦ by rw [h.eq_zero_of_bound_zero z hz]⟩ · apply ContinuousMultilinearMap.ext; intro a change (continuousMultilinearCurryFin1 𝕜 E F) (p.changeOriginSeries 1 n a) = 0 rw [p.changeOriginSeries_finite_of_finite h.finite 1 (Nat.zero_le _)] exact map_zero _ · rw [← Nat.succ_pred hn] at h exact h.fderiv /-- If a function is polynomial on a set `s`, so is its Fréchet derivative. -/ theorem CPolynomialOn.fderiv (h : CPolynomialOn 𝕜 f s) : CPolynomialOn 𝕜 (fderiv 𝕜 f) s := by intro y hy rcases h y hy with ⟨p, r, n, hp⟩ exact hp.fderiv'.cPolynomialAt /-- If a function is polynomial on a set `s`, so are its successive Fréchet derivative. -/ theorem CPolynomialOn.iteratedFDeriv (h : CPolynomialOn 𝕜 f s) (n : ℕ) : CPolynomialOn 𝕜 (iteratedFDeriv 𝕜 n f) s := by induction' n with n IH · rw [iteratedFDeriv_zero_eq_comp] exact ((continuousMultilinearCurryFin0 𝕜 E F).symm : F →L[𝕜] E[×0]→L[𝕜] F).comp_cPolynomialOn h · rw [iteratedFDeriv_succ_eq_comp_left] convert ContinuousLinearMap.comp_cPolynomialOn ?g IH.fderiv case g => exact ↑(continuousMultilinearCurryLeftEquiv 𝕜 (fun _ : Fin (n + 1) ↦ E) F) simp /-- A polynomial function is infinitely differentiable. -/ theorem CPolynomialOn.contDiffOn (h : CPolynomialOn 𝕜 f s) {n : ℕ∞} : ContDiffOn 𝕜 n f s := let t := { x | CPolynomialAt 𝕜 f x } suffices ContDiffOn 𝕜 n f t from this.mono h have H : CPolynomialOn 𝕜 f t := fun _x hx ↦ hx have t_open : IsOpen t := isOpen_cPolynomialAt 𝕜 f contDiffOn_of_continuousOn_differentiableOn (fun m _ ↦ (H.iteratedFDeriv m).continuousOn.congr fun _ hx ↦ iteratedFDerivWithin_of_isOpen _ t_open hx) (fun m _ ↦ (H.iteratedFDeriv m).analyticOn.differentiableOn.congr fun _ hx ↦ iteratedFDerivWithin_of_isOpen _ t_open hx) theorem CPolynomialAt.contDiffAt (h : CPolynomialAt 𝕜 f x) {n : ℕ∞} : ContDiffAt 𝕜 n f x := let ⟨_, hs, hf⟩ := h.exists_mem_nhds_cPolynomialOn hf.contDiffOn.contDiffAt hs end fderiv section deriv variable {p : FormalMultilinearSeries 𝕜 𝕜 F} {r : ℝ≥0∞} variable {f : 𝕜 → F} {x : 𝕜} {s : Set 𝕜} /-- If a function is polynomial on a set `s`, so is its derivative. -/ protected theorem CPolynomialOn.deriv (h : CPolynomialOn 𝕜 f s) : CPolynomialOn 𝕜 (deriv f) s := (ContinuousLinearMap.apply 𝕜 F (1 : 𝕜)).comp_cPolynomialOn h.fderiv /-- If a function is polynomial on a set `s`, so are its successive derivatives. -/ theorem CPolynomialOn.iterated_deriv (h : CPolynomialOn 𝕜 f s) (n : ℕ) : CPolynomialOn 𝕜 (deriv^[n] f) s := by induction' n with n IH · exact h · simpa only [Function.iterate_succ', Function.comp_apply] using IH.deriv end deriv namespace ContinuousMultilinearMap variable {ι : Type*} {E : ι → Type*} [∀ i, NormedAddCommGroup (E i)] [∀ i, NormedSpace 𝕜 (E i)] [Fintype ι] (f : ContinuousMultilinearMap 𝕜 E F) open FormalMultilinearSeries protected theorem hasFiniteFPowerSeriesOnBall : HasFiniteFPowerSeriesOnBall f f.toFormalMultilinearSeries 0 (Fintype.card ι + 1) ⊤ := .mk' (fun m hm ↦ dif_neg (Nat.succ_le_iff.mp hm).ne) ENNReal.zero_lt_top fun y _ ↦ by rw [Finset.sum_eq_single_of_mem _ (Finset.self_mem_range_succ _), zero_add] · rw [toFormalMultilinearSeries, dif_pos rfl]; rfl · intro m _ ne; rw [toFormalMultilinearSeries, dif_neg ne.symm]; rfl theorem changeOriginSeries_support {k l : ℕ} (h : k + l ≠ Fintype.card ι) : f.toFormalMultilinearSeries.changeOriginSeries k l = 0 := Finset.sum_eq_zero fun _ _ ↦ by simp_rw [FormalMultilinearSeries.changeOriginSeriesTerm, toFormalMultilinearSeries, dif_neg h.symm, LinearIsometryEquiv.map_zero] variable {n : ℕ∞} (x : ∀ i, E i) open Finset in
Mathlib/Analysis/Calculus/FDeriv/Analytic.lean
314
346
theorem changeOrigin_toFormalMultilinearSeries [DecidableEq ι] : continuousMultilinearCurryFin1 𝕜 (∀ i, E i) F (f.toFormalMultilinearSeries.changeOrigin x 1) = f.linearDeriv x := by
ext y rw [continuousMultilinearCurryFin1_apply, linearDeriv_apply, changeOrigin, FormalMultilinearSeries.sum] cases isEmpty_or_nonempty ι · have (l) : 1 + l ≠ Fintype.card ι := by rw [add_comm, Fintype.card_eq_zero]; exact Nat.succ_ne_zero _ simp_rw [Fintype.sum_empty, changeOriginSeries_support _ (this _), zero_apply _, tsum_zero]; rfl rw [tsum_eq_single (Fintype.card ι - 1), changeOriginSeries]; swap · intro m hm rw [Ne, eq_tsub_iff_add_eq_of_le (by exact Fintype.card_pos), add_comm] at hm rw [f.changeOriginSeries_support hm, zero_apply] rw [sum_apply, ContinuousMultilinearMap.sum_apply, Fin.snoc_zero] simp_rw [changeOriginSeriesTerm_apply] refine (Fintype.sum_bijective (?_ ∘ Fintype.equivFinOfCardEq (Nat.add_sub_of_le Fintype.card_pos).symm) (.comp ?_ <| Equiv.bijective _) _ _ fun i ↦ ?_).symm · exact (⟨{·}ᶜ, by rw [card_compl, Fintype.card_fin, card_singleton, Nat.add_sub_cancel_left]⟩) · use fun _ _ ↦ (singleton_injective <| compl_injective <| Subtype.ext_iff.mp ·) intro ⟨s, hs⟩ have h : sᶜ.card = 1 := by rw [card_compl, hs, Fintype.card_fin, Nat.add_sub_cancel] obtain ⟨a, ha⟩ := card_eq_one.mp h exact ⟨a, Subtype.ext (compl_eq_comm.mp ha)⟩ rw [Function.comp_apply, Subtype.coe_mk, compl_singleton, piecewise_erase_univ, toFormalMultilinearSeries, dif_pos (Nat.add_sub_of_le Fintype.card_pos).symm] simp_rw [domDomCongr_apply, compContinuousLinearMap_apply, ContinuousLinearMap.proj_apply, Function.update_apply, (Equiv.injective _).eq_iff, ite_apply] congr; ext j obtain rfl | hj := eq_or_ne j i · rw [Function.update_same, if_pos rfl] · rw [Function.update_noteq hj, if_neg hj]
/- Copyright (c) 2023 Scott Carnahan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Carnahan -/ import Mathlib.Algebra.Group.NatPowAssoc import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Induction import Mathlib.Algebra.Polynomial.Eval /-! # Scalar-multiple polynomial evaluation This file defines polynomial evaluation via scalar multiplication. Our polynomials have coefficients in a semiring `R`, and we evaluate at a weak form of `R`-algebra, namely an additive commutative monoid with an action of `R` and a notion of natural number power. This is a generalization of `Algebra.Polynomial.Eval`. ## Main definitions * `Polynomial.smeval`: function for evaluating a polynomial with coefficients in a `Semiring` `R` at an element `x` of an `AddCommMonoid` `S` that has natural number powers and an `R`-action. * `smeval.linearMap`: the `smeval` function as an `R`-linear map, when `S` is an `R`-module. * `smeval.algebraMap`: the `smeval` function as an `R`-algebra map, when `S` is an `R`-algebra. ## Main results * `smeval_monomial`: monomials evaluate as we expect. * `smeval_add`, `smeval_smul`: linearity of evaluation, given an `R`-module. * `smeval_mul`, `smeval_comp`: multiplicativity of evaluation, given power-associativity. * `eval₂_eq_smeval`, `leval_eq_smeval.linearMap`, `aeval = smeval.algebraMap`, etc.: comparisons ## To do * `smeval_neg` and `smeval_intCast` for `R` a ring and `S` an `AddCommGroup`. * Nonunital evaluation for polynomials with vanishing constant term for `Pow S ℕ+` (different file?) -/ namespace Polynomial section MulActionWithZero variable {R : Type*} [Semiring R] (r : R) (p : R[X]) {S : Type*} [AddCommMonoid S] [Pow S ℕ] [MulActionWithZero R S] (x : S) /-- Scalar multiplication together with taking a natural number power. -/ def smul_pow : ℕ → R → S := fun n r => r • x^n /-- Evaluate a polynomial `p` in the scalar semiring `R` at an element `x` in the target `S` using scalar multiple `R`-action. -/ irreducible_def smeval : S := p.sum (smul_pow x) theorem smeval_eq_sum : p.smeval x = p.sum (smul_pow x) := by rw [smeval_def] @[simp] theorem smeval_C : (C r).smeval x = r • x ^ 0 := by simp only [smeval_eq_sum, smul_pow, zero_smul, sum_C_index] @[simp] theorem smeval_monomial (n : ℕ) : (monomial n r).smeval x = r • x ^ n := by simp only [smeval_eq_sum, smul_pow, zero_smul, sum_monomial_index] theorem eval_eq_smeval : p.eval r = p.smeval r := by rw [eval_eq_sum, smeval_eq_sum] rfl theorem eval₂_eq_smeval (R : Type*) [Semiring R] {S : Type*} [Semiring S] (f : R →+* S) (p : R[X]) (x: S) : letI : Module R S := RingHom.toModule f p.eval₂ f x = p.smeval x := by letI : Module R S := RingHom.toModule f rw [smeval_eq_sum, eval₂_eq_sum] rfl variable (R) @[simp] theorem smeval_zero : (0 : R[X]).smeval x = 0 := by simp only [smeval_eq_sum, smul_pow, sum_zero_index] @[simp] theorem smeval_one : (1 : R[X]).smeval x = 1 • x ^ 0 := by rw [← C_1, smeval_C] simp only [Nat.cast_one, one_smul] @[simp] theorem smeval_X : (X : R[X]).smeval x = x ^ 1 := by simp only [smeval_eq_sum, smul_pow, zero_smul, sum_X_index, one_smul] @[simp] theorem smeval_X_pow {n : ℕ} : (X ^ n : R[X]).smeval x = x ^ n := by simp only [smeval_eq_sum, smul_pow, X_pow_eq_monomial, zero_smul, sum_monomial_index, one_smul] end MulActionWithZero section Module variable (R : Type*) [Semiring R] (p q : R[X]) {S : Type*} [AddCommMonoid S] [Pow S ℕ] [Module R S] (x : S) @[simp] theorem smeval_add : (p + q).smeval x = p.smeval x + q.smeval x := by simp only [smeval_eq_sum, smul_pow] refine sum_add_index p q (smul_pow x) (fun _ ↦ ?_) (fun _ _ _ ↦ ?_) · rw [smul_pow, zero_smul] · rw [smul_pow, smul_pow, smul_pow, add_smul] theorem smeval_natCast (n : ℕ) : (n : R[X]).smeval x = n • x ^ 0 := by induction' n with n ih · simp only [smeval_zero, Nat.cast_zero, Nat.zero_eq, zero_smul] · rw [n.cast_succ, smeval_add, ih, smeval_one, ← add_nsmul] @[deprecated (since := "2024-04-17")] alias smeval_nat_cast := smeval_natCast @[simp] theorem smeval_smul (r : R) : (r • p).smeval x = r • p.smeval x := by induction p using Polynomial.induction_on' with | h_add p q ph qh => rw [smul_add, smeval_add, ph, qh, ← smul_add, smeval_add] | h_monomial n a => rw [smul_monomial, smeval_monomial, smeval_monomial, smul_assoc] /-- `Polynomial.smeval` as a linear map. -/ def smeval.linearMap : R[X] →ₗ[R] S where toFun f := f.smeval x map_add' f g := by simp only [smeval_add] map_smul' c f := by simp only [smeval_smul, smul_eq_mul, RingHom.id_apply] @[simp] theorem smeval.linearMap_apply : smeval.linearMap R x p = p.smeval x := rfl theorem leval_coe_eq_smeval {R : Type*} [Semiring R] (r : R) : ⇑(leval r) = fun p => p.smeval r := by rw [Function.funext_iff] intro rw [leval_apply, smeval_def, eval_eq_sum] rfl theorem leval_eq_smeval.linearMap {R : Type*} [Semiring R] (r : R) : leval r = smeval.linearMap R r := by refine LinearMap.ext ?_ intro rw [leval_apply, smeval.linearMap_apply, eval_eq_smeval] end Module section Neg variable (R : Type*) [Ring R] {S : Type*} [AddCommGroup S] [Pow S ℕ] [Module R S] (p q : R[X]) (x : S) @[simp] theorem smeval_neg : (-p).smeval x = - p.smeval x := by have h : (p + -p).smeval x = 0 := by rw [add_neg_self, smeval_zero] rw [smeval_add, add_eq_zero_iff_neg_eq] at h exact id h.symm @[simp] theorem smeval_sub : (p - q).smeval x = p.smeval x - q.smeval x := by rw [sub_eq_add_neg, smeval_add, smeval_neg, sub_eq_add_neg] end Neg section NatPowAssoc /-! In the module docstring for algebras at `Mathlib.Algebra.Algebra.Basic`, we see that `[CommSemiring R] [Semiring S] [Module R S] [IsScalarTower R S S] [SMulCommClass R S S]` is an equivalent way to express `[CommSemiring R] [Semiring S] [Algebra R S]` that allows one to relax the defining structures independently. For non-associative power-associative algebras (e.g., octonions), we replace the `[Semiring S]` with `[NonAssocSemiring S] [Pow S ℕ] [NatPowAssoc S]`. -/ variable (R : Type*) [Semiring R] {p : R[X]} (r : R) (p q : R[X]) {S : Type*} [NonAssocSemiring S] [Module R S] [IsScalarTower R S S] [SMulCommClass R S S] [Pow S ℕ] [NatPowAssoc S] (x : S) theorem smeval_at_natCast (q : ℕ[X]): ∀(n : ℕ), q.smeval (n : S) = q.smeval n := by induction q using Polynomial.induction_on' with | h_add p q ph qh => intro n simp only [add_mul, smeval_add, ph, qh, Nat.cast_add] | h_monomial n a => intro n rw [smeval_monomial, smeval_monomial, nsmul_eq_mul, smul_eq_mul, Nat.cast_mul, Nat.cast_npow] @[deprecated (since := "2024-04-17")] alias smeval_at_nat_cast := smeval_at_natCast
Mathlib/Algebra/Polynomial/Smeval.lean
194
202
theorem smeval_at_zero : p.smeval (0 : S) = (p.coeff 0) • (1 : S) := by
induction p using Polynomial.induction_on' with | h_add p q ph qh => simp_all only [smeval_add, coeff_add, add_smul] | h_monomial n a => cases n with | zero => simp only [Nat.zero_eq, monomial_zero_left, smeval_C, npow_zero, coeff_C_zero] | succ n => rw [coeff_monomial_succ, smeval_monomial, npow_add, npow_one, mul_zero, zero_smul, smul_zero]
/- Copyright (c) 2024 Raghuram Sundararajan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Raghuram Sundararajan -/ import Mathlib.Algebra.Ring.Defs import Mathlib.Algebra.Group.Ext /-! # Extensionality lemmas for rings and similar structures In this file we prove extensionality lemmas for the ring-like structures defined in `Mathlib/Algebra/Ring/Defs.lean`, ranging from `NonUnitalNonAssocSemiring` to `CommRing`. These extensionality lemmas take the form of asserting that two algebraic structures on a type are equal whenever the addition and multiplication defined by them are both the same. ## Implementation details We follow `Mathlib/Algebra/Group/Ext.lean` in using the term `(letI := i; HMul.hMul : R → R → R)` to refer to the multiplication specified by a typeclass instance `i` on a type `R` (and similarly for addition). We abbreviate these using some local notations. Since `Mathlib/Algebra/Group/Ext.lean` proved several injectivity lemmas, we do so as well — even if sometimes we don't need them to prove extensionality. ## Tags semiring, ring, extensionality -/ local macro:max "local_hAdd[" type:term ", " inst:term "]" : term => `(term| (letI := $inst; HAdd.hAdd : $type → $type → $type)) local macro:max "local_hMul[" type:term ", " inst:term "]" : term => `(term| (letI := $inst; HMul.hMul : $type → $type → $type)) universe u variable {R : Type u} /-! ### Distrib -/ namespace Distrib @[ext] theorem ext ⦃inst₁ inst₂ : Distrib R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by -- Split into `add` and `mul` functions and properties. rcases inst₁ with @⟨⟨⟩, ⟨⟩⟩ rcases inst₂ with @⟨⟨⟩, ⟨⟩⟩ -- Prove equality of parts using function extensionality. congr theorem ext_iff {inst₁ inst₂ : Distrib R} : inst₁ = inst₂ ↔ (local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) ∧ (local_hMul[R, inst₁] = local_hMul[R, inst₂]) := ⟨by rintro rfl; constructor <;> rfl, And.elim (ext · ·)⟩ end Distrib /-! ### NonUnitalNonAssocSemiring -/ namespace NonUnitalNonAssocSemiring @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalNonAssocSemiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by -- Split into `AddMonoid` instance, `mul` function and properties. rcases inst₁ with @⟨_, ⟨⟩⟩ rcases inst₂ with @⟨_, ⟨⟩⟩ -- Prove equality of parts using already-proved extensionality lemmas. congr; ext : 1; assumption theorem toDistrib_injective : Function.Injective (@toDistrib R) := by intro _ _ h ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h theorem ext_iff {inst₁ inst₂ : NonUnitalNonAssocSemiring R} : inst₁ = inst₂ ↔ (local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) ∧ (local_hMul[R, inst₁] = local_hMul[R, inst₂]) := ⟨by rintro rfl; constructor <;> rfl, And.elim (ext · ·)⟩ end NonUnitalNonAssocSemiring /-! ### NonUnitalSemiring -/ namespace NonUnitalSemiring theorem toNonUnitalNonAssocSemiring_injective : Function.Injective (@toNonUnitalNonAssocSemiring R) := by rintro ⟨⟩ ⟨⟩ _; congr @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalSemiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := toNonUnitalNonAssocSemiring_injective <| NonUnitalNonAssocSemiring.ext h_add h_mul theorem ext_iff {inst₁ inst₂ : NonUnitalSemiring R} : inst₁ = inst₂ ↔ (local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) ∧ (local_hMul[R, inst₁] = local_hMul[R, inst₂]) := ⟨by rintro rfl; constructor <;> rfl, And.elim (ext · ·)⟩ end NonUnitalSemiring /-! ### NonAssocSemiring and its ancestors This section also includes results for `AddMonoidWithOne`, `AddCommMonoidWithOne`, etc. as these are considered implementation detail of the ring classes. TODO consider relocating these lemmas. -/ /- TODO consider relocating these lemmas. -/ @[ext] theorem AddMonoidWithOne.ext ⦃inst₁ inst₂ : AddMonoidWithOne R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_one : (letI := inst₁; One.one : R) = (letI := inst₂; One.one : R)) : inst₁ = inst₂ := by have h_monoid : inst₁.toAddMonoid = inst₂.toAddMonoid := by ext : 1; exact h_add have h_zero' : inst₁.toZero = inst₂.toZero := congrArg (·.toZero) h_monoid have h_one' : inst₁.toOne = inst₂.toOne := congrArg One.mk h_one have h_natCast : inst₁.toNatCast.natCast = inst₂.toNatCast.natCast := by funext n; induction n with | zero => rewrite [inst₁.natCast_zero, inst₂.natCast_zero] exact congrArg (@Zero.zero R) h_zero' | succ n h => rw [inst₁.natCast_succ, inst₂.natCast_succ, h_add] exact congrArg₂ _ h h_one rcases inst₁ with @⟨⟨⟩⟩; rcases inst₂ with @⟨⟨⟩⟩ congr theorem AddCommMonoidWithOne.toAddMonoidWithOne_injective : Function.Injective (@AddCommMonoidWithOne.toAddMonoidWithOne R) := by rintro ⟨⟩ ⟨⟩ _; congr @[ext] theorem AddCommMonoidWithOne.ext ⦃inst₁ inst₂ : AddCommMonoidWithOne R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_one : (letI := inst₁; One.one : R) = (letI := inst₂; One.one : R)) : inst₁ = inst₂ := AddCommMonoidWithOne.toAddMonoidWithOne_injective <| AddMonoidWithOne.ext h_add h_one namespace NonAssocSemiring /- The best place to prove that the `NatCast` is determined by the other operations is probably in an extensionality lemma for `AddMonoidWithOne`, in which case we may as well do the typeclasses defined in `Mathlib/Algebra/GroupWithZero/Defs.lean` as well. -/ @[ext] theorem ext ⦃inst₁ inst₂ : NonAssocSemiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by have h : inst₁.toNonUnitalNonAssocSemiring = inst₂.toNonUnitalNonAssocSemiring := by ext : 1 <;> assumption have h_zero : (inst₁.toMulZeroClass).toZero.zero = (inst₂.toMulZeroClass).toZero.zero := congrArg (fun inst => (inst.toMulZeroClass).toZero.zero) h have h_one' : (inst₁.toMulZeroOneClass).toMulOneClass.toOne = (inst₂.toMulZeroOneClass).toMulOneClass.toOne := congrArg (@MulOneClass.toOne R) <| by ext : 1; exact h_mul have h_one : (inst₁.toMulZeroOneClass).toMulOneClass.toOne.one = (inst₂.toMulZeroOneClass).toMulOneClass.toOne.one := congrArg (@One.one R) h_one' have : inst₁.toAddCommMonoidWithOne = inst₂.toAddCommMonoidWithOne := by ext : 1 <;> assumption have : inst₁.toNatCast = inst₂.toNatCast := congrArg (·.toNatCast) this -- Split into `NonUnitalNonAssocSemiring`, `One` and `natCast` instances. cases inst₁; cases inst₂ congr theorem toNonUnitalNonAssocSemiring_injective : Function.Injective (@toNonUnitalNonAssocSemiring R) := by intro _ _ _ ext <;> congr theorem ext_iff {inst₁ inst₂ : NonAssocSemiring R} : inst₁ = inst₂ ↔ (local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) ∧ (local_hMul[R, inst₁] = local_hMul[R, inst₂]) := ⟨by rintro rfl; constructor <;> rfl, And.elim (ext · ·)⟩ end NonAssocSemiring /-! ### NonUnitalNonAssocRing -/ namespace NonUnitalNonAssocRing @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalNonAssocRing R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by -- Split into `AddCommGroup` instance, `mul` function and properties. rcases inst₁ with @⟨_, ⟨⟩⟩; rcases inst₂ with @⟨_, ⟨⟩⟩ congr; (ext : 1; assumption) theorem toNonUnitalNonAssocSemiring_injective : Function.Injective (@toNonUnitalNonAssocSemiring R) := by intro _ _ h -- Use above extensionality lemma to prove injectivity by showing that `h_add` and `h_mul` hold. ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h theorem ext_iff {inst₁ inst₂ : NonUnitalNonAssocRing R} : inst₁ = inst₂ ↔ (local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) ∧ (local_hMul[R, inst₁] = local_hMul[R, inst₂]) := ⟨by rintro rfl; constructor <;> rfl, And.elim (ext · ·)⟩ end NonUnitalNonAssocRing /-! ### NonUnitalRing -/ namespace NonUnitalRing @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalRing R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by have : inst₁.toNonUnitalNonAssocRing = inst₂.toNonUnitalNonAssocRing := by ext : 1 <;> assumption -- Split into fields and prove they are equal using the above. cases inst₁; cases inst₂ congr theorem toNonUnitalSemiring_injective : Function.Injective (@toNonUnitalSemiring R) := by intro _ _ h ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h theorem toNonUnitalNonAssocring_injective : Function.Injective (@toNonUnitalNonAssocRing R) := by intro _ _ _ ext <;> congr theorem ext_iff {inst₁ inst₂ : NonUnitalRing R} : inst₁ = inst₂ ↔ (local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) ∧ (local_hMul[R, inst₁] = local_hMul[R, inst₂]) := ⟨by rintro rfl; constructor <;> rfl, And.elim (ext · ·)⟩ end NonUnitalRing /-! ### NonAssocRing and its ancestors This section also includes results for `AddGroupWithOne`, `AddCommGroupWithOne`, etc. as these are considered implementation detail of the ring classes. TODO consider relocating these lemmas. -/ @[ext] theorem AddGroupWithOne.ext ⦃inst₁ inst₂ : AddGroupWithOne R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_one : (letI := inst₁; One.one : R) = (letI := inst₂; One.one)) : inst₁ = inst₂ := by have : inst₁.toAddMonoidWithOne = inst₂.toAddMonoidWithOne := AddMonoidWithOne.ext h_add h_one have : inst₁.toNatCast = inst₂.toNatCast := congrArg (·.toNatCast) this have h_group : inst₁.toAddGroup = inst₂.toAddGroup := by ext : 1; exact h_add -- Extract equality of necessary substructures from h_group injection h_group with h_group; injection h_group have : inst₁.toIntCast.intCast = inst₂.toIntCast.intCast := by funext n; cases n with | ofNat n => rewrite [Int.ofNat_eq_coe, inst₁.intCast_ofNat, inst₂.intCast_ofNat]; congr | negSucc n => rewrite [inst₁.intCast_negSucc, inst₂.intCast_negSucc]; congr rcases inst₁ with @⟨⟨⟩⟩; rcases inst₂ with @⟨⟨⟩⟩ congr @[ext] theorem AddCommGroupWithOne.ext ⦃inst₁ inst₂ : AddCommGroupWithOne R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_one : (letI := inst₁; One.one : R) = (letI := inst₂; One.one)) : inst₁ = inst₂ := by have : inst₁.toAddCommGroup = inst₂.toAddCommGroup := AddCommGroup.ext h_add have : inst₁.toAddGroupWithOne = inst₂.toAddGroupWithOne := AddGroupWithOne.ext h_add h_one injection this with _ h_addMonoidWithOne; injection h_addMonoidWithOne cases inst₁; cases inst₂ congr namespace NonAssocRing @[ext] theorem ext ⦃inst₁ inst₂ : NonAssocRing R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by have h₁ : inst₁.toNonUnitalNonAssocRing = inst₂.toNonUnitalNonAssocRing := by ext : 1 <;> assumption have h₂ : inst₁.toNonAssocSemiring = inst₂.toNonAssocSemiring := by ext : 1 <;> assumption -- Mathematically non-trivial fact: `intCast` is determined by the rest. have h₃ : inst₁.toAddCommGroupWithOne = inst₂.toAddCommGroupWithOne := AddCommGroupWithOne.ext h_add (congrArg (·.toOne.one) h₂) cases inst₁; cases inst₂ congr <;> solve| injection h₁ | injection h₂ | injection h₃ theorem toNonAssocSemiring_injective : Function.Injective (@toNonAssocSemiring R) := by intro _ _ h ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h theorem toNonUnitalNonAssocring_injective : Function.Injective (@toNonUnitalNonAssocRing R) := by intro _ _ _ ext <;> congr theorem ext_iff {inst₁ inst₂ : NonAssocRing R} : inst₁ = inst₂ ↔ (local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) ∧ (local_hMul[R, inst₁] = local_hMul[R, inst₂]) := ⟨by rintro rfl; constructor <;> rfl, And.elim (ext · ·)⟩ end NonAssocRing /-! ### Semiring -/ namespace Semiring @[ext] theorem ext ⦃inst₁ inst₂ : Semiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by -- Show that enough substructures are equal. have h₁ : inst₁.toNonUnitalSemiring = inst₂.toNonUnitalSemiring := by ext : 1 <;> assumption have h₂ : inst₁.toNonAssocSemiring = inst₂.toNonAssocSemiring := by ext : 1 <;> assumption have h₃ : (inst₁.toMonoidWithZero).toMonoid = (inst₂.toMonoidWithZero).toMonoid := by ext : 1; exact h_mul -- Split into fields and prove they are equal using the above. cases inst₁; cases inst₂ congr <;> solve| injection h₁ | injection h₂ | injection h₃ theorem toNonUnitalSemiring_injective : Function.Injective (@toNonUnitalSemiring R) := by intro _ _ h ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h
Mathlib/Algebra/Ring/Ext.lean
339
344
theorem toNonAssocSemiring_injective : Function.Injective (@toNonAssocSemiring R) := by
intro _ _ h ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) 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 -/ import Mathlib.Topology.Algebra.InfiniteSum.Group import Mathlib.Logic.Encodable.Lattice /-! # Infinite sums and products over `ℕ` and `ℤ` This file contains lemmas about `HasSum`, `Summable`, `tsum`, `HasProd`, `Multipliable`, and `tprod` applied to the important special cases where the domain is `ℕ` or `ℤ`. For instance, we prove the formula `∑ i ∈ range k, f i + ∑' i, f (i + k) = ∑' i, f i`, ∈ `sum_add_tsum_nat_add`, as well as several results relating sums and products on `ℕ` to sums and products on `ℤ`. -/ noncomputable section open Filter Finset Function Encodable open scoped Topology variable {M : Type*} [CommMonoid M] [TopologicalSpace M] {m m' : M} variable {G : Type*} [CommGroup G] {g g' : G} -- don't declare [TopologicalAddGroup G] here as some results require [UniformAddGroup G] instead /-! ## Sums over `ℕ` -/ section Nat section Monoid namespace HasProd /-- If `f : ℕ → M` has product `m`, then the partial products `∏ i ∈ range n, f i` converge to `m`. -/ @[to_additive "If `f : ℕ → M` has sum `m`, then the partial sums `∑ i ∈ range n, f i` converge to `m`."] theorem tendsto_prod_nat {f : ℕ → M} (h : HasProd f m) : Tendsto (fun n ↦ ∏ i ∈ range n, f i) atTop (𝓝 m) := h.comp tendsto_finset_range #align has_sum.tendsto_sum_nat HasSum.tendsto_sum_nat /-- If `f : ℕ → M` is multipliable, then the partial products `∏ i ∈ range n, f i` converge to `∏' i, f i`. -/ @[to_additive "If `f : ℕ → M` is summable, then the partial sums `∑ i ∈ range n, f i` converge to `∑' i, f i`."] theorem Multipliable.tendsto_prod_tprod_nat {f : ℕ → M} (h : Multipliable f) : Tendsto (fun n ↦ ∏ i ∈ range n, f i) atTop (𝓝 (∏' i, f i)) := tendsto_prod_nat h.hasProd section ContinuousMul variable [ContinuousMul M] @[to_additive] theorem prod_range_mul {f : ℕ → M} {k : ℕ} (h : HasProd (fun n ↦ f (n + k)) m) : HasProd f ((∏ i ∈ range k, f i) * m) := by refine ((range k).hasProd f).mul_compl ?_ rwa [← (notMemRangeEquiv k).symm.hasProd_iff] @[to_additive] theorem zero_mul {f : ℕ → M} (h : HasProd (fun n ↦ f (n + 1)) m) : HasProd f (f 0 * m) := by simpa only [prod_range_one] using h.prod_range_mul @[to_additive] theorem even_mul_odd {f : ℕ → M} (he : HasProd (fun k ↦ f (2 * k)) m) (ho : HasProd (fun k ↦ f (2 * k + 1)) m') : HasProd f (m * m') := by have := mul_right_injective₀ (two_ne_zero' ℕ) replace ho := ((add_left_injective 1).comp this).hasProd_range_iff.2 ho refine (this.hasProd_range_iff.2 he).mul_isCompl ?_ ho simpa [(· ∘ ·)] using Nat.isCompl_even_odd #align has_sum.even_add_odd HasSum.even_add_odd end ContinuousMul end HasProd namespace Multipliable @[to_additive] theorem hasProd_iff_tendsto_nat [T2Space M] {f : ℕ → M} (hf : Multipliable f) : HasProd f m ↔ Tendsto (fun n : ℕ ↦ ∏ i ∈ range n, f i) atTop (𝓝 m) := by refine ⟨fun h ↦ h.tendsto_prod_nat, fun h ↦ ?_⟩ rw [tendsto_nhds_unique h hf.hasProd.tendsto_prod_nat] exact hf.hasProd #align summable.has_sum_iff_tendsto_nat Summable.hasSum_iff_tendsto_nat section ContinuousMul variable [ContinuousMul M] @[to_additive] theorem comp_nat_add {f : ℕ → M} {k : ℕ} (h : Multipliable fun n ↦ f (n + k)) : Multipliable f := h.hasProd.prod_range_mul.multipliable @[to_additive] theorem even_mul_odd {f : ℕ → M} (he : Multipliable fun k ↦ f (2 * k)) (ho : Multipliable fun k ↦ f (2 * k + 1)) : Multipliable f := (he.hasProd.even_mul_odd ho.hasProd).multipliable end ContinuousMul end Multipliable section tprod variable [T2Space M] {α β γ : Type*} section Encodable variable [Encodable β] /-- You can compute a product over an encodable type by multiplying over the natural numbers and taking a supremum. -/ @[to_additive "You can compute a sum over an encodable type by summing over the natural numbers and taking a supremum. This is useful for outer measures."] theorem tprod_iSup_decode₂ [CompleteLattice α] (m : α → M) (m0 : m ⊥ = 1) (s : β → α) : ∏' i : ℕ, m (⨆ b ∈ decode₂ β i, s b) = ∏' b : β, m (s b) := by rw [← tprod_extend_one (@encode_injective β _)] refine tprod_congr fun n ↦ ?_ rcases em (n ∈ Set.range (encode : β → ℕ)) with ⟨a, rfl⟩ | hn · simp [encode_injective.extend_apply] · rw [extend_apply' _ _ _ hn] rw [← decode₂_ne_none_iff, ne_eq, not_not] at hn simp [hn, m0] #align tsum_supr_decode₂ tsum_iSup_decode₂ /-- `tprod_iSup_decode₂` specialized to the complete lattice of sets. -/ @[to_additive "`tsum_iSup_decode₂` specialized to the complete lattice of sets."] theorem tprod_iUnion_decode₂ (m : Set α → M) (m0 : m ∅ = 1) (s : β → Set α) : ∏' i, m (⋃ b ∈ decode₂ β i, s b) = ∏' b, m (s b) := tprod_iSup_decode₂ m m0 s #align tsum_Union_decode₂ tsum_iUnion_decode₂ end Encodable /-! Some properties about measure-like functions. These could also be functions defined on complete sublattices of sets, with the property that they are countably sub-additive. `R` will probably be instantiated with `(≤)` in all applications. -/ section Countable variable [Countable β] /-- If a function is countably sub-multiplicative then it is sub-multiplicative on countable types -/ @[to_additive "If a function is countably sub-additive then it is sub-additive on countable types"] theorem rel_iSup_tprod [CompleteLattice α] (m : α → M) (m0 : m ⊥ = 1) (R : M → M → Prop) (m_iSup : ∀ s : ℕ → α, R (m (⨆ i, s i)) (∏' i, m (s i))) (s : β → α) : R (m (⨆ b : β, s b)) (∏' b : β, m (s b)) := by cases nonempty_encodable β rw [← iSup_decode₂, ← tprod_iSup_decode₂ _ m0 s] exact m_iSup _ #align rel_supr_tsum rel_iSup_tsum /-- If a function is countably sub-multiplicative then it is sub-multiplicative on finite sets -/ @[to_additive "If a function is countably sub-additive then it is sub-additive on finite sets"] theorem rel_iSup_prod [CompleteLattice α] (m : α → M) (m0 : m ⊥ = 1) (R : M → M → Prop) (m_iSup : ∀ s : ℕ → α, R (m (⨆ i, s i)) (∏' i, m (s i))) (s : γ → α) (t : Finset γ) : R (m (⨆ d ∈ t, s d)) (∏ d ∈ t, m (s d)) := by rw [iSup_subtype', ← Finset.tprod_subtype] exact rel_iSup_tprod m m0 R m_iSup _ #align rel_supr_sum rel_iSup_sum /-- If a function is countably sub-multiplicative then it is binary sub-multiplicative -/ @[to_additive "If a function is countably sub-additive then it is binary sub-additive"] theorem rel_sup_mul [CompleteLattice α] (m : α → M) (m0 : m ⊥ = 1) (R : M → M → Prop) (m_iSup : ∀ s : ℕ → α, R (m (⨆ i, s i)) (∏' i, m (s i))) (s₁ s₂ : α) : R (m (s₁ ⊔ s₂)) (m s₁ * m s₂) := by convert rel_iSup_tprod m m0 R m_iSup fun b ↦ cond b s₁ s₂ · simp only [iSup_bool_eq, cond] · rw [tprod_fintype, Fintype.prod_bool, cond, cond] #align rel_sup_add rel_sup_add end Countable section ContinuousMul variable [ContinuousMul M] @[to_additive] theorem prod_mul_tprod_nat_mul' {f : ℕ → M} {k : ℕ} (h : Multipliable (fun n ↦ f (n + k))) : ((∏ i ∈ range k, f i) * ∏' i, f (i + k)) = ∏' i, f i := h.hasProd.prod_range_mul.tprod_eq.symm @[to_additive] theorem tprod_eq_zero_mul' {f : ℕ → M} (hf : Multipliable (fun n ↦ f (n + 1))) : ∏' b, f b = f 0 * ∏' b, f (b + 1) := by simpa only [prod_range_one] using (prod_mul_tprod_nat_mul' hf).symm @[to_additive] theorem tprod_even_mul_odd {f : ℕ → M} (he : Multipliable fun k ↦ f (2 * k)) (ho : Multipliable fun k ↦ f (2 * k + 1)) : (∏' k, f (2 * k)) * ∏' k, f (2 * k + 1) = ∏' k, f k := (he.hasProd.even_mul_odd ho.hasProd).tprod_eq.symm #align tsum_even_add_odd tsum_even_add_odd end ContinuousMul end tprod end Monoid section TopologicalGroup variable [TopologicalSpace G] [TopologicalGroup G] @[to_additive] theorem hasProd_nat_add_iff {f : ℕ → G} (k : ℕ) : HasProd (fun n ↦ f (n + k)) g ↔ HasProd f (g * ∏ i ∈ range k, f i) := by refine Iff.trans ?_ (range k).hasProd_compl_iff rw [← (notMemRangeEquiv k).symm.hasProd_iff, Function.comp_def, coe_notMemRangeEquiv_symm] #align has_sum_nat_add_iff hasSum_nat_add_iff @[to_additive] theorem multipliable_nat_add_iff {f : ℕ → G} (k : ℕ) : (Multipliable fun n ↦ f (n + k)) ↔ Multipliable f := Iff.symm <| (Equiv.mulRight (∏ i ∈ range k, f i)).surjective.multipliable_iff_of_hasProd_iff (hasProd_nat_add_iff k).symm #align summable_nat_add_iff summable_nat_add_iff @[to_additive] theorem hasProd_nat_add_iff' {f : ℕ → G} (k : ℕ) : HasProd (fun n ↦ f (n + k)) (g / ∏ i ∈ range k, f i) ↔ HasProd f g := by simp [hasProd_nat_add_iff] #align has_sum_nat_add_iff' hasSum_nat_add_iff' @[to_additive] theorem prod_mul_tprod_nat_add [T2Space G] {f : ℕ → G} (k : ℕ) (h : Multipliable f) : ((∏ i ∈ range k, f i) * ∏' i, f (i + k)) = ∏' i, f i := prod_mul_tprod_nat_mul' <| (multipliable_nat_add_iff k).2 h #align sum_add_tsum_nat_add sum_add_tsum_nat_add @[to_additive] theorem tprod_eq_zero_mul [T2Space G] {f : ℕ → G} (hf : Multipliable f) : ∏' b, f b = f 0 * ∏' b, f (b + 1) := tprod_eq_zero_mul' <| (multipliable_nat_add_iff 1).2 hf #align tsum_eq_zero_add tsum_eq_zero_add /-- For `f : ℕ → G`, the product `∏' k, f (k + i)` tends to one. This does not require a multipliability assumption on `f`, as otherwise all such products are one. -/ @[to_additive "For `f : ℕ → G`, the sum `∑' k, f (k + i)` tends to zero. This does not require a summability assumption on `f`, as otherwise all such sums are zero."] theorem tendsto_prod_nat_add [T2Space G] (f : ℕ → G) : Tendsto (fun i ↦ ∏' k, f (k + i)) atTop (𝓝 1) := by by_cases hf : Multipliable f · have h₀ : (fun i ↦ (∏' i, f i) / ∏ j ∈ range i, f j) = fun i ↦ ∏' k : ℕ, f (k + i) := by ext1 i rw [div_eq_iff_eq_mul, mul_comm, prod_mul_tprod_nat_add i hf] have h₁ : Tendsto (fun _ : ℕ ↦ ∏' i, f i) atTop (𝓝 (∏' i, f i)) := tendsto_const_nhds simpa only [h₀, div_self'] using Tendsto.div' h₁ hf.hasProd.tendsto_prod_nat · refine tendsto_const_nhds.congr fun n ↦ (tprod_eq_one_of_not_multipliable ?_).symm rwa [multipliable_nat_add_iff n] #align tendsto_sum_nat_add tendsto_sum_nat_add end TopologicalGroup section UniformGroup variable [UniformSpace G] [UniformGroup G] @[to_additive] theorem cauchySeq_finset_iff_nat_tprod_vanishing {f : ℕ → G} : (CauchySeq fun s : Finset ℕ ↦ ∏ n ∈ s, f n) ↔ ∀ e ∈ 𝓝 (1 : G), ∃ N : ℕ, ∀ t ⊆ {n | N ≤ n}, (∏' n : t, f n) ∈ e := by refine cauchySeq_finset_iff_tprod_vanishing.trans ⟨fun vanish e he ↦ ?_, fun vanish e he ↦ ?_⟩ · obtain ⟨s, hs⟩ := vanish e he refine ⟨if h : s.Nonempty then s.max' h + 1 else 0, fun t ht ↦ hs _ <| Set.disjoint_left.mpr ?_⟩ split_ifs at ht with h · exact fun m hmt hms ↦ (s.le_max' _ hms).not_lt (Nat.succ_le_iff.mp <| ht hmt) · exact fun _ _ hs ↦ h ⟨_, hs⟩ · obtain ⟨N, hN⟩ := vanish e he exact ⟨range N, fun t ht ↦ hN _ fun n hnt ↦ le_of_not_lt fun h ↦ Set.disjoint_left.mp ht hnt (mem_range.mpr h)⟩ variable [CompleteSpace G] @[to_additive]
Mathlib/Topology/Algebra/InfiniteSum/NatInt.lean
290
292
theorem multipliable_iff_nat_tprod_vanishing {f : ℕ → G} : Multipliable f ↔ ∀ e ∈ 𝓝 1, ∃ N : ℕ, ∀ t ⊆ {n | N ≤ n}, (∏' n : t, f n) ∈ e := by
rw [multipliable_iff_cauchySeq_finset, cauchySeq_finset_iff_nat_tprod_vanishing]
/- Copyright (c) 2022 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Batteries.Tactic.SeqFocus /-! ## Ordering -/ namespace Ordering @[simp] theorem swap_swap {o : Ordering} : o.swap.swap = o := by cases o <;> rfl @[simp] theorem swap_inj {o₁ o₂ : Ordering} : o₁.swap = o₂.swap ↔ o₁ = o₂ := ⟨fun h => by simpa using congrArg swap h, congrArg _⟩ theorem swap_then (o₁ o₂ : Ordering) : (o₁.then o₂).swap = o₁.swap.then o₂.swap := by cases o₁ <;> rfl theorem then_eq_lt {o₁ o₂ : Ordering} : o₁.then o₂ = lt ↔ o₁ = lt ∨ o₁ = eq ∧ o₂ = lt := by cases o₁ <;> cases o₂ <;> decide theorem then_eq_eq {o₁ o₂ : Ordering} : o₁.then o₂ = eq ↔ o₁ = eq ∧ o₂ = eq := by cases o₁ <;> simp [«then»] theorem then_eq_gt {o₁ o₂ : Ordering} : o₁.then o₂ = gt ↔ o₁ = gt ∨ o₁ = eq ∧ o₂ = gt := by cases o₁ <;> cases o₂ <;> decide end Ordering namespace Batteries /-- `TotalBLE le` asserts that `le` has a total order, that is, `le a b ∨ le b a`. -/ class TotalBLE (le : α → α → Bool) : Prop where /-- `le` is total: either `le a b` or `le b a`. -/ total : le a b ∨ le b a /-- `OrientedCmp cmp` asserts that `cmp` is determined by the relation `cmp x y = .lt`. -/ class OrientedCmp (cmp : α → α → Ordering) : Prop where /-- The comparator operation is symmetric, in the sense that if `cmp x y` equals `.lt` then `cmp y x = .gt` and vice versa. -/ symm (x y) : (cmp x y).swap = cmp y x namespace OrientedCmp theorem cmp_eq_gt [OrientedCmp cmp] : cmp x y = .gt ↔ cmp y x = .lt := by rw [← Ordering.swap_inj, symm]; exact .rfl theorem cmp_ne_gt [OrientedCmp cmp] : cmp x y ≠ .gt ↔ cmp y x ≠ .lt := not_congr cmp_eq_gt theorem cmp_eq_eq_symm [OrientedCmp cmp] : cmp x y = .eq ↔ cmp y x = .eq := by rw [← Ordering.swap_inj, symm]; exact .rfl theorem cmp_refl [OrientedCmp cmp] : cmp x x = .eq := match e : cmp x x with | .lt => nomatch e.symm.trans (cmp_eq_gt.2 e) | .eq => rfl | .gt => nomatch (cmp_eq_gt.1 e).symm.trans e end OrientedCmp /-- `TransCmp cmp` asserts that `cmp` induces a transitive relation. -/ class TransCmp (cmp : α → α → Ordering) extends OrientedCmp cmp : Prop where /-- The comparator operation is transitive. -/ le_trans : cmp x y ≠ .gt → cmp y z ≠ .gt → cmp x z ≠ .gt namespace TransCmp variable [TransCmp cmp] open OrientedCmp Decidable theorem ge_trans (h₁ : cmp x y ≠ .lt) (h₂ : cmp y z ≠ .lt) : cmp x z ≠ .lt := by have := @TransCmp.le_trans _ cmp _ z y x simp [cmp_eq_gt] at *; exact this h₂ h₁ theorem lt_asymm (h : cmp x y = .lt) : cmp y x ≠ .lt := fun h' => nomatch h.symm.trans (cmp_eq_gt.2 h') theorem gt_asymm (h : cmp x y = .gt) : cmp y x ≠ .gt := mt cmp_eq_gt.1 <| lt_asymm <| cmp_eq_gt.1 h theorem le_lt_trans (h₁ : cmp x y ≠ .gt) (h₂ : cmp y z = .lt) : cmp x z = .lt := byContradiction fun h₃ => ge_trans (mt cmp_eq_gt.2 h₁) h₃ h₂ theorem lt_le_trans (h₁ : cmp x y = .lt) (h₂ : cmp y z ≠ .gt) : cmp x z = .lt := byContradiction fun h₃ => ge_trans h₃ (mt cmp_eq_gt.2 h₂) h₁ theorem lt_trans (h₁ : cmp x y = .lt) (h₂ : cmp y z = .lt) : cmp x z = .lt := le_lt_trans (gt_asymm <| cmp_eq_gt.2 h₁) h₂ theorem gt_trans (h₁ : cmp x y = .gt) (h₂ : cmp y z = .gt) : cmp x z = .gt := by rw [cmp_eq_gt] at h₁ h₂ ⊢; exact lt_trans h₂ h₁ theorem cmp_congr_left (xy : cmp x y = .eq) : cmp x z = cmp y z := match yz : cmp y z with | .lt => byContradiction (ge_trans (nomatch ·.symm.trans (cmp_eq_eq_symm.1 xy)) · yz) | .gt => byContradiction (le_trans (nomatch ·.symm.trans (cmp_eq_eq_symm.1 xy)) · yz) | .eq => match xz : cmp x z with | .lt => nomatch ge_trans (nomatch ·.symm.trans xy) (nomatch ·.symm.trans yz) xz | .gt => nomatch le_trans (nomatch ·.symm.trans xy) (nomatch ·.symm.trans yz) xz | .eq => rfl theorem cmp_congr_left' (xy : cmp x y = .eq) : cmp x = cmp y := funext fun _ => cmp_congr_left xy
.lake/packages/batteries/Batteries/Classes/Order.lean
105
106
theorem cmp_congr_right [TransCmp cmp] (yz : cmp y z = .eq) : cmp x y = cmp x z := by
rw [← Ordering.swap_inj, symm, symm, cmp_congr_left yz]
/- 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.MonoidAlgebra.Degree import Mathlib.Algebra.MvPolynomial.Rename import Mathlib.Algebra.Order.BigOperators.Ring.Finset #align_import data.mv_polynomial.variables from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Degrees of polynomials This file establishes many results about the degree of a multivariate polynomial. The *degree set* of a polynomial $P \in R[X]$ is a `Multiset` containing, for each $x$ in the variable set, $n$ copies of $x$, where $n$ is the maximum number of copies of $x$ appearing in a monomial of $P$. ## Main declarations * `MvPolynomial.degrees p` : the multiset of variables representing the union of the multisets corresponding to each non-zero monomial in `p`. For example if `7 ≠ 0` in `R` and `p = x²y+7y³` then `degrees p = {x, x, y, y, y}` * `MvPolynomial.degreeOf n p : ℕ` : the total degree of `p` with respect to the variable `n`. For example if `p = x⁴y+yz` then `degreeOf y p = 1`. * `MvPolynomial.totalDegree p : ℕ` : the max of the sizes of the multisets `s` whose monomials `X^s` occur in `p`. For example if `p = x⁴y+yz` then `totalDegree p = 5`. ## 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 Degrees /-! ### `degrees` -/ /-- The maximal degrees of each variable in a multi-variable polynomial, expressed as a multiset. (For example, `degrees (x^2 * y + y^3)` would be `{x, x, y, y, y}`.) -/ def degrees (p : MvPolynomial σ R) : Multiset σ := letI := Classical.decEq σ p.support.sup fun s : σ →₀ ℕ => toMultiset s #align mv_polynomial.degrees MvPolynomial.degrees theorem degrees_def [DecidableEq σ] (p : MvPolynomial σ R) : p.degrees = p.support.sup fun s : σ →₀ ℕ => Finsupp.toMultiset s := by rw [degrees]; convert rfl #align mv_polynomial.degrees_def MvPolynomial.degrees_def theorem degrees_monomial (s : σ →₀ ℕ) (a : R) : degrees (monomial s a) ≤ toMultiset s := by classical refine (supDegree_single s a).trans_le ?_ split_ifs exacts [bot_le, le_rfl] #align mv_polynomial.degrees_monomial MvPolynomial.degrees_monomial theorem degrees_monomial_eq (s : σ →₀ ℕ) (a : R) (ha : a ≠ 0) : degrees (monomial s a) = toMultiset s := by classical exact (supDegree_single s a).trans (if_neg ha) #align mv_polynomial.degrees_monomial_eq MvPolynomial.degrees_monomial_eq theorem degrees_C (a : R) : degrees (C a : MvPolynomial σ R) = 0 := Multiset.le_zero.1 <| degrees_monomial _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.degrees_C MvPolynomial.degrees_C theorem degrees_X' (n : σ) : degrees (X n : MvPolynomial σ R) ≤ {n} := le_trans (degrees_monomial _ _) <| le_of_eq <| toMultiset_single _ _ set_option linter.uppercaseLean3 false in #align mv_polynomial.degrees_X' MvPolynomial.degrees_X' @[simp] theorem degrees_X [Nontrivial R] (n : σ) : degrees (X n : MvPolynomial σ R) = {n} := (degrees_monomial_eq _ (1 : R) one_ne_zero).trans (toMultiset_single _ _) set_option linter.uppercaseLean3 false in #align mv_polynomial.degrees_X MvPolynomial.degrees_X @[simp] theorem degrees_zero : degrees (0 : MvPolynomial σ R) = 0 := by rw [← C_0] exact degrees_C 0 #align mv_polynomial.degrees_zero MvPolynomial.degrees_zero @[simp] theorem degrees_one : degrees (1 : MvPolynomial σ R) = 0 := degrees_C 1 #align mv_polynomial.degrees_one MvPolynomial.degrees_one theorem degrees_add [DecidableEq σ] (p q : MvPolynomial σ R) : (p + q).degrees ≤ p.degrees ⊔ q.degrees := by simp_rw [degrees_def]; exact supDegree_add_le #align mv_polynomial.degrees_add MvPolynomial.degrees_add theorem degrees_sum {ι : Type*} [DecidableEq σ] (s : Finset ι) (f : ι → MvPolynomial σ R) : (∑ i ∈ s, f i).degrees ≤ s.sup fun i => (f i).degrees := by simp_rw [degrees_def]; exact supDegree_sum_le #align mv_polynomial.degrees_sum MvPolynomial.degrees_sum theorem degrees_mul (p q : MvPolynomial σ R) : (p * q).degrees ≤ p.degrees + q.degrees := by classical simp_rw [degrees_def] exact supDegree_mul_le (map_add _) #align mv_polynomial.degrees_mul MvPolynomial.degrees_mul theorem degrees_prod {ι : Type*} (s : Finset ι) (f : ι → MvPolynomial σ R) : (∏ i ∈ s, f i).degrees ≤ ∑ i ∈ s, (f i).degrees := by classical exact supDegree_prod_le (map_zero _) (map_add _) #align mv_polynomial.degrees_prod MvPolynomial.degrees_prod theorem degrees_pow (p : MvPolynomial σ R) (n : ℕ) : (p ^ n).degrees ≤ n • p.degrees := by simpa using degrees_prod (Finset.range n) fun _ ↦ p #align mv_polynomial.degrees_pow MvPolynomial.degrees_pow theorem mem_degrees {p : MvPolynomial σ R} {i : σ} : i ∈ p.degrees ↔ ∃ d, p.coeff d ≠ 0 ∧ i ∈ d.support := by classical simp only [degrees_def, Multiset.mem_sup, ← mem_support_iff, Finsupp.mem_toMultiset, exists_prop] #align mv_polynomial.mem_degrees MvPolynomial.mem_degrees theorem le_degrees_add {p q : MvPolynomial σ R} (h : p.degrees.Disjoint q.degrees) : p.degrees ≤ (p + q).degrees := by classical apply Finset.sup_le intro d hd rw [Multiset.disjoint_iff_ne] at h obtain rfl | h0 := eq_or_ne d 0 · rw [toMultiset_zero]; apply Multiset.zero_le · refine Finset.le_sup_of_le (b := d) ?_ le_rfl rw [mem_support_iff, coeff_add] suffices q.coeff d = 0 by rwa [this, add_zero, coeff, ← Finsupp.mem_support_iff] rw [Ne, ← Finsupp.support_eq_empty, ← Ne, ← Finset.nonempty_iff_ne_empty] at h0 obtain ⟨j, hj⟩ := h0 contrapose! h rw [mem_support_iff] at hd refine ⟨j, ?_, j, ?_, rfl⟩ all_goals rw [mem_degrees]; refine ⟨d, ?_, hj⟩; assumption #align mv_polynomial.le_degrees_add MvPolynomial.le_degrees_add theorem degrees_add_of_disjoint [DecidableEq σ] {p q : MvPolynomial σ R} (h : Multiset.Disjoint p.degrees q.degrees) : (p + q).degrees = p.degrees ∪ q.degrees := by apply le_antisymm · apply degrees_add · apply Multiset.union_le · apply le_degrees_add h · rw [add_comm] apply le_degrees_add h.symm #align mv_polynomial.degrees_add_of_disjoint MvPolynomial.degrees_add_of_disjoint theorem degrees_map [CommSemiring S] (p : MvPolynomial σ R) (f : R →+* S) : (map f p).degrees ⊆ p.degrees := by classical dsimp only [degrees] apply Multiset.subset_of_le apply Finset.sup_mono apply MvPolynomial.support_map_subset #align mv_polynomial.degrees_map MvPolynomial.degrees_map theorem degrees_rename (f : σ → τ) (φ : MvPolynomial σ R) : (rename f φ).degrees ⊆ φ.degrees.map f := by classical intro i rw [mem_degrees, Multiset.mem_map] rintro ⟨d, hd, hi⟩ obtain ⟨x, rfl, hx⟩ := coeff_rename_ne_zero _ _ _ hd simp only [Finsupp.mapDomain, Finsupp.mem_support_iff] at hi rw [sum_apply, Finsupp.sum] at hi contrapose! hi rw [Finset.sum_eq_zero] intro j hj simp only [exists_prop, mem_degrees] at hi specialize hi j ⟨x, hx, hj⟩ rw [Finsupp.single_apply, if_neg hi] #align mv_polynomial.degrees_rename MvPolynomial.degrees_rename theorem degrees_map_of_injective [CommSemiring S] (p : MvPolynomial σ R) {f : R →+* S} (hf : Injective f) : (map f p).degrees = p.degrees := by simp only [degrees, MvPolynomial.support_map_of_injective _ hf] #align mv_polynomial.degrees_map_of_injective MvPolynomial.degrees_map_of_injective theorem degrees_rename_of_injective {p : MvPolynomial σ R} {f : σ → τ} (h : Function.Injective f) : degrees (rename f p) = (degrees p).map f := by classical simp only [degrees, Multiset.map_finset_sup p.support Finsupp.toMultiset f h, support_rename_of_injective h, Finset.sup_image] refine Finset.sup_congr rfl fun x _ => ?_ exact (Finsupp.toMultiset_map _ _).symm #align mv_polynomial.degrees_rename_of_injective MvPolynomial.degrees_rename_of_injective end Degrees section DegreeOf /-! ### `degreeOf` -/ /-- `degreeOf n p` gives the highest power of X_n that appears in `p` -/ def degreeOf (n : σ) (p : MvPolynomial σ R) : ℕ := letI := Classical.decEq σ p.degrees.count n #align mv_polynomial.degree_of MvPolynomial.degreeOf theorem degreeOf_def [DecidableEq σ] (n : σ) (p : MvPolynomial σ R) : p.degreeOf n = p.degrees.count n := by rw [degreeOf]; convert rfl #align mv_polynomial.degree_of_def MvPolynomial.degreeOf_def theorem degreeOf_eq_sup (n : σ) (f : MvPolynomial σ R) : degreeOf n f = f.support.sup fun m => m n := by classical rw [degreeOf_def, degrees, Multiset.count_finset_sup] congr ext simp #align mv_polynomial.degree_of_eq_sup MvPolynomial.degreeOf_eq_sup theorem degreeOf_lt_iff {n : σ} {f : MvPolynomial σ R} {d : ℕ} (h : 0 < d) : degreeOf n f < d ↔ ∀ m : σ →₀ ℕ, m ∈ f.support → m n < d := by rwa [degreeOf_eq_sup, Finset.sup_lt_iff] #align mv_polynomial.degree_of_lt_iff MvPolynomial.degreeOf_lt_iff lemma degreeOf_le_iff {n : σ} {f : MvPolynomial σ R} {d : ℕ} : degreeOf n f ≤ d ↔ ∀ m ∈ support f, m n ≤ d := by rw [degreeOf_eq_sup, Finset.sup_le_iff] @[simp] theorem degreeOf_zero (n : σ) : degreeOf n (0 : MvPolynomial σ R) = 0 := by classical simp only [degreeOf_def, degrees_zero, Multiset.count_zero] #align mv_polynomial.degree_of_zero MvPolynomial.degreeOf_zero @[simp] theorem degreeOf_C (a : R) (x : σ) : degreeOf x (C a : MvPolynomial σ R) = 0 := by classical simp [degreeOf_def, degrees_C] set_option linter.uppercaseLean3 false in #align mv_polynomial.degree_of_C MvPolynomial.degreeOf_C theorem degreeOf_X [DecidableEq σ] (i j : σ) [Nontrivial R] : degreeOf i (X j : MvPolynomial σ R) = if i = j then 1 else 0 := by classical by_cases c : i = j · simp only [c, if_true, eq_self_iff_true, degreeOf_def, degrees_X, Multiset.count_singleton] simp [c, if_false, degreeOf_def, degrees_X] set_option linter.uppercaseLean3 false in #align mv_polynomial.degree_of_X MvPolynomial.degreeOf_X theorem degreeOf_add_le (n : σ) (f g : MvPolynomial σ R) : degreeOf n (f + g) ≤ max (degreeOf n f) (degreeOf n g) := by simp_rw [degreeOf_eq_sup]; exact supDegree_add_le #align mv_polynomial.degree_of_add_le MvPolynomial.degreeOf_add_le theorem monomial_le_degreeOf (i : σ) {f : MvPolynomial σ R} {m : σ →₀ ℕ} (h_m : m ∈ f.support) : m i ≤ degreeOf i f := by rw [degreeOf_eq_sup i] apply Finset.le_sup h_m #align mv_polynomial.monomial_le_degree_of MvPolynomial.monomial_le_degreeOf -- TODO we can prove equality here if R is a domain theorem degreeOf_mul_le (i : σ) (f g : MvPolynomial σ R) : degreeOf i (f * g) ≤ degreeOf i f + degreeOf i g := by classical repeat' rw [degreeOf] convert Multiset.count_le_of_le i (degrees_mul f g) rw [Multiset.count_add] #align mv_polynomial.degree_of_mul_le MvPolynomial.degreeOf_mul_le theorem degreeOf_mul_X_ne {i j : σ} (f : MvPolynomial σ R) (h : i ≠ j) : degreeOf i (f * X j) = degreeOf i f := by classical repeat' rw [degreeOf_eq_sup (R := R) i] rw [support_mul_X] simp only [Finset.sup_map] congr ext simp only [Finsupp.single, Nat.one_ne_zero, add_right_eq_self, addRightEmbedding_apply, coe_mk, Pi.add_apply, comp_apply, ite_eq_right_iff, Finsupp.coe_add, Pi.single_eq_of_ne h] set_option linter.uppercaseLean3 false in #align mv_polynomial.degree_of_mul_X_ne MvPolynomial.degreeOf_mul_X_ne -- TODO in the following we have equality iff f ≠ 0 theorem degreeOf_mul_X_eq (j : σ) (f : MvPolynomial σ R) : degreeOf j (f * X j) ≤ degreeOf j f + 1 := by classical repeat' rw [degreeOf] apply (Multiset.count_le_of_le j (degrees_mul f (X j))).trans simp only [Multiset.count_add, add_le_add_iff_left] convert Multiset.count_le_of_le j (degrees_X' (R := R) j) rw [Multiset.count_singleton_self] set_option linter.uppercaseLean3 false in #align mv_polynomial.degree_of_mul_X_eq MvPolynomial.degreeOf_mul_X_eq theorem degreeOf_C_mul_le (p : MvPolynomial σ R) (i : σ) (c : R) : (C c * p).degreeOf i ≤ p.degreeOf i := by unfold degreeOf convert Multiset.count_le_of_le i <| degrees_mul (C c) p simp [degrees_C]
Mathlib/Algebra/MvPolynomial/Degrees.lean
334
338
theorem degreeOf_mul_C_le (p : MvPolynomial σ R) (i : σ) (c : R) : (p * C c).degreeOf i ≤ p.degreeOf i := by
unfold degreeOf convert Multiset.count_le_of_le i <| degrees_mul p (C c) simp [degrees_C]
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.FieldTheory.SplittingField.IsSplittingField import Mathlib.Algebra.CharP.Algebra #align_import field_theory.splitting_field.construction from "leanprover-community/mathlib"@"e3f4be1fcb5376c4948d7f095bec45350bfb9d1a" /-! # Splitting fields In this file we prove the existence and uniqueness of splitting fields. ## Main definitions * `Polynomial.SplittingField f`: A fixed splitting field of the polynomial `f`. ## Main statements * `Polynomial.IsSplittingField.algEquiv`: Every splitting field of a polynomial `f` is isomorphic to `SplittingField f` and thus, being a splitting field is unique up to isomorphism. ## Implementation details We construct a `SplittingFieldAux` without worrying about whether the instances satisfy nice definitional equalities. Then the actual `SplittingField` is defined to be a quotient of a `MvPolynomial` ring by the kernel of the obvious map into `SplittingFieldAux`. Because the actual `SplittingField` will be a quotient of a `MvPolynomial`, it has nice instances on it. -/ noncomputable section open scoped Classical Polynomial universe u v w variable {F : Type u} {K : Type v} {L : Type w} namespace Polynomial variable [Field K] [Field L] [Field F] open Polynomial section SplittingField /-- Non-computably choose an irreducible factor from a polynomial. -/ def factor (f : K[X]) : K[X] := if H : ∃ g, Irreducible g ∧ g ∣ f then Classical.choose H else X #align polynomial.factor Polynomial.factor theorem irreducible_factor (f : K[X]) : Irreducible (factor f) := by rw [factor] split_ifs with H · exact (Classical.choose_spec H).1 · exact irreducible_X #align polynomial.irreducible_factor Polynomial.irreducible_factor /-- See note [fact non-instances]. -/ theorem fact_irreducible_factor (f : K[X]) : Fact (Irreducible (factor f)) := ⟨irreducible_factor f⟩ #align polynomial.fact_irreducible_factor Polynomial.fact_irreducible_factor attribute [local instance] fact_irreducible_factor theorem factor_dvd_of_not_isUnit {f : K[X]} (hf1 : ¬IsUnit f) : factor f ∣ f := by by_cases hf2 : f = 0; · rw [hf2]; exact dvd_zero _ rw [factor, dif_pos (WfDvdMonoid.exists_irreducible_factor hf1 hf2)] exact (Classical.choose_spec <| WfDvdMonoid.exists_irreducible_factor hf1 hf2).2 #align polynomial.factor_dvd_of_not_is_unit Polynomial.factor_dvd_of_not_isUnit theorem factor_dvd_of_degree_ne_zero {f : K[X]} (hf : f.degree ≠ 0) : factor f ∣ f := factor_dvd_of_not_isUnit (mt degree_eq_zero_of_isUnit hf) #align polynomial.factor_dvd_of_degree_ne_zero Polynomial.factor_dvd_of_degree_ne_zero theorem factor_dvd_of_natDegree_ne_zero {f : K[X]} (hf : f.natDegree ≠ 0) : factor f ∣ f := factor_dvd_of_degree_ne_zero (mt natDegree_eq_of_degree_eq_some hf) #align polynomial.factor_dvd_of_nat_degree_ne_zero Polynomial.factor_dvd_of_natDegree_ne_zero /-- Divide a polynomial f by `X - C r` where `r` is a root of `f` in a bigger field extension. -/ def removeFactor (f : K[X]) : Polynomial (AdjoinRoot <| factor f) := map (AdjoinRoot.of f.factor) f /ₘ (X - C (AdjoinRoot.root f.factor)) #align polynomial.remove_factor Polynomial.removeFactor theorem X_sub_C_mul_removeFactor (f : K[X]) (hf : f.natDegree ≠ 0) : (X - C (AdjoinRoot.root f.factor)) * f.removeFactor = map (AdjoinRoot.of f.factor) f := by let ⟨g, hg⟩ := factor_dvd_of_natDegree_ne_zero hf apply (mul_divByMonic_eq_iff_isRoot (R := AdjoinRoot f.factor) (a := AdjoinRoot.root f.factor)).mpr rw [IsRoot.def, eval_map, hg, eval₂_mul, ← hg, AdjoinRoot.eval₂_root, zero_mul] set_option linter.uppercaseLean3 false in #align polynomial.X_sub_C_mul_remove_factor Polynomial.X_sub_C_mul_removeFactor
Mathlib/FieldTheory/SplittingField/Construction.lean
97
100
theorem natDegree_removeFactor (f : K[X]) : f.removeFactor.natDegree = f.natDegree - 1 := by
-- Porting note: `(map (AdjoinRoot.of f.factor) f)` was `_` rw [removeFactor, natDegree_divByMonic (map (AdjoinRoot.of f.factor) f) (monic_X_sub_C _), natDegree_map, natDegree_X_sub_C]
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Sébastien Gouëzel, Heather Macbeth -/ import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Tactic.LinearCombination #align_import analysis.convex.specific_functions.basic from "leanprover-community/mathlib"@"8f9fea08977f7e450770933ee6abb20733b47c92" /-! # Collection of convex functions In this file we prove that the following functions are convex or strictly convex: * `strictConvexOn_exp` : The exponential function is strictly convex. * `strictConcaveOn_log_Ioi`, `strictConcaveOn_log_Iio`: `Real.log` is strictly concave on $(0, +∞)$ and $(-∞, 0)$ respectively. * `convexOn_rpow`, `strictConvexOn_rpow` : For `p : ℝ`, `fun x ↦ x ^ p` is convex on $[0, +∞)$ when `1 ≤ p` and strictly convex when `1 < p`. The proofs in this file are deliberately elementary, *not* by appealing to the sign of the second derivative. This is in order to keep this file early in the import hierarchy, since it is on the path to Hölder's and Minkowski's inequalities and after that to Lp spaces and most of measure theory. (Strict) concavity of `fun x ↦ x ^ p` for `0 < p < 1` (`0 ≤ p ≤ 1`) can be found in `Analysis.Convex.SpecificFunctions.Pow`. ## See also `Analysis.Convex.Mul` for convexity of `x ↦ x ^ n` -/ open Real Set NNReal /-- `Real.exp` is strictly convex on the whole real line. -/ theorem strictConvexOn_exp : StrictConvexOn ℝ univ exp := by apply strictConvexOn_of_slope_strict_mono_adjacent convex_univ rintro x y z - - hxy hyz trans exp y · have h1 : 0 < y - x := by linarith have h2 : x - y < 0 := by linarith rw [div_lt_iff h1] calc exp y - exp x = exp y - exp y * exp (x - y) := by rw [← exp_add]; ring_nf _ = exp y * (1 - exp (x - y)) := by ring _ < exp y * -(x - y) := by gcongr; linarith [add_one_lt_exp h2.ne] _ = exp y * (y - x) := by ring · have h1 : 0 < z - y := by linarith rw [lt_div_iff h1] calc exp y * (z - y) < exp y * (exp (z - y) - 1) := by gcongr _ * ?_ linarith [add_one_lt_exp h1.ne'] _ = exp (z - y) * exp y - exp y := by ring _ ≤ exp z - exp y := by rw [← exp_add]; ring_nf; rfl #align strict_convex_on_exp strictConvexOn_exp /-- `Real.exp` is convex on the whole real line. -/ theorem convexOn_exp : ConvexOn ℝ univ exp := strictConvexOn_exp.convexOn #align convex_on_exp convexOn_exp /-- `Real.log` is strictly concave on `(0, +∞)`. -/ theorem strictConcaveOn_log_Ioi : StrictConcaveOn ℝ (Ioi 0) log := by apply strictConcaveOn_of_slope_strict_anti_adjacent (convex_Ioi (0 : ℝ)) intro x y z (hx : 0 < x) (hz : 0 < z) hxy hyz have hy : 0 < y := hx.trans hxy trans y⁻¹ · have h : 0 < z - y := by linarith rw [div_lt_iff h] have hyz' : 0 < z / y := by positivity have hyz'' : z / y ≠ 1 := by contrapose! h rw [div_eq_one_iff_eq hy.ne'] at h simp [h] calc log z - log y = log (z / y) := by rw [← log_div hz.ne' hy.ne'] _ < z / y - 1 := log_lt_sub_one_of_pos hyz' hyz'' _ = y⁻¹ * (z - y) := by field_simp · have h : 0 < y - x := by linarith rw [lt_div_iff h] have hxy' : 0 < x / y := by positivity have hxy'' : x / y ≠ 1 := by contrapose! h rw [div_eq_one_iff_eq hy.ne'] at h simp [h] calc y⁻¹ * (y - x) = 1 - x / y := by field_simp _ < -log (x / y) := by linarith [log_lt_sub_one_of_pos hxy' hxy''] _ = -(log x - log y) := by rw [log_div hx.ne' hy.ne'] _ = log y - log x := by ring #align strict_concave_on_log_Ioi strictConcaveOn_log_Ioi /-- **Bernoulli's inequality** for real exponents, strict version: for `1 < p` and `-1 ≤ s`, with `s ≠ 0`, we have `1 + p * s < (1 + s) ^ p`. -/ theorem one_add_mul_self_lt_rpow_one_add {s : ℝ} (hs : -1 ≤ s) (hs' : s ≠ 0) {p : ℝ} (hp : 1 < p) : 1 + p * s < (1 + s) ^ p := by have hp' : 0 < p := zero_lt_one.trans hp rcases eq_or_lt_of_le hs with rfl | hs · rwa [add_right_neg, zero_rpow hp'.ne', mul_neg_one, add_neg_lt_iff_lt_add, zero_add] have hs1 : 0 < 1 + s := neg_lt_iff_pos_add'.mp hs rcases le_or_lt (1 + p * s) 0 with hs2 | hs2 · exact hs2.trans_lt (rpow_pos_of_pos hs1 _) have hs3 : 1 + s ≠ 1 := hs' ∘ add_right_eq_self.mp have hs4 : 1 + p * s ≠ 1 := by contrapose! hs'; rwa [add_right_eq_self, mul_eq_zero, eq_false_intro hp'.ne', false_or] at hs' rw [rpow_def_of_pos hs1, ← exp_log hs2] apply exp_strictMono cases' lt_or_gt_of_ne hs' with hs' hs' · rw [← div_lt_iff hp', ← div_lt_div_right_of_neg hs'] convert strictConcaveOn_log_Ioi.secant_strict_mono (zero_lt_one' ℝ) hs2 hs1 hs4 hs3 _ using 1 · rw [add_sub_cancel_left, log_one, sub_zero] · rw [add_sub_cancel_left, div_div, log_one, sub_zero] · apply add_lt_add_left (mul_lt_of_one_lt_left hs' hp) · rw [← div_lt_iff hp', ← div_lt_div_right hs'] convert strictConcaveOn_log_Ioi.secant_strict_mono (zero_lt_one' ℝ) hs1 hs2 hs3 hs4 _ using 1 · rw [add_sub_cancel_left, div_div, log_one, sub_zero] · rw [add_sub_cancel_left, log_one, sub_zero] · apply add_lt_add_left (lt_mul_of_one_lt_left hs' hp) #align one_add_mul_self_lt_rpow_one_add one_add_mul_self_lt_rpow_one_add /-- **Bernoulli's inequality** for real exponents, non-strict version: for `1 ≤ p` and `-1 ≤ s` we have `1 + p * s ≤ (1 + s) ^ p`. -/ theorem one_add_mul_self_le_rpow_one_add {s : ℝ} (hs : -1 ≤ s) {p : ℝ} (hp : 1 ≤ p) : 1 + p * s ≤ (1 + s) ^ p := by rcases eq_or_lt_of_le hp with (rfl | hp) · simp by_cases hs' : s = 0 · simp [hs'] exact (one_add_mul_self_lt_rpow_one_add hs hs' hp).le #align one_add_mul_self_le_rpow_one_add one_add_mul_self_le_rpow_one_add /-- **Bernoulli's inequality** for real exponents, strict version: for `0 < p < 1` and `-1 ≤ s`, with `s ≠ 0`, we have `(1 + s) ^ p < 1 + p * s`. -/ theorem rpow_one_add_lt_one_add_mul_self {s : ℝ} (hs : -1 ≤ s) (hs' : s ≠ 0) {p : ℝ} (hp1 : 0 < p) (hp2 : p < 1) : (1 + s) ^ p < 1 + p * s := by rcases eq_or_lt_of_le hs with rfl | hs · rwa [add_right_neg, zero_rpow hp1.ne', mul_neg_one, lt_add_neg_iff_add_lt, zero_add] have hs1 : 0 < 1 + s := neg_lt_iff_pos_add'.mp hs have hs2 : 0 < 1 + p * s := by rw [← neg_lt_iff_pos_add'] rcases lt_or_gt_of_ne hs' with h | h · exact hs.trans (lt_mul_of_lt_one_left h hp2) · exact neg_one_lt_zero.trans (mul_pos hp1 h) have hs3 : 1 + s ≠ 1 := hs' ∘ add_right_eq_self.mp have hs4 : 1 + p * s ≠ 1 := by contrapose! hs'; rwa [add_right_eq_self, mul_eq_zero, eq_false_intro hp1.ne', false_or] at hs' rw [rpow_def_of_pos hs1, ← exp_log hs2] apply exp_strictMono cases' lt_or_gt_of_ne hs' with hs' hs' · rw [← lt_div_iff hp1, ← div_lt_div_right_of_neg hs'] convert strictConcaveOn_log_Ioi.secant_strict_mono (zero_lt_one' ℝ) hs1 hs2 hs3 hs4 _ using 1 · rw [add_sub_cancel_left, div_div, log_one, sub_zero] · rw [add_sub_cancel_left, log_one, sub_zero] · apply add_lt_add_left (lt_mul_of_lt_one_left hs' hp2) · rw [← lt_div_iff hp1, ← div_lt_div_right hs'] convert strictConcaveOn_log_Ioi.secant_strict_mono (zero_lt_one' ℝ) hs2 hs1 hs4 hs3 _ using 1 · rw [add_sub_cancel_left, log_one, sub_zero] · rw [add_sub_cancel_left, div_div, log_one, sub_zero] · apply add_lt_add_left (mul_lt_of_lt_one_left hs' hp2) /-- **Bernoulli's inequality** for real exponents, non-strict version: for `0 ≤ p ≤ 1` and `-1 ≤ s` we have `(1 + s) ^ p ≤ 1 + p * s`. -/ theorem rpow_one_add_le_one_add_mul_self {s : ℝ} (hs : -1 ≤ s) {p : ℝ} (hp1 : 0 ≤ p) (hp2 : p ≤ 1) : (1 + s) ^ p ≤ 1 + p * s := by rcases eq_or_lt_of_le hp1 with (rfl | hp1) · simp rcases eq_or_lt_of_le hp2 with (rfl | hp2) · simp by_cases hs' : s = 0 · simp [hs'] exact (rpow_one_add_lt_one_add_mul_self hs hs' hp1 hp2).le /-- For `p : ℝ` with `1 < p`, `fun x ↦ x ^ p` is strictly convex on $[0, +∞)$. -/ theorem strictConvexOn_rpow {p : ℝ} (hp : 1 < p) : StrictConvexOn ℝ (Ici 0) fun x : ℝ ↦ x ^ p := by apply strictConvexOn_of_slope_strict_mono_adjacent (convex_Ici (0 : ℝ)) intro x y z (hx : 0 ≤ x) (hz : 0 ≤ z) hxy hyz have hy : 0 < y := hx.trans_lt hxy have hy' : 0 < y ^ p := rpow_pos_of_pos hy _ trans p * y ^ (p - 1) · have q : 0 < y - x := by rwa [sub_pos] rw [div_lt_iff q, ← div_lt_div_right hy', _root_.sub_div, div_self hy'.ne', ← div_rpow hx hy.le, sub_lt_comm, ← add_sub_cancel_right (x / y) 1, add_comm, add_sub_assoc, ← div_mul_eq_mul_div, mul_div_assoc, ← rpow_sub hy, sub_sub_cancel_left, rpow_neg_one, mul_assoc, ← div_eq_inv_mul, sub_eq_add_neg, ← mul_neg, ← neg_div, neg_sub, _root_.sub_div, div_self hy.ne'] apply one_add_mul_self_lt_rpow_one_add _ _ hp · rw [le_sub_iff_add_le, add_left_neg, div_nonneg_iff] exact Or.inl ⟨hx, hy.le⟩ · rw [sub_ne_zero] exact ((div_lt_one hy).mpr hxy).ne · have q : 0 < z - y := by rwa [sub_pos] rw [lt_div_iff q, ← div_lt_div_right hy', _root_.sub_div, div_self hy'.ne', ← div_rpow hz hy.le, lt_sub_iff_add_lt', ← add_sub_cancel_right (z / y) 1, add_comm _ 1, add_sub_assoc, ← div_mul_eq_mul_div, mul_div_assoc, ← rpow_sub hy, sub_sub_cancel_left, rpow_neg_one, mul_assoc, ← div_eq_inv_mul, _root_.sub_div, div_self hy.ne'] apply one_add_mul_self_lt_rpow_one_add _ _ hp · rw [le_sub_iff_add_le, add_left_neg, div_nonneg_iff] exact Or.inl ⟨hz, hy.le⟩ · rw [sub_ne_zero] exact ((one_lt_div hy).mpr hyz).ne' #align strict_convex_on_rpow strictConvexOn_rpow
Mathlib/Analysis/Convex/SpecificFunctions/Basic.lean
206
209
theorem convexOn_rpow {p : ℝ} (hp : 1 ≤ p) : ConvexOn ℝ (Ici 0) fun x : ℝ ↦ x ^ p := by
rcases eq_or_lt_of_le hp with (rfl | hp) · simpa using convexOn_id (convex_Ici _) exact (strictConvexOn_rpow hp).convexOn
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.TwoDim import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic #align_import geometry.euclidean.angle.oriented.basic from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9" /-! # Oriented angles. This file defines oriented angles in real inner product spaces. ## Main definitions * `Orientation.oangle` is the oriented angle between two vectors with respect to an orientation. ## Implementation notes The definitions here use the `Real.angle` type, angles modulo `2 * π`. For some purposes, angles modulo `π` are more convenient, because results are true for such angles with less configuration dependence. Results that are only equalities modulo `π` can be represented modulo `2 * π` as equalities of `(2 : ℤ) • θ`. ## References * Evan Chen, Euclidean Geometry in Mathematical Olympiads. -/ noncomputable section open FiniteDimensional Complex open scoped Real RealInnerProductSpace ComplexConjugate namespace Orientation attribute [local instance] Complex.finrank_real_complex_fact variable {V V' : Type*} variable [NormedAddCommGroup V] [NormedAddCommGroup V'] variable [InnerProductSpace ℝ V] [InnerProductSpace ℝ V'] variable [Fact (finrank ℝ V = 2)] [Fact (finrank ℝ V' = 2)] (o : Orientation ℝ V (Fin 2)) local notation "ω" => o.areaForm /-- The oriented angle from `x` to `y`, modulo `2 * π`. If either vector is 0, this is 0. See `InnerProductGeometry.angle` for the corresponding unoriented angle definition. -/ def oangle (x y : V) : Real.Angle := Complex.arg (o.kahler x y) #align orientation.oangle Orientation.oangle /-- Oriented angles are continuous when the vectors involved are nonzero. -/ theorem continuousAt_oangle {x : V × V} (hx1 : x.1 ≠ 0) (hx2 : x.2 ≠ 0) : ContinuousAt (fun y : V × V => o.oangle y.1 y.2) x := by refine (Complex.continuousAt_arg_coe_angle ?_).comp ?_ · exact o.kahler_ne_zero hx1 hx2 exact ((continuous_ofReal.comp continuous_inner).add ((continuous_ofReal.comp o.areaForm'.continuous₂).mul continuous_const)).continuousAt #align orientation.continuous_at_oangle Orientation.continuousAt_oangle /-- If the first vector passed to `oangle` is 0, the result is 0. -/ @[simp] theorem oangle_zero_left (x : V) : o.oangle 0 x = 0 := by simp [oangle] #align orientation.oangle_zero_left Orientation.oangle_zero_left /-- If the second vector passed to `oangle` is 0, the result is 0. -/ @[simp] theorem oangle_zero_right (x : V) : o.oangle x 0 = 0 := by simp [oangle] #align orientation.oangle_zero_right Orientation.oangle_zero_right /-- If the two vectors passed to `oangle` are the same, the result is 0. -/ @[simp] theorem oangle_self (x : V) : o.oangle x x = 0 := by rw [oangle, kahler_apply_self, ← ofReal_pow] convert QuotientAddGroup.mk_zero (AddSubgroup.zmultiples (2 * π)) apply arg_ofReal_of_nonneg positivity #align orientation.oangle_self Orientation.oangle_self /-- If the angle between two vectors is nonzero, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : x ≠ 0 := by rintro rfl; simp at h #align orientation.left_ne_zero_of_oangle_ne_zero Orientation.left_ne_zero_of_oangle_ne_zero /-- If the angle between two vectors is nonzero, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : y ≠ 0 := by rintro rfl; simp at h #align orientation.right_ne_zero_of_oangle_ne_zero Orientation.right_ne_zero_of_oangle_ne_zero /-- If the angle between two vectors is nonzero, the vectors are not equal. -/ theorem ne_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : x ≠ y := by rintro rfl; simp at h #align orientation.ne_of_oangle_ne_zero Orientation.ne_of_oangle_ne_zero /-- If the angle between two vectors is `π`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0) #align orientation.left_ne_zero_of_oangle_eq_pi Orientation.left_ne_zero_of_oangle_eq_pi /-- If the angle between two vectors is `π`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0) #align orientation.right_ne_zero_of_oangle_eq_pi Orientation.right_ne_zero_of_oangle_eq_pi /-- If the angle between two vectors is `π`, the vectors are not equal. -/ theorem ne_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : x ≠ y := o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0) #align orientation.ne_of_oangle_eq_pi Orientation.ne_of_oangle_eq_pi /-- If the angle between two vectors is `π / 2`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0) #align orientation.left_ne_zero_of_oangle_eq_pi_div_two Orientation.left_ne_zero_of_oangle_eq_pi_div_two /-- If the angle between two vectors is `π / 2`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0) #align orientation.right_ne_zero_of_oangle_eq_pi_div_two Orientation.right_ne_zero_of_oangle_eq_pi_div_two /-- If the angle between two vectors is `π / 2`, the vectors are not equal. -/ theorem ne_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : x ≠ y := o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0) #align orientation.ne_of_oangle_eq_pi_div_two Orientation.ne_of_oangle_eq_pi_div_two /-- If the angle between two vectors is `-π / 2`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0) #align orientation.left_ne_zero_of_oangle_eq_neg_pi_div_two Orientation.left_ne_zero_of_oangle_eq_neg_pi_div_two /-- If the angle between two vectors is `-π / 2`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0) #align orientation.right_ne_zero_of_oangle_eq_neg_pi_div_two Orientation.right_ne_zero_of_oangle_eq_neg_pi_div_two /-- If the angle between two vectors is `-π / 2`, the vectors are not equal. -/ theorem ne_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : x ≠ y := o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0) #align orientation.ne_of_oangle_eq_neg_pi_div_two Orientation.ne_of_oangle_eq_neg_pi_div_two /-- If the sign of the angle between two vectors is nonzero, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 #align orientation.left_ne_zero_of_oangle_sign_ne_zero Orientation.left_ne_zero_of_oangle_sign_ne_zero /-- If the sign of the angle between two vectors is nonzero, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 #align orientation.right_ne_zero_of_oangle_sign_ne_zero Orientation.right_ne_zero_of_oangle_sign_ne_zero /-- If the sign of the angle between two vectors is nonzero, the vectors are not equal. -/ theorem ne_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : x ≠ y := o.ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 #align orientation.ne_of_oangle_sign_ne_zero Orientation.ne_of_oangle_sign_ne_zero /-- If the sign of the angle between two vectors is positive, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x ≠ 0 := o.left_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) #align orientation.left_ne_zero_of_oangle_sign_eq_one Orientation.left_ne_zero_of_oangle_sign_eq_one /-- If the sign of the angle between two vectors is positive, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : y ≠ 0 := o.right_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) #align orientation.right_ne_zero_of_oangle_sign_eq_one Orientation.right_ne_zero_of_oangle_sign_eq_one /-- If the sign of the angle between two vectors is positive, the vectors are not equal. -/ theorem ne_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x ≠ y := o.ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) #align orientation.ne_of_oangle_sign_eq_one Orientation.ne_of_oangle_sign_eq_one /-- If the sign of the angle between two vectors is negative, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x ≠ 0 := o.left_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) #align orientation.left_ne_zero_of_oangle_sign_eq_neg_one Orientation.left_ne_zero_of_oangle_sign_eq_neg_one /-- If the sign of the angle between two vectors is negative, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : y ≠ 0 := o.right_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) #align orientation.right_ne_zero_of_oangle_sign_eq_neg_one Orientation.right_ne_zero_of_oangle_sign_eq_neg_one /-- If the sign of the angle between two vectors is negative, the vectors are not equal. -/ theorem ne_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x ≠ y := o.ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) #align orientation.ne_of_oangle_sign_eq_neg_one Orientation.ne_of_oangle_sign_eq_neg_one /-- Swapping the two vectors passed to `oangle` negates the angle. -/ theorem oangle_rev (x y : V) : o.oangle y x = -o.oangle x y := by simp only [oangle, o.kahler_swap y x, Complex.arg_conj_coe_angle] #align orientation.oangle_rev Orientation.oangle_rev /-- Adding the angles between two vectors in each order results in 0. -/ @[simp] theorem oangle_add_oangle_rev (x y : V) : o.oangle x y + o.oangle y x = 0 := by simp [o.oangle_rev y x] #align orientation.oangle_add_oangle_rev Orientation.oangle_add_oangle_rev /-- Negating the first vector passed to `oangle` adds `π` to the angle. -/ theorem oangle_neg_left {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : o.oangle (-x) y = o.oangle x y + π := by simp only [oangle, map_neg] convert Complex.arg_neg_coe_angle _ exact o.kahler_ne_zero hx hy #align orientation.oangle_neg_left Orientation.oangle_neg_left /-- Negating the second vector passed to `oangle` adds `π` to the angle. -/ theorem oangle_neg_right {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : o.oangle x (-y) = o.oangle x y + π := by simp only [oangle, map_neg] convert Complex.arg_neg_coe_angle _ exact o.kahler_ne_zero hx hy #align orientation.oangle_neg_right Orientation.oangle_neg_right /-- Negating the first vector passed to `oangle` does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_neg_left (x y : V) : (2 : ℤ) • o.oangle (-x) y = (2 : ℤ) • o.oangle x y := by by_cases hx : x = 0 · simp [hx] · by_cases hy : y = 0 · simp [hy] · simp [o.oangle_neg_left hx hy] #align orientation.two_zsmul_oangle_neg_left Orientation.two_zsmul_oangle_neg_left /-- Negating the second vector passed to `oangle` does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_neg_right (x y : V) : (2 : ℤ) • o.oangle x (-y) = (2 : ℤ) • o.oangle x y := by by_cases hx : x = 0 · simp [hx] · by_cases hy : y = 0 · simp [hy] · simp [o.oangle_neg_right hx hy] #align orientation.two_zsmul_oangle_neg_right Orientation.two_zsmul_oangle_neg_right /-- Negating both vectors passed to `oangle` does not change the angle. -/ @[simp] theorem oangle_neg_neg (x y : V) : o.oangle (-x) (-y) = o.oangle x y := by simp [oangle] #align orientation.oangle_neg_neg Orientation.oangle_neg_neg /-- Negating the first vector produces the same angle as negating the second vector. -/ theorem oangle_neg_left_eq_neg_right (x y : V) : o.oangle (-x) y = o.oangle x (-y) := by rw [← neg_neg y, oangle_neg_neg, neg_neg] #align orientation.oangle_neg_left_eq_neg_right Orientation.oangle_neg_left_eq_neg_right /-- The angle between the negation of a nonzero vector and that vector is `π`. -/ @[simp] theorem oangle_neg_self_left {x : V} (hx : x ≠ 0) : o.oangle (-x) x = π := by simp [oangle_neg_left, hx] #align orientation.oangle_neg_self_left Orientation.oangle_neg_self_left /-- The angle between a nonzero vector and its negation is `π`. -/ @[simp] theorem oangle_neg_self_right {x : V} (hx : x ≠ 0) : o.oangle x (-x) = π := by simp [oangle_neg_right, hx] #align orientation.oangle_neg_self_right Orientation.oangle_neg_self_right /-- Twice the angle between the negation of a vector and that vector is 0. -/ -- @[simp] -- Porting note (#10618): simp can prove this theorem two_zsmul_oangle_neg_self_left (x : V) : (2 : ℤ) • o.oangle (-x) x = 0 := by by_cases hx : x = 0 <;> simp [hx] #align orientation.two_zsmul_oangle_neg_self_left Orientation.two_zsmul_oangle_neg_self_left /-- Twice the angle between a vector and its negation is 0. -/ -- @[simp] -- Porting note (#10618): simp can prove this theorem two_zsmul_oangle_neg_self_right (x : V) : (2 : ℤ) • o.oangle x (-x) = 0 := by by_cases hx : x = 0 <;> simp [hx] #align orientation.two_zsmul_oangle_neg_self_right Orientation.two_zsmul_oangle_neg_self_right /-- Adding the angles between two vectors in each order, with the first vector in each angle negated, results in 0. -/ @[simp] theorem oangle_add_oangle_rev_neg_left (x y : V) : o.oangle (-x) y + o.oangle (-y) x = 0 := by rw [oangle_neg_left_eq_neg_right, oangle_rev, add_left_neg] #align orientation.oangle_add_oangle_rev_neg_left Orientation.oangle_add_oangle_rev_neg_left /-- Adding the angles between two vectors in each order, with the second vector in each angle negated, results in 0. -/ @[simp] theorem oangle_add_oangle_rev_neg_right (x y : V) : o.oangle x (-y) + o.oangle y (-x) = 0 := by rw [o.oangle_rev (-x), oangle_neg_left_eq_neg_right, add_neg_self] #align orientation.oangle_add_oangle_rev_neg_right Orientation.oangle_add_oangle_rev_neg_right /-- Multiplying the first vector passed to `oangle` by a positive real does not change the angle. -/ @[simp] theorem oangle_smul_left_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : o.oangle (r • x) y = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr] #align orientation.oangle_smul_left_of_pos Orientation.oangle_smul_left_of_pos /-- Multiplying the second vector passed to `oangle` by a positive real does not change the angle. -/ @[simp] theorem oangle_smul_right_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : o.oangle x (r • y) = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr] #align orientation.oangle_smul_right_of_pos Orientation.oangle_smul_right_of_pos /-- Multiplying the first vector passed to `oangle` by a negative real produces the same angle as negating that vector. -/ @[simp] theorem oangle_smul_left_of_neg (x y : V) {r : ℝ} (hr : r < 0) : o.oangle (r • x) y = o.oangle (-x) y := by rw [← neg_neg r, neg_smul, ← smul_neg, o.oangle_smul_left_of_pos _ _ (neg_pos_of_neg hr)] #align orientation.oangle_smul_left_of_neg Orientation.oangle_smul_left_of_neg /-- Multiplying the second vector passed to `oangle` by a negative real produces the same angle as negating that vector. -/ @[simp] theorem oangle_smul_right_of_neg (x y : V) {r : ℝ} (hr : r < 0) : o.oangle x (r • y) = o.oangle x (-y) := by rw [← neg_neg r, neg_smul, ← smul_neg, o.oangle_smul_right_of_pos _ _ (neg_pos_of_neg hr)] #align orientation.oangle_smul_right_of_neg Orientation.oangle_smul_right_of_neg /-- The angle between a nonnegative multiple of a vector and that vector is 0. -/ @[simp] theorem oangle_smul_left_self_of_nonneg (x : V) {r : ℝ} (hr : 0 ≤ r) : o.oangle (r • x) x = 0 := by rcases hr.lt_or_eq with (h | h) · simp [h] · simp [h.symm] #align orientation.oangle_smul_left_self_of_nonneg Orientation.oangle_smul_left_self_of_nonneg /-- The angle between a vector and a nonnegative multiple of that vector is 0. -/ @[simp] theorem oangle_smul_right_self_of_nonneg (x : V) {r : ℝ} (hr : 0 ≤ r) : o.oangle x (r • x) = 0 := by rcases hr.lt_or_eq with (h | h) · simp [h] · simp [h.symm] #align orientation.oangle_smul_right_self_of_nonneg Orientation.oangle_smul_right_self_of_nonneg /-- The angle between two nonnegative multiples of the same vector is 0. -/ @[simp] theorem oangle_smul_smul_self_of_nonneg (x : V) {r₁ r₂ : ℝ} (hr₁ : 0 ≤ r₁) (hr₂ : 0 ≤ r₂) : o.oangle (r₁ • x) (r₂ • x) = 0 := by rcases hr₁.lt_or_eq with (h | h) · simp [h, hr₂] · simp [h.symm] #align orientation.oangle_smul_smul_self_of_nonneg Orientation.oangle_smul_smul_self_of_nonneg /-- Multiplying the first vector passed to `oangle` by a nonzero real does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_smul_left_of_ne_zero (x y : V) {r : ℝ} (hr : r ≠ 0) : (2 : ℤ) • o.oangle (r • x) y = (2 : ℤ) • o.oangle x y := by rcases hr.lt_or_lt with (h | h) <;> simp [h] #align orientation.two_zsmul_oangle_smul_left_of_ne_zero Orientation.two_zsmul_oangle_smul_left_of_ne_zero /-- Multiplying the second vector passed to `oangle` by a nonzero real does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_smul_right_of_ne_zero (x y : V) {r : ℝ} (hr : r ≠ 0) : (2 : ℤ) • o.oangle x (r • y) = (2 : ℤ) • o.oangle x y := by rcases hr.lt_or_lt with (h | h) <;> simp [h] #align orientation.two_zsmul_oangle_smul_right_of_ne_zero Orientation.two_zsmul_oangle_smul_right_of_ne_zero /-- Twice the angle between a multiple of a vector and that vector is 0. -/ @[simp] theorem two_zsmul_oangle_smul_left_self (x : V) {r : ℝ} : (2 : ℤ) • o.oangle (r • x) x = 0 := by rcases lt_or_le r 0 with (h | h) <;> simp [h] #align orientation.two_zsmul_oangle_smul_left_self Orientation.two_zsmul_oangle_smul_left_self /-- Twice the angle between a vector and a multiple of that vector is 0. -/ @[simp] theorem two_zsmul_oangle_smul_right_self (x : V) {r : ℝ} : (2 : ℤ) • o.oangle x (r • x) = 0 := by rcases lt_or_le r 0 with (h | h) <;> simp [h] #align orientation.two_zsmul_oangle_smul_right_self Orientation.two_zsmul_oangle_smul_right_self /-- Twice the angle between two multiples of a vector is 0. -/ @[simp] theorem two_zsmul_oangle_smul_smul_self (x : V) {r₁ r₂ : ℝ} : (2 : ℤ) • o.oangle (r₁ • x) (r₂ • x) = 0 := by by_cases h : r₁ = 0 <;> simp [h] #align orientation.two_zsmul_oangle_smul_smul_self Orientation.two_zsmul_oangle_smul_smul_self /-- If the spans of two vectors are equal, twice angles with those vectors on the left are equal. -/ theorem two_zsmul_oangle_left_of_span_eq {x y : V} (z : V) (h : (ℝ ∙ x) = ℝ ∙ y) : (2 : ℤ) • o.oangle x z = (2 : ℤ) • o.oangle y z := by rw [Submodule.span_singleton_eq_span_singleton] at h rcases h with ⟨r, rfl⟩ exact (o.two_zsmul_oangle_smul_left_of_ne_zero _ _ (Units.ne_zero _)).symm #align orientation.two_zsmul_oangle_left_of_span_eq Orientation.two_zsmul_oangle_left_of_span_eq /-- If the spans of two vectors are equal, twice angles with those vectors on the right are equal. -/ theorem two_zsmul_oangle_right_of_span_eq (x : V) {y z : V} (h : (ℝ ∙ y) = ℝ ∙ z) : (2 : ℤ) • o.oangle x y = (2 : ℤ) • o.oangle x z := by rw [Submodule.span_singleton_eq_span_singleton] at h rcases h with ⟨r, rfl⟩ exact (o.two_zsmul_oangle_smul_right_of_ne_zero _ _ (Units.ne_zero _)).symm #align orientation.two_zsmul_oangle_right_of_span_eq Orientation.two_zsmul_oangle_right_of_span_eq /-- If the spans of two pairs of vectors are equal, twice angles between those vectors are equal. -/ theorem two_zsmul_oangle_of_span_eq_of_span_eq {w x y z : V} (hwx : (ℝ ∙ w) = ℝ ∙ x) (hyz : (ℝ ∙ y) = ℝ ∙ z) : (2 : ℤ) • o.oangle w y = (2 : ℤ) • o.oangle x z := by rw [o.two_zsmul_oangle_left_of_span_eq y hwx, o.two_zsmul_oangle_right_of_span_eq x hyz] #align orientation.two_zsmul_oangle_of_span_eq_of_span_eq Orientation.two_zsmul_oangle_of_span_eq_of_span_eq /-- The oriented angle between two vectors is zero if and only if the angle with the vectors swapped is zero. -/ theorem oangle_eq_zero_iff_oangle_rev_eq_zero {x y : V} : o.oangle x y = 0 ↔ o.oangle y x = 0 := by rw [oangle_rev, neg_eq_zero] #align orientation.oangle_eq_zero_iff_oangle_rev_eq_zero Orientation.oangle_eq_zero_iff_oangle_rev_eq_zero /-- The oriented angle between two vectors is zero if and only if they are on the same ray. -/ theorem oangle_eq_zero_iff_sameRay {x y : V} : o.oangle x y = 0 ↔ SameRay ℝ x y := by rw [oangle, kahler_apply_apply, Complex.arg_coe_angle_eq_iff_eq_toReal, Real.Angle.toReal_zero, Complex.arg_eq_zero_iff] simpa using o.nonneg_inner_and_areaForm_eq_zero_iff_sameRay x y #align orientation.oangle_eq_zero_iff_same_ray Orientation.oangle_eq_zero_iff_sameRay /-- The oriented angle between two vectors is `π` if and only if the angle with the vectors swapped is `π`. -/ theorem oangle_eq_pi_iff_oangle_rev_eq_pi {x y : V} : o.oangle x y = π ↔ o.oangle y x = π := by rw [oangle_rev, neg_eq_iff_eq_neg, Real.Angle.neg_coe_pi] #align orientation.oangle_eq_pi_iff_oangle_rev_eq_pi Orientation.oangle_eq_pi_iff_oangle_rev_eq_pi /-- The oriented angle between two vectors is `π` if and only they are nonzero and the first is on the same ray as the negation of the second. -/ theorem oangle_eq_pi_iff_sameRay_neg {x y : V} : o.oangle x y = π ↔ x ≠ 0 ∧ y ≠ 0 ∧ SameRay ℝ x (-y) := by rw [← o.oangle_eq_zero_iff_sameRay] constructor · intro h by_cases hx : x = 0; · simp [hx, Real.Angle.pi_ne_zero.symm] at h by_cases hy : y = 0; · simp [hy, Real.Angle.pi_ne_zero.symm] at h refine ⟨hx, hy, ?_⟩ rw [o.oangle_neg_right hx hy, h, Real.Angle.coe_pi_add_coe_pi] · rintro ⟨hx, hy, h⟩ rwa [o.oangle_neg_right hx hy, ← Real.Angle.sub_coe_pi_eq_add_coe_pi, sub_eq_zero] at h #align orientation.oangle_eq_pi_iff_same_ray_neg Orientation.oangle_eq_pi_iff_sameRay_neg /-- The oriented angle between two vectors is zero or `π` if and only if those two vectors are not linearly independent. -/ theorem oangle_eq_zero_or_eq_pi_iff_not_linearIndependent {x y : V} : o.oangle x y = 0 ∨ o.oangle x y = π ↔ ¬LinearIndependent ℝ ![x, y] := by rw [oangle_eq_zero_iff_sameRay, oangle_eq_pi_iff_sameRay_neg, sameRay_or_ne_zero_and_sameRay_neg_iff_not_linearIndependent] #align orientation.oangle_eq_zero_or_eq_pi_iff_not_linear_independent Orientation.oangle_eq_zero_or_eq_pi_iff_not_linearIndependent /-- The oriented angle between two vectors is zero or `π` if and only if the first vector is zero or the second is a multiple of the first. -/ theorem oangle_eq_zero_or_eq_pi_iff_right_eq_smul {x y : V} : o.oangle x y = 0 ∨ o.oangle x y = π ↔ x = 0 ∨ ∃ r : ℝ, y = r • x := by rw [oangle_eq_zero_iff_sameRay, oangle_eq_pi_iff_sameRay_neg] refine ⟨fun h => ?_, fun h => ?_⟩ · rcases h with (h | ⟨-, -, h⟩) · by_cases hx : x = 0; · simp [hx] obtain ⟨r, -, rfl⟩ := h.exists_nonneg_left hx exact Or.inr ⟨r, rfl⟩ · by_cases hx : x = 0; · simp [hx] obtain ⟨r, -, hy⟩ := h.exists_nonneg_left hx refine Or.inr ⟨-r, ?_⟩ simp [hy] · rcases h with (rfl | ⟨r, rfl⟩); · simp by_cases hx : x = 0; · simp [hx] rcases lt_trichotomy r 0 with (hr | hr | hr) · rw [← neg_smul] exact Or.inr ⟨hx, smul_ne_zero hr.ne hx, SameRay.sameRay_pos_smul_right x (Left.neg_pos_iff.2 hr)⟩ · simp [hr] · exact Or.inl (SameRay.sameRay_pos_smul_right x hr) #align orientation.oangle_eq_zero_or_eq_pi_iff_right_eq_smul Orientation.oangle_eq_zero_or_eq_pi_iff_right_eq_smul /-- The oriented angle between two vectors is not zero or `π` if and only if those two vectors are linearly independent. -/ theorem oangle_ne_zero_and_ne_pi_iff_linearIndependent {x y : V} : o.oangle x y ≠ 0 ∧ o.oangle x y ≠ π ↔ LinearIndependent ℝ ![x, y] := by rw [← not_or, ← not_iff_not, Classical.not_not, oangle_eq_zero_or_eq_pi_iff_not_linearIndependent] #align orientation.oangle_ne_zero_and_ne_pi_iff_linear_independent Orientation.oangle_ne_zero_and_ne_pi_iff_linearIndependent /-- Two vectors are equal if and only if they have equal norms and zero angle between them. -/ theorem eq_iff_norm_eq_and_oangle_eq_zero (x y : V) : x = y ↔ ‖x‖ = ‖y‖ ∧ o.oangle x y = 0 := by rw [oangle_eq_zero_iff_sameRay] constructor · rintro rfl simp; rfl · rcases eq_or_ne y 0 with (rfl | hy) · simp rintro ⟨h₁, h₂⟩ obtain ⟨r, hr, rfl⟩ := h₂.exists_nonneg_right hy have : ‖y‖ ≠ 0 := by simpa using hy obtain rfl : r = 1 := by apply mul_right_cancel₀ this simpa [norm_smul, _root_.abs_of_nonneg hr] using h₁ simp #align orientation.eq_iff_norm_eq_and_oangle_eq_zero Orientation.eq_iff_norm_eq_and_oangle_eq_zero /-- Two vectors with equal norms are equal if and only if they have zero angle between them. -/ theorem eq_iff_oangle_eq_zero_of_norm_eq {x y : V} (h : ‖x‖ = ‖y‖) : x = y ↔ o.oangle x y = 0 := ⟨fun he => ((o.eq_iff_norm_eq_and_oangle_eq_zero x y).1 he).2, fun ha => (o.eq_iff_norm_eq_and_oangle_eq_zero x y).2 ⟨h, ha⟩⟩ #align orientation.eq_iff_oangle_eq_zero_of_norm_eq Orientation.eq_iff_oangle_eq_zero_of_norm_eq /-- Two vectors with zero angle between them are equal if and only if they have equal norms. -/ theorem eq_iff_norm_eq_of_oangle_eq_zero {x y : V} (h : o.oangle x y = 0) : x = y ↔ ‖x‖ = ‖y‖ := ⟨fun he => ((o.eq_iff_norm_eq_and_oangle_eq_zero x y).1 he).1, fun hn => (o.eq_iff_norm_eq_and_oangle_eq_zero x y).2 ⟨hn, h⟩⟩ #align orientation.eq_iff_norm_eq_of_oangle_eq_zero Orientation.eq_iff_norm_eq_of_oangle_eq_zero /-- Given three nonzero vectors, the angle between the first and the second plus the angle between the second and the third equals the angle between the first and the third. -/ @[simp] theorem oangle_add {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x y + o.oangle y z = o.oangle x z := by simp_rw [oangle] rw [← Complex.arg_mul_coe_angle, o.kahler_mul y x z] · congr 1 convert Complex.arg_real_mul _ (_ : 0 < ‖y‖ ^ 2) using 2 · norm_cast · have : 0 < ‖y‖ := by simpa using hy positivity · exact o.kahler_ne_zero hx hy · exact o.kahler_ne_zero hy hz #align orientation.oangle_add Orientation.oangle_add /-- Given three nonzero vectors, the angle between the second and the third plus the angle between the first and the second equals the angle between the first and the third. -/ @[simp] theorem oangle_add_swap {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle y z + o.oangle x y = o.oangle x z := by rw [add_comm, o.oangle_add hx hy hz] #align orientation.oangle_add_swap Orientation.oangle_add_swap /-- Given three nonzero vectors, the angle between the first and the third minus the angle between the first and the second equals the angle between the second and the third. -/ @[simp] theorem oangle_sub_left {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x z - o.oangle x y = o.oangle y z := by rw [sub_eq_iff_eq_add, o.oangle_add_swap hx hy hz] #align orientation.oangle_sub_left Orientation.oangle_sub_left /-- Given three nonzero vectors, the angle between the first and the third minus the angle between the second and the third equals the angle between the first and the second. -/ @[simp] theorem oangle_sub_right {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x z - o.oangle y z = o.oangle x y := by rw [sub_eq_iff_eq_add, o.oangle_add hx hy hz] #align orientation.oangle_sub_right Orientation.oangle_sub_right /-- Given three nonzero vectors, adding the angles between them in cyclic order results in 0. -/ @[simp] theorem oangle_add_cyc3 {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x y + o.oangle y z + o.oangle z x = 0 := by simp [hx, hy, hz] #align orientation.oangle_add_cyc3 Orientation.oangle_add_cyc3 /-- Given three nonzero vectors, adding the angles between them in cyclic order, with the first vector in each angle negated, results in π. If the vectors add to 0, this is a version of the sum of the angles of a triangle. -/ @[simp] theorem oangle_add_cyc3_neg_left {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle (-x) y + o.oangle (-y) z + o.oangle (-z) x = π := by rw [o.oangle_neg_left hx hy, o.oangle_neg_left hy hz, o.oangle_neg_left hz hx, show o.oangle x y + π + (o.oangle y z + π) + (o.oangle z x + π) = o.oangle x y + o.oangle y z + o.oangle z x + (π + π + π : Real.Angle) by abel, o.oangle_add_cyc3 hx hy hz, Real.Angle.coe_pi_add_coe_pi, zero_add, zero_add] #align orientation.oangle_add_cyc3_neg_left Orientation.oangle_add_cyc3_neg_left /-- Given three nonzero vectors, adding the angles between them in cyclic order, with the second vector in each angle negated, results in π. If the vectors add to 0, this is a version of the sum of the angles of a triangle. -/ @[simp] theorem oangle_add_cyc3_neg_right {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x (-y) + o.oangle y (-z) + o.oangle z (-x) = π := by simp_rw [← oangle_neg_left_eq_neg_right, o.oangle_add_cyc3_neg_left hx hy hz] #align orientation.oangle_add_cyc3_neg_right Orientation.oangle_add_cyc3_neg_right /-- Pons asinorum, oriented vector angle form. -/ theorem oangle_sub_eq_oangle_sub_rev_of_norm_eq {x y : V} (h : ‖x‖ = ‖y‖) : o.oangle x (x - y) = o.oangle (y - x) y := by simp [oangle, h] #align orientation.oangle_sub_eq_oangle_sub_rev_of_norm_eq Orientation.oangle_sub_eq_oangle_sub_rev_of_norm_eq /-- The angle at the apex of an isosceles triangle is `π` minus twice a base angle, oriented vector angle form. -/ theorem oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq {x y : V} (hn : x ≠ y) (h : ‖x‖ = ‖y‖) : o.oangle y x = π - (2 : ℤ) • o.oangle (y - x) y := by rw [two_zsmul] nth_rw 1 [← o.oangle_sub_eq_oangle_sub_rev_of_norm_eq h] rw [eq_sub_iff_add_eq, ← oangle_neg_neg, ← add_assoc] have hy : y ≠ 0 := by rintro rfl rw [norm_zero, norm_eq_zero] at h exact hn h have hx : x ≠ 0 := norm_ne_zero_iff.1 (h.symm ▸ norm_ne_zero_iff.2 hy) convert o.oangle_add_cyc3_neg_right (neg_ne_zero.2 hy) hx (sub_ne_zero_of_ne hn.symm) using 1 simp #align orientation.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq Orientation.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq /-- The angle between two vectors, with respect to an orientation given by `Orientation.map` with a linear isometric equivalence, equals the angle between those two vectors, transformed by the inverse of that equivalence, with respect to the original orientation. -/ @[simp] theorem oangle_map (x y : V') (f : V ≃ₗᵢ[ℝ] V') : (Orientation.map (Fin 2) f.toLinearEquiv o).oangle x y = o.oangle (f.symm x) (f.symm y) := by simp [oangle, o.kahler_map] #align orientation.oangle_map Orientation.oangle_map @[simp] protected theorem _root_.Complex.oangle (w z : ℂ) : Complex.orientation.oangle w z = Complex.arg (conj w * z) := by simp [oangle] #align complex.oangle Complex.oangle /-- The oriented angle on an oriented real inner product space of dimension 2 can be evaluated in terms of a complex-number representation of the space. -/ theorem oangle_map_complex (f : V ≃ₗᵢ[ℝ] ℂ) (hf : Orientation.map (Fin 2) f.toLinearEquiv o = Complex.orientation) (x y : V) : o.oangle x y = Complex.arg (conj (f x) * f y) := by rw [← Complex.oangle, ← hf, o.oangle_map] iterate 2 rw [LinearIsometryEquiv.symm_apply_apply] #align orientation.oangle_map_complex Orientation.oangle_map_complex /-- Negating the orientation negates the value of `oangle`. -/ theorem oangle_neg_orientation_eq_neg (x y : V) : (-o).oangle x y = -o.oangle x y := by simp [oangle] #align orientation.oangle_neg_orientation_eq_neg Orientation.oangle_neg_orientation_eq_neg /-- The inner product of two vectors is the product of the norms and the cosine of the oriented angle between the vectors. -/ theorem inner_eq_norm_mul_norm_mul_cos_oangle (x y : V) : ⟪x, y⟫ = ‖x‖ * ‖y‖ * Real.Angle.cos (o.oangle x y) := by by_cases hx : x = 0; · simp [hx] by_cases hy : y = 0; · simp [hy] have : ‖x‖ ≠ 0 := by simpa using hx have : ‖y‖ ≠ 0 := by simpa using hy rw [oangle, Real.Angle.cos_coe, Complex.cos_arg, o.abs_kahler] · simp only [kahler_apply_apply, real_smul, add_re, ofReal_re, mul_re, I_re, ofReal_im] field_simp · exact o.kahler_ne_zero hx hy #align orientation.inner_eq_norm_mul_norm_mul_cos_oangle Orientation.inner_eq_norm_mul_norm_mul_cos_oangle /-- The cosine of the oriented angle between two nonzero vectors is the inner product divided by the product of the norms. -/ theorem cos_oangle_eq_inner_div_norm_mul_norm {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : Real.Angle.cos (o.oangle x y) = ⟪x, y⟫ / (‖x‖ * ‖y‖) := by rw [o.inner_eq_norm_mul_norm_mul_cos_oangle] field_simp [norm_ne_zero_iff.2 hx, norm_ne_zero_iff.2 hy] #align orientation.cos_oangle_eq_inner_div_norm_mul_norm Orientation.cos_oangle_eq_inner_div_norm_mul_norm /-- The cosine of the oriented angle between two nonzero vectors equals that of the unoriented angle. -/ theorem cos_oangle_eq_cos_angle {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : Real.Angle.cos (o.oangle x y) = Real.cos (InnerProductGeometry.angle x y) := by rw [o.cos_oangle_eq_inner_div_norm_mul_norm hx hy, InnerProductGeometry.cos_angle] #align orientation.cos_oangle_eq_cos_angle Orientation.cos_oangle_eq_cos_angle /-- The oriented angle between two nonzero vectors is plus or minus the unoriented angle. -/ theorem oangle_eq_angle_or_eq_neg_angle {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : o.oangle x y = InnerProductGeometry.angle x y ∨ o.oangle x y = -InnerProductGeometry.angle x y := Real.Angle.cos_eq_real_cos_iff_eq_or_eq_neg.1 <| o.cos_oangle_eq_cos_angle hx hy #align orientation.oangle_eq_angle_or_eq_neg_angle Orientation.oangle_eq_angle_or_eq_neg_angle /-- The unoriented angle between two nonzero vectors is the absolute value of the oriented angle, converted to a real. -/ theorem angle_eq_abs_oangle_toReal {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : InnerProductGeometry.angle x y = |(o.oangle x y).toReal| := by have h0 := InnerProductGeometry.angle_nonneg x y have hpi := InnerProductGeometry.angle_le_pi x y rcases o.oangle_eq_angle_or_eq_neg_angle hx hy with (h | h) · rw [h, eq_comm, Real.Angle.abs_toReal_coe_eq_self_iff] exact ⟨h0, hpi⟩ · rw [h, eq_comm, Real.Angle.abs_toReal_neg_coe_eq_self_iff] exact ⟨h0, hpi⟩ #align orientation.angle_eq_abs_oangle_to_real Orientation.angle_eq_abs_oangle_toReal /-- If the sign of the oriented angle between two vectors is zero, either one of the vectors is zero or the unoriented angle is 0 or π. -/ theorem eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero {x y : V} (h : (o.oangle x y).sign = 0) : x = 0 ∨ y = 0 ∨ InnerProductGeometry.angle x y = 0 ∨ InnerProductGeometry.angle x y = π := by by_cases hx : x = 0; · simp [hx] by_cases hy : y = 0; · simp [hy] rw [o.angle_eq_abs_oangle_toReal hx hy] rw [Real.Angle.sign_eq_zero_iff] at h rcases h with (h | h) <;> simp [h, Real.pi_pos.le] #align orientation.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero Orientation.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero /-- If two unoriented angles are equal, and the signs of the corresponding oriented angles are equal, then the oriented angles are equal (even in degenerate cases). -/ theorem oangle_eq_of_angle_eq_of_sign_eq {w x y z : V} (h : InnerProductGeometry.angle w x = InnerProductGeometry.angle y z) (hs : (o.oangle w x).sign = (o.oangle y z).sign) : o.oangle w x = o.oangle y z := by by_cases h0 : (w = 0 ∨ x = 0) ∨ y = 0 ∨ z = 0 · have hs' : (o.oangle w x).sign = 0 ∧ (o.oangle y z).sign = 0 := by rcases h0 with ((rfl | rfl) | rfl | rfl) · simpa using hs.symm · simpa using hs.symm · simpa using hs · simpa using hs rcases hs' with ⟨hswx, hsyz⟩ have h' : InnerProductGeometry.angle w x = π / 2 ∧ InnerProductGeometry.angle y z = π / 2 := by rcases h0 with ((rfl | rfl) | rfl | rfl) · simpa using h.symm · simpa using h.symm · simpa using h · simpa using h rcases h' with ⟨hwx, hyz⟩ have hpi : π / 2 ≠ π := by intro hpi rw [div_eq_iff, eq_comm, ← sub_eq_zero, mul_two, add_sub_cancel_right] at hpi · exact Real.pi_pos.ne.symm hpi · exact two_ne_zero have h0wx : w = 0 ∨ x = 0 := by have h0' := o.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero hswx simpa [hwx, Real.pi_pos.ne.symm, hpi] using h0' have h0yz : y = 0 ∨ z = 0 := by have h0' := o.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero hsyz simpa [hyz, Real.pi_pos.ne.symm, hpi] using h0' rcases h0wx with (h0wx | h0wx) <;> rcases h0yz with (h0yz | h0yz) <;> simp [h0wx, h0yz] · push_neg at h0 rw [Real.Angle.eq_iff_abs_toReal_eq_of_sign_eq hs] rwa [o.angle_eq_abs_oangle_toReal h0.1.1 h0.1.2, o.angle_eq_abs_oangle_toReal h0.2.1 h0.2.2] at h #align orientation.oangle_eq_of_angle_eq_of_sign_eq Orientation.oangle_eq_of_angle_eq_of_sign_eq /-- If the signs of two oriented angles between nonzero vectors are equal, the oriented angles are equal if and only if the unoriented angles are equal. -/
Mathlib/Geometry/Euclidean/Angle/Oriented/Basic.lean
721
726
theorem angle_eq_iff_oangle_eq_of_sign_eq {w x y z : V} (hw : w ≠ 0) (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) (hs : (o.oangle w x).sign = (o.oangle y z).sign) : InnerProductGeometry.angle w x = InnerProductGeometry.angle y z ↔ o.oangle w x = o.oangle y z := by
refine ⟨fun h => o.oangle_eq_of_angle_eq_of_sign_eq h hs, fun h => ?_⟩ rw [o.angle_eq_abs_oangle_toReal hw hx, o.angle_eq_abs_oangle_toReal hy hz, h]
/- Copyright (c) 2022 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang, Jujian Zhang -/ import Mathlib.Algebra.Algebra.Bilinear import Mathlib.RingTheory.Localization.Basic #align_import algebra.module.localized_module from "leanprover-community/mathlib"@"831c494092374cfe9f50591ed0ac81a25efc5b86" /-! # Localized Module Given a commutative semiring `R`, a multiplicative subset `S ⊆ R` and an `R`-module `M`, we can localize `M` by `S`. This gives us a `Localization S`-module. ## Main definitions * `LocalizedModule.r` : the equivalence relation defining this localization, namely `(m, s) ≈ (m', s')` if and only if there is some `u : S` such that `u • s' • m = u • s • m'`. * `LocalizedModule M S` : the localized module by `S`. * `LocalizedModule.mk` : the canonical map sending `(m, s) : M × S ↦ m/s : LocalizedModule M S` * `LocalizedModule.liftOn` : any well defined function `f : M × S → α` respecting `r` descents to a function `LocalizedModule M S → α` * `LocalizedModule.liftOn₂` : any well defined function `f : M × S → M × S → α` respecting `r` descents to a function `LocalizedModule M S → LocalizedModule M S` * `LocalizedModule.mk_add_mk` : in the localized module `mk m s + mk m' s' = mk (s' • m + s • m') (s * s')` * `LocalizedModule.mk_smul_mk` : in the localized module, for any `r : R`, `s t : S`, `m : M`, we have `mk r s • mk m t = mk (r • m) (s * t)` where `mk r s : Localization S` is localized ring by `S`. * `LocalizedModule.isModule` : `LocalizedModule M S` is a `Localization S`-module. ## Future work * Redefine `Localization` for monoids and rings to coincide with `LocalizedModule`. -/ namespace LocalizedModule universe u v variable {R : Type u} [CommSemiring R] (S : Submonoid R) variable (M : Type v) [AddCommMonoid M] [Module R M] variable (T : Type*) [CommSemiring T] [Algebra R T] [IsLocalization S T] /-- The equivalence relation on `M × S` where `(m1, s1) ≈ (m2, s2)` if and only if for some (u : S), u * (s2 • m1 - s1 • m2) = 0-/ /- Porting note: We use small letter `r` since `R` is used for a ring. -/ def r (a b : M × S) : Prop := ∃ u : S, u • b.2 • a.1 = u • a.2 • b.1 #align localized_module.r LocalizedModule.r theorem r.isEquiv : IsEquiv _ (r S M) := { refl := fun ⟨m, s⟩ => ⟨1, by rw [one_smul]⟩ trans := fun ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨m3, s3⟩ ⟨u1, hu1⟩ ⟨u2, hu2⟩ => by use u1 * u2 * s2 -- Put everything in the same shape, sorting the terms using `simp` have hu1' := congr_arg ((u2 * s3) • ·) hu1.symm have hu2' := congr_arg ((u1 * s1) • ·) hu2.symm simp only [← mul_smul, smul_assoc, mul_assoc, mul_comm, mul_left_comm] at hu1' hu2' ⊢ rw [hu2', hu1'] symm := fun ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨u, hu⟩ => ⟨u, hu.symm⟩ } #align localized_module.r.is_equiv LocalizedModule.r.isEquiv instance r.setoid : Setoid (M × S) where r := r S M iseqv := ⟨(r.isEquiv S M).refl, (r.isEquiv S M).symm _ _, (r.isEquiv S M).trans _ _ _⟩ #align localized_module.r.setoid LocalizedModule.r.setoid -- TODO: change `Localization` to use `r'` instead of `r` so that the two types are also defeq, -- `Localization S = LocalizedModule S R`. example {R} [CommSemiring R] (S : Submonoid R) : ⇑(Localization.r' S) = LocalizedModule.r S R := rfl /-- If `S` is a multiplicative subset of a ring `R` and `M` an `R`-module, then we can localize `M` by `S`. -/ -- Porting note(#5171): @[nolint has_nonempty_instance] def _root_.LocalizedModule : Type max u v := Quotient (r.setoid S M) #align localized_module LocalizedModule section variable {M S} /-- The canonical map sending `(m, s) ↦ m/s`-/ def mk (m : M) (s : S) : LocalizedModule S M := Quotient.mk' ⟨m, s⟩ #align localized_module.mk LocalizedModule.mk theorem mk_eq {m m' : M} {s s' : S} : mk m s = mk m' s' ↔ ∃ u : S, u • s' • m = u • s • m' := Quotient.eq' #align localized_module.mk_eq LocalizedModule.mk_eq @[elab_as_elim] theorem induction_on {β : LocalizedModule S M → Prop} (h : ∀ (m : M) (s : S), β (mk m s)) : ∀ x : LocalizedModule S M, β x := by rintro ⟨⟨m, s⟩⟩ exact h m s #align localized_module.induction_on LocalizedModule.induction_on @[elab_as_elim] theorem induction_on₂ {β : LocalizedModule S M → LocalizedModule S M → Prop} (h : ∀ (m m' : M) (s s' : S), β (mk m s) (mk m' s')) : ∀ x y, β x y := by rintro ⟨⟨m, s⟩⟩ ⟨⟨m', s'⟩⟩ exact h m m' s s' #align localized_module.induction_on₂ LocalizedModule.induction_on₂ /-- If `f : M × S → α` respects the equivalence relation `LocalizedModule.r`, then `f` descents to a map `LocalizedModule M S → α`. -/ def liftOn {α : Type*} (x : LocalizedModule S M) (f : M × S → α) (wd : ∀ (p p' : M × S), p ≈ p' → f p = f p') : α := Quotient.liftOn x f wd #align localized_module.lift_on LocalizedModule.liftOn theorem liftOn_mk {α : Type*} {f : M × S → α} (wd : ∀ (p p' : M × S), p ≈ p' → f p = f p') (m : M) (s : S) : liftOn (mk m s) f wd = f ⟨m, s⟩ := by convert Quotient.liftOn_mk f wd ⟨m, s⟩ #align localized_module.lift_on_mk LocalizedModule.liftOn_mk /-- If `f : M × S → M × S → α` respects the equivalence relation `LocalizedModule.r`, then `f` descents to a map `LocalizedModule M S → LocalizedModule M S → α`. -/ def liftOn₂ {α : Type*} (x y : LocalizedModule S M) (f : M × S → M × S → α) (wd : ∀ (p q p' q' : M × S), p ≈ p' → q ≈ q' → f p q = f p' q') : α := Quotient.liftOn₂ x y f wd #align localized_module.lift_on₂ LocalizedModule.liftOn₂ theorem liftOn₂_mk {α : Type*} (f : M × S → M × S → α) (wd : ∀ (p q p' q' : M × S), p ≈ p' → q ≈ q' → f p q = f p' q') (m m' : M) (s s' : S) : liftOn₂ (mk m s) (mk m' s') f wd = f ⟨m, s⟩ ⟨m', s'⟩ := by convert Quotient.liftOn₂_mk f wd _ _ #align localized_module.lift_on₂_mk LocalizedModule.liftOn₂_mk instance : Zero (LocalizedModule S M) := ⟨mk 0 1⟩ /-- If `S` contains `0` then the localization at `S` is trivial. -/ theorem subsingleton (h : 0 ∈ S) : Subsingleton (LocalizedModule S M) := by refine ⟨fun a b ↦ ?_⟩ induction a,b using LocalizedModule.induction_on₂ exact mk_eq.mpr ⟨⟨0, h⟩, by simp only [Submonoid.mk_smul, zero_smul]⟩ @[simp] theorem zero_mk (s : S) : mk (0 : M) s = 0 := mk_eq.mpr ⟨1, by rw [one_smul, smul_zero, smul_zero, one_smul]⟩ #align localized_module.zero_mk LocalizedModule.zero_mk instance : Add (LocalizedModule S M) where add p1 p2 := liftOn₂ p1 p2 (fun x y => mk (y.2 • x.1 + x.2 • y.1) (x.2 * y.2)) <| fun ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨m1', s1'⟩ ⟨m2', s2'⟩ ⟨u1, hu1⟩ ⟨u2, hu2⟩ => mk_eq.mpr ⟨u1 * u2, by -- Put everything in the same shape, sorting the terms using `simp` have hu1' := congr_arg ((u2 * s2 * s2') • ·) hu1 have hu2' := congr_arg ((u1 * s1 * s1') • ·) hu2 simp only [smul_add, ← mul_smul, smul_assoc, mul_assoc, mul_comm, mul_left_comm] at hu1' hu2' ⊢ rw [hu1', hu2']⟩ theorem mk_add_mk {m1 m2 : M} {s1 s2 : S} : mk m1 s1 + mk m2 s2 = mk (s2 • m1 + s1 • m2) (s1 * s2) := mk_eq.mpr <| ⟨1, rfl⟩ #align localized_module.mk_add_mk LocalizedModule.mk_add_mk /-- Porting note: Some auxiliary lemmas are declared with `private` in the original mathlib3 file. We take that policy here as well, and remove the `#align` lines accordingly. -/ private theorem add_assoc' (x y z : LocalizedModule S M) : x + y + z = x + (y + z) := by induction' x using LocalizedModule.induction_on with mx sx induction' y using LocalizedModule.induction_on with my sy induction' z using LocalizedModule.induction_on with mz sz simp only [mk_add_mk, smul_add] refine mk_eq.mpr ⟨1, ?_⟩ rw [one_smul, one_smul] congr 1 · rw [mul_assoc] · rw [eq_comm, mul_comm, add_assoc, mul_smul, mul_smul, ← mul_smul sx sz, mul_comm, mul_smul] private theorem add_comm' (x y : LocalizedModule S M) : x + y = y + x := LocalizedModule.induction_on₂ (fun m m' s s' => by rw [mk_add_mk, mk_add_mk, add_comm, mul_comm]) x y private theorem zero_add' (x : LocalizedModule S M) : 0 + x = x := induction_on (fun m s => by rw [← zero_mk s, mk_add_mk, smul_zero, zero_add, mk_eq]; exact ⟨1, by rw [one_smul, mul_smul, one_smul]⟩) x private theorem add_zero' (x : LocalizedModule S M) : x + 0 = x := induction_on (fun m s => by rw [← zero_mk s, mk_add_mk, smul_zero, add_zero, mk_eq]; exact ⟨1, by rw [one_smul, mul_smul, one_smul]⟩) x instance hasNatSMul : SMul ℕ (LocalizedModule S M) where smul n := nsmulRec n #align localized_module.has_nat_smul LocalizedModule.hasNatSMul private theorem nsmul_zero' (x : LocalizedModule S M) : (0 : ℕ) • x = 0 := LocalizedModule.induction_on (fun _ _ => rfl) x private theorem nsmul_succ' (n : ℕ) (x : LocalizedModule S M) : n.succ • x = n • x + x := LocalizedModule.induction_on (fun _ _ => rfl) x instance : AddCommMonoid (LocalizedModule S M) where add := (· + ·) add_assoc := add_assoc' zero := 0 zero_add := zero_add' add_zero := add_zero' nsmul := (· • ·) nsmul_zero := nsmul_zero' nsmul_succ := nsmul_succ' add_comm := add_comm' instance {M : Type*} [AddCommGroup M] [Module R M] : Neg (LocalizedModule S M) where neg p := liftOn p (fun x => LocalizedModule.mk (-x.1) x.2) fun ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨u, hu⟩ => by rw [mk_eq] exact ⟨u, by simpa⟩ instance {M : Type*} [AddCommGroup M] [Module R M] : AddCommGroup (LocalizedModule S M) := { show AddCommMonoid (LocalizedModule S M) by infer_instance with add_left_neg := by rintro ⟨m, s⟩ change (liftOn (mk m s) (fun x => mk (-x.1) x.2) fun ⟨m1, s1⟩ ⟨m2, s2⟩ ⟨u, hu⟩ => by rw [mk_eq] exact ⟨u, by simpa⟩) + mk m s = 0 rw [liftOn_mk, mk_add_mk] simp -- TODO: fix the diamond zsmul := zsmulRec } theorem mk_neg {M : Type*} [AddCommGroup M] [Module R M] {m : M} {s : S} : mk (-m) s = -mk m s := rfl #align localized_module.mk_neg LocalizedModule.mk_neg instance {A : Type*} [Semiring A] [Algebra R A] {S : Submonoid R} : Monoid (LocalizedModule S A) := { mul := fun m₁ m₂ => liftOn₂ m₁ m₂ (fun x₁ x₂ => LocalizedModule.mk (x₁.1 * x₂.1) (x₁.2 * x₂.2)) (by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ ⟨b₁, t₁⟩ ⟨b₂, t₂⟩ ⟨u₁, e₁⟩ ⟨u₂, e₂⟩ rw [mk_eq] use u₁ * u₂ dsimp only at e₁ e₂ ⊢ rw [eq_comm] trans (u₁ • t₁ • a₁) • u₂ • t₂ • a₂ on_goal 1 => rw [e₁, e₂] on_goal 2 => rw [eq_comm] all_goals rw [smul_smul, mul_mul_mul_comm, ← smul_eq_mul, ← smul_eq_mul A, smul_smul_smul_comm, mul_smul, mul_smul]) one := mk 1 (1 : S) one_mul := by rintro ⟨a, s⟩ exact mk_eq.mpr ⟨1, by simp only [one_mul, one_smul]⟩ mul_one := by rintro ⟨a, s⟩ exact mk_eq.mpr ⟨1, by simp only [mul_one, one_smul]⟩ mul_assoc := by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ ⟨a₃, s₃⟩ apply mk_eq.mpr _ use 1 simp only [one_mul, smul_smul, ← mul_assoc, mul_right_comm] } instance {A : Type*} [Semiring A] [Algebra R A] {S : Submonoid R} : Semiring (LocalizedModule S A) := { show (AddCommMonoid (LocalizedModule S A)) by infer_instance, show (Monoid (LocalizedModule S A)) by infer_instance with left_distrib := by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ ⟨a₃, s₃⟩ apply mk_eq.mpr _ use 1 simp only [one_mul, smul_add, mul_add, mul_smul_comm, smul_smul, ← mul_assoc, mul_right_comm] right_distrib := by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ ⟨a₃, s₃⟩ apply mk_eq.mpr _ use 1 simp only [one_mul, smul_add, add_mul, smul_smul, ← mul_assoc, smul_mul_assoc, mul_right_comm] zero_mul := by rintro ⟨a, s⟩ exact mk_eq.mpr ⟨1, by simp only [zero_mul, smul_zero]⟩ mul_zero := by rintro ⟨a, s⟩ exact mk_eq.mpr ⟨1, by simp only [mul_zero, smul_zero]⟩ } instance {A : Type*} [CommSemiring A] [Algebra R A] {S : Submonoid R} : CommSemiring (LocalizedModule S A) := { show Semiring (LocalizedModule S A) by infer_instance with mul_comm := by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ exact mk_eq.mpr ⟨1, by simp only [one_smul, mul_comm]⟩ } instance {A : Type*} [Ring A] [Algebra R A] {S : Submonoid R} : Ring (LocalizedModule S A) := { inferInstanceAs (AddCommGroup (LocalizedModule S A)), inferInstanceAs (Semiring (LocalizedModule S A)) with } instance {A : Type*} [CommRing A] [Algebra R A] {S : Submonoid R} : CommRing (LocalizedModule S A) := { show (Ring (LocalizedModule S A)) by infer_instance with mul_comm := by rintro ⟨a₁, s₁⟩ ⟨a₂, s₂⟩ exact mk_eq.mpr ⟨1, by simp only [one_smul, mul_comm]⟩ } theorem mk_mul_mk {A : Type*} [Semiring A] [Algebra R A] {a₁ a₂ : A} {s₁ s₂ : S} : mk a₁ s₁ * mk a₂ s₂ = mk (a₁ * a₂) (s₁ * s₂) := rfl #align localized_module.mk_mul_mk LocalizedModule.mk_mul_mk noncomputable instance : SMul T (LocalizedModule S M) where smul x p := let a := IsLocalization.sec S x liftOn p (fun p ↦ mk (a.1 • p.1) (a.2 * p.2)) (by rintro p p' ⟨s, h⟩ refine mk_eq.mpr ⟨s, ?_⟩ calc _ = a.2 • a.1 • s • p'.2 • p.1 := by simp_rw [Submonoid.smul_def, Submonoid.coe_mul, ← mul_smul]; ring_nf _ = a.2 • a.1 • s • p.2 • p'.1 := by rw [h] _ = s • (a.2 * p.2) • a.1 • p'.1 := by simp_rw [Submonoid.smul_def, ← mul_smul, Submonoid.coe_mul]; ring_nf ) theorem smul_def (x : T) (m : M) (s : S) : x • mk m s = mk ((IsLocalization.sec S x).1 • m) ((IsLocalization.sec S x).2 * s) := rfl theorem mk'_smul_mk (r : R) (m : M) (s s' : S) : IsLocalization.mk' T r s • mk m s' = mk (r • m) (s * s') := by rw [smul_def, mk_eq] obtain ⟨c, hc⟩ := IsLocalization.eq.mp <| IsLocalization.mk'_sec T (IsLocalization.mk' T r s) use c simp_rw [← mul_smul, Submonoid.smul_def, Submonoid.coe_mul, ← mul_smul, ← mul_assoc, mul_comm _ (s':R), mul_assoc, hc] theorem mk_smul_mk (r : R) (m : M) (s t : S) : Localization.mk r s • mk m t = mk (r • m) (s * t) := by rw [Localization.mk_eq_mk'] exact mk'_smul_mk .. #align localized_module.mk_smul_mk LocalizedModule.mk_smul_mk variable {T} private theorem one_smul_aux (p : LocalizedModule S M) : (1 : T) • p = p := by induction' p using LocalizedModule.induction_on with m s rw [show (1:T) = IsLocalization.mk' T (1:R) (1:S) by rw [IsLocalization.mk'_one, map_one]] rw [mk'_smul_mk, one_smul, one_mul] private theorem mul_smul_aux (x y : T) (p : LocalizedModule S M) : (x * y) • p = x • y • p := by induction' p using LocalizedModule.induction_on with m s rw [← IsLocalization.mk'_sec (M := S) T x, ← IsLocalization.mk'_sec (M := S) T y] simp_rw [← IsLocalization.mk'_mul, mk'_smul_mk, ← mul_smul, mul_assoc] private theorem smul_add_aux (x : T) (p q : LocalizedModule S M) : x • (p + q) = x • p + x • q := by induction' p using LocalizedModule.induction_on with m s induction' q using LocalizedModule.induction_on with n t rw [smul_def, smul_def, mk_add_mk, mk_add_mk] rw [show x • _ = IsLocalization.mk' T _ _ • _ by rw [IsLocalization.mk'_sec (M := S) T]] rw [← IsLocalization.mk'_cancel _ _ (IsLocalization.sec S x).2, mk'_smul_mk] congr 1 · simp only [Submonoid.smul_def, smul_add, ← mul_smul, Submonoid.coe_mul]; ring_nf · rw [mul_mul_mul_comm] -- ring does not work here private theorem smul_zero_aux (x : T) : x • (0 : LocalizedModule S M) = 0 := by erw [smul_def, smul_zero, zero_mk] private theorem add_smul_aux (x y : T) (p : LocalizedModule S M) : (x + y) • p = x • p + y • p := by induction' p using LocalizedModule.induction_on with m s rw [smul_def T x, smul_def T y, mk_add_mk, show (x + y) • _ = IsLocalization.mk' T _ _ • _ by rw [← IsLocalization.mk'_sec (M := S) T x, ← IsLocalization.mk'_sec (M := S) T y, ← IsLocalization.mk'_add, IsLocalization.mk'_cancel _ _ s], mk'_smul_mk, ← smul_assoc, ← smul_assoc, ← add_smul] congr 1 · simp only [Submonoid.smul_def, Submonoid.coe_mul, smul_eq_mul]; ring_nf · rw [mul_mul_mul_comm, mul_assoc] -- ring does not work here private theorem zero_smul_aux (p : LocalizedModule S M) : (0 : T) • p = 0 := by induction' p using LocalizedModule.induction_on with m s rw [show (0:T) = IsLocalization.mk' T (0:R) (1:S) by rw [IsLocalization.mk'_zero], mk'_smul_mk, zero_smul, zero_mk] noncomputable instance isModule : Module T (LocalizedModule S M) where smul := (· • ·) one_smul := one_smul_aux mul_smul := mul_smul_aux smul_add := smul_add_aux smul_zero := smul_zero_aux add_smul := add_smul_aux zero_smul := zero_smul_aux @[simp] theorem mk_cancel_common_left (s' s : S) (m : M) : mk (s' • m) (s' * s) = mk m s := mk_eq.mpr ⟨1, by simp only [mul_smul, one_smul] rw [smul_comm]⟩ #align localized_module.mk_cancel_common_left LocalizedModule.mk_cancel_common_left @[simp] theorem mk_cancel (s : S) (m : M) : mk (s • m) s = mk m 1 := mk_eq.mpr ⟨1, by simp⟩ #align localized_module.mk_cancel LocalizedModule.mk_cancel @[simp] theorem mk_cancel_common_right (s s' : S) (m : M) : mk (s' • m) (s * s') = mk m s := mk_eq.mpr ⟨1, by simp [mul_smul]⟩ #align localized_module.mk_cancel_common_right LocalizedModule.mk_cancel_common_right noncomputable instance isModule' : Module R (LocalizedModule S M) := { Module.compHom (LocalizedModule S M) <| algebraMap R (Localization S) with } #align localized_module.is_module' LocalizedModule.isModule'
Mathlib/Algebra/Module/LocalizedModule.lean
427
428
theorem smul'_mk (r : R) (s : S) (m : M) : r • mk m s = mk (r • m) s := by
erw [mk_smul_mk r m 1 s, one_mul]
/- 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.MeasureTheory.Measure.WithDensity import Mathlib.Analysis.NormedSpace.Basic #align_import measure_theory.integral.lebesgue_normed_space from "leanprover-community/mathlib"@"bf6a01357ff5684b1ebcd0f1a13be314fc82c0bf" /-! # A lemma about measurability with density under scalar multiplication in normed spaces -/ open MeasureTheory Filter ENNReal Set open NNReal ENNReal variable {α β γ δ : Type*} {m : MeasurableSpace α} {μ : MeasureTheory.Measure α}
Mathlib/MeasureTheory/Integral/LebesgueNormedSpace.lean
20
47
theorem aemeasurable_withDensity_iff {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [SecondCountableTopology E] [MeasurableSpace E] [BorelSpace E] {f : α → ℝ≥0} (hf : Measurable f) {g : α → E} : AEMeasurable g (μ.withDensity fun x => (f x : ℝ≥0∞)) ↔ AEMeasurable (fun x => (f x : ℝ) • g x) μ := by
constructor · rintro ⟨g', g'meas, hg'⟩ have A : MeasurableSet { x : α | f x ≠ 0 } := (hf (measurableSet_singleton 0)).compl refine ⟨fun x => (f x : ℝ) • g' x, hf.coe_nnreal_real.smul g'meas, ?_⟩ apply @ae_of_ae_restrict_of_ae_restrict_compl _ _ _ { x | f x ≠ 0 } · rw [EventuallyEq, ae_withDensity_iff hf.coe_nnreal_ennreal] at hg' rw [ae_restrict_iff' A] filter_upwards [hg'] intro a ha h'a have : (f a : ℝ≥0∞) ≠ 0 := by simpa only [Ne, ENNReal.coe_eq_zero] using h'a rw [ha this] · filter_upwards [ae_restrict_mem A.compl] intro x hx simp only [Classical.not_not, mem_setOf_eq, mem_compl_iff] at hx simp [hx] · rintro ⟨g', g'meas, hg'⟩ refine ⟨fun x => (f x : ℝ)⁻¹ • g' x, hf.coe_nnreal_real.inv.smul g'meas, ?_⟩ rw [EventuallyEq, ae_withDensity_iff hf.coe_nnreal_ennreal] filter_upwards [hg'] intro x hx h'x rw [← hx, smul_smul, _root_.inv_mul_cancel, one_smul] simp only [Ne, ENNReal.coe_eq_zero] at h'x simpa only [NNReal.coe_eq_zero, Ne] using h'x
/- 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.Side import Mathlib.Geometry.Euclidean.Angle.Oriented.Rotation import Mathlib.Geometry.Euclidean.Angle.Unoriented.Affine #align_import geometry.euclidean.angle.oriented.affine from "leanprover-community/mathlib"@"46b633fd842bef9469441c0209906f6dddd2b4f5" /-! # Oriented angles. This file defines oriented angles in Euclidean affine spaces. ## Main definitions * `EuclideanGeometry.oangle`, with notation `∡`, is the oriented angle determined by three points. -/ noncomputable section open FiniteDimensional Complex open scoped Affine EuclideanGeometry Real RealInnerProductSpace ComplexConjugate namespace EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] [hd2 : Fact (finrank ℝ V = 2)] [Module.Oriented ℝ V (Fin 2)] /-- A fixed choice of positive orientation of Euclidean space `ℝ²` -/ abbrev o := @Module.Oriented.positiveOrientation /-- The oriented angle at `p₂` between the line segments to `p₁` and `p₃`, modulo `2 * π`. If either of those points equals `p₂`, this is 0. See `EuclideanGeometry.angle` for the corresponding unoriented angle definition. -/ def oangle (p₁ p₂ p₃ : P) : Real.Angle := o.oangle (p₁ -ᵥ p₂) (p₃ -ᵥ p₂) #align euclidean_geometry.oangle EuclideanGeometry.oangle @[inherit_doc] scoped notation "∡" => EuclideanGeometry.oangle /-- Oriented angles are continuous when neither end point equals the middle point. -/ theorem continuousAt_oangle {x : P × P × P} (hx12 : x.1 ≠ x.2.1) (hx32 : x.2.2 ≠ x.2.1) : ContinuousAt (fun y : P × P × P => ∡ y.1 y.2.1 y.2.2) x := by let f : P × P × P → V × V := fun y => (y.1 -ᵥ y.2.1, y.2.2 -ᵥ y.2.1) have hf1 : (f x).1 ≠ 0 := by simp [hx12] have hf2 : (f x).2 ≠ 0 := by simp [hx32] exact (o.continuousAt_oangle hf1 hf2).comp ((continuous_fst.vsub continuous_snd.fst).prod_mk (continuous_snd.snd.vsub continuous_snd.fst)).continuousAt #align euclidean_geometry.continuous_at_oangle EuclideanGeometry.continuousAt_oangle /-- The angle ∡AAB at a point. -/ @[simp] theorem oangle_self_left (p₁ p₂ : P) : ∡ p₁ p₁ p₂ = 0 := by simp [oangle] #align euclidean_geometry.oangle_self_left EuclideanGeometry.oangle_self_left /-- The angle ∡ABB at a point. -/ @[simp] theorem oangle_self_right (p₁ p₂ : P) : ∡ p₁ p₂ p₂ = 0 := by simp [oangle] #align euclidean_geometry.oangle_self_right EuclideanGeometry.oangle_self_right /-- The angle ∡ABA at a point. -/ @[simp] theorem oangle_self_left_right (p₁ p₂ : P) : ∡ p₁ p₂ p₁ = 0 := o.oangle_self _ #align euclidean_geometry.oangle_self_left_right EuclideanGeometry.oangle_self_left_right /-- If the angle between three points is nonzero, the first two points are not equal. -/ theorem left_ne_of_oangle_ne_zero {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ ≠ 0) : p₁ ≠ p₂ := by rw [← @vsub_ne_zero V]; exact o.left_ne_zero_of_oangle_ne_zero h #align euclidean_geometry.left_ne_of_oangle_ne_zero EuclideanGeometry.left_ne_of_oangle_ne_zero /-- If the angle between three points is nonzero, the last two points are not equal. -/ theorem right_ne_of_oangle_ne_zero {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ ≠ 0) : p₃ ≠ p₂ := by rw [← @vsub_ne_zero V]; exact o.right_ne_zero_of_oangle_ne_zero h #align euclidean_geometry.right_ne_of_oangle_ne_zero EuclideanGeometry.right_ne_of_oangle_ne_zero /-- If the angle between three points is nonzero, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_ne_zero {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ ≠ 0) : p₁ ≠ p₃ := by rw [← (vsub_left_injective p₂).ne_iff]; exact o.ne_of_oangle_ne_zero h #align euclidean_geometry.left_ne_right_of_oangle_ne_zero EuclideanGeometry.left_ne_right_of_oangle_ne_zero /-- If the angle between three points is `π`, the first two points are not equal. -/ theorem left_ne_of_oangle_eq_pi {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = π) : p₁ ≠ p₂ := left_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) #align euclidean_geometry.left_ne_of_oangle_eq_pi EuclideanGeometry.left_ne_of_oangle_eq_pi /-- If the angle between three points is `π`, the last two points are not equal. -/ theorem right_ne_of_oangle_eq_pi {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = π) : p₃ ≠ p₂ := right_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) #align euclidean_geometry.right_ne_of_oangle_eq_pi EuclideanGeometry.right_ne_of_oangle_eq_pi /-- If the angle between three points is `π`, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_eq_pi {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = π) : p₁ ≠ p₃ := left_ne_right_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) #align euclidean_geometry.left_ne_right_of_oangle_eq_pi EuclideanGeometry.left_ne_right_of_oangle_eq_pi /-- If the angle between three points is `π / 2`, the first two points are not equal. -/ theorem left_ne_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (π / 2 : ℝ)) : p₁ ≠ p₂ := left_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) #align euclidean_geometry.left_ne_of_oangle_eq_pi_div_two EuclideanGeometry.left_ne_of_oangle_eq_pi_div_two /-- If the angle between three points is `π / 2`, the last two points are not equal. -/ theorem right_ne_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (π / 2 : ℝ)) : p₃ ≠ p₂ := right_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) #align euclidean_geometry.right_ne_of_oangle_eq_pi_div_two EuclideanGeometry.right_ne_of_oangle_eq_pi_div_two /-- If the angle between three points is `π / 2`, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (π / 2 : ℝ)) : p₁ ≠ p₃ := left_ne_right_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) #align euclidean_geometry.left_ne_right_of_oangle_eq_pi_div_two EuclideanGeometry.left_ne_right_of_oangle_eq_pi_div_two /-- If the angle between three points is `-π / 2`, the first two points are not equal. -/ theorem left_ne_of_oangle_eq_neg_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (-π / 2 : ℝ)) : p₁ ≠ p₂ := left_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) #align euclidean_geometry.left_ne_of_oangle_eq_neg_pi_div_two EuclideanGeometry.left_ne_of_oangle_eq_neg_pi_div_two /-- If the angle between three points is `-π / 2`, the last two points are not equal. -/ theorem right_ne_of_oangle_eq_neg_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (-π / 2 : ℝ)) : p₃ ≠ p₂ := right_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) #align euclidean_geometry.right_ne_of_oangle_eq_neg_pi_div_two EuclideanGeometry.right_ne_of_oangle_eq_neg_pi_div_two /-- If the angle between three points is `-π / 2`, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_eq_neg_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (-π / 2 : ℝ)) : p₁ ≠ p₃ := left_ne_right_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) #align euclidean_geometry.left_ne_right_of_oangle_eq_neg_pi_div_two EuclideanGeometry.left_ne_right_of_oangle_eq_neg_pi_div_two /-- If the sign of the angle between three points is nonzero, the first two points are not equal. -/ theorem left_ne_of_oangle_sign_ne_zero {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign ≠ 0) : p₁ ≠ p₂ := left_ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 #align euclidean_geometry.left_ne_of_oangle_sign_ne_zero EuclideanGeometry.left_ne_of_oangle_sign_ne_zero /-- If the sign of the angle between three points is nonzero, the last two points are not equal. -/ theorem right_ne_of_oangle_sign_ne_zero {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign ≠ 0) : p₃ ≠ p₂ := right_ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 #align euclidean_geometry.right_ne_of_oangle_sign_ne_zero EuclideanGeometry.right_ne_of_oangle_sign_ne_zero /-- If the sign of the angle between three points is nonzero, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_sign_ne_zero {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign ≠ 0) : p₁ ≠ p₃ := left_ne_right_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 #align euclidean_geometry.left_ne_right_of_oangle_sign_ne_zero EuclideanGeometry.left_ne_right_of_oangle_sign_ne_zero /-- If the sign of the angle between three points is positive, the first two points are not equal. -/ theorem left_ne_of_oangle_sign_eq_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = 1) : p₁ ≠ p₂ := left_ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) #align euclidean_geometry.left_ne_of_oangle_sign_eq_one EuclideanGeometry.left_ne_of_oangle_sign_eq_one /-- If the sign of the angle between three points is positive, the last two points are not equal. -/ theorem right_ne_of_oangle_sign_eq_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = 1) : p₃ ≠ p₂ := right_ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) #align euclidean_geometry.right_ne_of_oangle_sign_eq_one EuclideanGeometry.right_ne_of_oangle_sign_eq_one /-- If the sign of the angle between three points is positive, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_sign_eq_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = 1) : p₁ ≠ p₃ := left_ne_right_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) #align euclidean_geometry.left_ne_right_of_oangle_sign_eq_one EuclideanGeometry.left_ne_right_of_oangle_sign_eq_one /-- If the sign of the angle between three points is negative, the first two points are not equal. -/ theorem left_ne_of_oangle_sign_eq_neg_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = -1) : p₁ ≠ p₂ := left_ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) #align euclidean_geometry.left_ne_of_oangle_sign_eq_neg_one EuclideanGeometry.left_ne_of_oangle_sign_eq_neg_one /-- If the sign of the angle between three points is negative, the last two points are not equal. -/ theorem right_ne_of_oangle_sign_eq_neg_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = -1) : p₃ ≠ p₂ := right_ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) #align euclidean_geometry.right_ne_of_oangle_sign_eq_neg_one EuclideanGeometry.right_ne_of_oangle_sign_eq_neg_one /-- If the sign of the angle between three points is negative, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_sign_eq_neg_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = -1) : p₁ ≠ p₃ := left_ne_right_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) #align euclidean_geometry.left_ne_right_of_oangle_sign_eq_neg_one EuclideanGeometry.left_ne_right_of_oangle_sign_eq_neg_one /-- Reversing the order of the points passed to `oangle` negates the angle. -/ theorem oangle_rev (p₁ p₂ p₃ : P) : ∡ p₃ p₂ p₁ = -∡ p₁ p₂ p₃ := o.oangle_rev _ _ #align euclidean_geometry.oangle_rev EuclideanGeometry.oangle_rev /-- Adding an angle to that with the order of the points reversed results in 0. -/ @[simp] theorem oangle_add_oangle_rev (p₁ p₂ p₃ : P) : ∡ p₁ p₂ p₃ + ∡ p₃ p₂ p₁ = 0 := o.oangle_add_oangle_rev _ _ #align euclidean_geometry.oangle_add_oangle_rev EuclideanGeometry.oangle_add_oangle_rev /-- An oriented angle is zero if and only if the angle with the order of the points reversed is zero. -/ theorem oangle_eq_zero_iff_oangle_rev_eq_zero {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = 0 ↔ ∡ p₃ p₂ p₁ = 0 := o.oangle_eq_zero_iff_oangle_rev_eq_zero #align euclidean_geometry.oangle_eq_zero_iff_oangle_rev_eq_zero EuclideanGeometry.oangle_eq_zero_iff_oangle_rev_eq_zero /-- An oriented angle is `π` if and only if the angle with the order of the points reversed is `π`. -/ theorem oangle_eq_pi_iff_oangle_rev_eq_pi {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = π ↔ ∡ p₃ p₂ p₁ = π := o.oangle_eq_pi_iff_oangle_rev_eq_pi #align euclidean_geometry.oangle_eq_pi_iff_oangle_rev_eq_pi EuclideanGeometry.oangle_eq_pi_iff_oangle_rev_eq_pi /-- An oriented angle is not zero or `π` if and only if the three points are affinely independent. -/ theorem oangle_ne_zero_and_ne_pi_iff_affineIndependent {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ ≠ 0 ∧ ∡ p₁ p₂ p₃ ≠ π ↔ AffineIndependent ℝ ![p₁, p₂, p₃] := by rw [oangle, o.oangle_ne_zero_and_ne_pi_iff_linearIndependent, affineIndependent_iff_linearIndependent_vsub ℝ _ (1 : Fin 3), ← linearIndependent_equiv (finSuccAboveEquiv (1 : Fin 3)).toEquiv] convert Iff.rfl ext i fin_cases i <;> rfl #align euclidean_geometry.oangle_ne_zero_and_ne_pi_iff_affine_independent EuclideanGeometry.oangle_ne_zero_and_ne_pi_iff_affineIndependent /-- An oriented angle is zero or `π` if and only if the three points are collinear. -/ theorem oangle_eq_zero_or_eq_pi_iff_collinear {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = 0 ∨ ∡ p₁ p₂ p₃ = π ↔ Collinear ℝ ({p₁, p₂, p₃} : Set P) := by rw [← not_iff_not, not_or, oangle_ne_zero_and_ne_pi_iff_affineIndependent, affineIndependent_iff_not_collinear_set] #align euclidean_geometry.oangle_eq_zero_or_eq_pi_iff_collinear EuclideanGeometry.oangle_eq_zero_or_eq_pi_iff_collinear /-- An oriented angle has a sign zero if and only if the three points are collinear. -/ theorem oangle_sign_eq_zero_iff_collinear {p₁ p₂ p₃ : P} : (∡ p₁ p₂ p₃).sign = 0 ↔ Collinear ℝ ({p₁, p₂, p₃} : Set P) := by rw [Real.Angle.sign_eq_zero_iff, oangle_eq_zero_or_eq_pi_iff_collinear] /-- If twice the oriented angles between two triples of points are equal, one triple is affinely independent if and only if the other is. -/ theorem affineIndependent_iff_of_two_zsmul_oangle_eq {p₁ p₂ p₃ p₄ p₅ p₆ : P} (h : (2 : ℤ) • ∡ p₁ p₂ p₃ = (2 : ℤ) • ∡ p₄ p₅ p₆) : AffineIndependent ℝ ![p₁, p₂, p₃] ↔ AffineIndependent ℝ ![p₄, p₅, p₆] := by simp_rw [← oangle_ne_zero_and_ne_pi_iff_affineIndependent, ← Real.Angle.two_zsmul_ne_zero_iff, h] #align euclidean_geometry.affine_independent_iff_of_two_zsmul_oangle_eq EuclideanGeometry.affineIndependent_iff_of_two_zsmul_oangle_eq /-- If twice the oriented angles between two triples of points are equal, one triple is collinear if and only if the other is. -/ theorem collinear_iff_of_two_zsmul_oangle_eq {p₁ p₂ p₃ p₄ p₅ p₆ : P} (h : (2 : ℤ) • ∡ p₁ p₂ p₃ = (2 : ℤ) • ∡ p₄ p₅ p₆) : Collinear ℝ ({p₁, p₂, p₃} : Set P) ↔ Collinear ℝ ({p₄, p₅, p₆} : Set P) := by simp_rw [← oangle_eq_zero_or_eq_pi_iff_collinear, ← Real.Angle.two_zsmul_eq_zero_iff, h] #align euclidean_geometry.collinear_iff_of_two_zsmul_oangle_eq EuclideanGeometry.collinear_iff_of_two_zsmul_oangle_eq /-- If corresponding pairs of points in two angles have the same vector span, twice those angles are equal. -/ theorem two_zsmul_oangle_of_vectorSpan_eq {p₁ p₂ p₃ p₄ p₅ p₆ : P} (h₁₂₄₅ : vectorSpan ℝ ({p₁, p₂} : Set P) = vectorSpan ℝ ({p₄, p₅} : Set P)) (h₃₂₆₅ : vectorSpan ℝ ({p₃, p₂} : Set P) = vectorSpan ℝ ({p₆, p₅} : Set P)) : (2 : ℤ) • ∡ p₁ p₂ p₃ = (2 : ℤ) • ∡ p₄ p₅ p₆ := by simp_rw [vectorSpan_pair] at h₁₂₄₅ h₃₂₆₅ exact o.two_zsmul_oangle_of_span_eq_of_span_eq h₁₂₄₅ h₃₂₆₅ #align euclidean_geometry.two_zsmul_oangle_of_vector_span_eq EuclideanGeometry.two_zsmul_oangle_of_vectorSpan_eq /-- If the lines determined by corresponding pairs of points in two angles are parallel, twice those angles are equal. -/ theorem two_zsmul_oangle_of_parallel {p₁ p₂ p₃ p₄ p₅ p₆ : P} (h₁₂₄₅ : line[ℝ, p₁, p₂] ∥ line[ℝ, p₄, p₅]) (h₃₂₆₅ : line[ℝ, p₃, p₂] ∥ line[ℝ, p₆, p₅]) : (2 : ℤ) • ∡ p₁ p₂ p₃ = (2 : ℤ) • ∡ p₄ p₅ p₆ := by rw [AffineSubspace.affineSpan_pair_parallel_iff_vectorSpan_eq] at h₁₂₄₅ h₃₂₆₅ exact two_zsmul_oangle_of_vectorSpan_eq h₁₂₄₅ h₃₂₆₅ #align euclidean_geometry.two_zsmul_oangle_of_parallel EuclideanGeometry.two_zsmul_oangle_of_parallel /-- Given three points not equal to `p`, the angle between the first and the second at `p` plus the angle between the second and the third equals the angle between the first and the third. -/ @[simp] theorem oangle_add {p p₁ p₂ p₃ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) (hp₃ : p₃ ≠ p) : ∡ p₁ p p₂ + ∡ p₂ p p₃ = ∡ p₁ p p₃ := o.oangle_add (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) (vsub_ne_zero.2 hp₃) #align euclidean_geometry.oangle_add EuclideanGeometry.oangle_add /-- Given three points not equal to `p`, the angle between the second and the third at `p` plus the angle between the first and the second equals the angle between the first and the third. -/ @[simp] theorem oangle_add_swap {p p₁ p₂ p₃ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) (hp₃ : p₃ ≠ p) : ∡ p₂ p p₃ + ∡ p₁ p p₂ = ∡ p₁ p p₃ := o.oangle_add_swap (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) (vsub_ne_zero.2 hp₃) #align euclidean_geometry.oangle_add_swap EuclideanGeometry.oangle_add_swap /-- Given three points not equal to `p`, the angle between the first and the third at `p` minus the angle between the first and the second equals the angle between the second and the third. -/ @[simp] theorem oangle_sub_left {p p₁ p₂ p₃ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) (hp₃ : p₃ ≠ p) : ∡ p₁ p p₃ - ∡ p₁ p p₂ = ∡ p₂ p p₃ := o.oangle_sub_left (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) (vsub_ne_zero.2 hp₃) #align euclidean_geometry.oangle_sub_left EuclideanGeometry.oangle_sub_left /-- Given three points not equal to `p`, the angle between the first and the third at `p` minus the angle between the second and the third equals the angle between the first and the second. -/ @[simp] theorem oangle_sub_right {p p₁ p₂ p₃ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) (hp₃ : p₃ ≠ p) : ∡ p₁ p p₃ - ∡ p₂ p p₃ = ∡ p₁ p p₂ := o.oangle_sub_right (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) (vsub_ne_zero.2 hp₃) #align euclidean_geometry.oangle_sub_right EuclideanGeometry.oangle_sub_right /-- Given three points not equal to `p`, adding the angles between them at `p` in cyclic order results in 0. -/ @[simp] theorem oangle_add_cyc3 {p p₁ p₂ p₃ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) (hp₃ : p₃ ≠ p) : ∡ p₁ p p₂ + ∡ p₂ p p₃ + ∡ p₃ p p₁ = 0 := o.oangle_add_cyc3 (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) (vsub_ne_zero.2 hp₃) #align euclidean_geometry.oangle_add_cyc3 EuclideanGeometry.oangle_add_cyc3 /-- Pons asinorum, oriented angle-at-point form. -/ theorem oangle_eq_oangle_of_dist_eq {p₁ p₂ p₃ : P} (h : dist p₁ p₂ = dist p₁ p₃) : ∡ p₁ p₂ p₃ = ∡ p₂ p₃ p₁ := by simp_rw [dist_eq_norm_vsub V] at h rw [oangle, oangle, ← vsub_sub_vsub_cancel_left p₃ p₂ p₁, ← vsub_sub_vsub_cancel_left p₂ p₃ p₁, o.oangle_sub_eq_oangle_sub_rev_of_norm_eq h] #align euclidean_geometry.oangle_eq_oangle_of_dist_eq EuclideanGeometry.oangle_eq_oangle_of_dist_eq /-- The angle at the apex of an isosceles triangle is `π` minus twice a base angle, oriented angle-at-point form. -/
Mathlib/Geometry/Euclidean/Angle/Oriented/Affine.lean
325
332
theorem oangle_eq_pi_sub_two_zsmul_oangle_of_dist_eq {p₁ p₂ p₃ : P} (hn : p₂ ≠ p₃) (h : dist p₁ p₂ = dist p₁ p₃) : ∡ p₃ p₁ p₂ = π - (2 : ℤ) • ∡ p₁ p₂ p₃ := by
simp_rw [dist_eq_norm_vsub V] at h rw [oangle, oangle] convert o.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq _ h using 1 · rw [← neg_vsub_eq_vsub_rev p₁ p₃, ← neg_vsub_eq_vsub_rev p₁ p₂, o.oangle_neg_neg] · rw [← o.oangle_sub_eq_oangle_sub_rev_of_norm_eq h]; simp · simpa using hn
/- Copyright (c) 2022 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Batteries.Data.Rat.Basic import Batteries.Tactic.SeqFocus /-! # Additional lemmas about the Rational Numbers -/ namespace Rat theorem ext : {p q : Rat} → p.num = q.num → p.den = q.den → p = q | ⟨_,_,_,_⟩, ⟨_,_,_,_⟩, rfl, rfl => rfl @[simp] theorem mk_den_one {r : Int} : ⟨r, 1, Nat.one_ne_zero, (Nat.coprime_one_right _)⟩ = (r : Rat) := rfl @[simp] theorem zero_num : (0 : Rat).num = 0 := rfl @[simp] theorem zero_den : (0 : Rat).den = 1 := rfl @[simp] theorem one_num : (1 : Rat).num = 1 := rfl @[simp] theorem one_den : (1 : Rat).den = 1 := rfl @[simp] theorem maybeNormalize_eq {num den g} (den_nz reduced) : maybeNormalize num den g den_nz reduced = { num := num.div g, den := den / g, den_nz, reduced } := by unfold maybeNormalize; split · subst g; simp · rfl theorem normalize.reduced' {num : Int} {den g : Nat} (den_nz : den ≠ 0) (e : g = num.natAbs.gcd den) : (num / g).natAbs.Coprime (den / g) := by rw [← Int.div_eq_ediv_of_dvd (e ▸ Int.ofNat_dvd_left.2 (Nat.gcd_dvd_left ..))] exact normalize.reduced den_nz e theorem normalize_eq {num den} (den_nz) : normalize num den den_nz = { num := num / num.natAbs.gcd den den := den / num.natAbs.gcd den den_nz := normalize.den_nz den_nz rfl reduced := normalize.reduced' den_nz rfl } := by simp only [normalize, maybeNormalize_eq, Int.div_eq_ediv_of_dvd (Int.ofNat_dvd_left.2 (Nat.gcd_dvd_left ..))] @[simp] theorem normalize_zero (nz) : normalize 0 d nz = 0 := by simp [normalize, Int.zero_div, Int.natAbs_zero, Nat.div_self (Nat.pos_of_ne_zero nz)]; rfl theorem mk_eq_normalize (num den nz c) : ⟨num, den, nz, c⟩ = normalize num den nz := by simp [normalize_eq, c.gcd_eq_one] theorem normalize_self (r : Rat) : normalize r.num r.den r.den_nz = r := (mk_eq_normalize ..).symm theorem normalize_mul_left {a : Nat} (d0 : d ≠ 0) (a0 : a ≠ 0) : normalize (↑a * n) (a * d) (Nat.mul_ne_zero a0 d0) = normalize n d d0 := by simp [normalize_eq, mk'.injEq, Int.natAbs_mul, Nat.gcd_mul_left, Nat.mul_div_mul_left _ _ (Nat.pos_of_ne_zero a0), Int.ofNat_mul, Int.mul_ediv_mul_of_pos _ _ (Int.ofNat_pos.2 <| Nat.pos_of_ne_zero a0)] theorem normalize_mul_right {a : Nat} (d0 : d ≠ 0) (a0 : a ≠ 0) : normalize (n * a) (d * a) (Nat.mul_ne_zero d0 a0) = normalize n d d0 := by rw [← normalize_mul_left (d0 := d0) a0]; congr 1 <;> [apply Int.mul_comm; apply Nat.mul_comm] theorem normalize_eq_iff (z₁ : d₁ ≠ 0) (z₂ : d₂ ≠ 0) : normalize n₁ d₁ z₁ = normalize n₂ d₂ z₂ ↔ n₁ * d₂ = n₂ * d₁ := by constructor <;> intro h · simp only [normalize_eq, mk'.injEq] at h have' hn₁ := Int.ofNat_dvd_left.2 <| Nat.gcd_dvd_left n₁.natAbs d₁ have' hn₂ := Int.ofNat_dvd_left.2 <| Nat.gcd_dvd_left n₂.natAbs d₂ have' hd₁ := Int.ofNat_dvd.2 <| Nat.gcd_dvd_right n₁.natAbs d₁ have' hd₂ := Int.ofNat_dvd.2 <| Nat.gcd_dvd_right n₂.natAbs d₂ rw [← Int.ediv_mul_cancel (Int.dvd_trans hd₂ (Int.dvd_mul_left ..)), Int.mul_ediv_assoc _ hd₂, ← Int.ofNat_ediv, ← h.2, Int.ofNat_ediv, ← Int.mul_ediv_assoc _ hd₁, Int.mul_ediv_assoc' _ hn₁, Int.mul_right_comm, h.1, Int.ediv_mul_cancel hn₂] · rw [← normalize_mul_right _ z₂, ← normalize_mul_left z₂ z₁, Int.mul_comm d₁, h] theorem maybeNormalize_eq_normalize {num : Int} {den g : Nat} (den_nz reduced) (hn : ↑g ∣ num) (hd : g ∣ den) : maybeNormalize num den g den_nz reduced = normalize num den (mt (by simp [·]) den_nz) := by simp only [maybeNormalize_eq, mk_eq_normalize, Int.div_eq_ediv_of_dvd hn] have : g ≠ 0 := mt (by simp [·]) den_nz rw [← normalize_mul_right _ this, Int.ediv_mul_cancel hn] congr 1; exact Nat.div_mul_cancel hd @[simp] theorem normalize_eq_zero (d0 : d ≠ 0) : normalize n d d0 = 0 ↔ n = 0 := by have' := normalize_eq_iff d0 Nat.one_ne_zero rw [normalize_zero (d := 1)] at this; rw [this]; simp theorem normalize_num_den' (num den nz) : ∃ d : Nat, d ≠ 0 ∧ num = (normalize num den nz).num * d ∧ den = (normalize num den nz).den * d := by refine ⟨num.natAbs.gcd den, Nat.gcd_ne_zero_right nz, ?_⟩ simp [normalize_eq, Int.ediv_mul_cancel (Int.ofNat_dvd_left.2 <| Nat.gcd_dvd_left ..), Nat.div_mul_cancel (Nat.gcd_dvd_right ..)] theorem normalize_num_den (h : normalize n d z = ⟨n', d', z', c⟩) : ∃ m : Nat, m ≠ 0 ∧ n = n' * m ∧ d = d' * m := by have := normalize_num_den' n d z; rwa [h] at this theorem normalize_eq_mkRat {num den} (den_nz) : normalize num den den_nz = mkRat num den := by simp [mkRat, den_nz] theorem mkRat_num_den (z : d ≠ 0) (h : mkRat n d = ⟨n', d', z', c⟩) : ∃ m : Nat, m ≠ 0 ∧ n = n' * m ∧ d = d' * m := normalize_num_den ((normalize_eq_mkRat z).symm ▸ h) theorem mkRat_def (n d) : mkRat n d = if d0 : d = 0 then 0 else normalize n d d0 := rfl theorem mkRat_self (a : Rat) : mkRat a.num a.den = a := by rw [← normalize_eq_mkRat a.den_nz, normalize_self] theorem mk_eq_mkRat (num den nz c) : ⟨num, den, nz, c⟩ = mkRat num den := by simp [mk_eq_normalize, normalize_eq_mkRat] @[simp] theorem zero_mkRat (n) : mkRat 0 n = 0 := by simp [mkRat_def] @[simp] theorem mkRat_zero (n) : mkRat n 0 = 0 := by simp [mkRat_def] theorem mkRat_eq_zero (d0 : d ≠ 0) : mkRat n d = 0 ↔ n = 0 := by simp [mkRat_def, d0] theorem mkRat_ne_zero (d0 : d ≠ 0) : mkRat n d ≠ 0 ↔ n ≠ 0 := not_congr (mkRat_eq_zero d0) theorem mkRat_mul_left {a : Nat} (a0 : a ≠ 0) : mkRat (↑a * n) (a * d) = mkRat n d := by if d0 : d = 0 then simp [d0] else rw [← normalize_eq_mkRat d0, ← normalize_mul_left d0 a0, normalize_eq_mkRat] theorem mkRat_mul_right {a : Nat} (a0 : a ≠ 0) : mkRat (n * a) (d * a) = mkRat n d := by rw [← mkRat_mul_left (d := d) a0]; congr 1 <;> [apply Int.mul_comm; apply Nat.mul_comm] theorem mkRat_eq_iff (z₁ : d₁ ≠ 0) (z₂ : d₂ ≠ 0) : mkRat n₁ d₁ = mkRat n₂ d₂ ↔ n₁ * d₂ = n₂ * d₁ := by rw [← normalize_eq_mkRat z₁, ← normalize_eq_mkRat z₂, normalize_eq_iff] @[simp] theorem divInt_ofNat (num den) : num /. (den : Nat) = mkRat num den := by simp [divInt, normalize_eq_mkRat] theorem mk_eq_divInt (num den nz c) : ⟨num, den, nz, c⟩ = num /. (den : Nat) := by simp [mk_eq_mkRat] theorem divInt_self (a : Rat) : a.num /. a.den = a := by rw [divInt_ofNat, mkRat_self] @[simp] theorem zero_divInt (n) : 0 /. n = 0 := by cases n <;> simp [divInt] @[simp] theorem divInt_zero (n) : n /. 0 = 0 := mkRat_zero n theorem neg_divInt_neg (num den) : -num /. -den = num /. den := by match den with | Nat.succ n => simp only [divInt, Int.neg_ofNat_succ] simp [normalize_eq_mkRat, Int.neg_neg] | 0 => rfl | Int.negSucc n => simp only [divInt, Int.neg_negSucc] simp [normalize_eq_mkRat, Int.neg_neg] theorem divInt_neg' (num den) : num /. -den = -num /. den := by rw [← neg_divInt_neg, Int.neg_neg] theorem divInt_eq_iff (z₁ : d₁ ≠ 0) (z₂ : d₂ ≠ 0) : n₁ /. d₁ = n₂ /. d₂ ↔ n₁ * d₂ = n₂ * d₁ := by rcases Int.eq_nat_or_neg d₁ with ⟨_, rfl | rfl⟩ <;> rcases Int.eq_nat_or_neg d₂ with ⟨_, rfl | rfl⟩ <;> simp_all [divInt_neg', Int.ofNat_eq_zero, Int.neg_eq_zero, mkRat_eq_iff, Int.neg_mul, Int.mul_neg, Int.eq_neg_comm, eq_comm] theorem divInt_mul_left {a : Int} (a0 : a ≠ 0) : (a * n) /. (a * d) = n /. d := by if d0 : d = 0 then simp [d0] else simp [divInt_eq_iff (Int.mul_ne_zero a0 d0) d0, Int.mul_assoc, Int.mul_left_comm] theorem divInt_mul_right {a : Int} (a0 : a ≠ 0) : (n * a) /. (d * a) = n /. d := by simp [← divInt_mul_left (d := d) a0, Int.mul_comm] theorem divInt_num_den (z : d ≠ 0) (h : n /. d = ⟨n', d', z', c⟩) : ∃ m, m ≠ 0 ∧ n = n' * m ∧ d = d' * m := by rcases Int.eq_nat_or_neg d with ⟨_, rfl | rfl⟩ <;> simp_all [divInt_neg', Int.ofNat_eq_zero, Int.neg_eq_zero] · have ⟨m, h₁, h₂⟩ := mkRat_num_den z h; exists m simp [Int.ofNat_eq_zero, Int.ofNat_mul, h₁, h₂] · have ⟨m, h₁, h₂⟩ := mkRat_num_den z h; exists -m rw [← Int.neg_inj, Int.neg_neg] at h₂ simp [Int.ofNat_eq_zero, Int.ofNat_mul, h₁, h₂, Int.mul_neg, Int.neg_eq_zero] @[simp] theorem ofInt_ofNat : ofInt (OfNat.ofNat n) = OfNat.ofNat n := rfl @[simp] theorem ofInt_num : (ofInt n : Rat).num = n := rfl @[simp] theorem ofInt_den : (ofInt n : Rat).den = 1 := rfl @[simp] theorem ofNat_num : (OfNat.ofNat n : Rat).num = OfNat.ofNat n := rfl @[simp] theorem ofNat_den : (OfNat.ofNat n : Rat).den = 1 := rfl theorem add_def (a b : Rat) : a + b = normalize (a.num * b.den + b.num * a.den) (a.den * b.den) (Nat.mul_ne_zero a.den_nz b.den_nz) := by show Rat.add .. = _; delta Rat.add; dsimp only; split · exact (normalize_self _).symm · have : a.den.gcd b.den ≠ 0 := Nat.gcd_ne_zero_left a.den_nz rw [maybeNormalize_eq_normalize _ _ (Int.ofNat_dvd_left.2 <| Nat.gcd_dvd_left ..) (Nat.dvd_trans (Nat.gcd_dvd_right ..) <| Nat.dvd_trans (Nat.gcd_dvd_right ..) (Nat.dvd_mul_left ..)), ← normalize_mul_right _ this]; congr 1 · simp only [Int.add_mul, Int.mul_assoc, Int.ofNat_mul_ofNat, Nat.div_mul_cancel (Nat.gcd_dvd_left ..), Nat.div_mul_cancel (Nat.gcd_dvd_right ..)] · rw [Nat.mul_right_comm, Nat.div_mul_cancel (Nat.gcd_dvd_left ..)] theorem add_def' (a b : Rat) : a + b = mkRat (a.num * b.den + b.num * a.den) (a.den * b.den) := by rw [add_def, normalize_eq_mkRat] theorem normalize_add_normalize (n₁ n₂) {d₁ d₂} (z₁ z₂) : normalize n₁ d₁ z₁ + normalize n₂ d₂ z₂ = normalize (n₁ * d₂ + n₂ * d₁) (d₁ * d₂) (Nat.mul_ne_zero z₁ z₂) := by cases e₁ : normalize n₁ d₁ z₁; rcases normalize_num_den e₁ with ⟨g₁, zg₁, rfl, rfl⟩ cases e₂ : normalize n₂ d₂ z₂; rcases normalize_num_den e₂ with ⟨g₂, zg₂, rfl, rfl⟩ simp only [add_def]; rw [← normalize_mul_right _ (Nat.mul_ne_zero zg₁ zg₂)]; congr 1 · rw [Int.add_mul]; simp [Int.ofNat_mul, Int.mul_assoc, Int.mul_left_comm, Int.mul_comm] · simp [Nat.mul_left_comm, Nat.mul_comm] theorem mkRat_add_mkRat (n₁ n₂ : Int) {d₁ d₂} (z₁ : d₁ ≠ 0) (z₂ : d₂ ≠ 0) : mkRat n₁ d₁ + mkRat n₂ d₂ = mkRat (n₁ * d₂ + n₂ * d₁) (d₁ * d₂) := by rw [← normalize_eq_mkRat z₁, ← normalize_eq_mkRat z₂, normalize_add_normalize, normalize_eq_mkRat] theorem divInt_add_divInt (n₁ n₂ : Int) {d₁ d₂} (z₁ : d₁ ≠ 0) (z₂ : d₂ ≠ 0) : n₁ /. d₁ + n₂ /. d₂ = (n₁ * d₂ + n₂ * d₁) /. (d₁ * d₂) := by rcases Int.eq_nat_or_neg d₁ with ⟨_, rfl | rfl⟩ <;> rcases Int.eq_nat_or_neg d₂ with ⟨_, rfl | rfl⟩ <;> simp_all [-Int.natCast_mul, Int.ofNat_eq_zero, Int.neg_eq_zero, divInt_neg', Int.mul_neg, Int.ofNat_mul_ofNat, Int.neg_add, Int.neg_mul, mkRat_add_mkRat] @[simp] theorem neg_num (a : Rat) : (-a).num = -a.num := rfl @[simp] theorem neg_den (a : Rat) : (-a).den = a.den := rfl theorem neg_normalize (n d z) : -normalize n d z = normalize (-n) d z := by simp [normalize]; rfl theorem neg_mkRat (n d) : -mkRat n d = mkRat (-n) d := by if z : d = 0 then simp [z]; rfl else simp [← normalize_eq_mkRat z, neg_normalize] theorem neg_divInt (n d) : -(n /. d) = -n /. d := by rcases Int.eq_nat_or_neg d with ⟨_, rfl | rfl⟩ <;> simp [divInt_neg', neg_mkRat] theorem sub_def (a b : Rat) : a - b = normalize (a.num * b.den - b.num * a.den) (a.den * b.den) (Nat.mul_ne_zero a.den_nz b.den_nz) := by show Rat.sub .. = _; delta Rat.sub; dsimp only; split · exact (normalize_self _).symm · have : a.den.gcd b.den ≠ 0 := Nat.gcd_ne_zero_left a.den_nz rw [maybeNormalize_eq_normalize _ _ (Int.ofNat_dvd_left.2 <| Nat.gcd_dvd_left ..) (Nat.dvd_trans (Nat.gcd_dvd_right ..) <| Nat.dvd_trans (Nat.gcd_dvd_right ..) (Nat.dvd_mul_left ..)), ← normalize_mul_right _ this]; congr 1 · simp only [Int.sub_mul, Int.mul_assoc, Int.ofNat_mul_ofNat, Nat.div_mul_cancel (Nat.gcd_dvd_left ..), Nat.div_mul_cancel (Nat.gcd_dvd_right ..)] · rw [Nat.mul_right_comm, Nat.div_mul_cancel (Nat.gcd_dvd_left ..)] theorem sub_def' (a b : Rat) : a - b = mkRat (a.num * b.den - b.num * a.den) (a.den * b.den) := by rw [sub_def, normalize_eq_mkRat] protected theorem sub_eq_add_neg (a b : Rat) : a - b = a + -b := by simp [add_def, sub_def, Int.neg_mul, Int.sub_eq_add_neg] theorem divInt_sub_divInt (n₁ n₂ : Int) {d₁ d₂} (z₁ : d₁ ≠ 0) (z₂ : d₂ ≠ 0) : n₁ /. d₁ - n₂ /. d₂ = (n₁ * d₂ - n₂ * d₁) /. (d₁ * d₂) := by simp only [Rat.sub_eq_add_neg, neg_divInt, divInt_add_divInt _ _ z₁ z₂, Int.neg_mul, Int.sub_eq_add_neg] theorem mul_def (a b : Rat) : a * b = normalize (a.num * b.num) (a.den * b.den) (Nat.mul_ne_zero a.den_nz b.den_nz) := by show Rat.mul .. = _; delta Rat.mul; dsimp only have H1 : a.num.natAbs.gcd b.den ≠ 0 := Nat.gcd_ne_zero_right b.den_nz have H2 : b.num.natAbs.gcd a.den ≠ 0 := Nat.gcd_ne_zero_right a.den_nz rw [mk_eq_normalize, ← normalize_mul_right _ (Nat.mul_ne_zero H1 H2)]; congr 1 · rw [Int.ofNat_mul, ← Int.mul_assoc, Int.mul_right_comm (Int.div ..), Int.div_mul_cancel (Int.ofNat_dvd_left.2 <| Nat.gcd_dvd_left ..), Int.mul_assoc, Int.div_mul_cancel (Int.ofNat_dvd_left.2 <| Nat.gcd_dvd_left ..)] · rw [← Nat.mul_assoc, Nat.mul_right_comm, Nat.mul_right_comm (_/_), Nat.div_mul_cancel (Nat.gcd_dvd_right ..), Nat.mul_assoc, Nat.div_mul_cancel (Nat.gcd_dvd_right ..)] protected theorem mul_comm (a b : Rat) : a * b = b * a := by simp [mul_def, normalize_eq_mkRat, Int.mul_comm, Nat.mul_comm] @[simp] protected theorem zero_mul (a : Rat) : 0 * a = 0 := by simp [mul_def] @[simp] protected theorem mul_zero (a : Rat) : a * 0 = 0 := by simp [mul_def] @[simp] protected theorem one_mul (a : Rat) : 1 * a = a := by simp [mul_def, normalize_self] @[simp] protected theorem mul_one (a : Rat) : a * 1 = a := by simp [mul_def, normalize_self] theorem normalize_mul_normalize (n₁ n₂) {d₁ d₂} (z₁ z₂) : normalize n₁ d₁ z₁ * normalize n₂ d₂ z₂ = normalize (n₁ * n₂) (d₁ * d₂) (Nat.mul_ne_zero z₁ z₂) := by cases e₁ : normalize n₁ d₁ z₁; rcases normalize_num_den e₁ with ⟨g₁, zg₁, rfl, rfl⟩ cases e₂ : normalize n₂ d₂ z₂; rcases normalize_num_den e₂ with ⟨g₂, zg₂, rfl, rfl⟩ simp only [mul_def]; rw [← normalize_mul_right _ (Nat.mul_ne_zero zg₁ zg₂)]; congr 1 · simp [Int.ofNat_mul, Int.mul_assoc, Int.mul_left_comm] · simp [Nat.mul_left_comm, Nat.mul_comm] theorem mkRat_mul_mkRat (n₁ n₂ : Int) (d₁ d₂) : mkRat n₁ d₁ * mkRat n₂ d₂ = mkRat (n₁ * n₂) (d₁ * d₂) := by if z₁ : d₁ = 0 then simp [z₁] else if z₂ : d₂ = 0 then simp [z₂] else rw [← normalize_eq_mkRat z₁, ← normalize_eq_mkRat z₂, normalize_mul_normalize, normalize_eq_mkRat] theorem divInt_mul_divInt (n₁ n₂ : Int) {d₁ d₂} (z₁ : d₁ ≠ 0) (z₂ : d₂ ≠ 0) : (n₁ /. d₁) * (n₂ /. d₂) = (n₁ * n₂) /. (d₁ * d₂) := by rcases Int.eq_nat_or_neg d₁ with ⟨_, rfl | rfl⟩ <;> rcases Int.eq_nat_or_neg d₂ with ⟨_, rfl | rfl⟩ <;> simp_all [-Int.natCast_mul, divInt_neg', Int.mul_neg, Int.ofNat_mul_ofNat, Int.neg_mul, mkRat_mul_mkRat]
.lake/packages/batteries/Batteries/Data/Rat/Lemmas.lean
306
314
theorem inv_def (a : Rat) : a.inv = a.den /. a.num := by
unfold Rat.inv; split · next h => rw [mk_eq_divInt, ← Int.natAbs_neg, Int.natAbs_of_nonneg (Int.le_of_lt <| Int.neg_pos_of_neg h), neg_divInt_neg] split · next h => rw [mk_eq_divInt, Int.natAbs_of_nonneg (Int.le_of_lt h)] · next h₁ h₂ => apply (divInt_self _).symm.trans simp [Int.le_antisymm (Int.not_lt.1 h₂) (Int.not_lt.1 h₁)]
/- Copyright (c) 2022 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Batteries.Data.Fin.Basic namespace Fin attribute [norm_cast] val_last protected theorem le_antisymm_iff {x y : Fin n} : x = y ↔ x ≤ y ∧ y ≤ x := Fin.ext_iff.trans Nat.le_antisymm_iff protected theorem le_antisymm {x y : Fin n} (h1 : x ≤ y) (h2 : y ≤ x) : x = y := Fin.le_antisymm_iff.2 ⟨h1, h2⟩ /-! ### clamp -/ @[simp] theorem coe_clamp (n m : Nat) : (clamp n m : Nat) = min n m := rfl /-! ### enum/list -/ @[simp] theorem size_enum (n) : (enum n).size = n := Array.size_ofFn .. @[simp] theorem enum_zero : (enum 0) = #[] := by simp [enum, Array.ofFn, Array.ofFn.go] @[simp] theorem getElem_enum (i) (h : i < (enum n).size) : (enum n)[i] = ⟨i, size_enum n ▸ h⟩ := Array.getElem_ofFn .. @[simp] theorem length_list (n) : (list n).length = n := by simp [list] @[simp] theorem get_list (i : Fin (list n).length) : (list n).get i = i.cast (length_list n) := by cases i; simp only [list]; rw [← Array.getElem_eq_data_get, getElem_enum, cast_mk] @[simp] theorem list_zero : list 0 = [] := by simp [list] theorem list_succ (n) : list (n+1) = 0 :: (list n).map Fin.succ := by apply List.ext_get; simp; intro i; cases i <;> simp theorem list_succ_last (n) : list (n+1) = (list n).map castSucc ++ [last n] := by rw [list_succ] induction n with | zero => rfl | succ n ih => rw [list_succ, List.map_cons castSucc, ih] simp [Function.comp_def, succ_castSucc] theorem list_reverse (n) : (list n).reverse = (list n).map rev := by induction n with | zero => rfl | succ n ih => conv => lhs; rw [list_succ_last] conv => rhs; rw [list_succ] simp [List.reverse_map, ih, Function.comp_def, rev_succ] /-! ### foldl -/ theorem foldl_loop_lt (f : α → Fin n → α) (x) (h : m < n) : foldl.loop n f x m = foldl.loop n f (f x ⟨m, h⟩) (m+1) := by rw [foldl.loop, dif_pos h] theorem foldl_loop_eq (f : α → Fin n → α) (x) : foldl.loop n f x n = x := by rw [foldl.loop, dif_neg (Nat.lt_irrefl _)] theorem foldl_loop (f : α → Fin (n+1) → α) (x) (h : m < n+1) : foldl.loop (n+1) f x m = foldl.loop n (fun x i => f x i.succ) (f x ⟨m, h⟩) m := by if h' : m < n then rw [foldl_loop_lt _ _ h, foldl_loop_lt _ _ h', foldl_loop]; rfl else cases Nat.le_antisymm (Nat.le_of_lt_succ h) (Nat.not_lt.1 h') rw [foldl_loop_lt, foldl_loop_eq, foldl_loop_eq] termination_by n - m @[simp] theorem foldl_zero (f : α → Fin 0 → α) (x) : foldl 0 f x = x := by simp [foldl, foldl.loop] theorem foldl_succ (f : α → Fin (n+1) → α) (x) : foldl (n+1) f x = foldl n (fun x i => f x i.succ) (f x 0) := foldl_loop .. theorem foldl_succ_last (f : α → Fin (n+1) → α) (x) : foldl (n+1) f x = f (foldl n (f · ·.castSucc) x) (last n) := by rw [foldl_succ] induction n generalizing x with | zero => simp [foldl_succ, Fin.last] | succ n ih => rw [foldl_succ, ih (f · ·.succ), foldl_succ]; simp [succ_castSucc] theorem foldl_eq_foldl_list (f : α → Fin n → α) (x) : foldl n f x = (list n).foldl f x := by induction n generalizing x with | zero => rw [foldl_zero, list_zero, List.foldl_nil] | succ n ih => rw [foldl_succ, ih, list_succ, List.foldl_cons, List.foldl_map] /-! ### foldr -/ unseal foldr.loop in theorem foldr_loop_zero (f : Fin n → α → α) (x) : foldr.loop n f ⟨0, Nat.zero_le _⟩ x = x := rfl unseal foldr.loop in theorem foldr_loop_succ (f : Fin n → α → α) (x) (h : m < n) : foldr.loop n f ⟨m+1, h⟩ x = foldr.loop n f ⟨m, Nat.le_of_lt h⟩ (f ⟨m, h⟩ x) := rfl theorem foldr_loop (f : Fin (n+1) → α → α) (x) (h : m+1 ≤ n+1) : foldr.loop (n+1) f ⟨m+1, h⟩ x = f 0 (foldr.loop n (fun i => f i.succ) ⟨m, Nat.le_of_succ_le_succ h⟩ x) := by induction m generalizing x with | zero => simp [foldr_loop_zero, foldr_loop_succ] | succ m ih => rw [foldr_loop_succ, ih, foldr_loop_succ, Fin.succ] @[simp] theorem foldr_zero (f : Fin 0 → α → α) (x) : foldr 0 f x = x := foldr_loop_zero .. theorem foldr_succ (f : Fin (n+1) → α → α) (x) : foldr (n+1) f x = f 0 (foldr n (fun i => f i.succ) x) := foldr_loop ..
.lake/packages/batteries/Batteries/Data/Fin/Lemmas.lean
116
120
theorem foldr_succ_last (f : Fin (n+1) → α → α) (x) : foldr (n+1) f x = foldr n (f ·.castSucc) (f (last n) x) := by
induction n generalizing x with | zero => simp [foldr_succ, Fin.last] | succ n ih => rw [foldr_succ, ih (f ·.succ), foldr_succ]; simp [succ_castSucc]
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro -/ import Mathlib.Algebra.Module.Submodule.Bilinear import Mathlib.GroupTheory.Congruence.Basic import Mathlib.LinearAlgebra.Basic import Mathlib.Tactic.SuppressCompilation #align_import linear_algebra.tensor_product from "leanprover-community/mathlib"@"88fcdc3da43943f5b01925deddaa5bf0c0e85e4e" /-! # Tensor product of modules over commutative semirings. This file constructs the tensor product of modules over commutative semirings. Given a semiring `R` and modules over it `M` and `N`, the standard construction of the tensor product is `TensorProduct R M N`. It is also a module over `R`. It comes with a canonical bilinear map `M → N → TensorProduct R M N`. Given any bilinear map `M → N → P`, there is a unique linear map `TensorProduct R M N → P` whose composition with the canonical bilinear map `M → N → TensorProduct R M N` is the given bilinear map `M → N → P`. We start by proving basic lemmas about bilinear maps. ## Notations This file uses the localized notation `M ⊗ N` and `M ⊗[R] N` for `TensorProduct R M N`, as well as `m ⊗ₜ n` and `m ⊗ₜ[R] n` for `TensorProduct.tmul R m n`. ## Tags bilinear, tensor, tensor product -/ suppress_compilation section Semiring variable {R : Type*} [CommSemiring R] variable {R' : Type*} [Monoid R'] variable {R'' : Type*} [Semiring R''] variable {M : Type*} {N : Type*} {P : Type*} {Q : Type*} {S : Type*} {T : Type*} variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] variable [AddCommMonoid Q] [AddCommMonoid S] [AddCommMonoid T] variable [Module R M] [Module R N] [Module R P] [Module R Q] [Module R S] [Module R T] variable [DistribMulAction R' M] variable [Module R'' M] variable (M N) namespace TensorProduct section variable (R) /-- The relation on `FreeAddMonoid (M × N)` that generates a congruence whose quotient is the tensor product. -/ inductive Eqv : FreeAddMonoid (M × N) → FreeAddMonoid (M × N) → Prop | of_zero_left : ∀ n : N, Eqv (.of (0, n)) 0 | of_zero_right : ∀ m : M, Eqv (.of (m, 0)) 0 | of_add_left : ∀ (m₁ m₂ : M) (n : N), Eqv (.of (m₁, n) + .of (m₂, n)) (.of (m₁ + m₂, n)) | of_add_right : ∀ (m : M) (n₁ n₂ : N), Eqv (.of (m, n₁) + .of (m, n₂)) (.of (m, n₁ + n₂)) | of_smul : ∀ (r : R) (m : M) (n : N), Eqv (.of (r • m, n)) (.of (m, r • n)) | add_comm : ∀ x y, Eqv (x + y) (y + x) #align tensor_product.eqv TensorProduct.Eqv end end TensorProduct variable (R) /-- The tensor product of two modules `M` and `N` over the same commutative semiring `R`. The localized notations are `M ⊗ N` and `M ⊗[R] N`, accessed by `open scoped TensorProduct`. -/ def TensorProduct : Type _ := (addConGen (TensorProduct.Eqv R M N)).Quotient #align tensor_product TensorProduct variable {R} set_option quotPrecheck false in @[inherit_doc TensorProduct] scoped[TensorProduct] infixl:100 " ⊗ " => TensorProduct _ @[inherit_doc] scoped[TensorProduct] notation:100 M " ⊗[" R "] " N:100 => TensorProduct R M N namespace TensorProduct section Module protected instance add : Add (M ⊗[R] N) := (addConGen (TensorProduct.Eqv R M N)).hasAdd instance addZeroClass : AddZeroClass (M ⊗[R] N) := { (addConGen (TensorProduct.Eqv R M N)).addMonoid with /- The `toAdd` field is given explicitly as `TensorProduct.add` for performance reasons. This avoids any need to unfold `Con.addMonoid` when the type checker is checking that instance diagrams commute -/ toAdd := TensorProduct.add _ _ } instance addSemigroup : AddSemigroup (M ⊗[R] N) := { (addConGen (TensorProduct.Eqv R M N)).addMonoid with toAdd := TensorProduct.add _ _ } instance addCommSemigroup : AddCommSemigroup (M ⊗[R] N) := { (addConGen (TensorProduct.Eqv R M N)).addMonoid with toAddSemigroup := TensorProduct.addSemigroup _ _ add_comm := fun x y => AddCon.induction_on₂ x y fun _ _ => Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.add_comm _ _ } instance : Inhabited (M ⊗[R] N) := ⟨0⟩ variable (R) {M N} /-- The canonical function `M → N → M ⊗ N`. The localized notations are `m ⊗ₜ n` and `m ⊗ₜ[R] n`, accessed by `open scoped TensorProduct`. -/ def tmul (m : M) (n : N) : M ⊗[R] N := AddCon.mk' _ <| FreeAddMonoid.of (m, n) #align tensor_product.tmul TensorProduct.tmul variable {R} /-- The canonical function `M → N → M ⊗ N`. -/ infixl:100 " ⊗ₜ " => tmul _ /-- The canonical function `M → N → M ⊗ N`. -/ notation:100 x " ⊗ₜ[" R "] " y:100 => tmul R x y -- Porting note: make the arguments of induction_on explicit @[elab_as_elim] protected theorem induction_on {motive : M ⊗[R] N → Prop} (z : M ⊗[R] N) (zero : motive 0) (tmul : ∀ x y, motive <| x ⊗ₜ[R] y) (add : ∀ x y, motive x → motive y → motive (x + y)) : motive z := AddCon.induction_on z fun x => FreeAddMonoid.recOn x zero fun ⟨m, n⟩ y ih => by rw [AddCon.coe_add] exact add _ _ (tmul ..) ih #align tensor_product.induction_on TensorProduct.induction_on /-- Lift an `R`-balanced map to the tensor product. A map `f : M →+ N →+ P` additive in both components is `R`-balanced, or middle linear with respect to `R`, if scalar multiplication in either argument is equivalent, `f (r • m) n = f m (r • n)`. Note that strictly the first action should be a right-action by `R`, but for now `R` is commutative so it doesn't matter. -/ -- TODO: use this to implement `lift` and `SMul.aux`. For now we do not do this as it causes -- performance issues elsewhere. def liftAddHom (f : M →+ N →+ P) (hf : ∀ (r : R) (m : M) (n : N), f (r • m) n = f m (r • n)) : M ⊗[R] N →+ P := (addConGen (TensorProduct.Eqv R M N)).lift (FreeAddMonoid.lift (fun mn : M × N => f mn.1 mn.2)) <| AddCon.addConGen_le fun x y hxy => match x, y, hxy with | _, _, .of_zero_left n => (AddCon.ker_rel _).2 <| by simp_rw [map_zero, FreeAddMonoid.lift_eval_of, map_zero, AddMonoidHom.zero_apply] | _, _, .of_zero_right m => (AddCon.ker_rel _).2 <| by simp_rw [map_zero, FreeAddMonoid.lift_eval_of, map_zero] | _, _, .of_add_left m₁ m₂ n => (AddCon.ker_rel _).2 <| by simp_rw [map_add, FreeAddMonoid.lift_eval_of, map_add, AddMonoidHom.add_apply] | _, _, .of_add_right m n₁ n₂ => (AddCon.ker_rel _).2 <| by simp_rw [map_add, FreeAddMonoid.lift_eval_of, map_add] | _, _, .of_smul s m n => (AddCon.ker_rel _).2 <| by rw [FreeAddMonoid.lift_eval_of, FreeAddMonoid.lift_eval_of, hf] | _, _, .add_comm x y => (AddCon.ker_rel _).2 <| by simp_rw [map_add, add_comm] @[simp] theorem liftAddHom_tmul (f : M →+ N →+ P) (hf : ∀ (r : R) (m : M) (n : N), f (r • m) n = f m (r • n)) (m : M) (n : N) : liftAddHom f hf (m ⊗ₜ n) = f m n := rfl variable (M) @[simp] theorem zero_tmul (n : N) : (0 : M) ⊗ₜ[R] n = 0 := Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_zero_left _ #align tensor_product.zero_tmul TensorProduct.zero_tmul variable {M} theorem add_tmul (m₁ m₂ : M) (n : N) : (m₁ + m₂) ⊗ₜ n = m₁ ⊗ₜ n + m₂ ⊗ₜ[R] n := Eq.symm <| Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_add_left _ _ _ #align tensor_product.add_tmul TensorProduct.add_tmul variable (N) @[simp] theorem tmul_zero (m : M) : m ⊗ₜ[R] (0 : N) = 0 := Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_zero_right _ #align tensor_product.tmul_zero TensorProduct.tmul_zero variable {N} theorem tmul_add (m : M) (n₁ n₂ : N) : m ⊗ₜ (n₁ + n₂) = m ⊗ₜ n₁ + m ⊗ₜ[R] n₂ := Eq.symm <| Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_add_right _ _ _ #align tensor_product.tmul_add TensorProduct.tmul_add instance uniqueLeft [Subsingleton M] : Unique (M ⊗[R] N) where default := 0 uniq z := z.induction_on rfl (fun x y ↦ by rw [Subsingleton.elim x 0, zero_tmul]; rfl) <| by rintro _ _ rfl rfl; apply add_zero instance uniqueRight [Subsingleton N] : Unique (M ⊗[R] N) where default := 0 uniq z := z.induction_on rfl (fun x y ↦ by rw [Subsingleton.elim y 0, tmul_zero]; rfl) <| by rintro _ _ rfl rfl; apply add_zero section variable (R R' M N) /-- A typeclass for `SMul` structures which can be moved across a tensor product. This typeclass is generated automatically from an `IsScalarTower` instance, but exists so that we can also add an instance for `AddCommGroup.intModule`, allowing `z •` to be moved even if `R` does not support negation. Note that `Module R' (M ⊗[R] N)` is available even without this typeclass on `R'`; it's only needed if `TensorProduct.smul_tmul`, `TensorProduct.smul_tmul'`, or `TensorProduct.tmul_smul` is used. -/ class CompatibleSMul [DistribMulAction R' N] : Prop where smul_tmul : ∀ (r : R') (m : M) (n : N), (r • m) ⊗ₜ n = m ⊗ₜ[R] (r • n) #align tensor_product.compatible_smul TensorProduct.CompatibleSMul end /-- Note that this provides the default `compatible_smul R R M N` instance through `IsScalarTower.left`. -/ instance (priority := 100) CompatibleSMul.isScalarTower [SMul R' R] [IsScalarTower R' R M] [DistribMulAction R' N] [IsScalarTower R' R N] : CompatibleSMul R R' M N := ⟨fun r m n => by conv_lhs => rw [← one_smul R m] conv_rhs => rw [← one_smul R n] rw [← smul_assoc, ← smul_assoc] exact Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_smul _ _ _⟩ #align tensor_product.compatible_smul.is_scalar_tower TensorProduct.CompatibleSMul.isScalarTower /-- `smul` can be moved from one side of the product to the other . -/ theorem smul_tmul [DistribMulAction R' N] [CompatibleSMul R R' M N] (r : R') (m : M) (n : N) : (r • m) ⊗ₜ n = m ⊗ₜ[R] (r • n) := CompatibleSMul.smul_tmul _ _ _ #align tensor_product.smul_tmul TensorProduct.smul_tmul -- Porting note: This is added as a local instance for `SMul.aux`. -- For some reason type-class inference in Lean 3 unfolded this definition. private def addMonoidWithWrongNSMul : AddMonoid (M ⊗[R] N) := { (addConGen (TensorProduct.Eqv R M N)).addMonoid with } attribute [local instance] addMonoidWithWrongNSMul in /-- Auxiliary function to defining scalar multiplication on tensor product. -/ def SMul.aux {R' : Type*} [SMul R' M] (r : R') : FreeAddMonoid (M × N) →+ M ⊗[R] N := FreeAddMonoid.lift fun p : M × N => (r • p.1) ⊗ₜ p.2 #align tensor_product.smul.aux TensorProduct.SMul.aux theorem SMul.aux_of {R' : Type*} [SMul R' M] (r : R') (m : M) (n : N) : SMul.aux r (.of (m, n)) = (r • m) ⊗ₜ[R] n := rfl #align tensor_product.smul.aux_of TensorProduct.SMul.aux_of variable [SMulCommClass R R' M] [SMulCommClass R R'' M] /-- Given two modules over a commutative semiring `R`, if one of the factors carries a (distributive) action of a second type of scalars `R'`, which commutes with the action of `R`, then the tensor product (over `R`) carries an action of `R'`. This instance defines this `R'` action in the case that it is the left module which has the `R'` action. Two natural ways in which this situation arises are: * Extension of scalars * A tensor product of a group representation with a module not carrying an action Note that in the special case that `R = R'`, since `R` is commutative, we just get the usual scalar action on a tensor product of two modules. This special case is important enough that, for performance reasons, we define it explicitly below. -/ instance leftHasSMul : SMul R' (M ⊗[R] N) := ⟨fun r => (addConGen (TensorProduct.Eqv R M N)).lift (SMul.aux r : _ →+ M ⊗[R] N) <| AddCon.addConGen_le fun x y hxy => match x, y, hxy with | _, _, .of_zero_left n => (AddCon.ker_rel _).2 <| by simp_rw [map_zero, SMul.aux_of, smul_zero, zero_tmul] | _, _, .of_zero_right m => (AddCon.ker_rel _).2 <| by simp_rw [map_zero, SMul.aux_of, tmul_zero] | _, _, .of_add_left m₁ m₂ n => (AddCon.ker_rel _).2 <| by simp_rw [map_add, SMul.aux_of, smul_add, add_tmul] | _, _, .of_add_right m n₁ n₂ => (AddCon.ker_rel _).2 <| by simp_rw [map_add, SMul.aux_of, tmul_add] | _, _, .of_smul s m n => (AddCon.ker_rel _).2 <| by rw [SMul.aux_of, SMul.aux_of, ← smul_comm, smul_tmul] | _, _, .add_comm x y => (AddCon.ker_rel _).2 <| by simp_rw [map_add, add_comm]⟩ #align tensor_product.left_has_smul TensorProduct.leftHasSMul instance : SMul R (M ⊗[R] N) := TensorProduct.leftHasSMul protected theorem smul_zero (r : R') : r • (0 : M ⊗[R] N) = 0 := AddMonoidHom.map_zero _ #align tensor_product.smul_zero TensorProduct.smul_zero protected theorem smul_add (r : R') (x y : M ⊗[R] N) : r • (x + y) = r • x + r • y := AddMonoidHom.map_add _ _ _ #align tensor_product.smul_add TensorProduct.smul_add protected theorem zero_smul (x : M ⊗[R] N) : (0 : R'') • x = 0 := have : ∀ (r : R'') (m : M) (n : N), r • m ⊗ₜ[R] n = (r • m) ⊗ₜ n := fun _ _ _ => rfl x.induction_on (by rw [TensorProduct.smul_zero]) (fun m n => by rw [this, zero_smul, zero_tmul]) fun x y ihx ihy => by rw [TensorProduct.smul_add, ihx, ihy, add_zero] #align tensor_product.zero_smul TensorProduct.zero_smul protected theorem one_smul (x : M ⊗[R] N) : (1 : R') • x = x := have : ∀ (r : R') (m : M) (n : N), r • m ⊗ₜ[R] n = (r • m) ⊗ₜ n := fun _ _ _ => rfl x.induction_on (by rw [TensorProduct.smul_zero]) (fun m n => by rw [this, one_smul]) fun x y ihx ihy => by rw [TensorProduct.smul_add, ihx, ihy] #align tensor_product.one_smul TensorProduct.one_smul protected theorem add_smul (r s : R'') (x : M ⊗[R] N) : (r + s) • x = r • x + s • x := have : ∀ (r : R'') (m : M) (n : N), r • m ⊗ₜ[R] n = (r • m) ⊗ₜ n := fun _ _ _ => rfl x.induction_on (by simp_rw [TensorProduct.smul_zero, add_zero]) (fun m n => by simp_rw [this, add_smul, add_tmul]) fun x y ihx ihy => by simp_rw [TensorProduct.smul_add] rw [ihx, ihy, add_add_add_comm] #align tensor_product.add_smul TensorProduct.add_smul instance addMonoid : AddMonoid (M ⊗[R] N) := { TensorProduct.addZeroClass _ _ with toAddSemigroup := TensorProduct.addSemigroup _ _ toZero := (TensorProduct.addZeroClass _ _).toZero nsmul := fun n v => n • v nsmul_zero := by simp [TensorProduct.zero_smul] nsmul_succ := by simp only [TensorProduct.one_smul, TensorProduct.add_smul, add_comm, forall_const] } instance addCommMonoid : AddCommMonoid (M ⊗[R] N) := { TensorProduct.addCommSemigroup _ _ with toAddMonoid := TensorProduct.addMonoid } instance leftDistribMulAction : DistribMulAction R' (M ⊗[R] N) := have : ∀ (r : R') (m : M) (n : N), r • m ⊗ₜ[R] n = (r • m) ⊗ₜ n := fun _ _ _ => rfl { smul_add := fun r x y => TensorProduct.smul_add r x y mul_smul := fun r s x => x.induction_on (by simp_rw [TensorProduct.smul_zero]) (fun m n => by simp_rw [this, mul_smul]) fun x y ihx ihy => by simp_rw [TensorProduct.smul_add] rw [ihx, ihy] one_smul := TensorProduct.one_smul smul_zero := TensorProduct.smul_zero } #align tensor_product.left_distrib_mul_action TensorProduct.leftDistribMulAction instance : DistribMulAction R (M ⊗[R] N) := TensorProduct.leftDistribMulAction theorem smul_tmul' (r : R') (m : M) (n : N) : r • m ⊗ₜ[R] n = (r • m) ⊗ₜ n := rfl #align tensor_product.smul_tmul' TensorProduct.smul_tmul' @[simp] theorem tmul_smul [DistribMulAction R' N] [CompatibleSMul R R' M N] (r : R') (x : M) (y : N) : x ⊗ₜ (r • y) = r • x ⊗ₜ[R] y := (smul_tmul _ _ _).symm #align tensor_product.tmul_smul TensorProduct.tmul_smul theorem smul_tmul_smul (r s : R) (m : M) (n : N) : (r • m) ⊗ₜ[R] (s • n) = (r * s) • m ⊗ₜ[R] n := by simp_rw [smul_tmul, tmul_smul, mul_smul] #align tensor_product.smul_tmul_smul TensorProduct.smul_tmul_smul instance leftModule : Module R'' (M ⊗[R] N) := { add_smul := TensorProduct.add_smul zero_smul := TensorProduct.zero_smul } #align tensor_product.left_module TensorProduct.leftModule instance : Module R (M ⊗[R] N) := TensorProduct.leftModule instance [Module R''ᵐᵒᵖ M] [IsCentralScalar R'' M] : IsCentralScalar R'' (M ⊗[R] N) where op_smul_eq_smul r x := x.induction_on (by rw [smul_zero, smul_zero]) (fun x y => by rw [smul_tmul', smul_tmul', op_smul_eq_smul]) fun x y hx hy => by rw [smul_add, smul_add, hx, hy] section -- Like `R'`, `R'₂` provides a `DistribMulAction R'₂ (M ⊗[R] N)` variable {R'₂ : Type*} [Monoid R'₂] [DistribMulAction R'₂ M] variable [SMulCommClass R R'₂ M] /-- `SMulCommClass R' R'₂ M` implies `SMulCommClass R' R'₂ (M ⊗[R] N)` -/ instance smulCommClass_left [SMulCommClass R' R'₂ M] : SMulCommClass R' R'₂ (M ⊗[R] N) where smul_comm r' r'₂ x := TensorProduct.induction_on x (by simp_rw [TensorProduct.smul_zero]) (fun m n => by simp_rw [smul_tmul', smul_comm]) fun x y ihx ihy => by simp_rw [TensorProduct.smul_add]; rw [ihx, ihy] #align tensor_product.smul_comm_class_left TensorProduct.smulCommClass_left variable [SMul R'₂ R'] /-- `IsScalarTower R'₂ R' M` implies `IsScalarTower R'₂ R' (M ⊗[R] N)` -/ instance isScalarTower_left [IsScalarTower R'₂ R' M] : IsScalarTower R'₂ R' (M ⊗[R] N) := ⟨fun s r x => x.induction_on (by simp) (fun m n => by rw [smul_tmul', smul_tmul', smul_tmul', smul_assoc]) fun x y ihx ihy => by rw [smul_add, smul_add, smul_add, ihx, ihy]⟩ #align tensor_product.is_scalar_tower_left TensorProduct.isScalarTower_left variable [DistribMulAction R'₂ N] [DistribMulAction R' N] variable [CompatibleSMul R R'₂ M N] [CompatibleSMul R R' M N] /-- `IsScalarTower R'₂ R' N` implies `IsScalarTower R'₂ R' (M ⊗[R] N)` -/ instance isScalarTower_right [IsScalarTower R'₂ R' N] : IsScalarTower R'₂ R' (M ⊗[R] N) := ⟨fun s r x => x.induction_on (by simp) (fun m n => by rw [← tmul_smul, ← tmul_smul, ← tmul_smul, smul_assoc]) fun x y ihx ihy => by rw [smul_add, smul_add, smul_add, ihx, ihy]⟩ #align tensor_product.is_scalar_tower_right TensorProduct.isScalarTower_right end /-- A short-cut instance for the common case, where the requirements for the `compatible_smul` instances are sufficient. -/ instance isScalarTower [SMul R' R] [IsScalarTower R' R M] : IsScalarTower R' R (M ⊗[R] N) := TensorProduct.isScalarTower_left #align tensor_product.is_scalar_tower TensorProduct.isScalarTower -- or right variable (R M N) /-- The canonical bilinear map `M → N → M ⊗[R] N`. -/ def mk : M →ₗ[R] N →ₗ[R] M ⊗[R] N := LinearMap.mk₂ R (· ⊗ₜ ·) add_tmul (fun c m n => by simp_rw [smul_tmul, tmul_smul]) tmul_add tmul_smul #align tensor_product.mk TensorProduct.mk variable {R M N} @[simp] theorem mk_apply (m : M) (n : N) : mk R M N m n = m ⊗ₜ n := rfl #align tensor_product.mk_apply TensorProduct.mk_apply theorem ite_tmul (x₁ : M) (x₂ : N) (P : Prop) [Decidable P] : (if P then x₁ else 0) ⊗ₜ[R] x₂ = if P then x₁ ⊗ₜ x₂ else 0 := by split_ifs <;> simp #align tensor_product.ite_tmul TensorProduct.ite_tmul theorem tmul_ite (x₁ : M) (x₂ : N) (P : Prop) [Decidable P] : (x₁ ⊗ₜ[R] if P then x₂ else 0) = if P then x₁ ⊗ₜ x₂ else 0 := by split_ifs <;> simp #align tensor_product.tmul_ite TensorProduct.tmul_ite section theorem sum_tmul {α : Type*} (s : Finset α) (m : α → M) (n : N) : (∑ a ∈ s, m a) ⊗ₜ[R] n = ∑ a ∈ s, m a ⊗ₜ[R] n := by classical induction' s using Finset.induction with a s has ih h · simp · simp [Finset.sum_insert has, add_tmul, ih] #align tensor_product.sum_tmul TensorProduct.sum_tmul theorem tmul_sum (m : M) {α : Type*} (s : Finset α) (n : α → N) : (m ⊗ₜ[R] ∑ a ∈ s, n a) = ∑ a ∈ s, m ⊗ₜ[R] n a := by classical induction' s using Finset.induction with a s has ih h · simp · simp [Finset.sum_insert has, tmul_add, ih] #align tensor_product.tmul_sum TensorProduct.tmul_sum end variable (R M N) /-- The simple (aka pure) elements span the tensor product. -/ theorem span_tmul_eq_top : Submodule.span R { t : M ⊗[R] N | ∃ m n, m ⊗ₜ n = t } = ⊤ := by ext t; simp only [Submodule.mem_top, iff_true_iff] refine t.induction_on ?_ ?_ ?_ · exact Submodule.zero_mem _ · intro m n apply Submodule.subset_span use m, n · intro t₁ t₂ ht₁ ht₂ exact Submodule.add_mem _ ht₁ ht₂ #align tensor_product.span_tmul_eq_top TensorProduct.span_tmul_eq_top @[simp] theorem map₂_mk_top_top_eq_top : Submodule.map₂ (mk R M N) ⊤ ⊤ = ⊤ := by rw [← top_le_iff, ← span_tmul_eq_top, Submodule.map₂_eq_span_image2] exact Submodule.span_mono fun _ ⟨m, n, h⟩ => ⟨m, trivial, n, trivial, h⟩ #align tensor_product.map₂_mk_top_top_eq_top TensorProduct.map₂_mk_top_top_eq_top theorem exists_eq_tmul_of_forall (x : TensorProduct R M N) (h : ∀ (m₁ m₂ : M) (n₁ n₂ : N), ∃ m n, m₁ ⊗ₜ n₁ + m₂ ⊗ₜ n₂ = m ⊗ₜ[R] n) : ∃ m n, x = m ⊗ₜ n := by induction x using TensorProduct.induction_on with | zero => use 0, 0 rw [TensorProduct.zero_tmul] | tmul m n => use m, n | add x y h₁ h₂ => obtain ⟨m₁, n₁, rfl⟩ := h₁ obtain ⟨m₂, n₂, rfl⟩ := h₂ apply h end Module section UMP variable {M N} variable (f : M →ₗ[R] N →ₗ[R] P) /-- Auxiliary function to constructing a linear map `M ⊗ N → P` given a bilinear map `M → N → P` with the property that its composition with the canonical bilinear map `M → N → M ⊗ N` is the given bilinear map `M → N → P`. -/ def liftAux : M ⊗[R] N →+ P := liftAddHom (LinearMap.toAddMonoidHom'.comp <| f.toAddMonoidHom) fun r m n => by dsimp; rw [LinearMap.map_smul₂, map_smul] #align tensor_product.lift_aux TensorProduct.liftAux theorem liftAux_tmul (m n) : liftAux f (m ⊗ₜ n) = f m n := rfl #align tensor_product.lift_aux_tmul TensorProduct.liftAux_tmul variable {f} @[simp] theorem liftAux.smul (r : R) (x) : liftAux f (r • x) = r • liftAux f x := TensorProduct.induction_on x (smul_zero _).symm (fun p q => by simp_rw [← tmul_smul, liftAux_tmul, (f p).map_smul]) fun p q ih1 ih2 => by simp_rw [smul_add, (liftAux f).map_add, ih1, ih2, smul_add] #align tensor_product.lift_aux.smul TensorProduct.liftAux.smul variable (f) /-- Constructing a linear map `M ⊗ N → P` given a bilinear map `M → N → P` with the property that its composition with the canonical bilinear map `M → N → M ⊗ N` is the given bilinear map `M → N → P`. -/ def lift : M ⊗[R] N →ₗ[R] P := { liftAux f with map_smul' := liftAux.smul } #align tensor_product.lift TensorProduct.lift variable {f} @[simp] theorem lift.tmul (x y) : lift f (x ⊗ₜ y) = f x y := rfl #align tensor_product.lift.tmul TensorProduct.lift.tmul @[simp] theorem lift.tmul' (x y) : (lift f).1 (x ⊗ₜ y) = f x y := rfl #align tensor_product.lift.tmul' TensorProduct.lift.tmul' theorem ext' {g h : M ⊗[R] N →ₗ[R] P} (H : ∀ x y, g (x ⊗ₜ y) = h (x ⊗ₜ y)) : g = h := LinearMap.ext fun z => TensorProduct.induction_on z (by simp_rw [LinearMap.map_zero]) H fun x y ihx ihy => by rw [g.map_add, h.map_add, ihx, ihy] #align tensor_product.ext' TensorProduct.ext' theorem lift.unique {g : M ⊗[R] N →ₗ[R] P} (H : ∀ x y, g (x ⊗ₜ y) = f x y) : g = lift f := ext' fun m n => by rw [H, lift.tmul] #align tensor_product.lift.unique TensorProduct.lift.unique theorem lift_mk : lift (mk R M N) = LinearMap.id := Eq.symm <| lift.unique fun _ _ => rfl #align tensor_product.lift_mk TensorProduct.lift_mk theorem lift_compr₂ (g : P →ₗ[R] Q) : lift (f.compr₂ g) = g.comp (lift f) := Eq.symm <| lift.unique fun _ _ => by simp #align tensor_product.lift_compr₂ TensorProduct.lift_compr₂ theorem lift_mk_compr₂ (f : M ⊗ N →ₗ[R] P) : lift ((mk R M N).compr₂ f) = f := by rw [lift_compr₂ f, lift_mk, LinearMap.comp_id] #align tensor_product.lift_mk_compr₂ TensorProduct.lift_mk_compr₂ /-- This used to be an `@[ext]` lemma, but it fails very slowly when the `ext` tactic tries to apply it in some cases, notably when one wants to show equality of two linear maps. The `@[ext]` attribute is now added locally where it is needed. Using this as the `@[ext]` lemma instead of `TensorProduct.ext'` allows `ext` to apply lemmas specific to `M →ₗ _` and `N →ₗ _`. See note [partially-applied ext lemmas]. -/ theorem ext {g h : M ⊗ N →ₗ[R] P} (H : (mk R M N).compr₂ g = (mk R M N).compr₂ h) : g = h := by rw [← lift_mk_compr₂ g, H, lift_mk_compr₂] #align tensor_product.ext TensorProduct.ext attribute [local ext high] ext example : M → N → (M → N → P) → P := fun m => flip fun f => f m variable (R M N P) /-- Linearly constructing a linear map `M ⊗ N → P` given a bilinear map `M → N → P` with the property that its composition with the canonical bilinear map `M → N → M ⊗ N` is the given bilinear map `M → N → P`. -/ def uncurry : (M →ₗ[R] N →ₗ[R] P) →ₗ[R] M ⊗[R] N →ₗ[R] P := LinearMap.flip <| lift <| LinearMap.lflip.comp (LinearMap.flip LinearMap.id) #align tensor_product.uncurry TensorProduct.uncurry variable {R M N P} @[simp] theorem uncurry_apply (f : M →ₗ[R] N →ₗ[R] P) (m : M) (n : N) : uncurry R M N P f (m ⊗ₜ n) = f m n := by rw [uncurry, LinearMap.flip_apply, lift.tmul]; rfl #align tensor_product.uncurry_apply TensorProduct.uncurry_apply variable (R M N P) /-- A linear equivalence constructing a linear map `M ⊗ N → P` given a bilinear map `M → N → P` with the property that its composition with the canonical bilinear map `M → N → M ⊗ N` is the given bilinear map `M → N → P`. -/ def lift.equiv : (M →ₗ[R] N →ₗ[R] P) ≃ₗ[R] M ⊗[R] N →ₗ[R] P := { uncurry R M N P with invFun := fun f => (mk R M N).compr₂ f left_inv := fun _ => LinearMap.ext₂ fun _ _ => lift.tmul _ _ right_inv := fun _ => ext' fun _ _ => lift.tmul _ _ } #align tensor_product.lift.equiv TensorProduct.lift.equiv @[simp] theorem lift.equiv_apply (f : M →ₗ[R] N →ₗ[R] P) (m : M) (n : N) : lift.equiv R M N P f (m ⊗ₜ n) = f m n := uncurry_apply f m n #align tensor_product.lift.equiv_apply TensorProduct.lift.equiv_apply @[simp] theorem lift.equiv_symm_apply (f : M ⊗[R] N →ₗ[R] P) (m : M) (n : N) : (lift.equiv R M N P).symm f m n = f (m ⊗ₜ n) := rfl #align tensor_product.lift.equiv_symm_apply TensorProduct.lift.equiv_symm_apply /-- Given a linear map `M ⊗ N → P`, compose it with the canonical bilinear map `M → N → M ⊗ N` to form a bilinear map `M → N → P`. -/ def lcurry : (M ⊗[R] N →ₗ[R] P) →ₗ[R] M →ₗ[R] N →ₗ[R] P := (lift.equiv R M N P).symm #align tensor_product.lcurry TensorProduct.lcurry variable {R M N P} @[simp] theorem lcurry_apply (f : M ⊗[R] N →ₗ[R] P) (m : M) (n : N) : lcurry R M N P f m n = f (m ⊗ₜ n) := rfl #align tensor_product.lcurry_apply TensorProduct.lcurry_apply /-- Given a linear map `M ⊗ N → P`, compose it with the canonical bilinear map `M → N → M ⊗ N` to form a bilinear map `M → N → P`. -/ def curry (f : M ⊗[R] N →ₗ[R] P) : M →ₗ[R] N →ₗ[R] P := lcurry R M N P f #align tensor_product.curry TensorProduct.curry @[simp] theorem curry_apply (f : M ⊗ N →ₗ[R] P) (m : M) (n : N) : curry f m n = f (m ⊗ₜ n) := rfl #align tensor_product.curry_apply TensorProduct.curry_apply theorem curry_injective : Function.Injective (curry : (M ⊗[R] N →ₗ[R] P) → M →ₗ[R] N →ₗ[R] P) := fun _ _ H => ext H #align tensor_product.curry_injective TensorProduct.curry_injective theorem ext_threefold {g h : (M ⊗[R] N) ⊗[R] P →ₗ[R] Q} (H : ∀ x y z, g (x ⊗ₜ y ⊗ₜ z) = h (x ⊗ₜ y ⊗ₜ z)) : g = h := by ext x y z exact H x y z #align tensor_product.ext_threefold TensorProduct.ext_threefold -- We'll need this one for checking the pentagon identity! theorem ext_fourfold {g h : ((M ⊗[R] N) ⊗[R] P) ⊗[R] Q →ₗ[R] S} (H : ∀ w x y z, g (w ⊗ₜ x ⊗ₜ y ⊗ₜ z) = h (w ⊗ₜ x ⊗ₜ y ⊗ₜ z)) : g = h := by ext w x y z exact H w x y z #align tensor_product.ext_fourfold TensorProduct.ext_fourfold /-- Two linear maps (M ⊗ N) ⊗ (P ⊗ Q) → S which agree on all elements of the form (m ⊗ₜ n) ⊗ₜ (p ⊗ₜ q) are equal. -/ theorem ext_fourfold' {φ ψ : (M ⊗[R] N) ⊗[R] P ⊗[R] Q →ₗ[R] S} (H : ∀ w x y z, φ (w ⊗ₜ x ⊗ₜ (y ⊗ₜ z)) = ψ (w ⊗ₜ x ⊗ₜ (y ⊗ₜ z))) : φ = ψ := by ext m n p q exact H m n p q #align tensor_product.ext_fourfold' TensorProduct.ext_fourfold' end UMP variable {M N} section variable (R M) /-- The base ring is a left identity for the tensor product of modules, up to linear equivalence. -/ protected def lid : R ⊗[R] M ≃ₗ[R] M := LinearEquiv.ofLinear (lift <| LinearMap.lsmul R M) (mk R R M 1) (LinearMap.ext fun _ => by simp) (ext' fun r m => by simp; rw [← tmul_smul, ← smul_tmul, smul_eq_mul, mul_one]) #align tensor_product.lid TensorProduct.lid end @[simp] theorem lid_tmul (m : M) (r : R) : (TensorProduct.lid R M : R ⊗ M → M) (r ⊗ₜ m) = r • m := rfl #align tensor_product.lid_tmul TensorProduct.lid_tmul @[simp] theorem lid_symm_apply (m : M) : (TensorProduct.lid R M).symm m = 1 ⊗ₜ m := rfl #align tensor_product.lid_symm_apply TensorProduct.lid_symm_apply section variable (R M N) /-- The tensor product of modules is commutative, up to linear equivalence. -/ protected def comm : M ⊗[R] N ≃ₗ[R] N ⊗[R] M := LinearEquiv.ofLinear (lift (mk R N M).flip) (lift (mk R M N).flip) (ext' fun _ _ => rfl) (ext' fun _ _ => rfl) #align tensor_product.comm TensorProduct.comm @[simp] theorem comm_tmul (m : M) (n : N) : (TensorProduct.comm R M N) (m ⊗ₜ n) = n ⊗ₜ m := rfl #align tensor_product.comm_tmul TensorProduct.comm_tmul @[simp] theorem comm_symm_tmul (m : M) (n : N) : (TensorProduct.comm R M N).symm (n ⊗ₜ m) = m ⊗ₜ n := rfl #align tensor_product.comm_symm_tmul TensorProduct.comm_symm_tmul lemma lift_comp_comm_eq (f : M →ₗ[R] N →ₗ[R] P) : lift f ∘ₗ TensorProduct.comm R N M = lift f.flip := ext rfl end section variable (R M) /-- The base ring is a right identity for the tensor product of modules, up to linear equivalence. -/ protected def rid : M ⊗[R] R ≃ₗ[R] M := LinearEquiv.trans (TensorProduct.comm R M R) (TensorProduct.lid R M) #align tensor_product.rid TensorProduct.rid end @[simp] theorem rid_tmul (m : M) (r : R) : (TensorProduct.rid R M) (m ⊗ₜ r) = r • m := rfl #align tensor_product.rid_tmul TensorProduct.rid_tmul @[simp] theorem rid_symm_apply (m : M) : (TensorProduct.rid R M).symm m = m ⊗ₜ 1 := rfl #align tensor_product.rid_symm_apply TensorProduct.rid_symm_apply variable (R) in theorem lid_eq_rid : TensorProduct.lid R R = TensorProduct.rid R R := LinearEquiv.toLinearMap_injective <| ext' mul_comm open LinearMap section variable (R M N P) /-- The associator for tensor product of R-modules, as a linear equivalence. -/ protected def assoc : (M ⊗[R] N) ⊗[R] P ≃ₗ[R] M ⊗[R] N ⊗[R] P := by refine LinearEquiv.ofLinear (lift <| lift <| comp (lcurry R _ _ _) <| mk _ _ _) (lift <| comp (uncurry R _ _ _) <| curry <| mk _ _ _) (ext <| LinearMap.ext fun m => ext' fun n p => ?_) (ext <| flip_inj <| LinearMap.ext fun p => ext' fun m n => ?_) <;> repeat' first |rw [lift.tmul]|rw [compr₂_apply]|rw [comp_apply]|rw [mk_apply]|rw [flip_apply] |rw [lcurry_apply]|rw [uncurry_apply]|rw [curry_apply]|rw [id_apply] #align tensor_product.assoc TensorProduct.assoc end @[simp] theorem assoc_tmul (m : M) (n : N) (p : P) : (TensorProduct.assoc R M N P) (m ⊗ₜ n ⊗ₜ p) = m ⊗ₜ (n ⊗ₜ p) := rfl #align tensor_product.assoc_tmul TensorProduct.assoc_tmul @[simp] theorem assoc_symm_tmul (m : M) (n : N) (p : P) : (TensorProduct.assoc R M N P).symm (m ⊗ₜ (n ⊗ₜ p)) = m ⊗ₜ n ⊗ₜ p := rfl #align tensor_product.assoc_symm_tmul TensorProduct.assoc_symm_tmul /-- The tensor product of a pair of linear maps between modules. -/ def map (f : M →ₗ[R] P) (g : N →ₗ[R] Q) : M ⊗[R] N →ₗ[R] P ⊗[R] Q := lift <| comp (compl₂ (mk _ _ _) g) f #align tensor_product.map TensorProduct.map @[simp] theorem map_tmul (f : M →ₗ[R] P) (g : N →ₗ[R] Q) (m : M) (n : N) : map f g (m ⊗ₜ n) = f m ⊗ₜ g n := rfl #align tensor_product.map_tmul TensorProduct.map_tmul /-- Given linear maps `f : M → P`, `g : N → Q`, if we identify `M ⊗ N` with `N ⊗ M` and `P ⊗ Q` with `Q ⊗ P`, then this lemma states that `f ⊗ g = g ⊗ f`. -/ lemma map_comp_comm_eq (f : M →ₗ[R] P) (g : N →ₗ[R] Q) : map f g ∘ₗ TensorProduct.comm R N M = TensorProduct.comm R Q P ∘ₗ map g f := ext rfl lemma map_comm (f : M →ₗ[R] P) (g : N →ₗ[R] Q) (x : N ⊗[R] M): map f g (TensorProduct.comm R N M x) = TensorProduct.comm R Q P (map g f x) := DFunLike.congr_fun (map_comp_comm_eq _ _) _ /-- Given linear maps `f : M → Q`, `g : N → S`, and `h : P → T`, if we identify `(M ⊗ N) ⊗ P` with `M ⊗ (N ⊗ P)` and `(Q ⊗ S) ⊗ T` with `Q ⊗ (S ⊗ T)`, then this lemma states that `f ⊗ (g ⊗ h) = (f ⊗ g) ⊗ h`. -/ lemma map_map_comp_assoc_eq (f : M →ₗ[R] Q) (g : N →ₗ[R] S) (h : P →ₗ[R] T) : map f (map g h) ∘ₗ TensorProduct.assoc R M N P = TensorProduct.assoc R Q S T ∘ₗ map (map f g) h := ext <| ext <| LinearMap.ext fun _ => LinearMap.ext fun _ => LinearMap.ext fun _ => rfl lemma map_map_assoc (f : M →ₗ[R] Q) (g : N →ₗ[R] S) (h : P →ₗ[R] T) (x : (M ⊗[R] N) ⊗[R] P) : map f (map g h) (TensorProduct.assoc R M N P x) = TensorProduct.assoc R Q S T (map (map f g) h x) := DFunLike.congr_fun (map_map_comp_assoc_eq _ _ _) _ /-- Given linear maps `f : M → Q`, `g : N → S`, and `h : P → T`, if we identify `M ⊗ (N ⊗ P)` with `(M ⊗ N) ⊗ P` and `Q ⊗ (S ⊗ T)` with `(Q ⊗ S) ⊗ T`, then this lemma states that `(f ⊗ g) ⊗ h = f ⊗ (g ⊗ h)`. -/ lemma map_map_comp_assoc_symm_eq (f : M →ₗ[R] Q) (g : N →ₗ[R] S) (h : P →ₗ[R] T) : map (map f g) h ∘ₗ (TensorProduct.assoc R M N P).symm = (TensorProduct.assoc R Q S T).symm ∘ₗ map f (map g h) := ext <| LinearMap.ext fun _ => ext <| LinearMap.ext fun _ => LinearMap.ext fun _ => rfl lemma map_map_assoc_symm (f : M →ₗ[R] Q) (g : N →ₗ[R] S) (h : P →ₗ[R] T) (x : M ⊗[R] (N ⊗[R] P)) : map (map f g) h ((TensorProduct.assoc R M N P).symm x) = (TensorProduct.assoc R Q S T).symm (map f (map g h) x) := DFunLike.congr_fun (map_map_comp_assoc_symm_eq _ _ _) _ theorem map_range_eq_span_tmul (f : M →ₗ[R] P) (g : N →ₗ[R] Q) : range (map f g) = Submodule.span R { t | ∃ m n, f m ⊗ₜ g n = t } := by simp only [← Submodule.map_top, ← span_tmul_eq_top, Submodule.map_span, Set.mem_image, Set.mem_setOf_eq] congr; ext t constructor · rintro ⟨_, ⟨⟨m, n, rfl⟩, rfl⟩⟩ use m, n simp only [map_tmul] · rintro ⟨m, n, rfl⟩ refine ⟨_, ⟨⟨m, n, rfl⟩, ?_⟩⟩ simp only [map_tmul] #align tensor_product.map_range_eq_span_tmul TensorProduct.map_range_eq_span_tmul /-- Given submodules `p ⊆ P` and `q ⊆ Q`, this is the natural map: `p ⊗ q → P ⊗ Q`. -/ @[simp] def mapIncl (p : Submodule R P) (q : Submodule R Q) : p ⊗[R] q →ₗ[R] P ⊗[R] Q := map p.subtype q.subtype #align tensor_product.map_incl TensorProduct.mapIncl lemma range_mapIncl (p : Submodule R P) (q : Submodule R Q) : LinearMap.range (mapIncl p q) = Submodule.span R (Set.image2 (· ⊗ₜ ·) p q) := by rw [mapIncl, map_range_eq_span_tmul] congr; ext; simp theorem map₂_eq_range_lift_comp_mapIncl (f : P →ₗ[R] Q →ₗ[R] M) (p : Submodule R P) (q : Submodule R Q) : Submodule.map₂ f p q = LinearMap.range (lift f ∘ₗ mapIncl p q) := by simp_rw [LinearMap.range_comp, range_mapIncl, Submodule.map_span, Set.image_image2, Submodule.map₂_eq_span_image2, lift.tmul] section variable {P' Q' : Type*} variable [AddCommMonoid P'] [Module R P'] variable [AddCommMonoid Q'] [Module R Q'] theorem map_comp (f₂ : P →ₗ[R] P') (f₁ : M →ₗ[R] P) (g₂ : Q →ₗ[R] Q') (g₁ : N →ₗ[R] Q) : map (f₂.comp f₁) (g₂.comp g₁) = (map f₂ g₂).comp (map f₁ g₁) := ext' fun _ _ => rfl #align tensor_product.map_comp TensorProduct.map_comp lemma range_mapIncl_mono {p p' : Submodule R P} {q q' : Submodule R Q} (hp : p ≤ p') (hq : q ≤ q') : LinearMap.range (mapIncl p q) ≤ LinearMap.range (mapIncl p' q') := by simp_rw [range_mapIncl] exact Submodule.span_mono (Set.image2_subset hp hq) theorem lift_comp_map (i : P →ₗ[R] Q →ₗ[R] Q') (f : M →ₗ[R] P) (g : N →ₗ[R] Q) : (lift i).comp (map f g) = lift ((i.comp f).compl₂ g) := ext' fun _ _ => rfl #align tensor_product.lift_comp_map TensorProduct.lift_comp_map attribute [local ext high] ext @[simp] theorem map_id : map (id : M →ₗ[R] M) (id : N →ₗ[R] N) = .id := by ext simp only [mk_apply, id_coe, compr₂_apply, _root_.id, map_tmul] #align tensor_product.map_id TensorProduct.map_id @[simp] theorem map_one : map (1 : M →ₗ[R] M) (1 : N →ₗ[R] N) = 1 := map_id #align tensor_product.map_one TensorProduct.map_one theorem map_mul (f₁ f₂ : M →ₗ[R] M) (g₁ g₂ : N →ₗ[R] N) : map (f₁ * f₂) (g₁ * g₂) = map f₁ g₁ * map f₂ g₂ := map_comp f₁ f₂ g₁ g₂ #align tensor_product.map_mul TensorProduct.map_mul @[simp] protected theorem map_pow (f : M →ₗ[R] M) (g : N →ₗ[R] N) (n : ℕ) : map f g ^ n = map (f ^ n) (g ^ n) := by induction' n with n ih · simp only [Nat.zero_eq, pow_zero, map_one] · simp only [pow_succ', ih, map_mul] #align tensor_product.map_pow TensorProduct.map_pow theorem map_add_left (f₁ f₂ : M →ₗ[R] P) (g : N →ₗ[R] Q) : map (f₁ + f₂) g = map f₁ g + map f₂ g := by ext simp only [add_tmul, compr₂_apply, mk_apply, map_tmul, add_apply] #align tensor_product.map_add_left TensorProduct.map_add_left theorem map_add_right (f : M →ₗ[R] P) (g₁ g₂ : N →ₗ[R] Q) : map f (g₁ + g₂) = map f g₁ + map f g₂ := by ext simp only [tmul_add, compr₂_apply, mk_apply, map_tmul, add_apply] #align tensor_product.map_add_right TensorProduct.map_add_right theorem map_smul_left (r : R) (f : M →ₗ[R] P) (g : N →ₗ[R] Q) : map (r • f) g = r • map f g := by ext simp only [smul_tmul, compr₂_apply, mk_apply, map_tmul, smul_apply, tmul_smul] #align tensor_product.map_smul_left TensorProduct.map_smul_left theorem map_smul_right (r : R) (f : M →ₗ[R] P) (g : N →ₗ[R] Q) : map f (r • g) = r • map f g := by ext simp only [smul_tmul, compr₂_apply, mk_apply, map_tmul, smul_apply, tmul_smul] #align tensor_product.map_smul_right TensorProduct.map_smul_right variable (R M N P Q) /-- The tensor product of a pair of linear maps between modules, bilinear in both maps. -/ def mapBilinear : (M →ₗ[R] P) →ₗ[R] (N →ₗ[R] Q) →ₗ[R] M ⊗[R] N →ₗ[R] P ⊗[R] Q := LinearMap.mk₂ R map map_add_left map_smul_left map_add_right map_smul_right #align tensor_product.map_bilinear TensorProduct.mapBilinear /-- The canonical linear map from `P ⊗[R] (M →ₗ[R] Q)` to `(M →ₗ[R] P ⊗[R] Q)` -/ def lTensorHomToHomLTensor : P ⊗[R] (M →ₗ[R] Q) →ₗ[R] M →ₗ[R] P ⊗[R] Q := TensorProduct.lift (llcomp R M Q _ ∘ₗ mk R P Q) #align tensor_product.ltensor_hom_to_hom_ltensor TensorProduct.lTensorHomToHomLTensor /-- The canonical linear map from `(M →ₗ[R] P) ⊗[R] Q` to `(M →ₗ[R] P ⊗[R] Q)` -/ def rTensorHomToHomRTensor : (M →ₗ[R] P) ⊗[R] Q →ₗ[R] M →ₗ[R] P ⊗[R] Q := TensorProduct.lift (llcomp R M P _ ∘ₗ (mk R P Q).flip).flip #align tensor_product.rtensor_hom_to_hom_rtensor TensorProduct.rTensorHomToHomRTensor /-- The linear map from `(M →ₗ P) ⊗ (N →ₗ Q)` to `(M ⊗ N →ₗ P ⊗ Q)` sending `f ⊗ₜ g` to the `TensorProduct.map f g`, the tensor product of the two maps. -/ def homTensorHomMap : (M →ₗ[R] P) ⊗[R] (N →ₗ[R] Q) →ₗ[R] M ⊗[R] N →ₗ[R] P ⊗[R] Q := lift (mapBilinear R M N P Q) #align tensor_product.hom_tensor_hom_map TensorProduct.homTensorHomMap variable {R M N P Q} /-- This is a binary version of `TensorProduct.map`: Given a bilinear map `f : M ⟶ P ⟶ Q` and a bilinear map `g : N ⟶ S ⟶ T`, if we think `f` and `g` as linear maps with two inputs, then `map₂ f g` is a bilinear map taking two inputs `M ⊗ N → P ⊗ S → Q ⊗ S` defined by `map₂ f g (m ⊗ n) (p ⊗ s) = f m p ⊗ g n s`. Mathematically, `TensorProduct.map₂` is defined as the composition `M ⊗ N -map→ Hom(P, Q) ⊗ Hom(S, T) -homTensorHomMap→ Hom(P ⊗ S, Q ⊗ T)`. -/ def map₂ (f : M →ₗ[R] P →ₗ[R] Q) (g : N →ₗ[R] S →ₗ[R] T) : M ⊗[R] N →ₗ[R] P ⊗[R] S →ₗ[R] Q ⊗[R] T := homTensorHomMap R _ _ _ _ ∘ₗ map f g @[simp] theorem mapBilinear_apply (f : M →ₗ[R] P) (g : N →ₗ[R] Q) : mapBilinear R M N P Q f g = map f g := rfl #align tensor_product.map_bilinear_apply TensorProduct.mapBilinear_apply @[simp] theorem lTensorHomToHomLTensor_apply (p : P) (f : M →ₗ[R] Q) (m : M) : lTensorHomToHomLTensor R M P Q (p ⊗ₜ f) m = p ⊗ₜ f m := rfl #align tensor_product.ltensor_hom_to_hom_ltensor_apply TensorProduct.lTensorHomToHomLTensor_apply @[simp] theorem rTensorHomToHomRTensor_apply (f : M →ₗ[R] P) (q : Q) (m : M) : rTensorHomToHomRTensor R M P Q (f ⊗ₜ q) m = f m ⊗ₜ q := rfl #align tensor_product.rtensor_hom_to_hom_rtensor_apply TensorProduct.rTensorHomToHomRTensor_apply @[simp] theorem homTensorHomMap_apply (f : M →ₗ[R] P) (g : N →ₗ[R] Q) : homTensorHomMap R M N P Q (f ⊗ₜ g) = map f g := rfl #align tensor_product.hom_tensor_hom_map_apply TensorProduct.homTensorHomMap_apply @[simp] theorem map₂_apply_tmul (f : M →ₗ[R] P →ₗ[R] Q) (g : N →ₗ[R] S →ₗ[R] T) (m : M) (n : N) : map₂ f g (m ⊗ₜ n) = map (f m) (g n) := rfl @[simp] theorem map_zero_left (g : N →ₗ[R] Q) : map (0 : M →ₗ[R] P) g = 0 := (mapBilinear R M N P Q).map_zero₂ _ @[simp] theorem map_zero_right (f : M →ₗ[R] P) : map f (0 : N →ₗ[R] Q) = 0 := (mapBilinear R M N P Q _).map_zero end /-- If `M` and `P` are linearly equivalent and `N` and `Q` are linearly equivalent then `M ⊗ N` and `P ⊗ Q` are linearly equivalent. -/ def congr (f : M ≃ₗ[R] P) (g : N ≃ₗ[R] Q) : M ⊗[R] N ≃ₗ[R] P ⊗[R] Q := LinearEquiv.ofLinear (map f g) (map f.symm g.symm) (ext' fun m n => by simp) (ext' fun m n => by simp) #align tensor_product.congr TensorProduct.congr @[simp] theorem congr_tmul (f : M ≃ₗ[R] P) (g : N ≃ₗ[R] Q) (m : M) (n : N) : congr f g (m ⊗ₜ n) = f m ⊗ₜ g n := rfl #align tensor_product.congr_tmul TensorProduct.congr_tmul @[simp] theorem congr_symm_tmul (f : M ≃ₗ[R] P) (g : N ≃ₗ[R] Q) (p : P) (q : Q) : (congr f g).symm (p ⊗ₜ q) = f.symm p ⊗ₜ g.symm q := rfl #align tensor_product.congr_symm_tmul TensorProduct.congr_symm_tmul theorem congr_symm (f : M ≃ₗ[R] P) (g : N ≃ₗ[R] Q) : (congr f g).symm = congr f.symm g.symm := rfl @[simp] theorem congr_refl_refl : congr (.refl R M) (.refl R N) = .refl R _ := LinearEquiv.toLinearMap_injective <| ext' fun _ _ ↦ rfl theorem congr_trans (f : M ≃ₗ[R] P) (g : N ≃ₗ[R] Q) (f' : P ≃ₗ[R] S) (g' : Q ≃ₗ[R] T) : congr (f ≪≫ₗ f') (g ≪≫ₗ g') = congr f g ≪≫ₗ congr f' g' := LinearEquiv.toLinearMap_injective <| map_comp _ _ _ _ theorem congr_mul (f : M ≃ₗ[R] M) (g : N ≃ₗ[R] N) (f' : M ≃ₗ[R] M) (g' : N ≃ₗ[R] N) : congr (f * f') (g * g') = congr f g * congr f' g' := congr_trans _ _ _ _ @[simp] theorem congr_pow (f : M ≃ₗ[R] M) (g : N ≃ₗ[R] N) (n : ℕ) : congr f g ^ n = congr (f ^ n) (g ^ n) := by induction n with | zero => exact congr_refl_refl.symm | succ n ih => simp_rw [pow_succ, ih, congr_mul] @[simp] theorem congr_zpow (f : M ≃ₗ[R] M) (g : N ≃ₗ[R] N) (n : ℤ) : congr f g ^ n = congr (f ^ n) (g ^ n) := by induction n with | ofNat n => exact congr_pow _ _ _ | negSucc n => simp_rw [zpow_negSucc, congr_pow]; exact congr_symm _ _ variable (R M N P Q) /-- A tensor product analogue of `mul_left_comm`. -/ def leftComm : M ⊗[R] N ⊗[R] P ≃ₗ[R] N ⊗[R] M ⊗[R] P := let e₁ := (TensorProduct.assoc R M N P).symm let e₂ := congr (TensorProduct.comm R M N) (1 : P ≃ₗ[R] P) let e₃ := TensorProduct.assoc R N M P e₁ ≪≫ₗ (e₂ ≪≫ₗ e₃) #align tensor_product.left_comm TensorProduct.leftComm variable {M N P Q} @[simp] theorem leftComm_tmul (m : M) (n : N) (p : P) : leftComm R M N P (m ⊗ₜ (n ⊗ₜ p)) = n ⊗ₜ (m ⊗ₜ p) := rfl #align tensor_product.left_comm_tmul TensorProduct.leftComm_tmul @[simp] theorem leftComm_symm_tmul (m : M) (n : N) (p : P) : (leftComm R M N P).symm (n ⊗ₜ (m ⊗ₜ p)) = m ⊗ₜ (n ⊗ₜ p) := rfl #align tensor_product.left_comm_symm_tmul TensorProduct.leftComm_symm_tmul variable (M N P Q) /-- This special case is worth defining explicitly since it is useful for defining multiplication on tensor products of modules carrying multiplications (e.g., associative rings, Lie rings, ...). E.g., suppose `M = P` and `N = Q` and that `M` and `N` carry bilinear multiplications: `M ⊗ M → M` and `N ⊗ N → N`. Using `map`, we can define `(M ⊗ M) ⊗ (N ⊗ N) → M ⊗ N` which, when combined with this definition, yields a bilinear multiplication on `M ⊗ N`: `(M ⊗ N) ⊗ (M ⊗ N) → M ⊗ N`. In particular we could use this to define the multiplication in the `TensorProduct.semiring` instance (currently defined "by hand" using `TensorProduct.mul`). See also `mul_mul_mul_comm`. -/ def tensorTensorTensorComm : (M ⊗[R] N) ⊗[R] P ⊗[R] Q ≃ₗ[R] (M ⊗[R] P) ⊗[R] N ⊗[R] Q := let e₁ := TensorProduct.assoc R M N (P ⊗[R] Q) let e₂ := congr (1 : M ≃ₗ[R] M) (leftComm R N P Q) let e₃ := (TensorProduct.assoc R M P (N ⊗[R] Q)).symm e₁ ≪≫ₗ (e₂ ≪≫ₗ e₃) #align tensor_product.tensor_tensor_tensor_comm TensorProduct.tensorTensorTensorComm variable {M N P Q} @[simp] theorem tensorTensorTensorComm_tmul (m : M) (n : N) (p : P) (q : Q) : tensorTensorTensorComm R M N P Q (m ⊗ₜ n ⊗ₜ (p ⊗ₜ q)) = m ⊗ₜ p ⊗ₜ (n ⊗ₜ q) := rfl #align tensor_product.tensor_tensor_tensor_comm_tmul TensorProduct.tensorTensorTensorComm_tmul -- Porting note: the proof here was `rfl` but that caused a timeout. @[simp] theorem tensorTensorTensorComm_symm : (tensorTensorTensorComm R M N P Q).symm = tensorTensorTensorComm R M P N Q := by ext; rfl #align tensor_product.tensor_tensor_tensor_comm_symm TensorProduct.tensorTensorTensorComm_symm variable (M N P Q) /-- This special case is useful for describing the interplay between `dualTensorHomEquiv` and composition of linear maps. E.g., composition of linear maps gives a map `(M → N) ⊗ (N → P) → (M → P)`, and applying `dual_tensor_hom_equiv.symm` to the three hom-modules gives a map `(M.dual ⊗ N) ⊗ (N.dual ⊗ P) → (M.dual ⊗ P)`, which agrees with the application of `contractRight` on `N ⊗ N.dual` after the suitable rebracketting. -/ def tensorTensorTensorAssoc : (M ⊗[R] N) ⊗[R] P ⊗[R] Q ≃ₗ[R] (M ⊗[R] N ⊗[R] P) ⊗[R] Q := (TensorProduct.assoc R (M ⊗[R] N) P Q).symm ≪≫ₗ congr (TensorProduct.assoc R M N P) (1 : Q ≃ₗ[R] Q) #align tensor_product.tensor_tensor_tensor_assoc TensorProduct.tensorTensorTensorAssoc variable {M N P Q} @[simp] theorem tensorTensorTensorAssoc_tmul (m : M) (n : N) (p : P) (q : Q) : tensorTensorTensorAssoc R M N P Q (m ⊗ₜ n ⊗ₜ (p ⊗ₜ q)) = m ⊗ₜ (n ⊗ₜ p) ⊗ₜ q := rfl #align tensor_product.tensor_tensor_tensor_assoc_tmul TensorProduct.tensorTensorTensorAssoc_tmul @[simp] theorem tensorTensorTensorAssoc_symm_tmul (m : M) (n : N) (p : P) (q : Q) : (tensorTensorTensorAssoc R M N P Q).symm (m ⊗ₜ (n ⊗ₜ p) ⊗ₜ q) = m ⊗ₜ n ⊗ₜ (p ⊗ₜ q) := rfl #align tensor_product.tensor_tensor_tensor_assoc_symm_tmul TensorProduct.tensorTensorTensorAssoc_symm_tmul end TensorProduct open scoped TensorProduct namespace LinearMap variable {N} /-- `LinearMap.lTensor M f : M ⊗ N →ₗ M ⊗ P` is the natural linear map induced by `f : N →ₗ P`. -/ def lTensor (f : N →ₗ[R] P) : M ⊗[R] N →ₗ[R] M ⊗[R] P := TensorProduct.map id f #align linear_map.ltensor LinearMap.lTensor /-- `LinearMap.rTensor M f : N₁ ⊗ M →ₗ N₂ ⊗ M` is the natural linear map induced by `f : N₁ →ₗ N₂`. -/ def rTensor (f : N →ₗ[R] P) : N ⊗[R] M →ₗ[R] P ⊗[R] M := TensorProduct.map f id #align linear_map.rtensor LinearMap.rTensor variable (g : P →ₗ[R] Q) (f : N →ₗ[R] P) @[simp] theorem lTensor_tmul (m : M) (n : N) : f.lTensor M (m ⊗ₜ n) = m ⊗ₜ f n := rfl #align linear_map.ltensor_tmul LinearMap.lTensor_tmul @[simp] theorem rTensor_tmul (m : M) (n : N) : f.rTensor M (n ⊗ₜ m) = f n ⊗ₜ m := rfl #align linear_map.rtensor_tmul LinearMap.rTensor_tmul @[simp] theorem lTensor_comp_mk (m : M) : f.lTensor M ∘ₗ TensorProduct.mk R M N m = TensorProduct.mk R M P m ∘ₗ f := rfl @[simp] theorem rTensor_comp_flip_mk (m : M) : f.rTensor M ∘ₗ (TensorProduct.mk R N M).flip m = (TensorProduct.mk R P M).flip m ∘ₗ f := rfl lemma comm_comp_rTensor_comp_comm_eq (g : N →ₗ[R] P) : TensorProduct.comm R P Q ∘ₗ rTensor Q g ∘ₗ TensorProduct.comm R Q N = lTensor Q g := TensorProduct.ext rfl lemma comm_comp_lTensor_comp_comm_eq (g : N →ₗ[R] P) : TensorProduct.comm R Q P ∘ₗ lTensor Q g ∘ₗ TensorProduct.comm R N Q = rTensor Q g := TensorProduct.ext rfl /-- Given a linear map `f : N → P`, `f ⊗ M` is injective if and only if `M ⊗ f` is injective. -/ theorem lTensor_inj_iff_rTensor_inj : Function.Injective (lTensor M f) ↔ Function.Injective (rTensor M f) := by simp [← comm_comp_rTensor_comp_comm_eq] /-- Given a linear map `f : N → P`, `f ⊗ M` is surjective if and only if `M ⊗ f` is surjective. -/ theorem lTensor_surj_iff_rTensor_surj : Function.Surjective (lTensor M f) ↔ Function.Surjective (rTensor M f) := by simp [← comm_comp_rTensor_comp_comm_eq] /-- Given a linear map `f : N → P`, `f ⊗ M` is bijective if and only if `M ⊗ f` is bijective. -/ theorem lTensor_bij_iff_rTensor_bij : Function.Bijective (lTensor M f) ↔ Function.Bijective (rTensor M f) := by simp [← comm_comp_rTensor_comp_comm_eq] open TensorProduct attribute [local ext high] TensorProduct.ext /-- `lTensorHom M` is the natural linear map that sends a linear map `f : N →ₗ P` to `M ⊗ f`. -/ def lTensorHom : (N →ₗ[R] P) →ₗ[R] M ⊗[R] N →ₗ[R] M ⊗[R] P where toFun := lTensor M map_add' f g := by ext x y simp only [compr₂_apply, mk_apply, add_apply, lTensor_tmul, tmul_add] map_smul' r f := by dsimp ext x y simp only [compr₂_apply, mk_apply, tmul_smul, smul_apply, lTensor_tmul] #align linear_map.ltensor_hom LinearMap.lTensorHom /-- `rTensorHom M` is the natural linear map that sends a linear map `f : N →ₗ P` to `f ⊗ M`. -/ def rTensorHom : (N →ₗ[R] P) →ₗ[R] N ⊗[R] M →ₗ[R] P ⊗[R] M where toFun f := f.rTensor M map_add' f g := by ext x y simp only [compr₂_apply, mk_apply, add_apply, rTensor_tmul, add_tmul] map_smul' r f := by dsimp ext x y simp only [compr₂_apply, mk_apply, smul_tmul, tmul_smul, smul_apply, rTensor_tmul] #align linear_map.rtensor_hom LinearMap.rTensorHom @[simp] theorem coe_lTensorHom : (lTensorHom M : (N →ₗ[R] P) → M ⊗[R] N →ₗ[R] M ⊗[R] P) = lTensor M := rfl #align linear_map.coe_ltensor_hom LinearMap.coe_lTensorHom @[simp] theorem coe_rTensorHom : (rTensorHom M : (N →ₗ[R] P) → N ⊗[R] M →ₗ[R] P ⊗[R] M) = rTensor M := rfl #align linear_map.coe_rtensor_hom LinearMap.coe_rTensorHom @[simp] theorem lTensor_add (f g : N →ₗ[R] P) : (f + g).lTensor M = f.lTensor M + g.lTensor M := (lTensorHom M).map_add f g #align linear_map.ltensor_add LinearMap.lTensor_add @[simp] theorem rTensor_add (f g : N →ₗ[R] P) : (f + g).rTensor M = f.rTensor M + g.rTensor M := (rTensorHom M).map_add f g #align linear_map.rtensor_add LinearMap.rTensor_add @[simp] theorem lTensor_zero : lTensor M (0 : N →ₗ[R] P) = 0 := (lTensorHom M).map_zero #align linear_map.ltensor_zero LinearMap.lTensor_zero @[simp] theorem rTensor_zero : rTensor M (0 : N →ₗ[R] P) = 0 := (rTensorHom M).map_zero #align linear_map.rtensor_zero LinearMap.rTensor_zero @[simp] theorem lTensor_smul (r : R) (f : N →ₗ[R] P) : (r • f).lTensor M = r • f.lTensor M := (lTensorHom M).map_smul r f #align linear_map.ltensor_smul LinearMap.lTensor_smul @[simp] theorem rTensor_smul (r : R) (f : N →ₗ[R] P) : (r • f).rTensor M = r • f.rTensor M := (rTensorHom M).map_smul r f #align linear_map.rtensor_smul LinearMap.rTensor_smul theorem lTensor_comp : (g.comp f).lTensor M = (g.lTensor M).comp (f.lTensor M) := by ext m n simp only [compr₂_apply, mk_apply, comp_apply, lTensor_tmul] #align linear_map.ltensor_comp LinearMap.lTensor_comp theorem lTensor_comp_apply (x : M ⊗[R] N) : (g.comp f).lTensor M x = (g.lTensor M) ((f.lTensor M) x) := by rw [lTensor_comp, coe_comp]; rfl #align linear_map.ltensor_comp_apply LinearMap.lTensor_comp_apply theorem rTensor_comp : (g.comp f).rTensor M = (g.rTensor M).comp (f.rTensor M) := by ext m n simp only [compr₂_apply, mk_apply, comp_apply, rTensor_tmul] #align linear_map.rtensor_comp LinearMap.rTensor_comp theorem rTensor_comp_apply (x : N ⊗[R] M) : (g.comp f).rTensor M x = (g.rTensor M) ((f.rTensor M) x) := by rw [rTensor_comp, coe_comp]; rfl #align linear_map.rtensor_comp_apply LinearMap.rTensor_comp_apply theorem lTensor_mul (f g : Module.End R N) : (f * g).lTensor M = f.lTensor M * g.lTensor M := lTensor_comp M f g #align linear_map.ltensor_mul LinearMap.lTensor_mul theorem rTensor_mul (f g : Module.End R N) : (f * g).rTensor M = f.rTensor M * g.rTensor M := rTensor_comp M f g #align linear_map.rtensor_mul LinearMap.rTensor_mul variable (N) @[simp] theorem lTensor_id : (id : N →ₗ[R] N).lTensor M = id := map_id #align linear_map.ltensor_id LinearMap.lTensor_id -- `simp` can prove this. theorem lTensor_id_apply (x : M ⊗[R] N) : (LinearMap.id : N →ₗ[R] N).lTensor M x = x := by rw [lTensor_id, id_coe, _root_.id] #align linear_map.ltensor_id_apply LinearMap.lTensor_id_apply @[simp] theorem rTensor_id : (id : N →ₗ[R] N).rTensor M = id := map_id #align linear_map.rtensor_id LinearMap.rTensor_id -- `simp` can prove this. theorem rTensor_id_apply (x : N ⊗[R] M) : (LinearMap.id : N →ₗ[R] N).rTensor M x = x := by rw [rTensor_id, id_coe, _root_.id] #align linear_map.rtensor_id_apply LinearMap.rTensor_id_apply @[simp] theorem lTensor_smul_action (r : R) : (DistribMulAction.toLinearMap R N r).lTensor M = DistribMulAction.toLinearMap R (M ⊗[R] N) r := (lTensor_smul M r LinearMap.id).trans (congrArg _ (lTensor_id M N)) @[simp] theorem rTensor_smul_action (r : R) : (DistribMulAction.toLinearMap R N r).rTensor M = DistribMulAction.toLinearMap R (N ⊗[R] M) r := (rTensor_smul M r LinearMap.id).trans (congrArg _ (rTensor_id M N)) variable {N} theorem lid_comp_rTensor (f : N →ₗ[R] R) : (TensorProduct.lid R M).comp (rTensor M f) = lift ((lsmul R M).comp f) := ext' fun _ _ ↦ rfl @[simp] theorem lTensor_comp_rTensor (f : M →ₗ[R] P) (g : N →ₗ[R] Q) : (g.lTensor P).comp (f.rTensor N) = map f g := by simp only [lTensor, rTensor, ← map_comp, id_comp, comp_id] #align linear_map.ltensor_comp_rtensor LinearMap.lTensor_comp_rTensor @[simp] theorem rTensor_comp_lTensor (f : M →ₗ[R] P) (g : N →ₗ[R] Q) : (f.rTensor Q).comp (g.lTensor M) = map f g := by simp only [lTensor, rTensor, ← map_comp, id_comp, comp_id] #align linear_map.rtensor_comp_ltensor LinearMap.rTensor_comp_lTensor @[simp] theorem map_comp_rTensor (f : M →ₗ[R] P) (g : N →ₗ[R] Q) (f' : S →ₗ[R] M) : (map f g).comp (f'.rTensor _) = map (f.comp f') g := by simp only [lTensor, rTensor, ← map_comp, id_comp, comp_id] #align linear_map.map_comp_rtensor LinearMap.map_comp_rTensor @[simp]
Mathlib/LinearAlgebra/TensorProduct/Basic.lean
1,368
1,370
theorem map_comp_lTensor (f : M →ₗ[R] P) (g : N →ₗ[R] Q) (g' : S →ₗ[R] N) : (map f g).comp (g'.lTensor _) = map f (g.comp g') := by
simp only [lTensor, rTensor, ← map_comp, id_comp, comp_id]
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Sites.IsSheafFor import Mathlib.CategoryTheory.Limits.Shapes.Types import Mathlib.Tactic.ApplyFun #align_import category_theory.sites.sheaf_of_types from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a" /-! # The equalizer diagram sheaf condition for a presieve In `Mathlib/CategoryTheory/Sites/IsSheafFor.lean` it is defined what it means for a presheaf to be a sheaf *for* a particular presieve. In this file we provide equivalent conditions in terms of equalizer diagrams. * In `Equalizer.Presieve.sheaf_condition`, the sheaf condition at a presieve is shown to be equivalent to that of https://stacks.math.columbia.edu/tag/00VM (and combined with `isSheaf_pretopology`, this shows the notions of `IsSheaf` are exactly equivalent.) * In `Equalizer.Sieve.equalizer_sheaf_condition`, the sheaf condition at a sieve is shown to be equivalent to that of Equation (3) p. 122 in Maclane-Moerdijk [MM92]. ## References * [MM92]: *Sheaves in geometry and logic*, Saunders MacLane, and Ieke Moerdijk: Chapter III, Section 4. * https://stacks.math.columbia.edu/tag/00VL (sheaves on a pretopology or site) -/ universe w v u namespace CategoryTheory open Opposite CategoryTheory Category Limits Sieve namespace Equalizer variable {C : Type u} [Category.{v} C] (P : Cᵒᵖ ⥤ Type max v u) {X : C} (R : Presieve X) (S : Sieve X) noncomputable section /-- The middle object of the fork diagram given in Equation (3) of [MM92], as well as the fork diagram of <https://stacks.math.columbia.edu/tag/00VM>. -/ def FirstObj : Type max v u := ∏ᶜ fun f : ΣY, { f : Y ⟶ X // R f } => P.obj (op f.1) #align category_theory.equalizer.first_obj CategoryTheory.Equalizer.FirstObj variable {P R} -- Porting note (#10688): added to ease automation @[ext] lemma FirstObj.ext (z₁ z₂ : FirstObj P R) (h : ∀ (Y : C) (f : Y ⟶ X) (hf : R f), (Pi.π _ ⟨Y, f, hf⟩ : FirstObj P R ⟶ _) z₁ = (Pi.π _ ⟨Y, f, hf⟩ : FirstObj P R ⟶ _) z₂) : z₁ = z₂ := by apply Limits.Types.limit_ext rintro ⟨⟨Y, f, hf⟩⟩ exact h Y f hf variable (P R) /-- Show that `FirstObj` is isomorphic to `FamilyOfElements`. -/ @[simps] def firstObjEqFamily : FirstObj P R ≅ R.FamilyOfElements P where hom t Y f hf := Pi.π (fun f : ΣY, { f : Y ⟶ X // R f } => P.obj (op f.1)) ⟨_, _, hf⟩ t inv := Pi.lift fun f x => x _ f.2.2 #align category_theory.equalizer.first_obj_eq_family CategoryTheory.Equalizer.firstObjEqFamily instance : Inhabited (FirstObj P (⊥ : Presieve X)) := (firstObjEqFamily P _).toEquiv.inhabited -- Porting note: was not needed in mathlib instance : Inhabited (FirstObj P ((⊥ : Sieve X) : Presieve X)) := (inferInstance : Inhabited (FirstObj P (⊥ : Presieve X))) /-- The left morphism of the fork diagram given in Equation (3) of [MM92], as well as the fork diagram of <https://stacks.math.columbia.edu/tag/00VM>. -/ def forkMap : P.obj (op X) ⟶ FirstObj P R := Pi.lift fun f => P.map f.2.1.op #align category_theory.equalizer.fork_map CategoryTheory.Equalizer.forkMap /-! This section establishes the equivalence between the sheaf condition of Equation (3) [MM92] and the definition of `IsSheafFor`. -/ namespace Sieve /-- The rightmost object of the fork diagram of Equation (3) [MM92], which contains the data used to check a family is compatible. -/ def SecondObj : Type max v u := ∏ᶜ fun f : Σ(Y Z : _) (_ : Z ⟶ Y), { f' : Y ⟶ X // S f' } => P.obj (op f.2.1) #align category_theory.equalizer.sieve.second_obj CategoryTheory.Equalizer.Sieve.SecondObj variable {P S} -- Porting note (#10688): added to ease automation @[ext] lemma SecondObj.ext (z₁ z₂ : SecondObj P S) (h : ∀ (Y Z : C) (g : Z ⟶ Y) (f : Y ⟶ X) (hf : S.arrows f), (Pi.π _ ⟨Y, Z, g, f, hf⟩ : SecondObj P S ⟶ _) z₁ = (Pi.π _ ⟨Y, Z, g, f, hf⟩ : SecondObj P S ⟶ _) z₂) : z₁ = z₂ := by apply Limits.Types.limit_ext rintro ⟨⟨Y, Z, g, f, hf⟩⟩ apply h variable (P S) /-- The map `p` of Equations (3,4) [MM92]. -/ def firstMap : FirstObj P (S : Presieve X) ⟶ SecondObj P S := Pi.lift fun fg => Pi.π _ (⟨_, _, S.downward_closed fg.2.2.2.2 fg.2.2.1⟩ : ΣY, { f : Y ⟶ X // S f }) #align category_theory.equalizer.sieve.first_map CategoryTheory.Equalizer.Sieve.firstMap instance : Inhabited (SecondObj P (⊥ : Sieve X)) := ⟨firstMap _ _ default⟩ /-- The map `a` of Equations (3,4) [MM92]. -/ def secondMap : FirstObj P (S : Presieve X) ⟶ SecondObj P S := Pi.lift fun fg => Pi.π _ ⟨_, fg.2.2.2⟩ ≫ P.map fg.2.2.1.op #align category_theory.equalizer.sieve.second_map CategoryTheory.Equalizer.Sieve.secondMap theorem w : forkMap P (S : Presieve X) ≫ firstMap P S = forkMap P S ≫ secondMap P S := by ext simp [firstMap, secondMap, forkMap] #align category_theory.equalizer.sieve.w CategoryTheory.Equalizer.Sieve.w /-- The family of elements given by `x : FirstObj P S` is compatible iff `firstMap` and `secondMap` map it to the same point. -/ theorem compatible_iff (x : FirstObj P S) : ((firstObjEqFamily P S).hom x).Compatible ↔ firstMap P S x = secondMap P S x := by rw [Presieve.compatible_iff_sieveCompatible] constructor · intro t apply SecondObj.ext intros Y Z g f hf simpa [firstMap, secondMap] using t _ g hf · intro t Y Z f g hf rw [Types.limit_ext_iff'] at t simpa [firstMap, secondMap] using t ⟨⟨Y, Z, g, f, hf⟩⟩ #align category_theory.equalizer.sieve.compatible_iff CategoryTheory.Equalizer.Sieve.compatible_iff /-- `P` is a sheaf for `S`, iff the fork given by `w` is an equalizer. -/ theorem equalizer_sheaf_condition : Presieve.IsSheafFor P (S : Presieve X) ↔ Nonempty (IsLimit (Fork.ofι _ (w P S))) := by rw [Types.type_equalizer_iff_unique, ← Equiv.forall_congr_left (firstObjEqFamily P (S : Presieve X)).toEquiv.symm] simp_rw [← compatible_iff] simp only [inv_hom_id_apply, Iso.toEquiv_symm_fun] apply forall₂_congr intro x _ apply exists_unique_congr intro t rw [← Iso.toEquiv_symm_fun] rw [Equiv.eq_symm_apply] constructor · intro q funext Y f hf simpa [firstObjEqFamily, forkMap] using q _ _ · intro q Y f hf rw [← q] simp [firstObjEqFamily, forkMap] #align category_theory.equalizer.sieve.equalizer_sheaf_condition CategoryTheory.Equalizer.Sieve.equalizer_sheaf_condition end Sieve /-! This section establishes the equivalence between the sheaf condition of https://stacks.math.columbia.edu/tag/00VM and the definition of `isSheafFor`. -/ namespace Presieve variable [R.hasPullbacks] /-- The rightmost object of the fork diagram of https://stacks.math.columbia.edu/tag/00VM, which contains the data used to check a family of elements for a presieve is compatible. -/ @[simp] def SecondObj : Type max v u := ∏ᶜ fun fg : (ΣY, { f : Y ⟶ X // R f }) × ΣZ, { g : Z ⟶ X // R g } => haveI := Presieve.hasPullbacks.has_pullbacks fg.1.2.2 fg.2.2.2 P.obj (op (pullback fg.1.2.1 fg.2.2.1)) #align category_theory.equalizer.presieve.second_obj CategoryTheory.Equalizer.Presieve.SecondObj /-- The map `pr₀*` of <https://stacks.math.columbia.edu/tag/00VL>. -/ def firstMap : FirstObj P R ⟶ SecondObj P R := Pi.lift fun fg => haveI := Presieve.hasPullbacks.has_pullbacks fg.1.2.2 fg.2.2.2 Pi.π _ _ ≫ P.map pullback.fst.op #align category_theory.equalizer.presieve.first_map CategoryTheory.Equalizer.Presieve.firstMap instance [HasPullbacks C] : Inhabited (SecondObj P (⊥ : Presieve X)) := ⟨firstMap _ _ default⟩ /-- The map `pr₁*` of <https://stacks.math.columbia.edu/tag/00VL>. -/ def secondMap : FirstObj P R ⟶ SecondObj P R := Pi.lift fun fg => haveI := Presieve.hasPullbacks.has_pullbacks fg.1.2.2 fg.2.2.2 Pi.π _ _ ≫ P.map pullback.snd.op #align category_theory.equalizer.presieve.second_map CategoryTheory.Equalizer.Presieve.secondMap theorem w : forkMap P R ≫ firstMap P R = forkMap P R ≫ secondMap P R := by dsimp ext fg simp only [firstMap, secondMap, forkMap] simp only [limit.lift_π, limit.lift_π_assoc, assoc, Fan.mk_π_app] haveI := Presieve.hasPullbacks.has_pullbacks fg.1.2.2 fg.2.2.2 rw [← P.map_comp, ← op_comp, pullback.condition] simp #align category_theory.equalizer.presieve.w CategoryTheory.Equalizer.Presieve.w /-- The family of elements given by `x : FirstObj P S` is compatible iff `firstMap` and `secondMap` map it to the same point. -/ theorem compatible_iff (x : FirstObj P R) : ((firstObjEqFamily P R).hom x).Compatible ↔ firstMap P R x = secondMap P R x := by rw [Presieve.pullbackCompatible_iff] constructor · intro t apply Limits.Types.limit_ext rintro ⟨⟨Y, f, hf⟩, Z, g, hg⟩ simpa [firstMap, secondMap] using t hf hg · intro t Y Z f g hf hg rw [Types.limit_ext_iff'] at t simpa [firstMap, secondMap] using t ⟨⟨⟨Y, f, hf⟩, Z, g, hg⟩⟩ #align category_theory.equalizer.presieve.compatible_iff CategoryTheory.Equalizer.Presieve.compatible_iff /-- `P` is a sheaf for `R`, iff the fork given by `w` is an equalizer. See <https://stacks.math.columbia.edu/tag/00VM>. -/ theorem sheaf_condition : R.IsSheafFor P ↔ Nonempty (IsLimit (Fork.ofι _ (w P R))) := by rw [Types.type_equalizer_iff_unique] erw [← Equiv.forall_congr_left (firstObjEqFamily P R).toEquiv.symm] simp_rw [← compatible_iff, ← Iso.toEquiv_fun, Equiv.apply_symm_apply] apply forall₂_congr intro x _ apply exists_unique_congr intro t rw [Equiv.eq_symm_apply] constructor · intro q funext Y f hf simpa [forkMap] using q _ _ · intro q Y f hf rw [← q] simp [forkMap] #align category_theory.equalizer.presieve.sheaf_condition CategoryTheory.Equalizer.Presieve.sheaf_condition namespace Arrows variable (P : Cᵒᵖ ⥤ Type w) {X : C} (R : Presieve X) (S : Sieve X) open Presieve variable {B : C} {I : Type} (X : I → C) (π : (i : I) → X i ⟶ B) [(Presieve.ofArrows X π).hasPullbacks] -- TODO: allow `I : Type w`  /-- The middle object of the fork diagram of <https://stacks.math.columbia.edu/tag/00VM>. The difference between this and `Equalizer.FirstObj P (ofArrows X π)` arrises if the family of arrows `π` contains duplicates. The `Presieve.ofArrows` doesn't see those. -/ def FirstObj : Type w := ∏ᶜ (fun i ↦ P.obj (op (X i))) @[ext] lemma FirstObj.ext (z₁ z₂ : FirstObj P X) (h : ∀ i, (Pi.π _ i : FirstObj P X ⟶ _) z₁ = (Pi.π _ i : FirstObj P X ⟶ _) z₂) : z₁ = z₂ := by apply Limits.Types.limit_ext rintro ⟨i⟩ exact h i /-- The rightmost object of the fork diagram of https://stacks.math.columbia.edu/tag/00VM. The difference between this and `Equalizer.Presieve.SecondObj P (ofArrows X π)` arrises if the family of arrows `π` contains duplicates. The `Presieve.ofArrows` doesn't see those. -/ def SecondObj : Type w := ∏ᶜ (fun (ij : I × I) ↦ P.obj (op (pullback (π ij.1) (π ij.2)))) @[ext] lemma SecondObj.ext (z₁ z₂ : SecondObj P X π) (h : ∀ ij, (Pi.π _ ij : SecondObj P X π ⟶ _) z₁ = (Pi.π _ ij : SecondObj P X π ⟶ _) z₂) : z₁ = z₂ := by apply Limits.Types.limit_ext rintro ⟨i⟩ exact h i /-- The left morphism of the fork diagram. -/ def forkMap : P.obj (op B) ⟶ FirstObj P X := Pi.lift (fun i ↦ P.map (π i).op) /-- The first of the two parallel morphisms of the fork diagram, induced by the first projection in each pullback. -/ def firstMap : FirstObj P X ⟶ SecondObj P X π := Pi.lift fun _ => Pi.π _ _ ≫ P.map pullback.fst.op /-- The second of the two parallel morphisms of the fork diagram, induced by the second projection in each pullback. -/ def secondMap : FirstObj P X ⟶ SecondObj P X π := Pi.lift fun _ => Pi.π _ _ ≫ P.map pullback.snd.op theorem w : forkMap P X π ≫ firstMap P X π = forkMap P X π ≫ secondMap P X π := by ext x ij simp only [firstMap, secondMap, forkMap, types_comp_apply, Types.pi_lift_π_apply, ← FunctorToTypes.map_comp_apply, ← op_comp, pullback.condition] /-- The family of elements given by `x : FirstObj P S` is compatible iff `firstMap` and `secondMap` map it to the same point. -/
Mathlib/CategoryTheory/Sites/EqualizerSheafCondition.lean
329
338
theorem compatible_iff (x : FirstObj P X) : (Arrows.Compatible P π ((Types.productIso _).hom x)) ↔ firstMap P X π x = secondMap P X π x := by
rw [Arrows.pullbackCompatible_iff] constructor · intro t ext ij simpa [firstMap, secondMap] using t ij.1 ij.2 · intro t i j apply_fun Pi.π (fun (ij : I × I) ↦ P.obj (op (pullback (π ij.1) (π ij.2)))) ⟨i, j⟩ at t simpa [firstMap, secondMap] using t
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.TwoDim import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic #align_import geometry.euclidean.angle.oriented.basic from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9" /-! # Oriented angles. This file defines oriented angles in real inner product spaces. ## Main definitions * `Orientation.oangle` is the oriented angle between two vectors with respect to an orientation. ## Implementation notes The definitions here use the `Real.angle` type, angles modulo `2 * π`. For some purposes, angles modulo `π` are more convenient, because results are true for such angles with less configuration dependence. Results that are only equalities modulo `π` can be represented modulo `2 * π` as equalities of `(2 : ℤ) • θ`. ## References * Evan Chen, Euclidean Geometry in Mathematical Olympiads. -/ noncomputable section open FiniteDimensional Complex open scoped Real RealInnerProductSpace ComplexConjugate namespace Orientation attribute [local instance] Complex.finrank_real_complex_fact variable {V V' : Type*} variable [NormedAddCommGroup V] [NormedAddCommGroup V'] variable [InnerProductSpace ℝ V] [InnerProductSpace ℝ V'] variable [Fact (finrank ℝ V = 2)] [Fact (finrank ℝ V' = 2)] (o : Orientation ℝ V (Fin 2)) local notation "ω" => o.areaForm /-- The oriented angle from `x` to `y`, modulo `2 * π`. If either vector is 0, this is 0. See `InnerProductGeometry.angle` for the corresponding unoriented angle definition. -/ def oangle (x y : V) : Real.Angle := Complex.arg (o.kahler x y) #align orientation.oangle Orientation.oangle /-- Oriented angles are continuous when the vectors involved are nonzero. -/ theorem continuousAt_oangle {x : V × V} (hx1 : x.1 ≠ 0) (hx2 : x.2 ≠ 0) : ContinuousAt (fun y : V × V => o.oangle y.1 y.2) x := by refine (Complex.continuousAt_arg_coe_angle ?_).comp ?_ · exact o.kahler_ne_zero hx1 hx2 exact ((continuous_ofReal.comp continuous_inner).add ((continuous_ofReal.comp o.areaForm'.continuous₂).mul continuous_const)).continuousAt #align orientation.continuous_at_oangle Orientation.continuousAt_oangle /-- If the first vector passed to `oangle` is 0, the result is 0. -/ @[simp] theorem oangle_zero_left (x : V) : o.oangle 0 x = 0 := by simp [oangle] #align orientation.oangle_zero_left Orientation.oangle_zero_left /-- If the second vector passed to `oangle` is 0, the result is 0. -/ @[simp] theorem oangle_zero_right (x : V) : o.oangle x 0 = 0 := by simp [oangle] #align orientation.oangle_zero_right Orientation.oangle_zero_right /-- If the two vectors passed to `oangle` are the same, the result is 0. -/ @[simp] theorem oangle_self (x : V) : o.oangle x x = 0 := by rw [oangle, kahler_apply_self, ← ofReal_pow] convert QuotientAddGroup.mk_zero (AddSubgroup.zmultiples (2 * π)) apply arg_ofReal_of_nonneg positivity #align orientation.oangle_self Orientation.oangle_self /-- If the angle between two vectors is nonzero, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : x ≠ 0 := by rintro rfl; simp at h #align orientation.left_ne_zero_of_oangle_ne_zero Orientation.left_ne_zero_of_oangle_ne_zero /-- If the angle between two vectors is nonzero, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : y ≠ 0 := by rintro rfl; simp at h #align orientation.right_ne_zero_of_oangle_ne_zero Orientation.right_ne_zero_of_oangle_ne_zero /-- If the angle between two vectors is nonzero, the vectors are not equal. -/ theorem ne_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : x ≠ y := by rintro rfl; simp at h #align orientation.ne_of_oangle_ne_zero Orientation.ne_of_oangle_ne_zero /-- If the angle between two vectors is `π`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0) #align orientation.left_ne_zero_of_oangle_eq_pi Orientation.left_ne_zero_of_oangle_eq_pi /-- If the angle between two vectors is `π`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0) #align orientation.right_ne_zero_of_oangle_eq_pi Orientation.right_ne_zero_of_oangle_eq_pi /-- If the angle between two vectors is `π`, the vectors are not equal. -/ theorem ne_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : x ≠ y := o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0) #align orientation.ne_of_oangle_eq_pi Orientation.ne_of_oangle_eq_pi /-- If the angle between two vectors is `π / 2`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0) #align orientation.left_ne_zero_of_oangle_eq_pi_div_two Orientation.left_ne_zero_of_oangle_eq_pi_div_two /-- If the angle between two vectors is `π / 2`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0) #align orientation.right_ne_zero_of_oangle_eq_pi_div_two Orientation.right_ne_zero_of_oangle_eq_pi_div_two /-- If the angle between two vectors is `π / 2`, the vectors are not equal. -/ theorem ne_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : x ≠ y := o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0) #align orientation.ne_of_oangle_eq_pi_div_two Orientation.ne_of_oangle_eq_pi_div_two /-- If the angle between two vectors is `-π / 2`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0) #align orientation.left_ne_zero_of_oangle_eq_neg_pi_div_two Orientation.left_ne_zero_of_oangle_eq_neg_pi_div_two /-- If the angle between two vectors is `-π / 2`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0) #align orientation.right_ne_zero_of_oangle_eq_neg_pi_div_two Orientation.right_ne_zero_of_oangle_eq_neg_pi_div_two /-- If the angle between two vectors is `-π / 2`, the vectors are not equal. -/ theorem ne_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : x ≠ y := o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0) #align orientation.ne_of_oangle_eq_neg_pi_div_two Orientation.ne_of_oangle_eq_neg_pi_div_two /-- If the sign of the angle between two vectors is nonzero, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 #align orientation.left_ne_zero_of_oangle_sign_ne_zero Orientation.left_ne_zero_of_oangle_sign_ne_zero /-- If the sign of the angle between two vectors is nonzero, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 #align orientation.right_ne_zero_of_oangle_sign_ne_zero Orientation.right_ne_zero_of_oangle_sign_ne_zero /-- If the sign of the angle between two vectors is nonzero, the vectors are not equal. -/ theorem ne_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : x ≠ y := o.ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 #align orientation.ne_of_oangle_sign_ne_zero Orientation.ne_of_oangle_sign_ne_zero /-- If the sign of the angle between two vectors is positive, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x ≠ 0 := o.left_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) #align orientation.left_ne_zero_of_oangle_sign_eq_one Orientation.left_ne_zero_of_oangle_sign_eq_one /-- If the sign of the angle between two vectors is positive, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : y ≠ 0 := o.right_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) #align orientation.right_ne_zero_of_oangle_sign_eq_one Orientation.right_ne_zero_of_oangle_sign_eq_one /-- If the sign of the angle between two vectors is positive, the vectors are not equal. -/ theorem ne_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x ≠ y := o.ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) #align orientation.ne_of_oangle_sign_eq_one Orientation.ne_of_oangle_sign_eq_one /-- If the sign of the angle between two vectors is negative, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x ≠ 0 := o.left_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) #align orientation.left_ne_zero_of_oangle_sign_eq_neg_one Orientation.left_ne_zero_of_oangle_sign_eq_neg_one /-- If the sign of the angle between two vectors is negative, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : y ≠ 0 := o.right_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) #align orientation.right_ne_zero_of_oangle_sign_eq_neg_one Orientation.right_ne_zero_of_oangle_sign_eq_neg_one /-- If the sign of the angle between two vectors is negative, the vectors are not equal. -/ theorem ne_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x ≠ y := o.ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) #align orientation.ne_of_oangle_sign_eq_neg_one Orientation.ne_of_oangle_sign_eq_neg_one /-- Swapping the two vectors passed to `oangle` negates the angle. -/ theorem oangle_rev (x y : V) : o.oangle y x = -o.oangle x y := by simp only [oangle, o.kahler_swap y x, Complex.arg_conj_coe_angle] #align orientation.oangle_rev Orientation.oangle_rev /-- Adding the angles between two vectors in each order results in 0. -/ @[simp] theorem oangle_add_oangle_rev (x y : V) : o.oangle x y + o.oangle y x = 0 := by simp [o.oangle_rev y x] #align orientation.oangle_add_oangle_rev Orientation.oangle_add_oangle_rev /-- Negating the first vector passed to `oangle` adds `π` to the angle. -/ theorem oangle_neg_left {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : o.oangle (-x) y = o.oangle x y + π := by simp only [oangle, map_neg] convert Complex.arg_neg_coe_angle _ exact o.kahler_ne_zero hx hy #align orientation.oangle_neg_left Orientation.oangle_neg_left /-- Negating the second vector passed to `oangle` adds `π` to the angle. -/ theorem oangle_neg_right {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : o.oangle x (-y) = o.oangle x y + π := by simp only [oangle, map_neg] convert Complex.arg_neg_coe_angle _ exact o.kahler_ne_zero hx hy #align orientation.oangle_neg_right Orientation.oangle_neg_right /-- Negating the first vector passed to `oangle` does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_neg_left (x y : V) : (2 : ℤ) • o.oangle (-x) y = (2 : ℤ) • o.oangle x y := by by_cases hx : x = 0 · simp [hx] · by_cases hy : y = 0 · simp [hy] · simp [o.oangle_neg_left hx hy] #align orientation.two_zsmul_oangle_neg_left Orientation.two_zsmul_oangle_neg_left /-- Negating the second vector passed to `oangle` does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_neg_right (x y : V) : (2 : ℤ) • o.oangle x (-y) = (2 : ℤ) • o.oangle x y := by by_cases hx : x = 0 · simp [hx] · by_cases hy : y = 0 · simp [hy] · simp [o.oangle_neg_right hx hy] #align orientation.two_zsmul_oangle_neg_right Orientation.two_zsmul_oangle_neg_right /-- Negating both vectors passed to `oangle` does not change the angle. -/ @[simp] theorem oangle_neg_neg (x y : V) : o.oangle (-x) (-y) = o.oangle x y := by simp [oangle] #align orientation.oangle_neg_neg Orientation.oangle_neg_neg /-- Negating the first vector produces the same angle as negating the second vector. -/ theorem oangle_neg_left_eq_neg_right (x y : V) : o.oangle (-x) y = o.oangle x (-y) := by rw [← neg_neg y, oangle_neg_neg, neg_neg] #align orientation.oangle_neg_left_eq_neg_right Orientation.oangle_neg_left_eq_neg_right /-- The angle between the negation of a nonzero vector and that vector is `π`. -/ @[simp] theorem oangle_neg_self_left {x : V} (hx : x ≠ 0) : o.oangle (-x) x = π := by simp [oangle_neg_left, hx] #align orientation.oangle_neg_self_left Orientation.oangle_neg_self_left /-- The angle between a nonzero vector and its negation is `π`. -/ @[simp] theorem oangle_neg_self_right {x : V} (hx : x ≠ 0) : o.oangle x (-x) = π := by simp [oangle_neg_right, hx] #align orientation.oangle_neg_self_right Orientation.oangle_neg_self_right /-- Twice the angle between the negation of a vector and that vector is 0. -/ -- @[simp] -- Porting note (#10618): simp can prove this theorem two_zsmul_oangle_neg_self_left (x : V) : (2 : ℤ) • o.oangle (-x) x = 0 := by by_cases hx : x = 0 <;> simp [hx] #align orientation.two_zsmul_oangle_neg_self_left Orientation.two_zsmul_oangle_neg_self_left /-- Twice the angle between a vector and its negation is 0. -/ -- @[simp] -- Porting note (#10618): simp can prove this theorem two_zsmul_oangle_neg_self_right (x : V) : (2 : ℤ) • o.oangle x (-x) = 0 := by by_cases hx : x = 0 <;> simp [hx] #align orientation.two_zsmul_oangle_neg_self_right Orientation.two_zsmul_oangle_neg_self_right /-- Adding the angles between two vectors in each order, with the first vector in each angle negated, results in 0. -/ @[simp] theorem oangle_add_oangle_rev_neg_left (x y : V) : o.oangle (-x) y + o.oangle (-y) x = 0 := by rw [oangle_neg_left_eq_neg_right, oangle_rev, add_left_neg] #align orientation.oangle_add_oangle_rev_neg_left Orientation.oangle_add_oangle_rev_neg_left /-- Adding the angles between two vectors in each order, with the second vector in each angle negated, results in 0. -/ @[simp] theorem oangle_add_oangle_rev_neg_right (x y : V) : o.oangle x (-y) + o.oangle y (-x) = 0 := by rw [o.oangle_rev (-x), oangle_neg_left_eq_neg_right, add_neg_self] #align orientation.oangle_add_oangle_rev_neg_right Orientation.oangle_add_oangle_rev_neg_right /-- Multiplying the first vector passed to `oangle` by a positive real does not change the angle. -/ @[simp] theorem oangle_smul_left_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : o.oangle (r • x) y = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr] #align orientation.oangle_smul_left_of_pos Orientation.oangle_smul_left_of_pos /-- Multiplying the second vector passed to `oangle` by a positive real does not change the angle. -/ @[simp]
Mathlib/Geometry/Euclidean/Angle/Oriented/Basic.lean
299
300
theorem oangle_smul_right_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : o.oangle x (r • y) = o.oangle x y := by
simp [oangle, Complex.arg_real_mul _ hr]
/- 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 -/ import Mathlib.Data.Bool.Set import Mathlib.Data.Nat.Set import Mathlib.Data.Set.Prod import Mathlib.Data.ULift import Mathlib.Order.Bounds.Basic import Mathlib.Order.Hom.Set import Mathlib.Order.SetNotation #align_import order.complete_lattice from "leanprover-community/mathlib"@"5709b0d8725255e76f47debca6400c07b5c2d8e6" /-! # Theory of complete lattices ## Main definitions * `sSup` and `sInf` are the supremum and the infimum of a set; * `iSup (f : ι → α)` and `iInf (f : ι → α)` are indexed supremum and infimum of a function, defined as `sSup` and `sInf` of the range of this function; * class `CompleteLattice`: a bounded lattice such that `sSup s` is always the least upper boundary of `s` and `sInf s` is always the greatest lower boundary of `s`; * class `CompleteLinearOrder`: a linear ordered complete lattice. ## Naming conventions In lemma names, * `sSup` is called `sSup` * `sInf` is called `sInf` * `⨆ i, s i` is called `iSup` * `⨅ i, s i` is called `iInf` * `⨆ i j, s i j` is called `iSup₂`. This is an `iSup` inside an `iSup`. * `⨅ i j, s i j` is called `iInf₂`. This is an `iInf` inside an `iInf`. * `⨆ i ∈ s, t i` is called `biSup` for "bounded `iSup`". This is the special case of `iSup₂` where `j : i ∈ s`. * `⨅ i ∈ s, t i` is called `biInf` for "bounded `iInf`". This is the special case of `iInf₂` where `j : i ∈ s`. ## Notation * `⨆ i, f i` : `iSup f`, the supremum of the range of `f`; * `⨅ i, f i` : `iInf f`, the infimum of the range of `f`. -/ open Function OrderDual Set variable {α β β₂ γ : Type*} {ι ι' : Sort*} {κ : ι → Sort*} {κ' : ι' → Sort*} instance OrderDual.supSet (α) [InfSet α] : SupSet αᵒᵈ := ⟨(sInf : Set α → α)⟩ instance OrderDual.infSet (α) [SupSet α] : InfSet αᵒᵈ := ⟨(sSup : Set α → α)⟩ /-- Note that we rarely use `CompleteSemilatticeSup` (in fact, any such object is always a `CompleteLattice`, so it's usually best to start there). Nevertheless it is sometimes a useful intermediate step in constructions. -/ class CompleteSemilatticeSup (α : Type*) extends PartialOrder α, SupSet α where /-- Any element of a set is less than the set supremum. -/ le_sSup : ∀ s, ∀ a ∈ s, a ≤ sSup s /-- Any upper bound is more than the set supremum. -/ sSup_le : ∀ s a, (∀ b ∈ s, b ≤ a) → sSup s ≤ a #align complete_semilattice_Sup CompleteSemilatticeSup section variable [CompleteSemilatticeSup α] {s t : Set α} {a b : α} theorem le_sSup : a ∈ s → a ≤ sSup s := CompleteSemilatticeSup.le_sSup s a #align le_Sup le_sSup theorem sSup_le : (∀ b ∈ s, b ≤ a) → sSup s ≤ a := CompleteSemilatticeSup.sSup_le s a #align Sup_le sSup_le theorem isLUB_sSup (s : Set α) : IsLUB s (sSup s) := ⟨fun _ ↦ le_sSup, fun _ ↦ sSup_le⟩ #align is_lub_Sup isLUB_sSup lemma isLUB_iff_sSup_eq : IsLUB s a ↔ sSup s = a := ⟨(isLUB_sSup s).unique, by rintro rfl; exact isLUB_sSup _⟩ alias ⟨IsLUB.sSup_eq, _⟩ := isLUB_iff_sSup_eq #align is_lub.Sup_eq IsLUB.sSup_eq theorem le_sSup_of_le (hb : b ∈ s) (h : a ≤ b) : a ≤ sSup s := le_trans h (le_sSup hb) #align le_Sup_of_le le_sSup_of_le @[gcongr] theorem sSup_le_sSup (h : s ⊆ t) : sSup s ≤ sSup t := (isLUB_sSup s).mono (isLUB_sSup t) h #align Sup_le_Sup sSup_le_sSup @[simp] theorem sSup_le_iff : sSup s ≤ a ↔ ∀ b ∈ s, b ≤ a := isLUB_le_iff (isLUB_sSup s) #align Sup_le_iff sSup_le_iff theorem le_sSup_iff : a ≤ sSup s ↔ ∀ b ∈ upperBounds s, a ≤ b := ⟨fun h _ hb => le_trans h (sSup_le hb), fun hb => hb _ fun _ => le_sSup⟩ #align le_Sup_iff le_sSup_iff theorem le_iSup_iff {s : ι → α} : a ≤ iSup s ↔ ∀ b, (∀ i, s i ≤ b) → a ≤ b := by simp [iSup, le_sSup_iff, upperBounds] #align le_supr_iff le_iSup_iff theorem sSup_le_sSup_of_forall_exists_le (h : ∀ x ∈ s, ∃ y ∈ t, x ≤ y) : sSup s ≤ sSup t := le_sSup_iff.2 fun _ hb => sSup_le fun a ha => let ⟨_, hct, hac⟩ := h a ha hac.trans (hb hct) #align Sup_le_Sup_of_forall_exists_le sSup_le_sSup_of_forall_exists_le -- We will generalize this to conditionally complete lattices in `csSup_singleton`. theorem sSup_singleton {a : α} : sSup {a} = a := isLUB_singleton.sSup_eq #align Sup_singleton sSup_singleton end /-- Note that we rarely use `CompleteSemilatticeInf` (in fact, any such object is always a `CompleteLattice`, so it's usually best to start there). Nevertheless it is sometimes a useful intermediate step in constructions. -/ class CompleteSemilatticeInf (α : Type*) extends PartialOrder α, InfSet α where /-- Any element of a set is more than the set infimum. -/ sInf_le : ∀ s, ∀ a ∈ s, sInf s ≤ a /-- Any lower bound is less than the set infimum. -/ le_sInf : ∀ s a, (∀ b ∈ s, a ≤ b) → a ≤ sInf s #align complete_semilattice_Inf CompleteSemilatticeInf section variable [CompleteSemilatticeInf α] {s t : Set α} {a b : α} theorem sInf_le : a ∈ s → sInf s ≤ a := CompleteSemilatticeInf.sInf_le s a #align Inf_le sInf_le theorem le_sInf : (∀ b ∈ s, a ≤ b) → a ≤ sInf s := CompleteSemilatticeInf.le_sInf s a #align le_Inf le_sInf theorem isGLB_sInf (s : Set α) : IsGLB s (sInf s) := ⟨fun _ => sInf_le, fun _ => le_sInf⟩ #align is_glb_Inf isGLB_sInf lemma isGLB_iff_sInf_eq : IsGLB s a ↔ sInf s = a := ⟨(isGLB_sInf s).unique, by rintro rfl; exact isGLB_sInf _⟩ alias ⟨IsGLB.sInf_eq, _⟩ := isGLB_iff_sInf_eq #align is_glb.Inf_eq IsGLB.sInf_eq theorem sInf_le_of_le (hb : b ∈ s) (h : b ≤ a) : sInf s ≤ a := le_trans (sInf_le hb) h #align Inf_le_of_le sInf_le_of_le @[gcongr] theorem sInf_le_sInf (h : s ⊆ t) : sInf t ≤ sInf s := (isGLB_sInf s).mono (isGLB_sInf t) h #align Inf_le_Inf sInf_le_sInf @[simp] theorem le_sInf_iff : a ≤ sInf s ↔ ∀ b ∈ s, a ≤ b := le_isGLB_iff (isGLB_sInf s) #align le_Inf_iff le_sInf_iff theorem sInf_le_iff : sInf s ≤ a ↔ ∀ b ∈ lowerBounds s, b ≤ a := ⟨fun h _ hb => le_trans (le_sInf hb) h, fun hb => hb _ fun _ => sInf_le⟩ #align Inf_le_iff sInf_le_iff theorem iInf_le_iff {s : ι → α} : iInf s ≤ a ↔ ∀ b, (∀ i, b ≤ s i) → b ≤ a := by simp [iInf, sInf_le_iff, lowerBounds] #align infi_le_iff iInf_le_iff theorem sInf_le_sInf_of_forall_exists_le (h : ∀ x ∈ s, ∃ y ∈ t, y ≤ x) : sInf t ≤ sInf s := le_sInf fun x hx ↦ let ⟨_y, hyt, hyx⟩ := h x hx; sInf_le_of_le hyt hyx #align Inf_le_Inf_of_forall_exists_le sInf_le_sInf_of_forall_exists_le -- We will generalize this to conditionally complete lattices in `csInf_singleton`. theorem sInf_singleton {a : α} : sInf {a} = a := isGLB_singleton.sInf_eq #align Inf_singleton sInf_singleton end /-- A complete lattice is a bounded lattice which has suprema and infima for every subset. -/ class CompleteLattice (α : Type*) extends Lattice α, CompleteSemilatticeSup α, CompleteSemilatticeInf α, Top α, Bot α where /-- Any element is less than the top one. -/ protected le_top : ∀ x : α, x ≤ ⊤ /-- Any element is more than the bottom one. -/ protected bot_le : ∀ x : α, ⊥ ≤ x #align complete_lattice CompleteLattice -- see Note [lower instance priority] instance (priority := 100) CompleteLattice.toBoundedOrder [h : CompleteLattice α] : BoundedOrder α := { h with } #align complete_lattice.to_bounded_order CompleteLattice.toBoundedOrder /-- Create a `CompleteLattice` from a `PartialOrder` and `InfSet` that returns the greatest lower bound of a set. Usually this constructor provides poor definitional equalities. If other fields are known explicitly, they should be provided; for example, if `inf` is known explicitly, construct the `CompleteLattice` instance as ``` instance : CompleteLattice my_T where inf := better_inf le_inf := ... inf_le_right := ... inf_le_left := ... -- don't care to fix sup, sSup, bot, top __ := completeLatticeOfInf my_T _ ``` -/ def completeLatticeOfInf (α : Type*) [H1 : PartialOrder α] [H2 : InfSet α] (isGLB_sInf : ∀ s : Set α, IsGLB s (sInf s)) : CompleteLattice α where __ := H1; __ := H2 bot := sInf univ bot_le x := (isGLB_sInf univ).1 trivial top := sInf ∅ le_top a := (isGLB_sInf ∅).2 <| by simp sup a b := sInf { x : α | a ≤ x ∧ b ≤ x } inf a b := sInf {a, b} le_inf a b c hab hac := by apply (isGLB_sInf _).2 simp [*] inf_le_right a b := (isGLB_sInf _).1 <| mem_insert_of_mem _ <| mem_singleton _ inf_le_left a b := (isGLB_sInf _).1 <| mem_insert _ _ sup_le a b c hac hbc := (isGLB_sInf _).1 <| by simp [*] le_sup_left a b := (isGLB_sInf _).2 fun x => And.left le_sup_right a b := (isGLB_sInf _).2 fun x => And.right le_sInf s a ha := (isGLB_sInf s).2 ha sInf_le s a ha := (isGLB_sInf s).1 ha sSup s := sInf (upperBounds s) le_sSup s a ha := (isGLB_sInf (upperBounds s)).2 fun b hb => hb ha sSup_le s a ha := (isGLB_sInf (upperBounds s)).1 ha #align complete_lattice_of_Inf completeLatticeOfInf /-- Any `CompleteSemilatticeInf` is in fact a `CompleteLattice`. Note that this construction has bad definitional properties: see the doc-string on `completeLatticeOfInf`. -/ def completeLatticeOfCompleteSemilatticeInf (α : Type*) [CompleteSemilatticeInf α] : CompleteLattice α := completeLatticeOfInf α fun s => isGLB_sInf s #align complete_lattice_of_complete_semilattice_Inf completeLatticeOfCompleteSemilatticeInf /-- Create a `CompleteLattice` from a `PartialOrder` and `SupSet` that returns the least upper bound of a set. Usually this constructor provides poor definitional equalities. If other fields are known explicitly, they should be provided; for example, if `inf` is known explicitly, construct the `CompleteLattice` instance as ``` instance : CompleteLattice my_T where inf := better_inf le_inf := ... inf_le_right := ... inf_le_left := ... -- don't care to fix sup, sInf, bot, top __ := completeLatticeOfSup my_T _ ``` -/ def completeLatticeOfSup (α : Type*) [H1 : PartialOrder α] [H2 : SupSet α] (isLUB_sSup : ∀ s : Set α, IsLUB s (sSup s)) : CompleteLattice α where __ := H1; __ := H2 top := sSup univ le_top x := (isLUB_sSup univ).1 trivial bot := sSup ∅ bot_le x := (isLUB_sSup ∅).2 <| by simp sup a b := sSup {a, b} sup_le a b c hac hbc := (isLUB_sSup _).2 (by simp [*]) le_sup_left a b := (isLUB_sSup _).1 <| mem_insert _ _ le_sup_right a b := (isLUB_sSup _).1 <| mem_insert_of_mem _ <| mem_singleton _ inf a b := sSup { x | x ≤ a ∧ x ≤ b } le_inf a b c hab hac := (isLUB_sSup _).1 <| by simp [*] inf_le_left a b := (isLUB_sSup _).2 fun x => And.left inf_le_right a b := (isLUB_sSup _).2 fun x => And.right sInf s := sSup (lowerBounds s) sSup_le s a ha := (isLUB_sSup s).2 ha le_sSup s a ha := (isLUB_sSup s).1 ha sInf_le s a ha := (isLUB_sSup (lowerBounds s)).2 fun b hb => hb ha le_sInf s a ha := (isLUB_sSup (lowerBounds s)).1 ha #align complete_lattice_of_Sup completeLatticeOfSup /-- Any `CompleteSemilatticeSup` is in fact a `CompleteLattice`. Note that this construction has bad definitional properties: see the doc-string on `completeLatticeOfSup`. -/ def completeLatticeOfCompleteSemilatticeSup (α : Type*) [CompleteSemilatticeSup α] : CompleteLattice α := completeLatticeOfSup α fun s => isLUB_sSup s #align complete_lattice_of_complete_semilattice_Sup completeLatticeOfCompleteSemilatticeSup -- Porting note: as we cannot rename fields while extending, -- `CompleteLinearOrder` does not directly extend `LinearOrder`. -- Instead we add the fields by hand, and write a manual instance. /-- A complete linear order is a linear order whose lattice structure is complete. -/ class CompleteLinearOrder (α : Type*) extends CompleteLattice α where /-- A linear order is total. -/ le_total (a b : α) : a ≤ b ∨ b ≤ a /-- In a linearly ordered type, we assume the order relations are all decidable. -/ decidableLE : DecidableRel (· ≤ · : α → α → Prop) /-- In a linearly ordered type, we assume the order relations are all decidable. -/ decidableEq : DecidableEq α := @decidableEqOfDecidableLE _ _ decidableLE /-- In a linearly ordered type, we assume the order relations are all decidable. -/ decidableLT : DecidableRel (· < · : α → α → Prop) := @decidableLTOfDecidableLE _ _ decidableLE #align complete_linear_order CompleteLinearOrder instance CompleteLinearOrder.toLinearOrder [i : CompleteLinearOrder α] : LinearOrder α where __ := i min := Inf.inf max := Sup.sup min_def a b := by split_ifs with h · simp [h] · simp [(CompleteLinearOrder.le_total a b).resolve_left h] max_def a b := by split_ifs with h · simp [h] · simp [(CompleteLinearOrder.le_total a b).resolve_left h] namespace OrderDual instance instCompleteLattice [CompleteLattice α] : CompleteLattice αᵒᵈ where __ := instBoundedOrder α le_sSup := @CompleteLattice.sInf_le α _ sSup_le := @CompleteLattice.le_sInf α _ sInf_le := @CompleteLattice.le_sSup α _ le_sInf := @CompleteLattice.sSup_le α _ instance instCompleteLinearOrder [CompleteLinearOrder α] : CompleteLinearOrder αᵒᵈ where __ := instCompleteLattice __ := instLinearOrder α end OrderDual open OrderDual section variable [CompleteLattice α] {s t : Set α} {a b : α} @[simp] theorem toDual_sSup (s : Set α) : toDual (sSup s) = sInf (ofDual ⁻¹' s) := rfl #align to_dual_Sup toDual_sSup @[simp] theorem toDual_sInf (s : Set α) : toDual (sInf s) = sSup (ofDual ⁻¹' s) := rfl #align to_dual_Inf toDual_sInf @[simp] theorem ofDual_sSup (s : Set αᵒᵈ) : ofDual (sSup s) = sInf (toDual ⁻¹' s) := rfl #align of_dual_Sup ofDual_sSup @[simp] theorem ofDual_sInf (s : Set αᵒᵈ) : ofDual (sInf s) = sSup (toDual ⁻¹' s) := rfl #align of_dual_Inf ofDual_sInf @[simp] theorem toDual_iSup (f : ι → α) : toDual (⨆ i, f i) = ⨅ i, toDual (f i) := rfl #align to_dual_supr toDual_iSup @[simp] theorem toDual_iInf (f : ι → α) : toDual (⨅ i, f i) = ⨆ i, toDual (f i) := rfl #align to_dual_infi toDual_iInf @[simp] theorem ofDual_iSup (f : ι → αᵒᵈ) : ofDual (⨆ i, f i) = ⨅ i, ofDual (f i) := rfl #align of_dual_supr ofDual_iSup @[simp] theorem ofDual_iInf (f : ι → αᵒᵈ) : ofDual (⨅ i, f i) = ⨆ i, ofDual (f i) := rfl #align of_dual_infi ofDual_iInf theorem sInf_le_sSup (hs : s.Nonempty) : sInf s ≤ sSup s := isGLB_le_isLUB (isGLB_sInf s) (isLUB_sSup s) hs #align Inf_le_Sup sInf_le_sSup theorem sSup_union {s t : Set α} : sSup (s ∪ t) = sSup s ⊔ sSup t := ((isLUB_sSup s).union (isLUB_sSup t)).sSup_eq #align Sup_union sSup_union theorem sInf_union {s t : Set α} : sInf (s ∪ t) = sInf s ⊓ sInf t := ((isGLB_sInf s).union (isGLB_sInf t)).sInf_eq #align Inf_union sInf_union theorem sSup_inter_le {s t : Set α} : sSup (s ∩ t) ≤ sSup s ⊓ sSup t := sSup_le fun _ hb => le_inf (le_sSup hb.1) (le_sSup hb.2) #align Sup_inter_le sSup_inter_le theorem le_sInf_inter {s t : Set α} : sInf s ⊔ sInf t ≤ sInf (s ∩ t) := @sSup_inter_le αᵒᵈ _ _ _ #align le_Inf_inter le_sInf_inter @[simp] theorem sSup_empty : sSup ∅ = (⊥ : α) := (@isLUB_empty α _ _).sSup_eq #align Sup_empty sSup_empty @[simp] theorem sInf_empty : sInf ∅ = (⊤ : α) := (@isGLB_empty α _ _).sInf_eq #align Inf_empty sInf_empty @[simp] theorem sSup_univ : sSup univ = (⊤ : α) := (@isLUB_univ α _ _).sSup_eq #align Sup_univ sSup_univ @[simp] theorem sInf_univ : sInf univ = (⊥ : α) := (@isGLB_univ α _ _).sInf_eq #align Inf_univ sInf_univ -- TODO(Jeremy): get this automatically @[simp] theorem sSup_insert {a : α} {s : Set α} : sSup (insert a s) = a ⊔ sSup s := ((isLUB_sSup s).insert a).sSup_eq #align Sup_insert sSup_insert @[simp] theorem sInf_insert {a : α} {s : Set α} : sInf (insert a s) = a ⊓ sInf s := ((isGLB_sInf s).insert a).sInf_eq #align Inf_insert sInf_insert theorem sSup_le_sSup_of_subset_insert_bot (h : s ⊆ insert ⊥ t) : sSup s ≤ sSup t := (sSup_le_sSup h).trans_eq (sSup_insert.trans (bot_sup_eq _)) #align Sup_le_Sup_of_subset_insert_bot sSup_le_sSup_of_subset_insert_bot theorem sInf_le_sInf_of_subset_insert_top (h : s ⊆ insert ⊤ t) : sInf t ≤ sInf s := (sInf_le_sInf h).trans_eq' (sInf_insert.trans (top_inf_eq _)).symm #align Inf_le_Inf_of_subset_insert_top sInf_le_sInf_of_subset_insert_top @[simp] theorem sSup_diff_singleton_bot (s : Set α) : sSup (s \ {⊥}) = sSup s := (sSup_le_sSup diff_subset).antisymm <| sSup_le_sSup_of_subset_insert_bot <| subset_insert_diff_singleton _ _ #align Sup_diff_singleton_bot sSup_diff_singleton_bot @[simp] theorem sInf_diff_singleton_top (s : Set α) : sInf (s \ {⊤}) = sInf s := @sSup_diff_singleton_bot αᵒᵈ _ s #align Inf_diff_singleton_top sInf_diff_singleton_top theorem sSup_pair {a b : α} : sSup {a, b} = a ⊔ b := (@isLUB_pair α _ a b).sSup_eq #align Sup_pair sSup_pair theorem sInf_pair {a b : α} : sInf {a, b} = a ⊓ b := (@isGLB_pair α _ a b).sInf_eq #align Inf_pair sInf_pair @[simp] theorem sSup_eq_bot : sSup s = ⊥ ↔ ∀ a ∈ s, a = ⊥ := ⟨fun h _ ha => bot_unique <| h ▸ le_sSup ha, fun h => bot_unique <| sSup_le fun a ha => le_bot_iff.2 <| h a ha⟩ #align Sup_eq_bot sSup_eq_bot @[simp] theorem sInf_eq_top : sInf s = ⊤ ↔ ∀ a ∈ s, a = ⊤ := @sSup_eq_bot αᵒᵈ _ _ #align Inf_eq_top sInf_eq_top theorem eq_singleton_bot_of_sSup_eq_bot_of_nonempty {s : Set α} (h_sup : sSup s = ⊥) (hne : s.Nonempty) : s = {⊥} := by rw [Set.eq_singleton_iff_nonempty_unique_mem] rw [sSup_eq_bot] at h_sup exact ⟨hne, h_sup⟩ #align eq_singleton_bot_of_Sup_eq_bot_of_nonempty eq_singleton_bot_of_sSup_eq_bot_of_nonempty theorem eq_singleton_top_of_sInf_eq_top_of_nonempty : sInf s = ⊤ → s.Nonempty → s = {⊤} := @eq_singleton_bot_of_sSup_eq_bot_of_nonempty αᵒᵈ _ _ #align eq_singleton_top_of_Inf_eq_top_of_nonempty eq_singleton_top_of_sInf_eq_top_of_nonempty /-- Introduction rule to prove that `b` is the supremum of `s`: it suffices to check that `b` is larger than all elements of `s`, and that this is not the case of any `w < b`. See `csSup_eq_of_forall_le_of_forall_lt_exists_gt` for a version in conditionally complete lattices. -/ theorem sSup_eq_of_forall_le_of_forall_lt_exists_gt (h₁ : ∀ a ∈ s, a ≤ b) (h₂ : ∀ w, w < b → ∃ a ∈ s, w < a) : sSup s = b := (sSup_le h₁).eq_of_not_lt fun h => let ⟨_, ha, ha'⟩ := h₂ _ h ((le_sSup ha).trans_lt ha').false #align Sup_eq_of_forall_le_of_forall_lt_exists_gt sSup_eq_of_forall_le_of_forall_lt_exists_gt /-- Introduction rule to prove that `b` is the infimum of `s`: it suffices to check that `b` is smaller than all elements of `s`, and that this is not the case of any `w > b`. See `csInf_eq_of_forall_ge_of_forall_gt_exists_lt` for a version in conditionally complete lattices. -/ theorem sInf_eq_of_forall_ge_of_forall_gt_exists_lt : (∀ a ∈ s, b ≤ a) → (∀ w, b < w → ∃ a ∈ s, a < w) → sInf s = b := @sSup_eq_of_forall_le_of_forall_lt_exists_gt αᵒᵈ _ _ _ #align Inf_eq_of_forall_ge_of_forall_gt_exists_lt sInf_eq_of_forall_ge_of_forall_gt_exists_lt end section CompleteLinearOrder variable [CompleteLinearOrder α] {s t : Set α} {a b : α} theorem lt_sSup_iff : b < sSup s ↔ ∃ a ∈ s, b < a := lt_isLUB_iff <| isLUB_sSup s #align lt_Sup_iff lt_sSup_iff theorem sInf_lt_iff : sInf s < b ↔ ∃ a ∈ s, a < b := isGLB_lt_iff <| isGLB_sInf s #align Inf_lt_iff sInf_lt_iff theorem sSup_eq_top : sSup s = ⊤ ↔ ∀ b < ⊤, ∃ a ∈ s, b < a := ⟨fun h _ hb => lt_sSup_iff.1 <| hb.trans_eq h.symm, fun h => top_unique <| le_of_not_gt fun h' => let ⟨_, ha, h⟩ := h _ h' (h.trans_le <| le_sSup ha).false⟩ #align Sup_eq_top sSup_eq_top theorem sInf_eq_bot : sInf s = ⊥ ↔ ∀ b > ⊥, ∃ a ∈ s, a < b := @sSup_eq_top αᵒᵈ _ _ #align Inf_eq_bot sInf_eq_bot theorem lt_iSup_iff {f : ι → α} : a < iSup f ↔ ∃ i, a < f i := lt_sSup_iff.trans exists_range_iff #align lt_supr_iff lt_iSup_iff theorem iInf_lt_iff {f : ι → α} : iInf f < a ↔ ∃ i, f i < a := sInf_lt_iff.trans exists_range_iff #align infi_lt_iff iInf_lt_iff end CompleteLinearOrder /- ### iSup & iInf -/ section SupSet variable [SupSet α] {f g : ι → α} theorem sSup_range : sSup (range f) = iSup f := rfl #align Sup_range sSup_range theorem sSup_eq_iSup' (s : Set α) : sSup s = ⨆ a : s, (a : α) := by rw [iSup, Subtype.range_coe] #align Sup_eq_supr' sSup_eq_iSup' theorem iSup_congr (h : ∀ i, f i = g i) : ⨆ i, f i = ⨆ i, g i := congr_arg _ <| funext h #align supr_congr iSup_congr theorem biSup_congr {p : ι → Prop} (h : ∀ i, p i → f i = g i) : ⨆ (i) (_ : p i), f i = ⨆ (i) (_ : p i), g i := iSup_congr fun i ↦ iSup_congr (h i) theorem biSup_congr' {p : ι → Prop} {f g : (i : ι) → p i → α} (h : ∀ i (hi : p i), f i hi = g i hi) : ⨆ i, ⨆ (hi : p i), f i hi = ⨆ i, ⨆ (hi : p i), g i hi := by congr; ext i; congr; ext hi; exact h i hi theorem Function.Surjective.iSup_comp {f : ι → ι'} (hf : Surjective f) (g : ι' → α) : ⨆ x, g (f x) = ⨆ y, g y := by simp only [iSup.eq_1] congr exact hf.range_comp g #align function.surjective.supr_comp Function.Surjective.iSup_comp theorem Equiv.iSup_comp {g : ι' → α} (e : ι ≃ ι') : ⨆ x, g (e x) = ⨆ y, g y := e.surjective.iSup_comp _ #align equiv.supr_comp Equiv.iSup_comp protected theorem Function.Surjective.iSup_congr {g : ι' → α} (h : ι → ι') (h1 : Surjective h) (h2 : ∀ x, g (h x) = f x) : ⨆ x, f x = ⨆ y, g y := by convert h1.iSup_comp g exact (h2 _).symm #align function.surjective.supr_congr Function.Surjective.iSup_congr protected theorem Equiv.iSup_congr {g : ι' → α} (e : ι ≃ ι') (h : ∀ x, g (e x) = f x) : ⨆ x, f x = ⨆ y, g y := e.surjective.iSup_congr _ h #align equiv.supr_congr Equiv.iSup_congr @[congr] theorem iSup_congr_Prop {p q : Prop} {f₁ : p → α} {f₂ : q → α} (pq : p ↔ q) (f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iSup f₁ = iSup f₂ := by obtain rfl := propext pq congr with x apply f #align supr_congr_Prop iSup_congr_Prop theorem iSup_plift_up (f : PLift ι → α) : ⨆ i, f (PLift.up i) = ⨆ i, f i := (PLift.up_surjective.iSup_congr _) fun _ => rfl #align supr_plift_up iSup_plift_up theorem iSup_plift_down (f : ι → α) : ⨆ i, f (PLift.down i) = ⨆ i, f i := (PLift.down_surjective.iSup_congr _) fun _ => rfl #align supr_plift_down iSup_plift_down theorem iSup_range' (g : β → α) (f : ι → β) : ⨆ b : range f, g b = ⨆ i, g (f i) := by rw [iSup, iSup, ← image_eq_range, ← range_comp] rfl #align supr_range' iSup_range' theorem sSup_image' {s : Set β} {f : β → α} : sSup (f '' s) = ⨆ a : s, f a := by rw [iSup, image_eq_range] #align Sup_image' sSup_image' end SupSet section InfSet variable [InfSet α] {f g : ι → α} theorem sInf_range : sInf (range f) = iInf f := rfl #align Inf_range sInf_range theorem sInf_eq_iInf' (s : Set α) : sInf s = ⨅ a : s, (a : α) := @sSup_eq_iSup' αᵒᵈ _ _ #align Inf_eq_infi' sInf_eq_iInf' theorem iInf_congr (h : ∀ i, f i = g i) : ⨅ i, f i = ⨅ i, g i := congr_arg _ <| funext h #align infi_congr iInf_congr theorem biInf_congr {p : ι → Prop} (h : ∀ i, p i → f i = g i) : ⨅ (i) (_ : p i), f i = ⨅ (i) (_ : p i), g i := biSup_congr (α := αᵒᵈ) h theorem biInf_congr' {p : ι → Prop} {f g : (i : ι) → p i → α} (h : ∀ i (hi : p i), f i hi = g i hi) : ⨅ i, ⨅ (hi : p i), f i hi = ⨅ i, ⨅ (hi : p i), g i hi := by congr; ext i; congr; ext hi; exact h i hi theorem Function.Surjective.iInf_comp {f : ι → ι'} (hf : Surjective f) (g : ι' → α) : ⨅ x, g (f x) = ⨅ y, g y := @Function.Surjective.iSup_comp αᵒᵈ _ _ _ f hf g #align function.surjective.infi_comp Function.Surjective.iInf_comp theorem Equiv.iInf_comp {g : ι' → α} (e : ι ≃ ι') : ⨅ x, g (e x) = ⨅ y, g y := @Equiv.iSup_comp αᵒᵈ _ _ _ _ e #align equiv.infi_comp Equiv.iInf_comp protected theorem Function.Surjective.iInf_congr {g : ι' → α} (h : ι → ι') (h1 : Surjective h) (h2 : ∀ x, g (h x) = f x) : ⨅ x, f x = ⨅ y, g y := @Function.Surjective.iSup_congr αᵒᵈ _ _ _ _ _ h h1 h2 #align function.surjective.infi_congr Function.Surjective.iInf_congr protected theorem Equiv.iInf_congr {g : ι' → α} (e : ι ≃ ι') (h : ∀ x, g (e x) = f x) : ⨅ x, f x = ⨅ y, g y := @Equiv.iSup_congr αᵒᵈ _ _ _ _ _ e h #align equiv.infi_congr Equiv.iInf_congr @[congr] theorem iInf_congr_Prop {p q : Prop} {f₁ : p → α} {f₂ : q → α} (pq : p ↔ q) (f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iInf f₁ = iInf f₂ := @iSup_congr_Prop αᵒᵈ _ p q f₁ f₂ pq f #align infi_congr_Prop iInf_congr_Prop theorem iInf_plift_up (f : PLift ι → α) : ⨅ i, f (PLift.up i) = ⨅ i, f i := (PLift.up_surjective.iInf_congr _) fun _ => rfl #align infi_plift_up iInf_plift_up theorem iInf_plift_down (f : ι → α) : ⨅ i, f (PLift.down i) = ⨅ i, f i := (PLift.down_surjective.iInf_congr _) fun _ => rfl #align infi_plift_down iInf_plift_down theorem iInf_range' (g : β → α) (f : ι → β) : ⨅ b : range f, g b = ⨅ i, g (f i) := @iSup_range' αᵒᵈ _ _ _ _ _ #align infi_range' iInf_range' theorem sInf_image' {s : Set β} {f : β → α} : sInf (f '' s) = ⨅ a : s, f a := @sSup_image' αᵒᵈ _ _ _ _ #align Inf_image' sInf_image' end InfSet section variable [CompleteLattice α] {f g s t : ι → α} {a b : α} theorem le_iSup (f : ι → α) (i : ι) : f i ≤ iSup f := le_sSup ⟨i, rfl⟩ #align le_supr le_iSup theorem iInf_le (f : ι → α) (i : ι) : iInf f ≤ f i := sInf_le ⟨i, rfl⟩ #align infi_le iInf_le theorem le_iSup' (f : ι → α) (i : ι) : f i ≤ iSup f := le_sSup ⟨i, rfl⟩ #align le_supr' le_iSup' theorem iInf_le' (f : ι → α) (i : ι) : iInf f ≤ f i := sInf_le ⟨i, rfl⟩ #align infi_le' iInf_le' theorem isLUB_iSup : IsLUB (range f) (⨆ j, f j) := isLUB_sSup _ #align is_lub_supr isLUB_iSup theorem isGLB_iInf : IsGLB (range f) (⨅ j, f j) := isGLB_sInf _ #align is_glb_infi isGLB_iInf theorem IsLUB.iSup_eq (h : IsLUB (range f) a) : ⨆ j, f j = a := h.sSup_eq #align is_lub.supr_eq IsLUB.iSup_eq theorem IsGLB.iInf_eq (h : IsGLB (range f) a) : ⨅ j, f j = a := h.sInf_eq #align is_glb.infi_eq IsGLB.iInf_eq theorem le_iSup_of_le (i : ι) (h : a ≤ f i) : a ≤ iSup f := h.trans <| le_iSup _ i #align le_supr_of_le le_iSup_of_le theorem iInf_le_of_le (i : ι) (h : f i ≤ a) : iInf f ≤ a := (iInf_le _ i).trans h #align infi_le_of_le iInf_le_of_le theorem le_iSup₂ {f : ∀ i, κ i → α} (i : ι) (j : κ i) : f i j ≤ ⨆ (i) (j), f i j := le_iSup_of_le i <| le_iSup (f i) j #align le_supr₂ le_iSup₂ theorem iInf₂_le {f : ∀ i, κ i → α} (i : ι) (j : κ i) : ⨅ (i) (j), f i j ≤ f i j := iInf_le_of_le i <| iInf_le (f i) j #align infi₂_le iInf₂_le theorem le_iSup₂_of_le {f : ∀ i, κ i → α} (i : ι) (j : κ i) (h : a ≤ f i j) : a ≤ ⨆ (i) (j), f i j := h.trans <| le_iSup₂ i j #align le_supr₂_of_le le_iSup₂_of_le theorem iInf₂_le_of_le {f : ∀ i, κ i → α} (i : ι) (j : κ i) (h : f i j ≤ a) : ⨅ (i) (j), f i j ≤ a := (iInf₂_le i j).trans h #align infi₂_le_of_le iInf₂_le_of_le theorem iSup_le (h : ∀ i, f i ≤ a) : iSup f ≤ a := sSup_le fun _ ⟨i, Eq⟩ => Eq ▸ h i #align supr_le iSup_le theorem le_iInf (h : ∀ i, a ≤ f i) : a ≤ iInf f := le_sInf fun _ ⟨i, Eq⟩ => Eq ▸ h i #align le_infi le_iInf theorem iSup₂_le {f : ∀ i, κ i → α} (h : ∀ i j, f i j ≤ a) : ⨆ (i) (j), f i j ≤ a := iSup_le fun i => iSup_le <| h i #align supr₂_le iSup₂_le theorem le_iInf₂ {f : ∀ i, κ i → α} (h : ∀ i j, a ≤ f i j) : a ≤ ⨅ (i) (j), f i j := le_iInf fun i => le_iInf <| h i #align le_infi₂ le_iInf₂ theorem iSup₂_le_iSup (κ : ι → Sort*) (f : ι → α) : ⨆ (i) (_ : κ i), f i ≤ ⨆ i, f i := iSup₂_le fun i _ => le_iSup f i #align supr₂_le_supr iSup₂_le_iSup theorem iInf_le_iInf₂ (κ : ι → Sort*) (f : ι → α) : ⨅ i, f i ≤ ⨅ (i) (_ : κ i), f i := le_iInf₂ fun i _ => iInf_le f i #align infi_le_infi₂ iInf_le_iInf₂ @[gcongr] theorem iSup_mono (h : ∀ i, f i ≤ g i) : iSup f ≤ iSup g := iSup_le fun i => le_iSup_of_le i <| h i #align supr_mono iSup_mono @[gcongr] theorem iInf_mono (h : ∀ i, f i ≤ g i) : iInf f ≤ iInf g := le_iInf fun i => iInf_le_of_le i <| h i #align infi_mono iInf_mono theorem iSup₂_mono {f g : ∀ i, κ i → α} (h : ∀ i j, f i j ≤ g i j) : ⨆ (i) (j), f i j ≤ ⨆ (i) (j), g i j := iSup_mono fun i => iSup_mono <| h i #align supr₂_mono iSup₂_mono theorem iInf₂_mono {f g : ∀ i, κ i → α} (h : ∀ i j, f i j ≤ g i j) : ⨅ (i) (j), f i j ≤ ⨅ (i) (j), g i j := iInf_mono fun i => iInf_mono <| h i #align infi₂_mono iInf₂_mono theorem iSup_mono' {g : ι' → α} (h : ∀ i, ∃ i', f i ≤ g i') : iSup f ≤ iSup g := iSup_le fun i => Exists.elim (h i) le_iSup_of_le #align supr_mono' iSup_mono' theorem iInf_mono' {g : ι' → α} (h : ∀ i', ∃ i, f i ≤ g i') : iInf f ≤ iInf g := le_iInf fun i' => Exists.elim (h i') iInf_le_of_le #align infi_mono' iInf_mono' theorem iSup₂_mono' {f : ∀ i, κ i → α} {g : ∀ i', κ' i' → α} (h : ∀ i j, ∃ i' j', f i j ≤ g i' j') : ⨆ (i) (j), f i j ≤ ⨆ (i) (j), g i j := iSup₂_le fun i j => let ⟨i', j', h⟩ := h i j le_iSup₂_of_le i' j' h #align supr₂_mono' iSup₂_mono' theorem iInf₂_mono' {f : ∀ i, κ i → α} {g : ∀ i', κ' i' → α} (h : ∀ i j, ∃ i' j', f i' j' ≤ g i j) : ⨅ (i) (j), f i j ≤ ⨅ (i) (j), g i j := le_iInf₂ fun i j => let ⟨i', j', h⟩ := h i j iInf₂_le_of_le i' j' h #align infi₂_mono' iInf₂_mono' theorem iSup_const_mono (h : ι → ι') : ⨆ _ : ι, a ≤ ⨆ _ : ι', a := iSup_le <| le_iSup _ ∘ h #align supr_const_mono iSup_const_mono theorem iInf_const_mono (h : ι' → ι) : ⨅ _ : ι, a ≤ ⨅ _ : ι', a := le_iInf <| iInf_le _ ∘ h #align infi_const_mono iInf_const_mono theorem iSup_iInf_le_iInf_iSup (f : ι → ι' → α) : ⨆ i, ⨅ j, f i j ≤ ⨅ j, ⨆ i, f i j := iSup_le fun i => iInf_mono fun j => le_iSup (fun i => f i j) i #align supr_infi_le_infi_supr iSup_iInf_le_iInf_iSup theorem biSup_mono {p q : ι → Prop} (hpq : ∀ i, p i → q i) : ⨆ (i) (_ : p i), f i ≤ ⨆ (i) (_ : q i), f i := iSup_mono fun i => iSup_const_mono (hpq i) #align bsupr_mono biSup_mono theorem biInf_mono {p q : ι → Prop} (hpq : ∀ i, p i → q i) : ⨅ (i) (_ : q i), f i ≤ ⨅ (i) (_ : p i), f i := iInf_mono fun i => iInf_const_mono (hpq i) #align binfi_mono biInf_mono @[simp] theorem iSup_le_iff : iSup f ≤ a ↔ ∀ i, f i ≤ a := (isLUB_le_iff isLUB_iSup).trans forall_mem_range #align supr_le_iff iSup_le_iff @[simp] theorem le_iInf_iff : a ≤ iInf f ↔ ∀ i, a ≤ f i := (le_isGLB_iff isGLB_iInf).trans forall_mem_range #align le_infi_iff le_iInf_iff theorem iSup₂_le_iff {f : ∀ i, κ i → α} : ⨆ (i) (j), f i j ≤ a ↔ ∀ i j, f i j ≤ a := by simp_rw [iSup_le_iff] #align supr₂_le_iff iSup₂_le_iff theorem le_iInf₂_iff {f : ∀ i, κ i → α} : (a ≤ ⨅ (i) (j), f i j) ↔ ∀ i j, a ≤ f i j := by simp_rw [le_iInf_iff] #align le_infi₂_iff le_iInf₂_iff theorem iSup_lt_iff : iSup f < a ↔ ∃ b, b < a ∧ ∀ i, f i ≤ b := ⟨fun h => ⟨iSup f, h, le_iSup f⟩, fun ⟨_, h, hb⟩ => (iSup_le hb).trans_lt h⟩ #align supr_lt_iff iSup_lt_iff theorem lt_iInf_iff : a < iInf f ↔ ∃ b, a < b ∧ ∀ i, b ≤ f i := ⟨fun h => ⟨iInf f, h, iInf_le f⟩, fun ⟨_, h, hb⟩ => h.trans_le <| le_iInf hb⟩ #align lt_infi_iff lt_iInf_iff theorem sSup_eq_iSup {s : Set α} : sSup s = ⨆ a ∈ s, a := le_antisymm (sSup_le le_iSup₂) (iSup₂_le fun _ => le_sSup) #align Sup_eq_supr sSup_eq_iSup theorem sInf_eq_iInf {s : Set α} : sInf s = ⨅ a ∈ s, a := @sSup_eq_iSup αᵒᵈ _ _ #align Inf_eq_infi sInf_eq_iInf theorem Monotone.le_map_iSup [CompleteLattice β] {f : α → β} (hf : Monotone f) : ⨆ i, f (s i) ≤ f (iSup s) := iSup_le fun _ => hf <| le_iSup _ _ #align monotone.le_map_supr Monotone.le_map_iSup theorem Antitone.le_map_iInf [CompleteLattice β] {f : α → β} (hf : Antitone f) : ⨆ i, f (s i) ≤ f (iInf s) := hf.dual_left.le_map_iSup #align antitone.le_map_infi Antitone.le_map_iInf theorem Monotone.le_map_iSup₂ [CompleteLattice β] {f : α → β} (hf : Monotone f) (s : ∀ i, κ i → α) : ⨆ (i) (j), f (s i j) ≤ f (⨆ (i) (j), s i j) := iSup₂_le fun _ _ => hf <| le_iSup₂ _ _ #align monotone.le_map_supr₂ Monotone.le_map_iSup₂ theorem Antitone.le_map_iInf₂ [CompleteLattice β] {f : α → β} (hf : Antitone f) (s : ∀ i, κ i → α) : ⨆ (i) (j), f (s i j) ≤ f (⨅ (i) (j), s i j) := hf.dual_left.le_map_iSup₂ _ #align antitone.le_map_infi₂ Antitone.le_map_iInf₂ theorem Monotone.le_map_sSup [CompleteLattice β] {s : Set α} {f : α → β} (hf : Monotone f) : ⨆ a ∈ s, f a ≤ f (sSup s) := by rw [sSup_eq_iSup]; exact hf.le_map_iSup₂ _ #align monotone.le_map_Sup Monotone.le_map_sSup theorem Antitone.le_map_sInf [CompleteLattice β] {s : Set α} {f : α → β} (hf : Antitone f) : ⨆ a ∈ s, f a ≤ f (sInf s) := hf.dual_left.le_map_sSup #align antitone.le_map_Inf Antitone.le_map_sInf theorem OrderIso.map_iSup [CompleteLattice β] (f : α ≃o β) (x : ι → α) : f (⨆ i, x i) = ⨆ i, f (x i) := eq_of_forall_ge_iff <| f.surjective.forall.2 fun x => by simp only [f.le_iff_le, iSup_le_iff] #align order_iso.map_supr OrderIso.map_iSup theorem OrderIso.map_iInf [CompleteLattice β] (f : α ≃o β) (x : ι → α) : f (⨅ i, x i) = ⨅ i, f (x i) := OrderIso.map_iSup f.dual _ #align order_iso.map_infi OrderIso.map_iInf theorem OrderIso.map_sSup [CompleteLattice β] (f : α ≃o β) (s : Set α) : f (sSup s) = ⨆ a ∈ s, f a := by simp only [sSup_eq_iSup, OrderIso.map_iSup] #align order_iso.map_Sup OrderIso.map_sSup theorem OrderIso.map_sInf [CompleteLattice β] (f : α ≃o β) (s : Set α) : f (sInf s) = ⨅ a ∈ s, f a := OrderIso.map_sSup f.dual _ #align order_iso.map_Inf OrderIso.map_sInf theorem iSup_comp_le {ι' : Sort*} (f : ι' → α) (g : ι → ι') : ⨆ x, f (g x) ≤ ⨆ y, f y := iSup_mono' fun _ => ⟨_, le_rfl⟩ #align supr_comp_le iSup_comp_le theorem le_iInf_comp {ι' : Sort*} (f : ι' → α) (g : ι → ι') : ⨅ y, f y ≤ ⨅ x, f (g x) := iInf_mono' fun _ => ⟨_, le_rfl⟩ #align le_infi_comp le_iInf_comp theorem Monotone.iSup_comp_eq [Preorder β] {f : β → α} (hf : Monotone f) {s : ι → β} (hs : ∀ x, ∃ i, x ≤ s i) : ⨆ x, f (s x) = ⨆ y, f y := le_antisymm (iSup_comp_le _ _) (iSup_mono' fun x => (hs x).imp fun _ hi => hf hi) #align monotone.supr_comp_eq Monotone.iSup_comp_eq theorem Monotone.iInf_comp_eq [Preorder β] {f : β → α} (hf : Monotone f) {s : ι → β} (hs : ∀ x, ∃ i, s i ≤ x) : ⨅ x, f (s x) = ⨅ y, f y := le_antisymm (iInf_mono' fun x => (hs x).imp fun _ hi => hf hi) (le_iInf_comp _ _) #align monotone.infi_comp_eq Monotone.iInf_comp_eq theorem Antitone.map_iSup_le [CompleteLattice β] {f : α → β} (hf : Antitone f) : f (iSup s) ≤ ⨅ i, f (s i) := le_iInf fun _ => hf <| le_iSup _ _ #align antitone.map_supr_le Antitone.map_iSup_le theorem Monotone.map_iInf_le [CompleteLattice β] {f : α → β} (hf : Monotone f) : f (iInf s) ≤ ⨅ i, f (s i) := hf.dual_left.map_iSup_le #align monotone.map_infi_le Monotone.map_iInf_le theorem Antitone.map_iSup₂_le [CompleteLattice β] {f : α → β} (hf : Antitone f) (s : ∀ i, κ i → α) : f (⨆ (i) (j), s i j) ≤ ⨅ (i) (j), f (s i j) := hf.dual.le_map_iInf₂ _ #align antitone.map_supr₂_le Antitone.map_iSup₂_le theorem Monotone.map_iInf₂_le [CompleteLattice β] {f : α → β} (hf : Monotone f) (s : ∀ i, κ i → α) : f (⨅ (i) (j), s i j) ≤ ⨅ (i) (j), f (s i j) := hf.dual.le_map_iSup₂ _ #align monotone.map_infi₂_le Monotone.map_iInf₂_le
Mathlib/Order/CompleteLattice.lean
969
972
theorem Antitone.map_sSup_le [CompleteLattice β] {s : Set α} {f : α → β} (hf : Antitone f) : f (sSup s) ≤ ⨅ a ∈ s, f a := by
rw [sSup_eq_iSup] exact hf.map_iSup₂_le _
/- Copyright (c) 2022 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.Analysis.Calculus.ContDiff.Basic import Mathlib.Analysis.Calculus.ParametricIntegral import Mathlib.MeasureTheory.Constructions.Prod.Integral import Mathlib.MeasureTheory.Function.LocallyIntegrable import Mathlib.MeasureTheory.Group.Integral import Mathlib.MeasureTheory.Group.Prod import Mathlib.MeasureTheory.Integral.IntervalIntegral #align_import analysis.convolution from "leanprover-community/mathlib"@"8905e5ed90859939681a725b00f6063e65096d95" /-! # Convolution of functions This file defines the convolution on two functions, i.e. `x ↦ ∫ f(t)g(x - t) ∂t`. In the general case, these functions can be vector-valued, and have an arbitrary (additive) group as domain. We use a continuous bilinear operation `L` on these function values as "multiplication". The domain must be equipped with a Haar measure `μ` (though many individual results have weaker conditions on `μ`). For many applications we can take `L = ContinuousLinearMap.lsmul ℝ ℝ` or `L = ContinuousLinearMap.mul ℝ ℝ`. We also define `ConvolutionExists` and `ConvolutionExistsAt` to state that the convolution is well-defined (everywhere or at a single point). These conditions are needed for pointwise computations (e.g. `ConvolutionExistsAt.distrib_add`), but are generally not strong enough for any local (or global) properties of the convolution. For this we need stronger assumptions on `f` and/or `g`, and generally if we impose stronger conditions on one of the functions, we can impose weaker conditions on the other. We have proven many of the properties of the convolution assuming one of these functions has compact support (in which case the other function only needs to be locally integrable). We still need to prove the properties for other pairs of conditions (e.g. both functions are rapidly decreasing) # Design Decisions We use a bilinear map `L` to "multiply" the two functions in the integrand. This generality has several advantages * This allows us to compute the total derivative of the convolution, in case the functions are multivariate. The total derivative is again a convolution, but where the codomains of the functions can be higher-dimensional. See `HasCompactSupport.hasFDerivAt_convolution_right`. * This allows us to use `@[to_additive]` everywhere (which would not be possible if we would use `mul`/`smul` in the integral, since `@[to_additive]` will incorrectly also try to additivize those definitions). * We need to support the case where at least one of the functions is vector-valued, but if we use `smul` to multiply the functions, that would be an asymmetric definition. # Main Definitions * `convolution f g L μ x = (f ⋆[L, μ] g) x = ∫ t, L (f t) (g (x - t)) ∂μ` is the convolution of `f` and `g` w.r.t. the continuous bilinear map `L` and measure `μ`. * `ConvolutionExistsAt f g x L μ` states that the convolution `(f ⋆[L, μ] g) x` is well-defined (i.e. the integral exists). * `ConvolutionExists f g L μ` states that the convolution `f ⋆[L, μ] g` is well-defined at each point. # Main Results * `HasCompactSupport.hasFDerivAt_convolution_right` and `HasCompactSupport.hasFDerivAt_convolution_left`: we can compute the total derivative of the convolution as a convolution with the total derivative of the right (left) function. * `HasCompactSupport.contDiff_convolution_right` and `HasCompactSupport.contDiff_convolution_left`: the convolution is `𝒞ⁿ` if one of the functions is `𝒞ⁿ` with compact support and the other function in locally integrable. Versions of these statements for functions depending on a parameter are also given. * `convolution_tendsto_right`: Given a sequence of nonnegative normalized functions whose support tends to a small neighborhood around `0`, the convolution tends to the right argument. This is specialized to bump functions in `ContDiffBump.convolution_tendsto_right`. # Notation The following notations are localized in the locale `convolution`: * `f ⋆[L, μ] g` for the convolution. Note: you have to use parentheses to apply the convolution to an argument: `(f ⋆[L, μ] g) x`. * `f ⋆[L] g := f ⋆[L, volume] g` * `f ⋆ g := f ⋆[lsmul ℝ ℝ] g` # To do * Existence and (uniform) continuity of the convolution if one of the maps is in `ℒ^p` and the other in `ℒ^q` with `1 / p + 1 / q = 1`. This might require a generalization of `MeasureTheory.Memℒp.smul` where `smul` is generalized to a continuous bilinear map. (see e.g. [Fremlin, *Measure Theory* (volume 2)][fremlin_vol2], 255K) * The convolution is an `AEStronglyMeasurable` function (see e.g. [Fremlin, *Measure Theory* (volume 2)][fremlin_vol2], 255I). * Prove properties about the convolution if both functions are rapidly decreasing. * Use `@[to_additive]` everywhere (this likely requires changes in `to_additive`) -/ open Set Function Filter MeasureTheory MeasureTheory.Measure TopologicalSpace open ContinuousLinearMap Metric Bornology open scoped Pointwise Topology NNReal Filter universe u𝕜 uG uE uE' uE'' uF uF' uF'' uP variable {𝕜 : Type u𝕜} {G : Type uG} {E : Type uE} {E' : Type uE'} {E'' : Type uE''} {F : Type uF} {F' : Type uF'} {F'' : Type uF''} {P : Type uP} variable [NormedAddCommGroup E] [NormedAddCommGroup E'] [NormedAddCommGroup E''] [NormedAddCommGroup F] {f f' : G → E} {g g' : G → E'} {x x' : G} {y y' : E} namespace MeasureTheory section NontriviallyNormedField variable [NontriviallyNormedField 𝕜] variable [NormedSpace 𝕜 E] [NormedSpace 𝕜 E'] [NormedSpace 𝕜 E''] [NormedSpace 𝕜 F] variable (L : E →L[𝕜] E' →L[𝕜] F) section NoMeasurability variable [AddGroup G] [TopologicalSpace G] theorem convolution_integrand_bound_right_of_le_of_subset {C : ℝ} (hC : ∀ i, ‖g i‖ ≤ C) {x t : G} {s u : Set G} (hx : x ∈ s) (hu : -tsupport g + s ⊆ u) : ‖L (f t) (g (x - t))‖ ≤ u.indicator (fun t => ‖L‖ * ‖f t‖ * C) t := by -- Porting note: had to add `f := _` refine le_indicator (f := fun t ↦ ‖L (f t) (g (x - t))‖) (fun t _ => ?_) (fun t ht => ?_) t · apply_rules [L.le_of_opNorm₂_le_of_le, le_rfl] · have : x - t ∉ support g := by refine mt (fun hxt => hu ?_) ht refine ⟨_, Set.neg_mem_neg.mpr (subset_closure hxt), _, hx, ?_⟩ simp only [neg_sub, sub_add_cancel] simp only [nmem_support.mp this, (L _).map_zero, norm_zero, le_rfl] #align convolution_integrand_bound_right_of_le_of_subset MeasureTheory.convolution_integrand_bound_right_of_le_of_subset theorem _root_.HasCompactSupport.convolution_integrand_bound_right_of_subset (hcg : HasCompactSupport g) (hg : Continuous g) {x t : G} {s u : Set G} (hx : x ∈ s) (hu : -tsupport g + s ⊆ u) : ‖L (f t) (g (x - t))‖ ≤ u.indicator (fun t => ‖L‖ * ‖f t‖ * ⨆ i, ‖g i‖) t := by refine convolution_integrand_bound_right_of_le_of_subset _ (fun i => ?_) hx hu exact le_ciSup (hg.norm.bddAbove_range_of_hasCompactSupport hcg.norm) _ #align has_compact_support.convolution_integrand_bound_right_of_subset HasCompactSupport.convolution_integrand_bound_right_of_subset theorem _root_.HasCompactSupport.convolution_integrand_bound_right (hcg : HasCompactSupport g) (hg : Continuous g) {x t : G} {s : Set G} (hx : x ∈ s) : ‖L (f t) (g (x - t))‖ ≤ (-tsupport g + s).indicator (fun t => ‖L‖ * ‖f t‖ * ⨆ i, ‖g i‖) t := hcg.convolution_integrand_bound_right_of_subset L hg hx Subset.rfl #align has_compact_support.convolution_integrand_bound_right HasCompactSupport.convolution_integrand_bound_right theorem _root_.Continuous.convolution_integrand_fst [ContinuousSub G] (hg : Continuous g) (t : G) : Continuous fun x => L (f t) (g (x - t)) := L.continuous₂.comp₂ continuous_const <| hg.comp <| continuous_id.sub continuous_const #align continuous.convolution_integrand_fst Continuous.convolution_integrand_fst theorem _root_.HasCompactSupport.convolution_integrand_bound_left (hcf : HasCompactSupport f) (hf : Continuous f) {x t : G} {s : Set G} (hx : x ∈ s) : ‖L (f (x - t)) (g t)‖ ≤ (-tsupport f + s).indicator (fun t => (‖L‖ * ⨆ i, ‖f i‖) * ‖g t‖) t := by convert hcf.convolution_integrand_bound_right L.flip hf hx using 1 simp_rw [L.opNorm_flip, mul_right_comm] #align has_compact_support.convolution_integrand_bound_left HasCompactSupport.convolution_integrand_bound_left end NoMeasurability section Measurability variable [MeasurableSpace G] {μ ν : Measure G} /-- The convolution of `f` and `g` exists at `x` when the function `t ↦ L (f t) (g (x - t))` is integrable. There are various conditions on `f` and `g` to prove this. -/ def ConvolutionExistsAt [Sub G] (f : G → E) (g : G → E') (x : G) (L : E →L[𝕜] E' →L[𝕜] F) (μ : Measure G := by volume_tac) : Prop := Integrable (fun t => L (f t) (g (x - t))) μ #align convolution_exists_at MeasureTheory.ConvolutionExistsAt /-- The convolution of `f` and `g` exists when the function `t ↦ L (f t) (g (x - t))` is integrable for all `x : G`. There are various conditions on `f` and `g` to prove this. -/ def ConvolutionExists [Sub G] (f : G → E) (g : G → E') (L : E →L[𝕜] E' →L[𝕜] F) (μ : Measure G := by volume_tac) : Prop := ∀ x : G, ConvolutionExistsAt f g x L μ #align convolution_exists MeasureTheory.ConvolutionExists section ConvolutionExists variable {L} in theorem ConvolutionExistsAt.integrable [Sub G] {x : G} (h : ConvolutionExistsAt f g x L μ) : Integrable (fun t => L (f t) (g (x - t))) μ := h #align convolution_exists_at.integrable MeasureTheory.ConvolutionExistsAt.integrable section Group variable [AddGroup G] theorem AEStronglyMeasurable.convolution_integrand' [MeasurableAdd₂ G] [MeasurableNeg G] [SigmaFinite ν] (hf : AEStronglyMeasurable f ν) (hg : AEStronglyMeasurable g <| map (fun p : G × G => p.1 - p.2) (μ.prod ν)) : AEStronglyMeasurable (fun p : G × G => L (f p.2) (g (p.1 - p.2))) (μ.prod ν) := L.aestronglyMeasurable_comp₂ hf.snd <| hg.comp_measurable measurable_sub #align measure_theory.ae_strongly_measurable.convolution_integrand' MeasureTheory.AEStronglyMeasurable.convolution_integrand' section variable [MeasurableAdd G] [MeasurableNeg G] theorem AEStronglyMeasurable.convolution_integrand_snd' (hf : AEStronglyMeasurable f μ) {x : G} (hg : AEStronglyMeasurable g <| map (fun t => x - t) μ) : AEStronglyMeasurable (fun t => L (f t) (g (x - t))) μ := L.aestronglyMeasurable_comp₂ hf <| hg.comp_measurable <| measurable_id.const_sub x #align measure_theory.ae_strongly_measurable.convolution_integrand_snd' MeasureTheory.AEStronglyMeasurable.convolution_integrand_snd' theorem AEStronglyMeasurable.convolution_integrand_swap_snd' {x : G} (hf : AEStronglyMeasurable f <| map (fun t => x - t) μ) (hg : AEStronglyMeasurable g μ) : AEStronglyMeasurable (fun t => L (f (x - t)) (g t)) μ := L.aestronglyMeasurable_comp₂ (hf.comp_measurable <| measurable_id.const_sub x) hg #align measure_theory.ae_strongly_measurable.convolution_integrand_swap_snd' MeasureTheory.AEStronglyMeasurable.convolution_integrand_swap_snd' /-- A sufficient condition to prove that `f ⋆[L, μ] g` exists. We assume that `f` is integrable on a set `s` and `g` is bounded and ae strongly measurable on `x₀ - s` (note that both properties hold if `g` is continuous with compact support). -/ theorem _root_.BddAbove.convolutionExistsAt' {x₀ : G} {s : Set G} (hbg : BddAbove ((fun i => ‖g i‖) '' ((fun t => -t + x₀) ⁻¹' s))) (hs : MeasurableSet s) (h2s : (support fun t => L (f t) (g (x₀ - t))) ⊆ s) (hf : IntegrableOn f s μ) (hmg : AEStronglyMeasurable g <| map (fun t => x₀ - t) (μ.restrict s)) : ConvolutionExistsAt f g x₀ L μ := by rw [ConvolutionExistsAt] rw [← integrableOn_iff_integrable_of_support_subset h2s] set s' := (fun t => -t + x₀) ⁻¹' s have : ∀ᵐ t : G ∂μ.restrict s, ‖L (f t) (g (x₀ - t))‖ ≤ s.indicator (fun t => ‖L‖ * ‖f t‖ * ⨆ i : s', ‖g i‖) t := by filter_upwards refine le_indicator (fun t ht => ?_) fun t ht => ?_ · apply_rules [L.le_of_opNorm₂_le_of_le, le_rfl] refine (le_ciSup_set hbg <| mem_preimage.mpr ?_) rwa [neg_sub, sub_add_cancel] · have : t ∉ support fun t => L (f t) (g (x₀ - t)) := mt (fun h => h2s h) ht rw [nmem_support.mp this, norm_zero] refine Integrable.mono' ?_ ?_ this · rw [integrable_indicator_iff hs]; exact ((hf.norm.const_mul _).mul_const _).integrableOn · exact hf.aestronglyMeasurable.convolution_integrand_snd' L hmg #align bdd_above.convolution_exists_at' BddAbove.convolutionExistsAt' /-- If `‖f‖ *[μ] ‖g‖` exists, then `f *[L, μ] g` exists. -/ theorem ConvolutionExistsAt.ofNorm' {x₀ : G} (h : ConvolutionExistsAt (fun x => ‖f x‖) (fun x => ‖g x‖) x₀ (mul ℝ ℝ) μ) (hmf : AEStronglyMeasurable f μ) (hmg : AEStronglyMeasurable g <| map (fun t => x₀ - t) μ) : ConvolutionExistsAt f g x₀ L μ := by refine (h.const_mul ‖L‖).mono' (hmf.convolution_integrand_snd' L hmg) (eventually_of_forall fun x => ?_) rw [mul_apply', ← mul_assoc] apply L.le_opNorm₂ #align convolution_exists_at.of_norm' MeasureTheory.ConvolutionExistsAt.ofNorm' end section Left variable [MeasurableAdd₂ G] [MeasurableNeg G] [SigmaFinite μ] [IsAddRightInvariant μ] theorem AEStronglyMeasurable.convolution_integrand_snd (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) (x : G) : AEStronglyMeasurable (fun t => L (f t) (g (x - t))) μ := hf.convolution_integrand_snd' L <| hg.mono_ac <| (quasiMeasurePreserving_sub_left_of_right_invariant μ x).absolutelyContinuous #align measure_theory.ae_strongly_measurable.convolution_integrand_snd MeasureTheory.AEStronglyMeasurable.convolution_integrand_snd theorem AEStronglyMeasurable.convolution_integrand_swap_snd (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) (x : G) : AEStronglyMeasurable (fun t => L (f (x - t)) (g t)) μ := (hf.mono_ac (quasiMeasurePreserving_sub_left_of_right_invariant μ x).absolutelyContinuous).convolution_integrand_swap_snd' L hg #align measure_theory.ae_strongly_measurable.convolution_integrand_swap_snd MeasureTheory.AEStronglyMeasurable.convolution_integrand_swap_snd /-- If `‖f‖ *[μ] ‖g‖` exists, then `f *[L, μ] g` exists. -/ theorem ConvolutionExistsAt.ofNorm {x₀ : G} (h : ConvolutionExistsAt (fun x => ‖f x‖) (fun x => ‖g x‖) x₀ (mul ℝ ℝ) μ) (hmf : AEStronglyMeasurable f μ) (hmg : AEStronglyMeasurable g μ) : ConvolutionExistsAt f g x₀ L μ := h.ofNorm' L hmf <| hmg.mono_ac (quasiMeasurePreserving_sub_left_of_right_invariant μ x₀).absolutelyContinuous #align convolution_exists_at.of_norm MeasureTheory.ConvolutionExistsAt.ofNorm end Left section Right variable [MeasurableAdd₂ G] [MeasurableNeg G] [SigmaFinite μ] [IsAddRightInvariant μ] [SigmaFinite ν] theorem AEStronglyMeasurable.convolution_integrand (hf : AEStronglyMeasurable f ν) (hg : AEStronglyMeasurable g μ) : AEStronglyMeasurable (fun p : G × G => L (f p.2) (g (p.1 - p.2))) (μ.prod ν) := hf.convolution_integrand' L <| hg.mono_ac (quasiMeasurePreserving_sub_of_right_invariant μ ν).absolutelyContinuous #align measure_theory.ae_strongly_measurable.convolution_integrand MeasureTheory.AEStronglyMeasurable.convolution_integrand theorem Integrable.convolution_integrand (hf : Integrable f ν) (hg : Integrable g μ) : Integrable (fun p : G × G => L (f p.2) (g (p.1 - p.2))) (μ.prod ν) := by have h_meas : AEStronglyMeasurable (fun p : G × G => L (f p.2) (g (p.1 - p.2))) (μ.prod ν) := hf.aestronglyMeasurable.convolution_integrand L hg.aestronglyMeasurable have h2_meas : AEStronglyMeasurable (fun y : G => ∫ x : G, ‖L (f y) (g (x - y))‖ ∂μ) ν := h_meas.prod_swap.norm.integral_prod_right' simp_rw [integrable_prod_iff' h_meas] refine ⟨eventually_of_forall fun t => (L (f t)).integrable_comp (hg.comp_sub_right t), ?_⟩ refine Integrable.mono' ?_ h2_meas (eventually_of_forall fun t => (?_ : _ ≤ ‖L‖ * ‖f t‖ * ∫ x, ‖g (x - t)‖ ∂μ)) · simp only [integral_sub_right_eq_self (‖g ·‖)] exact (hf.norm.const_mul _).mul_const _ · simp_rw [← integral_mul_left] rw [Real.norm_of_nonneg (by positivity)] exact integral_mono_of_nonneg (eventually_of_forall fun t => norm_nonneg _) ((hg.comp_sub_right t).norm.const_mul _) (eventually_of_forall fun t => L.le_opNorm₂ _ _) #align measure_theory.integrable.convolution_integrand MeasureTheory.Integrable.convolution_integrand theorem Integrable.ae_convolution_exists (hf : Integrable f ν) (hg : Integrable g μ) : ∀ᵐ x ∂μ, ConvolutionExistsAt f g x L ν := ((integrable_prod_iff <| hf.aestronglyMeasurable.convolution_integrand L hg.aestronglyMeasurable).mp <| hf.convolution_integrand L hg).1 #align measure_theory.integrable.ae_convolution_exists MeasureTheory.Integrable.ae_convolution_exists end Right variable [TopologicalSpace G] [TopologicalAddGroup G] [BorelSpace G] theorem _root_.HasCompactSupport.convolutionExistsAt {x₀ : G} (h : HasCompactSupport fun t => L (f t) (g (x₀ - t))) (hf : LocallyIntegrable f μ) (hg : Continuous g) : ConvolutionExistsAt f g x₀ L μ := by let u := (Homeomorph.neg G).trans (Homeomorph.addRight x₀) let v := (Homeomorph.neg G).trans (Homeomorph.addLeft x₀) apply ((u.isCompact_preimage.mpr h).bddAbove_image hg.norm.continuousOn).convolutionExistsAt' L isClosed_closure.measurableSet subset_closure (hf.integrableOn_isCompact h) have A : AEStronglyMeasurable (g ∘ v) (μ.restrict (tsupport fun t : G => L (f t) (g (x₀ - t)))) := by apply (hg.comp v.continuous).continuousOn.aestronglyMeasurable_of_isCompact h exact (isClosed_tsupport _).measurableSet convert ((v.continuous.measurable.measurePreserving (μ.restrict (tsupport fun t => L (f t) (g (x₀ - t))))).aestronglyMeasurable_comp_iff v.measurableEmbedding).1 A ext x simp only [v, Homeomorph.neg, sub_eq_add_neg, val_toAddUnits_apply, Homeomorph.trans_apply, Equiv.neg_apply, Equiv.toFun_as_coe, Homeomorph.homeomorph_mk_coe, Equiv.coe_fn_mk, Homeomorph.coe_addLeft] #align has_compact_support.convolution_exists_at HasCompactSupport.convolutionExistsAt theorem _root_.HasCompactSupport.convolutionExists_right (hcg : HasCompactSupport g) (hf : LocallyIntegrable f μ) (hg : Continuous g) : ConvolutionExists f g L μ := by intro x₀ refine HasCompactSupport.convolutionExistsAt L ?_ hf hg refine (hcg.comp_homeomorph (Homeomorph.subLeft x₀)).mono ?_ refine fun t => mt fun ht : g (x₀ - t) = 0 => ?_ simp_rw [ht, (L _).map_zero] #align has_compact_support.convolution_exists_right HasCompactSupport.convolutionExists_right theorem _root_.HasCompactSupport.convolutionExists_left_of_continuous_right (hcf : HasCompactSupport f) (hf : LocallyIntegrable f μ) (hg : Continuous g) : ConvolutionExists f g L μ := by intro x₀ refine HasCompactSupport.convolutionExistsAt L ?_ hf hg refine hcf.mono ?_ refine fun t => mt fun ht : f t = 0 => ?_ simp_rw [ht, L.map_zero₂] #align has_compact_support.convolution_exists_left_of_continuous_right HasCompactSupport.convolutionExists_left_of_continuous_right end Group section CommGroup variable [AddCommGroup G] section MeasurableGroup variable [MeasurableNeg G] [IsAddLeftInvariant μ] /-- A sufficient condition to prove that `f ⋆[L, μ] g` exists. We assume that the integrand has compact support and `g` is bounded on this support (note that both properties hold if `g` is continuous with compact support). We also require that `f` is integrable on the support of the integrand, and that both functions are strongly measurable. This is a variant of `BddAbove.convolutionExistsAt'` in an abelian group with a left-invariant measure. This allows us to state the boundedness and measurability of `g` in a more natural way. -/ theorem _root_.BddAbove.convolutionExistsAt [MeasurableAdd₂ G] [SigmaFinite μ] {x₀ : G} {s : Set G} (hbg : BddAbove ((fun i => ‖g i‖) '' ((fun t => x₀ - t) ⁻¹' s))) (hs : MeasurableSet s) (h2s : (support fun t => L (f t) (g (x₀ - t))) ⊆ s) (hf : IntegrableOn f s μ) (hmg : AEStronglyMeasurable g μ) : ConvolutionExistsAt f g x₀ L μ := by refine BddAbove.convolutionExistsAt' L ?_ hs h2s hf ?_ · simp_rw [← sub_eq_neg_add, hbg] · have : AEStronglyMeasurable g (map (fun t : G => x₀ - t) μ) := hmg.mono_ac (quasiMeasurePreserving_sub_left_of_right_invariant μ x₀).absolutelyContinuous apply this.mono_measure exact map_mono restrict_le_self (measurable_const.sub measurable_id') #align bdd_above.convolution_exists_at BddAbove.convolutionExistsAt variable {L} [MeasurableAdd G] [IsNegInvariant μ] theorem convolutionExistsAt_flip : ConvolutionExistsAt g f x L.flip μ ↔ ConvolutionExistsAt f g x L μ := by simp_rw [ConvolutionExistsAt, ← integrable_comp_sub_left (fun t => L (f t) (g (x - t))) x, sub_sub_cancel, flip_apply] #align convolution_exists_at_flip MeasureTheory.convolutionExistsAt_flip theorem ConvolutionExistsAt.integrable_swap (h : ConvolutionExistsAt f g x L μ) : Integrable (fun t => L (f (x - t)) (g t)) μ := by convert h.comp_sub_left x simp_rw [sub_sub_self] #align convolution_exists_at.integrable_swap MeasureTheory.ConvolutionExistsAt.integrable_swap theorem convolutionExistsAt_iff_integrable_swap : ConvolutionExistsAt f g x L μ ↔ Integrable (fun t => L (f (x - t)) (g t)) μ := convolutionExistsAt_flip.symm #align convolution_exists_at_iff_integrable_swap MeasureTheory.convolutionExistsAt_iff_integrable_swap end MeasurableGroup variable [TopologicalSpace G] [TopologicalAddGroup G] [BorelSpace G] variable [IsAddLeftInvariant μ] [IsNegInvariant μ] theorem _root_.HasCompactSupport.convolutionExistsLeft (hcf : HasCompactSupport f) (hf : Continuous f) (hg : LocallyIntegrable g μ) : ConvolutionExists f g L μ := fun x₀ => convolutionExistsAt_flip.mp <| hcf.convolutionExists_right L.flip hg hf x₀ #align has_compact_support.convolution_exists_left HasCompactSupport.convolutionExistsLeft theorem _root_.HasCompactSupport.convolutionExistsRightOfContinuousLeft (hcg : HasCompactSupport g) (hf : Continuous f) (hg : LocallyIntegrable g μ) : ConvolutionExists f g L μ := fun x₀ => convolutionExistsAt_flip.mp <| hcg.convolutionExists_left_of_continuous_right L.flip hg hf x₀ #align has_compact_support.convolution_exists_right_of_continuous_left HasCompactSupport.convolutionExistsRightOfContinuousLeft end CommGroup end ConvolutionExists variable [NormedSpace ℝ F] /-- The convolution of two functions `f` and `g` with respect to a continuous bilinear map `L` and measure `μ`. It is defined to be `(f ⋆[L, μ] g) x = ∫ t, L (f t) (g (x - t)) ∂μ`. -/ noncomputable def convolution [Sub G] (f : G → E) (g : G → E') (L : E →L[𝕜] E' →L[𝕜] F) (μ : Measure G := by volume_tac) : G → F := fun x => ∫ t, L (f t) (g (x - t)) ∂μ #align convolution MeasureTheory.convolution /-- The convolution of two functions with respect to a bilinear operation `L` and a measure `μ`. -/ scoped[Convolution] notation:67 f " ⋆[" L:67 ", " μ:67 "] " g:66 => convolution f g L μ /-- The convolution of two functions with respect to a bilinear operation `L` and the volume. -/ scoped[Convolution] notation:67 f " ⋆[" L:67 "]" g:66 => convolution f g L MeasureSpace.volume /-- The convolution of two real-valued functions with respect to volume. -/ scoped[Convolution] notation:67 f " ⋆ " g:66 => convolution f g (ContinuousLinearMap.lsmul ℝ ℝ) MeasureSpace.volume open scoped Convolution theorem convolution_def [Sub G] : (f ⋆[L, μ] g) x = ∫ t, L (f t) (g (x - t)) ∂μ := rfl #align convolution_def MeasureTheory.convolution_def /-- The definition of convolution where the bilinear operator is scalar multiplication. Note: it often helps the elaborator to give the type of the convolution explicitly. -/ theorem convolution_lsmul [Sub G] {f : G → 𝕜} {g : G → F} : (f ⋆[lsmul 𝕜 𝕜, μ] g : G → F) x = ∫ t, f t • g (x - t) ∂μ := rfl #align convolution_lsmul MeasureTheory.convolution_lsmul /-- The definition of convolution where the bilinear operator is multiplication. -/ theorem convolution_mul [Sub G] [NormedSpace ℝ 𝕜] {f : G → 𝕜} {g : G → 𝕜} : (f ⋆[mul 𝕜 𝕜, μ] g) x = ∫ t, f t * g (x - t) ∂μ := rfl #align convolution_mul MeasureTheory.convolution_mul section Group variable {L} [AddGroup G] theorem smul_convolution [SMulCommClass ℝ 𝕜 F] {y : 𝕜} : y • f ⋆[L, μ] g = y • (f ⋆[L, μ] g) := by ext; simp only [Pi.smul_apply, convolution_def, ← integral_smul, L.map_smul₂] #align smul_convolution MeasureTheory.smul_convolution theorem convolution_smul [SMulCommClass ℝ 𝕜 F] {y : 𝕜} : f ⋆[L, μ] y • g = y • (f ⋆[L, μ] g) := by ext; simp only [Pi.smul_apply, convolution_def, ← integral_smul, (L _).map_smul] #align convolution_smul MeasureTheory.convolution_smul @[simp] theorem zero_convolution : 0 ⋆[L, μ] g = 0 := by ext simp_rw [convolution_def, Pi.zero_apply, L.map_zero₂, integral_zero] #align zero_convolution MeasureTheory.zero_convolution @[simp] theorem convolution_zero : f ⋆[L, μ] 0 = 0 := by ext simp_rw [convolution_def, Pi.zero_apply, (L _).map_zero, integral_zero] #align convolution_zero MeasureTheory.convolution_zero theorem ConvolutionExistsAt.distrib_add {x : G} (hfg : ConvolutionExistsAt f g x L μ) (hfg' : ConvolutionExistsAt f g' x L μ) : (f ⋆[L, μ] (g + g')) x = (f ⋆[L, μ] g) x + (f ⋆[L, μ] g') x := by simp only [convolution_def, (L _).map_add, Pi.add_apply, integral_add hfg hfg'] #align convolution_exists_at.distrib_add MeasureTheory.ConvolutionExistsAt.distrib_add theorem ConvolutionExists.distrib_add (hfg : ConvolutionExists f g L μ) (hfg' : ConvolutionExists f g' L μ) : f ⋆[L, μ] (g + g') = f ⋆[L, μ] g + f ⋆[L, μ] g' := by ext x exact (hfg x).distrib_add (hfg' x) #align convolution_exists.distrib_add MeasureTheory.ConvolutionExists.distrib_add theorem ConvolutionExistsAt.add_distrib {x : G} (hfg : ConvolutionExistsAt f g x L μ) (hfg' : ConvolutionExistsAt f' g x L μ) : ((f + f') ⋆[L, μ] g) x = (f ⋆[L, μ] g) x + (f' ⋆[L, μ] g) x := by simp only [convolution_def, L.map_add₂, Pi.add_apply, integral_add hfg hfg'] #align convolution_exists_at.add_distrib MeasureTheory.ConvolutionExistsAt.add_distrib theorem ConvolutionExists.add_distrib (hfg : ConvolutionExists f g L μ) (hfg' : ConvolutionExists f' g L μ) : (f + f') ⋆[L, μ] g = f ⋆[L, μ] g + f' ⋆[L, μ] g := by ext x exact (hfg x).add_distrib (hfg' x) #align convolution_exists.add_distrib MeasureTheory.ConvolutionExists.add_distrib theorem convolution_mono_right {f g g' : G → ℝ} (hfg : ConvolutionExistsAt f g x (lsmul ℝ ℝ) μ) (hfg' : ConvolutionExistsAt f g' x (lsmul ℝ ℝ) μ) (hf : ∀ x, 0 ≤ f x) (hg : ∀ x, g x ≤ g' x) : (f ⋆[lsmul ℝ ℝ, μ] g) x ≤ (f ⋆[lsmul ℝ ℝ, μ] g') x := by apply integral_mono hfg hfg' simp only [lsmul_apply, Algebra.id.smul_eq_mul] intro t apply mul_le_mul_of_nonneg_left (hg _) (hf _) #align convolution_mono_right MeasureTheory.convolution_mono_right theorem convolution_mono_right_of_nonneg {f g g' : G → ℝ} (hfg' : ConvolutionExistsAt f g' x (lsmul ℝ ℝ) μ) (hf : ∀ x, 0 ≤ f x) (hg : ∀ x, g x ≤ g' x) (hg' : ∀ x, 0 ≤ g' x) : (f ⋆[lsmul ℝ ℝ, μ] g) x ≤ (f ⋆[lsmul ℝ ℝ, μ] g') x := by by_cases H : ConvolutionExistsAt f g x (lsmul ℝ ℝ) μ · exact convolution_mono_right H hfg' hf hg have : (f ⋆[lsmul ℝ ℝ, μ] g) x = 0 := integral_undef H rw [this] exact integral_nonneg fun y => mul_nonneg (hf y) (hg' (x - y)) #align convolution_mono_right_of_nonneg MeasureTheory.convolution_mono_right_of_nonneg variable (L) theorem convolution_congr [MeasurableAdd₂ G] [MeasurableNeg G] [SigmaFinite μ] [IsAddRightInvariant μ] (h1 : f =ᵐ[μ] f') (h2 : g =ᵐ[μ] g') : f ⋆[L, μ] g = f' ⋆[L, μ] g' := by ext x apply integral_congr_ae exact (h1.prod_mk <| h2.comp_tendsto (quasiMeasurePreserving_sub_left_of_right_invariant μ x).tendsto_ae).fun_comp ↿fun x y => L x y #align convolution_congr MeasureTheory.convolution_congr theorem support_convolution_subset_swap : support (f ⋆[L, μ] g) ⊆ support g + support f := by intro x h2x by_contra hx apply h2x simp_rw [Set.mem_add, ← exists_and_left, not_exists, not_and_or, nmem_support] at hx rw [convolution_def] convert integral_zero G F using 2 ext t rcases hx (x - t) t with (h | h | h) · rw [h, (L _).map_zero] · rw [h, L.map_zero₂] · exact (h <| sub_add_cancel x t).elim #align support_convolution_subset_swap MeasureTheory.support_convolution_subset_swap section variable [MeasurableAdd₂ G] [MeasurableNeg G] [SigmaFinite μ] [IsAddRightInvariant μ] theorem Integrable.integrable_convolution (hf : Integrable f μ) (hg : Integrable g μ) : Integrable (f ⋆[L, μ] g) μ := (hf.convolution_integrand L hg).integral_prod_left #align measure_theory.integrable.integrable_convolution MeasureTheory.Integrable.integrable_convolution end variable [TopologicalSpace G] variable [TopologicalAddGroup G] protected theorem _root_.HasCompactSupport.convolution [T2Space G] (hcf : HasCompactSupport f) (hcg : HasCompactSupport g) : HasCompactSupport (f ⋆[L, μ] g) := (hcg.isCompact.add hcf).of_isClosed_subset isClosed_closure <| closure_minimal ((support_convolution_subset_swap L).trans <| add_subset_add subset_closure subset_closure) (hcg.isCompact.add hcf).isClosed #align has_compact_support.convolution HasCompactSupport.convolution variable [BorelSpace G] [TopologicalSpace P] /-- The convolution `f * g` is continuous if `f` is locally integrable and `g` is continuous and compactly supported. Version where `g` depends on an additional parameter in a subset `s` of a parameter space `P` (and the compact support `k` is independent of the parameter in `s`). -/ theorem continuousOn_convolution_right_with_param {g : P → G → E'} {s : Set P} {k : Set G} (hk : IsCompact k) (hgs : ∀ p, ∀ x, p ∈ s → x ∉ k → g p x = 0) (hf : LocallyIntegrable f μ) (hg : ContinuousOn (↿g) (s ×ˢ univ)) : ContinuousOn (fun q : P × G => (f ⋆[L, μ] g q.1) q.2) (s ×ˢ univ) := by /- First get rid of the case where the space is not locally compact. Then `g` vanishes everywhere and the conclusion is trivial. -/ by_cases H : ∀ p ∈ s, ∀ x, g p x = 0 · apply (continuousOn_const (c := 0)).congr rintro ⟨p, x⟩ ⟨hp, -⟩ apply integral_eq_zero_of_ae (eventually_of_forall (fun y ↦ ?_)) simp [H p hp _] have : LocallyCompactSpace G := by push_neg at H rcases H with ⟨p, hp, x, hx⟩ have A : support (g p) ⊆ k := support_subset_iff'.2 (fun y hy ↦ hgs p y hp hy) have B : Continuous (g p) := by refine hg.comp_continuous (continuous_const.prod_mk continuous_id') fun x => ?_ simpa only [prod_mk_mem_set_prod_eq, mem_univ, and_true] using hp rcases eq_zero_or_locallyCompactSpace_of_support_subset_isCompact_of_addGroup hk A B with H|H · simp [H] at hx · exact H /- Since `G` is locally compact, one may thicken `k` a little bit into a larger compact set `(-k) + t`, outside of which all functions that appear in the convolution vanish. Then we can apply a continuity statement for integrals depending on a parameter, with respect to locally integrable functions and compactly supported continuous functions. -/ rintro ⟨q₀, x₀⟩ ⟨hq₀, -⟩ obtain ⟨t, t_comp, ht⟩ : ∃ t, IsCompact t ∧ t ∈ 𝓝 x₀ := exists_compact_mem_nhds x₀ let k' : Set G := (-k) +ᵥ t have k'_comp : IsCompact k' := IsCompact.vadd_set hk.neg t_comp let g' : (P × G) → G → E' := fun p x ↦ g p.1 (p.2 - x) let s' : Set (P × G) := s ×ˢ t have A : ContinuousOn g'.uncurry (s' ×ˢ univ) := by have : g'.uncurry = g.uncurry ∘ (fun w ↦ (w.1.1, w.1.2 - w.2)) := by ext y; rfl rw [this] refine hg.comp (continuous_fst.fst.prod_mk (continuous_fst.snd.sub continuous_snd)).continuousOn ?_ simp (config := {contextual := true}) [s', MapsTo] have B : ContinuousOn (fun a ↦ ∫ x, L (f x) (g' a x) ∂μ) s' := by apply continuousOn_integral_bilinear_of_locally_integrable_of_compact_support L k'_comp A _ (hf.integrableOn_isCompact k'_comp) rintro ⟨p, x⟩ y ⟨hp, hx⟩ hy apply hgs p _ hp contrapose! hy exact ⟨y - x, by simpa using hy, x, hx, by simp⟩ apply ContinuousWithinAt.mono_of_mem (B (q₀, x₀) ⟨hq₀, mem_of_mem_nhds ht⟩) exact mem_nhdsWithin_prod_iff.2 ⟨s, self_mem_nhdsWithin, t, nhdsWithin_le_nhds ht, Subset.rfl⟩ #align continuous_on_convolution_right_with_param' MeasureTheory.continuousOn_convolution_right_with_param #align continuous_on_convolution_right_with_param MeasureTheory.continuousOn_convolution_right_with_param /-- The convolution `f * g` is continuous if `f` is locally integrable and `g` is continuous and compactly supported. Version where `g` depends on an additional parameter in an open subset `s` of a parameter space `P` (and the compact support `k` is independent of the parameter in `s`), given in terms of compositions with an additional continuous map. -/ theorem continuousOn_convolution_right_with_param_comp {s : Set P} {v : P → G} (hv : ContinuousOn v s) {g : P → G → E'} {k : Set G} (hk : IsCompact k) (hgs : ∀ p, ∀ x, p ∈ s → x ∉ k → g p x = 0) (hf : LocallyIntegrable f μ) (hg : ContinuousOn (↿g) (s ×ˢ univ)) : ContinuousOn (fun x => (f ⋆[L, μ] g x) (v x)) s := by apply (continuousOn_convolution_right_with_param L hk hgs hf hg).comp (continuousOn_id.prod hv) intro x hx simp only [hx, prod_mk_mem_set_prod_eq, mem_univ, and_self_iff, _root_.id] #align continuous_on_convolution_right_with_param_comp' MeasureTheory.continuousOn_convolution_right_with_param_comp #align continuous_on_convolution_right_with_param_comp MeasureTheory.continuousOn_convolution_right_with_param_comp /-- The convolution is continuous if one function is locally integrable and the other has compact support and is continuous. -/ theorem _root_.HasCompactSupport.continuous_convolution_right (hcg : HasCompactSupport g) (hf : LocallyIntegrable f μ) (hg : Continuous g) : Continuous (f ⋆[L, μ] g) := by rw [continuous_iff_continuousOn_univ] let g' : G → G → E' := fun _ q => g q have : ContinuousOn (↿g') (univ ×ˢ univ) := (hg.comp continuous_snd).continuousOn exact continuousOn_convolution_right_with_param_comp L (continuous_iff_continuousOn_univ.1 continuous_id) hcg (fun p x _ hx => image_eq_zero_of_nmem_tsupport hx) hf this #align has_compact_support.continuous_convolution_right HasCompactSupport.continuous_convolution_right /-- The convolution is continuous if one function is integrable and the other is bounded and continuous. -/ theorem _root_.BddAbove.continuous_convolution_right_of_integrable [FirstCountableTopology G] [SecondCountableTopologyEither G E'] (hbg : BddAbove (range fun x => ‖g x‖)) (hf : Integrable f μ) (hg : Continuous g) : Continuous (f ⋆[L, μ] g) := by refine continuous_iff_continuousAt.mpr fun x₀ => ?_ have : ∀ᶠ x in 𝓝 x₀, ∀ᵐ t : G ∂μ, ‖L (f t) (g (x - t))‖ ≤ ‖L‖ * ‖f t‖ * ⨆ i, ‖g i‖ := by filter_upwards with x; filter_upwards with t apply_rules [L.le_of_opNorm₂_le_of_le, le_rfl, le_ciSup hbg (x - t)] refine continuousAt_of_dominated ?_ this ?_ ?_ · exact eventually_of_forall fun x => hf.aestronglyMeasurable.convolution_integrand_snd' L hg.aestronglyMeasurable · exact (hf.norm.const_mul _).mul_const _ · exact eventually_of_forall fun t => (L.continuous₂.comp₂ continuous_const <| hg.comp <| continuous_id.sub continuous_const).continuousAt #align bdd_above.continuous_convolution_right_of_integrable BddAbove.continuous_convolution_right_of_integrable end Group section CommGroup variable [AddCommGroup G] theorem support_convolution_subset : support (f ⋆[L, μ] g) ⊆ support f + support g := (support_convolution_subset_swap L).trans (add_comm _ _).subset #align support_convolution_subset MeasureTheory.support_convolution_subset variable [IsAddLeftInvariant μ] [IsNegInvariant μ] section Measurable variable [MeasurableNeg G] variable [MeasurableAdd G] /-- Commutativity of convolution -/ theorem convolution_flip : g ⋆[L.flip, μ] f = f ⋆[L, μ] g := by ext1 x simp_rw [convolution_def] rw [← integral_sub_left_eq_self _ μ x] simp_rw [sub_sub_self, flip_apply] #align convolution_flip MeasureTheory.convolution_flip /-- The symmetric definition of convolution. -/ theorem convolution_eq_swap : (f ⋆[L, μ] g) x = ∫ t, L (f (x - t)) (g t) ∂μ := by rw [← convolution_flip]; rfl #align convolution_eq_swap MeasureTheory.convolution_eq_swap /-- The symmetric definition of convolution where the bilinear operator is scalar multiplication. -/ theorem convolution_lsmul_swap {f : G → 𝕜} {g : G → F} : (f ⋆[lsmul 𝕜 𝕜, μ] g : G → F) x = ∫ t, f (x - t) • g t ∂μ := convolution_eq_swap _ #align convolution_lsmul_swap MeasureTheory.convolution_lsmul_swap /-- The symmetric definition of convolution where the bilinear operator is multiplication. -/ theorem convolution_mul_swap [NormedSpace ℝ 𝕜] {f : G → 𝕜} {g : G → 𝕜} : (f ⋆[mul 𝕜 𝕜, μ] g) x = ∫ t, f (x - t) * g t ∂μ := convolution_eq_swap _ #align convolution_mul_swap MeasureTheory.convolution_mul_swap /-- The convolution of two even functions is also even. -/ theorem convolution_neg_of_neg_eq (h1 : ∀ᵐ x ∂μ, f (-x) = f x) (h2 : ∀ᵐ x ∂μ, g (-x) = g x) : (f ⋆[L, μ] g) (-x) = (f ⋆[L, μ] g) x := calc ∫ t : G, (L (f t)) (g (-x - t)) ∂μ = ∫ t : G, (L (f (-t))) (g (x + t)) ∂μ := by apply integral_congr_ae filter_upwards [h1, (eventually_add_left_iff μ x).2 h2] with t ht h't simp_rw [ht, ← h't, neg_add'] _ = ∫ t : G, (L (f t)) (g (x - t)) ∂μ := by rw [← integral_neg_eq_self] simp only [neg_neg, ← sub_eq_add_neg] #align convolution_neg_of_neg_eq MeasureTheory.convolution_neg_of_neg_eq end Measurable variable [TopologicalSpace G] variable [TopologicalAddGroup G] variable [BorelSpace G] theorem _root_.HasCompactSupport.continuous_convolution_left (hcf : HasCompactSupport f) (hf : Continuous f) (hg : LocallyIntegrable g μ) : Continuous (f ⋆[L, μ] g) := by rw [← convolution_flip] exact hcf.continuous_convolution_right L.flip hg hf #align has_compact_support.continuous_convolution_left HasCompactSupport.continuous_convolution_left theorem _root_.BddAbove.continuous_convolution_left_of_integrable [FirstCountableTopology G] [SecondCountableTopologyEither G E] (hbf : BddAbove (range fun x => ‖f x‖)) (hf : Continuous f) (hg : Integrable g μ) : Continuous (f ⋆[L, μ] g) := by rw [← convolution_flip] exact hbf.continuous_convolution_right_of_integrable L.flip hg hf #align bdd_above.continuous_convolution_left_of_integrable BddAbove.continuous_convolution_left_of_integrable end CommGroup section NormedAddCommGroup variable [SeminormedAddCommGroup G] /-- Compute `(f ⋆ g) x₀` if the support of the `f` is within `Metric.ball 0 R`, and `g` is constant on `Metric.ball x₀ R`. We can simplify the RHS further if we assume `f` is integrable, but also if `L = (•)` or more generally if `L` has an `AntilipschitzWith`-condition. -/ theorem convolution_eq_right' {x₀ : G} {R : ℝ} (hf : support f ⊆ ball (0 : G) R) (hg : ∀ x ∈ ball x₀ R, g x = g x₀) : (f ⋆[L, μ] g) x₀ = ∫ t, L (f t) (g x₀) ∂μ := by have h2 : ∀ t, L (f t) (g (x₀ - t)) = L (f t) (g x₀) := fun t ↦ by by_cases ht : t ∈ support f · have h2t := hf ht rw [mem_ball_zero_iff] at h2t specialize hg (x₀ - t) rw [sub_eq_add_neg, add_mem_ball_iff_norm, norm_neg, ← sub_eq_add_neg] at hg rw [hg h2t] · rw [nmem_support] at ht simp_rw [ht, L.map_zero₂] simp_rw [convolution_def, h2] #align convolution_eq_right' MeasureTheory.convolution_eq_right' variable [BorelSpace G] [SecondCountableTopology G] variable [IsAddLeftInvariant μ] [SigmaFinite μ] /-- Approximate `(f ⋆ g) x₀` if the support of the `f` is bounded within a ball, and `g` is near `g x₀` on a ball with the same radius around `x₀`. See `dist_convolution_le` for a special case. We can simplify the second argument of `dist` further if we add some extra type-classes on `E` and `𝕜` or if `L` is scalar multiplication. -/ theorem dist_convolution_le' {x₀ : G} {R ε : ℝ} {z₀ : E'} (hε : 0 ≤ ε) (hif : Integrable f μ) (hf : support f ⊆ ball (0 : G) R) (hmg : AEStronglyMeasurable g μ) (hg : ∀ x ∈ ball x₀ R, dist (g x) z₀ ≤ ε) : dist ((f ⋆[L, μ] g : G → F) x₀) (∫ t, L (f t) z₀ ∂μ) ≤ (‖L‖ * ∫ x, ‖f x‖ ∂μ) * ε := by have hfg : ConvolutionExistsAt f g x₀ L μ := by refine BddAbove.convolutionExistsAt L ?_ Metric.isOpen_ball.measurableSet (Subset.trans ?_ hf) hif.integrableOn hmg swap; · refine fun t => mt fun ht : f t = 0 => ?_; simp_rw [ht, L.map_zero₂] rw [bddAbove_def] refine ⟨‖z₀‖ + ε, ?_⟩ rintro _ ⟨x, hx, rfl⟩ refine norm_le_norm_add_const_of_dist_le (hg x ?_) rwa [mem_ball_iff_norm, norm_sub_rev, ← mem_ball_zero_iff] have h2 : ∀ t, dist (L (f t) (g (x₀ - t))) (L (f t) z₀) ≤ ‖L (f t)‖ * ε := by intro t; by_cases ht : t ∈ support f · have h2t := hf ht rw [mem_ball_zero_iff] at h2t specialize hg (x₀ - t) rw [sub_eq_add_neg, add_mem_ball_iff_norm, norm_neg, ← sub_eq_add_neg] at hg refine ((L (f t)).dist_le_opNorm _ _).trans ?_ exact mul_le_mul_of_nonneg_left (hg h2t) (norm_nonneg _) · rw [nmem_support] at ht simp_rw [ht, L.map_zero₂, L.map_zero, norm_zero, zero_mul, dist_self] rfl simp_rw [convolution_def] simp_rw [dist_eq_norm] at h2 ⊢ rw [← integral_sub hfg.integrable]; swap; · exact (L.flip z₀).integrable_comp hif refine (norm_integral_le_of_norm_le ((L.integrable_comp hif).norm.mul_const ε) (eventually_of_forall h2)).trans ?_ rw [integral_mul_right] refine mul_le_mul_of_nonneg_right ?_ hε have h3 : ∀ t, ‖L (f t)‖ ≤ ‖L‖ * ‖f t‖ := by intro t exact L.le_opNorm (f t) refine (integral_mono (L.integrable_comp hif).norm (hif.norm.const_mul _) h3).trans_eq ?_ rw [integral_mul_left] #align dist_convolution_le' MeasureTheory.dist_convolution_le' variable [NormedSpace ℝ E] [NormedSpace ℝ E'] [CompleteSpace E'] /-- Approximate `f ⋆ g` if the support of the `f` is bounded within a ball, and `g` is near `g x₀` on a ball with the same radius around `x₀`. This is a special case of `dist_convolution_le'` where `L` is `(•)`, `f` has integral 1 and `f` is nonnegative. -/ theorem dist_convolution_le {f : G → ℝ} {x₀ : G} {R ε : ℝ} {z₀ : E'} (hε : 0 ≤ ε) (hf : support f ⊆ ball (0 : G) R) (hnf : ∀ x, 0 ≤ f x) (hintf : ∫ x, f x ∂μ = 1) (hmg : AEStronglyMeasurable g μ) (hg : ∀ x ∈ ball x₀ R, dist (g x) z₀ ≤ ε) : dist ((f ⋆[lsmul ℝ ℝ, μ] g : G → E') x₀) z₀ ≤ ε := by have hif : Integrable f μ := integrable_of_integral_eq_one hintf convert (dist_convolution_le' (lsmul ℝ ℝ) hε hif hf hmg hg).trans _ · simp_rw [lsmul_apply, integral_smul_const, hintf, one_smul] · simp_rw [Real.norm_of_nonneg (hnf _), hintf, mul_one] exact (mul_le_mul_of_nonneg_right opNorm_lsmul_le hε).trans_eq (one_mul ε) #align dist_convolution_le MeasureTheory.dist_convolution_le /-- `(φ i ⋆ g i) (k i)` tends to `z₀` as `i` tends to some filter `l` if * `φ` is a sequence of nonnegative functions with integral `1` as `i` tends to `l`; * The support of `φ` tends to small neighborhoods around `(0 : G)` as `i` tends to `l`; * `g i` is `mu`-a.e. strongly measurable as `i` tends to `l`; * `g i x` tends to `z₀` as `(i, x)` tends to `l ×ˢ 𝓝 x₀`; * `k i` tends to `x₀`. See also `ContDiffBump.convolution_tendsto_right`. -/ theorem convolution_tendsto_right {ι} {g : ι → G → E'} {l : Filter ι} {x₀ : G} {z₀ : E'} {φ : ι → G → ℝ} {k : ι → G} (hnφ : ∀ᶠ i in l, ∀ x, 0 ≤ φ i x) (hiφ : ∀ᶠ i in l, ∫ x, φ i x ∂μ = 1) -- todo: we could weaken this to "the integral tends to 1" (hφ : Tendsto (fun n => support (φ n)) l (𝓝 0).smallSets) (hmg : ∀ᶠ i in l, AEStronglyMeasurable (g i) μ) (hcg : Tendsto (uncurry g) (l ×ˢ 𝓝 x₀) (𝓝 z₀)) (hk : Tendsto k l (𝓝 x₀)) : Tendsto (fun i : ι => (φ i ⋆[lsmul ℝ ℝ, μ] g i : G → E') (k i)) l (𝓝 z₀) := by simp_rw [tendsto_smallSets_iff] at hφ rw [Metric.tendsto_nhds] at hcg ⊢ simp_rw [Metric.eventually_prod_nhds_iff] at hcg intro ε hε have h2ε : 0 < ε / 3 := div_pos hε (by norm_num) obtain ⟨p, hp, δ, hδ, hgδ⟩ := hcg _ h2ε dsimp only [uncurry] at hgδ have h2k := hk.eventually (ball_mem_nhds x₀ <| half_pos hδ) have h2φ := hφ (ball (0 : G) _) <| ball_mem_nhds _ (half_pos hδ) filter_upwards [hp, h2k, h2φ, hnφ, hiφ, hmg] with i hpi hki hφi hnφi hiφi hmgi have hgi : dist (g i (k i)) z₀ < ε / 3 := hgδ hpi (hki.trans <| half_lt_self hδ) have h1 : ∀ x' ∈ ball (k i) (δ / 2), dist (g i x') (g i (k i)) ≤ ε / 3 + ε / 3 := by intro x' hx' refine (dist_triangle_right _ _ _).trans (add_le_add (hgδ hpi ?_).le hgi.le) exact ((dist_triangle _ _ _).trans_lt (add_lt_add hx'.out hki)).trans_eq (add_halves δ) have := dist_convolution_le (add_pos h2ε h2ε).le hφi hnφi hiφi hmgi h1 refine ((dist_triangle _ _ _).trans_lt (add_lt_add_of_le_of_lt this hgi)).trans_eq ?_ field_simp; ring_nf #align convolution_tendsto_right MeasureTheory.convolution_tendsto_right end NormedAddCommGroup end Measurability end NontriviallyNormedField open scoped Convolution section RCLike variable [RCLike 𝕜] variable [NormedSpace 𝕜 E] variable [NormedSpace 𝕜 E'] variable [NormedSpace 𝕜 E''] variable [NormedSpace ℝ F] [NormedSpace 𝕜 F] variable {n : ℕ∞} variable [CompleteSpace F] variable [MeasurableSpace G] {μ ν : Measure G} variable (L : E →L[𝕜] E' →L[𝕜] F) section Assoc variable [NormedAddCommGroup F'] [NormedSpace ℝ F'] [NormedSpace 𝕜 F'] [CompleteSpace F'] variable [NormedAddCommGroup F''] [NormedSpace ℝ F''] [NormedSpace 𝕜 F''] [CompleteSpace F''] variable {k : G → E''} variable (L₂ : F →L[𝕜] E'' →L[𝕜] F') variable (L₃ : E →L[𝕜] F'' →L[𝕜] F') variable (L₄ : E' →L[𝕜] E'' →L[𝕜] F'') variable [AddGroup G] variable [SigmaFinite μ] [SigmaFinite ν] [IsAddRightInvariant μ] theorem integral_convolution [MeasurableAdd₂ G] [MeasurableNeg G] [NormedSpace ℝ E] [NormedSpace ℝ E'] [CompleteSpace E] [CompleteSpace E'] (hf : Integrable f ν) (hg : Integrable g μ) : ∫ x, (f ⋆[L, ν] g) x ∂μ = L (∫ x, f x ∂ν) (∫ x, g x ∂μ) := by refine (integral_integral_swap (by apply hf.convolution_integrand L hg)).trans ?_ simp_rw [integral_comp_comm _ (hg.comp_sub_right _), integral_sub_right_eq_self] exact (L.flip (∫ x, g x ∂μ)).integral_comp_comm hf #align integral_convolution MeasureTheory.integral_convolution variable [MeasurableAdd₂ G] [IsAddRightInvariant ν] [MeasurableNeg G] /-- Convolution is associative. This has a weak but inconvenient integrability condition. See also `convolution_assoc`. -/ theorem convolution_assoc' (hL : ∀ (x : E) (y : E') (z : E''), L₂ (L x y) z = L₃ x (L₄ y z)) {x₀ : G} (hfg : ∀ᵐ y ∂μ, ConvolutionExistsAt f g y L ν) (hgk : ∀ᵐ x ∂ν, ConvolutionExistsAt g k x L₄ μ) (hi : Integrable (uncurry fun x y => (L₃ (f y)) ((L₄ (g (x - y))) (k (x₀ - x)))) (μ.prod ν)) : ((f ⋆[L, ν] g) ⋆[L₂, μ] k) x₀ = (f ⋆[L₃, ν] g ⋆[L₄, μ] k) x₀ := calc ((f ⋆[L, ν] g) ⋆[L₂, μ] k) x₀ = ∫ t, L₂ (∫ s, L (f s) (g (t - s)) ∂ν) (k (x₀ - t)) ∂μ := rfl _ = ∫ t, ∫ s, L₂ (L (f s) (g (t - s))) (k (x₀ - t)) ∂ν ∂μ := (integral_congr_ae (hfg.mono fun t ht => ((L₂.flip (k (x₀ - t))).integral_comp_comm ht).symm)) _ = ∫ t, ∫ s, L₃ (f s) (L₄ (g (t - s)) (k (x₀ - t))) ∂ν ∂μ := by simp_rw [hL] _ = ∫ s, ∫ t, L₃ (f s) (L₄ (g (t - s)) (k (x₀ - t))) ∂μ ∂ν := by rw [integral_integral_swap hi] _ = ∫ s, ∫ u, L₃ (f s) (L₄ (g u) (k (x₀ - s - u))) ∂μ ∂ν := by congr; ext t rw [eq_comm, ← integral_sub_right_eq_self _ t] simp_rw [sub_sub_sub_cancel_right] _ = ∫ s, L₃ (f s) (∫ u, L₄ (g u) (k (x₀ - s - u)) ∂μ) ∂ν := by refine integral_congr_ae ?_ refine ((quasiMeasurePreserving_sub_left_of_right_invariant ν x₀).ae hgk).mono fun t ht => ?_ exact (L₃ (f t)).integral_comp_comm ht _ = (f ⋆[L₃, ν] g ⋆[L₄, μ] k) x₀ := rfl #align convolution_assoc' MeasureTheory.convolution_assoc' /-- Convolution is associative. This requires that * all maps are a.e. strongly measurable w.r.t one of the measures * `f ⋆[L, ν] g` exists almost everywhere * `‖g‖ ⋆[μ] ‖k‖` exists almost everywhere * `‖f‖ ⋆[ν] (‖g‖ ⋆[μ] ‖k‖)` exists at `x₀` -/ theorem convolution_assoc (hL : ∀ (x : E) (y : E') (z : E''), L₂ (L x y) z = L₃ x (L₄ y z)) {x₀ : G} (hf : AEStronglyMeasurable f ν) (hg : AEStronglyMeasurable g μ) (hk : AEStronglyMeasurable k μ) (hfg : ∀ᵐ y ∂μ, ConvolutionExistsAt f g y L ν) (hgk : ∀ᵐ x ∂ν, ConvolutionExistsAt (fun x => ‖g x‖) (fun x => ‖k x‖) x (mul ℝ ℝ) μ) (hfgk : ConvolutionExistsAt (fun x => ‖f x‖) ((fun x => ‖g x‖) ⋆[mul ℝ ℝ, μ] fun x => ‖k x‖) x₀ (mul ℝ ℝ) ν) : ((f ⋆[L, ν] g) ⋆[L₂, μ] k) x₀ = (f ⋆[L₃, ν] g ⋆[L₄, μ] k) x₀ := by refine convolution_assoc' L L₂ L₃ L₄ hL hfg (hgk.mono fun x hx => hx.ofNorm L₄ hg hk) ?_ -- the following is similar to `Integrable.convolution_integrand` have h_meas : AEStronglyMeasurable (uncurry fun x y => L₃ (f y) (L₄ (g x) (k (x₀ - y - x)))) (μ.prod ν) := by refine L₃.aestronglyMeasurable_comp₂ hf.snd ?_ refine L₄.aestronglyMeasurable_comp₂ hg.fst ?_ refine (hk.mono_ac ?_).comp_measurable ((measurable_const.sub measurable_snd).sub measurable_fst) refine QuasiMeasurePreserving.absolutelyContinuous ?_ refine QuasiMeasurePreserving.prod_of_left ((measurable_const.sub measurable_snd).sub measurable_fst) (eventually_of_forall fun y => ?_) dsimp only exact quasiMeasurePreserving_sub_left_of_right_invariant μ _ have h2_meas : AEStronglyMeasurable (fun y => ∫ x, ‖L₃ (f y) (L₄ (g x) (k (x₀ - y - x)))‖ ∂μ) ν := h_meas.prod_swap.norm.integral_prod_right' have h3 : map (fun z : G × G => (z.1 - z.2, z.2)) (μ.prod ν) = μ.prod ν := (measurePreserving_sub_prod μ ν).map_eq suffices Integrable (uncurry fun x y => L₃ (f y) (L₄ (g x) (k (x₀ - y - x)))) (μ.prod ν) by rw [← h3] at this convert this.comp_measurable (measurable_sub.prod_mk measurable_snd) ext ⟨x, y⟩ simp (config := { unfoldPartialApp := true }) only [uncurry, Function.comp_apply, sub_sub_sub_cancel_right] simp_rw [integrable_prod_iff' h_meas] refine ⟨((quasiMeasurePreserving_sub_left_of_right_invariant ν x₀).ae hgk).mono fun t ht => (L₃ (f t)).integrable_comp <| ht.ofNorm L₄ hg hk, ?_⟩ refine (hfgk.const_mul (‖L₃‖ * ‖L₄‖)).mono' h2_meas (((quasiMeasurePreserving_sub_left_of_right_invariant ν x₀).ae hgk).mono fun t ht => ?_) simp_rw [convolution_def, mul_apply', mul_mul_mul_comm ‖L₃‖ ‖L₄‖, ← integral_mul_left] rw [Real.norm_of_nonneg (by positivity)] refine integral_mono_of_nonneg (eventually_of_forall fun t => norm_nonneg _) ((ht.const_mul _).const_mul _) (eventually_of_forall fun s => ?_) simp only [← mul_assoc ‖L₄‖] apply_rules [ContinuousLinearMap.le_of_opNorm₂_le_of_le, le_rfl] #align convolution_assoc MeasureTheory.convolution_assoc end Assoc variable [NormedAddCommGroup G] [BorelSpace G] theorem convolution_precompR_apply {g : G → E'' →L[𝕜] E'} (hf : LocallyIntegrable f μ) (hcg : HasCompactSupport g) (hg : Continuous g) (x₀ : G) (x : E'') : (f ⋆[L.precompR E'', μ] g) x₀ x = (f ⋆[L, μ] fun a => g a x) x₀ := by have := hcg.convolutionExists_right (L.precompR E'' : _) hf hg x₀ simp_rw [convolution_def, ContinuousLinearMap.integral_apply this] rfl set_option linter.uppercaseLean3 false in #align convolution_precompR_apply MeasureTheory.convolution_precompR_apply variable [NormedSpace 𝕜 G] [SigmaFinite μ] [IsAddLeftInvariant μ] /-- Compute the total derivative of `f ⋆ g` if `g` is `C^1` with compact support and `f` is locally integrable. To write down the total derivative as a convolution, we use `ContinuousLinearMap.precompR`. -/ theorem _root_.HasCompactSupport.hasFDerivAt_convolution_right (hcg : HasCompactSupport g) (hf : LocallyIntegrable f μ) (hg : ContDiff 𝕜 1 g) (x₀ : G) : HasFDerivAt (f ⋆[L, μ] g) ((f ⋆[L.precompR G, μ] fderiv 𝕜 g) x₀) x₀ := by rcases hcg.eq_zero_or_finiteDimensional 𝕜 hg.continuous with (rfl | fin_dim) · have : fderiv 𝕜 (0 : G → E') = 0 := fderiv_const (0 : E') simp only [this, convolution_zero, Pi.zero_apply] exact hasFDerivAt_const (0 : F) x₀ have : ProperSpace G := FiniteDimensional.proper_rclike 𝕜 G set L' := L.precompR G have h1 : ∀ᶠ x in 𝓝 x₀, AEStronglyMeasurable (fun t => L (f t) (g (x - t))) μ := eventually_of_forall (hf.aestronglyMeasurable.convolution_integrand_snd L hg.continuous.aestronglyMeasurable) have h2 : ∀ x, AEStronglyMeasurable (fun t => L' (f t) (fderiv 𝕜 g (x - t))) μ := hf.aestronglyMeasurable.convolution_integrand_snd L' (hg.continuous_fderiv le_rfl).aestronglyMeasurable have h3 : ∀ x t, HasFDerivAt (fun x => g (x - t)) (fderiv 𝕜 g (x - t)) x := fun x t ↦ by simpa using (hg.differentiable le_rfl).differentiableAt.hasFDerivAt.comp x ((hasFDerivAt_id x).sub (hasFDerivAt_const t x)) let K' := -tsupport (fderiv 𝕜 g) + closedBall x₀ 1 have hK' : IsCompact K' := (hcg.fderiv 𝕜).neg.add (isCompact_closedBall x₀ 1) -- Porting note: was -- `refine' hasFDerivAt_integral_of_dominated_of_fderiv_le zero_lt_one h1 _ (h2 x₀) _ _ _` -- but it failed; surprisingly, `apply` works apply hasFDerivAt_integral_of_dominated_of_fderiv_le zero_lt_one h1 _ (h2 x₀) · filter_upwards with t x hx using (hcg.fderiv 𝕜).convolution_integrand_bound_right L' (hg.continuous_fderiv le_rfl) (ball_subset_closedBall hx) · rw [integrable_indicator_iff hK'.measurableSet] exact ((hf.integrableOn_isCompact hK').norm.const_mul _).mul_const _ · exact eventually_of_forall fun t x _ => (L _).hasFDerivAt.comp x (h3 x t) · exact hcg.convolutionExists_right L hf hg.continuous x₀ #align has_compact_support.has_fderiv_at_convolution_right HasCompactSupport.hasFDerivAt_convolution_right theorem _root_.HasCompactSupport.hasFDerivAt_convolution_left [IsNegInvariant μ] (hcf : HasCompactSupport f) (hf : ContDiff 𝕜 1 f) (hg : LocallyIntegrable g μ) (x₀ : G) : HasFDerivAt (f ⋆[L, μ] g) ((fderiv 𝕜 f ⋆[L.precompL G, μ] g) x₀) x₀ := by simp (config := { singlePass := true }) only [← convolution_flip] exact hcf.hasFDerivAt_convolution_right L.flip hg hf x₀ #align has_compact_support.has_fderiv_at_convolution_left HasCompactSupport.hasFDerivAt_convolution_left end RCLike section Real /-! The one-variable case -/ variable [RCLike 𝕜] variable [NormedSpace 𝕜 E] variable [NormedSpace 𝕜 E'] variable [NormedSpace ℝ F] [NormedSpace 𝕜 F] variable {f₀ : 𝕜 → E} {g₀ : 𝕜 → E'} variable {n : ℕ∞} variable (L : E →L[𝕜] E' →L[𝕜] F) variable [CompleteSpace F] variable {μ : Measure 𝕜} variable [IsAddLeftInvariant μ] [SigmaFinite μ] theorem _root_.HasCompactSupport.hasDerivAt_convolution_right (hf : LocallyIntegrable f₀ μ) (hcg : HasCompactSupport g₀) (hg : ContDiff 𝕜 1 g₀) (x₀ : 𝕜) : HasDerivAt (f₀ ⋆[L, μ] g₀) ((f₀ ⋆[L, μ] deriv g₀) x₀) x₀ := by convert (hcg.hasFDerivAt_convolution_right L hf hg x₀).hasDerivAt using 1 rw [convolution_precompR_apply L hf (hcg.fderiv 𝕜) (hg.continuous_fderiv le_rfl)] rfl #align has_compact_support.has_deriv_at_convolution_right HasCompactSupport.hasDerivAt_convolution_right theorem _root_.HasCompactSupport.hasDerivAt_convolution_left [IsNegInvariant μ] (hcf : HasCompactSupport f₀) (hf : ContDiff 𝕜 1 f₀) (hg : LocallyIntegrable g₀ μ) (x₀ : 𝕜) : HasDerivAt (f₀ ⋆[L, μ] g₀) ((deriv f₀ ⋆[L, μ] g₀) x₀) x₀ := by simp (config := { singlePass := true }) only [← convolution_flip] exact hcf.hasDerivAt_convolution_right L.flip hg hf x₀ #align has_compact_support.has_deriv_at_convolution_left HasCompactSupport.hasDerivAt_convolution_left end Real section WithParam variable [RCLike 𝕜] [NormedSpace 𝕜 E] [NormedSpace 𝕜 E'] [NormedSpace 𝕜 E''] [NormedSpace ℝ F] [NormedSpace 𝕜 F] [CompleteSpace F] [MeasurableSpace G] [NormedAddCommGroup G] [BorelSpace G] [NormedSpace 𝕜 G] [NormedAddCommGroup P] [NormedSpace 𝕜 P] {μ : Measure G} (L : E →L[𝕜] E' →L[𝕜] F) /-- The derivative of the convolution `f * g` is given by `f * Dg`, when `f` is locally integrable and `g` is `C^1` and compactly supported. Version where `g` depends on an additional parameter in an open subset `s` of a parameter space `P` (and the compact support `k` is independent of the parameter in `s`). -/ theorem hasFDerivAt_convolution_right_with_param {g : P → G → E'} {s : Set P} {k : Set G} (hs : IsOpen s) (hk : IsCompact k) (hgs : ∀ p, ∀ x, p ∈ s → x ∉ k → g p x = 0) (hf : LocallyIntegrable f μ) (hg : ContDiffOn 𝕜 1 (↿g) (s ×ˢ univ)) (q₀ : P × G) (hq₀ : q₀.1 ∈ s) : HasFDerivAt (fun q : P × G => (f ⋆[L, μ] g q.1) q.2) ((f ⋆[L.precompR (P × G), μ] fun x : G => fderiv 𝕜 (↿g) (q₀.1, x)) q₀.2) q₀ := by let g' := fderiv 𝕜 ↿g have A : ∀ p ∈ s, Continuous (g p) := fun p hp ↦ by refine hg.continuousOn.comp_continuous (continuous_const.prod_mk continuous_id') fun x => ?_ simpa only [prod_mk_mem_set_prod_eq, mem_univ, and_true_iff] using hp have A' : ∀ q : P × G, q.1 ∈ s → s ×ˢ univ ∈ 𝓝 q := fun q hq ↦ by apply (hs.prod isOpen_univ).mem_nhds simpa only [mem_prod, mem_univ, and_true_iff] using hq -- The derivative of `g` vanishes away from `k`. have g'_zero : ∀ p x, p ∈ s → x ∉ k → g' (p, x) = 0 := by intro p x hp hx refine (hasFDerivAt_zero_of_eventually_const 0 ?_).fderiv have M2 : kᶜ ∈ 𝓝 x := hk.isClosed.isOpen_compl.mem_nhds hx have M1 : s ∈ 𝓝 p := hs.mem_nhds hp rw [nhds_prod_eq] filter_upwards [prod_mem_prod M1 M2] rintro ⟨p, y⟩ ⟨hp, hy⟩ exact hgs p y hp hy /- We find a small neighborhood of `{q₀.1} × k` on which the derivative is uniformly bounded. This follows from the continuity at all points of the compact set `k`. -/ obtain ⟨ε, C, εpos, h₀ε, hε⟩ : ∃ ε C, 0 < ε ∧ ball q₀.1 ε ⊆ s ∧ ∀ p x, ‖p - q₀.1‖ < ε → ‖g' (p, x)‖ ≤ C := by have A : IsCompact ({q₀.1} ×ˢ k) := isCompact_singleton.prod hk obtain ⟨t, kt, t_open, ht⟩ : ∃ t, {q₀.1} ×ˢ k ⊆ t ∧ IsOpen t ∧ IsBounded (g' '' t) := by have B : ContinuousOn g' (s ×ˢ univ) := hg.continuousOn_fderiv_of_isOpen (hs.prod isOpen_univ) le_rfl apply exists_isOpen_isBounded_image_of_isCompact_of_continuousOn A (hs.prod isOpen_univ) _ B simp only [prod_subset_prod_iff, hq₀, singleton_subset_iff, subset_univ, and_self_iff, true_or_iff] obtain ⟨ε, εpos, hε, h'ε⟩ : ∃ ε : ℝ, 0 < ε ∧ thickening ε ({q₀.fst} ×ˢ k) ⊆ t ∧ ball q₀.1 ε ⊆ s := by obtain ⟨ε, εpos, hε⟩ : ∃ ε : ℝ, 0 < ε ∧ thickening ε (({q₀.fst} : Set P) ×ˢ k) ⊆ t := A.exists_thickening_subset_open t_open kt obtain ⟨δ, δpos, hδ⟩ : ∃ δ : ℝ, 0 < δ ∧ ball q₀.1 δ ⊆ s := Metric.isOpen_iff.1 hs _ hq₀ refine ⟨min ε δ, lt_min εpos δpos, ?_, ?_⟩ · exact Subset.trans (thickening_mono (min_le_left _ _) _) hε · exact Subset.trans (ball_subset_ball (min_le_right _ _)) hδ obtain ⟨C, Cpos, hC⟩ : ∃ C, 0 < C ∧ g' '' t ⊆ closedBall 0 C := ht.subset_closedBall_lt 0 0 refine ⟨ε, C, εpos, h'ε, fun p x hp => ?_⟩ have hps : p ∈ s := h'ε (mem_ball_iff_norm.2 hp) by_cases hx : x ∈ k · have H : (p, x) ∈ t := by apply hε refine mem_thickening_iff.2 ⟨(q₀.1, x), ?_, ?_⟩ · simp only [hx, singleton_prod, mem_image, Prod.mk.inj_iff, eq_self_iff_true, true_and_iff, exists_eq_right] · rw [← dist_eq_norm] at hp simpa only [Prod.dist_eq, εpos, dist_self, max_lt_iff, and_true_iff] using hp have : g' (p, x) ∈ closedBall (0 : P × G →L[𝕜] E') C := hC (mem_image_of_mem _ H) rwa [mem_closedBall_zero_iff] at this · have : g' (p, x) = 0 := g'_zero _ _ hps hx rw [this] simpa only [norm_zero] using Cpos.le /- Now, we wish to apply a theorem on differentiation of integrals. For this, we need to check trivial measurability or integrability assumptions (in `I1`, `I2`, `I3`), as well as a uniform integrability assumption over the derivative (in `I4` and `I5`) and pointwise differentiability in `I6`. -/ have I1 : ∀ᶠ x : P × G in 𝓝 q₀, AEStronglyMeasurable (fun a : G => L (f a) (g x.1 (x.2 - a))) μ := by filter_upwards [A' q₀ hq₀] rintro ⟨p, x⟩ ⟨hp, -⟩ refine (HasCompactSupport.convolutionExists_right L ?_ hf (A _ hp) _).1 apply hk.of_isClosed_subset (isClosed_tsupport _) exact closure_minimal (support_subset_iff'.2 fun z hz => hgs _ _ hp hz) hk.isClosed have I2 : Integrable (fun a : G => L (f a) (g q₀.1 (q₀.2 - a))) μ := by have M : HasCompactSupport (g q₀.1) := HasCompactSupport.intro hk fun x hx => hgs q₀.1 x hq₀ hx apply M.convolutionExists_right L hf (A q₀.1 hq₀) q₀.2 have I3 : AEStronglyMeasurable (fun a : G => (L (f a)).comp (g' (q₀.fst, q₀.snd - a))) μ := by have T : HasCompactSupport fun y => g' (q₀.1, y) := HasCompactSupport.intro hk fun x hx => g'_zero q₀.1 x hq₀ hx apply (HasCompactSupport.convolutionExists_right (L.precompR (P × G) : _) T hf _ q₀.2).1 have : ContinuousOn g' (s ×ˢ univ) := hg.continuousOn_fderiv_of_isOpen (hs.prod isOpen_univ) le_rfl apply this.comp_continuous (continuous_const.prod_mk continuous_id') intro x simpa only [prod_mk_mem_set_prod_eq, mem_univ, and_true_iff] using hq₀ set K' := (-k + {q₀.2} : Set G) with K'_def have hK' : IsCompact K' := hk.neg.add isCompact_singleton obtain ⟨U, U_open, K'U, hU⟩ : ∃ U, IsOpen U ∧ K' ⊆ U ∧ IntegrableOn f U μ := hf.integrableOn_nhds_isCompact hK' obtain ⟨δ, δpos, δε, hδ⟩ : ∃ δ, (0 : ℝ) < δ ∧ δ ≤ ε ∧ K' + ball 0 δ ⊆ U := by obtain ⟨V, V_mem, hV⟩ : ∃ V ∈ 𝓝 (0 : G), K' + V ⊆ U := compact_open_separated_add_right hK' U_open K'U rcases Metric.mem_nhds_iff.1 V_mem with ⟨δ, δpos, hδ⟩ refine ⟨min δ ε, lt_min δpos εpos, min_le_right δ ε, ?_⟩ exact (add_subset_add_left ((ball_subset_ball (min_le_left _ _)).trans hδ)).trans hV -- Porting note: added to speed up the line below. letI := ContinuousLinearMap.hasOpNorm (𝕜 := 𝕜) (𝕜₂ := 𝕜) (E := E) (F := (P × G →L[𝕜] E') →L[𝕜] P × G →L[𝕜] F) (σ₁₂ := RingHom.id 𝕜) let bound : G → ℝ := indicator U fun t => ‖(L.precompR (P × G))‖ * ‖f t‖ * C have I4 : ∀ᵐ a : G ∂μ, ∀ x : P × G, dist x q₀ < δ → ‖L.precompR (P × G) (f a) (g' (x.fst, x.snd - a))‖ ≤ bound a := by filter_upwards with a x hx rw [Prod.dist_eq, dist_eq_norm, dist_eq_norm] at hx have : (-tsupport fun a => g' (x.1, a)) + ball q₀.2 δ ⊆ U := by apply Subset.trans _ hδ rw [K'_def, add_assoc] apply add_subset_add · rw [neg_subset_neg] refine closure_minimal (support_subset_iff'.2 fun z hz => ?_) hk.isClosed apply g'_zero x.1 z (h₀ε _) hz rw [mem_ball_iff_norm] exact ((le_max_left _ _).trans_lt hx).trans_le δε · simp only [add_ball, thickening_singleton, zero_vadd, subset_rfl] apply convolution_integrand_bound_right_of_le_of_subset _ _ _ this · intro y exact hε _ _ (((le_max_left _ _).trans_lt hx).trans_le δε) · rw [mem_ball_iff_norm] exact (le_max_right _ _).trans_lt hx have I5 : Integrable bound μ := by rw [integrable_indicator_iff U_open.measurableSet] exact (hU.norm.const_mul _).mul_const _ have I6 : ∀ᵐ a : G ∂μ, ∀ x : P × G, dist x q₀ < δ → HasFDerivAt (fun x : P × G => L (f a) (g x.1 (x.2 - a))) ((L (f a)).comp (g' (x.fst, x.snd - a))) x := by filter_upwards with a x hx apply (L _).hasFDerivAt.comp x have N : s ×ˢ univ ∈ 𝓝 (x.1, x.2 - a) := by apply A' apply h₀ε rw [Prod.dist_eq] at hx exact lt_of_lt_of_le (lt_of_le_of_lt (le_max_left _ _) hx) δε have Z := ((hg.differentiableOn le_rfl).differentiableAt N).hasFDerivAt have Z' : HasFDerivAt (fun x : P × G => (x.1, x.2 - a)) (ContinuousLinearMap.id 𝕜 (P × G)) x := by have : (fun x : P × G => (x.1, x.2 - a)) = _root_.id - fun x => (0, a) := by ext x <;> simp only [Pi.sub_apply, _root_.id, Prod.fst_sub, sub_zero, Prod.snd_sub] rw [this] exact (hasFDerivAt_id x).sub_const (0, a) exact Z.comp x Z' exact hasFDerivAt_integral_of_dominated_of_fderiv_le δpos I1 I2 I3 I4 I5 I6 #align has_fderiv_at_convolution_right_with_param MeasureTheory.hasFDerivAt_convolution_right_with_param /-- The convolution `f * g` is `C^n` when `f` is locally integrable and `g` is `C^n` and compactly supported. Version where `g` depends on an additional parameter in an open subset `s` of a parameter space `P` (and the compact support `k` is independent of the parameter in `s`). In this version, all the types belong to the same universe (to get an induction working in the proof). Use instead `contDiffOn_convolution_right_with_param`, which removes this restriction. -/ theorem contDiffOn_convolution_right_with_param_aux {G : Type uP} {E' : Type uP} {F : Type uP} {P : Type uP} [NormedAddCommGroup E'] [NormedAddCommGroup F] [NormedSpace 𝕜 E'] [NormedSpace ℝ F] [NormedSpace 𝕜 F] [CompleteSpace F] [MeasurableSpace G] {μ : Measure G} [NormedAddCommGroup G] [BorelSpace G] [NormedSpace 𝕜 G] [NormedAddCommGroup P] [NormedSpace 𝕜 P] {f : G → E} {n : ℕ∞} (L : E →L[𝕜] E' →L[𝕜] F) {g : P → G → E'} {s : Set P} {k : Set G} (hs : IsOpen s) (hk : IsCompact k) (hgs : ∀ p, ∀ x, p ∈ s → x ∉ k → g p x = 0) (hf : LocallyIntegrable f μ) (hg : ContDiffOn 𝕜 n (↿g) (s ×ˢ univ)) : ContDiffOn 𝕜 n (fun q : P × G => (f ⋆[L, μ] g q.1) q.2) (s ×ˢ univ) := by /- We have a formula for the derivation of `f * g`, which is of the same form, thanks to `hasFDerivAt_convolution_right_with_param`. Therefore, we can prove the result by induction on `n` (but for this we need the spaces at the different steps of the induction to live in the same universe, which is why we make the assumption in the lemma that all the relevant spaces come from the same universe). -/ induction' n using ENat.nat_induction with n ih ih generalizing g E' F · rw [contDiffOn_zero] at hg ⊢ exact continuousOn_convolution_right_with_param L hk hgs hf hg · let f' : P → G → P × G →L[𝕜] F := fun p a => (f ⋆[L.precompR (P × G), μ] fun x : G => fderiv 𝕜 (uncurry g) (p, x)) a have A : ∀ q₀ : P × G, q₀.1 ∈ s → HasFDerivAt (fun q : P × G => (f ⋆[L, μ] g q.1) q.2) (f' q₀.1 q₀.2) q₀ := hasFDerivAt_convolution_right_with_param L hs hk hgs hf hg.one_of_succ rw [contDiffOn_succ_iff_fderiv_of_isOpen (hs.prod (@isOpen_univ G _))] at hg ⊢ constructor · rintro ⟨p, x⟩ ⟨hp, -⟩ exact (A (p, x) hp).differentiableAt.differentiableWithinAt · suffices H : ContDiffOn 𝕜 n (↿f') (s ×ˢ univ) by apply H.congr rintro ⟨p, x⟩ ⟨hp, -⟩ exact (A (p, x) hp).fderiv have B : ∀ (p : P) (x : G), p ∈ s → x ∉ k → fderiv 𝕜 (uncurry g) (p, x) = 0 := by intro p x hp hx apply (hasFDerivAt_zero_of_eventually_const (0 : E') _).fderiv have M2 : kᶜ ∈ 𝓝 x := IsOpen.mem_nhds hk.isClosed.isOpen_compl hx have M1 : s ∈ 𝓝 p := hs.mem_nhds hp rw [nhds_prod_eq] filter_upwards [prod_mem_prod M1 M2] rintro ⟨p, y⟩ ⟨hp, hy⟩ exact hgs p y hp hy apply ih (L.precompR (P × G) : _) B convert hg.2 · rw [contDiffOn_top] at hg ⊢ intro n exact ih n L hgs (hg n) #align cont_diff_on_convolution_right_with_param_aux MeasureTheory.contDiffOn_convolution_right_with_param_aux /-- The convolution `f * g` is `C^n` when `f` is locally integrable and `g` is `C^n` and compactly supported. Version where `g` depends on an additional parameter in an open subset `s` of a parameter space `P` (and the compact support `k` is independent of the parameter in `s`). -/ theorem contDiffOn_convolution_right_with_param {f : G → E} {n : ℕ∞} (L : E →L[𝕜] E' →L[𝕜] F) {g : P → G → E'} {s : Set P} {k : Set G} (hs : IsOpen s) (hk : IsCompact k) (hgs : ∀ p, ∀ x, p ∈ s → x ∉ k → g p x = 0) (hf : LocallyIntegrable f μ) (hg : ContDiffOn 𝕜 n (↿g) (s ×ˢ univ)) : ContDiffOn 𝕜 n (fun q : P × G => (f ⋆[L, μ] g q.1) q.2) (s ×ˢ univ) := by /- The result is known when all the universes are the same, from `contDiffOn_convolution_right_with_param_aux`. We reduce to this situation by pushing everything through `ULift` continuous linear equivalences. -/ let eG : Type max uG uE' uF uP := ULift.{max uE' uF uP} G borelize eG let eE' : Type max uE' uG uF uP := ULift.{max uG uF uP} E' let eF : Type max uF uG uE' uP := ULift.{max uG uE' uP} F let eP : Type max uP uG uE' uF := ULift.{max uG uE' uF} P have isoG : eG ≃L[𝕜] G := ContinuousLinearEquiv.ulift have isoE' : eE' ≃L[𝕜] E' := ContinuousLinearEquiv.ulift have isoF : eF ≃L[𝕜] F := ContinuousLinearEquiv.ulift have isoP : eP ≃L[𝕜] P := ContinuousLinearEquiv.ulift let ef := f ∘ isoG let eμ : Measure eG := Measure.map isoG.symm μ let eg : eP → eG → eE' := fun ep ex => isoE'.symm (g (isoP ep) (isoG ex)) let eL := ContinuousLinearMap.comp ((ContinuousLinearEquiv.arrowCongr isoE' isoF).symm : (E' →L[𝕜] F) →L[𝕜] eE' →L[𝕜] eF) L let R := fun q : eP × eG => (ef ⋆[eL, eμ] eg q.1) q.2 have R_contdiff : ContDiffOn 𝕜 n R ((isoP ⁻¹' s) ×ˢ univ) := by have hek : IsCompact (isoG ⁻¹' k) := isoG.toHomeomorph.closedEmbedding.isCompact_preimage hk have hes : IsOpen (isoP ⁻¹' s) := isoP.continuous.isOpen_preimage _ hs refine contDiffOn_convolution_right_with_param_aux eL hes hek ?_ ?_ ?_ · intro p x hp hx simp only [eg, (· ∘ ·), ContinuousLinearEquiv.prod_apply, LinearIsometryEquiv.coe_coe, ContinuousLinearEquiv.map_eq_zero_iff] exact hgs _ _ hp hx · apply (locallyIntegrable_map_homeomorph isoG.symm.toHomeomorph).2 convert hf ext1 x simp only [ef, ContinuousLinearEquiv.coe_toHomeomorph, (· ∘ ·), ContinuousLinearEquiv.apply_symm_apply] · apply isoE'.symm.contDiff.comp_contDiffOn apply hg.comp (isoP.prod isoG).contDiff.contDiffOn rintro ⟨p, x⟩ ⟨hp, -⟩ simpa only [mem_preimage, ContinuousLinearEquiv.prod_apply, prod_mk_mem_set_prod_eq, mem_univ, and_true_iff] using hp have A : ContDiffOn 𝕜 n (isoF ∘ R ∘ (isoP.prod isoG).symm) (s ×ˢ univ) := by apply isoF.contDiff.comp_contDiffOn apply R_contdiff.comp (ContinuousLinearEquiv.contDiff _).contDiffOn rintro ⟨p, x⟩ ⟨hp, -⟩ simpa only [mem_preimage, mem_prod, mem_univ, and_true_iff, ContinuousLinearEquiv.prod_symm, ContinuousLinearEquiv.prod_apply, ContinuousLinearEquiv.apply_symm_apply] using hp have : isoF ∘ R ∘ (isoP.prod isoG).symm = fun q : P × G => (f ⋆[L, μ] g q.1) q.2 := by apply funext rintro ⟨p, x⟩ simp only [LinearIsometryEquiv.coe_coe, (· ∘ ·), ContinuousLinearEquiv.prod_symm, ContinuousLinearEquiv.prod_apply] simp only [R, convolution, coe_comp', ContinuousLinearEquiv.coe_coe, (· ∘ ·)] rw [ClosedEmbedding.integral_map, ← isoF.integral_comp_comm] swap; · exact isoG.symm.toHomeomorph.closedEmbedding congr 1 ext1 a simp only [ef, eg, eL, (· ∘ ·), ContinuousLinearEquiv.apply_symm_apply, coe_comp', ContinuousLinearEquiv.prod_apply, ContinuousLinearEquiv.map_sub, ContinuousLinearEquiv.arrowCongr, ContinuousLinearEquiv.arrowCongrSL_symm_apply, ContinuousLinearEquiv.coe_coe, Function.comp_apply, ContinuousLinearEquiv.apply_symm_apply] simp_rw [this] at A exact A #align cont_diff_on_convolution_right_with_param MeasureTheory.contDiffOn_convolution_right_with_param /-- The convolution `f * g` is `C^n` when `f` is locally integrable and `g` is `C^n` and compactly supported. Version where `g` depends on an additional parameter in an open subset `s` of a parameter space `P` (and the compact support `k` is independent of the parameter in `s`), given in terms of composition with an additional smooth function. -/ theorem contDiffOn_convolution_right_with_param_comp {n : ℕ∞} (L : E →L[𝕜] E' →L[𝕜] F) {s : Set P} {v : P → G} (hv : ContDiffOn 𝕜 n v s) {f : G → E} {g : P → G → E'} {k : Set G} (hs : IsOpen s) (hk : IsCompact k) (hgs : ∀ p, ∀ x, p ∈ s → x ∉ k → g p x = 0) (hf : LocallyIntegrable f μ) (hg : ContDiffOn 𝕜 n (↿g) (s ×ˢ univ)) : ContDiffOn 𝕜 n (fun x => (f ⋆[L, μ] g x) (v x)) s := by apply (contDiffOn_convolution_right_with_param L hs hk hgs hf hg).comp (contDiffOn_id.prod hv) intro x hx simp only [hx, mem_preimage, prod_mk_mem_set_prod_eq, mem_univ, and_self_iff, _root_.id] #align cont_diff_on_convolution_right_with_param_comp MeasureTheory.contDiffOn_convolution_right_with_param_comp /-- The convolution `g * f` is `C^n` when `f` is locally integrable and `g` is `C^n` and compactly supported. Version where `g` depends on an additional parameter in an open subset `s` of a parameter space `P` (and the compact support `k` is independent of the parameter in `s`). -/ theorem contDiffOn_convolution_left_with_param [μ.IsAddLeftInvariant] [μ.IsNegInvariant] (L : E' →L[𝕜] E →L[𝕜] F) {f : G → E} {n : ℕ∞} {g : P → G → E'} {s : Set P} {k : Set G} (hs : IsOpen s) (hk : IsCompact k) (hgs : ∀ p, ∀ x, p ∈ s → x ∉ k → g p x = 0) (hf : LocallyIntegrable f μ) (hg : ContDiffOn 𝕜 n (↿g) (s ×ˢ univ)) : ContDiffOn 𝕜 n (fun q : P × G => (g q.1 ⋆[L, μ] f) q.2) (s ×ˢ univ) := by simpa only [convolution_flip] using contDiffOn_convolution_right_with_param L.flip hs hk hgs hf hg #align cont_diff_on_convolution_left_with_param MeasureTheory.contDiffOn_convolution_left_with_param /-- The convolution `g * f` is `C^n` when `f` is locally integrable and `g` is `C^n` and compactly supported. Version where `g` depends on an additional parameter in an open subset `s` of a parameter space `P` (and the compact support `k` is independent of the parameter in `s`), given in terms of composition with additional smooth functions. -/ theorem contDiffOn_convolution_left_with_param_comp [μ.IsAddLeftInvariant] [μ.IsNegInvariant] (L : E' →L[𝕜] E →L[𝕜] F) {s : Set P} {n : ℕ∞} {v : P → G} (hv : ContDiffOn 𝕜 n v s) {f : G → E} {g : P → G → E'} {k : Set G} (hs : IsOpen s) (hk : IsCompact k) (hgs : ∀ p, ∀ x, p ∈ s → x ∉ k → g p x = 0) (hf : LocallyIntegrable f μ) (hg : ContDiffOn 𝕜 n (↿g) (s ×ˢ univ)) : ContDiffOn 𝕜 n (fun x => (g x ⋆[L, μ] f) (v x)) s := by apply (contDiffOn_convolution_left_with_param L hs hk hgs hf hg).comp (contDiffOn_id.prod hv) intro x hx simp only [hx, mem_preimage, prod_mk_mem_set_prod_eq, mem_univ, and_self_iff, _root_.id] #align cont_diff_on_convolution_left_with_param_comp MeasureTheory.contDiffOn_convolution_left_with_param_comp theorem _root_.HasCompactSupport.contDiff_convolution_right {n : ℕ∞} (hcg : HasCompactSupport g) (hf : LocallyIntegrable f μ) (hg : ContDiff 𝕜 n g) : ContDiff 𝕜 n (f ⋆[L, μ] g) := by rcases exists_compact_iff_hasCompactSupport.2 hcg with ⟨k, hk, h'k⟩ rw [← contDiffOn_univ] exact contDiffOn_convolution_right_with_param_comp L contDiffOn_id isOpen_univ hk (fun p x _ hx => h'k x hx) hf (hg.comp contDiff_snd).contDiffOn #align has_compact_support.cont_diff_convolution_right HasCompactSupport.contDiff_convolution_right
Mathlib/Analysis/Convolution.lean
1,410
1,414
theorem _root_.HasCompactSupport.contDiff_convolution_left [μ.IsAddLeftInvariant] [μ.IsNegInvariant] {n : ℕ∞} (hcf : HasCompactSupport f) (hf : ContDiff 𝕜 n f) (hg : LocallyIntegrable g μ) : ContDiff 𝕜 n (f ⋆[L, μ] g) := by
rw [← convolution_flip] exact hcf.contDiff_convolution_right L.flip hg hf
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Mario Carneiro -/ import Mathlib.Data.FunLike.Equiv import Mathlib.Data.Quot import Mathlib.Init.Data.Bool.Lemmas import Mathlib.Logic.Unique import Mathlib.Tactic.Substs import Mathlib.Tactic.Conv #align_import logic.equiv.defs from "leanprover-community/mathlib"@"48fb5b5280e7c81672afc9524185ae994553ebf4" /-! # Equivalence between types In this file we define two types: * `Equiv α β` a.k.a. `α ≃ β`: a bijective map `α → β` bundled with its inverse map; we use this (and not equality!) to express that various `Type`s or `Sort`s are equivalent. * `Equiv.Perm α`: the group of permutations `α ≃ α`. More lemmas about `Equiv.Perm` can be found in `GroupTheory.Perm`. Then we define * canonical isomorphisms between various types: e.g., - `Equiv.refl α` is the identity map interpreted as `α ≃ α`; * operations on equivalences: e.g., - `Equiv.symm e : β ≃ α` is the inverse of `e : α ≃ β`; - `Equiv.trans e₁ e₂ : α ≃ γ` is the composition of `e₁ : α ≃ β` and `e₂ : β ≃ γ` (note the order of the arguments!); * definitions that transfer some instances along an equivalence. By convention, we transfer instances from right to left. - `Equiv.inhabited` takes `e : α ≃ β` and `[Inhabited β]` and returns `Inhabited α`; - `Equiv.unique` takes `e : α ≃ β` and `[Unique β]` and returns `Unique α`; - `Equiv.decidableEq` takes `e : α ≃ β` and `[DecidableEq β]` and returns `DecidableEq α`. More definitions of this kind can be found in other files. E.g., `Data.Equiv.TransferInstance` does it for many algebraic type classes like `Group`, `Module`, etc. Many more such isomorphisms and operations are defined in `Logic.Equiv.Basic`. ## Tags equivalence, congruence, bijective map -/ open Function universe u v w z variable {α : Sort u} {β : Sort v} {γ : Sort w} /-- `α ≃ β` is the type of functions from `α → β` with a two-sided inverse. -/ structure Equiv (α : Sort*) (β : Sort _) where protected toFun : α → β protected invFun : β → α protected left_inv : LeftInverse invFun toFun protected right_inv : RightInverse invFun toFun #align equiv Equiv @[inherit_doc] infixl:25 " ≃ " => Equiv /-- Turn an element of a type `F` satisfying `EquivLike F α β` into an actual `Equiv`. This is declared as the default coercion from `F` to `α ≃ β`. -/ @[coe] def EquivLike.toEquiv {F} [EquivLike F α β] (f : F) : α ≃ β where toFun := f invFun := EquivLike.inv f left_inv := EquivLike.left_inv f right_inv := EquivLike.right_inv f /-- Any type satisfying `EquivLike` can be cast into `Equiv` via `EquivLike.toEquiv`. -/ instance {F} [EquivLike F α β] : CoeTC F (α ≃ β) := ⟨EquivLike.toEquiv⟩ /-- `Perm α` is the type of bijections from `α` to itself. -/ abbrev Equiv.Perm (α : Sort*) := Equiv α α #align equiv.perm Equiv.Perm namespace Equiv instance : EquivLike (α ≃ β) α β where coe := Equiv.toFun inv := Equiv.invFun left_inv := Equiv.left_inv right_inv := Equiv.right_inv coe_injective' e₁ e₂ h₁ h₂ := by cases e₁; cases e₂; congr /-- Helper instance when inference gets stuck on following the normal chain `EquivLike → FunLike`. TODO: this instance doesn't appear to be necessary: remove it (after benchmarking?) -/ instance : FunLike (α ≃ β) α β where coe := Equiv.toFun coe_injective' := DFunLike.coe_injective @[simp, norm_cast] lemma _root_.EquivLike.coe_coe {F} [EquivLike F α β] (e : F) : ((e : α ≃ β) : α → β) = e := rfl @[simp] theorem coe_fn_mk (f : α → β) (g l r) : (Equiv.mk f g l r : α → β) = f := rfl #align equiv.coe_fn_mk Equiv.coe_fn_mk /-- The map `(r ≃ s) → (r → s)` is injective. -/ theorem coe_fn_injective : @Function.Injective (α ≃ β) (α → β) (fun e => e) := DFunLike.coe_injective' #align equiv.coe_fn_injective Equiv.coe_fn_injective protected theorem coe_inj {e₁ e₂ : α ≃ β} : (e₁ : α → β) = e₂ ↔ e₁ = e₂ := @DFunLike.coe_fn_eq _ _ _ _ e₁ e₂ #align equiv.coe_inj Equiv.coe_inj @[ext] theorem ext {f g : Equiv α β} (H : ∀ x, f x = g x) : f = g := DFunLike.ext f g H #align equiv.ext Equiv.ext protected theorem congr_arg {f : Equiv α β} {x x' : α} : x = x' → f x = f x' := DFunLike.congr_arg f #align equiv.congr_arg Equiv.congr_arg protected theorem congr_fun {f g : Equiv α β} (h : f = g) (x : α) : f x = g x := DFunLike.congr_fun h x #align equiv.congr_fun Equiv.congr_fun theorem ext_iff {f g : Equiv α β} : f = g ↔ ∀ x, f x = g x := DFunLike.ext_iff #align equiv.ext_iff Equiv.ext_iff @[ext] theorem Perm.ext {σ τ : Equiv.Perm α} (H : ∀ x, σ x = τ x) : σ = τ := Equiv.ext H #align equiv.perm.ext Equiv.Perm.ext protected theorem Perm.congr_arg {f : Equiv.Perm α} {x x' : α} : x = x' → f x = f x' := Equiv.congr_arg #align equiv.perm.congr_arg Equiv.Perm.congr_arg protected theorem Perm.congr_fun {f g : Equiv.Perm α} (h : f = g) (x : α) : f x = g x := Equiv.congr_fun h x #align equiv.perm.congr_fun Equiv.Perm.congr_fun theorem Perm.ext_iff {σ τ : Equiv.Perm α} : σ = τ ↔ ∀ x, σ x = τ x := Equiv.ext_iff #align equiv.perm.ext_iff Equiv.Perm.ext_iff /-- Any type is equivalent to itself. -/ @[refl] protected def refl (α : Sort*) : α ≃ α := ⟨id, id, fun _ => rfl, fun _ => rfl⟩ #align equiv.refl Equiv.refl instance inhabited' : Inhabited (α ≃ α) := ⟨Equiv.refl α⟩ /-- Inverse of an equivalence `e : α ≃ β`. -/ @[symm] protected def symm (e : α ≃ β) : β ≃ α := ⟨e.invFun, e.toFun, e.right_inv, e.left_inv⟩ #align equiv.symm Equiv.symm /-- See Note [custom simps projection] -/ def Simps.symm_apply (e : α ≃ β) : β → α := e.symm #align equiv.simps.symm_apply Equiv.Simps.symm_apply initialize_simps_projections Equiv (toFun → apply, invFun → symm_apply) -- Porting note: -- Added these lemmas as restatements of `left_inv` and `right_inv`, -- which use the coercions. -- We might even consider switching the names, and having these as a public API. theorem left_inv' (e : α ≃ β) : Function.LeftInverse e.symm e := e.left_inv theorem right_inv' (e : α ≃ β) : Function.RightInverse e.symm e := e.right_inv /-- Composition of equivalences `e₁ : α ≃ β` and `e₂ : β ≃ γ`. -/ @[trans] protected def trans (e₁ : α ≃ β) (e₂ : β ≃ γ) : α ≃ γ := ⟨e₂ ∘ e₁, e₁.symm ∘ e₂.symm, e₂.left_inv.comp e₁.left_inv, e₂.right_inv.comp e₁.right_inv⟩ #align equiv.trans Equiv.trans @[simps] instance : Trans Equiv Equiv Equiv where trans := Equiv.trans -- Porting note: this is not a syntactic tautology any more because -- the coercion from `e` to a function is now `DFunLike.coe` not `e.toFun` @[simp, mfld_simps] theorem toFun_as_coe (e : α ≃ β) : e.toFun = e := rfl #align equiv.to_fun_as_coe Equiv.toFun_as_coe @[simp, mfld_simps] theorem invFun_as_coe (e : α ≃ β) : e.invFun = e.symm := rfl #align equiv.inv_fun_as_coe Equiv.invFun_as_coe protected theorem injective (e : α ≃ β) : Injective e := EquivLike.injective e #align equiv.injective Equiv.injective protected theorem surjective (e : α ≃ β) : Surjective e := EquivLike.surjective e #align equiv.surjective Equiv.surjective protected theorem bijective (e : α ≃ β) : Bijective e := EquivLike.bijective e #align equiv.bijective Equiv.bijective protected theorem subsingleton (e : α ≃ β) [Subsingleton β] : Subsingleton α := e.injective.subsingleton #align equiv.subsingleton Equiv.subsingleton protected theorem subsingleton.symm (e : α ≃ β) [Subsingleton α] : Subsingleton β := e.symm.injective.subsingleton #align equiv.subsingleton.symm Equiv.subsingleton.symm theorem subsingleton_congr (e : α ≃ β) : Subsingleton α ↔ Subsingleton β := ⟨fun _ => e.symm.subsingleton, fun _ => e.subsingleton⟩ #align equiv.subsingleton_congr Equiv.subsingleton_congr instance equiv_subsingleton_cod [Subsingleton β] : Subsingleton (α ≃ β) := ⟨fun _ _ => Equiv.ext fun _ => Subsingleton.elim _ _⟩ instance equiv_subsingleton_dom [Subsingleton α] : Subsingleton (α ≃ β) := ⟨fun f _ => Equiv.ext fun _ => @Subsingleton.elim _ (Equiv.subsingleton.symm f) _ _⟩ instance permUnique [Subsingleton α] : Unique (Perm α) := uniqueOfSubsingleton (Equiv.refl α) theorem Perm.subsingleton_eq_refl [Subsingleton α] (e : Perm α) : e = Equiv.refl α := Subsingleton.elim _ _ #align equiv.perm.subsingleton_eq_refl Equiv.Perm.subsingleton_eq_refl /-- Transfer `DecidableEq` across an equivalence. -/ protected def decidableEq (e : α ≃ β) [DecidableEq β] : DecidableEq α := e.injective.decidableEq #align equiv.decidable_eq Equiv.decidableEq theorem nonempty_congr (e : α ≃ β) : Nonempty α ↔ Nonempty β := Nonempty.congr e e.symm #align equiv.nonempty_congr Equiv.nonempty_congr protected theorem nonempty (e : α ≃ β) [Nonempty β] : Nonempty α := e.nonempty_congr.mpr ‹_› #align equiv.nonempty Equiv.nonempty /-- If `α ≃ β` and `β` is inhabited, then so is `α`. -/ protected def inhabited [Inhabited β] (e : α ≃ β) : Inhabited α := ⟨e.symm default⟩ #align equiv.inhabited Equiv.inhabited /-- If `α ≃ β` and `β` is a singleton type, then so is `α`. -/ protected def unique [Unique β] (e : α ≃ β) : Unique α := e.symm.surjective.unique #align equiv.unique Equiv.unique /-- Equivalence between equal types. -/ protected def cast {α β : Sort _} (h : α = β) : α ≃ β := ⟨cast h, cast h.symm, fun _ => by cases h; rfl, fun _ => by cases h; rfl⟩ #align equiv.cast Equiv.cast @[simp] theorem coe_fn_symm_mk (f : α → β) (g l r) : ((Equiv.mk f g l r).symm : β → α) = g := rfl #align equiv.coe_fn_symm_mk Equiv.coe_fn_symm_mk @[simp] theorem coe_refl : (Equiv.refl α : α → α) = id := rfl #align equiv.coe_refl Equiv.coe_refl /-- This cannot be a `simp` lemmas as it incorrectly matches against `e : α ≃ synonym α`, when `synonym α` is semireducible. This makes a mess of `Multiplicative.ofAdd` etc. -/ theorem Perm.coe_subsingleton {α : Type*} [Subsingleton α] (e : Perm α) : (e : α → α) = id := by rw [Perm.subsingleton_eq_refl e, coe_refl] #align equiv.perm.coe_subsingleton Equiv.Perm.coe_subsingleton -- Porting note: marking this as `@[simp]` because `simp` doesn't fire on `coe_refl` -- in an expression such as `Equiv.refl a x` @[simp] theorem refl_apply (x : α) : Equiv.refl α x = x := rfl #align equiv.refl_apply Equiv.refl_apply @[simp] theorem coe_trans (f : α ≃ β) (g : β ≃ γ) : (f.trans g : α → γ) = g ∘ f := rfl #align equiv.coe_trans Equiv.coe_trans -- Porting note: marking this as `@[simp]` because `simp` doesn't fire on `coe_trans` -- in an expression such as `Equiv.trans f g x` @[simp] theorem trans_apply (f : α ≃ β) (g : β ≃ γ) (a : α) : (f.trans g) a = g (f a) := rfl #align equiv.trans_apply Equiv.trans_apply @[simp] theorem apply_symm_apply (e : α ≃ β) (x : β) : e (e.symm x) = x := e.right_inv x #align equiv.apply_symm_apply Equiv.apply_symm_apply @[simp] theorem symm_apply_apply (e : α ≃ β) (x : α) : e.symm (e x) = x := e.left_inv x #align equiv.symm_apply_apply Equiv.symm_apply_apply @[simp] theorem symm_comp_self (e : α ≃ β) : e.symm ∘ e = id := funext e.symm_apply_apply #align equiv.symm_comp_self Equiv.symm_comp_self @[simp] theorem self_comp_symm (e : α ≃ β) : e ∘ e.symm = id := funext e.apply_symm_apply #align equiv.self_comp_symm Equiv.self_comp_symm @[simp] lemma _root_.EquivLike.apply_coe_symm_apply {F} [EquivLike F α β] (e : F) (x : β) : e ((e : α ≃ β).symm x) = x := (e : α ≃ β).apply_symm_apply x @[simp] lemma _root_.EquivLike.coe_symm_apply_apply {F} [EquivLike F α β] (e : F) (x : α) : (e : α ≃ β).symm (e x) = x := (e : α ≃ β).symm_apply_apply x @[simp] lemma _root_.EquivLike.coe_symm_comp_self {F} [EquivLike F α β] (e : F) : (e : α ≃ β).symm ∘ e = id := (e : α ≃ β).symm_comp_self @[simp] lemma _root_.EquivLike.self_comp_coe_symm {F} [EquivLike F α β] (e : F) : e ∘ (e : α ≃ β).symm = id := (e : α ≃ β).self_comp_symm @[simp] theorem symm_trans_apply (f : α ≃ β) (g : β ≃ γ) (a : γ) : (f.trans g).symm a = f.symm (g.symm a) := rfl #align equiv.symm_trans_apply Equiv.symm_trans_apply -- The `simp` attribute is needed to make this a `dsimp` lemma. -- `simp` will always rewrite with `Equiv.symm_symm` before this has a chance to fire. @[simp, nolint simpNF] theorem symm_symm_apply (f : α ≃ β) (b : α) : f.symm.symm b = f b := rfl #align equiv.symm_symm_apply Equiv.symm_symm_apply theorem apply_eq_iff_eq (f : α ≃ β) {x y : α} : f x = f y ↔ x = y := EquivLike.apply_eq_iff_eq f #align equiv.apply_eq_iff_eq Equiv.apply_eq_iff_eq theorem apply_eq_iff_eq_symm_apply {x : α} {y : β} (f : α ≃ β) : f x = y ↔ x = f.symm y := by conv_lhs => rw [← apply_symm_apply f y] rw [apply_eq_iff_eq] #align equiv.apply_eq_iff_eq_symm_apply Equiv.apply_eq_iff_eq_symm_apply @[simp] theorem cast_apply {α β} (h : α = β) (x : α) : Equiv.cast h x = cast h x := rfl #align equiv.cast_apply Equiv.cast_apply @[simp] theorem cast_symm {α β} (h : α = β) : (Equiv.cast h).symm = Equiv.cast h.symm := rfl #align equiv.cast_symm Equiv.cast_symm @[simp] theorem cast_refl {α} (h : α = α := rfl) : Equiv.cast h = Equiv.refl α := rfl #align equiv.cast_refl Equiv.cast_refl @[simp] theorem cast_trans {α β γ} (h : α = β) (h2 : β = γ) : (Equiv.cast h).trans (Equiv.cast h2) = Equiv.cast (h.trans h2) := ext fun x => by substs h h2; rfl #align equiv.cast_trans Equiv.cast_trans theorem cast_eq_iff_heq {α β} (h : α = β) {a : α} {b : β} : Equiv.cast h a = b ↔ HEq a b := by subst h; simp [coe_refl] #align equiv.cast_eq_iff_heq Equiv.cast_eq_iff_heq theorem symm_apply_eq {α β} (e : α ≃ β) {x y} : e.symm x = y ↔ x = e y := ⟨fun H => by simp [H.symm], fun H => by simp [H]⟩ #align equiv.symm_apply_eq Equiv.symm_apply_eq theorem eq_symm_apply {α β} (e : α ≃ β) {x y} : y = e.symm x ↔ e y = x := (eq_comm.trans e.symm_apply_eq).trans eq_comm #align equiv.eq_symm_apply Equiv.eq_symm_apply @[simp] theorem symm_symm (e : α ≃ β) : e.symm.symm = e := by cases e; rfl #align equiv.symm_symm Equiv.symm_symm theorem symm_bijective : Function.Bijective (Equiv.symm : (α ≃ β) → β ≃ α) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ @[simp] theorem trans_refl (e : α ≃ β) : e.trans (Equiv.refl β) = e := by cases e; rfl #align equiv.trans_refl Equiv.trans_refl @[simp] theorem refl_symm : (Equiv.refl α).symm = Equiv.refl α := rfl #align equiv.refl_symm Equiv.refl_symm @[simp] theorem refl_trans (e : α ≃ β) : (Equiv.refl α).trans e = e := by cases e; rfl #align equiv.refl_trans Equiv.refl_trans @[simp] theorem symm_trans_self (e : α ≃ β) : e.symm.trans e = Equiv.refl β := ext <| by simp #align equiv.symm_trans_self Equiv.symm_trans_self @[simp] theorem self_trans_symm (e : α ≃ β) : e.trans e.symm = Equiv.refl α := ext <| by simp #align equiv.self_trans_symm Equiv.self_trans_symm theorem trans_assoc {δ} (ab : α ≃ β) (bc : β ≃ γ) (cd : γ ≃ δ) : (ab.trans bc).trans cd = ab.trans (bc.trans cd) := Equiv.ext fun _ => rfl #align equiv.trans_assoc Equiv.trans_assoc theorem leftInverse_symm (f : Equiv α β) : LeftInverse f.symm f := f.left_inv #align equiv.left_inverse_symm Equiv.leftInverse_symm theorem rightInverse_symm (f : Equiv α β) : Function.RightInverse f.symm f := f.right_inv #align equiv.right_inverse_symm Equiv.rightInverse_symm theorem injective_comp (e : α ≃ β) (f : β → γ) : Injective (f ∘ e) ↔ Injective f := EquivLike.injective_comp e f #align equiv.injective_comp Equiv.injective_comp theorem comp_injective (f : α → β) (e : β ≃ γ) : Injective (e ∘ f) ↔ Injective f := EquivLike.comp_injective f e #align equiv.comp_injective Equiv.comp_injective theorem surjective_comp (e : α ≃ β) (f : β → γ) : Surjective (f ∘ e) ↔ Surjective f := EquivLike.surjective_comp e f #align equiv.surjective_comp Equiv.surjective_comp theorem comp_surjective (f : α → β) (e : β ≃ γ) : Surjective (e ∘ f) ↔ Surjective f := EquivLike.comp_surjective f e #align equiv.comp_surjective Equiv.comp_surjective theorem bijective_comp (e : α ≃ β) (f : β → γ) : Bijective (f ∘ e) ↔ Bijective f := EquivLike.bijective_comp e f #align equiv.bijective_comp Equiv.bijective_comp theorem comp_bijective (f : α → β) (e : β ≃ γ) : Bijective (e ∘ f) ↔ Bijective f := EquivLike.comp_bijective f e #align equiv.comp_bijective Equiv.comp_bijective /-- If `α` is equivalent to `β` and `γ` is equivalent to `δ`, then the type of equivalences `α ≃ γ` is equivalent to the type of equivalences `β ≃ δ`. -/ def equivCongr {δ : Sort*} (ab : α ≃ β) (cd : γ ≃ δ) : (α ≃ γ) ≃ (β ≃ δ) where toFun ac := (ab.symm.trans ac).trans cd invFun bd := ab.trans <| bd.trans <| cd.symm left_inv ac := by ext x; simp only [trans_apply, comp_apply, symm_apply_apply] right_inv ac := by ext x; simp only [trans_apply, comp_apply, apply_symm_apply] #align equiv.equiv_congr Equiv.equivCongr @[simp] theorem equivCongr_refl {α β} : (Equiv.refl α).equivCongr (Equiv.refl β) = Equiv.refl (α ≃ β) := by ext; rfl #align equiv.equiv_congr_refl Equiv.equivCongr_refl @[simp] theorem equivCongr_symm {δ} (ab : α ≃ β) (cd : γ ≃ δ) : (ab.equivCongr cd).symm = ab.symm.equivCongr cd.symm := by ext; rfl #align equiv.equiv_congr_symm Equiv.equivCongr_symm @[simp] theorem equivCongr_trans {δ ε ζ} (ab : α ≃ β) (de : δ ≃ ε) (bc : β ≃ γ) (ef : ε ≃ ζ) : (ab.equivCongr de).trans (bc.equivCongr ef) = (ab.trans bc).equivCongr (de.trans ef) := by ext; rfl #align equiv.equiv_congr_trans Equiv.equivCongr_trans @[simp] theorem equivCongr_refl_left {α β γ} (bg : β ≃ γ) (e : α ≃ β) : (Equiv.refl α).equivCongr bg e = e.trans bg := rfl #align equiv.equiv_congr_refl_left Equiv.equivCongr_refl_left @[simp] theorem equivCongr_refl_right {α β} (ab e : α ≃ β) : ab.equivCongr (Equiv.refl β) e = ab.symm.trans e := rfl #align equiv.equiv_congr_refl_right Equiv.equivCongr_refl_right @[simp] theorem equivCongr_apply_apply {δ} (ab : α ≃ β) (cd : γ ≃ δ) (e : α ≃ γ) (x) : ab.equivCongr cd e x = cd (e (ab.symm x)) := rfl #align equiv.equiv_congr_apply_apply Equiv.equivCongr_apply_apply section permCongr variable {α' β' : Type*} (e : α' ≃ β') /-- If `α` is equivalent to `β`, then `Perm α` is equivalent to `Perm β`. -/ def permCongr : Perm α' ≃ Perm β' := equivCongr e e #align equiv.perm_congr Equiv.permCongr theorem permCongr_def (p : Equiv.Perm α') : e.permCongr p = (e.symm.trans p).trans e := rfl #align equiv.perm_congr_def Equiv.permCongr_def @[simp] theorem permCongr_refl : e.permCongr (Equiv.refl _) = Equiv.refl _ := by simp [permCongr_def] #align equiv.perm_congr_refl Equiv.permCongr_refl @[simp] theorem permCongr_symm : e.permCongr.symm = e.symm.permCongr := rfl #align equiv.perm_congr_symm Equiv.permCongr_symm @[simp] theorem permCongr_apply (p : Equiv.Perm α') (x) : e.permCongr p x = e (p (e.symm x)) := rfl #align equiv.perm_congr_apply Equiv.permCongr_apply theorem permCongr_symm_apply (p : Equiv.Perm β') (x) : e.permCongr.symm p x = e.symm (p (e x)) := rfl #align equiv.perm_congr_symm_apply Equiv.permCongr_symm_apply theorem permCongr_trans (p p' : Equiv.Perm α') : (e.permCongr p).trans (e.permCongr p') = e.permCongr (p.trans p') := by ext; simp only [trans_apply, comp_apply, permCongr_apply, symm_apply_apply] #align equiv.perm_congr_trans Equiv.permCongr_trans end permCongr /-- Two empty types are equivalent. -/ def equivOfIsEmpty (α β : Sort*) [IsEmpty α] [IsEmpty β] : α ≃ β := ⟨isEmptyElim, isEmptyElim, isEmptyElim, isEmptyElim⟩ #align equiv.equiv_of_is_empty Equiv.equivOfIsEmpty /-- If `α` is an empty type, then it is equivalent to the `Empty` type. -/ def equivEmpty (α : Sort u) [IsEmpty α] : α ≃ Empty := equivOfIsEmpty α _ #align equiv.equiv_empty Equiv.equivEmpty /-- If `α` is an empty type, then it is equivalent to the `PEmpty` type in any universe. -/ def equivPEmpty (α : Sort v) [IsEmpty α] : α ≃ PEmpty.{u} := equivOfIsEmpty α _ #align equiv.equiv_pempty Equiv.equivPEmpty /-- `α` is equivalent to an empty type iff `α` is empty. -/ def equivEmptyEquiv (α : Sort u) : α ≃ Empty ≃ IsEmpty α := ⟨fun e => Function.isEmpty e, @equivEmpty α, fun e => ext fun x => (e x).elim, fun _ => rfl⟩ #align equiv.equiv_empty_equiv Equiv.equivEmptyEquiv /-- The `Sort` of proofs of a false proposition is equivalent to `PEmpty`. -/ def propEquivPEmpty {p : Prop} (h : ¬p) : p ≃ PEmpty := @equivPEmpty p <| IsEmpty.prop_iff.2 h #align equiv.prop_equiv_pempty Equiv.propEquivPEmpty /-- If both `α` and `β` have a unique element, then `α ≃ β`. -/ def equivOfUnique (α β : Sort _) [Unique.{u} α] [Unique.{v} β] : α ≃ β where toFun := default invFun := default left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ #align equiv.equiv_of_unique Equiv.equivOfUnique /-- If `α` has a unique element, then it is equivalent to any `PUnit`. -/ def equivPUnit (α : Sort u) [Unique α] : α ≃ PUnit.{v} := equivOfUnique α _ #align equiv.equiv_punit Equiv.equivPUnit /-- The `Sort` of proofs of a true proposition is equivalent to `PUnit`. -/ def propEquivPUnit {p : Prop} (h : p) : p ≃ PUnit.{0} := @equivPUnit p <| uniqueProp h #align equiv.prop_equiv_punit Equiv.propEquivPUnit /-- `ULift α` is equivalent to `α`. -/ @[simps (config := .asFn) apply] protected def ulift {α : Type v} : ULift.{u} α ≃ α := ⟨ULift.down, ULift.up, ULift.up_down, ULift.down_up.{v, u}⟩ #align equiv.ulift Equiv.ulift #align equiv.ulift_apply Equiv.ulift_apply /-- `PLift α` is equivalent to `α`. -/ @[simps (config := .asFn) apply] protected def plift : PLift α ≃ α := ⟨PLift.down, PLift.up, PLift.up_down, PLift.down_up⟩ #align equiv.plift Equiv.plift #align equiv.plift_apply Equiv.plift_apply /-- equivalence of propositions is the same as iff -/ def ofIff {P Q : Prop} (h : P ↔ Q) : P ≃ Q := ⟨h.mp, h.mpr, fun _ => rfl, fun _ => rfl⟩ #align equiv.of_iff Equiv.ofIff /-- If `α₁` is equivalent to `α₂` and `β₁` is equivalent to `β₂`, then the type of maps `α₁ → β₁` is equivalent to the type of maps `α₂ → β₂`. -/ -- Porting note: removing `congr` attribute @[simps apply] def arrowCongr {α₁ β₁ α₂ β₂ : Sort*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : (α₁ → β₁) ≃ (α₂ → β₂) where toFun f := e₂ ∘ f ∘ e₁.symm invFun f := e₂.symm ∘ f ∘ e₁ left_inv f := funext fun x => by simp only [comp_apply, symm_apply_apply] right_inv f := funext fun x => by simp only [comp_apply, apply_symm_apply] #align equiv.arrow_congr_apply Equiv.arrowCongr_apply #align equiv.arrow_congr Equiv.arrowCongr theorem arrowCongr_comp {α₁ β₁ γ₁ α₂ β₂ γ₂ : Sort*} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) (ec : γ₁ ≃ γ₂) (f : α₁ → β₁) (g : β₁ → γ₁) : arrowCongr ea ec (g ∘ f) = arrowCongr eb ec g ∘ arrowCongr ea eb f := by ext; simp only [comp, arrowCongr_apply, eb.symm_apply_apply] #align equiv.arrow_congr_comp Equiv.arrowCongr_comp @[simp] theorem arrowCongr_refl {α β : Sort*} : arrowCongr (Equiv.refl α) (Equiv.refl β) = Equiv.refl (α → β) := rfl #align equiv.arrow_congr_refl Equiv.arrowCongr_refl @[simp] theorem arrowCongr_trans {α₁ α₂ α₃ β₁ β₂ β₃ : Sort*} (e₁ : α₁ ≃ α₂) (e₁' : β₁ ≃ β₂) (e₂ : α₂ ≃ α₃) (e₂' : β₂ ≃ β₃) : arrowCongr (e₁.trans e₂) (e₁'.trans e₂') = (arrowCongr e₁ e₁').trans (arrowCongr e₂ e₂') := rfl #align equiv.arrow_congr_trans Equiv.arrowCongr_trans @[simp] theorem arrowCongr_symm {α₁ α₂ β₁ β₂ : Sort*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : (arrowCongr e₁ e₂).symm = arrowCongr e₁.symm e₂.symm := rfl #align equiv.arrow_congr_symm Equiv.arrowCongr_symm /-- A version of `Equiv.arrowCongr` in `Type`, rather than `Sort`. The `equiv_rw` tactic is not able to use the default `Sort` level `Equiv.arrowCongr`, because Lean's universe rules will not unify `?l_1` with `imax (1 ?m_1)`. -/ -- Porting note: removing `congr` attribute @[simps! apply] def arrowCongr' {α₁ β₁ α₂ β₂ : Type*} (hα : α₁ ≃ α₂) (hβ : β₁ ≃ β₂) : (α₁ → β₁) ≃ (α₂ → β₂) := Equiv.arrowCongr hα hβ #align equiv.arrow_congr' Equiv.arrowCongr' #align equiv.arrow_congr'_apply Equiv.arrowCongr'_apply @[simp] theorem arrowCongr'_refl {α β : Type*} : arrowCongr' (Equiv.refl α) (Equiv.refl β) = Equiv.refl (α → β) := rfl #align equiv.arrow_congr'_refl Equiv.arrowCongr'_refl @[simp] theorem arrowCongr'_trans {α₁ α₂ β₁ β₂ α₃ β₃ : Type*} (e₁ : α₁ ≃ α₂) (e₁' : β₁ ≃ β₂) (e₂ : α₂ ≃ α₃) (e₂' : β₂ ≃ β₃) : arrowCongr' (e₁.trans e₂) (e₁'.trans e₂') = (arrowCongr' e₁ e₁').trans (arrowCongr' e₂ e₂') := rfl #align equiv.arrow_congr'_trans Equiv.arrowCongr'_trans @[simp] theorem arrowCongr'_symm {α₁ α₂ β₁ β₂ : Type*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : (arrowCongr' e₁ e₂).symm = arrowCongr' e₁.symm e₂.symm := rfl #align equiv.arrow_congr'_symm Equiv.arrowCongr'_symm /-- Conjugate a map `f : α → α` by an equivalence `α ≃ β`. -/ @[simps! apply] def conj (e : α ≃ β) : (α → α) ≃ (β → β) := arrowCongr e e #align equiv.conj Equiv.conj #align equiv.conj_apply Equiv.conj_apply @[simp] theorem conj_refl : conj (Equiv.refl α) = Equiv.refl (α → α) := rfl #align equiv.conj_refl Equiv.conj_refl @[simp] theorem conj_symm (e : α ≃ β) : e.conj.symm = e.symm.conj := rfl #align equiv.conj_symm Equiv.conj_symm @[simp] theorem conj_trans (e₁ : α ≃ β) (e₂ : β ≃ γ) : (e₁.trans e₂).conj = e₁.conj.trans e₂.conj := rfl #align equiv.conj_trans Equiv.conj_trans -- This should not be a simp lemma as long as `(∘)` is reducible: -- when `(∘)` is reducible, Lean can unify `f₁ ∘ f₂` with any `g` using -- `f₁ := g` and `f₂ := fun x ↦ x`. This causes nontermination.
Mathlib/Logic/Equiv/Defs.lean
601
602
theorem conj_comp (e : α ≃ β) (f₁ f₂ : α → α) : e.conj (f₁ ∘ f₂) = e.conj f₁ ∘ e.conj f₂ := by
apply arrowCongr_comp
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Floris van Doorn, Violeta Hernández Palacios -/ import Mathlib.SetTheory.Ordinal.Basic import Mathlib.Data.Nat.SuccPred #align_import set_theory.ordinal.arithmetic from "leanprover-community/mathlib"@"31b269b60935483943542d547a6dd83a66b37dc7" /-! # Ordinal arithmetic Ordinals have an addition (corresponding to disjoint union) that turns them into an additive monoid, and a multiplication (corresponding to the lexicographic order on the product) that turns them into a monoid. One can also define correspondingly a subtraction, a division, a successor function, a power function and a logarithm function. We also define limit ordinals and prove the basic induction principle on ordinals separating successor ordinals and limit ordinals, in `limitRecOn`. ## Main definitions and results * `o₁ + o₂` is the order on the disjoint union of `o₁` and `o₂` obtained by declaring that every element of `o₁` is smaller than every element of `o₂`. * `o₁ - o₂` is the unique ordinal `o` such that `o₂ + o = o₁`, when `o₂ ≤ o₁`. * `o₁ * o₂` is the lexicographic order on `o₂ × o₁`. * `o₁ / o₂` is the ordinal `o` such that `o₁ = o₂ * o + o'` with `o' < o₂`. We also define the divisibility predicate, and a modulo operation. * `Order.succ o = o + 1` is the successor of `o`. * `pred o` if the predecessor of `o`. If `o` is not a successor, we set `pred o = o`. We discuss the properties of casts of natural numbers of and of `ω` with respect to these operations. Some properties of the operations are also used to discuss general tools on ordinals: * `IsLimit o`: an ordinal is a limit ordinal if it is neither `0` nor a successor. * `limitRecOn` is the main induction principle of ordinals: if one can prove a property by induction at successor ordinals and at limit ordinals, then it holds for all ordinals. * `IsNormal`: a function `f : Ordinal → Ordinal` satisfies `IsNormal` if it is strictly increasing and order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for `a < o`. * `enumOrd`: enumerates an unbounded set of ordinals by the ordinals themselves. * `sup`, `lsub`: the supremum / least strict upper bound of an indexed family of ordinals in `Type u`, as an ordinal in `Type u`. * `bsup`, `blsub`: the supremum / least strict upper bound of a set of ordinals indexed by ordinals less than a given ordinal `o`. Various other basic arithmetic results are given in `Principal.lean` instead. -/ assert_not_exists Field assert_not_exists Module noncomputable section open Function Cardinal Set Equiv Order open scoped Classical open Cardinal Ordinal universe u v w namespace Ordinal variable {α : Type*} {β : Type*} {γ : Type*} {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop} /-! ### Further properties of addition on ordinals -/ @[simp] theorem lift_add (a b : Ordinal.{v}) : lift.{u} (a + b) = lift.{u} a + lift.{u} b := Quotient.inductionOn₂ a b fun ⟨_α, _r, _⟩ ⟨_β, _s, _⟩ => Quotient.sound ⟨(RelIso.preimage Equiv.ulift _).trans (RelIso.sumLexCongr (RelIso.preimage Equiv.ulift _) (RelIso.preimage Equiv.ulift _)).symm⟩ #align ordinal.lift_add Ordinal.lift_add @[simp] theorem lift_succ (a : Ordinal.{v}) : lift.{u} (succ a) = succ (lift.{u} a) := by rw [← add_one_eq_succ, lift_add, lift_one] rfl #align ordinal.lift_succ Ordinal.lift_succ instance add_contravariantClass_le : ContravariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· ≤ ·) := ⟨fun a b c => inductionOn a fun α r hr => inductionOn b fun β₁ s₁ hs₁ => inductionOn c fun β₂ s₂ hs₂ ⟨f⟩ => ⟨have fl : ∀ a, f (Sum.inl a) = Sum.inl a := fun a => by simpa only [InitialSeg.trans_apply, InitialSeg.leAdd_apply] using @InitialSeg.eq _ _ _ _ _ ((InitialSeg.leAdd r s₁).trans f) (InitialSeg.leAdd r s₂) a have : ∀ b, { b' // f (Sum.inr b) = Sum.inr b' } := by intro b; cases e : f (Sum.inr b) · rw [← fl] at e have := f.inj' e contradiction · exact ⟨_, rfl⟩ let g (b) := (this b).1 have fr : ∀ b, f (Sum.inr b) = Sum.inr (g b) := fun b => (this b).2 ⟨⟨⟨g, fun x y h => by injection f.inj' (by rw [fr, fr, h] : f (Sum.inr x) = f (Sum.inr y))⟩, @fun a b => by -- Porting note: -- `relEmbedding.coe_fn_to_embedding` & `initial_seg.coe_fn_to_rel_embedding` -- → `InitialSeg.coe_coe_fn` simpa only [Sum.lex_inr_inr, fr, InitialSeg.coe_coe_fn, Embedding.coeFn_mk] using @RelEmbedding.map_rel_iff _ _ _ _ f.toRelEmbedding (Sum.inr a) (Sum.inr b)⟩, fun a b H => by rcases f.init (by rw [fr] <;> exact Sum.lex_inr_inr.2 H) with ⟨a' | a', h⟩ · rw [fl] at h cases h · rw [fr] at h exact ⟨a', Sum.inr.inj h⟩⟩⟩⟩ #align ordinal.add_contravariant_class_le Ordinal.add_contravariantClass_le theorem add_left_cancel (a) {b c : Ordinal} : a + b = a + c ↔ b = c := by simp only [le_antisymm_iff, add_le_add_iff_left] #align ordinal.add_left_cancel Ordinal.add_left_cancel private theorem add_lt_add_iff_left' (a) {b c : Ordinal} : a + b < a + c ↔ b < c := by rw [← not_le, ← not_le, add_le_add_iff_left] instance add_covariantClass_lt : CovariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· < ·) := ⟨fun a _b _c => (add_lt_add_iff_left' a).2⟩ #align ordinal.add_covariant_class_lt Ordinal.add_covariantClass_lt instance add_contravariantClass_lt : ContravariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· < ·) := ⟨fun a _b _c => (add_lt_add_iff_left' a).1⟩ #align ordinal.add_contravariant_class_lt Ordinal.add_contravariantClass_lt instance add_swap_contravariantClass_lt : ContravariantClass Ordinal.{u} Ordinal.{u} (swap (· + ·)) (· < ·) := ⟨fun _a _b _c => lt_imp_lt_of_le_imp_le fun h => add_le_add_right h _⟩ #align ordinal.add_swap_contravariant_class_lt Ordinal.add_swap_contravariantClass_lt theorem add_le_add_iff_right {a b : Ordinal} : ∀ n : ℕ, a + n ≤ b + n ↔ a ≤ b | 0 => by simp | n + 1 => by simp only [natCast_succ, add_succ, add_succ, succ_le_succ_iff, add_le_add_iff_right] #align ordinal.add_le_add_iff_right Ordinal.add_le_add_iff_right theorem add_right_cancel {a b : Ordinal} (n : ℕ) : a + n = b + n ↔ a = b := by simp only [le_antisymm_iff, add_le_add_iff_right] #align ordinal.add_right_cancel Ordinal.add_right_cancel theorem add_eq_zero_iff {a b : Ordinal} : a + b = 0 ↔ a = 0 ∧ b = 0 := inductionOn a fun α r _ => inductionOn b fun β s _ => by simp_rw [← type_sum_lex, type_eq_zero_iff_isEmpty] exact isEmpty_sum #align ordinal.add_eq_zero_iff Ordinal.add_eq_zero_iff theorem left_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : a = 0 := (add_eq_zero_iff.1 h).1 #align ordinal.left_eq_zero_of_add_eq_zero Ordinal.left_eq_zero_of_add_eq_zero theorem right_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : b = 0 := (add_eq_zero_iff.1 h).2 #align ordinal.right_eq_zero_of_add_eq_zero Ordinal.right_eq_zero_of_add_eq_zero /-! ### The predecessor of an ordinal -/ /-- The ordinal predecessor of `o` is `o'` if `o = succ o'`, and `o` otherwise. -/ def pred (o : Ordinal) : Ordinal := if h : ∃ a, o = succ a then Classical.choose h else o #align ordinal.pred Ordinal.pred @[simp] theorem pred_succ (o) : pred (succ o) = o := by have h : ∃ a, succ o = succ a := ⟨_, rfl⟩; simpa only [pred, dif_pos h] using (succ_injective <| Classical.choose_spec h).symm #align ordinal.pred_succ Ordinal.pred_succ theorem pred_le_self (o) : pred o ≤ o := if h : ∃ a, o = succ a then by let ⟨a, e⟩ := h rw [e, pred_succ]; exact le_succ a else by rw [pred, dif_neg h] #align ordinal.pred_le_self Ordinal.pred_le_self theorem pred_eq_iff_not_succ {o} : pred o = o ↔ ¬∃ a, o = succ a := ⟨fun e ⟨a, e'⟩ => by rw [e', pred_succ] at e; exact (lt_succ a).ne e, fun h => dif_neg h⟩ #align ordinal.pred_eq_iff_not_succ Ordinal.pred_eq_iff_not_succ theorem pred_eq_iff_not_succ' {o} : pred o = o ↔ ∀ a, o ≠ succ a := by simpa using pred_eq_iff_not_succ #align ordinal.pred_eq_iff_not_succ' Ordinal.pred_eq_iff_not_succ' theorem pred_lt_iff_is_succ {o} : pred o < o ↔ ∃ a, o = succ a := Iff.trans (by simp only [le_antisymm_iff, pred_le_self, true_and_iff, not_le]) (iff_not_comm.1 pred_eq_iff_not_succ).symm #align ordinal.pred_lt_iff_is_succ Ordinal.pred_lt_iff_is_succ @[simp] theorem pred_zero : pred 0 = 0 := pred_eq_iff_not_succ'.2 fun a => (succ_ne_zero a).symm #align ordinal.pred_zero Ordinal.pred_zero theorem succ_pred_iff_is_succ {o} : succ (pred o) = o ↔ ∃ a, o = succ a := ⟨fun e => ⟨_, e.symm⟩, fun ⟨a, e⟩ => by simp only [e, pred_succ]⟩ #align ordinal.succ_pred_iff_is_succ Ordinal.succ_pred_iff_is_succ theorem succ_lt_of_not_succ {o b : Ordinal} (h : ¬∃ a, o = succ a) : succ b < o ↔ b < o := ⟨(lt_succ b).trans, fun l => lt_of_le_of_ne (succ_le_of_lt l) fun e => h ⟨_, e.symm⟩⟩ #align ordinal.succ_lt_of_not_succ Ordinal.succ_lt_of_not_succ theorem lt_pred {a b} : a < pred b ↔ succ a < b := if h : ∃ a, b = succ a then by let ⟨c, e⟩ := h rw [e, pred_succ, succ_lt_succ_iff] else by simp only [pred, dif_neg h, succ_lt_of_not_succ h] #align ordinal.lt_pred Ordinal.lt_pred theorem pred_le {a b} : pred a ≤ b ↔ a ≤ succ b := le_iff_le_iff_lt_iff_lt.2 lt_pred #align ordinal.pred_le Ordinal.pred_le @[simp] theorem lift_is_succ {o : Ordinal.{v}} : (∃ a, lift.{u} o = succ a) ↔ ∃ a, o = succ a := ⟨fun ⟨a, h⟩ => let ⟨b, e⟩ := lift_down <| show a ≤ lift.{u} o from le_of_lt <| h.symm ▸ lt_succ a ⟨b, lift_inj.1 <| by rw [h, ← e, lift_succ]⟩, fun ⟨a, h⟩ => ⟨lift.{u} a, by simp only [h, lift_succ]⟩⟩ #align ordinal.lift_is_succ Ordinal.lift_is_succ @[simp] theorem lift_pred (o : Ordinal.{v}) : lift.{u} (pred o) = pred (lift.{u} o) := if h : ∃ a, o = succ a then by cases' h with a e; simp only [e, pred_succ, lift_succ] else by rw [pred_eq_iff_not_succ.2 h, pred_eq_iff_not_succ.2 (mt lift_is_succ.1 h)] #align ordinal.lift_pred Ordinal.lift_pred /-! ### Limit ordinals -/ /-- A limit ordinal is an ordinal which is not zero and not a successor. -/ def IsLimit (o : Ordinal) : Prop := o ≠ 0 ∧ ∀ a < o, succ a < o #align ordinal.is_limit Ordinal.IsLimit theorem IsLimit.isSuccLimit {o} (h : IsLimit o) : IsSuccLimit o := isSuccLimit_iff_succ_lt.mpr h.2 theorem IsLimit.succ_lt {o a : Ordinal} (h : IsLimit o) : a < o → succ a < o := h.2 a #align ordinal.is_limit.succ_lt Ordinal.IsLimit.succ_lt theorem isSuccLimit_zero : IsSuccLimit (0 : Ordinal) := isSuccLimit_bot theorem not_zero_isLimit : ¬IsLimit 0 | ⟨h, _⟩ => h rfl #align ordinal.not_zero_is_limit Ordinal.not_zero_isLimit theorem not_succ_isLimit (o) : ¬IsLimit (succ o) | ⟨_, h⟩ => lt_irrefl _ (h _ (lt_succ o)) #align ordinal.not_succ_is_limit Ordinal.not_succ_isLimit theorem not_succ_of_isLimit {o} (h : IsLimit o) : ¬∃ a, o = succ a | ⟨a, e⟩ => not_succ_isLimit a (e ▸ h) #align ordinal.not_succ_of_is_limit Ordinal.not_succ_of_isLimit theorem succ_lt_of_isLimit {o a : Ordinal} (h : IsLimit o) : succ a < o ↔ a < o := ⟨(lt_succ a).trans, h.2 _⟩ #align ordinal.succ_lt_of_is_limit Ordinal.succ_lt_of_isLimit theorem le_succ_of_isLimit {o} (h : IsLimit o) {a} : o ≤ succ a ↔ o ≤ a := le_iff_le_iff_lt_iff_lt.2 <| succ_lt_of_isLimit h #align ordinal.le_succ_of_is_limit Ordinal.le_succ_of_isLimit theorem limit_le {o} (h : IsLimit o) {a} : o ≤ a ↔ ∀ x < o, x ≤ a := ⟨fun h _x l => l.le.trans h, fun H => (le_succ_of_isLimit h).1 <| le_of_not_lt fun hn => not_lt_of_le (H _ hn) (lt_succ a)⟩ #align ordinal.limit_le Ordinal.limit_le theorem lt_limit {o} (h : IsLimit o) {a} : a < o ↔ ∃ x < o, a < x := by -- Porting note: `bex_def` is required. simpa only [not_forall₂, not_le, bex_def] using not_congr (@limit_le _ h a) #align ordinal.lt_limit Ordinal.lt_limit @[simp] theorem lift_isLimit (o) : IsLimit (lift o) ↔ IsLimit o := and_congr (not_congr <| by simpa only [lift_zero] using @lift_inj o 0) ⟨fun H a h => lift_lt.1 <| by simpa only [lift_succ] using H _ (lift_lt.2 h), fun H a h => by obtain ⟨a', rfl⟩ := lift_down h.le rw [← lift_succ, lift_lt] exact H a' (lift_lt.1 h)⟩ #align ordinal.lift_is_limit Ordinal.lift_isLimit theorem IsLimit.pos {o : Ordinal} (h : IsLimit o) : 0 < o := lt_of_le_of_ne (Ordinal.zero_le _) h.1.symm #align ordinal.is_limit.pos Ordinal.IsLimit.pos theorem IsLimit.one_lt {o : Ordinal} (h : IsLimit o) : 1 < o := by simpa only [succ_zero] using h.2 _ h.pos #align ordinal.is_limit.one_lt Ordinal.IsLimit.one_lt theorem IsLimit.nat_lt {o : Ordinal} (h : IsLimit o) : ∀ n : ℕ, (n : Ordinal) < o | 0 => h.pos | n + 1 => h.2 _ (IsLimit.nat_lt h n) #align ordinal.is_limit.nat_lt Ordinal.IsLimit.nat_lt theorem zero_or_succ_or_limit (o : Ordinal) : o = 0 ∨ (∃ a, o = succ a) ∨ IsLimit o := if o0 : o = 0 then Or.inl o0 else if h : ∃ a, o = succ a then Or.inr (Or.inl h) else Or.inr <| Or.inr ⟨o0, fun _a => (succ_lt_of_not_succ h).2⟩ #align ordinal.zero_or_succ_or_limit Ordinal.zero_or_succ_or_limit /-- Main induction principle of ordinals: if one can prove a property by induction at successor ordinals and at limit ordinals, then it holds for all ordinals. -/ @[elab_as_elim] def limitRecOn {C : Ordinal → Sort*} (o : Ordinal) (H₁ : C 0) (H₂ : ∀ o, C o → C (succ o)) (H₃ : ∀ o, IsLimit o → (∀ o' < o, C o') → C o) : C o := SuccOrder.limitRecOn o (fun o _ ↦ H₂ o) fun o hl ↦ if h : o = 0 then fun _ ↦ h ▸ H₁ else H₃ o ⟨h, fun _ ↦ hl.succ_lt⟩ #align ordinal.limit_rec_on Ordinal.limitRecOn @[simp] theorem limitRecOn_zero {C} (H₁ H₂ H₃) : @limitRecOn C 0 H₁ H₂ H₃ = H₁ := by rw [limitRecOn, SuccOrder.limitRecOn_limit _ _ isSuccLimit_zero, dif_pos rfl] #align ordinal.limit_rec_on_zero Ordinal.limitRecOn_zero @[simp] theorem limitRecOn_succ {C} (o H₁ H₂ H₃) : @limitRecOn C (succ o) H₁ H₂ H₃ = H₂ o (@limitRecOn C o H₁ H₂ H₃) := by simp_rw [limitRecOn, SuccOrder.limitRecOn_succ _ _ (not_isMax _)] #align ordinal.limit_rec_on_succ Ordinal.limitRecOn_succ @[simp] theorem limitRecOn_limit {C} (o H₁ H₂ H₃ h) : @limitRecOn C o H₁ H₂ H₃ = H₃ o h fun x _h => @limitRecOn C x H₁ H₂ H₃ := by simp_rw [limitRecOn, SuccOrder.limitRecOn_limit _ _ h.isSuccLimit, dif_neg h.1] #align ordinal.limit_rec_on_limit Ordinal.limitRecOn_limit instance orderTopOutSucc (o : Ordinal) : OrderTop (succ o).out.α := @OrderTop.mk _ _ (Top.mk _) le_enum_succ #align ordinal.order_top_out_succ Ordinal.orderTopOutSucc theorem enum_succ_eq_top {o : Ordinal} : enum (· < ·) o (by rw [type_lt] exact lt_succ o) = (⊤ : (succ o).out.α) := rfl #align ordinal.enum_succ_eq_top Ordinal.enum_succ_eq_top theorem has_succ_of_type_succ_lt {α} {r : α → α → Prop} [wo : IsWellOrder α r] (h : ∀ a < type r, succ a < type r) (x : α) : ∃ y, r x y := by use enum r (succ (typein r x)) (h _ (typein_lt_type r x)) convert (enum_lt_enum (typein_lt_type r x) (h _ (typein_lt_type r x))).mpr (lt_succ _); rw [enum_typein] #align ordinal.has_succ_of_type_succ_lt Ordinal.has_succ_of_type_succ_lt theorem out_no_max_of_succ_lt {o : Ordinal} (ho : ∀ a < o, succ a < o) : NoMaxOrder o.out.α := ⟨has_succ_of_type_succ_lt (by rwa [type_lt])⟩ #align ordinal.out_no_max_of_succ_lt Ordinal.out_no_max_of_succ_lt theorem bounded_singleton {r : α → α → Prop} [IsWellOrder α r] (hr : (type r).IsLimit) (x) : Bounded r {x} := by refine ⟨enum r (succ (typein r x)) (hr.2 _ (typein_lt_type r x)), ?_⟩ intro b hb rw [mem_singleton_iff.1 hb] nth_rw 1 [← enum_typein r x] rw [@enum_lt_enum _ r] apply lt_succ #align ordinal.bounded_singleton Ordinal.bounded_singleton -- Porting note: `· < ·` requires a type ascription for an `IsWellOrder` instance. theorem type_subrel_lt (o : Ordinal.{u}) : type (Subrel ((· < ·) : Ordinal → Ordinal → Prop) { o' : Ordinal | o' < o }) = Ordinal.lift.{u + 1} o := by refine Quotient.inductionOn o ?_ rintro ⟨α, r, wo⟩; apply Quotient.sound -- Porting note: `symm; refine' [term]` → `refine' [term].symm` constructor; refine ((RelIso.preimage Equiv.ulift r).trans (enumIso r).symm).symm #align ordinal.type_subrel_lt Ordinal.type_subrel_lt theorem mk_initialSeg (o : Ordinal.{u}) : #{ o' : Ordinal | o' < o } = Cardinal.lift.{u + 1} o.card := by rw [lift_card, ← type_subrel_lt, card_type] #align ordinal.mk_initial_seg Ordinal.mk_initialSeg /-! ### Normal ordinal functions -/ /-- A normal ordinal function is a strictly increasing function which is order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for `a < o`. -/ def IsNormal (f : Ordinal → Ordinal) : Prop := (∀ o, f o < f (succ o)) ∧ ∀ o, IsLimit o → ∀ a, f o ≤ a ↔ ∀ b < o, f b ≤ a #align ordinal.is_normal Ordinal.IsNormal theorem IsNormal.limit_le {f} (H : IsNormal f) : ∀ {o}, IsLimit o → ∀ {a}, f o ≤ a ↔ ∀ b < o, f b ≤ a := @H.2 #align ordinal.is_normal.limit_le Ordinal.IsNormal.limit_le theorem IsNormal.limit_lt {f} (H : IsNormal f) {o} (h : IsLimit o) {a} : a < f o ↔ ∃ b < o, a < f b := not_iff_not.1 <| by simpa only [exists_prop, not_exists, not_and, not_lt] using H.2 _ h a #align ordinal.is_normal.limit_lt Ordinal.IsNormal.limit_lt theorem IsNormal.strictMono {f} (H : IsNormal f) : StrictMono f := fun a b => limitRecOn b (Not.elim (not_lt_of_le <| Ordinal.zero_le _)) (fun _b IH h => (lt_or_eq_of_le (le_of_lt_succ h)).elim (fun h => (IH h).trans (H.1 _)) fun e => e ▸ H.1 _) fun _b l _IH h => lt_of_lt_of_le (H.1 a) ((H.2 _ l _).1 le_rfl _ (l.2 _ h)) #align ordinal.is_normal.strict_mono Ordinal.IsNormal.strictMono theorem IsNormal.monotone {f} (H : IsNormal f) : Monotone f := H.strictMono.monotone #align ordinal.is_normal.monotone Ordinal.IsNormal.monotone theorem isNormal_iff_strictMono_limit (f : Ordinal → Ordinal) : IsNormal f ↔ StrictMono f ∧ ∀ o, IsLimit o → ∀ a, (∀ b < o, f b ≤ a) → f o ≤ a := ⟨fun hf => ⟨hf.strictMono, fun a ha c => (hf.2 a ha c).2⟩, fun ⟨hs, hl⟩ => ⟨fun a => hs (lt_succ a), fun a ha c => ⟨fun hac _b hba => ((hs hba).trans_le hac).le, hl a ha c⟩⟩⟩ #align ordinal.is_normal_iff_strict_mono_limit Ordinal.isNormal_iff_strictMono_limit theorem IsNormal.lt_iff {f} (H : IsNormal f) {a b} : f a < f b ↔ a < b := StrictMono.lt_iff_lt <| H.strictMono #align ordinal.is_normal.lt_iff Ordinal.IsNormal.lt_iff theorem IsNormal.le_iff {f} (H : IsNormal f) {a b} : f a ≤ f b ↔ a ≤ b := le_iff_le_iff_lt_iff_lt.2 H.lt_iff #align ordinal.is_normal.le_iff Ordinal.IsNormal.le_iff theorem IsNormal.inj {f} (H : IsNormal f) {a b} : f a = f b ↔ a = b := by simp only [le_antisymm_iff, H.le_iff] #align ordinal.is_normal.inj Ordinal.IsNormal.inj theorem IsNormal.self_le {f} (H : IsNormal f) (a) : a ≤ f a := lt_wf.self_le_of_strictMono H.strictMono a #align ordinal.is_normal.self_le Ordinal.IsNormal.self_le theorem IsNormal.le_set {f o} (H : IsNormal f) (p : Set Ordinal) (p0 : p.Nonempty) (b) (H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f a ≤ o := ⟨fun h a pa => (H.le_iff.2 ((H₂ _).1 le_rfl _ pa)).trans h, fun h => by -- Porting note: `refine'` didn't work well so `induction` is used induction b using limitRecOn with | H₁ => cases' p0 with x px have := Ordinal.le_zero.1 ((H₂ _).1 (Ordinal.zero_le _) _ px) rw [this] at px exact h _ px | H₂ S _ => rcases not_forall₂.1 (mt (H₂ S).2 <| (lt_succ S).not_le) with ⟨a, h₁, h₂⟩ exact (H.le_iff.2 <| succ_le_of_lt <| not_le.1 h₂).trans (h _ h₁) | H₃ S L _ => refine (H.2 _ L _).2 fun a h' => ?_ rcases not_forall₂.1 (mt (H₂ a).2 h'.not_le) with ⟨b, h₁, h₂⟩ exact (H.le_iff.2 <| (not_le.1 h₂).le).trans (h _ h₁)⟩ #align ordinal.is_normal.le_set Ordinal.IsNormal.le_set theorem IsNormal.le_set' {f o} (H : IsNormal f) (p : Set α) (p0 : p.Nonempty) (g : α → Ordinal) (b) (H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, g a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f (g a) ≤ o := by simpa [H₂] using H.le_set (g '' p) (p0.image g) b #align ordinal.is_normal.le_set' Ordinal.IsNormal.le_set' theorem IsNormal.refl : IsNormal id := ⟨lt_succ, fun _o l _a => Ordinal.limit_le l⟩ #align ordinal.is_normal.refl Ordinal.IsNormal.refl theorem IsNormal.trans {f g} (H₁ : IsNormal f) (H₂ : IsNormal g) : IsNormal (f ∘ g) := ⟨fun _x => H₁.lt_iff.2 (H₂.1 _), fun o l _a => H₁.le_set' (· < o) ⟨0, l.pos⟩ g _ fun _c => H₂.2 _ l _⟩ #align ordinal.is_normal.trans Ordinal.IsNormal.trans theorem IsNormal.isLimit {f} (H : IsNormal f) {o} (l : IsLimit o) : IsLimit (f o) := ⟨ne_of_gt <| (Ordinal.zero_le _).trans_lt <| H.lt_iff.2 l.pos, fun _ h => let ⟨_b, h₁, h₂⟩ := (H.limit_lt l).1 h (succ_le_of_lt h₂).trans_lt (H.lt_iff.2 h₁)⟩ #align ordinal.is_normal.is_limit Ordinal.IsNormal.isLimit theorem IsNormal.le_iff_eq {f} (H : IsNormal f) {a} : f a ≤ a ↔ f a = a := (H.self_le a).le_iff_eq #align ordinal.is_normal.le_iff_eq Ordinal.IsNormal.le_iff_eq theorem add_le_of_limit {a b c : Ordinal} (h : IsLimit b) : a + b ≤ c ↔ ∀ b' < b, a + b' ≤ c := ⟨fun h b' l => (add_le_add_left l.le _).trans h, fun H => le_of_not_lt <| by -- Porting note: `induction` tactics are required because of the parser bug. induction a using inductionOn with | H α r => induction b using inductionOn with | H β s => intro l suffices ∀ x : β, Sum.Lex r s (Sum.inr x) (enum _ _ l) by -- Porting note: `revert` & `intro` is required because `cases'` doesn't replace -- `enum _ _ l` in `this`. revert this; cases' enum _ _ l with x x <;> intro this · cases this (enum s 0 h.pos) · exact irrefl _ (this _) intro x rw [← typein_lt_typein (Sum.Lex r s), typein_enum] have := H _ (h.2 _ (typein_lt_type s x)) rw [add_succ, succ_le_iff] at this refine (RelEmbedding.ofMonotone (fun a => ?_) fun a b => ?_).ordinal_type_le.trans_lt this · rcases a with ⟨a | b, h⟩ · exact Sum.inl a · exact Sum.inr ⟨b, by cases h; assumption⟩ · rcases a with ⟨a | a, h₁⟩ <;> rcases b with ⟨b | b, h₂⟩ <;> cases h₁ <;> cases h₂ <;> rintro ⟨⟩ <;> constructor <;> assumption⟩ #align ordinal.add_le_of_limit Ordinal.add_le_of_limit theorem add_isNormal (a : Ordinal) : IsNormal (a + ·) := ⟨fun b => (add_lt_add_iff_left a).2 (lt_succ b), fun _b l _c => add_le_of_limit l⟩ #align ordinal.add_is_normal Ordinal.add_isNormal theorem add_isLimit (a) {b} : IsLimit b → IsLimit (a + b) := (add_isNormal a).isLimit #align ordinal.add_is_limit Ordinal.add_isLimit alias IsLimit.add := add_isLimit #align ordinal.is_limit.add Ordinal.IsLimit.add /-! ### Subtraction on ordinals-/ /-- The set in the definition of subtraction is nonempty. -/ theorem sub_nonempty {a b : Ordinal} : { o | a ≤ b + o }.Nonempty := ⟨a, le_add_left _ _⟩ #align ordinal.sub_nonempty Ordinal.sub_nonempty /-- `a - b` is the unique ordinal satisfying `b + (a - b) = a` when `b ≤ a`. -/ instance sub : Sub Ordinal := ⟨fun a b => sInf { o | a ≤ b + o }⟩ theorem le_add_sub (a b : Ordinal) : a ≤ b + (a - b) := csInf_mem sub_nonempty #align ordinal.le_add_sub Ordinal.le_add_sub theorem sub_le {a b c : Ordinal} : a - b ≤ c ↔ a ≤ b + c := ⟨fun h => (le_add_sub a b).trans (add_le_add_left h _), fun h => csInf_le' h⟩ #align ordinal.sub_le Ordinal.sub_le theorem lt_sub {a b c : Ordinal} : a < b - c ↔ c + a < b := lt_iff_lt_of_le_iff_le sub_le #align ordinal.lt_sub Ordinal.lt_sub theorem add_sub_cancel (a b : Ordinal) : a + b - a = b := le_antisymm (sub_le.2 <| le_rfl) ((add_le_add_iff_left a).1 <| le_add_sub _ _) #align ordinal.add_sub_cancel Ordinal.add_sub_cancel theorem sub_eq_of_add_eq {a b c : Ordinal} (h : a + b = c) : c - a = b := h ▸ add_sub_cancel _ _ #align ordinal.sub_eq_of_add_eq Ordinal.sub_eq_of_add_eq theorem sub_le_self (a b : Ordinal) : a - b ≤ a := sub_le.2 <| le_add_left _ _ #align ordinal.sub_le_self Ordinal.sub_le_self protected theorem add_sub_cancel_of_le {a b : Ordinal} (h : b ≤ a) : b + (a - b) = a := (le_add_sub a b).antisymm' (by rcases zero_or_succ_or_limit (a - b) with (e | ⟨c, e⟩ | l) · simp only [e, add_zero, h] · rw [e, add_succ, succ_le_iff, ← lt_sub, e] exact lt_succ c · exact (add_le_of_limit l).2 fun c l => (lt_sub.1 l).le) #align ordinal.add_sub_cancel_of_le Ordinal.add_sub_cancel_of_le theorem le_sub_of_le {a b c : Ordinal} (h : b ≤ a) : c ≤ a - b ↔ b + c ≤ a := by rw [← add_le_add_iff_left b, Ordinal.add_sub_cancel_of_le h] #align ordinal.le_sub_of_le Ordinal.le_sub_of_le theorem sub_lt_of_le {a b c : Ordinal} (h : b ≤ a) : a - b < c ↔ a < b + c := lt_iff_lt_of_le_iff_le (le_sub_of_le h) #align ordinal.sub_lt_of_le Ordinal.sub_lt_of_le instance existsAddOfLE : ExistsAddOfLE Ordinal := ⟨fun h => ⟨_, (Ordinal.add_sub_cancel_of_le h).symm⟩⟩ @[simp] theorem sub_zero (a : Ordinal) : a - 0 = a := by simpa only [zero_add] using add_sub_cancel 0 a #align ordinal.sub_zero Ordinal.sub_zero @[simp] theorem zero_sub (a : Ordinal) : 0 - a = 0 := by rw [← Ordinal.le_zero]; apply sub_le_self #align ordinal.zero_sub Ordinal.zero_sub @[simp] theorem sub_self (a : Ordinal) : a - a = 0 := by simpa only [add_zero] using add_sub_cancel a 0 #align ordinal.sub_self Ordinal.sub_self protected theorem sub_eq_zero_iff_le {a b : Ordinal} : a - b = 0 ↔ a ≤ b := ⟨fun h => by simpa only [h, add_zero] using le_add_sub a b, fun h => by rwa [← Ordinal.le_zero, sub_le, add_zero]⟩ #align ordinal.sub_eq_zero_iff_le Ordinal.sub_eq_zero_iff_le theorem sub_sub (a b c : Ordinal) : a - b - c = a - (b + c) := eq_of_forall_ge_iff fun d => by rw [sub_le, sub_le, sub_le, add_assoc] #align ordinal.sub_sub Ordinal.sub_sub @[simp] theorem add_sub_add_cancel (a b c : Ordinal) : a + b - (a + c) = b - c := by rw [← sub_sub, add_sub_cancel] #align ordinal.add_sub_add_cancel Ordinal.add_sub_add_cancel theorem sub_isLimit {a b} (l : IsLimit a) (h : b < a) : IsLimit (a - b) := ⟨ne_of_gt <| lt_sub.2 <| by rwa [add_zero], fun c h => by rw [lt_sub, add_succ]; exact l.2 _ (lt_sub.1 h)⟩ #align ordinal.sub_is_limit Ordinal.sub_isLimit -- @[simp] -- Porting note (#10618): simp can prove this theorem one_add_omega : 1 + ω = ω := by refine le_antisymm ?_ (le_add_left _ _) rw [omega, ← lift_one.{_, 0}, ← lift_add, lift_le, ← type_unit, ← type_sum_lex] refine ⟨RelEmbedding.collapse (RelEmbedding.ofMonotone ?_ ?_)⟩ · apply Sum.rec · exact fun _ => 0 · exact Nat.succ · intro a b cases a <;> cases b <;> intro H <;> cases' H with _ _ H _ _ H <;> [exact H.elim; exact Nat.succ_pos _; exact Nat.succ_lt_succ H] #align ordinal.one_add_omega Ordinal.one_add_omega @[simp] theorem one_add_of_omega_le {o} (h : ω ≤ o) : 1 + o = o := by rw [← Ordinal.add_sub_cancel_of_le h, ← add_assoc, one_add_omega] #align ordinal.one_add_of_omega_le Ordinal.one_add_of_omega_le /-! ### Multiplication of ordinals-/ /-- The multiplication of ordinals `o₁` and `o₂` is the (well founded) lexicographic order on `o₂ × o₁`. -/ instance monoid : Monoid Ordinal.{u} where mul a b := Quotient.liftOn₂ a b (fun ⟨α, r, wo⟩ ⟨β, s, wo'⟩ => ⟦⟨β × α, Prod.Lex s r, inferInstance⟩⟧ : WellOrder → WellOrder → Ordinal) fun ⟨α₁, r₁, o₁⟩ ⟨α₂, r₂, o₂⟩ ⟨β₁, s₁, p₁⟩ ⟨β₂, s₂, p₂⟩ ⟨f⟩ ⟨g⟩ => Quot.sound ⟨RelIso.prodLexCongr g f⟩ one := 1 mul_assoc a b c := Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ => Eq.symm <| Quotient.sound ⟨⟨prodAssoc _ _ _, @fun a b => by rcases a with ⟨⟨a₁, a₂⟩, a₃⟩ rcases b with ⟨⟨b₁, b₂⟩, b₃⟩ simp [Prod.lex_def, and_or_left, or_assoc, and_assoc]⟩⟩ mul_one a := inductionOn a fun α r _ => Quotient.sound ⟨⟨punitProd _, @fun a b => by rcases a with ⟨⟨⟨⟩⟩, a⟩; rcases b with ⟨⟨⟨⟩⟩, b⟩ simp only [Prod.lex_def, EmptyRelation, false_or_iff] simp only [eq_self_iff_true, true_and_iff] rfl⟩⟩ one_mul a := inductionOn a fun α r _ => Quotient.sound ⟨⟨prodPUnit _, @fun a b => by rcases a with ⟨a, ⟨⟨⟩⟩⟩; rcases b with ⟨b, ⟨⟨⟩⟩⟩ simp only [Prod.lex_def, EmptyRelation, and_false_iff, or_false_iff] rfl⟩⟩ @[simp] theorem type_prod_lex {α β : Type u} (r : α → α → Prop) (s : β → β → Prop) [IsWellOrder α r] [IsWellOrder β s] : type (Prod.Lex s r) = type r * type s := rfl #align ordinal.type_prod_lex Ordinal.type_prod_lex private theorem mul_eq_zero' {a b : Ordinal} : a * b = 0 ↔ a = 0 ∨ b = 0 := inductionOn a fun α _ _ => inductionOn b fun β _ _ => by simp_rw [← type_prod_lex, type_eq_zero_iff_isEmpty] rw [or_comm] exact isEmpty_prod instance monoidWithZero : MonoidWithZero Ordinal := { Ordinal.monoid with zero := 0 mul_zero := fun _a => mul_eq_zero'.2 <| Or.inr rfl zero_mul := fun _a => mul_eq_zero'.2 <| Or.inl rfl } instance noZeroDivisors : NoZeroDivisors Ordinal := ⟨fun {_ _} => mul_eq_zero'.1⟩ @[simp] theorem lift_mul (a b : Ordinal.{v}) : lift.{u} (a * b) = lift.{u} a * lift.{u} b := Quotient.inductionOn₂ a b fun ⟨_α, _r, _⟩ ⟨_β, _s, _⟩ => Quotient.sound ⟨(RelIso.preimage Equiv.ulift _).trans (RelIso.prodLexCongr (RelIso.preimage Equiv.ulift _) (RelIso.preimage Equiv.ulift _)).symm⟩ #align ordinal.lift_mul Ordinal.lift_mul @[simp] theorem card_mul (a b) : card (a * b) = card a * card b := Quotient.inductionOn₂ a b fun ⟨α, _r, _⟩ ⟨β, _s, _⟩ => mul_comm #β #α #align ordinal.card_mul Ordinal.card_mul instance leftDistribClass : LeftDistribClass Ordinal.{u} := ⟨fun a b c => Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ => Quotient.sound ⟨⟨sumProdDistrib _ _ _, by rintro ⟨a₁ | a₁, a₂⟩ ⟨b₁ | b₁, b₂⟩ <;> simp only [Prod.lex_def, Sum.lex_inl_inl, Sum.Lex.sep, Sum.lex_inr_inl, Sum.lex_inr_inr, sumProdDistrib_apply_left, sumProdDistrib_apply_right] <;> -- Porting note: `Sum.inr.inj_iff` is required. simp only [Sum.inl.inj_iff, Sum.inr.inj_iff, true_or_iff, false_and_iff, false_or_iff]⟩⟩⟩ theorem mul_succ (a b : Ordinal) : a * succ b = a * b + a := mul_add_one a b #align ordinal.mul_succ Ordinal.mul_succ instance mul_covariantClass_le : CovariantClass Ordinal.{u} Ordinal.{u} (· * ·) (· ≤ ·) := ⟨fun c a b => Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨f⟩ => by refine (RelEmbedding.ofMonotone (fun a : α × γ => (f a.1, a.2)) fun a b h => ?_).ordinal_type_le cases' h with a₁ b₁ a₂ b₂ h' a b₁ b₂ h' · exact Prod.Lex.left _ _ (f.toRelEmbedding.map_rel_iff.2 h') · exact Prod.Lex.right _ h'⟩ #align ordinal.mul_covariant_class_le Ordinal.mul_covariantClass_le instance mul_swap_covariantClass_le : CovariantClass Ordinal.{u} Ordinal.{u} (swap (· * ·)) (· ≤ ·) := ⟨fun c a b => Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨f⟩ => by refine (RelEmbedding.ofMonotone (fun a : γ × α => (a.1, f a.2)) fun a b h => ?_).ordinal_type_le cases' h with a₁ b₁ a₂ b₂ h' a b₁ b₂ h' · exact Prod.Lex.left _ _ h' · exact Prod.Lex.right _ (f.toRelEmbedding.map_rel_iff.2 h')⟩ #align ordinal.mul_swap_covariant_class_le Ordinal.mul_swap_covariantClass_le theorem le_mul_left (a : Ordinal) {b : Ordinal} (hb : 0 < b) : a ≤ a * b := by convert mul_le_mul_left' (one_le_iff_pos.2 hb) a rw [mul_one a] #align ordinal.le_mul_left Ordinal.le_mul_left theorem le_mul_right (a : Ordinal) {b : Ordinal} (hb : 0 < b) : a ≤ b * a := by convert mul_le_mul_right' (one_le_iff_pos.2 hb) a rw [one_mul a] #align ordinal.le_mul_right Ordinal.le_mul_right private theorem mul_le_of_limit_aux {α β r s} [IsWellOrder α r] [IsWellOrder β s] {c} (h : IsLimit (type s)) (H : ∀ b' < type s, type r * b' ≤ c) (l : c < type r * type s) : False := by suffices ∀ a b, Prod.Lex s r (b, a) (enum _ _ l) by cases' enum _ _ l with b a exact irrefl _ (this _ _) intro a b rw [← typein_lt_typein (Prod.Lex s r), typein_enum] have := H _ (h.2 _ (typein_lt_type s b)) rw [mul_succ] at this have := ((add_lt_add_iff_left _).2 (typein_lt_type _ a)).trans_le this refine (RelEmbedding.ofMonotone (fun a => ?_) fun a b => ?_).ordinal_type_le.trans_lt this · rcases a with ⟨⟨b', a'⟩, h⟩ by_cases e : b = b' · refine Sum.inr ⟨a', ?_⟩ subst e cases' h with _ _ _ _ h _ _ _ h · exact (irrefl _ h).elim · exact h · refine Sum.inl (⟨b', ?_⟩, a') cases' h with _ _ _ _ h _ _ _ h · exact h · exact (e rfl).elim · rcases a with ⟨⟨b₁, a₁⟩, h₁⟩ rcases b with ⟨⟨b₂, a₂⟩, h₂⟩ intro h by_cases e₁ : b = b₁ <;> by_cases e₂ : b = b₂ · substs b₁ b₂ simpa only [subrel_val, Prod.lex_def, @irrefl _ s _ b, true_and_iff, false_or_iff, eq_self_iff_true, dif_pos, Sum.lex_inr_inr] using h · subst b₁ simp only [subrel_val, Prod.lex_def, e₂, Prod.lex_def, dif_pos, subrel_val, eq_self_iff_true, or_false_iff, dif_neg, not_false_iff, Sum.lex_inr_inl, false_and_iff] at h ⊢ cases' h₂ with _ _ _ _ h₂_h h₂_h <;> [exact asymm h h₂_h; exact e₂ rfl] -- Porting note: `cc` hadn't ported yet. · simp [e₂, dif_neg e₁, show b₂ ≠ b₁ from e₂ ▸ e₁] · simpa only [dif_neg e₁, dif_neg e₂, Prod.lex_def, subrel_val, Subtype.mk_eq_mk, Sum.lex_inl_inl] using h theorem mul_le_of_limit {a b c : Ordinal} (h : IsLimit b) : a * b ≤ c ↔ ∀ b' < b, a * b' ≤ c := ⟨fun h b' l => (mul_le_mul_left' l.le _).trans h, fun H => -- Porting note: `induction` tactics are required because of the parser bug. le_of_not_lt <| by induction a using inductionOn with | H α r => induction b using inductionOn with | H β s => exact mul_le_of_limit_aux h H⟩ #align ordinal.mul_le_of_limit Ordinal.mul_le_of_limit theorem mul_isNormal {a : Ordinal} (h : 0 < a) : IsNormal (a * ·) := -- Porting note(#12129): additional beta reduction needed ⟨fun b => by beta_reduce rw [mul_succ] simpa only [add_zero] using (add_lt_add_iff_left (a * b)).2 h, fun b l c => mul_le_of_limit l⟩ #align ordinal.mul_is_normal Ordinal.mul_isNormal theorem lt_mul_of_limit {a b c : Ordinal} (h : IsLimit c) : a < b * c ↔ ∃ c' < c, a < b * c' := by -- Porting note: `bex_def` is required. simpa only [not_forall₂, not_le, bex_def] using not_congr (@mul_le_of_limit b c a h) #align ordinal.lt_mul_of_limit Ordinal.lt_mul_of_limit theorem mul_lt_mul_iff_left {a b c : Ordinal} (a0 : 0 < a) : a * b < a * c ↔ b < c := (mul_isNormal a0).lt_iff #align ordinal.mul_lt_mul_iff_left Ordinal.mul_lt_mul_iff_left theorem mul_le_mul_iff_left {a b c : Ordinal} (a0 : 0 < a) : a * b ≤ a * c ↔ b ≤ c := (mul_isNormal a0).le_iff #align ordinal.mul_le_mul_iff_left Ordinal.mul_le_mul_iff_left theorem mul_lt_mul_of_pos_left {a b c : Ordinal} (h : a < b) (c0 : 0 < c) : c * a < c * b := (mul_lt_mul_iff_left c0).2 h #align ordinal.mul_lt_mul_of_pos_left Ordinal.mul_lt_mul_of_pos_left theorem mul_pos {a b : Ordinal} (h₁ : 0 < a) (h₂ : 0 < b) : 0 < a * b := by simpa only [mul_zero] using mul_lt_mul_of_pos_left h₂ h₁ #align ordinal.mul_pos Ordinal.mul_pos theorem mul_ne_zero {a b : Ordinal} : a ≠ 0 → b ≠ 0 → a * b ≠ 0 := by simpa only [Ordinal.pos_iff_ne_zero] using mul_pos #align ordinal.mul_ne_zero Ordinal.mul_ne_zero theorem le_of_mul_le_mul_left {a b c : Ordinal} (h : c * a ≤ c * b) (h0 : 0 < c) : a ≤ b := le_imp_le_of_lt_imp_lt (fun h' => mul_lt_mul_of_pos_left h' h0) h #align ordinal.le_of_mul_le_mul_left Ordinal.le_of_mul_le_mul_left theorem mul_right_inj {a b c : Ordinal} (a0 : 0 < a) : a * b = a * c ↔ b = c := (mul_isNormal a0).inj #align ordinal.mul_right_inj Ordinal.mul_right_inj theorem mul_isLimit {a b : Ordinal} (a0 : 0 < a) : IsLimit b → IsLimit (a * b) := (mul_isNormal a0).isLimit #align ordinal.mul_is_limit Ordinal.mul_isLimit theorem mul_isLimit_left {a b : Ordinal} (l : IsLimit a) (b0 : 0 < b) : IsLimit (a * b) := by rcases zero_or_succ_or_limit b with (rfl | ⟨b, rfl⟩ | lb) · exact b0.false.elim · rw [mul_succ] exact add_isLimit _ l · exact mul_isLimit l.pos lb #align ordinal.mul_is_limit_left Ordinal.mul_isLimit_left theorem smul_eq_mul : ∀ (n : ℕ) (a : Ordinal), n • a = a * n | 0, a => by rw [zero_nsmul, Nat.cast_zero, mul_zero] | n + 1, a => by rw [succ_nsmul, Nat.cast_add, mul_add, Nat.cast_one, mul_one, smul_eq_mul n] #align ordinal.smul_eq_mul Ordinal.smul_eq_mul /-! ### Division on ordinals -/ /-- The set in the definition of division is nonempty. -/ theorem div_nonempty {a b : Ordinal} (h : b ≠ 0) : { o | a < b * succ o }.Nonempty := ⟨a, (succ_le_iff (a := a) (b := b * succ a)).1 <| by simpa only [succ_zero, one_mul] using mul_le_mul_right' (succ_le_of_lt (Ordinal.pos_iff_ne_zero.2 h)) (succ a)⟩ #align ordinal.div_nonempty Ordinal.div_nonempty /-- `a / b` is the unique ordinal `o` satisfying `a = b * o + o'` with `o' < b`. -/ instance div : Div Ordinal := ⟨fun a b => if _h : b = 0 then 0 else sInf { o | a < b * succ o }⟩ @[simp] theorem div_zero (a : Ordinal) : a / 0 = 0 := dif_pos rfl #align ordinal.div_zero Ordinal.div_zero theorem div_def (a) {b : Ordinal} (h : b ≠ 0) : a / b = sInf { o | a < b * succ o } := dif_neg h #align ordinal.div_def Ordinal.div_def theorem lt_mul_succ_div (a) {b : Ordinal} (h : b ≠ 0) : a < b * succ (a / b) := by rw [div_def a h]; exact csInf_mem (div_nonempty h) #align ordinal.lt_mul_succ_div Ordinal.lt_mul_succ_div theorem lt_mul_div_add (a) {b : Ordinal} (h : b ≠ 0) : a < b * (a / b) + b := by simpa only [mul_succ] using lt_mul_succ_div a h #align ordinal.lt_mul_div_add Ordinal.lt_mul_div_add theorem div_le {a b c : Ordinal} (b0 : b ≠ 0) : a / b ≤ c ↔ a < b * succ c := ⟨fun h => (lt_mul_succ_div a b0).trans_le (mul_le_mul_left' (succ_le_succ_iff.2 h) _), fun h => by rw [div_def a b0]; exact csInf_le' h⟩ #align ordinal.div_le Ordinal.div_le theorem lt_div {a b c : Ordinal} (h : c ≠ 0) : a < b / c ↔ c * succ a ≤ b := by rw [← not_le, div_le h, not_lt] #align ordinal.lt_div Ordinal.lt_div theorem div_pos {b c : Ordinal} (h : c ≠ 0) : 0 < b / c ↔ c ≤ b := by simp [lt_div h] #align ordinal.div_pos Ordinal.div_pos theorem le_div {a b c : Ordinal} (c0 : c ≠ 0) : a ≤ b / c ↔ c * a ≤ b := by induction a using limitRecOn with | H₁ => simp only [mul_zero, Ordinal.zero_le] | H₂ _ _ => rw [succ_le_iff, lt_div c0] | H₃ _ h₁ h₂ => revert h₁ h₂ simp (config := { contextual := true }) only [mul_le_of_limit, limit_le, iff_self_iff, forall_true_iff] #align ordinal.le_div Ordinal.le_div theorem div_lt {a b c : Ordinal} (b0 : b ≠ 0) : a / b < c ↔ a < b * c := lt_iff_lt_of_le_iff_le <| le_div b0 #align ordinal.div_lt Ordinal.div_lt theorem div_le_of_le_mul {a b c : Ordinal} (h : a ≤ b * c) : a / b ≤ c := if b0 : b = 0 then by simp only [b0, div_zero, Ordinal.zero_le] else (div_le b0).2 <| h.trans_lt <| mul_lt_mul_of_pos_left (lt_succ c) (Ordinal.pos_iff_ne_zero.2 b0) #align ordinal.div_le_of_le_mul Ordinal.div_le_of_le_mul theorem mul_lt_of_lt_div {a b c : Ordinal} : a < b / c → c * a < b := lt_imp_lt_of_le_imp_le div_le_of_le_mul #align ordinal.mul_lt_of_lt_div Ordinal.mul_lt_of_lt_div @[simp] theorem zero_div (a : Ordinal) : 0 / a = 0 := Ordinal.le_zero.1 <| div_le_of_le_mul <| Ordinal.zero_le _ #align ordinal.zero_div Ordinal.zero_div theorem mul_div_le (a b : Ordinal) : b * (a / b) ≤ a := if b0 : b = 0 then by simp only [b0, zero_mul, Ordinal.zero_le] else (le_div b0).1 le_rfl #align ordinal.mul_div_le Ordinal.mul_div_le theorem mul_add_div (a) {b : Ordinal} (b0 : b ≠ 0) (c) : (b * a + c) / b = a + c / b := by apply le_antisymm · apply (div_le b0).2 rw [mul_succ, mul_add, add_assoc, add_lt_add_iff_left] apply lt_mul_div_add _ b0 · rw [le_div b0, mul_add, add_le_add_iff_left] apply mul_div_le #align ordinal.mul_add_div Ordinal.mul_add_div theorem div_eq_zero_of_lt {a b : Ordinal} (h : a < b) : a / b = 0 := by rw [← Ordinal.le_zero, div_le <| Ordinal.pos_iff_ne_zero.1 <| (Ordinal.zero_le _).trans_lt h] simpa only [succ_zero, mul_one] using h #align ordinal.div_eq_zero_of_lt Ordinal.div_eq_zero_of_lt @[simp] theorem mul_div_cancel (a) {b : Ordinal} (b0 : b ≠ 0) : b * a / b = a := by simpa only [add_zero, zero_div] using mul_add_div a b0 0 #align ordinal.mul_div_cancel Ordinal.mul_div_cancel @[simp] theorem div_one (a : Ordinal) : a / 1 = a := by simpa only [one_mul] using mul_div_cancel a Ordinal.one_ne_zero #align ordinal.div_one Ordinal.div_one @[simp] theorem div_self {a : Ordinal} (h : a ≠ 0) : a / a = 1 := by simpa only [mul_one] using mul_div_cancel 1 h #align ordinal.div_self Ordinal.div_self theorem mul_sub (a b c : Ordinal) : a * (b - c) = a * b - a * c := if a0 : a = 0 then by simp only [a0, zero_mul, sub_self] else eq_of_forall_ge_iff fun d => by rw [sub_le, ← le_div a0, sub_le, ← le_div a0, mul_add_div _ a0] #align ordinal.mul_sub Ordinal.mul_sub theorem isLimit_add_iff {a b} : IsLimit (a + b) ↔ IsLimit b ∨ b = 0 ∧ IsLimit a := by constructor <;> intro h · by_cases h' : b = 0 · rw [h', add_zero] at h right exact ⟨h', h⟩ left rw [← add_sub_cancel a b] apply sub_isLimit h suffices a + 0 < a + b by simpa only [add_zero] using this rwa [add_lt_add_iff_left, Ordinal.pos_iff_ne_zero] rcases h with (h | ⟨rfl, h⟩) · exact add_isLimit a h · simpa only [add_zero] #align ordinal.is_limit_add_iff Ordinal.isLimit_add_iff theorem dvd_add_iff : ∀ {a b c : Ordinal}, a ∣ b → (a ∣ b + c ↔ a ∣ c) | a, _, c, ⟨b, rfl⟩ => ⟨fun ⟨d, e⟩ => ⟨d - b, by rw [mul_sub, ← e, add_sub_cancel]⟩, fun ⟨d, e⟩ => by rw [e, ← mul_add] apply dvd_mul_right⟩ #align ordinal.dvd_add_iff Ordinal.dvd_add_iff theorem div_mul_cancel : ∀ {a b : Ordinal}, a ≠ 0 → a ∣ b → a * (b / a) = b | a, _, a0, ⟨b, rfl⟩ => by rw [mul_div_cancel _ a0] #align ordinal.div_mul_cancel Ordinal.div_mul_cancel theorem le_of_dvd : ∀ {a b : Ordinal}, b ≠ 0 → a ∣ b → a ≤ b -- Porting note: `⟨b, rfl⟩ => by` → `⟨b, e⟩ => by subst e` | a, _, b0, ⟨b, e⟩ => by subst e -- Porting note: `Ne` is required. simpa only [mul_one] using mul_le_mul_left' (one_le_iff_ne_zero.2 fun h : b = 0 => by simp only [h, mul_zero, Ne, not_true_eq_false] at b0) a #align ordinal.le_of_dvd Ordinal.le_of_dvd theorem dvd_antisymm {a b : Ordinal} (h₁ : a ∣ b) (h₂ : b ∣ a) : a = b := if a0 : a = 0 then by subst a; exact (eq_zero_of_zero_dvd h₁).symm else if b0 : b = 0 then by subst b; exact eq_zero_of_zero_dvd h₂ else (le_of_dvd b0 h₁).antisymm (le_of_dvd a0 h₂) #align ordinal.dvd_antisymm Ordinal.dvd_antisymm instance isAntisymm : IsAntisymm Ordinal (· ∣ ·) := ⟨@dvd_antisymm⟩ /-- `a % b` is the unique ordinal `o'` satisfying `a = b * o + o'` with `o' < b`. -/ instance mod : Mod Ordinal := ⟨fun a b => a - b * (a / b)⟩ theorem mod_def (a b : Ordinal) : a % b = a - b * (a / b) := rfl #align ordinal.mod_def Ordinal.mod_def theorem mod_le (a b : Ordinal) : a % b ≤ a := sub_le_self a _ #align ordinal.mod_le Ordinal.mod_le @[simp] theorem mod_zero (a : Ordinal) : a % 0 = a := by simp only [mod_def, div_zero, zero_mul, sub_zero] #align ordinal.mod_zero Ordinal.mod_zero theorem mod_eq_of_lt {a b : Ordinal} (h : a < b) : a % b = a := by simp only [mod_def, div_eq_zero_of_lt h, mul_zero, sub_zero] #align ordinal.mod_eq_of_lt Ordinal.mod_eq_of_lt @[simp] theorem zero_mod (b : Ordinal) : 0 % b = 0 := by simp only [mod_def, zero_div, mul_zero, sub_self] #align ordinal.zero_mod Ordinal.zero_mod theorem div_add_mod (a b : Ordinal) : b * (a / b) + a % b = a := Ordinal.add_sub_cancel_of_le <| mul_div_le _ _ #align ordinal.div_add_mod Ordinal.div_add_mod theorem mod_lt (a) {b : Ordinal} (h : b ≠ 0) : a % b < b := (add_lt_add_iff_left (b * (a / b))).1 <| by rw [div_add_mod]; exact lt_mul_div_add a h #align ordinal.mod_lt Ordinal.mod_lt @[simp] theorem mod_self (a : Ordinal) : a % a = 0 := if a0 : a = 0 then by simp only [a0, zero_mod] else by simp only [mod_def, div_self a0, mul_one, sub_self] #align ordinal.mod_self Ordinal.mod_self @[simp] theorem mod_one (a : Ordinal) : a % 1 = 0 := by simp only [mod_def, div_one, one_mul, sub_self] #align ordinal.mod_one Ordinal.mod_one theorem dvd_of_mod_eq_zero {a b : Ordinal} (H : a % b = 0) : b ∣ a := ⟨a / b, by simpa [H] using (div_add_mod a b).symm⟩ #align ordinal.dvd_of_mod_eq_zero Ordinal.dvd_of_mod_eq_zero theorem mod_eq_zero_of_dvd {a b : Ordinal} (H : b ∣ a) : a % b = 0 := by rcases H with ⟨c, rfl⟩ rcases eq_or_ne b 0 with (rfl | hb) · simp · simp [mod_def, hb] #align ordinal.mod_eq_zero_of_dvd Ordinal.mod_eq_zero_of_dvd theorem dvd_iff_mod_eq_zero {a b : Ordinal} : b ∣ a ↔ a % b = 0 := ⟨mod_eq_zero_of_dvd, dvd_of_mod_eq_zero⟩ #align ordinal.dvd_iff_mod_eq_zero Ordinal.dvd_iff_mod_eq_zero @[simp] theorem mul_add_mod_self (x y z : Ordinal) : (x * y + z) % x = z % x := by rcases eq_or_ne x 0 with rfl | hx · simp · rwa [mod_def, mul_add_div, mul_add, ← sub_sub, add_sub_cancel, mod_def] #align ordinal.mul_add_mod_self Ordinal.mul_add_mod_self @[simp] theorem mul_mod (x y : Ordinal) : x * y % x = 0 := by simpa using mul_add_mod_self x y 0 #align ordinal.mul_mod Ordinal.mul_mod theorem mod_mod_of_dvd (a : Ordinal) {b c : Ordinal} (h : c ∣ b) : a % b % c = a % c := by nth_rw 2 [← div_add_mod a b] rcases h with ⟨d, rfl⟩ rw [mul_assoc, mul_add_mod_self] #align ordinal.mod_mod_of_dvd Ordinal.mod_mod_of_dvd @[simp] theorem mod_mod (a b : Ordinal) : a % b % b = a % b := mod_mod_of_dvd a dvd_rfl #align ordinal.mod_mod Ordinal.mod_mod /-! ### Families of ordinals There are two kinds of indexed families that naturally arise when dealing with ordinals: those indexed by some type in the appropriate universe, and those indexed by ordinals less than another. The following API allows one to convert from one kind of family to the other. In many cases, this makes it easy to prove claims about one kind of family via the corresponding claim on the other. -/ /-- Converts a family indexed by a `Type u` to one indexed by an `Ordinal.{u}` using a specified well-ordering. -/ def bfamilyOfFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α) : ∀ a < type r, α := fun a ha => f (enum r a ha) #align ordinal.bfamily_of_family' Ordinal.bfamilyOfFamily' /-- Converts a family indexed by a `Type u` to one indexed by an `Ordinal.{u}` using a well-ordering given by the axiom of choice. -/ def bfamilyOfFamily {ι : Type u} : (ι → α) → ∀ a < type (@WellOrderingRel ι), α := bfamilyOfFamily' WellOrderingRel #align ordinal.bfamily_of_family Ordinal.bfamilyOfFamily /-- Converts a family indexed by an `Ordinal.{u}` to one indexed by a `Type u` using a specified well-ordering. -/ def familyOfBFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o} (ho : type r = o) (f : ∀ a < o, α) : ι → α := fun i => f (typein r i) (by rw [← ho] exact typein_lt_type r i) #align ordinal.family_of_bfamily' Ordinal.familyOfBFamily' /-- Converts a family indexed by an `Ordinal.{u}` to one indexed by a `Type u` using a well-ordering given by the axiom of choice. -/ def familyOfBFamily (o : Ordinal) (f : ∀ a < o, α) : o.out.α → α := familyOfBFamily' (· < ·) (type_lt o) f #align ordinal.family_of_bfamily Ordinal.familyOfBFamily @[simp] theorem bfamilyOfFamily'_typein {ι} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α) (i) : bfamilyOfFamily' r f (typein r i) (typein_lt_type r i) = f i := by simp only [bfamilyOfFamily', enum_typein] #align ordinal.bfamily_of_family'_typein Ordinal.bfamilyOfFamily'_typein @[simp] theorem bfamilyOfFamily_typein {ι} (f : ι → α) (i) : bfamilyOfFamily f (typein _ i) (typein_lt_type _ i) = f i := bfamilyOfFamily'_typein _ f i #align ordinal.bfamily_of_family_typein Ordinal.bfamilyOfFamily_typein @[simp, nolint simpNF] -- Porting note (#10959): simp cannot prove this theorem familyOfBFamily'_enum {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o} (ho : type r = o) (f : ∀ a < o, α) (i hi) : familyOfBFamily' r ho f (enum r i (by rwa [ho])) = f i hi := by simp only [familyOfBFamily', typein_enum] #align ordinal.family_of_bfamily'_enum Ordinal.familyOfBFamily'_enum @[simp, nolint simpNF] -- Porting note (#10959): simp cannot prove this theorem familyOfBFamily_enum (o : Ordinal) (f : ∀ a < o, α) (i hi) : familyOfBFamily o f (enum (· < ·) i (by convert hi exact type_lt _)) = f i hi := familyOfBFamily'_enum _ (type_lt o) f _ _ #align ordinal.family_of_bfamily_enum Ordinal.familyOfBFamily_enum /-- The range of a family indexed by ordinals. -/ def brange (o : Ordinal) (f : ∀ a < o, α) : Set α := { a | ∃ i hi, f i hi = a } #align ordinal.brange Ordinal.brange theorem mem_brange {o : Ordinal} {f : ∀ a < o, α} {a} : a ∈ brange o f ↔ ∃ i hi, f i hi = a := Iff.rfl #align ordinal.mem_brange Ordinal.mem_brange theorem mem_brange_self {o} (f : ∀ a < o, α) (i hi) : f i hi ∈ brange o f := ⟨i, hi, rfl⟩ #align ordinal.mem_brange_self Ordinal.mem_brange_self @[simp] theorem range_familyOfBFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o} (ho : type r = o) (f : ∀ a < o, α) : range (familyOfBFamily' r ho f) = brange o f := by refine Set.ext fun a => ⟨?_, ?_⟩ · rintro ⟨b, rfl⟩ apply mem_brange_self · rintro ⟨i, hi, rfl⟩ exact ⟨_, familyOfBFamily'_enum _ _ _ _ _⟩ #align ordinal.range_family_of_bfamily' Ordinal.range_familyOfBFamily' @[simp] theorem range_familyOfBFamily {o} (f : ∀ a < o, α) : range (familyOfBFamily o f) = brange o f := range_familyOfBFamily' _ _ f #align ordinal.range_family_of_bfamily Ordinal.range_familyOfBFamily @[simp] theorem brange_bfamilyOfFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α) : brange _ (bfamilyOfFamily' r f) = range f := by refine Set.ext fun a => ⟨?_, ?_⟩ · rintro ⟨i, hi, rfl⟩ apply mem_range_self · rintro ⟨b, rfl⟩ exact ⟨_, _, bfamilyOfFamily'_typein _ _ _⟩ #align ordinal.brange_bfamily_of_family' Ordinal.brange_bfamilyOfFamily' @[simp] theorem brange_bfamilyOfFamily {ι : Type u} (f : ι → α) : brange _ (bfamilyOfFamily f) = range f := brange_bfamilyOfFamily' _ _ #align ordinal.brange_bfamily_of_family Ordinal.brange_bfamilyOfFamily @[simp] theorem brange_const {o : Ordinal} (ho : o ≠ 0) {c : α} : (brange o fun _ _ => c) = {c} := by rw [← range_familyOfBFamily] exact @Set.range_const _ o.out.α (out_nonempty_iff_ne_zero.2 ho) c #align ordinal.brange_const Ordinal.brange_const theorem comp_bfamilyOfFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α) (g : α → β) : (fun i hi => g (bfamilyOfFamily' r f i hi)) = bfamilyOfFamily' r (g ∘ f) := rfl #align ordinal.comp_bfamily_of_family' Ordinal.comp_bfamilyOfFamily' theorem comp_bfamilyOfFamily {ι : Type u} (f : ι → α) (g : α → β) : (fun i hi => g (bfamilyOfFamily f i hi)) = bfamilyOfFamily (g ∘ f) := rfl #align ordinal.comp_bfamily_of_family Ordinal.comp_bfamilyOfFamily theorem comp_familyOfBFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o} (ho : type r = o) (f : ∀ a < o, α) (g : α → β) : g ∘ familyOfBFamily' r ho f = familyOfBFamily' r ho fun i hi => g (f i hi) := rfl #align ordinal.comp_family_of_bfamily' Ordinal.comp_familyOfBFamily' theorem comp_familyOfBFamily {o} (f : ∀ a < o, α) (g : α → β) : g ∘ familyOfBFamily o f = familyOfBFamily o fun i hi => g (f i hi) := rfl #align ordinal.comp_family_of_bfamily Ordinal.comp_familyOfBFamily /-! ### Supremum of a family of ordinals -/ -- Porting note: Universes should be specified in `sup`s. /-- The supremum of a family of ordinals -/ def sup {ι : Type u} (f : ι → Ordinal.{max u v}) : Ordinal.{max u v} := iSup f #align ordinal.sup Ordinal.sup @[simp] theorem sSup_eq_sup {ι : Type u} (f : ι → Ordinal.{max u v}) : sSup (Set.range f) = sup.{_, v} f := rfl #align ordinal.Sup_eq_sup Ordinal.sSup_eq_sup /-- The range of an indexed ordinal function, whose outputs live in a higher universe than the inputs, is always bounded above. See `Ordinal.lsub` for an explicit bound. -/ theorem bddAbove_range {ι : Type u} (f : ι → Ordinal.{max u v}) : BddAbove (Set.range f) := ⟨(iSup (succ ∘ card ∘ f)).ord, by rintro a ⟨i, rfl⟩ exact le_of_lt (Cardinal.lt_ord.2 ((lt_succ _).trans_le (le_ciSup (Cardinal.bddAbove_range.{_, v} _) _)))⟩ #align ordinal.bdd_above_range Ordinal.bddAbove_range theorem le_sup {ι : Type u} (f : ι → Ordinal.{max u v}) : ∀ i, f i ≤ sup.{_, v} f := fun i => le_csSup (bddAbove_range.{_, v} f) (mem_range_self i) #align ordinal.le_sup Ordinal.le_sup theorem sup_le_iff {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : sup.{_, v} f ≤ a ↔ ∀ i, f i ≤ a := (csSup_le_iff' (bddAbove_range.{_, v} f)).trans (by simp) #align ordinal.sup_le_iff Ordinal.sup_le_iff theorem sup_le {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : (∀ i, f i ≤ a) → sup.{_, v} f ≤ a := sup_le_iff.2 #align ordinal.sup_le Ordinal.sup_le theorem lt_sup {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : a < sup.{_, v} f ↔ ∃ i, a < f i := by simpa only [not_forall, not_le] using not_congr (@sup_le_iff.{_, v} _ f a) #align ordinal.lt_sup Ordinal.lt_sup theorem ne_sup_iff_lt_sup {ι : Type u} {f : ι → Ordinal.{max u v}} : (∀ i, f i ≠ sup.{_, v} f) ↔ ∀ i, f i < sup.{_, v} f := ⟨fun hf _ => lt_of_le_of_ne (le_sup _ _) (hf _), fun hf _ => ne_of_lt (hf _)⟩ #align ordinal.ne_sup_iff_lt_sup Ordinal.ne_sup_iff_lt_sup theorem sup_not_succ_of_ne_sup {ι : Type u} {f : ι → Ordinal.{max u v}} (hf : ∀ i, f i ≠ sup.{_, v} f) {a} (hao : a < sup.{_, v} f) : succ a < sup.{_, v} f := by by_contra! hoa exact hao.not_le (sup_le fun i => le_of_lt_succ <| (lt_of_le_of_ne (le_sup _ _) (hf i)).trans_le hoa) #align ordinal.sup_not_succ_of_ne_sup Ordinal.sup_not_succ_of_ne_sup @[simp] theorem sup_eq_zero_iff {ι : Type u} {f : ι → Ordinal.{max u v}} : sup.{_, v} f = 0 ↔ ∀ i, f i = 0 := by refine ⟨fun h i => ?_, fun h => le_antisymm (sup_le fun i => Ordinal.le_zero.2 (h i)) (Ordinal.zero_le _)⟩ rw [← Ordinal.le_zero, ← h] exact le_sup f i #align ordinal.sup_eq_zero_iff Ordinal.sup_eq_zero_iff theorem IsNormal.sup {f : Ordinal.{max u v} → Ordinal.{max u w}} (H : IsNormal f) {ι : Type u} (g : ι → Ordinal.{max u v}) [Nonempty ι] : f (sup.{_, v} g) = sup.{_, w} (f ∘ g) := eq_of_forall_ge_iff fun a => by rw [sup_le_iff]; simp only [comp]; rw [H.le_set' Set.univ Set.univ_nonempty g] <;> simp [sup_le_iff] #align ordinal.is_normal.sup Ordinal.IsNormal.sup @[simp] theorem sup_empty {ι} [IsEmpty ι] (f : ι → Ordinal) : sup f = 0 := ciSup_of_empty f #align ordinal.sup_empty Ordinal.sup_empty @[simp] theorem sup_const {ι} [_hι : Nonempty ι] (o : Ordinal) : (sup fun _ : ι => o) = o := ciSup_const #align ordinal.sup_const Ordinal.sup_const @[simp] theorem sup_unique {ι} [Unique ι] (f : ι → Ordinal) : sup f = f default := ciSup_unique #align ordinal.sup_unique Ordinal.sup_unique theorem sup_le_of_range_subset {ι ι'} {f : ι → Ordinal} {g : ι' → Ordinal} (h : Set.range f ⊆ Set.range g) : sup.{u, max v w} f ≤ sup.{v, max u w} g := sup_le fun i => match h (mem_range_self i) with | ⟨_j, hj⟩ => hj ▸ le_sup _ _ #align ordinal.sup_le_of_range_subset Ordinal.sup_le_of_range_subset theorem sup_eq_of_range_eq {ι ι'} {f : ι → Ordinal} {g : ι' → Ordinal} (h : Set.range f = Set.range g) : sup.{u, max v w} f = sup.{v, max u w} g := (sup_le_of_range_subset.{u, v, w} h.le).antisymm (sup_le_of_range_subset.{v, u, w} h.ge) #align ordinal.sup_eq_of_range_eq Ordinal.sup_eq_of_range_eq @[simp] theorem sup_sum {α : Type u} {β : Type v} (f : Sum α β → Ordinal) : sup.{max u v, w} f = max (sup.{u, max v w} fun a => f (Sum.inl a)) (sup.{v, max u w} fun b => f (Sum.inr b)) := by apply (sup_le_iff.2 _).antisymm (max_le_iff.2 ⟨_, _⟩) · rintro (i | i) · exact le_max_of_le_left (le_sup _ i) · exact le_max_of_le_right (le_sup _ i) all_goals apply sup_le_of_range_subset.{_, max u v, w} rintro i ⟨a, rfl⟩ apply mem_range_self #align ordinal.sup_sum Ordinal.sup_sum theorem unbounded_range_of_sup_ge {α β : Type u} (r : α → α → Prop) [IsWellOrder α r] (f : β → α) (h : type r ≤ sup.{u, u} (typein r ∘ f)) : Unbounded r (range f) := (not_bounded_iff _).1 fun ⟨x, hx⟩ => not_lt_of_le h <| lt_of_le_of_lt (sup_le fun y => le_of_lt <| (typein_lt_typein r).2 <| hx _ <| mem_range_self y) (typein_lt_type r x) #align ordinal.unbounded_range_of_sup_ge Ordinal.unbounded_range_of_sup_ge theorem le_sup_shrink_equiv {s : Set Ordinal.{u}} (hs : Small.{u} s) (a) (ha : a ∈ s) : a ≤ sup.{u, u} fun x => ((@equivShrink s hs).symm x).val := by convert le_sup.{u, u} (fun x => ((@equivShrink s hs).symm x).val) ((@equivShrink s hs) ⟨a, ha⟩) rw [symm_apply_apply] #align ordinal.le_sup_shrink_equiv Ordinal.le_sup_shrink_equiv instance small_Iio (o : Ordinal.{u}) : Small.{u} (Set.Iio o) := let f : o.out.α → Set.Iio o := fun x => ⟨typein ((· < ·) : o.out.α → o.out.α → Prop) x, typein_lt_self x⟩ let hf : Surjective f := fun b => ⟨enum (· < ·) b.val (by rw [type_lt] exact b.prop), Subtype.ext (typein_enum _ _)⟩ small_of_surjective hf #align ordinal.small_Iio Ordinal.small_Iio instance small_Iic (o : Ordinal.{u}) : Small.{u} (Set.Iic o) := by rw [← Iio_succ] infer_instance #align ordinal.small_Iic Ordinal.small_Iic theorem bddAbove_iff_small {s : Set Ordinal.{u}} : BddAbove s ↔ Small.{u} s := ⟨fun ⟨a, h⟩ => small_subset <| show s ⊆ Iic a from fun _x hx => h hx, fun h => ⟨sup.{u, u} fun x => ((@equivShrink s h).symm x).val, le_sup_shrink_equiv h⟩⟩ #align ordinal.bdd_above_iff_small Ordinal.bddAbove_iff_small theorem bddAbove_of_small (s : Set Ordinal.{u}) [h : Small.{u} s] : BddAbove s := bddAbove_iff_small.2 h #align ordinal.bdd_above_of_small Ordinal.bddAbove_of_small theorem sup_eq_sSup {s : Set Ordinal.{u}} (hs : Small.{u} s) : (sup.{u, u} fun x => (@equivShrink s hs).symm x) = sSup s := let hs' := bddAbove_iff_small.2 hs ((csSup_le_iff' hs').2 (le_sup_shrink_equiv hs)).antisymm' (sup_le fun _x => le_csSup hs' (Subtype.mem _)) #align ordinal.sup_eq_Sup Ordinal.sup_eq_sSup theorem sSup_ord {s : Set Cardinal.{u}} (hs : BddAbove s) : (sSup s).ord = sSup (ord '' s) := eq_of_forall_ge_iff fun a => by rw [csSup_le_iff' (bddAbove_iff_small.2 (@small_image _ _ _ s (Cardinal.bddAbove_iff_small.1 hs))), ord_le, csSup_le_iff' hs] simp [ord_le] #align ordinal.Sup_ord Ordinal.sSup_ord theorem iSup_ord {ι} {f : ι → Cardinal} (hf : BddAbove (range f)) : (iSup f).ord = ⨆ i, (f i).ord := by unfold iSup convert sSup_ord hf -- Porting note: `change` is required. conv_lhs => change range (ord ∘ f) rw [range_comp] #align ordinal.supr_ord Ordinal.iSup_ord private theorem sup_le_sup {ι ι' : Type u} (r : ι → ι → Prop) (r' : ι' → ι' → Prop) [IsWellOrder ι r] [IsWellOrder ι' r'] {o} (ho : type r = o) (ho' : type r' = o) (f : ∀ a < o, Ordinal.{max u v}) : sup.{_, v} (familyOfBFamily' r ho f) ≤ sup.{_, v} (familyOfBFamily' r' ho' f) := sup_le fun i => by cases' typein_surj r' (by rw [ho', ← ho] exact typein_lt_type r i) with j hj simp_rw [familyOfBFamily', ← hj] apply le_sup theorem sup_eq_sup {ι ι' : Type u} (r : ι → ι → Prop) (r' : ι' → ι' → Prop) [IsWellOrder ι r] [IsWellOrder ι' r'] {o : Ordinal.{u}} (ho : type r = o) (ho' : type r' = o) (f : ∀ a < o, Ordinal.{max u v}) : sup.{_, v} (familyOfBFamily' r ho f) = sup.{_, v} (familyOfBFamily' r' ho' f) := sup_eq_of_range_eq.{u, u, v} (by simp) #align ordinal.sup_eq_sup Ordinal.sup_eq_sup /-- The supremum of a family of ordinals indexed by the set of ordinals less than some `o : Ordinal.{u}`. This is a special case of `sup` over the family provided by `familyOfBFamily`. -/ def bsup (o : Ordinal.{u}) (f : ∀ a < o, Ordinal.{max u v}) : Ordinal.{max u v} := sup.{_, v} (familyOfBFamily o f) #align ordinal.bsup Ordinal.bsup @[simp] theorem sup_eq_bsup {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : sup.{_, v} (familyOfBFamily o f) = bsup.{_, v} o f := rfl #align ordinal.sup_eq_bsup Ordinal.sup_eq_bsup @[simp] theorem sup_eq_bsup' {o : Ordinal.{u}} {ι} (r : ι → ι → Prop) [IsWellOrder ι r] (ho : type r = o) (f : ∀ a < o, Ordinal.{max u v}) : sup.{_, v} (familyOfBFamily' r ho f) = bsup.{_, v} o f := sup_eq_sup r _ ho _ f #align ordinal.sup_eq_bsup' Ordinal.sup_eq_bsup' @[simp, nolint simpNF] -- Porting note (#10959): simp cannot prove this theorem sSup_eq_bsup {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : sSup (brange o f) = bsup.{_, v} o f := by congr rw [range_familyOfBFamily] #align ordinal.Sup_eq_bsup Ordinal.sSup_eq_bsup @[simp] theorem bsup_eq_sup' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → Ordinal.{max u v}) : bsup.{_, v} _ (bfamilyOfFamily' r f) = sup.{_, v} f := by simp (config := { unfoldPartialApp := true }) only [← sup_eq_bsup' r, enum_typein, familyOfBFamily', bfamilyOfFamily'] #align ordinal.bsup_eq_sup' Ordinal.bsup_eq_sup' theorem bsup_eq_bsup {ι : Type u} (r r' : ι → ι → Prop) [IsWellOrder ι r] [IsWellOrder ι r'] (f : ι → Ordinal.{max u v}) : bsup.{_, v} _ (bfamilyOfFamily' r f) = bsup.{_, v} _ (bfamilyOfFamily' r' f) := by rw [bsup_eq_sup', bsup_eq_sup'] #align ordinal.bsup_eq_bsup Ordinal.bsup_eq_bsup @[simp] theorem bsup_eq_sup {ι : Type u} (f : ι → Ordinal.{max u v}) : bsup.{_, v} _ (bfamilyOfFamily f) = sup.{_, v} f := bsup_eq_sup' _ f #align ordinal.bsup_eq_sup Ordinal.bsup_eq_sup @[congr] theorem bsup_congr {o₁ o₂ : Ordinal.{u}} (f : ∀ a < o₁, Ordinal.{max u v}) (ho : o₁ = o₂) : bsup.{_, v} o₁ f = bsup.{_, v} o₂ fun a h => f a (h.trans_eq ho.symm) := by subst ho -- Porting note: `rfl` is required. rfl #align ordinal.bsup_congr Ordinal.bsup_congr theorem bsup_le_iff {o f a} : bsup.{u, v} o f ≤ a ↔ ∀ i h, f i h ≤ a := sup_le_iff.trans ⟨fun h i hi => by rw [← familyOfBFamily_enum o f] exact h _, fun h i => h _ _⟩ #align ordinal.bsup_le_iff Ordinal.bsup_le_iff theorem bsup_le {o : Ordinal} {f : ∀ b < o, Ordinal} {a} : (∀ i h, f i h ≤ a) → bsup.{u, v} o f ≤ a := bsup_le_iff.2 #align ordinal.bsup_le Ordinal.bsup_le theorem le_bsup {o} (f : ∀ a < o, Ordinal) (i h) : f i h ≤ bsup o f := bsup_le_iff.1 le_rfl _ _ #align ordinal.le_bsup Ordinal.le_bsup theorem lt_bsup {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) {a} : a < bsup.{_, v} o f ↔ ∃ i hi, a < f i hi := by simpa only [not_forall, not_le] using not_congr (@bsup_le_iff.{_, v} _ f a) #align ordinal.lt_bsup Ordinal.lt_bsup theorem IsNormal.bsup {f : Ordinal.{max u v} → Ordinal.{max u w}} (H : IsNormal f) {o : Ordinal.{u}} : ∀ (g : ∀ a < o, Ordinal), o ≠ 0 → f (bsup.{_, v} o g) = bsup.{_, w} o fun a h => f (g a h) := inductionOn o fun α r _ g h => by haveI := type_ne_zero_iff_nonempty.1 h rw [← sup_eq_bsup' r, IsNormal.sup.{_, v, w} H, ← sup_eq_bsup' r] <;> rfl #align ordinal.is_normal.bsup Ordinal.IsNormal.bsup theorem lt_bsup_of_ne_bsup {o : Ordinal.{u}} {f : ∀ a < o, Ordinal.{max u v}} : (∀ i h, f i h ≠ bsup.{_, v} o f) ↔ ∀ i h, f i h < bsup.{_, v} o f := ⟨fun hf _ _ => lt_of_le_of_ne (le_bsup _ _ _) (hf _ _), fun hf _ _ => ne_of_lt (hf _ _)⟩ #align ordinal.lt_bsup_of_ne_bsup Ordinal.lt_bsup_of_ne_bsup theorem bsup_not_succ_of_ne_bsup {o : Ordinal.{u}} {f : ∀ a < o, Ordinal.{max u v}} (hf : ∀ {i : Ordinal} (h : i < o), f i h ≠ bsup.{_, v} o f) (a) : a < bsup.{_, v} o f → succ a < bsup.{_, v} o f := by rw [← sup_eq_bsup] at * exact sup_not_succ_of_ne_sup fun i => hf _ #align ordinal.bsup_not_succ_of_ne_bsup Ordinal.bsup_not_succ_of_ne_bsup @[simp] theorem bsup_eq_zero_iff {o} {f : ∀ a < o, Ordinal} : bsup o f = 0 ↔ ∀ i hi, f i hi = 0 := by refine ⟨fun h i hi => ?_, fun h => le_antisymm (bsup_le fun i hi => Ordinal.le_zero.2 (h i hi)) (Ordinal.zero_le _)⟩ rw [← Ordinal.le_zero, ← h] exact le_bsup f i hi #align ordinal.bsup_eq_zero_iff Ordinal.bsup_eq_zero_iff theorem lt_bsup_of_limit {o : Ordinal} {f : ∀ a < o, Ordinal} (hf : ∀ {a a'} (ha : a < o) (ha' : a' < o), a < a' → f a ha < f a' ha') (ho : ∀ a < o, succ a < o) (i h) : f i h < bsup o f := (hf _ _ <| lt_succ i).trans_le (le_bsup f (succ i) <| ho _ h) #align ordinal.lt_bsup_of_limit Ordinal.lt_bsup_of_limit theorem bsup_succ_of_mono {o : Ordinal} {f : ∀ a < succ o, Ordinal} (hf : ∀ {i j} (hi hj), i ≤ j → f i hi ≤ f j hj) : bsup _ f = f o (lt_succ o) := le_antisymm (bsup_le fun _i hi => hf _ _ <| le_of_lt_succ hi) (le_bsup _ _ _) #align ordinal.bsup_succ_of_mono Ordinal.bsup_succ_of_mono @[simp] theorem bsup_zero (f : ∀ a < (0 : Ordinal), Ordinal) : bsup 0 f = 0 := bsup_eq_zero_iff.2 fun i hi => (Ordinal.not_lt_zero i hi).elim #align ordinal.bsup_zero Ordinal.bsup_zero theorem bsup_const {o : Ordinal.{u}} (ho : o ≠ 0) (a : Ordinal.{max u v}) : (bsup.{_, v} o fun _ _ => a) = a := le_antisymm (bsup_le fun _ _ => le_rfl) (le_bsup _ 0 (Ordinal.pos_iff_ne_zero.2 ho)) #align ordinal.bsup_const Ordinal.bsup_const @[simp] theorem bsup_one (f : ∀ a < (1 : Ordinal), Ordinal) : bsup 1 f = f 0 zero_lt_one := by simp_rw [← sup_eq_bsup, sup_unique, familyOfBFamily, familyOfBFamily', typein_one_out] #align ordinal.bsup_one Ordinal.bsup_one theorem bsup_le_of_brange_subset {o o'} {f : ∀ a < o, Ordinal} {g : ∀ a < o', Ordinal} (h : brange o f ⊆ brange o' g) : bsup.{u, max v w} o f ≤ bsup.{v, max u w} o' g := bsup_le fun i hi => by obtain ⟨j, hj, hj'⟩ := h ⟨i, hi, rfl⟩ rw [← hj'] apply le_bsup #align ordinal.bsup_le_of_brange_subset Ordinal.bsup_le_of_brange_subset theorem bsup_eq_of_brange_eq {o o'} {f : ∀ a < o, Ordinal} {g : ∀ a < o', Ordinal} (h : brange o f = brange o' g) : bsup.{u, max v w} o f = bsup.{v, max u w} o' g := (bsup_le_of_brange_subset.{u, v, w} h.le).antisymm (bsup_le_of_brange_subset.{v, u, w} h.ge) #align ordinal.bsup_eq_of_brange_eq Ordinal.bsup_eq_of_brange_eq /-- The least strict upper bound of a family of ordinals. -/ def lsub {ι} (f : ι → Ordinal) : Ordinal := sup (succ ∘ f) #align ordinal.lsub Ordinal.lsub @[simp] theorem sup_eq_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) : sup.{_, v} (succ ∘ f) = lsub.{_, v} f := rfl #align ordinal.sup_eq_lsub Ordinal.sup_eq_lsub theorem lsub_le_iff {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : lsub.{_, v} f ≤ a ↔ ∀ i, f i < a := by convert sup_le_iff.{_, v} (f := succ ∘ f) (a := a) using 2 -- Porting note: `comp_apply` is required. simp only [comp_apply, succ_le_iff] #align ordinal.lsub_le_iff Ordinal.lsub_le_iff theorem lsub_le {ι} {f : ι → Ordinal} {a} : (∀ i, f i < a) → lsub f ≤ a := lsub_le_iff.2 #align ordinal.lsub_le Ordinal.lsub_le theorem lt_lsub {ι} (f : ι → Ordinal) (i) : f i < lsub f := succ_le_iff.1 (le_sup _ i) #align ordinal.lt_lsub Ordinal.lt_lsub theorem lt_lsub_iff {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : a < lsub.{_, v} f ↔ ∃ i, a ≤ f i := by simpa only [not_forall, not_lt, not_le] using not_congr (@lsub_le_iff.{_, v} _ f a) #align ordinal.lt_lsub_iff Ordinal.lt_lsub_iff theorem sup_le_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) : sup.{_, v} f ≤ lsub.{_, v} f := sup_le fun i => (lt_lsub f i).le #align ordinal.sup_le_lsub Ordinal.sup_le_lsub theorem lsub_le_sup_succ {ι : Type u} (f : ι → Ordinal.{max u v}) : lsub.{_, v} f ≤ succ (sup.{_, v} f) := lsub_le fun i => lt_succ_iff.2 (le_sup f i) #align ordinal.lsub_le_sup_succ Ordinal.lsub_le_sup_succ theorem sup_eq_lsub_or_sup_succ_eq_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) : sup.{_, v} f = lsub.{_, v} f ∨ succ (sup.{_, v} f) = lsub.{_, v} f := by cases' eq_or_lt_of_le (sup_le_lsub.{_, v} f) with h h · exact Or.inl h · exact Or.inr ((succ_le_of_lt h).antisymm (lsub_le_sup_succ f)) #align ordinal.sup_eq_lsub_or_sup_succ_eq_lsub Ordinal.sup_eq_lsub_or_sup_succ_eq_lsub theorem sup_succ_le_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) : succ (sup.{_, v} f) ≤ lsub.{_, v} f ↔ ∃ i, f i = sup.{_, v} f := by refine ⟨fun h => ?_, ?_⟩ · by_contra! hf exact (succ_le_iff.1 h).ne ((sup_le_lsub f).antisymm (lsub_le (ne_sup_iff_lt_sup.1 hf))) rintro ⟨_, hf⟩ rw [succ_le_iff, ← hf] exact lt_lsub _ _ #align ordinal.sup_succ_le_lsub Ordinal.sup_succ_le_lsub theorem sup_succ_eq_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) : succ (sup.{_, v} f) = lsub.{_, v} f ↔ ∃ i, f i = sup.{_, v} f := (lsub_le_sup_succ f).le_iff_eq.symm.trans (sup_succ_le_lsub f) #align ordinal.sup_succ_eq_lsub Ordinal.sup_succ_eq_lsub theorem sup_eq_lsub_iff_succ {ι : Type u} (f : ι → Ordinal.{max u v}) : sup.{_, v} f = lsub.{_, v} f ↔ ∀ a < lsub.{_, v} f, succ a < lsub.{_, v} f := by refine ⟨fun h => ?_, fun hf => le_antisymm (sup_le_lsub f) (lsub_le fun i => ?_)⟩ · rw [← h] exact fun a => sup_not_succ_of_ne_sup fun i => (lsub_le_iff.1 (le_of_eq h.symm) i).ne by_contra! hle have heq := (sup_succ_eq_lsub f).2 ⟨i, le_antisymm (le_sup _ _) hle⟩ have := hf _ (by rw [← heq] exact lt_succ (sup f)) rw [heq] at this exact this.false #align ordinal.sup_eq_lsub_iff_succ Ordinal.sup_eq_lsub_iff_succ theorem sup_eq_lsub_iff_lt_sup {ι : Type u} (f : ι → Ordinal.{max u v}) : sup.{_, v} f = lsub.{_, v} f ↔ ∀ i, f i < sup.{_, v} f := ⟨fun h i => by rw [h] apply lt_lsub, fun h => le_antisymm (sup_le_lsub f) (lsub_le h)⟩ #align ordinal.sup_eq_lsub_iff_lt_sup Ordinal.sup_eq_lsub_iff_lt_sup @[simp] theorem lsub_empty {ι} [h : IsEmpty ι] (f : ι → Ordinal) : lsub f = 0 := by rw [← Ordinal.le_zero, lsub_le_iff] exact h.elim #align ordinal.lsub_empty Ordinal.lsub_empty theorem lsub_pos {ι : Type u} [h : Nonempty ι] (f : ι → Ordinal.{max u v}) : 0 < lsub.{_, v} f := h.elim fun i => (Ordinal.zero_le _).trans_lt (lt_lsub f i) #align ordinal.lsub_pos Ordinal.lsub_pos @[simp] theorem lsub_eq_zero_iff {ι : Type u} (f : ι → Ordinal.{max u v}) : lsub.{_, v} f = 0 ↔ IsEmpty ι := by refine ⟨fun h => ⟨fun i => ?_⟩, fun h => @lsub_empty _ h _⟩ have := @lsub_pos.{_, v} _ ⟨i⟩ f rw [h] at this exact this.false #align ordinal.lsub_eq_zero_iff Ordinal.lsub_eq_zero_iff @[simp] theorem lsub_const {ι} [Nonempty ι] (o : Ordinal) : (lsub fun _ : ι => o) = succ o := sup_const (succ o) #align ordinal.lsub_const Ordinal.lsub_const @[simp] theorem lsub_unique {ι} [Unique ι] (f : ι → Ordinal) : lsub f = succ (f default) := sup_unique _ #align ordinal.lsub_unique Ordinal.lsub_unique theorem lsub_le_of_range_subset {ι ι'} {f : ι → Ordinal} {g : ι' → Ordinal} (h : Set.range f ⊆ Set.range g) : lsub.{u, max v w} f ≤ lsub.{v, max u w} g := sup_le_of_range_subset.{u, v, w} (by convert Set.image_subset succ h <;> apply Set.range_comp) #align ordinal.lsub_le_of_range_subset Ordinal.lsub_le_of_range_subset theorem lsub_eq_of_range_eq {ι ι'} {f : ι → Ordinal} {g : ι' → Ordinal} (h : Set.range f = Set.range g) : lsub.{u, max v w} f = lsub.{v, max u w} g := (lsub_le_of_range_subset.{u, v, w} h.le).antisymm (lsub_le_of_range_subset.{v, u, w} h.ge) #align ordinal.lsub_eq_of_range_eq Ordinal.lsub_eq_of_range_eq @[simp] theorem lsub_sum {α : Type u} {β : Type v} (f : Sum α β → Ordinal) : lsub.{max u v, w} f = max (lsub.{u, max v w} fun a => f (Sum.inl a)) (lsub.{v, max u w} fun b => f (Sum.inr b)) := sup_sum _ #align ordinal.lsub_sum Ordinal.lsub_sum theorem lsub_not_mem_range {ι : Type u} (f : ι → Ordinal.{max u v}) : lsub.{_, v} f ∉ Set.range f := fun ⟨i, h⟩ => h.not_lt (lt_lsub f i) #align ordinal.lsub_not_mem_range Ordinal.lsub_not_mem_range theorem nonempty_compl_range {ι : Type u} (f : ι → Ordinal.{max u v}) : (Set.range f)ᶜ.Nonempty := ⟨_, lsub_not_mem_range.{_, v} f⟩ #align ordinal.nonempty_compl_range Ordinal.nonempty_compl_range @[simp] theorem lsub_typein (o : Ordinal) : lsub.{u, u} (typein ((· < ·) : o.out.α → o.out.α → Prop)) = o := (lsub_le.{u, u} typein_lt_self).antisymm (by by_contra! h -- Porting note: `nth_rw` → `conv_rhs` & `rw` conv_rhs at h => rw [← type_lt o] simpa [typein_enum] using lt_lsub.{u, u} (typein (· < ·)) (enum (· < ·) _ h)) #align ordinal.lsub_typein Ordinal.lsub_typein theorem sup_typein_limit {o : Ordinal} (ho : ∀ a, a < o → succ a < o) : sup.{u, u} (typein ((· < ·) : o.out.α → o.out.α → Prop)) = o := by -- Porting note: `rwa` → `rw` & `assumption` rw [(sup_eq_lsub_iff_succ.{u, u} (typein (· < ·))).2] <;> rw [lsub_typein o]; assumption #align ordinal.sup_typein_limit Ordinal.sup_typein_limit @[simp] theorem sup_typein_succ {o : Ordinal} : sup.{u, u} (typein ((· < ·) : (succ o).out.α → (succ o).out.α → Prop)) = o := by cases' sup_eq_lsub_or_sup_succ_eq_lsub.{u, u} (typein ((· < ·) : (succ o).out.α → (succ o).out.α → Prop)) with h h · rw [sup_eq_lsub_iff_succ] at h simp only [lsub_typein] at h exact (h o (lt_succ o)).false.elim rw [← succ_eq_succ_iff, h] apply lsub_typein #align ordinal.sup_typein_succ Ordinal.sup_typein_succ /-- The least strict upper bound of a family of ordinals indexed by the set of ordinals less than some `o : Ordinal.{u}`. This is to `lsub` as `bsup` is to `sup`. -/ def blsub (o : Ordinal.{u}) (f : ∀ a < o, Ordinal.{max u v}) : Ordinal.{max u v} := bsup.{_, v} o fun a ha => succ (f a ha) #align ordinal.blsub Ordinal.blsub @[simp] theorem bsup_eq_blsub (o : Ordinal.{u}) (f : ∀ a < o, Ordinal.{max u v}) : (bsup.{_, v} o fun a ha => succ (f a ha)) = blsub.{_, v} o f := rfl #align ordinal.bsup_eq_blsub Ordinal.bsup_eq_blsub theorem lsub_eq_blsub' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o} (ho : type r = o) (f : ∀ a < o, Ordinal.{max u v}) : lsub.{_, v} (familyOfBFamily' r ho f) = blsub.{_, v} o f := sup_eq_bsup'.{_, v} r ho fun a ha => succ (f a ha) #align ordinal.lsub_eq_blsub' Ordinal.lsub_eq_blsub' theorem lsub_eq_lsub {ι ι' : Type u} (r : ι → ι → Prop) (r' : ι' → ι' → Prop) [IsWellOrder ι r] [IsWellOrder ι' r'] {o} (ho : type r = o) (ho' : type r' = o) (f : ∀ a < o, Ordinal.{max u v}) : lsub.{_, v} (familyOfBFamily' r ho f) = lsub.{_, v} (familyOfBFamily' r' ho' f) := by rw [lsub_eq_blsub', lsub_eq_blsub'] #align ordinal.lsub_eq_lsub Ordinal.lsub_eq_lsub @[simp] theorem lsub_eq_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : lsub.{_, v} (familyOfBFamily o f) = blsub.{_, v} o f := lsub_eq_blsub' _ _ _ #align ordinal.lsub_eq_blsub Ordinal.lsub_eq_blsub @[simp] theorem blsub_eq_lsub' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → Ordinal.{max u v}) : blsub.{_, v} _ (bfamilyOfFamily' r f) = lsub.{_, v} f := bsup_eq_sup'.{_, v} r (succ ∘ f) #align ordinal.blsub_eq_lsub' Ordinal.blsub_eq_lsub' theorem blsub_eq_blsub {ι : Type u} (r r' : ι → ι → Prop) [IsWellOrder ι r] [IsWellOrder ι r'] (f : ι → Ordinal.{max u v}) : blsub.{_, v} _ (bfamilyOfFamily' r f) = blsub.{_, v} _ (bfamilyOfFamily' r' f) := by rw [blsub_eq_lsub', blsub_eq_lsub'] #align ordinal.blsub_eq_blsub Ordinal.blsub_eq_blsub @[simp] theorem blsub_eq_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) : blsub.{_, v} _ (bfamilyOfFamily f) = lsub.{_, v} f := blsub_eq_lsub' _ _ #align ordinal.blsub_eq_lsub Ordinal.blsub_eq_lsub @[congr] theorem blsub_congr {o₁ o₂ : Ordinal.{u}} (f : ∀ a < o₁, Ordinal.{max u v}) (ho : o₁ = o₂) : blsub.{_, v} o₁ f = blsub.{_, v} o₂ fun a h => f a (h.trans_eq ho.symm) := by subst ho -- Porting note: `rfl` is required. rfl #align ordinal.blsub_congr Ordinal.blsub_congr theorem blsub_le_iff {o : Ordinal.{u}} {f : ∀ a < o, Ordinal.{max u v}} {a} : blsub.{_, v} o f ≤ a ↔ ∀ i h, f i h < a := by convert bsup_le_iff.{_, v} (f := fun a ha => succ (f a ha)) (a := a) using 2 simp_rw [succ_le_iff] #align ordinal.blsub_le_iff Ordinal.blsub_le_iff theorem blsub_le {o : Ordinal} {f : ∀ b < o, Ordinal} {a} : (∀ i h, f i h < a) → blsub o f ≤ a := blsub_le_iff.2 #align ordinal.blsub_le Ordinal.blsub_le theorem lt_blsub {o} (f : ∀ a < o, Ordinal) (i h) : f i h < blsub o f := blsub_le_iff.1 le_rfl _ _ #align ordinal.lt_blsub Ordinal.lt_blsub theorem lt_blsub_iff {o : Ordinal.{u}} {f : ∀ b < o, Ordinal.{max u v}} {a} : a < blsub.{_, v} o f ↔ ∃ i hi, a ≤ f i hi := by simpa only [not_forall, not_lt, not_le] using not_congr (@blsub_le_iff.{_, v} _ f a) #align ordinal.lt_blsub_iff Ordinal.lt_blsub_iff theorem bsup_le_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : bsup.{_, v} o f ≤ blsub.{_, v} o f := bsup_le fun i h => (lt_blsub f i h).le #align ordinal.bsup_le_blsub Ordinal.bsup_le_blsub theorem blsub_le_bsup_succ {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : blsub.{_, v} o f ≤ succ (bsup.{_, v} o f) := blsub_le fun i h => lt_succ_iff.2 (le_bsup f i h) #align ordinal.blsub_le_bsup_succ Ordinal.blsub_le_bsup_succ theorem bsup_eq_blsub_or_succ_bsup_eq_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : bsup.{_, v} o f = blsub.{_, v} o f ∨ succ (bsup.{_, v} o f) = blsub.{_, v} o f := by rw [← sup_eq_bsup, ← lsub_eq_blsub] exact sup_eq_lsub_or_sup_succ_eq_lsub _ #align ordinal.bsup_eq_blsub_or_succ_bsup_eq_blsub Ordinal.bsup_eq_blsub_or_succ_bsup_eq_blsub theorem bsup_succ_le_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : succ (bsup.{_, v} o f) ≤ blsub.{_, v} o f ↔ ∃ i hi, f i hi = bsup.{_, v} o f := by refine ⟨fun h => ?_, ?_⟩ · by_contra! hf exact ne_of_lt (succ_le_iff.1 h) (le_antisymm (bsup_le_blsub f) (blsub_le (lt_bsup_of_ne_bsup.1 hf))) rintro ⟨_, _, hf⟩ rw [succ_le_iff, ← hf] exact lt_blsub _ _ _ #align ordinal.bsup_succ_le_blsub Ordinal.bsup_succ_le_blsub theorem bsup_succ_eq_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : succ (bsup.{_, v} o f) = blsub.{_, v} o f ↔ ∃ i hi, f i hi = bsup.{_, v} o f := (blsub_le_bsup_succ f).le_iff_eq.symm.trans (bsup_succ_le_blsub f) #align ordinal.bsup_succ_eq_blsub Ordinal.bsup_succ_eq_blsub theorem bsup_eq_blsub_iff_succ {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : bsup.{_, v} o f = blsub.{_, v} o f ↔ ∀ a < blsub.{_, v} o f, succ a < blsub.{_, v} o f := by rw [← sup_eq_bsup, ← lsub_eq_blsub] apply sup_eq_lsub_iff_succ #align ordinal.bsup_eq_blsub_iff_succ Ordinal.bsup_eq_blsub_iff_succ theorem bsup_eq_blsub_iff_lt_bsup {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) : bsup.{_, v} o f = blsub.{_, v} o f ↔ ∀ i hi, f i hi < bsup.{_, v} o f := ⟨fun h i => by rw [h] apply lt_blsub, fun h => le_antisymm (bsup_le_blsub f) (blsub_le h)⟩ #align ordinal.bsup_eq_blsub_iff_lt_bsup Ordinal.bsup_eq_blsub_iff_lt_bsup theorem bsup_eq_blsub_of_lt_succ_limit {o : Ordinal.{u}} (ho : IsLimit o) {f : ∀ a < o, Ordinal.{max u v}} (hf : ∀ a ha, f a ha < f (succ a) (ho.2 a ha)) : bsup.{_, v} o f = blsub.{_, v} o f := by rw [bsup_eq_blsub_iff_lt_bsup] exact fun i hi => (hf i hi).trans_le (le_bsup f _ _) #align ordinal.bsup_eq_blsub_of_lt_succ_limit Ordinal.bsup_eq_blsub_of_lt_succ_limit theorem blsub_succ_of_mono {o : Ordinal.{u}} {f : ∀ a < succ o, Ordinal.{max u v}} (hf : ∀ {i j} (hi hj), i ≤ j → f i hi ≤ f j hj) : blsub.{_, v} _ f = succ (f o (lt_succ o)) := bsup_succ_of_mono fun {_ _} hi hj h => succ_le_succ (hf hi hj h) #align ordinal.blsub_succ_of_mono Ordinal.blsub_succ_of_mono @[simp] theorem blsub_eq_zero_iff {o} {f : ∀ a < o, Ordinal} : blsub o f = 0 ↔ o = 0 := by rw [← lsub_eq_blsub, lsub_eq_zero_iff] exact out_empty_iff_eq_zero #align ordinal.blsub_eq_zero_iff Ordinal.blsub_eq_zero_iff -- Porting note: `rwa` → `rw` @[simp] theorem blsub_zero (f : ∀ a < (0 : Ordinal), Ordinal) : blsub 0 f = 0 := by rw [blsub_eq_zero_iff] #align ordinal.blsub_zero Ordinal.blsub_zero theorem blsub_pos {o : Ordinal} (ho : 0 < o) (f : ∀ a < o, Ordinal) : 0 < blsub o f := (Ordinal.zero_le _).trans_lt (lt_blsub f 0 ho) #align ordinal.blsub_pos Ordinal.blsub_pos theorem blsub_type {α : Type u} (r : α → α → Prop) [IsWellOrder α r] (f : ∀ a < type r, Ordinal.{max u v}) : blsub.{_, v} (type r) f = lsub.{_, v} fun a => f (typein r a) (typein_lt_type _ _) := eq_of_forall_ge_iff fun o => by rw [blsub_le_iff, lsub_le_iff]; exact ⟨fun H b => H _ _, fun H i h => by simpa only [typein_enum] using H (enum r i h)⟩ #align ordinal.blsub_type Ordinal.blsub_type theorem blsub_const {o : Ordinal} (ho : o ≠ 0) (a : Ordinal) : (blsub.{u, v} o fun _ _ => a) = succ a := bsup_const.{u, v} ho (succ a) #align ordinal.blsub_const Ordinal.blsub_const @[simp] theorem blsub_one (f : ∀ a < (1 : Ordinal), Ordinal) : blsub 1 f = succ (f 0 zero_lt_one) := bsup_one _ #align ordinal.blsub_one Ordinal.blsub_one @[simp] theorem blsub_id : ∀ o, (blsub.{u, u} o fun x _ => x) = o := lsub_typein #align ordinal.blsub_id Ordinal.blsub_id theorem bsup_id_limit {o : Ordinal} : (∀ a < o, succ a < o) → (bsup.{u, u} o fun x _ => x) = o := sup_typein_limit #align ordinal.bsup_id_limit Ordinal.bsup_id_limit @[simp] theorem bsup_id_succ (o) : (bsup.{u, u} (succ o) fun x _ => x) = o := sup_typein_succ #align ordinal.bsup_id_succ Ordinal.bsup_id_succ theorem blsub_le_of_brange_subset {o o'} {f : ∀ a < o, Ordinal} {g : ∀ a < o', Ordinal} (h : brange o f ⊆ brange o' g) : blsub.{u, max v w} o f ≤ blsub.{v, max u w} o' g := bsup_le_of_brange_subset.{u, v, w} fun a ⟨b, hb, hb'⟩ => by obtain ⟨c, hc, hc'⟩ := h ⟨b, hb, rfl⟩ simp_rw [← hc'] at hb' exact ⟨c, hc, hb'⟩ #align ordinal.blsub_le_of_brange_subset Ordinal.blsub_le_of_brange_subset theorem blsub_eq_of_brange_eq {o o'} {f : ∀ a < o, Ordinal} {g : ∀ a < o', Ordinal} (h : { o | ∃ i hi, f i hi = o } = { o | ∃ i hi, g i hi = o }) : blsub.{u, max v w} o f = blsub.{v, max u w} o' g := (blsub_le_of_brange_subset.{u, v, w} h.le).antisymm (blsub_le_of_brange_subset.{v, u, w} h.ge) #align ordinal.blsub_eq_of_brange_eq Ordinal.blsub_eq_of_brange_eq theorem bsup_comp {o o' : Ordinal.{max u v}} {f : ∀ a < o, Ordinal.{max u v w}} (hf : ∀ {i j} (hi) (hj), i ≤ j → f i hi ≤ f j hj) {g : ∀ a < o', Ordinal.{max u v}} (hg : blsub.{_, u} o' g = o) : (bsup.{_, w} o' fun a ha => f (g a ha) (by rw [← hg]; apply lt_blsub)) = bsup.{_, w} o f := by apply le_antisymm <;> refine bsup_le fun i hi => ?_ · apply le_bsup · rw [← hg, lt_blsub_iff] at hi rcases hi with ⟨j, hj, hj'⟩ exact (hf _ _ hj').trans (le_bsup _ _ _) #align ordinal.bsup_comp Ordinal.bsup_comp theorem blsub_comp {o o' : Ordinal.{max u v}} {f : ∀ a < o, Ordinal.{max u v w}} (hf : ∀ {i j} (hi) (hj), i ≤ j → f i hi ≤ f j hj) {g : ∀ a < o', Ordinal.{max u v}} (hg : blsub.{_, u} o' g = o) : (blsub.{_, w} o' fun a ha => f (g a ha) (by rw [← hg]; apply lt_blsub)) = blsub.{_, w} o f := @bsup_comp.{u, v, w} o _ (fun a ha => succ (f a ha)) (fun {_ _} _ _ h => succ_le_succ_iff.2 (hf _ _ h)) g hg #align ordinal.blsub_comp Ordinal.blsub_comp theorem IsNormal.bsup_eq {f : Ordinal.{u} → Ordinal.{max u v}} (H : IsNormal f) {o : Ordinal.{u}} (h : IsLimit o) : (Ordinal.bsup.{_, v} o fun x _ => f x) = f o := by rw [← IsNormal.bsup.{u, u, v} H (fun x _ => x) h.1, bsup_id_limit h.2] #align ordinal.is_normal.bsup_eq Ordinal.IsNormal.bsup_eq theorem IsNormal.blsub_eq {f : Ordinal.{u} → Ordinal.{max u v}} (H : IsNormal f) {o : Ordinal.{u}} (h : IsLimit o) : (blsub.{_, v} o fun x _ => f x) = f o := by rw [← IsNormal.bsup_eq.{u, v} H h, bsup_eq_blsub_of_lt_succ_limit h] exact fun a _ => H.1 a #align ordinal.is_normal.blsub_eq Ordinal.IsNormal.blsub_eq theorem isNormal_iff_lt_succ_and_bsup_eq {f : Ordinal.{u} → Ordinal.{max u v}} : IsNormal f ↔ (∀ a, f a < f (succ a)) ∧ ∀ o, IsLimit o → (bsup.{_, v} o fun x _ => f x) = f o := ⟨fun h => ⟨h.1, @IsNormal.bsup_eq f h⟩, fun ⟨h₁, h₂⟩ => ⟨h₁, fun o ho a => by rw [← h₂ o ho] exact bsup_le_iff⟩⟩ #align ordinal.is_normal_iff_lt_succ_and_bsup_eq Ordinal.isNormal_iff_lt_succ_and_bsup_eq theorem isNormal_iff_lt_succ_and_blsub_eq {f : Ordinal.{u} → Ordinal.{max u v}} : IsNormal f ↔ (∀ a, f a < f (succ a)) ∧ ∀ o, IsLimit o → (blsub.{_, v} o fun x _ => f x) = f o := by rw [isNormal_iff_lt_succ_and_bsup_eq.{u, v}, and_congr_right_iff] intro h constructor <;> intro H o ho <;> have := H o ho <;> rwa [← bsup_eq_blsub_of_lt_succ_limit ho fun a _ => h a] at * #align ordinal.is_normal_iff_lt_succ_and_blsub_eq Ordinal.isNormal_iff_lt_succ_and_blsub_eq theorem IsNormal.eq_iff_zero_and_succ {f g : Ordinal.{u} → Ordinal.{u}} (hf : IsNormal f) (hg : IsNormal g) : f = g ↔ f 0 = g 0 ∧ ∀ a, f a = g a → f (succ a) = g (succ a) := ⟨fun h => by simp [h], fun ⟨h₁, h₂⟩ => funext fun a => by induction' a using limitRecOn with _ _ _ ho H any_goals solve_by_elim rw [← IsNormal.bsup_eq.{u, u} hf ho, ← IsNormal.bsup_eq.{u, u} hg ho] congr ext b hb exact H b hb⟩ #align ordinal.is_normal.eq_iff_zero_and_succ Ordinal.IsNormal.eq_iff_zero_and_succ /-- A two-argument version of `Ordinal.blsub`. We don't develop a full API for this, since it's only used in a handful of existence results. -/ def blsub₂ (o₁ o₂ : Ordinal) (op : {a : Ordinal} → (a < o₁) → {b : Ordinal} → (b < o₂) → Ordinal) : Ordinal := lsub (fun x : o₁.out.α × o₂.out.α => op (typein_lt_self x.1) (typein_lt_self x.2)) #align ordinal.blsub₂ Ordinal.blsub₂
Mathlib/SetTheory/Ordinal/Arithmetic.lean
2,005
2,010
theorem lt_blsub₂ {o₁ o₂ : Ordinal} (op : {a : Ordinal} → (a < o₁) → {b : Ordinal} → (b < o₂) → Ordinal) {a b : Ordinal} (ha : a < o₁) (hb : b < o₂) : op ha hb < blsub₂ o₁ o₂ op := by
convert lt_lsub _ (Prod.mk (enum (· < ·) a (by rwa [type_lt])) (enum (· < ·) b (by rwa [type_lt]))) simp only [typein_enum]
/- Copyright (c) 2024 Josha Dekker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Josha Dekker, Devon Tuma, Kexing Ying -/ import Mathlib.Probability.Notation import Mathlib.Probability.Density import Mathlib.Probability.ConditionalProbability import Mathlib.Probability.ProbabilityMassFunction.Constructions /-! # Uniform distributions and probability mass functions This file defines two related notions of uniform distributions, which will be unified in the future. # Uniform distributions Defines the uniform distribution for any set with finite measure. ## Main definitions * `IsUniform X s ℙ μ` : A random variable `X` has uniform distribution on `s` under `ℙ` if the push-forward measure agrees with the rescaled restricted measure `μ`. # Uniform probability mass functions This file defines a number of uniform `PMF` distributions from various inputs, uniformly drawing from the corresponding object. ## Main definitions `PMF.uniformOfFinset` gives each element in the set equal probability, with `0` probability for elements not in the set. `PMF.uniformOfFintype` gives all elements equal probability, equal to the inverse of the size of the `Fintype`. `PMF.ofMultiset` draws randomly from the given `Multiset`, treating duplicate values as distinct. Each probability is given by the count of the element divided by the size of the `Multiset` # To Do: * Refactor the `PMF` definitions to come from a `uniformMeasure` on a `Finset`/`Fintype`/`Multiset`. -/ open scoped Classical MeasureTheory NNReal ENNReal -- TODO: We can't `open ProbabilityTheory` without opening the `ProbabilityTheory` locale :( open TopologicalSpace MeasureTheory.Measure PMF noncomputable section namespace MeasureTheory variable {E : Type*} [MeasurableSpace E] {m : Measure E} {μ : Measure E} namespace pdf variable {Ω : Type*} variable {_ : MeasurableSpace Ω} {ℙ : Measure Ω} /-- A random variable `X` has uniform distribution on `s` if its push-forward measure is `(μ s)⁻¹ • μ.restrict s`. -/ def IsUniform (X : Ω → E) (s : Set E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) := map X ℙ = ProbabilityTheory.cond μ s #align measure_theory.pdf.is_uniform MeasureTheory.pdf.IsUniform namespace IsUniform theorem aemeasurable {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞) (hu : IsUniform X s ℙ μ) : AEMeasurable X ℙ := by dsimp [IsUniform, ProbabilityTheory.cond] at hu by_contra h rw [map_of_not_aemeasurable h] at hu apply zero_ne_one' ℝ≥0∞ calc 0 = (0 : Measure E) Set.univ := rfl _ = _ := by rw [hu, smul_apply, restrict_apply MeasurableSet.univ, Set.univ_inter, smul_eq_mul, ENNReal.inv_mul_cancel hns hnt] theorem absolutelyContinuous {X : Ω → E} {s : Set E} (hu : IsUniform X s ℙ μ) : map X ℙ ≪ μ := by rw [hu]; exact ProbabilityTheory.cond_absolutelyContinuous theorem measure_preimage {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞) (hu : IsUniform X s ℙ μ) {A : Set E} (hA : MeasurableSet A) : ℙ (X ⁻¹' A) = μ (s ∩ A) / μ s := by rwa [← map_apply_of_aemeasurable (hu.aemeasurable hns hnt) hA, hu, ProbabilityTheory.cond_apply', ENNReal.div_eq_inv_mul] #align measure_theory.pdf.is_uniform.measure_preimage MeasureTheory.pdf.IsUniform.measure_preimage theorem isProbabilityMeasure {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞) (hu : IsUniform X s ℙ μ) : IsProbabilityMeasure ℙ := ⟨by have : X ⁻¹' Set.univ = Set.univ := Set.preimage_univ rw [← this, hu.measure_preimage hns hnt MeasurableSet.univ, Set.inter_univ, ENNReal.div_self hns hnt]⟩ #align measure_theory.pdf.is_uniform.is_probability_measure MeasureTheory.pdf.IsUniform.isProbabilityMeasure theorem toMeasurable_iff {X : Ω → E} {s : Set E} : IsUniform X (toMeasurable μ s) ℙ μ ↔ IsUniform X s ℙ μ := by unfold IsUniform rw [ProbabilityTheory.cond_toMeasurable_eq] protected theorem toMeasurable {X : Ω → E} {s : Set E} (hu : IsUniform X s ℙ μ) : IsUniform X (toMeasurable μ s) ℙ μ := by unfold IsUniform at * rwa [ProbabilityTheory.cond_toMeasurable_eq] theorem hasPDF {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞) (hu : IsUniform X s ℙ μ) : HasPDF X ℙ μ := by let t := toMeasurable μ s apply hasPDF_of_map_eq_withDensity (hu.aemeasurable hns hnt) (t.indicator ((μ t)⁻¹ • 1)) <| (measurable_one.aemeasurable.const_smul (μ t)⁻¹).indicator (measurableSet_toMeasurable μ s) rw [hu, withDensity_indicator (measurableSet_toMeasurable μ s), withDensity_smul _ measurable_one, withDensity_one, restrict_toMeasurable hnt, measure_toMeasurable, ProbabilityTheory.cond] #align measure_theory.pdf.is_uniform.has_pdf MeasureTheory.pdf.IsUniform.hasPDF theorem pdf_eq_zero_of_measure_eq_zero_or_top {X : Ω → E} {s : Set E} (hu : IsUniform X s ℙ μ) (hμs : μ s = 0 ∨ μ s = ∞) : pdf X ℙ μ =ᵐ[μ] 0 := by rcases hμs with H|H · simp only [IsUniform, ProbabilityTheory.cond, H, ENNReal.inv_zero, restrict_eq_zero.mpr H, smul_zero] at hu simp [pdf, hu] · simp only [IsUniform, ProbabilityTheory.cond, H, ENNReal.inv_top, zero_smul] at hu simp [pdf, hu] theorem pdf_eq {X : Ω → E} {s : Set E} (hms : MeasurableSet s) (hu : IsUniform X s ℙ μ) : pdf X ℙ μ =ᵐ[μ] s.indicator ((μ s)⁻¹ • (1 : E → ℝ≥0∞)) := by by_cases hnt : μ s = ∞ · simp [pdf_eq_zero_of_measure_eq_zero_or_top hu (Or.inr hnt), hnt] by_cases hns : μ s = 0 · filter_upwards [measure_zero_iff_ae_nmem.mp hns, pdf_eq_zero_of_measure_eq_zero_or_top hu (Or.inl hns)] with x hx h'x simp [hx, h'x, hns] have : HasPDF X ℙ μ := hasPDF hns hnt hu have : IsProbabilityMeasure ℙ := isProbabilityMeasure hns hnt hu apply (eq_of_map_eq_withDensity _ _).mp · rw [hu, withDensity_indicator hms, withDensity_smul _ measurable_one, withDensity_one, ProbabilityTheory.cond] · exact (measurable_one.aemeasurable.const_smul (μ s)⁻¹).indicator hms theorem pdf_toReal_ae_eq {X : Ω → E} {s : Set E} (hms : MeasurableSet s) (hX : IsUniform X s ℙ μ) : (fun x => (pdf X ℙ μ x).toReal) =ᵐ[μ] fun x => (s.indicator ((μ s)⁻¹ • (1 : E → ℝ≥0∞)) x).toReal := Filter.EventuallyEq.fun_comp (pdf_eq hms hX) ENNReal.toReal #align measure_theory.pdf.is_uniform.pdf_to_real_ae_eq MeasureTheory.pdf.IsUniform.pdf_toReal_ae_eq variable {X : Ω → ℝ} {s : Set ℝ} theorem mul_pdf_integrable (hcs : IsCompact s) (huX : IsUniform X s ℙ) : Integrable fun x : ℝ => x * (pdf X ℙ volume x).toReal := by by_cases hnt : volume s = 0 ∨ volume s = ∞ · have I : Integrable (fun x ↦ x * ENNReal.toReal (0)) := by simp apply I.congr filter_upwards [pdf_eq_zero_of_measure_eq_zero_or_top huX hnt] with x hx simp [hx] simp only [not_or] at hnt have : IsProbabilityMeasure ℙ := isProbabilityMeasure hnt.1 hnt.2 huX constructor · exact aestronglyMeasurable_id.mul (measurable_pdf X ℙ).aemeasurable.ennreal_toReal.aestronglyMeasurable refine hasFiniteIntegral_mul (pdf_eq hcs.measurableSet huX) ?_ set ind := (volume s)⁻¹ • (1 : ℝ → ℝ≥0∞) have : ∀ x, ↑‖x‖₊ * s.indicator ind x = s.indicator (fun x => ‖x‖₊ * ind x) x := fun x => (s.indicator_mul_right (fun x => ↑‖x‖₊) ind).symm simp only [ind, this, lintegral_indicator _ hcs.measurableSet, mul_one, Algebra.id.smul_eq_mul, Pi.one_apply, Pi.smul_apply] rw [lintegral_mul_const _ measurable_nnnorm.coe_nnreal_ennreal] exact (ENNReal.mul_lt_top (set_lintegral_lt_top_of_isCompact hnt.2 hcs continuous_nnnorm).ne (ENNReal.inv_lt_top.2 (pos_iff_ne_zero.mpr hnt.1)).ne).ne #align measure_theory.pdf.is_uniform.mul_pdf_integrable MeasureTheory.pdf.IsUniform.mul_pdf_integrable /-- A real uniform random variable `X` with support `s` has expectation `(λ s)⁻¹ * ∫ x in s, x ∂λ` where `λ` is the Lebesgue measure. -/ theorem integral_eq (huX : IsUniform X s ℙ) : ∫ x, X x ∂ℙ = (volume s)⁻¹.toReal * ∫ x in s, x := by rw [← smul_eq_mul, ← integral_smul_measure] dsimp only [IsUniform, ProbabilityTheory.cond] at huX rw [← huX] by_cases hX : AEMeasurable X ℙ · exact (integral_map hX aestronglyMeasurable_id).symm · rw [map_of_not_aemeasurable hX, integral_zero_measure, integral_non_aestronglyMeasurable] rwa [aestronglyMeasurable_iff_aemeasurable] #align measure_theory.pdf.is_uniform.integral_eq MeasureTheory.pdf.IsUniform.integral_eq end IsUniform variable {X : Ω → E} lemma IsUniform.cond {s : Set E} : IsUniform (id : E → E) s (ProbabilityTheory.cond μ s) μ := by unfold IsUniform rw [Measure.map_id] /-- The density of the uniform measure on a set with respect to itself. This allows us to abstract away the choice of random variable and probability space. -/ def uniformPDF (s : Set E) (x : E) (μ : Measure E := by volume_tac) : ℝ≥0∞ := s.indicator ((μ s)⁻¹ • (1 : E → ℝ≥0∞)) x /-- Check that indeed any uniform random variable has the uniformPDF. -/ lemma uniformPDF_eq_pdf {s : Set E} (hs : MeasurableSet s) (hu : pdf.IsUniform X s ℙ μ) : (fun x ↦ uniformPDF s x μ) =ᵐ[μ] pdf X ℙ μ := by unfold uniformPDF exact Filter.EventuallyEq.trans (pdf.IsUniform.pdf_eq hs hu).symm (ae_eq_refl _) /-- Alternative way of writing the uniformPDF. -/ lemma uniformPDF_ite {s : Set E} {x : E} : uniformPDF s x μ = if x ∈ s then (μ s)⁻¹ else 0 := by unfold uniformPDF unfold Set.indicator simp only [Pi.smul_apply, Pi.one_apply, smul_eq_mul, mul_one] end pdf end MeasureTheory noncomputable section namespace PMF variable {α β γ : Type*} open scoped Classical NNReal ENNReal section UniformOfFinset /-- Uniform distribution taking the same non-zero probability on the nonempty finset `s` -/ def uniformOfFinset (s : Finset α) (hs : s.Nonempty) : PMF α := by refine ofFinset (fun a => if a ∈ s then s.card⁻¹ else 0) s ?_ ?_ · simp only [Finset.sum_ite_mem, Finset.inter_self, Finset.sum_const, nsmul_eq_mul] have : (s.card : ℝ≥0∞) ≠ 0 := by simpa only [Ne, Nat.cast_eq_zero, Finset.card_eq_zero] using Finset.nonempty_iff_ne_empty.1 hs exact ENNReal.mul_inv_cancel this <| ENNReal.natCast_ne_top s.card · exact fun x hx => by simp only [hx, if_false] #align pmf.uniform_of_finset PMF.uniformOfFinset variable {s : Finset α} (hs : s.Nonempty) {a : α} @[simp] theorem uniformOfFinset_apply (a : α) : uniformOfFinset s hs a = if a ∈ s then (s.card : ℝ≥0∞)⁻¹ else 0 := rfl #align pmf.uniform_of_finset_apply PMF.uniformOfFinset_apply theorem uniformOfFinset_apply_of_mem (ha : a ∈ s) : uniformOfFinset s hs a = (s.card : ℝ≥0∞)⁻¹ := by simp [ha] #align pmf.uniform_of_finset_apply_of_mem PMF.uniformOfFinset_apply_of_mem theorem uniformOfFinset_apply_of_not_mem (ha : a ∉ s) : uniformOfFinset s hs a = 0 := by simp [ha] #align pmf.uniform_of_finset_apply_of_not_mem PMF.uniformOfFinset_apply_of_not_mem @[simp] theorem support_uniformOfFinset : (uniformOfFinset s hs).support = s := Set.ext (by let ⟨a, ha⟩ := hs simp [mem_support_iff, Finset.ne_empty_of_mem ha]) #align pmf.support_uniform_of_finset PMF.support_uniformOfFinset theorem mem_support_uniformOfFinset_iff (a : α) : a ∈ (uniformOfFinset s hs).support ↔ a ∈ s := by simp #align pmf.mem_support_uniform_of_finset_iff PMF.mem_support_uniformOfFinset_iff section Measure variable (t : Set α) @[simp] theorem toOuterMeasure_uniformOfFinset_apply : (uniformOfFinset s hs).toOuterMeasure t = (s.filter (· ∈ t)).card / s.card := calc (uniformOfFinset s hs).toOuterMeasure t = ∑' x, if x ∈ t then uniformOfFinset s hs x else 0 := toOuterMeasure_apply (uniformOfFinset s hs) t _ = ∑' x, if x ∈ s ∧ x ∈ t then (s.card : ℝ≥0∞)⁻¹ else 0 := (tsum_congr fun x => by simp_rw [uniformOfFinset_apply, ← ite_and, and_comm]) _ = ∑ x ∈ s.filter (· ∈ t), if x ∈ s ∧ x ∈ t then (s.card : ℝ≥0∞)⁻¹ else 0 := (tsum_eq_sum fun x hx => if_neg fun h => hx (Finset.mem_filter.2 h)) _ = ∑ _x ∈ s.filter (· ∈ t), (s.card : ℝ≥0∞)⁻¹ := (Finset.sum_congr rfl fun x hx => by let this : x ∈ s ∧ x ∈ t := by simpa using hx simp only [this, and_self_iff, if_true]) _ = (s.filter (· ∈ t)).card / s.card := by simp only [div_eq_mul_inv, Finset.sum_const, nsmul_eq_mul] #align pmf.to_outer_measure_uniform_of_finset_apply PMF.toOuterMeasure_uniformOfFinset_apply @[simp] theorem toMeasure_uniformOfFinset_apply [MeasurableSpace α] (ht : MeasurableSet t) : (uniformOfFinset s hs).toMeasure t = (s.filter (· ∈ t)).card / s.card := (toMeasure_apply_eq_toOuterMeasure_apply _ t ht).trans (toOuterMeasure_uniformOfFinset_apply hs t) #align pmf.to_measure_uniform_of_finset_apply PMF.toMeasure_uniformOfFinset_apply end Measure end UniformOfFinset section UniformOfFintype /-- The uniform pmf taking the same uniform value on all of the fintype `α` -/ def uniformOfFintype (α : Type*) [Fintype α] [Nonempty α] : PMF α := uniformOfFinset Finset.univ Finset.univ_nonempty #align pmf.uniform_of_fintype PMF.uniformOfFintype variable [Fintype α] [Nonempty α] @[simp]
Mathlib/Probability/Distributions/Uniform.lean
305
306
theorem uniformOfFintype_apply (a : α) : uniformOfFintype α a = (Fintype.card α : ℝ≥0∞)⁻¹ := by
simp [uniformOfFintype, Finset.mem_univ, if_true, uniformOfFinset_apply]
/- Copyright (c) 2021 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Sébastien Gouëzel -/ import Mathlib.LinearAlgebra.FiniteDimensional import Mathlib.MeasureTheory.Group.Pointwise import Mathlib.MeasureTheory.Measure.Lebesgue.Basic import Mathlib.MeasureTheory.Measure.Haar.Basic import Mathlib.MeasureTheory.Measure.Doubling import Mathlib.MeasureTheory.Constructions.BorelSpace.Metric #align_import measure_theory.measure.lebesgue.eq_haar from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844" /-! # Relationship between the Haar and Lebesgue measures We prove that the Haar measure and Lebesgue measure are equal on `ℝ` and on `ℝ^ι`, in `MeasureTheory.addHaarMeasure_eq_volume` and `MeasureTheory.addHaarMeasure_eq_volume_pi`. We deduce basic properties of any Haar measure on a finite dimensional real vector space: * `map_linearMap_addHaar_eq_smul_addHaar`: a linear map rescales the Haar measure by the absolute value of its determinant. * `addHaar_preimage_linearMap` : when `f` is a linear map with nonzero determinant, the measure of `f ⁻¹' s` is the measure of `s` multiplied by the absolute value of the inverse of the determinant of `f`. * `addHaar_image_linearMap` : when `f` is a linear map, the measure of `f '' s` is the measure of `s` multiplied by the absolute value of the determinant of `f`. * `addHaar_submodule` : a strict submodule has measure `0`. * `addHaar_smul` : the measure of `r • s` is `|r| ^ dim * μ s`. * `addHaar_ball`: the measure of `ball x r` is `r ^ dim * μ (ball 0 1)`. * `addHaar_closedBall`: the measure of `closedBall x r` is `r ^ dim * μ (ball 0 1)`. * `addHaar_sphere`: spheres have zero measure. This makes it possible to associate a Lebesgue measure to an `n`-alternating map in dimension `n`. This measure is called `AlternatingMap.measure`. Its main property is `ω.measure_parallelepiped v`, stating that the associated measure of the parallelepiped spanned by vectors `v₁, ..., vₙ` is given by `|ω v|`. We also show that a Lebesgue density point `x` of a set `s` (with respect to closed balls) has density one for the rescaled copies `{x} + r • t` of a given set `t` with positive measure, in `tendsto_addHaar_inter_smul_one_of_density_one`. In particular, `s` intersects `{x} + r • t` for small `r`, see `eventually_nonempty_inter_smul_of_density_one`. Statements on integrals of functions with respect to an additive Haar measure can be found in `MeasureTheory.Measure.Haar.NormedSpace`. -/ assert_not_exists MeasureTheory.integral open TopologicalSpace Set Filter Metric Bornology open scoped ENNReal Pointwise Topology NNReal /-- The interval `[0,1]` as a compact set with non-empty interior. -/ def TopologicalSpace.PositiveCompacts.Icc01 : PositiveCompacts ℝ where carrier := Icc 0 1 isCompact' := isCompact_Icc interior_nonempty' := by simp_rw [interior_Icc, nonempty_Ioo, zero_lt_one] #align topological_space.positive_compacts.Icc01 TopologicalSpace.PositiveCompacts.Icc01 universe u /-- The set `[0,1]^ι` as a compact set with non-empty interior. -/ def TopologicalSpace.PositiveCompacts.piIcc01 (ι : Type*) [Finite ι] : PositiveCompacts (ι → ℝ) where carrier := pi univ fun _ => Icc 0 1 isCompact' := isCompact_univ_pi fun _ => isCompact_Icc interior_nonempty' := by simp only [interior_pi_set, Set.toFinite, interior_Icc, univ_pi_nonempty_iff, nonempty_Ioo, imp_true_iff, zero_lt_one] #align topological_space.positive_compacts.pi_Icc01 TopologicalSpace.PositiveCompacts.piIcc01 /-- The parallelepiped formed from the standard basis for `ι → ℝ` is `[0,1]^ι` -/ theorem Basis.parallelepiped_basisFun (ι : Type*) [Fintype ι] : (Pi.basisFun ℝ ι).parallelepiped = TopologicalSpace.PositiveCompacts.piIcc01 ι := SetLike.coe_injective <| by refine Eq.trans ?_ ((uIcc_of_le ?_).trans (Set.pi_univ_Icc _ _).symm) · classical convert parallelepiped_single (ι := ι) 1 · exact zero_le_one #align basis.parallelepiped_basis_fun Basis.parallelepiped_basisFun /-- A parallelepiped can be expressed on the standard basis. -/ theorem Basis.parallelepiped_eq_map {ι E : Type*} [Fintype ι] [NormedAddCommGroup E] [NormedSpace ℝ E] (b : Basis ι ℝ E) : b.parallelepiped = (PositiveCompacts.piIcc01 ι).map b.equivFun.symm b.equivFunL.symm.continuous b.equivFunL.symm.isOpenMap := by classical rw [← Basis.parallelepiped_basisFun, ← Basis.parallelepiped_map] congr with x simp open MeasureTheory MeasureTheory.Measure theorem Basis.map_addHaar {ι E F : Type*} [Fintype ι] [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace ℝ E] [NormedSpace ℝ F] [MeasurableSpace E] [MeasurableSpace F] [BorelSpace E] [BorelSpace F] [SecondCountableTopology F] [SigmaCompactSpace F] (b : Basis ι ℝ E) (f : E ≃L[ℝ] F) : map f b.addHaar = (b.map f.toLinearEquiv).addHaar := by have : IsAddHaarMeasure (map f b.addHaar) := AddEquiv.isAddHaarMeasure_map b.addHaar f.toAddEquiv f.continuous f.symm.continuous rw [eq_comm, Basis.addHaar_eq_iff, Measure.map_apply f.continuous.measurable (PositiveCompacts.isCompact _).measurableSet, Basis.coe_parallelepiped, Basis.coe_map] erw [← image_parallelepiped, f.toEquiv.preimage_image, addHaar_self] namespace MeasureTheory open Measure TopologicalSpace.PositiveCompacts FiniteDimensional /-! ### The Lebesgue measure is a Haar measure on `ℝ` and on `ℝ^ι`. -/ /-- The Haar measure equals the Lebesgue measure on `ℝ`. -/ theorem addHaarMeasure_eq_volume : addHaarMeasure Icc01 = volume := by convert (addHaarMeasure_unique volume Icc01).symm; simp [Icc01] #align measure_theory.add_haar_measure_eq_volume MeasureTheory.addHaarMeasure_eq_volume /-- The Haar measure equals the Lebesgue measure on `ℝ^ι`. -/ theorem addHaarMeasure_eq_volume_pi (ι : Type*) [Fintype ι] : addHaarMeasure (piIcc01 ι) = volume := by convert (addHaarMeasure_unique volume (piIcc01 ι)).symm simp only [piIcc01, volume_pi_pi fun _ => Icc (0 : ℝ) 1, PositiveCompacts.coe_mk, Compacts.coe_mk, Finset.prod_const_one, ENNReal.ofReal_one, Real.volume_Icc, one_smul, sub_zero] #align measure_theory.add_haar_measure_eq_volume_pi MeasureTheory.addHaarMeasure_eq_volume_pi -- Porting note (#11215): TODO: remove this instance? instance isAddHaarMeasure_volume_pi (ι : Type*) [Fintype ι] : IsAddHaarMeasure (volume : Measure (ι → ℝ)) := inferInstance #align measure_theory.is_add_haar_measure_volume_pi MeasureTheory.isAddHaarMeasure_volume_pi namespace Measure /-! ### Strict subspaces have zero measure -/ /-- If a set is disjoint of its translates by infinitely many bounded vectors, then it has measure zero. This auxiliary lemma proves this assuming additionally that the set is bounded. -/ theorem addHaar_eq_zero_of_disjoint_translates_aux {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] {s : Set E} (u : ℕ → E) (sb : IsBounded s) (hu : IsBounded (range u)) (hs : Pairwise (Disjoint on fun n => {u n} + s)) (h's : MeasurableSet s) : μ s = 0 := by by_contra h apply lt_irrefl ∞ calc ∞ = ∑' _ : ℕ, μ s := (ENNReal.tsum_const_eq_top_of_ne_zero h).symm _ = ∑' n : ℕ, μ ({u n} + s) := by congr 1; ext1 n; simp only [image_add_left, measure_preimage_add, singleton_add] _ = μ (⋃ n, {u n} + s) := Eq.symm <| measure_iUnion hs fun n => by simpa only [image_add_left, singleton_add] using measurable_id.const_add _ h's _ = μ (range u + s) := by rw [← iUnion_add, iUnion_singleton_eq_range] _ < ∞ := (hu.add sb).measure_lt_top #align measure_theory.measure.add_haar_eq_zero_of_disjoint_translates_aux MeasureTheory.Measure.addHaar_eq_zero_of_disjoint_translates_aux /-- If a set is disjoint of its translates by infinitely many bounded vectors, then it has measure zero. -/ theorem addHaar_eq_zero_of_disjoint_translates {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] {s : Set E} (u : ℕ → E) (hu : IsBounded (range u)) (hs : Pairwise (Disjoint on fun n => {u n} + s)) (h's : MeasurableSet s) : μ s = 0 := by suffices H : ∀ R, μ (s ∩ closedBall 0 R) = 0 by apply le_antisymm _ (zero_le _) calc μ s ≤ ∑' n : ℕ, μ (s ∩ closedBall 0 n) := by conv_lhs => rw [← iUnion_inter_closedBall_nat s 0] exact measure_iUnion_le _ _ = 0 := by simp only [H, tsum_zero] intro R apply addHaar_eq_zero_of_disjoint_translates_aux μ u (isBounded_closedBall.subset inter_subset_right) hu _ (h's.inter measurableSet_closedBall) refine pairwise_disjoint_mono hs fun n => ?_ exact add_subset_add Subset.rfl inter_subset_left #align measure_theory.measure.add_haar_eq_zero_of_disjoint_translates MeasureTheory.Measure.addHaar_eq_zero_of_disjoint_translates /-- A strict vector subspace has measure zero. -/ theorem addHaar_submodule {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] (s : Submodule ℝ E) (hs : s ≠ ⊤) : μ s = 0 := by obtain ⟨x, hx⟩ : ∃ x, x ∉ s := by simpa only [Submodule.eq_top_iff', not_exists, Ne, not_forall] using hs obtain ⟨c, cpos, cone⟩ : ∃ c : ℝ, 0 < c ∧ c < 1 := ⟨1 / 2, by norm_num, by norm_num⟩ have A : IsBounded (range fun n : ℕ => c ^ n • x) := have : Tendsto (fun n : ℕ => c ^ n • x) atTop (𝓝 ((0 : ℝ) • x)) := (tendsto_pow_atTop_nhds_zero_of_lt_one cpos.le cone).smul_const x isBounded_range_of_tendsto _ this apply addHaar_eq_zero_of_disjoint_translates μ _ A _ (Submodule.closed_of_finiteDimensional s).measurableSet intro m n hmn simp only [Function.onFun, image_add_left, singleton_add, disjoint_left, mem_preimage, SetLike.mem_coe] intro y hym hyn have A : (c ^ n - c ^ m) • x ∈ s := by convert s.sub_mem hym hyn using 1 simp only [sub_smul, neg_sub_neg, add_sub_add_right_eq_sub] have H : c ^ n - c ^ m ≠ 0 := by simpa only [sub_eq_zero, Ne] using (pow_right_strictAnti cpos cone).injective.ne hmn.symm have : x ∈ s := by convert s.smul_mem (c ^ n - c ^ m)⁻¹ A rw [smul_smul, inv_mul_cancel H, one_smul] exact hx this #align measure_theory.measure.add_haar_submodule MeasureTheory.Measure.addHaar_submodule /-- A strict affine subspace has measure zero. -/ theorem addHaar_affineSubspace {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] (s : AffineSubspace ℝ E) (hs : s ≠ ⊤) : μ s = 0 := by rcases s.eq_bot_or_nonempty with (rfl | hne) · rw [AffineSubspace.bot_coe, measure_empty] rw [Ne, ← AffineSubspace.direction_eq_top_iff_of_nonempty hne] at hs rcases hne with ⟨x, hx : x ∈ s⟩ simpa only [AffineSubspace.coe_direction_eq_vsub_set_right hx, vsub_eq_sub, sub_eq_add_neg, image_add_right, neg_neg, measure_preimage_add_right] using addHaar_submodule μ s.direction hs #align measure_theory.measure.add_haar_affine_subspace MeasureTheory.Measure.addHaar_affineSubspace /-! ### Applying a linear map rescales Haar measure by the determinant We first prove this on `ι → ℝ`, using that this is already known for the product Lebesgue measure (thanks to matrices computations). Then, we extend this to any finite-dimensional real vector space by using a linear equiv with a space of the form `ι → ℝ`, and arguing that such a linear equiv maps Haar measure to Haar measure. -/ theorem map_linearMap_addHaar_pi_eq_smul_addHaar {ι : Type*} [Finite ι] {f : (ι → ℝ) →ₗ[ℝ] ι → ℝ} (hf : LinearMap.det f ≠ 0) (μ : Measure (ι → ℝ)) [IsAddHaarMeasure μ] : Measure.map f μ = ENNReal.ofReal (abs (LinearMap.det f)⁻¹) • μ := by cases nonempty_fintype ι /- We have already proved the result for the Lebesgue product measure, using matrices. We deduce it for any Haar measure by uniqueness (up to scalar multiplication). -/ have := addHaarMeasure_unique μ (piIcc01 ι) rw [this, addHaarMeasure_eq_volume_pi, Measure.map_smul, Real.map_linearMap_volume_pi_eq_smul_volume_pi hf, smul_comm] #align measure_theory.measure.map_linear_map_add_haar_pi_eq_smul_add_haar MeasureTheory.Measure.map_linearMap_addHaar_pi_eq_smul_addHaar variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F] theorem map_linearMap_addHaar_eq_smul_addHaar {f : E →ₗ[ℝ] E} (hf : LinearMap.det f ≠ 0) : Measure.map f μ = ENNReal.ofReal |(LinearMap.det f)⁻¹| • μ := by -- we reduce to the case of `E = ι → ℝ`, for which we have already proved the result using -- matrices in `map_linearMap_addHaar_pi_eq_smul_addHaar`. let ι := Fin (finrank ℝ E) haveI : FiniteDimensional ℝ (ι → ℝ) := by infer_instance have : finrank ℝ E = finrank ℝ (ι → ℝ) := by simp [ι] have e : E ≃ₗ[ℝ] ι → ℝ := LinearEquiv.ofFinrankEq E (ι → ℝ) this -- next line is to avoid `g` getting reduced by `simp`. obtain ⟨g, hg⟩ : ∃ g, g = (e : E →ₗ[ℝ] ι → ℝ).comp (f.comp (e.symm : (ι → ℝ) →ₗ[ℝ] E)) := ⟨_, rfl⟩ have gdet : LinearMap.det g = LinearMap.det f := by rw [hg]; exact LinearMap.det_conj f e rw [← gdet] at hf ⊢ have fg : f = (e.symm : (ι → ℝ) →ₗ[ℝ] E).comp (g.comp (e : E →ₗ[ℝ] ι → ℝ)) := by ext x simp only [LinearEquiv.coe_coe, Function.comp_apply, LinearMap.coe_comp, LinearEquiv.symm_apply_apply, hg] simp only [fg, LinearEquiv.coe_coe, LinearMap.coe_comp] have Ce : Continuous e := (e : E →ₗ[ℝ] ι → ℝ).continuous_of_finiteDimensional have Cg : Continuous g := LinearMap.continuous_of_finiteDimensional g have Cesymm : Continuous e.symm := (e.symm : (ι → ℝ) →ₗ[ℝ] E).continuous_of_finiteDimensional rw [← map_map Cesymm.measurable (Cg.comp Ce).measurable, ← map_map Cg.measurable Ce.measurable] haveI : IsAddHaarMeasure (map e μ) := (e : E ≃+ (ι → ℝ)).isAddHaarMeasure_map μ Ce Cesymm have ecomp : e.symm ∘ e = id := by ext x; simp only [id, Function.comp_apply, LinearEquiv.symm_apply_apply] rw [map_linearMap_addHaar_pi_eq_smul_addHaar hf (map e μ), Measure.map_smul, map_map Cesymm.measurable Ce.measurable, ecomp, Measure.map_id] #align measure_theory.measure.map_linear_map_add_haar_eq_smul_add_haar MeasureTheory.Measure.map_linearMap_addHaar_eq_smul_addHaar /-- The preimage of a set `s` under a linear map `f` with nonzero determinant has measure equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/ @[simp] theorem addHaar_preimage_linearMap {f : E →ₗ[ℝ] E} (hf : LinearMap.det f ≠ 0) (s : Set E) : μ (f ⁻¹' s) = ENNReal.ofReal |(LinearMap.det f)⁻¹| * μ s := calc μ (f ⁻¹' s) = Measure.map f μ s := ((f.equivOfDetNeZero hf).toContinuousLinearEquiv.toHomeomorph.toMeasurableEquiv.map_apply s).symm _ = ENNReal.ofReal |(LinearMap.det f)⁻¹| * μ s := by rw [map_linearMap_addHaar_eq_smul_addHaar μ hf]; rfl #align measure_theory.measure.add_haar_preimage_linear_map MeasureTheory.Measure.addHaar_preimage_linearMap /-- The preimage of a set `s` under a continuous linear map `f` with nonzero determinant has measure equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/ @[simp] theorem addHaar_preimage_continuousLinearMap {f : E →L[ℝ] E} (hf : LinearMap.det (f : E →ₗ[ℝ] E) ≠ 0) (s : Set E) : μ (f ⁻¹' s) = ENNReal.ofReal (abs (LinearMap.det (f : E →ₗ[ℝ] E))⁻¹) * μ s := addHaar_preimage_linearMap μ hf s #align measure_theory.measure.add_haar_preimage_continuous_linear_map MeasureTheory.Measure.addHaar_preimage_continuousLinearMap /-- The preimage of a set `s` under a linear equiv `f` has measure equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/ @[simp] theorem addHaar_preimage_linearEquiv (f : E ≃ₗ[ℝ] E) (s : Set E) : μ (f ⁻¹' s) = ENNReal.ofReal |LinearMap.det (f.symm : E →ₗ[ℝ] E)| * μ s := by have A : LinearMap.det (f : E →ₗ[ℝ] E) ≠ 0 := (LinearEquiv.isUnit_det' f).ne_zero convert addHaar_preimage_linearMap μ A s simp only [LinearEquiv.det_coe_symm] #align measure_theory.measure.add_haar_preimage_linear_equiv MeasureTheory.Measure.addHaar_preimage_linearEquiv /-- The preimage of a set `s` under a continuous linear equiv `f` has measure equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/ @[simp] theorem addHaar_preimage_continuousLinearEquiv (f : E ≃L[ℝ] E) (s : Set E) : μ (f ⁻¹' s) = ENNReal.ofReal |LinearMap.det (f.symm : E →ₗ[ℝ] E)| * μ s := addHaar_preimage_linearEquiv μ _ s #align measure_theory.measure.add_haar_preimage_continuous_linear_equiv MeasureTheory.Measure.addHaar_preimage_continuousLinearEquiv /-- The image of a set `s` under a linear map `f` has measure equal to `μ s` times the absolute value of the determinant of `f`. -/ @[simp] theorem addHaar_image_linearMap (f : E →ₗ[ℝ] E) (s : Set E) : μ (f '' s) = ENNReal.ofReal |LinearMap.det f| * μ s := by rcases ne_or_eq (LinearMap.det f) 0 with (hf | hf) · let g := (f.equivOfDetNeZero hf).toContinuousLinearEquiv change μ (g '' s) = _ rw [ContinuousLinearEquiv.image_eq_preimage g s, addHaar_preimage_continuousLinearEquiv] congr · simp only [hf, zero_mul, ENNReal.ofReal_zero, abs_zero] have : μ (LinearMap.range f) = 0 := addHaar_submodule μ _ (LinearMap.range_lt_top_of_det_eq_zero hf).ne exact le_antisymm (le_trans (measure_mono (image_subset_range _ _)) this.le) (zero_le _) #align measure_theory.measure.add_haar_image_linear_map MeasureTheory.Measure.addHaar_image_linearMap /-- The image of a set `s` under a continuous linear map `f` has measure equal to `μ s` times the absolute value of the determinant of `f`. -/ @[simp] theorem addHaar_image_continuousLinearMap (f : E →L[ℝ] E) (s : Set E) : μ (f '' s) = ENNReal.ofReal |LinearMap.det (f : E →ₗ[ℝ] E)| * μ s := addHaar_image_linearMap μ _ s #align measure_theory.measure.add_haar_image_continuous_linear_map MeasureTheory.Measure.addHaar_image_continuousLinearMap /-- The image of a set `s` under a continuous linear equiv `f` has measure equal to `μ s` times the absolute value of the determinant of `f`. -/ @[simp] theorem addHaar_image_continuousLinearEquiv (f : E ≃L[ℝ] E) (s : Set E) : μ (f '' s) = ENNReal.ofReal |LinearMap.det (f : E →ₗ[ℝ] E)| * μ s := μ.addHaar_image_linearMap (f : E →ₗ[ℝ] E) s #align measure_theory.measure.add_haar_image_continuous_linear_equiv MeasureTheory.Measure.addHaar_image_continuousLinearEquiv theorem LinearMap.quasiMeasurePreserving (f : E →ₗ[ℝ] E) (hf : LinearMap.det f ≠ 0) : QuasiMeasurePreserving f μ μ := by refine ⟨f.continuous_of_finiteDimensional.measurable, ?_⟩ rw [map_linearMap_addHaar_eq_smul_addHaar μ hf] exact smul_absolutelyContinuous theorem ContinuousLinearMap.quasiMeasurePreserving (f : E →L[ℝ] E) (hf : f.det ≠ 0) : QuasiMeasurePreserving f μ μ := LinearMap.quasiMeasurePreserving μ (f : E →ₗ[ℝ] E) hf /-! ### Basic properties of Haar measures on real vector spaces -/ theorem map_addHaar_smul {r : ℝ} (hr : r ≠ 0) : Measure.map (r • ·) μ = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) • μ := by let f : E →ₗ[ℝ] E := r • (1 : E →ₗ[ℝ] E) change Measure.map f μ = _ have hf : LinearMap.det f ≠ 0 := by simp only [f, mul_one, LinearMap.det_smul, Ne, MonoidHom.map_one] intro h exact hr (pow_eq_zero h) simp only [f, map_linearMap_addHaar_eq_smul_addHaar μ hf, mul_one, LinearMap.det_smul, map_one] #align measure_theory.measure.map_add_haar_smul MeasureTheory.Measure.map_addHaar_smul theorem quasiMeasurePreserving_smul {r : ℝ} (hr : r ≠ 0) : QuasiMeasurePreserving (r • ·) μ μ := by refine ⟨measurable_const_smul r, ?_⟩ rw [map_addHaar_smul μ hr] exact smul_absolutelyContinuous @[simp] theorem addHaar_preimage_smul {r : ℝ} (hr : r ≠ 0) (s : Set E) : μ ((r • ·) ⁻¹' s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) * μ s := calc μ ((r • ·) ⁻¹' s) = Measure.map (r • ·) μ s := ((Homeomorph.smul (isUnit_iff_ne_zero.2 hr).unit).toMeasurableEquiv.map_apply s).symm _ = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) * μ s := by rw [map_addHaar_smul μ hr, coe_smul, Pi.smul_apply, smul_eq_mul] #align measure_theory.measure.add_haar_preimage_smul MeasureTheory.Measure.addHaar_preimage_smul /-- Rescaling a set by a factor `r` multiplies its measure by `abs (r ^ dim)`. -/ @[simp] theorem addHaar_smul (r : ℝ) (s : Set E) : μ (r • s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * μ s := by rcases ne_or_eq r 0 with (h | rfl) · rw [← preimage_smul_inv₀ h, addHaar_preimage_smul μ (inv_ne_zero h), inv_pow, inv_inv] rcases eq_empty_or_nonempty s with (rfl | hs) · simp only [measure_empty, mul_zero, smul_set_empty] rw [zero_smul_set hs, ← singleton_zero] by_cases h : finrank ℝ E = 0 · haveI : Subsingleton E := finrank_zero_iff.1 h simp only [h, one_mul, ENNReal.ofReal_one, abs_one, Subsingleton.eq_univ_of_nonempty hs, pow_zero, Subsingleton.eq_univ_of_nonempty (singleton_nonempty (0 : E))] · haveI : Nontrivial E := nontrivial_of_finrank_pos (bot_lt_iff_ne_bot.2 h) simp only [h, zero_mul, ENNReal.ofReal_zero, abs_zero, Ne, not_false_iff, zero_pow, measure_singleton] #align measure_theory.measure.add_haar_smul MeasureTheory.Measure.addHaar_smul theorem addHaar_smul_of_nonneg {r : ℝ} (hr : 0 ≤ r) (s : Set E) : μ (r • s) = ENNReal.ofReal (r ^ finrank ℝ E) * μ s := by rw [addHaar_smul, abs_pow, abs_of_nonneg hr] #align measure_theory.measure.add_haar_smul_of_nonneg MeasureTheory.Measure.addHaar_smul_of_nonneg variable {μ} {s : Set E} -- Note: We might want to rename this once we acquire the lemma corresponding to -- `MeasurableSet.const_smul` theorem NullMeasurableSet.const_smul (hs : NullMeasurableSet s μ) (r : ℝ) : NullMeasurableSet (r • s) μ := by obtain rfl | hs' := s.eq_empty_or_nonempty · simp obtain rfl | hr := eq_or_ne r 0 · simpa [zero_smul_set hs'] using nullMeasurableSet_singleton _ obtain ⟨t, ht, hst⟩ := hs refine ⟨_, ht.const_smul_of_ne_zero hr, ?_⟩ rw [← measure_symmDiff_eq_zero_iff] at hst ⊢ rw [← smul_set_symmDiff₀ hr, addHaar_smul μ, hst, mul_zero] #align measure_theory.measure.null_measurable_set.const_smul MeasureTheory.Measure.NullMeasurableSet.const_smul variable (μ) @[simp] theorem addHaar_image_homothety (x : E) (r : ℝ) (s : Set E) : μ (AffineMap.homothety x r '' s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * μ s := calc μ (AffineMap.homothety x r '' s) = μ ((fun y => y + x) '' (r • (fun y => y + -x) '' s)) := by simp only [← image_smul, image_image, ← sub_eq_add_neg]; rfl _ = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * μ s := by simp only [image_add_right, measure_preimage_add_right, addHaar_smul] #align measure_theory.measure.add_haar_image_homothety MeasureTheory.Measure.addHaar_image_homothety /-! We don't need to state `map_addHaar_neg` here, because it has already been proved for general Haar measures on general commutative groups. -/ /-! ### Measure of balls -/ theorem addHaar_ball_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E] [BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] (x : E) (r : ℝ) : μ (ball x r) = μ (ball (0 : E) r) := by have : ball (0 : E) r = (x + ·) ⁻¹' ball x r := by simp [preimage_add_ball] rw [this, measure_preimage_add] #align measure_theory.measure.add_haar_ball_center MeasureTheory.Measure.addHaar_ball_center theorem addHaar_closedBall_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E] [BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] (x : E) (r : ℝ) : μ (closedBall x r) = μ (closedBall (0 : E) r) := by have : closedBall (0 : E) r = (x + ·) ⁻¹' closedBall x r := by simp [preimage_add_closedBall] rw [this, measure_preimage_add] #align measure_theory.measure.add_haar_closed_ball_center MeasureTheory.Measure.addHaar_closedBall_center theorem addHaar_ball_mul_of_pos (x : E) {r : ℝ} (hr : 0 < r) (s : ℝ) : μ (ball x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 s) := by have : ball (0 : E) (r * s) = r • ball (0 : E) s := by simp only [_root_.smul_ball hr.ne' (0 : E) s, Real.norm_eq_abs, abs_of_nonneg hr.le, smul_zero] simp only [this, addHaar_smul, abs_of_nonneg hr.le, addHaar_ball_center, abs_pow] #align measure_theory.measure.add_haar_ball_mul_of_pos MeasureTheory.Measure.addHaar_ball_mul_of_pos theorem addHaar_ball_of_pos (x : E) {r : ℝ} (hr : 0 < r) : μ (ball x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 1) := by rw [← addHaar_ball_mul_of_pos μ x hr, mul_one] #align measure_theory.measure.add_haar_ball_of_pos MeasureTheory.Measure.addHaar_ball_of_pos theorem addHaar_ball_mul [Nontrivial E] (x : E) {r : ℝ} (hr : 0 ≤ r) (s : ℝ) : μ (ball x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 s) := by rcases hr.eq_or_lt with (rfl | h) · simp only [zero_pow (finrank_pos (R := ℝ) (M := E)).ne', measure_empty, zero_mul, ENNReal.ofReal_zero, ball_zero] · exact addHaar_ball_mul_of_pos μ x h s #align measure_theory.measure.add_haar_ball_mul MeasureTheory.Measure.addHaar_ball_mul theorem addHaar_ball [Nontrivial E] (x : E) {r : ℝ} (hr : 0 ≤ r) : μ (ball x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 1) := by rw [← addHaar_ball_mul μ x hr, mul_one] #align measure_theory.measure.add_haar_ball MeasureTheory.Measure.addHaar_ball theorem addHaar_closedBall_mul_of_pos (x : E) {r : ℝ} (hr : 0 < r) (s : ℝ) : μ (closedBall x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall 0 s) := by have : closedBall (0 : E) (r * s) = r • closedBall (0 : E) s := by simp [smul_closedBall' hr.ne' (0 : E), abs_of_nonneg hr.le] simp only [this, addHaar_smul, abs_of_nonneg hr.le, addHaar_closedBall_center, abs_pow] #align measure_theory.measure.add_haar_closed_ball_mul_of_pos MeasureTheory.Measure.addHaar_closedBall_mul_of_pos theorem addHaar_closedBall_mul (x : E) {r : ℝ} (hr : 0 ≤ r) {s : ℝ} (hs : 0 ≤ s) : μ (closedBall x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall 0 s) := by have : closedBall (0 : E) (r * s) = r • closedBall (0 : E) s := by simp [smul_closedBall r (0 : E) hs, abs_of_nonneg hr] simp only [this, addHaar_smul, abs_of_nonneg hr, addHaar_closedBall_center, abs_pow] #align measure_theory.measure.add_haar_closed_ball_mul MeasureTheory.Measure.addHaar_closedBall_mul /-- The measure of a closed ball can be expressed in terms of the measure of the closed unit ball. Use instead `addHaar_closedBall`, which uses the measure of the open unit ball as a standard form. -/ theorem addHaar_closedBall' (x : E) {r : ℝ} (hr : 0 ≤ r) : μ (closedBall x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall 0 1) := by rw [← addHaar_closedBall_mul μ x hr zero_le_one, mul_one] #align measure_theory.measure.add_haar_closed_ball' MeasureTheory.Measure.addHaar_closedBall' theorem addHaar_closed_unit_ball_eq_addHaar_unit_ball : μ (closedBall (0 : E) 1) = μ (ball 0 1) := by apply le_antisymm _ (measure_mono ball_subset_closedBall) have A : Tendsto (fun r : ℝ => ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall (0 : E) 1)) (𝓝[<] 1) (𝓝 (ENNReal.ofReal ((1 : ℝ) ^ finrank ℝ E) * μ (closedBall (0 : E) 1))) := by refine ENNReal.Tendsto.mul ?_ (by simp) tendsto_const_nhds (by simp) exact ENNReal.tendsto_ofReal ((tendsto_id'.2 nhdsWithin_le_nhds).pow _) simp only [one_pow, one_mul, ENNReal.ofReal_one] at A refine le_of_tendsto A ?_ refine mem_nhdsWithin_Iio_iff_exists_Ioo_subset.2 ⟨(0 : ℝ), by simp, fun r hr => ?_⟩ dsimp rw [← addHaar_closedBall' μ (0 : E) hr.1.le] exact measure_mono (closedBall_subset_ball hr.2) #align measure_theory.measure.add_haar_closed_unit_ball_eq_add_haar_unit_ball MeasureTheory.Measure.addHaar_closed_unit_ball_eq_addHaar_unit_ball theorem addHaar_closedBall (x : E) {r : ℝ} (hr : 0 ≤ r) : μ (closedBall x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 1) := by rw [addHaar_closedBall' μ x hr, addHaar_closed_unit_ball_eq_addHaar_unit_ball] #align measure_theory.measure.add_haar_closed_ball MeasureTheory.Measure.addHaar_closedBall theorem addHaar_closedBall_eq_addHaar_ball [Nontrivial E] (x : E) (r : ℝ) : μ (closedBall x r) = μ (ball x r) := by by_cases h : r < 0 · rw [Metric.closedBall_eq_empty.mpr h, Metric.ball_eq_empty.mpr h.le] push_neg at h rw [addHaar_closedBall μ x h, addHaar_ball μ x h] #align measure_theory.measure.add_haar_closed_ball_eq_add_haar_ball MeasureTheory.Measure.addHaar_closedBall_eq_addHaar_ball theorem addHaar_sphere_of_ne_zero (x : E) {r : ℝ} (hr : r ≠ 0) : μ (sphere x r) = 0 := by rcases hr.lt_or_lt with (h | h) · simp only [empty_diff, measure_empty, ← closedBall_diff_ball, closedBall_eq_empty.2 h] · rw [← closedBall_diff_ball, measure_diff ball_subset_closedBall measurableSet_ball measure_ball_lt_top.ne, addHaar_ball_of_pos μ _ h, addHaar_closedBall μ _ h.le, tsub_self] #align measure_theory.measure.add_haar_sphere_of_ne_zero MeasureTheory.Measure.addHaar_sphere_of_ne_zero
Mathlib/MeasureTheory/Measure/Lebesgue/EqHaar.lean
538
541
theorem addHaar_sphere [Nontrivial E] (x : E) (r : ℝ) : μ (sphere x r) = 0 := by
rcases eq_or_ne r 0 with (rfl | h) · rw [sphere_zero, measure_singleton] · exact addHaar_sphere_of_ne_zero μ x h
/- 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.Algebra.CharP.Invertible import Mathlib.Algebra.Order.Interval.Set.Group import Mathlib.Analysis.Convex.Segment import Mathlib.LinearAlgebra.AffineSpace.FiniteDimensional import Mathlib.Tactic.FieldSimp #align_import analysis.convex.between from "leanprover-community/mathlib"@"571e13cacbed7bf042fd3058ce27157101433842" /-! # Betweenness in affine spaces This file defines notions of a point in an affine space being between two given points. ## Main definitions * `affineSegment R x y`: The segment of points weakly between `x` and `y`. * `Wbtw R x y z`: The point `y` is weakly between `x` and `z`. * `Sbtw R x y z`: The point `y` is strictly between `x` and `z`. -/ variable (R : Type*) {V V' P P' : Type*} open AffineEquiv AffineMap section OrderedRing variable [OrderedRing R] [AddCommGroup V] [Module R V] [AddTorsor V P] variable [AddCommGroup V'] [Module R V'] [AddTorsor V' P'] /-- The segment of points weakly between `x` and `y`. When convexity is refactored to support abstract affine combination spaces, this will no longer need to be a separate definition from `segment`. However, lemmas involving `+ᵥ` or `-ᵥ` will still be relevant after such a refactoring, as distinct from versions involving `+` or `-` in a module. -/ def affineSegment (x y : P) := lineMap x y '' Set.Icc (0 : R) 1 #align affine_segment affineSegment theorem affineSegment_eq_segment (x y : V) : affineSegment R x y = segment R x y := by rw [segment_eq_image_lineMap, affineSegment] #align affine_segment_eq_segment affineSegment_eq_segment theorem affineSegment_comm (x y : P) : affineSegment R x y = affineSegment R y x := by refine Set.ext fun z => ?_ constructor <;> · rintro ⟨t, ht, hxy⟩ refine ⟨1 - t, ?_, ?_⟩ · rwa [Set.sub_mem_Icc_iff_right, sub_self, sub_zero] · rwa [lineMap_apply_one_sub] #align affine_segment_comm affineSegment_comm theorem left_mem_affineSegment (x y : P) : x ∈ affineSegment R x y := ⟨0, Set.left_mem_Icc.2 zero_le_one, lineMap_apply_zero _ _⟩ #align left_mem_affine_segment left_mem_affineSegment theorem right_mem_affineSegment (x y : P) : y ∈ affineSegment R x y := ⟨1, Set.right_mem_Icc.2 zero_le_one, lineMap_apply_one _ _⟩ #align right_mem_affine_segment right_mem_affineSegment @[simp] theorem affineSegment_same (x : P) : affineSegment R x x = {x} := by -- Porting note: added as this doesn't do anything in `simp_rw` any more rw [affineSegment] -- Note: when adding "simp made no progress" in lean4#2336, -- had to change `lineMap_same` to `lineMap_same _`. Not sure why? -- Porting note: added `_ _` and `Function.const` simp_rw [lineMap_same _, AffineMap.coe_const _ _, Function.const, (Set.nonempty_Icc.mpr zero_le_one).image_const] #align affine_segment_same affineSegment_same variable {R} @[simp] theorem affineSegment_image (f : P →ᵃ[R] P') (x y : P) : f '' affineSegment R x y = affineSegment R (f x) (f y) := by rw [affineSegment, affineSegment, Set.image_image, ← comp_lineMap] rfl #align affine_segment_image affineSegment_image variable (R) @[simp] theorem affineSegment_const_vadd_image (x y : P) (v : V) : (v +ᵥ ·) '' affineSegment R x y = affineSegment R (v +ᵥ x) (v +ᵥ y) := affineSegment_image (AffineEquiv.constVAdd R P v : P →ᵃ[R] P) x y #align affine_segment_const_vadd_image affineSegment_const_vadd_image @[simp] theorem affineSegment_vadd_const_image (x y : V) (p : P) : (· +ᵥ p) '' affineSegment R x y = affineSegment R (x +ᵥ p) (y +ᵥ p) := affineSegment_image (AffineEquiv.vaddConst R p : V →ᵃ[R] P) x y #align affine_segment_vadd_const_image affineSegment_vadd_const_image @[simp] theorem affineSegment_const_vsub_image (x y p : P) : (p -ᵥ ·) '' affineSegment R x y = affineSegment R (p -ᵥ x) (p -ᵥ y) := affineSegment_image (AffineEquiv.constVSub R p : P →ᵃ[R] V) x y #align affine_segment_const_vsub_image affineSegment_const_vsub_image @[simp] theorem affineSegment_vsub_const_image (x y p : P) : (· -ᵥ p) '' affineSegment R x y = affineSegment R (x -ᵥ p) (y -ᵥ p) := affineSegment_image ((AffineEquiv.vaddConst R p).symm : P →ᵃ[R] V) x y #align affine_segment_vsub_const_image affineSegment_vsub_const_image variable {R} @[simp] theorem mem_const_vadd_affineSegment {x y z : P} (v : V) : v +ᵥ z ∈ affineSegment R (v +ᵥ x) (v +ᵥ y) ↔ z ∈ affineSegment R x y := by rw [← affineSegment_const_vadd_image, (AddAction.injective v).mem_set_image] #align mem_const_vadd_affine_segment mem_const_vadd_affineSegment @[simp] theorem mem_vadd_const_affineSegment {x y z : V} (p : P) : z +ᵥ p ∈ affineSegment R (x +ᵥ p) (y +ᵥ p) ↔ z ∈ affineSegment R x y := by rw [← affineSegment_vadd_const_image, (vadd_right_injective p).mem_set_image] #align mem_vadd_const_affine_segment mem_vadd_const_affineSegment @[simp] theorem mem_const_vsub_affineSegment {x y z : P} (p : P) : p -ᵥ z ∈ affineSegment R (p -ᵥ x) (p -ᵥ y) ↔ z ∈ affineSegment R x y := by rw [← affineSegment_const_vsub_image, (vsub_right_injective p).mem_set_image] #align mem_const_vsub_affine_segment mem_const_vsub_affineSegment @[simp] theorem mem_vsub_const_affineSegment {x y z : P} (p : P) : z -ᵥ p ∈ affineSegment R (x -ᵥ p) (y -ᵥ p) ↔ z ∈ affineSegment R x y := by rw [← affineSegment_vsub_const_image, (vsub_left_injective p).mem_set_image] #align mem_vsub_const_affine_segment mem_vsub_const_affineSegment variable (R) /-- The point `y` is weakly between `x` and `z`. -/ def Wbtw (x y z : P) : Prop := y ∈ affineSegment R x z #align wbtw Wbtw /-- The point `y` is strictly between `x` and `z`. -/ def Sbtw (x y z : P) : Prop := Wbtw R x y z ∧ y ≠ x ∧ y ≠ z #align sbtw Sbtw variable {R} lemma mem_segment_iff_wbtw {x y z : V} : y ∈ segment R x z ↔ Wbtw R x y z := by rw [Wbtw, affineSegment_eq_segment] theorem Wbtw.map {x y z : P} (h : Wbtw R x y z) (f : P →ᵃ[R] P') : Wbtw R (f x) (f y) (f z) := by rw [Wbtw, ← affineSegment_image] exact Set.mem_image_of_mem _ h #align wbtw.map Wbtw.map theorem Function.Injective.wbtw_map_iff {x y z : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : Wbtw R (f x) (f y) (f z) ↔ Wbtw R x y z := by refine ⟨fun h => ?_, fun h => h.map _⟩ rwa [Wbtw, ← affineSegment_image, hf.mem_set_image] at h #align function.injective.wbtw_map_iff Function.Injective.wbtw_map_iff theorem Function.Injective.sbtw_map_iff {x y z : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : Sbtw R (f x) (f y) (f z) ↔ Sbtw R x y z := by simp_rw [Sbtw, hf.wbtw_map_iff, hf.ne_iff] #align function.injective.sbtw_map_iff Function.Injective.sbtw_map_iff @[simp] theorem AffineEquiv.wbtw_map_iff {x y z : P} (f : P ≃ᵃ[R] P') : Wbtw R (f x) (f y) (f z) ↔ Wbtw R x y z := by refine Function.Injective.wbtw_map_iff (?_ : Function.Injective f.toAffineMap) exact f.injective #align affine_equiv.wbtw_map_iff AffineEquiv.wbtw_map_iff @[simp] theorem AffineEquiv.sbtw_map_iff {x y z : P} (f : P ≃ᵃ[R] P') : Sbtw R (f x) (f y) (f z) ↔ Sbtw R x y z := by refine Function.Injective.sbtw_map_iff (?_ : Function.Injective f.toAffineMap) exact f.injective #align affine_equiv.sbtw_map_iff AffineEquiv.sbtw_map_iff @[simp] theorem wbtw_const_vadd_iff {x y z : P} (v : V) : Wbtw R (v +ᵥ x) (v +ᵥ y) (v +ᵥ z) ↔ Wbtw R x y z := mem_const_vadd_affineSegment _ #align wbtw_const_vadd_iff wbtw_const_vadd_iff @[simp] theorem wbtw_vadd_const_iff {x y z : V} (p : P) : Wbtw R (x +ᵥ p) (y +ᵥ p) (z +ᵥ p) ↔ Wbtw R x y z := mem_vadd_const_affineSegment _ #align wbtw_vadd_const_iff wbtw_vadd_const_iff @[simp] theorem wbtw_const_vsub_iff {x y z : P} (p : P) : Wbtw R (p -ᵥ x) (p -ᵥ y) (p -ᵥ z) ↔ Wbtw R x y z := mem_const_vsub_affineSegment _ #align wbtw_const_vsub_iff wbtw_const_vsub_iff @[simp] theorem wbtw_vsub_const_iff {x y z : P} (p : P) : Wbtw R (x -ᵥ p) (y -ᵥ p) (z -ᵥ p) ↔ Wbtw R x y z := mem_vsub_const_affineSegment _ #align wbtw_vsub_const_iff wbtw_vsub_const_iff @[simp] theorem sbtw_const_vadd_iff {x y z : P} (v : V) : Sbtw R (v +ᵥ x) (v +ᵥ y) (v +ᵥ z) ↔ Sbtw R x y z := by rw [Sbtw, Sbtw, wbtw_const_vadd_iff, (AddAction.injective v).ne_iff, (AddAction.injective v).ne_iff] #align sbtw_const_vadd_iff sbtw_const_vadd_iff @[simp] theorem sbtw_vadd_const_iff {x y z : V} (p : P) : Sbtw R (x +ᵥ p) (y +ᵥ p) (z +ᵥ p) ↔ Sbtw R x y z := by rw [Sbtw, Sbtw, wbtw_vadd_const_iff, (vadd_right_injective p).ne_iff, (vadd_right_injective p).ne_iff] #align sbtw_vadd_const_iff sbtw_vadd_const_iff @[simp] theorem sbtw_const_vsub_iff {x y z : P} (p : P) : Sbtw R (p -ᵥ x) (p -ᵥ y) (p -ᵥ z) ↔ Sbtw R x y z := by rw [Sbtw, Sbtw, wbtw_const_vsub_iff, (vsub_right_injective p).ne_iff, (vsub_right_injective p).ne_iff] #align sbtw_const_vsub_iff sbtw_const_vsub_iff @[simp] theorem sbtw_vsub_const_iff {x y z : P} (p : P) : Sbtw R (x -ᵥ p) (y -ᵥ p) (z -ᵥ p) ↔ Sbtw R x y z := by rw [Sbtw, Sbtw, wbtw_vsub_const_iff, (vsub_left_injective p).ne_iff, (vsub_left_injective p).ne_iff] #align sbtw_vsub_const_iff sbtw_vsub_const_iff theorem Sbtw.wbtw {x y z : P} (h : Sbtw R x y z) : Wbtw R x y z := h.1 #align sbtw.wbtw Sbtw.wbtw theorem Sbtw.ne_left {x y z : P} (h : Sbtw R x y z) : y ≠ x := h.2.1 #align sbtw.ne_left Sbtw.ne_left theorem Sbtw.left_ne {x y z : P} (h : Sbtw R x y z) : x ≠ y := h.2.1.symm #align sbtw.left_ne Sbtw.left_ne theorem Sbtw.ne_right {x y z : P} (h : Sbtw R x y z) : y ≠ z := h.2.2 #align sbtw.ne_right Sbtw.ne_right theorem Sbtw.right_ne {x y z : P} (h : Sbtw R x y z) : z ≠ y := h.2.2.symm #align sbtw.right_ne Sbtw.right_ne theorem Sbtw.mem_image_Ioo {x y z : P} (h : Sbtw R x y z) : y ∈ lineMap x z '' Set.Ioo (0 : R) 1 := by rcases h with ⟨⟨t, ht, rfl⟩, hyx, hyz⟩ rcases Set.eq_endpoints_or_mem_Ioo_of_mem_Icc ht with (rfl | rfl | ho) · exfalso exact hyx (lineMap_apply_zero _ _) · exfalso exact hyz (lineMap_apply_one _ _) · exact ⟨t, ho, rfl⟩ #align sbtw.mem_image_Ioo Sbtw.mem_image_Ioo theorem Wbtw.mem_affineSpan {x y z : P} (h : Wbtw R x y z) : y ∈ line[R, x, z] := by rcases h with ⟨r, ⟨-, rfl⟩⟩ exact lineMap_mem_affineSpan_pair _ _ _ #align wbtw.mem_affine_span Wbtw.mem_affineSpan
Mathlib/Analysis/Convex/Between.lean
273
274
theorem wbtw_comm {x y z : P} : Wbtw R x y z ↔ Wbtw R z y x := by
rw [Wbtw, Wbtw, affineSegment_comm]
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen -/ import Mathlib.Algebra.Algebra.Tower import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.GroupTheory.MonoidLocalization import Mathlib.RingTheory.Ideal.Basic import Mathlib.GroupTheory.GroupAction.Ring #align_import ring_theory.localization.basic from "leanprover-community/mathlib"@"b69c9a770ecf37eb21f7b8cf4fa00de3b62694ec" /-! # Localizations of commutative rings We characterize the localization of a commutative ring `R` at a submonoid `M` up to isomorphism; that is, a commutative ring `S` is the localization of `R` at `M` iff we can find a ring homomorphism `f : R →+* S` satisfying 3 properties: 1. For all `y ∈ M`, `f y` is a unit; 2. For all `z : S`, there exists `(x, y) : R × M` such that `z * f y = f x`; 3. For all `x, y : R` such that `f x = f y`, there exists `c ∈ M` such that `x * c = y * c`. (The converse is a consequence of 1.) In the following, let `R, P` be commutative rings, `S, Q` be `R`- and `P`-algebras and `M, T` be submonoids of `R` and `P` respectively, e.g.: ``` variable (R S P Q : Type*) [CommRing R] [CommRing S] [CommRing P] [CommRing Q] variable [Algebra R S] [Algebra P Q] (M : Submonoid R) (T : Submonoid P) ``` ## Main definitions * `IsLocalization (M : Submonoid R) (S : Type*)` is a typeclass expressing that `S` is a localization of `R` at `M`, i.e. the canonical map `algebraMap R S : R →+* S` is a localization map (satisfying the above properties). * `IsLocalization.mk' S` is a surjection sending `(x, y) : R × M` to `f x * (f y)⁻¹` * `IsLocalization.lift` is the ring homomorphism from `S` induced by a homomorphism from `R` which maps elements of `M` to invertible elements of the codomain. * `IsLocalization.map S Q` is the ring homomorphism from `S` to `Q` which maps elements of `M` to elements of `T` * `IsLocalization.ringEquivOfRingEquiv`: if `R` and `P` are isomorphic by an isomorphism sending `M` to `T`, then `S` and `Q` are isomorphic * `IsLocalization.algEquiv`: if `Q` is another localization of `R` at `M`, then `S` and `Q` are isomorphic as `R`-algebras ## Main results * `Localization M S`, a construction of the localization as a quotient type, defined in `GroupTheory.MonoidLocalization`, has `CommRing`, `Algebra R` and `IsLocalization M` instances if `R` is a ring. `Localization.Away`, `Localization.AtPrime` and `FractionRing` are abbreviations for `Localization`s and have their corresponding `IsLocalization` instances ## Implementation notes In maths it is natural to reason up to isomorphism, but in Lean we cannot naturally `rewrite` one structure with an isomorphic one; one way around this is to isolate a predicate characterizing a structure up to isomorphism, and reason about things that satisfy the predicate. A previous version of this file used a fully bundled type of ring localization maps, then used a type synonym `f.codomain` for `f : LocalizationMap M S` to instantiate the `R`-algebra structure on `S`. This results in defining ad-hoc copies for everything already defined on `S`. By making `IsLocalization` a predicate on the `algebraMap R S`, we can ensure the localization map commutes nicely with other `algebraMap`s. To prove most lemmas about a localization map `algebraMap R S` in this file we invoke the corresponding proof for the underlying `CommMonoid` localization map `IsLocalization.toLocalizationMap M S`, which can be found in `GroupTheory.MonoidLocalization` and the namespace `Submonoid.LocalizationMap`. To reason about the localization as a quotient type, use `mk_eq_of_mk'` and associated lemmas. These show the quotient map `mk : R → M → Localization M` equals the surjection `LocalizationMap.mk'` induced by the map `algebraMap : R →+* Localization M`. The lemma `mk_eq_of_mk'` hence gives you access to the results in the rest of the file, which are about the `LocalizationMap.mk'` induced by any localization map. The proof that "a `CommRing` `K` which is the localization of an integral domain `R` at `R \ {0}` is a field" is a `def` rather than an `instance`, so if you want to reason about a field of fractions `K`, assume `[Field K]` instead of just `[CommRing K]`. ## Tags localization, ring localization, commutative ring localization, characteristic predicate, commutative ring, field of fractions -/ open Function section CommSemiring variable {R : Type*} [CommSemiring R] (M : Submonoid R) (S : Type*) [CommSemiring S] variable [Algebra R S] {P : Type*} [CommSemiring P] /-- The typeclass `IsLocalization (M : Submonoid R) S` where `S` is an `R`-algebra expresses that `S` is isomorphic to the localization of `R` at `M`. -/ @[mk_iff] class IsLocalization : Prop where -- Porting note: add ' to fields, and made new versions of these with either `S` or `M` explicit. /-- Everything in the image of `algebraMap` is a unit -/ map_units' : ∀ y : M, IsUnit (algebraMap R S y) /-- The `algebraMap` is surjective -/ surj' : ∀ z : S, ∃ x : R × M, z * algebraMap R S x.2 = algebraMap R S x.1 /-- The kernel of `algebraMap` is contained in the annihilator of `M`; it is then equal to the annihilator by `map_units'` -/ exists_of_eq : ∀ {x y}, algebraMap R S x = algebraMap R S y → ∃ c : M, ↑c * x = ↑c * y #align is_localization IsLocalization variable {M} namespace IsLocalization section IsLocalization variable [IsLocalization M S] section @[inherit_doc IsLocalization.map_units'] theorem map_units : ∀ y : M, IsUnit (algebraMap R S y) := IsLocalization.map_units' variable (M) {S} @[inherit_doc IsLocalization.surj'] theorem surj : ∀ z : S, ∃ x : R × M, z * algebraMap R S x.2 = algebraMap R S x.1 := IsLocalization.surj' variable (S) @[inherit_doc IsLocalization.exists_of_eq] theorem eq_iff_exists {x y} : algebraMap R S x = algebraMap R S y ↔ ∃ c : M, ↑c * x = ↑c * y := Iff.intro IsLocalization.exists_of_eq fun ⟨c, h⟩ ↦ by apply_fun algebraMap R S at h rw [map_mul, map_mul] at h exact (IsLocalization.map_units S c).mul_right_inj.mp h variable {S} theorem of_le (N : Submonoid R) (h₁ : M ≤ N) (h₂ : ∀ r ∈ N, IsUnit (algebraMap R S r)) : IsLocalization N S where map_units' r := h₂ r r.2 surj' s := have ⟨⟨x, y, hy⟩, H⟩ := IsLocalization.surj M s ⟨⟨x, y, h₁ hy⟩, H⟩ exists_of_eq {x y} := by rw [IsLocalization.eq_iff_exists M] rintro ⟨c, hc⟩ exact ⟨⟨c, h₁ c.2⟩, hc⟩ #align is_localization.of_le IsLocalization.of_le variable (S) /-- `IsLocalization.toLocalizationWithZeroMap M S` shows `S` is the monoid localization of `R` at `M`. -/ @[simps] def toLocalizationWithZeroMap : Submonoid.LocalizationWithZeroMap M S where __ := algebraMap R S toFun := algebraMap R S map_units' := IsLocalization.map_units _ surj' := IsLocalization.surj _ exists_of_eq _ _ := IsLocalization.exists_of_eq #align is_localization.to_localization_with_zero_map IsLocalization.toLocalizationWithZeroMap /-- `IsLocalization.toLocalizationMap M S` shows `S` is the monoid localization of `R` at `M`. -/ abbrev toLocalizationMap : Submonoid.LocalizationMap M S := (toLocalizationWithZeroMap M S).toLocalizationMap #align is_localization.to_localization_map IsLocalization.toLocalizationMap @[simp] theorem toLocalizationMap_toMap : (toLocalizationMap M S).toMap = (algebraMap R S : R →*₀ S) := rfl #align is_localization.to_localization_map_to_map IsLocalization.toLocalizationMap_toMap theorem toLocalizationMap_toMap_apply (x) : (toLocalizationMap M S).toMap x = algebraMap R S x := rfl #align is_localization.to_localization_map_to_map_apply IsLocalization.toLocalizationMap_toMap_apply theorem surj₂ : ∀ z w : S, ∃ z' w' : R, ∃ d : M, (z * algebraMap R S d = algebraMap R S z') ∧ (w * algebraMap R S d = algebraMap R S w') := (toLocalizationMap M S).surj₂ end variable (M) {S} /-- Given a localization map `f : M →* N`, a section function sending `z : N` to some `(x, y) : M × S` such that `f x * (f y)⁻¹ = z`. -/ noncomputable def sec (z : S) : R × M := Classical.choose <| IsLocalization.surj _ z #align is_localization.sec IsLocalization.sec @[simp] theorem toLocalizationMap_sec : (toLocalizationMap M S).sec = sec M := rfl #align is_localization.to_localization_map_sec IsLocalization.toLocalizationMap_sec /-- Given `z : S`, `IsLocalization.sec M z` is defined to be a pair `(x, y) : R × M` such that `z * f y = f x` (so this lemma is true by definition). -/ theorem sec_spec (z : S) : z * algebraMap R S (IsLocalization.sec M z).2 = algebraMap R S (IsLocalization.sec M z).1 := Classical.choose_spec <| IsLocalization.surj _ z #align is_localization.sec_spec IsLocalization.sec_spec /-- Given `z : S`, `IsLocalization.sec M z` is defined to be a pair `(x, y) : R × M` such that `z * f y = f x`, so this lemma is just an application of `S`'s commutativity. -/ theorem sec_spec' (z : S) : algebraMap R S (IsLocalization.sec M z).1 = algebraMap R S (IsLocalization.sec M z).2 * z := by rw [mul_comm, sec_spec] #align is_localization.sec_spec' IsLocalization.sec_spec' variable {M} /-- If `M` contains `0` then the localization at `M` is trivial. -/ theorem subsingleton (h : 0 ∈ M) : Subsingleton S := (toLocalizationMap M S).subsingleton h theorem map_right_cancel {x y} {c : M} (h : algebraMap R S (c * x) = algebraMap R S (c * y)) : algebraMap R S x = algebraMap R S y := (toLocalizationMap M S).map_right_cancel h #align is_localization.map_right_cancel IsLocalization.map_right_cancel theorem map_left_cancel {x y} {c : M} (h : algebraMap R S (x * c) = algebraMap R S (y * c)) : algebraMap R S x = algebraMap R S y := (toLocalizationMap M S).map_left_cancel h #align is_localization.map_left_cancel IsLocalization.map_left_cancel theorem eq_zero_of_fst_eq_zero {z x} {y : M} (h : z * algebraMap R S y = algebraMap R S x) (hx : x = 0) : z = 0 := by rw [hx, (algebraMap R S).map_zero] at h exact (IsUnit.mul_left_eq_zero (IsLocalization.map_units S y)).1 h #align is_localization.eq_zero_of_fst_eq_zero IsLocalization.eq_zero_of_fst_eq_zero variable (M S) theorem map_eq_zero_iff (r : R) : algebraMap R S r = 0 ↔ ∃ m : M, ↑m * r = 0 := by constructor · intro h obtain ⟨m, hm⟩ := (IsLocalization.eq_iff_exists M S).mp ((algebraMap R S).map_zero.trans h.symm) exact ⟨m, by simpa using hm.symm⟩ · rintro ⟨m, hm⟩ rw [← (IsLocalization.map_units S m).mul_right_inj, mul_zero, ← RingHom.map_mul, hm, RingHom.map_zero] #align is_localization.map_eq_zero_iff IsLocalization.map_eq_zero_iff variable {M} /-- `IsLocalization.mk' S` is the surjection sending `(x, y) : R × M` to `f x * (f y)⁻¹`. -/ noncomputable def mk' (x : R) (y : M) : S := (toLocalizationMap M S).mk' x y #align is_localization.mk' IsLocalization.mk' @[simp] theorem mk'_sec (z : S) : mk' S (IsLocalization.sec M z).1 (IsLocalization.sec M z).2 = z := (toLocalizationMap M S).mk'_sec _ #align is_localization.mk'_sec IsLocalization.mk'_sec theorem mk'_mul (x₁ x₂ : R) (y₁ y₂ : M) : mk' S (x₁ * x₂) (y₁ * y₂) = mk' S x₁ y₁ * mk' S x₂ y₂ := (toLocalizationMap M S).mk'_mul _ _ _ _ #align is_localization.mk'_mul IsLocalization.mk'_mul theorem mk'_one (x) : mk' S x (1 : M) = algebraMap R S x := (toLocalizationMap M S).mk'_one _ #align is_localization.mk'_one IsLocalization.mk'_one @[simp] theorem mk'_spec (x) (y : M) : mk' S x y * algebraMap R S y = algebraMap R S x := (toLocalizationMap M S).mk'_spec _ _ #align is_localization.mk'_spec IsLocalization.mk'_spec @[simp] theorem mk'_spec' (x) (y : M) : algebraMap R S y * mk' S x y = algebraMap R S x := (toLocalizationMap M S).mk'_spec' _ _ #align is_localization.mk'_spec' IsLocalization.mk'_spec' @[simp] theorem mk'_spec_mk (x) (y : R) (hy : y ∈ M) : mk' S x ⟨y, hy⟩ * algebraMap R S y = algebraMap R S x := mk'_spec S x ⟨y, hy⟩ #align is_localization.mk'_spec_mk IsLocalization.mk'_spec_mk @[simp] theorem mk'_spec'_mk (x) (y : R) (hy : y ∈ M) : algebraMap R S y * mk' S x ⟨y, hy⟩ = algebraMap R S x := mk'_spec' S x ⟨y, hy⟩ #align is_localization.mk'_spec'_mk IsLocalization.mk'_spec'_mk variable {S} theorem eq_mk'_iff_mul_eq {x} {y : M} {z} : z = mk' S x y ↔ z * algebraMap R S y = algebraMap R S x := (toLocalizationMap M S).eq_mk'_iff_mul_eq #align is_localization.eq_mk'_iff_mul_eq IsLocalization.eq_mk'_iff_mul_eq theorem mk'_eq_iff_eq_mul {x} {y : M} {z} : mk' S x y = z ↔ algebraMap R S x = z * algebraMap R S y := (toLocalizationMap M S).mk'_eq_iff_eq_mul #align is_localization.mk'_eq_iff_eq_mul IsLocalization.mk'_eq_iff_eq_mul theorem mk'_add_eq_iff_add_mul_eq_mul {x} {y : M} {z₁ z₂} : mk' S x y + z₁ = z₂ ↔ algebraMap R S x + z₁ * algebraMap R S y = z₂ * algebraMap R S y := by rw [← mk'_spec S x y, ← IsUnit.mul_left_inj (IsLocalization.map_units S y), right_distrib] #align is_localization.mk'_add_eq_iff_add_mul_eq_mul IsLocalization.mk'_add_eq_iff_add_mul_eq_mul variable (M) theorem mk'_surjective (z : S) : ∃ (x : _) (y : M), mk' S x y = z := let ⟨r, hr⟩ := IsLocalization.surj _ z ⟨r.1, r.2, (eq_mk'_iff_mul_eq.2 hr).symm⟩ #align is_localization.mk'_surjective IsLocalization.mk'_surjective variable (S) /-- The localization of a `Fintype` is a `Fintype`. Cannot be an instance. -/ noncomputable def fintype' [Fintype R] : Fintype S := have := Classical.propDecidable Fintype.ofSurjective (Function.uncurry <| IsLocalization.mk' S) fun a => Prod.exists'.mpr <| IsLocalization.mk'_surjective M a #align is_localization.fintype' IsLocalization.fintype' variable {M S} /-- Localizing at a submonoid with 0 inside it leads to the trivial ring. -/ def uniqueOfZeroMem (h : (0 : R) ∈ M) : Unique S := uniqueOfZeroEqOne <| by simpa using IsLocalization.map_units S ⟨0, h⟩ #align is_localization.unique_of_zero_mem IsLocalization.uniqueOfZeroMem theorem mk'_eq_iff_eq {x₁ x₂} {y₁ y₂ : M} : mk' S x₁ y₁ = mk' S x₂ y₂ ↔ algebraMap R S (y₂ * x₁) = algebraMap R S (y₁ * x₂) := (toLocalizationMap M S).mk'_eq_iff_eq #align is_localization.mk'_eq_iff_eq IsLocalization.mk'_eq_iff_eq theorem mk'_eq_iff_eq' {x₁ x₂} {y₁ y₂ : M} : mk' S x₁ y₁ = mk' S x₂ y₂ ↔ algebraMap R S (x₁ * y₂) = algebraMap R S (x₂ * y₁) := (toLocalizationMap M S).mk'_eq_iff_eq' #align is_localization.mk'_eq_iff_eq' IsLocalization.mk'_eq_iff_eq' theorem mk'_mem_iff {x} {y : M} {I : Ideal S} : mk' S x y ∈ I ↔ algebraMap R S x ∈ I := by constructor <;> intro h · rw [← mk'_spec S x y, mul_comm] exact I.mul_mem_left ((algebraMap R S) y) h · rw [← mk'_spec S x y] at h obtain ⟨b, hb⟩ := isUnit_iff_exists_inv.1 (map_units S y) have := I.mul_mem_left b h rwa [mul_comm, mul_assoc, hb, mul_one] at this #align is_localization.mk'_mem_iff IsLocalization.mk'_mem_iff protected theorem eq {a₁ b₁} {a₂ b₂ : M} : mk' S a₁ a₂ = mk' S b₁ b₂ ↔ ∃ c : M, ↑c * (↑b₂ * a₁) = c * (a₂ * b₁) := (toLocalizationMap M S).eq #align is_localization.eq IsLocalization.eq theorem mk'_eq_zero_iff (x : R) (s : M) : mk' S x s = 0 ↔ ∃ m : M, ↑m * x = 0 := by rw [← (map_units S s).mul_left_inj, mk'_spec, zero_mul, map_eq_zero_iff M] #align is_localization.mk'_eq_zero_iff IsLocalization.mk'_eq_zero_iff @[simp] theorem mk'_zero (s : M) : IsLocalization.mk' S 0 s = 0 := by rw [eq_comm, IsLocalization.eq_mk'_iff_mul_eq, zero_mul, map_zero] #align is_localization.mk'_zero IsLocalization.mk'_zero theorem ne_zero_of_mk'_ne_zero {x : R} {y : M} (hxy : IsLocalization.mk' S x y ≠ 0) : x ≠ 0 := by rintro rfl exact hxy (IsLocalization.mk'_zero _) #align is_localization.ne_zero_of_mk'_ne_zero IsLocalization.ne_zero_of_mk'_ne_zero section Ext variable [Algebra R P] [IsLocalization M P] theorem eq_iff_eq {x y} : algebraMap R S x = algebraMap R S y ↔ algebraMap R P x = algebraMap R P y := (toLocalizationMap M S).eq_iff_eq (toLocalizationMap M P) #align is_localization.eq_iff_eq IsLocalization.eq_iff_eq theorem mk'_eq_iff_mk'_eq {x₁ x₂} {y₁ y₂ : M} : mk' S x₁ y₁ = mk' S x₂ y₂ ↔ mk' P x₁ y₁ = mk' P x₂ y₂ := (toLocalizationMap M S).mk'_eq_iff_mk'_eq (toLocalizationMap M P) #align is_localization.mk'_eq_iff_mk'_eq IsLocalization.mk'_eq_iff_mk'_eq theorem mk'_eq_of_eq {a₁ b₁ : R} {a₂ b₂ : M} (H : ↑a₂ * b₁ = ↑b₂ * a₁) : mk' S a₁ a₂ = mk' S b₁ b₂ := (toLocalizationMap M S).mk'_eq_of_eq H #align is_localization.mk'_eq_of_eq IsLocalization.mk'_eq_of_eq theorem mk'_eq_of_eq' {a₁ b₁ : R} {a₂ b₂ : M} (H : b₁ * ↑a₂ = a₁ * ↑b₂) : mk' S a₁ a₂ = mk' S b₁ b₂ := (toLocalizationMap M S).mk'_eq_of_eq' H #align is_localization.mk'_eq_of_eq' IsLocalization.mk'_eq_of_eq' theorem mk'_cancel (a : R) (b c : M) : mk' S (a * c) (b * c) = mk' S a b := (toLocalizationMap M S).mk'_cancel _ _ _ variable (S) @[simp] theorem mk'_self {x : R} (hx : x ∈ M) : mk' S x ⟨x, hx⟩ = 1 := (toLocalizationMap M S).mk'_self _ hx #align is_localization.mk'_self IsLocalization.mk'_self @[simp] theorem mk'_self' {x : M} : mk' S (x : R) x = 1 := (toLocalizationMap M S).mk'_self' _ #align is_localization.mk'_self' IsLocalization.mk'_self' theorem mk'_self'' {x : M} : mk' S x.1 x = 1 := mk'_self' _ #align is_localization.mk'_self'' IsLocalization.mk'_self'' end Ext theorem mul_mk'_eq_mk'_of_mul (x y : R) (z : M) : (algebraMap R S) x * mk' S y z = mk' S (x * y) z := (toLocalizationMap M S).mul_mk'_eq_mk'_of_mul _ _ _ #align is_localization.mul_mk'_eq_mk'_of_mul IsLocalization.mul_mk'_eq_mk'_of_mul theorem mk'_eq_mul_mk'_one (x : R) (y : M) : mk' S x y = (algebraMap R S) x * mk' S 1 y := ((toLocalizationMap M S).mul_mk'_one_eq_mk' _ _).symm #align is_localization.mk'_eq_mul_mk'_one IsLocalization.mk'_eq_mul_mk'_one @[simp] theorem mk'_mul_cancel_left (x : R) (y : M) : mk' S (y * x : R) y = (algebraMap R S) x := (toLocalizationMap M S).mk'_mul_cancel_left _ _ #align is_localization.mk'_mul_cancel_left IsLocalization.mk'_mul_cancel_left theorem mk'_mul_cancel_right (x : R) (y : M) : mk' S (x * y) y = (algebraMap R S) x := (toLocalizationMap M S).mk'_mul_cancel_right _ _ #align is_localization.mk'_mul_cancel_right IsLocalization.mk'_mul_cancel_right @[simp] theorem mk'_mul_mk'_eq_one (x y : M) : mk' S (x : R) y * mk' S (y : R) x = 1 := by rw [← mk'_mul, mul_comm]; exact mk'_self _ _ #align is_localization.mk'_mul_mk'_eq_one IsLocalization.mk'_mul_mk'_eq_one theorem mk'_mul_mk'_eq_one' (x : R) (y : M) (h : x ∈ M) : mk' S x y * mk' S (y : R) ⟨x, h⟩ = 1 := mk'_mul_mk'_eq_one ⟨x, h⟩ _ #align is_localization.mk'_mul_mk'_eq_one' IsLocalization.mk'_mul_mk'_eq_one' theorem smul_mk' (x y : R) (m : M) : x • mk' S y m = mk' S (x * y) m := by nth_rw 2 [← one_mul m] rw [mk'_mul, mk'_one, Algebra.smul_def] @[simp] theorem smul_mk'_one (x : R) (m : M) : x • mk' S 1 m = mk' S x m := by rw [smul_mk', mul_one] @[simp] lemma smul_mk'_self {m : M} {r : R} : (m : R) • mk' S r m = algebraMap R S r := by rw [smul_mk', mk'_mul_cancel_left] @[simps] instance invertible_mk'_one (s : M) : Invertible (IsLocalization.mk' S (1 : R) s) where invOf := algebraMap R S s invOf_mul_self := by simp mul_invOf_self := by simp section variable (M) theorem isUnit_comp (j : S →+* P) (y : M) : IsUnit (j.comp (algebraMap R S) y) := (toLocalizationMap M S).isUnit_comp j.toMonoidHom _ #align is_localization.is_unit_comp IsLocalization.isUnit_comp end /-- Given a localization map `f : R →+* S` for a submonoid `M ⊆ R` and a map of `CommSemiring`s `g : R →+* P` such that `g(M) ⊆ Units P`, `f x = f y → g x = g y` for all `x y : R`. -/ theorem eq_of_eq {g : R →+* P} (hg : ∀ y : M, IsUnit (g y)) {x y} (h : (algebraMap R S) x = (algebraMap R S) y) : g x = g y := Submonoid.LocalizationMap.eq_of_eq (toLocalizationMap M S) (g := g.toMonoidHom) hg h #align is_localization.eq_of_eq IsLocalization.eq_of_eq theorem mk'_add (x₁ x₂ : R) (y₁ y₂ : M) : mk' S (x₁ * y₂ + x₂ * y₁) (y₁ * y₂) = mk' S x₁ y₁ + mk' S x₂ y₂ := mk'_eq_iff_eq_mul.2 <| Eq.symm (by rw [mul_comm (_ + _), mul_add, mul_mk'_eq_mk'_of_mul, mk'_add_eq_iff_add_mul_eq_mul, mul_comm (_ * _), ← mul_assoc, add_comm, ← map_mul, mul_mk'_eq_mk'_of_mul, mk'_add_eq_iff_add_mul_eq_mul] simp only [map_add, Submonoid.coe_mul, map_mul] ring) #align is_localization.mk'_add IsLocalization.mk'_add theorem mul_add_inv_left {g : R →+* P} (h : ∀ y : M, IsUnit (g y)) (y : M) (w z₁ z₂ : P) : w * ↑(IsUnit.liftRight (g.toMonoidHom.restrict M) h y)⁻¹ + z₁ = z₂ ↔ w + g y * z₁ = g y * z₂ := by rw [mul_comm, ← one_mul z₁, ← Units.inv_mul (IsUnit.liftRight (g.toMonoidHom.restrict M) h y), mul_assoc, ← mul_add, Units.inv_mul_eq_iff_eq_mul, Units.inv_mul_cancel_left, IsUnit.coe_liftRight] simp [RingHom.toMonoidHom_eq_coe, MonoidHom.restrict_apply] #align is_localization.mul_add_inv_left IsLocalization.mul_add_inv_left theorem lift_spec_mul_add {g : R →+* P} (hg : ∀ y : M, IsUnit (g y)) (z w w' v) : ((toLocalizationWithZeroMap M S).lift g.toMonoidWithZeroHom hg) z * w + w' = v ↔ g ((toLocalizationMap M S).sec z).1 * w + g ((toLocalizationMap M S).sec z).2 * w' = g ((toLocalizationMap M S).sec z).2 * v := by erw [mul_comm, ← mul_assoc, mul_add_inv_left hg, mul_comm] rfl #align is_localization.lift_spec_mul_add IsLocalization.lift_spec_mul_add /-- Given a localization map `f : R →+* S` for a submonoid `M ⊆ R` and a map of `CommSemiring`s `g : R →+* P` such that `g y` is invertible for all `y : M`, the homomorphism induced from `S` to `P` sending `z : S` to `g x * (g y)⁻¹`, where `(x, y) : R × M` are such that `z = f x * (f y)⁻¹`. -/ noncomputable def lift {g : R →+* P} (hg : ∀ y : M, IsUnit (g y)) : S →+* P := { Submonoid.LocalizationWithZeroMap.lift (toLocalizationWithZeroMap M S) g.toMonoidWithZeroHom hg with map_add' := by intro x y erw [(toLocalizationMap M S).lift_spec, mul_add, mul_comm, eq_comm, lift_spec_mul_add, add_comm, mul_comm, mul_assoc, mul_comm, mul_assoc, lift_spec_mul_add] simp_rw [← mul_assoc] show g _ * g _ * g _ + g _ * g _ * g _ = g _ * g _ * g _ simp_rw [← map_mul g, ← map_add g] apply eq_of_eq (S := S) hg simp only [sec_spec', toLocalizationMap_sec, map_add, map_mul] ring } #align is_localization.lift IsLocalization.lift variable {g : R →+* P} (hg : ∀ y : M, IsUnit (g y)) /-- Given a localization map `f : R →+* S` for a submonoid `M ⊆ R` and a map of `CommSemiring`s `g : R →* P` such that `g y` is invertible for all `y : M`, the homomorphism induced from `S` to `P` maps `f x * (f y)⁻¹` to `g x * (g y)⁻¹` for all `x : R, y ∈ M`. -/ theorem lift_mk' (x y) : lift hg (mk' S x y) = g x * ↑(IsUnit.liftRight (g.toMonoidHom.restrict M) hg y)⁻¹ := (toLocalizationMap M S).lift_mk' _ _ _ #align is_localization.lift_mk' IsLocalization.lift_mk' theorem lift_mk'_spec (x v) (y : M) : lift hg (mk' S x y) = v ↔ g x = g y * v := (toLocalizationMap M S).lift_mk'_spec _ _ _ _ #align is_localization.lift_mk'_spec IsLocalization.lift_mk'_spec @[simp] theorem lift_eq (x : R) : lift hg ((algebraMap R S) x) = g x := (toLocalizationMap M S).lift_eq _ _ #align is_localization.lift_eq IsLocalization.lift_eq theorem lift_eq_iff {x y : R × M} : lift hg (mk' S x.1 x.2) = lift hg (mk' S y.1 y.2) ↔ g (x.1 * y.2) = g (y.1 * x.2) := (toLocalizationMap M S).lift_eq_iff _ #align is_localization.lift_eq_iff IsLocalization.lift_eq_iff @[simp] theorem lift_comp : (lift hg).comp (algebraMap R S) = g := RingHom.ext <| (DFunLike.ext_iff (F := MonoidHom _ _)).1 <| (toLocalizationMap M S).lift_comp _ #align is_localization.lift_comp IsLocalization.lift_comp @[simp] theorem lift_of_comp (j : S →+* P) : lift (isUnit_comp M j) = j := RingHom.ext <| (DFunLike.ext_iff (F := MonoidHom _ _)).1 <| (toLocalizationMap M S).lift_of_comp j.toMonoidHom #align is_localization.lift_of_comp IsLocalization.lift_of_comp variable (M) /-- See note [partially-applied ext lemmas] -/ theorem monoidHom_ext ⦃j k : S →* P⦄ (h : j.comp (algebraMap R S : R →* S) = k.comp (algebraMap R S)) : j = k := Submonoid.LocalizationMap.epic_of_localizationMap (toLocalizationMap M S) <| DFunLike.congr_fun h #align is_localization.monoid_hom_ext IsLocalization.monoidHom_ext /-- See note [partially-applied ext lemmas] -/ theorem ringHom_ext ⦃j k : S →+* P⦄ (h : j.comp (algebraMap R S) = k.comp (algebraMap R S)) : j = k := RingHom.coe_monoidHom_injective <| monoidHom_ext M <| MonoidHom.ext <| RingHom.congr_fun h #align is_localization.ring_hom_ext IsLocalization.ringHom_ext /- This is not an instance because the submonoid `M` would become a metavariable in typeclass search. -/ theorem algHom_subsingleton [Algebra R P] : Subsingleton (S →ₐ[R] P) := ⟨fun f g => AlgHom.coe_ringHom_injective <| IsLocalization.ringHom_ext M <| by rw [f.comp_algebraMap, g.comp_algebraMap]⟩ #align is_localization.alg_hom_subsingleton IsLocalization.algHom_subsingleton /-- To show `j` and `k` agree on the whole localization, it suffices to show they agree on the image of the base ring, if they preserve `1` and `*`. -/ protected theorem ext (j k : S → P) (hj1 : j 1 = 1) (hk1 : k 1 = 1) (hjm : ∀ a b, j (a * b) = j a * j b) (hkm : ∀ a b, k (a * b) = k a * k b) (h : ∀ a, j (algebraMap R S a) = k (algebraMap R S a)) : j = k := let j' : MonoidHom S P := { toFun := j, map_one' := hj1, map_mul' := hjm } let k' : MonoidHom S P := { toFun := k, map_one' := hk1, map_mul' := hkm } have : j' = k' := monoidHom_ext M (MonoidHom.ext h) show j'.toFun = k'.toFun by rw [this] #align is_localization.ext IsLocalization.ext variable {M} theorem lift_unique {j : S →+* P} (hj : ∀ x, j ((algebraMap R S) x) = g x) : lift hg = j := RingHom.ext <| (DFunLike.ext_iff (F := MonoidHom _ _)).1 <| Submonoid.LocalizationMap.lift_unique (toLocalizationMap M S) (g := g.toMonoidHom) hg (j := j.toMonoidHom) hj #align is_localization.lift_unique IsLocalization.lift_unique @[simp] theorem lift_id (x) : lift (map_units S : ∀ _ : M, IsUnit _) x = x := (toLocalizationMap M S).lift_id _ #align is_localization.lift_id IsLocalization.lift_id theorem lift_surjective_iff : Surjective (lift hg : S → P) ↔ ∀ v : P, ∃ x : R × M, v * g x.2 = g x.1 := (toLocalizationMap M S).lift_surjective_iff hg #align is_localization.lift_surjective_iff IsLocalization.lift_surjective_iff theorem lift_injective_iff : Injective (lift hg : S → P) ↔ ∀ x y, algebraMap R S x = algebraMap R S y ↔ g x = g y := (toLocalizationMap M S).lift_injective_iff hg #align is_localization.lift_injective_iff IsLocalization.lift_injective_iff section Map variable {T : Submonoid P} {Q : Type*} [CommSemiring Q] (hy : M ≤ T.comap g) variable [Algebra P Q] [IsLocalization T Q] section variable (Q) /-- Map a homomorphism `g : R →+* P` to `S →+* Q`, where `S` and `Q` are localizations of `R` and `P` at `M` and `T` respectively, such that `g(M) ⊆ T`. We send `z : S` to `algebraMap P Q (g x) * (algebraMap P Q (g y))⁻¹`, where `(x, y) : R × M` are such that `z = f x * (f y)⁻¹`. -/ noncomputable def map (g : R →+* P) (hy : M ≤ T.comap g) : S →+* Q := lift (M := M) (g := (algebraMap P Q).comp g) fun y => map_units _ ⟨g y, hy y.2⟩ #align is_localization.map IsLocalization.map end -- Porting note: added `simp` attribute, since it proves very similar lemmas marked `simp` @[simp] theorem map_eq (x) : map Q g hy ((algebraMap R S) x) = algebraMap P Q (g x) := lift_eq (fun y => map_units _ ⟨g y, hy y.2⟩) x #align is_localization.map_eq IsLocalization.map_eq @[simp] theorem map_comp : (map Q g hy).comp (algebraMap R S) = (algebraMap P Q).comp g := lift_comp fun y => map_units _ ⟨g y, hy y.2⟩ #align is_localization.map_comp IsLocalization.map_comp theorem map_mk' (x) (y : M) : map Q g hy (mk' S x y) = mk' Q (g x) ⟨g y, hy y.2⟩ := Submonoid.LocalizationMap.map_mk' (toLocalizationMap M S) (g := g.toMonoidHom) (fun y => hy y.2) (k := toLocalizationMap T Q) .. #align is_localization.map_mk' IsLocalization.map_mk' -- Porting note (#10756): new theorem @[simp] theorem map_id_mk' {Q : Type*} [CommSemiring Q] [Algebra R Q] [IsLocalization M Q] (x) (y : M) : map Q (RingHom.id R) (le_refl M) (mk' S x y) = mk' Q x y := map_mk' .. @[simp] theorem map_id (z : S) (h : M ≤ M.comap (RingHom.id R) := le_refl M) : map S (RingHom.id _) h z = z := lift_id _ #align is_localization.map_id IsLocalization.map_id theorem map_unique (j : S →+* Q) (hj : ∀ x : R, j (algebraMap R S x) = algebraMap P Q (g x)) : map Q g hy = j := lift_unique (fun y => map_units _ ⟨g y, hy y.2⟩) hj #align is_localization.map_unique IsLocalization.map_unique /-- If `CommSemiring` homs `g : R →+* P, l : P →+* A` induce maps of localizations, the composition of the induced maps equals the map of localizations induced by `l ∘ g`. -/ theorem map_comp_map {A : Type*} [CommSemiring A] {U : Submonoid A} {W} [CommSemiring W] [Algebra A W] [IsLocalization U W] {l : P →+* A} (hl : T ≤ U.comap l) : (map W l hl).comp (map Q g hy : S →+* _) = map W (l.comp g) fun _ hx => hl (hy hx) := RingHom.ext fun x => Submonoid.LocalizationMap.map_map (P := P) (toLocalizationMap M S) (fun y => hy y.2) (toLocalizationMap U W) (fun w => hl w.2) x #align is_localization.map_comp_map IsLocalization.map_comp_map /-- If `CommSemiring` homs `g : R →+* P, l : P →+* A` induce maps of localizations, the composition of the induced maps equals the map of localizations induced by `l ∘ g`. -/ theorem map_map {A : Type*} [CommSemiring A] {U : Submonoid A} {W} [CommSemiring W] [Algebra A W] [IsLocalization U W] {l : P →+* A} (hl : T ≤ U.comap l) (x : S) : map W l hl (map Q g hy x) = map W (l.comp g) (fun x hx => hl (hy hx)) x := by rw [← map_comp_map (Q := Q) hy hl]; rfl #align is_localization.map_map IsLocalization.map_map theorem map_smul (x : S) (z : R) : map Q g hy (z • x : S) = g z • map Q g hy x := by rw [Algebra.smul_def, Algebra.smul_def, RingHom.map_mul, map_eq] #align is_localization.map_smul IsLocalization.map_smul section variable (S Q) /-- If `S`, `Q` are localizations of `R` and `P` at submonoids `M, T` respectively, an isomorphism `j : R ≃+* P` such that `j(M) = T` induces an isomorphism of localizations `S ≃+* Q`. -/ @[simps] noncomputable def ringEquivOfRingEquiv (h : R ≃+* P) (H : M.map h.toMonoidHom = T) : S ≃+* Q := have H' : T.map h.symm.toMonoidHom = M := by rw [← M.map_id, ← H, Submonoid.map_map] congr ext apply h.symm_apply_apply { map Q (h : R →+* P) (M.le_comap_of_map_le (le_of_eq H)) with toFun := map Q (h : R →+* P) (M.le_comap_of_map_le (le_of_eq H)) invFun := map S (h.symm : P →+* R) (T.le_comap_of_map_le (le_of_eq H')) left_inv := fun x => by rw [map_map, map_unique _ (RingHom.id _), RingHom.id_apply] simp right_inv := fun x => by rw [map_map, map_unique _ (RingHom.id _), RingHom.id_apply] simp } #align is_localization.ring_equiv_of_ring_equiv IsLocalization.ringEquivOfRingEquiv end theorem ringEquivOfRingEquiv_eq_map {j : R ≃+* P} (H : M.map j.toMonoidHom = T) : (ringEquivOfRingEquiv S Q j H : S →+* Q) = map Q (j : R →+* P) (M.le_comap_of_map_le (le_of_eq H)) := rfl #align is_localization.ring_equiv_of_ring_equiv_eq_map IsLocalization.ringEquivOfRingEquiv_eq_map -- Porting note (#10618): removed `simp`, `simp` can prove it theorem ringEquivOfRingEquiv_eq {j : R ≃+* P} (H : M.map j.toMonoidHom = T) (x) : ringEquivOfRingEquiv S Q j H ((algebraMap R S) x) = algebraMap P Q (j x) := by simp #align is_localization.ring_equiv_of_ring_equiv_eq IsLocalization.ringEquivOfRingEquiv_eq theorem ringEquivOfRingEquiv_mk' {j : R ≃+* P} (H : M.map j.toMonoidHom = T) (x : R) (y : M) : ringEquivOfRingEquiv S Q j H (mk' S x y) = mk' Q (j x) ⟨j y, show j y ∈ T from H ▸ Set.mem_image_of_mem j y.2⟩ := by simp [map_mk'] #align is_localization.ring_equiv_of_ring_equiv_mk' IsLocalization.ringEquivOfRingEquiv_mk' end Map section AlgEquiv variable {Q : Type*} [CommSemiring Q] [Algebra R Q] [IsLocalization M Q] section variable (M S Q) /-- If `S`, `Q` are localizations of `R` at the submonoid `M` respectively, there is an isomorphism of localizations `S ≃ₐ[R] Q`. -/ @[simps!] noncomputable def algEquiv : S ≃ₐ[R] Q := { ringEquivOfRingEquiv S Q (RingEquiv.refl R) M.map_id with commutes' := ringEquivOfRingEquiv_eq _ } #align is_localization.alg_equiv IsLocalization.algEquiv end -- Porting note (#10618): removed `simp`, `simp` can prove it theorem algEquiv_mk' (x : R) (y : M) : algEquiv M S Q (mk' S x y) = mk' Q x y := by simp #align is_localization.alg_equiv_mk' IsLocalization.algEquiv_mk' -- Porting note (#10618): removed `simp`, `simp` can prove it theorem algEquiv_symm_mk' (x : R) (y : M) : (algEquiv M S Q).symm (mk' Q x y) = mk' S x y := by simp #align is_localization.alg_equiv_symm_mk' IsLocalization.algEquiv_symm_mk' end AlgEquiv section at_units lemma at_units {R : Type*} [CommSemiring R] (S : Submonoid R) (hS : S ≤ IsUnit.submonoid R) : IsLocalization S R where map_units' y := hS y.prop surj' := fun s ↦ ⟨⟨s, 1⟩, by simp⟩ exists_of_eq := fun {x y} (e : x = y) ↦ ⟨1, e ▸ rfl⟩ variable (R M) /-- The localization at a module of units is isomorphic to the ring. -/ noncomputable def atUnits (H : M ≤ IsUnit.submonoid R) : R ≃ₐ[R] S := by refine AlgEquiv.ofBijective (Algebra.ofId R S) ⟨?_, ?_⟩ · intro x y hxy obtain ⟨c, eq⟩ := (IsLocalization.eq_iff_exists M S).mp hxy obtain ⟨u, hu⟩ := H c.prop rwa [← hu, Units.mul_right_inj] at eq · intro y obtain ⟨⟨x, s⟩, eq⟩ := IsLocalization.surj M y obtain ⟨u, hu⟩ := H s.prop use x * u.inv dsimp [Algebra.ofId, RingHom.toFun_eq_coe, AlgHom.coe_mks] rw [RingHom.map_mul, ← eq, ← hu, mul_assoc, ← RingHom.map_mul] simp #align is_localization.at_units IsLocalization.atUnits end at_units section variable (M S) (Q : Type*) [CommSemiring Q] [Algebra P Q] /-- Injectivity of a map descends to the map induced on localizations. -/ theorem map_injective_of_injective (h : Function.Injective g) [IsLocalization (M.map g) Q] : Function.Injective (map Q g M.le_comap_map : S → Q) := (toLocalizationMap M S).map_injective_of_injective h (toLocalizationMap (M.map g) Q) end end IsLocalization section variable (M) {S} theorem isLocalization_of_algEquiv [Algebra R P] [IsLocalization M S] (h : S ≃ₐ[R] P) : IsLocalization M P := by constructor · intro y convert (IsLocalization.map_units S y).map h.toAlgHom.toRingHom.toMonoidHom exact (h.commutes y).symm · intro y obtain ⟨⟨x, s⟩, e⟩ := IsLocalization.surj M (h.symm y) apply_fun (show S → P from h) at e simp only [h.map_mul, h.apply_symm_apply, h.commutes] at e exact ⟨⟨x, s⟩, e⟩ · intro x y rw [← h.symm.toEquiv.injective.eq_iff, ← IsLocalization.eq_iff_exists M S, ← h.symm.commutes, ← h.symm.commutes] exact id #align is_localization.is_localization_of_alg_equiv IsLocalization.isLocalization_of_algEquiv theorem isLocalization_iff_of_algEquiv [Algebra R P] (h : S ≃ₐ[R] P) : IsLocalization M S ↔ IsLocalization M P := ⟨fun _ => isLocalization_of_algEquiv M h, fun _ => isLocalization_of_algEquiv M h.symm⟩ #align is_localization.is_localization_iff_of_alg_equiv IsLocalization.isLocalization_iff_of_algEquiv theorem isLocalization_iff_of_ringEquiv (h : S ≃+* P) : IsLocalization M S ↔ haveI := (h.toRingHom.comp <| algebraMap R S).toAlgebra; IsLocalization M P := letI := (h.toRingHom.comp <| algebraMap R S).toAlgebra isLocalization_iff_of_algEquiv M { h with commutes' := fun _ => rfl } #align is_localization.is_localization_iff_of_ring_equiv IsLocalization.isLocalization_iff_of_ringEquiv variable (S) theorem isLocalization_of_base_ringEquiv [IsLocalization M S] (h : R ≃+* P) : haveI := ((algebraMap R S).comp h.symm.toRingHom).toAlgebra IsLocalization (M.map h.toMonoidHom) S := by letI : Algebra P S := ((algebraMap R S).comp h.symm.toRingHom).toAlgebra constructor · rintro ⟨_, ⟨y, hy, rfl⟩⟩ convert IsLocalization.map_units S ⟨y, hy⟩ dsimp only [RingHom.algebraMap_toAlgebra, RingHom.comp_apply] exact congr_arg _ (h.symm_apply_apply _) · intro y obtain ⟨⟨x, s⟩, e⟩ := IsLocalization.surj M y refine ⟨⟨h x, _, _, s.prop, rfl⟩, ?_⟩ dsimp only [RingHom.algebraMap_toAlgebra, RingHom.comp_apply] at e ⊢ convert e <;> exact h.symm_apply_apply _ · intro x y rw [RingHom.algebraMap_toAlgebra, RingHom.comp_apply, RingHom.comp_apply, IsLocalization.eq_iff_exists M S] simp_rw [← h.toEquiv.apply_eq_iff_eq] change (∃ c : M, h (c * h.symm x) = h (c * h.symm y)) → _ simp only [RingEquiv.apply_symm_apply, RingEquiv.map_mul] exact fun ⟨c, e⟩ ↦ ⟨⟨_, _, c.prop, rfl⟩, e⟩ #align is_localization.is_localization_of_base_ring_equiv IsLocalization.isLocalization_of_base_ringEquiv theorem isLocalization_iff_of_base_ringEquiv (h : R ≃+* P) : IsLocalization M S ↔ haveI := ((algebraMap R S).comp h.symm.toRingHom).toAlgebra IsLocalization (M.map h.toMonoidHom) S := by letI : Algebra P S := ((algebraMap R S).comp h.symm.toRingHom).toAlgebra refine ⟨fun _ => isLocalization_of_base_ringEquiv M S h, ?_⟩ intro H convert isLocalization_of_base_ringEquiv (Submonoid.map (RingEquiv.toMonoidHom h) M) S h.symm · erw [Submonoid.map_equiv_eq_comap_symm, Submonoid.comap_map_eq_of_injective] exact h.toEquiv.injective rw [RingHom.algebraMap_toAlgebra, RingHom.comp_assoc] simp only [RingHom.comp_id, RingEquiv.symm_symm, RingEquiv.symm_toRingHom_comp_toRingHom] apply Algebra.algebra_ext intro r rw [RingHom.algebraMap_toAlgebra] #align is_localization.is_localization_iff_of_base_ring_equiv IsLocalization.isLocalization_iff_of_base_ringEquiv end variable (M) theorem nonZeroDivisors_le_comap [IsLocalization M S] : nonZeroDivisors R ≤ (nonZeroDivisors S).comap (algebraMap R S) := by rintro a ha b (e : b * algebraMap R S a = 0) obtain ⟨x, s, rfl⟩ := mk'_surjective M b rw [← @mk'_one R _ M, ← mk'_mul, ← (algebraMap R S).map_zero, ← @mk'_one R _ M, IsLocalization.eq] at e obtain ⟨c, e⟩ := e rw [mul_zero, mul_zero, Submonoid.coe_one, one_mul, ← mul_assoc] at e rw [mk'_eq_zero_iff] exact ⟨c, ha _ e⟩ #align is_localization.non_zero_divisors_le_comap IsLocalization.nonZeroDivisors_le_comap theorem map_nonZeroDivisors_le [IsLocalization M S] : (nonZeroDivisors R).map (algebraMap R S) ≤ nonZeroDivisors S := Submonoid.map_le_iff_le_comap.mpr (nonZeroDivisors_le_comap M S) #align is_localization.map_non_zero_divisors_le IsLocalization.map_nonZeroDivisors_le end IsLocalization namespace Localization open IsLocalization /-! ### Constructing a localization at a given submonoid -/ section instance instUniqueLocalization [Subsingleton R] : Unique (Localization M) where uniq a := show a = mk 1 1 from Localization.induction_on a fun _ => by congr <;> apply Subsingleton.elim /-- Addition in a ring localization is defined as `⟨a, b⟩ + ⟨c, d⟩ = ⟨b * c + d * a, b * d⟩`. Should not be confused with `AddLocalization.add`, which is defined as `⟨a, b⟩ + ⟨c, d⟩ = ⟨a + c, b + d⟩`. -/ protected irreducible_def add (z w : Localization M) : Localization M := Localization.liftOn₂ z w (fun a b c d => mk ((b : R) * c + d * a) (b * d)) fun {a a' b b' c c' d d'} h1 h2 => mk_eq_mk_iff.2 (by rw [r_eq_r'] at h1 h2 ⊢ cases' h1 with t₅ ht₅ cases' h2 with t₆ ht₆ use t₅ * t₆ dsimp only calc ↑t₅ * ↑t₆ * (↑b' * ↑d' * ((b : R) * c + d * a)) _ = t₆ * (d' * c) * (t₅ * (b' * b)) + t₅ * (b' * a) * (t₆ * (d' * d)) := by ring _ = t₅ * t₆ * (b * d * (b' * c' + d' * a')) := by rw [ht₆, ht₅]; ring ) #align localization.add Localization.add instance : Add (Localization M) := ⟨Localization.add⟩ theorem add_mk (a b c d) : (mk a b : Localization M) + mk c d = mk ((b : R) * c + (d : R) * a) (b * d) := by show Localization.add (mk a b) (mk c d) = mk _ _ simp [Localization.add_def] #align localization.add_mk Localization.add_mk theorem add_mk_self (a b c) : (mk a b : Localization M) + mk c b = mk (a + c) b := by rw [add_mk, mk_eq_mk_iff, r_eq_r'] refine (r' M).symm ⟨1, ?_⟩ simp only [Submonoid.coe_one, Submonoid.coe_mul] ring #align localization.add_mk_self Localization.add_mk_self local macro "localization_tac" : tactic => `(tactic| { intros simp only [add_mk, Localization.mk_mul, ← Localization.mk_zero 1] refine mk_eq_mk_iff.mpr (r_of_eq ?_) simp only [Submonoid.coe_mul] ring }) instance : CommSemiring (Localization M) := { (show CommMonoidWithZero (Localization M) by infer_instance) with add := (· + ·) nsmul := (· • ·) nsmul_zero := fun x => Localization.induction_on x fun x => by simp only [smul_mk, zero_nsmul, mk_zero] nsmul_succ := fun n x => Localization.induction_on x fun x => by simp only [smul_mk, succ_nsmul, add_mk_self] add_assoc := fun m n k => Localization.induction_on₃ m n k (by localization_tac) zero_add := fun y => Localization.induction_on y (by localization_tac) add_zero := fun y => Localization.induction_on y (by localization_tac) add_comm := fun y z => Localization.induction_on₂ z y (by localization_tac) left_distrib := fun m n k => Localization.induction_on₃ m n k (by localization_tac) right_distrib := fun m n k => Localization.induction_on₃ m n k (by localization_tac) } /-- For any given denominator `b : M`, the map `a ↦ a / b` is an `AddMonoidHom` from `R` to `Localization M`-/ @[simps] def mkAddMonoidHom (b : M) : R →+ Localization M where toFun a := mk a b map_zero' := mk_zero _ map_add' _ _ := (add_mk_self _ _ _).symm #align localization.mk_add_monoid_hom Localization.mkAddMonoidHom theorem mk_sum {ι : Type*} (f : ι → R) (s : Finset ι) (b : M) : mk (∑ i ∈ s, f i) b = ∑ i ∈ s, mk (f i) b := map_sum (mkAddMonoidHom b) f s #align localization.mk_sum Localization.mk_sum theorem mk_list_sum (l : List R) (b : M) : mk l.sum b = (l.map fun a => mk a b).sum := map_list_sum (mkAddMonoidHom b) l #align localization.mk_list_sum Localization.mk_list_sum theorem mk_multiset_sum (l : Multiset R) (b : M) : mk l.sum b = (l.map fun a => mk a b).sum := (mkAddMonoidHom b).map_multiset_sum l #align localization.mk_multiset_sum Localization.mk_multiset_sum instance {S : Type*} [Monoid S] [DistribMulAction S R] [IsScalarTower S R R] : DistribMulAction S (Localization M) where smul_zero s := by simp only [← Localization.mk_zero 1, Localization.smul_mk, smul_zero] smul_add s x y := Localization.induction_on₂ x y <| Prod.rec fun r₁ x₁ => Prod.rec fun r₂ x₂ => by simp only [Localization.smul_mk, Localization.add_mk, smul_add, mul_comm _ (s • _), mul_comm _ r₁, mul_comm _ r₂, smul_mul_assoc] instance {S : Type*} [Semiring S] [MulSemiringAction S R] [IsScalarTower S R R] : MulSemiringAction S (Localization M) := { inferInstanceAs (MulDistribMulAction S (Localization M)), inferInstanceAs (DistribMulAction S (Localization M)) with } instance {S : Type*} [Semiring S] [Module S R] [IsScalarTower S R R] : Module S (Localization M) := { inferInstanceAs (DistribMulAction S (Localization M)) with zero_smul := Localization.ind <| Prod.rec <| by intros simp only [Localization.smul_mk, zero_smul, mk_zero] add_smul := fun s₁ s₂ => Localization.ind <| Prod.rec <| by intros simp only [Localization.smul_mk, add_smul, add_mk_self] } instance algebra {S : Type*} [CommSemiring S] [Algebra S R] : Algebra S (Localization M) where toRingHom := RingHom.comp { Localization.monoidOf M with toFun := (monoidOf M).toMap map_zero' := by rw [← mk_zero (1 : M), mk_one_eq_monoidOf_mk] map_add' := fun x y => by simp only [← mk_one_eq_monoidOf_mk, add_mk, Submonoid.coe_one, one_mul, add_comm] } (algebraMap S R) smul_def' s := Localization.ind <| Prod.rec <| by intro r x dsimp simp only [← mk_one_eq_monoidOf_mk, mk_mul, Localization.smul_mk, one_mul, Algebra.smul_def] commutes' s := Localization.ind <| Prod.rec <| by intro r x dsimp simp only [← mk_one_eq_monoidOf_mk, mk_mul, Localization.smul_mk, one_mul, mul_one, Algebra.commutes] instance isLocalization : IsLocalization M (Localization M) where map_units' := (Localization.monoidOf M).map_units surj' := (Localization.monoidOf M).surj exists_of_eq := (Localization.monoidOf M).eq_iff_exists.mp end @[simp] theorem toLocalizationMap_eq_monoidOf : toLocalizationMap M (Localization M) = monoidOf M := rfl #align localization.to_localization_map_eq_monoid_of Localization.toLocalizationMap_eq_monoidOf theorem monoidOf_eq_algebraMap (x) : (monoidOf M).toMap x = algebraMap R (Localization M) x := rfl #align localization.monoid_of_eq_algebra_map Localization.monoidOf_eq_algebraMap theorem mk_one_eq_algebraMap (x) : mk x 1 = algebraMap R (Localization M) x := rfl #align localization.mk_one_eq_algebra_map Localization.mk_one_eq_algebraMap theorem mk_eq_mk'_apply (x y) : mk x y = IsLocalization.mk' (Localization M) x y := by rw [mk_eq_monoidOf_mk'_apply, mk', toLocalizationMap_eq_monoidOf] #align localization.mk_eq_mk'_apply Localization.mk_eq_mk'_apply -- Porting note: removed `simp`. Left hand side can be simplified; not clear what normal form should --be. theorem mk_eq_mk' : (mk : R → M → Localization M) = IsLocalization.mk' (Localization M) := mk_eq_monoidOf_mk' #align localization.mk_eq_mk' Localization.mk_eq_mk' theorem mk_algebraMap {A : Type*} [CommSemiring A] [Algebra A R] (m : A) : mk (algebraMap A R m) 1 = algebraMap A (Localization M) m := by rw [mk_eq_mk', mk'_eq_iff_eq_mul, Submonoid.coe_one, map_one, mul_one]; rfl #align localization.mk_algebra_map Localization.mk_algebraMap theorem mk_natCast (m : ℕ) : (mk m 1 : Localization M) = m := by simpa using mk_algebraMap (R := R) (A := ℕ) _ #align localization.mk_nat_cast Localization.mk_natCast @[deprecated (since := "2024-04-17")] alias mk_nat_cast := mk_natCast variable [IsLocalization M S] section variable (M) /-- The localization of `R` at `M` as a quotient type is isomorphic to any other localization. -/ @[simps!] noncomputable def algEquiv : Localization M ≃ₐ[R] S := IsLocalization.algEquiv M _ _ #align localization.alg_equiv Localization.algEquiv /-- The localization of a singleton is a singleton. Cannot be an instance due to metavariables. -/ noncomputable def _root_.IsLocalization.unique (R Rₘ) [CommSemiring R] [CommSemiring Rₘ] (M : Submonoid R) [Subsingleton R] [Algebra R Rₘ] [IsLocalization M Rₘ] : Unique Rₘ := have : Inhabited Rₘ := ⟨1⟩ (algEquiv M Rₘ).symm.injective.unique #align is_localization.unique IsLocalization.unique end -- Porting note (#10618): removed `simp`, `simp` can prove it nonrec theorem algEquiv_mk' (x : R) (y : M) : algEquiv M S (mk' (Localization M) x y) = mk' S x y := algEquiv_mk' _ _ #align localization.alg_equiv_mk' Localization.algEquiv_mk' -- Porting note (#10618): removed `simp`, `simp` can prove it nonrec theorem algEquiv_symm_mk' (x : R) (y : M) : (algEquiv M S).symm (mk' S x y) = mk' (Localization M) x y := algEquiv_symm_mk' _ _ #align localization.alg_equiv_symm_mk' Localization.algEquiv_symm_mk' theorem algEquiv_mk (x y) : algEquiv M S (mk x y) = mk' S x y := by rw [mk_eq_mk', algEquiv_mk'] #align localization.alg_equiv_mk Localization.algEquiv_mk theorem algEquiv_symm_mk (x : R) (y : M) : (algEquiv M S).symm (mk' S x y) = mk x y := by rw [mk_eq_mk', algEquiv_symm_mk'] #align localization.alg_equiv_symm_mk Localization.algEquiv_symm_mk lemma coe_algEquiv : (Localization.algEquiv M S : Localization M →+* S) = IsLocalization.map (M := M) (T := M) _ (RingHom.id R) le_rfl := rfl lemma coe_algEquiv_symm : ((Localization.algEquiv M S).symm : S →+* Localization M) = IsLocalization.map (M := M) (T := M) _ (RingHom.id R) le_rfl := rfl end Localization end CommSemiring section CommRing variable {R : Type*} [CommRing R] {M : Submonoid R} (S : Type*) [CommRing S] variable [Algebra R S] {P : Type*} [CommRing P] namespace Localization /-- Negation in a ring localization is defined as `-⟨a, b⟩ = ⟨-a, b⟩`. -/ protected irreducible_def neg (z : Localization M) : Localization M := Localization.liftOn z (fun a b => mk (-a) b) fun {a b c d} h => mk_eq_mk_iff.2 (by rw [r_eq_r'] at h ⊢ cases' h with t ht use t rw [mul_neg, mul_neg, ht] ring_nf) #align localization.neg Localization.neg instance : Neg (Localization M) := ⟨Localization.neg⟩ theorem neg_mk (a b) : -(mk a b : Localization M) = mk (-a) b := by show Localization.neg (mk a b) = mk (-a) b rw [Localization.neg_def] apply liftOn_mk #align localization.neg_mk Localization.neg_mk instance : CommRing (Localization M) := { inferInstanceAs (CommSemiring (Localization M)) with zsmul := (· • ·) zsmul_zero' := fun x => Localization.induction_on x fun x => by simp only [smul_mk, zero_zsmul, mk_zero] zsmul_succ' := fun n x => Localization.induction_on x fun x => by simp [smul_mk, add_mk_self, -mk_eq_monoidOf_mk', add_smul] zsmul_neg' := fun n x => Localization.induction_on x fun x => by dsimp only rw [smul_mk, smul_mk, neg_mk, ← neg_smul] rfl neg := Neg.neg sub := fun x y => x + -y sub_eq_add_neg := fun x y => rfl add_left_neg := fun y => Localization.induction_on y (by intros simp only [add_mk, Localization.mk_mul, neg_mk, ← mk_zero 1] refine mk_eq_mk_iff.mpr (r_of_eq ?_) simp only [Submonoid.coe_mul] ring) } theorem sub_mk (a c) (b d) : (mk a b : Localization M) - mk c d = mk ((d : R) * a - b * c) (b * d) := calc mk a b - mk c d = mk a b + -mk c d := sub_eq_add_neg _ _ _ = mk a b + mk (-c) d := by rw [neg_mk] _ = mk (b * -c + d * a) (b * d) := add_mk _ _ _ _ _ = mk (d * a - b * c) (b * d) := by congr; ring #align localization.sub_mk Localization.sub_mk theorem mk_intCast (m : ℤ) : (mk m 1 : Localization M) = m := by simpa using mk_algebraMap (R := R) (A := ℤ) _ #align localization.mk_int_cast Localization.mk_intCast @[deprecated (since := "2024-04-17")] alias mk_int_cast := mk_intCast end Localization namespace IsLocalization variable {K : Type*} [IsLocalization M S] theorem to_map_eq_zero_iff {x : R} (hM : M ≤ nonZeroDivisors R) : algebraMap R S x = 0 ↔ x = 0 := by rw [← (algebraMap R S).map_zero] constructor <;> intro h · cases' (eq_iff_exists M S).mp h with c hc rw [mul_zero, mul_comm] at hc exact hM c.2 x hc · rw [h] #align is_localization.to_map_eq_zero_iff IsLocalization.to_map_eq_zero_iff protected theorem injective (hM : M ≤ nonZeroDivisors R) : Injective (algebraMap R S) := by rw [injective_iff_map_eq_zero (algebraMap R S)] intro a ha rwa [to_map_eq_zero_iff S hM] at ha #align is_localization.injective IsLocalization.injective protected theorem to_map_ne_zero_of_mem_nonZeroDivisors [Nontrivial R] (hM : M ≤ nonZeroDivisors R) {x : R} (hx : x ∈ nonZeroDivisors R) : algebraMap R S x ≠ 0 := show (algebraMap R S).toMonoidWithZeroHom x ≠ 0 from map_ne_zero_of_mem_nonZeroDivisors (algebraMap R S) (IsLocalization.injective S hM) hx #align is_localization.to_map_ne_zero_of_mem_non_zero_divisors IsLocalization.to_map_ne_zero_of_mem_nonZeroDivisors variable {S} theorem sec_snd_ne_zero [Nontrivial R] (hM : M ≤ nonZeroDivisors R) (x : S) : ((sec M x).snd : R) ≠ 0 := nonZeroDivisors.coe_ne_zero ⟨(sec M x).snd.val, hM (sec M x).snd.property⟩ #align is_localization.sec_snd_ne_zero IsLocalization.sec_snd_ne_zero theorem sec_fst_ne_zero [Nontrivial R] [NoZeroDivisors S] (hM : M ≤ nonZeroDivisors R) {x : S} (hx : x ≠ 0) : (sec M x).fst ≠ 0 := by have hsec := sec_spec M x intro hfst rw [hfst, map_zero, mul_eq_zero, _root_.map_eq_zero_iff] at hsec · exact Or.elim hsec hx (sec_snd_ne_zero hM x) · exact IsLocalization.injective S hM #align is_localization.sec_fst_ne_zero IsLocalization.sec_fst_ne_zero variable {Q : Type*} [CommRing Q] {g : R →+* P} [Algebra P Q] variable (A : Type*) [CommRing A] [IsDomain A] /-- A `CommRing` `S` which is the localization of a ring `R` without zero divisors at a subset of non-zero elements does not have zero divisors. -/ theorem noZeroDivisors_of_le_nonZeroDivisors [Algebra A S] {M : Submonoid A} [IsLocalization M S] (hM : M ≤ nonZeroDivisors A) : NoZeroDivisors S := { eq_zero_or_eq_zero_of_mul_eq_zero := by intro z w h cases' surj M z with x hx cases' surj M w with y hy have : z * w * algebraMap A S y.2 * algebraMap A S x.2 = algebraMap A S x.1 * algebraMap A S y.1 := by rw [mul_assoc z, hy, ← hx]; ring rw [h, zero_mul, zero_mul, ← (algebraMap A S).map_mul] at this cases' eq_zero_or_eq_zero_of_mul_eq_zero ((to_map_eq_zero_iff S hM).mp this.symm) with H H · exact Or.inl (eq_zero_of_fst_eq_zero hx H) · exact Or.inr (eq_zero_of_fst_eq_zero hy H) } #align is_localization.no_zero_divisors_of_le_non_zero_divisors IsLocalization.noZeroDivisors_of_le_nonZeroDivisors /-- A `CommRing` `S` which is the localization of an integral domain `R` at a subset of non-zero elements is an integral domain. -/ theorem isDomain_of_le_nonZeroDivisors [Algebra A S] {M : Submonoid A} [IsLocalization M S] (hM : M ≤ nonZeroDivisors A) : IsDomain S := by apply @NoZeroDivisors.to_isDomain _ _ (id _) (id _) · exact ⟨⟨(algebraMap A S) 0, (algebraMap A S) 1, fun h => zero_ne_one (IsLocalization.injective S hM h)⟩⟩ · exact noZeroDivisors_of_le_nonZeroDivisors _ hM #align is_localization.is_domain_of_le_non_zero_divisors IsLocalization.isDomain_of_le_nonZeroDivisors variable {A} /-- The localization of an integral domain to a set of non-zero elements is an integral domain. -/ theorem isDomain_localization {M : Submonoid A} (hM : M ≤ nonZeroDivisors A) : IsDomain (Localization M) := isDomain_of_le_nonZeroDivisors _ hM #align is_localization.is_domain_localization IsLocalization.isDomain_localization end IsLocalization open IsLocalization /-- If `R` is a field, then localizing at a submonoid not containing `0` adds no new elements. -/
Mathlib/RingTheory/Localization/Basic.lean
1,309
1,317
theorem IsField.localization_map_bijective {R Rₘ : Type*} [CommRing R] [CommRing Rₘ] {M : Submonoid R} (hM : (0 : R) ∉ M) (hR : IsField R) [Algebra R Rₘ] [IsLocalization M Rₘ] : Function.Bijective (algebraMap R Rₘ) := by
letI := hR.toField replace hM := le_nonZeroDivisors_of_noZeroDivisors hM refine ⟨IsLocalization.injective _ hM, fun x => ?_⟩ obtain ⟨r, ⟨m, hm⟩, rfl⟩ := mk'_surjective M x obtain ⟨n, hn⟩ := hR.mul_inv_cancel (nonZeroDivisors.ne_zero <| hM hm) exact ⟨r * n, by erw [eq_mk'_iff_mul_eq, ← map_mul, mul_assoc, _root_.mul_comm n, hn, mul_one]⟩
/- 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.Compactness.LocallyCompact /-! # Sigma-compactness in topological spaces ## Main definitions * `IsSigmaCompact`: a set that is the union of countably many compact sets. * `SigmaCompactSpace X`: `X` is a σ-compact topological space; i.e., is the union of a countable collection of compact subspaces. -/ open Set Filter Topology TopologicalSpace Classical universe u v variable {X : Type*} {Y : Type*} {ι : Type*} variable [TopologicalSpace X] [TopologicalSpace Y] {s t : Set X} /-- A subset `s ⊆ X` is called **σ-compact** if it is the union of countably many compact sets. -/ def IsSigmaCompact (s : Set X) : Prop := ∃ K : ℕ → Set X, (∀ n, IsCompact (K n)) ∧ ⋃ n, K n = s /-- Compact sets are σ-compact. -/ lemma IsCompact.isSigmaCompact {s : Set X} (hs : IsCompact s) : IsSigmaCompact s := ⟨fun _ => s, fun _ => hs, iUnion_const _⟩ /-- The empty set is σ-compact. -/ @[simp] lemma isSigmaCompact_empty : IsSigmaCompact (∅ : Set X) := IsCompact.isSigmaCompact isCompact_empty /-- Countable unions of compact sets are σ-compact. -/ lemma isSigmaCompact_iUnion_of_isCompact [hι : Countable ι] (s : ι → Set X) (hcomp : ∀ i, IsCompact (s i)) : IsSigmaCompact (⋃ i, s i) := by rcases isEmpty_or_nonempty ι · simp only [iUnion_of_empty, isSigmaCompact_empty] · -- If ι is non-empty, choose a surjection f : ℕ → ι, this yields a map ℕ → Set X. obtain ⟨f, hf⟩ := countable_iff_exists_surjective.mp hι exact ⟨s ∘ f, fun n ↦ hcomp (f n), Function.Surjective.iUnion_comp hf _⟩ /-- Countable unions of compact sets are σ-compact. -/ lemma isSigmaCompact_sUnion_of_isCompact {S : Set (Set X)} (hc : Set.Countable S) (hcomp : ∀ (s : Set X), s ∈ S → IsCompact s) : IsSigmaCompact (⋃₀ S) := by have : Countable S := countable_coe_iff.mpr hc rw [sUnion_eq_iUnion] apply isSigmaCompact_iUnion_of_isCompact _ (fun ⟨s, hs⟩ ↦ hcomp s hs) /-- Countable unions of σ-compact sets are σ-compact. -/ lemma isSigmaCompact_iUnion [Countable ι] (s : ι → Set X) (hcomp : ∀ i, IsSigmaCompact (s i)) : IsSigmaCompact (⋃ i, s i) := by -- Choose a decomposition s_i = ⋃ K_i,j for each i. choose K hcomp hcov using fun i ↦ hcomp i -- Then, we have a countable union of countable unions of compact sets, i.e. countably many. have := calc ⋃ i, s i _ = ⋃ i, ⋃ n, (K i n) := by simp_rw [hcov] _ = ⋃ (i) (n : ℕ), (K.uncurry ⟨i, n⟩) := by rw [Function.uncurry_def] _ = ⋃ x, K.uncurry x := by rw [← iUnion_prod'] rw [this] exact isSigmaCompact_iUnion_of_isCompact K.uncurry fun x ↦ (hcomp x.1 x.2) /-- Countable unions of σ-compact sets are σ-compact. -/ lemma isSigmaCompact_sUnion (S : Set (Set X)) (hc : Set.Countable S) (hcomp : ∀ s : S, IsSigmaCompact s (X := X)) : IsSigmaCompact (⋃₀ S) := by have : Countable S := countable_coe_iff.mpr hc apply sUnion_eq_iUnion.symm ▸ isSigmaCompact_iUnion _ hcomp /-- Countable unions of σ-compact sets are σ-compact. -/ lemma isSigmaCompact_biUnion {s : Set ι} {S : ι → Set X} (hc : Set.Countable s) (hcomp : ∀ (i : ι), i ∈ s → IsSigmaCompact (S i)) : IsSigmaCompact (⋃ (i : ι) (_ : i ∈ s), S i) := by have : Countable ↑s := countable_coe_iff.mpr hc rw [biUnion_eq_iUnion] exact isSigmaCompact_iUnion _ (fun ⟨i', hi'⟩ ↦ hcomp i' hi') /-- A closed subset of a σ-compact set is σ-compact. -/ lemma IsSigmaCompact.of_isClosed_subset {s t : Set X} (ht : IsSigmaCompact t) (hs : IsClosed s) (h : s ⊆ t) : IsSigmaCompact s := by rcases ht with ⟨K, hcompact, hcov⟩ refine ⟨(fun n ↦ s ∩ (K n)), fun n ↦ (hcompact n).inter_left hs, ?_⟩ rw [← inter_iUnion, hcov] exact inter_eq_left.mpr h /-- If `s` is σ-compact and `f` is continuous on `s`, `f(s)` is σ-compact. -/ lemma IsSigmaCompact.image_of_continuousOn {f : X → Y} {s : Set X} (hs : IsSigmaCompact s) (hf : ContinuousOn f s) : IsSigmaCompact (f '' s) := by rcases hs with ⟨K, hcompact, hcov⟩ refine ⟨fun n ↦ f '' K n, ?_, hcov.symm ▸ image_iUnion.symm⟩ exact fun n ↦ (hcompact n).image_of_continuousOn (hf.mono (hcov.symm ▸ subset_iUnion K n)) /-- If `s` is σ-compact and `f` continuous, `f(s)` is σ-compact. -/ lemma IsSigmaCompact.image {f : X → Y} (hf : Continuous f) {s : Set X} (hs : IsSigmaCompact s) : IsSigmaCompact (f '' s) := hs.image_of_continuousOn hf.continuousOn /-- If `f : X → Y` is `Inducing`, the image `f '' s` of a set `s` is σ-compact if and only `s` is σ-compact. -/ lemma Inducing.isSigmaCompact_iff {f : X → Y} {s : Set X} (hf : Inducing f) : IsSigmaCompact s ↔ IsSigmaCompact (f '' s) := by constructor · exact fun h ↦ h.image hf.continuous · rintro ⟨L, hcomp, hcov⟩ -- Suppose f(s) is σ-compact; we want to show s is σ-compact. -- Write f(s) as a union of compact sets L n, so s = ⋃ K n with K n := f⁻¹(L n) ∩ s. -- Since f is inducing, each K n is compact iff L n is. refine ⟨fun n ↦ f ⁻¹' (L n) ∩ s, ?_, ?_⟩ · intro n have : f '' (f ⁻¹' (L n) ∩ s) = L n := by rw [image_preimage_inter, inter_eq_left.mpr] exact (subset_iUnion _ n).trans hcov.le apply hf.isCompact_iff.mpr (this.symm ▸ (hcomp n)) · calc ⋃ n, f ⁻¹' L n ∩ s _ = f ⁻¹' (⋃ n, L n) ∩ s := by rw [preimage_iUnion, iUnion_inter] _ = f ⁻¹' (f '' s) ∩ s := by rw [hcov] _ = s := inter_eq_right.mpr (subset_preimage_image _ _) /-- If `f : X → Y` is an `Embedding`, the image `f '' s` of a set `s` is σ-compact if and only `s` is σ-compact. -/ lemma Embedding.isSigmaCompact_iff {f : X → Y} {s : Set X} (hf : Embedding f) : IsSigmaCompact s ↔ IsSigmaCompact (f '' s) := hf.toInducing.isSigmaCompact_iff /-- Sets of subtype are σ-compact iff the image under a coercion is. -/ lemma Subtype.isSigmaCompact_iff {p : X → Prop} {s : Set { a // p a }} : IsSigmaCompact s ↔ IsSigmaCompact ((↑) '' s : Set X) := embedding_subtype_val.isSigmaCompact_iff /-- A σ-compact space is a space that is the union of a countable collection of compact subspaces. Note that a locally compact separable T₂ space need not be σ-compact. The sequence can be extracted using `compactCovering`. -/ class SigmaCompactSpace (X : Type*) [TopologicalSpace X] : Prop where /-- In a σ-compact space, `Set.univ` is a σ-compact set. -/ isSigmaCompact_univ : IsSigmaCompact (univ : Set X) #align sigma_compact_space SigmaCompactSpace /-- A topological space is σ-compact iff `univ` is σ-compact. -/ lemma isSigmaCompact_univ_iff : IsSigmaCompact (univ : Set X) ↔ SigmaCompactSpace X := ⟨fun h => ⟨h⟩, fun h => h.1⟩ /-- In a σ-compact space, `univ` is σ-compact. -/ lemma isSigmaCompact_univ [h : SigmaCompactSpace X] : IsSigmaCompact (univ : Set X) := isSigmaCompact_univ_iff.mpr h /-- A topological space is σ-compact iff there exists a countable collection of compact subspaces that cover the entire space. -/ lemma SigmaCompactSpace_iff_exists_compact_covering : SigmaCompactSpace X ↔ ∃ K : ℕ → Set X, (∀ n, IsCompact (K n)) ∧ ⋃ n, K n = univ := by rw [← isSigmaCompact_univ_iff, IsSigmaCompact] lemma SigmaCompactSpace.exists_compact_covering [h : SigmaCompactSpace X] : ∃ K : ℕ → Set X, (∀ n, IsCompact (K n)) ∧ ⋃ n, K n = univ := SigmaCompactSpace_iff_exists_compact_covering.mp h /-- If `X` is σ-compact, `im f` is σ-compact. -/ lemma isSigmaCompact_range {f : X → Y} (hf : Continuous f) [SigmaCompactSpace X] : IsSigmaCompact (range f) := image_univ ▸ isSigmaCompact_univ.image hf /-- A subset `s` is σ-compact iff `s` (with the subspace topology) is a σ-compact space. -/ lemma isSigmaCompact_iff_isSigmaCompact_univ {s : Set X} : IsSigmaCompact s ↔ IsSigmaCompact (univ : Set s) := by rw [Subtype.isSigmaCompact_iff, image_univ, Subtype.range_coe] lemma isSigmaCompact_iff_sigmaCompactSpace {s : Set X} : IsSigmaCompact s ↔ SigmaCompactSpace s := isSigmaCompact_iff_isSigmaCompact_univ.trans isSigmaCompact_univ_iff -- see Note [lower instance priority] instance (priority := 200) CompactSpace.sigma_compact [CompactSpace X] : SigmaCompactSpace X := ⟨⟨fun _ => univ, fun _ => isCompact_univ, iUnion_const _⟩⟩ #align compact_space.sigma_compact CompactSpace.sigma_compact theorem SigmaCompactSpace.of_countable (S : Set (Set X)) (Hc : S.Countable) (Hcomp : ∀ s ∈ S, IsCompact s) (HU : ⋃₀ S = univ) : SigmaCompactSpace X := ⟨(exists_seq_cover_iff_countable ⟨_, isCompact_empty⟩).2 ⟨S, Hc, Hcomp, HU⟩⟩ #align sigma_compact_space.of_countable SigmaCompactSpace.of_countable -- see Note [lower instance priority] instance (priority := 100) sigmaCompactSpace_of_locally_compact_second_countable [LocallyCompactSpace X] [SecondCountableTopology X] : SigmaCompactSpace X := by choose K hKc hxK using fun x : X => exists_compact_mem_nhds x rcases countable_cover_nhds hxK with ⟨s, hsc, hsU⟩ refine SigmaCompactSpace.of_countable _ (hsc.image K) (forall_mem_image.2 fun x _ => hKc x) ?_ rwa [sUnion_image] #align sigma_compact_space_of_locally_compact_second_countable sigmaCompactSpace_of_locally_compact_second_countable -- Porting note: doesn't work on the same line variable (X) variable [SigmaCompactSpace X] open SigmaCompactSpace /-- A choice of compact covering for a `σ`-compact space, chosen to be monotone. -/ def compactCovering : ℕ → Set X := Accumulate exists_compact_covering.choose #align compact_covering compactCovering theorem isCompact_compactCovering (n : ℕ) : IsCompact (compactCovering X n) := isCompact_accumulate (Classical.choose_spec SigmaCompactSpace.exists_compact_covering).1 n #align is_compact_compact_covering isCompact_compactCovering theorem iUnion_compactCovering : ⋃ n, compactCovering X n = univ := by rw [compactCovering, iUnion_accumulate] exact (Classical.choose_spec SigmaCompactSpace.exists_compact_covering).2 #align Union_compact_covering iUnion_compactCovering @[mono] theorem compactCovering_subset ⦃m n : ℕ⦄ (h : m ≤ n) : compactCovering X m ⊆ compactCovering X n := monotone_accumulate h #align compact_covering_subset compactCovering_subset variable {X} theorem exists_mem_compactCovering (x : X) : ∃ n, x ∈ compactCovering X n := iUnion_eq_univ_iff.mp (iUnion_compactCovering X) x #align exists_mem_compact_covering exists_mem_compactCovering instance [SigmaCompactSpace Y] : SigmaCompactSpace (X × Y) := ⟨⟨fun n => compactCovering X n ×ˢ compactCovering Y n, fun _ => (isCompact_compactCovering _ _).prod (isCompact_compactCovering _ _), by simp only [iUnion_prod_of_monotone (compactCovering_subset X) (compactCovering_subset Y), iUnion_compactCovering, univ_prod_univ]⟩⟩ instance [Finite ι] {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, SigmaCompactSpace (X i)] : SigmaCompactSpace (∀ i, X i) := by refine ⟨⟨fun n => Set.pi univ fun i => compactCovering (X i) n, fun n => isCompact_univ_pi fun i => isCompact_compactCovering (X i) _, ?_⟩⟩ rw [iUnion_univ_pi_of_monotone] · simp only [iUnion_compactCovering, pi_univ] · exact fun i => compactCovering_subset (X i) instance [SigmaCompactSpace Y] : SigmaCompactSpace (Sum X Y) := ⟨⟨fun n => Sum.inl '' compactCovering X n ∪ Sum.inr '' compactCovering Y n, fun n => ((isCompact_compactCovering X n).image continuous_inl).union ((isCompact_compactCovering Y n).image continuous_inr), by simp only [iUnion_union_distrib, ← image_iUnion, iUnion_compactCovering, image_univ, range_inl_union_range_inr]⟩⟩ instance [Countable ι] {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, SigmaCompactSpace (X i)] : SigmaCompactSpace (Σi, X i) := by cases isEmpty_or_nonempty ι · infer_instance · rcases exists_surjective_nat ι with ⟨f, hf⟩ refine ⟨⟨fun n => ⋃ k ≤ n, Sigma.mk (f k) '' compactCovering (X (f k)) n, fun n => ?_, ?_⟩⟩ · refine (finite_le_nat _).isCompact_biUnion fun k _ => ?_ exact (isCompact_compactCovering _ _).image continuous_sigmaMk · simp only [iUnion_eq_univ_iff, Sigma.forall, mem_iUnion, hf.forall] intro k y rcases exists_mem_compactCovering y with ⟨n, hn⟩ refine ⟨max k n, k, le_max_left _ _, mem_image_of_mem _ ?_⟩ exact compactCovering_subset _ (le_max_right _ _) hn protected theorem ClosedEmbedding.sigmaCompactSpace {e : Y → X} (he : ClosedEmbedding e) : SigmaCompactSpace Y := ⟨⟨fun n => e ⁻¹' compactCovering X n, fun n => he.isCompact_preimage (isCompact_compactCovering _ _), by rw [← preimage_iUnion, iUnion_compactCovering, preimage_univ]⟩⟩ #align closed_embedding.sigma_compact_space ClosedEmbedding.sigmaCompactSpace -- Porting note (#10756): new lemma theorem IsClosed.sigmaCompactSpace {s : Set X} (hs : IsClosed s) : SigmaCompactSpace s := (closedEmbedding_subtype_val hs).sigmaCompactSpace instance [SigmaCompactSpace Y] : SigmaCompactSpace (ULift.{u} Y) := ULift.closedEmbedding_down.sigmaCompactSpace /-- If `X` is a `σ`-compact space, then a locally finite family of nonempty sets of `X` can have only countably many elements, `Set.Countable` version. -/ protected theorem LocallyFinite.countable_univ {f : ι → Set X} (hf : LocallyFinite f) (hne : ∀ i, (f i).Nonempty) : (univ : Set ι).Countable := by have := fun n => hf.finite_nonempty_inter_compact (isCompact_compactCovering X n) refine (countable_iUnion fun n => (this n).countable).mono fun i _ => ?_ rcases hne i with ⟨x, hx⟩ rcases iUnion_eq_univ_iff.1 (iUnion_compactCovering X) x with ⟨n, hn⟩ exact mem_iUnion.2 ⟨n, x, hx, hn⟩ #align locally_finite.countable_univ LocallyFinite.countable_univ /-- If `f : ι → Set X` is a locally finite covering of a σ-compact topological space by nonempty sets, then the index type `ι` is encodable. -/ protected noncomputable def LocallyFinite.encodable {ι : Type*} {f : ι → Set X} (hf : LocallyFinite f) (hne : ∀ i, (f i).Nonempty) : Encodable ι := @Encodable.ofEquiv _ _ (hf.countable_univ hne).toEncodable (Equiv.Set.univ _).symm #align locally_finite.encodable LocallyFinite.encodable /-- In a topological space with sigma compact topology, if `f` is a function that sends each point `x` of a closed set `s` to a neighborhood of `x` within `s`, then for some countable set `t ⊆ s`, the neighborhoods `f x`, `x ∈ t`, cover the whole set `s`. -/ theorem countable_cover_nhdsWithin_of_sigma_compact {f : X → Set X} {s : Set X} (hs : IsClosed s) (hf : ∀ x ∈ s, f x ∈ 𝓝[s] x) : ∃ t ⊆ s, t.Countable ∧ s ⊆ ⋃ x ∈ t, f x := by simp only [nhdsWithin, mem_inf_principal] at hf choose t ht hsub using fun n => ((isCompact_compactCovering X n).inter_right hs).elim_nhds_subcover _ fun x hx => hf x hx.right refine ⟨⋃ n, (t n : Set X), iUnion_subset fun n x hx => (ht n x hx).2, countable_iUnion fun n => (t n).countable_toSet, fun x hx => mem_iUnion₂.2 ?_⟩ rcases exists_mem_compactCovering x with ⟨n, hn⟩ rcases mem_iUnion₂.1 (hsub n ⟨hn, hx⟩) with ⟨y, hyt : y ∈ t n, hyf : x ∈ s → x ∈ f y⟩ exact ⟨y, mem_iUnion.2 ⟨n, hyt⟩, hyf hx⟩ #align countable_cover_nhds_within_of_sigma_compact countable_cover_nhdsWithin_of_sigma_compact /-- In a topological space with sigma compact topology, if `f` is a function that sends each point `x` to a neighborhood of `x`, then for some countable set `s`, the neighborhoods `f x`, `x ∈ s`, cover the whole space. -/ theorem countable_cover_nhds_of_sigma_compact {f : X → Set X} (hf : ∀ x, f x ∈ 𝓝 x) : ∃ s : Set X, s.Countable ∧ ⋃ x ∈ s, f x = univ := by simp only [← nhdsWithin_univ] at hf rcases countable_cover_nhdsWithin_of_sigma_compact isClosed_univ fun x _ => hf x with ⟨s, -, hsc, hsU⟩ exact ⟨s, hsc, univ_subset_iff.1 hsU⟩ #align countable_cover_nhds_of_sigma_compact countable_cover_nhds_of_sigma_compact /-- An [exhaustion by compact sets](https://en.wikipedia.org/wiki/Exhaustion_by_compact_sets) of a topological space is a sequence of compact sets `K n` such that `K n ⊆ interior (K (n + 1))` and `⋃ n, K n = univ`. If `X` is a locally compact sigma compact space, then `CompactExhaustion.choice X` provides a choice of an exhaustion by compact sets. This choice is also available as `(default : CompactExhaustion X)`. -/ structure CompactExhaustion (X : Type*) [TopologicalSpace X] where /-- The sequence of compact sets that form a compact exhaustion. -/ toFun : ℕ → Set X /-- The sets in the compact exhaustion are in fact compact. -/ isCompact' : ∀ n, IsCompact (toFun n) /-- The sets in the compact exhaustion form a sequence: each set is contained in the interior of the next. -/ subset_interior_succ' : ∀ n, toFun n ⊆ interior (toFun (n + 1)) /-- The union of all sets in a compact exhaustion equals the entire space. -/ iUnion_eq' : ⋃ n, toFun n = univ #align compact_exhaustion CompactExhaustion namespace CompactExhaustion instance : FunLike (CompactExhaustion X) ℕ (Set X) where coe := toFun coe_injective' | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl instance : RelHomClass (CompactExhaustion X) LE.le HasSubset.Subset where map_rel f _ _ h := monotone_nat_of_le_succ (fun n ↦ (f.subset_interior_succ' n).trans interior_subset) h variable (K : CompactExhaustion X) @[simp] theorem toFun_eq_coe : K.toFun = K := rfl protected theorem isCompact (n : ℕ) : IsCompact (K n) := K.isCompact' n #align compact_exhaustion.is_compact CompactExhaustion.isCompact theorem subset_interior_succ (n : ℕ) : K n ⊆ interior (K (n + 1)) := K.subset_interior_succ' n #align compact_exhaustion.subset_interior_succ CompactExhaustion.subset_interior_succ @[mono] protected theorem subset ⦃m n : ℕ⦄ (h : m ≤ n) : K m ⊆ K n := OrderHomClass.mono K h #align compact_exhaustion.subset CompactExhaustion.subset theorem subset_succ (n : ℕ) : K n ⊆ K (n + 1) := K.subset n.le_succ #align compact_exhaustion.subset_succ CompactExhaustion.subset_succ theorem subset_interior ⦃m n : ℕ⦄ (h : m < n) : K m ⊆ interior (K n) := Subset.trans (K.subset_interior_succ m) <| interior_mono <| K.subset h #align compact_exhaustion.subset_interior CompactExhaustion.subset_interior theorem iUnion_eq : ⋃ n, K n = univ := K.iUnion_eq' #align compact_exhaustion.Union_eq CompactExhaustion.iUnion_eq theorem exists_mem (x : X) : ∃ n, x ∈ K n := iUnion_eq_univ_iff.1 K.iUnion_eq x #align compact_exhaustion.exists_mem CompactExhaustion.exists_mem /-- A compact exhaustion eventually covers any compact set. -/
Mathlib/Topology/Compactness/SigmaCompact.lean
381
387
theorem exists_superset_of_isCompact {s : Set X} (hs : IsCompact s) : ∃ n, s ⊆ K n := by
suffices ∃ n, s ⊆ interior (K n) from this.imp fun _ ↦ (Subset.trans · interior_subset) refine hs.elim_directed_cover (interior ∘ K) (fun _ ↦ isOpen_interior) ?_ ?_ · intro x _ rcases K.exists_mem x with ⟨k, hk⟩ exact mem_iUnion.2 ⟨k + 1, K.subset_interior_succ _ hk⟩ · exact Monotone.directed_le fun _ _ h ↦ interior_mono <| K.subset h
/- Copyright (c) 2023 Bulhwi Cha. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bulhwi Cha, Mario Carneiro -/ import Batteries.Data.Char import Batteries.Data.List.Lemmas import Batteries.Data.String.Basic import Batteries.Tactic.Lint.Misc import Batteries.Tactic.SeqFocus namespace String attribute [ext] ext theorem lt_trans {s₁ s₂ s₃ : String} : s₁ < s₂ → s₂ < s₃ → s₁ < s₃ := List.lt_trans' (α := Char) Nat.lt_trans (fun h1 h2 => Nat.not_lt.2 <| Nat.le_trans (Nat.not_lt.1 h2) (Nat.not_lt.1 h1)) theorem lt_antisymm {s₁ s₂ : String} (h₁ : ¬s₁ < s₂) (h₂ : ¬s₂ < s₁) : s₁ = s₂ := ext <| List.lt_antisymm' (α := Char) (fun h1 h2 => Char.le_antisymm (Nat.not_lt.1 h2) (Nat.not_lt.1 h1)) h₁ h₂ instance : Batteries.TransOrd String := .compareOfLessAndEq String.lt_irrefl String.lt_trans String.lt_antisymm instance : Batteries.LTOrd String := .compareOfLessAndEq String.lt_irrefl String.lt_trans String.lt_antisymm instance : Batteries.BEqOrd String := .compareOfLessAndEq String.lt_irrefl @[simp] theorem mk_length (s : List Char) : (String.mk s).length = s.length := rfl attribute [simp] toList -- prefer `String.data` over `String.toList` in lemmas private theorem add_csize_pos : 0 < i + csize c := Nat.add_pos_right _ (csize_pos c) private theorem ne_add_csize_add_self : i ≠ n + csize c + i := Nat.ne_of_lt (Nat.lt_add_of_pos_left add_csize_pos) private theorem ne_self_add_add_csize : i ≠ i + (n + csize c) := Nat.ne_of_lt (Nat.lt_add_of_pos_right add_csize_pos) /-- The UTF-8 byte length of a list of characters. (This is intended for specification purposes.) -/ @[inline] def utf8Len : List Char → Nat := utf8ByteSize.go @[simp] theorem utf8ByteSize.go_eq : utf8ByteSize.go = utf8Len := rfl @[simp] theorem utf8ByteSize_mk (cs) : utf8ByteSize ⟨cs⟩ = utf8Len cs := rfl @[simp] theorem utf8Len_nil : utf8Len [] = 0 := rfl @[simp] theorem utf8Len_cons (c cs) : utf8Len (c :: cs) = utf8Len cs + csize c := rfl @[simp] theorem utf8Len_append (cs₁ cs₂) : utf8Len (cs₁ ++ cs₂) = utf8Len cs₁ + utf8Len cs₂ := by induction cs₁ <;> simp [*, Nat.add_right_comm] @[simp] theorem utf8Len_reverseAux (cs₁ cs₂) : utf8Len (cs₁.reverseAux cs₂) = utf8Len cs₁ + utf8Len cs₂ := by induction cs₁ generalizing cs₂ <;> simp [*, ← Nat.add_assoc, Nat.add_right_comm] @[simp] theorem utf8Len_reverse (cs) : utf8Len cs.reverse = utf8Len cs := utf8Len_reverseAux .. @[simp] theorem utf8Len_eq_zero : utf8Len l = 0 ↔ l = [] := by cases l <;> simp [Nat.ne_of_gt add_csize_pos] section open List theorem utf8Len_le_of_sublist : ∀ {cs₁ cs₂}, cs₁ <+ cs₂ → utf8Len cs₁ ≤ utf8Len cs₂ | _, _, .slnil => Nat.le_refl _ | _, _, .cons _ h => Nat.le_trans (utf8Len_le_of_sublist h) (Nat.le_add_right ..) | _, _, .cons₂ _ h => Nat.add_le_add_right (utf8Len_le_of_sublist h) _ theorem utf8Len_le_of_infix (h : cs₁ <:+: cs₂) : utf8Len cs₁ ≤ utf8Len cs₂ := utf8Len_le_of_sublist h.sublist theorem utf8Len_le_of_suffix (h : cs₁ <:+ cs₂) : utf8Len cs₁ ≤ utf8Len cs₂ := utf8Len_le_of_sublist h.sublist theorem utf8Len_le_of_prefix (h : cs₁ <+: cs₂) : utf8Len cs₁ ≤ utf8Len cs₂ := utf8Len_le_of_sublist h.sublist end @[simp] theorem endPos_eq (cs : List Char) : endPos ⟨cs⟩ = ⟨utf8Len cs⟩ := rfl namespace Pos attribute [ext] ext theorem lt_addChar (p : Pos) (c : Char) : p < p + c := Nat.lt_add_of_pos_right (csize_pos _) private theorem zero_ne_addChar {i : Pos} {c : Char} : 0 ≠ i + c := ne_of_lt add_csize_pos /-- A string position is valid if it is equal to the UTF-8 length of an initial substring of `s`. -/ def Valid (s : String) (p : Pos) : Prop := ∃ cs cs', cs ++ cs' = s.1 ∧ p.1 = utf8Len cs @[simp] theorem valid_zero : Valid s 0 := ⟨[], s.1, rfl, rfl⟩ @[simp] theorem valid_endPos : Valid s (endPos s) := ⟨s.1, [], by simp, rfl⟩ theorem Valid.mk (cs cs' : List Char) : Valid ⟨cs ++ cs'⟩ ⟨utf8Len cs⟩ := ⟨cs, cs', rfl, rfl⟩ theorem Valid.le_endPos : ∀ {s p}, Valid s p → p ≤ endPos s | ⟨_⟩, ⟨_⟩, ⟨cs, cs', rfl, rfl⟩ => by simp [Nat.le_add_right] end Pos theorem endPos_eq_zero : ∀ (s : String), endPos s = 0 ↔ s = "" | ⟨_⟩ => Pos.ext_iff.trans <| utf8Len_eq_zero.trans ext_iff.symm theorem isEmpty_iff (s : String) : isEmpty s ↔ s = "" := (beq_iff_eq ..).trans (endPos_eq_zero _) /-- Induction along the valid positions in a list of characters. (This definition is intended only for specification purposes.) -/ def utf8InductionOn {motive : List Char → Pos → Sort u} (s : List Char) (i p : Pos) (nil : ∀ i, motive [] i) (eq : ∀ c cs, motive (c :: cs) p) (ind : ∀ (c : Char) cs i, i ≠ p → motive cs (i + c) → motive (c :: cs) i) : motive s i := match s with | [] => nil i | c::cs => if h : i = p then h ▸ eq c cs else ind c cs i h (utf8InductionOn cs (i + c) p nil eq ind) theorem utf8GetAux_add_right_cancel (s : List Char) (i p n : Nat) : utf8GetAux s ⟨i + n⟩ ⟨p + n⟩ = utf8GetAux s ⟨i⟩ ⟨p⟩ := by apply utf8InductionOn s ⟨i⟩ ⟨p⟩ (motive := fun s i => utf8GetAux s ⟨i.byteIdx + n⟩ ⟨p + n⟩ = utf8GetAux s i ⟨p⟩) <;> simp [utf8GetAux] intro c cs ⟨i⟩ h ih simp [Pos.ext_iff, Pos.addChar_eq] at h ⊢ simp [Nat.add_right_cancel_iff, h] rw [Nat.add_right_comm] exact ih theorem utf8GetAux_addChar_right_cancel (s : List Char) (i p : Pos) (c : Char) : utf8GetAux s (i + c) (p + c) = utf8GetAux s i p := utf8GetAux_add_right_cancel .. theorem utf8GetAux_of_valid (cs cs' : List Char) {i p : Nat} (hp : i + utf8Len cs = p) : utf8GetAux (cs ++ cs') ⟨i⟩ ⟨p⟩ = cs'.headD default := by match cs, cs' with | [], [] => rfl | [], c::cs' => simp [← hp, utf8GetAux] | c::cs, cs' => simp [utf8GetAux, -List.headD_eq_head?]; rw [if_neg] case hnc => simp [← hp, Pos.ext_iff]; exact ne_self_add_add_csize refine utf8GetAux_of_valid cs cs' ?_ simpa [Nat.add_assoc, Nat.add_comm] using hp theorem get_of_valid (cs cs' : List Char) : get ⟨cs ++ cs'⟩ ⟨utf8Len cs⟩ = cs'.headD default := utf8GetAux_of_valid _ _ (Nat.zero_add _) theorem get_cons_addChar (c : Char) (cs : List Char) (i : Pos) : get ⟨c :: cs⟩ (i + c) = get ⟨cs⟩ i := by simp [get, utf8GetAux, Pos.zero_ne_addChar, utf8GetAux_addChar_right_cancel] theorem utf8GetAux?_of_valid (cs cs' : List Char) {i p : Nat} (hp : i + utf8Len cs = p) : utf8GetAux? (cs ++ cs') ⟨i⟩ ⟨p⟩ = cs'.head? := by match cs, cs' with | [], [] => rfl | [], c::cs' => simp [← hp, utf8GetAux?] | c::cs, cs' => simp [utf8GetAux?]; rw [if_neg] case hnc => simp [← hp, Pos.ext_iff]; exact ne_self_add_add_csize refine utf8GetAux?_of_valid cs cs' ?_ simpa [Nat.add_assoc, Nat.add_comm] using hp theorem get?_of_valid (cs cs' : List Char) : get? ⟨cs ++ cs'⟩ ⟨utf8Len cs⟩ = cs'.head? := utf8GetAux?_of_valid _ _ (Nat.zero_add _) theorem utf8SetAux_of_valid (c' : Char) (cs cs' : List Char) {i p : Nat} (hp : i + utf8Len cs = p) : utf8SetAux c' (cs ++ cs') ⟨i⟩ ⟨p⟩ = cs ++ cs'.modifyHead fun _ => c' := by match cs, cs' with | [], [] => rfl | [], c::cs' => simp [← hp, utf8SetAux] | c::cs, cs' => simp [utf8SetAux]; rw [if_neg] case hnc => simp [← hp, Pos.ext_iff]; exact ne_self_add_add_csize refine congrArg (c::·) (utf8SetAux_of_valid c' cs cs' ?_) simpa [Nat.add_assoc, Nat.add_comm] using hp theorem set_of_valid (cs cs' : List Char) (c' : Char) : set ⟨cs ++ cs'⟩ ⟨utf8Len cs⟩ c' = ⟨cs ++ cs'.modifyHead fun _ => c'⟩ := ext (utf8SetAux_of_valid _ _ _ (Nat.zero_add _)) theorem modify_of_valid (cs cs' : List Char) : modify ⟨cs ++ cs'⟩ ⟨utf8Len cs⟩ f = ⟨cs ++ cs'.modifyHead f⟩ := by rw [modify, set_of_valid, get_of_valid]; cases cs' <;> rfl theorem next_of_valid' (cs cs' : List Char) : next ⟨cs ++ cs'⟩ ⟨utf8Len cs⟩ = ⟨utf8Len cs + csize (cs'.headD default)⟩ := by simp only [next, get_of_valid]; rfl theorem next_of_valid (cs : List Char) (c : Char) (cs' : List Char) : next ⟨cs ++ c :: cs'⟩ ⟨utf8Len cs⟩ = ⟨utf8Len cs + csize c⟩ := next_of_valid' .. @[simp] theorem atEnd_iff (s : String) (p : Pos) : atEnd s p ↔ s.endPos ≤ p := decide_eq_true_iff _
.lake/packages/batteries/Batteries/Data/String/Lemmas.lean
209
214
theorem valid_next {p : Pos} (h : p.Valid s) (h₂ : p < s.endPos) : (next s p).Valid s := by
match s, p, h with | ⟨_⟩, ⟨_⟩, ⟨cs, [], rfl, rfl⟩ => simp at h₂ | ⟨_⟩, ⟨_⟩, ⟨cs, c::cs', rfl, rfl⟩ => rw [utf8ByteSize.go_eq, next_of_valid] simpa using Pos.Valid.mk (cs ++ [c]) cs'
/- Copyright (c) 2021 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Riccardo Brasca -/ import Mathlib.Analysis.NormedSpace.Basic import Mathlib.Analysis.Normed.Group.Hom import Mathlib.Data.Real.Sqrt import Mathlib.RingTheory.Ideal.QuotientOperations import Mathlib.Topology.MetricSpace.HausdorffDistance #align_import analysis.normed.group.quotient from "leanprover-community/mathlib"@"2196ab363eb097c008d4497125e0dde23fb36db2" /-! # Quotients of seminormed groups For any `SeminormedAddCommGroup M` and any `S : AddSubgroup M`, we provide a `SeminormedAddCommGroup`, the group quotient `M ⧸ S`. If `S` is closed, we provide `NormedAddCommGroup (M ⧸ S)` (regardless of whether `M` itself is separated). The two main properties of these structures are the underlying topology is the quotient topology and the projection is a normed group homomorphism which is norm non-increasing (better, it has operator norm exactly one unless `S` is dense in `M`). The corresponding universal property is that every normed group hom defined on `M` which vanishes on `S` descends to a normed group hom defined on `M ⧸ S`. This file also introduces a predicate `IsQuotient` characterizing normed group homs that are isomorphic to the canonical projection onto a normed group quotient. In addition, this file also provides normed structures for quotients of modules by submodules, and of (commutative) rings by ideals. The `SeminormedAddCommGroup` and `NormedAddCommGroup` instances described above are transferred directly, but we also define instances of `NormedSpace`, `SeminormedCommRing`, `NormedCommRing` and `NormedAlgebra` under appropriate type class assumptions on the original space. Moreover, while `QuotientAddGroup.completeSpace` works out-of-the-box for quotients of `NormedAddCommGroup`s by `AddSubgroup`s, we need to transfer this instance in `Submodule.Quotient.completeSpace` so that it applies to these other quotients. ## Main definitions We use `M` and `N` to denote seminormed groups and `S : AddSubgroup M`. All the following definitions are in the `AddSubgroup` namespace. Hence we can access `AddSubgroup.normedMk S` as `S.normedMk`. * `seminormedAddCommGroupQuotient` : The seminormed group structure on the quotient by an additive subgroup. This is an instance so there is no need to explicitly use it. * `normedAddCommGroupQuotient` : The normed group structure on the quotient by a closed additive subgroup. This is an instance so there is no need to explicitly use it. * `normedMk S` : the normed group hom from `M` to `M ⧸ S`. * `lift S f hf`: implements the universal property of `M ⧸ S`. Here `(f : NormedAddGroupHom M N)`, `(hf : ∀ s ∈ S, f s = 0)` and `lift S f hf : NormedAddGroupHom (M ⧸ S) N`. * `IsQuotient`: given `f : NormedAddGroupHom M N`, `IsQuotient f` means `N` is isomorphic to a quotient of `M` by a subgroup, with projection `f`. Technically it asserts `f` is surjective and the norm of `f x` is the infimum of the norms of `x + m` for `m` in `f.ker`. ## Main results * `norm_normedMk` : the operator norm of the projection is `1` if the subspace is not dense. * `IsQuotient.norm_lift`: Provided `f : normed_hom M N` satisfies `IsQuotient f`, for every `n : N` and positive `ε`, there exists `m` such that `f m = n ∧ ‖m‖ < ‖n‖ + ε`. ## Implementation details For any `SeminormedAddCommGroup M` and any `S : AddSubgroup M` we define a norm on `M ⧸ S` by `‖x‖ = sInf (norm '' {m | mk' S m = x})`. This formula is really an implementation detail, it shouldn't be needed outside of this file setting up the theory. Since `M ⧸ S` is automatically a topological space (as any quotient of a topological space), one needs to be careful while defining the `SeminormedAddCommGroup` instance to avoid having two different topologies on this quotient. This is not purely a technological issue. Mathematically there is something to prove. The main point is proved in the auxiliary lemma `quotient_nhd_basis` that has no use beyond this verification and states that zero in the quotient admits as basis of neighborhoods in the quotient topology the sets `{x | ‖x‖ < ε}` for positive `ε`. Once this mathematical point is settled, we have two topologies that are propositionally equal. This is not good enough for the type class system. As usual we ensure *definitional* equality using forgetful inheritance, see Note [forgetful inheritance]. A (semi)-normed group structure includes a uniform space structure which includes a topological space structure, together with propositional fields asserting compatibility conditions. The usual way to define a `SeminormedAddCommGroup` is to let Lean build a uniform space structure using the provided norm, and then trivially build a proof that the norm and uniform structure are compatible. Here the uniform structure is provided using `TopologicalAddGroup.toUniformSpace` which uses the topological structure and the group structure to build the uniform structure. This uniform structure induces the correct topological structure by construction, but the fact that it is compatible with the norm is not obvious; this is where the mathematical content explained in the previous paragraph kicks in. -/ noncomputable section open QuotientAddGroup Metric Set Topology NNReal variable {M N : Type*} [SeminormedAddCommGroup M] [SeminormedAddCommGroup N] /-- The definition of the norm on the quotient by an additive subgroup. -/ noncomputable instance normOnQuotient (S : AddSubgroup M) : Norm (M ⧸ S) where norm x := sInf (norm '' { m | mk' S m = x }) #align norm_on_quotient normOnQuotient theorem AddSubgroup.quotient_norm_eq {S : AddSubgroup M} (x : M ⧸ S) : ‖x‖ = sInf (norm '' { m : M | (m : M ⧸ S) = x }) := rfl #align add_subgroup.quotient_norm_eq AddSubgroup.quotient_norm_eq theorem QuotientAddGroup.norm_eq_infDist {S : AddSubgroup M} (x : M ⧸ S) : ‖x‖ = infDist 0 { m : M | (m : M ⧸ S) = x } := by simp only [AddSubgroup.quotient_norm_eq, infDist_eq_iInf, sInf_image', dist_zero_left] /-- An alternative definition of the norm on the quotient group: the norm of `((x : M) : M ⧸ S)` is equal to the distance from `x` to `S`. -/ theorem QuotientAddGroup.norm_mk {S : AddSubgroup M} (x : M) : ‖(x : M ⧸ S)‖ = infDist x S := by rw [norm_eq_infDist, ← infDist_image (IsometryEquiv.subLeft x).isometry, IsometryEquiv.subLeft_apply, sub_zero, ← IsometryEquiv.preimage_symm] congr 1 with y simp only [mem_preimage, IsometryEquiv.subLeft_symm_apply, mem_setOf_eq, QuotientAddGroup.eq, neg_add, neg_neg, neg_add_cancel_right, SetLike.mem_coe] theorem image_norm_nonempty {S : AddSubgroup M} (x : M ⧸ S) : (norm '' { m | mk' S m = x }).Nonempty := .image _ <| Quot.exists_rep x #align image_norm_nonempty image_norm_nonempty theorem bddBelow_image_norm (s : Set M) : BddBelow (norm '' s) := ⟨0, forall_mem_image.2 fun _ _ ↦ norm_nonneg _⟩ #align bdd_below_image_norm bddBelow_image_norm theorem isGLB_quotient_norm {S : AddSubgroup M} (x : M ⧸ S) : IsGLB (norm '' { m | mk' S m = x }) (‖x‖) := isGLB_csInf (image_norm_nonempty x) (bddBelow_image_norm _) /-- The norm on the quotient satisfies `‖-x‖ = ‖x‖`. -/ theorem quotient_norm_neg {S : AddSubgroup M} (x : M ⧸ S) : ‖-x‖ = ‖x‖ := by simp only [AddSubgroup.quotient_norm_eq] congr 1 with r constructor <;> { rintro ⟨m, hm, rfl⟩; use -m; simpa [neg_eq_iff_eq_neg] using hm } #align quotient_norm_neg quotient_norm_neg theorem quotient_norm_sub_rev {S : AddSubgroup M} (x y : M ⧸ S) : ‖x - y‖ = ‖y - x‖ := by rw [← neg_sub, quotient_norm_neg] #align quotient_norm_sub_rev quotient_norm_sub_rev /-- The norm of the projection is smaller or equal to the norm of the original element. -/ theorem quotient_norm_mk_le (S : AddSubgroup M) (m : M) : ‖mk' S m‖ ≤ ‖m‖ := csInf_le (bddBelow_image_norm _) <| Set.mem_image_of_mem _ rfl #align quotient_norm_mk_le quotient_norm_mk_le /-- The norm of the projection is smaller or equal to the norm of the original element. -/ theorem quotient_norm_mk_le' (S : AddSubgroup M) (m : M) : ‖(m : M ⧸ S)‖ ≤ ‖m‖ := quotient_norm_mk_le S m #align quotient_norm_mk_le' quotient_norm_mk_le' /-- The norm of the image under the natural morphism to the quotient. -/
Mathlib/Analysis/Normed/Group/Quotient.lean
162
166
theorem quotient_norm_mk_eq (S : AddSubgroup M) (m : M) : ‖mk' S m‖ = sInf ((‖m + ·‖) '' S) := by
rw [mk'_apply, norm_mk, sInf_image', ← infDist_image isometry_neg, image_neg, neg_coe_set (H := S), infDist_eq_iInf] simp only [dist_eq_norm', sub_neg_eq_add, add_comm]
/- 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
Mathlib/Data/Set/Prod.lean
511
512
theorem diagonal_eq_univ_iff : diagonal α = univ ↔ Subsingleton α := by
simp only [subsingleton_iff, eq_univ_iff_forall, Prod.forall, mem_diagonal_iff]
/- Copyright (c) 2020 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Jalex Stark -/ import Mathlib.Algebra.Polynomial.Monic #align_import algebra.polynomial.big_operators from "leanprover-community/mathlib"@"47adfab39a11a072db552f47594bf8ed2cf8a722" /-! # Lemmas for the interaction between polynomials and `∑` and `∏`. Recall that `∑` and `∏` are notation for `Finset.sum` and `Finset.prod` respectively. ## Main results - `Polynomial.natDegree_prod_of_monic` : the degree of a product of monic polynomials is the product of degrees. We prove this only for `[CommSemiring R]`, but it ought to be true for `[Semiring R]` and `List.prod`. - `Polynomial.natDegree_prod` : for polynomials over an integral domain, the degree of the product is the sum of degrees. - `Polynomial.leadingCoeff_prod` : for polynomials over an integral domain, the leading coefficient is the product of leading coefficients. - `Polynomial.prod_X_sub_C_coeff_card_pred` carries most of the content for computing the second coefficient of the characteristic polynomial. -/ open Finset open Multiset open Polynomial universe u w variable {R : Type u} {ι : Type w} namespace Polynomial variable (s : Finset ι) section Semiring variable {S : Type*} [Semiring S] set_option backward.isDefEq.lazyProjDelta false in -- See https://github.com/leanprover-community/mathlib4/issues/12535 theorem natDegree_list_sum_le (l : List S[X]) : natDegree l.sum ≤ (l.map natDegree).foldr max 0 := List.sum_le_foldr_max natDegree (by simp) natDegree_add_le _ #align polynomial.nat_degree_list_sum_le Polynomial.natDegree_list_sum_le theorem natDegree_multiset_sum_le (l : Multiset S[X]) : natDegree l.sum ≤ (l.map natDegree).foldr max max_left_comm 0 := Quotient.inductionOn l (by simpa using natDegree_list_sum_le) #align polynomial.nat_degree_multiset_sum_le Polynomial.natDegree_multiset_sum_le theorem natDegree_sum_le (f : ι → S[X]) : natDegree (∑ i ∈ s, f i) ≤ s.fold max 0 (natDegree ∘ f) := by simpa using natDegree_multiset_sum_le (s.val.map f) #align polynomial.nat_degree_sum_le Polynomial.natDegree_sum_le lemma natDegree_sum_le_of_forall_le {n : ℕ} (f : ι → S[X]) (h : ∀ i ∈ s, natDegree (f i) ≤ n) : natDegree (∑ i ∈ s, f i) ≤ n := le_trans (natDegree_sum_le s f) <| (Finset.fold_max_le n).mpr <| by simpa theorem degree_list_sum_le (l : List S[X]) : degree l.sum ≤ (l.map natDegree).maximum := by by_cases h : l.sum = 0 · simp [h] · rw [degree_eq_natDegree h] suffices (l.map natDegree).maximum = ((l.map natDegree).foldr max 0 : ℕ) by rw [this] simpa using natDegree_list_sum_le l rw [← List.foldr_max_of_ne_nil] · congr contrapose! h rw [List.map_eq_nil] at h simp [h] #align polynomial.degree_list_sum_le Polynomial.degree_list_sum_le theorem natDegree_list_prod_le (l : List S[X]) : natDegree l.prod ≤ (l.map natDegree).sum := by induction' l with hd tl IH · simp · simpa using natDegree_mul_le.trans (add_le_add_left IH _) #align polynomial.nat_degree_list_prod_le Polynomial.natDegree_list_prod_le theorem degree_list_prod_le (l : List S[X]) : degree l.prod ≤ (l.map degree).sum := by induction' l with hd tl IH · simp · simpa using (degree_mul_le _ _).trans (add_le_add_left IH _) #align polynomial.degree_list_prod_le Polynomial.degree_list_prod_le theorem coeff_list_prod_of_natDegree_le (l : List S[X]) (n : ℕ) (hl : ∀ p ∈ l, natDegree p ≤ n) : coeff (List.prod l) (l.length * n) = (l.map fun p => coeff p n).prod := by induction' l with hd tl IH · simp · have hl' : ∀ p ∈ tl, natDegree p ≤ n := fun p hp => hl p (List.mem_cons_of_mem _ hp) simp only [List.prod_cons, List.map, List.length] rw [add_mul, one_mul, add_comm, ← IH hl', mul_comm tl.length] have h : natDegree tl.prod ≤ n * tl.length := by refine (natDegree_list_prod_le _).trans ?_ rw [← tl.length_map natDegree, mul_comm] refine List.sum_le_card_nsmul _ _ ?_ simpa using hl' have hdn : natDegree hd ≤ n := hl _ (List.mem_cons_self _ _) rcases hdn.eq_or_lt with (rfl | hdn') · rcases h.eq_or_lt with h' | h' · rw [← h', coeff_mul_degree_add_degree, leadingCoeff, leadingCoeff] · rw [coeff_eq_zero_of_natDegree_lt, coeff_eq_zero_of_natDegree_lt h', mul_zero] exact natDegree_mul_le.trans_lt (add_lt_add_left h' _) · rw [coeff_eq_zero_of_natDegree_lt hdn', coeff_eq_zero_of_natDegree_lt, zero_mul] exact natDegree_mul_le.trans_lt (add_lt_add_of_lt_of_le hdn' h) #align polynomial.coeff_list_prod_of_nat_degree_le Polynomial.coeff_list_prod_of_natDegree_le end Semiring section CommSemiring variable [CommSemiring R] (f : ι → R[X]) (t : Multiset R[X]) theorem natDegree_multiset_prod_le : t.prod.natDegree ≤ (t.map natDegree).sum := Quotient.inductionOn t (by simpa using natDegree_list_prod_le) #align polynomial.nat_degree_multiset_prod_le Polynomial.natDegree_multiset_prod_le theorem natDegree_prod_le : (∏ i ∈ s, f i).natDegree ≤ ∑ i ∈ s, (f i).natDegree := by simpa using natDegree_multiset_prod_le (s.1.map f) #align polynomial.nat_degree_prod_le Polynomial.natDegree_prod_le /-- The degree of a product of polynomials is at most the sum of the degrees, where the degree of the zero polynomial is ⊥. -/ theorem degree_multiset_prod_le : t.prod.degree ≤ (t.map Polynomial.degree).sum := Quotient.inductionOn t (by simpa using degree_list_prod_le) #align polynomial.degree_multiset_prod_le Polynomial.degree_multiset_prod_le theorem degree_prod_le : (∏ i ∈ s, f i).degree ≤ ∑ i ∈ s, (f i).degree := by simpa only [Multiset.map_map] using degree_multiset_prod_le (s.1.map f) #align polynomial.degree_prod_le Polynomial.degree_prod_le /-- The leading coefficient of a product of polynomials is equal to the product of the leading coefficients, provided that this product is nonzero. See `Polynomial.leadingCoeff_multiset_prod` (without the `'`) for a version for integral domains, where this condition is automatically satisfied. -/ theorem leadingCoeff_multiset_prod' (h : (t.map leadingCoeff).prod ≠ 0) : t.prod.leadingCoeff = (t.map leadingCoeff).prod := by induction' t using Multiset.induction_on with a t ih; · simp simp only [Multiset.map_cons, Multiset.prod_cons] at h ⊢ rw [Polynomial.leadingCoeff_mul'] · rw [ih] simp only [ne_eq] apply right_ne_zero_of_mul h · rw [ih] · exact h simp only [ne_eq, not_false_eq_true] apply right_ne_zero_of_mul h #align polynomial.leading_coeff_multiset_prod' Polynomial.leadingCoeff_multiset_prod' /-- The leading coefficient of a product of polynomials is equal to the product of the leading coefficients, provided that this product is nonzero. See `Polynomial.leadingCoeff_prod` (without the `'`) for a version for integral domains, where this condition is automatically satisfied. -/ theorem leadingCoeff_prod' (h : (∏ i ∈ s, (f i).leadingCoeff) ≠ 0) : (∏ i ∈ s, f i).leadingCoeff = ∏ i ∈ s, (f i).leadingCoeff := by simpa using leadingCoeff_multiset_prod' (s.1.map f) (by simpa using h) #align polynomial.leading_coeff_prod' Polynomial.leadingCoeff_prod' /-- The degree of a product of polynomials is equal to the sum of the degrees, provided that the product of leading coefficients is nonzero. See `Polynomial.natDegree_multiset_prod` (without the `'`) for a version for integral domains, where this condition is automatically satisfied. -/ theorem natDegree_multiset_prod' (h : (t.map fun f => leadingCoeff f).prod ≠ 0) : t.prod.natDegree = (t.map fun f => natDegree f).sum := by revert h refine Multiset.induction_on t ?_ fun a t ih ht => ?_; · simp rw [Multiset.map_cons, Multiset.prod_cons] at ht ⊢ rw [Multiset.sum_cons, Polynomial.natDegree_mul', ih] · apply right_ne_zero_of_mul ht · rwa [Polynomial.leadingCoeff_multiset_prod'] apply right_ne_zero_of_mul ht #align polynomial.nat_degree_multiset_prod' Polynomial.natDegree_multiset_prod' /-- The degree of a product of polynomials is equal to the sum of the degrees, provided that the product of leading coefficients is nonzero. See `Polynomial.natDegree_prod` (without the `'`) for a version for integral domains, where this condition is automatically satisfied. -/ theorem natDegree_prod' (h : (∏ i ∈ s, (f i).leadingCoeff) ≠ 0) : (∏ i ∈ s, f i).natDegree = ∑ i ∈ s, (f i).natDegree := by simpa using natDegree_multiset_prod' (s.1.map f) (by simpa using h) #align polynomial.nat_degree_prod' Polynomial.natDegree_prod' theorem natDegree_multiset_prod_of_monic (h : ∀ f ∈ t, Monic f) : t.prod.natDegree = (t.map natDegree).sum := by nontriviality R apply natDegree_multiset_prod' suffices (t.map fun f => leadingCoeff f).prod = 1 by rw [this] simp convert prod_replicate (Multiset.card t) (1 : R) · simp only [eq_replicate, Multiset.card_map, eq_self_iff_true, true_and_iff] rintro i hi obtain ⟨i, hi, rfl⟩ := Multiset.mem_map.mp hi apply h assumption · simp #align polynomial.nat_degree_multiset_prod_of_monic Polynomial.natDegree_multiset_prod_of_monic theorem natDegree_prod_of_monic (h : ∀ i ∈ s, (f i).Monic) : (∏ i ∈ s, f i).natDegree = ∑ i ∈ s, (f i).natDegree := by simpa using natDegree_multiset_prod_of_monic (s.1.map f) (by simpa using h) #align polynomial.nat_degree_prod_of_monic Polynomial.natDegree_prod_of_monic theorem coeff_multiset_prod_of_natDegree_le (n : ℕ) (hl : ∀ p ∈ t, natDegree p ≤ n) : coeff t.prod ((Multiset.card t) * n) = (t.map fun p => coeff p n).prod := by induction t using Quotient.inductionOn simpa using coeff_list_prod_of_natDegree_le _ _ hl #align polynomial.coeff_multiset_prod_of_nat_degree_le Polynomial.coeff_multiset_prod_of_natDegree_le theorem coeff_prod_of_natDegree_le (f : ι → R[X]) (n : ℕ) (h : ∀ p ∈ s, natDegree (f p) ≤ n) : coeff (∏ i ∈ s, f i) (s.card * n) = ∏ i ∈ s, coeff (f i) n := by cases' s with l hl convert coeff_multiset_prod_of_natDegree_le (l.map f) n ?_ · simp · simp · simpa using h #align polynomial.coeff_prod_of_nat_degree_le Polynomial.coeff_prod_of_natDegree_le theorem coeff_zero_multiset_prod : t.prod.coeff 0 = (t.map fun f => coeff f 0).prod := by refine Multiset.induction_on t ?_ fun a t ht => ?_; · simp rw [Multiset.prod_cons, Multiset.map_cons, Multiset.prod_cons, Polynomial.mul_coeff_zero, ht] #align polynomial.coeff_zero_multiset_prod Polynomial.coeff_zero_multiset_prod theorem coeff_zero_prod : (∏ i ∈ s, f i).coeff 0 = ∏ i ∈ s, (f i).coeff 0 := by simpa using coeff_zero_multiset_prod (s.1.map f) #align polynomial.coeff_zero_prod Polynomial.coeff_zero_prod end CommSemiring section CommRing variable [CommRing R] open Monic -- Eventually this can be generalized with Vieta's formulas -- plus the connection between roots and factorization. theorem multiset_prod_X_sub_C_nextCoeff (t : Multiset R) : nextCoeff (t.map fun x => X - C x).prod = -t.sum := by rw [nextCoeff_multiset_prod] · simp only [nextCoeff_X_sub_C] exact t.sum_hom (-AddMonoidHom.id R) · intros apply monic_X_sub_C set_option linter.uppercaseLean3 false in #align polynomial.multiset_prod_X_sub_C_next_coeff Polynomial.multiset_prod_X_sub_C_nextCoeff theorem prod_X_sub_C_nextCoeff {s : Finset ι} (f : ι → R) : nextCoeff (∏ i ∈ s, (X - C (f i))) = -∑ i ∈ s, f i := by simpa using multiset_prod_X_sub_C_nextCoeff (s.1.map f) set_option linter.uppercaseLean3 false in #align polynomial.prod_X_sub_C_next_coeff Polynomial.prod_X_sub_C_nextCoeff theorem multiset_prod_X_sub_C_coeff_card_pred (t : Multiset R) (ht : 0 < Multiset.card t) : (t.map fun x => X - C x).prod.coeff ((Multiset.card t) - 1) = -t.sum := by nontriviality R convert multiset_prod_X_sub_C_nextCoeff (by assumption) rw [nextCoeff, if_neg] swap · rw [natDegree_multiset_prod_of_monic] swap · simp only [Multiset.mem_map] rintro _ ⟨_, _, rfl⟩ apply monic_X_sub_C simp_rw [Multiset.sum_eq_zero_iff, Multiset.mem_map] obtain ⟨x, hx⟩ := card_pos_iff_exists_mem.mp ht exact fun h => one_ne_zero <| h 1 ⟨_, ⟨x, hx, rfl⟩, natDegree_X_sub_C _⟩ congr; rw [natDegree_multiset_prod_of_monic] <;> · simp [natDegree_X_sub_C, monic_X_sub_C] set_option linter.uppercaseLean3 false in #align polynomial.multiset_prod_X_sub_C_coeff_card_pred Polynomial.multiset_prod_X_sub_C_coeff_card_pred theorem prod_X_sub_C_coeff_card_pred (s : Finset ι) (f : ι → R) (hs : 0 < s.card) : (∏ i ∈ s, (X - C (f i))).coeff (s.card - 1) = -∑ i ∈ s, f i := by simpa using multiset_prod_X_sub_C_coeff_card_pred (s.1.map f) (by simpa using hs) set_option linter.uppercaseLean3 false in #align polynomial.prod_X_sub_C_coeff_card_pred Polynomial.prod_X_sub_C_coeff_card_pred end CommRing section NoZeroDivisors section Semiring variable [Semiring R] [NoZeroDivisors R] /-- The degree of a product of polynomials is equal to the sum of the degrees, where the degree of the zero polynomial is ⊥. `[Nontrivial R]` is needed, otherwise for `l = []` we have `⊥` in the LHS and `0` in the RHS. -/ theorem degree_list_prod [Nontrivial R] (l : List R[X]) : l.prod.degree = (l.map degree).sum := map_list_prod (@degreeMonoidHom R _ _ _) l #align polynomial.degree_list_prod Polynomial.degree_list_prod end Semiring section CommSemiring variable [CommSemiring R] [NoZeroDivisors R] (f : ι → R[X]) (t : Multiset R[X]) /-- The degree of a product of polynomials is equal to the sum of the degrees. See `Polynomial.natDegree_prod'` (with a `'`) for a version for commutative semirings, where additionally, the product of the leading coefficients must be nonzero. -/ theorem natDegree_prod (h : ∀ i ∈ s, f i ≠ 0) : (∏ i ∈ s, f i).natDegree = ∑ i ∈ s, (f i).natDegree := by nontriviality R apply natDegree_prod' rw [prod_ne_zero_iff] intro x hx; simp [h x hx] #align polynomial.nat_degree_prod Polynomial.natDegree_prod theorem natDegree_multiset_prod (h : (0 : R[X]) ∉ t) : natDegree t.prod = (t.map natDegree).sum := by nontriviality R rw [natDegree_multiset_prod'] simp_rw [Ne, Multiset.prod_eq_zero_iff, Multiset.mem_map, leadingCoeff_eq_zero] rintro ⟨_, h, rfl⟩ contradiction #align polynomial.nat_degree_multiset_prod Polynomial.natDegree_multiset_prod /-- The degree of a product of polynomials is equal to the sum of the degrees, where the degree of the zero polynomial is ⊥. -/ theorem degree_multiset_prod [Nontrivial R] : t.prod.degree = (t.map fun f => degree f).sum := map_multiset_prod (@degreeMonoidHom R _ _ _) _ #align polynomial.degree_multiset_prod Polynomial.degree_multiset_prod /-- The degree of a product of polynomials is equal to the sum of the degrees, where the degree of the zero polynomial is ⊥. -/ theorem degree_prod [Nontrivial R] : (∏ i ∈ s, f i).degree = ∑ i ∈ s, (f i).degree := map_prod (@degreeMonoidHom R _ _ _) _ _ #align polynomial.degree_prod Polynomial.degree_prod /-- The leading coefficient of a product of polynomials is equal to the product of the leading coefficients. See `Polynomial.leadingCoeff_multiset_prod'` (with a `'`) for a version for commutative semirings, where additionally, the product of the leading coefficients must be nonzero. -/
Mathlib/Algebra/Polynomial/BigOperators.lean
358
361
theorem leadingCoeff_multiset_prod : t.prod.leadingCoeff = (t.map fun f => leadingCoeff f).prod := by
rw [← leadingCoeffHom_apply, MonoidHom.map_multiset_prod] rfl
/- 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 -/
.lake/packages/batteries/Batteries/Data/List/Lemmas.lean
267
273
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]
/- 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.Data.Set.Subsingleton import Mathlib.Order.WithBot #align_import data.set.image from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29" /-! # Images and preimages of sets ## Main definitions * `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β. * `range f : Set β` : the image of `univ` under `f`. Also works for `{p : Prop} (f : p → α)` (unlike `image`) ## Notation * `f ⁻¹' t` for `Set.preimage f t` * `f '' s` for `Set.image f s` ## Tags set, sets, image, preimage, pre-image, range -/ universe u v open Function Set namespace Set variable {α β γ : Type*} {ι ι' : Sort*} /-! ### Inverse image -/ section Preimage variable {f : α → β} {g : β → γ} @[simp] theorem preimage_empty : f ⁻¹' ∅ = ∅ := rfl #align set.preimage_empty Set.preimage_empty theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by congr with x simp [h] #align set.preimage_congr Set.preimage_congr @[gcongr] theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx #align set.preimage_mono Set.preimage_mono @[simp, mfld_simps] theorem preimage_univ : f ⁻¹' univ = univ := rfl #align set.preimage_univ Set.preimage_univ theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ := subset_univ _ #align set.subset_preimage_univ Set.subset_preimage_univ @[simp, mfld_simps] theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t := rfl #align set.preimage_inter Set.preimage_inter @[simp] theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t := rfl #align set.preimage_union Set.preimage_union @[simp] theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ := rfl #align set.preimage_compl Set.preimage_compl @[simp] theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t := rfl #align set.preimage_diff Set.preimage_diff open scoped symmDiff in @[simp] lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) := rfl #align set.preimage_symm_diff Set.preimage_symmDiff @[simp] theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) : f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) := rfl #align set.preimage_ite Set.preimage_ite @[simp] theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } := rfl #align set.preimage_set_of_eq Set.preimage_setOf_eq @[simp] theorem preimage_id_eq : preimage (id : α → α) = id := rfl #align set.preimage_id_eq Set.preimage_id_eq @[mfld_simps] theorem preimage_id {s : Set α} : id ⁻¹' s = s := rfl #align set.preimage_id Set.preimage_id @[simp, mfld_simps] theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s := rfl #align set.preimage_id' Set.preimage_id' @[simp] theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ := eq_univ_of_forall fun _ => h #align set.preimage_const_of_mem Set.preimage_const_of_mem @[simp] theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ := eq_empty_of_subset_empty fun _ hx => h hx #align set.preimage_const_of_not_mem Set.preimage_const_of_not_mem theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] : (fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by split_ifs with hb exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb] #align set.preimage_const Set.preimage_const /-- If preimage of each singleton under `f : α → β` is either empty or the whole type, then `f` is a constant. -/ lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β} (hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf' · exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩ · have : ∀ x b, f x ≠ b := fun x b ↦ eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩ theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) := rfl #align set.preimage_comp Set.preimage_comp theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g := rfl #align set.preimage_comp_eq Set.preimage_comp_eq theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by induction' n with n ih; · simp rw [iterate_succ, iterate_succ', preimage_comp_eq, ih] #align set.preimage_iterate_eq Set.preimage_iterate_eq theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} : f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s := preimage_comp.symm #align set.preimage_preimage Set.preimage_preimage theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} : s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t := ⟨fun s_eq x h => by rw [s_eq] simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩ #align set.eq_preimage_subtype_val_iff Set.eq_preimage_subtype_val_iff theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) : s.Nonempty := let ⟨x, hx⟩ := hf ⟨f x, hx⟩ #align set.nonempty_of_nonempty_preimage Set.nonempty_of_nonempty_preimage @[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp #align set.preimage_singleton_true Set.preimage_singleton_true @[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp #align set.preimage_singleton_false Set.preimage_singleton_false theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v) (H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by ext ⟨x, x_in_s⟩ constructor · intro x_in_u x_in_v exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩ · intro hx exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx' #align set.preimage_subtype_coe_eq_compl Set.preimage_subtype_coe_eq_compl end Preimage /-! ### Image of a set under a function -/ section Image variable {f : α → β} {s t : Set α} -- Porting note: `Set.image` is already defined in `Init.Set` #align set.image Set.image @[deprecated mem_image (since := "2024-03-23")] theorem mem_image_iff_bex {f : α → β} {s : Set α} {y : β} : y ∈ f '' s ↔ ∃ (x : _) (_ : x ∈ s), f x = y := bex_def.symm #align set.mem_image_iff_bex Set.mem_image_iff_bex theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s := rfl #align set.image_eta Set.image_eta theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} : f a ∈ f '' s ↔ a ∈ s := ⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩ #align function.injective.mem_set_image Function.Injective.mem_set_image theorem forall_mem_image {f : α → β} {s : Set α} {p : β → Prop} : (∀ y ∈ f '' s, p y) ↔ ∀ ⦃x⦄, x ∈ s → p (f x) := by simp #align set.ball_image_iff Set.forall_mem_image theorem exists_mem_image {f : α → β} {s : Set α} {p : β → Prop} : (∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp #align set.bex_image_iff Set.exists_mem_image @[deprecated (since := "2024-02-21")] alias ball_image_iff := forall_mem_image @[deprecated (since := "2024-02-21")] alias bex_image_iff := exists_mem_image @[deprecated (since := "2024-02-21")] alias ⟨_, ball_image_of_ball⟩ := forall_mem_image #align set.ball_image_of_ball Set.ball_image_of_ball @[deprecated forall_mem_image (since := "2024-02-21")] theorem mem_image_elim {f : α → β} {s : Set α} {C : β → Prop} (h : ∀ x : α, x ∈ s → C (f x)) : ∀ {y : β}, y ∈ f '' s → C y := forall_mem_image.2 h _ #align set.mem_image_elim Set.mem_image_elim @[deprecated forall_mem_image (since := "2024-02-21")] theorem mem_image_elim_on {f : α → β} {s : Set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s) (h : ∀ x : α, x ∈ s → C (f x)) : C y := forall_mem_image.2 h _ h_y #align set.mem_image_elim_on Set.mem_image_elim_on -- Porting note: used to be `safe` @[congr] theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by ext x exact exists_congr fun a ↦ and_congr_right fun ha ↦ by rw [h a ha] #align set.image_congr Set.image_congr /-- A common special case of `image_congr` -/ theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s := image_congr fun x _ => h x #align set.image_congr' Set.image_congr' @[gcongr] lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha) theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) := by aesop #align set.image_comp Set.image_comp theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp /-- A variant of `image_comp`, useful for rewriting -/ theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s := (image_comp g f s).symm #align set.image_image Set.image_image theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ} (h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by simp_rw [image_image, h_comm] #align set.image_comm Set.image_comm theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β} (h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ => image_comm h #align function.semiconj.set_image Function.Semiconj.set_image theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) : Function.Commute (image f) (image g) := Function.Semiconj.set_image h #align function.commute.set_image Function.Commute.set_image /-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in terms of `≤`. -/ @[gcongr] theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by simp only [subset_def, mem_image] exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩ #align set.image_subset Set.image_subset /-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/ lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _ #align set.monotone_image Set.monotone_image theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t := ext fun x => ⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine ⟨_, ?_, rfl⟩ · exact mem_union_left t h · exact mem_union_right s h⟩ #align set.image_union Set.image_union @[simp] theorem image_empty (f : α → β) : f '' ∅ = ∅ := by ext simp #align set.image_empty Set.image_empty theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t := subset_inter (image_subset _ inter_subset_left) (image_subset _ inter_subset_right) #align set.image_inter_subset Set.image_inter_subset theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) : f '' (s ∩ t) = f '' s ∩ f '' t := (image_inter_subset _ _ _).antisymm fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦ have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*]) ⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩ #align set.image_inter_on Set.image_inter_on theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t := image_inter_on fun _ _ _ _ h => H h #align set.image_inter Set.image_inter theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ := eq_univ_of_forall <| by simpa [image] #align set.image_univ_of_surjective Set.image_univ_of_surjective @[simp] theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by ext simp [image, eq_comm] #align set.image_singleton Set.image_singleton @[simp] theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} := ext fun _ => ⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h => (eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩ #align set.nonempty.image_const Set.Nonempty.image_const @[simp, mfld_simps] theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by simp only [eq_empty_iff_forall_not_mem] exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩ #align set.image_eq_empty Set.image_eq_empty -- Porting note: `compl` is already defined in `Init.Set` theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) : HasCompl.compl ⁻¹' S = HasCompl.compl '' S := Set.ext fun x => ⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h => Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩ #align set.preimage_compl_eq_image_compl Set.preimage_compl_eq_image_compl theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) : t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by simp [← preimage_compl_eq_image_compl] #align set.mem_compl_image Set.mem_compl_image @[simp] theorem image_id_eq : image (id : α → α) = id := by ext; simp /-- A variant of `image_id` -/ @[simp] theorem image_id' (s : Set α) : (fun x => x) '' s = s := by ext simp #align set.image_id' Set.image_id' theorem image_id (s : Set α) : id '' s = s := by simp #align set.image_id Set.image_id lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by induction n with | zero => simp | succ n ih => rw [iterate_succ', iterate_succ', ← ih, image_comp_eq] theorem compl_compl_image [BooleanAlgebra α] (S : Set α) : HasCompl.compl '' (HasCompl.compl '' S) = S := by rw [← image_comp, compl_comp_compl, image_id] #align set.compl_compl_image Set.compl_compl_image theorem image_insert_eq {f : α → β} {a : α} {s : Set α} : f '' insert a s = insert (f a) (f '' s) := by ext simp [and_or_left, exists_or, eq_comm, or_comm, and_comm] #align set.image_insert_eq Set.image_insert_eq theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by simp only [image_insert_eq, image_singleton] #align set.image_pair Set.image_pair theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) : f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s) #align set.image_subset_preimage_of_inverse Set.image_subset_preimage_of_inverse theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) : f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩ #align set.preimage_subset_image_of_inverse Set.preimage_subset_image_of_inverse theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f) (h₂ : RightInverse g f) : image f = preimage g := funext fun s => Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s) #align set.image_eq_preimage_of_inverse Set.image_eq_preimage_of_inverse theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f) (h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by rw [image_eq_preimage_of_inverse h₁ h₂]; rfl #align set.mem_image_iff_of_inverse Set.mem_image_iff_of_inverse theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ := Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H] #align set.image_compl_subset Set.image_compl_subset theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ := compl_subset_iff_union.2 <| by rw [← image_union] simp [image_univ_of_surjective H] #align set.subset_image_compl Set.subset_image_compl theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ := Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2) #align set.image_compl_eq Set.image_compl_eq theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by rw [diff_subset_iff, ← image_union, union_diff_self] exact image_subset f subset_union_right #align set.subset_image_diff Set.subset_image_diff open scoped symmDiff in theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t := (union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans (superset_of_eq (image_union _ _ _)) #align set.subset_image_symm_diff Set.subset_image_symmDiff theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t := Subset.antisymm (Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf) (subset_image_diff f s t) #align set.image_diff Set.image_diff open scoped symmDiff in theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by simp_rw [Set.symmDiff_def, image_union, image_diff hf] #align set.image_symm_diff Set.image_symmDiff theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty | ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩ #align set.nonempty.image Set.Nonempty.image theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty | ⟨_, x, hx, _⟩ => ⟨x, hx⟩ #align set.nonempty.of_image Set.Nonempty.of_image @[simp] theorem image_nonempty {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty := ⟨Nonempty.of_image, fun h => h.image f⟩ #align set.nonempty_image_iff Set.image_nonempty @[deprecated (since := "2024-01-06")] alias nonempty_image_iff := image_nonempty theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) : (f ⁻¹' s).Nonempty := let ⟨y, hy⟩ := hs let ⟨x, hx⟩ := hf y ⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩ #align set.nonempty.preimage Set.Nonempty.preimage instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) := (Set.Nonempty.image f nonempty_of_nonempty_subtype).to_subtype /-- image and preimage are a Galois connection -/ @[simp] theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t := forall_mem_image #align set.image_subset_iff Set.image_subset_iff theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s := image_subset_iff.2 Subset.rfl #align set.image_preimage_subset Set.image_preimage_subset theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ => mem_image_of_mem f #align set.subset_preimage_image Set.subset_preimage_image @[simp] theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s := Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s) #align set.preimage_image_eq Set.preimage_image_eq @[simp] theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s := Subset.antisymm (image_preimage_subset f s) fun x hx => let ⟨y, e⟩ := h x ⟨y, (e.symm ▸ hx : f y ∈ s), e⟩ #align set.image_preimage_eq Set.image_preimage_eq @[simp] theorem Nonempty.subset_preimage_const {s : Set α} (hs : Set.Nonempty s) (t : Set β) (a : β) : s ⊆ (fun _ => a) ⁻¹' t ↔ a ∈ t := by rw [← image_subset_iff, hs.image_const, singleton_subset_iff] @[simp] theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t := Iff.intro fun eq => by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq] fun eq => eq ▸ rfl #align set.preimage_eq_preimage Set.preimage_eq_preimage theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) : f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by apply Subset.antisymm · calc f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _ _ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t) · rintro _ ⟨⟨x, h', rfl⟩, h⟩ exact ⟨x, ⟨h', h⟩, rfl⟩ #align set.image_inter_preimage Set.image_inter_preimage theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) : f '' (f ⁻¹' t ∩ s) = t ∩ f '' s := by simp only [inter_comm, image_inter_preimage] #align set.image_preimage_inter Set.image_preimage_inter @[simp] theorem image_inter_nonempty_iff {f : α → β} {s : Set α} {t : Set β} : (f '' s ∩ t).Nonempty ↔ (s ∩ f ⁻¹' t).Nonempty := by rw [← image_inter_preimage, image_nonempty] #align set.image_inter_nonempty_iff Set.image_inter_nonempty_iff theorem image_diff_preimage {f : α → β} {s : Set α} {t : Set β} : f '' (s \ f ⁻¹' t) = f '' s \ t := by simp_rw [diff_eq, ← preimage_compl, image_inter_preimage] #align set.image_diff_preimage Set.image_diff_preimage theorem compl_image : image (compl : Set α → Set α) = preimage compl := image_eq_preimage_of_inverse compl_compl compl_compl #align set.compl_image Set.compl_image theorem compl_image_set_of {p : Set α → Prop} : compl '' { s | p s } = { s | p sᶜ } := congr_fun compl_image p #align set.compl_image_set_of Set.compl_image_set_of theorem inter_preimage_subset (s : Set α) (t : Set β) (f : α → β) : s ∩ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∩ t) := fun _ h => ⟨mem_image_of_mem _ h.left, h.right⟩ #align set.inter_preimage_subset Set.inter_preimage_subset theorem union_preimage_subset (s : Set α) (t : Set β) (f : α → β) : s ∪ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∪ t) := fun _ h => Or.elim h (fun l => Or.inl <| mem_image_of_mem _ l) fun r => Or.inr r #align set.union_preimage_subset Set.union_preimage_subset theorem subset_image_union (f : α → β) (s : Set α) (t : Set β) : f '' (s ∪ f ⁻¹' t) ⊆ f '' s ∪ t := image_subset_iff.2 (union_preimage_subset _ _ _) #align set.subset_image_union Set.subset_image_union theorem preimage_subset_iff {A : Set α} {B : Set β} {f : α → β} : f ⁻¹' B ⊆ A ↔ ∀ a : α, f a ∈ B → a ∈ A := Iff.rfl #align set.preimage_subset_iff Set.preimage_subset_iff theorem image_eq_image {f : α → β} (hf : Injective f) : f '' s = f '' t ↔ s = t := Iff.symm <| (Iff.intro fun eq => eq ▸ rfl) fun eq => by rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, eq] #align set.image_eq_image Set.image_eq_image theorem subset_image_iff {t : Set β} : t ⊆ f '' s ↔ ∃ u, u ⊆ s ∧ f '' u = t := by refine ⟨fun h ↦ ⟨f ⁻¹' t ∩ s, inter_subset_right, ?_⟩, fun ⟨u, hu, hu'⟩ ↦ hu'.symm ▸ image_mono hu⟩ rwa [image_preimage_inter, inter_eq_left] theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t := by refine Iff.symm <| (Iff.intro (image_subset f)) fun h => ?_ rw [← preimage_image_eq s hf, ← preimage_image_eq t hf] exact preimage_mono h #align set.image_subset_image_iff Set.image_subset_image_iff theorem prod_quotient_preimage_eq_image [s : Setoid α] (g : Quotient s → β) {h : α → β} (Hh : h = g ∘ Quotient.mk'') (r : Set (β × β)) : { x : Quotient s × Quotient s | (g x.1, g x.2) ∈ r } = (fun a : α × α => (⟦a.1⟧, ⟦a.2⟧)) '' ((fun a : α × α => (h a.1, h a.2)) ⁻¹' r) := Hh.symm ▸ Set.ext fun ⟨a₁, a₂⟩ => ⟨Quot.induction_on₂ a₁ a₂ fun a₁ a₂ h => ⟨(a₁, a₂), h, rfl⟩, fun ⟨⟨b₁, b₂⟩, h₁, h₂⟩ => show (g a₁, g a₂) ∈ r from have h₃ : ⟦b₁⟧ = a₁ ∧ ⟦b₂⟧ = a₂ := Prod.ext_iff.1 h₂ h₃.1 ▸ h₃.2 ▸ h₁⟩ #align set.prod_quotient_preimage_eq_image Set.prod_quotient_preimage_eq_image theorem exists_image_iff (f : α → β) (x : Set α) (P : β → Prop) : (∃ a : f '' x, P a) ↔ ∃ a : x, P (f a) := ⟨fun ⟨a, h⟩ => ⟨⟨_, a.prop.choose_spec.1⟩, a.prop.choose_spec.2.symm ▸ h⟩, fun ⟨a, h⟩ => ⟨⟨_, _, a.prop, rfl⟩, h⟩⟩ #align set.exists_image_iff Set.exists_image_iff theorem imageFactorization_eq {f : α → β} {s : Set α} : Subtype.val ∘ imageFactorization f s = f ∘ Subtype.val := funext fun _ => rfl #align set.image_factorization_eq Set.imageFactorization_eq theorem surjective_onto_image {f : α → β} {s : Set α} : Surjective (imageFactorization f s) := fun ⟨_, ⟨a, ha, rfl⟩⟩ => ⟨⟨a, ha⟩, rfl⟩ #align set.surjective_onto_image Set.surjective_onto_image /-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect. -/ theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by ext i obtain hi | hi := eq_or_ne (σ i) i · refine ⟨?_, fun h => ⟨i, h, hi⟩⟩ rintro ⟨j, hj, h⟩ rwa [σ.injective (hi.trans h.symm)] · refine iff_of_true ⟨σ.symm i, hs fun h => hi ?_, σ.apply_symm_apply _⟩ (hs hi) convert congr_arg σ h <;> exact (σ.apply_symm_apply _).symm #align set.image_perm Set.image_perm end Image /-! ### Lemmas about the powerset and image. -/ /-- The powerset of `{a} ∪ s` is `𝒫 s` together with `{a} ∪ t` for each `t ∈ 𝒫 s`. -/ theorem powerset_insert (s : Set α) (a : α) : 𝒫 insert a s = 𝒫 s ∪ insert a '' 𝒫 s := by ext t simp_rw [mem_union, mem_image, mem_powerset_iff] constructor · intro h by_cases hs : a ∈ t · right refine ⟨t \ {a}, ?_, ?_⟩ · rw [diff_singleton_subset_iff] assumption · rw [insert_diff_singleton, insert_eq_of_mem hs] · left exact (subset_insert_iff_of_not_mem hs).mp h · rintro (h | ⟨s', h₁, rfl⟩) · exact subset_trans h (subset_insert a s) · exact insert_subset_insert h₁ #align set.powerset_insert Set.powerset_insert /-! ### Lemmas about range of a function. -/ section Range variable {f : ι → α} {s t : Set α} theorem forall_mem_range {p : α → Prop} : (∀ a ∈ range f, p a) ↔ ∀ i, p (f i) := by simp #align set.forall_range_iff Set.forall_mem_range @[deprecated (since := "2024-02-21")] alias forall_range_iff := forall_mem_range theorem forall_subtype_range_iff {p : range f → Prop} : (∀ a : range f, p a) ↔ ∀ i, p ⟨f i, mem_range_self _⟩ := ⟨fun H i => H _, fun H ⟨y, i, hi⟩ => by subst hi apply H⟩ #align set.forall_subtype_range_iff Set.forall_subtype_range_iff theorem exists_range_iff {p : α → Prop} : (∃ a ∈ range f, p a) ↔ ∃ i, p (f i) := by simp #align set.exists_range_iff Set.exists_range_iff @[deprecated (since := "2024-03-10")] alias exists_range_iff' := exists_range_iff #align set.exists_range_iff' Set.exists_range_iff' theorem exists_subtype_range_iff {p : range f → Prop} : (∃ a : range f, p a) ↔ ∃ i, p ⟨f i, mem_range_self _⟩ := ⟨fun ⟨⟨a, i, hi⟩, ha⟩ => by subst a exact ⟨i, ha⟩, fun ⟨i, hi⟩ => ⟨_, hi⟩⟩ #align set.exists_subtype_range_iff Set.exists_subtype_range_iff theorem range_iff_surjective : range f = univ ↔ Surjective f := eq_univ_iff_forall #align set.range_iff_surjective Set.range_iff_surjective alias ⟨_, _root_.Function.Surjective.range_eq⟩ := range_iff_surjective #align function.surjective.range_eq Function.Surjective.range_eq @[simp] theorem subset_range_of_surjective {f : α → β} (h : Surjective f) (s : Set β) : s ⊆ range f := Surjective.range_eq h ▸ subset_univ s @[simp] theorem image_univ {f : α → β} : f '' univ = range f := by ext simp [image, range] #align set.image_univ Set.image_univ @[simp] theorem preimage_eq_univ_iff {f : α → β} {s} : f ⁻¹' s = univ ↔ range f ⊆ s := by rw [← univ_subset_iff, ← image_subset_iff, image_univ] theorem image_subset_range (f : α → β) (s) : f '' s ⊆ range f := by rw [← image_univ]; exact image_subset _ (subset_univ _) #align set.image_subset_range Set.image_subset_range theorem mem_range_of_mem_image (f : α → β) (s) {x : β} (h : x ∈ f '' s) : x ∈ range f := image_subset_range f s h #align set.mem_range_of_mem_image Set.mem_range_of_mem_image theorem _root_.Nat.mem_range_succ (i : ℕ) : i ∈ range Nat.succ ↔ 0 < i := ⟨by rintro ⟨n, rfl⟩ exact Nat.succ_pos n, fun h => ⟨_, Nat.succ_pred_eq_of_pos h⟩⟩ #align nat.mem_range_succ Nat.mem_range_succ theorem Nonempty.preimage' {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : s ⊆ range f) : (f ⁻¹' s).Nonempty := let ⟨_, hy⟩ := hs let ⟨x, hx⟩ := hf hy ⟨x, Set.mem_preimage.2 <| hx.symm ▸ hy⟩ #align set.nonempty.preimage' Set.Nonempty.preimage' theorem range_comp (g : α → β) (f : ι → α) : range (g ∘ f) = g '' range f := by aesop #align set.range_comp Set.range_comp theorem range_subset_iff : range f ⊆ s ↔ ∀ y, f y ∈ s := forall_mem_range #align set.range_subset_iff Set.range_subset_iff theorem range_subset_range_iff_exists_comp {f : α → γ} {g : β → γ} : range f ⊆ range g ↔ ∃ h : α → β, f = g ∘ h := by simp only [range_subset_iff, mem_range, Classical.skolem, Function.funext_iff, (· ∘ ·), eq_comm] theorem range_eq_iff (f : α → β) (s : Set β) : range f = s ↔ (∀ a, f a ∈ s) ∧ ∀ b ∈ s, ∃ a, f a = b := by rw [← range_subset_iff] exact le_antisymm_iff #align set.range_eq_iff Set.range_eq_iff theorem range_comp_subset_range (f : α → β) (g : β → γ) : range (g ∘ f) ⊆ range g := by rw [range_comp]; apply image_subset_range #align set.range_comp_subset_range Set.range_comp_subset_range theorem range_nonempty_iff_nonempty : (range f).Nonempty ↔ Nonempty ι := ⟨fun ⟨_, x, _⟩ => ⟨x⟩, fun ⟨x⟩ => ⟨f x, mem_range_self x⟩⟩ #align set.range_nonempty_iff_nonempty Set.range_nonempty_iff_nonempty theorem range_nonempty [h : Nonempty ι] (f : ι → α) : (range f).Nonempty := range_nonempty_iff_nonempty.2 h #align set.range_nonempty Set.range_nonempty @[simp] theorem range_eq_empty_iff {f : ι → α} : range f = ∅ ↔ IsEmpty ι := by rw [← not_nonempty_iff, ← range_nonempty_iff_nonempty, not_nonempty_iff_eq_empty] #align set.range_eq_empty_iff Set.range_eq_empty_iff theorem range_eq_empty [IsEmpty ι] (f : ι → α) : range f = ∅ := range_eq_empty_iff.2 ‹_› #align set.range_eq_empty Set.range_eq_empty instance instNonemptyRange [Nonempty ι] (f : ι → α) : Nonempty (range f) := (range_nonempty f).to_subtype @[simp] theorem image_union_image_compl_eq_range (f : α → β) : f '' s ∪ f '' sᶜ = range f := by rw [← image_union, ← image_univ, ← union_compl_self] #align set.image_union_image_compl_eq_range Set.image_union_image_compl_eq_range theorem insert_image_compl_eq_range (f : α → β) (x : α) : insert (f x) (f '' {x}ᶜ) = range f := by rw [← image_insert_eq, insert_eq, union_compl_self, image_univ] #align set.insert_image_compl_eq_range Set.insert_image_compl_eq_range theorem image_preimage_eq_range_inter {f : α → β} {t : Set β} : f '' (f ⁻¹' t) = range f ∩ t := ext fun x => ⟨fun ⟨x, hx, HEq⟩ => HEq ▸ ⟨mem_range_self _, hx⟩, fun ⟨⟨y, h_eq⟩, hx⟩ => h_eq ▸ mem_image_of_mem f <| show y ∈ f ⁻¹' t by rw [preimage, mem_setOf, h_eq]; exact hx⟩ theorem image_preimage_eq_inter_range {f : α → β} {t : Set β} : f '' (f ⁻¹' t) = t ∩ range f := by rw [image_preimage_eq_range_inter, inter_comm] #align set.image_preimage_eq_inter_range Set.image_preimage_eq_inter_range theorem image_preimage_eq_of_subset {f : α → β} {s : Set β} (hs : s ⊆ range f) : f '' (f ⁻¹' s) = s := by rw [image_preimage_eq_range_inter, inter_eq_self_of_subset_right hs] #align set.image_preimage_eq_of_subset Set.image_preimage_eq_of_subset theorem image_preimage_eq_iff {f : α → β} {s : Set β} : f '' (f ⁻¹' s) = s ↔ s ⊆ range f := ⟨by intro h rw [← h] apply image_subset_range, image_preimage_eq_of_subset⟩ #align set.image_preimage_eq_iff Set.image_preimage_eq_iff theorem subset_range_iff_exists_image_eq {f : α → β} {s : Set β} : s ⊆ range f ↔ ∃ t, f '' t = s := ⟨fun h => ⟨_, image_preimage_eq_iff.2 h⟩, fun ⟨_, ht⟩ => ht ▸ image_subset_range _ _⟩ #align set.subset_range_iff_exists_image_eq Set.subset_range_iff_exists_image_eq theorem range_image (f : α → β) : range (image f) = 𝒫 range f := ext fun _ => subset_range_iff_exists_image_eq.symm #align set.range_image Set.range_image @[simp] theorem exists_subset_range_and_iff {f : α → β} {p : Set β → Prop} : (∃ s, s ⊆ range f ∧ p s) ↔ ∃ s, p (f '' s) := by rw [← exists_range_iff, range_image]; rfl #align set.exists_subset_range_and_iff Set.exists_subset_range_and_iff theorem exists_subset_range_iff {f : α → β} {p : Set β → Prop} : (∃ (s : _) (_ : s ⊆ range f), p s) ↔ ∃ s, p (f '' s) := by simp #align set.exists_subset_range_iff Set.exists_subset_range_iff theorem forall_subset_range_iff {f : α → β} {p : Set β → Prop} : (∀ s, s ⊆ range f → p s) ↔ ∀ s, p (f '' s) := by rw [← forall_mem_range, range_image]; rfl @[simp] theorem preimage_subset_preimage_iff {s t : Set α} {f : β → α} (hs : s ⊆ range f) : f ⁻¹' s ⊆ f ⁻¹' t ↔ s ⊆ t := by constructor · intro h x hx rcases hs hx with ⟨y, rfl⟩ exact h hx intro h x; apply h #align set.preimage_subset_preimage_iff Set.preimage_subset_preimage_iff theorem preimage_eq_preimage' {s t : Set α} {f : β → α} (hs : s ⊆ range f) (ht : t ⊆ range f) : f ⁻¹' s = f ⁻¹' t ↔ s = t := by constructor · intro h apply Subset.antisymm · rw [← preimage_subset_preimage_iff hs, h] · rw [← preimage_subset_preimage_iff ht, h] rintro rfl; rfl #align set.preimage_eq_preimage' Set.preimage_eq_preimage' -- Porting note: -- @[simp] `simp` can prove this theorem preimage_inter_range {f : α → β} {s : Set β} : f ⁻¹' (s ∩ range f) = f ⁻¹' s := Set.ext fun x => and_iff_left ⟨x, rfl⟩ #align set.preimage_inter_range Set.preimage_inter_range -- Porting note: -- @[simp] `simp` can prove this theorem preimage_range_inter {f : α → β} {s : Set β} : f ⁻¹' (range f ∩ s) = f ⁻¹' s := by rw [inter_comm, preimage_inter_range] #align set.preimage_range_inter Set.preimage_range_inter theorem preimage_image_preimage {f : α → β} {s : Set β} : f ⁻¹' (f '' (f ⁻¹' s)) = f ⁻¹' s := by rw [image_preimage_eq_range_inter, preimage_range_inter] #align set.preimage_image_preimage Set.preimage_image_preimage @[simp, mfld_simps] theorem range_id : range (@id α) = univ := range_iff_surjective.2 surjective_id #align set.range_id Set.range_id @[simp, mfld_simps] theorem range_id' : (range fun x : α => x) = univ := range_id #align set.range_id' Set.range_id' @[simp] theorem _root_.Prod.range_fst [Nonempty β] : range (Prod.fst : α × β → α) = univ := Prod.fst_surjective.range_eq #align prod.range_fst Prod.range_fst @[simp] theorem _root_.Prod.range_snd [Nonempty α] : range (Prod.snd : α × β → β) = univ := Prod.snd_surjective.range_eq #align prod.range_snd Prod.range_snd @[simp] theorem range_eval {α : ι → Sort _} [∀ i, Nonempty (α i)] (i : ι) : range (eval i : (∀ i, α i) → α i) = univ := (surjective_eval i).range_eq #align set.range_eval Set.range_eval theorem range_inl : range (@Sum.inl α β) = {x | Sum.isLeft x} := by ext (_|_) <;> simp #align set.range_inl Set.range_inl theorem range_inr : range (@Sum.inr α β) = {x | Sum.isRight x} := by ext (_|_) <;> simp #align set.range_inr Set.range_inr theorem isCompl_range_inl_range_inr : IsCompl (range <| @Sum.inl α β) (range Sum.inr) := IsCompl.of_le (by rintro y ⟨⟨x₁, rfl⟩, ⟨x₂, h⟩⟩ exact Sum.noConfusion h) (by rintro (x | y) - <;> [left; right] <;> exact mem_range_self _) #align set.is_compl_range_inl_range_inr Set.isCompl_range_inl_range_inr @[simp] theorem range_inl_union_range_inr : range (Sum.inl : α → Sum α β) ∪ range Sum.inr = univ := isCompl_range_inl_range_inr.sup_eq_top #align set.range_inl_union_range_inr Set.range_inl_union_range_inr @[simp] theorem range_inl_inter_range_inr : range (Sum.inl : α → Sum α β) ∩ range Sum.inr = ∅ := isCompl_range_inl_range_inr.inf_eq_bot #align set.range_inl_inter_range_inr Set.range_inl_inter_range_inr @[simp] theorem range_inr_union_range_inl : range (Sum.inr : β → Sum α β) ∪ range Sum.inl = univ := isCompl_range_inl_range_inr.symm.sup_eq_top #align set.range_inr_union_range_inl Set.range_inr_union_range_inl @[simp] theorem range_inr_inter_range_inl : range (Sum.inr : β → Sum α β) ∩ range Sum.inl = ∅ := isCompl_range_inl_range_inr.symm.inf_eq_bot #align set.range_inr_inter_range_inl Set.range_inr_inter_range_inl @[simp] theorem preimage_inl_image_inr (s : Set β) : Sum.inl ⁻¹' (@Sum.inr α β '' s) = ∅ := by ext simp #align set.preimage_inl_image_inr Set.preimage_inl_image_inr @[simp] theorem preimage_inr_image_inl (s : Set α) : Sum.inr ⁻¹' (@Sum.inl α β '' s) = ∅ := by ext simp #align set.preimage_inr_image_inl Set.preimage_inr_image_inl @[simp] theorem preimage_inl_range_inr : Sum.inl ⁻¹' range (Sum.inr : β → Sum α β) = ∅ := by rw [← image_univ, preimage_inl_image_inr] #align set.preimage_inl_range_inr Set.preimage_inl_range_inr @[simp] theorem preimage_inr_range_inl : Sum.inr ⁻¹' range (Sum.inl : α → Sum α β) = ∅ := by rw [← image_univ, preimage_inr_image_inl] #align set.preimage_inr_range_inl Set.preimage_inr_range_inl @[simp] theorem compl_range_inl : (range (Sum.inl : α → Sum α β))ᶜ = range (Sum.inr : β → Sum α β) := IsCompl.compl_eq isCompl_range_inl_range_inr #align set.compl_range_inl Set.compl_range_inl @[simp] theorem compl_range_inr : (range (Sum.inr : β → Sum α β))ᶜ = range (Sum.inl : α → Sum α β) := IsCompl.compl_eq isCompl_range_inl_range_inr.symm #align set.compl_range_inr Set.compl_range_inr theorem image_preimage_inl_union_image_preimage_inr (s : Set (Sum α β)) : Sum.inl '' (Sum.inl ⁻¹' s) ∪ Sum.inr '' (Sum.inr ⁻¹' s) = s := by rw [image_preimage_eq_inter_range, image_preimage_eq_inter_range, ← inter_union_distrib_left, range_inl_union_range_inr, inter_univ] #align set.image_preimage_inl_union_image_preimage_inr Set.image_preimage_inl_union_image_preimage_inr @[simp] theorem range_quot_mk (r : α → α → Prop) : range (Quot.mk r) = univ := (surjective_quot_mk r).range_eq #align set.range_quot_mk Set.range_quot_mk @[simp] theorem range_quot_lift {r : ι → ι → Prop} (hf : ∀ x y, r x y → f x = f y) : range (Quot.lift f hf) = range f := ext fun _ => (surjective_quot_mk _).exists #align set.range_quot_lift Set.range_quot_lift -- Porting note: the `Setoid α` instance is not being filled in @[simp] theorem range_quotient_mk [sa : Setoid α] : (range (α := Quotient sa) fun x : α => ⟦x⟧) = univ := range_quot_mk _ #align set.range_quotient_mk Set.range_quotient_mk @[simp] theorem range_quotient_lift [s : Setoid ι] (hf) : range (Quotient.lift f hf : Quotient s → α) = range f := range_quot_lift _ #align set.range_quotient_lift Set.range_quotient_lift @[simp] theorem range_quotient_mk' {s : Setoid α} : range (Quotient.mk' : α → Quotient s) = univ := range_quot_mk _ #align set.range_quotient_mk' Set.range_quotient_mk' @[simp] lemma Quotient.range_mk'' {sa : Setoid α} : range (Quotient.mk'' (s₁ := sa)) = univ := range_quotient_mk @[simp] theorem range_quotient_lift_on' {s : Setoid ι} (hf) : (range fun x : Quotient s => Quotient.liftOn' x f hf) = range f := range_quot_lift _ #align set.range_quotient_lift_on' Set.range_quotient_lift_on' instance canLift (c) (p) [CanLift α β c p] : CanLift (Set α) (Set β) (c '' ·) fun s => ∀ x ∈ s, p x where prf _ hs := subset_range_iff_exists_image_eq.mp fun x hx => CanLift.prf _ (hs x hx) #align set.can_lift Set.canLift theorem range_const_subset {c : α} : (range fun _ : ι => c) ⊆ {c} := range_subset_iff.2 fun _ => rfl #align set.range_const_subset Set.range_const_subset @[simp] theorem range_const : ∀ [Nonempty ι] {c : α}, (range fun _ : ι => c) = {c} | ⟨x⟩, _ => (Subset.antisymm range_const_subset) fun _ hy => (mem_singleton_iff.1 hy).symm ▸ mem_range_self x #align set.range_const Set.range_const theorem range_subtype_map {p : α → Prop} {q : β → Prop} (f : α → β) (h : ∀ x, p x → q (f x)) : range (Subtype.map f h) = (↑) ⁻¹' (f '' { x | p x }) := by ext ⟨x, hx⟩ rw [mem_preimage, mem_range, mem_image, Subtype.exists, Subtype.coe_mk] apply Iff.intro · rintro ⟨a, b, hab⟩ rw [Subtype.map, Subtype.mk.injEq] at hab use a trivial · rintro ⟨a, b, hab⟩ use a use b rw [Subtype.map, Subtype.mk.injEq] exact hab -- Porting note: `simp_rw` fails here -- simp_rw [mem_preimage, mem_range, mem_image, Subtype.exists, Subtype.map, Subtype.coe_mk, -- mem_set_of, exists_prop] #align set.range_subtype_map Set.range_subtype_map theorem image_swap_eq_preimage_swap : image (@Prod.swap α β) = preimage Prod.swap := image_eq_preimage_of_inverse Prod.swap_leftInverse Prod.swap_rightInverse #align set.image_swap_eq_preimage_swap Set.image_swap_eq_preimage_swap theorem preimage_singleton_nonempty {f : α → β} {y : β} : (f ⁻¹' {y}).Nonempty ↔ y ∈ range f := Iff.rfl #align set.preimage_singleton_nonempty Set.preimage_singleton_nonempty theorem preimage_singleton_eq_empty {f : α → β} {y : β} : f ⁻¹' {y} = ∅ ↔ y ∉ range f := not_nonempty_iff_eq_empty.symm.trans preimage_singleton_nonempty.not #align set.preimage_singleton_eq_empty Set.preimage_singleton_eq_empty theorem range_subset_singleton {f : ι → α} {x : α} : range f ⊆ {x} ↔ f = const ι x := by simp [range_subset_iff, funext_iff, mem_singleton] #align set.range_subset_singleton Set.range_subset_singleton theorem image_compl_preimage {f : α → β} {s : Set β} : f '' (f ⁻¹' s)ᶜ = range f \ s := by rw [compl_eq_univ_diff, image_diff_preimage, image_univ] #align set.image_compl_preimage Set.image_compl_preimage theorem rangeFactorization_eq {f : ι → β} : Subtype.val ∘ rangeFactorization f = f := funext fun _ => rfl #align set.range_factorization_eq Set.rangeFactorization_eq @[simp] theorem rangeFactorization_coe (f : ι → β) (a : ι) : (rangeFactorization f a : β) = f a := rfl #align set.range_factorization_coe Set.rangeFactorization_coe @[simp] theorem coe_comp_rangeFactorization (f : ι → β) : (↑) ∘ rangeFactorization f = f := rfl #align set.coe_comp_range_factorization Set.coe_comp_rangeFactorization theorem surjective_onto_range : Surjective (rangeFactorization f) := fun ⟨_, ⟨i, rfl⟩⟩ => ⟨i, rfl⟩ #align set.surjective_onto_range Set.surjective_onto_range theorem image_eq_range (f : α → β) (s : Set α) : f '' s = range fun x : s => f x := by ext constructor · rintro ⟨x, h1, h2⟩ exact ⟨⟨x, h1⟩, h2⟩ · rintro ⟨⟨x, h1⟩, h2⟩ exact ⟨x, h1, h2⟩ #align set.image_eq_range Set.image_eq_range theorem _root_.Sum.range_eq (f : Sum α β → γ) : range f = range (f ∘ Sum.inl) ∪ range (f ∘ Sum.inr) := ext fun _ => Sum.exists #align sum.range_eq Sum.range_eq @[simp] theorem Sum.elim_range (f : α → γ) (g : β → γ) : range (Sum.elim f g) = range f ∪ range g := Sum.range_eq _ #align set.sum.elim_range Set.Sum.elim_range theorem range_ite_subset' {p : Prop} [Decidable p] {f g : α → β} : range (if p then f else g) ⊆ range f ∪ range g := by by_cases h : p · rw [if_pos h] exact subset_union_left · rw [if_neg h] exact subset_union_right #align set.range_ite_subset' Set.range_ite_subset' theorem range_ite_subset {p : α → Prop} [DecidablePred p] {f g : α → β} : (range fun x => if p x then f x else g x) ⊆ range f ∪ range g := by rw [range_subset_iff]; intro x; by_cases h : p x · simp only [if_pos h, mem_union, mem_range, exists_apply_eq_apply, true_or] · simp [if_neg h, mem_union, mem_range_self] #align set.range_ite_subset Set.range_ite_subset @[simp] theorem preimage_range (f : α → β) : f ⁻¹' range f = univ := eq_univ_of_forall mem_range_self #align set.preimage_range Set.preimage_range /-- The range of a function from a `Unique` type contains just the function applied to its single value. -/ theorem range_unique [h : Unique ι] : range f = {f default} := by ext x rw [mem_range] constructor · rintro ⟨i, hi⟩ rw [h.uniq i] at hi exact hi ▸ mem_singleton _ · exact fun h => ⟨default, h.symm⟩ #align set.range_unique Set.range_unique theorem range_diff_image_subset (f : α → β) (s : Set α) : range f \ f '' s ⊆ f '' sᶜ := fun _ ⟨⟨x, h₁⟩, h₂⟩ => ⟨x, fun h => h₂ ⟨x, h, h₁⟩, h₁⟩ #align set.range_diff_image_subset Set.range_diff_image_subset theorem range_diff_image {f : α → β} (H : Injective f) (s : Set α) : range f \ f '' s = f '' sᶜ := (Subset.antisymm (range_diff_image_subset f s)) fun _ ⟨_, hx, hy⟩ => hy ▸ ⟨mem_range_self _, fun ⟨_, hx', Eq⟩ => hx <| H Eq ▸ hx'⟩ #align set.range_diff_image Set.range_diff_image @[simp] theorem range_inclusion (h : s ⊆ t) : range (inclusion h) = { x : t | (x : α) ∈ s } := by ext ⟨x, hx⟩ -- Porting note: `simp [inclusion]` doesn't solve goal apply Iff.intro · rw [mem_range] rintro ⟨a, ha⟩ rw [inclusion, Subtype.mk.injEq] at ha rw [mem_setOf, Subtype.coe_mk, ← ha] exact Subtype.coe_prop _ · rw [mem_setOf, Subtype.coe_mk, mem_range] intro hx' use ⟨x, hx'⟩ trivial -- simp_rw [inclusion, mem_range, Subtype.mk_eq_mk] -- rw [SetCoe.exists, Subtype.coe_mk, exists_prop, exists_eq_right, mem_set_of, Subtype.coe_mk] #align set.range_inclusion Set.range_inclusion -- When `f` is injective, see also `Equiv.ofInjective`. theorem leftInverse_rangeSplitting (f : α → β) : LeftInverse (rangeFactorization f) (rangeSplitting f) := fun x => by apply Subtype.ext -- Porting note: why doesn't `ext` find this lemma? simp only [rangeFactorization_coe] apply apply_rangeSplitting #align set.left_inverse_range_splitting Set.leftInverse_rangeSplitting theorem rangeSplitting_injective (f : α → β) : Injective (rangeSplitting f) := (leftInverse_rangeSplitting f).injective #align set.range_splitting_injective Set.rangeSplitting_injective theorem rightInverse_rangeSplitting {f : α → β} (h : Injective f) : RightInverse (rangeFactorization f) (rangeSplitting f) := (leftInverse_rangeSplitting f).rightInverse_of_injective fun _ _ hxy => h <| Subtype.ext_iff.1 hxy #align set.right_inverse_range_splitting Set.rightInverse_rangeSplitting theorem preimage_rangeSplitting {f : α → β} (hf : Injective f) : preimage (rangeSplitting f) = image (rangeFactorization f) := (image_eq_preimage_of_inverse (rightInverse_rangeSplitting hf) (leftInverse_rangeSplitting f)).symm #align set.preimage_range_splitting Set.preimage_rangeSplitting theorem isCompl_range_some_none (α : Type*) : IsCompl (range (some : α → Option α)) {none} := IsCompl.of_le (fun _ ⟨⟨_, ha⟩, (hn : _ = none)⟩ => Option.some_ne_none _ (ha.trans hn)) fun x _ => Option.casesOn x (Or.inr rfl) fun _ => Or.inl <| mem_range_self _ #align set.is_compl_range_some_none Set.isCompl_range_some_none @[simp] theorem compl_range_some (α : Type*) : (range (some : α → Option α))ᶜ = {none} := (isCompl_range_some_none α).compl_eq #align set.compl_range_some Set.compl_range_some @[simp] theorem range_some_inter_none (α : Type*) : range (some : α → Option α) ∩ {none} = ∅ := (isCompl_range_some_none α).inf_eq_bot #align set.range_some_inter_none Set.range_some_inter_none -- Porting note: -- @[simp] `simp` can prove this theorem range_some_union_none (α : Type*) : range (some : α → Option α) ∪ {none} = univ := (isCompl_range_some_none α).sup_eq_top #align set.range_some_union_none Set.range_some_union_none @[simp] theorem insert_none_range_some (α : Type*) : insert none (range (some : α → Option α)) = univ := (isCompl_range_some_none α).symm.sup_eq_top #align set.insert_none_range_some Set.insert_none_range_some end Range section Subsingleton variable {s : Set α} /-- The image of a subsingleton is a subsingleton. -/ theorem Subsingleton.image (hs : s.Subsingleton) (f : α → β) : (f '' s).Subsingleton := fun _ ⟨_, hx, Hx⟩ _ ⟨_, hy, Hy⟩ => Hx ▸ Hy ▸ congr_arg f (hs hx hy) #align set.subsingleton.image Set.Subsingleton.image /-- The preimage of a subsingleton under an injective map is a subsingleton. -/ theorem Subsingleton.preimage {s : Set β} (hs : s.Subsingleton) {f : α → β} (hf : Function.Injective f) : (f ⁻¹' s).Subsingleton := fun _ ha _ hb => hf <| hs ha hb #align set.subsingleton.preimage Set.Subsingleton.preimage /-- If the image of a set under an injective map is a subsingleton, the set is a subsingleton. -/ theorem subsingleton_of_image {f : α → β} (hf : Function.Injective f) (s : Set α) (hs : (f '' s).Subsingleton) : s.Subsingleton := (hs.preimage hf).anti <| subset_preimage_image _ _ #align set.subsingleton_of_image Set.subsingleton_of_image /-- If the preimage of a set under a surjective map is a subsingleton, the set is a subsingleton. -/ theorem subsingleton_of_preimage {f : α → β} (hf : Function.Surjective f) (s : Set β) (hs : (f ⁻¹' s).Subsingleton) : s.Subsingleton := fun fx hx fy hy => by rcases hf fx, hf fy with ⟨⟨x, rfl⟩, ⟨y, rfl⟩⟩ exact congr_arg f (hs hx hy) #align set.subsingleton_of_preimage Set.subsingleton_of_preimage theorem subsingleton_range {α : Sort*} [Subsingleton α] (f : α → β) : (range f).Subsingleton := forall_mem_range.2 fun x => forall_mem_range.2 fun y => congr_arg f (Subsingleton.elim x y) #align set.subsingleton_range Set.subsingleton_range /-- The preimage of a nontrivial set under a surjective map is nontrivial. -/ theorem Nontrivial.preimage {s : Set β} (hs : s.Nontrivial) {f : α → β} (hf : Function.Surjective f) : (f ⁻¹' s).Nontrivial := by rcases hs with ⟨fx, hx, fy, hy, hxy⟩ rcases hf fx, hf fy with ⟨⟨x, rfl⟩, ⟨y, rfl⟩⟩ exact ⟨x, hx, y, hy, mt (congr_arg f) hxy⟩ #align set.nontrivial.preimage Set.Nontrivial.preimage /-- The image of a nontrivial set under an injective map is nontrivial. -/ theorem Nontrivial.image (hs : s.Nontrivial) {f : α → β} (hf : Function.Injective f) : (f '' s).Nontrivial := let ⟨x, hx, y, hy, hxy⟩ := hs ⟨f x, mem_image_of_mem f hx, f y, mem_image_of_mem f hy, hf.ne hxy⟩ #align set.nontrivial.image Set.Nontrivial.image /-- If the image of a set is nontrivial, the set is nontrivial. -/ theorem nontrivial_of_image (f : α → β) (s : Set α) (hs : (f '' s).Nontrivial) : s.Nontrivial := let ⟨_, ⟨x, hx, rfl⟩, _, ⟨y, hy, rfl⟩, hxy⟩ := hs ⟨x, hx, y, hy, mt (congr_arg f) hxy⟩ #align set.nontrivial_of_image Set.nontrivial_of_image @[simp] theorem image_nontrivial {f : α → β} (hf : f.Injective) : (f '' s).Nontrivial ↔ s.Nontrivial := ⟨nontrivial_of_image f s, fun h ↦ h.image hf⟩ /-- If the preimage of a set under an injective map is nontrivial, the set is nontrivial. -/ theorem nontrivial_of_preimage {f : α → β} (hf : Function.Injective f) (s : Set β) (hs : (f ⁻¹' s).Nontrivial) : s.Nontrivial := (hs.image hf).mono <| image_preimage_subset _ _ #align set.nontrivial_of_preimage Set.nontrivial_of_preimage end Subsingleton end Set namespace Function variable {α β : Type*} {ι : Sort*} {f : α → β} open Set theorem Surjective.preimage_injective (hf : Surjective f) : Injective (preimage f) := fun _ _ => (preimage_eq_preimage hf).1 #align function.surjective.preimage_injective Function.Surjective.preimage_injective theorem Injective.preimage_image (hf : Injective f) (s : Set α) : f ⁻¹' (f '' s) = s := preimage_image_eq s hf #align function.injective.preimage_image Function.Injective.preimage_image theorem Injective.preimage_surjective (hf : Injective f) : Surjective (preimage f) := by intro s use f '' s rw [hf.preimage_image] #align function.injective.preimage_surjective Function.Injective.preimage_surjective theorem Injective.subsingleton_image_iff (hf : Injective f) {s : Set α} : (f '' s).Subsingleton ↔ s.Subsingleton := ⟨subsingleton_of_image hf s, fun h => h.image f⟩ #align function.injective.subsingleton_image_iff Function.Injective.subsingleton_image_iff theorem Surjective.image_preimage (hf : Surjective f) (s : Set β) : f '' (f ⁻¹' s) = s := image_preimage_eq s hf #align function.surjective.image_preimage Function.Surjective.image_preimage theorem Surjective.image_surjective (hf : Surjective f) : Surjective (image f) := by intro s use f ⁻¹' s rw [hf.image_preimage] #align function.surjective.image_surjective Function.Surjective.image_surjective @[simp] theorem Surjective.nonempty_preimage (hf : Surjective f) {s : Set β} : (f ⁻¹' s).Nonempty ↔ s.Nonempty := by rw [← image_nonempty, hf.image_preimage] #align function.surjective.nonempty_preimage Function.Surjective.nonempty_preimage theorem Injective.image_injective (hf : Injective f) : Injective (image f) := by intro s t h rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, h] #align function.injective.image_injective Function.Injective.image_injective theorem Surjective.preimage_subset_preimage_iff {s t : Set β} (hf : Surjective f) : f ⁻¹' s ⊆ f ⁻¹' t ↔ s ⊆ t := by apply Set.preimage_subset_preimage_iff rw [hf.range_eq] apply subset_univ #align function.surjective.preimage_subset_preimage_iff Function.Surjective.preimage_subset_preimage_iff theorem Surjective.range_comp {ι' : Sort*} {f : ι → ι'} (hf : Surjective f) (g : ι' → α) : range (g ∘ f) = range g := ext fun y => (@Surjective.exists _ _ _ hf fun x => g x = y).symm #align function.surjective.range_comp Function.Surjective.range_comp theorem Injective.mem_range_iff_exists_unique (hf : Injective f) {b : β} : b ∈ range f ↔ ∃! a, f a = b := ⟨fun ⟨a, h⟩ => ⟨a, h, fun _ ha => hf (ha.trans h.symm)⟩, ExistsUnique.exists⟩ #align function.injective.mem_range_iff_exists_unique Function.Injective.mem_range_iff_exists_unique theorem Injective.exists_unique_of_mem_range (hf : Injective f) {b : β} (hb : b ∈ range f) : ∃! a, f a = b := hf.mem_range_iff_exists_unique.mp hb #align function.injective.exists_unique_of_mem_range Function.Injective.exists_unique_of_mem_range theorem Injective.compl_image_eq (hf : Injective f) (s : Set α) : (f '' s)ᶜ = f '' sᶜ ∪ (range f)ᶜ := by ext y rcases em (y ∈ range f) with (⟨x, rfl⟩ | hx) · simp [hf.eq_iff] · rw [mem_range, not_exists] at hx simp [hx] #align function.injective.compl_image_eq Function.Injective.compl_image_eq theorem LeftInverse.image_image {g : β → α} (h : LeftInverse g f) (s : Set α) : g '' (f '' s) = s := by rw [← image_comp, h.comp_eq_id, image_id] #align function.left_inverse.image_image Function.LeftInverse.image_image theorem LeftInverse.preimage_preimage {g : β → α} (h : LeftInverse g f) (s : Set α) : f ⁻¹' (g ⁻¹' s) = s := by rw [← preimage_comp, h.comp_eq_id, preimage_id] #align function.left_inverse.preimage_preimage Function.LeftInverse.preimage_preimage protected theorem Involutive.preimage {f : α → α} (hf : Involutive f) : Involutive (preimage f) := hf.rightInverse.preimage_preimage #align function.involutive.preimage Function.Involutive.preimage end Function namespace EquivLike variable {ι ι' : Sort*} {E : Type*} [EquivLike E ι ι'] @[simp] lemma range_comp {α : Type*} (f : ι' → α) (e : E) : range (f ∘ e) = range f := (EquivLike.surjective _).range_comp _ #align equiv_like.range_comp EquivLike.range_comp end EquivLike /-! ### Image and preimage on subtypes -/ namespace Subtype variable {α : Type*} theorem coe_image {p : α → Prop} {s : Set (Subtype p)} : (↑) '' s = { x | ∃ h : p x, (⟨x, h⟩ : Subtype p) ∈ s } := Set.ext fun a => ⟨fun ⟨⟨_, ha'⟩, in_s, h_eq⟩ => h_eq ▸ ⟨ha', in_s⟩, fun ⟨ha, in_s⟩ => ⟨⟨a, ha⟩, in_s, rfl⟩⟩ #align subtype.coe_image Subtype.coe_image @[simp] theorem coe_image_of_subset {s t : Set α} (h : t ⊆ s) : (↑) '' { x : ↥s | ↑x ∈ t } = t := by ext x rw [mem_image] exact ⟨fun ⟨_, hx', hx⟩ => hx ▸ hx', fun hx => ⟨⟨x, h hx⟩, hx, rfl⟩⟩ #align subtype.coe_image_of_subset Subtype.coe_image_of_subset theorem range_coe {s : Set α} : range ((↑) : s → α) = s := by rw [← image_univ] simp [-image_univ, coe_image] #align subtype.range_coe Subtype.range_coe /-- A variant of `range_coe`. Try to use `range_coe` if possible. This version is useful when defining a new type that is defined as the subtype of something. In that case, the coercion doesn't fire anymore. -/ theorem range_val {s : Set α} : range (Subtype.val : s → α) = s := range_coe #align subtype.range_val Subtype.range_val /-- We make this the simp lemma instead of `range_coe`. The reason is that if we write for `s : Set α` the function `(↑) : s → α`, then the inferred implicit arguments of `(↑)` are `↑α (fun x ↦ x ∈ s)`. -/ @[simp] theorem range_coe_subtype {p : α → Prop} : range ((↑) : Subtype p → α) = { x | p x } := range_coe #align subtype.range_coe_subtype Subtype.range_coe_subtype @[simp] theorem coe_preimage_self (s : Set α) : ((↑) : s → α) ⁻¹' s = univ := by rw [← preimage_range, range_coe] #align subtype.coe_preimage_self Subtype.coe_preimage_self theorem range_val_subtype {p : α → Prop} : range (Subtype.val : Subtype p → α) = { x | p x } := range_coe #align subtype.range_val_subtype Subtype.range_val_subtype theorem coe_image_subset (s : Set α) (t : Set s) : ((↑) : s → α) '' t ⊆ s := fun x ⟨y, _, yvaleq⟩ => by rw [← yvaleq]; exact y.property #align subtype.coe_image_subset Subtype.coe_image_subset theorem coe_image_univ (s : Set α) : ((↑) : s → α) '' Set.univ = s := image_univ.trans range_coe #align subtype.coe_image_univ Subtype.coe_image_univ @[simp] theorem image_preimage_coe (s t : Set α) : ((↑) : s → α) '' (((↑) : s → α) ⁻¹' t) = s ∩ t := image_preimage_eq_range_inter.trans <| congr_arg (· ∩ t) range_coe #align subtype.image_preimage_coe Subtype.image_preimage_coe theorem image_preimage_val (s t : Set α) : (Subtype.val : s → α) '' (Subtype.val ⁻¹' t) = s ∩ t := image_preimage_coe s t #align subtype.image_preimage_val Subtype.image_preimage_val theorem preimage_coe_eq_preimage_coe_iff {s t u : Set α} : ((↑) : s → α) ⁻¹' t = ((↑) : s → α) ⁻¹' u ↔ s ∩ t = s ∩ u := by rw [← image_preimage_coe, ← image_preimage_coe, coe_injective.image_injective.eq_iff] #align subtype.preimage_coe_eq_preimage_coe_iff Subtype.preimage_coe_eq_preimage_coe_iff theorem preimage_coe_self_inter (s t : Set α) : ((↑) : s → α) ⁻¹' (s ∩ t) = ((↑) : s → α) ⁻¹' t := by rw [preimage_coe_eq_preimage_coe_iff, ← inter_assoc, inter_self] -- Porting note: -- @[simp] `simp` can prove this theorem preimage_coe_inter_self (s t : Set α) : ((↑) : s → α) ⁻¹' (t ∩ s) = ((↑) : s → α) ⁻¹' t := by rw [inter_comm, preimage_coe_self_inter] #align subtype.preimage_coe_inter_self Subtype.preimage_coe_inter_self theorem preimage_val_eq_preimage_val_iff (s t u : Set α) : (Subtype.val : s → α) ⁻¹' t = Subtype.val ⁻¹' u ↔ s ∩ t = s ∩ u := preimage_coe_eq_preimage_coe_iff #align subtype.preimage_val_eq_preimage_val_iff Subtype.preimage_val_eq_preimage_val_iff lemma preimage_val_subset_preimage_val_iff (s t u : Set α) : (Subtype.val ⁻¹' t : Set s) ⊆ Subtype.val ⁻¹' u ↔ s ∩ t ⊆ s ∩ u := by constructor · rw [← image_preimage_coe, ← image_preimage_coe] exact image_subset _ · intro h x a exact (h ⟨x.2, a⟩).2 theorem exists_set_subtype {t : Set α} (p : Set α → Prop) : (∃ s : Set t, p (((↑) : t → α) '' s)) ↔ ∃ s : Set α, s ⊆ t ∧ p s := by rw [← exists_subset_range_and_iff, range_coe] #align subtype.exists_set_subtype Subtype.exists_set_subtype
Mathlib/Data/Set/Image.lean
1,456
1,458
theorem forall_set_subtype {t : Set α} (p : Set α → Prop) : (∀ s : Set t, p (((↑) : t → α) '' s)) ↔ ∀ s : Set α, s ⊆ t → p s := by
rw [← forall_subset_range_iff, range_coe]
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Sébastien Gouëzel, Frédéric Dupuis -/ import Mathlib.Analysis.InnerProductSpace.Basic import Mathlib.LinearAlgebra.SesquilinearForm #align_import analysis.inner_product_space.orthogonal from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9" /-! # Orthogonal complements of submodules In this file, the `orthogonal` complement of a submodule `K` is defined, and basic API established. Some of the more subtle results about the orthogonal complement are delayed to `Analysis.InnerProductSpace.Projection`. See also `BilinForm.orthogonal` for orthogonality with respect to a general bilinear form. ## Notation The orthogonal complement of a submodule `K` is denoted by `Kᗮ`. The proposition that two submodules are orthogonal, `Submodule.IsOrtho`, is denoted by `U ⟂ V`. Note this is not the same unicode symbol as `⊥` (`Bot`). -/ variable {𝕜 E F : Type*} [RCLike 𝕜] variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] variable [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y namespace Submodule variable (K : Submodule 𝕜 E) /-- The subspace of vectors orthogonal to a given subspace. -/ def orthogonal : Submodule 𝕜 E where carrier := { v | ∀ u ∈ K, ⟪u, v⟫ = 0 } zero_mem' _ _ := inner_zero_right _ add_mem' hx hy u hu := by rw [inner_add_right, hx u hu, hy u hu, add_zero] smul_mem' c x hx u hu := by rw [inner_smul_right, hx u hu, mul_zero] #align submodule.orthogonal Submodule.orthogonal @[inherit_doc] notation:1200 K "ᗮ" => orthogonal K /-- When a vector is in `Kᗮ`. -/ theorem mem_orthogonal (v : E) : v ∈ Kᗮ ↔ ∀ u ∈ K, ⟪u, v⟫ = 0 := Iff.rfl #align submodule.mem_orthogonal Submodule.mem_orthogonal /-- When a vector is in `Kᗮ`, with the inner product the other way round. -/ theorem mem_orthogonal' (v : E) : v ∈ Kᗮ ↔ ∀ u ∈ K, ⟪v, u⟫ = 0 := by simp_rw [mem_orthogonal, inner_eq_zero_symm] #align submodule.mem_orthogonal' Submodule.mem_orthogonal' variable {K} /-- A vector in `K` is orthogonal to one in `Kᗮ`. -/ theorem inner_right_of_mem_orthogonal {u v : E} (hu : u ∈ K) (hv : v ∈ Kᗮ) : ⟪u, v⟫ = 0 := (K.mem_orthogonal v).1 hv u hu #align submodule.inner_right_of_mem_orthogonal Submodule.inner_right_of_mem_orthogonal /-- A vector in `Kᗮ` is orthogonal to one in `K`. -/ theorem inner_left_of_mem_orthogonal {u v : E} (hu : u ∈ K) (hv : v ∈ Kᗮ) : ⟪v, u⟫ = 0 := by rw [inner_eq_zero_symm]; exact inner_right_of_mem_orthogonal hu hv #align submodule.inner_left_of_mem_orthogonal Submodule.inner_left_of_mem_orthogonal /-- A vector is in `(𝕜 ∙ u)ᗮ` iff it is orthogonal to `u`. -/ theorem mem_orthogonal_singleton_iff_inner_right {u v : E} : v ∈ (𝕜 ∙ u)ᗮ ↔ ⟪u, v⟫ = 0 := by refine ⟨inner_right_of_mem_orthogonal (mem_span_singleton_self u), ?_⟩ intro hv w hw rw [mem_span_singleton] at hw obtain ⟨c, rfl⟩ := hw simp [inner_smul_left, hv] #align submodule.mem_orthogonal_singleton_iff_inner_right Submodule.mem_orthogonal_singleton_iff_inner_right /-- A vector in `(𝕜 ∙ u)ᗮ` is orthogonal to `u`. -/ theorem mem_orthogonal_singleton_iff_inner_left {u v : E} : v ∈ (𝕜 ∙ u)ᗮ ↔ ⟪v, u⟫ = 0 := by rw [mem_orthogonal_singleton_iff_inner_right, inner_eq_zero_symm] #align submodule.mem_orthogonal_singleton_iff_inner_left Submodule.mem_orthogonal_singleton_iff_inner_left theorem sub_mem_orthogonal_of_inner_left {x y : E} (h : ∀ v : K, ⟪x, v⟫ = ⟪y, v⟫) : x - y ∈ Kᗮ := by rw [mem_orthogonal'] intro u hu rw [inner_sub_left, sub_eq_zero] exact h ⟨u, hu⟩ #align submodule.sub_mem_orthogonal_of_inner_left Submodule.sub_mem_orthogonal_of_inner_left theorem sub_mem_orthogonal_of_inner_right {x y : E} (h : ∀ v : K, ⟪(v : E), x⟫ = ⟪(v : E), y⟫) : x - y ∈ Kᗮ := by intro u hu rw [inner_sub_right, sub_eq_zero] exact h ⟨u, hu⟩ #align submodule.sub_mem_orthogonal_of_inner_right Submodule.sub_mem_orthogonal_of_inner_right variable (K) /-- `K` and `Kᗮ` have trivial intersection. -/ theorem inf_orthogonal_eq_bot : K ⊓ Kᗮ = ⊥ := by rw [eq_bot_iff] intro x rw [mem_inf] exact fun ⟨hx, ho⟩ => inner_self_eq_zero.1 (ho x hx) #align submodule.inf_orthogonal_eq_bot Submodule.inf_orthogonal_eq_bot /-- `K` and `Kᗮ` have trivial intersection. -/ theorem orthogonal_disjoint : Disjoint K Kᗮ := by simp [disjoint_iff, K.inf_orthogonal_eq_bot] #align submodule.orthogonal_disjoint Submodule.orthogonal_disjoint /-- `Kᗮ` can be characterized as the intersection of the kernels of the operations of inner product with each of the elements of `K`. -/ theorem orthogonal_eq_inter : Kᗮ = ⨅ v : K, LinearMap.ker (innerSL 𝕜 (v : E)) := by apply le_antisymm · rw [le_iInf_iff] rintro ⟨v, hv⟩ w hw simpa using hw _ hv · intro v hv w hw simp only [mem_iInf] at hv exact hv ⟨w, hw⟩ #align submodule.orthogonal_eq_inter Submodule.orthogonal_eq_inter /-- The orthogonal complement of any submodule `K` is closed. -/ theorem isClosed_orthogonal : IsClosed (Kᗮ : Set E) := by rw [orthogonal_eq_inter K] have := fun v : K => ContinuousLinearMap.isClosed_ker (innerSL 𝕜 (v : E)) convert isClosed_iInter this simp only [iInf_coe] #align submodule.is_closed_orthogonal Submodule.isClosed_orthogonal /-- In a complete space, the orthogonal complement of any submodule `K` is complete. -/ instance instOrthogonalCompleteSpace [CompleteSpace E] : CompleteSpace Kᗮ := K.isClosed_orthogonal.completeSpace_coe variable (𝕜 E) /-- `orthogonal` gives a `GaloisConnection` between `Submodule 𝕜 E` and its `OrderDual`. -/ theorem orthogonal_gc : @GaloisConnection (Submodule 𝕜 E) (Submodule 𝕜 E)ᵒᵈ _ _ orthogonal orthogonal := fun _K₁ _K₂ => ⟨fun h _v hv _u hu => inner_left_of_mem_orthogonal hv (h hu), fun h _v hv _u hu => inner_left_of_mem_orthogonal hv (h hu)⟩ #align submodule.orthogonal_gc Submodule.orthogonal_gc variable {𝕜 E} /-- `orthogonal` reverses the `≤` ordering of two subspaces. -/ theorem orthogonal_le {K₁ K₂ : Submodule 𝕜 E} (h : K₁ ≤ K₂) : K₂ᗮ ≤ K₁ᗮ := (orthogonal_gc 𝕜 E).monotone_l h #align submodule.orthogonal_le Submodule.orthogonal_le /-- `orthogonal.orthogonal` preserves the `≤` ordering of two subspaces. -/ theorem orthogonal_orthogonal_monotone {K₁ K₂ : Submodule 𝕜 E} (h : K₁ ≤ K₂) : K₁ᗮᗮ ≤ K₂ᗮᗮ := orthogonal_le (orthogonal_le h) #align submodule.orthogonal_orthogonal_monotone Submodule.orthogonal_orthogonal_monotone /-- `K` is contained in `Kᗮᗮ`. -/ theorem le_orthogonal_orthogonal : K ≤ Kᗮᗮ := (orthogonal_gc 𝕜 E).le_u_l _ #align submodule.le_orthogonal_orthogonal Submodule.le_orthogonal_orthogonal /-- The inf of two orthogonal subspaces equals the subspace orthogonal to the sup. -/ theorem inf_orthogonal (K₁ K₂ : Submodule 𝕜 E) : K₁ᗮ ⊓ K₂ᗮ = (K₁ ⊔ K₂)ᗮ := (orthogonal_gc 𝕜 E).l_sup.symm #align submodule.inf_orthogonal Submodule.inf_orthogonal /-- The inf of an indexed family of orthogonal subspaces equals the subspace orthogonal to the sup. -/ theorem iInf_orthogonal {ι : Type*} (K : ι → Submodule 𝕜 E) : ⨅ i, (K i)ᗮ = (iSup K)ᗮ := (orthogonal_gc 𝕜 E).l_iSup.symm #align submodule.infi_orthogonal Submodule.iInf_orthogonal /-- The inf of a set of orthogonal subspaces equals the subspace orthogonal to the sup. -/ theorem sInf_orthogonal (s : Set <| Submodule 𝕜 E) : ⨅ K ∈ s, Kᗮ = (sSup s)ᗮ := (orthogonal_gc 𝕜 E).l_sSup.symm #align submodule.Inf_orthogonal Submodule.sInf_orthogonal @[simp] theorem top_orthogonal_eq_bot : (⊤ : Submodule 𝕜 E)ᗮ = ⊥ := by ext x rw [mem_bot, mem_orthogonal] exact ⟨fun h => inner_self_eq_zero.mp (h x mem_top), by rintro rfl simp⟩ #align submodule.top_orthogonal_eq_bot Submodule.top_orthogonal_eq_bot @[simp]
Mathlib/Analysis/InnerProductSpace/Orthogonal.lean
195
197
theorem bot_orthogonal_eq_top : (⊥ : Submodule 𝕜 E)ᗮ = ⊤ := by
rw [← top_orthogonal_eq_bot, eq_top_iff] exact le_orthogonal_orthogonal ⊤
/- 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⟩
Mathlib/Topology/Separation.lean
941
945
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
/- Copyright (c) 2020 Kexing Ying and Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying, Kevin Buzzard, Yury Kudryashov -/ import Mathlib.Algebra.BigOperators.GroupWithZero.Finset import Mathlib.Algebra.Group.FiniteSupport import Mathlib.Algebra.Module.Defs import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Data.Set.Subsingleton #align_import algebra.big_operators.finprod from "leanprover-community/mathlib"@"d6fad0e5bf2d6f48da9175d25c3dc5706b3834ce" /-! # Finite products and sums over types and sets We define products and sums over types and subsets of types, with no finiteness hypotheses. All infinite products and sums are defined to be junk values (i.e. one or zero). This approach is sometimes easier to use than `Finset.sum`, when issues arise with `Finset` and `Fintype` being data. ## Main definitions We use the following variables: * `α`, `β` - types with no structure; * `s`, `t` - sets * `M`, `N` - additive or multiplicative commutative monoids * `f`, `g` - functions Definitions in this file: * `finsum f : M` : the sum of `f x` as `x` ranges over the support of `f`, if it's finite. Zero otherwise. * `finprod f : M` : the product of `f x` as `x` ranges over the multiplicative support of `f`, if it's finite. One otherwise. ## Notation * `∑ᶠ i, f i` and `∑ᶠ i : α, f i` for `finsum f` * `∏ᶠ i, f i` and `∏ᶠ i : α, f i` for `finprod f` This notation works for functions `f : p → M`, where `p : Prop`, so the following works: * `∑ᶠ i ∈ s, f i`, where `f : α → M`, `s : Set α` : sum over the set `s`; * `∑ᶠ n < 5, f n`, where `f : ℕ → M` : same as `f 0 + f 1 + f 2 + f 3 + f 4`; * `∏ᶠ (n >= -2) (hn : n < 3), f n`, where `f : ℤ → M` : same as `f (-2) * f (-1) * f 0 * f 1 * f 2`. ## Implementation notes `finsum` and `finprod` is "yet another way of doing finite sums and products in Lean". However experiments in the wild (e.g. with matroids) indicate that it is a helpful approach in settings where the user is not interested in computability and wants to do reasoning without running into typeclass diamonds caused by the constructive finiteness used in definitions such as `Finset` and `Fintype`. By sticking solely to `Set.Finite` we avoid these problems. We are aware that there are other solutions but for beginner mathematicians this approach is easier in practice. Another application is the construction of a partition of unity from a collection of “bump” function. In this case the finite set depends on the point and it's convenient to have a definition that does not mention the set explicitly. The first arguments in all definitions and lemmas is the codomain of the function of the big operator. This is necessary for the heuristic in `@[to_additive]`. See the documentation of `to_additive.attr` for more information. We did not add `IsFinite (X : Type) : Prop`, because it is simply `Nonempty (Fintype X)`. ## Tags finsum, finprod, finite sum, finite product -/ open Function Set /-! ### Definition and relation to `Finset.sum` and `Finset.prod` -/ -- Porting note: Used to be section Sort section sort variable {G M N : Type*} {α β ι : Sort*} [CommMonoid M] [CommMonoid N] section /- Note: we use classical logic only for these definitions, to ensure that we do not write lemmas with `Classical.dec` in their statement. -/ open scoped Classical /-- Sum of `f x` as `x` ranges over the elements of the support of `f`, if it's finite. Zero otherwise. -/ noncomputable irreducible_def finsum (lemma := finsum_def') [AddCommMonoid M] (f : α → M) : M := if h : (support (f ∘ PLift.down)).Finite then ∑ i ∈ h.toFinset, f i.down else 0 #align finsum finsum /-- Product of `f x` as `x` ranges over the elements of the multiplicative support of `f`, if it's finite. One otherwise. -/ @[to_additive existing] noncomputable irreducible_def finprod (lemma := finprod_def') (f : α → M) : M := if h : (mulSupport (f ∘ PLift.down)).Finite then ∏ i ∈ h.toFinset, f i.down else 1 #align finprod finprod attribute [to_additive existing] finprod_def' end open Batteries.ExtendedBinder /-- `∑ᶠ x, f x` is notation for `finsum f`. It is the sum of `f x`, where `x` ranges over the support of `f`, if it's finite, zero otherwise. Taking the sum over multiple arguments or conditions is possible, e.g. `∏ᶠ (x) (y), f x y` and `∏ᶠ (x) (h: x ∈ s), f x`-/ notation3"∑ᶠ "(...)", "r:67:(scoped f => finsum f) => r /-- `∏ᶠ x, f x` is notation for `finprod f`. It is the product of `f x`, where `x` ranges over the multiplicative support of `f`, if it's finite, one otherwise. Taking the product over multiple arguments or conditions is possible, e.g. `∏ᶠ (x) (y), f x y` and `∏ᶠ (x) (h: x ∈ s), f x`-/ notation3"∏ᶠ "(...)", "r:67:(scoped f => finprod f) => r -- Porting note: The following ports the lean3 notation for this file, but is currently very fickle. -- syntax (name := bigfinsum) "∑ᶠ" extBinders ", " term:67 : term -- macro_rules (kind := bigfinsum) -- | `(∑ᶠ $x:ident, $p) => `(finsum (fun $x:ident ↦ $p)) -- | `(∑ᶠ $x:ident : $t, $p) => `(finsum (fun $x:ident : $t ↦ $p)) -- | `(∑ᶠ $x:ident $b:binderPred, $p) => -- `(finsum fun $x => (finsum (α := satisfies_binder_pred% $x $b) (fun _ => $p))) -- | `(∑ᶠ ($x:ident) ($h:ident : $t), $p) => -- `(finsum fun ($x) => finsum (α := $t) (fun $h => $p)) -- | `(∑ᶠ ($x:ident : $_) ($h:ident : $t), $p) => -- `(finsum fun ($x) => finsum (α := $t) (fun $h => $p)) -- | `(∑ᶠ ($x:ident) ($y:ident), $p) => -- `(finsum fun $x => (finsum fun $y => $p)) -- | `(∑ᶠ ($x:ident) ($y:ident) ($h:ident : $t), $p) => -- `(finsum fun $x => (finsum fun $y => (finsum (α := $t) fun $h => $p))) -- | `(∑ᶠ ($x:ident) ($y:ident) ($z:ident), $p) => -- `(finsum fun $x => (finsum fun $y => (finsum fun $z => $p))) -- | `(∑ᶠ ($x:ident) ($y:ident) ($z:ident) ($h:ident : $t), $p) => -- `(finsum fun $x => (finsum fun $y => (finsum fun $z => (finsum (α := $t) fun $h => $p)))) -- -- -- syntax (name := bigfinprod) "∏ᶠ " extBinders ", " term:67 : term -- macro_rules (kind := bigfinprod) -- | `(∏ᶠ $x:ident, $p) => `(finprod (fun $x:ident ↦ $p)) -- | `(∏ᶠ $x:ident : $t, $p) => `(finprod (fun $x:ident : $t ↦ $p)) -- | `(∏ᶠ $x:ident $b:binderPred, $p) => -- `(finprod fun $x => (finprod (α := satisfies_binder_pred% $x $b) (fun _ => $p))) -- | `(∏ᶠ ($x:ident) ($h:ident : $t), $p) => -- `(finprod fun ($x) => finprod (α := $t) (fun $h => $p)) -- | `(∏ᶠ ($x:ident : $_) ($h:ident : $t), $p) => -- `(finprod fun ($x) => finprod (α := $t) (fun $h => $p)) -- | `(∏ᶠ ($x:ident) ($y:ident), $p) => -- `(finprod fun $x => (finprod fun $y => $p)) -- | `(∏ᶠ ($x:ident) ($y:ident) ($h:ident : $t), $p) => -- `(finprod fun $x => (finprod fun $y => (finprod (α := $t) fun $h => $p))) -- | `(∏ᶠ ($x:ident) ($y:ident) ($z:ident), $p) => -- `(finprod fun $x => (finprod fun $y => (finprod fun $z => $p))) -- | `(∏ᶠ ($x:ident) ($y:ident) ($z:ident) ($h:ident : $t), $p) => -- `(finprod fun $x => (finprod fun $y => (finprod fun $z => -- (finprod (α := $t) fun $h => $p)))) @[to_additive] theorem finprod_eq_prod_plift_of_mulSupport_toFinset_subset {f : α → M} (hf : (mulSupport (f ∘ PLift.down)).Finite) {s : Finset (PLift α)} (hs : hf.toFinset ⊆ s) : ∏ᶠ i, f i = ∏ i ∈ s, f i.down := by rw [finprod, dif_pos] refine Finset.prod_subset hs fun x _ hxf => ?_ rwa [hf.mem_toFinset, nmem_mulSupport] at hxf #align finprod_eq_prod_plift_of_mul_support_to_finset_subset finprod_eq_prod_plift_of_mulSupport_toFinset_subset #align finsum_eq_sum_plift_of_support_to_finset_subset finsum_eq_sum_plift_of_support_toFinset_subset @[to_additive] theorem finprod_eq_prod_plift_of_mulSupport_subset {f : α → M} {s : Finset (PLift α)} (hs : mulSupport (f ∘ PLift.down) ⊆ s) : ∏ᶠ i, f i = ∏ i ∈ s, f i.down := finprod_eq_prod_plift_of_mulSupport_toFinset_subset (s.finite_toSet.subset hs) fun x hx => by rw [Finite.mem_toFinset] at hx exact hs hx #align finprod_eq_prod_plift_of_mul_support_subset finprod_eq_prod_plift_of_mulSupport_subset #align finsum_eq_sum_plift_of_support_subset finsum_eq_sum_plift_of_support_subset @[to_additive (attr := simp)] theorem finprod_one : (∏ᶠ _ : α, (1 : M)) = 1 := by have : (mulSupport fun x : PLift α => (fun _ => 1 : α → M) x.down) ⊆ (∅ : Finset (PLift α)) := fun x h => by simp at h rw [finprod_eq_prod_plift_of_mulSupport_subset this, Finset.prod_empty] #align finprod_one finprod_one #align finsum_zero finsum_zero @[to_additive] theorem finprod_of_isEmpty [IsEmpty α] (f : α → M) : ∏ᶠ i, f i = 1 := by rw [← finprod_one] congr simp [eq_iff_true_of_subsingleton] #align finprod_of_is_empty finprod_of_isEmpty #align finsum_of_is_empty finsum_of_isEmpty @[to_additive (attr := simp)] theorem finprod_false (f : False → M) : ∏ᶠ i, f i = 1 := finprod_of_isEmpty _ #align finprod_false finprod_false #align finsum_false finsum_false @[to_additive] theorem finprod_eq_single (f : α → M) (a : α) (ha : ∀ x, x ≠ a → f x = 1) : ∏ᶠ x, f x = f a := by have : mulSupport (f ∘ PLift.down) ⊆ ({PLift.up a} : Finset (PLift α)) := by intro x contrapose simpa [PLift.eq_up_iff_down_eq] using ha x.down rw [finprod_eq_prod_plift_of_mulSupport_subset this, Finset.prod_singleton] #align finprod_eq_single finprod_eq_single #align finsum_eq_single finsum_eq_single @[to_additive] theorem finprod_unique [Unique α] (f : α → M) : ∏ᶠ i, f i = f default := finprod_eq_single f default fun _x hx => (hx <| Unique.eq_default _).elim #align finprod_unique finprod_unique #align finsum_unique finsum_unique @[to_additive (attr := simp)] theorem finprod_true (f : True → M) : ∏ᶠ i, f i = f trivial := @finprod_unique M True _ ⟨⟨trivial⟩, fun _ => rfl⟩ f #align finprod_true finprod_true #align finsum_true finsum_true @[to_additive] theorem finprod_eq_dif {p : Prop} [Decidable p] (f : p → M) : ∏ᶠ i, f i = if h : p then f h else 1 := by split_ifs with h · haveI : Unique p := ⟨⟨h⟩, fun _ => rfl⟩ exact finprod_unique f · haveI : IsEmpty p := ⟨h⟩ exact finprod_of_isEmpty f #align finprod_eq_dif finprod_eq_dif #align finsum_eq_dif finsum_eq_dif @[to_additive] theorem finprod_eq_if {p : Prop} [Decidable p] {x : M} : ∏ᶠ _ : p, x = if p then x else 1 := finprod_eq_dif fun _ => x #align finprod_eq_if finprod_eq_if #align finsum_eq_if finsum_eq_if @[to_additive] theorem finprod_congr {f g : α → M} (h : ∀ x, f x = g x) : finprod f = finprod g := congr_arg _ <| funext h #align finprod_congr finprod_congr #align finsum_congr finsum_congr @[to_additive (attr := congr)] theorem finprod_congr_Prop {p q : Prop} {f : p → M} {g : q → M} (hpq : p = q) (hfg : ∀ h : q, f (hpq.mpr h) = g h) : finprod f = finprod g := by subst q exact finprod_congr hfg #align finprod_congr_Prop finprod_congr_Prop #align finsum_congr_Prop finsum_congr_Prop /-- To prove a property of a finite product, it suffices to prove that the property is multiplicative and holds on the factors. -/ @[to_additive "To prove a property of a finite sum, it suffices to prove that the property is additive and holds on the summands."] theorem finprod_induction {f : α → M} (p : M → Prop) (hp₀ : p 1) (hp₁ : ∀ x y, p x → p y → p (x * y)) (hp₂ : ∀ i, p (f i)) : p (∏ᶠ i, f i) := by rw [finprod] split_ifs exacts [Finset.prod_induction _ _ hp₁ hp₀ fun i _ => hp₂ _, hp₀] #align finprod_induction finprod_induction #align finsum_induction finsum_induction theorem finprod_nonneg {R : Type*} [OrderedCommSemiring R] {f : α → R} (hf : ∀ x, 0 ≤ f x) : 0 ≤ ∏ᶠ x, f x := finprod_induction (fun x => 0 ≤ x) zero_le_one (fun _ _ => mul_nonneg) hf #align finprod_nonneg finprod_nonneg @[to_additive finsum_nonneg] theorem one_le_finprod' {M : Type*} [OrderedCommMonoid M] {f : α → M} (hf : ∀ i, 1 ≤ f i) : 1 ≤ ∏ᶠ i, f i := finprod_induction _ le_rfl (fun _ _ => one_le_mul) hf #align one_le_finprod' one_le_finprod' #align finsum_nonneg finsum_nonneg @[to_additive] theorem MonoidHom.map_finprod_plift (f : M →* N) (g : α → M) (h : (mulSupport <| g ∘ PLift.down).Finite) : f (∏ᶠ x, g x) = ∏ᶠ x, f (g x) := by rw [finprod_eq_prod_plift_of_mulSupport_subset h.coe_toFinset.ge, finprod_eq_prod_plift_of_mulSupport_subset, map_prod] rw [h.coe_toFinset] exact mulSupport_comp_subset f.map_one (g ∘ PLift.down) #align monoid_hom.map_finprod_plift MonoidHom.map_finprod_plift #align add_monoid_hom.map_finsum_plift AddMonoidHom.map_finsum_plift @[to_additive] theorem MonoidHom.map_finprod_Prop {p : Prop} (f : M →* N) (g : p → M) : f (∏ᶠ x, g x) = ∏ᶠ x, f (g x) := f.map_finprod_plift g (Set.toFinite _) #align monoid_hom.map_finprod_Prop MonoidHom.map_finprod_Prop #align add_monoid_hom.map_finsum_Prop AddMonoidHom.map_finsum_Prop @[to_additive] theorem MonoidHom.map_finprod_of_preimage_one (f : M →* N) (hf : ∀ x, f x = 1 → x = 1) (g : α → M) : f (∏ᶠ i, g i) = ∏ᶠ i, f (g i) := by by_cases hg : (mulSupport <| g ∘ PLift.down).Finite; · exact f.map_finprod_plift g hg rw [finprod, dif_neg, f.map_one, finprod, dif_neg] exacts [Infinite.mono (fun x hx => mt (hf (g x.down)) hx) hg, hg] #align monoid_hom.map_finprod_of_preimage_one MonoidHom.map_finprod_of_preimage_one #align add_monoid_hom.map_finsum_of_preimage_zero AddMonoidHom.map_finsum_of_preimage_zero @[to_additive] theorem MonoidHom.map_finprod_of_injective (g : M →* N) (hg : Injective g) (f : α → M) : g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) := g.map_finprod_of_preimage_one (fun _ => (hg.eq_iff' g.map_one).mp) f #align monoid_hom.map_finprod_of_injective MonoidHom.map_finprod_of_injective #align add_monoid_hom.map_finsum_of_injective AddMonoidHom.map_finsum_of_injective @[to_additive] theorem MulEquiv.map_finprod (g : M ≃* N) (f : α → M) : g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) := g.toMonoidHom.map_finprod_of_injective (EquivLike.injective g) f #align mul_equiv.map_finprod MulEquiv.map_finprod #align add_equiv.map_finsum AddEquiv.map_finsum /-- The `NoZeroSMulDivisors` makes sure that the result holds even when the support of `f` is infinite. For a more usual version assuming `(support f).Finite` instead, see `finsum_smul'`. -/ theorem finsum_smul {R M : Type*} [Ring R] [AddCommGroup M] [Module R M] [NoZeroSMulDivisors R M] (f : ι → R) (x : M) : (∑ᶠ i, f i) • x = ∑ᶠ i, f i • x := by rcases eq_or_ne x 0 with (rfl | hx) · simp · exact ((smulAddHom R M).flip x).map_finsum_of_injective (smul_left_injective R hx) _ #align finsum_smul finsum_smul /-- The `NoZeroSMulDivisors` makes sure that the result holds even when the support of `f` is infinite. For a more usual version assuming `(support f).Finite` instead, see `smul_finsum'`. -/ theorem smul_finsum {R M : Type*} [Ring R] [AddCommGroup M] [Module R M] [NoZeroSMulDivisors R M] (c : R) (f : ι → M) : (c • ∑ᶠ i, f i) = ∑ᶠ i, c • f i := by rcases eq_or_ne c 0 with (rfl | hc) · simp · exact (smulAddHom R M c).map_finsum_of_injective (smul_right_injective M hc) _ #align smul_finsum smul_finsum @[to_additive] theorem finprod_inv_distrib [DivisionCommMonoid G] (f : α → G) : (∏ᶠ x, (f x)⁻¹) = (∏ᶠ x, f x)⁻¹ := ((MulEquiv.inv G).map_finprod f).symm #align finprod_inv_distrib finprod_inv_distrib #align finsum_neg_distrib finsum_neg_distrib end sort -- Porting note: Used to be section Type section type variable {α β ι G M N : Type*} [CommMonoid M] [CommMonoid N] @[to_additive] theorem finprod_eq_mulIndicator_apply (s : Set α) (f : α → M) (a : α) : ∏ᶠ _ : a ∈ s, f a = mulIndicator s f a := by classical convert finprod_eq_if (M := M) (p := a ∈ s) (x := f a) #align finprod_eq_mul_indicator_apply finprod_eq_mulIndicator_apply #align finsum_eq_indicator_apply finsum_eq_indicator_apply @[to_additive (attr := simp)] theorem finprod_mem_mulSupport (f : α → M) (a : α) : ∏ᶠ _ : f a ≠ 1, f a = f a := by rw [← mem_mulSupport, finprod_eq_mulIndicator_apply, mulIndicator_mulSupport] #align finprod_mem_mul_support finprod_mem_mulSupport #align finsum_mem_support finsum_mem_support @[to_additive] theorem finprod_mem_def (s : Set α) (f : α → M) : ∏ᶠ a ∈ s, f a = ∏ᶠ a, mulIndicator s f a := finprod_congr <| finprod_eq_mulIndicator_apply s f #align finprod_mem_def finprod_mem_def #align finsum_mem_def finsum_mem_def @[to_additive] theorem finprod_eq_prod_of_mulSupport_subset (f : α → M) {s : Finset α} (h : mulSupport f ⊆ s) : ∏ᶠ i, f i = ∏ i ∈ s, f i := by have A : mulSupport (f ∘ PLift.down) = Equiv.plift.symm '' mulSupport f := by rw [mulSupport_comp_eq_preimage] exact (Equiv.plift.symm.image_eq_preimage _).symm have : mulSupport (f ∘ PLift.down) ⊆ s.map Equiv.plift.symm.toEmbedding := by rw [A, Finset.coe_map] exact image_subset _ h rw [finprod_eq_prod_plift_of_mulSupport_subset this] simp only [Finset.prod_map, Equiv.coe_toEmbedding] congr #align finprod_eq_prod_of_mul_support_subset finprod_eq_prod_of_mulSupport_subset #align finsum_eq_sum_of_support_subset finsum_eq_sum_of_support_subset @[to_additive] theorem finprod_eq_prod_of_mulSupport_toFinset_subset (f : α → M) (hf : (mulSupport f).Finite) {s : Finset α} (h : hf.toFinset ⊆ s) : ∏ᶠ i, f i = ∏ i ∈ s, f i := finprod_eq_prod_of_mulSupport_subset _ fun _ hx => h <| hf.mem_toFinset.2 hx #align finprod_eq_prod_of_mul_support_to_finset_subset finprod_eq_prod_of_mulSupport_toFinset_subset #align finsum_eq_sum_of_support_to_finset_subset finsum_eq_sum_of_support_toFinset_subset @[to_additive] theorem finprod_eq_finset_prod_of_mulSupport_subset (f : α → M) {s : Finset α} (h : mulSupport f ⊆ (s : Set α)) : ∏ᶠ i, f i = ∏ i ∈ s, f i := haveI h' : (s.finite_toSet.subset h).toFinset ⊆ s := by simpa [← Finset.coe_subset, Set.coe_toFinset] finprod_eq_prod_of_mulSupport_toFinset_subset _ _ h' #align finprod_eq_finset_prod_of_mul_support_subset finprod_eq_finset_prod_of_mulSupport_subset #align finsum_eq_finset_sum_of_support_subset finsum_eq_finset_sum_of_support_subset @[to_additive] theorem finprod_def (f : α → M) [Decidable (mulSupport f).Finite] : ∏ᶠ i : α, f i = if h : (mulSupport f).Finite then ∏ i ∈ h.toFinset, f i else 1 := by split_ifs with h · exact finprod_eq_prod_of_mulSupport_toFinset_subset _ h (Finset.Subset.refl _) · rw [finprod, dif_neg] rw [mulSupport_comp_eq_preimage] exact mt (fun hf => hf.of_preimage Equiv.plift.surjective) h #align finprod_def finprod_def #align finsum_def finsum_def @[to_additive] theorem finprod_of_infinite_mulSupport {f : α → M} (hf : (mulSupport f).Infinite) : ∏ᶠ i, f i = 1 := by classical rw [finprod_def, dif_neg hf] #align finprod_of_infinite_mul_support finprod_of_infinite_mulSupport #align finsum_of_infinite_support finsum_of_infinite_support @[to_additive] theorem finprod_eq_prod (f : α → M) (hf : (mulSupport f).Finite) : ∏ᶠ i : α, f i = ∏ i ∈ hf.toFinset, f i := by classical rw [finprod_def, dif_pos hf] #align finprod_eq_prod finprod_eq_prod #align finsum_eq_sum finsum_eq_sum @[to_additive] theorem finprod_eq_prod_of_fintype [Fintype α] (f : α → M) : ∏ᶠ i : α, f i = ∏ i, f i := finprod_eq_prod_of_mulSupport_toFinset_subset _ (Set.toFinite _) <| Finset.subset_univ _ #align finprod_eq_prod_of_fintype finprod_eq_prod_of_fintype #align finsum_eq_sum_of_fintype finsum_eq_sum_of_fintype @[to_additive]
Mathlib/Algebra/BigOperators/Finprod.lean
440
450
theorem finprod_cond_eq_prod_of_cond_iff (f : α → M) {p : α → Prop} {t : Finset α} (h : ∀ {x}, f x ≠ 1 → (p x ↔ x ∈ t)) : (∏ᶠ (i) (_ : p i), f i) = ∏ i ∈ t, f i := by
set s := { x | p x } have : mulSupport (s.mulIndicator f) ⊆ t := by rw [Set.mulSupport_mulIndicator] intro x hx exact (h hx.2).1 hx.1 erw [finprod_mem_def, finprod_eq_prod_of_mulSupport_subset _ this] refine Finset.prod_congr rfl fun x hx => mulIndicator_apply_eq_self.2 fun hxs => ?_ contrapose! hxs exact (h hxs).2 hx
/- 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`
Mathlib/Algebra/Group/Subgroup/Basic.lean
738
738
theorem mk_eq_one {g : G} {h} : (⟨g, h⟩ : H) = 1 ↔ g = 1 := by
simp