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 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nicolò Cavalleri, Sebastien Gouezel, Heather Macbeth, Patrick Massot, Floris van Doorn -/ import Mathlib.Analysis.NormedSpace.BoundedLinearMaps import Mathlib.Topology.FiberBundle.Basic #align_import topology.vector_bundle.basic from "leanprover-community/mathlib"@"e473c3198bb41f68560cab68a0529c854b618833" /-! # Vector bundles In this file we define (topological) vector bundles. Let `B` be the base space, let `F` be a normed space over a normed field `R`, and let `E : B → Type*` be a `FiberBundle` with fiber `F`, in which, for each `x`, the fiber `E x` is a topological vector space over `R`. To have a vector bundle structure on `Bundle.TotalSpace F E`, one should additionally have the following properties: * The bundle trivializations in the trivialization atlas should be continuous linear equivs in the fibers; * For any two trivializations `e`, `e'` in the atlas the transition function considered as a map from `B` into `F →L[R] F` is continuous on `e.baseSet ∩ e'.baseSet` with respect to the operator norm topology on `F →L[R] F`. If these conditions are satisfied, we register the typeclass `VectorBundle R F E`. We define constructions on vector bundles like pullbacks and direct sums in other files. ## Main Definitions * `Trivialization.IsLinear`: a class stating that a trivialization is fiberwise linear on its base set. * `Trivialization.linearEquivAt` and `Trivialization.continuousLinearMapAt` are the (continuous) linear fiberwise equivalences a trivialization induces. * They have forward maps `Trivialization.linearMapAt` / `Trivialization.continuousLinearMapAt` and inverses `Trivialization.symmₗ` / `Trivialization.symmL`. Note that these are all defined everywhere, since they are extended using the zero function. * `Trivialization.coordChangeL` is the coordinate change induced by two trivializations. It only makes sense on the intersection of their base sets, but is extended outside it using the identity. * Given a continuous (semi)linear map between `E x` and `E' y` where `E` and `E'` are bundles over possibly different base sets, `ContinuousLinearMap.inCoordinates` turns this into a continuous (semi)linear map between the chosen fibers of those bundles. ## Implementation notes The implementation choices in the vector bundle definition are discussed in the "Implementation notes" section of `Mathlib.Topology.FiberBundle.Basic`. ## Tags Vector bundle -/ noncomputable section open scoped Classical open Bundle Set open scoped Topology variable (R : Type*) {B : Type*} (F : Type*) (E : B → Type*) section TopologicalVectorSpace variable {F E} variable [Semiring R] [TopologicalSpace F] [TopologicalSpace B] /-- A mixin class for `Pretrivialization`, stating that a pretrivialization is fiberwise linear with respect to given module structures on its fibers and the model fiber. -/ protected class Pretrivialization.IsLinear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] (e : Pretrivialization F (π F E)) : Prop where linear : ∀ b ∈ e.baseSet, IsLinearMap R fun x : E b => (e ⟨b, x⟩).2 #align pretrivialization.is_linear Pretrivialization.IsLinear namespace Pretrivialization variable (e : Pretrivialization F (π F E)) {x : TotalSpace F E} {b : B} {y : E b} theorem linear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : IsLinearMap R fun x : E b => (e ⟨b, x⟩).2 := Pretrivialization.IsLinear.linear b hb #align pretrivialization.linear Pretrivialization.linear variable [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] /-- A fiberwise linear inverse to `e`. -/ @[simps!] protected def symmₗ (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) : F →ₗ[R] E b := by refine IsLinearMap.mk' (e.symm b) ?_ by_cases hb : b ∈ e.baseSet · exact (((e.linear R hb).mk' _).inverse (e.symm b) (e.symm_apply_apply_mk hb) fun v ↦ congr_arg Prod.snd <| e.apply_mk_symm hb v).isLinear · rw [e.coe_symm_of_not_mem hb] exact (0 : F →ₗ[R] E b).isLinear #align pretrivialization.symmₗ Pretrivialization.symmₗ /-- A pretrivialization for a vector bundle defines linear equivalences between the fibers and the model space. -/ @[simps (config := .asFn)] def linearEquivAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) : E b ≃ₗ[R] F where toFun y := (e ⟨b, y⟩).2 invFun := e.symm b left_inv := e.symm_apply_apply_mk hb right_inv v := by simp_rw [e.apply_mk_symm hb v] map_add' v w := (e.linear R hb).map_add v w map_smul' c v := (e.linear R hb).map_smul c v #align pretrivialization.linear_equiv_at Pretrivialization.linearEquivAt /-- A fiberwise linear map equal to `e` on `e.baseSet`. -/ protected def linearMapAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) : E b →ₗ[R] F := if hb : b ∈ e.baseSet then e.linearEquivAt R b hb else 0 #align pretrivialization.linear_map_at Pretrivialization.linearMapAt variable {R} theorem coe_linearMapAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) : ⇑(e.linearMapAt R b) = fun y => if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := by rw [Pretrivialization.linearMapAt] split_ifs <;> rfl #align pretrivialization.coe_linear_map_at Pretrivialization.coe_linearMapAt theorem coe_linearMapAt_of_mem (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : ⇑(e.linearMapAt R b) = fun y => (e ⟨b, y⟩).2 := by simp_rw [coe_linearMapAt, if_pos hb] #align pretrivialization.coe_linear_map_at_of_mem Pretrivialization.coe_linearMapAt_of_mem theorem linearMapAt_apply (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (y : E b) : e.linearMapAt R b y = if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := by rw [coe_linearMapAt] #align pretrivialization.linear_map_at_apply Pretrivialization.linearMapAt_apply theorem linearMapAt_def_of_mem (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : e.linearMapAt R b = e.linearEquivAt R b hb := dif_pos hb #align pretrivialization.linear_map_at_def_of_mem Pretrivialization.linearMapAt_def_of_mem theorem linearMapAt_def_of_not_mem (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∉ e.baseSet) : e.linearMapAt R b = 0 := dif_neg hb #align pretrivialization.linear_map_at_def_of_not_mem Pretrivialization.linearMapAt_def_of_not_mem theorem linearMapAt_eq_zero (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∉ e.baseSet) : e.linearMapAt R b = 0 := dif_neg hb #align pretrivialization.linear_map_at_eq_zero Pretrivialization.linearMapAt_eq_zero theorem symmₗ_linearMapAt (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) (y : E b) : e.symmₗ R b (e.linearMapAt R b y) = y := by rw [e.linearMapAt_def_of_mem hb] exact (e.linearEquivAt R b hb).left_inv y #align pretrivialization.symmₗ_linear_map_at Pretrivialization.symmₗ_linearMapAt theorem linearMapAt_symmₗ (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) (y : F) : e.linearMapAt R b (e.symmₗ R b y) = y := by rw [e.linearMapAt_def_of_mem hb] exact (e.linearEquivAt R b hb).right_inv y #align pretrivialization.linear_map_at_symmₗ Pretrivialization.linearMapAt_symmₗ end Pretrivialization variable [TopologicalSpace (TotalSpace F E)] /-- A mixin class for `Trivialization`, stating that a trivialization is fiberwise linear with respect to given module structures on its fibers and the model fiber. -/ protected class Trivialization.IsLinear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] (e : Trivialization F (π F E)) : Prop where linear : ∀ b ∈ e.baseSet, IsLinearMap R fun x : E b => (e ⟨b, x⟩).2 #align trivialization.is_linear Trivialization.IsLinear namespace Trivialization variable (e : Trivialization F (π F E)) {x : TotalSpace F E} {b : B} {y : E b} protected theorem linear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : IsLinearMap R fun y : E b => (e ⟨b, y⟩).2 := Trivialization.IsLinear.linear b hb #align trivialization.linear Trivialization.linear instance toPretrivialization.isLinear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] [e.IsLinear R] : e.toPretrivialization.IsLinear R := { (‹_› : e.IsLinear R) with } #align trivialization.to_pretrivialization.is_linear Trivialization.toPretrivialization.isLinear variable [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] /-- A trivialization for a vector bundle defines linear equivalences between the fibers and the model space. -/ def linearEquivAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) : E b ≃ₗ[R] F := e.toPretrivialization.linearEquivAt R b hb #align trivialization.linear_equiv_at Trivialization.linearEquivAt variable {R} @[simp] theorem linearEquivAt_apply (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) (v : E b) : e.linearEquivAt R b hb v = (e ⟨b, v⟩).2 := rfl #align trivialization.linear_equiv_at_apply Trivialization.linearEquivAt_apply @[simp] theorem linearEquivAt_symm_apply (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) (v : F) : (e.linearEquivAt R b hb).symm v = e.symm b v := rfl #align trivialization.linear_equiv_at_symm_apply Trivialization.linearEquivAt_symm_apply variable (R) /-- A fiberwise linear inverse to `e`. -/ protected def symmₗ (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : F →ₗ[R] E b := e.toPretrivialization.symmₗ R b #align trivialization.symmₗ Trivialization.symmₗ variable {R} theorem coe_symmₗ (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : ⇑(e.symmₗ R b) = e.symm b := rfl #align trivialization.coe_symmₗ Trivialization.coe_symmₗ variable (R) /-- A fiberwise linear map equal to `e` on `e.baseSet`. -/ protected def linearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : E b →ₗ[R] F := e.toPretrivialization.linearMapAt R b #align trivialization.linear_map_at Trivialization.linearMapAt variable {R} theorem coe_linearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : ⇑(e.linearMapAt R b) = fun y => if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := e.toPretrivialization.coe_linearMapAt b #align trivialization.coe_linear_map_at Trivialization.coe_linearMapAt theorem coe_linearMapAt_of_mem (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : ⇑(e.linearMapAt R b) = fun y => (e ⟨b, y⟩).2 := by simp_rw [coe_linearMapAt, if_pos hb] #align trivialization.coe_linear_map_at_of_mem Trivialization.coe_linearMapAt_of_mem theorem linearMapAt_apply (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (y : E b) : e.linearMapAt R b y = if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := by rw [coe_linearMapAt] #align trivialization.linear_map_at_apply Trivialization.linearMapAt_apply theorem linearMapAt_def_of_mem (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : e.linearMapAt R b = e.linearEquivAt R b hb := dif_pos hb #align trivialization.linear_map_at_def_of_mem Trivialization.linearMapAt_def_of_mem theorem linearMapAt_def_of_not_mem (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∉ e.baseSet) : e.linearMapAt R b = 0 := dif_neg hb #align trivialization.linear_map_at_def_of_not_mem Trivialization.linearMapAt_def_of_not_mem theorem symmₗ_linearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) (y : E b) : e.symmₗ R b (e.linearMapAt R b y) = y := e.toPretrivialization.symmₗ_linearMapAt hb y #align trivialization.symmₗ_linear_map_at Trivialization.symmₗ_linearMapAt theorem linearMapAt_symmₗ (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) (y : F) : e.linearMapAt R b (e.symmₗ R b y) = y := e.toPretrivialization.linearMapAt_symmₗ hb y #align trivialization.linear_map_at_symmₗ Trivialization.linearMapAt_symmₗ variable (R) /-- A coordinate change function between two trivializations, as a continuous linear equivalence. Defined to be the identity when `b` does not lie in the base set of both trivializations. -/ def coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] (b : B) : F ≃L[R] F := { toLinearEquiv := if hb : b ∈ e.baseSet ∩ e'.baseSet then (e.linearEquivAt R b (hb.1 : _)).symm.trans (e'.linearEquivAt R b hb.2) else LinearEquiv.refl R F continuous_toFun := by by_cases hb : b ∈ e.baseSet ∩ e'.baseSet · rw [dif_pos hb] refine (e'.continuousOn.comp_continuous ?_ ?_).snd · exact e.continuousOn_symm.comp_continuous (Continuous.Prod.mk b) fun y => mk_mem_prod hb.1 (mem_univ y) · exact fun y => e'.mem_source.mpr hb.2 · rw [dif_neg hb] exact continuous_id continuous_invFun := by by_cases hb : b ∈ e.baseSet ∩ e'.baseSet · rw [dif_pos hb] refine (e.continuousOn.comp_continuous ?_ ?_).snd · exact e'.continuousOn_symm.comp_continuous (Continuous.Prod.mk b) fun y => mk_mem_prod hb.2 (mem_univ y) exact fun y => e.mem_source.mpr hb.1 · rw [dif_neg hb] exact continuous_id } set_option linter.uppercaseLean3 false in #align trivialization.coord_changeL Trivialization.coordChangeL variable {R} theorem coe_coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) : ⇑(coordChangeL R e e' b) = (e.linearEquivAt R b hb.1).symm.trans (e'.linearEquivAt R b hb.2) := congr_arg (fun f : F ≃ₗ[R] F ↦ ⇑f) (dif_pos hb) set_option linter.uppercaseLean3 false in #align trivialization.coe_coord_changeL Trivialization.coe_coordChangeL theorem coe_coordChangeL' (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) : (coordChangeL R e e' b).toLinearEquiv = (e.linearEquivAt R b hb.1).symm.trans (e'.linearEquivAt R b hb.2) := LinearEquiv.coe_injective (coe_coordChangeL _ _ hb) set_option linter.uppercaseLean3 false in #align trivialization.coe_coord_changeL' Trivialization.coe_coordChangeL' theorem symm_coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e'.baseSet ∩ e.baseSet) : (e.coordChangeL R e' b).symm = e'.coordChangeL R e b := by apply ContinuousLinearEquiv.toLinearEquiv_injective rw [coe_coordChangeL' e' e hb, (coordChangeL R e e' b).symm_toLinearEquiv, coe_coordChangeL' e e' hb.symm, LinearEquiv.trans_symm, LinearEquiv.symm_symm] set_option linter.uppercaseLean3 false in #align trivialization.symm_coord_changeL Trivialization.symm_coordChangeL theorem coordChangeL_apply (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) (y : F) : coordChangeL R e e' b y = (e' ⟨b, e.symm b y⟩).2 := congr_fun (coe_coordChangeL e e' hb) y set_option linter.uppercaseLean3 false in #align trivialization.coord_changeL_apply Trivialization.coordChangeL_apply theorem mk_coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) (y : F) : (b, coordChangeL R e e' b y) = e' ⟨b, e.symm b y⟩ := by ext · rw [e.mk_symm hb.1 y, e'.coe_fst', e.proj_symm_apply' hb.1] rw [e.proj_symm_apply' hb.1] exact hb.2 · exact e.coordChangeL_apply e' hb y set_option linter.uppercaseLean3 false in #align trivialization.mk_coord_changeL Trivialization.mk_coordChangeL theorem apply_symm_apply_eq_coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) (v : F) : e' (e.toPartialHomeomorph.symm (b, v)) = (b, e.coordChangeL R e' b v) := by rw [e.mk_coordChangeL e' hb, e.mk_symm hb.1] set_option linter.uppercaseLean3 false in #align trivialization.apply_symm_apply_eq_coord_changeL Trivialization.apply_symm_apply_eq_coordChangeL /-- A version of `Trivialization.coordChangeL_apply` that fully unfolds `coordChange`. The right-hand side is ugly, but has good definitional properties for specifically defined trivializations. -/ theorem coordChangeL_apply' (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) (y : F) : coordChangeL R e e' b y = (e' (e.toPartialHomeomorph.symm (b, y))).2 := by rw [e.coordChangeL_apply e' hb, e.mk_symm hb.1] set_option linter.uppercaseLean3 false in #align trivialization.coord_changeL_apply' Trivialization.coordChangeL_apply' theorem coordChangeL_symm_apply (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) : ⇑(coordChangeL R e e' b).symm = (e'.linearEquivAt R b hb.2).symm.trans (e.linearEquivAt R b hb.1) := congr_arg LinearEquiv.invFun (dif_pos hb) set_option linter.uppercaseLean3 false in #align trivialization.coord_changeL_symm_apply Trivialization.coordChangeL_symm_apply end Trivialization end TopologicalVectorSpace section namespace Bundle /-- The zero section of a vector bundle -/ def zeroSection [∀ x, Zero (E x)] : B → TotalSpace F E := (⟨·, 0⟩) #align bundle.zero_section Bundle.zeroSection @[simp, mfld_simps] theorem zeroSection_proj [∀ x, Zero (E x)] (x : B) : (zeroSection F E x).proj = x := rfl #align bundle.zero_section_proj Bundle.zeroSection_proj @[simp, mfld_simps] theorem zeroSection_snd [∀ x, Zero (E x)] (x : B) : (zeroSection F E x).2 = 0 := rfl #align bundle.zero_section_snd Bundle.zeroSection_snd end Bundle open Bundle variable [NontriviallyNormedField R] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] [NormedAddCommGroup F] [NormedSpace R F] [TopologicalSpace B] [TopologicalSpace (TotalSpace F E)] [∀ x, TopologicalSpace (E x)] [FiberBundle F E] /-- The space `Bundle.TotalSpace F E` (for `E : B → Type*` such that each `E x` is a topological vector space) has a topological vector space structure with fiber `F` (denoted with `VectorBundle R F E`) if around every point there is a fiber bundle trivialization which is linear in the fibers. -/ class VectorBundle : Prop where trivialization_linear' : ∀ (e : Trivialization F (π F E)) [MemTrivializationAtlas e], e.IsLinear R continuousOn_coordChange' : ∀ (e e' : Trivialization F (π F E)) [MemTrivializationAtlas e] [MemTrivializationAtlas e'], ContinuousOn (fun b => Trivialization.coordChangeL R e e' b : B → F →L[R] F) (e.baseSet ∩ e'.baseSet) #align vector_bundle VectorBundle variable {F E} instance (priority := 100) trivialization_linear [VectorBundle R F E] (e : Trivialization F (π F E)) [MemTrivializationAtlas e] : e.IsLinear R := VectorBundle.trivialization_linear' e #align trivialization_linear trivialization_linear theorem continuousOn_coordChange [VectorBundle R F E] (e e' : Trivialization F (π F E)) [MemTrivializationAtlas e] [MemTrivializationAtlas e'] : ContinuousOn (fun b => Trivialization.coordChangeL R e e' b : B → F →L[R] F) (e.baseSet ∩ e'.baseSet) := VectorBundle.continuousOn_coordChange' e e' #align continuous_on_coord_change continuousOn_coordChange namespace Trivialization /-- Forward map of `Trivialization.continuousLinearEquivAt` (only propositionally equal), defined everywhere (`0` outside domain). -/ @[simps (config := .asFn) apply] def continuousLinearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : E b →L[R] F := { e.linearMapAt R b with toFun := e.linearMapAt R b -- given explicitly to help `simps` cont := by dsimp rw [e.coe_linearMapAt b] refine continuous_if_const _ (fun hb => ?_) fun _ => continuous_zero exact (e.continuousOn.comp_continuous (FiberBundle.totalSpaceMk_inducing F E b).continuous fun x => e.mem_source.mpr hb).snd } #align trivialization.continuous_linear_map_at Trivialization.continuousLinearMapAt /-- Backwards map of `Trivialization.continuousLinearEquivAt`, defined everywhere. -/ @[simps (config := .asFn) apply] def symmL (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : F →L[R] E b := { e.symmₗ R b with toFun := e.symm b -- given explicitly to help `simps` cont := by by_cases hb : b ∈ e.baseSet · rw [(FiberBundle.totalSpaceMk_inducing F E b).continuous_iff] exact e.continuousOn_symm.comp_continuous (continuous_const.prod_mk continuous_id) fun x ↦ mk_mem_prod hb (mem_univ x) · refine continuous_zero.congr fun x => (e.symm_apply_of_not_mem hb x).symm } set_option linter.uppercaseLean3 false in #align trivialization.symmL Trivialization.symmL variable {R} theorem symmL_continuousLinearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) (y : E b) : e.symmL R b (e.continuousLinearMapAt R b y) = y := e.symmₗ_linearMapAt hb y set_option linter.uppercaseLean3 false in #align trivialization.symmL_continuous_linear_map_at Trivialization.symmL_continuousLinearMapAt theorem continuousLinearMapAt_symmL (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) (y : F) : e.continuousLinearMapAt R b (e.symmL R b y) = y := e.linearMapAt_symmₗ hb y set_option linter.uppercaseLean3 false in #align trivialization.continuous_linear_map_at_symmL Trivialization.continuousLinearMapAt_symmL variable (R) /-- In a vector bundle, a trivialization in the fiber (which is a priori only linear) is in fact a continuous linear equiv between the fibers and the model fiber. -/ @[simps (config := .asFn) apply symm_apply] def continuousLinearEquivAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) : E b ≃L[R] F := { e.toPretrivialization.linearEquivAt R b hb with toFun := fun y => (e ⟨b, y⟩).2 -- given explicitly to help `simps` invFun := e.symm b -- given explicitly to help `simps` continuous_toFun := (e.continuousOn.comp_continuous (FiberBundle.totalSpaceMk_inducing F E b).continuous fun _ => e.mem_source.mpr hb).snd continuous_invFun := (e.symmL R b).continuous } #align trivialization.continuous_linear_equiv_at Trivialization.continuousLinearEquivAt variable {R} theorem coe_continuousLinearEquivAt_eq (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : (e.continuousLinearEquivAt R b hb : E b → F) = e.continuousLinearMapAt R b := (e.coe_linearMapAt_of_mem hb).symm #align trivialization.coe_continuous_linear_equiv_at_eq Trivialization.coe_continuousLinearEquivAt_eq theorem symm_continuousLinearEquivAt_eq (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : ((e.continuousLinearEquivAt R b hb).symm : F → E b) = e.symmL R b := rfl #align trivialization.symm_continuous_linear_equiv_at_eq Trivialization.symm_continuousLinearEquivAt_eq @[simp, nolint simpNF] -- `simp` can prove it but `dsimp` can't; todo: prove `Sigma.eta` with `rfl` theorem continuousLinearEquivAt_apply' (e : Trivialization F (π F E)) [e.IsLinear R] (x : TotalSpace F E) (hx : x ∈ e.source) : e.continuousLinearEquivAt R x.proj (e.mem_source.1 hx) x.2 = (e x).2 := rfl #align trivialization.continuous_linear_equiv_at_apply' Trivialization.continuousLinearEquivAt_apply' variable (R) theorem apply_eq_prod_continuousLinearEquivAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) (z : E b) : e ⟨b, z⟩ = (b, e.continuousLinearEquivAt R b hb z) := by ext · refine e.coe_fst ?_ rw [e.source_eq] exact hb · simp only [coe_coe, continuousLinearEquivAt_apply] #align trivialization.apply_eq_prod_continuous_linear_equiv_at Trivialization.apply_eq_prod_continuousLinearEquivAt protected theorem zeroSection (e : Trivialization F (π F E)) [e.IsLinear R] {x : B} (hx : x ∈ e.baseSet) : e (zeroSection F E x) = (x, 0) := by simp_rw [zeroSection, e.apply_eq_prod_continuousLinearEquivAt R x hx 0, map_zero] #align trivialization.zero_section Trivialization.zeroSection variable {R} theorem symm_apply_eq_mk_continuousLinearEquivAt_symm (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) (z : F) : e.toPartialHomeomorph.symm ⟨b, z⟩ = ⟨b, (e.continuousLinearEquivAt R b hb).symm z⟩ := by have h : (b, z) ∈ e.target := by rw [e.target_eq] exact ⟨hb, mem_univ _⟩ apply e.injOn (e.map_target h) · simpa only [e.source_eq, mem_preimage] · simp_rw [e.right_inv h, coe_coe, e.apply_eq_prod_continuousLinearEquivAt R b hb, ContinuousLinearEquiv.apply_symm_apply] #align trivialization.symm_apply_eq_mk_continuous_linear_equiv_at_symm Trivialization.symm_apply_eq_mk_continuousLinearEquivAt_symm theorem comp_continuousLinearEquivAt_eq_coord_change (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) : (e.continuousLinearEquivAt R b hb.1).symm.trans (e'.continuousLinearEquivAt R b hb.2) = coordChangeL R e e' b := by ext v rw [coordChangeL_apply e e' hb] rfl #align trivialization.comp_continuous_linear_equiv_at_eq_coord_change Trivialization.comp_continuousLinearEquivAt_eq_coord_change end Trivialization /-! ### Constructing vector bundles -/ variable (B F) /-- Analogous construction of `FiberBundleCore` for vector bundles. This construction gives a way to construct vector bundles from a structure registering how trivialization changes act on fibers. -/ structure VectorBundleCore (ι : Type*) where baseSet : ι → Set B isOpen_baseSet : ∀ i, IsOpen (baseSet i) indexAt : B → ι mem_baseSet_at : ∀ x, x ∈ baseSet (indexAt x) coordChange : ι → ι → B → F →L[R] F coordChange_self : ∀ i, ∀ x ∈ baseSet i, ∀ v, coordChange i i x v = v continuousOn_coordChange : ∀ i j, ContinuousOn (coordChange i j) (baseSet i ∩ baseSet j) coordChange_comp : ∀ i j k, ∀ x ∈ baseSet i ∩ baseSet j ∩ baseSet k, ∀ v, (coordChange j k x) (coordChange i j x v) = coordChange i k x v #align vector_bundle_core VectorBundleCore /-- The trivial vector bundle core, in which all the changes of coordinates are the identity. -/ def trivialVectorBundleCore (ι : Type*) [Inhabited ι] : VectorBundleCore R B F ι where baseSet _ := univ isOpen_baseSet _ := isOpen_univ indexAt := default mem_baseSet_at x := mem_univ x coordChange _ _ _ := ContinuousLinearMap.id R F coordChange_self _ _ _ _ := rfl coordChange_comp _ _ _ _ _ _ := rfl continuousOn_coordChange _ _ := continuousOn_const #align trivial_vector_bundle_core trivialVectorBundleCore instance (ι : Type*) [Inhabited ι] : Inhabited (VectorBundleCore R B F ι) := ⟨trivialVectorBundleCore R B F ι⟩ namespace VectorBundleCore variable {R B F} {ι : Type*} variable (Z : VectorBundleCore R B F ι) /-- Natural identification to a `FiberBundleCore`. -/ @[simps (config := mfld_cfg)] def toFiberBundleCore : FiberBundleCore ι B F := { Z with coordChange := fun i j b => Z.coordChange i j b continuousOn_coordChange := fun i j => isBoundedBilinearMap_apply.continuous.comp_continuousOn ((Z.continuousOn_coordChange i j).prod_map continuousOn_id) } #align vector_bundle_core.to_fiber_bundle_core VectorBundleCore.toFiberBundleCore -- Porting note (#11215): TODO: restore coercion -- instance toFiberBundleCoreCoe : Coe (VectorBundleCore R B F ι) (FiberBundleCore ι B F) := -- ⟨toFiberBundleCore⟩ -- #align vector_bundle_core.to_fiber_bundle_core_coe VectorBundleCore.toFiberBundleCoreCoe theorem coordChange_linear_comp (i j k : ι) : ∀ x ∈ Z.baseSet i ∩ Z.baseSet j ∩ Z.baseSet k, (Z.coordChange j k x).comp (Z.coordChange i j x) = Z.coordChange i k x := fun x hx => by ext v exact Z.coordChange_comp i j k x hx v #align vector_bundle_core.coord_change_linear_comp VectorBundleCore.coordChange_linear_comp /-- The index set of a vector bundle core, as a convenience function for dot notation -/ @[nolint unusedArguments] -- Porting note(#5171): was `nolint has_nonempty_instance` def Index := ι #align vector_bundle_core.index VectorBundleCore.Index /-- The base space of a vector bundle core, as a convenience function for dot notation-/ @[nolint unusedArguments, reducible] def Base := B #align vector_bundle_core.base VectorBundleCore.Base /-- The fiber of a vector bundle core, as a convenience function for dot notation and typeclass inference -/ @[nolint unusedArguments] -- Porting note(#5171): was `nolint has_nonempty_instance` def Fiber : B → Type _ := Z.toFiberBundleCore.Fiber #align vector_bundle_core.fiber VectorBundleCore.Fiber instance topologicalSpaceFiber (x : B) : TopologicalSpace (Z.Fiber x) := Z.toFiberBundleCore.topologicalSpaceFiber x #align vector_bundle_core.topological_space_fiber VectorBundleCore.topologicalSpaceFiber -- Porting note: fixed: used to assume both `[NormedAddCommGroup F]` and `[AddCommGroupCat F]` instance addCommGroupFiber (x : B) : AddCommGroup (Z.Fiber x) := inferInstanceAs (AddCommGroup F) #align vector_bundle_core.add_comm_group_fiber VectorBundleCore.addCommGroupFiber instance moduleFiber (x : B) : Module R (Z.Fiber x) := inferInstanceAs (Module R F) #align vector_bundle_core.module_fiber VectorBundleCore.moduleFiber /-- The projection from the total space of a fiber bundle core, on its base. -/ @[reducible, simp, mfld_simps] protected def proj : TotalSpace F Z.Fiber → B := TotalSpace.proj #align vector_bundle_core.proj VectorBundleCore.proj /-- The total space of the vector bundle, as a convenience function for dot notation. It is by definition equal to `Bundle.TotalSpace F Z.Fiber`. -/ @[nolint unusedArguments, reducible] protected def TotalSpace := Bundle.TotalSpace F Z.Fiber #align vector_bundle_core.total_space VectorBundleCore.TotalSpace /-- Local homeomorphism version of the trivialization change. -/ def trivChange (i j : ι) : PartialHomeomorph (B × F) (B × F) := Z.toFiberBundleCore.trivChange i j #align vector_bundle_core.triv_change VectorBundleCore.trivChange @[simp, mfld_simps] theorem mem_trivChange_source (i j : ι) (p : B × F) : p ∈ (Z.trivChange i j).source ↔ p.1 ∈ Z.baseSet i ∩ Z.baseSet j := Z.toFiberBundleCore.mem_trivChange_source i j p #align vector_bundle_core.mem_triv_change_source VectorBundleCore.mem_trivChange_source /-- Topological structure on the total space of a vector bundle created from core, designed so that all the local trivialization are continuous. -/ instance toTopologicalSpace : TopologicalSpace Z.TotalSpace := Z.toFiberBundleCore.toTopologicalSpace #align vector_bundle_core.to_topological_space VectorBundleCore.toTopologicalSpace variable (b : B) (a : F) @[simp, mfld_simps] theorem coe_coordChange (i j : ι) : Z.toFiberBundleCore.coordChange i j b = Z.coordChange i j b := rfl #align vector_bundle_core.coe_coord_change VectorBundleCore.coe_coordChange /-- One of the standard local trivializations of a vector bundle constructed from core, taken by considering this in particular as a fiber bundle constructed from core. -/ def localTriv (i : ι) : Trivialization F (π F Z.Fiber) := Z.toFiberBundleCore.localTriv i #align vector_bundle_core.local_triv VectorBundleCore.localTriv -- Porting note: moved from below to fix the next instance @[simp, mfld_simps] theorem localTriv_apply {i : ι} (p : Z.TotalSpace) : (Z.localTriv i) p = ⟨p.1, Z.coordChange (Z.indexAt p.1) i p.1 p.2⟩ := rfl #align vector_bundle_core.local_triv_apply VectorBundleCore.localTriv_apply /-- The standard local trivializations of a vector bundle constructed from core are linear. -/ instance localTriv.isLinear (i : ι) : (Z.localTriv i).IsLinear R where linear x _ := { map_add := fun _ _ => by simp only [map_add, localTriv_apply, mfld_simps] map_smul := fun _ _ => by simp only [map_smul, localTriv_apply, mfld_simps] } #align vector_bundle_core.local_triv.is_linear VectorBundleCore.localTriv.isLinear variable (i j : ι) @[simp, mfld_simps] theorem mem_localTriv_source (p : Z.TotalSpace) : p ∈ (Z.localTriv i).source ↔ p.1 ∈ Z.baseSet i := Iff.rfl #align vector_bundle_core.mem_local_triv_source VectorBundleCore.mem_localTriv_source @[simp, mfld_simps] theorem baseSet_at : Z.baseSet i = (Z.localTriv i).baseSet := rfl #align vector_bundle_core.base_set_at VectorBundleCore.baseSet_at @[simp, mfld_simps] theorem mem_localTriv_target (p : B × F) : p ∈ (Z.localTriv i).target ↔ p.1 ∈ (Z.localTriv i).baseSet := Z.toFiberBundleCore.mem_localTriv_target i p #align vector_bundle_core.mem_local_triv_target VectorBundleCore.mem_localTriv_target @[simp, mfld_simps] theorem localTriv_symm_fst (p : B × F) : (Z.localTriv i).toPartialHomeomorph.symm p = ⟨p.1, Z.coordChange i (Z.indexAt p.1) p.1 p.2⟩ := rfl #align vector_bundle_core.local_triv_symm_fst VectorBundleCore.localTriv_symm_fst @[simp, mfld_simps] theorem localTriv_symm_apply {b : B} (hb : b ∈ Z.baseSet i) (v : F) : (Z.localTriv i).symm b v = Z.coordChange i (Z.indexAt b) b v := by apply (Z.localTriv i).symm_apply hb v #align vector_bundle_core.local_triv_symm_apply VectorBundleCore.localTriv_symm_apply @[simp, mfld_simps] theorem localTriv_coordChange_eq {b : B} (hb : b ∈ Z.baseSet i ∩ Z.baseSet j) (v : F) : (Z.localTriv i).coordChangeL R (Z.localTriv j) b v = Z.coordChange i j b v := by rw [Trivialization.coordChangeL_apply', localTriv_symm_fst, localTriv_apply, coordChange_comp] exacts [⟨⟨hb.1, Z.mem_baseSet_at b⟩, hb.2⟩, hb] #align vector_bundle_core.local_triv_coord_change_eq VectorBundleCore.localTriv_coordChange_eq /-- Preferred local trivialization of a vector bundle constructed from core, at a given point, as a bundle trivialization -/ def localTrivAt (b : B) : Trivialization F (π F Z.Fiber) := Z.localTriv (Z.indexAt b) #align vector_bundle_core.local_triv_at VectorBundleCore.localTrivAt @[simp, mfld_simps] theorem localTrivAt_def : Z.localTriv (Z.indexAt b) = Z.localTrivAt b := rfl #align vector_bundle_core.local_triv_at_def VectorBundleCore.localTrivAt_def @[simp, mfld_simps] theorem mem_source_at : (⟨b, a⟩ : Z.TotalSpace) ∈ (Z.localTrivAt b).source := by rw [localTrivAt, mem_localTriv_source] exact Z.mem_baseSet_at b #align vector_bundle_core.mem_source_at VectorBundleCore.mem_source_at @[simp, mfld_simps] theorem localTrivAt_apply (p : Z.TotalSpace) : Z.localTrivAt p.1 p = ⟨p.1, p.2⟩ := Z.toFiberBundleCore.localTrivAt_apply p #align vector_bundle_core.local_triv_at_apply VectorBundleCore.localTrivAt_apply @[simp, mfld_simps] theorem localTrivAt_apply_mk (b : B) (a : F) : Z.localTrivAt b ⟨b, a⟩ = ⟨b, a⟩ := Z.localTrivAt_apply _ #align vector_bundle_core.local_triv_at_apply_mk VectorBundleCore.localTrivAt_apply_mk @[simp, mfld_simps] theorem mem_localTrivAt_baseSet : b ∈ (Z.localTrivAt b).baseSet := Z.toFiberBundleCore.mem_localTrivAt_baseSet b #align vector_bundle_core.mem_local_triv_at_base_set VectorBundleCore.mem_localTrivAt_baseSet instance fiberBundle : FiberBundle F Z.Fiber := Z.toFiberBundleCore.fiberBundle #align vector_bundle_core.fiber_bundle VectorBundleCore.fiberBundle instance vectorBundle : VectorBundle R F Z.Fiber where trivialization_linear' := by rintro _ ⟨i, rfl⟩ apply localTriv.isLinear continuousOn_coordChange' := by rintro _ _ ⟨i, rfl⟩ ⟨i', rfl⟩ refine (Z.continuousOn_coordChange i i').congr fun b hb => ?_ ext v exact Z.localTriv_coordChange_eq i i' hb v #align vector_bundle_core.vector_bundle VectorBundleCore.vectorBundle /-- The projection on the base of a vector bundle created from core is continuous -/ @[continuity] theorem continuous_proj : Continuous Z.proj := Z.toFiberBundleCore.continuous_proj #align vector_bundle_core.continuous_proj VectorBundleCore.continuous_proj /-- The projection on the base of a vector bundle created from core is an open map -/ theorem isOpenMap_proj : IsOpenMap Z.proj := Z.toFiberBundleCore.isOpenMap_proj #align vector_bundle_core.is_open_map_proj VectorBundleCore.isOpenMap_proj variable {i j} @[simp, mfld_simps] theorem localTriv_continuousLinearMapAt {b : B} (hb : b ∈ Z.baseSet i) : (Z.localTriv i).continuousLinearMapAt R b = Z.coordChange (Z.indexAt b) i b := by ext1 v rw [(Z.localTriv i).continuousLinearMapAt_apply R, (Z.localTriv i).coe_linearMapAt_of_mem] exacts [rfl, hb] #align vector_bundle_core.local_triv_continuous_linear_map_at VectorBundleCore.localTriv_continuousLinearMapAt @[simp, mfld_simps] theorem trivializationAt_continuousLinearMapAt {b₀ b : B} (hb : b ∈ (trivializationAt F Z.Fiber b₀).baseSet) : (trivializationAt F Z.Fiber b₀).continuousLinearMapAt R b = Z.coordChange (Z.indexAt b) (Z.indexAt b₀) b := Z.localTriv_continuousLinearMapAt hb #align vector_bundle_core.trivialization_at_continuous_linear_map_at VectorBundleCore.trivializationAt_continuousLinearMapAt @[simp, mfld_simps] theorem localTriv_symmL {b : B} (hb : b ∈ Z.baseSet i) : (Z.localTriv i).symmL R b = Z.coordChange i (Z.indexAt b) b := by ext1 v rw [(Z.localTriv i).symmL_apply R, (Z.localTriv i).symm_apply] exacts [rfl, hb] set_option linter.uppercaseLean3 false in #align vector_bundle_core.local_triv_symmL VectorBundleCore.localTriv_symmL @[simp, mfld_simps] theorem trivializationAt_symmL {b₀ b : B} (hb : b ∈ (trivializationAt F Z.Fiber b₀).baseSet) : (trivializationAt F Z.Fiber b₀).symmL R b = Z.coordChange (Z.indexAt b₀) (Z.indexAt b) b := Z.localTriv_symmL hb set_option linter.uppercaseLean3 false in #align vector_bundle_core.trivialization_at_symmL VectorBundleCore.trivializationAt_symmL @[simp, mfld_simps] theorem trivializationAt_coordChange_eq {b₀ b₁ b : B} (hb : b ∈ (trivializationAt F Z.Fiber b₀).baseSet ∩ (trivializationAt F Z.Fiber b₁).baseSet) (v : F) : (trivializationAt F Z.Fiber b₀).coordChangeL R (trivializationAt F Z.Fiber b₁) b v = Z.coordChange (Z.indexAt b₀) (Z.indexAt b₁) b v := Z.localTriv_coordChange_eq _ _ hb v #align vector_bundle_core.trivialization_at_coord_change_eq VectorBundleCore.trivializationAt_coordChange_eq end VectorBundleCore end /-! ### Vector prebundle -/ section variable [NontriviallyNormedField R] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] [NormedAddCommGroup F] [NormedSpace R F] [TopologicalSpace B] [∀ x, TopologicalSpace (E x)] open TopologicalSpace open VectorBundle /-- This structure permits to define a vector bundle when trivializations are given as local equivalences but there is not yet a topology on the total space or the fibers. The total space is hence given a topology in such a way that there is a fiber bundle structure for which the partial equivalences are also partial homeomorphisms and hence vector bundle trivializations. The topology on the fibers is induced from the one on the total space. The field `exists_coordChange` is stated as an existential statement (instead of 3 separate fields), since it depends on propositional information (namely `e e' ∈ pretrivializationAtlas`). This makes it inconvenient to explicitly define a `coordChange` function when constructing a `VectorPrebundle`. -/ -- Porting note(#5171): was @[nolint has_nonempty_instance] structure VectorPrebundle where pretrivializationAtlas : Set (Pretrivialization F (π F E)) pretrivialization_linear' : ∀ e, e ∈ pretrivializationAtlas → e.IsLinear R pretrivializationAt : B → Pretrivialization F (π F E) mem_base_pretrivializationAt : ∀ x : B, x ∈ (pretrivializationAt x).baseSet pretrivialization_mem_atlas : ∀ x : B, pretrivializationAt x ∈ pretrivializationAtlas exists_coordChange : ∀ᵉ (e ∈ pretrivializationAtlas) (e' ∈ pretrivializationAtlas), ∃ f : B → F →L[R] F, ContinuousOn f (e.baseSet ∩ e'.baseSet) ∧ ∀ᵉ (b ∈ e.baseSet ∩ e'.baseSet) (v : F), f b v = (e' ⟨b, e.symm b v⟩).2 totalSpaceMk_inducing : ∀ b : B, Inducing (pretrivializationAt b ∘ .mk b) #align vector_prebundle VectorPrebundle namespace VectorPrebundle variable {R E F} /-- A randomly chosen coordinate change on a `VectorPrebundle`, given by the field `exists_coordChange`. -/ def coordChange (a : VectorPrebundle R F E) {e e' : Pretrivialization F (π F E)} (he : e ∈ a.pretrivializationAtlas) (he' : e' ∈ a.pretrivializationAtlas) (b : B) : F →L[R] F := Classical.choose (a.exists_coordChange e he e' he') b #align vector_prebundle.coord_change VectorPrebundle.coordChange theorem continuousOn_coordChange (a : VectorPrebundle R F E) {e e' : Pretrivialization F (π F E)} (he : e ∈ a.pretrivializationAtlas) (he' : e' ∈ a.pretrivializationAtlas) : ContinuousOn (a.coordChange he he') (e.baseSet ∩ e'.baseSet) := (Classical.choose_spec (a.exists_coordChange e he e' he')).1 #align vector_prebundle.continuous_on_coord_change VectorPrebundle.continuousOn_coordChange theorem coordChange_apply (a : VectorPrebundle R F E) {e e' : Pretrivialization F (π F E)} (he : e ∈ a.pretrivializationAtlas) (he' : e' ∈ a.pretrivializationAtlas) {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) (v : F) : a.coordChange he he' b v = (e' ⟨b, e.symm b v⟩).2 := (Classical.choose_spec (a.exists_coordChange e he e' he')).2 b hb v #align vector_prebundle.coord_change_apply VectorPrebundle.coordChange_apply theorem mk_coordChange (a : VectorPrebundle R F E) {e e' : Pretrivialization F (π F E)} (he : e ∈ a.pretrivializationAtlas) (he' : e' ∈ a.pretrivializationAtlas) {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) (v : F) : (b, a.coordChange he he' b v) = e' ⟨b, e.symm b v⟩ := by ext · rw [e.mk_symm hb.1 v, e'.coe_fst', e.proj_symm_apply' hb.1] rw [e.proj_symm_apply' hb.1] exact hb.2 · exact a.coordChange_apply he he' hb v #align vector_prebundle.mk_coord_change VectorPrebundle.mk_coordChange /-- Natural identification of `VectorPrebundle` as a `FiberPrebundle`. -/ def toFiberPrebundle (a : VectorPrebundle R F E) : FiberPrebundle F E := { a with continuous_trivChange := fun e he e' he' ↦ by have : ContinuousOn (fun x : B × F ↦ a.coordChange he' he x.1 x.2) ((e'.baseSet ∩ e.baseSet) ×ˢ univ) := isBoundedBilinearMap_apply.continuous.comp_continuousOn ((a.continuousOn_coordChange he' he).prod_map continuousOn_id) rw [e.target_inter_preimage_symm_source_eq e', inter_comm] refine (continuousOn_fst.prod this).congr ?_ rintro ⟨b, f⟩ ⟨hb, -⟩ dsimp only [Function.comp_def, Prod.map] rw [a.mk_coordChange _ _ hb, e'.mk_symm hb.1] } #align vector_prebundle.to_fiber_prebundle VectorPrebundle.toFiberPrebundle /-- Topology on the total space that will make the prebundle into a bundle. -/ def totalSpaceTopology (a : VectorPrebundle R F E) : TopologicalSpace (TotalSpace F E) := a.toFiberPrebundle.totalSpaceTopology #align vector_prebundle.total_space_topology VectorPrebundle.totalSpaceTopology /-- Promotion from a `Pretrivialization` in the `pretrivializationAtlas` of a `VectorPrebundle` to a `Trivialization`. -/ def trivializationOfMemPretrivializationAtlas (a : VectorPrebundle R F E) {e : Pretrivialization F (π F E)} (he : e ∈ a.pretrivializationAtlas) : @Trivialization B F _ _ _ a.totalSpaceTopology (π F E) := a.toFiberPrebundle.trivializationOfMemPretrivializationAtlas he #align vector_prebundle.trivialization_of_mem_pretrivialization_atlas VectorPrebundle.trivializationOfMemPretrivializationAtlas theorem linear_trivializationOfMemPretrivializationAtlas (a : VectorPrebundle R F E) {e : Pretrivialization F (π F E)} (he : e ∈ a.pretrivializationAtlas) : letI := a.totalSpaceTopology Trivialization.IsLinear R (trivializationOfMemPretrivializationAtlas a he) := letI := a.totalSpaceTopology { linear := (a.pretrivialization_linear' e he).linear } #align vector_prebundle.linear_of_mem_pretrivialization_atlas VectorPrebundle.linear_trivializationOfMemPretrivializationAtlas variable (a : VectorPrebundle R F E) theorem mem_trivialization_at_source (b : B) (x : E b) : ⟨b, x⟩ ∈ (a.pretrivializationAt b).source := a.toFiberPrebundle.mem_pretrivializationAt_source b x #align vector_prebundle.mem_trivialization_at_source VectorPrebundle.mem_trivialization_at_source @[simp] theorem totalSpaceMk_preimage_source (b : B) : .mk b ⁻¹' (a.pretrivializationAt b).source = univ := a.toFiberPrebundle.totalSpaceMk_preimage_source b #align vector_prebundle.total_space_mk_preimage_source VectorPrebundle.totalSpaceMk_preimage_source @[continuity] theorem continuous_totalSpaceMk (b : B) : Continuous[_, a.totalSpaceTopology] (.mk b) := a.toFiberPrebundle.continuous_totalSpaceMk b #align vector_prebundle.continuous_total_space_mk VectorPrebundle.continuous_totalSpaceMk /-- Make a `FiberBundle` from a `VectorPrebundle`; auxiliary construction for `VectorPrebundle.toVectorBundle`. -/ def toFiberBundle : @FiberBundle B F _ _ _ a.totalSpaceTopology _ := a.toFiberPrebundle.toFiberBundle #align vector_prebundle.to_fiber_bundle VectorPrebundle.toFiberBundle /-- Make a `VectorBundle` from a `VectorPrebundle`. Concretely this means that, given a `VectorPrebundle` structure for a sigma-type `E` -- which consists of a number of "pretrivializations" identifying parts of `E` with product spaces `U × F` -- one establishes that for the topology constructed on the sigma-type using `VectorPrebundle.totalSpaceTopology`, these "pretrivializations" are actually "trivializations" (i.e., homeomorphisms with respect to the constructed topology). -/ theorem toVectorBundle : @VectorBundle R _ F E _ _ _ _ _ _ a.totalSpaceTopology _ a.toFiberBundle := letI := a.totalSpaceTopology; letI := a.toFiberBundle { trivialization_linear' := by rintro _ ⟨e, he, rfl⟩ apply linear_trivializationOfMemPretrivializationAtlas continuousOn_coordChange' := by rintro _ _ ⟨e, he, rfl⟩ ⟨e', he', rfl⟩ refine (a.continuousOn_coordChange he he').congr fun b hb ↦ ?_ ext v -- Porting note: help `rw` find instances haveI h₁ := a.linear_trivializationOfMemPretrivializationAtlas he haveI h₂ := a.linear_trivializationOfMemPretrivializationAtlas he' rw [trivializationOfMemPretrivializationAtlas] at h₁ h₂ rw [a.coordChange_apply he he' hb v, ContinuousLinearEquiv.coe_coe, Trivialization.coordChangeL_apply] exacts [rfl, hb] } #align vector_prebundle.to_vector_bundle VectorPrebundle.toVectorBundle end VectorPrebundle namespace ContinuousLinearMap variable {𝕜₁ 𝕜₂ : Type*} [NontriviallyNormedField 𝕜₁] [NontriviallyNormedField 𝕜₂] variable {σ : 𝕜₁ →+* 𝕜₂} variable {B' : Type*} [TopologicalSpace B'] variable [NormedSpace 𝕜₁ F] [∀ x, Module 𝕜₁ (E x)] [TopologicalSpace (TotalSpace F E)] variable {F' : Type*} [NormedAddCommGroup F'] [NormedSpace 𝕜₂ F'] {E' : B' → Type*} [∀ x, AddCommMonoid (E' x)] [∀ x, Module 𝕜₂ (E' x)] [TopologicalSpace (TotalSpace F' E')] variable [FiberBundle F E] [VectorBundle 𝕜₁ F E] variable [∀ x, TopologicalSpace (E' x)] [FiberBundle F' E'] [VectorBundle 𝕜₂ F' E'] variable (F' E') /-- When `ϕ` is a continuous (semi)linear map between the fibers `E x` and `E' y` of two vector bundles `E` and `E'`, `ContinuousLinearMap.inCoordinates F E F' E' x₀ x y₀ y ϕ` is a coordinate change of this continuous linear map w.r.t. the chart around `x₀` and the chart around `y₀`. It is defined by composing `ϕ` with appropriate coordinate changes given by the vector bundles `E` and `E'`. We use the operations `Trivialization.continuousLinearMapAt` and `Trivialization.symmL` in the definition, instead of `Trivialization.continuousLinearEquivAt`, so that `ContinuousLinearMap.inCoordinates` is defined everywhere (but see `ContinuousLinearMap.inCoordinates_eq`). This is the (second component of the) underlying function of a trivialization of the hom-bundle (see `hom_trivializationAt_apply`). However, note that `ContinuousLinearMap.inCoordinates` is defined even when `x` and `y` live in different base sets. Therefore, it is also convenient when working with the hom-bundle between pulled back bundles. -/ def inCoordinates (x₀ x : B) (y₀ y : B') (ϕ : E x →SL[σ] E' y) : F →SL[σ] F' := ((trivializationAt F' E' y₀).continuousLinearMapAt 𝕜₂ y).comp <| ϕ.comp <| (trivializationAt F E x₀).symmL 𝕜₁ x #align continuous_linear_map.in_coordinates ContinuousLinearMap.inCoordinates variable {F F'} /-- Rewrite `ContinuousLinearMap.inCoordinates` using continuous linear equivalences. -/
Mathlib/Topology/VectorBundle/Basic.lean
1,029
1,037
theorem inCoordinates_eq (x₀ x : B) (y₀ y : B') (ϕ : E x →SL[σ] E' y) (hx : x ∈ (trivializationAt F E x₀).baseSet) (hy : y ∈ (trivializationAt F' E' y₀).baseSet) : inCoordinates F E F' E' x₀ x y₀ y ϕ = ((trivializationAt F' E' y₀).continuousLinearEquivAt 𝕜₂ y hy : E' y →L[𝕜₂] F').comp (ϕ.comp <| (((trivializationAt F E x₀).continuousLinearEquivAt 𝕜₁ x hx).symm : F →L[𝕜₁] E x)) := by
ext simp_rw [inCoordinates, ContinuousLinearMap.coe_comp', ContinuousLinearEquiv.coe_coe, Trivialization.coe_continuousLinearEquivAt_eq, Trivialization.symm_continuousLinearEquivAt_eq]
/- Copyright (c) 2022 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Gabin Kolly -/ import Mathlib.Init.Align import Mathlib.Data.Fintype.Order import Mathlib.Algebra.DirectLimit import Mathlib.ModelTheory.Quotients import Mathlib.ModelTheory.FinitelyGenerated #align_import model_theory.direct_limit from "leanprover-community/mathlib"@"f53b23994ac4c13afa38d31195c588a1121d1860" /-! # Direct Limits of First-Order Structures This file constructs the direct limit of a directed system of first-order embeddings. ## Main Definitions * `FirstOrder.Language.DirectLimit G f` is the direct limit of the directed system `f` of first-order embeddings between the structures indexed by `G`. * `FirstOrder.Language.DirectLimit.lift` is the universal property of the direct limit: maps from the components to another module that respect the directed system structure give rise to a unique map out of the direct limit. * `FirstOrder.Language.DirectLimit.equiv_lift` is the equivalence between limits of isomorphic direct systems. -/ universe v w w' u₁ u₂ open FirstOrder namespace FirstOrder namespace Language open Structure Set variable {L : Language} {ι : Type v} [Preorder ι] variable {G : ι → Type w} [∀ i, L.Structure (G i)] variable (f : ∀ i j, i ≤ j → G i ↪[L] G j) namespace DirectedSystem /-- A copy of `DirectedSystem.map_self` specialized to `L`-embeddings, as otherwise the `fun i j h ↦ f i j h` can confuse the simplifier. -/ nonrec theorem map_self [DirectedSystem G fun i j h => f i j h] (i x h) : f i i h x = x := DirectedSystem.map_self (fun i j h => f i j h) i x h #align first_order.language.directed_system.map_self FirstOrder.Language.DirectedSystem.map_self /-- A copy of `DirectedSystem.map_map` specialized to `L`-embeddings, as otherwise the `fun i j h ↦ f i j h` can confuse the simplifier. -/ nonrec theorem map_map [DirectedSystem G fun i j h => f i j h] {i j k} (hij hjk x) : f j k hjk (f i j hij x) = f i k (le_trans hij hjk) x := DirectedSystem.map_map (fun i j h => f i j h) hij hjk x #align first_order.language.directed_system.map_map FirstOrder.Language.DirectedSystem.map_map variable {G' : ℕ → Type w} [∀ i, L.Structure (G' i)] (f' : ∀ n : ℕ, G' n ↪[L] G' (n + 1)) /-- Given a chain of embeddings of structures indexed by `ℕ`, defines a `DirectedSystem` by composing them. -/ def natLERec (m n : ℕ) (h : m ≤ n) : G' m ↪[L] G' n := Nat.leRecOn h (@fun k g => (f' k).comp g) (Embedding.refl L _) #align first_order.language.directed_system.nat_le_rec FirstOrder.Language.DirectedSystem.natLERec @[simp] theorem coe_natLERec (m n : ℕ) (h : m ≤ n) : (natLERec f' m n h : G' m → G' n) = Nat.leRecOn h (@fun k => f' k) := by obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le h ext x induction' k with k ih · -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [natLERec, Nat.leRecOn_self, Embedding.refl_apply, Nat.leRecOn_self] · -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [Nat.leRecOn_succ le_self_add, natLERec, Nat.leRecOn_succ le_self_add, ← natLERec, Embedding.comp_apply, ih] #align first_order.language.directed_system.coe_nat_le_rec FirstOrder.Language.DirectedSystem.coe_natLERec instance natLERec.directedSystem : DirectedSystem G' fun i j h => natLERec f' i j h := ⟨fun i x _ => congr (congr rfl (Nat.leRecOn_self _)) rfl, fun hij hjk => by simp [Nat.leRecOn_trans hij hjk]⟩ #align first_order.language.directed_system.nat_le_rec.directed_system FirstOrder.Language.DirectedSystem.natLERec.directedSystem end DirectedSystem -- Porting note: Instead of `Σ i, G i`, we use the alias `Language.Structure.Sigma` -- which depends on `f`. This way, Lean can infer what `L` and `f` are in the `Setoid` instance. -- Otherwise we have a "cannot find synthesization order" error. See the discussion at -- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/local.20instance.20cannot.20find.20synthesization.20order.20in.20porting set_option linter.unusedVariables false in /-- Alias for `Σ i, G i`. -/ @[nolint unusedArguments] protected abbrev Structure.Sigma (f : ∀ i j, i ≤ j → G i ↪[L] G j) := Σ i, G i -- Porting note: Setting up notation for `Language.Structure.Sigma`: add a little asterisk to `Σ` local notation "Σˣ" => Structure.Sigma /-- Constructor for `FirstOrder.Language.Structure.Sigma` alias. -/ abbrev Structure.Sigma.mk (i : ι) (x : G i) : Σˣ f := ⟨i, x⟩ namespace DirectLimit /-- Raises a family of elements in the `Σ`-type to the same level along the embeddings. -/ def unify {α : Type*} (x : α → Σˣ f) (i : ι) (h : i ∈ upperBounds (range (Sigma.fst ∘ x))) (a : α) : G i := f (x a).1 i (h (mem_range_self a)) (x a).2 #align first_order.language.direct_limit.unify FirstOrder.Language.DirectLimit.unify variable [DirectedSystem G fun i j h => f i j h] @[simp] theorem unify_sigma_mk_self {α : Type*} {i : ι} {x : α → G i} : (unify f (fun a => .mk f i (x a)) i fun j ⟨a, hj⟩ => _root_.trans (le_of_eq hj.symm) (refl _)) = x := by ext a rw [unify] apply DirectedSystem.map_self #align first_order.language.direct_limit.unify_sigma_mk_self FirstOrder.Language.DirectLimit.unify_sigma_mk_self theorem comp_unify {α : Type*} {x : α → Σˣ f} {i j : ι} (ij : i ≤ j) (h : i ∈ upperBounds (range (Sigma.fst ∘ x))) : f i j ij ∘ unify f x i h = unify f x j fun k hk => _root_.trans (mem_upperBounds.1 h k hk) ij := by ext a simp [unify, DirectedSystem.map_map] #align first_order.language.direct_limit.comp_unify FirstOrder.Language.DirectLimit.comp_unify end DirectLimit variable (G) namespace DirectLimit /-- The directed limit glues together the structures along the embeddings. -/ def setoid [DirectedSystem G fun i j h => f i j h] [IsDirected ι (· ≤ ·)] : Setoid (Σˣ f) where r := fun ⟨i, x⟩ ⟨j, y⟩ => ∃ (k : ι) (ik : i ≤ k) (jk : j ≤ k), f i k ik x = f j k jk y iseqv := ⟨fun ⟨i, x⟩ => ⟨i, refl i, refl i, rfl⟩, @fun ⟨i, x⟩ ⟨j, y⟩ ⟨k, ik, jk, h⟩ => ⟨k, jk, ik, h.symm⟩, @fun ⟨i, x⟩ ⟨j, y⟩ ⟨k, z⟩ ⟨ij, hiij, hjij, hij⟩ ⟨jk, hjjk, hkjk, hjk⟩ => by obtain ⟨ijk, hijijk, hjkijk⟩ := directed_of (· ≤ ·) ij jk refine ⟨ijk, le_trans hiij hijijk, le_trans hkjk hjkijk, ?_⟩ rw [← DirectedSystem.map_map, hij, DirectedSystem.map_map] · symm rw [← DirectedSystem.map_map, ← hjk, DirectedSystem.map_map] <;> assumption⟩ #align first_order.language.direct_limit.setoid FirstOrder.Language.DirectLimit.setoid /-- The structure on the `Σ`-type which becomes the structure on the direct limit after quotienting. -/ noncomputable def sigmaStructure [IsDirected ι (· ≤ ·)] [Nonempty ι] : L.Structure (Σˣ f) where funMap F x := ⟨_, funMap F (unify f x (Classical.choose (Finite.bddAbove_range fun a => (x a).1)) (Classical.choose_spec (Finite.bddAbove_range fun a => (x a).1)))⟩ RelMap R x := RelMap R (unify f x (Classical.choose (Finite.bddAbove_range fun a => (x a).1)) (Classical.choose_spec (Finite.bddAbove_range fun a => (x a).1))) #align first_order.language.direct_limit.sigma_structure FirstOrder.Language.DirectLimit.sigmaStructure end DirectLimit /-- The direct limit of a directed system is the structures glued together along the embeddings. -/ def DirectLimit [DirectedSystem G fun i j h => f i j h] [IsDirected ι (· ≤ ·)] := Quotient (DirectLimit.setoid G f) #align first_order.language.direct_limit FirstOrder.Language.DirectLimit attribute [local instance] DirectLimit.setoid -- Porting note (#10754): Added local instance attribute [local instance] DirectLimit.sigmaStructure instance [DirectedSystem G fun i j h => f i j h] [IsDirected ι (· ≤ ·)] [Inhabited ι] [Inhabited (G default)] : Inhabited (DirectLimit G f) := ⟨⟦⟨default, default⟩⟧⟩ namespace DirectLimit variable [IsDirected ι (· ≤ ·)] [DirectedSystem G fun i j h => f i j h] theorem equiv_iff {x y : Σˣ f} {i : ι} (hx : x.1 ≤ i) (hy : y.1 ≤ i) : x ≈ y ↔ (f x.1 i hx) x.2 = (f y.1 i hy) y.2 := by cases x cases y refine ⟨fun xy => ?_, fun xy => ⟨i, hx, hy, xy⟩⟩ obtain ⟨j, _, _, h⟩ := xy obtain ⟨k, ik, jk⟩ := directed_of (· ≤ ·) i j have h := congr_arg (f j k jk) h apply (f i k ik).injective rw [DirectedSystem.map_map, DirectedSystem.map_map] at * exact h #align first_order.language.direct_limit.equiv_iff FirstOrder.Language.DirectLimit.equiv_iff theorem funMap_unify_equiv {n : ℕ} (F : L.Functions n) (x : Fin n → Σˣ f) (i j : ι) (hi : i ∈ upperBounds (range (Sigma.fst ∘ x))) (hj : j ∈ upperBounds (range (Sigma.fst ∘ x))) : Structure.Sigma.mk f i (funMap F (unify f x i hi)) ≈ .mk f j (funMap F (unify f x j hj)) := by obtain ⟨k, ik, jk⟩ := directed_of (· ≤ ·) i j refine ⟨k, ik, jk, ?_⟩ rw [(f i k ik).map_fun, (f j k jk).map_fun, comp_unify, comp_unify] #align first_order.language.direct_limit.fun_map_unify_equiv FirstOrder.Language.DirectLimit.funMap_unify_equiv theorem relMap_unify_equiv {n : ℕ} (R : L.Relations n) (x : Fin n → Σˣ f) (i j : ι) (hi : i ∈ upperBounds (range (Sigma.fst ∘ x))) (hj : j ∈ upperBounds (range (Sigma.fst ∘ x))) : RelMap R (unify f x i hi) = RelMap R (unify f x j hj) := by obtain ⟨k, ik, jk⟩ := directed_of (· ≤ ·) i j rw [← (f i k ik).map_rel, comp_unify, ← (f j k jk).map_rel, comp_unify] #align first_order.language.direct_limit.rel_map_unify_equiv FirstOrder.Language.DirectLimit.relMap_unify_equiv variable [Nonempty ι] theorem exists_unify_eq {α : Type*} [Finite α] {x y : α → Σˣ f} (xy : x ≈ y) : ∃ (i : ι) (hx : i ∈ upperBounds (range (Sigma.fst ∘ x))) (hy : i ∈ upperBounds (range (Sigma.fst ∘ y))), unify f x i hx = unify f y i hy := by obtain ⟨i, hi⟩ := Finite.bddAbove_range (Sum.elim (fun a => (x a).1) fun a => (y a).1) rw [Sum.elim_range, upperBounds_union] at hi simp_rw [← Function.comp_apply (f := Sigma.fst)] at hi exact ⟨i, hi.1, hi.2, funext fun a => (equiv_iff G f _ _).1 (xy a)⟩ #align first_order.language.direct_limit.exists_unify_eq FirstOrder.Language.DirectLimit.exists_unify_eq theorem funMap_equiv_unify {n : ℕ} (F : L.Functions n) (x : Fin n → Σˣ f) (i : ι) (hi : i ∈ upperBounds (range (Sigma.fst ∘ x))) : funMap F x ≈ .mk f _ (funMap F (unify f x i hi)) := funMap_unify_equiv G f F x (Classical.choose (Finite.bddAbove_range fun a => (x a).1)) i _ hi #align first_order.language.direct_limit.fun_map_equiv_unify FirstOrder.Language.DirectLimit.funMap_equiv_unify theorem relMap_equiv_unify {n : ℕ} (R : L.Relations n) (x : Fin n → Σˣ f) (i : ι) (hi : i ∈ upperBounds (range (Sigma.fst ∘ x))) : RelMap R x = RelMap R (unify f x i hi) := relMap_unify_equiv G f R x (Classical.choose (Finite.bddAbove_range fun a => (x a).1)) i _ hi #align first_order.language.direct_limit.rel_map_equiv_unify FirstOrder.Language.DirectLimit.relMap_equiv_unify /-- The direct limit `setoid` respects the structure `sigmaStructure`, so quotienting by it gives rise to a valid structure. -/ noncomputable instance prestructure : L.Prestructure (DirectLimit.setoid G f) where toStructure := sigmaStructure G f fun_equiv {n} {F} x y xy := by obtain ⟨i, hx, hy, h⟩ := exists_unify_eq G f xy refine Setoid.trans (funMap_equiv_unify G f F x i hx) (Setoid.trans ?_ (Setoid.symm (funMap_equiv_unify G f F y i hy))) rw [h] rel_equiv {n} {R} x y xy := by obtain ⟨i, hx, hy, h⟩ := exists_unify_eq G f xy refine _root_.trans (relMap_equiv_unify G f R x i hx) (_root_.trans ?_ (symm (relMap_equiv_unify G f R y i hy))) rw [h] #align first_order.language.direct_limit.prestructure FirstOrder.Language.DirectLimit.prestructure /-- The `L.Structure` on a direct limit of `L.Structure`s. -/ noncomputable instance instStructureDirectLimit : L.Structure (DirectLimit G f) := Language.quotientStructure set_option linter.uppercaseLean3 false in #align first_order.language.direct_limit.Structure FirstOrder.Language.DirectLimit.instStructureDirectLimit @[simp] theorem funMap_quotient_mk'_sigma_mk' {n : ℕ} {F : L.Functions n} {i : ι} {x : Fin n → G i} : funMap F (fun a => (⟦.mk f i (x a)⟧ : DirectLimit G f)) = ⟦.mk f i (funMap F x)⟧ := by simp only [funMap_quotient_mk', Quotient.eq] obtain ⟨k, ik, jk⟩ := directed_of (· ≤ ·) i (Classical.choose (Finite.bddAbove_range fun _ : Fin n => i)) refine ⟨k, jk, ik, ?_⟩ simp only [Embedding.map_fun, comp_unify] rfl #align first_order.language.direct_limit.fun_map_quotient_mk_sigma_mk FirstOrder.Language.DirectLimit.funMap_quotient_mk'_sigma_mk' @[simp] theorem relMap_quotient_mk'_sigma_mk' {n : ℕ} {R : L.Relations n} {i : ι} {x : Fin n → G i} : RelMap R (fun a => (⟦.mk f i (x a)⟧ : DirectLimit G f)) = RelMap R x := by rw [relMap_quotient_mk'] obtain ⟨k, _, _⟩ := directed_of (· ≤ ·) i (Classical.choose (Finite.bddAbove_range fun _ : Fin n => i)) rw [relMap_equiv_unify G f R (fun a => .mk f i (x a)) i] rw [unify_sigma_mk_self] #align first_order.language.direct_limit.rel_map_quotient_mk_sigma_mk FirstOrder.Language.DirectLimit.relMap_quotient_mk'_sigma_mk'
Mathlib/ModelTheory/DirectLimit.lean
279
291
theorem exists_quotient_mk'_sigma_mk'_eq {α : Type*} [Finite α] (x : α → DirectLimit G f) : ∃ (i : ι) (y : α → G i), x = fun a => ⟦.mk f i (y a)⟧ := by
obtain ⟨i, hi⟩ := Finite.bddAbove_range fun a => (x a).out.1 refine ⟨i, unify f (Quotient.out ∘ x) i hi, ?_⟩ ext a rw [Quotient.eq_mk_iff_out, unify] generalize_proofs r change _ ≈ .mk f i (f (Quotient.out (x a)).fst i r (Quotient.out (x a)).snd) have : (.mk f i (f (Quotient.out (x a)).fst i r (Quotient.out (x a)).snd) : Σˣ f).fst ≤ i := le_rfl rw [equiv_iff G f (i := i) (hi _) this] · simp only [DirectedSystem.map_self] exact ⟨a, rfl⟩
/- 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
Mathlib/MeasureTheory/Integral/Lebesgue.lean
1,010
1,014
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
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Floris van Doorn -/ import Mathlib.Analysis.Calculus.ContDiff.Defs import Mathlib.Analysis.Calculus.FDeriv.Add import Mathlib.Analysis.Calculus.FDeriv.Mul import Mathlib.Analysis.Calculus.Deriv.Inverse #align_import analysis.calculus.cont_diff from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # Higher differentiability of usual operations We prove that the usual operations (addition, multiplication, difference, composition, and so on) preserve `C^n` functions. We also expand the API around `C^n` functions. ## Main results * `ContDiff.comp` states that the composition of two `C^n` functions is `C^n`. Similar results are given for `C^n` functions on domains. ## Notations We use the notation `E [×n]→L[𝕜] F` for the space of continuous multilinear maps on `E^n` with values in `F`. This is the space in which the `n`-th derivative of a function from `E` to `F` lives. In this file, we denote `⊤ : ℕ∞` with `∞`. ## Tags derivative, differentiability, higher derivative, `C^n`, multilinear, Taylor series, formal series -/ noncomputable section open scoped Classical NNReal Nat local notation "∞" => (⊤ : ℕ∞) universe u v w uD uE uF uG attribute [local instance 1001] NormedAddCommGroup.toAddCommGroup NormedSpace.toModule' AddCommGroup.toAddCommMonoid open Set Fin Filter Function open scoped Topology variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {D : Type uD} [NormedAddCommGroup D] [NormedSpace 𝕜 D] {E : Type uE} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type uF} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type uG} [NormedAddCommGroup G] [NormedSpace 𝕜 G] {X : Type*} [NormedAddCommGroup X] [NormedSpace 𝕜 X] {s s₁ t u : Set E} {f f₁ : E → F} {g : F → G} {x x₀ : E} {c : F} {b : E × F → G} {m n : ℕ∞} {p : E → FormalMultilinearSeries 𝕜 E F} /-! ### Constants -/ @[simp] theorem iteratedFDerivWithin_zero_fun (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) {i : ℕ} : iteratedFDerivWithin 𝕜 i (fun _ : E ↦ (0 : F)) s x = 0 := by induction i generalizing x with | zero => ext; simp | succ i IH => ext m rw [iteratedFDerivWithin_succ_apply_left, fderivWithin_congr (fun _ ↦ IH) (IH hx)] rw [fderivWithin_const_apply _ (hs x hx)] rfl @[simp] theorem iteratedFDeriv_zero_fun {n : ℕ} : (iteratedFDeriv 𝕜 n fun _ : E ↦ (0 : F)) = 0 := funext fun x ↦ by simpa [← iteratedFDerivWithin_univ] using iteratedFDerivWithin_zero_fun uniqueDiffOn_univ (mem_univ x) #align iterated_fderiv_zero_fun iteratedFDeriv_zero_fun theorem contDiff_zero_fun : ContDiff 𝕜 n fun _ : E => (0 : F) := contDiff_of_differentiable_iteratedFDeriv fun m _ => by rw [iteratedFDeriv_zero_fun] exact differentiable_const (0 : E[×m]→L[𝕜] F) #align cont_diff_zero_fun contDiff_zero_fun /-- Constants are `C^∞`. -/ theorem contDiff_const {c : F} : ContDiff 𝕜 n fun _ : E => c := by suffices h : ContDiff 𝕜 ∞ fun _ : E => c from h.of_le le_top rw [contDiff_top_iff_fderiv] refine ⟨differentiable_const c, ?_⟩ rw [fderiv_const] exact contDiff_zero_fun #align cont_diff_const contDiff_const theorem contDiffOn_const {c : F} {s : Set E} : ContDiffOn 𝕜 n (fun _ : E => c) s := contDiff_const.contDiffOn #align cont_diff_on_const contDiffOn_const theorem contDiffAt_const {c : F} : ContDiffAt 𝕜 n (fun _ : E => c) x := contDiff_const.contDiffAt #align cont_diff_at_const contDiffAt_const theorem contDiffWithinAt_const {c : F} : ContDiffWithinAt 𝕜 n (fun _ : E => c) s x := contDiffAt_const.contDiffWithinAt #align cont_diff_within_at_const contDiffWithinAt_const @[nontriviality] theorem contDiff_of_subsingleton [Subsingleton F] : ContDiff 𝕜 n f := by rw [Subsingleton.elim f fun _ => 0]; exact contDiff_const #align cont_diff_of_subsingleton contDiff_of_subsingleton @[nontriviality] theorem contDiffAt_of_subsingleton [Subsingleton F] : ContDiffAt 𝕜 n f x := by rw [Subsingleton.elim f fun _ => 0]; exact contDiffAt_const #align cont_diff_at_of_subsingleton contDiffAt_of_subsingleton @[nontriviality] theorem contDiffWithinAt_of_subsingleton [Subsingleton F] : ContDiffWithinAt 𝕜 n f s x := by rw [Subsingleton.elim f fun _ => 0]; exact contDiffWithinAt_const #align cont_diff_within_at_of_subsingleton contDiffWithinAt_of_subsingleton @[nontriviality]
Mathlib/Analysis/Calculus/ContDiff/Basic.lean
122
123
theorem contDiffOn_of_subsingleton [Subsingleton F] : ContDiffOn 𝕜 n f s := by
rw [Subsingleton.elim f fun _ => 0]; exact contDiffOn_const
/- Copyright (c) 2022 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.FieldTheory.Minpoly.IsIntegrallyClosed import Mathlib.RingTheory.PowerBasis #align_import ring_theory.is_adjoin_root from "leanprover-community/mathlib"@"f7fc89d5d5ff1db2d1242c7bb0e9062ce47ef47c" /-! # A predicate on adjoining roots of polynomial This file defines a predicate `IsAdjoinRoot S f`, which states that the ring `S` can be constructed by adjoining a specified root of the polynomial `f : R[X]` to `R`. This predicate is useful when the same ring can be generated by adjoining the root of different polynomials, and you want to vary which polynomial you're considering. The results in this file are intended to mirror those in `RingTheory.AdjoinRoot`, in order to provide an easier way to translate results from one to the other. ## Motivation `AdjoinRoot` presents one construction of a ring `R[α]`. However, it is possible to obtain rings of this form in many ways, such as `NumberField.ringOfIntegers ℚ(√-5)`, or `Algebra.adjoin R {α, α^2}`, or `IntermediateField.adjoin R {α, 2 - α}`, or even if we want to view `ℂ` as adjoining a root of `X^2 + 1` to `ℝ`. ## Main definitions The two main predicates in this file are: * `IsAdjoinRoot S f`: `S` is generated by adjoining a specified root of `f : R[X]` to `R` * `IsAdjoinRootMonic S f`: `S` is generated by adjoining a root of the monic polynomial `f : R[X]` to `R` Using `IsAdjoinRoot` to map into `S`: * `IsAdjoinRoot.map`: inclusion from `R[X]` to `S` * `IsAdjoinRoot.root`: the specific root adjoined to `R` to give `S` Using `IsAdjoinRoot` to map out of `S`: * `IsAdjoinRoot.repr`: choose a non-unique representative in `R[X]` * `IsAdjoinRoot.lift`, `IsAdjoinRoot.liftHom`: lift a morphism `R →+* T` to `S →+* T` * `IsAdjoinRootMonic.modByMonicHom`: a unique representative in `R[X]` if `f` is monic ## Main results * `AdjoinRoot.isAdjoinRoot` and `AdjoinRoot.isAdjoinRootMonic`: `AdjoinRoot` satisfies the conditions on `IsAdjoinRoot`(`_monic`) * `IsAdjoinRootMonic.powerBasis`: the `root` generates a power basis on `S` over `R` * `IsAdjoinRoot.aequiv`: algebra isomorphism showing adjoining a root gives a unique ring up to isomorphism * `IsAdjoinRoot.ofEquiv`: transfer `IsAdjoinRoot` across an algebra isomorphism * `IsAdjoinRootMonic.minpoly_eq`: the minimal polynomial of the adjoined root of `f` is equal to `f`, if `f` is irreducible and monic, and `R` is a GCD domain -/ open scoped Polynomial open Polynomial noncomputable section universe u v -- Porting note: this looks like something that should not be here -- section MoveMe -- -- end MoveMe -- This class doesn't really make sense on a predicate /-- `IsAdjoinRoot S f` states that the ring `S` can be constructed by adjoining a specified root of the polynomial `f : R[X]` to `R`. Compare `PowerBasis R S`, which does not explicitly specify which polynomial we adjoin a root of (in particular `f` does not need to be the minimal polynomial of the root we adjoin), and `AdjoinRoot` which constructs a new type. This is not a typeclass because the choice of root given `S` and `f` is not unique. -/ -- Porting note(#5171): this linter isn't ported yet. -- @[nolint has_nonempty_instance] structure IsAdjoinRoot {R : Type u} (S : Type v) [CommSemiring R] [Semiring S] [Algebra R S] (f : R[X]) : Type max u v where map : R[X] →+* S map_surjective : Function.Surjective map ker_map : RingHom.ker map = Ideal.span {f} algebraMap_eq : algebraMap R S = map.comp Polynomial.C #align is_adjoin_root IsAdjoinRoot -- This class doesn't really make sense on a predicate /-- `IsAdjoinRootMonic S f` states that the ring `S` can be constructed by adjoining a specified root of the monic polynomial `f : R[X]` to `R`. As long as `f` is monic, there is a well-defined representation of elements of `S` as polynomials in `R[X]` of degree lower than `deg f` (see `modByMonicHom` and `coeff`). In particular, we have `IsAdjoinRootMonic.powerBasis`. Bundling `Monic` into this structure is very useful when working with explicit `f`s such as `X^2 - C a * X - C b` since it saves you carrying around the proofs of monicity. -/ -- @[nolint has_nonempty_instance] -- Porting note: This linter does not exist yet. structure IsAdjoinRootMonic {R : Type u} (S : Type v) [CommSemiring R] [Semiring S] [Algebra R S] (f : R[X]) extends IsAdjoinRoot S f where Monic : Monic f #align is_adjoin_root_monic IsAdjoinRootMonic section Ring variable {R : Type u} {S : Type v} [CommRing R] [Ring S] {f : R[X]} [Algebra R S] namespace IsAdjoinRoot /-- `(h : IsAdjoinRoot S f).root` is the root of `f` that can be adjoined to generate `S`. -/ def root (h : IsAdjoinRoot S f) : S := h.map X #align is_adjoin_root.root IsAdjoinRoot.root theorem subsingleton (h : IsAdjoinRoot S f) [Subsingleton R] : Subsingleton S := h.map_surjective.subsingleton #align is_adjoin_root.subsingleton IsAdjoinRoot.subsingleton theorem algebraMap_apply (h : IsAdjoinRoot S f) (x : R) : algebraMap R S x = h.map (Polynomial.C x) := by rw [h.algebraMap_eq, RingHom.comp_apply] #align is_adjoin_root.algebra_map_apply IsAdjoinRoot.algebraMap_apply @[simp] theorem mem_ker_map (h : IsAdjoinRoot S f) {p} : p ∈ RingHom.ker h.map ↔ f ∣ p := by rw [h.ker_map, Ideal.mem_span_singleton] #align is_adjoin_root.mem_ker_map IsAdjoinRoot.mem_ker_map theorem map_eq_zero_iff (h : IsAdjoinRoot S f) {p} : h.map p = 0 ↔ f ∣ p := by rw [← h.mem_ker_map, RingHom.mem_ker] #align is_adjoin_root.map_eq_zero_iff IsAdjoinRoot.map_eq_zero_iff @[simp] theorem map_X (h : IsAdjoinRoot S f) : h.map X = h.root := rfl set_option linter.uppercaseLean3 false in #align is_adjoin_root.map_X IsAdjoinRoot.map_X @[simp] theorem map_self (h : IsAdjoinRoot S f) : h.map f = 0 := h.map_eq_zero_iff.mpr dvd_rfl #align is_adjoin_root.map_self IsAdjoinRoot.map_self @[simp] theorem aeval_eq (h : IsAdjoinRoot S f) (p : R[X]) : aeval h.root p = h.map p := Polynomial.induction_on p (fun x => by rw [aeval_C, h.algebraMap_apply]) (fun p q ihp ihq => by rw [AlgHom.map_add, RingHom.map_add, ihp, ihq]) fun n x _ => by rw [AlgHom.map_mul, aeval_C, AlgHom.map_pow, aeval_X, RingHom.map_mul, ← h.algebraMap_apply, RingHom.map_pow, map_X] #align is_adjoin_root.aeval_eq IsAdjoinRoot.aeval_eq -- @[simp] -- Porting note (#10618): simp can prove this theorem aeval_root (h : IsAdjoinRoot S f) : aeval h.root f = 0 := by rw [aeval_eq, map_self] #align is_adjoin_root.aeval_root IsAdjoinRoot.aeval_root /-- Choose an arbitrary representative so that `h.map (h.repr x) = x`. If `f` is monic, use `IsAdjoinRootMonic.modByMonicHom` for a unique choice of representative. -/ def repr (h : IsAdjoinRoot S f) (x : S) : R[X] := (h.map_surjective x).choose #align is_adjoin_root.repr IsAdjoinRoot.repr theorem map_repr (h : IsAdjoinRoot S f) (x : S) : h.map (h.repr x) = x := (h.map_surjective x).choose_spec #align is_adjoin_root.map_repr IsAdjoinRoot.map_repr /-- `repr` preserves zero, up to multiples of `f` -/ theorem repr_zero_mem_span (h : IsAdjoinRoot S f) : h.repr 0 ∈ Ideal.span ({f} : Set R[X]) := by rw [← h.ker_map, RingHom.mem_ker, h.map_repr] #align is_adjoin_root.repr_zero_mem_span IsAdjoinRoot.repr_zero_mem_span /-- `repr` preserves addition, up to multiples of `f` -/ theorem repr_add_sub_repr_add_repr_mem_span (h : IsAdjoinRoot S f) (x y : S) : h.repr (x + y) - (h.repr x + h.repr y) ∈ Ideal.span ({f} : Set R[X]) := by rw [← h.ker_map, RingHom.mem_ker, map_sub, h.map_repr, map_add, h.map_repr, h.map_repr, sub_self] #align is_adjoin_root.repr_add_sub_repr_add_repr_mem_span IsAdjoinRoot.repr_add_sub_repr_add_repr_mem_span /-- Extensionality of the `IsAdjoinRoot` structure itself. See `IsAdjoinRootMonic.ext_elem` for extensionality of the ring elements. -/ theorem ext_map (h h' : IsAdjoinRoot S f) (eq : ∀ x, h.map x = h'.map x) : h = h' := by cases h; cases h'; congr exact RingHom.ext eq #align is_adjoin_root.ext_map IsAdjoinRoot.ext_map /-- Extensionality of the `IsAdjoinRoot` structure itself. See `IsAdjoinRootMonic.ext_elem` for extensionality of the ring elements. -/ @[ext] theorem ext (h h' : IsAdjoinRoot S f) (eq : h.root = h'.root) : h = h' := h.ext_map h' fun x => by rw [← h.aeval_eq, ← h'.aeval_eq, eq] #align is_adjoin_root.ext IsAdjoinRoot.ext section lift variable {T : Type*} [CommRing T] {i : R →+* T} {x : T} (hx : f.eval₂ i x = 0) /-- Auxiliary lemma for `IsAdjoinRoot.lift` -/ theorem eval₂_repr_eq_eval₂_of_map_eq (h : IsAdjoinRoot S f) (z : S) (w : R[X]) (hzw : h.map w = z) : (h.repr z).eval₂ i x = w.eval₂ i x := by rw [eq_comm, ← sub_eq_zero, ← h.map_repr z, ← map_sub, h.map_eq_zero_iff] at hzw obtain ⟨y, hy⟩ := hzw rw [← sub_eq_zero, ← eval₂_sub, hy, eval₂_mul, hx, zero_mul] #align is_adjoin_root.eval₂_repr_eq_eval₂_of_map_eq IsAdjoinRoot.eval₂_repr_eq_eval₂_of_map_eq variable (i x) -- To match `AdjoinRoot.lift` /-- Lift a ring homomorphism `R →+* T` to `S →+* T` by specifying a root `x` of `f` in `T`, where `S` is given by adjoining a root of `f` to `R`. -/ def lift (h : IsAdjoinRoot S f) : S →+* T where toFun z := (h.repr z).eval₂ i x map_zero' := by dsimp only -- Porting note (#10752): added `dsimp only` rw [h.eval₂_repr_eq_eval₂_of_map_eq hx _ _ (map_zero _), eval₂_zero] map_add' z w := by dsimp only -- Porting note (#10752): added `dsimp only` rw [h.eval₂_repr_eq_eval₂_of_map_eq hx _ (h.repr z + h.repr w), eval₂_add] rw [map_add, map_repr, map_repr] map_one' := by beta_reduce -- Porting note (#12129): additional beta reduction needed rw [h.eval₂_repr_eq_eval₂_of_map_eq hx _ _ (map_one _), eval₂_one] map_mul' z w := by dsimp only -- Porting note (#10752): added `dsimp only` rw [h.eval₂_repr_eq_eval₂_of_map_eq hx _ (h.repr z * h.repr w), eval₂_mul] rw [map_mul, map_repr, map_repr] #align is_adjoin_root.lift IsAdjoinRoot.lift variable {i x} @[simp] theorem lift_map (h : IsAdjoinRoot S f) (z : R[X]) : h.lift i x hx (h.map z) = z.eval₂ i x := by rw [lift, RingHom.coe_mk] dsimp -- Porting note (#11227):added a `dsimp` rw [h.eval₂_repr_eq_eval₂_of_map_eq hx _ _ rfl] #align is_adjoin_root.lift_map IsAdjoinRoot.lift_map @[simp]
Mathlib/RingTheory/IsAdjoinRoot.lean
243
244
theorem lift_root (h : IsAdjoinRoot S f) : h.lift i x hx h.root = x := by
rw [← h.map_X, lift_map, eval₂_X]
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Algebra.GroupPower.IterateHom import Mathlib.Algebra.Ring.Divisibility.Basic import Mathlib.Data.List.Cycle import Mathlib.Data.Nat.Prime import Mathlib.Data.PNat.Basic import Mathlib.Dynamics.FixedPoints.Basic import Mathlib.GroupTheory.GroupAction.Group #align_import dynamics.periodic_pts from "leanprover-community/mathlib"@"d07245fd37786daa997af4f1a73a49fa3b748408" /-! # Periodic points A point `x : α` is a periodic point of `f : α → α` of period `n` if `f^[n] x = x`. ## Main definitions * `IsPeriodicPt f n x` : `x` is a periodic point of `f` of period `n`, i.e. `f^[n] x = x`. We do not require `n > 0` in the definition. * `ptsOfPeriod f n` : the set `{x | IsPeriodicPt f n x}`. Note that `n` is not required to be the minimal period of `x`. * `periodicPts f` : the set of all periodic points of `f`. * `minimalPeriod f x` : the minimal period of a point `x` under an endomorphism `f` or zero if `x` is not a periodic point of `f`. * `orbit f x`: the cycle `[x, f x, f (f x), ...]` for a periodic point. * `MulAction.period g x` : the minimal period of a point `x` under the multiplicative action of `g`; an equivalent `AddAction.period g x` is defined for additive actions. ## Main statements We provide “dot syntax”-style operations on terms of the form `h : IsPeriodicPt f n x` including arithmetic operations on `n` and `h.map (hg : SemiconjBy g f f')`. We also prove that `f` is bijective on each set `ptsOfPeriod f n` and on `periodicPts f`. Finally, we prove that `x` is a periodic point of `f` of period `n` if and only if `minimalPeriod f x | n`. ## References * https://en.wikipedia.org/wiki/Periodic_point -/ open Set namespace Function open Function (Commute) variable {α : Type*} {β : Type*} {f fa : α → α} {fb : β → β} {x y : α} {m n : ℕ} /-- A point `x` is a periodic point of `f : α → α` of period `n` if `f^[n] x = x`. Note that we do not require `0 < n` in this definition. Many theorems about periodic points need this assumption. -/ def IsPeriodicPt (f : α → α) (n : ℕ) (x : α) := IsFixedPt f^[n] x #align function.is_periodic_pt Function.IsPeriodicPt /-- A fixed point of `f` is a periodic point of `f` of any prescribed period. -/ theorem IsFixedPt.isPeriodicPt (hf : IsFixedPt f x) (n : ℕ) : IsPeriodicPt f n x := hf.iterate n #align function.is_fixed_pt.is_periodic_pt Function.IsFixedPt.isPeriodicPt /-- For the identity map, all points are periodic. -/ theorem is_periodic_id (n : ℕ) (x : α) : IsPeriodicPt id n x := (isFixedPt_id x).isPeriodicPt n #align function.is_periodic_id Function.is_periodic_id /-- Any point is a periodic point of period `0`. -/ theorem isPeriodicPt_zero (f : α → α) (x : α) : IsPeriodicPt f 0 x := isFixedPt_id x #align function.is_periodic_pt_zero Function.isPeriodicPt_zero namespace IsPeriodicPt instance [DecidableEq α] {f : α → α} {n : ℕ} {x : α} : Decidable (IsPeriodicPt f n x) := IsFixedPt.decidable protected theorem isFixedPt (hf : IsPeriodicPt f n x) : IsFixedPt f^[n] x := hf #align function.is_periodic_pt.is_fixed_pt Function.IsPeriodicPt.isFixedPt protected theorem map (hx : IsPeriodicPt fa n x) {g : α → β} (hg : Semiconj g fa fb) : IsPeriodicPt fb n (g x) := IsFixedPt.map hx (hg.iterate_right n) #align function.is_periodic_pt.map Function.IsPeriodicPt.map theorem apply_iterate (hx : IsPeriodicPt f n x) (m : ℕ) : IsPeriodicPt f n (f^[m] x) := hx.map <| Commute.iterate_self f m #align function.is_periodic_pt.apply_iterate Function.IsPeriodicPt.apply_iterate protected theorem apply (hx : IsPeriodicPt f n x) : IsPeriodicPt f n (f x) := hx.apply_iterate 1 #align function.is_periodic_pt.apply Function.IsPeriodicPt.apply protected theorem add (hn : IsPeriodicPt f n x) (hm : IsPeriodicPt f m x) : IsPeriodicPt f (n + m) x := by rw [IsPeriodicPt, iterate_add] exact hn.comp hm #align function.is_periodic_pt.add Function.IsPeriodicPt.add theorem left_of_add (hn : IsPeriodicPt f (n + m) x) (hm : IsPeriodicPt f m x) : IsPeriodicPt f n x := by rw [IsPeriodicPt, iterate_add] at hn exact hn.left_of_comp hm #align function.is_periodic_pt.left_of_add Function.IsPeriodicPt.left_of_add theorem right_of_add (hn : IsPeriodicPt f (n + m) x) (hm : IsPeriodicPt f n x) : IsPeriodicPt f m x := by rw [add_comm] at hn exact hn.left_of_add hm #align function.is_periodic_pt.right_of_add Function.IsPeriodicPt.right_of_add protected theorem sub (hm : IsPeriodicPt f m x) (hn : IsPeriodicPt f n x) : IsPeriodicPt f (m - n) x := by rcases le_total n m with h | h · refine left_of_add ?_ hn rwa [tsub_add_cancel_of_le h] · rw [tsub_eq_zero_iff_le.mpr h] apply isPeriodicPt_zero #align function.is_periodic_pt.sub Function.IsPeriodicPt.sub protected theorem mul_const (hm : IsPeriodicPt f m x) (n : ℕ) : IsPeriodicPt f (m * n) x := by simp only [IsPeriodicPt, iterate_mul, hm.isFixedPt.iterate n] #align function.is_periodic_pt.mul_const Function.IsPeriodicPt.mul_const protected theorem const_mul (hm : IsPeriodicPt f m x) (n : ℕ) : IsPeriodicPt f (n * m) x := by simp only [mul_comm n, hm.mul_const n] #align function.is_periodic_pt.const_mul Function.IsPeriodicPt.const_mul theorem trans_dvd (hm : IsPeriodicPt f m x) {n : ℕ} (hn : m ∣ n) : IsPeriodicPt f n x := let ⟨k, hk⟩ := hn hk.symm ▸ hm.mul_const k #align function.is_periodic_pt.trans_dvd Function.IsPeriodicPt.trans_dvd protected theorem iterate (hf : IsPeriodicPt f n x) (m : ℕ) : IsPeriodicPt f^[m] n x := by rw [IsPeriodicPt, ← iterate_mul, mul_comm, iterate_mul] exact hf.isFixedPt.iterate m #align function.is_periodic_pt.iterate Function.IsPeriodicPt.iterate theorem comp {g : α → α} (hco : Commute f g) (hf : IsPeriodicPt f n x) (hg : IsPeriodicPt g n x) : IsPeriodicPt (f ∘ g) n x := by rw [IsPeriodicPt, hco.comp_iterate] exact IsFixedPt.comp hf hg #align function.is_periodic_pt.comp Function.IsPeriodicPt.comp theorem comp_lcm {g : α → α} (hco : Commute f g) (hf : IsPeriodicPt f m x) (hg : IsPeriodicPt g n x) : IsPeriodicPt (f ∘ g) (Nat.lcm m n) x := (hf.trans_dvd <| Nat.dvd_lcm_left _ _).comp hco (hg.trans_dvd <| Nat.dvd_lcm_right _ _) #align function.is_periodic_pt.comp_lcm Function.IsPeriodicPt.comp_lcm theorem left_of_comp {g : α → α} (hco : Commute f g) (hfg : IsPeriodicPt (f ∘ g) n x) (hg : IsPeriodicPt g n x) : IsPeriodicPt f n x := by rw [IsPeriodicPt, hco.comp_iterate] at hfg exact hfg.left_of_comp hg #align function.is_periodic_pt.left_of_comp Function.IsPeriodicPt.left_of_comp theorem iterate_mod_apply (h : IsPeriodicPt f n x) (m : ℕ) : f^[m % n] x = f^[m] x := by conv_rhs => rw [← Nat.mod_add_div m n, iterate_add_apply, (h.mul_const _).eq] #align function.is_periodic_pt.iterate_mod_apply Function.IsPeriodicPt.iterate_mod_apply protected theorem mod (hm : IsPeriodicPt f m x) (hn : IsPeriodicPt f n x) : IsPeriodicPt f (m % n) x := (hn.iterate_mod_apply m).trans hm #align function.is_periodic_pt.mod Function.IsPeriodicPt.mod protected theorem gcd (hm : IsPeriodicPt f m x) (hn : IsPeriodicPt f n x) : IsPeriodicPt f (m.gcd n) x := by revert hm hn refine Nat.gcd.induction m n (fun n _ hn => ?_) fun m n _ ih hm hn => ?_ · rwa [Nat.gcd_zero_left] · rw [Nat.gcd_rec] exact ih (hn.mod hm) hm #align function.is_periodic_pt.gcd Function.IsPeriodicPt.gcd /-- If `f` sends two periodic points `x` and `y` of the same positive period to the same point, then `x = y`. For a similar statement about points of different periods see `eq_of_apply_eq`. -/ theorem eq_of_apply_eq_same (hx : IsPeriodicPt f n x) (hy : IsPeriodicPt f n y) (hn : 0 < n) (h : f x = f y) : x = y := by rw [← hx.eq, ← hy.eq, ← iterate_pred_comp_of_pos f hn, comp_apply, comp_apply, h] #align function.is_periodic_pt.eq_of_apply_eq_same Function.IsPeriodicPt.eq_of_apply_eq_same /-- If `f` sends two periodic points `x` and `y` of positive periods to the same point, then `x = y`. -/ theorem eq_of_apply_eq (hx : IsPeriodicPt f m x) (hy : IsPeriodicPt f n y) (hm : 0 < m) (hn : 0 < n) (h : f x = f y) : x = y := (hx.mul_const n).eq_of_apply_eq_same (hy.const_mul m) (mul_pos hm hn) h #align function.is_periodic_pt.eq_of_apply_eq Function.IsPeriodicPt.eq_of_apply_eq end IsPeriodicPt /-- The set of periodic points of a given (possibly non-minimal) period. -/ def ptsOfPeriod (f : α → α) (n : ℕ) : Set α := { x : α | IsPeriodicPt f n x } #align function.pts_of_period Function.ptsOfPeriod @[simp] theorem mem_ptsOfPeriod : x ∈ ptsOfPeriod f n ↔ IsPeriodicPt f n x := Iff.rfl #align function.mem_pts_of_period Function.mem_ptsOfPeriod theorem Semiconj.mapsTo_ptsOfPeriod {g : α → β} (h : Semiconj g fa fb) (n : ℕ) : MapsTo g (ptsOfPeriod fa n) (ptsOfPeriod fb n) := (h.iterate_right n).mapsTo_fixedPoints #align function.semiconj.maps_to_pts_of_period Function.Semiconj.mapsTo_ptsOfPeriod theorem bijOn_ptsOfPeriod (f : α → α) {n : ℕ} (hn : 0 < n) : BijOn f (ptsOfPeriod f n) (ptsOfPeriod f n) := ⟨(Commute.refl f).mapsTo_ptsOfPeriod n, fun x hx y hy hxy => hx.eq_of_apply_eq_same hy hn hxy, fun x hx => ⟨f^[n.pred] x, hx.apply_iterate _, by rw [← comp_apply (f := f), comp_iterate_pred_of_pos f hn, hx.eq]⟩⟩ #align function.bij_on_pts_of_period Function.bijOn_ptsOfPeriod theorem directed_ptsOfPeriod_pNat (f : α → α) : Directed (· ⊆ ·) fun n : ℕ+ => ptsOfPeriod f n := fun m n => ⟨m * n, fun _ hx => hx.mul_const n, fun _ hx => hx.const_mul m⟩ #align function.directed_pts_of_period_pnat Function.directed_ptsOfPeriod_pNat /-- The set of periodic points of a map `f : α → α`. -/ def periodicPts (f : α → α) : Set α := { x : α | ∃ n > 0, IsPeriodicPt f n x } #align function.periodic_pts Function.periodicPts theorem mk_mem_periodicPts (hn : 0 < n) (hx : IsPeriodicPt f n x) : x ∈ periodicPts f := ⟨n, hn, hx⟩ #align function.mk_mem_periodic_pts Function.mk_mem_periodicPts theorem mem_periodicPts : x ∈ periodicPts f ↔ ∃ n > 0, IsPeriodicPt f n x := Iff.rfl #align function.mem_periodic_pts Function.mem_periodicPts theorem isPeriodicPt_of_mem_periodicPts_of_isPeriodicPt_iterate (hx : x ∈ periodicPts f) (hm : IsPeriodicPt f m (f^[n] x)) : IsPeriodicPt f m x := by rcases hx with ⟨r, hr, hr'⟩ suffices n ≤ (n / r + 1) * r by -- Porting note: convert used to unfold IsPeriodicPt change _ = _ convert (hm.apply_iterate ((n / r + 1) * r - n)).eq <;> rw [← iterate_add_apply, Nat.sub_add_cancel this, iterate_mul, (hr'.iterate _).eq] rw [add_mul, one_mul] exact (Nat.lt_div_mul_add hr).le #align function.is_periodic_pt_of_mem_periodic_pts_of_is_periodic_pt_iterate Function.isPeriodicPt_of_mem_periodicPts_of_isPeriodicPt_iterate variable (f) theorem bUnion_ptsOfPeriod : ⋃ n > 0, ptsOfPeriod f n = periodicPts f := Set.ext fun x => by simp [mem_periodicPts] #align function.bUnion_pts_of_period Function.bUnion_ptsOfPeriod theorem iUnion_pNat_ptsOfPeriod : ⋃ n : ℕ+, ptsOfPeriod f n = periodicPts f := iSup_subtype.trans <| bUnion_ptsOfPeriod f #align function.Union_pnat_pts_of_period Function.iUnion_pNat_ptsOfPeriod theorem bijOn_periodicPts : BijOn f (periodicPts f) (periodicPts f) := iUnion_pNat_ptsOfPeriod f ▸ bijOn_iUnion_of_directed (directed_ptsOfPeriod_pNat f) fun i => bijOn_ptsOfPeriod f i.pos #align function.bij_on_periodic_pts Function.bijOn_periodicPts variable {f} theorem Semiconj.mapsTo_periodicPts {g : α → β} (h : Semiconj g fa fb) : MapsTo g (periodicPts fa) (periodicPts fb) := fun _ ⟨n, hn, hx⟩ => ⟨n, hn, hx.map h⟩ #align function.semiconj.maps_to_periodic_pts Function.Semiconj.mapsTo_periodicPts open scoped Classical noncomputable section /-- Minimal period of a point `x` under an endomorphism `f`. If `x` is not a periodic point of `f`, then `minimalPeriod f x = 0`. -/ def minimalPeriod (f : α → α) (x : α) := if h : x ∈ periodicPts f then Nat.find h else 0 #align function.minimal_period Function.minimalPeriod theorem isPeriodicPt_minimalPeriod (f : α → α) (x : α) : IsPeriodicPt f (minimalPeriod f x) x := by delta minimalPeriod split_ifs with hx · exact (Nat.find_spec hx).2 · exact isPeriodicPt_zero f x #align function.is_periodic_pt_minimal_period Function.isPeriodicPt_minimalPeriod @[simp] theorem iterate_minimalPeriod : f^[minimalPeriod f x] x = x := isPeriodicPt_minimalPeriod f x #align function.iterate_minimal_period Function.iterate_minimalPeriod @[simp] theorem iterate_add_minimalPeriod_eq : f^[n + minimalPeriod f x] x = f^[n] x := by rw [iterate_add_apply] congr exact isPeriodicPt_minimalPeriod f x #align function.iterate_add_minimal_period_eq Function.iterate_add_minimalPeriod_eq @[simp] theorem iterate_mod_minimalPeriod_eq : f^[n % minimalPeriod f x] x = f^[n] x := (isPeriodicPt_minimalPeriod f x).iterate_mod_apply n #align function.iterate_mod_minimal_period_eq Function.iterate_mod_minimalPeriod_eq theorem minimalPeriod_pos_of_mem_periodicPts (hx : x ∈ periodicPts f) : 0 < minimalPeriod f x := by simp only [minimalPeriod, dif_pos hx, (Nat.find_spec hx).1.lt] #align function.minimal_period_pos_of_mem_periodic_pts Function.minimalPeriod_pos_of_mem_periodicPts theorem minimalPeriod_eq_zero_of_nmem_periodicPts (hx : x ∉ periodicPts f) : minimalPeriod f x = 0 := by simp only [minimalPeriod, dif_neg hx] #align function.minimal_period_eq_zero_of_nmem_periodic_pts Function.minimalPeriod_eq_zero_of_nmem_periodicPts theorem IsPeriodicPt.minimalPeriod_pos (hn : 0 < n) (hx : IsPeriodicPt f n x) : 0 < minimalPeriod f x := minimalPeriod_pos_of_mem_periodicPts <| mk_mem_periodicPts hn hx #align function.is_periodic_pt.minimal_period_pos Function.IsPeriodicPt.minimalPeriod_pos theorem minimalPeriod_pos_iff_mem_periodicPts : 0 < minimalPeriod f x ↔ x ∈ periodicPts f := ⟨not_imp_not.1 fun h => by simp only [minimalPeriod, dif_neg h, lt_irrefl 0, not_false_iff], minimalPeriod_pos_of_mem_periodicPts⟩ #align function.minimal_period_pos_iff_mem_periodic_pts Function.minimalPeriod_pos_iff_mem_periodicPts
Mathlib/Dynamics/PeriodicPts.lean
321
322
theorem minimalPeriod_eq_zero_iff_nmem_periodicPts : minimalPeriod f x = 0 ↔ x ∉ periodicPts f := by
rw [← minimalPeriod_pos_iff_mem_periodicPts, not_lt, nonpos_iff_eq_zero]
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne -/ import Mathlib.Analysis.Complex.Asymptotics import Mathlib.Analysis.SpecificLimits.Normed #align_import analysis.special_functions.exp from "leanprover-community/mathlib"@"ba5ff5ad5d120fb0ef094ad2994967e9bfaf5112" /-! # Complex and real exponential In this file we prove continuity of `Complex.exp` and `Real.exp`. We also prove a few facts about limits of `Real.exp` at infinity. ## Tags exp -/ noncomputable section open Finset Filter Metric Asymptotics Set Function Bornology open scoped Classical Topology Nat namespace Complex variable {z y x : ℝ} theorem exp_bound_sq (x z : ℂ) (hz : ‖z‖ ≤ 1) : ‖exp (x + z) - exp x - z • exp x‖ ≤ ‖exp x‖ * ‖z‖ ^ 2 := calc ‖exp (x + z) - exp x - z * exp x‖ = ‖exp x * (exp z - 1 - z)‖ := by congr rw [exp_add] ring _ = ‖exp x‖ * ‖exp z - 1 - z‖ := norm_mul _ _ _ ≤ ‖exp x‖ * ‖z‖ ^ 2 := mul_le_mul_of_nonneg_left (abs_exp_sub_one_sub_id_le hz) (norm_nonneg _) #align complex.exp_bound_sq Complex.exp_bound_sq
Mathlib/Analysis/SpecialFunctions/Exp.lean
45
61
theorem locally_lipschitz_exp {r : ℝ} (hr_nonneg : 0 ≤ r) (hr_le : r ≤ 1) (x y : ℂ) (hyx : ‖y - x‖ < r) : ‖exp y - exp x‖ ≤ (1 + r) * ‖exp x‖ * ‖y - x‖ := by
have hy_eq : y = x + (y - x) := by abel have hyx_sq_le : ‖y - x‖ ^ 2 ≤ r * ‖y - x‖ := by rw [pow_two] exact mul_le_mul hyx.le le_rfl (norm_nonneg _) hr_nonneg have h_sq : ∀ z, ‖z‖ ≤ 1 → ‖exp (x + z) - exp x‖ ≤ ‖z‖ * ‖exp x‖ + ‖exp x‖ * ‖z‖ ^ 2 := by intro z hz have : ‖exp (x + z) - exp x - z • exp x‖ ≤ ‖exp x‖ * ‖z‖ ^ 2 := exp_bound_sq x z hz rw [← sub_le_iff_le_add', ← norm_smul z] exact (norm_sub_norm_le _ _).trans this calc ‖exp y - exp x‖ = ‖exp (x + (y - x)) - exp x‖ := by nth_rw 1 [hy_eq] _ ≤ ‖y - x‖ * ‖exp x‖ + ‖exp x‖ * ‖y - x‖ ^ 2 := h_sq (y - x) (hyx.le.trans hr_le) _ ≤ ‖y - x‖ * ‖exp x‖ + ‖exp x‖ * (r * ‖y - x‖) := (add_le_add_left (mul_le_mul le_rfl hyx_sq_le (sq_nonneg _) (norm_nonneg _)) _) _ = (1 + r) * ‖exp x‖ * ‖y - x‖ := by ring
/- 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.Init.ZeroOne import Mathlib.Data.Set.Defs import Mathlib.Order.Basic import Mathlib.Order.SymmDiff import Mathlib.Tactic.Tauto import Mathlib.Tactic.ByContra import Mathlib.Util.Delaborators #align_import data.set.basic from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29" /-! # Basic properties of sets Sets in Lean are homogeneous; all their elements have the same type. Sets whose elements have type `X` are thus defined as `Set X := X → Prop`. Note that this function need not be decidable. The definition is in the core library. This file provides some basic definitions related to sets and functions not present in the core library, as well as extra lemmas for functions in the core library (empty set, univ, union, intersection, insert, singleton, set-theoretic difference, complement, and powerset). Note that a set is a term, not a type. There is a coercion from `Set α` to `Type*` sending `s` to the corresponding subtype `↥s`. See also the file `SetTheory/ZFC.lean`, which contains an encoding of ZFC set theory in Lean. ## Main definitions Notation used here: - `f : α → β` is a function, - `s : Set α` and `s₁ s₂ : Set α` are subsets of `α` - `t : Set β` is a subset of `β`. Definitions in the file: * `Nonempty s : Prop` : the predicate `s ≠ ∅`. Note that this is the preferred way to express the fact that `s` has an element (see the Implementation Notes). * `inclusion s₁ s₂ : ↥s₁ → ↥s₂` : the map `↥s₁ → ↥s₂` induced by an inclusion `s₁ ⊆ s₂`. ## Notation * `sᶜ` for the complement of `s` ## Implementation notes * `s.Nonempty` is to be preferred to `s ≠ ∅` or `∃ x, x ∈ s`. It has the advantage that the `s.Nonempty` dot notation can be used. * For `s : Set α`, do not use `Subtype s`. Instead use `↥s` or `(s : Type*)` or `s`. ## Tags set, sets, subset, subsets, union, intersection, insert, singleton, complement, powerset -/ /-! ### Set coercion to a type -/ open Function universe u v w x namespace Set variable {α : Type u} {s t : Set α} instance instBooleanAlgebraSet : BooleanAlgebra (Set α) := { (inferInstance : BooleanAlgebra (α → Prop)) with sup := (· ∪ ·), le := (· ≤ ·), lt := fun s t => s ⊆ t ∧ ¬t ⊆ s, inf := (· ∩ ·), bot := ∅, compl := (·ᶜ), top := univ, sdiff := (· \ ·) } instance : HasSSubset (Set α) := ⟨(· < ·)⟩ @[simp] theorem top_eq_univ : (⊤ : Set α) = univ := rfl #align set.top_eq_univ Set.top_eq_univ @[simp] theorem bot_eq_empty : (⊥ : Set α) = ∅ := rfl #align set.bot_eq_empty Set.bot_eq_empty @[simp] theorem sup_eq_union : ((· ⊔ ·) : Set α → Set α → Set α) = (· ∪ ·) := rfl #align set.sup_eq_union Set.sup_eq_union @[simp] theorem inf_eq_inter : ((· ⊓ ·) : Set α → Set α → Set α) = (· ∩ ·) := rfl #align set.inf_eq_inter Set.inf_eq_inter @[simp] theorem le_eq_subset : ((· ≤ ·) : Set α → Set α → Prop) = (· ⊆ ·) := rfl #align set.le_eq_subset Set.le_eq_subset @[simp] theorem lt_eq_ssubset : ((· < ·) : Set α → Set α → Prop) = (· ⊂ ·) := rfl #align set.lt_eq_ssubset Set.lt_eq_ssubset theorem le_iff_subset : s ≤ t ↔ s ⊆ t := Iff.rfl #align set.le_iff_subset Set.le_iff_subset theorem lt_iff_ssubset : s < t ↔ s ⊂ t := Iff.rfl #align set.lt_iff_ssubset Set.lt_iff_ssubset alias ⟨_root_.LE.le.subset, _root_.HasSubset.Subset.le⟩ := le_iff_subset #align has_subset.subset.le HasSubset.Subset.le alias ⟨_root_.LT.lt.ssubset, _root_.HasSSubset.SSubset.lt⟩ := lt_iff_ssubset #align has_ssubset.ssubset.lt HasSSubset.SSubset.lt instance PiSetCoe.canLift (ι : Type u) (α : ι → Type v) [∀ i, Nonempty (α i)] (s : Set ι) : CanLift (∀ i : s, α i) (∀ i, α i) (fun f i => f i) fun _ => True := PiSubtype.canLift ι α s #align set.pi_set_coe.can_lift Set.PiSetCoe.canLift instance PiSetCoe.canLift' (ι : Type u) (α : Type v) [Nonempty α] (s : Set ι) : CanLift (s → α) (ι → α) (fun f i => f i) fun _ => True := PiSetCoe.canLift ι (fun _ => α) s #align set.pi_set_coe.can_lift' Set.PiSetCoe.canLift' end Set section SetCoe variable {α : Type u} instance (s : Set α) : CoeTC s α := ⟨fun x => x.1⟩ theorem Set.coe_eq_subtype (s : Set α) : ↥s = { x // x ∈ s } := rfl #align set.coe_eq_subtype Set.coe_eq_subtype @[simp] theorem Set.coe_setOf (p : α → Prop) : ↥{ x | p x } = { x // p x } := rfl #align set.coe_set_of Set.coe_setOf -- Porting note (#10618): removed `simp` because `simp` can prove it theorem SetCoe.forall {s : Set α} {p : s → Prop} : (∀ x : s, p x) ↔ ∀ (x) (h : x ∈ s), p ⟨x, h⟩ := Subtype.forall #align set_coe.forall SetCoe.forall -- Porting note (#10618): removed `simp` because `simp` can prove it theorem SetCoe.exists {s : Set α} {p : s → Prop} : (∃ x : s, p x) ↔ ∃ (x : _) (h : x ∈ s), p ⟨x, h⟩ := Subtype.exists #align set_coe.exists SetCoe.exists theorem SetCoe.exists' {s : Set α} {p : ∀ x, x ∈ s → Prop} : (∃ (x : _) (h : x ∈ s), p x h) ↔ ∃ x : s, p x.1 x.2 := (@SetCoe.exists _ _ fun x => p x.1 x.2).symm #align set_coe.exists' SetCoe.exists' theorem SetCoe.forall' {s : Set α} {p : ∀ x, x ∈ s → Prop} : (∀ (x) (h : x ∈ s), p x h) ↔ ∀ x : s, p x.1 x.2 := (@SetCoe.forall _ _ fun x => p x.1 x.2).symm #align set_coe.forall' SetCoe.forall' @[simp] theorem set_coe_cast : ∀ {s t : Set α} (H' : s = t) (H : ↥s = ↥t) (x : s), cast H x = ⟨x.1, H' ▸ x.2⟩ | _, _, rfl, _, _ => rfl #align set_coe_cast set_coe_cast theorem SetCoe.ext {s : Set α} {a b : s} : (a : α) = b → a = b := Subtype.eq #align set_coe.ext SetCoe.ext theorem SetCoe.ext_iff {s : Set α} {a b : s} : (↑a : α) = ↑b ↔ a = b := Iff.intro SetCoe.ext fun h => h ▸ rfl #align set_coe.ext_iff SetCoe.ext_iff end SetCoe /-- See also `Subtype.prop` -/ theorem Subtype.mem {α : Type*} {s : Set α} (p : s) : (p : α) ∈ s := p.prop #align subtype.mem Subtype.mem /-- Duplicate of `Eq.subset'`, which currently has elaboration problems. -/ theorem Eq.subset {α} {s t : Set α} : s = t → s ⊆ t := fun h₁ _ h₂ => by rw [← h₁]; exact h₂ #align eq.subset Eq.subset namespace Set variable {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} {a b : α} {s s₁ s₂ t t₁ t₂ u : Set α} instance : Inhabited (Set α) := ⟨∅⟩ theorem ext_iff {s t : Set α} : s = t ↔ ∀ x, x ∈ s ↔ x ∈ t := ⟨fun h x => by rw [h], ext⟩ #align set.ext_iff Set.ext_iff @[trans] theorem mem_of_mem_of_subset {x : α} {s t : Set α} (hx : x ∈ s) (h : s ⊆ t) : x ∈ t := h hx #align set.mem_of_mem_of_subset Set.mem_of_mem_of_subset theorem forall_in_swap {p : α → β → Prop} : (∀ a ∈ s, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ s, p a b := by tauto #align set.forall_in_swap Set.forall_in_swap /-! ### Lemmas about `mem` and `setOf` -/ theorem mem_setOf {a : α} {p : α → Prop} : a ∈ { x | p x } ↔ p a := Iff.rfl #align set.mem_set_of Set.mem_setOf /-- If `h : a ∈ {x | p x}` then `h.out : p x`. These are definitionally equal, but this can nevertheless be useful for various reasons, e.g. to apply further projection notation or in an argument to `simp`. -/ theorem _root_.Membership.mem.out {p : α → Prop} {a : α} (h : a ∈ { x | p x }) : p a := h #align has_mem.mem.out Membership.mem.out theorem nmem_setOf_iff {a : α} {p : α → Prop} : a ∉ { x | p x } ↔ ¬p a := Iff.rfl #align set.nmem_set_of_iff Set.nmem_setOf_iff @[simp] theorem setOf_mem_eq {s : Set α} : { x | x ∈ s } = s := rfl #align set.set_of_mem_eq Set.setOf_mem_eq theorem setOf_set {s : Set α} : setOf s = s := rfl #align set.set_of_set Set.setOf_set theorem setOf_app_iff {p : α → Prop} {x : α} : { x | p x } x ↔ p x := Iff.rfl #align set.set_of_app_iff Set.setOf_app_iff theorem mem_def {a : α} {s : Set α} : a ∈ s ↔ s a := Iff.rfl #align set.mem_def Set.mem_def theorem setOf_bijective : Bijective (setOf : (α → Prop) → Set α) := bijective_id #align set.set_of_bijective Set.setOf_bijective theorem subset_setOf {p : α → Prop} {s : Set α} : s ⊆ setOf p ↔ ∀ x, x ∈ s → p x := Iff.rfl theorem setOf_subset {p : α → Prop} {s : Set α} : setOf p ⊆ s ↔ ∀ x, p x → x ∈ s := Iff.rfl @[simp] theorem setOf_subset_setOf {p q : α → Prop} : { a | p a } ⊆ { a | q a } ↔ ∀ a, p a → q a := Iff.rfl #align set.set_of_subset_set_of Set.setOf_subset_setOf theorem setOf_and {p q : α → Prop} : { a | p a ∧ q a } = { a | p a } ∩ { a | q a } := rfl #align set.set_of_and Set.setOf_and theorem setOf_or {p q : α → Prop} : { a | p a ∨ q a } = { a | p a } ∪ { a | q a } := rfl #align set.set_of_or Set.setOf_or /-! ### Subset and strict subset relations -/ instance : IsRefl (Set α) (· ⊆ ·) := show IsRefl (Set α) (· ≤ ·) by infer_instance instance : IsTrans (Set α) (· ⊆ ·) := show IsTrans (Set α) (· ≤ ·) by infer_instance instance : Trans ((· ⊆ ·) : Set α → Set α → Prop) (· ⊆ ·) (· ⊆ ·) := show Trans (· ≤ ·) (· ≤ ·) (· ≤ ·) by infer_instance instance : IsAntisymm (Set α) (· ⊆ ·) := show IsAntisymm (Set α) (· ≤ ·) by infer_instance instance : IsIrrefl (Set α) (· ⊂ ·) := show IsIrrefl (Set α) (· < ·) by infer_instance instance : IsTrans (Set α) (· ⊂ ·) := show IsTrans (Set α) (· < ·) by infer_instance instance : Trans ((· ⊂ ·) : Set α → Set α → Prop) (· ⊂ ·) (· ⊂ ·) := show Trans (· < ·) (· < ·) (· < ·) by infer_instance instance : Trans ((· ⊂ ·) : Set α → Set α → Prop) (· ⊆ ·) (· ⊂ ·) := show Trans (· < ·) (· ≤ ·) (· < ·) by infer_instance instance : Trans ((· ⊆ ·) : Set α → Set α → Prop) (· ⊂ ·) (· ⊂ ·) := show Trans (· ≤ ·) (· < ·) (· < ·) by infer_instance instance : IsAsymm (Set α) (· ⊂ ·) := show IsAsymm (Set α) (· < ·) by infer_instance instance : IsNonstrictStrictOrder (Set α) (· ⊆ ·) (· ⊂ ·) := ⟨fun _ _ => Iff.rfl⟩ -- TODO(Jeremy): write a tactic to unfold specific instances of generic notation? theorem subset_def : (s ⊆ t) = ∀ x, x ∈ s → x ∈ t := rfl #align set.subset_def Set.subset_def theorem ssubset_def : (s ⊂ t) = (s ⊆ t ∧ ¬t ⊆ s) := rfl #align set.ssubset_def Set.ssubset_def @[refl] theorem Subset.refl (a : Set α) : a ⊆ a := fun _ => id #align set.subset.refl Set.Subset.refl theorem Subset.rfl {s : Set α} : s ⊆ s := Subset.refl s #align set.subset.rfl Set.Subset.rfl @[trans] theorem Subset.trans {a b c : Set α} (ab : a ⊆ b) (bc : b ⊆ c) : a ⊆ c := fun _ h => bc <| ab h #align set.subset.trans Set.Subset.trans @[trans] theorem mem_of_eq_of_mem {x y : α} {s : Set α} (hx : x = y) (h : y ∈ s) : x ∈ s := hx.symm ▸ h #align set.mem_of_eq_of_mem Set.mem_of_eq_of_mem theorem Subset.antisymm {a b : Set α} (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b := Set.ext fun _ => ⟨@h₁ _, @h₂ _⟩ #align set.subset.antisymm Set.Subset.antisymm theorem Subset.antisymm_iff {a b : Set α} : a = b ↔ a ⊆ b ∧ b ⊆ a := ⟨fun e => ⟨e.subset, e.symm.subset⟩, fun ⟨h₁, h₂⟩ => Subset.antisymm h₁ h₂⟩ #align set.subset.antisymm_iff Set.Subset.antisymm_iff -- an alternative name theorem eq_of_subset_of_subset {a b : Set α} : a ⊆ b → b ⊆ a → a = b := Subset.antisymm #align set.eq_of_subset_of_subset Set.eq_of_subset_of_subset theorem mem_of_subset_of_mem {s₁ s₂ : Set α} {a : α} (h : s₁ ⊆ s₂) : a ∈ s₁ → a ∈ s₂ := @h _ #align set.mem_of_subset_of_mem Set.mem_of_subset_of_mem theorem not_mem_subset (h : s ⊆ t) : a ∉ t → a ∉ s := mt <| mem_of_subset_of_mem h #align set.not_mem_subset Set.not_mem_subset theorem not_subset : ¬s ⊆ t ↔ ∃ a ∈ s, a ∉ t := by simp only [subset_def, not_forall, exists_prop] #align set.not_subset Set.not_subset lemma eq_of_forall_subset_iff (h : ∀ u, s ⊆ u ↔ t ⊆ u) : s = t := eq_of_forall_ge_iff h /-! ### Definition of strict subsets `s ⊂ t` and basic properties. -/ protected theorem eq_or_ssubset_of_subset (h : s ⊆ t) : s = t ∨ s ⊂ t := eq_or_lt_of_le h #align set.eq_or_ssubset_of_subset Set.eq_or_ssubset_of_subset theorem exists_of_ssubset {s t : Set α} (h : s ⊂ t) : ∃ x ∈ t, x ∉ s := not_subset.1 h.2 #align set.exists_of_ssubset Set.exists_of_ssubset protected theorem ssubset_iff_subset_ne {s t : Set α} : s ⊂ t ↔ s ⊆ t ∧ s ≠ t := @lt_iff_le_and_ne (Set α) _ s t #align set.ssubset_iff_subset_ne Set.ssubset_iff_subset_ne theorem ssubset_iff_of_subset {s t : Set α} (h : s ⊆ t) : s ⊂ t ↔ ∃ x ∈ t, x ∉ s := ⟨exists_of_ssubset, fun ⟨_, hxt, hxs⟩ => ⟨h, fun h => hxs <| h hxt⟩⟩ #align set.ssubset_iff_of_subset Set.ssubset_iff_of_subset protected theorem ssubset_of_ssubset_of_subset {s₁ s₂ s₃ : Set α} (hs₁s₂ : s₁ ⊂ s₂) (hs₂s₃ : s₂ ⊆ s₃) : s₁ ⊂ s₃ := ⟨Subset.trans hs₁s₂.1 hs₂s₃, fun hs₃s₁ => hs₁s₂.2 (Subset.trans hs₂s₃ hs₃s₁)⟩ #align set.ssubset_of_ssubset_of_subset Set.ssubset_of_ssubset_of_subset protected theorem ssubset_of_subset_of_ssubset {s₁ s₂ s₃ : Set α} (hs₁s₂ : s₁ ⊆ s₂) (hs₂s₃ : s₂ ⊂ s₃) : s₁ ⊂ s₃ := ⟨Subset.trans hs₁s₂ hs₂s₃.1, fun hs₃s₁ => hs₂s₃.2 (Subset.trans hs₃s₁ hs₁s₂)⟩ #align set.ssubset_of_subset_of_ssubset Set.ssubset_of_subset_of_ssubset theorem not_mem_empty (x : α) : ¬x ∈ (∅ : Set α) := id #align set.not_mem_empty Set.not_mem_empty -- Porting note (#10618): removed `simp` because `simp` can prove it theorem not_not_mem : ¬a ∉ s ↔ a ∈ s := not_not #align set.not_not_mem Set.not_not_mem /-! ### Non-empty sets -/ -- Porting note: we seem to need parentheses at `(↥s)`, -- even if we increase the right precedence of `↥` in `Mathlib.Tactic.Coe`. -- Porting note: removed `simp` as it is competing with `nonempty_subtype`. -- @[simp] theorem nonempty_coe_sort {s : Set α} : Nonempty (↥s) ↔ s.Nonempty := nonempty_subtype #align set.nonempty_coe_sort Set.nonempty_coe_sort alias ⟨_, Nonempty.coe_sort⟩ := nonempty_coe_sort #align set.nonempty.coe_sort Set.Nonempty.coe_sort theorem nonempty_def : s.Nonempty ↔ ∃ x, x ∈ s := Iff.rfl #align set.nonempty_def Set.nonempty_def theorem nonempty_of_mem {x} (h : x ∈ s) : s.Nonempty := ⟨x, h⟩ #align set.nonempty_of_mem Set.nonempty_of_mem theorem Nonempty.not_subset_empty : s.Nonempty → ¬s ⊆ ∅ | ⟨_, hx⟩, hs => hs hx #align set.nonempty.not_subset_empty Set.Nonempty.not_subset_empty /-- Extract a witness from `s.Nonempty`. This function might be used instead of case analysis on the argument. Note that it makes a proof depend on the `Classical.choice` axiom. -/ protected noncomputable def Nonempty.some (h : s.Nonempty) : α := Classical.choose h #align set.nonempty.some Set.Nonempty.some protected theorem Nonempty.some_mem (h : s.Nonempty) : h.some ∈ s := Classical.choose_spec h #align set.nonempty.some_mem Set.Nonempty.some_mem theorem Nonempty.mono (ht : s ⊆ t) (hs : s.Nonempty) : t.Nonempty := hs.imp ht #align set.nonempty.mono Set.Nonempty.mono theorem nonempty_of_not_subset (h : ¬s ⊆ t) : (s \ t).Nonempty := let ⟨x, xs, xt⟩ := not_subset.1 h ⟨x, xs, xt⟩ #align set.nonempty_of_not_subset Set.nonempty_of_not_subset theorem nonempty_of_ssubset (ht : s ⊂ t) : (t \ s).Nonempty := nonempty_of_not_subset ht.2 #align set.nonempty_of_ssubset Set.nonempty_of_ssubset theorem Nonempty.of_diff (h : (s \ t).Nonempty) : s.Nonempty := h.imp fun _ => And.left #align set.nonempty.of_diff Set.Nonempty.of_diff theorem nonempty_of_ssubset' (ht : s ⊂ t) : t.Nonempty := (nonempty_of_ssubset ht).of_diff #align set.nonempty_of_ssubset' Set.nonempty_of_ssubset' theorem Nonempty.inl (hs : s.Nonempty) : (s ∪ t).Nonempty := hs.imp fun _ => Or.inl #align set.nonempty.inl Set.Nonempty.inl theorem Nonempty.inr (ht : t.Nonempty) : (s ∪ t).Nonempty := ht.imp fun _ => Or.inr #align set.nonempty.inr Set.Nonempty.inr @[simp] theorem union_nonempty : (s ∪ t).Nonempty ↔ s.Nonempty ∨ t.Nonempty := exists_or #align set.union_nonempty Set.union_nonempty theorem Nonempty.left (h : (s ∩ t).Nonempty) : s.Nonempty := h.imp fun _ => And.left #align set.nonempty.left Set.Nonempty.left theorem Nonempty.right (h : (s ∩ t).Nonempty) : t.Nonempty := h.imp fun _ => And.right #align set.nonempty.right Set.Nonempty.right theorem inter_nonempty : (s ∩ t).Nonempty ↔ ∃ x, x ∈ s ∧ x ∈ t := Iff.rfl #align set.inter_nonempty Set.inter_nonempty theorem inter_nonempty_iff_exists_left : (s ∩ t).Nonempty ↔ ∃ x ∈ s, x ∈ t := by simp_rw [inter_nonempty] #align set.inter_nonempty_iff_exists_left Set.inter_nonempty_iff_exists_left theorem inter_nonempty_iff_exists_right : (s ∩ t).Nonempty ↔ ∃ x ∈ t, x ∈ s := by simp_rw [inter_nonempty, and_comm] #align set.inter_nonempty_iff_exists_right Set.inter_nonempty_iff_exists_right theorem nonempty_iff_univ_nonempty : Nonempty α ↔ (univ : Set α).Nonempty := ⟨fun ⟨x⟩ => ⟨x, trivial⟩, fun ⟨x, _⟩ => ⟨x⟩⟩ #align set.nonempty_iff_univ_nonempty Set.nonempty_iff_univ_nonempty @[simp] theorem univ_nonempty : ∀ [Nonempty α], (univ : Set α).Nonempty | ⟨x⟩ => ⟨x, trivial⟩ #align set.univ_nonempty Set.univ_nonempty theorem Nonempty.to_subtype : s.Nonempty → Nonempty (↥s) := nonempty_subtype.2 #align set.nonempty.to_subtype Set.Nonempty.to_subtype theorem Nonempty.to_type : s.Nonempty → Nonempty α := fun ⟨x, _⟩ => ⟨x⟩ #align set.nonempty.to_type Set.Nonempty.to_type instance univ.nonempty [Nonempty α] : Nonempty (↥(Set.univ : Set α)) := Set.univ_nonempty.to_subtype #align set.univ.nonempty Set.univ.nonempty theorem nonempty_of_nonempty_subtype [Nonempty (↥s)] : s.Nonempty := nonempty_subtype.mp ‹_› #align set.nonempty_of_nonempty_subtype Set.nonempty_of_nonempty_subtype /-! ### Lemmas about the empty set -/ theorem empty_def : (∅ : Set α) = { _x : α | False } := rfl #align set.empty_def Set.empty_def @[simp] theorem mem_empty_iff_false (x : α) : x ∈ (∅ : Set α) ↔ False := Iff.rfl #align set.mem_empty_iff_false Set.mem_empty_iff_false @[simp] theorem setOf_false : { _a : α | False } = ∅ := rfl #align set.set_of_false Set.setOf_false @[simp] theorem setOf_bot : { _x : α | ⊥ } = ∅ := rfl @[simp] theorem empty_subset (s : Set α) : ∅ ⊆ s := nofun #align set.empty_subset Set.empty_subset theorem subset_empty_iff {s : Set α} : s ⊆ ∅ ↔ s = ∅ := (Subset.antisymm_iff.trans <| and_iff_left (empty_subset _)).symm #align set.subset_empty_iff Set.subset_empty_iff theorem eq_empty_iff_forall_not_mem {s : Set α} : s = ∅ ↔ ∀ x, x ∉ s := subset_empty_iff.symm #align set.eq_empty_iff_forall_not_mem Set.eq_empty_iff_forall_not_mem theorem eq_empty_of_forall_not_mem (h : ∀ x, x ∉ s) : s = ∅ := subset_empty_iff.1 h #align set.eq_empty_of_forall_not_mem Set.eq_empty_of_forall_not_mem theorem eq_empty_of_subset_empty {s : Set α} : s ⊆ ∅ → s = ∅ := subset_empty_iff.1 #align set.eq_empty_of_subset_empty Set.eq_empty_of_subset_empty theorem eq_empty_of_isEmpty [IsEmpty α] (s : Set α) : s = ∅ := eq_empty_of_subset_empty fun x _ => isEmptyElim x #align set.eq_empty_of_is_empty Set.eq_empty_of_isEmpty /-- There is exactly one set of a type that is empty. -/ instance uniqueEmpty [IsEmpty α] : Unique (Set α) where default := ∅ uniq := eq_empty_of_isEmpty #align set.unique_empty Set.uniqueEmpty /-- See also `Set.nonempty_iff_ne_empty`. -/ theorem not_nonempty_iff_eq_empty {s : Set α} : ¬s.Nonempty ↔ s = ∅ := by simp only [Set.Nonempty, not_exists, eq_empty_iff_forall_not_mem] #align set.not_nonempty_iff_eq_empty Set.not_nonempty_iff_eq_empty /-- See also `Set.not_nonempty_iff_eq_empty`. -/ theorem nonempty_iff_ne_empty : s.Nonempty ↔ s ≠ ∅ := not_nonempty_iff_eq_empty.not_right #align set.nonempty_iff_ne_empty Set.nonempty_iff_ne_empty /-- See also `nonempty_iff_ne_empty'`. -/ theorem not_nonempty_iff_eq_empty' : ¬Nonempty s ↔ s = ∅ := by rw [nonempty_subtype, not_exists, eq_empty_iff_forall_not_mem] /-- See also `not_nonempty_iff_eq_empty'`. -/ theorem nonempty_iff_ne_empty' : Nonempty s ↔ s ≠ ∅ := not_nonempty_iff_eq_empty'.not_right alias ⟨Nonempty.ne_empty, _⟩ := nonempty_iff_ne_empty #align set.nonempty.ne_empty Set.Nonempty.ne_empty @[simp] theorem not_nonempty_empty : ¬(∅ : Set α).Nonempty := fun ⟨_, hx⟩ => hx #align set.not_nonempty_empty Set.not_nonempty_empty -- Porting note: removing `@[simp]` as it is competing with `isEmpty_subtype`. -- @[simp] theorem isEmpty_coe_sort {s : Set α} : IsEmpty (↥s) ↔ s = ∅ := not_iff_not.1 <| by simpa using nonempty_iff_ne_empty #align set.is_empty_coe_sort Set.isEmpty_coe_sort theorem eq_empty_or_nonempty (s : Set α) : s = ∅ ∨ s.Nonempty := or_iff_not_imp_left.2 nonempty_iff_ne_empty.2 #align set.eq_empty_or_nonempty Set.eq_empty_or_nonempty theorem subset_eq_empty {s t : Set α} (h : t ⊆ s) (e : s = ∅) : t = ∅ := subset_empty_iff.1 <| e ▸ h #align set.subset_eq_empty Set.subset_eq_empty theorem forall_mem_empty {p : α → Prop} : (∀ x ∈ (∅ : Set α), p x) ↔ True := iff_true_intro fun _ => False.elim #align set.ball_empty_iff Set.forall_mem_empty @[deprecated (since := "2024-03-23")] alias ball_empty_iff := forall_mem_empty instance (α : Type u) : IsEmpty.{u + 1} (↥(∅ : Set α)) := ⟨fun x => x.2⟩ @[simp] theorem empty_ssubset : ∅ ⊂ s ↔ s.Nonempty := (@bot_lt_iff_ne_bot (Set α) _ _ _).trans nonempty_iff_ne_empty.symm #align set.empty_ssubset Set.empty_ssubset alias ⟨_, Nonempty.empty_ssubset⟩ := empty_ssubset #align set.nonempty.empty_ssubset Set.Nonempty.empty_ssubset /-! ### Universal set. In Lean `@univ α` (or `univ : Set α`) is the set that contains all elements of type `α`. Mathematically it is the same as `α` but it has a different type. -/ @[simp] theorem setOf_true : { _x : α | True } = univ := rfl #align set.set_of_true Set.setOf_true @[simp] theorem setOf_top : { _x : α | ⊤ } = univ := rfl @[simp] theorem univ_eq_empty_iff : (univ : Set α) = ∅ ↔ IsEmpty α := eq_empty_iff_forall_not_mem.trans ⟨fun H => ⟨fun x => H x trivial⟩, fun H x _ => @IsEmpty.false α H x⟩ #align set.univ_eq_empty_iff Set.univ_eq_empty_iff theorem empty_ne_univ [Nonempty α] : (∅ : Set α) ≠ univ := fun e => not_isEmpty_of_nonempty α <| univ_eq_empty_iff.1 e.symm #align set.empty_ne_univ Set.empty_ne_univ @[simp] theorem subset_univ (s : Set α) : s ⊆ univ := fun _ _ => trivial #align set.subset_univ Set.subset_univ @[simp] theorem univ_subset_iff {s : Set α} : univ ⊆ s ↔ s = univ := @top_le_iff _ _ _ s #align set.univ_subset_iff Set.univ_subset_iff alias ⟨eq_univ_of_univ_subset, _⟩ := univ_subset_iff #align set.eq_univ_of_univ_subset Set.eq_univ_of_univ_subset theorem eq_univ_iff_forall {s : Set α} : s = univ ↔ ∀ x, x ∈ s := univ_subset_iff.symm.trans <| forall_congr' fun _ => imp_iff_right trivial #align set.eq_univ_iff_forall Set.eq_univ_iff_forall theorem eq_univ_of_forall {s : Set α} : (∀ x, x ∈ s) → s = univ := eq_univ_iff_forall.2 #align set.eq_univ_of_forall Set.eq_univ_of_forall theorem Nonempty.eq_univ [Subsingleton α] : s.Nonempty → s = univ := by rintro ⟨x, hx⟩ exact eq_univ_of_forall fun y => by rwa [Subsingleton.elim y x] #align set.nonempty.eq_univ Set.Nonempty.eq_univ theorem eq_univ_of_subset {s t : Set α} (h : s ⊆ t) (hs : s = univ) : t = univ := eq_univ_of_univ_subset <| (hs ▸ h : univ ⊆ t) #align set.eq_univ_of_subset Set.eq_univ_of_subset theorem exists_mem_of_nonempty (α) : ∀ [Nonempty α], ∃ x : α, x ∈ (univ : Set α) | ⟨x⟩ => ⟨x, trivial⟩ #align set.exists_mem_of_nonempty Set.exists_mem_of_nonempty theorem ne_univ_iff_exists_not_mem {α : Type*} (s : Set α) : s ≠ univ ↔ ∃ a, a ∉ s := by rw [← not_forall, ← eq_univ_iff_forall] #align set.ne_univ_iff_exists_not_mem Set.ne_univ_iff_exists_not_mem theorem not_subset_iff_exists_mem_not_mem {α : Type*} {s t : Set α} : ¬s ⊆ t ↔ ∃ x, x ∈ s ∧ x ∉ t := by simp [subset_def] #align set.not_subset_iff_exists_mem_not_mem Set.not_subset_iff_exists_mem_not_mem theorem univ_unique [Unique α] : @Set.univ α = {default} := Set.ext fun x => iff_of_true trivial <| Subsingleton.elim x default #align set.univ_unique Set.univ_unique theorem ssubset_univ_iff : s ⊂ univ ↔ s ≠ univ := lt_top_iff_ne_top #align set.ssubset_univ_iff Set.ssubset_univ_iff instance nontrivial_of_nonempty [Nonempty α] : Nontrivial (Set α) := ⟨⟨∅, univ, empty_ne_univ⟩⟩ #align set.nontrivial_of_nonempty Set.nontrivial_of_nonempty /-! ### Lemmas about union -/ theorem union_def {s₁ s₂ : Set α} : s₁ ∪ s₂ = { a | a ∈ s₁ ∨ a ∈ s₂ } := rfl #align set.union_def Set.union_def theorem mem_union_left {x : α} {a : Set α} (b : Set α) : x ∈ a → x ∈ a ∪ b := Or.inl #align set.mem_union_left Set.mem_union_left theorem mem_union_right {x : α} {b : Set α} (a : Set α) : x ∈ b → x ∈ a ∪ b := Or.inr #align set.mem_union_right Set.mem_union_right theorem mem_or_mem_of_mem_union {x : α} {a b : Set α} (H : x ∈ a ∪ b) : x ∈ a ∨ x ∈ b := H #align set.mem_or_mem_of_mem_union Set.mem_or_mem_of_mem_union theorem MemUnion.elim {x : α} {a b : Set α} {P : Prop} (H₁ : x ∈ a ∪ b) (H₂ : x ∈ a → P) (H₃ : x ∈ b → P) : P := Or.elim H₁ H₂ H₃ #align set.mem_union.elim Set.MemUnion.elim @[simp] theorem mem_union (x : α) (a b : Set α) : x ∈ a ∪ b ↔ x ∈ a ∨ x ∈ b := Iff.rfl #align set.mem_union Set.mem_union @[simp] theorem union_self (a : Set α) : a ∪ a = a := ext fun _ => or_self_iff #align set.union_self Set.union_self @[simp] theorem union_empty (a : Set α) : a ∪ ∅ = a := ext fun _ => or_false_iff _ #align set.union_empty Set.union_empty @[simp] theorem empty_union (a : Set α) : ∅ ∪ a = a := ext fun _ => false_or_iff _ #align set.empty_union Set.empty_union theorem union_comm (a b : Set α) : a ∪ b = b ∪ a := ext fun _ => or_comm #align set.union_comm Set.union_comm theorem union_assoc (a b c : Set α) : a ∪ b ∪ c = a ∪ (b ∪ c) := ext fun _ => or_assoc #align set.union_assoc Set.union_assoc instance union_isAssoc : Std.Associative (α := Set α) (· ∪ ·) := ⟨union_assoc⟩ #align set.union_is_assoc Set.union_isAssoc instance union_isComm : Std.Commutative (α := Set α) (· ∪ ·) := ⟨union_comm⟩ #align set.union_is_comm Set.union_isComm theorem union_left_comm (s₁ s₂ s₃ : Set α) : s₁ ∪ (s₂ ∪ s₃) = s₂ ∪ (s₁ ∪ s₃) := ext fun _ => or_left_comm #align set.union_left_comm Set.union_left_comm theorem union_right_comm (s₁ s₂ s₃ : Set α) : s₁ ∪ s₂ ∪ s₃ = s₁ ∪ s₃ ∪ s₂ := ext fun _ => or_right_comm #align set.union_right_comm Set.union_right_comm @[simp] theorem union_eq_left {s t : Set α} : s ∪ t = s ↔ t ⊆ s := sup_eq_left #align set.union_eq_left_iff_subset Set.union_eq_left @[simp] theorem union_eq_right {s t : Set α} : s ∪ t = t ↔ s ⊆ t := sup_eq_right #align set.union_eq_right_iff_subset Set.union_eq_right theorem union_eq_self_of_subset_left {s t : Set α} (h : s ⊆ t) : s ∪ t = t := union_eq_right.mpr h #align set.union_eq_self_of_subset_left Set.union_eq_self_of_subset_left theorem union_eq_self_of_subset_right {s t : Set α} (h : t ⊆ s) : s ∪ t = s := union_eq_left.mpr h #align set.union_eq_self_of_subset_right Set.union_eq_self_of_subset_right @[simp] theorem subset_union_left {s t : Set α} : s ⊆ s ∪ t := fun _ => Or.inl #align set.subset_union_left Set.subset_union_left @[simp] theorem subset_union_right {s t : Set α} : t ⊆ s ∪ t := fun _ => Or.inr #align set.subset_union_right Set.subset_union_right theorem union_subset {s t r : Set α} (sr : s ⊆ r) (tr : t ⊆ r) : s ∪ t ⊆ r := fun _ => Or.rec (@sr _) (@tr _) #align set.union_subset Set.union_subset @[simp] theorem union_subset_iff {s t u : Set α} : s ∪ t ⊆ u ↔ s ⊆ u ∧ t ⊆ u := (forall_congr' fun _ => or_imp).trans forall_and #align set.union_subset_iff Set.union_subset_iff @[gcongr] theorem union_subset_union {s₁ s₂ t₁ t₂ : Set α} (h₁ : s₁ ⊆ s₂) (h₂ : t₁ ⊆ t₂) : s₁ ∪ t₁ ⊆ s₂ ∪ t₂ := fun _ => Or.imp (@h₁ _) (@h₂ _) #align set.union_subset_union Set.union_subset_union @[gcongr] theorem union_subset_union_left {s₁ s₂ : Set α} (t) (h : s₁ ⊆ s₂) : s₁ ∪ t ⊆ s₂ ∪ t := union_subset_union h Subset.rfl #align set.union_subset_union_left Set.union_subset_union_left @[gcongr] theorem union_subset_union_right (s) {t₁ t₂ : Set α} (h : t₁ ⊆ t₂) : s ∪ t₁ ⊆ s ∪ t₂ := union_subset_union Subset.rfl h #align set.union_subset_union_right Set.union_subset_union_right theorem subset_union_of_subset_left {s t : Set α} (h : s ⊆ t) (u : Set α) : s ⊆ t ∪ u := h.trans subset_union_left #align set.subset_union_of_subset_left Set.subset_union_of_subset_left theorem subset_union_of_subset_right {s u : Set α} (h : s ⊆ u) (t : Set α) : s ⊆ t ∪ u := h.trans subset_union_right #align set.subset_union_of_subset_right Set.subset_union_of_subset_right -- Porting note: replaced `⊔` in RHS theorem union_congr_left (ht : t ⊆ s ∪ u) (hu : u ⊆ s ∪ t) : s ∪ t = s ∪ u := sup_congr_left ht hu #align set.union_congr_left Set.union_congr_left theorem union_congr_right (hs : s ⊆ t ∪ u) (ht : t ⊆ s ∪ u) : s ∪ u = t ∪ u := sup_congr_right hs ht #align set.union_congr_right Set.union_congr_right theorem union_eq_union_iff_left : s ∪ t = s ∪ u ↔ t ⊆ s ∪ u ∧ u ⊆ s ∪ t := sup_eq_sup_iff_left #align set.union_eq_union_iff_left Set.union_eq_union_iff_left theorem union_eq_union_iff_right : s ∪ u = t ∪ u ↔ s ⊆ t ∪ u ∧ t ⊆ s ∪ u := sup_eq_sup_iff_right #align set.union_eq_union_iff_right Set.union_eq_union_iff_right @[simp] theorem union_empty_iff {s t : Set α} : s ∪ t = ∅ ↔ s = ∅ ∧ t = ∅ := by simp only [← subset_empty_iff] exact union_subset_iff #align set.union_empty_iff Set.union_empty_iff @[simp] theorem union_univ (s : Set α) : s ∪ univ = univ := sup_top_eq _ #align set.union_univ Set.union_univ @[simp] theorem univ_union (s : Set α) : univ ∪ s = univ := top_sup_eq _ #align set.univ_union Set.univ_union /-! ### Lemmas about intersection -/ theorem inter_def {s₁ s₂ : Set α} : s₁ ∩ s₂ = { a | a ∈ s₁ ∧ a ∈ s₂ } := rfl #align set.inter_def Set.inter_def @[simp, mfld_simps] theorem mem_inter_iff (x : α) (a b : Set α) : x ∈ a ∩ b ↔ x ∈ a ∧ x ∈ b := Iff.rfl #align set.mem_inter_iff Set.mem_inter_iff theorem mem_inter {x : α} {a b : Set α} (ha : x ∈ a) (hb : x ∈ b) : x ∈ a ∩ b := ⟨ha, hb⟩ #align set.mem_inter Set.mem_inter theorem mem_of_mem_inter_left {x : α} {a b : Set α} (h : x ∈ a ∩ b) : x ∈ a := h.left #align set.mem_of_mem_inter_left Set.mem_of_mem_inter_left theorem mem_of_mem_inter_right {x : α} {a b : Set α} (h : x ∈ a ∩ b) : x ∈ b := h.right #align set.mem_of_mem_inter_right Set.mem_of_mem_inter_right @[simp] theorem inter_self (a : Set α) : a ∩ a = a := ext fun _ => and_self_iff #align set.inter_self Set.inter_self @[simp] theorem inter_empty (a : Set α) : a ∩ ∅ = ∅ := ext fun _ => and_false_iff _ #align set.inter_empty Set.inter_empty @[simp] theorem empty_inter (a : Set α) : ∅ ∩ a = ∅ := ext fun _ => false_and_iff _ #align set.empty_inter Set.empty_inter theorem inter_comm (a b : Set α) : a ∩ b = b ∩ a := ext fun _ => and_comm #align set.inter_comm Set.inter_comm theorem inter_assoc (a b c : Set α) : a ∩ b ∩ c = a ∩ (b ∩ c) := ext fun _ => and_assoc #align set.inter_assoc Set.inter_assoc instance inter_isAssoc : Std.Associative (α := Set α) (· ∩ ·) := ⟨inter_assoc⟩ #align set.inter_is_assoc Set.inter_isAssoc instance inter_isComm : Std.Commutative (α := Set α) (· ∩ ·) := ⟨inter_comm⟩ #align set.inter_is_comm Set.inter_isComm theorem inter_left_comm (s₁ s₂ s₃ : Set α) : s₁ ∩ (s₂ ∩ s₃) = s₂ ∩ (s₁ ∩ s₃) := ext fun _ => and_left_comm #align set.inter_left_comm Set.inter_left_comm theorem inter_right_comm (s₁ s₂ s₃ : Set α) : s₁ ∩ s₂ ∩ s₃ = s₁ ∩ s₃ ∩ s₂ := ext fun _ => and_right_comm #align set.inter_right_comm Set.inter_right_comm @[simp, mfld_simps] theorem inter_subset_left {s t : Set α} : s ∩ t ⊆ s := fun _ => And.left #align set.inter_subset_left Set.inter_subset_left @[simp] theorem inter_subset_right {s t : Set α} : s ∩ t ⊆ t := fun _ => And.right #align set.inter_subset_right Set.inter_subset_right theorem subset_inter {s t r : Set α} (rs : r ⊆ s) (rt : r ⊆ t) : r ⊆ s ∩ t := fun _ h => ⟨rs h, rt h⟩ #align set.subset_inter Set.subset_inter @[simp] theorem subset_inter_iff {s t r : Set α} : r ⊆ s ∩ t ↔ r ⊆ s ∧ r ⊆ t := (forall_congr' fun _ => imp_and).trans forall_and #align set.subset_inter_iff Set.subset_inter_iff @[simp] lemma inter_eq_left : s ∩ t = s ↔ s ⊆ t := inf_eq_left #align set.inter_eq_left_iff_subset Set.inter_eq_left @[simp] lemma inter_eq_right : s ∩ t = t ↔ t ⊆ s := inf_eq_right #align set.inter_eq_right_iff_subset Set.inter_eq_right @[simp] lemma left_eq_inter : s = s ∩ t ↔ s ⊆ t := left_eq_inf @[simp] lemma right_eq_inter : t = s ∩ t ↔ t ⊆ s := right_eq_inf theorem inter_eq_self_of_subset_left {s t : Set α} : s ⊆ t → s ∩ t = s := inter_eq_left.mpr #align set.inter_eq_self_of_subset_left Set.inter_eq_self_of_subset_left theorem inter_eq_self_of_subset_right {s t : Set α} : t ⊆ s → s ∩ t = t := inter_eq_right.mpr #align set.inter_eq_self_of_subset_right Set.inter_eq_self_of_subset_right theorem inter_congr_left (ht : s ∩ u ⊆ t) (hu : s ∩ t ⊆ u) : s ∩ t = s ∩ u := inf_congr_left ht hu #align set.inter_congr_left Set.inter_congr_left theorem inter_congr_right (hs : t ∩ u ⊆ s) (ht : s ∩ u ⊆ t) : s ∩ u = t ∩ u := inf_congr_right hs ht #align set.inter_congr_right Set.inter_congr_right theorem inter_eq_inter_iff_left : s ∩ t = s ∩ u ↔ s ∩ u ⊆ t ∧ s ∩ t ⊆ u := inf_eq_inf_iff_left #align set.inter_eq_inter_iff_left Set.inter_eq_inter_iff_left theorem inter_eq_inter_iff_right : s ∩ u = t ∩ u ↔ t ∩ u ⊆ s ∧ s ∩ u ⊆ t := inf_eq_inf_iff_right #align set.inter_eq_inter_iff_right Set.inter_eq_inter_iff_right @[simp, mfld_simps] theorem inter_univ (a : Set α) : a ∩ univ = a := inf_top_eq _ #align set.inter_univ Set.inter_univ @[simp, mfld_simps] theorem univ_inter (a : Set α) : univ ∩ a = a := top_inf_eq _ #align set.univ_inter Set.univ_inter @[gcongr] theorem inter_subset_inter {s₁ s₂ t₁ t₂ : Set α} (h₁ : s₁ ⊆ t₁) (h₂ : s₂ ⊆ t₂) : s₁ ∩ s₂ ⊆ t₁ ∩ t₂ := fun _ => And.imp (@h₁ _) (@h₂ _) #align set.inter_subset_inter Set.inter_subset_inter @[gcongr] theorem inter_subset_inter_left {s t : Set α} (u : Set α) (H : s ⊆ t) : s ∩ u ⊆ t ∩ u := inter_subset_inter H Subset.rfl #align set.inter_subset_inter_left Set.inter_subset_inter_left @[gcongr] theorem inter_subset_inter_right {s t : Set α} (u : Set α) (H : s ⊆ t) : u ∩ s ⊆ u ∩ t := inter_subset_inter Subset.rfl H #align set.inter_subset_inter_right Set.inter_subset_inter_right theorem union_inter_cancel_left {s t : Set α} : (s ∪ t) ∩ s = s := inter_eq_self_of_subset_right subset_union_left #align set.union_inter_cancel_left Set.union_inter_cancel_left theorem union_inter_cancel_right {s t : Set α} : (s ∪ t) ∩ t = t := inter_eq_self_of_subset_right subset_union_right #align set.union_inter_cancel_right Set.union_inter_cancel_right theorem inter_setOf_eq_sep (s : Set α) (p : α → Prop) : s ∩ {a | p a} = {a ∈ s | p a} := rfl #align set.inter_set_of_eq_sep Set.inter_setOf_eq_sep theorem setOf_inter_eq_sep (p : α → Prop) (s : Set α) : {a | p a} ∩ s = {a ∈ s | p a} := inter_comm _ _ #align set.set_of_inter_eq_sep Set.setOf_inter_eq_sep /-! ### Distributivity laws -/ theorem inter_union_distrib_left (s t u : Set α) : s ∩ (t ∪ u) = s ∩ t ∪ s ∩ u := inf_sup_left _ _ _ #align set.inter_distrib_left Set.inter_union_distrib_left theorem union_inter_distrib_right (s t u : Set α) : (s ∪ t) ∩ u = s ∩ u ∪ t ∩ u := inf_sup_right _ _ _ #align set.inter_distrib_right Set.union_inter_distrib_right theorem union_inter_distrib_left (s t u : Set α) : s ∪ t ∩ u = (s ∪ t) ∩ (s ∪ u) := sup_inf_left _ _ _ #align set.union_distrib_left Set.union_inter_distrib_left theorem inter_union_distrib_right (s t u : Set α) : s ∩ t ∪ u = (s ∪ u) ∩ (t ∪ u) := sup_inf_right _ _ _ #align set.union_distrib_right Set.inter_union_distrib_right -- 2024-03-22 @[deprecated] alias inter_distrib_left := inter_union_distrib_left @[deprecated] alias inter_distrib_right := union_inter_distrib_right @[deprecated] alias union_distrib_left := union_inter_distrib_left @[deprecated] alias union_distrib_right := inter_union_distrib_right theorem union_union_distrib_left (s t u : Set α) : s ∪ (t ∪ u) = s ∪ t ∪ (s ∪ u) := sup_sup_distrib_left _ _ _ #align set.union_union_distrib_left Set.union_union_distrib_left theorem union_union_distrib_right (s t u : Set α) : s ∪ t ∪ u = s ∪ u ∪ (t ∪ u) := sup_sup_distrib_right _ _ _ #align set.union_union_distrib_right Set.union_union_distrib_right theorem inter_inter_distrib_left (s t u : Set α) : s ∩ (t ∩ u) = s ∩ t ∩ (s ∩ u) := inf_inf_distrib_left _ _ _ #align set.inter_inter_distrib_left Set.inter_inter_distrib_left theorem inter_inter_distrib_right (s t u : Set α) : s ∩ t ∩ u = s ∩ u ∩ (t ∩ u) := inf_inf_distrib_right _ _ _ #align set.inter_inter_distrib_right Set.inter_inter_distrib_right theorem union_union_union_comm (s t u v : Set α) : s ∪ t ∪ (u ∪ v) = s ∪ u ∪ (t ∪ v) := sup_sup_sup_comm _ _ _ _ #align set.union_union_union_comm Set.union_union_union_comm theorem inter_inter_inter_comm (s t u v : Set α) : s ∩ t ∩ (u ∩ v) = s ∩ u ∩ (t ∩ v) := inf_inf_inf_comm _ _ _ _ #align set.inter_inter_inter_comm Set.inter_inter_inter_comm /-! ### Lemmas about `insert` `insert α s` is the set `{α} ∪ s`. -/ theorem insert_def (x : α) (s : Set α) : insert x s = { y | y = x ∨ y ∈ s } := rfl #align set.insert_def Set.insert_def @[simp] theorem subset_insert (x : α) (s : Set α) : s ⊆ insert x s := fun _ => Or.inr #align set.subset_insert Set.subset_insert theorem mem_insert (x : α) (s : Set α) : x ∈ insert x s := Or.inl rfl #align set.mem_insert Set.mem_insert theorem mem_insert_of_mem {x : α} {s : Set α} (y : α) : x ∈ s → x ∈ insert y s := Or.inr #align set.mem_insert_of_mem Set.mem_insert_of_mem theorem eq_or_mem_of_mem_insert {x a : α} {s : Set α} : x ∈ insert a s → x = a ∨ x ∈ s := id #align set.eq_or_mem_of_mem_insert Set.eq_or_mem_of_mem_insert theorem mem_of_mem_insert_of_ne : b ∈ insert a s → b ≠ a → b ∈ s := Or.resolve_left #align set.mem_of_mem_insert_of_ne Set.mem_of_mem_insert_of_ne theorem eq_of_not_mem_of_mem_insert : b ∈ insert a s → b ∉ s → b = a := Or.resolve_right #align set.eq_of_not_mem_of_mem_insert Set.eq_of_not_mem_of_mem_insert @[simp] theorem mem_insert_iff {x a : α} {s : Set α} : x ∈ insert a s ↔ x = a ∨ x ∈ s := Iff.rfl #align set.mem_insert_iff Set.mem_insert_iff @[simp] theorem insert_eq_of_mem {a : α} {s : Set α} (h : a ∈ s) : insert a s = s := ext fun _ => or_iff_right_of_imp fun e => e.symm ▸ h #align set.insert_eq_of_mem Set.insert_eq_of_mem theorem ne_insert_of_not_mem {s : Set α} (t : Set α) {a : α} : a ∉ s → s ≠ insert a t := mt fun e => e.symm ▸ mem_insert _ _ #align set.ne_insert_of_not_mem Set.ne_insert_of_not_mem @[simp] theorem insert_eq_self : insert a s = s ↔ a ∈ s := ⟨fun h => h ▸ mem_insert _ _, insert_eq_of_mem⟩ #align set.insert_eq_self Set.insert_eq_self theorem insert_ne_self : insert a s ≠ s ↔ a ∉ s := insert_eq_self.not #align set.insert_ne_self Set.insert_ne_self theorem insert_subset_iff : insert a s ⊆ t ↔ a ∈ t ∧ s ⊆ t := by simp only [subset_def, mem_insert_iff, or_imp, forall_and, forall_eq] #align set.insert_subset Set.insert_subset_iff theorem insert_subset (ha : a ∈ t) (hs : s ⊆ t) : insert a s ⊆ t := insert_subset_iff.mpr ⟨ha, hs⟩ theorem insert_subset_insert (h : s ⊆ t) : insert a s ⊆ insert a t := fun _ => Or.imp_right (@h _) #align set.insert_subset_insert Set.insert_subset_insert @[simp] theorem insert_subset_insert_iff (ha : a ∉ s) : insert a s ⊆ insert a t ↔ s ⊆ t := by refine ⟨fun h x hx => ?_, insert_subset_insert⟩ rcases h (subset_insert _ _ hx) with (rfl | hxt) exacts [(ha hx).elim, hxt] #align set.insert_subset_insert_iff Set.insert_subset_insert_iff theorem subset_insert_iff_of_not_mem (ha : a ∉ s) : s ⊆ insert a t ↔ s ⊆ t := forall₂_congr fun _ hb => or_iff_right <| ne_of_mem_of_not_mem hb ha #align set.subset_insert_iff_of_not_mem Set.subset_insert_iff_of_not_mem theorem ssubset_iff_insert {s t : Set α} : s ⊂ t ↔ ∃ a ∉ s, insert a s ⊆ t := by simp only [insert_subset_iff, exists_and_right, ssubset_def, not_subset] aesop #align set.ssubset_iff_insert Set.ssubset_iff_insert theorem ssubset_insert {s : Set α} {a : α} (h : a ∉ s) : s ⊂ insert a s := ssubset_iff_insert.2 ⟨a, h, Subset.rfl⟩ #align set.ssubset_insert Set.ssubset_insert theorem insert_comm (a b : α) (s : Set α) : insert a (insert b s) = insert b (insert a s) := ext fun _ => or_left_comm #align set.insert_comm Set.insert_comm -- Porting note (#10618): removing `simp` attribute because `simp` can prove it theorem insert_idem (a : α) (s : Set α) : insert a (insert a s) = insert a s := insert_eq_of_mem <| mem_insert _ _ #align set.insert_idem Set.insert_idem theorem insert_union : insert a s ∪ t = insert a (s ∪ t) := ext fun _ => or_assoc #align set.insert_union Set.insert_union @[simp] theorem union_insert : s ∪ insert a t = insert a (s ∪ t) := ext fun _ => or_left_comm #align set.union_insert Set.union_insert @[simp] theorem insert_nonempty (a : α) (s : Set α) : (insert a s).Nonempty := ⟨a, mem_insert a s⟩ #align set.insert_nonempty Set.insert_nonempty instance (a : α) (s : Set α) : Nonempty (insert a s : Set α) := (insert_nonempty a s).to_subtype theorem insert_inter_distrib (a : α) (s t : Set α) : insert a (s ∩ t) = insert a s ∩ insert a t := ext fun _ => or_and_left #align set.insert_inter_distrib Set.insert_inter_distrib theorem insert_union_distrib (a : α) (s t : Set α) : insert a (s ∪ t) = insert a s ∪ insert a t := ext fun _ => or_or_distrib_left #align set.insert_union_distrib Set.insert_union_distrib theorem insert_inj (ha : a ∉ s) : insert a s = insert b s ↔ a = b := ⟨fun h => eq_of_not_mem_of_mem_insert (h.subst <| mem_insert a s) ha, congr_arg (fun x => insert x s)⟩ #align set.insert_inj Set.insert_inj -- useful in proofs by induction theorem forall_of_forall_insert {P : α → Prop} {a : α} {s : Set α} (H : ∀ x, x ∈ insert a s → P x) (x) (h : x ∈ s) : P x := H _ (Or.inr h) #align set.forall_of_forall_insert Set.forall_of_forall_insert theorem forall_insert_of_forall {P : α → Prop} {a : α} {s : Set α} (H : ∀ x, x ∈ s → P x) (ha : P a) (x) (h : x ∈ insert a s) : P x := h.elim (fun e => e.symm ▸ ha) (H _) #align set.forall_insert_of_forall Set.forall_insert_of_forall /- Porting note: ∃ x ∈ insert a s, P x is parsed as ∃ x, x ∈ insert a s ∧ P x, where in Lean3 it was parsed as `∃ x, ∃ (h : x ∈ insert a s), P x` -/ theorem exists_mem_insert {P : α → Prop} {a : α} {s : Set α} : (∃ x ∈ insert a s, P x) ↔ (P a ∨ ∃ x ∈ s, P x) := by simp [mem_insert_iff, or_and_right, exists_and_left, exists_or] #align set.bex_insert_iff Set.exists_mem_insert @[deprecated (since := "2024-03-23")] alias bex_insert_iff := exists_mem_insert theorem forall_mem_insert {P : α → Prop} {a : α} {s : Set α} : (∀ x ∈ insert a s, P x) ↔ P a ∧ ∀ x ∈ s, P x := forall₂_or_left.trans <| and_congr_left' forall_eq #align set.ball_insert_iff Set.forall_mem_insert @[deprecated (since := "2024-03-23")] alias ball_insert_iff := forall_mem_insert /-! ### Lemmas about singletons -/ /- porting note: instance was in core in Lean3 -/ instance : LawfulSingleton α (Set α) := ⟨fun x => Set.ext fun a => by simp only [mem_empty_iff_false, mem_insert_iff, or_false] exact Iff.rfl⟩ theorem singleton_def (a : α) : ({a} : Set α) = insert a ∅ := (insert_emptyc_eq a).symm #align set.singleton_def Set.singleton_def @[simp] theorem mem_singleton_iff {a b : α} : a ∈ ({b} : Set α) ↔ a = b := Iff.rfl #align set.mem_singleton_iff Set.mem_singleton_iff @[simp] theorem setOf_eq_eq_singleton {a : α} : { n | n = a } = {a} := rfl #align set.set_of_eq_eq_singleton Set.setOf_eq_eq_singleton @[simp] theorem setOf_eq_eq_singleton' {a : α} : { x | a = x } = {a} := ext fun _ => eq_comm #align set.set_of_eq_eq_singleton' Set.setOf_eq_eq_singleton' -- TODO: again, annotation needed --Porting note (#11119): removed `simp` attribute theorem mem_singleton (a : α) : a ∈ ({a} : Set α) := @rfl _ _ #align set.mem_singleton Set.mem_singleton theorem eq_of_mem_singleton {x y : α} (h : x ∈ ({y} : Set α)) : x = y := h #align set.eq_of_mem_singleton Set.eq_of_mem_singleton @[simp] theorem singleton_eq_singleton_iff {x y : α} : {x} = ({y} : Set α) ↔ x = y := ext_iff.trans eq_iff_eq_cancel_left #align set.singleton_eq_singleton_iff Set.singleton_eq_singleton_iff theorem singleton_injective : Injective (singleton : α → Set α) := fun _ _ => singleton_eq_singleton_iff.mp #align set.singleton_injective Set.singleton_injective theorem mem_singleton_of_eq {x y : α} (H : x = y) : x ∈ ({y} : Set α) := H #align set.mem_singleton_of_eq Set.mem_singleton_of_eq theorem insert_eq (x : α) (s : Set α) : insert x s = ({x} : Set α) ∪ s := rfl #align set.insert_eq Set.insert_eq @[simp] theorem singleton_nonempty (a : α) : ({a} : Set α).Nonempty := ⟨a, rfl⟩ #align set.singleton_nonempty Set.singleton_nonempty @[simp] theorem singleton_ne_empty (a : α) : ({a} : Set α) ≠ ∅ := (singleton_nonempty _).ne_empty #align set.singleton_ne_empty Set.singleton_ne_empty --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem empty_ssubset_singleton : (∅ : Set α) ⊂ {a} := (singleton_nonempty _).empty_ssubset #align set.empty_ssubset_singleton Set.empty_ssubset_singleton @[simp] theorem singleton_subset_iff {a : α} {s : Set α} : {a} ⊆ s ↔ a ∈ s := forall_eq #align set.singleton_subset_iff Set.singleton_subset_iff theorem singleton_subset_singleton : ({a} : Set α) ⊆ {b} ↔ a = b := by simp #align set.singleton_subset_singleton Set.singleton_subset_singleton theorem set_compr_eq_eq_singleton {a : α} : { b | b = a } = {a} := rfl #align set.set_compr_eq_eq_singleton Set.set_compr_eq_eq_singleton @[simp] theorem singleton_union : {a} ∪ s = insert a s := rfl #align set.singleton_union Set.singleton_union @[simp] theorem union_singleton : s ∪ {a} = insert a s := union_comm _ _ #align set.union_singleton Set.union_singleton @[simp] theorem singleton_inter_nonempty : ({a} ∩ s).Nonempty ↔ a ∈ s := by simp only [Set.Nonempty, mem_inter_iff, mem_singleton_iff, exists_eq_left] #align set.singleton_inter_nonempty Set.singleton_inter_nonempty @[simp] theorem inter_singleton_nonempty : (s ∩ {a}).Nonempty ↔ a ∈ s := by rw [inter_comm, singleton_inter_nonempty] #align set.inter_singleton_nonempty Set.inter_singleton_nonempty @[simp] theorem singleton_inter_eq_empty : {a} ∩ s = ∅ ↔ a ∉ s := not_nonempty_iff_eq_empty.symm.trans singleton_inter_nonempty.not #align set.singleton_inter_eq_empty Set.singleton_inter_eq_empty @[simp] theorem inter_singleton_eq_empty : s ∩ {a} = ∅ ↔ a ∉ s := by rw [inter_comm, singleton_inter_eq_empty] #align set.inter_singleton_eq_empty Set.inter_singleton_eq_empty theorem nmem_singleton_empty {s : Set α} : s ∉ ({∅} : Set (Set α)) ↔ s.Nonempty := nonempty_iff_ne_empty.symm #align set.nmem_singleton_empty Set.nmem_singleton_empty instance uniqueSingleton (a : α) : Unique (↥({a} : Set α)) := ⟨⟨⟨a, mem_singleton a⟩⟩, fun ⟨_, h⟩ => Subtype.eq h⟩ #align set.unique_singleton Set.uniqueSingleton theorem eq_singleton_iff_unique_mem : s = {a} ↔ a ∈ s ∧ ∀ x ∈ s, x = a := Subset.antisymm_iff.trans <| and_comm.trans <| and_congr_left' singleton_subset_iff #align set.eq_singleton_iff_unique_mem Set.eq_singleton_iff_unique_mem theorem eq_singleton_iff_nonempty_unique_mem : s = {a} ↔ s.Nonempty ∧ ∀ x ∈ s, x = a := eq_singleton_iff_unique_mem.trans <| and_congr_left fun H => ⟨fun h' => ⟨_, h'⟩, fun ⟨x, h⟩ => H x h ▸ h⟩ #align set.eq_singleton_iff_nonempty_unique_mem Set.eq_singleton_iff_nonempty_unique_mem set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532 -- while `simp` is capable of proving this, it is not capable of turning the LHS into the RHS. @[simp] theorem default_coe_singleton (x : α) : (default : ({x} : Set α)) = ⟨x, rfl⟩ := rfl #align set.default_coe_singleton Set.default_coe_singleton /-! ### Lemmas about sets defined as `{x ∈ s | p x}`. -/ section Sep variable {p q : α → Prop} {x : α} theorem mem_sep (xs : x ∈ s) (px : p x) : x ∈ { x ∈ s | p x } := ⟨xs, px⟩ #align set.mem_sep Set.mem_sep @[simp] theorem sep_mem_eq : { x ∈ s | x ∈ t } = s ∩ t := rfl #align set.sep_mem_eq Set.sep_mem_eq @[simp] theorem mem_sep_iff : x ∈ { x ∈ s | p x } ↔ x ∈ s ∧ p x := Iff.rfl #align set.mem_sep_iff Set.mem_sep_iff theorem sep_ext_iff : { x ∈ s | p x } = { x ∈ s | q x } ↔ ∀ x ∈ s, p x ↔ q x := by simp_rw [ext_iff, mem_sep_iff, and_congr_right_iff] #align set.sep_ext_iff Set.sep_ext_iff theorem sep_eq_of_subset (h : s ⊆ t) : { x ∈ t | x ∈ s } = s := inter_eq_self_of_subset_right h #align set.sep_eq_of_subset Set.sep_eq_of_subset @[simp] theorem sep_subset (s : Set α) (p : α → Prop) : { x ∈ s | p x } ⊆ s := fun _ => And.left #align set.sep_subset Set.sep_subset @[simp] theorem sep_eq_self_iff_mem_true : { x ∈ s | p x } = s ↔ ∀ x ∈ s, p x := by simp_rw [ext_iff, mem_sep_iff, and_iff_left_iff_imp] #align set.sep_eq_self_iff_mem_true Set.sep_eq_self_iff_mem_true @[simp] theorem sep_eq_empty_iff_mem_false : { x ∈ s | p x } = ∅ ↔ ∀ x ∈ s, ¬p x := by simp_rw [ext_iff, mem_sep_iff, mem_empty_iff_false, iff_false_iff, not_and] #align set.sep_eq_empty_iff_mem_false Set.sep_eq_empty_iff_mem_false --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem sep_true : { x ∈ s | True } = s := inter_univ s #align set.sep_true Set.sep_true --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem sep_false : { x ∈ s | False } = ∅ := inter_empty s #align set.sep_false Set.sep_false --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem sep_empty (p : α → Prop) : { x ∈ (∅ : Set α) | p x } = ∅ := empty_inter {x | p x} #align set.sep_empty Set.sep_empty --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem sep_univ : { x ∈ (univ : Set α) | p x } = { x | p x } := univ_inter {x | p x} #align set.sep_univ Set.sep_univ @[simp] theorem sep_union : { x | (x ∈ s ∨ x ∈ t) ∧ p x } = { x ∈ s | p x } ∪ { x ∈ t | p x } := union_inter_distrib_right { x | x ∈ s } { x | x ∈ t } p #align set.sep_union Set.sep_union @[simp] theorem sep_inter : { x | (x ∈ s ∧ x ∈ t) ∧ p x } = { x ∈ s | p x } ∩ { x ∈ t | p x } := inter_inter_distrib_right s t {x | p x} #align set.sep_inter Set.sep_inter @[simp] theorem sep_and : { x ∈ s | p x ∧ q x } = { x ∈ s | p x } ∩ { x ∈ s | q x } := inter_inter_distrib_left s {x | p x} {x | q x} #align set.sep_and Set.sep_and @[simp] theorem sep_or : { x ∈ s | p x ∨ q x } = { x ∈ s | p x } ∪ { x ∈ s | q x } := inter_union_distrib_left s p q #align set.sep_or Set.sep_or @[simp] theorem sep_setOf : { x ∈ { y | p y } | q x } = { x | p x ∧ q x } := rfl #align set.sep_set_of Set.sep_setOf end Sep @[simp] theorem subset_singleton_iff {α : Type*} {s : Set α} {x : α} : s ⊆ {x} ↔ ∀ y ∈ s, y = x := Iff.rfl #align set.subset_singleton_iff Set.subset_singleton_iff theorem subset_singleton_iff_eq {s : Set α} {x : α} : s ⊆ {x} ↔ s = ∅ ∨ s = {x} := by obtain rfl | hs := s.eq_empty_or_nonempty · exact ⟨fun _ => Or.inl rfl, fun _ => empty_subset _⟩ · simp [eq_singleton_iff_nonempty_unique_mem, hs, hs.ne_empty] #align set.subset_singleton_iff_eq Set.subset_singleton_iff_eq theorem Nonempty.subset_singleton_iff (h : s.Nonempty) : s ⊆ {a} ↔ s = {a} := subset_singleton_iff_eq.trans <| or_iff_right h.ne_empty #align set.nonempty.subset_singleton_iff Set.Nonempty.subset_singleton_iff theorem ssubset_singleton_iff {s : Set α} {x : α} : s ⊂ {x} ↔ s = ∅ := by rw [ssubset_iff_subset_ne, subset_singleton_iff_eq, or_and_right, and_not_self_iff, or_false_iff, and_iff_left_iff_imp] exact fun h => h ▸ (singleton_ne_empty _).symm #align set.ssubset_singleton_iff Set.ssubset_singleton_iff theorem eq_empty_of_ssubset_singleton {s : Set α} {x : α} (hs : s ⊂ {x}) : s = ∅ := ssubset_singleton_iff.1 hs #align set.eq_empty_of_ssubset_singleton Set.eq_empty_of_ssubset_singleton theorem eq_of_nonempty_of_subsingleton {α} [Subsingleton α] (s t : Set α) [Nonempty s] [Nonempty t] : s = t := nonempty_of_nonempty_subtype.eq_univ.trans nonempty_of_nonempty_subtype.eq_univ.symm theorem eq_of_nonempty_of_subsingleton' {α} [Subsingleton α] {s : Set α} (t : Set α) (hs : s.Nonempty) [Nonempty t] : s = t := have := hs.to_subtype; eq_of_nonempty_of_subsingleton s t set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532 theorem Nonempty.eq_zero [Subsingleton α] [Zero α] {s : Set α} (h : s.Nonempty) : s = {0} := eq_of_nonempty_of_subsingleton' {0} h set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532 theorem Nonempty.eq_one [Subsingleton α] [One α] {s : Set α} (h : s.Nonempty) : s = {1} := eq_of_nonempty_of_subsingleton' {1} h /-! ### Disjointness -/ protected theorem disjoint_iff : Disjoint s t ↔ s ∩ t ⊆ ∅ := disjoint_iff_inf_le #align set.disjoint_iff Set.disjoint_iff theorem disjoint_iff_inter_eq_empty : Disjoint s t ↔ s ∩ t = ∅ := disjoint_iff #align set.disjoint_iff_inter_eq_empty Set.disjoint_iff_inter_eq_empty theorem _root_.Disjoint.inter_eq : Disjoint s t → s ∩ t = ∅ := Disjoint.eq_bot #align disjoint.inter_eq Disjoint.inter_eq theorem disjoint_left : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ s → a ∉ t := disjoint_iff_inf_le.trans <| forall_congr' fun _ => not_and #align set.disjoint_left Set.disjoint_left theorem disjoint_right : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ t → a ∉ s := by rw [disjoint_comm, disjoint_left] #align set.disjoint_right Set.disjoint_right lemma not_disjoint_iff : ¬Disjoint s t ↔ ∃ x, x ∈ s ∧ x ∈ t := Set.disjoint_iff.not.trans <| not_forall.trans <| exists_congr fun _ ↦ not_not #align set.not_disjoint_iff Set.not_disjoint_iff lemma not_disjoint_iff_nonempty_inter : ¬ Disjoint s t ↔ (s ∩ t).Nonempty := not_disjoint_iff #align set.not_disjoint_iff_nonempty_inter Set.not_disjoint_iff_nonempty_inter alias ⟨_, Nonempty.not_disjoint⟩ := not_disjoint_iff_nonempty_inter #align set.nonempty.not_disjoint Set.Nonempty.not_disjoint lemma disjoint_or_nonempty_inter (s t : Set α) : Disjoint s t ∨ (s ∩ t).Nonempty := (em _).imp_right not_disjoint_iff_nonempty_inter.1 #align set.disjoint_or_nonempty_inter Set.disjoint_or_nonempty_inter lemma disjoint_iff_forall_ne : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ t → a ≠ b := by simp only [Ne, disjoint_left, @imp_not_comm _ (_ = _), forall_eq'] #align set.disjoint_iff_forall_ne Set.disjoint_iff_forall_ne alias ⟨_root_.Disjoint.ne_of_mem, _⟩ := disjoint_iff_forall_ne #align disjoint.ne_of_mem Disjoint.ne_of_mem lemma disjoint_of_subset_left (h : s ⊆ u) (d : Disjoint u t) : Disjoint s t := d.mono_left h #align set.disjoint_of_subset_left Set.disjoint_of_subset_left lemma disjoint_of_subset_right (h : t ⊆ u) (d : Disjoint s u) : Disjoint s t := d.mono_right h #align set.disjoint_of_subset_right Set.disjoint_of_subset_right lemma disjoint_of_subset (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) (h : Disjoint s₂ t₂) : Disjoint s₁ t₁ := h.mono hs ht #align set.disjoint_of_subset Set.disjoint_of_subset @[simp] lemma disjoint_union_left : Disjoint (s ∪ t) u ↔ Disjoint s u ∧ Disjoint t u := disjoint_sup_left #align set.disjoint_union_left Set.disjoint_union_left @[simp] lemma disjoint_union_right : Disjoint s (t ∪ u) ↔ Disjoint s t ∧ Disjoint s u := disjoint_sup_right #align set.disjoint_union_right Set.disjoint_union_right @[simp] lemma disjoint_empty (s : Set α) : Disjoint s ∅ := disjoint_bot_right #align set.disjoint_empty Set.disjoint_empty @[simp] lemma empty_disjoint (s : Set α) : Disjoint ∅ s := disjoint_bot_left #align set.empty_disjoint Set.empty_disjoint @[simp] lemma univ_disjoint : Disjoint univ s ↔ s = ∅ := top_disjoint #align set.univ_disjoint Set.univ_disjoint @[simp] lemma disjoint_univ : Disjoint s univ ↔ s = ∅ := disjoint_top #align set.disjoint_univ Set.disjoint_univ lemma disjoint_sdiff_left : Disjoint (t \ s) s := disjoint_sdiff_self_left #align set.disjoint_sdiff_left Set.disjoint_sdiff_left lemma disjoint_sdiff_right : Disjoint s (t \ s) := disjoint_sdiff_self_right #align set.disjoint_sdiff_right Set.disjoint_sdiff_right -- TODO: prove this in terms of a lattice lemma theorem disjoint_sdiff_inter : Disjoint (s \ t) (s ∩ t) := disjoint_of_subset_right inter_subset_right disjoint_sdiff_left #align set.disjoint_sdiff_inter Set.disjoint_sdiff_inter theorem diff_union_diff_cancel (hts : t ⊆ s) (hut : u ⊆ t) : s \ t ∪ t \ u = s \ u := sdiff_sup_sdiff_cancel hts hut #align set.diff_union_diff_cancel Set.diff_union_diff_cancel theorem diff_diff_eq_sdiff_union (h : u ⊆ s) : s \ (t \ u) = s \ t ∪ u := sdiff_sdiff_eq_sdiff_sup h #align set.diff_diff_eq_sdiff_union Set.diff_diff_eq_sdiff_union @[simp default+1] lemma disjoint_singleton_left : Disjoint {a} s ↔ a ∉ s := by simp [Set.disjoint_iff, subset_def] #align set.disjoint_singleton_left Set.disjoint_singleton_left @[simp] lemma disjoint_singleton_right : Disjoint s {a} ↔ a ∉ s := disjoint_comm.trans disjoint_singleton_left #align set.disjoint_singleton_right Set.disjoint_singleton_right lemma disjoint_singleton : Disjoint ({a} : Set α) {b} ↔ a ≠ b := by simp #align set.disjoint_singleton Set.disjoint_singleton lemma subset_diff : s ⊆ t \ u ↔ s ⊆ t ∧ Disjoint s u := le_iff_subset.symm.trans le_sdiff #align set.subset_diff Set.subset_diff lemma ssubset_iff_sdiff_singleton : s ⊂ t ↔ ∃ a ∈ t, s ⊆ t \ {a} := by simp [ssubset_iff_insert, subset_diff, insert_subset_iff]; aesop theorem inter_diff_distrib_left (s t u : Set α) : s ∩ (t \ u) = (s ∩ t) \ (s ∩ u) := inf_sdiff_distrib_left _ _ _ #align set.inter_diff_distrib_left Set.inter_diff_distrib_left theorem inter_diff_distrib_right (s t u : Set α) : s \ t ∩ u = (s ∩ u) \ (t ∩ u) := inf_sdiff_distrib_right _ _ _ #align set.inter_diff_distrib_right Set.inter_diff_distrib_right /-! ### Lemmas about complement -/ theorem compl_def (s : Set α) : sᶜ = { x | x ∉ s } := rfl #align set.compl_def Set.compl_def theorem mem_compl {s : Set α} {x : α} (h : x ∉ s) : x ∈ sᶜ := h #align set.mem_compl Set.mem_compl theorem compl_setOf {α} (p : α → Prop) : { a | p a }ᶜ = { a | ¬p a } := rfl #align set.compl_set_of Set.compl_setOf theorem not_mem_of_mem_compl {s : Set α} {x : α} (h : x ∈ sᶜ) : x ∉ s := h #align set.not_mem_of_mem_compl Set.not_mem_of_mem_compl theorem not_mem_compl_iff {x : α} : x ∉ sᶜ ↔ x ∈ s := not_not #align set.not_mem_compl_iff Set.not_mem_compl_iff @[simp] theorem inter_compl_self (s : Set α) : s ∩ sᶜ = ∅ := inf_compl_eq_bot #align set.inter_compl_self Set.inter_compl_self @[simp] theorem compl_inter_self (s : Set α) : sᶜ ∩ s = ∅ := compl_inf_eq_bot #align set.compl_inter_self Set.compl_inter_self @[simp] theorem compl_empty : (∅ : Set α)ᶜ = univ := compl_bot #align set.compl_empty Set.compl_empty @[simp] theorem compl_union (s t : Set α) : (s ∪ t)ᶜ = sᶜ ∩ tᶜ := compl_sup #align set.compl_union Set.compl_union theorem compl_inter (s t : Set α) : (s ∩ t)ᶜ = sᶜ ∪ tᶜ := compl_inf #align set.compl_inter Set.compl_inter @[simp] theorem compl_univ : (univ : Set α)ᶜ = ∅ := compl_top #align set.compl_univ Set.compl_univ @[simp] theorem compl_empty_iff {s : Set α} : sᶜ = ∅ ↔ s = univ := compl_eq_bot #align set.compl_empty_iff Set.compl_empty_iff @[simp] theorem compl_univ_iff {s : Set α} : sᶜ = univ ↔ s = ∅ := compl_eq_top #align set.compl_univ_iff Set.compl_univ_iff theorem compl_ne_univ : sᶜ ≠ univ ↔ s.Nonempty := compl_univ_iff.not.trans nonempty_iff_ne_empty.symm #align set.compl_ne_univ Set.compl_ne_univ theorem nonempty_compl : sᶜ.Nonempty ↔ s ≠ univ := (ne_univ_iff_exists_not_mem s).symm #align set.nonempty_compl Set.nonempty_compl @[simp] lemma nonempty_compl_of_nontrivial [Nontrivial α] (x : α) : Set.Nonempty {x}ᶜ := by obtain ⟨y, hy⟩ := exists_ne x exact ⟨y, by simp [hy]⟩ theorem mem_compl_singleton_iff {a x : α} : x ∈ ({a} : Set α)ᶜ ↔ x ≠ a := Iff.rfl #align set.mem_compl_singleton_iff Set.mem_compl_singleton_iff theorem compl_singleton_eq (a : α) : ({a} : Set α)ᶜ = { x | x ≠ a } := rfl #align set.compl_singleton_eq Set.compl_singleton_eq @[simp] theorem compl_ne_eq_singleton (a : α) : ({ x | x ≠ a } : Set α)ᶜ = {a} := compl_compl _ #align set.compl_ne_eq_singleton Set.compl_ne_eq_singleton theorem union_eq_compl_compl_inter_compl (s t : Set α) : s ∪ t = (sᶜ ∩ tᶜ)ᶜ := ext fun _ => or_iff_not_and_not #align set.union_eq_compl_compl_inter_compl Set.union_eq_compl_compl_inter_compl theorem inter_eq_compl_compl_union_compl (s t : Set α) : s ∩ t = (sᶜ ∪ tᶜ)ᶜ := ext fun _ => and_iff_not_or_not #align set.inter_eq_compl_compl_union_compl Set.inter_eq_compl_compl_union_compl @[simp] theorem union_compl_self (s : Set α) : s ∪ sᶜ = univ := eq_univ_iff_forall.2 fun _ => em _ #align set.union_compl_self Set.union_compl_self @[simp] theorem compl_union_self (s : Set α) : sᶜ ∪ s = univ := by rw [union_comm, union_compl_self] #align set.compl_union_self Set.compl_union_self theorem compl_subset_comm : sᶜ ⊆ t ↔ tᶜ ⊆ s := @compl_le_iff_compl_le _ s _ _ #align set.compl_subset_comm Set.compl_subset_comm theorem subset_compl_comm : s ⊆ tᶜ ↔ t ⊆ sᶜ := @le_compl_iff_le_compl _ _ _ t #align set.subset_compl_comm Set.subset_compl_comm @[simp] theorem compl_subset_compl : sᶜ ⊆ tᶜ ↔ t ⊆ s := @compl_le_compl_iff_le (Set α) _ _ _ #align set.compl_subset_compl Set.compl_subset_compl @[gcongr] theorem compl_subset_compl_of_subset (h : t ⊆ s) : sᶜ ⊆ tᶜ := compl_subset_compl.2 h theorem subset_compl_iff_disjoint_left : s ⊆ tᶜ ↔ Disjoint t s := @le_compl_iff_disjoint_left (Set α) _ _ _ #align set.subset_compl_iff_disjoint_left Set.subset_compl_iff_disjoint_left theorem subset_compl_iff_disjoint_right : s ⊆ tᶜ ↔ Disjoint s t := @le_compl_iff_disjoint_right (Set α) _ _ _ #align set.subset_compl_iff_disjoint_right Set.subset_compl_iff_disjoint_right theorem disjoint_compl_left_iff_subset : Disjoint sᶜ t ↔ t ⊆ s := disjoint_compl_left_iff #align set.disjoint_compl_left_iff_subset Set.disjoint_compl_left_iff_subset theorem disjoint_compl_right_iff_subset : Disjoint s tᶜ ↔ s ⊆ t := disjoint_compl_right_iff #align set.disjoint_compl_right_iff_subset Set.disjoint_compl_right_iff_subset alias ⟨_, _root_.Disjoint.subset_compl_right⟩ := subset_compl_iff_disjoint_right #align disjoint.subset_compl_right Disjoint.subset_compl_right alias ⟨_, _root_.Disjoint.subset_compl_left⟩ := subset_compl_iff_disjoint_left #align disjoint.subset_compl_left Disjoint.subset_compl_left alias ⟨_, _root_.HasSubset.Subset.disjoint_compl_left⟩ := disjoint_compl_left_iff_subset #align has_subset.subset.disjoint_compl_left HasSubset.Subset.disjoint_compl_left alias ⟨_, _root_.HasSubset.Subset.disjoint_compl_right⟩ := disjoint_compl_right_iff_subset #align has_subset.subset.disjoint_compl_right HasSubset.Subset.disjoint_compl_right theorem subset_union_compl_iff_inter_subset {s t u : Set α} : s ⊆ t ∪ uᶜ ↔ s ∩ u ⊆ t := (@isCompl_compl _ u _).le_sup_right_iff_inf_left_le #align set.subset_union_compl_iff_inter_subset Set.subset_union_compl_iff_inter_subset theorem compl_subset_iff_union {s t : Set α} : sᶜ ⊆ t ↔ s ∪ t = univ := Iff.symm <| eq_univ_iff_forall.trans <| forall_congr' fun _ => or_iff_not_imp_left #align set.compl_subset_iff_union Set.compl_subset_iff_union @[simp] theorem subset_compl_singleton_iff {a : α} {s : Set α} : s ⊆ {a}ᶜ ↔ a ∉ s := subset_compl_comm.trans singleton_subset_iff #align set.subset_compl_singleton_iff Set.subset_compl_singleton_iff theorem inter_subset (a b c : Set α) : a ∩ b ⊆ c ↔ a ⊆ bᶜ ∪ c := forall_congr' fun _ => and_imp.trans <| imp_congr_right fun _ => imp_iff_not_or #align set.inter_subset Set.inter_subset theorem inter_compl_nonempty_iff {s t : Set α} : (s ∩ tᶜ).Nonempty ↔ ¬s ⊆ t := (not_subset.trans <| exists_congr fun x => by simp [mem_compl]).symm #align set.inter_compl_nonempty_iff Set.inter_compl_nonempty_iff /-! ### Lemmas about set difference -/ theorem not_mem_diff_of_mem {s t : Set α} {x : α} (hx : x ∈ t) : x ∉ s \ t := fun h => h.2 hx #align set.not_mem_diff_of_mem Set.not_mem_diff_of_mem theorem mem_of_mem_diff {s t : Set α} {x : α} (h : x ∈ s \ t) : x ∈ s := h.left #align set.mem_of_mem_diff Set.mem_of_mem_diff theorem not_mem_of_mem_diff {s t : Set α} {x : α} (h : x ∈ s \ t) : x ∉ t := h.right #align set.not_mem_of_mem_diff Set.not_mem_of_mem_diff theorem diff_eq_compl_inter {s t : Set α} : s \ t = tᶜ ∩ s := by rw [diff_eq, inter_comm] #align set.diff_eq_compl_inter Set.diff_eq_compl_inter theorem nonempty_diff {s t : Set α} : (s \ t).Nonempty ↔ ¬s ⊆ t := inter_compl_nonempty_iff #align set.nonempty_diff Set.nonempty_diff theorem diff_subset {s t : Set α} : s \ t ⊆ s := show s \ t ≤ s from sdiff_le #align set.diff_subset Set.diff_subset theorem diff_subset_compl (s t : Set α) : s \ t ⊆ tᶜ := diff_eq_compl_inter ▸ inter_subset_left theorem union_diff_cancel' {s t u : Set α} (h₁ : s ⊆ t) (h₂ : t ⊆ u) : t ∪ u \ s = u := sup_sdiff_cancel' h₁ h₂ #align set.union_diff_cancel' Set.union_diff_cancel' theorem union_diff_cancel {s t : Set α} (h : s ⊆ t) : s ∪ t \ s = t := sup_sdiff_cancel_right h #align set.union_diff_cancel Set.union_diff_cancel theorem union_diff_cancel_left {s t : Set α} (h : s ∩ t ⊆ ∅) : (s ∪ t) \ s = t := Disjoint.sup_sdiff_cancel_left <| disjoint_iff_inf_le.2 h #align set.union_diff_cancel_left Set.union_diff_cancel_left theorem union_diff_cancel_right {s t : Set α} (h : s ∩ t ⊆ ∅) : (s ∪ t) \ t = s := Disjoint.sup_sdiff_cancel_right <| disjoint_iff_inf_le.2 h #align set.union_diff_cancel_right Set.union_diff_cancel_right @[simp] theorem union_diff_left {s t : Set α} : (s ∪ t) \ s = t \ s := sup_sdiff_left_self #align set.union_diff_left Set.union_diff_left @[simp] theorem union_diff_right {s t : Set α} : (s ∪ t) \ t = s \ t := sup_sdiff_right_self #align set.union_diff_right Set.union_diff_right theorem union_diff_distrib {s t u : Set α} : (s ∪ t) \ u = s \ u ∪ t \ u := sup_sdiff #align set.union_diff_distrib Set.union_diff_distrib theorem inter_diff_assoc (a b c : Set α) : (a ∩ b) \ c = a ∩ (b \ c) := inf_sdiff_assoc #align set.inter_diff_assoc Set.inter_diff_assoc @[simp] theorem inter_diff_self (a b : Set α) : a ∩ (b \ a) = ∅ := inf_sdiff_self_right #align set.inter_diff_self Set.inter_diff_self @[simp] theorem inter_union_diff (s t : Set α) : s ∩ t ∪ s \ t = s := sup_inf_sdiff s t #align set.inter_union_diff Set.inter_union_diff @[simp] theorem diff_union_inter (s t : Set α) : s \ t ∪ s ∩ t = s := by rw [union_comm] exact sup_inf_sdiff _ _ #align set.diff_union_inter Set.diff_union_inter @[simp] theorem inter_union_compl (s t : Set α) : s ∩ t ∪ s ∩ tᶜ = s := inter_union_diff _ _ #align set.inter_union_compl Set.inter_union_compl @[gcongr] theorem diff_subset_diff {s₁ s₂ t₁ t₂ : Set α} : s₁ ⊆ s₂ → t₂ ⊆ t₁ → s₁ \ t₁ ⊆ s₂ \ t₂ := show s₁ ≤ s₂ → t₂ ≤ t₁ → s₁ \ t₁ ≤ s₂ \ t₂ from sdiff_le_sdiff #align set.diff_subset_diff Set.diff_subset_diff @[gcongr] theorem diff_subset_diff_left {s₁ s₂ t : Set α} (h : s₁ ⊆ s₂) : s₁ \ t ⊆ s₂ \ t := sdiff_le_sdiff_right ‹s₁ ≤ s₂› #align set.diff_subset_diff_left Set.diff_subset_diff_left @[gcongr] theorem diff_subset_diff_right {s t u : Set α} (h : t ⊆ u) : s \ u ⊆ s \ t := sdiff_le_sdiff_left ‹t ≤ u› #align set.diff_subset_diff_right Set.diff_subset_diff_right theorem compl_eq_univ_diff (s : Set α) : sᶜ = univ \ s := top_sdiff.symm #align set.compl_eq_univ_diff Set.compl_eq_univ_diff @[simp] theorem empty_diff (s : Set α) : (∅ \ s : Set α) = ∅ := bot_sdiff #align set.empty_diff Set.empty_diff theorem diff_eq_empty {s t : Set α} : s \ t = ∅ ↔ s ⊆ t := sdiff_eq_bot_iff #align set.diff_eq_empty Set.diff_eq_empty @[simp] theorem diff_empty {s : Set α} : s \ ∅ = s := sdiff_bot #align set.diff_empty Set.diff_empty @[simp] theorem diff_univ (s : Set α) : s \ univ = ∅ := diff_eq_empty.2 (subset_univ s) #align set.diff_univ Set.diff_univ theorem diff_diff {u : Set α} : (s \ t) \ u = s \ (t ∪ u) := sdiff_sdiff_left #align set.diff_diff Set.diff_diff -- the following statement contains parentheses to help the reader theorem diff_diff_comm {s t u : Set α} : (s \ t) \ u = (s \ u) \ t := sdiff_sdiff_comm #align set.diff_diff_comm Set.diff_diff_comm theorem diff_subset_iff {s t u : Set α} : s \ t ⊆ u ↔ s ⊆ t ∪ u := show s \ t ≤ u ↔ s ≤ t ∪ u from sdiff_le_iff #align set.diff_subset_iff Set.diff_subset_iff theorem subset_diff_union (s t : Set α) : s ⊆ s \ t ∪ t := show s ≤ s \ t ∪ t from le_sdiff_sup #align set.subset_diff_union Set.subset_diff_union theorem diff_union_of_subset {s t : Set α} (h : t ⊆ s) : s \ t ∪ t = s := Subset.antisymm (union_subset diff_subset h) (subset_diff_union _ _) #align set.diff_union_of_subset Set.diff_union_of_subset @[simp] theorem diff_singleton_subset_iff {x : α} {s t : Set α} : s \ {x} ⊆ t ↔ s ⊆ insert x t := by rw [← union_singleton, union_comm] apply diff_subset_iff #align set.diff_singleton_subset_iff Set.diff_singleton_subset_iff theorem subset_diff_singleton {x : α} {s t : Set α} (h : s ⊆ t) (hx : x ∉ s) : s ⊆ t \ {x} := subset_inter h <| subset_compl_comm.1 <| singleton_subset_iff.2 hx #align set.subset_diff_singleton Set.subset_diff_singleton theorem subset_insert_diff_singleton (x : α) (s : Set α) : s ⊆ insert x (s \ {x}) := by rw [← diff_singleton_subset_iff] #align set.subset_insert_diff_singleton Set.subset_insert_diff_singleton theorem diff_subset_comm {s t u : Set α} : s \ t ⊆ u ↔ s \ u ⊆ t := show s \ t ≤ u ↔ s \ u ≤ t from sdiff_le_comm #align set.diff_subset_comm Set.diff_subset_comm theorem diff_inter {s t u : Set α} : s \ (t ∩ u) = s \ t ∪ s \ u := sdiff_inf #align set.diff_inter Set.diff_inter theorem diff_inter_diff {s t u : Set α} : s \ t ∩ (s \ u) = s \ (t ∪ u) := sdiff_sup.symm #align set.diff_inter_diff Set.diff_inter_diff theorem diff_compl : s \ tᶜ = s ∩ t := sdiff_compl #align set.diff_compl Set.diff_compl theorem diff_diff_right {s t u : Set α} : s \ (t \ u) = s \ t ∪ s ∩ u := sdiff_sdiff_right' #align set.diff_diff_right Set.diff_diff_right @[simp] theorem insert_diff_of_mem (s) (h : a ∈ t) : insert a s \ t = s \ t := by ext constructor <;> simp (config := { contextual := true }) [or_imp, h] #align set.insert_diff_of_mem Set.insert_diff_of_mem theorem insert_diff_of_not_mem (s) (h : a ∉ t) : insert a s \ t = insert a (s \ t) := by classical ext x by_cases h' : x ∈ t · have : x ≠ a := by intro H rw [H] at h' exact h h' simp [h, h', this] · simp [h, h'] #align set.insert_diff_of_not_mem Set.insert_diff_of_not_mem theorem insert_diff_self_of_not_mem {a : α} {s : Set α} (h : a ∉ s) : insert a s \ {a} = s := by ext x simp [and_iff_left_of_imp fun hx : x ∈ s => show x ≠ a from fun hxa => h <| hxa ▸ hx] #align set.insert_diff_self_of_not_mem Set.insert_diff_self_of_not_mem @[simp] theorem insert_diff_eq_singleton {a : α} {s : Set α} (h : a ∉ s) : insert a s \ s = {a} := by ext rw [Set.mem_diff, Set.mem_insert_iff, Set.mem_singleton_iff, or_and_right, and_not_self_iff, or_false_iff, and_iff_left_iff_imp] rintro rfl exact h #align set.insert_diff_eq_singleton Set.insert_diff_eq_singleton theorem inter_insert_of_mem (h : a ∈ s) : s ∩ insert a t = insert a (s ∩ t) := by rw [insert_inter_distrib, insert_eq_of_mem h] #align set.inter_insert_of_mem Set.inter_insert_of_mem theorem insert_inter_of_mem (h : a ∈ t) : insert a s ∩ t = insert a (s ∩ t) := by rw [insert_inter_distrib, insert_eq_of_mem h] #align set.insert_inter_of_mem Set.insert_inter_of_mem theorem inter_insert_of_not_mem (h : a ∉ s) : s ∩ insert a t = s ∩ t := ext fun _ => and_congr_right fun hx => or_iff_right <| ne_of_mem_of_not_mem hx h #align set.inter_insert_of_not_mem Set.inter_insert_of_not_mem theorem insert_inter_of_not_mem (h : a ∉ t) : insert a s ∩ t = s ∩ t := ext fun _ => and_congr_left fun hx => or_iff_right <| ne_of_mem_of_not_mem hx h #align set.insert_inter_of_not_mem Set.insert_inter_of_not_mem @[simp] theorem union_diff_self {s t : Set α} : s ∪ t \ s = s ∪ t := sup_sdiff_self _ _ #align set.union_diff_self Set.union_diff_self @[simp] theorem diff_union_self {s t : Set α} : s \ t ∪ t = s ∪ t := sdiff_sup_self _ _ #align set.diff_union_self Set.diff_union_self @[simp] theorem diff_inter_self {a b : Set α} : b \ a ∩ a = ∅ := inf_sdiff_self_left #align set.diff_inter_self Set.diff_inter_self @[simp] theorem diff_inter_self_eq_diff {s t : Set α} : s \ (t ∩ s) = s \ t := sdiff_inf_self_right _ _ #align set.diff_inter_self_eq_diff Set.diff_inter_self_eq_diff @[simp] theorem diff_self_inter {s t : Set α} : s \ (s ∩ t) = s \ t := sdiff_inf_self_left _ _ #align set.diff_self_inter Set.diff_self_inter @[simp] theorem diff_singleton_eq_self {a : α} {s : Set α} (h : a ∉ s) : s \ {a} = s := sdiff_eq_self_iff_disjoint.2 <| by simp [h] #align set.diff_singleton_eq_self Set.diff_singleton_eq_self @[simp] theorem diff_singleton_sSubset {s : Set α} {a : α} : s \ {a} ⊂ s ↔ a ∈ s := sdiff_le.lt_iff_ne.trans <| sdiff_eq_left.not.trans <| by simp #align set.diff_singleton_ssubset Set.diff_singleton_sSubset @[simp] theorem insert_diff_singleton {a : α} {s : Set α} : insert a (s \ {a}) = insert a s := by simp [insert_eq, union_diff_self, -union_singleton, -singleton_union] #align set.insert_diff_singleton Set.insert_diff_singleton theorem insert_diff_singleton_comm (hab : a ≠ b) (s : Set α) : insert a (s \ {b}) = insert a s \ {b} := by simp_rw [← union_singleton, union_diff_distrib, diff_singleton_eq_self (mem_singleton_iff.not.2 hab.symm)] #align set.insert_diff_singleton_comm Set.insert_diff_singleton_comm --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem diff_self {s : Set α} : s \ s = ∅ := sdiff_self #align set.diff_self Set.diff_self theorem diff_diff_right_self (s t : Set α) : s \ (s \ t) = s ∩ t := sdiff_sdiff_right_self #align set.diff_diff_right_self Set.diff_diff_right_self theorem diff_diff_cancel_left {s t : Set α} (h : s ⊆ t) : t \ (t \ s) = s := sdiff_sdiff_eq_self h #align set.diff_diff_cancel_left Set.diff_diff_cancel_left theorem mem_diff_singleton {x y : α} {s : Set α} : x ∈ s \ {y} ↔ x ∈ s ∧ x ≠ y := Iff.rfl #align set.mem_diff_singleton Set.mem_diff_singleton theorem mem_diff_singleton_empty {t : Set (Set α)} : s ∈ t \ {∅} ↔ s ∈ t ∧ s.Nonempty := mem_diff_singleton.trans <| and_congr_right' nonempty_iff_ne_empty.symm #align set.mem_diff_singleton_empty Set.mem_diff_singleton_empty theorem subset_insert_iff {s t : Set α} {x : α} : s ⊆ insert x t ↔ s ⊆ t ∨ (x ∈ s ∧ s \ {x} ⊆ t) := by rw [← diff_singleton_subset_iff] by_cases hx : x ∈ s · rw [and_iff_right hx, or_iff_right_of_imp diff_subset.trans] rw [diff_singleton_eq_self hx, or_iff_left_of_imp And.right] theorem union_eq_diff_union_diff_union_inter (s t : Set α) : s ∪ t = s \ t ∪ t \ s ∪ s ∩ t := sup_eq_sdiff_sup_sdiff_sup_inf #align set.union_eq_diff_union_diff_union_inter Set.union_eq_diff_union_diff_union_inter /-! ### Lemmas about pairs -/ --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem pair_eq_singleton (a : α) : ({a, a} : Set α) = {a} := union_self _ #align set.pair_eq_singleton Set.pair_eq_singleton theorem pair_comm (a b : α) : ({a, b} : Set α) = {b, a} := union_comm _ _ #align set.pair_comm Set.pair_comm theorem pair_eq_pair_iff {x y z w : α} : ({x, y} : Set α) = {z, w} ↔ x = z ∧ y = w ∨ x = w ∧ y = z := by simp [subset_antisymm_iff, insert_subset_iff]; aesop #align set.pair_eq_pair_iff Set.pair_eq_pair_iff theorem pair_diff_left (hne : a ≠ b) : ({a, b} : Set α) \ {a} = {b} := by rw [insert_diff_of_mem _ (mem_singleton a), diff_singleton_eq_self (by simpa)] theorem pair_diff_right (hne : a ≠ b) : ({a, b} : Set α) \ {b} = {a} := by rw [pair_comm, pair_diff_left hne.symm] theorem pair_subset_iff : {a, b} ⊆ s ↔ a ∈ s ∧ b ∈ s := by rw [insert_subset_iff, singleton_subset_iff] theorem pair_subset (ha : a ∈ s) (hb : b ∈ s) : {a, b} ⊆ s := pair_subset_iff.2 ⟨ha,hb⟩ theorem subset_pair_iff : s ⊆ {a, b} ↔ ∀ x ∈ s, x = a ∨ x = b := by simp [subset_def]
Mathlib/Data/Set/Basic.lean
2,097
2,102
theorem subset_pair_iff_eq {x y : α} : s ⊆ {x, y} ↔ s = ∅ ∨ s = {x} ∨ s = {y} ∨ s = {x, y} := by
refine ⟨?_, by rintro (rfl | rfl | rfl | rfl) <;> simp [pair_subset_iff]⟩ rw [subset_insert_iff, subset_singleton_iff_eq, subset_singleton_iff_eq, ← subset_empty_iff (s := s \ {x}), diff_subset_iff, union_empty, subset_singleton_iff_eq] have h : x ∈ s → {y} = s \ {x} → s = {x,y} := fun h₁ h₂ ↦ by simp [h₁, h₂] tauto
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca, Johan Commelin -/ import Mathlib.Algebra.Polynomial.FieldDivision import Mathlib.FieldTheory.Minpoly.Basic import Mathlib.RingTheory.Algebraic #align_import field_theory.minpoly.field from "leanprover-community/mathlib"@"cbdf7b565832144d024caa5a550117c6df0204a5" /-! # Minimal polynomials on an algebra over a field This file specializes the theory of minpoly to the setting of field extensions and derives some well-known properties, amongst which the fact that minimal polynomials are irreducible, and uniquely determined by their defining property. -/ open scoped Classical open Polynomial Set Function minpoly namespace minpoly variable {A B : Type*} variable (A) [Field A] section Ring variable [Ring B] [Algebra A B] (x : B) /-- If an element `x` is a root of a nonzero polynomial `p`, then the degree of `p` is at least the degree of the minimal polynomial of `x`. See also `minpoly.IsIntegrallyClosed.degree_le_of_ne_zero` which relaxes the assumptions on `A` in exchange for stronger assumptions on `B`. -/ theorem degree_le_of_ne_zero {p : A[X]} (pnz : p ≠ 0) (hp : Polynomial.aeval x p = 0) : degree (minpoly A x) ≤ degree p := calc degree (minpoly A x) ≤ degree (p * C (leadingCoeff p)⁻¹) := min A x (monic_mul_leadingCoeff_inv pnz) (by simp [hp]) _ = degree p := degree_mul_leadingCoeff_inv p pnz #align minpoly.degree_le_of_ne_zero minpoly.degree_le_of_ne_zero theorem ne_zero_of_finite (e : B) [FiniteDimensional A B] : minpoly A e ≠ 0 := minpoly.ne_zero <| .of_finite A _ #align minpoly.ne_zero_of_finite_field_extension minpoly.ne_zero_of_finite /-- The minimal polynomial of an element `x` is uniquely characterized by its defining property: if there is another monic polynomial of minimal degree that has `x` as a root, then this polynomial is equal to the minimal polynomial of `x`. See also `minpoly.IsIntegrallyClosed.Minpoly.unique` which relaxes the assumptions on `A` in exchange for stronger assumptions on `B`. -/ theorem unique {p : A[X]} (pmonic : p.Monic) (hp : Polynomial.aeval x p = 0) (pmin : ∀ q : A[X], q.Monic → Polynomial.aeval x q = 0 → degree p ≤ degree q) : p = minpoly A x := by have hx : IsIntegral A x := ⟨p, pmonic, hp⟩ symm; apply eq_of_sub_eq_zero by_contra hnz apply degree_le_of_ne_zero A x hnz (by simp [hp]) |>.not_lt apply degree_sub_lt _ (minpoly.ne_zero hx) · rw [(monic hx).leadingCoeff, pmonic.leadingCoeff] · exact le_antisymm (min A x pmonic hp) (pmin (minpoly A x) (monic hx) (aeval A x)) #align minpoly.unique minpoly.unique /-- If an element `x` is a root of a polynomial `p`, then the minimal polynomial of `x` divides `p`. See also `minpoly.isIntegrallyClosed_dvd` which relaxes the assumptions on `A` in exchange for stronger assumptions on `B`. -/ theorem dvd {p : A[X]} (hp : Polynomial.aeval x p = 0) : minpoly A x ∣ p := by by_cases hp0 : p = 0 · simp only [hp0, dvd_zero] have hx : IsIntegral A x := IsAlgebraic.isIntegral ⟨p, hp0, hp⟩ rw [← modByMonic_eq_zero_iff_dvd (monic hx)] by_contra hnz apply degree_le_of_ne_zero A x hnz ((aeval_modByMonic_eq_self_of_root (monic hx) (aeval _ _)).trans hp) |>.not_lt exact degree_modByMonic_lt _ (monic hx) #align minpoly.dvd minpoly.dvd variable {A x} in lemma dvd_iff {p : A[X]} : minpoly A x ∣ p ↔ Polynomial.aeval x p = 0 := ⟨fun ⟨q, hq⟩ ↦ by rw [hq, map_mul, aeval, zero_mul], minpoly.dvd A x⟩ theorem isRadical [IsReduced B] : IsRadical (minpoly A x) := fun n p dvd ↦ by rw [dvd_iff] at dvd ⊢; rw [map_pow] at dvd; exact IsReduced.eq_zero _ ⟨n, dvd⟩ theorem dvd_map_of_isScalarTower (A K : Type*) {R : Type*} [CommRing A] [Field K] [CommRing R] [Algebra A K] [Algebra A R] [Algebra K R] [IsScalarTower A K R] (x : R) : minpoly K x ∣ (minpoly A x).map (algebraMap A K) := by refine minpoly.dvd K x ?_ rw [aeval_map_algebraMap, minpoly.aeval] #align minpoly.dvd_map_of_is_scalar_tower minpoly.dvd_map_of_isScalarTower theorem dvd_map_of_isScalarTower' (R : Type*) {S : Type*} (K L : Type*) [CommRing R] [CommRing S] [Field K] [CommRing L] [Algebra R S] [Algebra R K] [Algebra S L] [Algebra K L] [Algebra R L] [IsScalarTower R K L] [IsScalarTower R S L] (s : S) : minpoly K (algebraMap S L s) ∣ map (algebraMap R K) (minpoly R s) := by apply minpoly.dvd K (algebraMap S L s) rw [← map_aeval_eq_aeval_map, minpoly.aeval, map_zero] rw [← IsScalarTower.algebraMap_eq, ← IsScalarTower.algebraMap_eq] #align minpoly.dvd_map_of_is_scalar_tower' minpoly.dvd_map_of_isScalarTower' /-- If `y` is a conjugate of `x` over a field `K`, then it is a conjugate over a subring `R`. -/ theorem aeval_of_isScalarTower (R : Type*) {K T U : Type*} [CommRing R] [Field K] [CommRing T] [Algebra R K] [Algebra K T] [Algebra R T] [IsScalarTower R K T] [CommSemiring U] [Algebra K U] [Algebra R U] [IsScalarTower R K U] (x : T) (y : U) (hy : Polynomial.aeval y (minpoly K x) = 0) : Polynomial.aeval y (minpoly R x) = 0 := aeval_map_algebraMap K y (minpoly R x) ▸ eval₂_eq_zero_of_dvd_of_eval₂_eq_zero (algebraMap K U) y (minpoly.dvd_map_of_isScalarTower R K x) hy #align minpoly.aeval_of_is_scalar_tower minpoly.aeval_of_isScalarTower /-- See also `minpoly.ker_eval` which relaxes the assumptions on `A` in exchange for stronger assumptions on `B`. -/ @[simp] lemma ker_aeval_eq_span_minpoly : RingHom.ker (Polynomial.aeval x) = A[X] ∙ minpoly A x := by ext p simp_rw [RingHom.mem_ker, ← minpoly.dvd_iff, Submodule.mem_span_singleton, dvd_iff_exists_eq_mul_left, smul_eq_mul, eq_comm (a := p)] variable {A x} theorem eq_of_irreducible_of_monic [Nontrivial B] {p : A[X]} (hp1 : Irreducible p) (hp2 : Polynomial.aeval x p = 0) (hp3 : p.Monic) : p = minpoly A x := let ⟨_, hq⟩ := dvd A x hp2 eq_of_monic_of_associated hp3 (monic ⟨p, ⟨hp3, hp2⟩⟩) <| mul_one (minpoly A x) ▸ hq.symm ▸ Associated.mul_left _ (associated_one_iff_isUnit.2 <| (hp1.isUnit_or_isUnit hq).resolve_left <| not_isUnit A x) #align minpoly.eq_of_irreducible_of_monic minpoly.eq_of_irreducible_of_monic theorem eq_of_irreducible [Nontrivial B] {p : A[X]} (hp1 : Irreducible p) (hp2 : Polynomial.aeval x p = 0) : p * C p.leadingCoeff⁻¹ = minpoly A x := by have : p.leadingCoeff ≠ 0 := leadingCoeff_ne_zero.mpr hp1.ne_zero apply eq_of_irreducible_of_monic · exact Associated.irreducible ⟨⟨C p.leadingCoeff⁻¹, C p.leadingCoeff, by rwa [← C_mul, inv_mul_cancel, C_1], by rwa [← C_mul, mul_inv_cancel, C_1]⟩, rfl⟩ hp1 · rw [aeval_mul, hp2, zero_mul] · rwa [Polynomial.Monic, leadingCoeff_mul, leadingCoeff_C, mul_inv_cancel] #align minpoly.eq_of_irreducible minpoly.eq_of_irreducible theorem add_algebraMap {B : Type*} [CommRing B] [Algebra A B] {x : B} (hx : IsIntegral A x) (a : A) : minpoly A (x + algebraMap A B a) = (minpoly A x).comp (X - C a) := by refine (minpoly.unique _ _ ((minpoly.monic hx).comp_X_sub_C _) ?_ fun q qmo hq => ?_).symm · simp [aeval_comp] · have : (Polynomial.aeval x) (q.comp (X + C a)) = 0 := by simpa [aeval_comp] using hq have H := minpoly.min A x (qmo.comp_X_add_C _) this rw [degree_eq_natDegree qmo.ne_zero, degree_eq_natDegree ((minpoly.monic hx).comp_X_sub_C _).ne_zero, natDegree_comp, natDegree_X_sub_C, mul_one] rwa [degree_eq_natDegree (minpoly.ne_zero hx), degree_eq_natDegree (qmo.comp_X_add_C _).ne_zero, natDegree_comp, natDegree_X_add_C, mul_one] at H #align minpoly.add_algebra_map minpoly.add_algebraMap theorem sub_algebraMap {B : Type*} [CommRing B] [Algebra A B] {x : B} (hx : IsIntegral A x) (a : A) : minpoly A (x - algebraMap A B a) = (minpoly A x).comp (X + C a) := by simpa [sub_eq_add_neg] using add_algebraMap hx (-a) #align minpoly.sub_algebra_map minpoly.sub_algebraMap section AlgHomFintype /-- A technical finiteness result. -/ noncomputable def Fintype.subtypeProd {E : Type*} {X : Set E} (hX : X.Finite) {L : Type*} (F : E → Multiset L) : Fintype (∀ x : X, { l : L // l ∈ F x }) := @Pi.fintype _ _ _ (Finite.fintype hX) _ #align minpoly.fintype.subtype_prod minpoly.Fintype.subtypeProd variable (F E K : Type*) [Field F] [Ring E] [CommRing K] [IsDomain K] [Algebra F E] [Algebra F K] [FiniteDimensional F E] -- Porting note (#11083): removed `noncomputable!` since it seems not to be slow in lean 4, -- though it isn't very computable in practice (since neither `finrank` nor `finBasis` are). /-- Function from Hom_K(E,L) to pi type Π (x : basis), roots of min poly of x -/ def rootsOfMinPolyPiType (φ : E →ₐ[F] K) (x : range (FiniteDimensional.finBasis F E : _ → E)) : { l : K // l ∈ (minpoly F x.1).aroots K } := ⟨φ x, by rw [mem_roots_map (minpoly.ne_zero_of_finite F x.val), ← aeval_def, aeval_algHom_apply, minpoly.aeval, map_zero]⟩ #align minpoly.roots_of_min_poly_pi_type minpoly.rootsOfMinPolyPiType theorem aux_inj_roots_of_min_poly : Injective (rootsOfMinPolyPiType F E K) := by intro f g h -- needs explicit coercion on the RHS suffices (f : E →ₗ[F] K) = (g : E →ₗ[F] K) by rwa [DFunLike.ext'_iff] at this ⊢ rw [funext_iff] at h exact LinearMap.ext_on (FiniteDimensional.finBasis F E).span_eq fun e he => Subtype.ext_iff.mp (h ⟨e, he⟩) #align minpoly.aux_inj_roots_of_min_poly minpoly.aux_inj_roots_of_min_poly /-- Given field extensions `E/F` and `K/F`, with `E/F` finite, there are finitely many `F`-algebra homomorphisms `E →ₐ[K] K`. -/ noncomputable instance AlgHom.fintype : Fintype (E →ₐ[F] K) := @Fintype.ofInjective _ _ (Fintype.subtypeProd (finite_range (FiniteDimensional.finBasis F E)) fun e => (minpoly F e).aroots K) _ (aux_inj_roots_of_min_poly F E K) #align minpoly.alg_hom.fintype minpoly.AlgHom.fintype end AlgHomFintype variable (B) [Nontrivial B] /-- If `B/K` is a nontrivial algebra over a field, and `x` is an element of `K`, then the minimal polynomial of `algebraMap K B x` is `X - C x`. -/ theorem eq_X_sub_C (a : A) : minpoly A (algebraMap A B a) = X - C a := eq_X_sub_C_of_algebraMap_inj a (algebraMap A B).injective set_option linter.uppercaseLean3 false in #align minpoly.eq_X_sub_C minpoly.eq_X_sub_C theorem eq_X_sub_C' (a : A) : minpoly A a = X - C a := eq_X_sub_C A a set_option linter.uppercaseLean3 false in #align minpoly.eq_X_sub_C' minpoly.eq_X_sub_C' variable (A) /-- The minimal polynomial of `0` is `X`. -/ @[simp] theorem zero : minpoly A (0 : B) = X := by simpa only [add_zero, C_0, sub_eq_add_neg, neg_zero, RingHom.map_zero] using eq_X_sub_C B (0 : A) #align minpoly.zero minpoly.zero /-- The minimal polynomial of `1` is `X - 1`. -/ @[simp] theorem one : minpoly A (1 : B) = X - 1 := by simpa only [RingHom.map_one, C_1, sub_eq_add_neg] using eq_X_sub_C B (1 : A) #align minpoly.one minpoly.one end Ring section IsDomain variable [Ring B] [IsDomain B] [Algebra A B] variable {A} {x : B} /-- A minimal polynomial is prime. -/
Mathlib/FieldTheory/Minpoly/Field.lean
238
243
theorem prime (hx : IsIntegral A x) : Prime (minpoly A x) := by
refine ⟨minpoly.ne_zero hx, not_isUnit A x, ?_⟩ rintro p q ⟨d, h⟩ have : Polynomial.aeval x (p * q) = 0 := by simp [h, aeval A x] replace : Polynomial.aeval x p = 0 ∨ Polynomial.aeval x q = 0 := by simpa exact Or.imp (dvd A x) (dvd A x) this
/- Copyright (c) 2018 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Johannes Hölzl, Yaël Dillies -/ import Mathlib.Analysis.Normed.Group.Seminorm import Mathlib.Order.LiminfLimsup import Mathlib.Topology.Instances.Rat import Mathlib.Topology.MetricSpace.Algebra import Mathlib.Topology.MetricSpace.IsometricSMul import Mathlib.Topology.Sequences #align_import analysis.normed.group.basic from "leanprover-community/mathlib"@"41bef4ae1254365bc190aee63b947674d2977f01" /-! # Normed (semi)groups In this file we define 10 classes: * `Norm`, `NNNorm`: auxiliary classes endowing a type `α` with a function `norm : α → ℝ` (notation: `‖x‖`) and `nnnorm : α → ℝ≥0` (notation: `‖x‖₊`), respectively; * `Seminormed...Group`: A seminormed (additive) (commutative) group is an (additive) (commutative) group with a norm and a compatible pseudometric space structure: `∀ x y, dist x y = ‖x / y‖` or `∀ x y, dist x y = ‖x - y‖`, depending on the group operation. * `Normed...Group`: A normed (additive) (commutative) group is an (additive) (commutative) group with a norm and a compatible metric space structure. We also prove basic properties of (semi)normed groups and provide some instances. ## TODO This file is huge; move material into separate files, such as `Mathlib/Analysis/Normed/Group/Lemmas.lean`. ## Notes The current convention `dist x y = ‖x - y‖` means that the distance is invariant under right addition, but actions in mathlib are usually from the left. This means we might want to change it to `dist x y = ‖-x + y‖`. The normed group hierarchy would lend itself well to a mixin design (that is, having `SeminormedGroup` and `SeminormedAddGroup` not extend `Group` and `AddGroup`), but we choose not to for performance concerns. ## Tags normed group -/ variable {𝓕 𝕜 α ι κ E F G : Type*} open Filter Function Metric Bornology open ENNReal Filter NNReal Uniformity Pointwise Topology /-- Auxiliary class, endowing a type `E` with a function `norm : E → ℝ` with notation `‖x‖`. This class is designed to be extended in more interesting classes specifying the properties of the norm. -/ @[notation_class] class Norm (E : Type*) where /-- the `ℝ`-valued norm function. -/ norm : E → ℝ #align has_norm Norm /-- Auxiliary class, endowing a type `α` with a function `nnnorm : α → ℝ≥0` with notation `‖x‖₊`. -/ @[notation_class] class NNNorm (E : Type*) where /-- the `ℝ≥0`-valued norm function. -/ nnnorm : E → ℝ≥0 #align has_nnnorm NNNorm export Norm (norm) export NNNorm (nnnorm) @[inherit_doc] notation "‖" e "‖" => norm e @[inherit_doc] notation "‖" e "‖₊" => nnnorm e /-- A seminormed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a pseudometric space structure. -/ class SeminormedAddGroup (E : Type*) extends Norm E, AddGroup E, PseudoMetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align seminormed_add_group SeminormedAddGroup /-- A seminormed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a pseudometric space structure. -/ @[to_additive] class SeminormedGroup (E : Type*) extends Norm E, Group E, PseudoMetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align seminormed_group SeminormedGroup /-- A normed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a metric space structure. -/ class NormedAddGroup (E : Type*) extends Norm E, AddGroup E, MetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align normed_add_group NormedAddGroup /-- A normed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a metric space structure. -/ @[to_additive] class NormedGroup (E : Type*) extends Norm E, Group E, MetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align normed_group NormedGroup /-- A seminormed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a pseudometric space structure. -/ class SeminormedAddCommGroup (E : Type*) extends Norm E, AddCommGroup E, PseudoMetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align seminormed_add_comm_group SeminormedAddCommGroup /-- A seminormed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a pseudometric space structure. -/ @[to_additive] class SeminormedCommGroup (E : Type*) extends Norm E, CommGroup E, PseudoMetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align seminormed_comm_group SeminormedCommGroup /-- A normed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a metric space structure. -/ class NormedAddCommGroup (E : Type*) extends Norm E, AddCommGroup E, MetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align normed_add_comm_group NormedAddCommGroup /-- A normed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a metric space structure. -/ @[to_additive] class NormedCommGroup (E : Type*) extends Norm E, CommGroup E, MetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align normed_comm_group NormedCommGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedGroup.toSeminormedGroup [NormedGroup E] : SeminormedGroup E := { ‹NormedGroup E› with } #align normed_group.to_seminormed_group NormedGroup.toSeminormedGroup #align normed_add_group.to_seminormed_add_group NormedAddGroup.toSeminormedAddGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedCommGroup.toSeminormedCommGroup [NormedCommGroup E] : SeminormedCommGroup E := { ‹NormedCommGroup E› with } #align normed_comm_group.to_seminormed_comm_group NormedCommGroup.toSeminormedCommGroup #align normed_add_comm_group.to_seminormed_add_comm_group NormedAddCommGroup.toSeminormedAddCommGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) SeminormedCommGroup.toSeminormedGroup [SeminormedCommGroup E] : SeminormedGroup E := { ‹SeminormedCommGroup E› with } #align seminormed_comm_group.to_seminormed_group SeminormedCommGroup.toSeminormedGroup #align seminormed_add_comm_group.to_seminormed_add_group SeminormedAddCommGroup.toSeminormedAddGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedCommGroup.toNormedGroup [NormedCommGroup E] : NormedGroup E := { ‹NormedCommGroup E› with } #align normed_comm_group.to_normed_group NormedCommGroup.toNormedGroup #align normed_add_comm_group.to_normed_add_group NormedAddCommGroup.toNormedAddGroup -- See note [reducible non-instances] /-- Construct a `NormedGroup` from a `SeminormedGroup` satisfying `∀ x, ‖x‖ = 0 → x = 1`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedGroup` instance as a special case of a more general `SeminormedGroup` instance. -/ @[to_additive (attr := reducible) "Construct a `NormedAddGroup` from a `SeminormedAddGroup` satisfying `∀ x, ‖x‖ = 0 → x = 0`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedAddGroup` instance as a special case of a more general `SeminormedAddGroup` instance."] def NormedGroup.ofSeparation [SeminormedGroup E] (h : ∀ x : E, ‖x‖ = 0 → x = 1) : NormedGroup E where dist_eq := ‹SeminormedGroup E›.dist_eq toMetricSpace := { eq_of_dist_eq_zero := fun hxy => div_eq_one.1 <| h _ <| by exact (‹SeminormedGroup E›.dist_eq _ _).symm.trans hxy } -- Porting note: the `rwa` no longer worked, but it was easy enough to provide the term. -- however, notice that if you make `x` and `y` accessible, then the following does work: -- `have := ‹SeminormedGroup E›.dist_eq x y; rwa [← this]`, so I'm not sure why the `rwa` -- was broken. #align normed_group.of_separation NormedGroup.ofSeparation #align normed_add_group.of_separation NormedAddGroup.ofSeparation -- See note [reducible non-instances] /-- Construct a `NormedCommGroup` from a `SeminormedCommGroup` satisfying `∀ x, ‖x‖ = 0 → x = 1`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedCommGroup` instance as a special case of a more general `SeminormedCommGroup` instance. -/ @[to_additive (attr := reducible) "Construct a `NormedAddCommGroup` from a `SeminormedAddCommGroup` satisfying `∀ x, ‖x‖ = 0 → x = 0`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedAddCommGroup` instance as a special case of a more general `SeminormedAddCommGroup` instance."] def NormedCommGroup.ofSeparation [SeminormedCommGroup E] (h : ∀ x : E, ‖x‖ = 0 → x = 1) : NormedCommGroup E := { ‹SeminormedCommGroup E›, NormedGroup.ofSeparation h with } #align normed_comm_group.of_separation NormedCommGroup.ofSeparation #align normed_add_comm_group.of_separation NormedAddCommGroup.ofSeparation -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant distance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant distance."] def SeminormedGroup.ofMulDist [Norm E] [Group E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : SeminormedGroup E where dist_eq x y := by rw [h₁]; apply le_antisymm · simpa only [div_eq_mul_inv, ← mul_right_inv y] using h₂ _ _ _ · simpa only [div_mul_cancel, one_mul] using h₂ (x / y) 1 y #align seminormed_group.of_mul_dist SeminormedGroup.ofMulDist #align seminormed_add_group.of_add_dist SeminormedAddGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant pseudodistance."] def SeminormedGroup.ofMulDist' [Norm E] [Group E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : SeminormedGroup E where dist_eq x y := by rw [h₁]; apply le_antisymm · simpa only [div_mul_cancel, one_mul] using h₂ (x / y) 1 y · simpa only [div_eq_mul_inv, ← mul_right_inv y] using h₂ _ _ _ #align seminormed_group.of_mul_dist' SeminormedGroup.ofMulDist' #align seminormed_add_group.of_add_dist' SeminormedAddGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant pseudodistance."] def SeminormedCommGroup.ofMulDist [Norm E] [CommGroup E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : SeminormedCommGroup E := { SeminormedGroup.ofMulDist h₁ h₂ with mul_comm := mul_comm } #align seminormed_comm_group.of_mul_dist SeminormedCommGroup.ofMulDist #align seminormed_add_comm_group.of_add_dist SeminormedAddCommGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant pseudodistance."] def SeminormedCommGroup.ofMulDist' [Norm E] [CommGroup E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : SeminormedCommGroup E := { SeminormedGroup.ofMulDist' h₁ h₂ with mul_comm := mul_comm } #align seminormed_comm_group.of_mul_dist' SeminormedCommGroup.ofMulDist' #align seminormed_add_comm_group.of_add_dist' SeminormedAddCommGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant distance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant distance."] def NormedGroup.ofMulDist [Norm E] [Group E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : NormedGroup E := { SeminormedGroup.ofMulDist h₁ h₂ with eq_of_dist_eq_zero := eq_of_dist_eq_zero } #align normed_group.of_mul_dist NormedGroup.ofMulDist #align normed_add_group.of_add_dist NormedAddGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant pseudodistance."] def NormedGroup.ofMulDist' [Norm E] [Group E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : NormedGroup E := { SeminormedGroup.ofMulDist' h₁ h₂ with eq_of_dist_eq_zero := eq_of_dist_eq_zero } #align normed_group.of_mul_dist' NormedGroup.ofMulDist' #align normed_add_group.of_add_dist' NormedAddGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant pseudodistance."] def NormedCommGroup.ofMulDist [Norm E] [CommGroup E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : NormedCommGroup E := { NormedGroup.ofMulDist h₁ h₂ with mul_comm := mul_comm } #align normed_comm_group.of_mul_dist NormedCommGroup.ofMulDist #align normed_add_comm_group.of_add_dist NormedAddCommGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant pseudodistance."] def NormedCommGroup.ofMulDist' [Norm E] [CommGroup E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : NormedCommGroup E := { NormedGroup.ofMulDist' h₁ h₂ with mul_comm := mul_comm } #align normed_comm_group.of_mul_dist' NormedCommGroup.ofMulDist' #align normed_add_comm_group.of_add_dist' NormedAddCommGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupSeminorm.toSeminormedGroup [Group E] (f : GroupSeminorm E) : SeminormedGroup E where dist x y := f (x / y) norm := f dist_eq x y := rfl dist_self x := by simp only [div_self', map_one_eq_zero] dist_triangle := le_map_div_add_map_div f dist_comm := map_div_rev f edist_dist x y := by exact ENNReal.coe_nnreal_eq _ -- Porting note: how did `mathlib3` solve this automatically? #align group_seminorm.to_seminormed_group GroupSeminorm.toSeminormedGroup #align add_group_seminorm.to_seminormed_add_group AddGroupSeminorm.toSeminormedAddGroup -- See note [reducible non-instances] /-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupSeminorm.toSeminormedCommGroup [CommGroup E] (f : GroupSeminorm E) : SeminormedCommGroup E := { f.toSeminormedGroup with mul_comm := mul_comm } #align group_seminorm.to_seminormed_comm_group GroupSeminorm.toSeminormedCommGroup #align add_group_seminorm.to_seminormed_add_comm_group AddGroupSeminorm.toSeminormedAddCommGroup -- See note [reducible non-instances] /-- Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupNorm.toNormedGroup [Group E] (f : GroupNorm E) : NormedGroup E := { f.toGroupSeminorm.toSeminormedGroup with eq_of_dist_eq_zero := fun h => div_eq_one.1 <| eq_one_of_map_eq_zero f h } #align group_norm.to_normed_group GroupNorm.toNormedGroup #align add_group_norm.to_normed_add_group AddGroupNorm.toNormedAddGroup -- See note [reducible non-instances] /-- Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupNorm.toNormedCommGroup [CommGroup E] (f : GroupNorm E) : NormedCommGroup E := { f.toNormedGroup with mul_comm := mul_comm } #align group_norm.to_normed_comm_group GroupNorm.toNormedCommGroup #align add_group_norm.to_normed_add_comm_group AddGroupNorm.toNormedAddCommGroup instance PUnit.normedAddCommGroup : NormedAddCommGroup PUnit where norm := Function.const _ 0 dist_eq _ _ := rfl @[simp] theorem PUnit.norm_eq_zero (r : PUnit) : ‖r‖ = 0 := rfl #align punit.norm_eq_zero PUnit.norm_eq_zero section SeminormedGroup variable [SeminormedGroup E] [SeminormedGroup F] [SeminormedGroup G] {s : Set E} {a a₁ a₂ b b₁ b₂ : E} {r r₁ r₂ : ℝ} @[to_additive] theorem dist_eq_norm_div (a b : E) : dist a b = ‖a / b‖ := SeminormedGroup.dist_eq _ _ #align dist_eq_norm_div dist_eq_norm_div #align dist_eq_norm_sub dist_eq_norm_sub @[to_additive] theorem dist_eq_norm_div' (a b : E) : dist a b = ‖b / a‖ := by rw [dist_comm, dist_eq_norm_div] #align dist_eq_norm_div' dist_eq_norm_div' #align dist_eq_norm_sub' dist_eq_norm_sub' alias dist_eq_norm := dist_eq_norm_sub #align dist_eq_norm dist_eq_norm alias dist_eq_norm' := dist_eq_norm_sub' #align dist_eq_norm' dist_eq_norm' @[to_additive] instance NormedGroup.to_isometricSMul_right : IsometricSMul Eᵐᵒᵖ E := ⟨fun a => Isometry.of_dist_eq fun b c => by simp [dist_eq_norm_div]⟩ #align normed_group.to_has_isometric_smul_right NormedGroup.to_isometricSMul_right #align normed_add_group.to_has_isometric_vadd_right NormedAddGroup.to_isometricVAdd_right @[to_additive (attr := simp)] theorem dist_one_right (a : E) : dist a 1 = ‖a‖ := by rw [dist_eq_norm_div, div_one] #align dist_one_right dist_one_right #align dist_zero_right dist_zero_right @[to_additive] theorem inseparable_one_iff_norm {a : E} : Inseparable a 1 ↔ ‖a‖ = 0 := by rw [Metric.inseparable_iff, dist_one_right] @[to_additive (attr := simp)] theorem dist_one_left : dist (1 : E) = norm := funext fun a => by rw [dist_comm, dist_one_right] #align dist_one_left dist_one_left #align dist_zero_left dist_zero_left @[to_additive] theorem Isometry.norm_map_of_map_one {f : E → F} (hi : Isometry f) (h₁ : f 1 = 1) (x : E) : ‖f x‖ = ‖x‖ := by rw [← dist_one_right, ← h₁, hi.dist_eq, dist_one_right] #align isometry.norm_map_of_map_one Isometry.norm_map_of_map_one #align isometry.norm_map_of_map_zero Isometry.norm_map_of_map_zero @[to_additive (attr := simp) comap_norm_atTop] theorem comap_norm_atTop' : comap norm atTop = cobounded E := by simpa only [dist_one_right] using comap_dist_right_atTop (1 : E) @[to_additive Filter.HasBasis.cobounded_of_norm] lemma Filter.HasBasis.cobounded_of_norm' {ι : Sort*} {p : ι → Prop} {s : ι → Set ℝ} (h : HasBasis atTop p s) : HasBasis (cobounded E) p fun i ↦ norm ⁻¹' s i := comap_norm_atTop' (E := E) ▸ h.comap _ @[to_additive Filter.hasBasis_cobounded_norm] lemma Filter.hasBasis_cobounded_norm' : HasBasis (cobounded E) (fun _ ↦ True) ({x | · ≤ ‖x‖}) := atTop_basis.cobounded_of_norm' @[to_additive (attr := simp) tendsto_norm_atTop_iff_cobounded] theorem tendsto_norm_atTop_iff_cobounded' {f : α → E} {l : Filter α} : Tendsto (‖f ·‖) l atTop ↔ Tendsto f l (cobounded E) := by rw [← comap_norm_atTop', tendsto_comap_iff]; rfl @[to_additive tendsto_norm_cobounded_atTop] theorem tendsto_norm_cobounded_atTop' : Tendsto norm (cobounded E) atTop := tendsto_norm_atTop_iff_cobounded'.2 tendsto_id @[to_additive eventually_cobounded_le_norm] lemma eventually_cobounded_le_norm' (a : ℝ) : ∀ᶠ x in cobounded E, a ≤ ‖x‖ := tendsto_norm_cobounded_atTop'.eventually_ge_atTop a @[to_additive tendsto_norm_cocompact_atTop] theorem tendsto_norm_cocompact_atTop' [ProperSpace E] : Tendsto norm (cocompact E) atTop := cobounded_eq_cocompact (α := E) ▸ tendsto_norm_cobounded_atTop' #align tendsto_norm_cocompact_at_top' tendsto_norm_cocompact_atTop' #align tendsto_norm_cocompact_at_top tendsto_norm_cocompact_atTop @[to_additive] theorem norm_div_rev (a b : E) : ‖a / b‖ = ‖b / a‖ := by simpa only [dist_eq_norm_div] using dist_comm a b #align norm_div_rev norm_div_rev #align norm_sub_rev norm_sub_rev @[to_additive (attr := simp) norm_neg] theorem norm_inv' (a : E) : ‖a⁻¹‖ = ‖a‖ := by simpa using norm_div_rev 1 a #align norm_inv' norm_inv' #align norm_neg norm_neg open scoped symmDiff in @[to_additive] theorem dist_mulIndicator (s t : Set α) (f : α → E) (x : α) : dist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖ := by rw [dist_eq_norm_div, Set.apply_mulIndicator_symmDiff norm_inv'] @[to_additive (attr := simp)] theorem dist_mul_self_right (a b : E) : dist b (a * b) = ‖a‖ := by rw [← dist_one_left, ← dist_mul_right 1 a b, one_mul] #align dist_mul_self_right dist_mul_self_right #align dist_add_self_right dist_add_self_right @[to_additive (attr := simp)] theorem dist_mul_self_left (a b : E) : dist (a * b) b = ‖a‖ := by rw [dist_comm, dist_mul_self_right] #align dist_mul_self_left dist_mul_self_left #align dist_add_self_left dist_add_self_left @[to_additive (attr := simp)] theorem dist_div_eq_dist_mul_left (a b c : E) : dist (a / b) c = dist a (c * b) := by rw [← dist_mul_right _ _ b, div_mul_cancel] #align dist_div_eq_dist_mul_left dist_div_eq_dist_mul_left #align dist_sub_eq_dist_add_left dist_sub_eq_dist_add_left @[to_additive (attr := simp)] theorem dist_div_eq_dist_mul_right (a b c : E) : dist a (b / c) = dist (a * c) b := by rw [← dist_mul_right _ _ c, div_mul_cancel] #align dist_div_eq_dist_mul_right dist_div_eq_dist_mul_right #align dist_sub_eq_dist_add_right dist_sub_eq_dist_add_right @[to_additive (attr := simp)] lemma Filter.inv_cobounded : (cobounded E)⁻¹ = cobounded E := by simp only [← comap_norm_atTop', ← Filter.comap_inv, comap_comap, (· ∘ ·), norm_inv'] /-- In a (semi)normed group, inversion `x ↦ x⁻¹` tends to infinity at infinity. -/ @[to_additive "In a (semi)normed group, negation `x ↦ -x` tends to infinity at infinity."] theorem Filter.tendsto_inv_cobounded : Tendsto Inv.inv (cobounded E) (cobounded E) := inv_cobounded.le #align filter.tendsto_inv_cobounded Filter.tendsto_inv_cobounded #align filter.tendsto_neg_cobounded Filter.tendsto_neg_cobounded /-- **Triangle inequality** for the norm. -/ @[to_additive norm_add_le "**Triangle inequality** for the norm."] theorem norm_mul_le' (a b : E) : ‖a * b‖ ≤ ‖a‖ + ‖b‖ := by simpa [dist_eq_norm_div] using dist_triangle a 1 b⁻¹ #align norm_mul_le' norm_mul_le' #align norm_add_le norm_add_le @[to_additive] theorem norm_mul_le_of_le (h₁ : ‖a₁‖ ≤ r₁) (h₂ : ‖a₂‖ ≤ r₂) : ‖a₁ * a₂‖ ≤ r₁ + r₂ := (norm_mul_le' a₁ a₂).trans <| add_le_add h₁ h₂ #align norm_mul_le_of_le norm_mul_le_of_le #align norm_add_le_of_le norm_add_le_of_le @[to_additive norm_add₃_le] theorem norm_mul₃_le (a b c : E) : ‖a * b * c‖ ≤ ‖a‖ + ‖b‖ + ‖c‖ := norm_mul_le_of_le (norm_mul_le' _ _) le_rfl #align norm_mul₃_le norm_mul₃_le #align norm_add₃_le norm_add₃_le @[to_additive] lemma norm_div_le_norm_div_add_norm_div (a b c : E) : ‖a / c‖ ≤ ‖a / b‖ + ‖b / c‖ := by simpa only [dist_eq_norm_div] using dist_triangle a b c @[to_additive (attr := simp) norm_nonneg] theorem norm_nonneg' (a : E) : 0 ≤ ‖a‖ := by rw [← dist_one_right] exact dist_nonneg #align norm_nonneg' norm_nonneg' #align norm_nonneg norm_nonneg @[to_additive (attr := simp) abs_norm] theorem abs_norm' (z : E) : |‖z‖| = ‖z‖ := abs_of_nonneg <| norm_nonneg' _ #align abs_norm abs_norm namespace Mathlib.Meta.Positivity open Lean Meta Qq Function /-- Extension for the `positivity` tactic: multiplicative norms are nonnegative, via `norm_nonneg'`. -/ @[positivity Norm.norm _] def evalMulNorm : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(@Norm.norm $β $instDist $a) => let _inst ← synthInstanceQ q(SeminormedGroup $β) assertInstancesCommute pure (.nonnegative q(norm_nonneg' $a)) | _, _, _ => throwError "not ‖ · ‖" /-- Extension for the `positivity` tactic: additive norms are nonnegative, via `norm_nonneg`. -/ @[positivity Norm.norm _] def evalAddNorm : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(@Norm.norm $β $instDist $a) => let _inst ← synthInstanceQ q(SeminormedAddGroup $β) assertInstancesCommute pure (.nonnegative q(norm_nonneg $a)) | _, _, _ => throwError "not ‖ · ‖" end Mathlib.Meta.Positivity @[to_additive (attr := simp) norm_zero] theorem norm_one' : ‖(1 : E)‖ = 0 := by rw [← dist_one_right, dist_self] #align norm_one' norm_one' #align norm_zero norm_zero @[to_additive] theorem ne_one_of_norm_ne_zero : ‖a‖ ≠ 0 → a ≠ 1 := mt <| by rintro rfl exact norm_one' #align ne_one_of_norm_ne_zero ne_one_of_norm_ne_zero #align ne_zero_of_norm_ne_zero ne_zero_of_norm_ne_zero @[to_additive (attr := nontriviality) norm_of_subsingleton] theorem norm_of_subsingleton' [Subsingleton E] (a : E) : ‖a‖ = 0 := by rw [Subsingleton.elim a 1, norm_one'] #align norm_of_subsingleton' norm_of_subsingleton' #align norm_of_subsingleton norm_of_subsingleton @[to_additive zero_lt_one_add_norm_sq] theorem zero_lt_one_add_norm_sq' (x : E) : 0 < 1 + ‖x‖ ^ 2 := by positivity #align zero_lt_one_add_norm_sq' zero_lt_one_add_norm_sq' #align zero_lt_one_add_norm_sq zero_lt_one_add_norm_sq @[to_additive] theorem norm_div_le (a b : E) : ‖a / b‖ ≤ ‖a‖ + ‖b‖ := by simpa [dist_eq_norm_div] using dist_triangle a 1 b #align norm_div_le norm_div_le #align norm_sub_le norm_sub_le @[to_additive] theorem norm_div_le_of_le {r₁ r₂ : ℝ} (H₁ : ‖a₁‖ ≤ r₁) (H₂ : ‖a₂‖ ≤ r₂) : ‖a₁ / a₂‖ ≤ r₁ + r₂ := (norm_div_le a₁ a₂).trans <| add_le_add H₁ H₂ #align norm_div_le_of_le norm_div_le_of_le #align norm_sub_le_of_le norm_sub_le_of_le @[to_additive dist_le_norm_add_norm] theorem dist_le_norm_add_norm' (a b : E) : dist a b ≤ ‖a‖ + ‖b‖ := by rw [dist_eq_norm_div] apply norm_div_le #align dist_le_norm_add_norm' dist_le_norm_add_norm' #align dist_le_norm_add_norm dist_le_norm_add_norm @[to_additive abs_norm_sub_norm_le] theorem abs_norm_sub_norm_le' (a b : E) : |‖a‖ - ‖b‖| ≤ ‖a / b‖ := by simpa [dist_eq_norm_div] using abs_dist_sub_le a b 1 #align abs_norm_sub_norm_le' abs_norm_sub_norm_le' #align abs_norm_sub_norm_le abs_norm_sub_norm_le @[to_additive norm_sub_norm_le] theorem norm_sub_norm_le' (a b : E) : ‖a‖ - ‖b‖ ≤ ‖a / b‖ := (le_abs_self _).trans (abs_norm_sub_norm_le' a b) #align norm_sub_norm_le' norm_sub_norm_le' #align norm_sub_norm_le norm_sub_norm_le @[to_additive dist_norm_norm_le] theorem dist_norm_norm_le' (a b : E) : dist ‖a‖ ‖b‖ ≤ ‖a / b‖ := abs_norm_sub_norm_le' a b #align dist_norm_norm_le' dist_norm_norm_le' #align dist_norm_norm_le dist_norm_norm_le @[to_additive] theorem norm_le_norm_add_norm_div' (u v : E) : ‖u‖ ≤ ‖v‖ + ‖u / v‖ := by rw [add_comm] refine (norm_mul_le' _ _).trans_eq' ?_ rw [div_mul_cancel] #align norm_le_norm_add_norm_div' norm_le_norm_add_norm_div' #align norm_le_norm_add_norm_sub' norm_le_norm_add_norm_sub' @[to_additive] theorem norm_le_norm_add_norm_div (u v : E) : ‖v‖ ≤ ‖u‖ + ‖u / v‖ := by rw [norm_div_rev] exact norm_le_norm_add_norm_div' v u #align norm_le_norm_add_norm_div norm_le_norm_add_norm_div #align norm_le_norm_add_norm_sub norm_le_norm_add_norm_sub alias norm_le_insert' := norm_le_norm_add_norm_sub' #align norm_le_insert' norm_le_insert' alias norm_le_insert := norm_le_norm_add_norm_sub #align norm_le_insert norm_le_insert @[to_additive] theorem norm_le_mul_norm_add (u v : E) : ‖u‖ ≤ ‖u * v‖ + ‖v‖ := calc ‖u‖ = ‖u * v / v‖ := by rw [mul_div_cancel_right] _ ≤ ‖u * v‖ + ‖v‖ := norm_div_le _ _ #align norm_le_mul_norm_add norm_le_mul_norm_add #align norm_le_add_norm_add norm_le_add_norm_add @[to_additive ball_eq] theorem ball_eq' (y : E) (ε : ℝ) : ball y ε = { x | ‖x / y‖ < ε } := Set.ext fun a => by simp [dist_eq_norm_div] #align ball_eq' ball_eq' #align ball_eq ball_eq @[to_additive] theorem ball_one_eq (r : ℝ) : ball (1 : E) r = { x | ‖x‖ < r } := Set.ext fun a => by simp #align ball_one_eq ball_one_eq #align ball_zero_eq ball_zero_eq @[to_additive mem_ball_iff_norm] theorem mem_ball_iff_norm'' : b ∈ ball a r ↔ ‖b / a‖ < r := by rw [mem_ball, dist_eq_norm_div] #align mem_ball_iff_norm'' mem_ball_iff_norm'' #align mem_ball_iff_norm mem_ball_iff_norm @[to_additive mem_ball_iff_norm'] theorem mem_ball_iff_norm''' : b ∈ ball a r ↔ ‖a / b‖ < r := by rw [mem_ball', dist_eq_norm_div] #align mem_ball_iff_norm''' mem_ball_iff_norm''' #align mem_ball_iff_norm' mem_ball_iff_norm' @[to_additive] -- Porting note (#10618): `simp` can prove it theorem mem_ball_one_iff : a ∈ ball (1 : E) r ↔ ‖a‖ < r := by rw [mem_ball, dist_one_right] #align mem_ball_one_iff mem_ball_one_iff #align mem_ball_zero_iff mem_ball_zero_iff @[to_additive mem_closedBall_iff_norm] theorem mem_closedBall_iff_norm'' : b ∈ closedBall a r ↔ ‖b / a‖ ≤ r := by rw [mem_closedBall, dist_eq_norm_div] #align mem_closed_ball_iff_norm'' mem_closedBall_iff_norm'' #align mem_closed_ball_iff_norm mem_closedBall_iff_norm @[to_additive] -- Porting note (#10618): `simp` can prove it theorem mem_closedBall_one_iff : a ∈ closedBall (1 : E) r ↔ ‖a‖ ≤ r := by rw [mem_closedBall, dist_one_right] #align mem_closed_ball_one_iff mem_closedBall_one_iff #align mem_closed_ball_zero_iff mem_closedBall_zero_iff @[to_additive mem_closedBall_iff_norm'] theorem mem_closedBall_iff_norm''' : b ∈ closedBall a r ↔ ‖a / b‖ ≤ r := by rw [mem_closedBall', dist_eq_norm_div] #align mem_closed_ball_iff_norm''' mem_closedBall_iff_norm''' #align mem_closed_ball_iff_norm' mem_closedBall_iff_norm' @[to_additive norm_le_of_mem_closedBall] theorem norm_le_of_mem_closedBall' (h : b ∈ closedBall a r) : ‖b‖ ≤ ‖a‖ + r := (norm_le_norm_add_norm_div' _ _).trans <| add_le_add_left (by rwa [← dist_eq_norm_div]) _ #align norm_le_of_mem_closed_ball' norm_le_of_mem_closedBall' #align norm_le_of_mem_closed_ball norm_le_of_mem_closedBall @[to_additive norm_le_norm_add_const_of_dist_le] theorem norm_le_norm_add_const_of_dist_le' : dist a b ≤ r → ‖a‖ ≤ ‖b‖ + r := norm_le_of_mem_closedBall' #align norm_le_norm_add_const_of_dist_le' norm_le_norm_add_const_of_dist_le' #align norm_le_norm_add_const_of_dist_le norm_le_norm_add_const_of_dist_le @[to_additive norm_lt_of_mem_ball] theorem norm_lt_of_mem_ball' (h : b ∈ ball a r) : ‖b‖ < ‖a‖ + r := (norm_le_norm_add_norm_div' _ _).trans_lt <| add_lt_add_left (by rwa [← dist_eq_norm_div]) _ #align norm_lt_of_mem_ball' norm_lt_of_mem_ball' #align norm_lt_of_mem_ball norm_lt_of_mem_ball @[to_additive] theorem norm_div_sub_norm_div_le_norm_div (u v w : E) : ‖u / w‖ - ‖v / w‖ ≤ ‖u / v‖ := by simpa only [div_div_div_cancel_right'] using norm_sub_norm_le' (u / w) (v / w) #align norm_div_sub_norm_div_le_norm_div norm_div_sub_norm_div_le_norm_div #align norm_sub_sub_norm_sub_le_norm_sub norm_sub_sub_norm_sub_le_norm_sub @[to_additive isBounded_iff_forall_norm_le] theorem isBounded_iff_forall_norm_le' : Bornology.IsBounded s ↔ ∃ C, ∀ x ∈ s, ‖x‖ ≤ C := by simpa only [Set.subset_def, mem_closedBall_one_iff] using isBounded_iff_subset_closedBall (1 : E) #align bounded_iff_forall_norm_le' isBounded_iff_forall_norm_le' #align bounded_iff_forall_norm_le isBounded_iff_forall_norm_le alias ⟨Bornology.IsBounded.exists_norm_le', _⟩ := isBounded_iff_forall_norm_le' #align metric.bounded.exists_norm_le' Bornology.IsBounded.exists_norm_le' alias ⟨Bornology.IsBounded.exists_norm_le, _⟩ := isBounded_iff_forall_norm_le #align metric.bounded.exists_norm_le Bornology.IsBounded.exists_norm_le attribute [to_additive existing exists_norm_le] Bornology.IsBounded.exists_norm_le' @[to_additive exists_pos_norm_le] theorem Bornology.IsBounded.exists_pos_norm_le' (hs : IsBounded s) : ∃ R > 0, ∀ x ∈ s, ‖x‖ ≤ R := let ⟨R₀, hR₀⟩ := hs.exists_norm_le' ⟨max R₀ 1, by positivity, fun x hx => (hR₀ x hx).trans <| le_max_left _ _⟩ #align metric.bounded.exists_pos_norm_le' Bornology.IsBounded.exists_pos_norm_le' #align metric.bounded.exists_pos_norm_le Bornology.IsBounded.exists_pos_norm_le @[to_additive Bornology.IsBounded.exists_pos_norm_lt] theorem Bornology.IsBounded.exists_pos_norm_lt' (hs : IsBounded s) : ∃ R > 0, ∀ x ∈ s, ‖x‖ < R := let ⟨R, hR₀, hR⟩ := hs.exists_pos_norm_le' ⟨R + 1, by positivity, fun x hx ↦ (hR x hx).trans_lt (lt_add_one _)⟩ @[to_additive (attr := simp 1001) mem_sphere_iff_norm] -- Porting note: increase priority so the left-hand side doesn't reduce theorem mem_sphere_iff_norm' : b ∈ sphere a r ↔ ‖b / a‖ = r := by simp [dist_eq_norm_div] #align mem_sphere_iff_norm' mem_sphere_iff_norm' #align mem_sphere_iff_norm mem_sphere_iff_norm @[to_additive] -- `simp` can prove this theorem mem_sphere_one_iff_norm : a ∈ sphere (1 : E) r ↔ ‖a‖ = r := by simp [dist_eq_norm_div] #align mem_sphere_one_iff_norm mem_sphere_one_iff_norm #align mem_sphere_zero_iff_norm mem_sphere_zero_iff_norm @[to_additive (attr := simp) norm_eq_of_mem_sphere] theorem norm_eq_of_mem_sphere' (x : sphere (1 : E) r) : ‖(x : E)‖ = r := mem_sphere_one_iff_norm.mp x.2 #align norm_eq_of_mem_sphere' norm_eq_of_mem_sphere' #align norm_eq_of_mem_sphere norm_eq_of_mem_sphere @[to_additive] theorem ne_one_of_mem_sphere (hr : r ≠ 0) (x : sphere (1 : E) r) : (x : E) ≠ 1 := ne_one_of_norm_ne_zero <| by rwa [norm_eq_of_mem_sphere' x] #align ne_one_of_mem_sphere ne_one_of_mem_sphere #align ne_zero_of_mem_sphere ne_zero_of_mem_sphere @[to_additive ne_zero_of_mem_unit_sphere] theorem ne_one_of_mem_unit_sphere (x : sphere (1 : E) 1) : (x : E) ≠ 1 := ne_one_of_mem_sphere one_ne_zero _ #align ne_one_of_mem_unit_sphere ne_one_of_mem_unit_sphere #align ne_zero_of_mem_unit_sphere ne_zero_of_mem_unit_sphere variable (E) /-- The norm of a seminormed group as a group seminorm. -/ @[to_additive "The norm of a seminormed group as an additive group seminorm."] def normGroupSeminorm : GroupSeminorm E := ⟨norm, norm_one', norm_mul_le', norm_inv'⟩ #align norm_group_seminorm normGroupSeminorm #align norm_add_group_seminorm normAddGroupSeminorm @[to_additive (attr := simp)] theorem coe_normGroupSeminorm : ⇑(normGroupSeminorm E) = norm := rfl #align coe_norm_group_seminorm coe_normGroupSeminorm #align coe_norm_add_group_seminorm coe_normAddGroupSeminorm variable {E} @[to_additive] theorem NormedCommGroup.tendsto_nhds_one {f : α → E} {l : Filter α} : Tendsto f l (𝓝 1) ↔ ∀ ε > 0, ∀ᶠ x in l, ‖f x‖ < ε := Metric.tendsto_nhds.trans <| by simp only [dist_one_right] #align normed_comm_group.tendsto_nhds_one NormedCommGroup.tendsto_nhds_one #align normed_add_comm_group.tendsto_nhds_zero NormedAddCommGroup.tendsto_nhds_zero @[to_additive] theorem NormedCommGroup.tendsto_nhds_nhds {f : E → F} {x : E} {y : F} : Tendsto f (𝓝 x) (𝓝 y) ↔ ∀ ε > 0, ∃ δ > 0, ∀ x', ‖x' / x‖ < δ → ‖f x' / y‖ < ε := by simp_rw [Metric.tendsto_nhds_nhds, dist_eq_norm_div] #align normed_comm_group.tendsto_nhds_nhds NormedCommGroup.tendsto_nhds_nhds #align normed_add_comm_group.tendsto_nhds_nhds NormedAddCommGroup.tendsto_nhds_nhds @[to_additive] theorem NormedCommGroup.cauchySeq_iff [Nonempty α] [SemilatticeSup α] {u : α → E} : CauchySeq u ↔ ∀ ε > 0, ∃ N, ∀ m, N ≤ m → ∀ n, N ≤ n → ‖u m / u n‖ < ε := by simp [Metric.cauchySeq_iff, dist_eq_norm_div] #align normed_comm_group.cauchy_seq_iff NormedCommGroup.cauchySeq_iff #align normed_add_comm_group.cauchy_seq_iff NormedAddCommGroup.cauchySeq_iff @[to_additive] theorem NormedCommGroup.nhds_basis_norm_lt (x : E) : (𝓝 x).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { y | ‖y / x‖ < ε } := by simp_rw [← ball_eq'] exact Metric.nhds_basis_ball #align normed_comm_group.nhds_basis_norm_lt NormedCommGroup.nhds_basis_norm_lt #align normed_add_comm_group.nhds_basis_norm_lt NormedAddCommGroup.nhds_basis_norm_lt @[to_additive] theorem NormedCommGroup.nhds_one_basis_norm_lt : (𝓝 (1 : E)).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { y | ‖y‖ < ε } := by convert NormedCommGroup.nhds_basis_norm_lt (1 : E) simp #align normed_comm_group.nhds_one_basis_norm_lt NormedCommGroup.nhds_one_basis_norm_lt #align normed_add_comm_group.nhds_zero_basis_norm_lt NormedAddCommGroup.nhds_zero_basis_norm_lt @[to_additive] theorem NormedCommGroup.uniformity_basis_dist : (𝓤 E).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { p : E × E | ‖p.fst / p.snd‖ < ε } := by convert Metric.uniformity_basis_dist (α := E) using 1 simp [dist_eq_norm_div] #align normed_comm_group.uniformity_basis_dist NormedCommGroup.uniformity_basis_dist #align normed_add_comm_group.uniformity_basis_dist NormedAddCommGroup.uniformity_basis_dist open Finset variable [FunLike 𝓕 E F] /-- A homomorphism `f` of seminormed groups is Lipschitz, if there exists a constant `C` such that for all `x`, one has `‖f x‖ ≤ C * ‖x‖`. The analogous condition for a linear map of (semi)normed spaces is in `Mathlib/Analysis/NormedSpace/OperatorNorm.lean`. -/ @[to_additive "A homomorphism `f` of seminormed groups is Lipschitz, if there exists a constant `C` such that for all `x`, one has `‖f x‖ ≤ C * ‖x‖`. The analogous condition for a linear map of (semi)normed spaces is in `Mathlib/Analysis/NormedSpace/OperatorNorm.lean`."] theorem MonoidHomClass.lipschitz_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ) (h : ∀ x, ‖f x‖ ≤ C * ‖x‖) : LipschitzWith (Real.toNNReal C) f := LipschitzWith.of_dist_le' fun x y => by simpa only [dist_eq_norm_div, map_div] using h (x / y) #align monoid_hom_class.lipschitz_of_bound MonoidHomClass.lipschitz_of_bound #align add_monoid_hom_class.lipschitz_of_bound AddMonoidHomClass.lipschitz_of_bound @[to_additive] theorem lipschitzOnWith_iff_norm_div_le {f : E → F} {C : ℝ≥0} : LipschitzOnWith C f s ↔ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ‖f x / f y‖ ≤ C * ‖x / y‖ := by simp only [lipschitzOnWith_iff_dist_le_mul, dist_eq_norm_div] #align lipschitz_on_with_iff_norm_div_le lipschitzOnWith_iff_norm_div_le #align lipschitz_on_with_iff_norm_sub_le lipschitzOnWith_iff_norm_sub_le alias ⟨LipschitzOnWith.norm_div_le, _⟩ := lipschitzOnWith_iff_norm_div_le #align lipschitz_on_with.norm_div_le LipschitzOnWith.norm_div_le attribute [to_additive] LipschitzOnWith.norm_div_le @[to_additive] theorem LipschitzOnWith.norm_div_le_of_le {f : E → F} {C : ℝ≥0} (h : LipschitzOnWith C f s) (ha : a ∈ s) (hb : b ∈ s) (hr : ‖a / b‖ ≤ r) : ‖f a / f b‖ ≤ C * r := (h.norm_div_le ha hb).trans <| by gcongr #align lipschitz_on_with.norm_div_le_of_le LipschitzOnWith.norm_div_le_of_le #align lipschitz_on_with.norm_sub_le_of_le LipschitzOnWith.norm_sub_le_of_le @[to_additive] theorem lipschitzWith_iff_norm_div_le {f : E → F} {C : ℝ≥0} : LipschitzWith C f ↔ ∀ x y, ‖f x / f y‖ ≤ C * ‖x / y‖ := by simp only [lipschitzWith_iff_dist_le_mul, dist_eq_norm_div] #align lipschitz_with_iff_norm_div_le lipschitzWith_iff_norm_div_le #align lipschitz_with_iff_norm_sub_le lipschitzWith_iff_norm_sub_le alias ⟨LipschitzWith.norm_div_le, _⟩ := lipschitzWith_iff_norm_div_le #align lipschitz_with.norm_div_le LipschitzWith.norm_div_le attribute [to_additive] LipschitzWith.norm_div_le @[to_additive] theorem LipschitzWith.norm_div_le_of_le {f : E → F} {C : ℝ≥0} (h : LipschitzWith C f) (hr : ‖a / b‖ ≤ r) : ‖f a / f b‖ ≤ C * r := (h.norm_div_le _ _).trans <| by gcongr #align lipschitz_with.norm_div_le_of_le LipschitzWith.norm_div_le_of_le #align lipschitz_with.norm_sub_le_of_le LipschitzWith.norm_sub_le_of_le /-- A homomorphism `f` of seminormed groups is continuous, if there exists a constant `C` such that for all `x`, one has `‖f x‖ ≤ C * ‖x‖`. -/ @[to_additive "A homomorphism `f` of seminormed groups is continuous, if there exists a constant `C` such that for all `x`, one has `‖f x‖ ≤ C * ‖x‖`"] theorem MonoidHomClass.continuous_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ) (h : ∀ x, ‖f x‖ ≤ C * ‖x‖) : Continuous f := (MonoidHomClass.lipschitz_of_bound f C h).continuous #align monoid_hom_class.continuous_of_bound MonoidHomClass.continuous_of_bound #align add_monoid_hom_class.continuous_of_bound AddMonoidHomClass.continuous_of_bound @[to_additive] theorem MonoidHomClass.uniformContinuous_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ) (h : ∀ x, ‖f x‖ ≤ C * ‖x‖) : UniformContinuous f := (MonoidHomClass.lipschitz_of_bound f C h).uniformContinuous #align monoid_hom_class.uniform_continuous_of_bound MonoidHomClass.uniformContinuous_of_bound #align add_monoid_hom_class.uniform_continuous_of_bound AddMonoidHomClass.uniformContinuous_of_bound @[to_additive IsCompact.exists_bound_of_continuousOn] theorem IsCompact.exists_bound_of_continuousOn' [TopologicalSpace α] {s : Set α} (hs : IsCompact s) {f : α → E} (hf : ContinuousOn f s) : ∃ C, ∀ x ∈ s, ‖f x‖ ≤ C := (isBounded_iff_forall_norm_le'.1 (hs.image_of_continuousOn hf).isBounded).imp fun _C hC _x hx => hC _ <| Set.mem_image_of_mem _ hx #align is_compact.exists_bound_of_continuous_on' IsCompact.exists_bound_of_continuousOn' #align is_compact.exists_bound_of_continuous_on IsCompact.exists_bound_of_continuousOn @[to_additive]
Mathlib/Analysis/Normed/Group/Basic.lean
946
948
theorem HasCompactMulSupport.exists_bound_of_continuous [TopologicalSpace α] {f : α → E} (hf : HasCompactMulSupport f) (h'f : Continuous f) : ∃ C, ∀ x, ‖f x‖ ≤ C := by
simpa using (hf.isCompact_range h'f).isBounded.exists_norm_le'
/- Copyright (c) 2019 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.Finsupp.Encodable import Mathlib.LinearAlgebra.Pi import Mathlib.LinearAlgebra.Span import Mathlib.Data.Set.Countable #align_import linear_algebra.finsupp from "leanprover-community/mathlib"@"9d684a893c52e1d6692a504a118bfccbae04feeb" /-! # Properties of the module `α →₀ M` Given an `R`-module `M`, the `R`-module structure on `α →₀ M` is defined in `Data.Finsupp.Basic`. In this file we define `Finsupp.supported s` to be the set `{f : α →₀ M | f.support ⊆ s}` interpreted as a submodule of `α →₀ M`. We also define `LinearMap` versions of various maps: * `Finsupp.lsingle a : M →ₗ[R] ι →₀ M`: `Finsupp.single a` as a linear map; * `Finsupp.lapply a : (ι →₀ M) →ₗ[R] M`: the map `fun f ↦ f a` as a linear map; * `Finsupp.lsubtypeDomain (s : Set α) : (α →₀ M) →ₗ[R] (s →₀ M)`: restriction to a subtype as a linear map; * `Finsupp.restrictDom`: `Finsupp.filter` as a linear map to `Finsupp.supported s`; * `Finsupp.lsum`: `Finsupp.sum` or `Finsupp.liftAddHom` as a `LinearMap`; * `Finsupp.total α M R (v : ι → M)`: sends `l : ι → R` to the linear combination of `v i` with coefficients `l i`; * `Finsupp.totalOn`: a restricted version of `Finsupp.total` with domain `Finsupp.supported R R s` and codomain `Submodule.span R (v '' s)`; * `Finsupp.supportedEquivFinsupp`: a linear equivalence between the functions `α →₀ M` supported on `s` and the functions `s →₀ M`; * `Finsupp.lmapDomain`: a linear map version of `Finsupp.mapDomain`; * `Finsupp.domLCongr`: a `LinearEquiv` version of `Finsupp.domCongr`; * `Finsupp.congr`: if the sets `s` and `t` are equivalent, then `supported M R s` is equivalent to `supported M R t`; * `Finsupp.lcongr`: a `LinearEquiv`alence between `α →₀ M` and `β →₀ N` constructed using `e : α ≃ β` and `e' : M ≃ₗ[R] N`. ## Tags function with finite support, module, linear algebra -/ noncomputable section open Set LinearMap Submodule namespace Finsupp section SMul variable {α : Type*} {β : Type*} {R : Type*} {M : Type*} {M₂ : Type*} theorem smul_sum [Zero β] [AddCommMonoid M] [DistribSMul R M] {v : α →₀ β} {c : R} {h : α → β → M} : c • v.sum h = v.sum fun a b => c • h a b := Finset.smul_sum #align finsupp.smul_sum Finsupp.smul_sum @[simp] theorem sum_smul_index_linearMap' [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid M₂] [Module R M₂] {v : α →₀ M} {c : R} {h : α → M →ₗ[R] M₂} : ((c • v).sum fun a => h a) = c • v.sum fun a => h a := by rw [Finsupp.sum_smul_index', Finsupp.smul_sum] · simp only [map_smul] · intro i exact (h i).map_zero #align finsupp.sum_smul_index_linear_map' Finsupp.sum_smul_index_linearMap' end SMul section LinearEquivFunOnFinite variable (R : Type*) {S : Type*} (M : Type*) (α : Type*) variable [Finite α] [AddCommMonoid M] [Semiring R] [Module R M] /-- Given `Finite α`, `linearEquivFunOnFinite R` is the natural `R`-linear equivalence between `α →₀ β` and `α → β`. -/ @[simps apply] noncomputable def linearEquivFunOnFinite : (α →₀ M) ≃ₗ[R] α → M := { equivFunOnFinite with toFun := (⇑) map_add' := fun _ _ => rfl map_smul' := fun _ _ => rfl } #align finsupp.linear_equiv_fun_on_finite Finsupp.linearEquivFunOnFinite @[simp] theorem linearEquivFunOnFinite_single [DecidableEq α] (x : α) (m : M) : (linearEquivFunOnFinite R M α) (single x m) = Pi.single x m := equivFunOnFinite_single x m #align finsupp.linear_equiv_fun_on_finite_single Finsupp.linearEquivFunOnFinite_single @[simp] theorem linearEquivFunOnFinite_symm_single [DecidableEq α] (x : α) (m : M) : (linearEquivFunOnFinite R M α).symm (Pi.single x m) = single x m := equivFunOnFinite_symm_single x m #align finsupp.linear_equiv_fun_on_finite_symm_single Finsupp.linearEquivFunOnFinite_symm_single @[simp] theorem linearEquivFunOnFinite_symm_coe (f : α →₀ M) : (linearEquivFunOnFinite R M α).symm f = f := (linearEquivFunOnFinite R M α).symm_apply_apply f #align finsupp.linear_equiv_fun_on_finite_symm_coe Finsupp.linearEquivFunOnFinite_symm_coe end LinearEquivFunOnFinite section LinearEquiv.finsuppUnique variable (R : Type*) {S : Type*} (M : Type*) variable [AddCommMonoid M] [Semiring R] [Module R M] variable (α : Type*) [Unique α] /-- If `α` has a unique term, then the type of finitely supported functions `α →₀ M` is `R`-linearly equivalent to `M`. -/ noncomputable def LinearEquiv.finsuppUnique : (α →₀ M) ≃ₗ[R] M := { Finsupp.equivFunOnFinite.trans (Equiv.funUnique α M) with map_add' := fun _ _ => rfl map_smul' := fun _ _ => rfl } #align finsupp.linear_equiv.finsupp_unique Finsupp.LinearEquiv.finsuppUnique variable {R M} @[simp] theorem LinearEquiv.finsuppUnique_apply (f : α →₀ M) : LinearEquiv.finsuppUnique R M α f = f default := rfl #align finsupp.linear_equiv.finsupp_unique_apply Finsupp.LinearEquiv.finsuppUnique_apply variable {α} @[simp]
Mathlib/LinearAlgebra/Finsupp.lean
133
136
theorem LinearEquiv.finsuppUnique_symm_apply [Unique α] (m : M) : (LinearEquiv.finsuppUnique R M α).symm m = Finsupp.single default m := by
ext; simp [LinearEquiv.finsuppUnique, Equiv.funUnique, single, Pi.single, equivFunOnFinite, Function.update]
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Patrick Massot, Eric Wieser, Yaël Dillies -/ import Mathlib.Analysis.NormedSpace.Basic import Mathlib.Topology.Algebra.Module.Basic #align_import analysis.normed_space.basic from "leanprover-community/mathlib"@"bc91ed7093bf098d253401e69df601fc33dde156" /-! # Basic facts about real (semi)normed spaces In this file we prove some theorems about (semi)normed spaces over real numberes. ## Main results - `closure_ball`, `frontier_ball`, `interior_closedBall`, `frontier_closedBall`, `interior_sphere`, `frontier_sphere`: formulas for the closure/interior/frontier of nontrivial balls and spheres in a real seminormed space; - `interior_closedBall'`, `frontier_closedBall'`, `interior_sphere'`, `frontier_sphere'`: similar lemmas assuming that the ambient space is separated and nontrivial instead of `r ≠ 0`. -/ open Metric Set Function Filter open scoped NNReal Topology /-- If `E` is a nontrivial topological module over `ℝ`, then `E` has no isolated points. This is a particular case of `Module.punctured_nhds_neBot`. -/ instance Real.punctured_nhds_module_neBot {E : Type*} [AddCommGroup E] [TopologicalSpace E] [ContinuousAdd E] [Nontrivial E] [Module ℝ E] [ContinuousSMul ℝ E] (x : E) : NeBot (𝓝[≠] x) := Module.punctured_nhds_neBot ℝ E x #align real.punctured_nhds_module_ne_bot Real.punctured_nhds_module_neBot section Seminormed variable {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ℝ E] theorem inv_norm_smul_mem_closed_unit_ball (x : E) : ‖x‖⁻¹ • x ∈ closedBall (0 : E) 1 := by simp only [mem_closedBall_zero_iff, norm_smul, norm_inv, norm_norm, ← div_eq_inv_mul, div_self_le_one] #align inv_norm_smul_mem_closed_unit_ball inv_norm_smul_mem_closed_unit_ball theorem norm_smul_of_nonneg {t : ℝ} (ht : 0 ≤ t) (x : E) : ‖t • x‖ = t * ‖x‖ := by rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg ht] #align norm_smul_of_nonneg norm_smul_of_nonneg
Mathlib/Analysis/NormedSpace/Real.lean
50
59
theorem dist_smul_add_one_sub_smul_le {r : ℝ} {x y : E} (h : r ∈ Icc 0 1) : dist (r • x + (1 - r) • y) x ≤ dist y x := calc dist (r • x + (1 - r) • y) x = ‖1 - r‖ * ‖x - y‖ := by
simp_rw [dist_eq_norm', ← norm_smul, sub_smul, one_smul, smul_sub, ← sub_sub, ← sub_add, sub_right_comm] _ = (1 - r) * dist y x := by rw [Real.norm_eq_abs, abs_eq_self.mpr (sub_nonneg.mpr h.2), dist_eq_norm'] _ ≤ (1 - 0) * dist y x := by gcongr; exact h.1 _ = dist y x := by rw [sub_zero, one_mul]
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Logic.Equiv.PartialEquiv import Mathlib.Topology.Sets.Opens #align_import topology.local_homeomorph from "leanprover-community/mathlib"@"431589bce478b2229eba14b14a283250428217db" /-! # Partial homeomorphisms This file defines homeomorphisms between open subsets of topological spaces. An element `e` of `PartialHomeomorph X Y` is an extension of `PartialEquiv X Y`, i.e., it is a pair of functions `e.toFun` and `e.invFun`, inverse of each other on the sets `e.source` and `e.target`. Additionally, we require that these sets are open, and that the functions are continuous on them. Equivalently, they are homeomorphisms there. As in equivs, we register a coercion to functions, and we use `e x` and `e.symm x` throughout instead of `e.toFun x` and `e.invFun x`. ## Main definitions * `Homeomorph.toPartialHomeomorph`: associating a partial homeomorphism to a homeomorphism, with `source = target = Set.univ`; * `PartialHomeomorph.symm`: the inverse of a partial homeomorphism * `PartialHomeomorph.trans`: the composition of two partial homeomorphisms * `PartialHomeomorph.refl`: the identity partial homeomorphism * `PartialHomeomorph.ofSet`: the identity on a set `s` * `PartialHomeomorph.EqOnSource`: equivalence relation describing the "right" notion of equality for partial homeomorphisms ## Implementation notes Most statements are copied from their `PartialEquiv` versions, although some care is required especially when restricting to subsets, as these should be open subsets. For design notes, see `PartialEquiv.lean`. ### Local coding conventions If a lemma deals with the intersection of a set with either source or target of a `PartialEquiv`, then it should use `e.source ∩ s` or `e.target ∩ t`, not `s ∩ e.source` or `t ∩ e.target`. -/ open Function Set Filter Topology variable {X X' : Type*} {Y Y' : Type*} {Z Z' : Type*} [TopologicalSpace X] [TopologicalSpace X'] [TopologicalSpace Y] [TopologicalSpace Y'] [TopologicalSpace Z] [TopologicalSpace Z'] /-- Partial homeomorphisms, defined on open subsets of the space -/ -- Porting note(#5171): this linter isn't ported yet. @[nolint has_nonempty_instance] structure PartialHomeomorph (X : Type*) (Y : Type*) [TopologicalSpace X] [TopologicalSpace Y] extends PartialEquiv X Y where open_source : IsOpen source open_target : IsOpen target continuousOn_toFun : ContinuousOn toFun source continuousOn_invFun : ContinuousOn invFun target #align local_homeomorph PartialHomeomorph namespace PartialHomeomorph variable (e : PartialHomeomorph X Y) /-! Basic properties; inverse (symm instance) -/ section Basic /-- Coercion of a partial homeomorphisms to a function. We don't use `e.toFun` because it is actually `e.toPartialEquiv.toFun`, so `simp` will apply lemmas about `toPartialEquiv`. While we may want to switch to this behavior later, doing it mid-port will break a lot of proofs. -/ @[coe] def toFun' : X → Y := e.toFun /-- Coercion of a `PartialHomeomorph` to function. Note that a `PartialHomeomorph` is not `DFunLike`. -/ instance : CoeFun (PartialHomeomorph X Y) fun _ => X → Y := ⟨fun e => e.toFun'⟩ /-- The inverse of a partial homeomorphism -/ @[symm] protected def symm : PartialHomeomorph Y X where toPartialEquiv := e.toPartialEquiv.symm open_source := e.open_target open_target := e.open_source continuousOn_toFun := e.continuousOn_invFun continuousOn_invFun := e.continuousOn_toFun #align local_homeomorph.symm PartialHomeomorph.symm /-- See Note [custom simps projection]. We need to specify this projection explicitly in this case, because it is a composition of multiple projections. -/ def Simps.apply (e : PartialHomeomorph X Y) : X → Y := e #align local_homeomorph.simps.apply PartialHomeomorph.Simps.apply /-- See Note [custom simps projection] -/ def Simps.symm_apply (e : PartialHomeomorph X Y) : Y → X := e.symm #align local_homeomorph.simps.symm_apply PartialHomeomorph.Simps.symm_apply initialize_simps_projections PartialHomeomorph (toFun → apply, invFun → symm_apply) protected theorem continuousOn : ContinuousOn e e.source := e.continuousOn_toFun #align local_homeomorph.continuous_on PartialHomeomorph.continuousOn theorem continuousOn_symm : ContinuousOn e.symm e.target := e.continuousOn_invFun #align local_homeomorph.continuous_on_symm PartialHomeomorph.continuousOn_symm @[simp, mfld_simps] theorem mk_coe (e : PartialEquiv X Y) (a b c d) : (PartialHomeomorph.mk e a b c d : X → Y) = e := rfl #align local_homeomorph.mk_coe PartialHomeomorph.mk_coe @[simp, mfld_simps] theorem mk_coe_symm (e : PartialEquiv X Y) (a b c d) : ((PartialHomeomorph.mk e a b c d).symm : Y → X) = e.symm := rfl #align local_homeomorph.mk_coe_symm PartialHomeomorph.mk_coe_symm theorem toPartialEquiv_injective : Injective (toPartialEquiv : PartialHomeomorph X Y → PartialEquiv X Y) | ⟨_, _, _, _, _⟩, ⟨_, _, _, _, _⟩, rfl => rfl #align local_homeomorph.to_local_equiv_injective PartialHomeomorph.toPartialEquiv_injective /- Register a few simp lemmas to make sure that `simp` puts the application of a local homeomorphism in its normal form, i.e., in terms of its coercion to a function. -/ @[simp, mfld_simps] theorem toFun_eq_coe (e : PartialHomeomorph X Y) : e.toFun = e := rfl #align local_homeomorph.to_fun_eq_coe PartialHomeomorph.toFun_eq_coe @[simp, mfld_simps] theorem invFun_eq_coe (e : PartialHomeomorph X Y) : e.invFun = e.symm := rfl #align local_homeomorph.inv_fun_eq_coe PartialHomeomorph.invFun_eq_coe @[simp, mfld_simps] theorem coe_coe : (e.toPartialEquiv : X → Y) = e := rfl #align local_homeomorph.coe_coe PartialHomeomorph.coe_coe @[simp, mfld_simps] theorem coe_coe_symm : (e.toPartialEquiv.symm : Y → X) = e.symm := rfl #align local_homeomorph.coe_coe_symm PartialHomeomorph.coe_coe_symm @[simp, mfld_simps] theorem map_source {x : X} (h : x ∈ e.source) : e x ∈ e.target := e.map_source' h #align local_homeomorph.map_source PartialHomeomorph.map_source /-- Variant of `map_source`, stated for images of subsets of `source`. -/ lemma map_source'' : e '' e.source ⊆ e.target := fun _ ⟨_, hx, hex⟩ ↦ mem_of_eq_of_mem (id hex.symm) (e.map_source' hx) @[simp, mfld_simps] theorem map_target {x : Y} (h : x ∈ e.target) : e.symm x ∈ e.source := e.map_target' h #align local_homeomorph.map_target PartialHomeomorph.map_target @[simp, mfld_simps] theorem left_inv {x : X} (h : x ∈ e.source) : e.symm (e x) = x := e.left_inv' h #align local_homeomorph.left_inv PartialHomeomorph.left_inv @[simp, mfld_simps] theorem right_inv {x : Y} (h : x ∈ e.target) : e (e.symm x) = x := e.right_inv' h #align local_homeomorph.right_inv PartialHomeomorph.right_inv theorem eq_symm_apply {x : X} {y : Y} (hx : x ∈ e.source) (hy : y ∈ e.target) : x = e.symm y ↔ e x = y := e.toPartialEquiv.eq_symm_apply hx hy #align local_homeomorph.eq_symm_apply PartialHomeomorph.eq_symm_apply protected theorem mapsTo : MapsTo e e.source e.target := fun _ => e.map_source #align local_homeomorph.maps_to PartialHomeomorph.mapsTo protected theorem symm_mapsTo : MapsTo e.symm e.target e.source := e.symm.mapsTo #align local_homeomorph.symm_maps_to PartialHomeomorph.symm_mapsTo protected theorem leftInvOn : LeftInvOn e.symm e e.source := fun _ => e.left_inv #align local_homeomorph.left_inv_on PartialHomeomorph.leftInvOn protected theorem rightInvOn : RightInvOn e.symm e e.target := fun _ => e.right_inv #align local_homeomorph.right_inv_on PartialHomeomorph.rightInvOn protected theorem invOn : InvOn e.symm e e.source e.target := ⟨e.leftInvOn, e.rightInvOn⟩ #align local_homeomorph.inv_on PartialHomeomorph.invOn protected theorem injOn : InjOn e e.source := e.leftInvOn.injOn #align local_homeomorph.inj_on PartialHomeomorph.injOn protected theorem bijOn : BijOn e e.source e.target := e.invOn.bijOn e.mapsTo e.symm_mapsTo #align local_homeomorph.bij_on PartialHomeomorph.bijOn protected theorem surjOn : SurjOn e e.source e.target := e.bijOn.surjOn #align local_homeomorph.surj_on PartialHomeomorph.surjOn end Basic /-- Interpret a `Homeomorph` as a `PartialHomeomorph` by restricting it to an open set `s` in the domain and to `t` in the codomain. -/ @[simps! (config := .asFn) apply symm_apply toPartialEquiv, simps! (config := .lemmasOnly) source target] def _root_.Homeomorph.toPartialHomeomorphOfImageEq (e : X ≃ₜ Y) (s : Set X) (hs : IsOpen s) (t : Set Y) (h : e '' s = t) : PartialHomeomorph X Y where toPartialEquiv := e.toPartialEquivOfImageEq s t h open_source := hs open_target := by simpa [← h] continuousOn_toFun := e.continuous.continuousOn continuousOn_invFun := e.symm.continuous.continuousOn /-- A homeomorphism induces a partial homeomorphism on the whole space -/ @[simps! (config := mfld_cfg)] def _root_.Homeomorph.toPartialHomeomorph (e : X ≃ₜ Y) : PartialHomeomorph X Y := e.toPartialHomeomorphOfImageEq univ isOpen_univ univ <| by rw [image_univ, e.surjective.range_eq] #align homeomorph.to_local_homeomorph Homeomorph.toPartialHomeomorph /-- Replace `toPartialEquiv` field to provide better definitional equalities. -/ def replaceEquiv (e : PartialHomeomorph X Y) (e' : PartialEquiv X Y) (h : e.toPartialEquiv = e') : PartialHomeomorph X Y where toPartialEquiv := e' open_source := h ▸ e.open_source open_target := h ▸ e.open_target continuousOn_toFun := h ▸ e.continuousOn_toFun continuousOn_invFun := h ▸ e.continuousOn_invFun #align local_homeomorph.replace_equiv PartialHomeomorph.replaceEquiv theorem replaceEquiv_eq_self (e' : PartialEquiv X Y) (h : e.toPartialEquiv = e') : e.replaceEquiv e' h = e := by cases e subst e' rfl #align local_homeomorph.replace_equiv_eq_self PartialHomeomorph.replaceEquiv_eq_self theorem source_preimage_target : e.source ⊆ e ⁻¹' e.target := e.mapsTo #align local_homeomorph.source_preimage_target PartialHomeomorph.source_preimage_target @[deprecated toPartialEquiv_injective (since := "2023-02-18")] theorem eq_of_partialEquiv_eq {e e' : PartialHomeomorph X Y} (h : e.toPartialEquiv = e'.toPartialEquiv) : e = e' := toPartialEquiv_injective h #align local_homeomorph.eq_of_local_equiv_eq PartialHomeomorph.eq_of_partialEquiv_eq theorem eventually_left_inverse {x} (hx : x ∈ e.source) : ∀ᶠ y in 𝓝 x, e.symm (e y) = y := (e.open_source.eventually_mem hx).mono e.left_inv' #align local_homeomorph.eventually_left_inverse PartialHomeomorph.eventually_left_inverse theorem eventually_left_inverse' {x} (hx : x ∈ e.target) : ∀ᶠ y in 𝓝 (e.symm x), e.symm (e y) = y := e.eventually_left_inverse (e.map_target hx) #align local_homeomorph.eventually_left_inverse' PartialHomeomorph.eventually_left_inverse' theorem eventually_right_inverse {x} (hx : x ∈ e.target) : ∀ᶠ y in 𝓝 x, e (e.symm y) = y := (e.open_target.eventually_mem hx).mono e.right_inv' #align local_homeomorph.eventually_right_inverse PartialHomeomorph.eventually_right_inverse theorem eventually_right_inverse' {x} (hx : x ∈ e.source) : ∀ᶠ y in 𝓝 (e x), e (e.symm y) = y := e.eventually_right_inverse (e.map_source hx) #align local_homeomorph.eventually_right_inverse' PartialHomeomorph.eventually_right_inverse' theorem eventually_ne_nhdsWithin {x} (hx : x ∈ e.source) : ∀ᶠ x' in 𝓝[≠] x, e x' ≠ e x := eventually_nhdsWithin_iff.2 <| (e.eventually_left_inverse hx).mono fun x' hx' => mt fun h => by rw [mem_singleton_iff, ← e.left_inv hx, ← h, hx'] #align local_homeomorph.eventually_ne_nhds_within PartialHomeomorph.eventually_ne_nhdsWithin theorem nhdsWithin_source_inter {x} (hx : x ∈ e.source) (s : Set X) : 𝓝[e.source ∩ s] x = 𝓝[s] x := nhdsWithin_inter_of_mem (mem_nhdsWithin_of_mem_nhds <| IsOpen.mem_nhds e.open_source hx) #align local_homeomorph.nhds_within_source_inter PartialHomeomorph.nhdsWithin_source_inter theorem nhdsWithin_target_inter {x} (hx : x ∈ e.target) (s : Set Y) : 𝓝[e.target ∩ s] x = 𝓝[s] x := e.symm.nhdsWithin_source_inter hx s #align local_homeomorph.nhds_within_target_inter PartialHomeomorph.nhdsWithin_target_inter theorem image_eq_target_inter_inv_preimage {s : Set X} (h : s ⊆ e.source) : e '' s = e.target ∩ e.symm ⁻¹' s := e.toPartialEquiv.image_eq_target_inter_inv_preimage h #align local_homeomorph.image_eq_target_inter_inv_preimage PartialHomeomorph.image_eq_target_inter_inv_preimage theorem image_source_inter_eq' (s : Set X) : e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' s := e.toPartialEquiv.image_source_inter_eq' s #align local_homeomorph.image_source_inter_eq' PartialHomeomorph.image_source_inter_eq' theorem image_source_inter_eq (s : Set X) : e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' (e.source ∩ s) := e.toPartialEquiv.image_source_inter_eq s #align local_homeomorph.image_source_inter_eq PartialHomeomorph.image_source_inter_eq theorem symm_image_eq_source_inter_preimage {s : Set Y} (h : s ⊆ e.target) : e.symm '' s = e.source ∩ e ⁻¹' s := e.symm.image_eq_target_inter_inv_preimage h #align local_homeomorph.symm_image_eq_source_inter_preimage PartialHomeomorph.symm_image_eq_source_inter_preimage theorem symm_image_target_inter_eq (s : Set Y) : e.symm '' (e.target ∩ s) = e.source ∩ e ⁻¹' (e.target ∩ s) := e.symm.image_source_inter_eq _ #align local_homeomorph.symm_image_target_inter_eq PartialHomeomorph.symm_image_target_inter_eq theorem source_inter_preimage_inv_preimage (s : Set X) : e.source ∩ e ⁻¹' (e.symm ⁻¹' s) = e.source ∩ s := e.toPartialEquiv.source_inter_preimage_inv_preimage s #align local_homeomorph.source_inter_preimage_inv_preimage PartialHomeomorph.source_inter_preimage_inv_preimage theorem target_inter_inv_preimage_preimage (s : Set Y) : e.target ∩ e.symm ⁻¹' (e ⁻¹' s) = e.target ∩ s := e.symm.source_inter_preimage_inv_preimage _ #align local_homeomorph.target_inter_inv_preimage_preimage PartialHomeomorph.target_inter_inv_preimage_preimage theorem source_inter_preimage_target_inter (s : Set Y) : e.source ∩ e ⁻¹' (e.target ∩ s) = e.source ∩ e ⁻¹' s := e.toPartialEquiv.source_inter_preimage_target_inter s #align local_homeomorph.source_inter_preimage_target_inter PartialHomeomorph.source_inter_preimage_target_inter theorem image_source_eq_target : e '' e.source = e.target := e.toPartialEquiv.image_source_eq_target #align local_homeomorph.image_source_eq_target PartialHomeomorph.image_source_eq_target theorem symm_image_target_eq_source : e.symm '' e.target = e.source := e.symm.image_source_eq_target #align local_homeomorph.symm_image_target_eq_source PartialHomeomorph.symm_image_target_eq_source /-- Two partial homeomorphisms are equal when they have equal `toFun`, `invFun` and `source`. It is not sufficient to have equal `toFun` and `source`, as this only determines `invFun` on the target. This would only be true for a weaker notion of equality, arguably the right one, called `EqOnSource`. -/ @[ext] protected theorem ext (e' : PartialHomeomorph X Y) (h : ∀ x, e x = e' x) (hinv : ∀ x, e.symm x = e'.symm x) (hs : e.source = e'.source) : e = e' := toPartialEquiv_injective (PartialEquiv.ext h hinv hs) #align local_homeomorph.ext PartialHomeomorph.ext protected theorem ext_iff {e e' : PartialHomeomorph X Y} : e = e' ↔ (∀ x, e x = e' x) ∧ (∀ x, e.symm x = e'.symm x) ∧ e.source = e'.source := ⟨by rintro rfl exact ⟨fun x => rfl, fun x => rfl, rfl⟩, fun h => e.ext e' h.1 h.2.1 h.2.2⟩ #align local_homeomorph.ext_iff PartialHomeomorph.ext_iff @[simp, mfld_simps] theorem symm_toPartialEquiv : e.symm.toPartialEquiv = e.toPartialEquiv.symm := rfl #align local_homeomorph.symm_to_local_equiv PartialHomeomorph.symm_toPartialEquiv -- The following lemmas are already simp via `PartialEquiv` theorem symm_source : e.symm.source = e.target := rfl #align local_homeomorph.symm_source PartialHomeomorph.symm_source theorem symm_target : e.symm.target = e.source := rfl #align local_homeomorph.symm_target PartialHomeomorph.symm_target @[simp, mfld_simps] theorem symm_symm : e.symm.symm = e := rfl #align local_homeomorph.symm_symm PartialHomeomorph.symm_symm theorem symm_bijective : Function.Bijective (PartialHomeomorph.symm : PartialHomeomorph X Y → PartialHomeomorph Y X) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ /-- A partial homeomorphism is continuous at any point of its source -/ protected theorem continuousAt {x : X} (h : x ∈ e.source) : ContinuousAt e x := (e.continuousOn x h).continuousAt (e.open_source.mem_nhds h) #align local_homeomorph.continuous_at PartialHomeomorph.continuousAt /-- A partial homeomorphism inverse is continuous at any point of its target -/ theorem continuousAt_symm {x : Y} (h : x ∈ e.target) : ContinuousAt e.symm x := e.symm.continuousAt h #align local_homeomorph.continuous_at_symm PartialHomeomorph.continuousAt_symm
Mathlib/Topology/PartialHomeomorph.lean
381
382
theorem tendsto_symm {x} (hx : x ∈ e.source) : Tendsto e.symm (𝓝 (e x)) (𝓝 x) := by
simpa only [ContinuousAt, e.left_inv hx] using e.continuousAt_symm (e.map_source hx)
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis -/ import Mathlib.RingTheory.Valuation.Basic import Mathlib.NumberTheory.Padics.PadicNorm import Mathlib.Analysis.Normed.Field.Basic #align_import number_theory.padics.padic_numbers from "leanprover-community/mathlib"@"b9b2114f7711fec1c1e055d507f082f8ceb2c3b7" /-! # p-adic numbers This file defines the `p`-adic numbers (rationals) `ℚ_[p]` as the completion of `ℚ` with respect to the `p`-adic norm. We show that the `p`-adic norm on `ℚ` extends to `ℚ_[p]`, that `ℚ` is embedded in `ℚ_[p]`, and that `ℚ_[p]` is Cauchy complete. ## Important definitions * `Padic` : the type of `p`-adic numbers * `padicNormE` : the rational valued `p`-adic norm on `ℚ_[p]` * `Padic.addValuation` : the additive `p`-adic valuation on `ℚ_[p]`, with values in `WithTop ℤ` ## Notation We introduce the notation `ℚ_[p]` for the `p`-adic numbers. ## Implementation notes Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically by taking `[Fact p.Prime]` as a type class argument. We use the same concrete Cauchy sequence construction that is used to construct `ℝ`. `ℚ_[p]` inherits a field structure from this construction. The extension of the norm on `ℚ` to `ℚ_[p]` is *not* analogous to extending the absolute value to `ℝ` and hence the proof that `ℚ_[p]` is complete is different from the proof that ℝ is complete. A small special-purpose simplification tactic, `padic_index_simp`, is used to manipulate sequence indices in the proof that the norm extends. `padicNormE` is the rational-valued `p`-adic norm on `ℚ_[p]`. To instantiate `ℚ_[p]` as a normed field, we must cast this into an `ℝ`-valued norm. The `ℝ`-valued norm, using notation `‖ ‖` from normed spaces, is the canonical representation of this norm. `simp` prefers `padicNorm` to `padicNormE` when possible. Since `padicNormE` and `‖ ‖` have different types, `simp` does not rewrite one to the other. Coercions from `ℚ` to `ℚ_[p]` are set up to work with the `norm_cast` tactic. ## References * [F. Q. Gouvêa, *p-adic numbers*][gouvea1997] * [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019] * <https://en.wikipedia.org/wiki/P-adic_number> ## Tags p-adic, p adic, padic, norm, valuation, cauchy, completion, p-adic completion -/ noncomputable section open scoped Classical open Nat multiplicity padicNorm CauSeq CauSeq.Completion Metric /-- The type of Cauchy sequences of rationals with respect to the `p`-adic norm. -/ abbrev PadicSeq (p : ℕ) := CauSeq _ (padicNorm p) #align padic_seq PadicSeq namespace PadicSeq section variable {p : ℕ} [Fact p.Prime] /-- The `p`-adic norm of the entries of a nonzero Cauchy sequence of rationals is eventually constant. -/ theorem stationary {f : CauSeq ℚ (padicNorm p)} (hf : ¬f ≈ 0) : ∃ N, ∀ m n, N ≤ m → N ≤ n → padicNorm p (f n) = padicNorm p (f m) := have : ∃ ε > 0, ∃ N1, ∀ j ≥ N1, ε ≤ padicNorm p (f j) := CauSeq.abv_pos_of_not_limZero <| not_limZero_of_not_congr_zero hf let ⟨ε, hε, N1, hN1⟩ := this let ⟨N2, hN2⟩ := CauSeq.cauchy₂ f hε ⟨max N1 N2, fun n m hn hm ↦ by have : padicNorm p (f n - f m) < ε := hN2 _ (max_le_iff.1 hn).2 _ (max_le_iff.1 hm).2 have : padicNorm p (f n - f m) < padicNorm p (f n) := lt_of_lt_of_le this <| hN1 _ (max_le_iff.1 hn).1 have : padicNorm p (f n - f m) < max (padicNorm p (f n)) (padicNorm p (f m)) := lt_max_iff.2 (Or.inl this) by_contra hne rw [← padicNorm.neg (f m)] at hne have hnam := add_eq_max_of_ne hne rw [padicNorm.neg, max_comm] at hnam rw [← hnam, sub_eq_add_neg, add_comm] at this apply _root_.lt_irrefl _ this⟩ #align padic_seq.stationary PadicSeq.stationary /-- For all `n ≥ stationaryPoint f hf`, the `p`-adic norm of `f n` is the same. -/ def stationaryPoint {f : PadicSeq p} (hf : ¬f ≈ 0) : ℕ := Classical.choose <| stationary hf #align padic_seq.stationary_point PadicSeq.stationaryPoint theorem stationaryPoint_spec {f : PadicSeq p} (hf : ¬f ≈ 0) : ∀ {m n}, stationaryPoint hf ≤ m → stationaryPoint hf ≤ n → padicNorm p (f n) = padicNorm p (f m) := @(Classical.choose_spec <| stationary hf) #align padic_seq.stationary_point_spec PadicSeq.stationaryPoint_spec /-- Since the norm of the entries of a Cauchy sequence is eventually stationary, we can lift the norm to sequences. -/ def norm (f : PadicSeq p) : ℚ := if hf : f ≈ 0 then 0 else padicNorm p (f (stationaryPoint hf)) #align padic_seq.norm PadicSeq.norm theorem norm_zero_iff (f : PadicSeq p) : f.norm = 0 ↔ f ≈ 0 := by constructor · intro h by_contra hf unfold norm at h split_ifs at h · contradiction apply hf intro ε hε exists stationaryPoint hf intro j hj have heq := stationaryPoint_spec hf le_rfl hj simpa [h, heq] · intro h simp [norm, h] #align padic_seq.norm_zero_iff PadicSeq.norm_zero_iff end section Embedding open CauSeq variable {p : ℕ} [Fact p.Prime] theorem equiv_zero_of_val_eq_of_equiv_zero {f g : PadicSeq p} (h : ∀ k, padicNorm p (f k) = padicNorm p (g k)) (hf : f ≈ 0) : g ≈ 0 := fun ε hε ↦ let ⟨i, hi⟩ := hf _ hε ⟨i, fun j hj ↦ by simpa [h] using hi _ hj⟩ #align padic_seq.equiv_zero_of_val_eq_of_equiv_zero PadicSeq.equiv_zero_of_val_eq_of_equiv_zero theorem norm_nonzero_of_not_equiv_zero {f : PadicSeq p} (hf : ¬f ≈ 0) : f.norm ≠ 0 := hf ∘ f.norm_zero_iff.1 #align padic_seq.norm_nonzero_of_not_equiv_zero PadicSeq.norm_nonzero_of_not_equiv_zero theorem norm_eq_norm_app_of_nonzero {f : PadicSeq p} (hf : ¬f ≈ 0) : ∃ k, f.norm = padicNorm p k ∧ k ≠ 0 := have heq : f.norm = padicNorm p (f <| stationaryPoint hf) := by simp [norm, hf] ⟨f <| stationaryPoint hf, heq, fun h ↦ norm_nonzero_of_not_equiv_zero hf (by simpa [h] using heq)⟩ #align padic_seq.norm_eq_norm_app_of_nonzero PadicSeq.norm_eq_norm_app_of_nonzero theorem not_limZero_const_of_nonzero {q : ℚ} (hq : q ≠ 0) : ¬LimZero (const (padicNorm p) q) := fun h' ↦ hq <| const_limZero.1 h' #align padic_seq.not_lim_zero_const_of_nonzero PadicSeq.not_limZero_const_of_nonzero theorem not_equiv_zero_const_of_nonzero {q : ℚ} (hq : q ≠ 0) : ¬const (padicNorm p) q ≈ 0 := fun h : LimZero (const (padicNorm p) q - 0) ↦ not_limZero_const_of_nonzero hq <| by simpa using h #align padic_seq.not_equiv_zero_const_of_nonzero PadicSeq.not_equiv_zero_const_of_nonzero theorem norm_nonneg (f : PadicSeq p) : 0 ≤ f.norm := if hf : f ≈ 0 then by simp [hf, norm] else by simp [norm, hf, padicNorm.nonneg] #align padic_seq.norm_nonneg PadicSeq.norm_nonneg /-- An auxiliary lemma for manipulating sequence indices. -/ theorem lift_index_left_left {f : PadicSeq p} (hf : ¬f ≈ 0) (v2 v3 : ℕ) : padicNorm p (f (stationaryPoint hf)) = padicNorm p (f (max (stationaryPoint hf) (max v2 v3))) := by apply stationaryPoint_spec hf · apply le_max_left · exact le_rfl #align padic_seq.lift_index_left_left PadicSeq.lift_index_left_left /-- An auxiliary lemma for manipulating sequence indices. -/ theorem lift_index_left {f : PadicSeq p} (hf : ¬f ≈ 0) (v1 v3 : ℕ) : padicNorm p (f (stationaryPoint hf)) = padicNorm p (f (max v1 (max (stationaryPoint hf) v3))) := by apply stationaryPoint_spec hf · apply le_trans · apply le_max_left _ v3 · apply le_max_right · exact le_rfl #align padic_seq.lift_index_left PadicSeq.lift_index_left /-- An auxiliary lemma for manipulating sequence indices. -/ theorem lift_index_right {f : PadicSeq p} (hf : ¬f ≈ 0) (v1 v2 : ℕ) : padicNorm p (f (stationaryPoint hf)) = padicNorm p (f (max v1 (max v2 (stationaryPoint hf)))) := by apply stationaryPoint_spec hf · apply le_trans · apply le_max_right v2 · apply le_max_right · exact le_rfl #align padic_seq.lift_index_right PadicSeq.lift_index_right end Embedding section Valuation open CauSeq variable {p : ℕ} [Fact p.Prime] /-! ### Valuation on `PadicSeq` -/ /-- The `p`-adic valuation on `ℚ` lifts to `PadicSeq p`. `Valuation f` is defined to be the valuation of the (`ℚ`-valued) stationary point of `f`. -/ def valuation (f : PadicSeq p) : ℤ := if hf : f ≈ 0 then 0 else padicValRat p (f (stationaryPoint hf)) #align padic_seq.valuation PadicSeq.valuation theorem norm_eq_pow_val {f : PadicSeq p} (hf : ¬f ≈ 0) : f.norm = (p : ℚ) ^ (-f.valuation : ℤ) := by rw [norm, valuation, dif_neg hf, dif_neg hf, padicNorm, if_neg] intro H apply CauSeq.not_limZero_of_not_congr_zero hf intro ε hε use stationaryPoint hf intro n hn rw [stationaryPoint_spec hf le_rfl hn] simpa [H] using hε #align padic_seq.norm_eq_pow_val PadicSeq.norm_eq_pow_val theorem val_eq_iff_norm_eq {f g : PadicSeq p} (hf : ¬f ≈ 0) (hg : ¬g ≈ 0) : f.valuation = g.valuation ↔ f.norm = g.norm := by rw [norm_eq_pow_val hf, norm_eq_pow_val hg, ← neg_inj, zpow_inj] · exact mod_cast (Fact.out : p.Prime).pos · exact mod_cast (Fact.out : p.Prime).ne_one #align padic_seq.val_eq_iff_norm_eq PadicSeq.val_eq_iff_norm_eq end Valuation end PadicSeq section open PadicSeq -- Porting note: Commented out `padic_index_simp` tactic /- private unsafe def index_simp_core (hh hf hg : expr) (at_ : Interactive.Loc := Interactive.Loc.ns [none]) : tactic Unit := do let [v1, v2, v3] ← [hh, hf, hg].mapM fun n => tactic.mk_app `` stationary_point [n] <|> return n let e1 ← tactic.mk_app `` lift_index_left_left [hh, v2, v3] <|> return q(True) let e2 ← tactic.mk_app `` lift_index_left [hf, v1, v3] <|> return q(True) let e3 ← tactic.mk_app `` lift_index_right [hg, v1, v2] <|> return q(True) let sl ← [e1, e2, e3].foldlM (fun s e => simp_lemmas.add s e) simp_lemmas.mk when at_ (tactic.simp_target sl >> tactic.skip) let hs ← at_.get_locals hs (tactic.simp_hyp sl []) #align index_simp_core index_simp_core /-- This is a special-purpose tactic that lifts `padicNorm (f (stationary_point f))` to `padicNorm (f (max _ _ _))`. -/ unsafe def tactic.interactive.padic_index_simp (l : interactive.parse interactive.types.pexpr_list) (at_ : interactive.parse interactive.types.location) : tactic Unit := do let [h, f, g] ← l.mapM tactic.i_to_expr index_simp_core h f g at_ #align tactic.interactive.padic_index_simp tactic.interactive.padic_index_simp -/ end namespace PadicSeq section Embedding open CauSeq variable {p : ℕ} [hp : Fact p.Prime] theorem norm_mul (f g : PadicSeq p) : (f * g).norm = f.norm * g.norm := if hf : f ≈ 0 then by have hg : f * g ≈ 0 := mul_equiv_zero' _ hf simp only [hf, hg, norm, dif_pos, zero_mul] else if hg : g ≈ 0 then by have hf : f * g ≈ 0 := mul_equiv_zero _ hg simp only [hf, hg, norm, dif_pos, mul_zero] else by unfold norm split_ifs with hfg · exact (mul_not_equiv_zero hf hg hfg).elim -- Porting note: originally `padic_index_simp [hfg, hf, hg]` rw [lift_index_left_left hfg, lift_index_left hf, lift_index_right hg] apply padicNorm.mul #align padic_seq.norm_mul PadicSeq.norm_mul theorem eq_zero_iff_equiv_zero (f : PadicSeq p) : mk f = 0 ↔ f ≈ 0 := mk_eq #align padic_seq.eq_zero_iff_equiv_zero PadicSeq.eq_zero_iff_equiv_zero theorem ne_zero_iff_nequiv_zero (f : PadicSeq p) : mk f ≠ 0 ↔ ¬f ≈ 0 := not_iff_not.2 (eq_zero_iff_equiv_zero _) #align padic_seq.ne_zero_iff_nequiv_zero PadicSeq.ne_zero_iff_nequiv_zero theorem norm_const (q : ℚ) : norm (const (padicNorm p) q) = padicNorm p q := if hq : q = 0 then by have : const (padicNorm p) q ≈ 0 := by simp [hq]; apply Setoid.refl (const (padicNorm p) 0) subst hq; simp [norm, this] else by have : ¬const (padicNorm p) q ≈ 0 := not_equiv_zero_const_of_nonzero hq simp [norm, this] #align padic_seq.norm_const PadicSeq.norm_const theorem norm_values_discrete (a : PadicSeq p) (ha : ¬a ≈ 0) : ∃ z : ℤ, a.norm = (p : ℚ) ^ (-z) := by let ⟨k, hk, hk'⟩ := norm_eq_norm_app_of_nonzero ha simpa [hk] using padicNorm.values_discrete hk' #align padic_seq.norm_values_discrete PadicSeq.norm_values_discrete theorem norm_one : norm (1 : PadicSeq p) = 1 := by have h1 : ¬(1 : PadicSeq p) ≈ 0 := one_not_equiv_zero _ simp [h1, norm, hp.1.one_lt] #align padic_seq.norm_one PadicSeq.norm_one private theorem norm_eq_of_equiv_aux {f g : PadicSeq p} (hf : ¬f ≈ 0) (hg : ¬g ≈ 0) (hfg : f ≈ g) (h : padicNorm p (f (stationaryPoint hf)) ≠ padicNorm p (g (stationaryPoint hg))) (hlt : padicNorm p (g (stationaryPoint hg)) < padicNorm p (f (stationaryPoint hf))) : False := by have hpn : 0 < padicNorm p (f (stationaryPoint hf)) - padicNorm p (g (stationaryPoint hg)) := sub_pos_of_lt hlt cases' hfg _ hpn with N hN let i := max N (max (stationaryPoint hf) (stationaryPoint hg)) have hi : N ≤ i := le_max_left _ _ have hN' := hN _ hi -- Porting note: originally `padic_index_simp [N, hf, hg] at hN' h hlt` rw [lift_index_left hf N (stationaryPoint hg), lift_index_right hg N (stationaryPoint hf)] at hN' h hlt have hpne : padicNorm p (f i) ≠ padicNorm p (-g i) := by rwa [← padicNorm.neg (g i)] at h rw [CauSeq.sub_apply, sub_eq_add_neg, add_eq_max_of_ne hpne, padicNorm.neg, max_eq_left_of_lt hlt] at hN' have : padicNorm p (f i) < padicNorm p (f i) := by apply lt_of_lt_of_le hN' apply sub_le_self apply padicNorm.nonneg exact lt_irrefl _ this private theorem norm_eq_of_equiv {f g : PadicSeq p} (hf : ¬f ≈ 0) (hg : ¬g ≈ 0) (hfg : f ≈ g) : padicNorm p (f (stationaryPoint hf)) = padicNorm p (g (stationaryPoint hg)) := by by_contra h cases' Decidable.em (padicNorm p (g (stationaryPoint hg)) < padicNorm p (f (stationaryPoint hf))) with hlt hnlt · exact norm_eq_of_equiv_aux hf hg hfg h hlt · apply norm_eq_of_equiv_aux hg hf (Setoid.symm hfg) (Ne.symm h) apply lt_of_le_of_ne · apply le_of_not_gt hnlt · apply h theorem norm_equiv {f g : PadicSeq p} (hfg : f ≈ g) : f.norm = g.norm := if hf : f ≈ 0 then by have hg : g ≈ 0 := Setoid.trans (Setoid.symm hfg) hf simp [norm, hf, hg] else by have hg : ¬g ≈ 0 := hf ∘ Setoid.trans hfg unfold norm; split_ifs; exact norm_eq_of_equiv hf hg hfg #align padic_seq.norm_equiv PadicSeq.norm_equiv private theorem norm_nonarchimedean_aux {f g : PadicSeq p} (hfg : ¬f + g ≈ 0) (hf : ¬f ≈ 0) (hg : ¬g ≈ 0) : (f + g).norm ≤ max f.norm g.norm := by unfold norm; split_ifs -- Porting note: originally `padic_index_simp [hfg, hf, hg]` rw [lift_index_left_left hfg, lift_index_left hf, lift_index_right hg] apply padicNorm.nonarchimedean theorem norm_nonarchimedean (f g : PadicSeq p) : (f + g).norm ≤ max f.norm g.norm := if hfg : f + g ≈ 0 then by have : 0 ≤ max f.norm g.norm := le_max_of_le_left (norm_nonneg _) simpa only [hfg, norm] else if hf : f ≈ 0 then by have hfg' : f + g ≈ g := by change LimZero (f - 0) at hf show LimZero (f + g - g); · simpa only [sub_zero, add_sub_cancel_right] using hf have hcfg : (f + g).norm = g.norm := norm_equiv hfg' have hcl : f.norm = 0 := (norm_zero_iff f).2 hf have : max f.norm g.norm = g.norm := by rw [hcl]; exact max_eq_right (norm_nonneg _) rw [this, hcfg] else if hg : g ≈ 0 then by have hfg' : f + g ≈ f := by change LimZero (g - 0) at hg show LimZero (f + g - f); · simpa only [add_sub_cancel_left, sub_zero] using hg have hcfg : (f + g).norm = f.norm := norm_equiv hfg' have hcl : g.norm = 0 := (norm_zero_iff g).2 hg have : max f.norm g.norm = f.norm := by rw [hcl]; exact max_eq_left (norm_nonneg _) rw [this, hcfg] else norm_nonarchimedean_aux hfg hf hg #align padic_seq.norm_nonarchimedean PadicSeq.norm_nonarchimedean theorem norm_eq {f g : PadicSeq p} (h : ∀ k, padicNorm p (f k) = padicNorm p (g k)) : f.norm = g.norm := if hf : f ≈ 0 then by have hg : g ≈ 0 := equiv_zero_of_val_eq_of_equiv_zero h hf simp only [hf, hg, norm, dif_pos] else by have hg : ¬g ≈ 0 := fun hg ↦ hf <| equiv_zero_of_val_eq_of_equiv_zero (by simp only [h, forall_const, eq_self_iff_true]) hg simp only [hg, hf, norm, dif_neg, not_false_iff] let i := max (stationaryPoint hf) (stationaryPoint hg) have hpf : padicNorm p (f (stationaryPoint hf)) = padicNorm p (f i) := by apply stationaryPoint_spec · apply le_max_left · exact le_rfl have hpg : padicNorm p (g (stationaryPoint hg)) = padicNorm p (g i) := by apply stationaryPoint_spec · apply le_max_right · exact le_rfl rw [hpf, hpg, h] #align padic_seq.norm_eq PadicSeq.norm_eq theorem norm_neg (a : PadicSeq p) : (-a).norm = a.norm := norm_eq <| by simp #align padic_seq.norm_neg PadicSeq.norm_neg theorem norm_eq_of_add_equiv_zero {f g : PadicSeq p} (h : f + g ≈ 0) : f.norm = g.norm := by have : LimZero (f + g - 0) := h have : f ≈ -g := show LimZero (f - -g) by simpa only [sub_zero, sub_neg_eq_add] have : f.norm = (-g).norm := norm_equiv this simpa only [norm_neg] using this #align padic_seq.norm_eq_of_add_equiv_zero PadicSeq.norm_eq_of_add_equiv_zero theorem add_eq_max_of_ne {f g : PadicSeq p} (hfgne : f.norm ≠ g.norm) : (f + g).norm = max f.norm g.norm := have hfg : ¬f + g ≈ 0 := mt norm_eq_of_add_equiv_zero hfgne if hf : f ≈ 0 then by have : LimZero (f - 0) := hf have : f + g ≈ g := show LimZero (f + g - g) by simpa only [sub_zero, add_sub_cancel_right] have h1 : (f + g).norm = g.norm := norm_equiv this have h2 : f.norm = 0 := (norm_zero_iff _).2 hf rw [h1, h2, max_eq_right (norm_nonneg _)] else if hg : g ≈ 0 then by have : LimZero (g - 0) := hg have : f + g ≈ f := show LimZero (f + g - f) by simpa only [add_sub_cancel_left, sub_zero] have h1 : (f + g).norm = f.norm := norm_equiv this have h2 : g.norm = 0 := (norm_zero_iff _).2 hg rw [h1, h2, max_eq_left (norm_nonneg _)] else by unfold norm at hfgne ⊢; split_ifs at hfgne ⊢ -- Porting note: originally `padic_index_simp [hfg, hf, hg] at hfgne ⊢` rw [lift_index_left hf, lift_index_right hg] at hfgne · rw [lift_index_left_left hfg, lift_index_left hf, lift_index_right hg] exact padicNorm.add_eq_max_of_ne hfgne #align padic_seq.add_eq_max_of_ne PadicSeq.add_eq_max_of_ne end Embedding end PadicSeq /-- The `p`-adic numbers `ℚ_[p]` are the Cauchy completion of `ℚ` with respect to the `p`-adic norm. -/ def Padic (p : ℕ) [Fact p.Prime] := CauSeq.Completion.Cauchy (padicNorm p) #align padic Padic /-- notation for p-padic rationals -/ notation "ℚ_[" p "]" => Padic p namespace Padic section Completion variable {p : ℕ} [Fact p.Prime] instance field : Field ℚ_[p] := Cauchy.field instance : Inhabited ℚ_[p] := ⟨0⟩ -- short circuits instance : CommRing ℚ_[p] := Cauchy.commRing instance : Ring ℚ_[p] := Cauchy.ring instance : Zero ℚ_[p] := by infer_instance instance : One ℚ_[p] := by infer_instance instance : Add ℚ_[p] := by infer_instance instance : Mul ℚ_[p] := by infer_instance instance : Sub ℚ_[p] := by infer_instance instance : Neg ℚ_[p] := by infer_instance instance : Div ℚ_[p] := by infer_instance instance : AddCommGroup ℚ_[p] := by infer_instance /-- Builds the equivalence class of a Cauchy sequence of rationals. -/ def mk : PadicSeq p → ℚ_[p] := Quotient.mk' #align padic.mk Padic.mk variable (p) theorem zero_def : (0 : ℚ_[p]) = ⟦0⟧ := rfl #align padic.zero_def Padic.zero_def theorem mk_eq {f g : PadicSeq p} : mk f = mk g ↔ f ≈ g := Quotient.eq' #align padic.mk_eq Padic.mk_eq theorem const_equiv {q r : ℚ} : const (padicNorm p) q ≈ const (padicNorm p) r ↔ q = r := ⟨fun heq ↦ eq_of_sub_eq_zero <| const_limZero.1 heq, fun heq ↦ by rw [heq]⟩ #align padic.const_equiv Padic.const_equiv @[norm_cast] theorem coe_inj {q r : ℚ} : (↑q : ℚ_[p]) = ↑r ↔ q = r := ⟨(const_equiv p).1 ∘ Quotient.eq'.1, fun h ↦ by rw [h]⟩ #align padic.coe_inj Padic.coe_inj instance : CharZero ℚ_[p] := ⟨fun m n ↦ by rw [← Rat.cast_natCast] norm_cast exact id⟩ @[norm_cast] theorem coe_add : ∀ {x y : ℚ}, (↑(x + y) : ℚ_[p]) = ↑x + ↑y := Rat.cast_add _ _ #align padic.coe_add Padic.coe_add @[norm_cast] theorem coe_neg : ∀ {x : ℚ}, (↑(-x) : ℚ_[p]) = -↑x := Rat.cast_neg _ #align padic.coe_neg Padic.coe_neg @[norm_cast] theorem coe_mul : ∀ {x y : ℚ}, (↑(x * y) : ℚ_[p]) = ↑x * ↑y := Rat.cast_mul _ _ #align padic.coe_mul Padic.coe_mul @[norm_cast] theorem coe_sub : ∀ {x y : ℚ}, (↑(x - y) : ℚ_[p]) = ↑x - ↑y := Rat.cast_sub _ _ #align padic.coe_sub Padic.coe_sub @[norm_cast] theorem coe_div : ∀ {x y : ℚ}, (↑(x / y) : ℚ_[p]) = ↑x / ↑y := Rat.cast_div _ _ #align padic.coe_div Padic.coe_div @[norm_cast] theorem coe_one : (↑(1 : ℚ) : ℚ_[p]) = 1 := rfl #align padic.coe_one Padic.coe_one @[norm_cast] theorem coe_zero : (↑(0 : ℚ) : ℚ_[p]) = 0 := rfl #align padic.coe_zero Padic.coe_zero end Completion end Padic /-- The rational-valued `p`-adic norm on `ℚ_[p]` is lifted from the norm on Cauchy sequences. The canonical form of this function is the normed space instance, with notation `‖ ‖`. -/ def padicNormE {p : ℕ} [hp : Fact p.Prime] : AbsoluteValue ℚ_[p] ℚ where toFun := Quotient.lift PadicSeq.norm <| @PadicSeq.norm_equiv _ _ map_mul' q r := Quotient.inductionOn₂ q r <| PadicSeq.norm_mul nonneg' q := Quotient.inductionOn q <| PadicSeq.norm_nonneg eq_zero' q := Quotient.inductionOn q fun r ↦ by rw [Padic.zero_def, Quotient.eq] exact PadicSeq.norm_zero_iff r add_le' q r := by trans max ((Quotient.lift PadicSeq.norm <| @PadicSeq.norm_equiv _ _) q) ((Quotient.lift PadicSeq.norm <| @PadicSeq.norm_equiv _ _) r) · exact Quotient.inductionOn₂ q r <| PadicSeq.norm_nonarchimedean refine max_le_add_of_nonneg (Quotient.inductionOn q <| PadicSeq.norm_nonneg) ?_ exact Quotient.inductionOn r <| PadicSeq.norm_nonneg #align padic_norm_e padicNormE namespace padicNormE section Embedding open PadicSeq variable {p : ℕ} [Fact p.Prime] -- Porting note: Expanded `⟦f⟧` to `Padic.mk f` theorem defn (f : PadicSeq p) {ε : ℚ} (hε : 0 < ε) : ∃ N, ∀ i ≥ N, padicNormE (Padic.mk f - f i : ℚ_[p]) < ε := by dsimp [padicNormE] change ∃ N, ∀ i ≥ N, (f - const _ (f i)).norm < ε by_contra! h cases' cauchy₂ f hε with N hN rcases h N with ⟨i, hi, hge⟩ have hne : ¬f - const (padicNorm p) (f i) ≈ 0 := fun h ↦ by rw [PadicSeq.norm, dif_pos h] at hge exact not_lt_of_ge hge hε unfold PadicSeq.norm at hge; split_ifs at hge · exact not_le_of_gt hε hge apply not_le_of_gt _ hge cases' _root_.em (N ≤ stationaryPoint hne) with hgen hngen · apply hN _ hgen _ hi · have := stationaryPoint_spec hne le_rfl (le_of_not_le hngen) rw [← this] exact hN _ le_rfl _ hi #align padic_norm_e.defn padicNormE.defn /-- Theorems about `padicNormE` are named with a `'` so the names do not conflict with the equivalent theorems about `norm` (`‖ ‖`). -/ theorem nonarchimedean' (q r : ℚ_[p]) : padicNormE (q + r : ℚ_[p]) ≤ max (padicNormE q) (padicNormE r) := Quotient.inductionOn₂ q r <| norm_nonarchimedean #align padic_norm_e.nonarchimedean' padicNormE.nonarchimedean' /-- Theorems about `padicNormE` are named with a `'` so the names do not conflict with the equivalent theorems about `norm` (`‖ ‖`). -/ theorem add_eq_max_of_ne' {q r : ℚ_[p]} : padicNormE q ≠ padicNormE r → padicNormE (q + r : ℚ_[p]) = max (padicNormE q) (padicNormE r) := Quotient.inductionOn₂ q r fun _ _ ↦ PadicSeq.add_eq_max_of_ne #align padic_norm_e.add_eq_max_of_ne' padicNormE.add_eq_max_of_ne' @[simp] theorem eq_padic_norm' (q : ℚ) : padicNormE (q : ℚ_[p]) = padicNorm p q := norm_const _ #align padic_norm_e.eq_padic_norm' padicNormE.eq_padic_norm' protected theorem image' {q : ℚ_[p]} : q ≠ 0 → ∃ n : ℤ, padicNormE q = (p : ℚ) ^ (-n) := Quotient.inductionOn q fun f hf ↦ have : ¬f ≈ 0 := (ne_zero_iff_nequiv_zero f).1 hf norm_values_discrete f this #align padic_norm_e.image' padicNormE.image' end Embedding end padicNormE namespace Padic section Complete open PadicSeq Padic variable {p : ℕ} [Fact p.Prime] (f : CauSeq _ (@padicNormE p _)) theorem rat_dense' (q : ℚ_[p]) {ε : ℚ} (hε : 0 < ε) : ∃ r : ℚ, padicNormE (q - r : ℚ_[p]) < ε := Quotient.inductionOn q fun q' ↦ have : ∃ N, ∀ m ≥ N, ∀ n ≥ N, padicNorm p (q' m - q' n) < ε := cauchy₂ _ hε let ⟨N, hN⟩ := this ⟨q' N, by dsimp [padicNormE] -- Porting note: `change` → `convert_to` (`change` times out!) -- and add `PadicSeq p` type annotation convert_to PadicSeq.norm (q' - const _ (q' N) : PadicSeq p) < ε cases' Decidable.em (q' - const (padicNorm p) (q' N) ≈ 0) with heq hne' · simpa only [heq, PadicSeq.norm, dif_pos] · simp only [PadicSeq.norm, dif_neg hne'] change padicNorm p (q' _ - q' _) < ε cases' Decidable.em (stationaryPoint hne' ≤ N) with hle hle · -- Porting note: inlined `stationaryPoint_spec` invocation. have := (stationaryPoint_spec hne' le_rfl hle).symm simp only [const_apply, sub_apply, padicNorm.zero, sub_self] at this simpa only [this] · exact hN _ (lt_of_not_ge hle).le _ le_rfl⟩ #align padic.rat_dense' Padic.rat_dense' open scoped Classical private theorem div_nat_pos (n : ℕ) : 0 < 1 / (n + 1 : ℚ) := div_pos zero_lt_one (mod_cast succ_pos _) /-- `limSeq f`, for `f` a Cauchy sequence of `p`-adic numbers, is a sequence of rationals with the same limit point as `f`. -/ def limSeq : ℕ → ℚ := fun n ↦ Classical.choose (rat_dense' (f n) (div_nat_pos n)) #align padic.lim_seq Padic.limSeq theorem exi_rat_seq_conv {ε : ℚ} (hε : 0 < ε) : ∃ N, ∀ i ≥ N, padicNormE (f i - (limSeq f i : ℚ_[p]) : ℚ_[p]) < ε := by refine (exists_nat_gt (1 / ε)).imp fun N hN i hi ↦ ?_ have h := Classical.choose_spec (rat_dense' (f i) (div_nat_pos i)) refine lt_of_lt_of_le h ((div_le_iff' <| mod_cast succ_pos _).mpr ?_) rw [right_distrib] apply le_add_of_le_of_nonneg · exact (div_le_iff hε).mp (le_trans (le_of_lt hN) (mod_cast hi)) · apply le_of_lt simpa #align padic.exi_rat_seq_conv Padic.exi_rat_seq_conv theorem exi_rat_seq_conv_cauchy : IsCauSeq (padicNorm p) (limSeq f) := fun ε hε ↦ by have hε3 : 0 < ε / 3 := div_pos hε (by norm_num) let ⟨N, hN⟩ := exi_rat_seq_conv f hε3 let ⟨N2, hN2⟩ := f.cauchy₂ hε3 exists max N N2 intro j hj suffices padicNormE (limSeq f j - f (max N N2) + (f (max N N2) - limSeq f (max N N2)) : ℚ_[p]) < ε by ring_nf at this ⊢ rw [← padicNormE.eq_padic_norm'] exact mod_cast this apply lt_of_le_of_lt · apply padicNormE.add_le · rw [← add_thirds ε] apply _root_.add_lt_add · suffices padicNormE (limSeq f j - f j + (f j - f (max N N2)) : ℚ_[p]) < ε / 3 + ε / 3 by simpa only [sub_add_sub_cancel] apply lt_of_le_of_lt · apply padicNormE.add_le · apply _root_.add_lt_add · rw [padicNormE.map_sub] apply mod_cast hN j exact le_of_max_le_left hj · exact hN2 _ (le_of_max_le_right hj) _ (le_max_right _ _) · apply mod_cast hN (max N N2) apply le_max_left #align padic.exi_rat_seq_conv_cauchy Padic.exi_rat_seq_conv_cauchy private def lim' : PadicSeq p := ⟨_, exi_rat_seq_conv_cauchy f⟩ private def lim : ℚ_[p] := ⟦lim' f⟧ theorem complete' : ∃ q : ℚ_[p], ∀ ε > 0, ∃ N, ∀ i ≥ N, padicNormE (q - f i : ℚ_[p]) < ε := ⟨lim f, fun ε hε ↦ by obtain ⟨N, hN⟩ := exi_rat_seq_conv f (half_pos hε) obtain ⟨N2, hN2⟩ := padicNormE.defn (lim' f) (half_pos hε) refine ⟨max N N2, fun i hi ↦ ?_⟩ rw [← sub_add_sub_cancel _ (lim' f i : ℚ_[p]) _] refine (padicNormE.add_le _ _).trans_lt ?_ rw [← add_halves ε] apply _root_.add_lt_add · apply hN2 _ (le_of_max_le_right hi) · rw [padicNormE.map_sub] exact hN _ (le_of_max_le_left hi)⟩ #align padic.complete' Padic.complete' theorem complete'' : ∃ q : ℚ_[p], ∀ ε > 0, ∃ N, ∀ i ≥ N, padicNormE (f i - q : ℚ_[p]) < ε := by obtain ⟨x, hx⟩ := complete' f refine ⟨x, fun ε hε => ?_⟩ obtain ⟨N, hN⟩ := hx ε hε refine ⟨N, fun i hi => ?_⟩ rw [padicNormE.map_sub] exact hN i hi end Complete section NormedSpace variable (p : ℕ) [Fact p.Prime] instance : Dist ℚ_[p] := ⟨fun x y ↦ padicNormE (x - y : ℚ_[p])⟩ instance metricSpace : MetricSpace ℚ_[p] where dist_self := by simp [dist] dist := dist dist_comm x y := by simp [dist, ← padicNormE.map_neg (x - y : ℚ_[p])] dist_triangle x y z := by dsimp [dist] exact mod_cast padicNormE.sub_le x y z eq_of_dist_eq_zero := by dsimp [dist]; intro _ _ h apply eq_of_sub_eq_zero apply padicNormE.eq_zero.1 exact mod_cast h -- Porting note: added because autoparam was not ported edist_dist := by intros; exact (ENNReal.ofReal_eq_coe_nnreal _).symm instance : Norm ℚ_[p] := ⟨fun x ↦ padicNormE x⟩ instance normedField : NormedField ℚ_[p] := { Padic.field, Padic.metricSpace p with dist_eq := fun _ _ ↦ rfl norm_mul' := by simp [Norm.norm, map_mul] norm := norm } instance isAbsoluteValue : IsAbsoluteValue fun a : ℚ_[p] ↦ ‖a‖ where abv_nonneg' := norm_nonneg abv_eq_zero' := norm_eq_zero abv_add' := norm_add_le abv_mul' := by simp [Norm.norm, map_mul] #align padic.is_absolute_value Padic.isAbsoluteValue theorem rat_dense (q : ℚ_[p]) {ε : ℝ} (hε : 0 < ε) : ∃ r : ℚ, ‖q - r‖ < ε := let ⟨ε', hε'l, hε'r⟩ := exists_rat_btwn hε let ⟨r, hr⟩ := rat_dense' q (ε := ε') (by simpa using hε'l) ⟨r, lt_trans (by simpa [Norm.norm] using hr) hε'r⟩ #align padic.rat_dense Padic.rat_dense end NormedSpace end Padic namespace padicNormE section NormedSpace variable {p : ℕ} [hp : Fact p.Prime] -- Porting note: Linter thinks this is a duplicate simp lemma, so `priority` is assigned @[simp (high)] protected theorem mul (q r : ℚ_[p]) : ‖q * r‖ = ‖q‖ * ‖r‖ := by simp [Norm.norm, map_mul] #align padic_norm_e.mul padicNormE.mul protected theorem is_norm (q : ℚ_[p]) : ↑(padicNormE q) = ‖q‖ := rfl #align padic_norm_e.is_norm padicNormE.is_norm theorem nonarchimedean (q r : ℚ_[p]) : ‖q + r‖ ≤ max ‖q‖ ‖r‖ := by dsimp [norm] exact mod_cast nonarchimedean' _ _ #align padic_norm_e.nonarchimedean padicNormE.nonarchimedean theorem add_eq_max_of_ne {q r : ℚ_[p]} (h : ‖q‖ ≠ ‖r‖) : ‖q + r‖ = max ‖q‖ ‖r‖ := by dsimp [norm] at h ⊢ have : padicNormE q ≠ padicNormE r := mod_cast h exact mod_cast add_eq_max_of_ne' this #align padic_norm_e.add_eq_max_of_ne padicNormE.add_eq_max_of_ne @[simp] theorem eq_padicNorm (q : ℚ) : ‖(q : ℚ_[p])‖ = padicNorm p q := by dsimp [norm] rw [← padicNormE.eq_padic_norm'] #align padic_norm_e.eq_padic_norm padicNormE.eq_padicNorm @[simp] theorem norm_p : ‖(p : ℚ_[p])‖ = (p : ℝ)⁻¹ := by rw [← @Rat.cast_natCast ℝ _ p] rw [← @Rat.cast_natCast ℚ_[p] _ p] simp [hp.1.ne_zero, hp.1.ne_one, norm, padicNorm, padicValRat, padicValInt, zpow_neg, -Rat.cast_natCast] #align padic_norm_e.norm_p padicNormE.norm_p theorem norm_p_lt_one : ‖(p : ℚ_[p])‖ < 1 := by rw [norm_p] apply inv_lt_one exact mod_cast hp.1.one_lt #align padic_norm_e.norm_p_lt_one padicNormE.norm_p_lt_one -- Porting note: Linter thinks this is a duplicate simp lemma, so `priority` is assigned @[simp (high)] theorem norm_p_zpow (n : ℤ) : ‖(p : ℚ_[p]) ^ n‖ = (p : ℝ) ^ (-n) := by rw [norm_zpow, norm_p, zpow_neg, inv_zpow] #align padic_norm_e.norm_p_zpow padicNormE.norm_p_zpow -- Porting note: Linter thinks this is a duplicate simp lemma, so `priority` is assigned @[simp (high)] theorem norm_p_pow (n : ℕ) : ‖(p : ℚ_[p]) ^ n‖ = (p : ℝ) ^ (-n : ℤ) := by rw [← norm_p_zpow, zpow_natCast] #align padic_norm_e.norm_p_pow padicNormE.norm_p_pow instance : NontriviallyNormedField ℚ_[p] := { Padic.normedField p with non_trivial := ⟨p⁻¹, by rw [norm_inv, norm_p, inv_inv] exact mod_cast hp.1.one_lt⟩ } protected theorem image {q : ℚ_[p]} : q ≠ 0 → ∃ n : ℤ, ‖q‖ = ↑((p : ℚ) ^ (-n)) := Quotient.inductionOn q fun f hf ↦ have : ¬f ≈ 0 := (PadicSeq.ne_zero_iff_nequiv_zero f).1 hf let ⟨n, hn⟩ := PadicSeq.norm_values_discrete f this ⟨n, by rw [← hn]; rfl⟩ #align padic_norm_e.image padicNormE.image protected theorem is_rat (q : ℚ_[p]) : ∃ q' : ℚ, ‖q‖ = q' := if h : q = 0 then ⟨0, by simp [h]⟩ else let ⟨n, hn⟩ := padicNormE.image h ⟨_, hn⟩ #align padic_norm_e.is_rat padicNormE.is_rat /-- `ratNorm q`, for a `p`-adic number `q` is the `p`-adic norm of `q`, as rational number. The lemma `padicNormE.eq_ratNorm` asserts `‖q‖ = ratNorm q`. -/ def ratNorm (q : ℚ_[p]) : ℚ := Classical.choose (padicNormE.is_rat q) #align padic_norm_e.rat_norm padicNormE.ratNorm theorem eq_ratNorm (q : ℚ_[p]) : ‖q‖ = ratNorm q := Classical.choose_spec (padicNormE.is_rat q) #align padic_norm_e.eq_rat_norm padicNormE.eq_ratNorm theorem norm_rat_le_one : ∀ {q : ℚ} (_ : ¬p ∣ q.den), ‖(q : ℚ_[p])‖ ≤ 1 | ⟨n, d, hn, hd⟩ => fun hq : ¬p ∣ d ↦ if hnz : n = 0 then by have : (⟨n, d, hn, hd⟩ : ℚ) = 0 := Rat.zero_iff_num_zero.mpr hnz set_option tactic.skipAssignedInstances false in norm_num [this] else by have hnz' : (⟨n, d, hn, hd⟩ : ℚ) ≠ 0 := mt Rat.zero_iff_num_zero.1 hnz rw [padicNormE.eq_padicNorm] norm_cast -- Porting note: `Nat.cast_zero` instead of another `norm_cast` call rw [padicNorm.eq_zpow_of_nonzero hnz', padicValRat, neg_sub, padicValNat.eq_zero_of_not_dvd hq, Nat.cast_zero, zero_sub, zpow_neg, zpow_natCast] apply inv_le_one norm_cast apply one_le_pow exact hp.1.pos #align padic_norm_e.norm_rat_le_one padicNormE.norm_rat_le_one theorem norm_int_le_one (z : ℤ) : ‖(z : ℚ_[p])‖ ≤ 1 := suffices ‖((z : ℚ) : ℚ_[p])‖ ≤ 1 by simpa norm_rat_le_one <| by simp [hp.1.ne_one] #align padic_norm_e.norm_int_le_one padicNormE.norm_int_le_one
Mathlib/NumberTheory/Padics/PadicNumbers.lean
918
937
theorem norm_int_lt_one_iff_dvd (k : ℤ) : ‖(k : ℚ_[p])‖ < 1 ↔ ↑p ∣ k := by
constructor · intro h contrapose! h apply le_of_eq rw [eq_comm] calc ‖(k : ℚ_[p])‖ = ‖((k : ℚ) : ℚ_[p])‖ := by norm_cast _ = padicNorm p k := padicNormE.eq_padicNorm _ _ = 1 := mod_cast (int_eq_one_iff k).mpr h · rintro ⟨x, rfl⟩ push_cast rw [padicNormE.mul] calc _ ≤ ‖(p : ℚ_[p])‖ * 1 := mul_le_mul le_rfl (by simpa using norm_int_le_one _) (norm_nonneg _) (norm_nonneg _) _ < 1 := by rw [mul_one, padicNormE.norm_p] apply inv_lt_one exact mod_cast hp.1.one_lt
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Order.WellFounded import Mathlib.Tactic.Common #align_import data.pi.lex from "leanprover-community/mathlib"@"6623e6af705e97002a9054c1c05a980180276fc1" /-! # Lexicographic order on Pi types This file defines the lexicographic order for Pi types. `a` is less than `b` if `a i = b i` for all `i` up to some point `k`, and `a k < b k`. ## Notation * `Πₗ i, α i`: Pi type equipped with the lexicographic order. Type synonym of `Π i, α i`. ## See also Related files are: * `Data.Finset.Colex`: Colexicographic order on finite sets. * `Data.List.Lex`: Lexicographic order on lists. * `Data.Sigma.Order`: Lexicographic order on `Σₗ i, α i`. * `Data.PSigma.Order`: Lexicographic order on `Σₗ' i, α i`. * `Data.Prod.Lex`: Lexicographic order on `α × β`. -/ assert_not_exists Monoid variable {ι : Type*} {β : ι → Type*} (r : ι → ι → Prop) (s : ∀ {i}, β i → β i → Prop) namespace Pi /-- The lexicographic relation on `Π i : ι, β i`, where `ι` is ordered by `r`, and each `β i` is ordered by `s`. -/ protected def Lex (x y : ∀ i, β i) : Prop := ∃ i, (∀ j, r j i → x j = y j) ∧ s (x i) (y i) #align pi.lex Pi.Lex /- This unfortunately results in a type that isn't delta-reduced, so we keep the notation out of the basic API, just in case -/ /-- The notation `Πₗ i, α i` refers to a pi type equipped with the lexicographic order. -/ notation3 (prettyPrint := false) "Πₗ "(...)", "r:(scoped p => Lex (∀ i, p i)) => r @[simp] theorem toLex_apply (x : ∀ i, β i) (i : ι) : toLex x i = x i := rfl #align pi.to_lex_apply Pi.toLex_apply @[simp] theorem ofLex_apply (x : Lex (∀ i, β i)) (i : ι) : ofLex x i = x i := rfl #align pi.of_lex_apply Pi.ofLex_apply theorem lex_lt_of_lt_of_preorder [∀ i, Preorder (β i)] {r} (hwf : WellFounded r) {x y : ∀ i, β i} (hlt : x < y) : ∃ i, (∀ j, r j i → x j ≤ y j ∧ y j ≤ x j) ∧ x i < y i := let h' := Pi.lt_def.1 hlt let ⟨i, hi, hl⟩ := hwf.has_min _ h'.2 ⟨i, fun j hj => ⟨h'.1 j, not_not.1 fun h => hl j (lt_of_le_not_le (h'.1 j) h) hj⟩, hi⟩ #align pi.lex_lt_of_lt_of_preorder Pi.lex_lt_of_lt_of_preorder
Mathlib/Order/PiLex.lean
65
68
theorem lex_lt_of_lt [∀ i, PartialOrder (β i)] {r} (hwf : WellFounded r) {x y : ∀ i, β i} (hlt : x < y) : Pi.Lex r (@fun i => (· < ·)) x y := by
simp_rw [Pi.Lex, le_antisymm_iff] exact lex_lt_of_lt_of_preorder hwf hlt
/- 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.Algebra.Order.Ring.Abs import Mathlib.Combinatorics.Enumerative.DoubleCounting import Mathlib.Combinatorics.SimpleGraph.Clique import Mathlib.Data.Finset.Sym import Mathlib.Tactic.GCongr import Mathlib.Tactic.Positivity import Mathlib.Tactic.Positivity.Finset #align_import combinatorics.simple_graph.triangle.basic from "leanprover-community/mathlib"@"3365b20c2ffa7c35e47e5209b89ba9abdddf3ffe" /-! # Triangles in graphs A *triangle* in a simple graph is a `3`-clique, namely a set of three vertices that are pairwise adjacent. This module defines and proves properties about triangles in simple graphs. ## Main declarations * `SimpleGraph.FarFromTriangleFree`: Predicate for a graph such that one must remove a lot of edges from it for it to become triangle-free. This is the crux of the Triangle Removal Lemma. ## TODO * Generalise `FarFromTriangleFree` to other graphs, to state and prove the Graph Removal Lemma. -/ open Finset Nat open Fintype (card) namespace SimpleGraph variable {α β 𝕜 : Type*} [LinearOrderedField 𝕜] {G H : SimpleGraph α} {ε δ : 𝕜} {n : ℕ} {s : Finset α} section LocallyLinear /-- A graph has edge-disjoint triangles if each edge belongs to at most one triangle. -/ def EdgeDisjointTriangles (G : SimpleGraph α) : Prop := (G.cliqueSet 3).Pairwise fun x y ↦ (x ∩ y : Set α).Subsingleton /-- A graph is locally linear if each edge belongs to exactly one triangle. -/ def LocallyLinear (G : SimpleGraph α) : Prop := G.EdgeDisjointTriangles ∧ ∀ ⦃x y⦄, G.Adj x y → ∃ s, G.IsNClique 3 s ∧ x ∈ s ∧ y ∈ s protected lemma LocallyLinear.edgeDisjointTriangles : G.LocallyLinear → G.EdgeDisjointTriangles := And.left nonrec lemma EdgeDisjointTriangles.mono (h : G ≤ H) (hH : H.EdgeDisjointTriangles) : G.EdgeDisjointTriangles := hH.mono $ cliqueSet_mono h @[simp] lemma edgeDisjointTriangles_bot : (⊥ : SimpleGraph α).EdgeDisjointTriangles := by simp [EdgeDisjointTriangles] @[simp] lemma locallyLinear_bot : (⊥ : SimpleGraph α).LocallyLinear := by simp [LocallyLinear] lemma EdgeDisjointTriangles.map (f : α ↪ β) (hG : G.EdgeDisjointTriangles) : (G.map f).EdgeDisjointTriangles := by rw [EdgeDisjointTriangles, cliqueSet_map (by norm_num : 3 ≠ 1), (Finset.map_injective f).injOn.pairwise_image] classical rintro s hs t ht hst dsimp [Function.onFun] rw [← coe_inter, ← map_inter, coe_map, coe_inter] exact (hG hs ht hst).image _ lemma LocallyLinear.map (f : α ↪ β) (hG : G.LocallyLinear) : (G.map f).LocallyLinear := by refine ⟨hG.1.map _, ?_⟩ rintro _ _ ⟨a, b, h, rfl, rfl⟩ obtain ⟨s, hs, ha, hb⟩ := hG.2 h exact ⟨s.map f, hs.map, mem_map_of_mem _ ha, mem_map_of_mem _ hb⟩ @[simp] lemma locallyLinear_comap {G : SimpleGraph β} {e : α ≃ β} : (G.comap e).LocallyLinear ↔ G.LocallyLinear := by refine ⟨fun h ↦ ?_, ?_⟩ · rw [← comap_map_eq e.symm.toEmbedding G, comap_symm, map_symm] exact h.map _ · rw [← Equiv.coe_toEmbedding, ← map_symm] exact LocallyLinear.map _ variable [DecidableEq α] lemma edgeDisjointTriangles_iff_mem_sym2_subsingleton : G.EdgeDisjointTriangles ↔ ∀ ⦃e : Sym2 α⦄, ¬ e.IsDiag → {s ∈ G.cliqueSet 3 | e ∈ (s : Finset α).sym2}.Subsingleton := by have (a b) (hab : a ≠ b) : {s ∈ (G.cliqueSet 3 : Set (Finset α)) | s(a, b) ∈ (s : Finset α).sym2} = {s | G.Adj a b ∧ ∃ c, G.Adj a c ∧ G.Adj b c ∧ s = {a, b, c}} := by ext s simp only [mem_sym2_iff, Sym2.mem_iff, forall_eq_or_imp, forall_eq, Set.sep_and, Set.mem_inter_iff, Set.mem_sep_iff, mem_cliqueSet_iff, Set.mem_setOf_eq, and_and_and_comm (b := _ ∈ _), and_self, is3Clique_iff] constructor · rintro ⟨⟨c, d, e, hcd, hce, hde, rfl⟩, hab⟩ simp only [mem_insert, mem_singleton] at hab obtain ⟨rfl | rfl | rfl, rfl | rfl | rfl⟩ := hab any_goals simp only [*, adj_comm, true_and, Ne, eq_self_iff_true, not_true] at * any_goals first | exact ⟨c, by aesop⟩ | exact ⟨d, by aesop⟩ | exact ⟨e, by aesop⟩ | simp only [*, adj_comm, true_and, Ne, eq_self_iff_true, not_true] at * exact ⟨c, by aesop⟩ | simp only [*, adj_comm, true_and, Ne, eq_self_iff_true, not_true] at * exact ⟨d, by aesop⟩ | simp only [*, adj_comm, true_and, Ne, eq_self_iff_true, not_true] at * exact ⟨e, by aesop⟩ · rintro ⟨hab, c, hac, hbc, rfl⟩ refine ⟨⟨a, b, c, ?_⟩, ?_⟩ <;> simp [*] constructor · rw [Sym2.forall] rintro hG a b hab simp only [Sym2.isDiag_iff_proj_eq] at hab rw [this _ _ (Sym2.mk_isDiag_iff.not.2 hab)] rintro _ ⟨hab, c, hac, hbc, rfl⟩ _ ⟨-, d, had, hbd, rfl⟩ refine hG.eq ?_ ?_ (Set.Nontrivial.not_subsingleton ⟨a, ?_, b, ?_, hab.ne⟩) <;> simp [is3Clique_triple_iff, *] · simp only [EdgeDisjointTriangles, is3Clique_iff, Set.Pairwise, mem_cliqueSet_iff, Ne, forall_exists_index, and_imp, ← Set.not_nontrivial_iff (s := _ ∩ _), not_imp_not, Set.Nontrivial, Set.mem_inter_iff, mem_coe] rintro hG _ a b c hab hac hbc rfl _ d e f hde hdf hef rfl g hg₁ hg₂ h hh₁ hh₂ hgh refine hG (Sym2.mk_isDiag_iff.not.2 hgh) ⟨⟨a, b, c, ?_⟩, by simpa using And.intro hg₁ hh₁⟩ ⟨⟨d, e, f, ?_⟩, by simpa using And.intro hg₂ hh₂⟩ <;> simp [is3Clique_triple_iff, *] alias ⟨EdgeDisjointTriangles.mem_sym2_subsingleton, _⟩ := edgeDisjointTriangles_iff_mem_sym2_subsingleton variable [Fintype α] [DecidableRel G.Adj] instance EdgeDisjointTriangles.instDecidable : Decidable G.EdgeDisjointTriangles := decidable_of_iff ((G.cliqueFinset 3 : Set (Finset α)).Pairwise fun x y ↦ ((x ∩ y).card ≤ 1)) $ by simp only [coe_cliqueFinset, EdgeDisjointTriangles, Finset.card_le_one, ← coe_inter]; rfl instance LocallyLinear.instDecidable : Decidable G.LocallyLinear := And.decidable lemma EdgeDisjointTriangles.card_edgeFinset_le (hG : G.EdgeDisjointTriangles) : 3 * (G.cliqueFinset 3).card ≤ G.edgeFinset.card := by rw [mul_comm, ← mul_one G.edgeFinset.card] refine card_mul_le_card_mul (fun s e ↦ e ∈ s.sym2) ?_ (fun e he ↦ ?_) · simp only [is3Clique_iff, mem_cliqueFinset_iff, mem_sym2_iff, forall_exists_index, and_imp] rintro _ a b c hab hac hbc rfl have : Finset.card ({s(a, b), s(a, c), s(b, c)} : Finset (Sym2 α)) = 3 := by refine card_eq_three.2 ⟨_, _, _, ?_, ?_, ?_, rfl⟩ <;> simp [hab.ne, hac.ne, hbc.ne] rw [← this] refine card_mono ?_ simp [insert_subset, *] · simpa only [card_le_one, mem_bipartiteBelow, and_imp, Set.Subsingleton, Set.mem_setOf_eq, mem_cliqueFinset_iff, mem_cliqueSet_iff] using hG.mem_sym2_subsingleton (G.not_isDiag_of_mem_edgeSet $ mem_edgeFinset.1 he) lemma LocallyLinear.card_edgeFinset (hG : G.LocallyLinear) : G.edgeFinset.card = 3 * (G.cliqueFinset 3).card := by refine hG.edgeDisjointTriangles.card_edgeFinset_le.antisymm' ?_ rw [← mul_comm, ← mul_one (Finset.card _)] refine card_mul_le_card_mul (fun e s ↦ e ∈ s.sym2) ?_ ?_ · simpa [Sym2.forall, Nat.one_le_iff_ne_zero, -card_eq_zero, card_ne_zero, Finset.Nonempty] using hG.2 simp only [mem_cliqueFinset_iff, is3Clique_iff, forall_exists_index, and_imp] rintro _ a b c hab hac hbc rfl calc _ ≤ ({s(a, b), s(a, c), s(b, c)} : Finset _).card := card_le_card ?_ _ ≤ 3 := (card_insert_le _ _).trans (succ_le_succ $ (card_insert_le _ _).trans_eq $ by rw [card_singleton]) simp only [subset_iff, Sym2.forall, mem_sym2_iff, le_eq_subset, mem_bipartiteBelow, mem_insert, mem_edgeFinset, mem_singleton, and_imp, mem_edgeSet, Sym2.mem_iff, forall_eq_or_imp, forall_eq, Quotient.eq, Sym2.rel_iff] rintro d e hde (rfl | rfl | rfl) (rfl | rfl | rfl) <;> simp [*] at * end LocallyLinear variable (G ε) variable [Fintype α] [DecidableEq α] [DecidableRel G.Adj] [DecidableRel H.Adj] /-- A simple graph is *`ε`-far from triangle-free* if one must remove at least `ε * (card α) ^ 2` edges to make it triangle-free. -/ def FarFromTriangleFree : Prop := G.DeleteFar (fun H ↦ H.CliqueFree 3) <| ε * (card α ^ 2 : ℕ) #align simple_graph.far_from_triangle_free SimpleGraph.FarFromTriangleFree variable {G ε} theorem farFromTriangleFree_iff : G.FarFromTriangleFree ε ↔ ∀ ⦃H : SimpleGraph α⦄, [DecidableRel H.Adj] → H ≤ G → H.CliqueFree 3 → ε * (card α ^ 2 : ℕ) ≤ G.edgeFinset.card - H.edgeFinset.card := deleteFar_iff #align simple_graph.far_from_triangle_free_iff SimpleGraph.farFromTriangleFree_iff alias ⟨farFromTriangleFree.le_card_sub_card, _⟩ := farFromTriangleFree_iff #align simple_graph.far_from_triangle_free.le_card_sub_card SimpleGraph.farFromTriangleFree.le_card_sub_card nonrec theorem FarFromTriangleFree.mono (hε : G.FarFromTriangleFree ε) (h : δ ≤ ε) : G.FarFromTriangleFree δ := hε.mono <| by gcongr #align simple_graph.far_from_triangle_free.mono SimpleGraph.FarFromTriangleFree.mono theorem FarFromTriangleFree.cliqueFinset_nonempty' (hH : H ≤ G) (hG : G.FarFromTriangleFree ε) (hcard : G.edgeFinset.card - H.edgeFinset.card < ε * (card α ^ 2 : ℕ)) : (H.cliqueFinset 3).Nonempty := nonempty_of_ne_empty <| cliqueFinset_eq_empty_iff.not.2 fun hH' => (hG.le_card_sub_card hH hH').not_lt hcard #align simple_graph.far_from_triangle_free.clique_finset_nonempty' SimpleGraph.FarFromTriangleFree.cliqueFinset_nonempty' private lemma farFromTriangleFree_of_disjoint_triangles_aux {tris : Finset (Finset α)} (htris : tris ⊆ G.cliqueFinset 3) (pd : (tris : Set (Finset α)).Pairwise fun x y ↦ (x ∩ y : Set α).Subsingleton) (hHG : H ≤ G) (hH : H.CliqueFree 3) : tris.card ≤ G.edgeFinset.card - H.edgeFinset.card := by rw [← card_sdiff (edgeFinset_mono hHG), ← card_attach] by_contra! hG have ⦃t⦄ (ht : t ∈ tris) : ∃ x y, x ∈ t ∧ y ∈ t ∧ x ≠ y ∧ s(x, y) ∈ G.edgeFinset \ H.edgeFinset := by by_contra! h refine hH t ?_ simp only [not_and, mem_sdiff, not_not, mem_edgeFinset, mem_edgeSet] at h obtain ⟨x, y, z, xy, xz, yz, rfl⟩ := is3Clique_iff.1 (mem_cliqueFinset_iff.1 $ htris ht) rw [is3Clique_triple_iff] refine ⟨h _ _ ?_ ?_ xy.ne xy, h _ _ ?_ ?_ xz.ne xz, h _ _ ?_ ?_ yz.ne yz⟩ <;> simp choose fx fy hfx hfy hfne fmem using this let f (t : {x // x ∈ tris}) : Sym2 α := s(fx t.2, fy t.2) have hf (x) (_ : x ∈ tris.attach) : f x ∈ G.edgeFinset \ H.edgeFinset := fmem _ obtain ⟨⟨t₁, ht₁⟩, -, ⟨t₂, ht₂⟩, -, tne, t : s(_, _) = s(_, _)⟩ := exists_ne_map_eq_of_card_lt_of_maps_to hG hf dsimp at t have i := pd ht₁ ht₂ (Subtype.val_injective.ne tne) rw [Sym2.eq_iff] at t obtain t | t := t · exact hfne _ (i ⟨hfx ht₁, t.1.symm ▸ hfx ht₂⟩ ⟨hfy ht₁, t.2.symm ▸ hfy ht₂⟩) · exact hfne _ (i ⟨hfx ht₁, t.1.symm ▸ hfy ht₂⟩ ⟨hfy ht₁, t.2.symm ▸ hfx ht₂⟩) /-- If there are `ε * (card α)^2` disjoint triangles, then the graph is `ε`-far from being triangle-free. -/ lemma farFromTriangleFree_of_disjoint_triangles (tris : Finset (Finset α)) (htris : tris ⊆ G.cliqueFinset 3) (pd : (tris : Set (Finset α)).Pairwise fun x y ↦ (x ∩ y : Set α).Subsingleton) (tris_big : ε * (card α ^ 2 : ℕ) ≤ tris.card) : G.FarFromTriangleFree ε := by rw [farFromTriangleFree_iff] intros H _ hG hH rw [← Nat.cast_sub (card_le_card $ edgeFinset_mono hG)] exact tris_big.trans (Nat.cast_le.2 $ farFromTriangleFree_of_disjoint_triangles_aux htris pd hG hH) protected lemma EdgeDisjointTriangles.farFromTriangleFree (hG : G.EdgeDisjointTriangles) (tris_big : ε * (card α ^ 2 : ℕ) ≤ (G.cliqueFinset 3).card) : G.FarFromTriangleFree ε := farFromTriangleFree_of_disjoint_triangles _ Subset.rfl (by simpa using hG) tris_big variable [Nonempty α] lemma FarFromTriangleFree.lt_half (hG : G.FarFromTriangleFree ε) : ε < 2⁻¹ := by by_contra! hε refine lt_irrefl (ε * card α ^ 2) ?_ have hε₀ : 0 < ε := hε.trans_lt' (by norm_num) rw [inv_pos_le_iff_one_le_mul (zero_lt_two' 𝕜)] at hε calc _ ≤ (G.edgeFinset.card : 𝕜) := by simpa using hG.le_card_sub_card bot_le (cliqueFree_bot (le_succ _)) _ ≤ ε * 2 * (edgeFinset G).card := le_mul_of_one_le_left (by positivity) (by assumption) _ < ε * card α ^ 2 := ?_ rw [mul_assoc, mul_lt_mul_left hε₀] norm_cast calc _ ≤ 2 * (⊤ : SimpleGraph α).edgeFinset.card := by gcongr; exact le_top _ < card α ^ 2 := ?_ rw [edgeFinset_top, filter_not, card_sdiff (subset_univ _), card_univ, Sym2.card,] simp_rw [choose_two_right, Nat.add_sub_cancel, Nat.mul_comm _ (card α), Sym2.isDiag_iff_mem_range_diag, univ_filter_mem_range, mul_tsub, Nat.mul_div_cancel' (card α).even_mul_succ_self.two_dvd] rw [card_image_of_injective _ Sym2.diag_injective, card_univ, mul_add_one (α := ℕ), two_mul, sq, add_tsub_add_eq_tsub_right] apply tsub_lt_self <;> positivity lemma FarFromTriangleFree.lt_one (hG : G.FarFromTriangleFree ε) : ε < 1 := hG.lt_half.trans $ inv_lt_one one_lt_two
Mathlib/Combinatorics/SimpleGraph/Triangle/Basic.lean
279
283
theorem FarFromTriangleFree.nonpos (h₀ : G.FarFromTriangleFree ε) (h₁ : G.CliqueFree 3) : ε ≤ 0 := by
have := h₀ (empty_subset _) rw [coe_empty, Finset.card_empty, cast_zero, deleteEdges_empty] at this exact nonpos_of_mul_nonpos_left (this h₁) (cast_pos.2 <| sq_pos_of_pos Fintype.card_pos)
/- Copyright (c) 2022 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.NumberTheory.BernoulliPolynomials import Mathlib.MeasureTheory.Integral.IntervalIntegral import Mathlib.Analysis.Calculus.Deriv.Polynomial import Mathlib.Analysis.Fourier.AddCircle import Mathlib.Analysis.PSeries #align_import number_theory.zeta_values from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9" /-! # Critical values of the Riemann zeta function In this file we prove formulae for the critical values of `ζ(s)`, and more generally of Hurwitz zeta functions, in terms of Bernoulli polynomials. ## Main results: * `hasSum_zeta_nat`: the final formula for zeta values, $$\zeta(2k) = \frac{(-1)^{(k + 1)} 2 ^ {2k - 1} \pi^{2k} B_{2 k}}{(2 k)!}.$$ * `hasSum_zeta_two` and `hasSum_zeta_four`: special cases given explicitly. * `hasSum_one_div_nat_pow_mul_cos`: a formula for the sum `∑ (n : ℕ), cos (2 π i n x) / n ^ k` as an explicit multiple of `Bₖ(x)`, for any `x ∈ [0, 1]` and `k ≥ 2` even. * `hasSum_one_div_nat_pow_mul_sin`: a formula for the sum `∑ (n : ℕ), sin (2 π i n x) / n ^ k` as an explicit multiple of `Bₖ(x)`, for any `x ∈ [0, 1]` and `k ≥ 3` odd. -/ noncomputable section open scoped Nat Real Interval open Complex MeasureTheory Set intervalIntegral local notation "𝕌" => UnitAddCircle section BernoulliFunProps /-! Simple properties of the Bernoulli polynomial, as a function `ℝ → ℝ`. -/ /-- The function `x ↦ Bₖ(x) : ℝ → ℝ`. -/ def bernoulliFun (k : ℕ) (x : ℝ) : ℝ := (Polynomial.map (algebraMap ℚ ℝ) (Polynomial.bernoulli k)).eval x #align bernoulli_fun bernoulliFun theorem bernoulliFun_eval_zero (k : ℕ) : bernoulliFun k 0 = bernoulli k := by rw [bernoulliFun, Polynomial.eval_zero_map, Polynomial.bernoulli_eval_zero, eq_ratCast] #align bernoulli_fun_eval_zero bernoulliFun_eval_zero theorem bernoulliFun_endpoints_eq_of_ne_one {k : ℕ} (hk : k ≠ 1) : bernoulliFun k 1 = bernoulliFun k 0 := by rw [bernoulliFun_eval_zero, bernoulliFun, Polynomial.eval_one_map, Polynomial.bernoulli_eval_one, bernoulli_eq_bernoulli'_of_ne_one hk, eq_ratCast] #align bernoulli_fun_endpoints_eq_of_ne_one bernoulliFun_endpoints_eq_of_ne_one
Mathlib/NumberTheory/ZetaValues.lean
59
64
theorem bernoulliFun_eval_one (k : ℕ) : bernoulliFun k 1 = bernoulliFun k 0 + ite (k = 1) 1 0 := by
rw [bernoulliFun, bernoulliFun_eval_zero, Polynomial.eval_one_map, Polynomial.bernoulli_eval_one] split_ifs with h · rw [h, bernoulli_one, bernoulli'_one, eq_ratCast] push_cast; ring · rw [bernoulli_eq_bernoulli'_of_ne_one h, add_zero, eq_ratCast]
/- 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.Order.Atoms import Mathlib.Order.OrderIsoNat import Mathlib.Order.RelIso.Set import Mathlib.Order.SupClosed import Mathlib.Order.SupIndep import Mathlib.Order.Zorn import Mathlib.Data.Finset.Order import Mathlib.Order.Interval.Set.OrderIso import Mathlib.Data.Finite.Set import Mathlib.Tactic.TFAE #align_import order.compactly_generated from "leanprover-community/mathlib"@"c813ed7de0f5115f956239124e9b30f3a621966f" /-! # Compactness properties for complete lattices For complete lattices, there are numerous equivalent ways to express the fact that the relation `>` is well-founded. In this file we define three especially-useful characterisations and provide proofs that they are indeed equivalent to well-foundedness. ## Main definitions * `CompleteLattice.IsSupClosedCompact` * `CompleteLattice.IsSupFiniteCompact` * `CompleteLattice.IsCompactElement` * `IsCompactlyGenerated` ## Main results The main result is that the following four conditions are equivalent for a complete lattice: * `well_founded (>)` * `CompleteLattice.IsSupClosedCompact` * `CompleteLattice.IsSupFiniteCompact` * `∀ k, CompleteLattice.IsCompactElement k` This is demonstrated by means of the following four lemmas: * `CompleteLattice.WellFounded.isSupFiniteCompact` * `CompleteLattice.IsSupFiniteCompact.isSupClosedCompact` * `CompleteLattice.IsSupClosedCompact.wellFounded` * `CompleteLattice.isSupFiniteCompact_iff_all_elements_compact` We also show well-founded lattices are compactly generated (`CompleteLattice.isCompactlyGenerated_of_wellFounded`). ## References - [G. Călugăreanu, *Lattice Concepts of Module Theory*][calugareanu] ## Tags complete lattice, well-founded, compact -/ open Set variable {ι : Sort*} {α : Type*} [CompleteLattice α] {f : ι → α} namespace CompleteLattice variable (α) /-- A compactness property for a complete lattice is that any `sup`-closed non-empty subset contains its `sSup`. -/ def IsSupClosedCompact : Prop := ∀ (s : Set α) (_ : s.Nonempty), SupClosed s → sSup s ∈ s #align complete_lattice.is_sup_closed_compact CompleteLattice.IsSupClosedCompact /-- A compactness property for a complete lattice is that any subset has a finite subset with the same `sSup`. -/ def IsSupFiniteCompact : Prop := ∀ s : Set α, ∃ t : Finset α, ↑t ⊆ s ∧ sSup s = t.sup id #align complete_lattice.is_Sup_finite_compact CompleteLattice.IsSupFiniteCompact /-- An element `k` of a complete lattice is said to be compact if any set with `sSup` above `k` has a finite subset with `sSup` above `k`. Such an element is also called "finite" or "S-compact". -/ def IsCompactElement {α : Type*} [CompleteLattice α] (k : α) := ∀ s : Set α, k ≤ sSup s → ∃ t : Finset α, ↑t ⊆ s ∧ k ≤ t.sup id #align complete_lattice.is_compact_element CompleteLattice.IsCompactElement theorem isCompactElement_iff.{u} {α : Type u} [CompleteLattice α] (k : α) : CompleteLattice.IsCompactElement k ↔ ∀ (ι : Type u) (s : ι → α), k ≤ iSup s → ∃ t : Finset ι, k ≤ t.sup s := by classical constructor · intro H ι s hs obtain ⟨t, ht, ht'⟩ := H (Set.range s) hs have : ∀ x : t, ∃ i, s i = x := fun x => ht x.prop choose f hf using this refine ⟨Finset.univ.image f, ht'.trans ?_⟩ rw [Finset.sup_le_iff] intro b hb rw [← show s (f ⟨b, hb⟩) = id b from hf _] exact Finset.le_sup (Finset.mem_image_of_mem f <| Finset.mem_univ (Subtype.mk b hb)) · intro H s hs obtain ⟨t, ht⟩ := H s Subtype.val (by delta iSup rwa [Subtype.range_coe]) refine ⟨t.image Subtype.val, by simp, ht.trans ?_⟩ rw [Finset.sup_le_iff] exact fun x hx => @Finset.le_sup _ _ _ _ _ id _ (Finset.mem_image_of_mem Subtype.val hx) #align complete_lattice.is_compact_element_iff CompleteLattice.isCompactElement_iff /-- An element `k` is compact if and only if any directed set with `sSup` above `k` already got above `k` at some point in the set. -/ theorem isCompactElement_iff_le_of_directed_sSup_le (k : α) : IsCompactElement k ↔ ∀ s : Set α, s.Nonempty → DirectedOn (· ≤ ·) s → k ≤ sSup s → ∃ x : α, x ∈ s ∧ k ≤ x := by classical constructor · intro hk s hne hdir hsup obtain ⟨t, ht⟩ := hk s hsup -- certainly every element of t is below something in s, since ↑t ⊆ s. have t_below_s : ∀ x ∈ t, ∃ y ∈ s, x ≤ y := fun x hxt => ⟨x, ht.left hxt, le_rfl⟩ obtain ⟨x, ⟨hxs, hsupx⟩⟩ := Finset.sup_le_of_le_directed s hne hdir t t_below_s exact ⟨x, ⟨hxs, le_trans ht.right hsupx⟩⟩ · intro hk s hsup -- Consider the set of finite joins of elements of the (plain) set s. let S : Set α := { x | ∃ t : Finset α, ↑t ⊆ s ∧ x = t.sup id } -- S is directed, nonempty, and still has sup above k. have dir_US : DirectedOn (· ≤ ·) S := by rintro x ⟨c, hc⟩ y ⟨d, hd⟩ use x ⊔ y constructor · use c ∪ d constructor · simp only [hc.left, hd.left, Set.union_subset_iff, Finset.coe_union, and_self_iff] · simp only [hc.right, hd.right, Finset.sup_union] simp only [and_self_iff, le_sup_left, le_sup_right] have sup_S : sSup s ≤ sSup S := by apply sSup_le_sSup intro x hx use {x} simpa only [and_true_iff, id, Finset.coe_singleton, eq_self_iff_true, Finset.sup_singleton, Set.singleton_subset_iff] have Sne : S.Nonempty := by suffices ⊥ ∈ S from Set.nonempty_of_mem this use ∅ simp only [Set.empty_subset, Finset.coe_empty, Finset.sup_empty, eq_self_iff_true, and_self_iff] -- Now apply the defn of compact and finish. obtain ⟨j, ⟨hjS, hjk⟩⟩ := hk S Sne dir_US (le_trans hsup sup_S) obtain ⟨t, ⟨htS, htsup⟩⟩ := hjS use t exact ⟨htS, by rwa [← htsup]⟩ #align complete_lattice.is_compact_element_iff_le_of_directed_Sup_le CompleteLattice.isCompactElement_iff_le_of_directed_sSup_le theorem IsCompactElement.exists_finset_of_le_iSup {k : α} (hk : IsCompactElement k) {ι : Type*} (f : ι → α) (h : k ≤ ⨆ i, f i) : ∃ s : Finset ι, k ≤ ⨆ i ∈ s, f i := by classical let g : Finset ι → α := fun s => ⨆ i ∈ s, f i have h1 : DirectedOn (· ≤ ·) (Set.range g) := by rintro - ⟨s, rfl⟩ - ⟨t, rfl⟩ exact ⟨g (s ∪ t), ⟨s ∪ t, rfl⟩, iSup_le_iSup_of_subset Finset.subset_union_left, iSup_le_iSup_of_subset Finset.subset_union_right⟩ have h2 : k ≤ sSup (Set.range g) := h.trans (iSup_le fun i => le_sSup_of_le ⟨{i}, rfl⟩ (le_iSup_of_le i (le_iSup_of_le (Finset.mem_singleton_self i) le_rfl))) obtain ⟨-, ⟨s, rfl⟩, hs⟩ := (isCompactElement_iff_le_of_directed_sSup_le α k).mp hk (Set.range g) (Set.range_nonempty g) h1 h2 exact ⟨s, hs⟩ #align complete_lattice.is_compact_element.exists_finset_of_le_supr CompleteLattice.IsCompactElement.exists_finset_of_le_iSup /-- A compact element `k` has the property that any directed set lying strictly below `k` has its `sSup` strictly below `k`. -/ theorem IsCompactElement.directed_sSup_lt_of_lt {α : Type*} [CompleteLattice α] {k : α} (hk : IsCompactElement k) {s : Set α} (hemp : s.Nonempty) (hdir : DirectedOn (· ≤ ·) s) (hbelow : ∀ x ∈ s, x < k) : sSup s < k := by rw [isCompactElement_iff_le_of_directed_sSup_le] at hk by_contra h have sSup' : sSup s ≤ k := sSup_le s k fun s hs => (hbelow s hs).le replace sSup : sSup s = k := eq_iff_le_not_lt.mpr ⟨sSup', h⟩ obtain ⟨x, hxs, hkx⟩ := hk s hemp hdir sSup.symm.le obtain hxk := hbelow x hxs exact hxk.ne (hxk.le.antisymm hkx) #align complete_lattice.is_compact_element.directed_Sup_lt_of_lt CompleteLattice.IsCompactElement.directed_sSup_lt_of_lt theorem isCompactElement_finsetSup {α β : Type*} [CompleteLattice α] {f : β → α} (s : Finset β) (h : ∀ x ∈ s, IsCompactElement (f x)) : IsCompactElement (s.sup f) := by classical rw [isCompactElement_iff_le_of_directed_sSup_le] intro d hemp hdir hsup rw [← Function.id_comp f] rw [← Finset.sup_image] apply Finset.sup_le_of_le_directed d hemp hdir rintro x hx obtain ⟨p, ⟨hps, rfl⟩⟩ := Finset.mem_image.mp hx specialize h p hps rw [isCompactElement_iff_le_of_directed_sSup_le] at h specialize h d hemp hdir (le_trans (Finset.le_sup hps) hsup) simpa only [exists_prop] #align complete_lattice.finset_sup_compact_of_compact CompleteLattice.isCompactElement_finsetSup theorem WellFounded.isSupFiniteCompact (h : WellFounded ((· > ·) : α → α → Prop)) : IsSupFiniteCompact α := fun s => by let S := { x | ∃ t : Finset α, ↑t ⊆ s ∧ t.sup id = x } obtain ⟨m, ⟨t, ⟨ht₁, rfl⟩⟩, hm⟩ := h.has_min S ⟨⊥, ∅, by simp⟩ refine ⟨t, ht₁, (sSup_le _ _ fun y hy => ?_).antisymm ?_⟩ · classical rw [eq_of_le_of_not_lt (Finset.sup_mono (t.subset_insert y)) (hm _ ⟨insert y t, by simp [Set.insert_subset_iff, hy, ht₁]⟩)] simp · rw [Finset.sup_id_eq_sSup] exact sSup_le_sSup ht₁ #align complete_lattice.well_founded.is_Sup_finite_compact CompleteLattice.WellFounded.isSupFiniteCompact theorem IsSupFiniteCompact.isSupClosedCompact (h : IsSupFiniteCompact α) : IsSupClosedCompact α := by intro s hne hsc; obtain ⟨t, ht₁, ht₂⟩ := h s; clear h rcases t.eq_empty_or_nonempty with h | h · subst h rw [Finset.sup_empty] at ht₂ rw [ht₂] simp [eq_singleton_bot_of_sSup_eq_bot_of_nonempty ht₂ hne] · rw [ht₂] exact hsc.finsetSup_mem h ht₁ #align complete_lattice.is_Sup_finite_compact.is_sup_closed_compact CompleteLattice.IsSupFiniteCompact.isSupClosedCompact theorem IsSupClosedCompact.wellFounded (h : IsSupClosedCompact α) : WellFounded ((· > ·) : α → α → Prop) := by refine RelEmbedding.wellFounded_iff_no_descending_seq.mpr ⟨fun a => ?_⟩ suffices sSup (Set.range a) ∈ Set.range a by obtain ⟨n, hn⟩ := Set.mem_range.mp this have h' : sSup (Set.range a) < a (n + 1) := by change _ > _ simp [← hn, a.map_rel_iff] apply lt_irrefl (a (n + 1)) apply lt_of_le_of_lt _ h' apply le_sSup apply Set.mem_range_self apply h (Set.range a) · use a 37 apply Set.mem_range_self · rintro x ⟨m, hm⟩ y ⟨n, hn⟩ use m ⊔ n rw [← hm, ← hn] apply RelHomClass.map_sup a #align complete_lattice.is_sup_closed_compact.well_founded CompleteLattice.IsSupClosedCompact.wellFounded theorem isSupFiniteCompact_iff_all_elements_compact : IsSupFiniteCompact α ↔ ∀ k : α, IsCompactElement k := by refine ⟨fun h k s hs => ?_, fun h s => ?_⟩ · obtain ⟨t, ⟨hts, htsup⟩⟩ := h s use t, hts rwa [← htsup] · obtain ⟨t, ⟨hts, htsup⟩⟩ := h (sSup s) s (by rfl) have : sSup s = t.sup id := by suffices t.sup id ≤ sSup s by apply le_antisymm <;> assumption simp only [id, Finset.sup_le_iff] intro x hx exact le_sSup _ _ (hts hx) exact ⟨t, hts, this⟩ #align complete_lattice.is_Sup_finite_compact_iff_all_elements_compact CompleteLattice.isSupFiniteCompact_iff_all_elements_compact open List in theorem wellFounded_characterisations : List.TFAE [WellFounded ((· > ·) : α → α → Prop), IsSupFiniteCompact α, IsSupClosedCompact α, ∀ k : α, IsCompactElement k] := by tfae_have 1 → 2 · exact WellFounded.isSupFiniteCompact α tfae_have 2 → 3 · exact IsSupFiniteCompact.isSupClosedCompact α tfae_have 3 → 1 · exact IsSupClosedCompact.wellFounded α tfae_have 2 ↔ 4 · exact isSupFiniteCompact_iff_all_elements_compact α tfae_finish #align complete_lattice.well_founded_characterisations CompleteLattice.wellFounded_characterisations theorem wellFounded_iff_isSupFiniteCompact : WellFounded ((· > ·) : α → α → Prop) ↔ IsSupFiniteCompact α := (wellFounded_characterisations α).out 0 1 #align complete_lattice.well_founded_iff_is_Sup_finite_compact CompleteLattice.wellFounded_iff_isSupFiniteCompact theorem isSupFiniteCompact_iff_isSupClosedCompact : IsSupFiniteCompact α ↔ IsSupClosedCompact α := (wellFounded_characterisations α).out 1 2 #align complete_lattice.is_Sup_finite_compact_iff_is_sup_closed_compact CompleteLattice.isSupFiniteCompact_iff_isSupClosedCompact theorem isSupClosedCompact_iff_wellFounded : IsSupClosedCompact α ↔ WellFounded ((· > ·) : α → α → Prop) := (wellFounded_characterisations α).out 2 0 #align complete_lattice.is_sup_closed_compact_iff_well_founded CompleteLattice.isSupClosedCompact_iff_wellFounded alias ⟨_, IsSupFiniteCompact.wellFounded⟩ := wellFounded_iff_isSupFiniteCompact #align complete_lattice.is_Sup_finite_compact.well_founded CompleteLattice.IsSupFiniteCompact.wellFounded alias ⟨_, IsSupClosedCompact.isSupFiniteCompact⟩ := isSupFiniteCompact_iff_isSupClosedCompact #align complete_lattice.is_sup_closed_compact.is_Sup_finite_compact CompleteLattice.IsSupClosedCompact.isSupFiniteCompact alias ⟨_, _root_.WellFounded.isSupClosedCompact⟩ := isSupClosedCompact_iff_wellFounded #align well_founded.is_sup_closed_compact WellFounded.isSupClosedCompact variable {α} theorem WellFounded.finite_of_setIndependent (h : WellFounded ((· > ·) : α → α → Prop)) {s : Set α} (hs : SetIndependent s) : s.Finite := by classical refine Set.not_infinite.mp fun contra => ?_ obtain ⟨t, ht₁, ht₂⟩ := WellFounded.isSupFiniteCompact α h s replace contra : ∃ x : α, x ∈ s ∧ x ≠ ⊥ ∧ x ∉ t := by have : (s \ (insert ⊥ t : Finset α)).Infinite := contra.diff (Finset.finite_toSet _) obtain ⟨x, hx₁, hx₂⟩ := this.nonempty exact ⟨x, hx₁, by simpa [not_or] using hx₂⟩ obtain ⟨x, hx₀, hx₁, hx₂⟩ := contra replace hs : x ⊓ sSup s = ⊥ := by have := hs.mono (by simp [ht₁, hx₀, -Set.union_singleton] : ↑t ∪ {x} ≤ s) (by simp : x ∈ _) simpa [Disjoint, hx₂, ← t.sup_id_eq_sSup, ← ht₂] using this.eq_bot apply hx₁ rw [← hs, eq_comm, inf_eq_left] exact le_sSup _ _ hx₀ #align complete_lattice.well_founded.finite_of_set_independent CompleteLattice.WellFounded.finite_of_setIndependent theorem WellFounded.finite_ne_bot_of_independent (hwf : WellFounded ((· > ·) : α → α → Prop)) {ι : Type*} {t : ι → α} (ht : Independent t) : Set.Finite {i | t i ≠ ⊥} := by refine Finite.of_finite_image (Finite.subset ?_ (image_subset_range t _)) ht.injOn exact WellFounded.finite_of_setIndependent hwf ht.setIndependent_range theorem WellFounded.finite_of_independent (hwf : WellFounded ((· > ·) : α → α → Prop)) {ι : Type*} {t : ι → α} (ht : Independent t) (h_ne_bot : ∀ i, t i ≠ ⊥) : Finite ι := haveI := (WellFounded.finite_of_setIndependent hwf ht.setIndependent_range).to_subtype Finite.of_injective_finite_range (ht.injective h_ne_bot) #align complete_lattice.well_founded.finite_of_independent CompleteLattice.WellFounded.finite_of_independent end CompleteLattice /-- A complete lattice is said to be compactly generated if any element is the `sSup` of compact elements. -/ class IsCompactlyGenerated (α : Type*) [CompleteLattice α] : Prop where /-- In a compactly generated complete lattice, every element is the `sSup` of some set of compact elements. -/ exists_sSup_eq : ∀ x : α, ∃ s : Set α, (∀ x ∈ s, CompleteLattice.IsCompactElement x) ∧ sSup s = x #align is_compactly_generated IsCompactlyGenerated section variable [CompleteLattice α] [IsCompactlyGenerated α] {a b : α} {s : Set α} @[simp] theorem sSup_compact_le_eq (b) : sSup { c : α | CompleteLattice.IsCompactElement c ∧ c ≤ b } = b := by rcases IsCompactlyGenerated.exists_sSup_eq b with ⟨s, hs, rfl⟩ exact le_antisymm (sSup_le fun c hc => hc.2) (sSup_le_sSup fun c cs => ⟨hs c cs, le_sSup cs⟩) #align Sup_compact_le_eq sSup_compact_le_eq @[simp] theorem sSup_compact_eq_top : sSup { a : α | CompleteLattice.IsCompactElement a } = ⊤ := by refine Eq.trans (congr rfl (Set.ext fun x => ?_)) (sSup_compact_le_eq ⊤) exact (and_iff_left le_top).symm #align Sup_compact_eq_top sSup_compact_eq_top theorem le_iff_compact_le_imp {a b : α} : a ≤ b ↔ ∀ c : α, CompleteLattice.IsCompactElement c → c ≤ a → c ≤ b := ⟨fun ab c _ ca => le_trans ca ab, fun h => by rw [← sSup_compact_le_eq a, ← sSup_compact_le_eq b] exact sSup_le_sSup fun c hc => ⟨hc.1, h c hc.1 hc.2⟩⟩ #align le_iff_compact_le_imp le_iff_compact_le_imp /-- This property is sometimes referred to as `α` being upper continuous. -/ theorem DirectedOn.inf_sSup_eq (h : DirectedOn (· ≤ ·) s) : a ⊓ sSup s = ⨆ b ∈ s, a ⊓ b := le_antisymm (by rw [le_iff_compact_le_imp] by_cases hs : s.Nonempty · intro c hc hcinf rw [le_inf_iff] at hcinf rw [CompleteLattice.isCompactElement_iff_le_of_directed_sSup_le] at hc rcases hc s hs h hcinf.2 with ⟨d, ds, cd⟩ refine (le_inf hcinf.1 cd).trans (le_trans ?_ (le_iSup₂ d ds)) rfl · rw [Set.not_nonempty_iff_eq_empty] at hs simp [hs]) iSup_inf_le_inf_sSup #align directed_on.inf_Sup_eq DirectedOn.inf_sSup_eq /-- This property is sometimes referred to as `α` being upper continuous. -/ protected theorem DirectedOn.sSup_inf_eq (h : DirectedOn (· ≤ ·) s) : sSup s ⊓ a = ⨆ b ∈ s, b ⊓ a := by simp_rw [inf_comm _ a, h.inf_sSup_eq] #align directed_on.Sup_inf_eq DirectedOn.sSup_inf_eq protected theorem Directed.inf_iSup_eq (h : Directed (· ≤ ·) f) : (a ⊓ ⨆ i, f i) = ⨆ i, a ⊓ f i := by rw [iSup, h.directedOn_range.inf_sSup_eq, iSup_range] #align directed.inf_supr_eq Directed.inf_iSup_eq protected theorem Directed.iSup_inf_eq (h : Directed (· ≤ ·) f) : (⨆ i, f i) ⊓ a = ⨆ i, f i ⊓ a := by rw [iSup, h.directedOn_range.sSup_inf_eq, iSup_range] #align directed.supr_inf_eq Directed.iSup_inf_eq protected theorem DirectedOn.disjoint_sSup_right (h : DirectedOn (· ≤ ·) s) : Disjoint a (sSup s) ↔ ∀ ⦃b⦄, b ∈ s → Disjoint a b := by simp_rw [disjoint_iff, h.inf_sSup_eq, iSup_eq_bot] #align directed_on.disjoint_Sup_right DirectedOn.disjoint_sSup_right protected theorem DirectedOn.disjoint_sSup_left (h : DirectedOn (· ≤ ·) s) : Disjoint (sSup s) a ↔ ∀ ⦃b⦄, b ∈ s → Disjoint b a := by simp_rw [disjoint_iff, h.sSup_inf_eq, iSup_eq_bot] #align directed_on.disjoint_Sup_left DirectedOn.disjoint_sSup_left protected theorem Directed.disjoint_iSup_right (h : Directed (· ≤ ·) f) : Disjoint a (⨆ i, f i) ↔ ∀ i, Disjoint a (f i) := by simp_rw [disjoint_iff, h.inf_iSup_eq, iSup_eq_bot] #align directed.disjoint_supr_right Directed.disjoint_iSup_right protected theorem Directed.disjoint_iSup_left (h : Directed (· ≤ ·) f) : Disjoint (⨆ i, f i) a ↔ ∀ i, Disjoint (f i) a := by simp_rw [disjoint_iff, h.iSup_inf_eq, iSup_eq_bot] #align directed.disjoint_supr_left Directed.disjoint_iSup_left /-- This property is equivalent to `α` being upper continuous. -/ theorem inf_sSup_eq_iSup_inf_sup_finset : a ⊓ sSup s = ⨆ (t : Finset α) (_ : ↑t ⊆ s), a ⊓ t.sup id := le_antisymm (by rw [le_iff_compact_le_imp] intro c hc hcinf rw [le_inf_iff] at hcinf rcases hc s hcinf.2 with ⟨t, ht1, ht2⟩ refine (le_inf hcinf.1 ht2).trans (le_trans ?_ (le_iSup₂ t ht1)) rfl) (iSup_le fun t => iSup_le fun h => inf_le_inf_left _ ((Finset.sup_id_eq_sSup t).symm ▸ sSup_le_sSup h)) #align inf_Sup_eq_supr_inf_sup_finset inf_sSup_eq_iSup_inf_sup_finset theorem CompleteLattice.setIndependent_iff_finite {s : Set α} : CompleteLattice.SetIndependent s ↔ ∀ t : Finset α, ↑t ⊆ s → CompleteLattice.SetIndependent (↑t : Set α) := ⟨fun hs t ht => hs.mono ht, fun h a ha => by rw [disjoint_iff, inf_sSup_eq_iSup_inf_sup_finset, iSup_eq_bot] intro t rw [iSup_eq_bot, Finset.sup_id_eq_sSup] intro ht classical have h' := (h (insert a t) ?_ (t.mem_insert_self a)).eq_bot · rwa [Finset.coe_insert, Set.insert_diff_self_of_not_mem] at h' exact fun con => ((Set.mem_diff a).1 (ht con)).2 (Set.mem_singleton a) · rw [Finset.coe_insert, Set.insert_subset_iff] exact ⟨ha, Set.Subset.trans ht diff_subset⟩⟩ #align complete_lattice.set_independent_iff_finite CompleteLattice.setIndependent_iff_finite lemma CompleteLattice.independent_iff_supIndep_of_injOn {ι : Type*} {f : ι → α} (hf : InjOn f {i | f i ≠ ⊥}) : CompleteLattice.Independent f ↔ ∀ (s : Finset ι), s.SupIndep f := by refine ⟨fun h ↦ h.supIndep', fun h ↦ CompleteLattice.independent_def'.mpr fun i ↦ ?_⟩ simp_rw [disjoint_iff, inf_sSup_eq_iSup_inf_sup_finset, iSup_eq_bot, ← disjoint_iff] intro s hs classical rw [← Finset.sup_erase_bot] set t := s.erase ⊥ replace hf : InjOn f (f ⁻¹' t) := fun i hi j _ hij ↦ by refine hf ?_ ?_ hij <;> aesop (add norm simp [t]) have : (Finset.erase (insert i (t.preimage _ hf)) i).image f = t := by ext a simp only [Finset.mem_preimage, Finset.mem_erase, ne_eq, Finset.mem_insert, true_or, not_true, Finset.erase_insert_eq_erase, not_and, Finset.mem_image, t] refine ⟨by aesop, fun ⟨ha, has⟩ ↦ ?_⟩ obtain ⟨j, hj, rfl⟩ := hs has exact ⟨j, ⟨hj, ha, has⟩, rfl⟩ rw [← this, Finset.sup_image] specialize h (insert i (t.preimage _ hf)) rw [Finset.supIndep_iff_disjoint_erase] at h exact h i (Finset.mem_insert_self i _) theorem CompleteLattice.setIndependent_iUnion_of_directed {η : Type*} {s : η → Set α} (hs : Directed (· ⊆ ·) s) (h : ∀ i, CompleteLattice.SetIndependent (s i)) : CompleteLattice.SetIndependent (⋃ i, s i) := by by_cases hη : Nonempty η · rw [CompleteLattice.setIndependent_iff_finite] intro t ht obtain ⟨I, fi, hI⟩ := Set.finite_subset_iUnion t.finite_toSet ht obtain ⟨i, hi⟩ := hs.finset_le fi.toFinset exact (h i).mono (Set.Subset.trans hI <| Set.iUnion₂_subset fun j hj => hi j (fi.mem_toFinset.2 hj)) · rintro a ⟨_, ⟨i, _⟩, _⟩ exfalso exact hη ⟨i⟩ #align complete_lattice.set_independent_Union_of_directed CompleteLattice.setIndependent_iUnion_of_directed theorem CompleteLattice.independent_sUnion_of_directed {s : Set (Set α)} (hs : DirectedOn (· ⊆ ·) s) (h : ∀ a ∈ s, CompleteLattice.SetIndependent a) : CompleteLattice.SetIndependent (⋃₀ s) := by rw [Set.sUnion_eq_iUnion] exact CompleteLattice.setIndependent_iUnion_of_directed hs.directed_val (by simpa using h) #align complete_lattice.independent_sUnion_of_directed CompleteLattice.independent_sUnion_of_directed end namespace CompleteLattice
Mathlib/Order/CompactlyGenerated/Basic.lean
498
502
theorem isCompactlyGenerated_of_wellFounded (h : WellFounded ((· > ·) : α → α → Prop)) : IsCompactlyGenerated α := by
rw [wellFounded_iff_isSupFiniteCompact, isSupFiniteCompact_iff_all_elements_compact] at h -- x is the join of the set of compact elements {x} exact ⟨fun x => ⟨{x}, ⟨fun x _ => h x, sSup_singleton⟩⟩⟩
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.MeasureTheory.Measure.MeasureSpace /-! # Restricting a measure to a subset or a subtype Given a measure `μ` on a type `α` and a subset `s` of `α`, we define a measure `μ.restrict s` as the restriction of `μ` to `s` (still as a measure on `α`). We investigate how this notion interacts with usual operations on measures (sum, pushforward, pullback), and on sets (inclusion, union, Union). We also study the relationship between the restriction of a measure to a subtype (given by the pullback under `Subtype.val`) and the restriction to a set as above. -/ open scoped ENNReal NNReal Topology open Set MeasureTheory Measure Filter MeasurableSpace ENNReal Function variable {R α β δ γ ι : Type*} namespace MeasureTheory variable {m0 : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ] variable {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : Measure α} {s s' t : Set α} namespace Measure /-! ### Restricting a measure -/ /-- Restrict a measure `μ` to a set `s` as an `ℝ≥0∞`-linear map. -/ noncomputable def restrictₗ {m0 : MeasurableSpace α} (s : Set α) : Measure α →ₗ[ℝ≥0∞] Measure α := liftLinear (OuterMeasure.restrict s) fun μ s' hs' t => by suffices μ (s ∩ t) = μ (s ∩ t ∩ s') + μ ((s ∩ t) \ s') by simpa [← Set.inter_assoc, Set.inter_comm _ s, ← inter_diff_assoc] exact le_toOuterMeasure_caratheodory _ _ hs' _ #align measure_theory.measure.restrictₗ MeasureTheory.Measure.restrictₗ /-- Restrict a measure `μ` to a set `s`. -/ noncomputable def restrict {_m0 : MeasurableSpace α} (μ : Measure α) (s : Set α) : Measure α := restrictₗ s μ #align measure_theory.measure.restrict MeasureTheory.Measure.restrict @[simp] theorem restrictₗ_apply {_m0 : MeasurableSpace α} (s : Set α) (μ : Measure α) : restrictₗ s μ = μ.restrict s := rfl #align measure_theory.measure.restrictₗ_apply MeasureTheory.Measure.restrictₗ_apply /-- This lemma shows that `restrict` and `toOuterMeasure` commute. Note that the LHS has a restrict on measures and the RHS has a restrict on outer measures. -/ theorem restrict_toOuterMeasure_eq_toOuterMeasure_restrict (h : MeasurableSet s) : (μ.restrict s).toOuterMeasure = OuterMeasure.restrict s μ.toOuterMeasure := by simp_rw [restrict, restrictₗ, liftLinear, LinearMap.coe_mk, AddHom.coe_mk, toMeasure_toOuterMeasure, OuterMeasure.restrict_trim h, μ.trimmed] #align measure_theory.measure.restrict_to_outer_measure_eq_to_outer_measure_restrict MeasureTheory.Measure.restrict_toOuterMeasure_eq_toOuterMeasure_restrict theorem restrict_apply₀ (ht : NullMeasurableSet t (μ.restrict s)) : μ.restrict s t = μ (t ∩ s) := by rw [← restrictₗ_apply, restrictₗ, liftLinear_apply₀ _ ht, OuterMeasure.restrict_apply, coe_toOuterMeasure] #align measure_theory.measure.restrict_apply₀ MeasureTheory.Measure.restrict_apply₀ /-- If `t` is a measurable set, then the measure of `t` with respect to the restriction of the measure to `s` equals the outer measure of `t ∩ s`. An alternate version requiring that `s` be measurable instead of `t` exists as `Measure.restrict_apply'`. -/ @[simp] theorem restrict_apply (ht : MeasurableSet t) : μ.restrict s t = μ (t ∩ s) := restrict_apply₀ ht.nullMeasurableSet #align measure_theory.measure.restrict_apply MeasureTheory.Measure.restrict_apply /-- Restriction of a measure to a subset is monotone both in set and in measure. -/ theorem restrict_mono' {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ ⦃μ ν : Measure α⦄ (hs : s ≤ᵐ[μ] s') (hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' := Measure.le_iff.2 fun t ht => calc μ.restrict s t = μ (t ∩ s) := restrict_apply ht _ ≤ μ (t ∩ s') := (measure_mono_ae <| hs.mono fun _x hx ⟨hxt, hxs⟩ => ⟨hxt, hx hxs⟩) _ ≤ ν (t ∩ s') := le_iff'.1 hμν (t ∩ s') _ = ν.restrict s' t := (restrict_apply ht).symm #align measure_theory.measure.restrict_mono' MeasureTheory.Measure.restrict_mono' /-- Restriction of a measure to a subset is monotone both in set and in measure. -/ @[mono] theorem restrict_mono {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ (hs : s ⊆ s') ⦃μ ν : Measure α⦄ (hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' := restrict_mono' (ae_of_all _ hs) hμν #align measure_theory.measure.restrict_mono MeasureTheory.Measure.restrict_mono theorem restrict_mono_ae (h : s ≤ᵐ[μ] t) : μ.restrict s ≤ μ.restrict t := restrict_mono' h (le_refl μ) #align measure_theory.measure.restrict_mono_ae MeasureTheory.Measure.restrict_mono_ae theorem restrict_congr_set (h : s =ᵐ[μ] t) : μ.restrict s = μ.restrict t := le_antisymm (restrict_mono_ae h.le) (restrict_mono_ae h.symm.le) #align measure_theory.measure.restrict_congr_set MeasureTheory.Measure.restrict_congr_set /-- If `s` is a measurable set, then the outer measure of `t` with respect to the restriction of the measure to `s` equals the outer measure of `t ∩ s`. This is an alternate version of `Measure.restrict_apply`, requiring that `s` is measurable instead of `t`. -/ @[simp] theorem restrict_apply' (hs : MeasurableSet s) : μ.restrict s t = μ (t ∩ s) := by rw [← toOuterMeasure_apply, Measure.restrict_toOuterMeasure_eq_toOuterMeasure_restrict hs, OuterMeasure.restrict_apply s t _, toOuterMeasure_apply] #align measure_theory.measure.restrict_apply' MeasureTheory.Measure.restrict_apply' theorem restrict_apply₀' (hs : NullMeasurableSet s μ) : μ.restrict s t = μ (t ∩ s) := by rw [← restrict_congr_set hs.toMeasurable_ae_eq, restrict_apply' (measurableSet_toMeasurable _ _), measure_congr ((ae_eq_refl t).inter hs.toMeasurable_ae_eq)] #align measure_theory.measure.restrict_apply₀' MeasureTheory.Measure.restrict_apply₀' theorem restrict_le_self : μ.restrict s ≤ μ := Measure.le_iff.2 fun t ht => calc μ.restrict s t = μ (t ∩ s) := restrict_apply ht _ ≤ μ t := measure_mono inter_subset_left #align measure_theory.measure.restrict_le_self MeasureTheory.Measure.restrict_le_self variable (μ) theorem restrict_eq_self (h : s ⊆ t) : μ.restrict t s = μ s := (le_iff'.1 restrict_le_self s).antisymm <| calc μ s ≤ μ (toMeasurable (μ.restrict t) s ∩ t) := measure_mono (subset_inter (subset_toMeasurable _ _) h) _ = μ.restrict t s := by rw [← restrict_apply (measurableSet_toMeasurable _ _), measure_toMeasurable] #align measure_theory.measure.restrict_eq_self MeasureTheory.Measure.restrict_eq_self @[simp] theorem restrict_apply_self (s : Set α) : (μ.restrict s) s = μ s := restrict_eq_self μ Subset.rfl #align measure_theory.measure.restrict_apply_self MeasureTheory.Measure.restrict_apply_self variable {μ} theorem restrict_apply_univ (s : Set α) : μ.restrict s univ = μ s := by rw [restrict_apply MeasurableSet.univ, Set.univ_inter] #align measure_theory.measure.restrict_apply_univ MeasureTheory.Measure.restrict_apply_univ theorem le_restrict_apply (s t : Set α) : μ (t ∩ s) ≤ μ.restrict s t := calc μ (t ∩ s) = μ.restrict s (t ∩ s) := (restrict_eq_self μ inter_subset_right).symm _ ≤ μ.restrict s t := measure_mono inter_subset_left #align measure_theory.measure.le_restrict_apply MeasureTheory.Measure.le_restrict_apply theorem restrict_apply_le (s t : Set α) : μ.restrict s t ≤ μ t := Measure.le_iff'.1 restrict_le_self _ theorem restrict_apply_superset (h : s ⊆ t) : μ.restrict s t = μ s := ((measure_mono (subset_univ _)).trans_eq <| restrict_apply_univ _).antisymm ((restrict_apply_self μ s).symm.trans_le <| measure_mono h) #align measure_theory.measure.restrict_apply_superset MeasureTheory.Measure.restrict_apply_superset @[simp] theorem restrict_add {_m0 : MeasurableSpace α} (μ ν : Measure α) (s : Set α) : (μ + ν).restrict s = μ.restrict s + ν.restrict s := (restrictₗ s).map_add μ ν #align measure_theory.measure.restrict_add MeasureTheory.Measure.restrict_add @[simp] theorem restrict_zero {_m0 : MeasurableSpace α} (s : Set α) : (0 : Measure α).restrict s = 0 := (restrictₗ s).map_zero #align measure_theory.measure.restrict_zero MeasureTheory.Measure.restrict_zero @[simp] theorem restrict_smul {_m0 : MeasurableSpace α} (c : ℝ≥0∞) (μ : Measure α) (s : Set α) : (c • μ).restrict s = c • μ.restrict s := (restrictₗ s).map_smul c μ #align measure_theory.measure.restrict_smul MeasureTheory.Measure.restrict_smul theorem restrict_restrict₀ (hs : NullMeasurableSet s (μ.restrict t)) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) := ext fun u hu => by simp only [Set.inter_assoc, restrict_apply hu, restrict_apply₀ (hu.nullMeasurableSet.inter hs)] #align measure_theory.measure.restrict_restrict₀ MeasureTheory.Measure.restrict_restrict₀ @[simp] theorem restrict_restrict (hs : MeasurableSet s) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) := restrict_restrict₀ hs.nullMeasurableSet #align measure_theory.measure.restrict_restrict MeasureTheory.Measure.restrict_restrict theorem restrict_restrict_of_subset (h : s ⊆ t) : (μ.restrict t).restrict s = μ.restrict s := by ext1 u hu rw [restrict_apply hu, restrict_apply hu, restrict_eq_self] exact inter_subset_right.trans h #align measure_theory.measure.restrict_restrict_of_subset MeasureTheory.Measure.restrict_restrict_of_subset theorem restrict_restrict₀' (ht : NullMeasurableSet t μ) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) := ext fun u hu => by simp only [restrict_apply hu, restrict_apply₀' ht, inter_assoc] #align measure_theory.measure.restrict_restrict₀' MeasureTheory.Measure.restrict_restrict₀' theorem restrict_restrict' (ht : MeasurableSet t) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) := restrict_restrict₀' ht.nullMeasurableSet #align measure_theory.measure.restrict_restrict' MeasureTheory.Measure.restrict_restrict' theorem restrict_comm (hs : MeasurableSet s) : (μ.restrict t).restrict s = (μ.restrict s).restrict t := by rw [restrict_restrict hs, restrict_restrict' hs, inter_comm] #align measure_theory.measure.restrict_comm MeasureTheory.Measure.restrict_comm theorem restrict_apply_eq_zero (ht : MeasurableSet t) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by rw [restrict_apply ht] #align measure_theory.measure.restrict_apply_eq_zero MeasureTheory.Measure.restrict_apply_eq_zero theorem measure_inter_eq_zero_of_restrict (h : μ.restrict s t = 0) : μ (t ∩ s) = 0 := nonpos_iff_eq_zero.1 (h ▸ le_restrict_apply _ _) #align measure_theory.measure.measure_inter_eq_zero_of_restrict MeasureTheory.Measure.measure_inter_eq_zero_of_restrict theorem restrict_apply_eq_zero' (hs : MeasurableSet s) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by rw [restrict_apply' hs] #align measure_theory.measure.restrict_apply_eq_zero' MeasureTheory.Measure.restrict_apply_eq_zero' @[simp] theorem restrict_eq_zero : μ.restrict s = 0 ↔ μ s = 0 := by rw [← measure_univ_eq_zero, restrict_apply_univ] #align measure_theory.measure.restrict_eq_zero MeasureTheory.Measure.restrict_eq_zero /-- If `μ s ≠ 0`, then `μ.restrict s ≠ 0`, in terms of `NeZero` instances. -/ instance restrict.neZero [NeZero (μ s)] : NeZero (μ.restrict s) := ⟨mt restrict_eq_zero.mp <| NeZero.ne _⟩ theorem restrict_zero_set {s : Set α} (h : μ s = 0) : μ.restrict s = 0 := restrict_eq_zero.2 h #align measure_theory.measure.restrict_zero_set MeasureTheory.Measure.restrict_zero_set @[simp] theorem restrict_empty : μ.restrict ∅ = 0 := restrict_zero_set measure_empty #align measure_theory.measure.restrict_empty MeasureTheory.Measure.restrict_empty @[simp] theorem restrict_univ : μ.restrict univ = μ := ext fun s hs => by simp [hs] #align measure_theory.measure.restrict_univ MeasureTheory.Measure.restrict_univ theorem restrict_inter_add_diff₀ (s : Set α) (ht : NullMeasurableSet t μ) : μ.restrict (s ∩ t) + μ.restrict (s \ t) = μ.restrict s := by ext1 u hu simp only [add_apply, restrict_apply hu, ← inter_assoc, diff_eq] exact measure_inter_add_diff₀ (u ∩ s) ht #align measure_theory.measure.restrict_inter_add_diff₀ MeasureTheory.Measure.restrict_inter_add_diff₀ theorem restrict_inter_add_diff (s : Set α) (ht : MeasurableSet t) : μ.restrict (s ∩ t) + μ.restrict (s \ t) = μ.restrict s := restrict_inter_add_diff₀ s ht.nullMeasurableSet #align measure_theory.measure.restrict_inter_add_diff MeasureTheory.Measure.restrict_inter_add_diff theorem restrict_union_add_inter₀ (s : Set α) (ht : NullMeasurableSet t μ) : μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t := by rw [← restrict_inter_add_diff₀ (s ∪ t) ht, union_inter_cancel_right, union_diff_right, ← restrict_inter_add_diff₀ s ht, add_comm, ← add_assoc, add_right_comm] #align measure_theory.measure.restrict_union_add_inter₀ MeasureTheory.Measure.restrict_union_add_inter₀ theorem restrict_union_add_inter (s : Set α) (ht : MeasurableSet t) : μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t := restrict_union_add_inter₀ s ht.nullMeasurableSet #align measure_theory.measure.restrict_union_add_inter MeasureTheory.Measure.restrict_union_add_inter theorem restrict_union_add_inter' (hs : MeasurableSet s) (t : Set α) : μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t := by simpa only [union_comm, inter_comm, add_comm] using restrict_union_add_inter t hs #align measure_theory.measure.restrict_union_add_inter' MeasureTheory.Measure.restrict_union_add_inter' theorem restrict_union₀ (h : AEDisjoint μ s t) (ht : NullMeasurableSet t μ) : μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t := by simp [← restrict_union_add_inter₀ s ht, restrict_zero_set h] #align measure_theory.measure.restrict_union₀ MeasureTheory.Measure.restrict_union₀ theorem restrict_union (h : Disjoint s t) (ht : MeasurableSet t) : μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t := restrict_union₀ h.aedisjoint ht.nullMeasurableSet #align measure_theory.measure.restrict_union MeasureTheory.Measure.restrict_union theorem restrict_union' (h : Disjoint s t) (hs : MeasurableSet s) : μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t := by rw [union_comm, restrict_union h.symm hs, add_comm] #align measure_theory.measure.restrict_union' MeasureTheory.Measure.restrict_union' @[simp]
Mathlib/MeasureTheory/Measure/Restrict.lean
287
290
theorem restrict_add_restrict_compl (hs : MeasurableSet s) : μ.restrict s + μ.restrict sᶜ = μ := by
rw [← restrict_union (@disjoint_compl_right (Set α) _ _) hs.compl, union_compl_self, restrict_univ]
/- Copyright (c) 2019 Jan-David Salchow. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jan-David Salchow, Sébastien Gouëzel, Jean Lo -/ import Mathlib.Analysis.NormedSpace.OperatorNorm.Basic /-! # Operator norm as an `NNNorm` Operator norm as an `NNNorm`, i.e. taking values in non-negative reals. -/ suppress_compilation open Bornology open Filter hiding map_smul open scoped Classical NNReal Topology Uniformity -- the `ₗ` subscript variables are for special cases about linear (as opposed to semilinear) maps variable {𝕜 𝕜₂ 𝕜₃ E Eₗ F Fₗ G Gₗ 𝓕 : Type*} section SemiNormed open Metric ContinuousLinearMap variable [SeminormedAddCommGroup E] [SeminormedAddCommGroup Eₗ] [SeminormedAddCommGroup F] [SeminormedAddCommGroup Fₗ] [SeminormedAddCommGroup G] [SeminormedAddCommGroup Gₗ] variable [NontriviallyNormedField 𝕜] [NontriviallyNormedField 𝕜₂] [NontriviallyNormedField 𝕜₃] [NormedSpace 𝕜 E] [NormedSpace 𝕜 Eₗ] [NormedSpace 𝕜₂ F] [NormedSpace 𝕜 Fₗ] [NormedSpace 𝕜₃ G] [NormedSpace 𝕜 Gₗ] {σ₁₂ : 𝕜 →+* 𝕜₂} {σ₂₃ : 𝕜₂ →+* 𝕜₃} {σ₁₃ : 𝕜 →+* 𝕜₃} [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] variable [FunLike 𝓕 E F] namespace ContinuousLinearMap section OpNorm open Set Real section variable [RingHomIsometric σ₁₂] [RingHomIsometric σ₂₃] (f g : E →SL[σ₁₂] F) (h : F →SL[σ₂₃] G) (x : E) theorem nnnorm_def (f : E →SL[σ₁₂] F) : ‖f‖₊ = sInf { c | ∀ x, ‖f x‖₊ ≤ c * ‖x‖₊ } := by ext rw [NNReal.coe_sInf, coe_nnnorm, norm_def, NNReal.coe_image] simp_rw [← NNReal.coe_le_coe, NNReal.coe_mul, coe_nnnorm, mem_setOf_eq, NNReal.coe_mk, exists_prop] #align continuous_linear_map.nnnorm_def ContinuousLinearMap.nnnorm_def /-- If one controls the norm of every `A x`, then one controls the norm of `A`. -/ theorem opNNNorm_le_bound (f : E →SL[σ₁₂] F) (M : ℝ≥0) (hM : ∀ x, ‖f x‖₊ ≤ M * ‖x‖₊) : ‖f‖₊ ≤ M := opNorm_le_bound f (zero_le M) hM #align continuous_linear_map.op_nnnorm_le_bound ContinuousLinearMap.opNNNorm_le_bound @[deprecated (since := "2024-02-02")] alias op_nnnorm_le_bound := opNNNorm_le_bound /-- If one controls the norm of every `A x`, `‖x‖₊ ≠ 0`, then one controls the norm of `A`. -/ theorem opNNNorm_le_bound' (f : E →SL[σ₁₂] F) (M : ℝ≥0) (hM : ∀ x, ‖x‖₊ ≠ 0 → ‖f x‖₊ ≤ M * ‖x‖₊) : ‖f‖₊ ≤ M := opNorm_le_bound' f (zero_le M) fun x hx => hM x <| by rwa [← NNReal.coe_ne_zero] #align continuous_linear_map.op_nnnorm_le_bound' ContinuousLinearMap.opNNNorm_le_bound' @[deprecated (since := "2024-02-02")] alias op_nnnorm_le_bound' := opNNNorm_le_bound' /-- For a continuous real linear map `f`, if one controls the norm of every `f x`, `‖x‖₊ = 1`, then one controls the norm of `f`. -/ theorem opNNNorm_le_of_unit_nnnorm [NormedSpace ℝ E] [NormedSpace ℝ F] {f : E →L[ℝ] F} {C : ℝ≥0} (hf : ∀ x, ‖x‖₊ = 1 → ‖f x‖₊ ≤ C) : ‖f‖₊ ≤ C := opNorm_le_of_unit_norm C.coe_nonneg fun x hx => hf x <| by rwa [← NNReal.coe_eq_one] #align continuous_linear_map.op_nnnorm_le_of_unit_nnnorm ContinuousLinearMap.opNNNorm_le_of_unit_nnnorm @[deprecated (since := "2024-02-02")] alias op_nnnorm_le_of_unit_nnnorm := opNNNorm_le_of_unit_nnnorm theorem opNNNorm_le_of_lipschitz {f : E →SL[σ₁₂] F} {K : ℝ≥0} (hf : LipschitzWith K f) : ‖f‖₊ ≤ K := opNorm_le_of_lipschitz hf #align continuous_linear_map.op_nnnorm_le_of_lipschitz ContinuousLinearMap.opNNNorm_le_of_lipschitz @[deprecated (since := "2024-02-02")] alias op_nnnorm_le_of_lipschitz := opNNNorm_le_of_lipschitz theorem opNNNorm_eq_of_bounds {φ : E →SL[σ₁₂] F} (M : ℝ≥0) (h_above : ∀ x, ‖φ x‖₊ ≤ M * ‖x‖₊) (h_below : ∀ N, (∀ x, ‖φ x‖₊ ≤ N * ‖x‖₊) → M ≤ N) : ‖φ‖₊ = M := Subtype.ext <| opNorm_eq_of_bounds (zero_le M) h_above <| Subtype.forall'.mpr h_below #align continuous_linear_map.op_nnnorm_eq_of_bounds ContinuousLinearMap.opNNNorm_eq_of_bounds @[deprecated (since := "2024-02-02")] alias op_nnnorm_eq_of_bounds := opNNNorm_eq_of_bounds theorem opNNNorm_le_iff {f : E →SL[σ₁₂] F} {C : ℝ≥0} : ‖f‖₊ ≤ C ↔ ∀ x, ‖f x‖₊ ≤ C * ‖x‖₊ := opNorm_le_iff C.2 @[deprecated (since := "2024-02-02")] alias op_nnnorm_le_iff := opNNNorm_le_iff theorem isLeast_opNNNorm : IsLeast {C : ℝ≥0 | ∀ x, ‖f x‖₊ ≤ C * ‖x‖₊} ‖f‖₊ := by simpa only [← opNNNorm_le_iff] using isLeast_Ici @[deprecated (since := "2024-02-02")] alias isLeast_op_nnnorm := isLeast_opNNNorm theorem opNNNorm_comp_le [RingHomIsometric σ₁₃] (f : E →SL[σ₁₂] F) : ‖h.comp f‖₊ ≤ ‖h‖₊ * ‖f‖₊ := opNorm_comp_le h f #align continuous_linear_map.op_nnnorm_comp_le ContinuousLinearMap.opNNNorm_comp_le @[deprecated (since := "2024-02-02")] alias op_nnnorm_comp_le := opNNNorm_comp_le theorem le_opNNNorm : ‖f x‖₊ ≤ ‖f‖₊ * ‖x‖₊ := f.le_opNorm x #align continuous_linear_map.le_op_nnnorm ContinuousLinearMap.le_opNNNorm @[deprecated (since := "2024-02-02")] alias le_op_nnnorm := le_opNNNorm theorem nndist_le_opNNNorm (x y : E) : nndist (f x) (f y) ≤ ‖f‖₊ * nndist x y := dist_le_opNorm f x y #align continuous_linear_map.nndist_le_op_nnnorm ContinuousLinearMap.nndist_le_opNNNorm @[deprecated (since := "2024-02-02")] alias nndist_le_op_nnnorm := nndist_le_opNNNorm /-- continuous linear maps are Lipschitz continuous. -/ theorem lipschitz : LipschitzWith ‖f‖₊ f := AddMonoidHomClass.lipschitz_of_bound_nnnorm f _ f.le_opNNNorm #align continuous_linear_map.lipschitz ContinuousLinearMap.lipschitz /-- Evaluation of a continuous linear map `f` at a point is Lipschitz continuous in `f`. -/ theorem lipschitz_apply (x : E) : LipschitzWith ‖x‖₊ fun f : E →SL[σ₁₂] F => f x := lipschitzWith_iff_norm_sub_le.2 fun f g => ((f - g).le_opNorm x).trans_eq (mul_comm _ _) #align continuous_linear_map.lipschitz_apply ContinuousLinearMap.lipschitz_apply end section Sup variable [RingHomIsometric σ₁₂] theorem exists_mul_lt_apply_of_lt_opNNNorm (f : E →SL[σ₁₂] F) {r : ℝ≥0} (hr : r < ‖f‖₊) : ∃ x, r * ‖x‖₊ < ‖f x‖₊ := by simpa only [not_forall, not_le, Set.mem_setOf] using not_mem_of_lt_csInf (nnnorm_def f ▸ hr : r < sInf { c : ℝ≥0 | ∀ x, ‖f x‖₊ ≤ c * ‖x‖₊ }) (OrderBot.bddBelow _) #align continuous_linear_map.exists_mul_lt_apply_of_lt_op_nnnorm ContinuousLinearMap.exists_mul_lt_apply_of_lt_opNNNorm @[deprecated (since := "2024-02-02")] alias exists_mul_lt_apply_of_lt_op_nnnorm := exists_mul_lt_apply_of_lt_opNNNorm theorem exists_mul_lt_of_lt_opNorm (f : E →SL[σ₁₂] F) {r : ℝ} (hr₀ : 0 ≤ r) (hr : r < ‖f‖) : ∃ x, r * ‖x‖ < ‖f x‖ := by lift r to ℝ≥0 using hr₀ exact f.exists_mul_lt_apply_of_lt_opNNNorm hr #align continuous_linear_map.exists_mul_lt_of_lt_op_norm ContinuousLinearMap.exists_mul_lt_of_lt_opNorm @[deprecated (since := "2024-02-02")] alias exists_mul_lt_of_lt_op_norm := exists_mul_lt_of_lt_opNorm
Mathlib/Analysis/NormedSpace/OperatorNorm/NNNorm.lean
158
172
theorem exists_lt_apply_of_lt_opNNNorm {𝕜 𝕜₂ E F : Type*} [NormedAddCommGroup E] [SeminormedAddCommGroup F] [DenselyNormedField 𝕜] [NontriviallyNormedField 𝕜₂] {σ₁₂ : 𝕜 →+* 𝕜₂} [NormedSpace 𝕜 E] [NormedSpace 𝕜₂ F] [RingHomIsometric σ₁₂] (f : E →SL[σ₁₂] F) {r : ℝ≥0} (hr : r < ‖f‖₊) : ∃ x : E, ‖x‖₊ < 1 ∧ r < ‖f x‖₊ := by
obtain ⟨y, hy⟩ := f.exists_mul_lt_apply_of_lt_opNNNorm hr have hy' : ‖y‖₊ ≠ 0 := nnnorm_ne_zero_iff.2 fun heq => by simp [heq, nnnorm_zero, map_zero, not_lt_zero'] at hy have hfy : ‖f y‖₊ ≠ 0 := (zero_le'.trans_lt hy).ne' rw [← inv_inv ‖f y‖₊, NNReal.lt_inv_iff_mul_lt (inv_ne_zero hfy), mul_assoc, mul_comm ‖y‖₊, ← mul_assoc, ← NNReal.lt_inv_iff_mul_lt hy'] at hy obtain ⟨k, hk₁, hk₂⟩ := NormedField.exists_lt_nnnorm_lt 𝕜 hy refine ⟨k • y, (nnnorm_smul k y).symm ▸ (NNReal.lt_inv_iff_mul_lt hy').1 hk₂, ?_⟩ have : ‖σ₁₂ k‖₊ = ‖k‖₊ := Subtype.ext RingHomIsometric.is_iso rwa [map_smulₛₗ f, nnnorm_smul, ← NNReal.div_lt_iff hfy, div_eq_mul_inv, this]
/- Copyright (c) 2022 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck -/ import Mathlib.Data.Complex.Basic import Mathlib.MeasureTheory.Integral.CircleIntegral #align_import measure_theory.integral.circle_transform from "leanprover-community/mathlib"@"d11893b411025250c8e61ff2f12ccbd7ee35ab15" /-! # Circle integral transform In this file we define the circle integral transform of a function `f` with complex domain. This is defined as $(2πi)^{-1}\frac{f(x)}{x-w}$ where `x` moves along a circle. We then prove some basic facts about these functions. These results are useful for proving that the uniform limit of a sequence of holomorphic functions is holomorphic. -/ open Set MeasureTheory Metric Filter Function open scoped Interval Real noncomputable section variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] (R : ℝ) (z w : ℂ) namespace Complex /-- Given a function `f : ℂ → E`, `circleTransform R z w f` is the function mapping `θ` to `(2 * ↑π * I)⁻¹ • deriv (circleMap z R) θ • ((circleMap z R θ) - w)⁻¹ • f (circleMap z R θ)`. If `f` is differentiable and `w` is in the interior of the ball, then the integral from `0` to `2 * π` of this gives the value `f(w)`. -/ def circleTransform (f : ℂ → E) (θ : ℝ) : E := (2 * ↑π * I)⁻¹ • deriv (circleMap z R) θ • (circleMap z R θ - w)⁻¹ • f (circleMap z R θ) #align complex.circle_transform Complex.circleTransform /-- The derivative of `circleTransform` w.r.t `w`. -/ def circleTransformDeriv (f : ℂ → E) (θ : ℝ) : E := (2 * ↑π * I)⁻¹ • deriv (circleMap z R) θ • ((circleMap z R θ - w) ^ 2)⁻¹ • f (circleMap z R θ) #align complex.circle_transform_deriv Complex.circleTransformDeriv theorem circleTransformDeriv_periodic (f : ℂ → E) : Periodic (circleTransformDeriv R z w f) (2 * π) := by have := periodic_circleMap simp_rw [Periodic] at * intro x simp_rw [circleTransformDeriv, this] congr 2 simp [this] #align complex.circle_transform_deriv_periodic Complex.circleTransformDeriv_periodic
Mathlib/MeasureTheory/Integral/CircleTransform.lean
58
65
theorem circleTransformDeriv_eq (f : ℂ → E) : circleTransformDeriv R z w f = fun θ => (circleMap z R θ - w)⁻¹ • circleTransform R z w f θ := by
ext simp_rw [circleTransformDeriv, circleTransform, ← mul_smul, ← mul_assoc] ring_nf rw [inv_pow] congr ring
/- Copyright (c) 2020 Thomas Browning, Patrick Lutz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning, Patrick Lutz -/ import Mathlib.Algebra.Algebra.Subalgebra.Directed import Mathlib.FieldTheory.IntermediateField import Mathlib.FieldTheory.Separable import Mathlib.FieldTheory.SplittingField.IsSplittingField import Mathlib.RingTheory.TensorProduct.Basic #align_import field_theory.adjoin from "leanprover-community/mathlib"@"df76f43357840485b9d04ed5dee5ab115d420e87" /-! # Adjoining Elements to Fields In this file we introduce the notion of adjoining elements to fields. This isn't quite the same as adjoining elements to rings. For example, `Algebra.adjoin K {x}` might not include `x⁻¹`. ## Main results - `adjoin_adjoin_left`: adjoining S and then T is the same as adjoining `S ∪ T`. - `bot_eq_top_of_rank_adjoin_eq_one`: if `F⟮x⟯` has dimension `1` over `F` for every `x` in `E` then `F = E` ## Notation - `F⟮α⟯`: adjoin a single element `α` to `F` (in scope `IntermediateField`). -/ set_option autoImplicit true open FiniteDimensional Polynomial open scoped Classical Polynomial namespace IntermediateField section AdjoinDef variable (F : Type*) [Field F] {E : Type*} [Field E] [Algebra F E] (S : Set E) -- Porting note: not adding `neg_mem'` causes an error. /-- `adjoin F S` extends a field `F` by adjoining a set `S ⊆ E`. -/ def adjoin : IntermediateField F E := { Subfield.closure (Set.range (algebraMap F E) ∪ S) with algebraMap_mem' := fun x => Subfield.subset_closure (Or.inl (Set.mem_range_self x)) } #align intermediate_field.adjoin IntermediateField.adjoin variable {S} theorem mem_adjoin_iff (x : E) : x ∈ adjoin F S ↔ ∃ r s : MvPolynomial S F, x = MvPolynomial.aeval Subtype.val r / MvPolynomial.aeval Subtype.val s := by simp only [adjoin, mem_mk, Subring.mem_toSubsemiring, Subfield.mem_toSubring, Subfield.mem_closure_iff, ← Algebra.adjoin_eq_ring_closure, Subalgebra.mem_toSubring, Algebra.adjoin_eq_range, AlgHom.mem_range, exists_exists_eq_and] tauto theorem mem_adjoin_simple_iff {α : E} (x : E) : x ∈ adjoin F {α} ↔ ∃ r s : F[X], x = aeval α r / aeval α s := by simp only [adjoin, mem_mk, Subring.mem_toSubsemiring, Subfield.mem_toSubring, Subfield.mem_closure_iff, ← Algebra.adjoin_eq_ring_closure, Subalgebra.mem_toSubring, Algebra.adjoin_singleton_eq_range_aeval, AlgHom.mem_range, exists_exists_eq_and] tauto end AdjoinDef section Lattice variable {F : Type*} [Field F] {E : Type*} [Field E] [Algebra F E] @[simp] theorem adjoin_le_iff {S : Set E} {T : IntermediateField F E} : adjoin F S ≤ T ↔ S ≤ T := ⟨fun H => le_trans (le_trans Set.subset_union_right Subfield.subset_closure) H, fun H => (@Subfield.closure_le E _ (Set.range (algebraMap F E) ∪ S) T.toSubfield).mpr (Set.union_subset (IntermediateField.set_range_subset T) H)⟩ #align intermediate_field.adjoin_le_iff IntermediateField.adjoin_le_iff theorem gc : GaloisConnection (adjoin F : Set E → IntermediateField F E) (fun (x : IntermediateField F E) => (x : Set E)) := fun _ _ => adjoin_le_iff #align intermediate_field.gc IntermediateField.gc /-- Galois insertion between `adjoin` and `coe`. -/ def gi : GaloisInsertion (adjoin F : Set E → IntermediateField F E) (fun (x : IntermediateField F E) => (x : Set E)) where choice s hs := (adjoin F s).copy s <| le_antisymm (gc.le_u_l s) hs gc := IntermediateField.gc le_l_u S := (IntermediateField.gc (S : Set E) (adjoin F S)).1 <| le_rfl choice_eq _ _ := copy_eq _ _ _ #align intermediate_field.gi IntermediateField.gi instance : CompleteLattice (IntermediateField F E) where __ := GaloisInsertion.liftCompleteLattice IntermediateField.gi bot := { toSubalgebra := ⊥ inv_mem' := by rintro x ⟨r, rfl⟩; exact ⟨r⁻¹, map_inv₀ _ _⟩ } bot_le x := (bot_le : ⊥ ≤ x.toSubalgebra) instance : Inhabited (IntermediateField F E) := ⟨⊤⟩ instance : Unique (IntermediateField F F) := { inferInstanceAs (Inhabited (IntermediateField F F)) with uniq := fun _ ↦ toSubalgebra_injective <| Subsingleton.elim _ _ } theorem coe_bot : ↑(⊥ : IntermediateField F E) = Set.range (algebraMap F E) := rfl #align intermediate_field.coe_bot IntermediateField.coe_bot theorem mem_bot {x : E} : x ∈ (⊥ : IntermediateField F E) ↔ x ∈ Set.range (algebraMap F E) := Iff.rfl #align intermediate_field.mem_bot IntermediateField.mem_bot @[simp] theorem bot_toSubalgebra : (⊥ : IntermediateField F E).toSubalgebra = ⊥ := rfl #align intermediate_field.bot_to_subalgebra IntermediateField.bot_toSubalgebra @[simp] theorem coe_top : ↑(⊤ : IntermediateField F E) = (Set.univ : Set E) := rfl #align intermediate_field.coe_top IntermediateField.coe_top @[simp] theorem mem_top {x : E} : x ∈ (⊤ : IntermediateField F E) := trivial #align intermediate_field.mem_top IntermediateField.mem_top @[simp] theorem top_toSubalgebra : (⊤ : IntermediateField F E).toSubalgebra = ⊤ := rfl #align intermediate_field.top_to_subalgebra IntermediateField.top_toSubalgebra @[simp] theorem top_toSubfield : (⊤ : IntermediateField F E).toSubfield = ⊤ := rfl #align intermediate_field.top_to_subfield IntermediateField.top_toSubfield @[simp, norm_cast] theorem coe_inf (S T : IntermediateField F E) : (↑(S ⊓ T) : Set E) = (S : Set E) ∩ T := rfl #align intermediate_field.coe_inf IntermediateField.coe_inf @[simp] theorem mem_inf {S T : IntermediateField F E} {x : E} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl #align intermediate_field.mem_inf IntermediateField.mem_inf @[simp] theorem inf_toSubalgebra (S T : IntermediateField F E) : (S ⊓ T).toSubalgebra = S.toSubalgebra ⊓ T.toSubalgebra := rfl #align intermediate_field.inf_to_subalgebra IntermediateField.inf_toSubalgebra @[simp] theorem inf_toSubfield (S T : IntermediateField F E) : (S ⊓ T).toSubfield = S.toSubfield ⊓ T.toSubfield := rfl #align intermediate_field.inf_to_subfield IntermediateField.inf_toSubfield @[simp, norm_cast] theorem coe_sInf (S : Set (IntermediateField F E)) : (↑(sInf S) : Set E) = sInf ((fun (x : IntermediateField F E) => (x : Set E)) '' S) := rfl #align intermediate_field.coe_Inf IntermediateField.coe_sInf @[simp] theorem sInf_toSubalgebra (S : Set (IntermediateField F E)) : (sInf S).toSubalgebra = sInf (toSubalgebra '' S) := SetLike.coe_injective <| by simp [Set.sUnion_image] #align intermediate_field.Inf_to_subalgebra IntermediateField.sInf_toSubalgebra @[simp] theorem sInf_toSubfield (S : Set (IntermediateField F E)) : (sInf S).toSubfield = sInf (toSubfield '' S) := SetLike.coe_injective <| by simp [Set.sUnion_image] #align intermediate_field.Inf_to_subfield IntermediateField.sInf_toSubfield @[simp, norm_cast] theorem coe_iInf {ι : Sort*} (S : ι → IntermediateField F E) : (↑(iInf S) : Set E) = ⋂ i, S i := by simp [iInf] #align intermediate_field.coe_infi IntermediateField.coe_iInf @[simp] theorem iInf_toSubalgebra {ι : Sort*} (S : ι → IntermediateField F E) : (iInf S).toSubalgebra = ⨅ i, (S i).toSubalgebra := SetLike.coe_injective <| by simp [iInf] #align intermediate_field.infi_to_subalgebra IntermediateField.iInf_toSubalgebra @[simp] theorem iInf_toSubfield {ι : Sort*} (S : ι → IntermediateField F E) : (iInf S).toSubfield = ⨅ i, (S i).toSubfield := SetLike.coe_injective <| by simp [iInf] #align intermediate_field.infi_to_subfield IntermediateField.iInf_toSubfield /-- Construct an algebra isomorphism from an equality of intermediate fields -/ @[simps! apply] def equivOfEq {S T : IntermediateField F E} (h : S = T) : S ≃ₐ[F] T := Subalgebra.equivOfEq _ _ (congr_arg toSubalgebra h) #align intermediate_field.equiv_of_eq IntermediateField.equivOfEq @[simp] theorem equivOfEq_symm {S T : IntermediateField F E} (h : S = T) : (equivOfEq h).symm = equivOfEq h.symm := rfl #align intermediate_field.equiv_of_eq_symm IntermediateField.equivOfEq_symm @[simp] theorem equivOfEq_rfl (S : IntermediateField F E) : equivOfEq (rfl : S = S) = AlgEquiv.refl := by ext; rfl #align intermediate_field.equiv_of_eq_rfl IntermediateField.equivOfEq_rfl @[simp] theorem equivOfEq_trans {S T U : IntermediateField F E} (hST : S = T) (hTU : T = U) : (equivOfEq hST).trans (equivOfEq hTU) = equivOfEq (hST.trans hTU) := rfl #align intermediate_field.equiv_of_eq_trans IntermediateField.equivOfEq_trans variable (F E) /-- The bottom intermediate_field is isomorphic to the field. -/ noncomputable def botEquiv : (⊥ : IntermediateField F E) ≃ₐ[F] F := (Subalgebra.equivOfEq _ _ bot_toSubalgebra).trans (Algebra.botEquiv F E) #align intermediate_field.bot_equiv IntermediateField.botEquiv variable {F E} -- Porting note: this was tagged `simp`. theorem botEquiv_def (x : F) : botEquiv F E (algebraMap F (⊥ : IntermediateField F E) x) = x := by simp #align intermediate_field.bot_equiv_def IntermediateField.botEquiv_def @[simp] theorem botEquiv_symm (x : F) : (botEquiv F E).symm x = algebraMap F _ x := rfl #align intermediate_field.bot_equiv_symm IntermediateField.botEquiv_symm noncomputable instance algebraOverBot : Algebra (⊥ : IntermediateField F E) F := (IntermediateField.botEquiv F E).toAlgHom.toRingHom.toAlgebra #align intermediate_field.algebra_over_bot IntermediateField.algebraOverBot theorem coe_algebraMap_over_bot : (algebraMap (⊥ : IntermediateField F E) F : (⊥ : IntermediateField F E) → F) = IntermediateField.botEquiv F E := rfl #align intermediate_field.coe_algebra_map_over_bot IntermediateField.coe_algebraMap_over_bot instance isScalarTower_over_bot : IsScalarTower (⊥ : IntermediateField F E) F E := IsScalarTower.of_algebraMap_eq (by intro x obtain ⟨y, rfl⟩ := (botEquiv F E).symm.surjective x rw [coe_algebraMap_over_bot, (botEquiv F E).apply_symm_apply, botEquiv_symm, IsScalarTower.algebraMap_apply F (⊥ : IntermediateField F E) E]) #align intermediate_field.is_scalar_tower_over_bot IntermediateField.isScalarTower_over_bot /-- The top `IntermediateField` is isomorphic to the field. This is the intermediate field version of `Subalgebra.topEquiv`. -/ @[simps!] def topEquiv : (⊤ : IntermediateField F E) ≃ₐ[F] E := (Subalgebra.equivOfEq _ _ top_toSubalgebra).trans Subalgebra.topEquiv #align intermediate_field.top_equiv IntermediateField.topEquiv -- Porting note: this theorem is now generated by the `@[simps!]` above. #align intermediate_field.top_equiv_symm_apply_coe IntermediateField.topEquiv_symm_apply_coe @[simp] theorem restrictScalars_bot_eq_self (K : IntermediateField F E) : (⊥ : IntermediateField K E).restrictScalars _ = K := SetLike.coe_injective Subtype.range_coe #align intermediate_field.restrict_scalars_bot_eq_self IntermediateField.restrictScalars_bot_eq_self @[simp] theorem restrictScalars_top {K : Type*} [Field K] [Algebra K E] [Algebra K F] [IsScalarTower K F E] : (⊤ : IntermediateField F E).restrictScalars K = ⊤ := rfl #align intermediate_field.restrict_scalars_top IntermediateField.restrictScalars_top variable {K : Type*} [Field K] [Algebra F K] @[simp] theorem map_bot (f : E →ₐ[F] K) : IntermediateField.map f ⊥ = ⊥ := toSubalgebra_injective <| Algebra.map_bot _ theorem map_sup (s t : IntermediateField F E) (f : E →ₐ[F] K) : (s ⊔ t).map f = s.map f ⊔ t.map f := (gc_map_comap f).l_sup theorem map_iSup {ι : Sort*} (f : E →ₐ[F] K) (s : ι → IntermediateField F E) : (iSup s).map f = ⨆ i, (s i).map f := (gc_map_comap f).l_iSup theorem _root_.AlgHom.fieldRange_eq_map (f : E →ₐ[F] K) : f.fieldRange = IntermediateField.map f ⊤ := SetLike.ext' Set.image_univ.symm #align alg_hom.field_range_eq_map AlgHom.fieldRange_eq_map theorem _root_.AlgHom.map_fieldRange {L : Type*} [Field L] [Algebra F L] (f : E →ₐ[F] K) (g : K →ₐ[F] L) : f.fieldRange.map g = (g.comp f).fieldRange := SetLike.ext' (Set.range_comp g f).symm #align alg_hom.map_field_range AlgHom.map_fieldRange theorem _root_.AlgHom.fieldRange_eq_top {f : E →ₐ[F] K} : f.fieldRange = ⊤ ↔ Function.Surjective f := SetLike.ext'_iff.trans Set.range_iff_surjective #align alg_hom.field_range_eq_top AlgHom.fieldRange_eq_top @[simp] theorem _root_.AlgEquiv.fieldRange_eq_top (f : E ≃ₐ[F] K) : (f : E →ₐ[F] K).fieldRange = ⊤ := AlgHom.fieldRange_eq_top.mpr f.surjective #align alg_equiv.field_range_eq_top AlgEquiv.fieldRange_eq_top end Lattice section equivMap variable {F : Type*} [Field F] {E : Type*} [Field E] [Algebra F E] {K : Type*} [Field K] [Algebra F K] (L : IntermediateField F E) (f : E →ₐ[F] K) theorem fieldRange_comp_val : (f.comp L.val).fieldRange = L.map f := toSubalgebra_injective <| by rw [toSubalgebra_map, AlgHom.fieldRange_toSubalgebra, AlgHom.range_comp, range_val] /-- An intermediate field is isomorphic to its image under an `AlgHom` (which is automatically injective) -/ noncomputable def equivMap : L ≃ₐ[F] L.map f := (AlgEquiv.ofInjective _ (f.comp L.val).injective).trans (equivOfEq (fieldRange_comp_val L f)) @[simp] theorem coe_equivMap_apply (x : L) : ↑(equivMap L f x) = f x := rfl end equivMap section AdjoinDef variable (F : Type*) [Field F] {E : Type*} [Field E] [Algebra F E] (S : Set E) theorem adjoin_eq_range_algebraMap_adjoin : (adjoin F S : Set E) = Set.range (algebraMap (adjoin F S) E) := Subtype.range_coe.symm #align intermediate_field.adjoin_eq_range_algebra_map_adjoin IntermediateField.adjoin_eq_range_algebraMap_adjoin theorem adjoin.algebraMap_mem (x : F) : algebraMap F E x ∈ adjoin F S := IntermediateField.algebraMap_mem (adjoin F S) x #align intermediate_field.adjoin.algebra_map_mem IntermediateField.adjoin.algebraMap_mem theorem adjoin.range_algebraMap_subset : Set.range (algebraMap F E) ⊆ adjoin F S := by intro x hx cases' hx with f hf rw [← hf] exact adjoin.algebraMap_mem F S f #align intermediate_field.adjoin.range_algebra_map_subset IntermediateField.adjoin.range_algebraMap_subset instance adjoin.fieldCoe : CoeTC F (adjoin F S) where coe x := ⟨algebraMap F E x, adjoin.algebraMap_mem F S x⟩ #align intermediate_field.adjoin.field_coe IntermediateField.adjoin.fieldCoe theorem subset_adjoin : S ⊆ adjoin F S := fun _ hx => Subfield.subset_closure (Or.inr hx) #align intermediate_field.subset_adjoin IntermediateField.subset_adjoin instance adjoin.setCoe : CoeTC S (adjoin F S) where coe x := ⟨x, subset_adjoin F S (Subtype.mem x)⟩ #align intermediate_field.adjoin.set_coe IntermediateField.adjoin.setCoe @[mono] theorem adjoin.mono (T : Set E) (h : S ⊆ T) : adjoin F S ≤ adjoin F T := GaloisConnection.monotone_l gc h #align intermediate_field.adjoin.mono IntermediateField.adjoin.mono theorem adjoin_contains_field_as_subfield (F : Subfield E) : (F : Set E) ⊆ adjoin F S := fun x hx => adjoin.algebraMap_mem F S ⟨x, hx⟩ #align intermediate_field.adjoin_contains_field_as_subfield IntermediateField.adjoin_contains_field_as_subfield theorem subset_adjoin_of_subset_left {F : Subfield E} {T : Set E} (HT : T ⊆ F) : T ⊆ adjoin F S := fun x hx => (adjoin F S).algebraMap_mem ⟨x, HT hx⟩ #align intermediate_field.subset_adjoin_of_subset_left IntermediateField.subset_adjoin_of_subset_left theorem subset_adjoin_of_subset_right {T : Set E} (H : T ⊆ S) : T ⊆ adjoin F S := fun _ hx => subset_adjoin F S (H hx) #align intermediate_field.subset_adjoin_of_subset_right IntermediateField.subset_adjoin_of_subset_right @[simp] theorem adjoin_empty (F E : Type*) [Field F] [Field E] [Algebra F E] : adjoin F (∅ : Set E) = ⊥ := eq_bot_iff.mpr (adjoin_le_iff.mpr (Set.empty_subset _)) #align intermediate_field.adjoin_empty IntermediateField.adjoin_empty @[simp] theorem adjoin_univ (F E : Type*) [Field F] [Field E] [Algebra F E] : adjoin F (Set.univ : Set E) = ⊤ := eq_top_iff.mpr <| subset_adjoin _ _ #align intermediate_field.adjoin_univ IntermediateField.adjoin_univ /-- If `K` is a field with `F ⊆ K` and `S ⊆ K` then `adjoin F S ≤ K`. -/ theorem adjoin_le_subfield {K : Subfield E} (HF : Set.range (algebraMap F E) ⊆ K) (HS : S ⊆ K) : (adjoin F S).toSubfield ≤ K := by apply Subfield.closure_le.mpr rw [Set.union_subset_iff] exact ⟨HF, HS⟩ #align intermediate_field.adjoin_le_subfield IntermediateField.adjoin_le_subfield theorem adjoin_subset_adjoin_iff {F' : Type*} [Field F'] [Algebra F' E] {S S' : Set E} : (adjoin F S : Set E) ⊆ adjoin F' S' ↔ Set.range (algebraMap F E) ⊆ adjoin F' S' ∧ S ⊆ adjoin F' S' := ⟨fun h => ⟨(adjoin.range_algebraMap_subset _ _).trans h, (subset_adjoin _ _).trans h⟩, fun ⟨hF, hS⟩ => (Subfield.closure_le (t := (adjoin F' S').toSubfield)).mpr (Set.union_subset hF hS)⟩ #align intermediate_field.adjoin_subset_adjoin_iff IntermediateField.adjoin_subset_adjoin_iff /-- `F[S][T] = F[S ∪ T]` -/ theorem adjoin_adjoin_left (T : Set E) : (adjoin (adjoin F S) T).restrictScalars _ = adjoin F (S ∪ T) := by rw [SetLike.ext'_iff] change (↑(adjoin (adjoin F S) T) : Set E) = _ apply Set.eq_of_subset_of_subset <;> rw [adjoin_subset_adjoin_iff] <;> constructor · rintro _ ⟨⟨x, hx⟩, rfl⟩; exact adjoin.mono _ _ _ Set.subset_union_left hx · exact subset_adjoin_of_subset_right _ _ Set.subset_union_right -- Porting note: orginal proof times out · rintro x ⟨f, rfl⟩ refine Subfield.subset_closure ?_ left exact ⟨f, rfl⟩ -- Porting note: orginal proof times out · refine Set.union_subset (fun x hx => Subfield.subset_closure ?_) (fun x hx => Subfield.subset_closure ?_) · left refine ⟨⟨x, Subfield.subset_closure ?_⟩, rfl⟩ right exact hx · right exact hx #align intermediate_field.adjoin_adjoin_left IntermediateField.adjoin_adjoin_left @[simp] theorem adjoin_insert_adjoin (x : E) : adjoin F (insert x (adjoin F S : Set E)) = adjoin F (insert x S) := le_antisymm (adjoin_le_iff.mpr (Set.insert_subset_iff.mpr ⟨subset_adjoin _ _ (Set.mem_insert _ _), adjoin_le_iff.mpr (subset_adjoin_of_subset_right _ _ (Set.subset_insert _ _))⟩)) (adjoin.mono _ _ _ (Set.insert_subset_insert (subset_adjoin _ _))) #align intermediate_field.adjoin_insert_adjoin IntermediateField.adjoin_insert_adjoin /-- `F[S][T] = F[T][S]` -/ theorem adjoin_adjoin_comm (T : Set E) : (adjoin (adjoin F S) T).restrictScalars F = (adjoin (adjoin F T) S).restrictScalars F := by rw [adjoin_adjoin_left, adjoin_adjoin_left, Set.union_comm] #align intermediate_field.adjoin_adjoin_comm IntermediateField.adjoin_adjoin_comm theorem adjoin_map {E' : Type*} [Field E'] [Algebra F E'] (f : E →ₐ[F] E') : (adjoin F S).map f = adjoin F (f '' S) := by ext x show x ∈ (Subfield.closure (Set.range (algebraMap F E) ∪ S)).map (f : E →+* E') ↔ x ∈ Subfield.closure (Set.range (algebraMap F E') ∪ f '' S) rw [RingHom.map_field_closure, Set.image_union, ← Set.range_comp, ← RingHom.coe_comp, f.comp_algebraMap] rfl #align intermediate_field.adjoin_map IntermediateField.adjoin_map @[simp] theorem lift_adjoin (K : IntermediateField F E) (S : Set K) : lift (adjoin F S) = adjoin F (Subtype.val '' S) := adjoin_map _ _ _ theorem lift_adjoin_simple (K : IntermediateField F E) (α : K) : lift (adjoin F {α}) = adjoin F {α.1} := by simp only [lift_adjoin, Set.image_singleton] @[simp] theorem lift_bot (K : IntermediateField F E) : lift (F := K) ⊥ = ⊥ := map_bot _ @[simp] theorem lift_top (K : IntermediateField F E) : lift (F := K) ⊤ = K := by rw [lift, ← AlgHom.fieldRange_eq_map, fieldRange_val] @[simp] theorem adjoin_self (K : IntermediateField F E) : adjoin F K = K := le_antisymm (adjoin_le_iff.2 fun _ ↦ id) (subset_adjoin F _)
Mathlib/FieldTheory/Adjoin.lean
484
486
theorem restrictScalars_adjoin (K : IntermediateField F E) (S : Set E) : restrictScalars F (adjoin K S) = adjoin F (K ∪ S) := by
rw [← adjoin_self _ K, adjoin_adjoin_left, adjoin_self _ K]
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker, Johan Commelin -/ import Mathlib.Algebra.Polynomial.RingDivision import Mathlib.RingTheory.Localization.FractionRing #align_import data.polynomial.ring_division from "leanprover-community/mathlib"@"8efcf8022aac8e01df8d302dcebdbc25d6a886c8" /-! # Theory of univariate polynomials We define the multiset of roots of a polynomial, and prove basic results about it. ## Main definitions * `Polynomial.roots p`: The multiset containing all the roots of `p`, including their multiplicities. * `Polynomial.rootSet p E`: The set of distinct roots of `p` in an algebra `E`. ## Main statements * `Polynomial.C_leadingCoeff_mul_prod_multiset_X_sub_C`: If a polynomial has as many roots as its degree, it can be written as the product of its leading coefficient with `∏ (X - a)` where `a` ranges through its roots. -/ noncomputable section namespace Polynomial universe u v w z variable {R : Type u} {S : Type v} {T : Type w} {a b : R} {n : ℕ} section CommRing variable [CommRing R] [IsDomain R] {p q : R[X]} section Roots open Multiset Finset /-- `roots p` noncomputably gives a multiset containing all the roots of `p`, including their multiplicities. -/ noncomputable def roots (p : R[X]) : Multiset R := haveI := Classical.decEq R haveI := Classical.dec (p = 0) if h : p = 0 then ∅ else Classical.choose (exists_multiset_roots h) #align polynomial.roots Polynomial.roots theorem roots_def [DecidableEq R] (p : R[X]) [Decidable (p = 0)] : p.roots = if h : p = 0 then ∅ else Classical.choose (exists_multiset_roots h) := by -- porting noteL `‹_›` doesn't work for instance arguments rename_i iR ip0 obtain rfl := Subsingleton.elim iR (Classical.decEq R) obtain rfl := Subsingleton.elim ip0 (Classical.dec (p = 0)) rfl #align polynomial.roots_def Polynomial.roots_def @[simp] theorem roots_zero : (0 : R[X]).roots = 0 := dif_pos rfl #align polynomial.roots_zero Polynomial.roots_zero theorem card_roots (hp0 : p ≠ 0) : (Multiset.card (roots p) : WithBot ℕ) ≤ degree p := by classical unfold roots rw [dif_neg hp0] exact (Classical.choose_spec (exists_multiset_roots hp0)).1 #align polynomial.card_roots Polynomial.card_roots theorem card_roots' (p : R[X]) : Multiset.card p.roots ≤ natDegree p := by by_cases hp0 : p = 0 · simp [hp0] exact WithBot.coe_le_coe.1 (le_trans (card_roots hp0) (le_of_eq <| degree_eq_natDegree hp0)) #align polynomial.card_roots' Polynomial.card_roots' theorem card_roots_sub_C {p : R[X]} {a : R} (hp0 : 0 < degree p) : (Multiset.card (p - C a).roots : WithBot ℕ) ≤ degree p := calc (Multiset.card (p - C a).roots : WithBot ℕ) ≤ degree (p - C a) := card_roots <| mt sub_eq_zero.1 fun h => not_le_of_gt hp0 <| h.symm ▸ degree_C_le _ = degree p := by rw [sub_eq_add_neg, ← C_neg]; exact degree_add_C hp0 set_option linter.uppercaseLean3 false in #align polynomial.card_roots_sub_C Polynomial.card_roots_sub_C theorem card_roots_sub_C' {p : R[X]} {a : R} (hp0 : 0 < degree p) : Multiset.card (p - C a).roots ≤ natDegree p := WithBot.coe_le_coe.1 (le_trans (card_roots_sub_C hp0) (le_of_eq <| degree_eq_natDegree fun h => by simp_all [lt_irrefl])) set_option linter.uppercaseLean3 false in #align polynomial.card_roots_sub_C' Polynomial.card_roots_sub_C' @[simp] theorem count_roots [DecidableEq R] (p : R[X]) : p.roots.count a = rootMultiplicity a p := by classical by_cases hp : p = 0 · simp [hp] rw [roots_def, dif_neg hp] exact (Classical.choose_spec (exists_multiset_roots hp)).2 a #align polynomial.count_roots Polynomial.count_roots @[simp] theorem mem_roots' : a ∈ p.roots ↔ p ≠ 0 ∧ IsRoot p a := by classical rw [← count_pos, count_roots p, rootMultiplicity_pos'] #align polynomial.mem_roots' Polynomial.mem_roots' theorem mem_roots (hp : p ≠ 0) : a ∈ p.roots ↔ IsRoot p a := mem_roots'.trans <| and_iff_right hp #align polynomial.mem_roots Polynomial.mem_roots theorem ne_zero_of_mem_roots (h : a ∈ p.roots) : p ≠ 0 := (mem_roots'.1 h).1 #align polynomial.ne_zero_of_mem_roots Polynomial.ne_zero_of_mem_roots theorem isRoot_of_mem_roots (h : a ∈ p.roots) : IsRoot p a := (mem_roots'.1 h).2 #align polynomial.is_root_of_mem_roots Polynomial.isRoot_of_mem_roots -- Porting note: added during port. lemma mem_roots_iff_aeval_eq_zero {x : R} (w : p ≠ 0) : x ∈ roots p ↔ aeval x p = 0 := by rw [mem_roots w, IsRoot.def, aeval_def, eval₂_eq_eval_map] simp theorem card_le_degree_of_subset_roots {p : R[X]} {Z : Finset R} (h : Z.val ⊆ p.roots) : Z.card ≤ p.natDegree := (Multiset.card_le_card (Finset.val_le_iff_val_subset.2 h)).trans (Polynomial.card_roots' p) #align polynomial.card_le_degree_of_subset_roots Polynomial.card_le_degree_of_subset_roots theorem finite_setOf_isRoot {p : R[X]} (hp : p ≠ 0) : Set.Finite { x | IsRoot p x } := by classical simpa only [← Finset.setOf_mem, Multiset.mem_toFinset, mem_roots hp] using p.roots.toFinset.finite_toSet #align polynomial.finite_set_of_is_root Polynomial.finite_setOf_isRoot theorem eq_zero_of_infinite_isRoot (p : R[X]) (h : Set.Infinite { x | IsRoot p x }) : p = 0 := not_imp_comm.mp finite_setOf_isRoot h #align polynomial.eq_zero_of_infinite_is_root Polynomial.eq_zero_of_infinite_isRoot theorem exists_max_root [LinearOrder R] (p : R[X]) (hp : p ≠ 0) : ∃ x₀, ∀ x, p.IsRoot x → x ≤ x₀ := Set.exists_upper_bound_image _ _ <| finite_setOf_isRoot hp #align polynomial.exists_max_root Polynomial.exists_max_root theorem exists_min_root [LinearOrder R] (p : R[X]) (hp : p ≠ 0) : ∃ x₀, ∀ x, p.IsRoot x → x₀ ≤ x := Set.exists_lower_bound_image _ _ <| finite_setOf_isRoot hp #align polynomial.exists_min_root Polynomial.exists_min_root theorem eq_of_infinite_eval_eq (p q : R[X]) (h : Set.Infinite { x | eval x p = eval x q }) : p = q := by rw [← sub_eq_zero] apply eq_zero_of_infinite_isRoot simpa only [IsRoot, eval_sub, sub_eq_zero] #align polynomial.eq_of_infinite_eval_eq Polynomial.eq_of_infinite_eval_eq theorem roots_mul {p q : R[X]} (hpq : p * q ≠ 0) : (p * q).roots = p.roots + q.roots := by classical exact Multiset.ext.mpr fun r => by rw [count_add, count_roots, count_roots, count_roots, rootMultiplicity_mul hpq] #align polynomial.roots_mul Polynomial.roots_mul theorem roots.le_of_dvd (h : q ≠ 0) : p ∣ q → roots p ≤ roots q := by rintro ⟨k, rfl⟩ exact Multiset.le_iff_exists_add.mpr ⟨k.roots, roots_mul h⟩ #align polynomial.roots.le_of_dvd Polynomial.roots.le_of_dvd theorem mem_roots_sub_C' {p : R[X]} {a x : R} : x ∈ (p - C a).roots ↔ p ≠ C a ∧ p.eval x = a := by rw [mem_roots', IsRoot.def, sub_ne_zero, eval_sub, sub_eq_zero, eval_C] set_option linter.uppercaseLean3 false in #align polynomial.mem_roots_sub_C' Polynomial.mem_roots_sub_C' theorem mem_roots_sub_C {p : R[X]} {a x : R} (hp0 : 0 < degree p) : x ∈ (p - C a).roots ↔ p.eval x = a := mem_roots_sub_C'.trans <| and_iff_right fun hp => hp0.not_le <| hp.symm ▸ degree_C_le set_option linter.uppercaseLean3 false in #align polynomial.mem_roots_sub_C Polynomial.mem_roots_sub_C @[simp] theorem roots_X_sub_C (r : R) : roots (X - C r) = {r} := by classical ext s rw [count_roots, rootMultiplicity_X_sub_C, count_singleton] set_option linter.uppercaseLean3 false in #align polynomial.roots_X_sub_C Polynomial.roots_X_sub_C @[simp] theorem roots_X : roots (X : R[X]) = {0} := by rw [← roots_X_sub_C, C_0, sub_zero] set_option linter.uppercaseLean3 false in #align polynomial.roots_X Polynomial.roots_X @[simp] theorem roots_C (x : R) : (C x).roots = 0 := by classical exact if H : x = 0 then by rw [H, C_0, roots_zero] else Multiset.ext.mpr fun r => (by rw [count_roots, count_zero, rootMultiplicity_eq_zero (not_isRoot_C _ _ H)]) set_option linter.uppercaseLean3 false in #align polynomial.roots_C Polynomial.roots_C @[simp] theorem roots_one : (1 : R[X]).roots = ∅ := roots_C 1 #align polynomial.roots_one Polynomial.roots_one @[simp] theorem roots_C_mul (p : R[X]) (ha : a ≠ 0) : (C a * p).roots = p.roots := by by_cases hp : p = 0 <;> simp only [roots_mul, *, Ne, mul_eq_zero, C_eq_zero, or_self_iff, not_false_iff, roots_C, zero_add, mul_zero] set_option linter.uppercaseLean3 false in #align polynomial.roots_C_mul Polynomial.roots_C_mul @[simp] theorem roots_smul_nonzero (p : R[X]) (ha : a ≠ 0) : (a • p).roots = p.roots := by rw [smul_eq_C_mul, roots_C_mul _ ha] #align polynomial.roots_smul_nonzero Polynomial.roots_smul_nonzero @[simp] lemma roots_neg (p : R[X]) : (-p).roots = p.roots := by rw [← neg_one_smul R p, roots_smul_nonzero p (neg_ne_zero.mpr one_ne_zero)] theorem roots_list_prod (L : List R[X]) : (0 : R[X]) ∉ L → L.prod.roots = (L : Multiset R[X]).bind roots := List.recOn L (fun _ => roots_one) fun hd tl ih H => by rw [List.mem_cons, not_or] at H rw [List.prod_cons, roots_mul (mul_ne_zero (Ne.symm H.1) <| List.prod_ne_zero H.2), ← Multiset.cons_coe, Multiset.cons_bind, ih H.2] #align polynomial.roots_list_prod Polynomial.roots_list_prod theorem roots_multiset_prod (m : Multiset R[X]) : (0 : R[X]) ∉ m → m.prod.roots = m.bind roots := by rcases m with ⟨L⟩ simpa only [Multiset.prod_coe, quot_mk_to_coe''] using roots_list_prod L #align polynomial.roots_multiset_prod Polynomial.roots_multiset_prod theorem roots_prod {ι : Type*} (f : ι → R[X]) (s : Finset ι) : s.prod f ≠ 0 → (s.prod f).roots = s.val.bind fun i => roots (f i) := by rcases s with ⟨m, hm⟩ simpa [Multiset.prod_eq_zero_iff, Multiset.bind_map] using roots_multiset_prod (m.map f) #align polynomial.roots_prod Polynomial.roots_prod @[simp] theorem roots_pow (p : R[X]) (n : ℕ) : (p ^ n).roots = n • p.roots := by induction' n with n ihn · rw [pow_zero, roots_one, zero_smul, empty_eq_zero] · rcases eq_or_ne p 0 with (rfl | hp) · rw [zero_pow n.succ_ne_zero, roots_zero, smul_zero] · rw [pow_succ, roots_mul (mul_ne_zero (pow_ne_zero _ hp) hp), ihn, add_smul, one_smul] #align polynomial.roots_pow Polynomial.roots_pow theorem roots_X_pow (n : ℕ) : (X ^ n : R[X]).roots = n • ({0} : Multiset R) := by rw [roots_pow, roots_X] set_option linter.uppercaseLean3 false in #align polynomial.roots_X_pow Polynomial.roots_X_pow theorem roots_C_mul_X_pow (ha : a ≠ 0) (n : ℕ) : Polynomial.roots (C a * X ^ n) = n • ({0} : Multiset R) := by rw [roots_C_mul _ ha, roots_X_pow] set_option linter.uppercaseLean3 false in #align polynomial.roots_C_mul_X_pow Polynomial.roots_C_mul_X_pow @[simp] theorem roots_monomial (ha : a ≠ 0) (n : ℕ) : (monomial n a).roots = n • ({0} : Multiset R) := by rw [← C_mul_X_pow_eq_monomial, roots_C_mul_X_pow ha] #align polynomial.roots_monomial Polynomial.roots_monomial
Mathlib/Algebra/Polynomial/Roots.lean
272
276
theorem roots_prod_X_sub_C (s : Finset R) : (s.prod fun a => X - C a).roots = s.val := by
apply (roots_prod (fun a => X - C a) s ?_).trans · simp_rw [roots_X_sub_C] rw [Multiset.bind_singleton, Multiset.map_id'] · refine prod_ne_zero_iff.mpr (fun a _ => X_sub_C_ne_zero a)
/- Copyright (c) 2022 Rémi Bottinelli. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémi Bottinelli, Junyan Xu -/ import Mathlib.Algebra.Group.Subgroup.Basic import Mathlib.CategoryTheory.Groupoid.VertexGroup import Mathlib.CategoryTheory.Groupoid.Basic import Mathlib.CategoryTheory.Groupoid import Mathlib.Data.Set.Lattice import Mathlib.Order.GaloisConnection #align_import category_theory.groupoid.subgroupoid from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a" /-! # Subgroupoid This file defines subgroupoids as `structure`s containing the subsets of arrows and their stability under composition and inversion. Also defined are: * containment of subgroupoids is a complete lattice; * images and preimages of subgroupoids under a functor; * the notion of normality of subgroupoids and its stability under intersection and preimage; * compatibility of the above with `CategoryTheory.Groupoid.vertexGroup`. ## Main definitions Given a type `C` with associated `groupoid C` instance. * `CategoryTheory.Subgroupoid C` is the type of subgroupoids of `C` * `CategoryTheory.Subgroupoid.IsNormal` is the property that the subgroupoid is stable under conjugation by arbitrary arrows, _and_ that all identity arrows are contained in the subgroupoid. * `CategoryTheory.Subgroupoid.comap` is the "preimage" map of subgroupoids along a functor. * `CategoryTheory.Subgroupoid.map` is the "image" map of subgroupoids along a functor _injective on objects_. * `CategoryTheory.Subgroupoid.vertexSubgroup` is the subgroup of the `vertex group` at a given vertex `v`, assuming `v` is contained in the `CategoryTheory.Subgroupoid` (meaning, by definition, that the arrow `𝟙 v` is contained in the subgroupoid). ## Implementation details The structure of this file is copied from/inspired by `Mathlib/GroupTheory/Subgroup/Basic.lean` and `Mathlib/Combinatorics/SimpleGraph/Subgraph.lean`. ## TODO * Equivalent inductive characterization of generated (normal) subgroupoids. * Characterization of normal subgroupoids as kernels. * Prove that `CategoryTheory.Subgroupoid.full` and `CategoryTheory.Subgroupoid.disconnect` preserve intersections (and `CategoryTheory.Subgroupoid.disconnect` also unions) ## Tags category theory, groupoid, subgroupoid -/ namespace CategoryTheory open Set Groupoid universe u v variable {C : Type u} [Groupoid C] /-- A sugroupoid of `C` consists of a choice of arrows for each pair of vertices, closed under composition and inverses. -/ @[ext] structure Subgroupoid (C : Type u) [Groupoid C] where arrows : ∀ c d : C, Set (c ⟶ d) protected inv : ∀ {c d} {p : c ⟶ d}, p ∈ arrows c d → Groupoid.inv p ∈ arrows d c protected mul : ∀ {c d e} {p}, p ∈ arrows c d → ∀ {q}, q ∈ arrows d e → p ≫ q ∈ arrows c e #align category_theory.subgroupoid CategoryTheory.Subgroupoid namespace Subgroupoid variable (S : Subgroupoid C) theorem inv_mem_iff {c d : C} (f : c ⟶ d) : Groupoid.inv f ∈ S.arrows d c ↔ f ∈ S.arrows c d := by constructor · intro h simpa only [inv_eq_inv, IsIso.inv_inv] using S.inv h · apply S.inv #align category_theory.subgroupoid.inv_mem_iff CategoryTheory.Subgroupoid.inv_mem_iff theorem mul_mem_cancel_left {c d e : C} {f : c ⟶ d} {g : d ⟶ e} (hf : f ∈ S.arrows c d) : f ≫ g ∈ S.arrows c e ↔ g ∈ S.arrows d e := by constructor · rintro h suffices Groupoid.inv f ≫ f ≫ g ∈ S.arrows d e by simpa only [inv_eq_inv, IsIso.inv_hom_id_assoc] using this apply S.mul (S.inv hf) h · apply S.mul hf #align category_theory.subgroupoid.mul_mem_cancel_left CategoryTheory.Subgroupoid.mul_mem_cancel_left theorem mul_mem_cancel_right {c d e : C} {f : c ⟶ d} {g : d ⟶ e} (hg : g ∈ S.arrows d e) : f ≫ g ∈ S.arrows c e ↔ f ∈ S.arrows c d := by constructor · rintro h suffices (f ≫ g) ≫ Groupoid.inv g ∈ S.arrows c d by simpa only [inv_eq_inv, IsIso.hom_inv_id, Category.comp_id, Category.assoc] using this apply S.mul h (S.inv hg) · exact fun hf => S.mul hf hg #align category_theory.subgroupoid.mul_mem_cancel_right CategoryTheory.Subgroupoid.mul_mem_cancel_right /-- The vertices of `C` on which `S` has non-trivial isotropy -/ def objs : Set C := {c : C | (S.arrows c c).Nonempty} #align category_theory.subgroupoid.objs CategoryTheory.Subgroupoid.objs theorem mem_objs_of_src {c d : C} {f : c ⟶ d} (h : f ∈ S.arrows c d) : c ∈ S.objs := ⟨f ≫ Groupoid.inv f, S.mul h (S.inv h)⟩ #align category_theory.subgroupoid.mem_objs_of_src CategoryTheory.Subgroupoid.mem_objs_of_src theorem mem_objs_of_tgt {c d : C} {f : c ⟶ d} (h : f ∈ S.arrows c d) : d ∈ S.objs := ⟨Groupoid.inv f ≫ f, S.mul (S.inv h) h⟩ #align category_theory.subgroupoid.mem_objs_of_tgt CategoryTheory.Subgroupoid.mem_objs_of_tgt theorem id_mem_of_nonempty_isotropy (c : C) : c ∈ objs S → 𝟙 c ∈ S.arrows c c := by rintro ⟨γ, hγ⟩ convert S.mul hγ (S.inv hγ) simp only [inv_eq_inv, IsIso.hom_inv_id] #align category_theory.subgroupoid.id_mem_of_nonempty_isotropy CategoryTheory.Subgroupoid.id_mem_of_nonempty_isotropy theorem id_mem_of_src {c d : C} {f : c ⟶ d} (h : f ∈ S.arrows c d) : 𝟙 c ∈ S.arrows c c := id_mem_of_nonempty_isotropy S c (mem_objs_of_src S h) #align category_theory.subgroupoid.id_mem_of_src CategoryTheory.Subgroupoid.id_mem_of_src theorem id_mem_of_tgt {c d : C} {f : c ⟶ d} (h : f ∈ S.arrows c d) : 𝟙 d ∈ S.arrows d d := id_mem_of_nonempty_isotropy S d (mem_objs_of_tgt S h) #align category_theory.subgroupoid.id_mem_of_tgt CategoryTheory.Subgroupoid.id_mem_of_tgt /-- A subgroupoid seen as a quiver on vertex set `C` -/ def asWideQuiver : Quiver C := ⟨fun c d => Subtype <| S.arrows c d⟩ #align category_theory.subgroupoid.as_wide_quiver CategoryTheory.Subgroupoid.asWideQuiver /-- The coercion of a subgroupoid as a groupoid -/ @[simps comp_coe, simps (config := .lemmasOnly) inv_coe] instance coe : Groupoid S.objs where Hom a b := S.arrows a.val b.val id a := ⟨𝟙 a.val, id_mem_of_nonempty_isotropy S a.val a.prop⟩ comp p q := ⟨p.val ≫ q.val, S.mul p.prop q.prop⟩ inv p := ⟨Groupoid.inv p.val, S.inv p.prop⟩ #align category_theory.subgroupoid.coe CategoryTheory.Subgroupoid.coe @[simp] theorem coe_inv_coe' {c d : S.objs} (p : c ⟶ d) : (CategoryTheory.inv p).val = CategoryTheory.inv p.val := by simp only [← inv_eq_inv, coe_inv_coe] #align category_theory.subgroupoid.coe_inv_coe' CategoryTheory.Subgroupoid.coe_inv_coe' /-- The embedding of the coerced subgroupoid to its parent-/ def hom : S.objs ⥤ C where obj c := c.val map f := f.val map_id _ := rfl map_comp _ _ := rfl #align category_theory.subgroupoid.hom CategoryTheory.Subgroupoid.hom theorem hom.inj_on_objects : Function.Injective (hom S).obj := by rintro ⟨c, hc⟩ ⟨d, hd⟩ hcd simp only [Subtype.mk_eq_mk]; exact hcd #align category_theory.subgroupoid.hom.inj_on_objects CategoryTheory.Subgroupoid.hom.inj_on_objects theorem hom.faithful : ∀ c d, Function.Injective fun f : c ⟶ d => (hom S).map f := by rintro ⟨c, hc⟩ ⟨d, hd⟩ ⟨f, hf⟩ ⟨g, hg⟩ hfg; exact Subtype.eq hfg #align category_theory.subgroupoid.hom.faithful CategoryTheory.Subgroupoid.hom.faithful /-- The subgroup of the vertex group at `c` given by the subgroupoid -/ def vertexSubgroup {c : C} (hc : c ∈ S.objs) : Subgroup (c ⟶ c) where carrier := S.arrows c c mul_mem' hf hg := S.mul hf hg one_mem' := id_mem_of_nonempty_isotropy _ _ hc inv_mem' hf := S.inv hf #align category_theory.subgroupoid.vertex_subgroup CategoryTheory.Subgroupoid.vertexSubgroup /-- The set of all arrows of a subgroupoid, as a set in `Σ c d : C, c ⟶ d`. -/ @[coe] def toSet (S : Subgroupoid C) : Set (Σ c d : C, c ⟶ d) := {F | F.2.2 ∈ S.arrows F.1 F.2.1} instance : SetLike (Subgroupoid C) (Σ c d : C, c ⟶ d) where coe := toSet coe_injective' := fun ⟨S, _, _⟩ ⟨T, _, _⟩ h => by ext c d f; apply Set.ext_iff.1 h ⟨c, d, f⟩ theorem mem_iff (S : Subgroupoid C) (F : Σ c d, c ⟶ d) : F ∈ S ↔ F.2.2 ∈ S.arrows F.1 F.2.1 := Iff.rfl #align category_theory.subgroupoid.mem_iff CategoryTheory.Subgroupoid.mem_iff theorem le_iff (S T : Subgroupoid C) : S ≤ T ↔ ∀ {c d}, S.arrows c d ⊆ T.arrows c d := by rw [SetLike.le_def, Sigma.forall]; exact forall_congr' fun c => Sigma.forall #align category_theory.subgroupoid.le_iff CategoryTheory.Subgroupoid.le_iff instance : Top (Subgroupoid C) := ⟨{ arrows := fun _ _ => Set.univ mul := by intros; trivial inv := by intros; trivial }⟩ theorem mem_top {c d : C} (f : c ⟶ d) : f ∈ (⊤ : Subgroupoid C).arrows c d := trivial #align category_theory.subgroupoid.mem_top CategoryTheory.Subgroupoid.mem_top theorem mem_top_objs (c : C) : c ∈ (⊤ : Subgroupoid C).objs := by dsimp [Top.top, objs] simp only [univ_nonempty] #align category_theory.subgroupoid.mem_top_objs CategoryTheory.Subgroupoid.mem_top_objs instance : Bot (Subgroupoid C) := ⟨{ arrows := fun _ _ => ∅ mul := False.elim inv := False.elim }⟩ instance : Inhabited (Subgroupoid C) := ⟨⊤⟩ instance : Inf (Subgroupoid C) := ⟨fun S T => { arrows := fun c d => S.arrows c d ∩ T.arrows c d inv := fun hp ↦ ⟨S.inv hp.1, T.inv hp.2⟩ mul := fun hp _ hq ↦ ⟨S.mul hp.1 hq.1, T.mul hp.2 hq.2⟩ }⟩ instance : InfSet (Subgroupoid C) := ⟨fun s => { arrows := fun c d => ⋂ S ∈ s, Subgroupoid.arrows S c d inv := fun hp ↦ by rw [mem_iInter₂] at hp ⊢; exact fun S hS => S.inv (hp S hS) mul := fun hp _ hq ↦ by rw [mem_iInter₂] at hp hq ⊢; exact fun S hS => S.mul (hp S hS) (hq S hS) }⟩ -- Porting note (#10756): new lemma theorem mem_sInf_arrows {s : Set (Subgroupoid C)} {c d : C} {p : c ⟶ d} : p ∈ (sInf s).arrows c d ↔ ∀ S ∈ s, p ∈ S.arrows c d := mem_iInter₂ theorem mem_sInf {s : Set (Subgroupoid C)} {p : Σ c d : C, c ⟶ d} : p ∈ sInf s ↔ ∀ S ∈ s, p ∈ S := mem_sInf_arrows instance : CompleteLattice (Subgroupoid C) := { completeLatticeOfInf (Subgroupoid C) (by refine fun s => ⟨fun S Ss F => ?_, fun T Tl F fT => ?_⟩ <;> simp only [mem_sInf] exacts [fun hp => hp S Ss, fun S Ss => Tl Ss fT]) with bot := ⊥ bot_le := fun S => empty_subset _ top := ⊤ le_top := fun S => subset_univ _ inf := (· ⊓ ·) le_inf := fun R S T RS RT _ pR => ⟨RS pR, RT pR⟩ inf_le_left := fun R S _ => And.left inf_le_right := fun R S _ => And.right } theorem le_objs {S T : Subgroupoid C} (h : S ≤ T) : S.objs ⊆ T.objs := fun s ⟨γ, hγ⟩ => ⟨γ, @h ⟨s, s, γ⟩ hγ⟩ #align category_theory.subgroupoid.le_objs CategoryTheory.Subgroupoid.le_objs /-- The functor associated to the embedding of subgroupoids -/ def inclusion {S T : Subgroupoid C} (h : S ≤ T) : S.objs ⥤ T.objs where obj s := ⟨s.val, le_objs h s.prop⟩ map f := ⟨f.val, @h ⟨_, _, f.val⟩ f.prop⟩ map_id _ := rfl map_comp _ _ := rfl #align category_theory.subgroupoid.inclusion CategoryTheory.Subgroupoid.inclusion theorem inclusion_inj_on_objects {S T : Subgroupoid C} (h : S ≤ T) : Function.Injective (inclusion h).obj := fun ⟨s, hs⟩ ⟨t, ht⟩ => by simpa only [inclusion, Subtype.mk_eq_mk] using id #align category_theory.subgroupoid.inclusion_inj_on_objects CategoryTheory.Subgroupoid.inclusion_inj_on_objects theorem inclusion_faithful {S T : Subgroupoid C} (h : S ≤ T) (s t : S.objs) : Function.Injective fun f : s ⟶ t => (inclusion h).map f := fun ⟨f, hf⟩ ⟨g, hg⟩ => by -- Porting note: was `...; simpa only [Subtype.mk_eq_mk] using id` dsimp only [inclusion]; rw [Subtype.mk_eq_mk, Subtype.mk_eq_mk]; exact id #align category_theory.subgroupoid.inclusion_faithful CategoryTheory.Subgroupoid.inclusion_faithful theorem inclusion_refl {S : Subgroupoid C} : inclusion (le_refl S) = 𝟭 S.objs := Functor.hext (fun _ => rfl) fun _ _ _ => HEq.refl _ #align category_theory.subgroupoid.inclusion_refl CategoryTheory.Subgroupoid.inclusion_refl theorem inclusion_trans {R S T : Subgroupoid C} (k : R ≤ S) (h : S ≤ T) : inclusion (k.trans h) = inclusion k ⋙ inclusion h := rfl #align category_theory.subgroupoid.inclusion_trans CategoryTheory.Subgroupoid.inclusion_trans theorem inclusion_comp_embedding {S T : Subgroupoid C} (h : S ≤ T) : inclusion h ⋙ T.hom = S.hom := rfl #align category_theory.subgroupoid.inclusion_comp_embedding CategoryTheory.Subgroupoid.inclusion_comp_embedding /-- The family of arrows of the discrete groupoid -/ inductive Discrete.Arrows : ∀ c d : C, (c ⟶ d) → Prop | id (c : C) : Discrete.Arrows c c (𝟙 c) #align category_theory.subgroupoid.discrete.arrows CategoryTheory.Subgroupoid.Discrete.Arrows /-- The only arrows of the discrete groupoid are the identity arrows. -/ def discrete : Subgroupoid C where arrows c d := {p | Discrete.Arrows c d p} inv := by rintro _ _ _ ⟨⟩; simp only [inv_eq_inv, IsIso.inv_id]; constructor mul := by rintro _ _ _ _ ⟨⟩ _ ⟨⟩; rw [Category.comp_id]; constructor #align category_theory.subgroupoid.discrete CategoryTheory.Subgroupoid.discrete theorem mem_discrete_iff {c d : C} (f : c ⟶ d) : f ∈ discrete.arrows c d ↔ ∃ h : c = d, f = eqToHom h := ⟨by rintro ⟨⟩; exact ⟨rfl, rfl⟩, by rintro ⟨rfl, rfl⟩; constructor⟩ #align category_theory.subgroupoid.mem_discrete_iff CategoryTheory.Subgroupoid.mem_discrete_iff /-- A subgroupoid is wide if its carrier set is all of `C`-/ structure IsWide : Prop where wide : ∀ c, 𝟙 c ∈ S.arrows c c #align category_theory.subgroupoid.is_wide CategoryTheory.Subgroupoid.IsWide theorem isWide_iff_objs_eq_univ : S.IsWide ↔ S.objs = Set.univ := by constructor · rintro h ext x; constructor <;> simp only [top_eq_univ, mem_univ, imp_true_iff, forall_true_left] apply mem_objs_of_src S (h.wide x) · rintro h refine ⟨fun c => ?_⟩ obtain ⟨γ, γS⟩ := (le_of_eq h.symm : ⊤ ⊆ S.objs) (Set.mem_univ c) exact id_mem_of_src S γS #align category_theory.subgroupoid.is_wide_iff_objs_eq_univ CategoryTheory.Subgroupoid.isWide_iff_objs_eq_univ theorem IsWide.id_mem {S : Subgroupoid C} (Sw : S.IsWide) (c : C) : 𝟙 c ∈ S.arrows c c := Sw.wide c #align category_theory.subgroupoid.is_wide.id_mem CategoryTheory.Subgroupoid.IsWide.id_mem theorem IsWide.eqToHom_mem {S : Subgroupoid C} (Sw : S.IsWide) {c d : C} (h : c = d) : eqToHom h ∈ S.arrows c d := by cases h; simp only [eqToHom_refl]; apply Sw.id_mem c #align category_theory.subgroupoid.is_wide.eq_to_hom_mem CategoryTheory.Subgroupoid.IsWide.eqToHom_mem /-- A subgroupoid is normal if it is wide and satisfies the expected stability under conjugacy. -/ structure IsNormal extends IsWide S : Prop where conj : ∀ {c d} (p : c ⟶ d) {γ : c ⟶ c}, γ ∈ S.arrows c c → Groupoid.inv p ≫ γ ≫ p ∈ S.arrows d d #align category_theory.subgroupoid.is_normal CategoryTheory.Subgroupoid.IsNormal theorem IsNormal.conj' {S : Subgroupoid C} (Sn : IsNormal S) : ∀ {c d} (p : d ⟶ c) {γ : c ⟶ c}, γ ∈ S.arrows c c → p ≫ γ ≫ Groupoid.inv p ∈ S.arrows d d := fun p γ hs => by convert Sn.conj (Groupoid.inv p) hs; simp #align category_theory.subgroupoid.is_normal.conj' CategoryTheory.Subgroupoid.IsNormal.conj' theorem IsNormal.conjugation_bij (Sn : IsNormal S) {c d} (p : c ⟶ d) : Set.BijOn (fun γ : c ⟶ c => Groupoid.inv p ≫ γ ≫ p) (S.arrows c c) (S.arrows d d) := by refine ⟨fun γ γS => Sn.conj p γS, fun γ₁ _ γ₂ _ h => ?_, fun δ δS => ⟨p ≫ δ ≫ Groupoid.inv p, Sn.conj' p δS, ?_⟩⟩ · simpa only [inv_eq_inv, Category.assoc, IsIso.hom_inv_id, Category.comp_id, IsIso.hom_inv_id_assoc] using p ≫= h =≫ inv p · simp only [inv_eq_inv, Category.assoc, IsIso.inv_hom_id, Category.comp_id, IsIso.inv_hom_id_assoc] #align category_theory.subgroupoid.is_normal.conjugation_bij CategoryTheory.Subgroupoid.IsNormal.conjugation_bij theorem top_isNormal : IsNormal (⊤ : Subgroupoid C) := { wide := fun _ => trivial conj := fun _ _ _ => trivial } #align category_theory.subgroupoid.top_is_normal CategoryTheory.Subgroupoid.top_isNormal theorem sInf_isNormal (s : Set <| Subgroupoid C) (sn : ∀ S ∈ s, IsNormal S) : IsNormal (sInf s) := { wide := by simp_rw [sInf, mem_iInter₂]; exact fun c S Ss => (sn S Ss).wide c conj := by simp_rw [sInf, mem_iInter₂]; exact fun p γ hγ S Ss => (sn S Ss).conj p (hγ S Ss) } #align category_theory.subgroupoid.Inf_is_normal CategoryTheory.Subgroupoid.sInf_isNormal theorem discrete_isNormal : (@discrete C _).IsNormal := { wide := fun c => by constructor conj := fun f γ hγ => by cases hγ simp only [inv_eq_inv, Category.id_comp, IsIso.inv_hom_id]; constructor } #align category_theory.subgroupoid.discrete_is_normal CategoryTheory.Subgroupoid.discrete_isNormal theorem IsNormal.vertexSubgroup (Sn : IsNormal S) (c : C) (cS : c ∈ S.objs) : (S.vertexSubgroup cS).Normal where conj_mem x hx y := by rw [mul_assoc]; exact Sn.conj' y hx #align category_theory.subgroupoid.is_normal.vertex_subgroup CategoryTheory.Subgroupoid.IsNormal.vertexSubgroup section GeneratedSubgroupoid -- TODO: proof that generated is just "words in X" and generatedNormal is similarly variable (X : ∀ c d : C, Set (c ⟶ d)) /-- The subgropoid generated by the set of arrows `X` -/ def generated : Subgroupoid C := sInf {S : Subgroupoid C | ∀ c d, X c d ⊆ S.arrows c d} #align category_theory.subgroupoid.generated CategoryTheory.Subgroupoid.generated theorem subset_generated (c d : C) : X c d ⊆ (generated X).arrows c d := by dsimp only [generated, sInf] simp only [subset_iInter₂_iff] exact fun S hS f fS => hS _ _ fS #align category_theory.subgroupoid.subset_generated CategoryTheory.Subgroupoid.subset_generated /-- The normal sugroupoid generated by the set of arrows `X` -/ def generatedNormal : Subgroupoid C := sInf {S : Subgroupoid C | (∀ c d, X c d ⊆ S.arrows c d) ∧ S.IsNormal} #align category_theory.subgroupoid.generated_normal CategoryTheory.Subgroupoid.generatedNormal theorem generated_le_generatedNormal : generated X ≤ generatedNormal X := by apply @sInf_le_sInf (Subgroupoid C) _ exact fun S ⟨h, _⟩ => h #align category_theory.subgroupoid.generated_le_generated_normal CategoryTheory.Subgroupoid.generated_le_generatedNormal theorem generatedNormal_isNormal : (generatedNormal X).IsNormal := sInf_isNormal _ fun _ h => h.right #align category_theory.subgroupoid.generated_normal_is_normal CategoryTheory.Subgroupoid.generatedNormal_isNormal theorem IsNormal.generatedNormal_le {S : Subgroupoid C} (Sn : S.IsNormal) : generatedNormal X ≤ S ↔ ∀ c d, X c d ⊆ S.arrows c d := by constructor · rintro h c d have h' := generated_le_generatedNormal X rw [le_iff] at h h' exact ((subset_generated X c d).trans (@h' c d)).trans (@h c d) · rintro h apply @sInf_le (Subgroupoid C) _ exact ⟨h, Sn⟩ #align category_theory.subgroupoid.is_normal.generated_normal_le CategoryTheory.Subgroupoid.IsNormal.generatedNormal_le end GeneratedSubgroupoid section Hom variable {D : Type*} [Groupoid D] (φ : C ⥤ D) /-- A functor between groupoid defines a map of subgroupoids in the reverse direction by taking preimages. -/ def comap (S : Subgroupoid D) : Subgroupoid C where arrows c d := {f : c ⟶ d | φ.map f ∈ S.arrows (φ.obj c) (φ.obj d)} inv hp := by rw [mem_setOf, inv_eq_inv, φ.map_inv, ← inv_eq_inv]; exact S.inv hp mul := by intros simp only [mem_setOf, Functor.map_comp] apply S.mul <;> assumption #align category_theory.subgroupoid.comap CategoryTheory.Subgroupoid.comap theorem comap_mono (S T : Subgroupoid D) : S ≤ T → comap φ S ≤ comap φ T := fun ST _ => @ST ⟨_, _, _⟩ #align category_theory.subgroupoid.comap_mono CategoryTheory.Subgroupoid.comap_mono theorem isNormal_comap {S : Subgroupoid D} (Sn : IsNormal S) : IsNormal (comap φ S) where wide c := by rw [comap, mem_setOf, Functor.map_id]; apply Sn.wide conj f γ hγ := by simp_rw [inv_eq_inv f, comap, mem_setOf, Functor.map_comp, Functor.map_inv, ← inv_eq_inv] exact Sn.conj _ hγ #align category_theory.subgroupoid.is_normal_comap CategoryTheory.Subgroupoid.isNormal_comap @[simp] theorem comap_comp {E : Type*} [Groupoid E] (ψ : D ⥤ E) : comap (φ ⋙ ψ) = comap φ ∘ comap ψ := rfl #align category_theory.subgroupoid.comap_comp CategoryTheory.Subgroupoid.comap_comp /-- The kernel of a functor between subgroupoid is the preimage. -/ def ker : Subgroupoid C := comap φ discrete #align category_theory.subgroupoid.ker CategoryTheory.Subgroupoid.ker theorem mem_ker_iff {c d : C} (f : c ⟶ d) : f ∈ (ker φ).arrows c d ↔ ∃ h : φ.obj c = φ.obj d, φ.map f = eqToHom h := mem_discrete_iff (φ.map f) #align category_theory.subgroupoid.mem_ker_iff CategoryTheory.Subgroupoid.mem_ker_iff theorem ker_isNormal : (ker φ).IsNormal := isNormal_comap φ discrete_isNormal #align category_theory.subgroupoid.ker_is_normal CategoryTheory.Subgroupoid.ker_isNormal @[simp] theorem ker_comp {E : Type*} [Groupoid E] (ψ : D ⥤ E) : ker (φ ⋙ ψ) = comap φ (ker ψ) := rfl #align category_theory.subgroupoid.ker_comp CategoryTheory.Subgroupoid.ker_comp /-- The family of arrows of the image of a subgroupoid under a functor injective on objects -/ inductive Map.Arrows (hφ : Function.Injective φ.obj) (S : Subgroupoid C) : ∀ c d : D, (c ⟶ d) → Prop | im {c d : C} (f : c ⟶ d) (hf : f ∈ S.arrows c d) : Map.Arrows hφ S (φ.obj c) (φ.obj d) (φ.map f) #align category_theory.subgroupoid.map.arrows CategoryTheory.Subgroupoid.Map.Arrows theorem Map.arrows_iff (hφ : Function.Injective φ.obj) (S : Subgroupoid C) {c d : D} (f : c ⟶ d) : Map.Arrows φ hφ S c d f ↔ ∃ (a b : C) (g : a ⟶ b) (ha : φ.obj a = c) (hb : φ.obj b = d) (_hg : g ∈ S.arrows a b), f = eqToHom ha.symm ≫ φ.map g ≫ eqToHom hb := by constructor · rintro ⟨g, hg⟩; exact ⟨_, _, g, rfl, rfl, hg, eq_conj_eqToHom _⟩ · rintro ⟨a, b, g, rfl, rfl, hg, rfl⟩; rw [← eq_conj_eqToHom]; constructor; exact hg #align category_theory.subgroupoid.map.arrows_iff CategoryTheory.Subgroupoid.Map.arrows_iff /-- The "forward" image of a subgroupoid under a functor injective on objects -/ def map (hφ : Function.Injective φ.obj) (S : Subgroupoid C) : Subgroupoid D where arrows c d := {x | Map.Arrows φ hφ S c d x} inv := by rintro _ _ _ ⟨⟩ rw [inv_eq_inv, ← Functor.map_inv, ← inv_eq_inv] constructor; apply S.inv; assumption mul := by rintro _ _ _ _ ⟨f, hf⟩ q hq obtain ⟨c₃, c₄, g, he, rfl, hg, gq⟩ := (Map.arrows_iff φ hφ S q).mp hq cases hφ he; rw [gq, ← eq_conj_eqToHom, ← φ.map_comp] constructor; exact S.mul hf hg #align category_theory.subgroupoid.map CategoryTheory.Subgroupoid.map theorem mem_map_iff (hφ : Function.Injective φ.obj) (S : Subgroupoid C) {c d : D} (f : c ⟶ d) : f ∈ (map φ hφ S).arrows c d ↔ ∃ (a b : C) (g : a ⟶ b) (ha : φ.obj a = c) (hb : φ.obj b = d) (_hg : g ∈ S.arrows a b), f = eqToHom ha.symm ≫ φ.map g ≫ eqToHom hb := Map.arrows_iff φ hφ S f #align category_theory.subgroupoid.mem_map_iff CategoryTheory.Subgroupoid.mem_map_iff theorem galoisConnection_map_comap (hφ : Function.Injective φ.obj) : GaloisConnection (map φ hφ) (comap φ) := by rintro S T; simp_rw [le_iff]; constructor · exact fun h c d f fS => h (Map.Arrows.im f fS) · rintro h _ _ g ⟨a, gφS⟩ exact h gφS #align category_theory.subgroupoid.galois_connection_map_comap CategoryTheory.Subgroupoid.galoisConnection_map_comap theorem map_mono (hφ : Function.Injective φ.obj) (S T : Subgroupoid C) : S ≤ T → map φ hφ S ≤ map φ hφ T := fun h => (galoisConnection_map_comap φ hφ).monotone_l h #align category_theory.subgroupoid.map_mono CategoryTheory.Subgroupoid.map_mono theorem le_comap_map (hφ : Function.Injective φ.obj) (S : Subgroupoid C) : S ≤ comap φ (map φ hφ S) := (galoisConnection_map_comap φ hφ).le_u_l S #align category_theory.subgroupoid.le_comap_map CategoryTheory.Subgroupoid.le_comap_map theorem map_comap_le (hφ : Function.Injective φ.obj) (T : Subgroupoid D) : map φ hφ (comap φ T) ≤ T := (galoisConnection_map_comap φ hφ).l_u_le T #align category_theory.subgroupoid.map_comap_le CategoryTheory.Subgroupoid.map_comap_le theorem map_le_iff_le_comap (hφ : Function.Injective φ.obj) (S : Subgroupoid C) (T : Subgroupoid D) : map φ hφ S ≤ T ↔ S ≤ comap φ T := (galoisConnection_map_comap φ hφ).le_iff_le #align category_theory.subgroupoid.map_le_iff_le_comap CategoryTheory.Subgroupoid.map_le_iff_le_comap theorem mem_map_objs_iff (hφ : Function.Injective φ.obj) (d : D) : d ∈ (map φ hφ S).objs ↔ ∃ c ∈ S.objs, φ.obj c = d := by dsimp [objs, map] constructor · rintro ⟨f, hf⟩ change Map.Arrows φ hφ S d d f at hf; rw [Map.arrows_iff] at hf obtain ⟨c, d, g, ec, ed, eg, gS, eg⟩ := hf exact ⟨c, ⟨mem_objs_of_src S eg, ec⟩⟩ · rintro ⟨c, ⟨γ, γS⟩, rfl⟩ exact ⟨φ.map γ, ⟨γ, γS⟩⟩ #align category_theory.subgroupoid.mem_map_objs_iff CategoryTheory.Subgroupoid.mem_map_objs_iff @[simp] theorem map_objs_eq (hφ : Function.Injective φ.obj) : (map φ hφ S).objs = φ.obj '' S.objs := by ext x; convert mem_map_objs_iff S φ hφ x #align category_theory.subgroupoid.map_objs_eq CategoryTheory.Subgroupoid.map_objs_eq /-- The image of a functor injective on objects -/ def im (hφ : Function.Injective φ.obj) := map φ hφ ⊤ #align category_theory.subgroupoid.im CategoryTheory.Subgroupoid.im theorem mem_im_iff (hφ : Function.Injective φ.obj) {c d : D} (f : c ⟶ d) : f ∈ (im φ hφ).arrows c d ↔ ∃ (a b : C) (g : a ⟶ b) (ha : φ.obj a = c) (hb : φ.obj b = d), f = eqToHom ha.symm ≫ φ.map g ≫ eqToHom hb := by convert Map.arrows_iff φ hφ ⊤ f; simp only [Top.top, mem_univ, exists_true_left] #align category_theory.subgroupoid.mem_im_iff CategoryTheory.Subgroupoid.mem_im_iff theorem mem_im_objs_iff (hφ : Function.Injective φ.obj) (d : D) : d ∈ (im φ hφ).objs ↔ ∃ c : C, φ.obj c = d := by simp only [im, mem_map_objs_iff, mem_top_objs, true_and] #align category_theory.subgroupoid.mem_im_objs_iff CategoryTheory.Subgroupoid.mem_im_objs_iff theorem obj_surjective_of_im_eq_top (hφ : Function.Injective φ.obj) (hφ' : im φ hφ = ⊤) : Function.Surjective φ.obj := by rintro d rw [← mem_im_objs_iff, hφ'] apply mem_top_objs #align category_theory.subgroupoid.obj_surjective_of_im_eq_top CategoryTheory.Subgroupoid.obj_surjective_of_im_eq_top theorem isNormal_map (hφ : Function.Injective φ.obj) (hφ' : im φ hφ = ⊤) (Sn : S.IsNormal) : (map φ hφ S).IsNormal := { wide := fun d => by obtain ⟨c, rfl⟩ := obj_surjective_of_im_eq_top φ hφ hφ' d change Map.Arrows φ hφ S _ _ (𝟙 _); rw [← Functor.map_id] constructor; exact Sn.wide c conj := fun {d d'} g δ hδ => by rw [mem_map_iff] at hδ obtain ⟨c, c', γ, cd, cd', γS, hγ⟩ := hδ; subst_vars; cases hφ cd' have : d' ∈ (im φ hφ).objs := by rw [hφ']; apply mem_top_objs rw [mem_im_objs_iff] at this obtain ⟨c', rfl⟩ := this have : g ∈ (im φ hφ).arrows (φ.obj c) (φ.obj c') := by rw [hφ']; trivial rw [mem_im_iff] at this obtain ⟨b, b', f, hb, hb', _, hf⟩ := this; cases hφ hb; cases hφ hb' change Map.Arrows φ hφ S (φ.obj c') (φ.obj c') _ simp only [eqToHom_refl, Category.comp_id, Category.id_comp, inv_eq_inv] suffices Map.Arrows φ hφ S (φ.obj c') (φ.obj c') (φ.map <| Groupoid.inv f ≫ γ ≫ f) by simp only [inv_eq_inv, Functor.map_comp, Functor.map_inv] at this; exact this constructor; apply Sn.conj f γS } #align category_theory.subgroupoid.is_normal_map CategoryTheory.Subgroupoid.isNormal_map end Hom section Thin /-- A subgroupoid is thin (`CategoryTheory.Subgroupoid.IsThin`) if it has at most one arrow between any two vertices. -/ abbrev IsThin := Quiver.IsThin S.objs #align category_theory.subgroupoid.is_thin CategoryTheory.Subgroupoid.IsThin nonrec theorem isThin_iff : S.IsThin ↔ ∀ c : S.objs, Subsingleton (S.arrows c c) := isThin_iff _ #align category_theory.subgroupoid.is_thin_iff CategoryTheory.Subgroupoid.isThin_iff end Thin section Disconnected /-- A subgroupoid `IsTotallyDisconnected` if it has only isotropy arrows. -/ nonrec abbrev IsTotallyDisconnected := IsTotallyDisconnected S.objs #align category_theory.subgroupoid.is_totally_disconnected CategoryTheory.Subgroupoid.IsTotallyDisconnected theorem isTotallyDisconnected_iff : S.IsTotallyDisconnected ↔ ∀ c d, (S.arrows c d).Nonempty → c = d := by constructor · rintro h c d ⟨f, fS⟩ have := h ⟨c, mem_objs_of_src S fS⟩ ⟨d, mem_objs_of_tgt S fS⟩ ⟨f, fS⟩ exact congr_arg Subtype.val this · rintro h ⟨c, hc⟩ ⟨d, hd⟩ ⟨f, fS⟩ simp only [Subtype.mk_eq_mk] exact h c d ⟨f, fS⟩ #align category_theory.subgroupoid.is_totally_disconnected_iff CategoryTheory.Subgroupoid.isTotallyDisconnected_iff /-- The isotropy subgroupoid of `S` -/ def disconnect : Subgroupoid C where arrows c d := {f | c = d ∧ f ∈ S.arrows c d} inv := by rintro _ _ _ ⟨rfl, h⟩; exact ⟨rfl, S.inv h⟩ mul := by rintro _ _ _ _ ⟨rfl, h⟩ _ ⟨rfl, h'⟩; exact ⟨rfl, S.mul h h'⟩ #align category_theory.subgroupoid.disconnect CategoryTheory.Subgroupoid.disconnect theorem disconnect_le : S.disconnect ≤ S := by rw [le_iff]; rintro _ _ _ ⟨⟩; assumption #align category_theory.subgroupoid.disconnect_le CategoryTheory.Subgroupoid.disconnect_le theorem disconnect_normal (Sn : S.IsNormal) : S.disconnect.IsNormal := { wide := fun c => ⟨rfl, Sn.wide c⟩ conj := fun _ _ ⟨_, h'⟩ => ⟨rfl, Sn.conj _ h'⟩ } #align category_theory.subgroupoid.disconnect_normal CategoryTheory.Subgroupoid.disconnect_normal @[simp] theorem mem_disconnect_objs_iff {c : C} : c ∈ S.disconnect.objs ↔ c ∈ S.objs := ⟨fun ⟨γ, _, γS⟩ => ⟨γ, γS⟩, fun ⟨γ, γS⟩ => ⟨γ, rfl, γS⟩⟩ #align category_theory.subgroupoid.mem_disconnect_objs_iff CategoryTheory.Subgroupoid.mem_disconnect_objs_iff theorem disconnect_objs : S.disconnect.objs = S.objs := Set.ext fun _ ↦ mem_disconnect_objs_iff _ #align category_theory.subgroupoid.disconnect_objs CategoryTheory.Subgroupoid.disconnect_objs theorem disconnect_isTotallyDisconnected : S.disconnect.IsTotallyDisconnected := by rw [isTotallyDisconnected_iff]; exact fun c d ⟨_, h, _⟩ => h #align category_theory.subgroupoid.disconnect_is_totally_disconnected CategoryTheory.Subgroupoid.disconnect_isTotallyDisconnected end Disconnected section Full variable (D : Set C) /-- The full subgroupoid on a set `D : Set C` -/ def full : Subgroupoid C where arrows c d := {_f | c ∈ D ∧ d ∈ D} inv := by rintro _ _ _ ⟨⟩; constructor <;> assumption mul := by rintro _ _ _ _ ⟨⟩ _ ⟨⟩; constructor <;> assumption #align category_theory.subgroupoid.full CategoryTheory.Subgroupoid.full theorem full_objs : (full D).objs = D := Set.ext fun _ => ⟨fun ⟨_, h, _⟩ => h, fun h => ⟨𝟙 _, h, h⟩⟩ #align category_theory.subgroupoid.full_objs CategoryTheory.Subgroupoid.full_objs @[simp] theorem mem_full_iff {c d : C} {f : c ⟶ d} : f ∈ (full D).arrows c d ↔ c ∈ D ∧ d ∈ D := Iff.rfl #align category_theory.subgroupoid.mem_full_iff CategoryTheory.Subgroupoid.mem_full_iff @[simp] theorem mem_full_objs_iff {c : C} : c ∈ (full D).objs ↔ c ∈ D := by rw [full_objs] #align category_theory.subgroupoid.mem_full_objs_iff CategoryTheory.Subgroupoid.mem_full_objs_iff @[simp]
Mathlib/CategoryTheory/Groupoid/Subgroupoid.lean
682
684
theorem full_empty : full ∅ = (⊥ : Subgroupoid C) := by
ext simp only [Bot.bot, mem_full_iff, mem_empty_iff_false, and_self_iff]
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Order.Ring.Cast import Mathlib.Data.Int.Cast.Lemmas import Mathlib.Data.Nat.Bitwise import Mathlib.Data.Nat.PSub import Mathlib.Data.Nat.Size import Mathlib.Data.Num.Bitwise #align_import data.num.lemmas from "leanprover-community/mathlib"@"2196ab363eb097c008d4497125e0dde23fb36db2" /-! # Properties of the binary representation of integers -/ /- Porting note: `bit0` and `bit1` are deprecated because it is mainly used to represent number literal in Lean3 but not in Lean4 anymore. However, this file uses them for encoding numbers so this linter is unnecessary. -/ set_option linter.deprecated false -- Porting note: Required for the notation `-[n+1]`. open Int Function attribute [local simp] add_assoc namespace PosNum variable {α : Type*} @[simp, norm_cast] theorem cast_one [One α] [Add α] : ((1 : PosNum) : α) = 1 := rfl #align pos_num.cast_one PosNum.cast_one @[simp] theorem cast_one' [One α] [Add α] : (PosNum.one : α) = 1 := rfl #align pos_num.cast_one' PosNum.cast_one' @[simp, norm_cast] theorem cast_bit0 [One α] [Add α] (n : PosNum) : (n.bit0 : α) = _root_.bit0 (n : α) := rfl #align pos_num.cast_bit0 PosNum.cast_bit0 @[simp, norm_cast] theorem cast_bit1 [One α] [Add α] (n : PosNum) : (n.bit1 : α) = _root_.bit1 (n : α) := rfl #align pos_num.cast_bit1 PosNum.cast_bit1 @[simp, norm_cast] theorem cast_to_nat [AddMonoidWithOne α] : ∀ n : PosNum, ((n : ℕ) : α) = n | 1 => Nat.cast_one | bit0 p => (Nat.cast_bit0 _).trans <| congr_arg _root_.bit0 p.cast_to_nat | bit1 p => (Nat.cast_bit1 _).trans <| congr_arg _root_.bit1 p.cast_to_nat #align pos_num.cast_to_nat PosNum.cast_to_nat @[norm_cast] -- @[simp] -- Porting note (#10618): simp can prove this theorem to_nat_to_int (n : PosNum) : ((n : ℕ) : ℤ) = n := cast_to_nat _ #align pos_num.to_nat_to_int PosNum.to_nat_to_int @[simp, norm_cast] theorem cast_to_int [AddGroupWithOne α] (n : PosNum) : ((n : ℤ) : α) = n := by rw [← to_nat_to_int, Int.cast_natCast, cast_to_nat] #align pos_num.cast_to_int PosNum.cast_to_int theorem succ_to_nat : ∀ n, (succ n : ℕ) = n + 1 | 1 => rfl | bit0 p => rfl | bit1 p => (congr_arg _root_.bit0 (succ_to_nat p)).trans <| show ↑p + 1 + ↑p + 1 = ↑p + ↑p + 1 + 1 by simp [add_left_comm] #align pos_num.succ_to_nat PosNum.succ_to_nat theorem one_add (n : PosNum) : 1 + n = succ n := by cases n <;> rfl #align pos_num.one_add PosNum.one_add theorem add_one (n : PosNum) : n + 1 = succ n := by cases n <;> rfl #align pos_num.add_one PosNum.add_one @[norm_cast] theorem add_to_nat : ∀ m n, ((m + n : PosNum) : ℕ) = m + n | 1, b => by rw [one_add b, succ_to_nat, add_comm, cast_one] | a, 1 => by rw [add_one a, succ_to_nat, cast_one] | bit0 a, bit0 b => (congr_arg _root_.bit0 (add_to_nat a b)).trans <| add_add_add_comm _ _ _ _ | bit0 a, bit1 b => (congr_arg _root_.bit1 (add_to_nat a b)).trans <| show (a + b + (a + b) + 1 : ℕ) = a + a + (b + b + 1) by simp [add_left_comm] | bit1 a, bit0 b => (congr_arg _root_.bit1 (add_to_nat a b)).trans <| show (a + b + (a + b) + 1 : ℕ) = a + a + 1 + (b + b) by simp [add_comm, add_left_comm] | bit1 a, bit1 b => show (succ (a + b) + succ (a + b) : ℕ) = a + a + 1 + (b + b + 1) by rw [succ_to_nat, add_to_nat a b]; simp [add_left_comm] #align pos_num.add_to_nat PosNum.add_to_nat theorem add_succ : ∀ m n : PosNum, m + succ n = succ (m + n) | 1, b => by simp [one_add] | bit0 a, 1 => congr_arg bit0 (add_one a) | bit1 a, 1 => congr_arg bit1 (add_one a) | bit0 a, bit0 b => rfl | bit0 a, bit1 b => congr_arg bit0 (add_succ a b) | bit1 a, bit0 b => rfl | bit1 a, bit1 b => congr_arg bit1 (add_succ a b) #align pos_num.add_succ PosNum.add_succ theorem bit0_of_bit0 : ∀ n, _root_.bit0 n = bit0 n | 1 => rfl | bit0 p => congr_arg bit0 (bit0_of_bit0 p) | bit1 p => show bit0 (succ (_root_.bit0 p)) = _ by rw [bit0_of_bit0 p, succ] #align pos_num.bit0_of_bit0 PosNum.bit0_of_bit0 theorem bit1_of_bit1 (n : PosNum) : _root_.bit1 n = bit1 n := show _root_.bit0 n + 1 = bit1 n by rw [add_one, bit0_of_bit0, succ] #align pos_num.bit1_of_bit1 PosNum.bit1_of_bit1 @[norm_cast] theorem mul_to_nat (m) : ∀ n, ((m * n : PosNum) : ℕ) = m * n | 1 => (mul_one _).symm | bit0 p => show (↑(m * p) + ↑(m * p) : ℕ) = ↑m * (p + p) by rw [mul_to_nat m p, left_distrib] | bit1 p => (add_to_nat (bit0 (m * p)) m).trans <| show (↑(m * p) + ↑(m * p) + ↑m : ℕ) = ↑m * (p + p) + m by rw [mul_to_nat m p, left_distrib] #align pos_num.mul_to_nat PosNum.mul_to_nat theorem to_nat_pos : ∀ n : PosNum, 0 < (n : ℕ) | 1 => Nat.zero_lt_one | bit0 p => let h := to_nat_pos p add_pos h h | bit1 _p => Nat.succ_pos _ #align pos_num.to_nat_pos PosNum.to_nat_pos theorem cmp_to_nat_lemma {m n : PosNum} : (m : ℕ) < n → (bit1 m : ℕ) < bit0 n := show (m : ℕ) < n → (m + m + 1 + 1 : ℕ) ≤ n + n by intro h; rw [Nat.add_right_comm m m 1, add_assoc]; exact Nat.add_le_add h h #align pos_num.cmp_to_nat_lemma PosNum.cmp_to_nat_lemma theorem cmp_swap (m) : ∀ n, (cmp m n).swap = cmp n m := by induction' m with m IH m IH <;> intro n <;> cases' n with n n <;> unfold cmp <;> try { rfl } <;> rw [← IH] <;> cases cmp m n <;> rfl #align pos_num.cmp_swap PosNum.cmp_swap theorem cmp_to_nat : ∀ m n, (Ordering.casesOn (cmp m n) ((m : ℕ) < n) (m = n) ((n : ℕ) < m) : Prop) | 1, 1 => rfl | bit0 a, 1 => let h : (1 : ℕ) ≤ a := to_nat_pos a Nat.add_le_add h h | bit1 a, 1 => Nat.succ_lt_succ <| to_nat_pos <| bit0 a | 1, bit0 b => let h : (1 : ℕ) ≤ b := to_nat_pos b Nat.add_le_add h h | 1, bit1 b => Nat.succ_lt_succ <| to_nat_pos <| bit0 b | bit0 a, bit0 b => by dsimp [cmp] have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this · exact Nat.add_lt_add this this · rw [this] · exact Nat.add_lt_add this this | bit0 a, bit1 b => by dsimp [cmp] have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this · exact Nat.le_succ_of_le (Nat.add_lt_add this this) · rw [this] apply Nat.lt_succ_self · exact cmp_to_nat_lemma this | bit1 a, bit0 b => by dsimp [cmp] have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this · exact cmp_to_nat_lemma this · rw [this] apply Nat.lt_succ_self · exact Nat.le_succ_of_le (Nat.add_lt_add this this) | bit1 a, bit1 b => by dsimp [cmp] have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this · exact Nat.succ_lt_succ (Nat.add_lt_add this this) · rw [this] · exact Nat.succ_lt_succ (Nat.add_lt_add this this) #align pos_num.cmp_to_nat PosNum.cmp_to_nat @[norm_cast] theorem lt_to_nat {m n : PosNum} : (m : ℕ) < n ↔ m < n := show (m : ℕ) < n ↔ cmp m n = Ordering.lt from match cmp m n, cmp_to_nat m n with | Ordering.lt, h => by simp only at h; simp [h] | Ordering.eq, h => by simp only at h; simp [h, lt_irrefl] | Ordering.gt, h => by simp [not_lt_of_gt h] #align pos_num.lt_to_nat PosNum.lt_to_nat @[norm_cast] theorem le_to_nat {m n : PosNum} : (m : ℕ) ≤ n ↔ m ≤ n := by rw [← not_lt]; exact not_congr lt_to_nat #align pos_num.le_to_nat PosNum.le_to_nat end PosNum namespace Num variable {α : Type*} open PosNum theorem add_zero (n : Num) : n + 0 = n := by cases n <;> rfl #align num.add_zero Num.add_zero theorem zero_add (n : Num) : 0 + n = n := by cases n <;> rfl #align num.zero_add Num.zero_add theorem add_one : ∀ n : Num, n + 1 = succ n | 0 => rfl | pos p => by cases p <;> rfl #align num.add_one Num.add_one theorem add_succ : ∀ m n : Num, m + succ n = succ (m + n) | 0, n => by simp [zero_add] | pos p, 0 => show pos (p + 1) = succ (pos p + 0) by rw [PosNum.add_one, add_zero, succ, succ'] | pos p, pos q => congr_arg pos (PosNum.add_succ _ _) #align num.add_succ Num.add_succ theorem bit0_of_bit0 : ∀ n : Num, bit0 n = n.bit0 | 0 => rfl | pos p => congr_arg pos p.bit0_of_bit0 #align num.bit0_of_bit0 Num.bit0_of_bit0 theorem bit1_of_bit1 : ∀ n : Num, bit1 n = n.bit1 | 0 => rfl | pos p => congr_arg pos p.bit1_of_bit1 #align num.bit1_of_bit1 Num.bit1_of_bit1 @[simp] theorem ofNat'_zero : Num.ofNat' 0 = 0 := by simp [Num.ofNat'] #align num.of_nat'_zero Num.ofNat'_zero theorem ofNat'_bit (b n) : ofNat' (Nat.bit b n) = cond b Num.bit1 Num.bit0 (ofNat' n) := Nat.binaryRec_eq rfl _ _ #align num.of_nat'_bit Num.ofNat'_bit @[simp] theorem ofNat'_one : Num.ofNat' 1 = 1 := by erw [ofNat'_bit true 0, cond, ofNat'_zero]; rfl #align num.of_nat'_one Num.ofNat'_one theorem bit1_succ : ∀ n : Num, n.bit1.succ = n.succ.bit0 | 0 => rfl | pos _n => rfl #align num.bit1_succ Num.bit1_succ theorem ofNat'_succ : ∀ {n}, ofNat' (n + 1) = ofNat' n + 1 := @(Nat.binaryRec (by simp [zero_add]) fun b n ih => by cases b · erw [ofNat'_bit true n, ofNat'_bit] simp only [← bit1_of_bit1, ← bit0_of_bit0, cond, _root_.bit1] -- Porting note: `cc` was not ported yet so `exact Nat.add_left_comm n 1 1` is used. · erw [show n.bit true + 1 = (n + 1).bit false by simpa [Nat.bit, _root_.bit1, _root_.bit0] using Nat.add_left_comm n 1 1, ofNat'_bit, ofNat'_bit, ih] simp only [cond, add_one, bit1_succ]) #align num.of_nat'_succ Num.ofNat'_succ @[simp] theorem add_ofNat' (m n) : Num.ofNat' (m + n) = Num.ofNat' m + Num.ofNat' n := by induction n · simp only [Nat.add_zero, ofNat'_zero, add_zero] · simp only [Nat.add_succ, Nat.add_zero, ofNat'_succ, add_one, add_succ, *] #align num.add_of_nat' Num.add_ofNat' @[simp, norm_cast] theorem cast_zero [Zero α] [One α] [Add α] : ((0 : Num) : α) = 0 := rfl #align num.cast_zero Num.cast_zero @[simp] theorem cast_zero' [Zero α] [One α] [Add α] : (Num.zero : α) = 0 := rfl #align num.cast_zero' Num.cast_zero' @[simp, norm_cast] theorem cast_one [Zero α] [One α] [Add α] : ((1 : Num) : α) = 1 := rfl #align num.cast_one Num.cast_one @[simp] theorem cast_pos [Zero α] [One α] [Add α] (n : PosNum) : (Num.pos n : α) = n := rfl #align num.cast_pos Num.cast_pos theorem succ'_to_nat : ∀ n, (succ' n : ℕ) = n + 1 | 0 => (Nat.zero_add _).symm | pos _p => PosNum.succ_to_nat _ #align num.succ'_to_nat Num.succ'_to_nat theorem succ_to_nat (n) : (succ n : ℕ) = n + 1 := succ'_to_nat n #align num.succ_to_nat Num.succ_to_nat @[simp, norm_cast] theorem cast_to_nat [AddMonoidWithOne α] : ∀ n : Num, ((n : ℕ) : α) = n | 0 => Nat.cast_zero | pos p => p.cast_to_nat #align num.cast_to_nat Num.cast_to_nat @[norm_cast] theorem add_to_nat : ∀ m n, ((m + n : Num) : ℕ) = m + n | 0, 0 => rfl | 0, pos _q => (Nat.zero_add _).symm | pos _p, 0 => rfl | pos _p, pos _q => PosNum.add_to_nat _ _ #align num.add_to_nat Num.add_to_nat @[norm_cast] theorem mul_to_nat : ∀ m n, ((m * n : Num) : ℕ) = m * n | 0, 0 => rfl | 0, pos _q => (zero_mul _).symm | pos _p, 0 => rfl | pos _p, pos _q => PosNum.mul_to_nat _ _ #align num.mul_to_nat Num.mul_to_nat theorem cmp_to_nat : ∀ m n, (Ordering.casesOn (cmp m n) ((m : ℕ) < n) (m = n) ((n : ℕ) < m) : Prop) | 0, 0 => rfl | 0, pos b => to_nat_pos _ | pos a, 0 => to_nat_pos _ | pos a, pos b => by have := PosNum.cmp_to_nat a b; revert this; dsimp [cmp]; cases PosNum.cmp a b exacts [id, congr_arg pos, id] #align num.cmp_to_nat Num.cmp_to_nat @[norm_cast] theorem lt_to_nat {m n : Num} : (m : ℕ) < n ↔ m < n := show (m : ℕ) < n ↔ cmp m n = Ordering.lt from match cmp m n, cmp_to_nat m n with | Ordering.lt, h => by simp only at h; simp [h] | Ordering.eq, h => by simp only at h; simp [h, lt_irrefl] | Ordering.gt, h => by simp [not_lt_of_gt h] #align num.lt_to_nat Num.lt_to_nat @[norm_cast] theorem le_to_nat {m n : Num} : (m : ℕ) ≤ n ↔ m ≤ n := by rw [← not_lt]; exact not_congr lt_to_nat #align num.le_to_nat Num.le_to_nat end Num namespace PosNum @[simp] theorem of_to_nat' : ∀ n : PosNum, Num.ofNat' (n : ℕ) = Num.pos n | 1 => by erw [@Num.ofNat'_bit true 0, Num.ofNat'_zero]; rfl | bit0 p => by erw [@Num.ofNat'_bit false, of_to_nat' p]; rfl | bit1 p => by erw [@Num.ofNat'_bit true, of_to_nat' p]; rfl #align pos_num.of_to_nat' PosNum.of_to_nat' end PosNum namespace Num @[simp, norm_cast] theorem of_to_nat' : ∀ n : Num, Num.ofNat' (n : ℕ) = n | 0 => ofNat'_zero | pos p => p.of_to_nat' #align num.of_to_nat' Num.of_to_nat' lemma toNat_injective : Injective (castNum : Num → ℕ) := LeftInverse.injective of_to_nat' @[norm_cast] theorem to_nat_inj {m n : Num} : (m : ℕ) = n ↔ m = n := toNat_injective.eq_iff #align num.to_nat_inj Num.to_nat_inj /-- This tactic tries to turn an (in)equality about `Num`s to one about `Nat`s by rewriting. ```lean example (n : Num) (m : Num) : n ≤ n + m := by transfer_rw exact Nat.le_add_right _ _ ``` -/ scoped macro (name := transfer_rw) "transfer_rw" : tactic => `(tactic| (repeat first | rw [← to_nat_inj] | rw [← lt_to_nat] | rw [← le_to_nat] repeat first | rw [add_to_nat] | rw [mul_to_nat] | rw [cast_one] | rw [cast_zero])) /-- This tactic tries to prove (in)equalities about `Num`s by transferring them to the `Nat` world and then trying to call `simp`. ```lean example (n : Num) (m : Num) : n ≤ n + m := by transfer ``` -/ scoped macro (name := transfer) "transfer" : tactic => `(tactic| (intros; transfer_rw; try simp)) instance addMonoid : AddMonoid Num where add := (· + ·) zero := 0 zero_add := zero_add add_zero := add_zero add_assoc := by transfer nsmul := nsmulRec #align num.add_monoid Num.addMonoid instance addMonoidWithOne : AddMonoidWithOne Num := { Num.addMonoid with natCast := Num.ofNat' one := 1 natCast_zero := ofNat'_zero natCast_succ := fun _ => ofNat'_succ } #align num.add_monoid_with_one Num.addMonoidWithOne instance commSemiring : CommSemiring Num where __ := Num.addMonoid __ := Num.addMonoidWithOne mul := (· * ·) npow := @npowRec Num ⟨1⟩ ⟨(· * ·)⟩ mul_zero _ := by rw [← to_nat_inj, mul_to_nat, cast_zero, mul_zero] zero_mul _ := by rw [← to_nat_inj, mul_to_nat, cast_zero, zero_mul] mul_one _ := by rw [← to_nat_inj, mul_to_nat, cast_one, mul_one] one_mul _ := by rw [← to_nat_inj, mul_to_nat, cast_one, one_mul] add_comm _ _ := by simp_rw [← to_nat_inj, add_to_nat, add_comm] mul_comm _ _ := by simp_rw [← to_nat_inj, mul_to_nat, mul_comm] mul_assoc _ _ _ := by simp_rw [← to_nat_inj, mul_to_nat, mul_assoc] left_distrib _ _ _ := by simp only [← to_nat_inj, mul_to_nat, add_to_nat, mul_add] right_distrib _ _ _ := by simp only [← to_nat_inj, mul_to_nat, add_to_nat, add_mul] #align num.comm_semiring Num.commSemiring instance orderedCancelAddCommMonoid : OrderedCancelAddCommMonoid Num where le := (· ≤ ·) lt := (· < ·) lt_iff_le_not_le a b := by simp only [← lt_to_nat, ← le_to_nat, lt_iff_le_not_le] le_refl := by transfer le_trans a b c := by transfer_rw; apply le_trans le_antisymm a b := by transfer_rw; apply le_antisymm add_le_add_left a b h c := by revert h; transfer_rw; exact fun h => add_le_add_left h c le_of_add_le_add_left a b c := by transfer_rw; apply le_of_add_le_add_left #align num.ordered_cancel_add_comm_monoid Num.orderedCancelAddCommMonoid instance linearOrderedSemiring : LinearOrderedSemiring Num := { Num.commSemiring, Num.orderedCancelAddCommMonoid with le_total := by intro a b transfer_rw apply le_total zero_le_one := by decide mul_lt_mul_of_pos_left := by intro a b c transfer_rw apply mul_lt_mul_of_pos_left mul_lt_mul_of_pos_right := by intro a b c transfer_rw apply mul_lt_mul_of_pos_right decidableLT := Num.decidableLT decidableLE := Num.decidableLE -- This is relying on an automatically generated instance name, -- generated in a `deriving` handler. -- See https://github.com/leanprover/lean4/issues/2343 decidableEq := instDecidableEqNum exists_pair_ne := ⟨0, 1, by decide⟩ } #align num.linear_ordered_semiring Num.linearOrderedSemiring @[norm_cast] -- @[simp] -- Porting note (#10618): simp can prove this theorem add_of_nat (m n) : ((m + n : ℕ) : Num) = m + n := add_ofNat' _ _ #align num.add_of_nat Num.add_of_nat @[norm_cast] -- @[simp] -- Porting note (#10618): simp can prove this theorem to_nat_to_int (n : Num) : ((n : ℕ) : ℤ) = n := cast_to_nat _ #align num.to_nat_to_int Num.to_nat_to_int @[simp, norm_cast] theorem cast_to_int {α} [AddGroupWithOne α] (n : Num) : ((n : ℤ) : α) = n := by rw [← to_nat_to_int, Int.cast_natCast, cast_to_nat] #align num.cast_to_int Num.cast_to_int theorem to_of_nat : ∀ n : ℕ, ((n : Num) : ℕ) = n | 0 => by rw [Nat.cast_zero, cast_zero] | n + 1 => by rw [Nat.cast_succ, add_one, succ_to_nat, to_of_nat n] #align num.to_of_nat Num.to_of_nat @[simp, norm_cast]
Mathlib/Data/Num/Lemmas.lean
485
486
theorem of_natCast {α} [AddMonoidWithOne α] (n : ℕ) : ((n : Num) : α) = n := by
rw [← cast_to_nat, to_of_nat]
/- Copyright (c) 2022 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import Mathlib.Topology.UniformSpace.UniformConvergenceTopology #align_import topology.uniform_space.equicontinuity from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Equicontinuity of a family of functions Let `X` be a topological space and `α` a `UniformSpace`. A family of functions `F : ι → X → α` is said to be *equicontinuous at a point `x₀ : X`* when, for any entourage `U` in `α`, there is a neighborhood `V` of `x₀` such that, for all `x ∈ V`, and *for all `i`*, `F i x` is `U`-close to `F i x₀`. In other words, one has `∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝 x₀, ∀ i, (F i x₀, F i x) ∈ U`. For maps between metric spaces, this corresponds to `∀ ε > 0, ∃ δ > 0, ∀ x, ∀ i, dist x₀ x < δ → dist (F i x₀) (F i x) < ε`. `F` is said to be *equicontinuous* if it is equicontinuous at each point. A closely related concept is that of ***uniform*** *equicontinuity* of a family of functions `F : ι → β → α` between uniform spaces, which means that, for any entourage `U` in `α`, there is an entourage `V` in `β` such that, if `x` and `y` are `V`-close, then *for all `i`*, `F i x` and `F i y` are `U`-close. In other words, one has `∀ U ∈ 𝓤 α, ∀ᶠ xy in 𝓤 β, ∀ i, (F i xy.1, F i xy.2) ∈ U`. For maps between metric spaces, this corresponds to `∀ ε > 0, ∃ δ > 0, ∀ x y, ∀ i, dist x y < δ → dist (F i x₀) (F i x) < ε`. ## Main definitions * `EquicontinuousAt`: equicontinuity of a family of functions at a point * `Equicontinuous`: equicontinuity of a family of functions on the whole domain * `UniformEquicontinuous`: uniform equicontinuity of a family of functions on the whole domain We also introduce relative versions, namely `EquicontinuousWithinAt`, `EquicontinuousOn` and `UniformEquicontinuousOn`, akin to `ContinuousWithinAt`, `ContinuousOn` and `UniformContinuousOn` respectively. ## Main statements * `equicontinuous_iff_continuous`: equicontinuity can be expressed as a simple continuity condition between well-chosen function spaces. This is really useful for building up the theory. * `Equicontinuous.closure`: if a set of functions is equicontinuous, its closure *for the topology of pointwise convergence* is also equicontinuous. ## Notations Throughout this file, we use : - `ι`, `κ` for indexing types - `X`, `Y`, `Z` for topological spaces - `α`, `β`, `γ` for uniform spaces ## Implementation details We choose to express equicontinuity as a properties of indexed families of functions rather than sets of functions for the following reasons: - it is really easy to express equicontinuity of `H : Set (X → α)` using our setup: it is just equicontinuity of the family `(↑) : ↥H → (X → α)`. On the other hand, going the other way around would require working with the range of the family, which is always annoying because it introduces useless existentials. - in most applications, one doesn't work with bare functions but with a more specific hom type `hom`. Equicontinuity of a set `H : Set hom` would then have to be expressed as equicontinuity of `coe_fn '' H`, which is super annoying to work with. This is much simpler with families, because equicontinuity of a family `𝓕 : ι → hom` would simply be expressed as equicontinuity of `coe_fn ∘ 𝓕`, which doesn't introduce any nasty existentials. To simplify statements, we do provide abbreviations `Set.EquicontinuousAt`, `Set.Equicontinuous` and `Set.UniformEquicontinuous` asserting the corresponding fact about the family `(↑) : ↥H → (X → α)` where `H : Set (X → α)`. Note however that these won't work for sets of hom types, and in that case one should go back to the family definition rather than using `Set.image`. ## References * [N. Bourbaki, *General Topology, Chapter X*][bourbaki1966] ## Tags equicontinuity, uniform convergence, ascoli -/ section open UniformSpace Filter Set Uniformity Topology UniformConvergence Function variable {ι κ X X' Y Z α α' β β' γ 𝓕 : Type*} [tX : TopologicalSpace X] [tY : TopologicalSpace Y] [tZ : TopologicalSpace Z] [uα : UniformSpace α] [uβ : UniformSpace β] [uγ : UniformSpace γ] /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous at `x₀ : X`* if, for all entourages `U ∈ 𝓤 α`, there is a neighborhood `V` of `x₀` such that, for all `x ∈ V` and for all `i : ι`, `F i x` is `U`-close to `F i x₀`. -/ def EquicontinuousAt (F : ι → X → α) (x₀ : X) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝 x₀, ∀ i, (F i x₀, F i x) ∈ U #align equicontinuous_at EquicontinuousAt /-- We say that a set `H : Set (X → α)` of functions is equicontinuous at a point if the family `(↑) : ↥H → (X → α)` is equicontinuous at that point. -/ protected abbrev Set.EquicontinuousAt (H : Set <| X → α) (x₀ : X) : Prop := EquicontinuousAt ((↑) : H → X → α) x₀ #align set.equicontinuous_at Set.EquicontinuousAt /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous at `x₀ : X` within `S : Set X`* if, for all entourages `U ∈ 𝓤 α`, there is a neighborhood `V` of `x₀` within `S` such that, for all `x ∈ V` and for all `i : ι`, `F i x` is `U`-close to `F i x₀`. -/ def EquicontinuousWithinAt (F : ι → X → α) (S : Set X) (x₀ : X) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝[S] x₀, ∀ i, (F i x₀, F i x) ∈ U /-- We say that a set `H : Set (X → α)` of functions is equicontinuous at a point within a subset if the family `(↑) : ↥H → (X → α)` is equicontinuous at that point within that same subset. -/ protected abbrev Set.EquicontinuousWithinAt (H : Set <| X → α) (S : Set X) (x₀ : X) : Prop := EquicontinuousWithinAt ((↑) : H → X → α) S x₀ /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous* on all of `X` if it is equicontinuous at each point of `X`. -/ def Equicontinuous (F : ι → X → α) : Prop := ∀ x₀, EquicontinuousAt F x₀ #align equicontinuous Equicontinuous /-- We say that a set `H : Set (X → α)` of functions is equicontinuous if the family `(↑) : ↥H → (X → α)` is equicontinuous. -/ protected abbrev Set.Equicontinuous (H : Set <| X → α) : Prop := Equicontinuous ((↑) : H → X → α) #align set.equicontinuous Set.Equicontinuous /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous on `S : Set X`* if it is equicontinuous *within `S`* at each point of `S`. -/ def EquicontinuousOn (F : ι → X → α) (S : Set X) : Prop := ∀ x₀ ∈ S, EquicontinuousWithinAt F S x₀ /-- We say that a set `H : Set (X → α)` of functions is equicontinuous on a subset if the family `(↑) : ↥H → (X → α)` is equicontinuous on that subset. -/ protected abbrev Set.EquicontinuousOn (H : Set <| X → α) (S : Set X) : Prop := EquicontinuousOn ((↑) : H → X → α) S /-- A family `F : ι → β → α` of functions between uniform spaces is *uniformly equicontinuous* if, for all entourages `U ∈ 𝓤 α`, there is an entourage `V ∈ 𝓤 β` such that, whenever `x` and `y` are `V`-close, we have that, *for all `i : ι`*, `F i x` is `U`-close to `F i y`. -/ def UniformEquicontinuous (F : ι → β → α) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ xy : β × β in 𝓤 β, ∀ i, (F i xy.1, F i xy.2) ∈ U #align uniform_equicontinuous UniformEquicontinuous /-- We say that a set `H : Set (X → α)` of functions is uniformly equicontinuous if the family `(↑) : ↥H → (X → α)` is uniformly equicontinuous. -/ protected abbrev Set.UniformEquicontinuous (H : Set <| β → α) : Prop := UniformEquicontinuous ((↑) : H → β → α) #align set.uniform_equicontinuous Set.UniformEquicontinuous /-- A family `F : ι → β → α` of functions between uniform spaces is *uniformly equicontinuous on `S : Set β`* if, for all entourages `U ∈ 𝓤 α`, there is a relative entourage `V ∈ 𝓤 β ⊓ 𝓟 (S ×ˢ S)` such that, whenever `x` and `y` are `V`-close, we have that, *for all `i : ι`*, `F i x` is `U`-close to `F i y`. -/ def UniformEquicontinuousOn (F : ι → β → α) (S : Set β) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ xy : β × β in 𝓤 β ⊓ 𝓟 (S ×ˢ S), ∀ i, (F i xy.1, F i xy.2) ∈ U /-- We say that a set `H : Set (X → α)` of functions is uniformly equicontinuous on a subset if the family `(↑) : ↥H → (X → α)` is uniformly equicontinuous on that subset. -/ protected abbrev Set.UniformEquicontinuousOn (H : Set <| β → α) (S : Set β) : Prop := UniformEquicontinuousOn ((↑) : H → β → α) S lemma EquicontinuousAt.equicontinuousWithinAt {F : ι → X → α} {x₀ : X} (H : EquicontinuousAt F x₀) (S : Set X) : EquicontinuousWithinAt F S x₀ := fun U hU ↦ (H U hU).filter_mono inf_le_left lemma EquicontinuousWithinAt.mono {F : ι → X → α} {x₀ : X} {S T : Set X} (H : EquicontinuousWithinAt F T x₀) (hST : S ⊆ T) : EquicontinuousWithinAt F S x₀ := fun U hU ↦ (H U hU).filter_mono <| nhdsWithin_mono x₀ hST @[simp] lemma equicontinuousWithinAt_univ (F : ι → X → α) (x₀ : X) : EquicontinuousWithinAt F univ x₀ ↔ EquicontinuousAt F x₀ := by rw [EquicontinuousWithinAt, EquicontinuousAt, nhdsWithin_univ] lemma equicontinuousAt_restrict_iff (F : ι → X → α) {S : Set X} (x₀ : S) : EquicontinuousAt (S.restrict ∘ F) x₀ ↔ EquicontinuousWithinAt F S x₀ := by simp [EquicontinuousWithinAt, EquicontinuousAt, ← eventually_nhds_subtype_iff] lemma Equicontinuous.equicontinuousOn {F : ι → X → α} (H : Equicontinuous F) (S : Set X) : EquicontinuousOn F S := fun x _ ↦ (H x).equicontinuousWithinAt S lemma EquicontinuousOn.mono {F : ι → X → α} {S T : Set X} (H : EquicontinuousOn F T) (hST : S ⊆ T) : EquicontinuousOn F S := fun x hx ↦ (H x (hST hx)).mono hST lemma equicontinuousOn_univ (F : ι → X → α) : EquicontinuousOn F univ ↔ Equicontinuous F := by simp [EquicontinuousOn, Equicontinuous] lemma equicontinuous_restrict_iff (F : ι → X → α) {S : Set X} : Equicontinuous (S.restrict ∘ F) ↔ EquicontinuousOn F S := by simp [Equicontinuous, EquicontinuousOn, equicontinuousAt_restrict_iff] lemma UniformEquicontinuous.uniformEquicontinuousOn {F : ι → β → α} (H : UniformEquicontinuous F) (S : Set β) : UniformEquicontinuousOn F S := fun U hU ↦ (H U hU).filter_mono inf_le_left lemma UniformEquicontinuousOn.mono {F : ι → β → α} {S T : Set β} (H : UniformEquicontinuousOn F T) (hST : S ⊆ T) : UniformEquicontinuousOn F S := fun U hU ↦ (H U hU).filter_mono <| by gcongr lemma uniformEquicontinuousOn_univ (F : ι → β → α) : UniformEquicontinuousOn F univ ↔ UniformEquicontinuous F := by simp [UniformEquicontinuousOn, UniformEquicontinuous] lemma uniformEquicontinuous_restrict_iff (F : ι → β → α) {S : Set β} : UniformEquicontinuous (S.restrict ∘ F) ↔ UniformEquicontinuousOn F S := by rw [UniformEquicontinuous, UniformEquicontinuousOn] conv in _ ⊓ _ => rw [← Subtype.range_val (s := S), ← range_prod_map, ← map_comap] rfl /-! ### Empty index type -/ @[simp] lemma equicontinuousAt_empty [h : IsEmpty ι] (F : ι → X → α) (x₀ : X) : EquicontinuousAt F x₀ := fun _ _ ↦ eventually_of_forall (fun _ ↦ h.elim) @[simp] lemma equicontinuousWithinAt_empty [h : IsEmpty ι] (F : ι → X → α) (S : Set X) (x₀ : X) : EquicontinuousWithinAt F S x₀ := fun _ _ ↦ eventually_of_forall (fun _ ↦ h.elim) @[simp] lemma equicontinuous_empty [IsEmpty ι] (F : ι → X → α) : Equicontinuous F := equicontinuousAt_empty F @[simp] lemma equicontinuousOn_empty [IsEmpty ι] (F : ι → X → α) (S : Set X) : EquicontinuousOn F S := fun x₀ _ ↦ equicontinuousWithinAt_empty F S x₀ @[simp] lemma uniformEquicontinuous_empty [h : IsEmpty ι] (F : ι → β → α) : UniformEquicontinuous F := fun _ _ ↦ eventually_of_forall (fun _ ↦ h.elim) @[simp] lemma uniformEquicontinuousOn_empty [h : IsEmpty ι] (F : ι → β → α) (S : Set β) : UniformEquicontinuousOn F S := fun _ _ ↦ eventually_of_forall (fun _ ↦ h.elim) /-! ### Finite index type -/ theorem equicontinuousAt_finite [Finite ι] {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ ∀ i, ContinuousAt (F i) x₀ := by simp [EquicontinuousAt, ContinuousAt, (nhds_basis_uniformity' (𝓤 α).basis_sets).tendsto_right_iff, UniformSpace.ball, @forall_swap _ ι] theorem equicontinuousWithinAt_finite [Finite ι] {F : ι → X → α} {S : Set X} {x₀ : X} : EquicontinuousWithinAt F S x₀ ↔ ∀ i, ContinuousWithinAt (F i) S x₀ := by simp [EquicontinuousWithinAt, ContinuousWithinAt, (nhds_basis_uniformity' (𝓤 α).basis_sets).tendsto_right_iff, UniformSpace.ball, @forall_swap _ ι] theorem equicontinuous_finite [Finite ι] {F : ι → X → α} : Equicontinuous F ↔ ∀ i, Continuous (F i) := by simp only [Equicontinuous, equicontinuousAt_finite, continuous_iff_continuousAt, @forall_swap ι] theorem equicontinuousOn_finite [Finite ι] {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ ∀ i, ContinuousOn (F i) S := by simp only [EquicontinuousOn, equicontinuousWithinAt_finite, ContinuousOn, @forall_swap ι] theorem uniformEquicontinuous_finite [Finite ι] {F : ι → β → α} : UniformEquicontinuous F ↔ ∀ i, UniformContinuous (F i) := by simp only [UniformEquicontinuous, eventually_all, @forall_swap _ ι]; rfl theorem uniformEquicontinuousOn_finite [Finite ι] {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ ∀ i, UniformContinuousOn (F i) S := by simp only [UniformEquicontinuousOn, eventually_all, @forall_swap _ ι]; rfl /-! ### Index type with a unique element -/ theorem equicontinuousAt_unique [Unique ι] {F : ι → X → α} {x : X} : EquicontinuousAt F x ↔ ContinuousAt (F default) x := equicontinuousAt_finite.trans Unique.forall_iff theorem equicontinuousWithinAt_unique [Unique ι] {F : ι → X → α} {S : Set X} {x : X} : EquicontinuousWithinAt F S x ↔ ContinuousWithinAt (F default) S x := equicontinuousWithinAt_finite.trans Unique.forall_iff theorem equicontinuous_unique [Unique ι] {F : ι → X → α} : Equicontinuous F ↔ Continuous (F default) := equicontinuous_finite.trans Unique.forall_iff theorem equicontinuousOn_unique [Unique ι] {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ ContinuousOn (F default) S := equicontinuousOn_finite.trans Unique.forall_iff theorem uniformEquicontinuous_unique [Unique ι] {F : ι → β → α} : UniformEquicontinuous F ↔ UniformContinuous (F default) := uniformEquicontinuous_finite.trans Unique.forall_iff theorem uniformEquicontinuousOn_unique [Unique ι] {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ UniformContinuousOn (F default) S := uniformEquicontinuousOn_finite.trans Unique.forall_iff /-- Reformulation of equicontinuity at `x₀` within a set `S`, comparing two variables near `x₀` instead of comparing only one with `x₀`. -/ theorem equicontinuousWithinAt_iff_pair {F : ι → X → α} {S : Set X} {x₀ : X} (hx₀ : x₀ ∈ S) : EquicontinuousWithinAt F S x₀ ↔ ∀ U ∈ 𝓤 α, ∃ V ∈ 𝓝[S] x₀, ∀ x ∈ V, ∀ y ∈ V, ∀ i, (F i x, F i y) ∈ U := by constructor <;> intro H U hU · rcases comp_symm_mem_uniformity_sets hU with ⟨V, hV, hVsymm, hVU⟩ refine ⟨_, H V hV, fun x hx y hy i => hVU (prod_mk_mem_compRel ?_ (hy i))⟩ exact hVsymm.mk_mem_comm.mp (hx i) · rcases H U hU with ⟨V, hV, hVU⟩ filter_upwards [hV] using fun x hx i => hVU x₀ (mem_of_mem_nhdsWithin hx₀ hV) x hx i /-- Reformulation of equicontinuity at `x₀` comparing two variables near `x₀` instead of comparing only one with `x₀`. -/ theorem equicontinuousAt_iff_pair {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ ∀ U ∈ 𝓤 α, ∃ V ∈ 𝓝 x₀, ∀ x ∈ V, ∀ y ∈ V, ∀ i, (F i x, F i y) ∈ U := by simp_rw [← equicontinuousWithinAt_univ, equicontinuousWithinAt_iff_pair (mem_univ x₀), nhdsWithin_univ] #align equicontinuous_at_iff_pair equicontinuousAt_iff_pair /-- Uniform equicontinuity implies equicontinuity. -/ theorem UniformEquicontinuous.equicontinuous {F : ι → β → α} (h : UniformEquicontinuous F) : Equicontinuous F := fun x₀ U hU ↦ mem_of_superset (ball_mem_nhds x₀ (h U hU)) fun _ hx i ↦ hx i #align uniform_equicontinuous.equicontinuous UniformEquicontinuous.equicontinuous /-- Uniform equicontinuity on a subset implies equicontinuity on that subset. -/ theorem UniformEquicontinuousOn.equicontinuousOn {F : ι → β → α} {S : Set β} (h : UniformEquicontinuousOn F S) : EquicontinuousOn F S := fun _ hx₀ U hU ↦ mem_of_superset (ball_mem_nhdsWithin hx₀ (h U hU)) fun _ hx i ↦ hx i /-- Each function of a family equicontinuous at `x₀` is continuous at `x₀`. -/ theorem EquicontinuousAt.continuousAt {F : ι → X → α} {x₀ : X} (h : EquicontinuousAt F x₀) (i : ι) : ContinuousAt (F i) x₀ := (UniformSpace.hasBasis_nhds _).tendsto_right_iff.2 fun U ⟨hU, _⟩ ↦ (h U hU).mono fun _x hx ↦ hx i #align equicontinuous_at.continuous_at EquicontinuousAt.continuousAt /-- Each function of a family equicontinuous at `x₀` within `S` is continuous at `x₀` within `S`. -/ theorem EquicontinuousWithinAt.continuousWithinAt {F : ι → X → α} {S : Set X} {x₀ : X} (h : EquicontinuousWithinAt F S x₀) (i : ι) : ContinuousWithinAt (F i) S x₀ := (UniformSpace.hasBasis_nhds _).tendsto_right_iff.2 fun U ⟨hU, _⟩ ↦ (h U hU).mono fun _x hx ↦ hx i protected theorem Set.EquicontinuousAt.continuousAt_of_mem {H : Set <| X → α} {x₀ : X} (h : H.EquicontinuousAt x₀) {f : X → α} (hf : f ∈ H) : ContinuousAt f x₀ := h.continuousAt ⟨f, hf⟩ #align set.equicontinuous_at.continuous_at_of_mem Set.EquicontinuousAt.continuousAt_of_mem protected theorem Set.EquicontinuousWithinAt.continuousWithinAt_of_mem {H : Set <| X → α} {S : Set X} {x₀ : X} (h : H.EquicontinuousWithinAt S x₀) {f : X → α} (hf : f ∈ H) : ContinuousWithinAt f S x₀ := h.continuousWithinAt ⟨f, hf⟩ /-- Each function of an equicontinuous family is continuous. -/ theorem Equicontinuous.continuous {F : ι → X → α} (h : Equicontinuous F) (i : ι) : Continuous (F i) := continuous_iff_continuousAt.mpr fun x => (h x).continuousAt i #align equicontinuous.continuous Equicontinuous.continuous /-- Each function of a family equicontinuous on `S` is continuous on `S`. -/ theorem EquicontinuousOn.continuousOn {F : ι → X → α} {S : Set X} (h : EquicontinuousOn F S) (i : ι) : ContinuousOn (F i) S := fun x hx ↦ (h x hx).continuousWithinAt i protected theorem Set.Equicontinuous.continuous_of_mem {H : Set <| X → α} (h : H.Equicontinuous) {f : X → α} (hf : f ∈ H) : Continuous f := h.continuous ⟨f, hf⟩ #align set.equicontinuous.continuous_of_mem Set.Equicontinuous.continuous_of_mem protected theorem Set.EquicontinuousOn.continuousOn_of_mem {H : Set <| X → α} {S : Set X} (h : H.EquicontinuousOn S) {f : X → α} (hf : f ∈ H) : ContinuousOn f S := h.continuousOn ⟨f, hf⟩ /-- Each function of a uniformly equicontinuous family is uniformly continuous. -/ theorem UniformEquicontinuous.uniformContinuous {F : ι → β → α} (h : UniformEquicontinuous F) (i : ι) : UniformContinuous (F i) := fun U hU => mem_map.mpr (mem_of_superset (h U hU) fun _ hxy => hxy i) #align uniform_equicontinuous.uniform_continuous UniformEquicontinuous.uniformContinuous /-- Each function of a family uniformly equicontinuous on `S` is uniformly continuous on `S`. -/ theorem UniformEquicontinuousOn.uniformContinuousOn {F : ι → β → α} {S : Set β} (h : UniformEquicontinuousOn F S) (i : ι) : UniformContinuousOn (F i) S := fun U hU => mem_map.mpr (mem_of_superset (h U hU) fun _ hxy => hxy i) protected theorem Set.UniformEquicontinuous.uniformContinuous_of_mem {H : Set <| β → α} (h : H.UniformEquicontinuous) {f : β → α} (hf : f ∈ H) : UniformContinuous f := h.uniformContinuous ⟨f, hf⟩ #align set.uniform_equicontinuous.uniform_continuous_of_mem Set.UniformEquicontinuous.uniformContinuous_of_mem protected theorem Set.UniformEquicontinuousOn.uniformContinuousOn_of_mem {H : Set <| β → α} {S : Set β} (h : H.UniformEquicontinuousOn S) {f : β → α} (hf : f ∈ H) : UniformContinuousOn f S := h.uniformContinuousOn ⟨f, hf⟩ /-- Taking sub-families preserves equicontinuity at a point. -/ theorem EquicontinuousAt.comp {F : ι → X → α} {x₀ : X} (h : EquicontinuousAt F x₀) (u : κ → ι) : EquicontinuousAt (F ∘ u) x₀ := fun U hU => (h U hU).mono fun _ H k => H (u k) #align equicontinuous_at.comp EquicontinuousAt.comp /-- Taking sub-families preserves equicontinuity at a point within a subset. -/ theorem EquicontinuousWithinAt.comp {F : ι → X → α} {S : Set X} {x₀ : X} (h : EquicontinuousWithinAt F S x₀) (u : κ → ι) : EquicontinuousWithinAt (F ∘ u) S x₀ := fun U hU ↦ (h U hU).mono fun _ H k => H (u k) protected theorem Set.EquicontinuousAt.mono {H H' : Set <| X → α} {x₀ : X} (h : H.EquicontinuousAt x₀) (hH : H' ⊆ H) : H'.EquicontinuousAt x₀ := h.comp (inclusion hH) #align set.equicontinuous_at.mono Set.EquicontinuousAt.mono protected theorem Set.EquicontinuousWithinAt.mono {H H' : Set <| X → α} {S : Set X} {x₀ : X} (h : H.EquicontinuousWithinAt S x₀) (hH : H' ⊆ H) : H'.EquicontinuousWithinAt S x₀ := h.comp (inclusion hH) /-- Taking sub-families preserves equicontinuity. -/ theorem Equicontinuous.comp {F : ι → X → α} (h : Equicontinuous F) (u : κ → ι) : Equicontinuous (F ∘ u) := fun x => (h x).comp u #align equicontinuous.comp Equicontinuous.comp /-- Taking sub-families preserves equicontinuity on a subset. -/ theorem EquicontinuousOn.comp {F : ι → X → α} {S : Set X} (h : EquicontinuousOn F S) (u : κ → ι) : EquicontinuousOn (F ∘ u) S := fun x hx ↦ (h x hx).comp u protected theorem Set.Equicontinuous.mono {H H' : Set <| X → α} (h : H.Equicontinuous) (hH : H' ⊆ H) : H'.Equicontinuous := h.comp (inclusion hH) #align set.equicontinuous.mono Set.Equicontinuous.mono protected theorem Set.EquicontinuousOn.mono {H H' : Set <| X → α} {S : Set X} (h : H.EquicontinuousOn S) (hH : H' ⊆ H) : H'.EquicontinuousOn S := h.comp (inclusion hH) /-- Taking sub-families preserves uniform equicontinuity. -/ theorem UniformEquicontinuous.comp {F : ι → β → α} (h : UniformEquicontinuous F) (u : κ → ι) : UniformEquicontinuous (F ∘ u) := fun U hU => (h U hU).mono fun _ H k => H (u k) #align uniform_equicontinuous.comp UniformEquicontinuous.comp /-- Taking sub-families preserves uniform equicontinuity on a subset. -/ theorem UniformEquicontinuousOn.comp {F : ι → β → α} {S : Set β} (h : UniformEquicontinuousOn F S) (u : κ → ι) : UniformEquicontinuousOn (F ∘ u) S := fun U hU ↦ (h U hU).mono fun _ H k => H (u k) protected theorem Set.UniformEquicontinuous.mono {H H' : Set <| β → α} (h : H.UniformEquicontinuous) (hH : H' ⊆ H) : H'.UniformEquicontinuous := h.comp (inclusion hH) #align set.uniform_equicontinuous.mono Set.UniformEquicontinuous.mono protected theorem Set.UniformEquicontinuousOn.mono {H H' : Set <| β → α} {S : Set β} (h : H.UniformEquicontinuousOn S) (hH : H' ⊆ H) : H'.UniformEquicontinuousOn S := h.comp (inclusion hH) /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` iff `range 𝓕` is equicontinuous at `x₀`, i.e the family `(↑) : range F → X → α` is equicontinuous at `x₀`. -/ theorem equicontinuousAt_iff_range {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ EquicontinuousAt ((↑) : range F → X → α) x₀ := by simp only [EquicontinuousAt, forall_subtype_range_iff] #align equicontinuous_at_iff_range equicontinuousAt_iff_range /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` within `S` iff `range 𝓕` is equicontinuous at `x₀` within `S`, i.e the family `(↑) : range F → X → α` is equicontinuous at `x₀` within `S`. -/ theorem equicontinuousWithinAt_iff_range {F : ι → X → α} {S : Set X} {x₀ : X} : EquicontinuousWithinAt F S x₀ ↔ EquicontinuousWithinAt ((↑) : range F → X → α) S x₀ := by simp only [EquicontinuousWithinAt, forall_subtype_range_iff] /-- A family `𝓕 : ι → X → α` is equicontinuous iff `range 𝓕` is equicontinuous, i.e the family `(↑) : range F → X → α` is equicontinuous. -/ theorem equicontinuous_iff_range {F : ι → X → α} : Equicontinuous F ↔ Equicontinuous ((↑) : range F → X → α) := forall_congr' fun _ => equicontinuousAt_iff_range #align equicontinuous_iff_range equicontinuous_iff_range /-- A family `𝓕 : ι → X → α` is equicontinuous on `S` iff `range 𝓕` is equicontinuous on `S`, i.e the family `(↑) : range F → X → α` is equicontinuous on `S`. -/ theorem equicontinuousOn_iff_range {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ EquicontinuousOn ((↑) : range F → X → α) S := forall_congr' fun _ ↦ forall_congr' fun _ ↦ equicontinuousWithinAt_iff_range /-- A family `𝓕 : ι → β → α` is uniformly equicontinuous iff `range 𝓕` is uniformly equicontinuous, i.e the family `(↑) : range F → β → α` is uniformly equicontinuous. -/ theorem uniformEquicontinuous_iff_range {F : ι → β → α} : UniformEquicontinuous F ↔ UniformEquicontinuous ((↑) : range F → β → α) := ⟨fun h => by rw [← comp_rangeSplitting F]; exact h.comp _, fun h => h.comp (rangeFactorization F)⟩ #align uniform_equicontinuous_at_iff_range uniformEquicontinuous_iff_range /-- A family `𝓕 : ι → β → α` is uniformly equicontinuous on `S` iff `range 𝓕` is uniformly equicontinuous on `S`, i.e the family `(↑) : range F → β → α` is uniformly equicontinuous on `S`. -/ theorem uniformEquicontinuousOn_iff_range {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ UniformEquicontinuousOn ((↑) : range F → β → α) S := ⟨fun h => by rw [← comp_rangeSplitting F]; exact h.comp _, fun h => h.comp (rangeFactorization F)⟩ section open UniformFun /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` iff the function `swap 𝓕 : X → ι → α` is continuous at `x₀` *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developping the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuousAt_iff_continuousAt {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ ContinuousAt (ofFun ∘ Function.swap F : X → ι →ᵤ α) x₀ := by rw [ContinuousAt, (UniformFun.hasBasis_nhds ι α _).tendsto_right_iff] rfl #align equicontinuous_at_iff_continuous_at equicontinuousAt_iff_continuousAt /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` within `S` iff the function `swap 𝓕 : X → ι → α` is continuous at `x₀` within `S` *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developping the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuousWithinAt_iff_continuousWithinAt {F : ι → X → α} {S : Set X} {x₀ : X} : EquicontinuousWithinAt F S x₀ ↔ ContinuousWithinAt (ofFun ∘ Function.swap F : X → ι →ᵤ α) S x₀ := by rw [ContinuousWithinAt, (UniformFun.hasBasis_nhds ι α _).tendsto_right_iff] rfl /-- A family `𝓕 : ι → X → α` is equicontinuous iff the function `swap 𝓕 : X → ι → α` is continuous *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developping the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuous_iff_continuous {F : ι → X → α} : Equicontinuous F ↔ Continuous (ofFun ∘ Function.swap F : X → ι →ᵤ α) := by simp_rw [Equicontinuous, continuous_iff_continuousAt, equicontinuousAt_iff_continuousAt] #align equicontinuous_iff_continuous equicontinuous_iff_continuous /-- A family `𝓕 : ι → X → α` is equicontinuous on `S` iff the function `swap 𝓕 : X → ι → α` is continuous on `S` *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developping the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuousOn_iff_continuousOn {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ ContinuousOn (ofFun ∘ Function.swap F : X → ι →ᵤ α) S := by simp_rw [EquicontinuousOn, ContinuousOn, equicontinuousWithinAt_iff_continuousWithinAt] /-- A family `𝓕 : ι → β → α` is uniformly equicontinuous iff the function `swap 𝓕 : β → ι → α` is uniformly continuous *when `ι → α` is equipped with the uniform structure of uniform convergence*. This is very useful for developping the equicontinuity API, but it should not be used directly for other purposes. -/ theorem uniformEquicontinuous_iff_uniformContinuous {F : ι → β → α} : UniformEquicontinuous F ↔ UniformContinuous (ofFun ∘ Function.swap F : β → ι →ᵤ α) := by rw [UniformContinuous, (UniformFun.hasBasis_uniformity ι α).tendsto_right_iff] rfl #align uniform_equicontinuous_iff_uniform_continuous uniformEquicontinuous_iff_uniformContinuous /-- A family `𝓕 : ι → β → α` is uniformly equicontinuous on `S` iff the function `swap 𝓕 : β → ι → α` is uniformly continuous on `S` *when `ι → α` is equipped with the uniform structure of uniform convergence*. This is very useful for developping the equicontinuity API, but it should not be used directly for other purposes. -/ theorem uniformEquicontinuousOn_iff_uniformContinuousOn {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ UniformContinuousOn (ofFun ∘ Function.swap F : β → ι →ᵤ α) S := by rw [UniformContinuousOn, (UniformFun.hasBasis_uniformity ι α).tendsto_right_iff] rfl theorem equicontinuousWithinAt_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'} {S : Set X} {x₀ : X} : EquicontinuousWithinAt (uα := ⨅ k, u k) F S x₀ ↔ ∀ k, EquicontinuousWithinAt (uα := u k) F S x₀ := by simp only [equicontinuousWithinAt_iff_continuousWithinAt (uα := _), topologicalSpace] unfold ContinuousWithinAt rw [UniformFun.iInf_eq, toTopologicalSpace_iInf, nhds_iInf, tendsto_iInf] theorem equicontinuousAt_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'} {x₀ : X} : EquicontinuousAt (uα := ⨅ k, u k) F x₀ ↔ ∀ k, EquicontinuousAt (uα := u k) F x₀ := by simp only [← equicontinuousWithinAt_univ (uα := _), equicontinuousWithinAt_iInf_rng] theorem equicontinuous_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'} : Equicontinuous (uα := ⨅ k, u k) F ↔ ∀ k, Equicontinuous (uα := u k) F := by simp_rw [equicontinuous_iff_continuous (uα := _), UniformFun.topologicalSpace] rw [UniformFun.iInf_eq, toTopologicalSpace_iInf, continuous_iInf_rng]
Mathlib/Topology/UniformSpace/Equicontinuity.lean
578
581
theorem equicontinuousOn_iInf_rng {u : κ → UniformSpace α'} {F : ι → X → α'} {S : Set X} : EquicontinuousOn (uα := ⨅ k, u k) F S ↔ ∀ k, EquicontinuousOn (uα := u k) F S := by
simp_rw [EquicontinuousOn, equicontinuousWithinAt_iInf_rng, @forall_swap _ κ]
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kevin Kappelmann -/ import Mathlib.Algebra.CharZero.Lemmas import Mathlib.Algebra.Order.Interval.Set.Group import Mathlib.Algebra.Group.Int import Mathlib.Data.Int.Lemmas import Mathlib.Data.Set.Subsingleton import Mathlib.Init.Data.Nat.Lemmas import Mathlib.Order.GaloisConnection import Mathlib.Tactic.Abel import Mathlib.Tactic.Linarith import Mathlib.Tactic.Positivity #align_import algebra.order.floor from "leanprover-community/mathlib"@"afdb43429311b885a7988ea15d0bac2aac80f69c" /-! # Floor and ceil ## Summary We define the natural- and integer-valued floor and ceil functions on linearly ordered rings. ## Main Definitions * `FloorSemiring`: An ordered semiring with natural-valued floor and ceil. * `Nat.floor a`: Greatest natural `n` such that `n ≤ a`. Equal to `0` if `a < 0`. * `Nat.ceil a`: Least natural `n` such that `a ≤ n`. * `FloorRing`: A linearly ordered ring with integer-valued floor and ceil. * `Int.floor a`: Greatest integer `z` such that `z ≤ a`. * `Int.ceil a`: Least integer `z` such that `a ≤ z`. * `Int.fract a`: Fractional part of `a`, defined as `a - floor a`. * `round a`: Nearest integer to `a`. It rounds halves towards infinity. ## Notations * `⌊a⌋₊` is `Nat.floor a`. * `⌈a⌉₊` is `Nat.ceil a`. * `⌊a⌋` is `Int.floor a`. * `⌈a⌉` is `Int.ceil a`. The index `₊` in the notations for `Nat.floor` and `Nat.ceil` is used in analogy to the notation for `nnnorm`. ## TODO `LinearOrderedRing`/`LinearOrderedSemiring` can be relaxed to `OrderedRing`/`OrderedSemiring` in many lemmas. ## Tags rounding, floor, ceil -/ open Set variable {F α β : Type*} /-! ### Floor semiring -/ /-- A `FloorSemiring` is an ordered semiring over `α` with a function `floor : α → ℕ` satisfying `∀ (n : ℕ) (x : α), n ≤ ⌊x⌋ ↔ (n : α) ≤ x)`. Note that many lemmas require a `LinearOrder`. Please see the above `TODO`. -/ class FloorSemiring (α) [OrderedSemiring α] where /-- `FloorSemiring.floor a` computes the greatest natural `n` such that `(n : α) ≤ a`. -/ floor : α → ℕ /-- `FloorSemiring.ceil a` computes the least natural `n` such that `a ≤ (n : α)`. -/ ceil : α → ℕ /-- `FloorSemiring.floor` of a negative element is zero. -/ floor_of_neg {a : α} (ha : a < 0) : floor a = 0 /-- A natural number `n` is smaller than `FloorSemiring.floor a` iff its coercion to `α` is smaller than `a`. -/ gc_floor {a : α} {n : ℕ} (ha : 0 ≤ a) : n ≤ floor a ↔ (n : α) ≤ a /-- `FloorSemiring.ceil` is the lower adjoint of the coercion `↑ : ℕ → α`. -/ gc_ceil : GaloisConnection ceil (↑) #align floor_semiring FloorSemiring instance : FloorSemiring ℕ where floor := id ceil := id floor_of_neg ha := (Nat.not_lt_zero _ ha).elim gc_floor _ := by rw [Nat.cast_id] rfl gc_ceil n a := by rw [Nat.cast_id] rfl namespace Nat section OrderedSemiring variable [OrderedSemiring α] [FloorSemiring α] {a : α} {n : ℕ} /-- `⌊a⌋₊` is the greatest natural `n` such that `n ≤ a`. If `a` is negative, then `⌊a⌋₊ = 0`. -/ def floor : α → ℕ := FloorSemiring.floor #align nat.floor Nat.floor /-- `⌈a⌉₊` is the least natural `n` such that `a ≤ n` -/ def ceil : α → ℕ := FloorSemiring.ceil #align nat.ceil Nat.ceil @[simp] theorem floor_nat : (Nat.floor : ℕ → ℕ) = id := rfl #align nat.floor_nat Nat.floor_nat @[simp] theorem ceil_nat : (Nat.ceil : ℕ → ℕ) = id := rfl #align nat.ceil_nat Nat.ceil_nat @[inherit_doc] notation "⌊" a "⌋₊" => Nat.floor a @[inherit_doc] notation "⌈" a "⌉₊" => Nat.ceil a end OrderedSemiring section LinearOrderedSemiring variable [LinearOrderedSemiring α] [FloorSemiring α] {a : α} {n : ℕ} theorem le_floor_iff (ha : 0 ≤ a) : n ≤ ⌊a⌋₊ ↔ (n : α) ≤ a := FloorSemiring.gc_floor ha #align nat.le_floor_iff Nat.le_floor_iff theorem le_floor (h : (n : α) ≤ a) : n ≤ ⌊a⌋₊ := (le_floor_iff <| n.cast_nonneg.trans h).2 h #align nat.le_floor Nat.le_floor theorem floor_lt (ha : 0 ≤ a) : ⌊a⌋₊ < n ↔ a < n := lt_iff_lt_of_le_iff_le <| le_floor_iff ha #align nat.floor_lt Nat.floor_lt theorem floor_lt_one (ha : 0 ≤ a) : ⌊a⌋₊ < 1 ↔ a < 1 := (floor_lt ha).trans <| by rw [Nat.cast_one] #align nat.floor_lt_one Nat.floor_lt_one theorem lt_of_floor_lt (h : ⌊a⌋₊ < n) : a < n := lt_of_not_le fun h' => (le_floor h').not_lt h #align nat.lt_of_floor_lt Nat.lt_of_floor_lt theorem lt_one_of_floor_lt_one (h : ⌊a⌋₊ < 1) : a < 1 := mod_cast lt_of_floor_lt h #align nat.lt_one_of_floor_lt_one Nat.lt_one_of_floor_lt_one theorem floor_le (ha : 0 ≤ a) : (⌊a⌋₊ : α) ≤ a := (le_floor_iff ha).1 le_rfl #align nat.floor_le Nat.floor_le theorem lt_succ_floor (a : α) : a < ⌊a⌋₊.succ := lt_of_floor_lt <| Nat.lt_succ_self _ #align nat.lt_succ_floor Nat.lt_succ_floor theorem lt_floor_add_one (a : α) : a < ⌊a⌋₊ + 1 := by simpa using lt_succ_floor a #align nat.lt_floor_add_one Nat.lt_floor_add_one @[simp] theorem floor_natCast (n : ℕ) : ⌊(n : α)⌋₊ = n := eq_of_forall_le_iff fun a => by rw [le_floor_iff, Nat.cast_le] exact n.cast_nonneg #align nat.floor_coe Nat.floor_natCast @[deprecated (since := "2024-06-08")] alias floor_coe := floor_natCast @[simp] theorem floor_zero : ⌊(0 : α)⌋₊ = 0 := by rw [← Nat.cast_zero, floor_natCast] #align nat.floor_zero Nat.floor_zero @[simp] theorem floor_one : ⌊(1 : α)⌋₊ = 1 := by rw [← Nat.cast_one, floor_natCast] #align nat.floor_one Nat.floor_one -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_ofNat (n : ℕ) [n.AtLeastTwo] : ⌊no_index (OfNat.ofNat n : α)⌋₊ = n := Nat.floor_natCast _ theorem floor_of_nonpos (ha : a ≤ 0) : ⌊a⌋₊ = 0 := ha.lt_or_eq.elim FloorSemiring.floor_of_neg <| by rintro rfl exact floor_zero #align nat.floor_of_nonpos Nat.floor_of_nonpos theorem floor_mono : Monotone (floor : α → ℕ) := fun a b h => by obtain ha | ha := le_total a 0 · rw [floor_of_nonpos ha] exact Nat.zero_le _ · exact le_floor ((floor_le ha).trans h) #align nat.floor_mono Nat.floor_mono @[gcongr] theorem floor_le_floor : ∀ x y : α, x ≤ y → ⌊x⌋₊ ≤ ⌊y⌋₊ := floor_mono theorem le_floor_iff' (hn : n ≠ 0) : n ≤ ⌊a⌋₊ ↔ (n : α) ≤ a := by obtain ha | ha := le_total a 0 · rw [floor_of_nonpos ha] exact iff_of_false (Nat.pos_of_ne_zero hn).not_le (not_le_of_lt <| ha.trans_lt <| cast_pos.2 <| Nat.pos_of_ne_zero hn) · exact le_floor_iff ha #align nat.le_floor_iff' Nat.le_floor_iff' @[simp] theorem one_le_floor_iff (x : α) : 1 ≤ ⌊x⌋₊ ↔ 1 ≤ x := mod_cast @le_floor_iff' α _ _ x 1 one_ne_zero #align nat.one_le_floor_iff Nat.one_le_floor_iff theorem floor_lt' (hn : n ≠ 0) : ⌊a⌋₊ < n ↔ a < n := lt_iff_lt_of_le_iff_le <| le_floor_iff' hn #align nat.floor_lt' Nat.floor_lt' theorem floor_pos : 0 < ⌊a⌋₊ ↔ 1 ≤ a := by -- Porting note: broken `convert le_floor_iff' Nat.one_ne_zero` rw [Nat.lt_iff_add_one_le, zero_add, le_floor_iff' Nat.one_ne_zero, cast_one] #align nat.floor_pos Nat.floor_pos theorem pos_of_floor_pos (h : 0 < ⌊a⌋₊) : 0 < a := (le_or_lt a 0).resolve_left fun ha => lt_irrefl 0 <| by rwa [floor_of_nonpos ha] at h #align nat.pos_of_floor_pos Nat.pos_of_floor_pos theorem lt_of_lt_floor (h : n < ⌊a⌋₊) : ↑n < a := (Nat.cast_lt.2 h).trans_le <| floor_le (pos_of_floor_pos <| (Nat.zero_le n).trans_lt h).le #align nat.lt_of_lt_floor Nat.lt_of_lt_floor theorem floor_le_of_le (h : a ≤ n) : ⌊a⌋₊ ≤ n := le_imp_le_iff_lt_imp_lt.2 lt_of_lt_floor h #align nat.floor_le_of_le Nat.floor_le_of_le theorem floor_le_one_of_le_one (h : a ≤ 1) : ⌊a⌋₊ ≤ 1 := floor_le_of_le <| h.trans_eq <| Nat.cast_one.symm #align nat.floor_le_one_of_le_one Nat.floor_le_one_of_le_one @[simp] theorem floor_eq_zero : ⌊a⌋₊ = 0 ↔ a < 1 := by rw [← lt_one_iff, ← @cast_one α] exact floor_lt' Nat.one_ne_zero #align nat.floor_eq_zero Nat.floor_eq_zero theorem floor_eq_iff (ha : 0 ≤ a) : ⌊a⌋₊ = n ↔ ↑n ≤ a ∧ a < ↑n + 1 := by rw [← le_floor_iff ha, ← Nat.cast_one, ← Nat.cast_add, ← floor_lt ha, Nat.lt_add_one_iff, le_antisymm_iff, and_comm] #align nat.floor_eq_iff Nat.floor_eq_iff theorem floor_eq_iff' (hn : n ≠ 0) : ⌊a⌋₊ = n ↔ ↑n ≤ a ∧ a < ↑n + 1 := by rw [← le_floor_iff' hn, ← Nat.cast_one, ← Nat.cast_add, ← floor_lt' (Nat.add_one_ne_zero n), Nat.lt_add_one_iff, le_antisymm_iff, and_comm] #align nat.floor_eq_iff' Nat.floor_eq_iff' theorem floor_eq_on_Ico (n : ℕ) : ∀ a ∈ (Set.Ico n (n + 1) : Set α), ⌊a⌋₊ = n := fun _ ⟨h₀, h₁⟩ => (floor_eq_iff <| n.cast_nonneg.trans h₀).mpr ⟨h₀, h₁⟩ #align nat.floor_eq_on_Ico Nat.floor_eq_on_Ico theorem floor_eq_on_Ico' (n : ℕ) : ∀ a ∈ (Set.Ico n (n + 1) : Set α), (⌊a⌋₊ : α) = n := fun x hx => mod_cast floor_eq_on_Ico n x hx #align nat.floor_eq_on_Ico' Nat.floor_eq_on_Ico' @[simp] theorem preimage_floor_zero : (floor : α → ℕ) ⁻¹' {0} = Iio 1 := ext fun _ => floor_eq_zero #align nat.preimage_floor_zero Nat.preimage_floor_zero -- Porting note: in mathlib3 there was no need for the type annotation in `(n:α)` theorem preimage_floor_of_ne_zero {n : ℕ} (hn : n ≠ 0) : (floor : α → ℕ) ⁻¹' {n} = Ico (n:α) (n + 1) := ext fun _ => floor_eq_iff' hn #align nat.preimage_floor_of_ne_zero Nat.preimage_floor_of_ne_zero /-! #### Ceil -/ theorem gc_ceil_coe : GaloisConnection (ceil : α → ℕ) (↑) := FloorSemiring.gc_ceil #align nat.gc_ceil_coe Nat.gc_ceil_coe @[simp] theorem ceil_le : ⌈a⌉₊ ≤ n ↔ a ≤ n := gc_ceil_coe _ _ #align nat.ceil_le Nat.ceil_le theorem lt_ceil : n < ⌈a⌉₊ ↔ (n : α) < a := lt_iff_lt_of_le_iff_le ceil_le #align nat.lt_ceil Nat.lt_ceil -- porting note (#10618): simp can prove this -- @[simp] theorem add_one_le_ceil_iff : n + 1 ≤ ⌈a⌉₊ ↔ (n : α) < a := by rw [← Nat.lt_ceil, Nat.add_one_le_iff] #align nat.add_one_le_ceil_iff Nat.add_one_le_ceil_iff @[simp] theorem one_le_ceil_iff : 1 ≤ ⌈a⌉₊ ↔ 0 < a := by rw [← zero_add 1, Nat.add_one_le_ceil_iff, Nat.cast_zero] #align nat.one_le_ceil_iff Nat.one_le_ceil_iff theorem ceil_le_floor_add_one (a : α) : ⌈a⌉₊ ≤ ⌊a⌋₊ + 1 := by rw [ceil_le, Nat.cast_add, Nat.cast_one] exact (lt_floor_add_one a).le #align nat.ceil_le_floor_add_one Nat.ceil_le_floor_add_one theorem le_ceil (a : α) : a ≤ ⌈a⌉₊ := ceil_le.1 le_rfl #align nat.le_ceil Nat.le_ceil @[simp] theorem ceil_intCast {α : Type*} [LinearOrderedRing α] [FloorSemiring α] (z : ℤ) : ⌈(z : α)⌉₊ = z.toNat := eq_of_forall_ge_iff fun a => by simp only [ceil_le, Int.toNat_le] norm_cast #align nat.ceil_int_cast Nat.ceil_intCast @[simp] theorem ceil_natCast (n : ℕ) : ⌈(n : α)⌉₊ = n := eq_of_forall_ge_iff fun a => by rw [ceil_le, cast_le] #align nat.ceil_nat_cast Nat.ceil_natCast theorem ceil_mono : Monotone (ceil : α → ℕ) := gc_ceil_coe.monotone_l #align nat.ceil_mono Nat.ceil_mono @[gcongr] theorem ceil_le_ceil : ∀ x y : α, x ≤ y → ⌈x⌉₊ ≤ ⌈y⌉₊ := ceil_mono @[simp] theorem ceil_zero : ⌈(0 : α)⌉₊ = 0 := by rw [← Nat.cast_zero, ceil_natCast] #align nat.ceil_zero Nat.ceil_zero @[simp] theorem ceil_one : ⌈(1 : α)⌉₊ = 1 := by rw [← Nat.cast_one, ceil_natCast] #align nat.ceil_one Nat.ceil_one -- See note [no_index around OfNat.ofNat] @[simp] theorem ceil_ofNat (n : ℕ) [n.AtLeastTwo] : ⌈no_index (OfNat.ofNat n : α)⌉₊ = n := ceil_natCast n @[simp] theorem ceil_eq_zero : ⌈a⌉₊ = 0 ↔ a ≤ 0 := by rw [← Nat.le_zero, ceil_le, Nat.cast_zero] #align nat.ceil_eq_zero Nat.ceil_eq_zero @[simp] theorem ceil_pos : 0 < ⌈a⌉₊ ↔ 0 < a := by rw [lt_ceil, cast_zero] #align nat.ceil_pos Nat.ceil_pos theorem lt_of_ceil_lt (h : ⌈a⌉₊ < n) : a < n := (le_ceil a).trans_lt (Nat.cast_lt.2 h) #align nat.lt_of_ceil_lt Nat.lt_of_ceil_lt theorem le_of_ceil_le (h : ⌈a⌉₊ ≤ n) : a ≤ n := (le_ceil a).trans (Nat.cast_le.2 h) #align nat.le_of_ceil_le Nat.le_of_ceil_le theorem floor_le_ceil (a : α) : ⌊a⌋₊ ≤ ⌈a⌉₊ := by obtain ha | ha := le_total a 0 · rw [floor_of_nonpos ha] exact Nat.zero_le _ · exact cast_le.1 ((floor_le ha).trans <| le_ceil _) #align nat.floor_le_ceil Nat.floor_le_ceil theorem floor_lt_ceil_of_lt_of_pos {a b : α} (h : a < b) (h' : 0 < b) : ⌊a⌋₊ < ⌈b⌉₊ := by rcases le_or_lt 0 a with (ha | ha) · rw [floor_lt ha] exact h.trans_le (le_ceil _) · rwa [floor_of_nonpos ha.le, lt_ceil, Nat.cast_zero] #align nat.floor_lt_ceil_of_lt_of_pos Nat.floor_lt_ceil_of_lt_of_pos theorem ceil_eq_iff (hn : n ≠ 0) : ⌈a⌉₊ = n ↔ ↑(n - 1) < a ∧ a ≤ n := by rw [← ceil_le, ← not_le, ← ceil_le, not_le, tsub_lt_iff_right (Nat.add_one_le_iff.2 (pos_iff_ne_zero.2 hn)), Nat.lt_add_one_iff, le_antisymm_iff, and_comm] #align nat.ceil_eq_iff Nat.ceil_eq_iff @[simp] theorem preimage_ceil_zero : (Nat.ceil : α → ℕ) ⁻¹' {0} = Iic 0 := ext fun _ => ceil_eq_zero #align nat.preimage_ceil_zero Nat.preimage_ceil_zero -- Porting note: in mathlib3 there was no need for the type annotation in `(↑(n - 1))` theorem preimage_ceil_of_ne_zero (hn : n ≠ 0) : (Nat.ceil : α → ℕ) ⁻¹' {n} = Ioc (↑(n - 1) : α) n := ext fun _ => ceil_eq_iff hn #align nat.preimage_ceil_of_ne_zero Nat.preimage_ceil_of_ne_zero /-! #### Intervals -/ -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Ioo {a b : α} (ha : 0 ≤ a) : (Nat.cast : ℕ → α) ⁻¹' Set.Ioo a b = Set.Ioo ⌊a⌋₊ ⌈b⌉₊ := by ext simp [floor_lt, lt_ceil, ha] #align nat.preimage_Ioo Nat.preimage_Ioo -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Ico {a b : α} : (Nat.cast : ℕ → α) ⁻¹' Set.Ico a b = Set.Ico ⌈a⌉₊ ⌈b⌉₊ := by ext simp [ceil_le, lt_ceil] #align nat.preimage_Ico Nat.preimage_Ico -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Ioc {a b : α} (ha : 0 ≤ a) (hb : 0 ≤ b) : (Nat.cast : ℕ → α) ⁻¹' Set.Ioc a b = Set.Ioc ⌊a⌋₊ ⌊b⌋₊ := by ext simp [floor_lt, le_floor_iff, hb, ha] #align nat.preimage_Ioc Nat.preimage_Ioc -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Icc {a b : α} (hb : 0 ≤ b) : (Nat.cast : ℕ → α) ⁻¹' Set.Icc a b = Set.Icc ⌈a⌉₊ ⌊b⌋₊ := by ext simp [ceil_le, hb, le_floor_iff] #align nat.preimage_Icc Nat.preimage_Icc -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Ioi {a : α} (ha : 0 ≤ a) : (Nat.cast : ℕ → α) ⁻¹' Set.Ioi a = Set.Ioi ⌊a⌋₊ := by ext simp [floor_lt, ha] #align nat.preimage_Ioi Nat.preimage_Ioi -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Ici {a : α} : (Nat.cast : ℕ → α) ⁻¹' Set.Ici a = Set.Ici ⌈a⌉₊ := by ext simp [ceil_le] #align nat.preimage_Ici Nat.preimage_Ici -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Iio {a : α} : (Nat.cast : ℕ → α) ⁻¹' Set.Iio a = Set.Iio ⌈a⌉₊ := by ext simp [lt_ceil] #align nat.preimage_Iio Nat.preimage_Iio -- Porting note: changed `(coe : ℕ → α)` to `(Nat.cast : ℕ → α)` @[simp] theorem preimage_Iic {a : α} (ha : 0 ≤ a) : (Nat.cast : ℕ → α) ⁻¹' Set.Iic a = Set.Iic ⌊a⌋₊ := by ext simp [le_floor_iff, ha] #align nat.preimage_Iic Nat.preimage_Iic theorem floor_add_nat (ha : 0 ≤ a) (n : ℕ) : ⌊a + n⌋₊ = ⌊a⌋₊ + n := eq_of_forall_le_iff fun b => by rw [le_floor_iff (add_nonneg ha n.cast_nonneg)] obtain hb | hb := le_total n b · obtain ⟨d, rfl⟩ := exists_add_of_le hb rw [Nat.cast_add, add_comm n, add_comm (n : α), add_le_add_iff_right, add_le_add_iff_right, le_floor_iff ha] · obtain ⟨d, rfl⟩ := exists_add_of_le hb rw [Nat.cast_add, add_left_comm _ b, add_left_comm _ (b : α)] refine iff_of_true ?_ le_self_add exact le_add_of_nonneg_right <| ha.trans <| le_add_of_nonneg_right d.cast_nonneg #align nat.floor_add_nat Nat.floor_add_nat theorem floor_add_one (ha : 0 ≤ a) : ⌊a + 1⌋₊ = ⌊a⌋₊ + 1 := by -- Porting note: broken `convert floor_add_nat ha 1` rw [← cast_one, floor_add_nat ha 1] #align nat.floor_add_one Nat.floor_add_one -- See note [no_index around OfNat.ofNat] theorem floor_add_ofNat (ha : 0 ≤ a) (n : ℕ) [n.AtLeastTwo] : ⌊a + (no_index (OfNat.ofNat n))⌋₊ = ⌊a⌋₊ + OfNat.ofNat n := floor_add_nat ha n @[simp] theorem floor_sub_nat [Sub α] [OrderedSub α] [ExistsAddOfLE α] (a : α) (n : ℕ) : ⌊a - n⌋₊ = ⌊a⌋₊ - n := by obtain ha | ha := le_total a 0 · rw [floor_of_nonpos ha, floor_of_nonpos (tsub_nonpos_of_le (ha.trans n.cast_nonneg)), zero_tsub] rcases le_total a n with h | h · rw [floor_of_nonpos (tsub_nonpos_of_le h), eq_comm, tsub_eq_zero_iff_le] exact Nat.cast_le.1 ((Nat.floor_le ha).trans h) · rw [eq_tsub_iff_add_eq_of_le (le_floor h), ← floor_add_nat _, tsub_add_cancel_of_le h] exact le_tsub_of_add_le_left ((add_zero _).trans_le h) #align nat.floor_sub_nat Nat.floor_sub_nat @[simp] theorem floor_sub_one [Sub α] [OrderedSub α] [ExistsAddOfLE α] (a : α) : ⌊a - 1⌋₊ = ⌊a⌋₊ - 1 := mod_cast floor_sub_nat a 1 -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_sub_ofNat [Sub α] [OrderedSub α] [ExistsAddOfLE α] (a : α) (n : ℕ) [n.AtLeastTwo] : ⌊a - (no_index (OfNat.ofNat n))⌋₊ = ⌊a⌋₊ - OfNat.ofNat n := floor_sub_nat a n theorem ceil_add_nat (ha : 0 ≤ a) (n : ℕ) : ⌈a + n⌉₊ = ⌈a⌉₊ + n := eq_of_forall_ge_iff fun b => by rw [← not_lt, ← not_lt, not_iff_not, lt_ceil] obtain hb | hb := le_or_lt n b · obtain ⟨d, rfl⟩ := exists_add_of_le hb rw [Nat.cast_add, add_comm n, add_comm (n : α), add_lt_add_iff_right, add_lt_add_iff_right, lt_ceil] · exact iff_of_true (lt_add_of_nonneg_of_lt ha <| cast_lt.2 hb) (Nat.lt_add_left _ hb) #align nat.ceil_add_nat Nat.ceil_add_nat theorem ceil_add_one (ha : 0 ≤ a) : ⌈a + 1⌉₊ = ⌈a⌉₊ + 1 := by -- Porting note: broken `convert ceil_add_nat ha 1` rw [cast_one.symm, ceil_add_nat ha 1] #align nat.ceil_add_one Nat.ceil_add_one -- See note [no_index around OfNat.ofNat] theorem ceil_add_ofNat (ha : 0 ≤ a) (n : ℕ) [n.AtLeastTwo] : ⌈a + (no_index (OfNat.ofNat n))⌉₊ = ⌈a⌉₊ + OfNat.ofNat n := ceil_add_nat ha n theorem ceil_lt_add_one (ha : 0 ≤ a) : (⌈a⌉₊ : α) < a + 1 := lt_ceil.1 <| (Nat.lt_succ_self _).trans_le (ceil_add_one ha).ge #align nat.ceil_lt_add_one Nat.ceil_lt_add_one theorem ceil_add_le (a b : α) : ⌈a + b⌉₊ ≤ ⌈a⌉₊ + ⌈b⌉₊ := by rw [ceil_le, Nat.cast_add] exact _root_.add_le_add (le_ceil _) (le_ceil _) #align nat.ceil_add_le Nat.ceil_add_le end LinearOrderedSemiring section LinearOrderedRing variable [LinearOrderedRing α] [FloorSemiring α] theorem sub_one_lt_floor (a : α) : a - 1 < ⌊a⌋₊ := sub_lt_iff_lt_add.2 <| lt_floor_add_one a #align nat.sub_one_lt_floor Nat.sub_one_lt_floor end LinearOrderedRing section LinearOrderedSemifield variable [LinearOrderedSemifield α] [FloorSemiring α] -- TODO: should these lemmas be `simp`? `norm_cast`? theorem floor_div_nat (a : α) (n : ℕ) : ⌊a / n⌋₊ = ⌊a⌋₊ / n := by rcases le_total a 0 with ha | ha · rw [floor_of_nonpos, floor_of_nonpos ha] · simp apply div_nonpos_of_nonpos_of_nonneg ha n.cast_nonneg obtain rfl | hn := n.eq_zero_or_pos · rw [cast_zero, div_zero, Nat.div_zero, floor_zero] refine (floor_eq_iff ?_).2 ?_ · exact div_nonneg ha n.cast_nonneg constructor · exact cast_div_le.trans (div_le_div_of_nonneg_right (floor_le ha) n.cast_nonneg) rw [div_lt_iff, add_mul, one_mul, ← cast_mul, ← cast_add, ← floor_lt ha] · exact lt_div_mul_add hn · exact cast_pos.2 hn #align nat.floor_div_nat Nat.floor_div_nat -- See note [no_index around OfNat.ofNat] theorem floor_div_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : ⌊a / (no_index (OfNat.ofNat n))⌋₊ = ⌊a⌋₊ / OfNat.ofNat n := floor_div_nat a n /-- Natural division is the floor of field division. -/ theorem floor_div_eq_div (m n : ℕ) : ⌊(m : α) / n⌋₊ = m / n := by convert floor_div_nat (m : α) n rw [m.floor_natCast] #align nat.floor_div_eq_div Nat.floor_div_eq_div end LinearOrderedSemifield end Nat /-- There exists at most one `FloorSemiring` structure on a linear ordered semiring. -/ theorem subsingleton_floorSemiring {α} [LinearOrderedSemiring α] : Subsingleton (FloorSemiring α) := by refine ⟨fun H₁ H₂ => ?_⟩ have : H₁.ceil = H₂.ceil := funext fun a => (H₁.gc_ceil.l_unique H₂.gc_ceil) fun n => rfl have : H₁.floor = H₂.floor := by ext a cases' lt_or_le a 0 with h h · rw [H₁.floor_of_neg, H₂.floor_of_neg] <;> exact h · refine eq_of_forall_le_iff fun n => ?_ rw [H₁.gc_floor, H₂.gc_floor] <;> exact h cases H₁ cases H₂ congr #align subsingleton_floor_semiring subsingleton_floorSemiring /-! ### Floor rings -/ /-- A `FloorRing` is a linear ordered ring over `α` with a function `floor : α → ℤ` satisfying `∀ (z : ℤ) (a : α), z ≤ floor a ↔ (z : α) ≤ a)`. -/ class FloorRing (α) [LinearOrderedRing α] where /-- `FloorRing.floor a` computes the greatest integer `z` such that `(z : α) ≤ a`. -/ floor : α → ℤ /-- `FloorRing.ceil a` computes the least integer `z` such that `a ≤ (z : α)`. -/ ceil : α → ℤ /-- `FloorRing.ceil` is the upper adjoint of the coercion `↑ : ℤ → α`. -/ gc_coe_floor : GaloisConnection (↑) floor /-- `FloorRing.ceil` is the lower adjoint of the coercion `↑ : ℤ → α`. -/ gc_ceil_coe : GaloisConnection ceil (↑) #align floor_ring FloorRing instance : FloorRing ℤ where floor := id ceil := id gc_coe_floor a b := by rw [Int.cast_id] rfl gc_ceil_coe a b := by rw [Int.cast_id] rfl /-- A `FloorRing` constructor from the `floor` function alone. -/ def FloorRing.ofFloor (α) [LinearOrderedRing α] (floor : α → ℤ) (gc_coe_floor : GaloisConnection (↑) floor) : FloorRing α := { floor ceil := fun a => -floor (-a) gc_coe_floor gc_ceil_coe := fun a z => by rw [neg_le, ← gc_coe_floor, Int.cast_neg, neg_le_neg_iff] } #align floor_ring.of_floor FloorRing.ofFloor /-- A `FloorRing` constructor from the `ceil` function alone. -/ def FloorRing.ofCeil (α) [LinearOrderedRing α] (ceil : α → ℤ) (gc_ceil_coe : GaloisConnection ceil (↑)) : FloorRing α := { floor := fun a => -ceil (-a) ceil gc_coe_floor := fun a z => by rw [le_neg, gc_ceil_coe, Int.cast_neg, neg_le_neg_iff] gc_ceil_coe } #align floor_ring.of_ceil FloorRing.ofCeil namespace Int variable [LinearOrderedRing α] [FloorRing α] {z : ℤ} {a : α} /-- `Int.floor a` is the greatest integer `z` such that `z ≤ a`. It is denoted with `⌊a⌋`. -/ def floor : α → ℤ := FloorRing.floor #align int.floor Int.floor /-- `Int.ceil a` is the smallest integer `z` such that `a ≤ z`. It is denoted with `⌈a⌉`. -/ def ceil : α → ℤ := FloorRing.ceil #align int.ceil Int.ceil /-- `Int.fract a`, the fractional part of `a`, is `a` minus its floor. -/ def fract (a : α) : α := a - floor a #align int.fract Int.fract @[simp] theorem floor_int : (Int.floor : ℤ → ℤ) = id := rfl #align int.floor_int Int.floor_int @[simp] theorem ceil_int : (Int.ceil : ℤ → ℤ) = id := rfl #align int.ceil_int Int.ceil_int @[simp] theorem fract_int : (Int.fract : ℤ → ℤ) = 0 := funext fun x => by simp [fract] #align int.fract_int Int.fract_int @[inherit_doc] notation "⌊" a "⌋" => Int.floor a @[inherit_doc] notation "⌈" a "⌉" => Int.ceil a -- Mathematical notation for `fract a` is usually `{a}`. Let's not even go there. @[simp] theorem floorRing_floor_eq : @FloorRing.floor = @Int.floor := rfl #align int.floor_ring_floor_eq Int.floorRing_floor_eq @[simp] theorem floorRing_ceil_eq : @FloorRing.ceil = @Int.ceil := rfl #align int.floor_ring_ceil_eq Int.floorRing_ceil_eq /-! #### Floor -/ theorem gc_coe_floor : GaloisConnection ((↑) : ℤ → α) floor := FloorRing.gc_coe_floor #align int.gc_coe_floor Int.gc_coe_floor theorem le_floor : z ≤ ⌊a⌋ ↔ (z : α) ≤ a := (gc_coe_floor z a).symm #align int.le_floor Int.le_floor theorem floor_lt : ⌊a⌋ < z ↔ a < z := lt_iff_lt_of_le_iff_le le_floor #align int.floor_lt Int.floor_lt theorem floor_le (a : α) : (⌊a⌋ : α) ≤ a := gc_coe_floor.l_u_le a #align int.floor_le Int.floor_le theorem floor_nonneg : 0 ≤ ⌊a⌋ ↔ 0 ≤ a := by rw [le_floor, Int.cast_zero] #align int.floor_nonneg Int.floor_nonneg @[simp] theorem floor_le_sub_one_iff : ⌊a⌋ ≤ z - 1 ↔ a < z := by rw [← floor_lt, le_sub_one_iff] #align int.floor_le_sub_one_iff Int.floor_le_sub_one_iff @[simp] theorem floor_le_neg_one_iff : ⌊a⌋ ≤ -1 ↔ a < 0 := by rw [← zero_sub (1 : ℤ), floor_le_sub_one_iff, cast_zero] #align int.floor_le_neg_one_iff Int.floor_le_neg_one_iff theorem floor_nonpos (ha : a ≤ 0) : ⌊a⌋ ≤ 0 := by rw [← @cast_le α, Int.cast_zero] exact (floor_le a).trans ha #align int.floor_nonpos Int.floor_nonpos theorem lt_succ_floor (a : α) : a < ⌊a⌋.succ := floor_lt.1 <| Int.lt_succ_self _ #align int.lt_succ_floor Int.lt_succ_floor @[simp] theorem lt_floor_add_one (a : α) : a < ⌊a⌋ + 1 := by simpa only [Int.succ, Int.cast_add, Int.cast_one] using lt_succ_floor a #align int.lt_floor_add_one Int.lt_floor_add_one @[simp] theorem sub_one_lt_floor (a : α) : a - 1 < ⌊a⌋ := sub_lt_iff_lt_add.2 (lt_floor_add_one a) #align int.sub_one_lt_floor Int.sub_one_lt_floor @[simp] theorem floor_intCast (z : ℤ) : ⌊(z : α)⌋ = z := eq_of_forall_le_iff fun a => by rw [le_floor, Int.cast_le] #align int.floor_int_cast Int.floor_intCast @[simp] theorem floor_natCast (n : ℕ) : ⌊(n : α)⌋ = n := eq_of_forall_le_iff fun a => by rw [le_floor, ← cast_natCast, cast_le] #align int.floor_nat_cast Int.floor_natCast @[simp] theorem floor_zero : ⌊(0 : α)⌋ = 0 := by rw [← cast_zero, floor_intCast] #align int.floor_zero Int.floor_zero @[simp] theorem floor_one : ⌊(1 : α)⌋ = 1 := by rw [← cast_one, floor_intCast] #align int.floor_one Int.floor_one -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_ofNat (n : ℕ) [n.AtLeastTwo] : ⌊(no_index (OfNat.ofNat n : α))⌋ = n := floor_natCast n @[mono] theorem floor_mono : Monotone (floor : α → ℤ) := gc_coe_floor.monotone_u #align int.floor_mono Int.floor_mono @[gcongr] theorem floor_le_floor : ∀ x y : α, x ≤ y → ⌊x⌋ ≤ ⌊y⌋ := floor_mono theorem floor_pos : 0 < ⌊a⌋ ↔ 1 ≤ a := by -- Porting note: broken `convert le_floor` rw [Int.lt_iff_add_one_le, zero_add, le_floor, cast_one] #align int.floor_pos Int.floor_pos @[simp] theorem floor_add_int (a : α) (z : ℤ) : ⌊a + z⌋ = ⌊a⌋ + z := eq_of_forall_le_iff fun a => by rw [le_floor, ← sub_le_iff_le_add, ← sub_le_iff_le_add, le_floor, Int.cast_sub] #align int.floor_add_int Int.floor_add_int @[simp] theorem floor_add_one (a : α) : ⌊a + 1⌋ = ⌊a⌋ + 1 := by -- Porting note: broken `convert floor_add_int a 1` rw [← cast_one, floor_add_int] #align int.floor_add_one Int.floor_add_one theorem le_floor_add (a b : α) : ⌊a⌋ + ⌊b⌋ ≤ ⌊a + b⌋ := by rw [le_floor, Int.cast_add] exact add_le_add (floor_le _) (floor_le _) #align int.le_floor_add Int.le_floor_add theorem le_floor_add_floor (a b : α) : ⌊a + b⌋ - 1 ≤ ⌊a⌋ + ⌊b⌋ := by rw [← sub_le_iff_le_add, le_floor, Int.cast_sub, sub_le_comm, Int.cast_sub, Int.cast_one] refine le_trans ?_ (sub_one_lt_floor _).le rw [sub_le_iff_le_add', ← add_sub_assoc, sub_le_sub_iff_right] exact floor_le _ #align int.le_floor_add_floor Int.le_floor_add_floor @[simp] theorem floor_int_add (z : ℤ) (a : α) : ⌊↑z + a⌋ = z + ⌊a⌋ := by simpa only [add_comm] using floor_add_int a z #align int.floor_int_add Int.floor_int_add @[simp] theorem floor_add_nat (a : α) (n : ℕ) : ⌊a + n⌋ = ⌊a⌋ + n := by rw [← Int.cast_natCast, floor_add_int] #align int.floor_add_nat Int.floor_add_nat -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_add_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : ⌊a + (no_index (OfNat.ofNat n))⌋ = ⌊a⌋ + OfNat.ofNat n := floor_add_nat a n @[simp] theorem floor_nat_add (n : ℕ) (a : α) : ⌊↑n + a⌋ = n + ⌊a⌋ := by rw [← Int.cast_natCast, floor_int_add] #align int.floor_nat_add Int.floor_nat_add -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_ofNat_add (n : ℕ) [n.AtLeastTwo] (a : α) : ⌊(no_index (OfNat.ofNat n)) + a⌋ = OfNat.ofNat n + ⌊a⌋ := floor_nat_add n a @[simp] theorem floor_sub_int (a : α) (z : ℤ) : ⌊a - z⌋ = ⌊a⌋ - z := Eq.trans (by rw [Int.cast_neg, sub_eq_add_neg]) (floor_add_int _ _) #align int.floor_sub_int Int.floor_sub_int @[simp] theorem floor_sub_nat (a : α) (n : ℕ) : ⌊a - n⌋ = ⌊a⌋ - n := by rw [← Int.cast_natCast, floor_sub_int] #align int.floor_sub_nat Int.floor_sub_nat @[simp] theorem floor_sub_one (a : α) : ⌊a - 1⌋ = ⌊a⌋ - 1 := mod_cast floor_sub_nat a 1 -- See note [no_index around OfNat.ofNat] @[simp] theorem floor_sub_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : ⌊a - (no_index (OfNat.ofNat n))⌋ = ⌊a⌋ - OfNat.ofNat n := floor_sub_nat a n theorem abs_sub_lt_one_of_floor_eq_floor {α : Type*} [LinearOrderedCommRing α] [FloorRing α] {a b : α} (h : ⌊a⌋ = ⌊b⌋) : |a - b| < 1 := by have : a < ⌊a⌋ + 1 := lt_floor_add_one a have : b < ⌊b⌋ + 1 := lt_floor_add_one b have : (⌊a⌋ : α) = ⌊b⌋ := Int.cast_inj.2 h have : (⌊a⌋ : α) ≤ a := floor_le a have : (⌊b⌋ : α) ≤ b := floor_le b exact abs_sub_lt_iff.2 ⟨by linarith, by linarith⟩ #align int.abs_sub_lt_one_of_floor_eq_floor Int.abs_sub_lt_one_of_floor_eq_floor theorem floor_eq_iff : ⌊a⌋ = z ↔ ↑z ≤ a ∧ a < z + 1 := by rw [le_antisymm_iff, le_floor, ← Int.lt_add_one_iff, floor_lt, Int.cast_add, Int.cast_one, and_comm] #align int.floor_eq_iff Int.floor_eq_iff @[simp] theorem floor_eq_zero_iff : ⌊a⌋ = 0 ↔ a ∈ Ico (0 : α) 1 := by simp [floor_eq_iff] #align int.floor_eq_zero_iff Int.floor_eq_zero_iff theorem floor_eq_on_Ico (n : ℤ) : ∀ a ∈ Set.Ico (n : α) (n + 1), ⌊a⌋ = n := fun _ ⟨h₀, h₁⟩ => floor_eq_iff.mpr ⟨h₀, h₁⟩ #align int.floor_eq_on_Ico Int.floor_eq_on_Ico theorem floor_eq_on_Ico' (n : ℤ) : ∀ a ∈ Set.Ico (n : α) (n + 1), (⌊a⌋ : α) = n := fun a ha => congr_arg _ <| floor_eq_on_Ico n a ha #align int.floor_eq_on_Ico' Int.floor_eq_on_Ico' -- Porting note: in mathlib3 there was no need for the type annotation in `(m:α)` @[simp] theorem preimage_floor_singleton (m : ℤ) : (floor : α → ℤ) ⁻¹' {m} = Ico (m : α) (m + 1) := ext fun _ => floor_eq_iff #align int.preimage_floor_singleton Int.preimage_floor_singleton /-! #### Fractional part -/ @[simp] theorem self_sub_floor (a : α) : a - ⌊a⌋ = fract a := rfl #align int.self_sub_floor Int.self_sub_floor @[simp] theorem floor_add_fract (a : α) : (⌊a⌋ : α) + fract a = a := add_sub_cancel _ _ #align int.floor_add_fract Int.floor_add_fract @[simp] theorem fract_add_floor (a : α) : fract a + ⌊a⌋ = a := sub_add_cancel _ _ #align int.fract_add_floor Int.fract_add_floor @[simp] theorem fract_add_int (a : α) (m : ℤ) : fract (a + m) = fract a := by rw [fract] simp #align int.fract_add_int Int.fract_add_int @[simp] theorem fract_add_nat (a : α) (m : ℕ) : fract (a + m) = fract a := by rw [fract] simp #align int.fract_add_nat Int.fract_add_nat @[simp] theorem fract_add_one (a : α) : fract (a + 1) = fract a := mod_cast fract_add_nat a 1 -- See note [no_index around OfNat.ofNat] @[simp] theorem fract_add_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : fract (a + (no_index (OfNat.ofNat n))) = fract a := fract_add_nat a n @[simp] theorem fract_int_add (m : ℤ) (a : α) : fract (↑m + a) = fract a := by rw [add_comm, fract_add_int] #align int.fract_int_add Int.fract_int_add @[simp] theorem fract_nat_add (n : ℕ) (a : α) : fract (↑n + a) = fract a := by rw [add_comm, fract_add_nat] @[simp] theorem fract_one_add (a : α) : fract (1 + a) = fract a := mod_cast fract_nat_add 1 a -- See note [no_index around OfNat.ofNat] @[simp] theorem fract_ofNat_add (n : ℕ) [n.AtLeastTwo] (a : α) : fract ((no_index (OfNat.ofNat n)) + a) = fract a := fract_nat_add n a @[simp] theorem fract_sub_int (a : α) (m : ℤ) : fract (a - m) = fract a := by rw [fract] simp #align int.fract_sub_int Int.fract_sub_int @[simp] theorem fract_sub_nat (a : α) (n : ℕ) : fract (a - n) = fract a := by rw [fract] simp #align int.fract_sub_nat Int.fract_sub_nat @[simp] theorem fract_sub_one (a : α) : fract (a - 1) = fract a := mod_cast fract_sub_nat a 1 -- See note [no_index around OfNat.ofNat] @[simp] theorem fract_sub_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : fract (a - (no_index (OfNat.ofNat n))) = fract a := fract_sub_nat a n -- Was a duplicate lemma under a bad name #align int.fract_int_nat Int.fract_int_add theorem fract_add_le (a b : α) : fract (a + b) ≤ fract a + fract b := by rw [fract, fract, fract, sub_add_sub_comm, sub_le_sub_iff_left, ← Int.cast_add, Int.cast_le] exact le_floor_add _ _ #align int.fract_add_le Int.fract_add_le theorem fract_add_fract_le (a b : α) : fract a + fract b ≤ fract (a + b) + 1 := by rw [fract, fract, fract, sub_add_sub_comm, sub_add, sub_le_sub_iff_left] exact mod_cast le_floor_add_floor a b #align int.fract_add_fract_le Int.fract_add_fract_le @[simp] theorem self_sub_fract (a : α) : a - fract a = ⌊a⌋ := sub_sub_cancel _ _ #align int.self_sub_fract Int.self_sub_fract @[simp] theorem fract_sub_self (a : α) : fract a - a = -⌊a⌋ := sub_sub_cancel_left _ _ #align int.fract_sub_self Int.fract_sub_self @[simp] theorem fract_nonneg (a : α) : 0 ≤ fract a := sub_nonneg.2 <| floor_le _ #align int.fract_nonneg Int.fract_nonneg /-- The fractional part of `a` is positive if and only if `a ≠ ⌊a⌋`. -/ lemma fract_pos : 0 < fract a ↔ a ≠ ⌊a⌋ := (fract_nonneg a).lt_iff_ne.trans <| ne_comm.trans sub_ne_zero #align int.fract_pos Int.fract_pos theorem fract_lt_one (a : α) : fract a < 1 := sub_lt_comm.1 <| sub_one_lt_floor _ #align int.fract_lt_one Int.fract_lt_one @[simp] theorem fract_zero : fract (0 : α) = 0 := by rw [fract, floor_zero, cast_zero, sub_self] #align int.fract_zero Int.fract_zero @[simp] theorem fract_one : fract (1 : α) = 0 := by simp [fract] #align int.fract_one Int.fract_one theorem abs_fract : |fract a| = fract a := abs_eq_self.mpr <| fract_nonneg a #align int.abs_fract Int.abs_fract @[simp] theorem abs_one_sub_fract : |1 - fract a| = 1 - fract a := abs_eq_self.mpr <| sub_nonneg.mpr (fract_lt_one a).le #align int.abs_one_sub_fract Int.abs_one_sub_fract @[simp] theorem fract_intCast (z : ℤ) : fract (z : α) = 0 := by unfold fract rw [floor_intCast] exact sub_self _ #align int.fract_int_cast Int.fract_intCast @[simp] theorem fract_natCast (n : ℕ) : fract (n : α) = 0 := by simp [fract] #align int.fract_nat_cast Int.fract_natCast -- See note [no_index around OfNat.ofNat] @[simp] theorem fract_ofNat (n : ℕ) [n.AtLeastTwo] : fract ((no_index (OfNat.ofNat n)) : α) = 0 := fract_natCast n -- porting note (#10618): simp can prove this -- @[simp] theorem fract_floor (a : α) : fract (⌊a⌋ : α) = 0 := fract_intCast _ #align int.fract_floor Int.fract_floor @[simp] theorem floor_fract (a : α) : ⌊fract a⌋ = 0 := by rw [floor_eq_iff, Int.cast_zero, zero_add]; exact ⟨fract_nonneg _, fract_lt_one _⟩ #align int.floor_fract Int.floor_fract theorem fract_eq_iff {a b : α} : fract a = b ↔ 0 ≤ b ∧ b < 1 ∧ ∃ z : ℤ, a - b = z := ⟨fun h => by rw [← h] exact ⟨fract_nonneg _, fract_lt_one _, ⟨⌊a⌋, sub_sub_cancel _ _⟩⟩, by rintro ⟨h₀, h₁, z, hz⟩ rw [← self_sub_floor, eq_comm, eq_sub_iff_add_eq, add_comm, ← eq_sub_iff_add_eq, hz, Int.cast_inj, floor_eq_iff, ← hz] constructor <;> simpa [sub_eq_add_neg, add_assoc] ⟩ #align int.fract_eq_iff Int.fract_eq_iff theorem fract_eq_fract {a b : α} : fract a = fract b ↔ ∃ z : ℤ, a - b = z := ⟨fun h => ⟨⌊a⌋ - ⌊b⌋, by unfold fract at h; rw [Int.cast_sub, sub_eq_sub_iff_sub_eq_sub.1 h]⟩, by rintro ⟨z, hz⟩ refine fract_eq_iff.2 ⟨fract_nonneg _, fract_lt_one _, z + ⌊b⌋, ?_⟩ rw [eq_add_of_sub_eq hz, add_comm, Int.cast_add] exact add_sub_sub_cancel _ _ _⟩ #align int.fract_eq_fract Int.fract_eq_fract @[simp] theorem fract_eq_self {a : α} : fract a = a ↔ 0 ≤ a ∧ a < 1 := fract_eq_iff.trans <| and_assoc.symm.trans <| and_iff_left ⟨0, by simp⟩ #align int.fract_eq_self Int.fract_eq_self @[simp] theorem fract_fract (a : α) : fract (fract a) = fract a := fract_eq_self.2 ⟨fract_nonneg _, fract_lt_one _⟩ #align int.fract_fract Int.fract_fract theorem fract_add (a b : α) : ∃ z : ℤ, fract (a + b) - fract a - fract b = z := ⟨⌊a⌋ + ⌊b⌋ - ⌊a + b⌋, by unfold fract simp only [sub_eq_add_neg, neg_add_rev, neg_neg, cast_add, cast_neg] abel⟩ #align int.fract_add Int.fract_add theorem fract_neg {x : α} (hx : fract x ≠ 0) : fract (-x) = 1 - fract x := by rw [fract_eq_iff] constructor · rw [le_sub_iff_add_le, zero_add] exact (fract_lt_one x).le refine ⟨sub_lt_self _ (lt_of_le_of_ne' (fract_nonneg x) hx), -⌊x⌋ - 1, ?_⟩ simp only [sub_sub_eq_add_sub, cast_sub, cast_neg, cast_one, sub_left_inj] conv in -x => rw [← floor_add_fract x] simp [-floor_add_fract] #align int.fract_neg Int.fract_neg @[simp] theorem fract_neg_eq_zero {x : α} : fract (-x) = 0 ↔ fract x = 0 := by simp only [fract_eq_iff, le_refl, zero_lt_one, tsub_zero, true_and_iff] constructor <;> rintro ⟨z, hz⟩ <;> use -z <;> simp [← hz] #align int.fract_neg_eq_zero Int.fract_neg_eq_zero theorem fract_mul_nat (a : α) (b : ℕ) : ∃ z : ℤ, fract a * b - fract (a * b) = z := by induction' b with c hc · use 0; simp · rcases hc with ⟨z, hz⟩ rw [Nat.cast_add, mul_add, mul_add, Nat.cast_one, mul_one, mul_one] rcases fract_add (a * c) a with ⟨y, hy⟩ use z - y rw [Int.cast_sub, ← hz, ← hy] abel #align int.fract_mul_nat Int.fract_mul_nat -- Porting note: in mathlib3 there was no need for the type annotation in `(m:α)` theorem preimage_fract (s : Set α) : fract ⁻¹' s = ⋃ m : ℤ, (fun x => x - (m:α)) ⁻¹' (s ∩ Ico (0 : α) 1) := by ext x simp only [mem_preimage, mem_iUnion, mem_inter_iff] refine ⟨fun h => ⟨⌊x⌋, h, fract_nonneg x, fract_lt_one x⟩, ?_⟩ rintro ⟨m, hms, hm0, hm1⟩ obtain rfl : ⌊x⌋ = m := floor_eq_iff.2 ⟨sub_nonneg.1 hm0, sub_lt_iff_lt_add'.1 hm1⟩ exact hms #align int.preimage_fract Int.preimage_fract theorem image_fract (s : Set α) : fract '' s = ⋃ m : ℤ, (fun x : α => x - m) '' s ∩ Ico 0 1 := by ext x simp only [mem_image, mem_inter_iff, mem_iUnion]; constructor · rintro ⟨y, hy, rfl⟩ exact ⟨⌊y⌋, ⟨y, hy, rfl⟩, fract_nonneg y, fract_lt_one y⟩ · rintro ⟨m, ⟨y, hys, rfl⟩, h0, h1⟩ obtain rfl : ⌊y⌋ = m := floor_eq_iff.2 ⟨sub_nonneg.1 h0, sub_lt_iff_lt_add'.1 h1⟩ exact ⟨y, hys, rfl⟩ #align int.image_fract Int.image_fract section LinearOrderedField variable {k : Type*} [LinearOrderedField k] [FloorRing k] {b : k} theorem fract_div_mul_self_mem_Ico (a b : k) (ha : 0 < a) : fract (b / a) * a ∈ Ico 0 a := ⟨(mul_nonneg_iff_of_pos_right ha).2 (fract_nonneg (b / a)), (mul_lt_iff_lt_one_left ha).2 (fract_lt_one (b / a))⟩ #align int.fract_div_mul_self_mem_Ico Int.fract_div_mul_self_mem_Ico theorem fract_div_mul_self_add_zsmul_eq (a b : k) (ha : a ≠ 0) : fract (b / a) * a + ⌊b / a⌋ • a = b := by rw [zsmul_eq_mul, ← add_mul, fract_add_floor, div_mul_cancel₀ b ha] #align int.fract_div_mul_self_add_zsmul_eq Int.fract_div_mul_self_add_zsmul_eq theorem sub_floor_div_mul_nonneg (a : k) (hb : 0 < b) : 0 ≤ a - ⌊a / b⌋ * b := sub_nonneg_of_le <| (le_div_iff hb).1 <| floor_le _ #align int.sub_floor_div_mul_nonneg Int.sub_floor_div_mul_nonneg theorem sub_floor_div_mul_lt (a : k) (hb : 0 < b) : a - ⌊a / b⌋ * b < b := sub_lt_iff_lt_add.2 <| by -- Porting note: `← one_add_mul` worked in mathlib3 without the argument rw [← one_add_mul _ b, ← div_lt_iff hb, add_comm] exact lt_floor_add_one _ #align int.sub_floor_div_mul_lt Int.sub_floor_div_mul_lt theorem fract_div_natCast_eq_div_natCast_mod {m n : ℕ} : fract ((m : k) / n) = ↑(m % n) / n := by rcases n.eq_zero_or_pos with (rfl | hn) · simp have hn' : 0 < (n : k) := by norm_cast refine fract_eq_iff.mpr ⟨?_, ?_, m / n, ?_⟩ · positivity · simpa only [div_lt_one hn', Nat.cast_lt] using m.mod_lt hn · rw [sub_eq_iff_eq_add', ← mul_right_inj' hn'.ne', mul_div_cancel₀ _ hn'.ne', mul_add, mul_div_cancel₀ _ hn'.ne'] norm_cast rw [← Nat.cast_add, Nat.mod_add_div m n] #align int.fract_div_nat_cast_eq_div_nat_cast_mod Int.fract_div_natCast_eq_div_natCast_mod -- TODO Generalise this to allow `n : ℤ` using `Int.fmod` instead of `Int.mod`. theorem fract_div_intCast_eq_div_intCast_mod {m : ℤ} {n : ℕ} : fract ((m : k) / n) = ↑(m % n) / n := by rcases n.eq_zero_or_pos with (rfl | hn) · simp replace hn : 0 < (n : k) := by norm_cast have : ∀ {l : ℤ}, 0 ≤ l → fract ((l : k) / n) = ↑(l % n) / n := by intros l hl obtain ⟨l₀, rfl | rfl⟩ := l.eq_nat_or_neg · rw [cast_natCast, ← natCast_mod, cast_natCast, fract_div_natCast_eq_div_natCast_mod] · rw [Right.nonneg_neg_iff, natCast_nonpos_iff] at hl simp [hl, zero_mod] obtain ⟨m₀, rfl | rfl⟩ := m.eq_nat_or_neg · exact this (ofNat_nonneg m₀) let q := ⌈↑m₀ / (n : k)⌉ let m₁ := q * ↑n - (↑m₀ : ℤ) have hm₁ : 0 ≤ m₁ := by simpa [m₁, ← @cast_le k, ← div_le_iff hn] using FloorRing.gc_ceil_coe.le_u_l _ calc fract ((Int.cast (-(m₀ : ℤ)) : k) / (n : k)) -- Porting note: the `rw [cast_neg, cast_natCast]` was `push_cast` = fract (-(m₀ : k) / n) := by rw [cast_neg, cast_natCast] _ = fract ((m₁ : k) / n) := ?_ _ = Int.cast (m₁ % (n : ℤ)) / Nat.cast n := this hm₁ _ = Int.cast (-(↑m₀ : ℤ) % ↑n) / Nat.cast n := ?_ · rw [← fract_int_add q, ← mul_div_cancel_right₀ (q : k) hn.ne', ← add_div, ← sub_eq_add_neg] -- Porting note: the `simp` was `push_cast` simp [m₁] · congr 2 change (q * ↑n - (↑m₀ : ℤ)) % ↑n = _ rw [sub_eq_add_neg, add_comm (q * ↑n), add_mul_emod_self] #align int.fract_div_int_cast_eq_div_int_cast_mod Int.fract_div_intCast_eq_div_intCast_mod end LinearOrderedField /-! #### Ceil -/ theorem gc_ceil_coe : GaloisConnection ceil ((↑) : ℤ → α) := FloorRing.gc_ceil_coe #align int.gc_ceil_coe Int.gc_ceil_coe theorem ceil_le : ⌈a⌉ ≤ z ↔ a ≤ z := gc_ceil_coe a z #align int.ceil_le Int.ceil_le theorem floor_neg : ⌊-a⌋ = -⌈a⌉ := eq_of_forall_le_iff fun z => by rw [le_neg, ceil_le, le_floor, Int.cast_neg, le_neg] #align int.floor_neg Int.floor_neg theorem ceil_neg : ⌈-a⌉ = -⌊a⌋ := eq_of_forall_ge_iff fun z => by rw [neg_le, ceil_le, le_floor, Int.cast_neg, neg_le] #align int.ceil_neg Int.ceil_neg theorem lt_ceil : z < ⌈a⌉ ↔ (z : α) < a := lt_iff_lt_of_le_iff_le ceil_le #align int.lt_ceil Int.lt_ceil @[simp] theorem add_one_le_ceil_iff : z + 1 ≤ ⌈a⌉ ↔ (z : α) < a := by rw [← lt_ceil, add_one_le_iff] #align int.add_one_le_ceil_iff Int.add_one_le_ceil_iff @[simp] theorem one_le_ceil_iff : 1 ≤ ⌈a⌉ ↔ 0 < a := by rw [← zero_add (1 : ℤ), add_one_le_ceil_iff, cast_zero] #align int.one_le_ceil_iff Int.one_le_ceil_iff theorem ceil_le_floor_add_one (a : α) : ⌈a⌉ ≤ ⌊a⌋ + 1 := by rw [ceil_le, Int.cast_add, Int.cast_one] exact (lt_floor_add_one a).le #align int.ceil_le_floor_add_one Int.ceil_le_floor_add_one theorem le_ceil (a : α) : a ≤ ⌈a⌉ := gc_ceil_coe.le_u_l a #align int.le_ceil Int.le_ceil @[simp] theorem ceil_intCast (z : ℤ) : ⌈(z : α)⌉ = z := eq_of_forall_ge_iff fun a => by rw [ceil_le, Int.cast_le] #align int.ceil_int_cast Int.ceil_intCast @[simp] theorem ceil_natCast (n : ℕ) : ⌈(n : α)⌉ = n := eq_of_forall_ge_iff fun a => by rw [ceil_le, ← cast_natCast, cast_le] #align int.ceil_nat_cast Int.ceil_natCast -- See note [no_index around OfNat.ofNat] @[simp] theorem ceil_ofNat (n : ℕ) [n.AtLeastTwo] : ⌈(no_index (OfNat.ofNat n : α))⌉ = n := ceil_natCast n theorem ceil_mono : Monotone (ceil : α → ℤ) := gc_ceil_coe.monotone_l #align int.ceil_mono Int.ceil_mono @[gcongr] theorem ceil_le_ceil : ∀ x y : α, x ≤ y → ⌈x⌉ ≤ ⌈y⌉ := ceil_mono @[simp] theorem ceil_add_int (a : α) (z : ℤ) : ⌈a + z⌉ = ⌈a⌉ + z := by rw [← neg_inj, neg_add', ← floor_neg, ← floor_neg, neg_add', floor_sub_int] #align int.ceil_add_int Int.ceil_add_int @[simp] theorem ceil_add_nat (a : α) (n : ℕ) : ⌈a + n⌉ = ⌈a⌉ + n := by rw [← Int.cast_natCast, ceil_add_int] #align int.ceil_add_nat Int.ceil_add_nat @[simp] theorem ceil_add_one (a : α) : ⌈a + 1⌉ = ⌈a⌉ + 1 := by -- Porting note: broken `convert ceil_add_int a (1 : ℤ)` rw [← ceil_add_int a (1 : ℤ), cast_one] #align int.ceil_add_one Int.ceil_add_one -- See note [no_index around OfNat.ofNat] @[simp] theorem ceil_add_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : ⌈a + (no_index (OfNat.ofNat n))⌉ = ⌈a⌉ + OfNat.ofNat n := ceil_add_nat a n @[simp] theorem ceil_sub_int (a : α) (z : ℤ) : ⌈a - z⌉ = ⌈a⌉ - z := Eq.trans (by rw [Int.cast_neg, sub_eq_add_neg]) (ceil_add_int _ _) #align int.ceil_sub_int Int.ceil_sub_int @[simp] theorem ceil_sub_nat (a : α) (n : ℕ) : ⌈a - n⌉ = ⌈a⌉ - n := by convert ceil_sub_int a n using 1 simp #align int.ceil_sub_nat Int.ceil_sub_nat @[simp] theorem ceil_sub_one (a : α) : ⌈a - 1⌉ = ⌈a⌉ - 1 := by rw [eq_sub_iff_add_eq, ← ceil_add_one, sub_add_cancel] #align int.ceil_sub_one Int.ceil_sub_one -- See note [no_index around OfNat.ofNat] @[simp] theorem ceil_sub_ofNat (a : α) (n : ℕ) [n.AtLeastTwo] : ⌈a - (no_index (OfNat.ofNat n))⌉ = ⌈a⌉ - OfNat.ofNat n := ceil_sub_nat a n theorem ceil_lt_add_one (a : α) : (⌈a⌉ : α) < a + 1 := by rw [← lt_ceil, ← Int.cast_one, ceil_add_int] apply lt_add_one #align int.ceil_lt_add_one Int.ceil_lt_add_one theorem ceil_add_le (a b : α) : ⌈a + b⌉ ≤ ⌈a⌉ + ⌈b⌉ := by rw [ceil_le, Int.cast_add] exact add_le_add (le_ceil _) (le_ceil _) #align int.ceil_add_le Int.ceil_add_le theorem ceil_add_ceil_le (a b : α) : ⌈a⌉ + ⌈b⌉ ≤ ⌈a + b⌉ + 1 := by rw [← le_sub_iff_add_le, ceil_le, Int.cast_sub, Int.cast_add, Int.cast_one, le_sub_comm] refine (ceil_lt_add_one _).le.trans ?_ rw [le_sub_iff_add_le', ← add_assoc, add_le_add_iff_right] exact le_ceil _ #align int.ceil_add_ceil_le Int.ceil_add_ceil_le @[simp] theorem ceil_pos : 0 < ⌈a⌉ ↔ 0 < a := by rw [lt_ceil, cast_zero] #align int.ceil_pos Int.ceil_pos @[simp] theorem ceil_zero : ⌈(0 : α)⌉ = 0 := by rw [← cast_zero, ceil_intCast] #align int.ceil_zero Int.ceil_zero @[simp] theorem ceil_one : ⌈(1 : α)⌉ = 1 := by rw [← cast_one, ceil_intCast] #align int.ceil_one Int.ceil_one theorem ceil_nonneg (ha : 0 ≤ a) : 0 ≤ ⌈a⌉ := mod_cast ha.trans (le_ceil a) #align int.ceil_nonneg Int.ceil_nonneg theorem ceil_eq_iff : ⌈a⌉ = z ↔ ↑z - 1 < a ∧ a ≤ z := by rw [← ceil_le, ← Int.cast_one, ← Int.cast_sub, ← lt_ceil, Int.sub_one_lt_iff, le_antisymm_iff, and_comm] #align int.ceil_eq_iff Int.ceil_eq_iff @[simp] theorem ceil_eq_zero_iff : ⌈a⌉ = 0 ↔ a ∈ Ioc (-1 : α) 0 := by simp [ceil_eq_iff] #align int.ceil_eq_zero_iff Int.ceil_eq_zero_iff theorem ceil_eq_on_Ioc (z : ℤ) : ∀ a ∈ Set.Ioc (z - 1 : α) z, ⌈a⌉ = z := fun _ ⟨h₀, h₁⟩ => ceil_eq_iff.mpr ⟨h₀, h₁⟩ #align int.ceil_eq_on_Ioc Int.ceil_eq_on_Ioc theorem ceil_eq_on_Ioc' (z : ℤ) : ∀ a ∈ Set.Ioc (z - 1 : α) z, (⌈a⌉ : α) = z := fun a ha => mod_cast ceil_eq_on_Ioc z a ha #align int.ceil_eq_on_Ioc' Int.ceil_eq_on_Ioc' theorem floor_le_ceil (a : α) : ⌊a⌋ ≤ ⌈a⌉ := cast_le.1 <| (floor_le _).trans <| le_ceil _ #align int.floor_le_ceil Int.floor_le_ceil theorem floor_lt_ceil_of_lt {a b : α} (h : a < b) : ⌊a⌋ < ⌈b⌉ := cast_lt.1 <| (floor_le a).trans_lt <| h.trans_le <| le_ceil b #align int.floor_lt_ceil_of_lt Int.floor_lt_ceil_of_lt -- Porting note: in mathlib3 there was no need for the type annotation in `(m : α)` @[simp] theorem preimage_ceil_singleton (m : ℤ) : (ceil : α → ℤ) ⁻¹' {m} = Ioc ((m : α) - 1) m := ext fun _ => ceil_eq_iff #align int.preimage_ceil_singleton Int.preimage_ceil_singleton theorem fract_eq_zero_or_add_one_sub_ceil (a : α) : fract a = 0 ∨ fract a = a + 1 - (⌈a⌉ : α) := by rcases eq_or_ne (fract a) 0 with ha | ha · exact Or.inl ha right suffices (⌈a⌉ : α) = ⌊a⌋ + 1 by rw [this, ← self_sub_fract] abel norm_cast rw [ceil_eq_iff] refine ⟨?_, _root_.le_of_lt <| by simp⟩ rw [cast_add, cast_one, add_tsub_cancel_right, ← self_sub_fract a, sub_lt_self_iff] exact ha.symm.lt_of_le (fract_nonneg a) #align int.fract_eq_zero_or_add_one_sub_ceil Int.fract_eq_zero_or_add_one_sub_ceil theorem ceil_eq_add_one_sub_fract (ha : fract a ≠ 0) : (⌈a⌉ : α) = a + 1 - fract a := by rw [(or_iff_right ha).mp (fract_eq_zero_or_add_one_sub_ceil a)] abel #align int.ceil_eq_add_one_sub_fract Int.ceil_eq_add_one_sub_fract theorem ceil_sub_self_eq (ha : fract a ≠ 0) : (⌈a⌉ : α) - a = 1 - fract a := by rw [(or_iff_right ha).mp (fract_eq_zero_or_add_one_sub_ceil a)] abel #align int.ceil_sub_self_eq Int.ceil_sub_self_eq /-! #### Intervals -/ @[simp] theorem preimage_Ioo {a b : α} : ((↑) : ℤ → α) ⁻¹' Set.Ioo a b = Set.Ioo ⌊a⌋ ⌈b⌉ := by ext simp [floor_lt, lt_ceil] #align int.preimage_Ioo Int.preimage_Ioo @[simp] theorem preimage_Ico {a b : α} : ((↑) : ℤ → α) ⁻¹' Set.Ico a b = Set.Ico ⌈a⌉ ⌈b⌉ := by ext simp [ceil_le, lt_ceil] #align int.preimage_Ico Int.preimage_Ico @[simp] theorem preimage_Ioc {a b : α} : ((↑) : ℤ → α) ⁻¹' Set.Ioc a b = Set.Ioc ⌊a⌋ ⌊b⌋ := by ext simp [floor_lt, le_floor] #align int.preimage_Ioc Int.preimage_Ioc @[simp] theorem preimage_Icc {a b : α} : ((↑) : ℤ → α) ⁻¹' Set.Icc a b = Set.Icc ⌈a⌉ ⌊b⌋ := by ext simp [ceil_le, le_floor] #align int.preimage_Icc Int.preimage_Icc @[simp] theorem preimage_Ioi : ((↑) : ℤ → α) ⁻¹' Set.Ioi a = Set.Ioi ⌊a⌋ := by ext simp [floor_lt] #align int.preimage_Ioi Int.preimage_Ioi @[simp] theorem preimage_Ici : ((↑) : ℤ → α) ⁻¹' Set.Ici a = Set.Ici ⌈a⌉ := by ext simp [ceil_le] #align int.preimage_Ici Int.preimage_Ici @[simp] theorem preimage_Iio : ((↑) : ℤ → α) ⁻¹' Set.Iio a = Set.Iio ⌈a⌉ := by ext simp [lt_ceil] #align int.preimage_Iio Int.preimage_Iio @[simp] theorem preimage_Iic : ((↑) : ℤ → α) ⁻¹' Set.Iic a = Set.Iic ⌊a⌋ := by ext simp [le_floor] #align int.preimage_Iic Int.preimage_Iic end Int open Int /-! ### Round -/ section round section LinearOrderedRing variable [LinearOrderedRing α] [FloorRing α] /-- `round` rounds a number to the nearest integer. `round (1 / 2) = 1` -/ def round (x : α) : ℤ := if 2 * fract x < 1 then ⌊x⌋ else ⌈x⌉ #align round round @[simp] theorem round_zero : round (0 : α) = 0 := by simp [round] #align round_zero round_zero @[simp] theorem round_one : round (1 : α) = 1 := by simp [round] #align round_one round_one @[simp] theorem round_natCast (n : ℕ) : round (n : α) = n := by simp [round] #align round_nat_cast round_natCast -- See note [no_index around OfNat.ofNat] @[simp] theorem round_ofNat (n : ℕ) [n.AtLeastTwo] : round (no_index (OfNat.ofNat n : α)) = n := round_natCast n @[simp] theorem round_intCast (n : ℤ) : round (n : α) = n := by simp [round] #align round_int_cast round_intCast @[simp] theorem round_add_int (x : α) (y : ℤ) : round (x + y) = round x + y := by rw [round, round, Int.fract_add_int, Int.floor_add_int, Int.ceil_add_int, ← apply_ite₂, ite_self] #align round_add_int round_add_int @[simp] theorem round_add_one (a : α) : round (a + 1) = round a + 1 := by -- Porting note: broken `convert round_add_int a 1` rw [← round_add_int a 1, cast_one] #align round_add_one round_add_one @[simp] theorem round_sub_int (x : α) (y : ℤ) : round (x - y) = round x - y := by rw [sub_eq_add_neg] norm_cast rw [round_add_int, sub_eq_add_neg] #align round_sub_int round_sub_int @[simp] theorem round_sub_one (a : α) : round (a - 1) = round a - 1 := by -- Porting note: broken `convert round_sub_int a 1` rw [← round_sub_int a 1, cast_one] #align round_sub_one round_sub_one @[simp] theorem round_add_nat (x : α) (y : ℕ) : round (x + y) = round x + y := mod_cast round_add_int x y #align round_add_nat round_add_nat -- See note [no_index around OfNat.ofNat] @[simp] theorem round_add_ofNat (x : α) (n : ℕ) [n.AtLeastTwo] : round (x + (no_index (OfNat.ofNat n))) = round x + OfNat.ofNat n := round_add_nat x n @[simp] theorem round_sub_nat (x : α) (y : ℕ) : round (x - y) = round x - y := mod_cast round_sub_int x y #align round_sub_nat round_sub_nat -- See note [no_index around OfNat.ofNat] @[simp] theorem round_sub_ofNat (x : α) (n : ℕ) [n.AtLeastTwo] : round (x - (no_index (OfNat.ofNat n))) = round x - OfNat.ofNat n := round_sub_nat x n @[simp] theorem round_int_add (x : α) (y : ℤ) : round ((y : α) + x) = y + round x := by rw [add_comm, round_add_int, add_comm] #align round_int_add round_int_add @[simp] theorem round_nat_add (x : α) (y : ℕ) : round ((y : α) + x) = y + round x := by rw [add_comm, round_add_nat, add_comm] #align round_nat_add round_nat_add -- See note [no_index around OfNat.ofNat] @[simp] theorem round_ofNat_add (n : ℕ) [n.AtLeastTwo] (x : α) : round ((no_index (OfNat.ofNat n)) + x) = OfNat.ofNat n + round x := round_nat_add x n theorem abs_sub_round_eq_min (x : α) : |x - round x| = min (fract x) (1 - fract x) := by simp_rw [round, min_def_lt, two_mul, ← lt_tsub_iff_left] cases' lt_or_ge (fract x) (1 - fract x) with hx hx · rw [if_pos hx, if_pos hx, self_sub_floor, abs_fract] · have : 0 < fract x := by replace hx : 0 < fract x + fract x := lt_of_lt_of_le zero_lt_one (tsub_le_iff_left.mp hx) simpa only [← two_mul, mul_pos_iff_of_pos_left, zero_lt_two] using hx rw [if_neg (not_lt.mpr hx), if_neg (not_lt.mpr hx), abs_sub_comm, ceil_sub_self_eq this.ne.symm, abs_one_sub_fract] #align abs_sub_round_eq_min abs_sub_round_eq_min
Mathlib/Algebra/Order/Floor.lean
1,546
1,556
theorem round_le (x : α) (z : ℤ) : |x - round x| ≤ |x - z| := by
rw [abs_sub_round_eq_min, min_le_iff] rcases le_or_lt (z : α) x with (hx | hx) <;> [left; right] · conv_rhs => rw [abs_eq_self.mpr (sub_nonneg.mpr hx), ← fract_add_floor x, add_sub_assoc] simpa only [le_add_iff_nonneg_right, sub_nonneg, cast_le] using le_floor.mpr hx · rw [abs_eq_neg_self.mpr (sub_neg.mpr hx).le] conv_rhs => rw [← fract_add_floor x] rw [add_sub_assoc, add_comm, neg_add, neg_sub, le_add_neg_iff_add_le, sub_add_cancel, le_sub_comm] norm_cast exact floor_le_sub_one_iff.mpr hx
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Antoine Chambert-Loir -/ import Mathlib.Algebra.Module.Defs import Mathlib.Algebra.Ring.Action.Basic import Mathlib.Algebra.Ring.Equiv import Mathlib.Algebra.Group.Hom.CompTypeclasses #align_import algebra.hom.group_action from "leanprover-community/mathlib"@"e7bab9a85e92cf46c02cb4725a7be2f04691e3a7" /-! # Equivariant homomorphisms ## Main definitions * `MulActionHom φ X Y`, the type of equivariant functions from `X` to `Y`, where `φ : M → N` is a map, `M` acting on the type `X` and `N` acting on the type of `Y`. * `DistribMulActionHom φ A B`, the type of equivariant additive monoid homomorphisms from `A` to `B`, where `φ : M → N` is a morphism of monoids, `M` acting on the additive monoid `A` and `N` acting on the additive monoid of `B` * `SMulSemiringHom φ R S`, the type of equivariant ring homomorphisms from `R` to `S`, where `φ : M → N` is a morphism of monoids, `M` acting on the ring `R` and `N` acting on the ring `S`. The above types have corresponding classes: * `MulActionHomClass F φ X Y` states that `F` is a type of bundled `X → Y` homs which are `φ`-equivariant * `DistribMulActionHomClass F φ A B` states that `F` is a type of bundled `A → B` homs preserving the additive monoid structure and `φ`-equivariant * `SMulSemiringHomClass F φ R S` states that `F` is a type of bundled `R → S` homs preserving the ring structure and `φ`-equivariant ## Notation We introduce the following notation to code equivariant maps (the subscript index `ₑ` is for *equivariant*) : * `X →ₑ[φ] Y` is `MulActionHom φ X Y`. * `A →ₑ+[φ] B` is `DistribMulActionHom φ A B`. * `R →ₑ+*[φ] S` is `MulSemiringActionHom φ R S`. When `M = N` and `φ = MonoidHom.id M`, we provide the backward compatible notation : * `X →[M] Y` is `MulActionHom (@id M) X Y` * `A →+[M] B` is `DistribMulActionHom (MonoidHom.id M) A B` * `R →+*[M] S` is `MulSemiringActionHom (MonoidHom.id M) R S` -/ assert_not_exists Submonoid section MulActionHom variable {M' : Type*} variable {M : Type*} {N : Type*} {P : Type*} variable (φ : M → N) (ψ : N → P) (χ : M → P) variable (X : Type*) [SMul M X] [SMul M' X] variable (Y : Type*) [SMul N Y] [SMul M' Y] variable (Z : Type*) [SMul P Z] /-- Equivariant functions : When `φ : M → N` is a function, and types `X` and `Y` are endowed with actions of `M` and `N`, a function `f : X → Y` is `φ`-equivariant if `f (m • x) = (φ m) • (f x)`. -/ -- Porting note(#5171): this linter isn't ported yet. -- @[nolint has_nonempty_instance] structure MulActionHom where /-- The underlying function. -/ protected toFun : X → Y /-- The proposition that the function commutes with the actions. -/ protected map_smul' : ∀ (m : M) (x : X), toFun (m • x) = (φ m) • toFun x /- Porting note: local notation given a name, conflict with Algebra.Hom.GroupAction see https://github.com/leanprover/lean4/issues/2000 -/ /-- `φ`-equivariant functions `X → Y`, where `φ : M → N`, where `M` and `N` act on `X` and `Y` respectively -/ notation:25 (name := «MulActionHomLocal≺») X " →ₑ[" φ:25 "] " Y:0 => MulActionHom φ X Y /-- `M`-equivariant functions `X → Y` with respect to the action of `M` This is the same as `X →ₑ[@id M] Y` -/ notation:25 (name := «MulActionHomIdLocal≺») X " →[" M:25 "] " Y:0 => MulActionHom (@id M) X Y /-- `MulActionSemiHomClass F φ X Y` states that `F` is a type of morphisms which are `φ`-equivariant. You should extend this class when you extend `MulActionHom`. -/ class MulActionSemiHomClass (F : Type*) {M N : outParam Type*} (φ : outParam (M → N)) (X Y : outParam Type*) [SMul M X] [SMul N Y] [FunLike F X Y] : Prop where /-- The proposition that the function preserves the action. -/ map_smulₛₗ : ∀ (f : F) (c : M) (x : X), f (c • x) = (φ c) • (f x) #align smul_hom_class MulActionSemiHomClass export MulActionSemiHomClass (map_smulₛₗ) /-- `MulActionHomClass F M X Y` states that `F` is a type of morphisms which are equivariant with respect to actions of `M` This is an abbreviation of `MulActionSemiHomClass`. -/ abbrev MulActionHomClass (F : Type*) (M : outParam Type*) (X Y : outParam Type*) [SMul M X] [SMul M Y] [FunLike F X Y] := MulActionSemiHomClass F (@id M) X Y instance : FunLike (MulActionHom φ X Y) X Y where coe := MulActionHom.toFun coe_injective' f g h := by cases f; cases g; congr @[simp] theorem map_smul {F M X Y : Type*} [SMul M X] [SMul M Y] [FunLike F X Y] [MulActionHomClass F M X Y] (f : F) (c : M) (x : X) : f (c • x) = c • f x := map_smulₛₗ f c x -- attribute [simp] map_smulₛₗ -- Porting note: removed has_coe_to_fun instance, coercions handled differently now #noalign mul_action_hom.has_coe_to_fun instance : MulActionSemiHomClass (X →ₑ[φ] Y) φ X Y where map_smulₛₗ := MulActionHom.map_smul' initialize_simps_projections MulActionHom (toFun → apply) namespace MulActionHom variable {φ X Y} variable {F : Type*} [FunLike F X Y] /- porting note: inserted following def & instance for consistent coercion behaviour, see also Algebra.Hom.Group -/ /-- Turn an element of a type `F` satisfying `MulActionSemiHomClass F φ X Y` into an actual `MulActionHom`. This is declared as the default coercion from `F` to `MulActionSemiHom φ X Y`. -/ @[coe] def _root_.MulActionSemiHomClass.toMulActionHom [MulActionSemiHomClass F φ X Y] (f : F) : X →ₑ[φ] Y where toFun := DFunLike.coe f map_smul' := map_smulₛₗ f /-- Any type satisfying `MulActionSemiHomClass` can be cast into `MulActionHom` via `MulActionHomSemiClass.toMulActionHom`. -/ instance [MulActionSemiHomClass F φ X Y] : CoeTC F (X →ₑ[φ] Y) := ⟨MulActionSemiHomClass.toMulActionHom⟩ variable (M' X Y F) in /-- If Y/X/M forms a scalar tower, any map X → Y preserving X-action also preserves M-action. -/ theorem _root_.IsScalarTower.smulHomClass [MulOneClass X] [SMul X Y] [IsScalarTower M' X Y] [MulActionHomClass F X X Y] : MulActionHomClass F M' X Y where map_smulₛₗ f m x := by rw [← mul_one (m • x), ← smul_eq_mul, map_smul, smul_assoc, ← map_smul, smul_eq_mul, mul_one, id_eq] protected theorem map_smul (f : X →[M'] Y) (m : M') (x : X) : f (m • x) = m • f x := map_smul f m x #align mul_action_hom.map_smul MulActionHom.map_smul @[ext] theorem ext {f g : X →ₑ[φ] Y} : (∀ x, f x = g x) → f = g := DFunLike.ext f g #align mul_action_hom.ext MulActionHom.ext theorem ext_iff {f g : X →ₑ[φ] Y} : f = g ↔ ∀ x, f x = g x := DFunLike.ext_iff #align mul_action_hom.ext_iff MulActionHom.ext_iff protected theorem congr_fun {f g : X →ₑ[φ] Y} (h : f = g) (x : X) : f x = g x := DFunLike.congr_fun h _ #align mul_action_hom.congr_fun MulActionHom.congr_fun /-- Two equal maps on scalars give rise to an equivariant map for identity -/ def ofEq {φ' : M → N} (h : φ = φ') (f : X →ₑ[φ] Y) : X →ₑ[φ'] Y where toFun := f.toFun map_smul' m a := h ▸ f.map_smul' m a #align equivariant_map.of_eq MulActionHom.ofEq @[simp] theorem ofEq_coe {φ' : M → N} (h : φ = φ') (f : X →ₑ[φ] Y) : (f.ofEq h).toFun = f.toFun := rfl #align equivariant_map.of_eq_coe MulActionHom.ofEq_coe @[simp] theorem ofEq_apply {φ' : M → N} (h : φ = φ') (f : X →ₑ[φ] Y) (a : X) : (f.ofEq h) a = f a := rfl #align equivariant_map.of_eq_apply MulActionHom.ofEq_apply variable {ψ χ} (M N) /-- The identity map as an equivariant map. -/ protected def id : X →[M] X := ⟨id, fun _ _ => rfl⟩ #align mul_action_hom.id MulActionHom.id variable {M N Z} @[simp] theorem id_apply (x : X) : MulActionHom.id M x = x := rfl #align mul_action_hom.id_apply MulActionHom.id_apply end MulActionHom namespace MulActionHom open MulActionHom variable {φ ψ χ X Y Z} -- attribute [instance] CompTriple.id_comp CompTriple.comp_id /-- Composition of two equivariant maps. -/ def comp (g : Y →ₑ[ψ] Z) (f : X →ₑ[φ] Y) [κ : CompTriple φ ψ χ] : X →ₑ[χ] Z := ⟨g ∘ f, fun m x => calc g (f (m • x)) = g (φ m • f x) := by rw [map_smulₛₗ] _ = ψ (φ m) • g (f x) := by rw [map_smulₛₗ] _ = (ψ ∘ φ) m • g (f x) := rfl _ = χ m • g (f x) := by rw [κ.comp_eq] ⟩ #align mul_action_hom.comp MulActionHom.comp @[simp] theorem comp_apply (g : Y →ₑ[ψ] Z) (f : X →ₑ[φ] Y) [CompTriple φ ψ χ] (x : X) : g.comp f x = g (f x) := rfl #align mul_action_hom.comp_apply MulActionHom.comp_apply @[simp] theorem id_comp (f : X →ₑ[φ] Y) : (MulActionHom.id N).comp f = f := ext fun x => by rw [comp_apply, id_apply] #align mul_action_hom.id_comp MulActionHom.id_comp @[simp] theorem comp_id (f : X →ₑ[φ] Y) : f.comp (MulActionHom.id M) = f := ext fun x => by rw [comp_apply, id_apply] #align mul_action_hom.comp_id MulActionHom.comp_id @[simp] theorem comp_assoc {Q T : Type*} [SMul Q T] {η : P → Q} {θ : M → Q} {ζ : N → Q} (h : Z →ₑ[η] T) (g : Y →ₑ[ψ] Z) (f : X →ₑ[φ] Y) [CompTriple φ ψ χ] [CompTriple χ η θ] [CompTriple ψ η ζ] [CompTriple φ ζ θ] : h.comp (g.comp f) = (h.comp g).comp f := ext fun _ => rfl #align equivariant_map.comp_assoc MulActionHom.comp_assoc variable {φ' : N → M} variable {Y₁ : Type*} [SMul M Y₁] /-- The inverse of a bijective equivariant map is equivariant. -/ @[simps] def inverse (f : X →[M] Y₁) (g : Y₁ → X) (h₁ : Function.LeftInverse g f) (h₂ : Function.RightInverse g f) : Y₁ →[M] X where toFun := g map_smul' m x := calc g (m • x) = g (m • f (g x)) := by rw [h₂] _ = g (f (m • g x)) := by simp only [map_smul, id_eq] _ = m • g x := by rw [h₁] /-- The inverse of a bijective equivariant map is equivariant. -/ @[simps] def inverse' (f : X →ₑ[φ] Y) (g : Y → X) (k : Function.RightInverse φ' φ) (h₁ : Function.LeftInverse g f) (h₂ : Function.RightInverse g f) : Y →ₑ[φ'] X where toFun := g map_smul' m x := calc g (m • x) = g (m • f (g x)) := by rw [h₂] _ = g ((φ (φ' m)) • f (g x)) := by rw [k] _ = g (f (φ' m • g x)) := by rw [map_smulₛₗ] _ = φ' m • g x := by rw [h₁] #align mul_action_hom.inverse MulActionHom.inverse' lemma inverse_eq_inverse' (f : X →[M] Y₁) (g : Y₁ → X) (h₁ : Function.LeftInverse g f) (h₂ : Function.RightInverse g f) : inverse f g h₁ h₂ = inverse' f g (congrFun rfl) h₁ h₂ := by rfl theorem inverse'_inverse' {f : X →ₑ[φ] Y} {g : Y → X} {k₁ : Function.LeftInverse φ' φ} {k₂ : Function.RightInverse φ' φ} {h₁ : Function.LeftInverse g f} {h₂ : Function.RightInverse g f} : inverse' (inverse' f g k₂ h₁ h₂) f k₁ h₂ h₁ = f := ext fun _ => rfl theorem comp_inverse' {f : X →ₑ[φ] Y } {g : Y → X} {k₁ : Function.LeftInverse φ' φ} {k₂ : Function.RightInverse φ' φ} {h₁ : Function.LeftInverse g f} {h₂ : Function.RightInverse g f} : (inverse' f g k₂ h₁ h₂).comp f (κ := CompTriple.comp_inv k₁) = MulActionHom.id M := by rw [ext_iff] intro x simp only [comp_apply, inverse_apply, id_apply] exact h₁ x theorem inverse'_comp {f : X →ₑ[φ] Y } {g : Y → X} {k₂ : Function.RightInverse φ' φ} {h₁ : Function.LeftInverse g f} {h₂ : Function.RightInverse g f} : f.comp (inverse' f g k₂ h₁ h₂) (κ := CompTriple.comp_inv k₂) = MulActionHom.id N := by rw [ext_iff] intro x simp only [comp_apply, inverse_apply, id_apply] exact h₂ x /-- If actions of `M` and `N` on `α` commute, then for `c : M`, `(c • · : α → α)` is an `N`-action homomorphism. -/ @[simps] def _root_.SMulCommClass.toMulActionHom {M} (N α : Type*) [SMul M α] [SMul N α] [SMulCommClass M N α] (c : M) : α →[N] α where toFun := (c • ·) map_smul' := smul_comm _ end MulActionHom end MulActionHom section DistribMulAction variable {M : Type*} [Monoid M] variable {N : Type*} [Monoid N] variable {P : Type*} [Monoid P] variable (φ: M →* N) (φ' : N →* M) (ψ : N →* P) (χ : M →* P) variable (A : Type*) [AddMonoid A] [DistribMulAction M A] variable (B : Type*) [AddMonoid B] [DistribMulAction N B] variable (B₁ : Type*) [AddMonoid B₁] [DistribMulAction M B₁] variable (C : Type*) [AddMonoid C] [DistribMulAction P C] variable (A' : Type*) [AddGroup A'] [DistribMulAction M A'] variable (B' : Type*) [AddGroup B'] [DistribMulAction N B'] /-- Equivariant additive monoid homomorphisms. -/ structure DistribMulActionHom extends A →ₑ[φ] B, A →+ B #align distrib_mul_action_hom DistribMulActionHom /-- Reinterpret an equivariant additive monoid homomorphism as an additive monoid homomorphism. -/ add_decl_doc DistribMulActionHom.toAddMonoidHom #align distrib_mul_action_hom.to_add_monoid_hom DistribMulActionHom.toAddMonoidHom /-- Reinterpret an equivariant additive monoid homomorphism as an equivariant function. -/ add_decl_doc DistribMulActionHom.toMulActionHom #align distrib_mul_action_hom.to_mul_action_hom DistribMulActionHom.toMulActionHom /- Porting note: local notation given a name, conflict with Algebra.Hom.Freiman see https://github.com/leanprover/lean4/issues/2000 -/ @[inherit_doc] notation:25 (name := «DistribMulActionHomLocal≺») A " →ₑ+[" φ:25 "] " B:0 => DistribMulActionHom φ A B @[inherit_doc] notation:25 (name := «DistribMulActionHomIdLocal≺») A " →+[" M:25 "] " B:0 => DistribMulActionHom (MonoidHom.id M) A B -- QUESTION/TODO : Impose that `φ` is a morphism of monoids? /-- `DistribMulActionSemiHomClass F φ A B` states that `F` is a type of morphisms preserving the additive monoid structure and equivariant with respect to `φ`. You should extend this class when you extend `DistribMulActionSemiHom`. -/ class DistribMulActionSemiHomClass (F : Type*) {M N : outParam Type*} (φ : outParam (M → N)) (A B : outParam Type*) [Monoid M] [Monoid N] [AddMonoid A] [AddMonoid B] [DistribMulAction M A] [DistribMulAction N B] [FunLike F A B] extends MulActionSemiHomClass F φ A B, AddMonoidHomClass F A B : Prop #align distrib_mul_action_hom_class DistribMulActionSemiHomClass /-- `DistribMulActionHomClass F M A B` states that `F` is a type of morphisms preserving the additive monoid structure and equivariant with respect to the action of `M`. It is an abbreviation to `DistribMulActionHomClass F (MonoidHom.id M) A B` You should extend this class when you extend `DistribMulActionHom`. -/ abbrev DistribMulActionHomClass (F : Type*) (M : outParam Type*) (A B : outParam Type*) [Monoid M] [AddMonoid A] [AddMonoid B] [DistribMulAction M A] [DistribMulAction M B] [FunLike F A B] := DistribMulActionSemiHomClass F (MonoidHom.id M) A B /- porting note: Removed a @[nolint dangerousInstance] for DistribMulActionHomClass.toAddMonoidHomClass not dangerous due to `outParam`s -/ namespace DistribMulActionHom /- Porting note (#11215): TODO decide whether the next two instances should be removed Coercion is already handled by all the HomClass constructions I believe -/ -- instance coe : Coe (A →+[M] B) (A →+ B) := -- ⟨toAddMonoidHom⟩ -- #align distrib_mul_action_hom.has_coe DistribMulActionHom.coe -- instance coe' : Coe (A →+[M] B) (A →[M] B) := -- ⟨toMulActionHom⟩ -- #align distrib_mul_action_hom.has_coe' DistribMulActionHom.coe' #noalign distrib_mul_action_hom.has_coe #noalign distrib_mul_action_hom.has_coe' #noalign distrib_mul_action_hom.has_coe_to_fun instance : FunLike (A →ₑ+[φ] B) A B where coe m := m.toFun coe_injective' f g h := by rcases f with ⟨tF, _, _⟩; rcases g with ⟨tG, _, _⟩ cases tF; cases tG; congr instance : DistribMulActionSemiHomClass (A →ₑ+[φ] B) φ A B where map_smulₛₗ m := m.map_smul' map_zero := DistribMulActionHom.map_zero' map_add := DistribMulActionHom.map_add' variable {φ φ' A B B₁} variable {F : Type*} [FunLike F A B] /- porting note: inserted following def & instance for consistent coercion behaviour, see also Algebra.Hom.Group -/ /-- Turn an element of a type `F` satisfying `MulActionHomClass F M X Y` into an actual `MulActionHom`. This is declared as the default coercion from `F` to `MulActionHom M X Y`. -/ @[coe] def _root_.DistribMulActionSemiHomClass.toDistribMulActionHom [DistribMulActionSemiHomClass F φ A B] (f : F) : A →ₑ+[φ] B := { (f : A →+ B), (f : A →ₑ[φ] B) with } /-- Any type satisfying `MulActionHomClass` can be cast into `MulActionHom` via `MulActionHomClass.toMulActionHom`. -/ instance [DistribMulActionSemiHomClass F φ A B] : CoeTC F (A →ₑ+[φ] B) := ⟨DistribMulActionSemiHomClass.toDistribMulActionHom⟩ /-- If `DistribMulAction` of `M` and `N` on `A` commute, then for each `c : M`, `(c • ·)` is an `N`-action additive homomorphism. -/ @[simps] def _root_.SMulCommClass.toDistribMulActionHom {M} (N A : Type*) [Monoid N] [AddMonoid A] [DistribSMul M A] [DistribMulAction N A] [SMulCommClass M N A] (c : M) : A →+[N] A := { SMulCommClass.toMulActionHom N A c, DistribSMul.toAddMonoidHom _ c with toFun := (c • ·) } @[simp] theorem toFun_eq_coe (f : A →ₑ+[φ] B) : f.toFun = f := rfl #align distrib_mul_action_hom.to_fun_eq_coe DistribMulActionHom.toFun_eq_coe @[norm_cast] theorem coe_fn_coe (f : A →ₑ+[φ] B) : ⇑(f : A →+ B) = f := rfl #align distrib_mul_action_hom.coe_fn_coe DistribMulActionHom.coe_fn_coe @[norm_cast] theorem coe_fn_coe' (f : A →ₑ+[φ] B) : ⇑(f : A →ₑ[φ] B) = f := rfl #align distrib_mul_action_hom.coe_fn_coe' DistribMulActionHom.coe_fn_coe' @[ext] theorem ext {f g : A →ₑ+[φ] B} : (∀ x, f x = g x) → f = g := DFunLike.ext f g #align distrib_mul_action_hom.ext DistribMulActionHom.ext theorem ext_iff {f g : A →ₑ+[φ] B} : f = g ↔ ∀ x, f x = g x := DFunLike.ext_iff #align distrib_mul_action_hom.ext_iff DistribMulActionHom.ext_iff protected theorem congr_fun {f g : A →ₑ+[φ] B} (h : f = g) (x : A) : f x = g x := DFunLike.congr_fun h _ #align distrib_mul_action_hom.congr_fun DistribMulActionHom.congr_fun
Mathlib/GroupTheory/GroupAction/Hom.lean
473
476
theorem toMulActionHom_injective {f g : A →ₑ+[φ] B} (h : (f : A →ₑ[φ] B) = (g : A →ₑ[φ] B)) : f = g := by
ext a exact MulActionHom.congr_fun h a
/- 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.Algebra.BigOperators.Option import Mathlib.Analysis.BoxIntegral.Box.Basic import Mathlib.Data.Set.Pairwise.Lattice #align_import analysis.box_integral.partition.basic from "leanprover-community/mathlib"@"84dc0bd6619acaea625086d6f53cb35cdd554219" /-! # Partitions of rectangular boxes in `ℝⁿ` In this file we define (pre)partitions of rectangular boxes in `ℝⁿ`. A partition of a box `I` in `ℝⁿ` (see `BoxIntegral.Prepartition` and `BoxIntegral.Prepartition.IsPartition`) is a finite set of pairwise disjoint boxes such that their union is exactly `I`. We use `boxes : Finset (Box ι)` to store the set of boxes. Many lemmas about box integrals deal with pairwise disjoint collections of subboxes, so we define a structure `BoxIntegral.Prepartition (I : BoxIntegral.Box ι)` that stores a collection of boxes such that * each box `J ∈ boxes` is a subbox of `I`; * the boxes are pairwise disjoint as sets in `ℝⁿ`. Then we define a predicate `BoxIntegral.Prepartition.IsPartition`; `π.IsPartition` means that the boxes of `π` actually cover the whole `I`. We also define some operations on prepartitions: * `BoxIntegral.Prepartition.biUnion`: split each box of a partition into smaller boxes; * `BoxIntegral.Prepartition.restrict`: restrict a partition to a smaller box. We also define a `SemilatticeInf` structure on `BoxIntegral.Prepartition I` for all `I : BoxIntegral.Box ι`. ## Tags rectangular box, partition -/ open Set Finset Function open scoped Classical open NNReal noncomputable section namespace BoxIntegral variable {ι : Type*} /-- A prepartition of `I : BoxIntegral.Box ι` is a finite set of pairwise disjoint subboxes of `I`. -/ structure Prepartition (I : Box ι) where /-- The underlying set of boxes -/ boxes : Finset (Box ι) /-- Each box is a sub-box of `I` -/ le_of_mem' : ∀ J ∈ boxes, J ≤ I /-- The boxes in a prepartition are pairwise disjoint. -/ pairwiseDisjoint : Set.Pairwise (↑boxes) (Disjoint on ((↑) : Box ι → Set (ι → ℝ))) #align box_integral.prepartition BoxIntegral.Prepartition namespace Prepartition variable {I J J₁ J₂ : Box ι} (π : Prepartition I) {π₁ π₂ : Prepartition I} {x : ι → ℝ} instance : Membership (Box ι) (Prepartition I) := ⟨fun J π => J ∈ π.boxes⟩ @[simp] theorem mem_boxes : J ∈ π.boxes ↔ J ∈ π := Iff.rfl #align box_integral.prepartition.mem_boxes BoxIntegral.Prepartition.mem_boxes @[simp] theorem mem_mk {s h₁ h₂} : J ∈ (mk s h₁ h₂ : Prepartition I) ↔ J ∈ s := Iff.rfl #align box_integral.prepartition.mem_mk BoxIntegral.Prepartition.mem_mk theorem disjoint_coe_of_mem (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (h : J₁ ≠ J₂) : Disjoint (J₁ : Set (ι → ℝ)) J₂ := π.pairwiseDisjoint h₁ h₂ h #align box_integral.prepartition.disjoint_coe_of_mem BoxIntegral.Prepartition.disjoint_coe_of_mem theorem eq_of_mem_of_mem (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (hx₁ : x ∈ J₁) (hx₂ : x ∈ J₂) : J₁ = J₂ := by_contra fun H => (π.disjoint_coe_of_mem h₁ h₂ H).le_bot ⟨hx₁, hx₂⟩ #align box_integral.prepartition.eq_of_mem_of_mem BoxIntegral.Prepartition.eq_of_mem_of_mem theorem eq_of_le_of_le (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (hle₁ : J ≤ J₁) (hle₂ : J ≤ J₂) : J₁ = J₂ := π.eq_of_mem_of_mem h₁ h₂ (hle₁ J.upper_mem) (hle₂ J.upper_mem) #align box_integral.prepartition.eq_of_le_of_le BoxIntegral.Prepartition.eq_of_le_of_le theorem eq_of_le (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (hle : J₁ ≤ J₂) : J₁ = J₂ := π.eq_of_le_of_le h₁ h₂ le_rfl hle #align box_integral.prepartition.eq_of_le BoxIntegral.Prepartition.eq_of_le theorem le_of_mem (hJ : J ∈ π) : J ≤ I := π.le_of_mem' J hJ #align box_integral.prepartition.le_of_mem BoxIntegral.Prepartition.le_of_mem theorem lower_le_lower (hJ : J ∈ π) : I.lower ≤ J.lower := Box.antitone_lower (π.le_of_mem hJ) #align box_integral.prepartition.lower_le_lower BoxIntegral.Prepartition.lower_le_lower theorem upper_le_upper (hJ : J ∈ π) : J.upper ≤ I.upper := Box.monotone_upper (π.le_of_mem hJ) #align box_integral.prepartition.upper_le_upper BoxIntegral.Prepartition.upper_le_upper theorem injective_boxes : Function.Injective (boxes : Prepartition I → Finset (Box ι)) := by rintro ⟨s₁, h₁, h₁'⟩ ⟨s₂, h₂, h₂'⟩ (rfl : s₁ = s₂) rfl #align box_integral.prepartition.injective_boxes BoxIntegral.Prepartition.injective_boxes @[ext] theorem ext (h : ∀ J, J ∈ π₁ ↔ J ∈ π₂) : π₁ = π₂ := injective_boxes <| Finset.ext h #align box_integral.prepartition.ext BoxIntegral.Prepartition.ext /-- The singleton prepartition `{J}`, `J ≤ I`. -/ @[simps] def single (I J : Box ι) (h : J ≤ I) : Prepartition I := ⟨{J}, by simpa, by simp⟩ #align box_integral.prepartition.single BoxIntegral.Prepartition.single @[simp] theorem mem_single {J'} (h : J ≤ I) : J' ∈ single I J h ↔ J' = J := mem_singleton #align box_integral.prepartition.mem_single BoxIntegral.Prepartition.mem_single /-- We say that `π ≤ π'` if each box of `π` is a subbox of some box of `π'`. -/ instance : LE (Prepartition I) := ⟨fun π π' => ∀ ⦃I⦄, I ∈ π → ∃ I' ∈ π', I ≤ I'⟩ instance partialOrder : PartialOrder (Prepartition I) where le := (· ≤ ·) le_refl π I hI := ⟨I, hI, le_rfl⟩ le_trans π₁ π₂ π₃ h₁₂ h₂₃ I₁ hI₁ := let ⟨I₂, hI₂, hI₁₂⟩ := h₁₂ hI₁ let ⟨I₃, hI₃, hI₂₃⟩ := h₂₃ hI₂ ⟨I₃, hI₃, hI₁₂.trans hI₂₃⟩ le_antisymm := by suffices ∀ {π₁ π₂ : Prepartition I}, π₁ ≤ π₂ → π₂ ≤ π₁ → π₁.boxes ⊆ π₂.boxes from fun π₁ π₂ h₁ h₂ => injective_boxes (Subset.antisymm (this h₁ h₂) (this h₂ h₁)) intro π₁ π₂ h₁ h₂ J hJ rcases h₁ hJ with ⟨J', hJ', hle⟩; rcases h₂ hJ' with ⟨J'', hJ'', hle'⟩ obtain rfl : J = J'' := π₁.eq_of_le hJ hJ'' (hle.trans hle') obtain rfl : J' = J := le_antisymm ‹_› ‹_› assumption instance : OrderTop (Prepartition I) where top := single I I le_rfl le_top π J hJ := ⟨I, by simp, π.le_of_mem hJ⟩ instance : OrderBot (Prepartition I) where bot := ⟨∅, fun _ hJ => (Finset.not_mem_empty _ hJ).elim, fun _ hJ => (Set.not_mem_empty _ <| Finset.coe_empty ▸ hJ).elim⟩ bot_le _ _ hJ := (Finset.not_mem_empty _ hJ).elim instance : Inhabited (Prepartition I) := ⟨⊤⟩ theorem le_def : π₁ ≤ π₂ ↔ ∀ J ∈ π₁, ∃ J' ∈ π₂, J ≤ J' := Iff.rfl #align box_integral.prepartition.le_def BoxIntegral.Prepartition.le_def @[simp] theorem mem_top : J ∈ (⊤ : Prepartition I) ↔ J = I := mem_singleton #align box_integral.prepartition.mem_top BoxIntegral.Prepartition.mem_top @[simp] theorem top_boxes : (⊤ : Prepartition I).boxes = {I} := rfl #align box_integral.prepartition.top_boxes BoxIntegral.Prepartition.top_boxes @[simp] theorem not_mem_bot : J ∉ (⊥ : Prepartition I) := Finset.not_mem_empty _ #align box_integral.prepartition.not_mem_bot BoxIntegral.Prepartition.not_mem_bot @[simp] theorem bot_boxes : (⊥ : Prepartition I).boxes = ∅ := rfl #align box_integral.prepartition.bot_boxes BoxIntegral.Prepartition.bot_boxes /-- An auxiliary lemma used to prove that the same point can't belong to more than `2 ^ Fintype.card ι` closed boxes of a prepartition. -/ theorem injOn_setOf_mem_Icc_setOf_lower_eq (x : ι → ℝ) : InjOn (fun J : Box ι => { i | J.lower i = x i }) { J | J ∈ π ∧ x ∈ Box.Icc J } := by rintro J₁ ⟨h₁, hx₁⟩ J₂ ⟨h₂, hx₂⟩ (H : { i | J₁.lower i = x i } = { i | J₂.lower i = x i }) suffices ∀ i, (Ioc (J₁.lower i) (J₁.upper i) ∩ Ioc (J₂.lower i) (J₂.upper i)).Nonempty by choose y hy₁ hy₂ using this exact π.eq_of_mem_of_mem h₁ h₂ hy₁ hy₂ intro i simp only [Set.ext_iff, mem_setOf] at H rcases (hx₁.1 i).eq_or_lt with hi₁ | hi₁ · have hi₂ : J₂.lower i = x i := (H _).1 hi₁ have H₁ : x i < J₁.upper i := by simpa only [hi₁] using J₁.lower_lt_upper i have H₂ : x i < J₂.upper i := by simpa only [hi₂] using J₂.lower_lt_upper i rw [Ioc_inter_Ioc, hi₁, hi₂, sup_idem, Set.nonempty_Ioc] exact lt_min H₁ H₂ · have hi₂ : J₂.lower i < x i := (hx₂.1 i).lt_of_ne (mt (H _).2 hi₁.ne) exact ⟨x i, ⟨hi₁, hx₁.2 i⟩, ⟨hi₂, hx₂.2 i⟩⟩ #align box_integral.prepartition.inj_on_set_of_mem_Icc_set_of_lower_eq BoxIntegral.Prepartition.injOn_setOf_mem_Icc_setOf_lower_eq /-- The set of boxes of a prepartition that contain `x` in their closures has cardinality at most `2 ^ Fintype.card ι`. -/ theorem card_filter_mem_Icc_le [Fintype ι] (x : ι → ℝ) : (π.boxes.filter fun J : Box ι => x ∈ Box.Icc J).card ≤ 2 ^ Fintype.card ι := by rw [← Fintype.card_set] refine Finset.card_le_card_of_inj_on (fun J : Box ι => { i | J.lower i = x i }) (fun _ _ => Finset.mem_univ _) ?_ simpa only [Finset.mem_filter] using π.injOn_setOf_mem_Icc_setOf_lower_eq x #align box_integral.prepartition.card_filter_mem_Icc_le BoxIntegral.Prepartition.card_filter_mem_Icc_le /-- Given a prepartition `π : BoxIntegral.Prepartition I`, `π.iUnion` is the part of `I` covered by the boxes of `π`. -/ protected def iUnion : Set (ι → ℝ) := ⋃ J ∈ π, ↑J #align box_integral.prepartition.Union BoxIntegral.Prepartition.iUnion theorem iUnion_def : π.iUnion = ⋃ J ∈ π, ↑J := rfl #align box_integral.prepartition.Union_def BoxIntegral.Prepartition.iUnion_def theorem iUnion_def' : π.iUnion = ⋃ J ∈ π.boxes, ↑J := rfl #align box_integral.prepartition.Union_def' BoxIntegral.Prepartition.iUnion_def' -- Porting note: Previous proof was `:= Set.mem_iUnion₂` @[simp] theorem mem_iUnion : x ∈ π.iUnion ↔ ∃ J ∈ π, x ∈ J := by convert Set.mem_iUnion₂ rw [Box.mem_coe, exists_prop] #align box_integral.prepartition.mem_Union BoxIntegral.Prepartition.mem_iUnion @[simp] theorem iUnion_single (h : J ≤ I) : (single I J h).iUnion = J := by simp [iUnion_def] #align box_integral.prepartition.Union_single BoxIntegral.Prepartition.iUnion_single @[simp] theorem iUnion_top : (⊤ : Prepartition I).iUnion = I := by simp [Prepartition.iUnion] #align box_integral.prepartition.Union_top BoxIntegral.Prepartition.iUnion_top @[simp] theorem iUnion_eq_empty : π₁.iUnion = ∅ ↔ π₁ = ⊥ := by simp [← injective_boxes.eq_iff, Finset.ext_iff, Prepartition.iUnion, imp_false] #align box_integral.prepartition.Union_eq_empty BoxIntegral.Prepartition.iUnion_eq_empty @[simp] theorem iUnion_bot : (⊥ : Prepartition I).iUnion = ∅ := iUnion_eq_empty.2 rfl #align box_integral.prepartition.Union_bot BoxIntegral.Prepartition.iUnion_bot theorem subset_iUnion (h : J ∈ π) : ↑J ⊆ π.iUnion := subset_biUnion_of_mem h #align box_integral.prepartition.subset_Union BoxIntegral.Prepartition.subset_iUnion theorem iUnion_subset : π.iUnion ⊆ I := iUnion₂_subset π.le_of_mem' #align box_integral.prepartition.Union_subset BoxIntegral.Prepartition.iUnion_subset @[mono] theorem iUnion_mono (h : π₁ ≤ π₂) : π₁.iUnion ⊆ π₂.iUnion := fun _ hx => let ⟨_, hJ₁, hx⟩ := π₁.mem_iUnion.1 hx let ⟨J₂, hJ₂, hle⟩ := h hJ₁ π₂.mem_iUnion.2 ⟨J₂, hJ₂, hle hx⟩ #align box_integral.prepartition.Union_mono BoxIntegral.Prepartition.iUnion_mono theorem disjoint_boxes_of_disjoint_iUnion (h : Disjoint π₁.iUnion π₂.iUnion) : Disjoint π₁.boxes π₂.boxes := Finset.disjoint_left.2 fun J h₁ h₂ => Disjoint.le_bot (h.mono (π₁.subset_iUnion h₁) (π₂.subset_iUnion h₂)) ⟨J.upper_mem, J.upper_mem⟩ #align box_integral.prepartition.disjoint_boxes_of_disjoint_Union BoxIntegral.Prepartition.disjoint_boxes_of_disjoint_iUnion theorem le_iff_nonempty_imp_le_and_iUnion_subset : π₁ ≤ π₂ ↔ (∀ J ∈ π₁, ∀ J' ∈ π₂, (J ∩ J' : Set (ι → ℝ)).Nonempty → J ≤ J') ∧ π₁.iUnion ⊆ π₂.iUnion := by constructor · refine fun H => ⟨fun J hJ J' hJ' Hne => ?_, iUnion_mono H⟩ rcases H hJ with ⟨J'', hJ'', Hle⟩ rcases Hne with ⟨x, hx, hx'⟩ rwa [π₂.eq_of_mem_of_mem hJ' hJ'' hx' (Hle hx)] · rintro ⟨H, HU⟩ J hJ simp only [Set.subset_def, mem_iUnion] at HU rcases HU J.upper ⟨J, hJ, J.upper_mem⟩ with ⟨J₂, hJ₂, hx⟩ exact ⟨J₂, hJ₂, H _ hJ _ hJ₂ ⟨_, J.upper_mem, hx⟩⟩ #align box_integral.prepartition.le_iff_nonempty_imp_le_and_Union_subset BoxIntegral.Prepartition.le_iff_nonempty_imp_le_and_iUnion_subset theorem eq_of_boxes_subset_iUnion_superset (h₁ : π₁.boxes ⊆ π₂.boxes) (h₂ : π₂.iUnion ⊆ π₁.iUnion) : π₁ = π₂ := le_antisymm (fun J hJ => ⟨J, h₁ hJ, le_rfl⟩) <| le_iff_nonempty_imp_le_and_iUnion_subset.2 ⟨fun _ hJ₁ _ hJ₂ Hne => (π₂.eq_of_mem_of_mem hJ₁ (h₁ hJ₂) Hne.choose_spec.1 Hne.choose_spec.2).le, h₂⟩ #align box_integral.prepartition.eq_of_boxes_subset_Union_superset BoxIntegral.Prepartition.eq_of_boxes_subset_iUnion_superset /-- Given a prepartition `π` of a box `I` and a collection of prepartitions `πi J` of all boxes `J ∈ π`, returns the prepartition of `I` into the union of the boxes of all `πi J`. Though we only use the values of `πi` on the boxes of `π`, we require `πi` to be a globally defined function. -/ @[simps] def biUnion (πi : ∀ J : Box ι, Prepartition J) : Prepartition I where boxes := π.boxes.biUnion fun J => (πi J).boxes le_of_mem' J hJ := by simp only [Finset.mem_biUnion, exists_prop, mem_boxes] at hJ rcases hJ with ⟨J', hJ', hJ⟩ exact ((πi J').le_of_mem hJ).trans (π.le_of_mem hJ') pairwiseDisjoint := by simp only [Set.Pairwise, Finset.mem_coe, Finset.mem_biUnion] rintro J₁' ⟨J₁, hJ₁, hJ₁'⟩ J₂' ⟨J₂, hJ₂, hJ₂'⟩ Hne rw [Function.onFun, Set.disjoint_left] rintro x hx₁ hx₂; apply Hne obtain rfl : J₁ = J₂ := π.eq_of_mem_of_mem hJ₁ hJ₂ ((πi J₁).le_of_mem hJ₁' hx₁) ((πi J₂).le_of_mem hJ₂' hx₂) exact (πi J₁).eq_of_mem_of_mem hJ₁' hJ₂' hx₁ hx₂ #align box_integral.prepartition.bUnion BoxIntegral.Prepartition.biUnion variable {πi πi₁ πi₂ : ∀ J : Box ι, Prepartition J} @[simp] theorem mem_biUnion : J ∈ π.biUnion πi ↔ ∃ J' ∈ π, J ∈ πi J' := by simp [biUnion] #align box_integral.prepartition.mem_bUnion BoxIntegral.Prepartition.mem_biUnion theorem biUnion_le (πi : ∀ J, Prepartition J) : π.biUnion πi ≤ π := fun _ hJ => let ⟨J', hJ', hJ⟩ := π.mem_biUnion.1 hJ ⟨J', hJ', (πi J').le_of_mem hJ⟩ #align box_integral.prepartition.bUnion_le BoxIntegral.Prepartition.biUnion_le @[simp] theorem biUnion_top : (π.biUnion fun _ => ⊤) = π := by ext simp #align box_integral.prepartition.bUnion_top BoxIntegral.Prepartition.biUnion_top @[congr] theorem biUnion_congr (h : π₁ = π₂) (hi : ∀ J ∈ π₁, πi₁ J = πi₂ J) : π₁.biUnion πi₁ = π₂.biUnion πi₂ := by subst π₂ ext J simp only [mem_biUnion] constructor <;> exact fun ⟨J', h₁, h₂⟩ => ⟨J', h₁, hi J' h₁ ▸ h₂⟩ #align box_integral.prepartition.bUnion_congr BoxIntegral.Prepartition.biUnion_congr theorem biUnion_congr_of_le (h : π₁ = π₂) (hi : ∀ J ≤ I, πi₁ J = πi₂ J) : π₁.biUnion πi₁ = π₂.biUnion πi₂ := biUnion_congr h fun J hJ => hi J (π₁.le_of_mem hJ) #align box_integral.prepartition.bUnion_congr_of_le BoxIntegral.Prepartition.biUnion_congr_of_le @[simp] theorem iUnion_biUnion (πi : ∀ J : Box ι, Prepartition J) : (π.biUnion πi).iUnion = ⋃ J ∈ π, (πi J).iUnion := by simp [Prepartition.iUnion] #align box_integral.prepartition.Union_bUnion BoxIntegral.Prepartition.iUnion_biUnion @[simp] theorem sum_biUnion_boxes {M : Type*} [AddCommMonoid M] (π : Prepartition I) (πi : ∀ J, Prepartition J) (f : Box ι → M) : (∑ J ∈ π.boxes.biUnion fun J => (πi J).boxes, f J) = ∑ J ∈ π.boxes, ∑ J' ∈ (πi J).boxes, f J' := by refine Finset.sum_biUnion fun J₁ h₁ J₂ h₂ hne => Finset.disjoint_left.2 fun J' h₁' h₂' => ?_ exact hne (π.eq_of_le_of_le h₁ h₂ ((πi J₁).le_of_mem h₁') ((πi J₂).le_of_mem h₂')) #align box_integral.prepartition.sum_bUnion_boxes BoxIntegral.Prepartition.sum_biUnion_boxes /-- Given a box `J ∈ π.biUnion πi`, returns the box `J' ∈ π` such that `J ∈ πi J'`. For `J ∉ π.biUnion πi`, returns `I`. -/ def biUnionIndex (πi : ∀ (J : Box ι), Prepartition J) (J : Box ι) : Box ι := if hJ : J ∈ π.biUnion πi then (π.mem_biUnion.1 hJ).choose else I #align box_integral.prepartition.bUnion_index BoxIntegral.Prepartition.biUnionIndex theorem biUnionIndex_mem (hJ : J ∈ π.biUnion πi) : π.biUnionIndex πi J ∈ π := by rw [biUnionIndex, dif_pos hJ] exact (π.mem_biUnion.1 hJ).choose_spec.1 #align box_integral.prepartition.bUnion_index_mem BoxIntegral.Prepartition.biUnionIndex_mem theorem biUnionIndex_le (πi : ∀ J, Prepartition J) (J : Box ι) : π.biUnionIndex πi J ≤ I := by by_cases hJ : J ∈ π.biUnion πi · exact π.le_of_mem (π.biUnionIndex_mem hJ) · rw [biUnionIndex, dif_neg hJ] #align box_integral.prepartition.bUnion_index_le BoxIntegral.Prepartition.biUnionIndex_le theorem mem_biUnionIndex (hJ : J ∈ π.biUnion πi) : J ∈ πi (π.biUnionIndex πi J) := by convert (π.mem_biUnion.1 hJ).choose_spec.2 <;> exact dif_pos hJ #align box_integral.prepartition.mem_bUnion_index BoxIntegral.Prepartition.mem_biUnionIndex theorem le_biUnionIndex (hJ : J ∈ π.biUnion πi) : J ≤ π.biUnionIndex πi J := le_of_mem _ (π.mem_biUnionIndex hJ) #align box_integral.prepartition.le_bUnion_index BoxIntegral.Prepartition.le_biUnionIndex /-- Uniqueness property of `BoxIntegral.Prepartition.biUnionIndex`. -/ theorem biUnionIndex_of_mem (hJ : J ∈ π) {J'} (hJ' : J' ∈ πi J) : π.biUnionIndex πi J' = J := have : J' ∈ π.biUnion πi := π.mem_biUnion.2 ⟨J, hJ, hJ'⟩ π.eq_of_le_of_le (π.biUnionIndex_mem this) hJ (π.le_biUnionIndex this) (le_of_mem _ hJ') #align box_integral.prepartition.bUnion_index_of_mem BoxIntegral.Prepartition.biUnionIndex_of_mem theorem biUnion_assoc (πi : ∀ J, Prepartition J) (πi' : Box ι → ∀ J : Box ι, Prepartition J) : (π.biUnion fun J => (πi J).biUnion (πi' J)) = (π.biUnion πi).biUnion fun J => πi' (π.biUnionIndex πi J) J := by ext J simp only [mem_biUnion, exists_prop] constructor · rintro ⟨J₁, hJ₁, J₂, hJ₂, hJ⟩ refine ⟨J₂, ⟨J₁, hJ₁, hJ₂⟩, ?_⟩ rwa [π.biUnionIndex_of_mem hJ₁ hJ₂] · rintro ⟨J₁, ⟨J₂, hJ₂, hJ₁⟩, hJ⟩ refine ⟨J₂, hJ₂, J₁, hJ₁, ?_⟩ rwa [π.biUnionIndex_of_mem hJ₂ hJ₁] at hJ #align box_integral.prepartition.bUnion_assoc BoxIntegral.Prepartition.biUnion_assoc /-- Create a `BoxIntegral.Prepartition` from a collection of possibly empty boxes by filtering out the empty one if it exists. -/ def ofWithBot (boxes : Finset (WithBot (Box ι))) (le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≤ I) (pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint) : Prepartition I where boxes := Finset.eraseNone boxes le_of_mem' J hJ := by rw [mem_eraseNone] at hJ simpa only [WithBot.some_eq_coe, WithBot.coe_le_coe] using le_of_mem _ hJ pairwiseDisjoint J₁ h₁ J₂ h₂ hne := by simp only [mem_coe, mem_eraseNone] at h₁ h₂ exact Box.disjoint_coe.1 (pairwise_disjoint h₁ h₂ (mt Option.some_inj.1 hne)) #align box_integral.prepartition.of_with_bot BoxIntegral.Prepartition.ofWithBot @[simp] theorem mem_ofWithBot {boxes : Finset (WithBot (Box ι))} {h₁ h₂} : J ∈ (ofWithBot boxes h₁ h₂ : Prepartition I) ↔ (J : WithBot (Box ι)) ∈ boxes := mem_eraseNone #align box_integral.prepartition.mem_of_with_bot BoxIntegral.Prepartition.mem_ofWithBot @[simp] theorem iUnion_ofWithBot (boxes : Finset (WithBot (Box ι))) (le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≤ I) (pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint) : (ofWithBot boxes le_of_mem pairwise_disjoint).iUnion = ⋃ J ∈ boxes, ↑J := by suffices ⋃ (J : Box ι) (_ : ↑J ∈ boxes), ↑J = ⋃ J ∈ boxes, (J : Set (ι → ℝ)) by simpa [ofWithBot, Prepartition.iUnion] simp only [← Box.biUnion_coe_eq_coe, @iUnion_comm _ _ (Box ι), @iUnion_comm _ _ (@Eq _ _ _), iUnion_iUnion_eq_right] #align box_integral.prepartition.Union_of_with_bot BoxIntegral.Prepartition.iUnion_ofWithBot theorem ofWithBot_le {boxes : Finset (WithBot (Box ι))} {le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≤ I} {pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint} (H : ∀ J ∈ boxes, J ≠ ⊥ → ∃ J' ∈ π, J ≤ ↑J') : ofWithBot boxes le_of_mem pairwise_disjoint ≤ π := by have : ∀ J : Box ι, ↑J ∈ boxes → ∃ J' ∈ π, J ≤ J' := fun J hJ => by simpa only [WithBot.coe_le_coe] using H J hJ WithBot.coe_ne_bot simpa [ofWithBot, le_def] #align box_integral.prepartition.of_with_bot_le BoxIntegral.Prepartition.ofWithBot_le theorem le_ofWithBot {boxes : Finset (WithBot (Box ι))} {le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≤ I} {pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint} (H : ∀ J ∈ π, ∃ J' ∈ boxes, ↑J ≤ J') : π ≤ ofWithBot boxes le_of_mem pairwise_disjoint := by intro J hJ rcases H J hJ with ⟨J', J'mem, hle⟩ lift J' to Box ι using ne_bot_of_le_ne_bot WithBot.coe_ne_bot hle exact ⟨J', mem_ofWithBot.2 J'mem, WithBot.coe_le_coe.1 hle⟩ #align box_integral.prepartition.le_of_with_bot BoxIntegral.Prepartition.le_ofWithBot theorem ofWithBot_mono {boxes₁ : Finset (WithBot (Box ι))} {le_of_mem₁ : ∀ J ∈ boxes₁, (J : WithBot (Box ι)) ≤ I} {pairwise_disjoint₁ : Set.Pairwise (boxes₁ : Set (WithBot (Box ι))) Disjoint} {boxes₂ : Finset (WithBot (Box ι))} {le_of_mem₂ : ∀ J ∈ boxes₂, (J : WithBot (Box ι)) ≤ I} {pairwise_disjoint₂ : Set.Pairwise (boxes₂ : Set (WithBot (Box ι))) Disjoint} (H : ∀ J ∈ boxes₁, J ≠ ⊥ → ∃ J' ∈ boxes₂, J ≤ J') : ofWithBot boxes₁ le_of_mem₁ pairwise_disjoint₁ ≤ ofWithBot boxes₂ le_of_mem₂ pairwise_disjoint₂ := le_ofWithBot _ fun J hJ => H J (mem_ofWithBot.1 hJ) WithBot.coe_ne_bot #align box_integral.prepartition.of_with_bot_mono BoxIntegral.Prepartition.ofWithBot_mono theorem sum_ofWithBot {M : Type*} [AddCommMonoid M] (boxes : Finset (WithBot (Box ι))) (le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≤ I) (pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint) (f : Box ι → M) : (∑ J ∈ (ofWithBot boxes le_of_mem pairwise_disjoint).boxes, f J) = ∑ J ∈ boxes, Option.elim' 0 f J := Finset.sum_eraseNone _ _ #align box_integral.prepartition.sum_of_with_bot BoxIntegral.Prepartition.sum_ofWithBot /-- Restrict a prepartition to a box. -/ def restrict (π : Prepartition I) (J : Box ι) : Prepartition J := ofWithBot (π.boxes.image fun J' : Box ι => J ⊓ J') (fun J' hJ' => by rcases Finset.mem_image.1 hJ' with ⟨J', -, rfl⟩ exact inf_le_left) (by simp only [Set.Pairwise, onFun, Finset.mem_coe, Finset.mem_image] rintro _ ⟨J₁, h₁, rfl⟩ _ ⟨J₂, h₂, rfl⟩ Hne have : J₁ ≠ J₂ := by rintro rfl exact Hne rfl exact ((Box.disjoint_coe.2 <| π.disjoint_coe_of_mem h₁ h₂ this).inf_left' _).inf_right' _) #align box_integral.prepartition.restrict BoxIntegral.Prepartition.restrict @[simp] theorem mem_restrict : J₁ ∈ π.restrict J ↔ ∃ J' ∈ π, (J₁ : WithBot (Box ι)) = ↑J ⊓ ↑J' := by simp [restrict, eq_comm] #align box_integral.prepartition.mem_restrict BoxIntegral.Prepartition.mem_restrict theorem mem_restrict' : J₁ ∈ π.restrict J ↔ ∃ J' ∈ π, (J₁ : Set (ι → ℝ)) = ↑J ∩ ↑J' := by simp only [mem_restrict, ← Box.withBotCoe_inj, Box.coe_inf, Box.coe_coe] #align box_integral.prepartition.mem_restrict' BoxIntegral.Prepartition.mem_restrict' @[mono] theorem restrict_mono {π₁ π₂ : Prepartition I} (Hle : π₁ ≤ π₂) : π₁.restrict J ≤ π₂.restrict J := by refine ofWithBot_mono fun J₁ hJ₁ hne => ?_ rw [Finset.mem_image] at hJ₁; rcases hJ₁ with ⟨J₁, hJ₁, rfl⟩ rcases Hle hJ₁ with ⟨J₂, hJ₂, hle⟩ exact ⟨_, Finset.mem_image_of_mem _ hJ₂, inf_le_inf_left _ <| WithBot.coe_le_coe.2 hle⟩ #align box_integral.prepartition.restrict_mono BoxIntegral.Prepartition.restrict_mono theorem monotone_restrict : Monotone fun π : Prepartition I => restrict π J := fun _ _ => restrict_mono #align box_integral.prepartition.monotone_restrict BoxIntegral.Prepartition.monotone_restrict /-- Restricting to a larger box does not change the set of boxes. We cannot claim equality of prepartitions because they have different types. -/ theorem restrict_boxes_of_le (π : Prepartition I) (h : I ≤ J) : (π.restrict J).boxes = π.boxes := by simp only [restrict, ofWithBot, eraseNone_eq_biUnion] refine Finset.image_biUnion.trans ?_ refine (Finset.biUnion_congr rfl ?_).trans Finset.biUnion_singleton_eq_self intro J' hJ' rw [inf_of_le_right, ← WithBot.some_eq_coe, Option.toFinset_some] exact WithBot.coe_le_coe.2 ((π.le_of_mem hJ').trans h) #align box_integral.prepartition.restrict_boxes_of_le BoxIntegral.Prepartition.restrict_boxes_of_le @[simp] theorem restrict_self : π.restrict I = π := injective_boxes <| restrict_boxes_of_le π le_rfl #align box_integral.prepartition.restrict_self BoxIntegral.Prepartition.restrict_self @[simp] theorem iUnion_restrict : (π.restrict J).iUnion = (J : Set (ι → ℝ)) ∩ (π.iUnion) := by simp [restrict, ← inter_iUnion, ← iUnion_def] #align box_integral.prepartition.Union_restrict BoxIntegral.Prepartition.iUnion_restrict @[simp] theorem restrict_biUnion (πi : ∀ J, Prepartition J) (hJ : J ∈ π) : (π.biUnion πi).restrict J = πi J := by refine (eq_of_boxes_subset_iUnion_superset (fun J₁ h₁ => ?_) ?_).symm · refine (mem_restrict _).2 ⟨J₁, π.mem_biUnion.2 ⟨J, hJ, h₁⟩, (inf_of_le_right ?_).symm⟩ exact WithBot.coe_le_coe.2 (le_of_mem _ h₁) · simp only [iUnion_restrict, iUnion_biUnion, Set.subset_def, Set.mem_inter_iff, Set.mem_iUnion] rintro x ⟨hxJ, J₁, h₁, hx⟩ obtain rfl : J = J₁ := π.eq_of_mem_of_mem hJ h₁ hxJ (iUnion_subset _ hx) exact hx #align box_integral.prepartition.restrict_bUnion BoxIntegral.Prepartition.restrict_biUnion theorem biUnion_le_iff {πi : ∀ J, Prepartition J} {π' : Prepartition I} : π.biUnion πi ≤ π' ↔ ∀ J ∈ π, πi J ≤ π'.restrict J := by constructor <;> intro H J hJ · rw [← π.restrict_biUnion πi hJ] exact restrict_mono H · rw [mem_biUnion] at hJ rcases hJ with ⟨J₁, h₁, hJ⟩ rcases H J₁ h₁ hJ with ⟨J₂, h₂, Hle⟩ rcases π'.mem_restrict.mp h₂ with ⟨J₃, h₃, H⟩ exact ⟨J₃, h₃, Hle.trans <| WithBot.coe_le_coe.1 <| H.trans_le inf_le_right⟩ #align box_integral.prepartition.bUnion_le_iff BoxIntegral.Prepartition.biUnion_le_iff theorem le_biUnion_iff {πi : ∀ J, Prepartition J} {π' : Prepartition I} : π' ≤ π.biUnion πi ↔ π' ≤ π ∧ ∀ J ∈ π, π'.restrict J ≤ πi J := by refine ⟨fun H => ⟨H.trans (π.biUnion_le πi), fun J hJ => ?_⟩, ?_⟩ · rw [← π.restrict_biUnion πi hJ] exact restrict_mono H · rintro ⟨H, Hi⟩ J' hJ' rcases H hJ' with ⟨J, hJ, hle⟩ have : J' ∈ π'.restrict J := π'.mem_restrict.2 ⟨J', hJ', (inf_of_le_right <| WithBot.coe_le_coe.2 hle).symm⟩ rcases Hi J hJ this with ⟨Ji, hJi, hlei⟩ exact ⟨Ji, π.mem_biUnion.2 ⟨J, hJ, hJi⟩, hlei⟩ #align box_integral.prepartition.le_bUnion_iff BoxIntegral.Prepartition.le_biUnion_iff instance inf : Inf (Prepartition I) := ⟨fun π₁ π₂ => π₁.biUnion fun J => π₂.restrict J⟩ theorem inf_def (π₁ π₂ : Prepartition I) : π₁ ⊓ π₂ = π₁.biUnion fun J => π₂.restrict J := rfl #align box_integral.prepartition.inf_def BoxIntegral.Prepartition.inf_def @[simp] theorem mem_inf {π₁ π₂ : Prepartition I} : J ∈ π₁ ⊓ π₂ ↔ ∃ J₁ ∈ π₁, ∃ J₂ ∈ π₂, (J : WithBot (Box ι)) = ↑J₁ ⊓ ↑J₂ := by simp only [inf_def, mem_biUnion, mem_restrict] #align box_integral.prepartition.mem_inf BoxIntegral.Prepartition.mem_inf @[simp] theorem iUnion_inf (π₁ π₂ : Prepartition I) : (π₁ ⊓ π₂).iUnion = π₁.iUnion ∩ π₂.iUnion := by simp only [inf_def, iUnion_biUnion, iUnion_restrict, ← iUnion_inter, ← iUnion_def] #align box_integral.prepartition.Union_inf BoxIntegral.Prepartition.iUnion_inf instance : SemilatticeInf (Prepartition I) := { Prepartition.inf, Prepartition.partialOrder with inf_le_left := fun π₁ _ => π₁.biUnion_le _ inf_le_right := fun _ _ => (biUnion_le_iff _).2 fun _ _ => le_rfl le_inf := fun _ π₁ _ h₁ h₂ => π₁.le_biUnion_iff.2 ⟨h₁, fun _ _ => restrict_mono h₂⟩ } /-- The prepartition with boxes `{J ∈ π | p J}`. -/ @[simps] def filter (π : Prepartition I) (p : Box ι → Prop) : Prepartition I where boxes := π.boxes.filter p le_of_mem' _ hJ := π.le_of_mem (mem_filter.1 hJ).1 pairwiseDisjoint _ h₁ _ h₂ := π.disjoint_coe_of_mem (mem_filter.1 h₁).1 (mem_filter.1 h₂).1 #align box_integral.prepartition.filter BoxIntegral.Prepartition.filter @[simp] theorem mem_filter {p : Box ι → Prop} : J ∈ π.filter p ↔ J ∈ π ∧ p J := Finset.mem_filter #align box_integral.prepartition.mem_filter BoxIntegral.Prepartition.mem_filter theorem filter_le (π : Prepartition I) (p : Box ι → Prop) : π.filter p ≤ π := fun J hJ => let ⟨hπ, _⟩ := π.mem_filter.1 hJ ⟨J, hπ, le_rfl⟩ #align box_integral.prepartition.filter_le BoxIntegral.Prepartition.filter_le theorem filter_of_true {p : Box ι → Prop} (hp : ∀ J ∈ π, p J) : π.filter p = π := by ext J simpa using hp J #align box_integral.prepartition.filter_of_true BoxIntegral.Prepartition.filter_of_true @[simp] theorem filter_true : (π.filter fun _ => True) = π := π.filter_of_true fun _ _ => trivial #align box_integral.prepartition.filter_true BoxIntegral.Prepartition.filter_true @[simp] theorem iUnion_filter_not (π : Prepartition I) (p : Box ι → Prop) : (π.filter fun J => ¬p J).iUnion = π.iUnion \ (π.filter p).iUnion := by simp only [Prepartition.iUnion] convert (@Set.biUnion_diff_biUnion_eq (ι → ℝ) (Box ι) π.boxes (π.filter p).boxes (↑) _).symm · simp (config := { contextual := true }) · rw [Set.PairwiseDisjoint] convert π.pairwiseDisjoint rw [Set.union_eq_left, filter_boxes, coe_filter] exact fun _ ⟨h, _⟩ => h #align box_integral.prepartition.Union_filter_not BoxIntegral.Prepartition.iUnion_filter_not theorem sum_fiberwise {α M} [AddCommMonoid M] (π : Prepartition I) (f : Box ι → α) (g : Box ι → M) : (∑ y ∈ π.boxes.image f, ∑ J ∈ (π.filter fun J => f J = y).boxes, g J) = ∑ J ∈ π.boxes, g J := by convert sum_fiberwise_of_maps_to (fun _ => Finset.mem_image_of_mem f) g #align box_integral.prepartition.sum_fiberwise BoxIntegral.Prepartition.sum_fiberwise /-- Union of two disjoint prepartitions. -/ @[simps] def disjUnion (π₁ π₂ : Prepartition I) (h : Disjoint π₁.iUnion π₂.iUnion) : Prepartition I where boxes := π₁.boxes ∪ π₂.boxes le_of_mem' J hJ := (Finset.mem_union.1 hJ).elim π₁.le_of_mem π₂.le_of_mem pairwiseDisjoint := suffices ∀ J₁ ∈ π₁, ∀ J₂ ∈ π₂, J₁ ≠ J₂ → Disjoint (J₁ : Set (ι → ℝ)) J₂ by simpa [pairwise_union_of_symmetric (symmetric_disjoint.comap _), pairwiseDisjoint] fun J₁ h₁ J₂ h₂ _ => h.mono (π₁.subset_iUnion h₁) (π₂.subset_iUnion h₂) #align box_integral.prepartition.disj_union BoxIntegral.Prepartition.disjUnion @[simp] theorem mem_disjUnion (H : Disjoint π₁.iUnion π₂.iUnion) : J ∈ π₁.disjUnion π₂ H ↔ J ∈ π₁ ∨ J ∈ π₂ := Finset.mem_union #align box_integral.prepartition.mem_disj_union BoxIntegral.Prepartition.mem_disjUnion @[simp]
Mathlib/Analysis/BoxIntegral/Partition/Basic.lean
657
659
theorem iUnion_disjUnion (h : Disjoint π₁.iUnion π₂.iUnion) : (π₁.disjUnion π₂ h).iUnion = π₁.iUnion ∪ π₂.iUnion := by
simp [disjUnion, Prepartition.iUnion, iUnion_or, iUnion_union_distrib]
/- Copyright (c) 2022 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.MonoidAlgebra.Basic #align_import algebra.monoid_algebra.division from "leanprover-community/mathlib"@"72c366d0475675f1309d3027d3d7d47ee4423951" /-! # Division of `AddMonoidAlgebra` by monomials This file is most important for when `G = ℕ` (polynomials) or `G = σ →₀ ℕ` (multivariate polynomials). In order to apply in maximal generality (such as for `LaurentPolynomial`s), this uses `∃ d, g' = g + d` in many places instead of `g ≤ g'`. ## Main definitions * `AddMonoidAlgebra.divOf x g`: divides `x` by the monomial `AddMonoidAlgebra.of k G g` * `AddMonoidAlgebra.modOf x g`: the remainder upon dividing `x` by the monomial `AddMonoidAlgebra.of k G g`. ## Main results * `AddMonoidAlgebra.divOf_add_modOf`, `AddMonoidAlgebra.modOf_add_divOf`: `divOf` and `modOf` are well-behaved as quotient and remainder operators. ## Implementation notes `∃ d, g' = g + d` is used as opposed to some other permutation up to commutativity in order to match the definition of `semigroupDvd`. The results in this file could be duplicated for `MonoidAlgebra` by using `g ∣ g'`, but this can't be done automatically, and in any case is not likely to be very useful. -/ variable {k G : Type*} [Semiring k] namespace AddMonoidAlgebra section variable [AddCancelCommMonoid G] /-- Divide by `of' k G g`, discarding terms not divisible by this. -/ noncomputable def divOf (x : k[G]) (g : G) : k[G] := -- note: comapping by `+ g` has the effect of subtracting `g` from every element in -- the support, and discarding the elements of the support from which `g` can't be subtracted. -- If `G` is an additive group, such as `ℤ` when used for `LaurentPolynomial`, -- then no discarding occurs. @Finsupp.comapDomain.addMonoidHom _ _ _ _ (g + ·) (add_right_injective g) x #align add_monoid_algebra.div_of AddMonoidAlgebra.divOf local infixl:70 " /ᵒᶠ " => divOf @[simp] theorem divOf_apply (g : G) (x : k[G]) (g' : G) : (x /ᵒᶠ g) g' = x (g + g') := rfl #align add_monoid_algebra.div_of_apply AddMonoidAlgebra.divOf_apply @[simp] theorem support_divOf (g : G) (x : k[G]) : (x /ᵒᶠ g).support = x.support.preimage (g + ·) (Function.Injective.injOn (add_right_injective g)) := rfl #align add_monoid_algebra.support_div_of AddMonoidAlgebra.support_divOf @[simp] theorem zero_divOf (g : G) : (0 : k[G]) /ᵒᶠ g = 0 := map_zero (Finsupp.comapDomain.addMonoidHom _) #align add_monoid_algebra.zero_div_of AddMonoidAlgebra.zero_divOf @[simp] theorem divOf_zero (x : k[G]) : x /ᵒᶠ 0 = x := by refine Finsupp.ext fun _ => ?_ -- Porting note: `ext` doesn't work simp only [AddMonoidAlgebra.divOf_apply, zero_add] #align add_monoid_algebra.div_of_zero AddMonoidAlgebra.divOf_zero theorem add_divOf (x y : k[G]) (g : G) : (x + y) /ᵒᶠ g = x /ᵒᶠ g + y /ᵒᶠ g := map_add (Finsupp.comapDomain.addMonoidHom _) _ _ #align add_monoid_algebra.add_div_of AddMonoidAlgebra.add_divOf theorem divOf_add (x : k[G]) (a b : G) : x /ᵒᶠ (a + b) = x /ᵒᶠ a /ᵒᶠ b := by refine Finsupp.ext fun _ => ?_ -- Porting note: `ext` doesn't work simp only [AddMonoidAlgebra.divOf_apply, add_assoc] #align add_monoid_algebra.div_of_add AddMonoidAlgebra.divOf_add /-- A bundled version of `AddMonoidAlgebra.divOf`. -/ @[simps] noncomputable def divOfHom : Multiplicative G →* AddMonoid.End k[G] where toFun g := { toFun := fun x => divOf x (Multiplicative.toAdd g) map_zero' := zero_divOf _ map_add' := fun x y => add_divOf x y (Multiplicative.toAdd g) } map_one' := AddMonoidHom.ext divOf_zero map_mul' g₁ g₂ := AddMonoidHom.ext fun _x => (congr_arg _ (add_comm (Multiplicative.toAdd g₁) (Multiplicative.toAdd g₂))).trans (divOf_add _ _ _) #align add_monoid_algebra.div_of_hom AddMonoidAlgebra.divOfHom theorem of'_mul_divOf (a : G) (x : k[G]) : of' k G a * x /ᵒᶠ a = x := by refine Finsupp.ext fun _ => ?_ -- Porting note: `ext` doesn't work rw [AddMonoidAlgebra.divOf_apply, of'_apply, single_mul_apply_aux, one_mul] intro c exact add_right_inj _ #align add_monoid_algebra.of'_mul_div_of AddMonoidAlgebra.of'_mul_divOf theorem mul_of'_divOf (x : k[G]) (a : G) : x * of' k G a /ᵒᶠ a = x := by refine Finsupp.ext fun _ => ?_ -- Porting note: `ext` doesn't work rw [AddMonoidAlgebra.divOf_apply, of'_apply, mul_single_apply_aux, mul_one] intro c rw [add_comm] exact add_right_inj _ #align add_monoid_algebra.mul_of'_div_of AddMonoidAlgebra.mul_of'_divOf theorem of'_divOf (a : G) : of' k G a /ᵒᶠ a = 1 := by simpa only [one_mul] using mul_of'_divOf (1 : k[G]) a #align add_monoid_algebra.of'_div_of AddMonoidAlgebra.of'_divOf /-- The remainder upon division by `of' k G g`. -/ noncomputable def modOf (x : k[G]) (g : G) : k[G] := letI := Classical.decPred fun g₁ => ∃ g₂, g₁ = g + g₂ x.filter fun g₁ => ¬∃ g₂, g₁ = g + g₂ #align add_monoid_algebra.mod_of AddMonoidAlgebra.modOf local infixl:70 " %ᵒᶠ " => modOf @[simp] theorem modOf_apply_of_not_exists_add (x : k[G]) (g : G) (g' : G) (h : ¬∃ d, g' = g + d) : (x %ᵒᶠ g) g' = x g' := by classical exact Finsupp.filter_apply_pos _ _ h #align add_monoid_algebra.mod_of_apply_of_not_exists_add AddMonoidAlgebra.modOf_apply_of_not_exists_add @[simp] theorem modOf_apply_of_exists_add (x : k[G]) (g : G) (g' : G) (h : ∃ d, g' = g + d) : (x %ᵒᶠ g) g' = 0 := by classical exact Finsupp.filter_apply_neg _ _ <| by rwa [Classical.not_not] #align add_monoid_algebra.mod_of_apply_of_exists_add AddMonoidAlgebra.modOf_apply_of_exists_add @[simp] theorem modOf_apply_add_self (x : k[G]) (g : G) (d : G) : (x %ᵒᶠ g) (d + g) = 0 := modOf_apply_of_exists_add _ _ _ ⟨_, add_comm _ _⟩ #align add_monoid_algebra.mod_of_apply_add_self AddMonoidAlgebra.modOf_apply_add_self -- @[simp] -- Porting note (#10618): simp can prove this theorem modOf_apply_self_add (x : k[G]) (g : G) (d : G) : (x %ᵒᶠ g) (g + d) = 0 := modOf_apply_of_exists_add _ _ _ ⟨_, rfl⟩ #align add_monoid_algebra.mod_of_apply_self_add AddMonoidAlgebra.modOf_apply_self_add theorem of'_mul_modOf (g : G) (x : k[G]) : of' k G g * x %ᵒᶠ g = 0 := by refine Finsupp.ext fun g' => ?_ -- Porting note: `ext g'` doesn't work rw [Finsupp.zero_apply] obtain ⟨d, rfl⟩ | h := em (∃ d, g' = g + d) · rw [modOf_apply_self_add] · rw [modOf_apply_of_not_exists_add _ _ _ h, of'_apply, single_mul_apply_of_not_exists_add _ _ h] #align add_monoid_algebra.of'_mul_mod_of AddMonoidAlgebra.of'_mul_modOf theorem mul_of'_modOf (x : k[G]) (g : G) : x * of' k G g %ᵒᶠ g = 0 := by refine Finsupp.ext fun g' => ?_ -- Porting note: `ext g'` doesn't work rw [Finsupp.zero_apply] obtain ⟨d, rfl⟩ | h := em (∃ d, g' = g + d) · rw [modOf_apply_self_add] · rw [modOf_apply_of_not_exists_add _ _ _ h, of'_apply, mul_single_apply_of_not_exists_add] simpa only [add_comm] using h #align add_monoid_algebra.mul_of'_mod_of AddMonoidAlgebra.mul_of'_modOf theorem of'_modOf (g : G) : of' k G g %ᵒᶠ g = 0 := by simpa only [one_mul] using mul_of'_modOf (1 : k[G]) g #align add_monoid_algebra.of'_mod_of AddMonoidAlgebra.of'_modOf theorem divOf_add_modOf (x : k[G]) (g : G) : of' k G g * (x /ᵒᶠ g) + x %ᵒᶠ g = x := by refine Finsupp.ext fun g' => ?_ -- Porting note: `ext` doesn't work rw [Finsupp.add_apply] -- Porting note: changed from `simp_rw` which can't see through the type obtain ⟨d, rfl⟩ | h := em (∃ d, g' = g + d) swap · rw [modOf_apply_of_not_exists_add x _ _ h, of'_apply, single_mul_apply_of_not_exists_add _ _ h, zero_add] · rw [modOf_apply_self_add, add_zero] rw [of'_apply, single_mul_apply_aux _ _ _, one_mul, divOf_apply] intro a exact add_right_inj _ #align add_monoid_algebra.div_of_add_mod_of AddMonoidAlgebra.divOf_add_modOf theorem modOf_add_divOf (x : k[G]) (g : G) : x %ᵒᶠ g + of' k G g * (x /ᵒᶠ g) = x := by rw [add_comm, divOf_add_modOf] #align add_monoid_algebra.mod_of_add_div_of AddMonoidAlgebra.modOf_add_divOf
Mathlib/Algebra/MonoidAlgebra/Division.lean
193
200
theorem of'_dvd_iff_modOf_eq_zero {x : k[G]} {g : G} : of' k G g ∣ x ↔ x %ᵒᶠ g = 0 := by
constructor · rintro ⟨x, rfl⟩ rw [of'_mul_modOf] · intro h rw [← divOf_add_modOf x g, h, add_zero] exact dvd_mul_right _ _
/- Copyright (c) 2021 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot -/ import Mathlib.Topology.Algebra.Nonarchimedean.Basic import Mathlib.Topology.Algebra.FilterBasis import Mathlib.Algebra.Module.Submodule.Pointwise #align_import topology.algebra.nonarchimedean.bases from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Neighborhood bases for non-archimedean rings and modules This files contains special families of filter bases on rings and modules that give rise to non-archimedean topologies. The main definition is `RingSubgroupsBasis` which is a predicate on a family of additive subgroups of a ring. The predicate ensures there is a topology `RingSubgroupsBasis.topology` which is compatible with a ring structure and admits the given family as a basis of neighborhoods of zero. In particular the given subgroups become open subgroups (bundled in `RingSubgroupsBasis.openAddSubgroup`) and we get a non-archimedean topological ring (`RingSubgroupsBasis.nonarchimedean`). A special case of this construction is given by `SubmodulesBasis` where the subgroups are sub-modules in a commutative algebra. This important example gives rise to the adic topology (studied in its own file). -/ open Set Filter Function Lattice open Topology Filter Pointwise /-- A family of additive subgroups on a ring `A` is a subgroups basis if it satisfies some axioms ensuring there is a topology on `A` which is compatible with the ring structure and admits this family as a basis of neighborhoods of zero. -/ structure RingSubgroupsBasis {A ι : Type*} [Ring A] (B : ι → AddSubgroup A) : Prop where /-- Condition for `B` to be a filter basis on `A`. -/ inter : ∀ i j, ∃ k, B k ≤ B i ⊓ B j /-- For each set `B` in the submodule basis on `A`, there is another basis element `B'` such that the set-theoretic product `B' * B'` is in `B`. -/ mul : ∀ i, ∃ j, (B j : Set A) * B j ⊆ B i /-- For any element `x : A` and any set `B` in the submodule basis on `A`, there is another basis element `B'` such that `B' * x` is in `B`. -/ leftMul : ∀ x : A, ∀ i, ∃ j, (B j : Set A) ⊆ (x * ·) ⁻¹' B i /-- For any element `x : A` and any set `B` in the submodule basis on `A`, there is another basis element `B'` such that `x * B'` is in `B`. -/ rightMul : ∀ x : A, ∀ i, ∃ j, (B j : Set A) ⊆ (· * x) ⁻¹' B i #align ring_subgroups_basis RingSubgroupsBasis namespace RingSubgroupsBasis variable {A ι : Type*} [Ring A] theorem of_comm {A ι : Type*} [CommRing A] (B : ι → AddSubgroup A) (inter : ∀ i j, ∃ k, B k ≤ B i ⊓ B j) (mul : ∀ i, ∃ j, (B j : Set A) * B j ⊆ B i) (leftMul : ∀ x : A, ∀ i, ∃ j, (B j : Set A) ⊆ (fun y : A => x * y) ⁻¹' B i) : RingSubgroupsBasis B := { inter mul leftMul rightMul := fun x i ↦ (leftMul x i).imp fun j hj ↦ by simpa only [mul_comm] using hj } #align ring_subgroups_basis.of_comm RingSubgroupsBasis.of_comm /-- Every subgroups basis on a ring leads to a ring filter basis. -/ def toRingFilterBasis [Nonempty ι] {B : ι → AddSubgroup A} (hB : RingSubgroupsBasis B) : RingFilterBasis A where sets := { U | ∃ i, U = B i } nonempty := by inhabit ι exact ⟨B default, default, rfl⟩ inter_sets := by rintro _ _ ⟨i, rfl⟩ ⟨j, rfl⟩ cases' hB.inter i j with k hk use B k constructor · use k · exact hk zero' := by rintro _ ⟨i, rfl⟩ exact (B i).zero_mem add' := by rintro _ ⟨i, rfl⟩ use B i constructor · use i · rintro x ⟨y, y_in, z, z_in, rfl⟩ exact (B i).add_mem y_in z_in neg' := by rintro _ ⟨i, rfl⟩ use B i constructor · use i · intro x x_in exact (B i).neg_mem x_in conj' := by rintro x₀ _ ⟨i, rfl⟩ use B i constructor · use i · simp mul' := by rintro _ ⟨i, rfl⟩ cases' hB.mul i with k hk use B k constructor · use k · exact hk mul_left' := by rintro x₀ _ ⟨i, rfl⟩ cases' hB.leftMul x₀ i with k hk use B k constructor · use k · exact hk mul_right' := by rintro x₀ _ ⟨i, rfl⟩ cases' hB.rightMul x₀ i with k hk use B k constructor · use k · exact hk #align ring_subgroups_basis.to_ring_filter_basis RingSubgroupsBasis.toRingFilterBasis variable [Nonempty ι] {B : ι → AddSubgroup A} (hB : RingSubgroupsBasis B) theorem mem_addGroupFilterBasis_iff {V : Set A} : V ∈ hB.toRingFilterBasis.toAddGroupFilterBasis ↔ ∃ i, V = B i := Iff.rfl #align ring_subgroups_basis.mem_add_group_filter_basis_iff RingSubgroupsBasis.mem_addGroupFilterBasis_iff theorem mem_addGroupFilterBasis (i) : (B i : Set A) ∈ hB.toRingFilterBasis.toAddGroupFilterBasis := ⟨i, rfl⟩ #align ring_subgroups_basis.mem_add_group_filter_basis RingSubgroupsBasis.mem_addGroupFilterBasis /-- The topology defined from a subgroups basis, admitting the given subgroups as a basis of neighborhoods of zero. -/ def topology : TopologicalSpace A := hB.toRingFilterBasis.toAddGroupFilterBasis.topology #align ring_subgroups_basis.topology RingSubgroupsBasis.topology theorem hasBasis_nhds_zero : HasBasis (@nhds A hB.topology 0) (fun _ => True) fun i => B i := ⟨by intro s rw [hB.toRingFilterBasis.toAddGroupFilterBasis.nhds_zero_hasBasis.mem_iff] constructor · rintro ⟨-, ⟨i, rfl⟩, hi⟩ exact ⟨i, trivial, hi⟩ · rintro ⟨i, -, hi⟩ exact ⟨B i, ⟨i, rfl⟩, hi⟩⟩ #align ring_subgroups_basis.has_basis_nhds_zero RingSubgroupsBasis.hasBasis_nhds_zero theorem hasBasis_nhds (a : A) : HasBasis (@nhds A hB.topology a) (fun _ => True) fun i => { b | b - a ∈ B i } := ⟨by intro s rw [(hB.toRingFilterBasis.toAddGroupFilterBasis.nhds_hasBasis a).mem_iff] simp only [true_and] constructor · rintro ⟨-, ⟨i, rfl⟩, hi⟩ use i suffices h : { b : A | b - a ∈ B i } = (fun y => a + y) '' ↑(B i) by rw [h] assumption simp only [image_add_left, neg_add_eq_sub] ext b simp · rintro ⟨i, hi⟩ use B i constructor · use i · rw [image_subset_iff] rintro b b_in apply hi simpa using b_in⟩ #align ring_subgroups_basis.has_basis_nhds RingSubgroupsBasis.hasBasis_nhds /-- Given a subgroups basis, the basis elements as open additive subgroups in the associated topology. -/ def openAddSubgroup (i : ι) : @OpenAddSubgroup A _ hB.topology := -- Porting note: failed to synthesize instance `TopologicalSpace A` let _ := hB.topology { B i with isOpen' := by rw [isOpen_iff_mem_nhds] intro a a_in rw [(hB.hasBasis_nhds a).mem_iff] use i, trivial rintro b b_in simpa using (B i).add_mem a_in b_in } #align ring_subgroups_basis.open_add_subgroup RingSubgroupsBasis.openAddSubgroup -- see Note [nonarchimedean non instances]
Mathlib/Topology/Algebra/Nonarchimedean/Bases.lean
194
199
theorem nonarchimedean : @NonarchimedeanRing A _ hB.topology := by
letI := hB.topology constructor intro U hU obtain ⟨i, -, hi : (B i : Set A) ⊆ U⟩ := hB.hasBasis_nhds_zero.mem_iff.mp hU exact ⟨hB.openAddSubgroup i, hi⟩
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Aaron Anderson, Yakov Pechersky -/ import Mathlib.Algebra.Group.Commute.Basic import Mathlib.Data.Fintype.Card import Mathlib.GroupTheory.Perm.Basic #align_import group_theory.perm.support from "leanprover-community/mathlib"@"9003f28797c0664a49e4179487267c494477d853" /-! # support of a permutation ## Main definitions In the following, `f g : Equiv.Perm α`. * `Equiv.Perm.Disjoint`: two permutations `f` and `g` are `Disjoint` if every element is fixed either by `f`, or by `g`. Equivalently, `f` and `g` are `Disjoint` iff their `support` are disjoint. * `Equiv.Perm.IsSwap`: `f = swap x y` for `x ≠ y`. * `Equiv.Perm.support`: the elements `x : α` that are not fixed by `f`. Assume `α` is a Fintype: * `Equiv.Perm.fixed_point_card_lt_of_ne_one f` says that `f` has strictly less than `Fintype.card α - 1` fixed points, unless `f = 1`. (Equivalently, `f.support` has at least 2 elements.) -/ open Equiv Finset namespace Equiv.Perm variable {α : Type*} section Disjoint /-- Two permutations `f` and `g` are `Disjoint` if their supports are disjoint, i.e., every element is fixed either by `f`, or by `g`. -/ def Disjoint (f g : Perm α) := ∀ x, f x = x ∨ g x = x #align equiv.perm.disjoint Equiv.Perm.Disjoint variable {f g h : Perm α} @[symm] theorem Disjoint.symm : Disjoint f g → Disjoint g f := by simp only [Disjoint, or_comm, imp_self] #align equiv.perm.disjoint.symm Equiv.Perm.Disjoint.symm theorem Disjoint.symmetric : Symmetric (@Disjoint α) := fun _ _ => Disjoint.symm #align equiv.perm.disjoint.symmetric Equiv.Perm.Disjoint.symmetric instance : IsSymm (Perm α) Disjoint := ⟨Disjoint.symmetric⟩ theorem disjoint_comm : Disjoint f g ↔ Disjoint g f := ⟨Disjoint.symm, Disjoint.symm⟩ #align equiv.perm.disjoint_comm Equiv.Perm.disjoint_comm theorem Disjoint.commute (h : Disjoint f g) : Commute f g := Equiv.ext fun x => (h x).elim (fun hf => (h (g x)).elim (fun hg => by simp [mul_apply, hf, hg]) fun hg => by simp [mul_apply, hf, g.injective hg]) fun hg => (h (f x)).elim (fun hf => by simp [mul_apply, f.injective hf, hg]) fun hf => by simp [mul_apply, hf, hg] #align equiv.perm.disjoint.commute Equiv.Perm.Disjoint.commute @[simp] theorem disjoint_one_left (f : Perm α) : Disjoint 1 f := fun _ => Or.inl rfl #align equiv.perm.disjoint_one_left Equiv.Perm.disjoint_one_left @[simp] theorem disjoint_one_right (f : Perm α) : Disjoint f 1 := fun _ => Or.inr rfl #align equiv.perm.disjoint_one_right Equiv.Perm.disjoint_one_right theorem disjoint_iff_eq_or_eq : Disjoint f g ↔ ∀ x : α, f x = x ∨ g x = x := Iff.rfl #align equiv.perm.disjoint_iff_eq_or_eq Equiv.Perm.disjoint_iff_eq_or_eq @[simp] theorem disjoint_refl_iff : Disjoint f f ↔ f = 1 := by refine ⟨fun h => ?_, fun h => h.symm ▸ disjoint_one_left 1⟩ ext x cases' h x with hx hx <;> simp [hx] #align equiv.perm.disjoint_refl_iff Equiv.Perm.disjoint_refl_iff theorem Disjoint.inv_left (h : Disjoint f g) : Disjoint f⁻¹ g := by intro x rw [inv_eq_iff_eq, eq_comm] exact h x #align equiv.perm.disjoint.inv_left Equiv.Perm.Disjoint.inv_left theorem Disjoint.inv_right (h : Disjoint f g) : Disjoint f g⁻¹ := h.symm.inv_left.symm #align equiv.perm.disjoint.inv_right Equiv.Perm.Disjoint.inv_right @[simp] theorem disjoint_inv_left_iff : Disjoint f⁻¹ g ↔ Disjoint f g := by refine ⟨fun h => ?_, Disjoint.inv_left⟩ convert h.inv_left #align equiv.perm.disjoint_inv_left_iff Equiv.Perm.disjoint_inv_left_iff @[simp] theorem disjoint_inv_right_iff : Disjoint f g⁻¹ ↔ Disjoint f g := by rw [disjoint_comm, disjoint_inv_left_iff, disjoint_comm] #align equiv.perm.disjoint_inv_right_iff Equiv.Perm.disjoint_inv_right_iff theorem Disjoint.mul_left (H1 : Disjoint f h) (H2 : Disjoint g h) : Disjoint (f * g) h := fun x => by cases H1 x <;> cases H2 x <;> simp [*] #align equiv.perm.disjoint.mul_left Equiv.Perm.Disjoint.mul_left theorem Disjoint.mul_right (H1 : Disjoint f g) (H2 : Disjoint f h) : Disjoint f (g * h) := by rw [disjoint_comm] exact H1.symm.mul_left H2.symm #align equiv.perm.disjoint.mul_right Equiv.Perm.Disjoint.mul_right -- Porting note (#11215): TODO: make it `@[simp]` theorem disjoint_conj (h : Perm α) : Disjoint (h * f * h⁻¹) (h * g * h⁻¹) ↔ Disjoint f g := (h⁻¹).forall_congr fun {_} ↦ by simp only [mul_apply, eq_inv_iff_eq] theorem Disjoint.conj (H : Disjoint f g) (h : Perm α) : Disjoint (h * f * h⁻¹) (h * g * h⁻¹) := (disjoint_conj h).2 H theorem disjoint_prod_right (l : List (Perm α)) (h : ∀ g ∈ l, Disjoint f g) : Disjoint f l.prod := by induction' l with g l ih · exact disjoint_one_right _ · rw [List.prod_cons] exact (h _ (List.mem_cons_self _ _)).mul_right (ih fun g hg => h g (List.mem_cons_of_mem _ hg)) #align equiv.perm.disjoint_prod_right Equiv.Perm.disjoint_prod_right open scoped List in theorem disjoint_prod_perm {l₁ l₂ : List (Perm α)} (hl : l₁.Pairwise Disjoint) (hp : l₁ ~ l₂) : l₁.prod = l₂.prod := hp.prod_eq' <| hl.imp Disjoint.commute #align equiv.perm.disjoint_prod_perm Equiv.Perm.disjoint_prod_perm theorem nodup_of_pairwise_disjoint {l : List (Perm α)} (h1 : (1 : Perm α) ∉ l) (h2 : l.Pairwise Disjoint) : l.Nodup := by refine List.Pairwise.imp_of_mem ?_ h2 intro τ σ h_mem _ h_disjoint _ subst τ suffices (σ : Perm α) = 1 by rw [this] at h_mem exact h1 h_mem exact ext fun a => or_self_iff.mp (h_disjoint a) #align equiv.perm.nodup_of_pairwise_disjoint Equiv.Perm.nodup_of_pairwise_disjoint theorem pow_apply_eq_self_of_apply_eq_self {x : α} (hfx : f x = x) : ∀ n : ℕ, (f ^ n) x = x | 0 => rfl | n + 1 => by rw [pow_succ, mul_apply, hfx, pow_apply_eq_self_of_apply_eq_self hfx n] #align equiv.perm.pow_apply_eq_self_of_apply_eq_self Equiv.Perm.pow_apply_eq_self_of_apply_eq_self theorem zpow_apply_eq_self_of_apply_eq_self {x : α} (hfx : f x = x) : ∀ n : ℤ, (f ^ n) x = x | (n : ℕ) => pow_apply_eq_self_of_apply_eq_self hfx n | Int.negSucc n => by rw [zpow_negSucc, inv_eq_iff_eq, pow_apply_eq_self_of_apply_eq_self hfx] #align equiv.perm.zpow_apply_eq_self_of_apply_eq_self Equiv.Perm.zpow_apply_eq_self_of_apply_eq_self theorem pow_apply_eq_of_apply_apply_eq_self {x : α} (hffx : f (f x) = x) : ∀ n : ℕ, (f ^ n) x = x ∨ (f ^ n) x = f x | 0 => Or.inl rfl | n + 1 => (pow_apply_eq_of_apply_apply_eq_self hffx n).elim (fun h => Or.inr (by rw [pow_succ', mul_apply, h])) fun h => Or.inl (by rw [pow_succ', mul_apply, h, hffx]) #align equiv.perm.pow_apply_eq_of_apply_apply_eq_self Equiv.Perm.pow_apply_eq_of_apply_apply_eq_self theorem zpow_apply_eq_of_apply_apply_eq_self {x : α} (hffx : f (f x) = x) : ∀ i : ℤ, (f ^ i) x = x ∨ (f ^ i) x = f x | (n : ℕ) => pow_apply_eq_of_apply_apply_eq_self hffx n | Int.negSucc n => by rw [zpow_negSucc, inv_eq_iff_eq, ← f.injective.eq_iff, ← mul_apply, ← pow_succ', eq_comm, inv_eq_iff_eq, ← mul_apply, ← pow_succ, @eq_comm _ x, or_comm] exact pow_apply_eq_of_apply_apply_eq_self hffx _ #align equiv.perm.zpow_apply_eq_of_apply_apply_eq_self Equiv.Perm.zpow_apply_eq_of_apply_apply_eq_self theorem Disjoint.mul_apply_eq_iff {σ τ : Perm α} (hστ : Disjoint σ τ) {a : α} : (σ * τ) a = a ↔ σ a = a ∧ τ a = a := by refine ⟨fun h => ?_, fun h => by rw [mul_apply, h.2, h.1]⟩ cases' hστ a with hσ hτ · exact ⟨hσ, σ.injective (h.trans hσ.symm)⟩ · exact ⟨(congr_arg σ hτ).symm.trans h, hτ⟩ #align equiv.perm.disjoint.mul_apply_eq_iff Equiv.Perm.Disjoint.mul_apply_eq_iff theorem Disjoint.mul_eq_one_iff {σ τ : Perm α} (hστ : Disjoint σ τ) : σ * τ = 1 ↔ σ = 1 ∧ τ = 1 := by simp_rw [ext_iff, one_apply, hστ.mul_apply_eq_iff, forall_and] #align equiv.perm.disjoint.mul_eq_one_iff Equiv.Perm.Disjoint.mul_eq_one_iff theorem Disjoint.zpow_disjoint_zpow {σ τ : Perm α} (hστ : Disjoint σ τ) (m n : ℤ) : Disjoint (σ ^ m) (τ ^ n) := fun x => Or.imp (fun h => zpow_apply_eq_self_of_apply_eq_self h m) (fun h => zpow_apply_eq_self_of_apply_eq_self h n) (hστ x) #align equiv.perm.disjoint.zpow_disjoint_zpow Equiv.Perm.Disjoint.zpow_disjoint_zpow theorem Disjoint.pow_disjoint_pow {σ τ : Perm α} (hστ : Disjoint σ τ) (m n : ℕ) : Disjoint (σ ^ m) (τ ^ n) := hστ.zpow_disjoint_zpow m n #align equiv.perm.disjoint.pow_disjoint_pow Equiv.Perm.Disjoint.pow_disjoint_pow end Disjoint section IsSwap variable [DecidableEq α] /-- `f.IsSwap` indicates that the permutation `f` is a transposition of two elements. -/ def IsSwap (f : Perm α) : Prop := ∃ x y, x ≠ y ∧ f = swap x y #align equiv.perm.is_swap Equiv.Perm.IsSwap @[simp] theorem ofSubtype_swap_eq {p : α → Prop} [DecidablePred p] (x y : Subtype p) : ofSubtype (Equiv.swap x y) = Equiv.swap ↑x ↑y := Equiv.ext fun z => by by_cases hz : p z · rw [swap_apply_def, ofSubtype_apply_of_mem _ hz] split_ifs with hzx hzy · simp_rw [hzx, Subtype.coe_eta, swap_apply_left] · simp_rw [hzy, Subtype.coe_eta, swap_apply_right] · rw [swap_apply_of_ne_of_ne] <;> simp [Subtype.ext_iff, *] · rw [ofSubtype_apply_of_not_mem _ hz, swap_apply_of_ne_of_ne] · intro h apply hz rw [h] exact Subtype.prop x intro h apply hz rw [h] exact Subtype.prop y #align equiv.perm.of_subtype_swap_eq Equiv.Perm.ofSubtype_swap_eq theorem IsSwap.of_subtype_isSwap {p : α → Prop} [DecidablePred p] {f : Perm (Subtype p)} (h : f.IsSwap) : (ofSubtype f).IsSwap := let ⟨⟨x, hx⟩, ⟨y, hy⟩, hxy⟩ := h ⟨x, y, by simp only [Ne, Subtype.ext_iff] at hxy exact hxy.1, by rw [hxy.2, ofSubtype_swap_eq]⟩ #align equiv.perm.is_swap.of_subtype_is_swap Equiv.Perm.IsSwap.of_subtype_isSwap theorem ne_and_ne_of_swap_mul_apply_ne_self {f : Perm α} {x y : α} (hy : (swap x (f x) * f) y ≠ y) : f y ≠ y ∧ y ≠ x := by simp only [swap_apply_def, mul_apply, f.injective.eq_iff] at * by_cases h : f y = x · constructor <;> intro <;> simp_all only [if_true, eq_self_iff_true, not_true, Ne] · split_ifs at hy with h h <;> try { simp [*] at * } #align equiv.perm.ne_and_ne_of_swap_mul_apply_ne_self Equiv.Perm.ne_and_ne_of_swap_mul_apply_ne_self end IsSwap section support section Set variable (p q : Perm α) theorem set_support_inv_eq : { x | p⁻¹ x ≠ x } = { x | p x ≠ x } := by ext x simp only [Set.mem_setOf_eq, Ne] rw [inv_def, symm_apply_eq, eq_comm] #align equiv.perm.set_support_inv_eq Equiv.Perm.set_support_inv_eq theorem set_support_apply_mem {p : Perm α} {a : α} : p a ∈ { x | p x ≠ x } ↔ a ∈ { x | p x ≠ x } := by simp #align equiv.perm.set_support_apply_mem Equiv.Perm.set_support_apply_mem theorem set_support_zpow_subset (n : ℤ) : { x | (p ^ n) x ≠ x } ⊆ { x | p x ≠ x } := by intro x simp only [Set.mem_setOf_eq, Ne] intro hx H simp [zpow_apply_eq_self_of_apply_eq_self H] at hx #align equiv.perm.set_support_zpow_subset Equiv.Perm.set_support_zpow_subset theorem set_support_mul_subset : { x | (p * q) x ≠ x } ⊆ { x | p x ≠ x } ∪ { x | q x ≠ x } := by intro x simp only [Perm.coe_mul, Function.comp_apply, Ne, Set.mem_union, Set.mem_setOf_eq] by_cases hq : q x = x <;> simp [hq] #align equiv.perm.set_support_mul_subset Equiv.Perm.set_support_mul_subset end Set variable [DecidableEq α] [Fintype α] {f g : Perm α} /-- The `Finset` of nonfixed points of a permutation. -/ def support (f : Perm α) : Finset α := univ.filter fun x => f x ≠ x #align equiv.perm.support Equiv.Perm.support @[simp] theorem mem_support {x : α} : x ∈ f.support ↔ f x ≠ x := by rw [support, mem_filter, and_iff_right (mem_univ x)] #align equiv.perm.mem_support Equiv.Perm.mem_support theorem not_mem_support {x : α} : x ∉ f.support ↔ f x = x := by simp #align equiv.perm.not_mem_support Equiv.Perm.not_mem_support theorem coe_support_eq_set_support (f : Perm α) : (f.support : Set α) = { x | f x ≠ x } := by ext simp #align equiv.perm.coe_support_eq_set_support Equiv.Perm.coe_support_eq_set_support @[simp] theorem support_eq_empty_iff {σ : Perm α} : σ.support = ∅ ↔ σ = 1 := by simp_rw [Finset.ext_iff, mem_support, Finset.not_mem_empty, iff_false_iff, not_not, Equiv.Perm.ext_iff, one_apply] #align equiv.perm.support_eq_empty_iff Equiv.Perm.support_eq_empty_iff @[simp] theorem support_one : (1 : Perm α).support = ∅ := by rw [support_eq_empty_iff] #align equiv.perm.support_one Equiv.Perm.support_one @[simp] theorem support_refl : support (Equiv.refl α) = ∅ := support_one #align equiv.perm.support_refl Equiv.Perm.support_refl theorem support_congr (h : f.support ⊆ g.support) (h' : ∀ x ∈ g.support, f x = g x) : f = g := by ext x by_cases hx : x ∈ g.support · exact h' x hx · rw [not_mem_support.mp hx, ← not_mem_support] exact fun H => hx (h H) #align equiv.perm.support_congr Equiv.Perm.support_congr theorem support_mul_le (f g : Perm α) : (f * g).support ≤ f.support ⊔ g.support := fun x => by simp only [sup_eq_union] rw [mem_union, mem_support, mem_support, mem_support, mul_apply, ← not_and_or, not_imp_not] rintro ⟨hf, hg⟩ rw [hg, hf] #align equiv.perm.support_mul_le Equiv.Perm.support_mul_le theorem exists_mem_support_of_mem_support_prod {l : List (Perm α)} {x : α} (hx : x ∈ l.prod.support) : ∃ f : Perm α, f ∈ l ∧ x ∈ f.support := by contrapose! hx simp_rw [mem_support, not_not] at hx ⊢ induction' l with f l ih · rfl · rw [List.prod_cons, mul_apply, ih, hx] · simp only [List.find?, List.mem_cons, true_or] intros f' hf' refine hx f' ?_ simp only [List.find?, List.mem_cons] exact Or.inr hf' #align equiv.perm.exists_mem_support_of_mem_support_prod Equiv.Perm.exists_mem_support_of_mem_support_prod theorem support_pow_le (σ : Perm α) (n : ℕ) : (σ ^ n).support ≤ σ.support := fun _ h1 => mem_support.mpr fun h2 => mem_support.mp h1 (pow_apply_eq_self_of_apply_eq_self h2 n) #align equiv.perm.support_pow_le Equiv.Perm.support_pow_le @[simp] theorem support_inv (σ : Perm α) : support σ⁻¹ = σ.support := by simp_rw [Finset.ext_iff, mem_support, not_iff_not, inv_eq_iff_eq.trans eq_comm, imp_true_iff] #align equiv.perm.support_inv Equiv.Perm.support_inv -- @[simp] -- Porting note (#10618): simp can prove this theorem apply_mem_support {x : α} : f x ∈ f.support ↔ x ∈ f.support := by rw [mem_support, mem_support, Ne, Ne, apply_eq_iff_eq] #align equiv.perm.apply_mem_support Equiv.Perm.apply_mem_support -- Porting note (#10756): new theorem @[simp] theorem apply_pow_apply_eq_iff (f : Perm α) (n : ℕ) {x : α} : f ((f ^ n) x) = (f ^ n) x ↔ f x = x := by rw [← mul_apply, Commute.self_pow f, mul_apply, apply_eq_iff_eq] -- @[simp] -- Porting note (#10618): simp can prove this theorem pow_apply_mem_support {n : ℕ} {x : α} : (f ^ n) x ∈ f.support ↔ x ∈ f.support := by simp only [mem_support, ne_eq, apply_pow_apply_eq_iff] #align equiv.perm.pow_apply_mem_support Equiv.Perm.pow_apply_mem_support -- Porting note (#10756): new theorem @[simp] theorem apply_zpow_apply_eq_iff (f : Perm α) (n : ℤ) {x : α} : f ((f ^ n) x) = (f ^ n) x ↔ f x = x := by rw [← mul_apply, Commute.self_zpow f, mul_apply, apply_eq_iff_eq] -- @[simp] -- Porting note (#10618): simp can prove this theorem zpow_apply_mem_support {n : ℤ} {x : α} : (f ^ n) x ∈ f.support ↔ x ∈ f.support := by simp only [mem_support, ne_eq, apply_zpow_apply_eq_iff] #align equiv.perm.zpow_apply_mem_support Equiv.Perm.zpow_apply_mem_support theorem pow_eq_on_of_mem_support (h : ∀ x ∈ f.support ∩ g.support, f x = g x) (k : ℕ) : ∀ x ∈ f.support ∩ g.support, (f ^ k) x = (g ^ k) x := by induction' k with k hk · simp · intro x hx rw [pow_succ, mul_apply, pow_succ, mul_apply, h _ hx, hk] rwa [mem_inter, apply_mem_support, ← h _ hx, apply_mem_support, ← mem_inter] #align equiv.perm.pow_eq_on_of_mem_support Equiv.Perm.pow_eq_on_of_mem_support
Mathlib/GroupTheory/Perm/Support.lean
398
400
theorem disjoint_iff_disjoint_support : Disjoint f g ↔ _root_.Disjoint f.support g.support := by
simp [disjoint_iff_eq_or_eq, disjoint_iff, disjoint_iff, Finset.ext_iff, not_and_or, imp_iff_not_or]
/- Copyright (c) 2021 David Wärn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Wärn -/ import Mathlib.Algebra.BigOperators.Group.Finset import Mathlib.Data.Fintype.Option import Mathlib.Data.Fintype.Pi import Mathlib.Data.Fintype.Sum #align_import combinatorics.hales_jewett from "leanprover-community/mathlib"@"1126441d6bccf98c81214a0780c73d499f6721fe" /-! # The Hales-Jewett theorem We prove the Hales-Jewett theorem and deduce Van der Waerden's theorem as a corollary. The Hales-Jewett theorem is a result in Ramsey theory dealing with *combinatorial lines*. Given an 'alphabet' `α : Type*` and `a b : α`, an example of a combinatorial line in `α^5` is `{ (a, x, x, b, x) | x : α }`. See `Combinatorics.Line` for a precise general definition. The Hales-Jewett theorem states that for any fixed finite types `α` and `κ`, there exists a (potentially huge) finite type `ι` such that whenever `ι → α` is `κ`-colored (i.e. for any coloring `C : (ι → α) → κ`), there exists a monochromatic line. We prove the Hales-Jewett theorem using the idea of *color focusing* and a *product argument*. See the proof of `Combinatorics.Line.exists_mono_in_high_dimension'` for details. The version of Van der Waerden's theorem in this file states that whenever a commutative monoid `M` is finitely colored and `S` is a finite subset, there exists a monochromatic homothetic copy of `S`. This follows from the Hales-Jewett theorem by considering the map `(ι → S) → M` sending `v` to `∑ i : ι, v i`, which sends a combinatorial line to a homothetic copy of `S`. ## Main results - `Combinatorics.Line.exists_mono_in_high_dimension`: the Hales-Jewett theorem. - `Combinatorics.exists_mono_homothetic_copy`: a generalization of Van der Waerden's theorem. ## Implementation details For convenience, we work directly with finite types instead of natural numbers. That is, we write `α, ι, κ` for (finite) types where one might traditionally use natural numbers `n, H, c`. This allows us to work directly with `α`, `Option α`, `(ι → α) → κ`, and `ι ⊕ ι'` instead of `Fin n`, `Fin (n+1)`, `Fin (c^(n^H))`, and `Fin (H + H')`. ## Todo - Prove a finitary version of Van der Waerden's theorem (either by compactness or by modifying the current proof). - One could reformulate the proof of Hales-Jewett to give explicit upper bounds on the number of coordinates needed. ## Tags combinatorial line, Ramsey theory, arithmetic progression ### References * https://en.wikipedia.org/wiki/Hales%E2%80%93Jewett_theorem -/ open scoped Classical universe u v namespace Combinatorics /-- The type of combinatorial lines. A line `l : Line α ι` in the hypercube `ι → α` defines a function `α → ι → α` from `α` to the hypercube, such that for each coordinate `i : ι`, the function `fun x ↦ l x i` is either `id` or constant. We require lines to be nontrivial in the sense that `fun x ↦ l x i` is `id` for at least one `i`. Formally, a line is represented by a word `l.idxFun : ι → Option α` which says whether `fun x ↦ l x i` is `id` (corresponding to `l.idxFun i = none`) or constantly `y` (corresponding to `l.idxFun i = some y`). When `α` has size `1` there can be many elements of `Line α ι` defining the same function. -/ structure Line (α ι : Type*) where /-- The word representing a combinatorial line. `l.idxfun i = none` means that `l x i = x` for all `x` and `l.idxfun i = some y` means that `l x i = y`. -/ idxFun : ι → Option α /-- We require combinatorial lines to be nontrivial in the sense that `fun x ↦ l x i` is `id` for at least one coordinate `i`. -/ proper : ∃ i, idxFun i = none #align combinatorics.line Combinatorics.Line namespace Line -- This lets us treat a line `l : Line α ι` as a function `α → ι → α`. instance (α ι) : CoeFun (Line α ι) fun _ => α → ι → α := ⟨fun l x i => (l.idxFun i).getD x⟩ /-- A line is monochromatic if all its points are the same color. -/ def IsMono {α ι κ} (C : (ι → α) → κ) (l : Line α ι) : Prop := ∃ c, ∀ x, C (l x) = c #align combinatorics.line.is_mono Combinatorics.Line.IsMono /-- The diagonal line. It is the identity at every coordinate. -/ def diagonal (α ι) [Nonempty ι] : Line α ι where idxFun _ := none proper := ⟨Classical.arbitrary ι, rfl⟩ #align combinatorics.line.diagonal Combinatorics.Line.diagonal instance (α ι) [Nonempty ι] : Inhabited (Line α ι) := ⟨diagonal α ι⟩ /-- The type of lines that are only one color except possibly at their endpoints. -/ structure AlmostMono {α ι κ : Type*} (C : (ι → Option α) → κ) where /-- The underlying line of an almost monochromatic line, where the coordinate dimension `α` is extended by an additional symbol `none`, thought to be marking the endpoint of the line. -/ line : Line (Option α) ι /-- The main color of an almost monochromatic line. -/ color : κ /-- The proposition that the underlying line of an almost monochromatic line assumes its main color except possibly at the endpoints. -/ has_color : ∀ x : α, C (line (some x)) = color #align combinatorics.line.almost_mono Combinatorics.Line.AlmostMono instance {α ι κ : Type*} [Nonempty ι] [Inhabited κ] : Inhabited (AlmostMono fun _ : ι → Option α => (default : κ)) := ⟨{ line := default color := default has_color := fun _ ↦ rfl}⟩ /-- The type of collections of lines such that - each line is only one color except possibly at its endpoint - the lines all have the same endpoint - the colors of the lines are distinct. Used in the proof `exists_mono_in_high_dimension`. -/ structure ColorFocused {α ι κ : Type*} (C : (ι → Option α) → κ) where /-- The underlying multiset of almost monochromatic lines of a color-focused collection. -/ lines : Multiset (AlmostMono C) /-- The common endpoint of the lines in the color-focused collection. -/ focus : ι → Option α /-- The proposition that all lines in a color-focused collection have the same endpoint. -/ is_focused : ∀ p ∈ lines, p.line none = focus /-- The proposition that all lines in a color-focused collection of lines have distinct colors. -/ distinct_colors : (lines.map AlmostMono.color).Nodup #align combinatorics.line.color_focused Combinatorics.Line.ColorFocused instance {α ι κ} (C : (ι → Option α) → κ) : Inhabited (ColorFocused C) := by refine ⟨⟨0, fun _ => none, fun h => ?_, Multiset.nodup_zero⟩⟩ simp only [Multiset.not_mem_zero, IsEmpty.forall_iff] /-- A function `f : α → α'` determines a function `line α ι → line α' ι`. For a coordinate `i`, `l.map f` is the identity at `i` if `l` is, and constantly `f y` if `l` is constantly `y` at `i`. -/ def map {α α' ι} (f : α → α') (l : Line α ι) : Line α' ι where idxFun i := (l.idxFun i).map f proper := ⟨l.proper.choose, by simp only [l.proper.choose_spec, Option.map_none']⟩ #align combinatorics.line.map Combinatorics.Line.map /-- A point in `ι → α` and a line in `ι' → α` determine a line in `ι ⊕ ι' → α`. -/ def vertical {α ι ι'} (v : ι → α) (l : Line α ι') : Line α (Sum ι ι') where idxFun := Sum.elim (some ∘ v) l.idxFun proper := ⟨Sum.inr l.proper.choose, l.proper.choose_spec⟩ #align combinatorics.line.vertical Combinatorics.Line.vertical /-- A line in `ι → α` and a point in `ι' → α` determine a line in `ι ⊕ ι' → α`. -/ def horizontal {α ι ι'} (l : Line α ι) (v : ι' → α) : Line α (Sum ι ι') where idxFun := Sum.elim l.idxFun (some ∘ v) proper := ⟨Sum.inl l.proper.choose, l.proper.choose_spec⟩ #align combinatorics.line.horizontal Combinatorics.Line.horizontal /-- One line in `ι → α` and one in `ι' → α` together determine a line in `ι ⊕ ι' → α`. -/ def prod {α ι ι'} (l : Line α ι) (l' : Line α ι') : Line α (Sum ι ι') where idxFun := Sum.elim l.idxFun l'.idxFun proper := ⟨Sum.inl l.proper.choose, l.proper.choose_spec⟩ #align combinatorics.line.prod Combinatorics.Line.prod theorem apply {α ι} (l : Line α ι) (x : α) : l x = fun i => (l.idxFun i).getD x := rfl #align combinatorics.line.apply Combinatorics.Line.apply theorem apply_none {α ι} (l : Line α ι) (x : α) (i : ι) (h : l.idxFun i = none) : l x i = x := by simp only [Option.getD_none, h, l.apply] #align combinatorics.line.apply_none Combinatorics.Line.apply_none theorem apply_of_ne_none {α ι} (l : Line α ι) (x : α) (i : ι) (h : l.idxFun i ≠ none) : some (l x i) = l.idxFun i := by rw [l.apply, Option.getD_of_ne_none h] #align combinatorics.line.apply_of_ne_none Combinatorics.Line.apply_of_ne_none @[simp] theorem map_apply {α α' ι} (f : α → α') (l : Line α ι) (x : α) : l.map f (f x) = f ∘ l x := by simp only [Line.apply, Line.map, Option.getD_map] rfl #align combinatorics.line.map_apply Combinatorics.Line.map_apply @[simp]
Mathlib/Combinatorics/HalesJewett.lean
190
193
theorem vertical_apply {α ι ι'} (v : ι → α) (l : Line α ι') (x : α) : l.vertical v x = Sum.elim v (l x) := by
funext i cases i <;> rfl
/- Copyright (c) 2022 Moritz Doll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Moritz Doll -/ import Mathlib.Analysis.Calculus.ContDiff.Bounds import Mathlib.Analysis.Calculus.IteratedDeriv.Defs import Mathlib.Analysis.Calculus.LineDeriv.Basic import Mathlib.Analysis.LocallyConvex.WithSeminorms import Mathlib.Analysis.Normed.Group.ZeroAtInfty import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Analysis.SpecialFunctions.JapaneseBracket import Mathlib.Topology.Algebra.UniformFilterBasis import Mathlib.Tactic.MoveAdd #align_import analysis.schwartz_space from "leanprover-community/mathlib"@"e137999b2c6f2be388f4cd3bbf8523de1910cd2b" /-! # Schwartz space This file defines the Schwartz space. Usually, the Schwartz space is defined as the set of smooth functions $f : ℝ^n → ℂ$ such that there exists $C_{αβ} > 0$ with $$|x^α ∂^β f(x)| < C_{αβ}$$ for all $x ∈ ℝ^n$ and for all multiindices $α, β$. In mathlib, we use a slightly different approach and define the Schwartz space as all smooth functions `f : E → F`, where `E` and `F` are real normed vector spaces such that for all natural numbers `k` and `n` we have uniform bounds `‖x‖^k * ‖iteratedFDeriv ℝ n f x‖ < C`. This approach completely avoids using partial derivatives as well as polynomials. We construct the topology on the Schwartz space by a family of seminorms, which are the best constants in the above estimates. The abstract theory of topological vector spaces developed in `SeminormFamily.moduleFilterBasis` and `WithSeminorms.toLocallyConvexSpace` turns the Schwartz space into a locally convex topological vector space. ## Main definitions * `SchwartzMap`: The Schwartz space is the space of smooth functions such that all derivatives decay faster than any power of `‖x‖`. * `SchwartzMap.seminorm`: The family of seminorms as described above * `SchwartzMap.fderivCLM`: The differential as a continuous linear map `𝓢(E, F) →L[𝕜] 𝓢(E, E →L[ℝ] F)` * `SchwartzMap.derivCLM`: The one-dimensional derivative as a continuous linear map `𝓢(ℝ, F) →L[𝕜] 𝓢(ℝ, F)` * `SchwartzMap.integralCLM`: Integration as a continuous linear map `𝓢(ℝ, F) →L[ℝ] F` ## Main statements * `SchwartzMap.instUniformAddGroup` and `SchwartzMap.instLocallyConvexSpace`: The Schwartz space is a locally convex topological vector space. * `SchwartzMap.one_add_le_sup_seminorm_apply`: For a Schwartz function `f` there is a uniform bound on `(1 + ‖x‖) ^ k * ‖iteratedFDeriv ℝ n f x‖`. ## Implementation details The implementation of the seminorms is taken almost literally from `ContinuousLinearMap.opNorm`. ## Notation * `𝓢(E, F)`: The Schwartz space `SchwartzMap E F` localized in `SchwartzSpace` ## Tags Schwartz space, tempered distributions -/ noncomputable section open scoped Nat NNReal variable {𝕜 𝕜' D E F G V : Type*} variable [NormedAddCommGroup E] [NormedSpace ℝ E] variable [NormedAddCommGroup F] [NormedSpace ℝ F] variable (E F) /-- A function is a Schwartz function if it is smooth and all derivatives decay faster than any power of `‖x‖`. -/ structure SchwartzMap where toFun : E → F smooth' : ContDiff ℝ ⊤ toFun decay' : ∀ k n : ℕ, ∃ C : ℝ, ∀ x, ‖x‖ ^ k * ‖iteratedFDeriv ℝ n toFun x‖ ≤ C #align schwartz_map SchwartzMap /-- A function is a Schwartz function if it is smooth and all derivatives decay faster than any power of `‖x‖`. -/ scoped[SchwartzMap] notation "𝓢(" E ", " F ")" => SchwartzMap E F variable {E F} namespace SchwartzMap -- Porting note: removed -- instance : Coe 𝓢(E, F) (E → F) := ⟨toFun⟩ instance instFunLike : FunLike 𝓢(E, F) E F where coe f := f.toFun coe_injective' f g h := by cases f; cases g; congr #align schwartz_map.fun_like SchwartzMap.instFunLike /-- Helper instance for when there's too many metavariables to apply `DFunLike.hasCoeToFun`. -/ instance instCoeFun : CoeFun 𝓢(E, F) fun _ => E → F := DFunLike.hasCoeToFun #align schwartz_map.has_coe_to_fun SchwartzMap.instCoeFun /-- All derivatives of a Schwartz function are rapidly decaying. -/ theorem decay (f : 𝓢(E, F)) (k n : ℕ) : ∃ C : ℝ, 0 < C ∧ ∀ x, ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ ≤ C := by rcases f.decay' k n with ⟨C, hC⟩ exact ⟨max C 1, by positivity, fun x => (hC x).trans (le_max_left _ _)⟩ #align schwartz_map.decay SchwartzMap.decay /-- Every Schwartz function is smooth. -/ theorem smooth (f : 𝓢(E, F)) (n : ℕ∞) : ContDiff ℝ n f := f.smooth'.of_le le_top #align schwartz_map.smooth SchwartzMap.smooth /-- Every Schwartz function is continuous. -/ @[continuity] protected theorem continuous (f : 𝓢(E, F)) : Continuous f := (f.smooth 0).continuous #align schwartz_map.continuous SchwartzMap.continuous instance instContinuousMapClass : ContinuousMapClass 𝓢(E, F) E F where map_continuous := SchwartzMap.continuous /-- Every Schwartz function is differentiable. -/ protected theorem differentiable (f : 𝓢(E, F)) : Differentiable ℝ f := (f.smooth 1).differentiable rfl.le #align schwartz_map.differentiable SchwartzMap.differentiable /-- Every Schwartz function is differentiable at any point. -/ protected theorem differentiableAt (f : 𝓢(E, F)) {x : E} : DifferentiableAt ℝ f x := f.differentiable.differentiableAt #align schwartz_map.differentiable_at SchwartzMap.differentiableAt @[ext] theorem ext {f g : 𝓢(E, F)} (h : ∀ x, (f : E → F) x = g x) : f = g := DFunLike.ext f g h #align schwartz_map.ext SchwartzMap.ext section IsBigO open Asymptotics Filter variable (f : 𝓢(E, F)) /-- Auxiliary lemma, used in proving the more general result `isBigO_cocompact_rpow`. -/ theorem isBigO_cocompact_zpow_neg_nat (k : ℕ) : f =O[cocompact E] fun x => ‖x‖ ^ (-k : ℤ) := by obtain ⟨d, _, hd'⟩ := f.decay k 0 simp only [norm_iteratedFDeriv_zero] at hd' simp_rw [Asymptotics.IsBigO, Asymptotics.IsBigOWith] refine ⟨d, Filter.Eventually.filter_mono Filter.cocompact_le_cofinite ?_⟩ refine (Filter.eventually_cofinite_ne 0).mono fun x hx => ?_ rw [Real.norm_of_nonneg (zpow_nonneg (norm_nonneg _) _), zpow_neg, ← div_eq_mul_inv, le_div_iff'] exacts [hd' x, zpow_pos_of_pos (norm_pos_iff.mpr hx) _] set_option linter.uppercaseLean3 false in #align schwartz_map.is_O_cocompact_zpow_neg_nat SchwartzMap.isBigO_cocompact_zpow_neg_nat theorem isBigO_cocompact_rpow [ProperSpace E] (s : ℝ) : f =O[cocompact E] fun x => ‖x‖ ^ s := by let k := ⌈-s⌉₊ have hk : -(k : ℝ) ≤ s := neg_le.mp (Nat.le_ceil (-s)) refine (isBigO_cocompact_zpow_neg_nat f k).trans ?_ suffices (fun x : ℝ => x ^ (-k : ℤ)) =O[atTop] fun x : ℝ => x ^ s from this.comp_tendsto tendsto_norm_cocompact_atTop simp_rw [Asymptotics.IsBigO, Asymptotics.IsBigOWith] refine ⟨1, (Filter.eventually_ge_atTop 1).mono fun x hx => ?_⟩ rw [one_mul, Real.norm_of_nonneg (Real.rpow_nonneg (zero_le_one.trans hx) _), Real.norm_of_nonneg (zpow_nonneg (zero_le_one.trans hx) _), ← Real.rpow_intCast, Int.cast_neg, Int.cast_natCast] exact Real.rpow_le_rpow_of_exponent_le hx hk set_option linter.uppercaseLean3 false in #align schwartz_map.is_O_cocompact_rpow SchwartzMap.isBigO_cocompact_rpow theorem isBigO_cocompact_zpow [ProperSpace E] (k : ℤ) : f =O[cocompact E] fun x => ‖x‖ ^ k := by simpa only [Real.rpow_intCast] using isBigO_cocompact_rpow f k set_option linter.uppercaseLean3 false in #align schwartz_map.is_O_cocompact_zpow SchwartzMap.isBigO_cocompact_zpow end IsBigO section Aux theorem bounds_nonempty (k n : ℕ) (f : 𝓢(E, F)) : ∃ c : ℝ, c ∈ { c : ℝ | 0 ≤ c ∧ ∀ x : E, ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ ≤ c } := let ⟨M, hMp, hMb⟩ := f.decay k n ⟨M, le_of_lt hMp, hMb⟩ #align schwartz_map.bounds_nonempty SchwartzMap.bounds_nonempty theorem bounds_bddBelow (k n : ℕ) (f : 𝓢(E, F)) : BddBelow { c | 0 ≤ c ∧ ∀ x, ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ ≤ c } := ⟨0, fun _ ⟨hn, _⟩ => hn⟩ #align schwartz_map.bounds_bdd_below SchwartzMap.bounds_bddBelow
Mathlib/Analysis/Distribution/SchwartzSpace.lean
194
200
theorem decay_add_le_aux (k n : ℕ) (f g : 𝓢(E, F)) (x : E) : ‖x‖ ^ k * ‖iteratedFDeriv ℝ n ((f : E → F) + (g : E → F)) x‖ ≤ ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ + ‖x‖ ^ k * ‖iteratedFDeriv ℝ n g x‖ := by
rw [← mul_add] refine mul_le_mul_of_nonneg_left ?_ (by positivity) rw [iteratedFDeriv_add_apply (f.smooth _) (g.smooth _)] exact norm_add_le _ _
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad -/ import Mathlib.Init.Function import Mathlib.Init.Order.Defs #align_import data.bool.basic from "leanprover-community/mathlib"@"c4658a649d216f57e99621708b09dcb3dcccbd23" /-! # Booleans This file proves various trivial lemmas about booleans and their relation to decidable propositions. ## Tags bool, boolean, Bool, De Morgan -/ namespace Bool @[deprecated (since := "2024-06-07")] alias decide_True := decide_true_eq_true #align bool.to_bool_true decide_true_eq_true @[deprecated (since := "2024-06-07")] alias decide_False := decide_false_eq_false #align bool.to_bool_false decide_false_eq_false #align bool.to_bool_coe Bool.decide_coe @[deprecated (since := "2024-06-07")] alias coe_decide := decide_eq_true_iff #align bool.coe_to_bool decide_eq_true_iff @[deprecated decide_eq_true_iff (since := "2024-06-07")] alias of_decide_iff := decide_eq_true_iff #align bool.of_to_bool_iff decide_eq_true_iff #align bool.tt_eq_to_bool_iff true_eq_decide_iff #align bool.ff_eq_to_bool_iff false_eq_decide_iff @[deprecated (since := "2024-06-07")] alias decide_not := decide_not #align bool.to_bool_not decide_not #align bool.to_bool_and Bool.decide_and #align bool.to_bool_or Bool.decide_or #align bool.to_bool_eq decide_eq_decide @[deprecated (since := "2024-06-07")] alias not_false' := false_ne_true #align bool.not_ff Bool.false_ne_true @[deprecated (since := "2024-06-07")] alias eq_iff_eq_true_iff := eq_iff_iff #align bool.default_bool Bool.default_bool theorem dichotomy (b : Bool) : b = false ∨ b = true := by cases b <;> simp #align bool.dichotomy Bool.dichotomy theorem forall_bool' {p : Bool → Prop} (b : Bool) : (∀ x, p x) ↔ p b ∧ p !b := ⟨fun h ↦ ⟨h _, h _⟩, fun ⟨h₁, h₂⟩ x ↦ by cases b <;> cases x <;> assumption⟩ @[simp] theorem forall_bool {p : Bool → Prop} : (∀ b, p b) ↔ p false ∧ p true := forall_bool' false #align bool.forall_bool Bool.forall_bool theorem exists_bool' {p : Bool → Prop} (b : Bool) : (∃ x, p x) ↔ p b ∨ p !b := ⟨fun ⟨x, hx⟩ ↦ by cases x <;> cases b <;> first | exact .inl ‹_› | exact .inr ‹_›, fun h ↦ by cases h <;> exact ⟨_, ‹_›⟩⟩ @[simp] theorem exists_bool {p : Bool → Prop} : (∃ b, p b) ↔ p false ∨ p true := exists_bool' false #align bool.exists_bool Bool.exists_bool #align bool.decidable_forall_bool Bool.instDecidableForallOfDecidablePred #align bool.decidable_exists_bool Bool.instDecidableExistsOfDecidablePred #align bool.cond_eq_ite Bool.cond_eq_ite #align bool.cond_to_bool Bool.cond_decide #align bool.cond_bnot Bool.cond_not theorem not_ne_id : not ≠ id := fun h ↦ false_ne_true <| congrFun h true #align bool.bnot_ne_id Bool.not_ne_id #align bool.coe_bool_iff Bool.coe_iff_coe @[deprecated (since := "2024-06-07")] alias eq_true_of_ne_false := eq_true_of_ne_false #align bool.eq_tt_of_ne_ff eq_true_of_ne_false @[deprecated (since := "2024-06-07")] alias eq_false_of_ne_true := eq_false_of_ne_true #align bool.eq_ff_of_ne_tt eq_true_of_ne_false #align bool.bor_comm Bool.or_comm #align bool.bor_assoc Bool.or_assoc #align bool.bor_left_comm Bool.or_left_comm theorem or_inl {a b : Bool} (H : a) : a || b := by simp [H] #align bool.bor_inl Bool.or_inl theorem or_inr {a b : Bool} (H : b) : a || b := by cases a <;> simp [H] #align bool.bor_inr Bool.or_inr #align bool.band_comm Bool.and_comm #align bool.band_assoc Bool.and_assoc #align bool.band_left_comm Bool.and_left_comm theorem and_elim_left : ∀ {a b : Bool}, a && b → a := by decide #align bool.band_elim_left Bool.and_elim_left theorem and_intro : ∀ {a b : Bool}, a → b → a && b := by decide #align bool.band_intro Bool.and_intro theorem and_elim_right : ∀ {a b : Bool}, a && b → b := by decide #align bool.band_elim_right Bool.and_elim_right #align bool.band_bor_distrib_left Bool.and_or_distrib_left #align bool.band_bor_distrib_right Bool.and_or_distrib_right #align bool.bor_band_distrib_left Bool.or_and_distrib_left #align bool.bor_band_distrib_right Bool.or_and_distrib_right #align bool.bnot_ff Bool.not_false #align bool.bnot_tt Bool.not_true lemma eq_not_iff : ∀ {a b : Bool}, a = !b ↔ a ≠ b := by decide #align bool.eq_bnot_iff Bool.eq_not_iff lemma not_eq_iff : ∀ {a b : Bool}, !a = b ↔ a ≠ b := by decide #align bool.bnot_eq_iff Bool.not_eq_iff #align bool.not_eq_bnot Bool.not_eq_not #align bool.bnot_not_eq Bool.not_not_eq theorem ne_not {a b : Bool} : a ≠ !b ↔ a = b := not_eq_not #align bool.ne_bnot Bool.ne_not @[deprecated (since := "2024-06-07")] alias not_ne := not_not_eq #align bool.bnot_ne Bool.not_not_eq lemma not_ne_self : ∀ b : Bool, (!b) ≠ b := by decide #align bool.bnot_ne_self Bool.not_ne_self lemma self_ne_not : ∀ b : Bool, b ≠ !b := by decide #align bool.self_ne_bnot Bool.self_ne_not lemma eq_or_eq_not : ∀ a b, a = b ∨ a = !b := by decide #align bool.eq_or_eq_bnot Bool.eq_or_eq_not -- Porting note: naming issue again: these two `not` are different. theorem not_iff_not : ∀ {b : Bool}, !b ↔ ¬b := by simp #align bool.bnot_iff_not Bool.not_iff_not theorem eq_true_of_not_eq_false' {a : Bool} : !a = false → a = true := by cases a <;> decide #align bool.eq_tt_of_bnot_eq_ff Bool.eq_true_of_not_eq_false' theorem eq_false_of_not_eq_true' {a : Bool} : !a = true → a = false := by cases a <;> decide #align bool.eq_ff_of_bnot_eq_tt Bool.eq_false_of_not_eq_true' #align bool.band_bnot_self Bool.and_not_self #align bool.bnot_band_self Bool.not_and_self #align bool.bor_bnot_self Bool.or_not_self #align bool.bnot_bor_self Bool.not_or_self theorem bne_eq_xor : bne = xor := by funext a b; revert a b; decide #align bool.bxor_comm Bool.xor_comm attribute [simp] xor_assoc #align bool.bxor_assoc Bool.xor_assoc #align bool.bxor_left_comm Bool.xor_left_comm #align bool.bxor_bnot_left Bool.not_xor #align bool.bxor_bnot_right Bool.xor_not #align bool.bxor_bnot_bnot Bool.not_xor_not #align bool.bxor_ff_left Bool.false_xor #align bool.bxor_ff_right Bool.xor_false #align bool.band_bxor_distrib_left Bool.and_xor_distrib_left #align bool.band_bxor_distrib_right Bool.and_xor_distrib_right theorem xor_iff_ne : ∀ {x y : Bool}, xor x y = true ↔ x ≠ y := by decide #align bool.bxor_iff_ne Bool.xor_iff_ne /-! ### De Morgan's laws for booleans-/ #align bool.bnot_band Bool.not_and #align bool.bnot_bor Bool.not_or #align bool.bnot_inj Bool.not_inj instance linearOrder : LinearOrder Bool where le_refl := by decide le_trans := by decide le_antisymm := by decide le_total := by decide decidableLE := inferInstance decidableEq := inferInstance decidableLT := inferInstance lt_iff_le_not_le := by decide max_def := by decide min_def := by decide #align bool.linear_order Bool.linearOrder #align bool.ff_le Bool.false_le #align bool.le_tt Bool.le_true theorem lt_iff : ∀ {x y : Bool}, x < y ↔ x = false ∧ y = true := by decide #align bool.lt_iff Bool.lt_iff @[simp] theorem false_lt_true : false < true := lt_iff.2 ⟨rfl, rfl⟩ #align bool.ff_lt_tt Bool.false_lt_true theorem le_iff_imp : ∀ {x y : Bool}, x ≤ y ↔ x → y := by decide #align bool.le_iff_imp Bool.le_iff_imp
Mathlib/Data/Bool/Basic.lean
221
221
theorem and_le_left : ∀ x y : Bool, (x && y) ≤ x := by
decide
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Jakob von Raumer -/ import Mathlib.CategoryTheory.Limits.HasLimits import Mathlib.CategoryTheory.Thin #align_import category_theory.limits.shapes.wide_pullbacks from "leanprover-community/mathlib"@"f187f1074fa1857c94589cc653c786cadc4c35ff" /-! # Wide pullbacks We define the category `WidePullbackShape`, (resp. `WidePushoutShape`) which is the category obtained from a discrete category of type `J` by adjoining a terminal (resp. initial) element. Limits of this shape are wide pullbacks (pushouts). The convenience method `wideCospan` (`wideSpan`) constructs a functor from this category, hitting the given morphisms. We use `WidePullbackShape` to define ordinary pullbacks (pushouts) by using `J := WalkingPair`, which allows easy proofs of some related lemmas. Furthermore, wide pullbacks are used to show the existence of limits in the slice category. Namely, if `C` has wide pullbacks then `C/B` has limits for any object `B` in `C`. Typeclasses `HasWidePullbacks` and `HasFiniteWidePullbacks` assert the existence of wide pullbacks and finite wide pullbacks. -/ universe w w' v u open CategoryTheory CategoryTheory.Limits Opposite namespace CategoryTheory.Limits variable (J : Type w) /-- A wide pullback shape for any type `J` can be written simply as `Option J`. -/ def WidePullbackShape := Option J #align category_theory.limits.wide_pullback_shape CategoryTheory.Limits.WidePullbackShape -- Porting note: strangely this could be synthesized instance : Inhabited (WidePullbackShape J) where default := none /-- A wide pushout shape for any type `J` can be written simply as `Option J`. -/ def WidePushoutShape := Option J #align category_theory.limits.wide_pushout_shape CategoryTheory.Limits.WidePushoutShape instance : Inhabited (WidePushoutShape J) where default := none namespace WidePullbackShape variable {J} /-- The type of arrows for the shape indexing a wide pullback. -/ inductive Hom : WidePullbackShape J → WidePullbackShape J → Type w | id : ∀ X, Hom X X | term : ∀ j : J, Hom (some j) none deriving DecidableEq #align category_theory.limits.wide_pullback_shape.hom CategoryTheory.Limits.WidePullbackShape.Hom -- This is relying on an automatically generated instance name, generated in a `deriving` handler. -- See https://github.com/leanprover/lean4/issues/2343 attribute [nolint unusedArguments] instDecidableEqHom instance struct : CategoryStruct (WidePullbackShape J) where Hom := Hom id j := Hom.id j comp f g := by cases f · exact g cases g apply Hom.term _ #align category_theory.limits.wide_pullback_shape.struct CategoryTheory.Limits.WidePullbackShape.struct instance Hom.inhabited : Inhabited (Hom (none : WidePullbackShape J) none) := ⟨Hom.id (none : WidePullbackShape J)⟩ #align category_theory.limits.wide_pullback_shape.hom.inhabited CategoryTheory.Limits.WidePullbackShape.Hom.inhabited open Lean Elab Tactic /- Pointing note: experimenting with manual scoping of aesop tactics. Attempted to define aesop rule directing on `WidePushoutOut` and it didn't take for some reason -/ /-- An aesop tactic for bulk cases on morphisms in `WidePushoutShape` -/ def evalCasesBash : TacticM Unit := do evalTactic (← `(tactic| casesm* WidePullbackShape _, (_: WidePullbackShape _) ⟶ (_ : WidePullbackShape _) )) attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] evalCasesBash instance subsingleton_hom : Quiver.IsThin (WidePullbackShape J) := fun _ _ => by constructor intro a b casesm* WidePullbackShape _, (_: WidePullbackShape _) ⟶ (_ : WidePullbackShape _) · rfl · rfl · rfl #align category_theory.limits.wide_pullback_shape.subsingleton_hom CategoryTheory.Limits.WidePullbackShape.subsingleton_hom instance category : SmallCategory (WidePullbackShape J) := thin_category #align category_theory.limits.wide_pullback_shape.category CategoryTheory.Limits.WidePullbackShape.category @[simp] theorem hom_id (X : WidePullbackShape J) : Hom.id X = 𝟙 X := rfl #align category_theory.limits.wide_pullback_shape.hom_id CategoryTheory.Limits.WidePullbackShape.hom_id /- Porting note: we get a warning that we should change LHS to `sizeOf (𝟙 X)` but Lean cannot find the category instance on `WidePullbackShape J` in that case. Once supplied in the proof, the proposed proof of `simp [only WidePullbackShape.hom_id]` does not work -/ attribute [nolint simpNF] Hom.id.sizeOf_spec variable {C : Type u} [Category.{v} C] /-- Construct a functor out of the wide pullback shape given a J-indexed collection of arrows to a fixed object. -/ @[simps] def wideCospan (B : C) (objs : J → C) (arrows : ∀ j : J, objs j ⟶ B) : WidePullbackShape J ⥤ C where obj j := Option.casesOn j B objs map f := by cases' f with _ j · apply 𝟙 _ · exact arrows j #align category_theory.limits.wide_pullback_shape.wide_cospan CategoryTheory.Limits.WidePullbackShape.wideCospan /-- Every diagram is naturally isomorphic (actually, equal) to a `wideCospan` -/ def diagramIsoWideCospan (F : WidePullbackShape J ⥤ C) : F ≅ wideCospan (F.obj none) (fun j => F.obj (some j)) fun j => F.map (Hom.term j) := NatIso.ofComponents fun j => eqToIso <| by aesop_cat #align category_theory.limits.wide_pullback_shape.diagram_iso_wide_cospan CategoryTheory.Limits.WidePullbackShape.diagramIsoWideCospan /-- Construct a cone over a wide cospan. -/ @[simps] def mkCone {F : WidePullbackShape J ⥤ C} {X : C} (f : X ⟶ F.obj none) (π : ∀ j, X ⟶ F.obj (some j)) (w : ∀ j, π j ≫ F.map (Hom.term j) = f) : Cone F := { pt := X π := { app := fun j => match j with | none => f | some j => π j naturality := fun j j' f => by cases j <;> cases j' <;> cases f <;> dsimp <;> simp [w] } } #align category_theory.limits.wide_pullback_shape.mk_cone CategoryTheory.Limits.WidePullbackShape.mkCone /-- Wide pullback diagrams of equivalent index types are equivalent. -/ def equivalenceOfEquiv (J' : Type w') (h : J ≃ J') : WidePullbackShape J ≌ WidePullbackShape J' where functor := wideCospan none (fun j => some (h j)) fun j => Hom.term (h j) inverse := wideCospan none (fun j => some (h.invFun j)) fun j => Hom.term (h.invFun j) unitIso := NatIso.ofComponents (fun j => by aesop_cat) fun f => by simp only [eq_iff_true_of_subsingleton] counitIso := NatIso.ofComponents (fun j => by aesop_cat) fun f => by simp only [eq_iff_true_of_subsingleton] #align category_theory.limits.wide_pullback_shape.equivalence_of_equiv CategoryTheory.Limits.WidePullbackShape.equivalenceOfEquiv /-- Lifting universe and morphism levels preserves wide pullback diagrams. -/ def uliftEquivalence : ULiftHom.{w'} (ULift.{w'} (WidePullbackShape J)) ≌ WidePullbackShape (ULift J) := (ULiftHomULiftCategory.equiv.{w', w', w, w} (WidePullbackShape J)).symm.trans (equivalenceOfEquiv _ (Equiv.ulift.{w', w}.symm : J ≃ ULift.{w'} J)) #align category_theory.limits.wide_pullback_shape.ulift_equivalence CategoryTheory.Limits.WidePullbackShape.uliftEquivalence end WidePullbackShape namespace WidePushoutShape variable {J} /-- The type of arrows for the shape indexing a wide pushout. -/ inductive Hom : WidePushoutShape J → WidePushoutShape J → Type w | id : ∀ X, Hom X X | init : ∀ j : J, Hom none (some j) deriving DecidableEq #align category_theory.limits.wide_pushout_shape.hom CategoryTheory.Limits.WidePushoutShape.Hom -- This is relying on an automatically generated instance name, generated in a `deriving` handler. -- See https://github.com/leanprover/lean4/issues/2343 attribute [nolint unusedArguments] instDecidableEqHom instance struct : CategoryStruct (WidePushoutShape J) where Hom := Hom id j := Hom.id j comp f g := by cases f · exact g cases g apply Hom.init _ #align category_theory.limits.wide_pushout_shape.struct CategoryTheory.Limits.WidePushoutShape.struct instance Hom.inhabited : Inhabited (Hom (none : WidePushoutShape J) none) := ⟨Hom.id (none : WidePushoutShape J)⟩ #align category_theory.limits.wide_pushout_shape.hom.inhabited CategoryTheory.Limits.WidePushoutShape.Hom.inhabited open Lean Elab Tactic -- Pointing note: experimenting with manual scoping of aesop tactics; only this worked /-- An aesop tactic for bulk cases on morphisms in `WidePushoutShape` -/ def evalCasesBash' : TacticM Unit := do evalTactic (← `(tactic| casesm* WidePushoutShape _, (_: WidePushoutShape _) ⟶ (_ : WidePushoutShape _) )) attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] evalCasesBash' instance subsingleton_hom : Quiver.IsThin (WidePushoutShape J) := fun _ _ => by constructor intro a b casesm* WidePushoutShape _, (_: WidePushoutShape _) ⟶ (_ : WidePushoutShape _) repeat rfl #align category_theory.limits.wide_pushout_shape.subsingleton_hom CategoryTheory.Limits.WidePushoutShape.subsingleton_hom instance category : SmallCategory (WidePushoutShape J) := thin_category #align category_theory.limits.wide_pushout_shape.category CategoryTheory.Limits.WidePushoutShape.category @[simp] theorem hom_id (X : WidePushoutShape J) : Hom.id X = 𝟙 X := rfl #align category_theory.limits.wide_pushout_shape.hom_id CategoryTheory.Limits.WidePushoutShape.hom_id /- Porting note: we get a warning that we should change LHS to `sizeOf (𝟙 X)` but Lean cannot find the category instance on `WidePushoutShape J` in that case. Once supplied in the proof, the proposed proof of `simp [only WidePushoutShape.hom_id]` does not work -/ attribute [nolint simpNF] Hom.id.sizeOf_spec variable {C : Type u} [Category.{v} C] /-- Construct a functor out of the wide pushout shape given a J-indexed collection of arrows from a fixed object. -/ @[simps] def wideSpan (B : C) (objs : J → C) (arrows : ∀ j : J, B ⟶ objs j) : WidePushoutShape J ⥤ C where obj j := Option.casesOn j B objs map f := by cases' f with _ j · apply 𝟙 _ · exact arrows j map_comp := fun f g => by cases f · simp only [Eq.ndrec, hom_id, eq_rec_constant, Category.id_comp]; congr · cases g simp only [Eq.ndrec, hom_id, eq_rec_constant, Category.comp_id]; congr #align category_theory.limits.wide_pushout_shape.wide_span CategoryTheory.Limits.WidePushoutShape.wideSpan /-- Every diagram is naturally isomorphic (actually, equal) to a `wideSpan` -/ def diagramIsoWideSpan (F : WidePushoutShape J ⥤ C) : F ≅ wideSpan (F.obj none) (fun j => F.obj (some j)) fun j => F.map (Hom.init j) := NatIso.ofComponents fun j => eqToIso <| by cases j; repeat rfl #align category_theory.limits.wide_pushout_shape.diagram_iso_wide_span CategoryTheory.Limits.WidePushoutShape.diagramIsoWideSpan /-- Construct a cocone over a wide span. -/ @[simps] def mkCocone {F : WidePushoutShape J ⥤ C} {X : C} (f : F.obj none ⟶ X) (ι : ∀ j, F.obj (some j) ⟶ X) (w : ∀ j, F.map (Hom.init j) ≫ ι j = f) : Cocone F := { pt := X ι := { app := fun j => match j with | none => f | some j => ι j naturality := fun j j' f => by cases j <;> cases j' <;> cases f <;> dsimp <;> simp [w] } } #align category_theory.limits.wide_pushout_shape.mk_cocone CategoryTheory.Limits.WidePushoutShape.mkCocone /-- Wide pushout diagrams of equivalent index types are equivalent. -/ def equivalenceOfEquiv (J' : Type w') (h : J ≃ J') : WidePushoutShape J ≌ WidePushoutShape J' where functor := wideSpan none (fun j => some (h j)) fun j => Hom.init (h j) inverse := wideSpan none (fun j => some (h.invFun j)) fun j => Hom.init (h.invFun j) unitIso := NatIso.ofComponents (fun j => by aesop_cat) fun f => by simp only [eq_iff_true_of_subsingleton] counitIso := NatIso.ofComponents (fun j => by aesop_cat) fun f => by simp only [eq_iff_true_of_subsingleton] /-- Lifting universe and morphism levels preserves wide pushout diagrams. -/ def uliftEquivalence : ULiftHom.{w'} (ULift.{w'} (WidePushoutShape J)) ≌ WidePushoutShape (ULift J) := (ULiftHomULiftCategory.equiv.{w', w', w, w} (WidePushoutShape J)).symm.trans (equivalenceOfEquiv _ (Equiv.ulift.{w', w}.symm : J ≃ ULift.{w'} J)) end WidePushoutShape variable (C : Type u) [Category.{v} C] /-- `HasWidePullbacks` represents a choice of wide pullback for every collection of morphisms -/ abbrev HasWidePullbacks : Prop := ∀ J : Type w, HasLimitsOfShape (WidePullbackShape J) C #align category_theory.limits.has_wide_pullbacks CategoryTheory.Limits.HasWidePullbacks /-- `HasWidePushouts` represents a choice of wide pushout for every collection of morphisms -/ abbrev HasWidePushouts : Prop := ∀ J : Type w, HasColimitsOfShape (WidePushoutShape J) C #align category_theory.limits.has_wide_pushouts CategoryTheory.Limits.HasWidePushouts variable {C J} /-- `HasWidePullback B objs arrows` means that `wideCospan B objs arrows` has a limit. -/ abbrev HasWidePullback (B : C) (objs : J → C) (arrows : ∀ j : J, objs j ⟶ B) : Prop := HasLimit (WidePullbackShape.wideCospan B objs arrows) #align category_theory.limits.has_wide_pullback CategoryTheory.Limits.HasWidePullback /-- `HasWidePushout B objs arrows` means that `wideSpan B objs arrows` has a colimit. -/ abbrev HasWidePushout (B : C) (objs : J → C) (arrows : ∀ j : J, B ⟶ objs j) : Prop := HasColimit (WidePushoutShape.wideSpan B objs arrows) #align category_theory.limits.has_wide_pushout CategoryTheory.Limits.HasWidePushout /-- A choice of wide pullback. -/ noncomputable abbrev widePullback (B : C) (objs : J → C) (arrows : ∀ j : J, objs j ⟶ B) [HasWidePullback B objs arrows] : C := limit (WidePullbackShape.wideCospan B objs arrows) #align category_theory.limits.wide_pullback CategoryTheory.Limits.widePullback /-- A choice of wide pushout. -/ noncomputable abbrev widePushout (B : C) (objs : J → C) (arrows : ∀ j : J, B ⟶ objs j) [HasWidePushout B objs arrows] : C := colimit (WidePushoutShape.wideSpan B objs arrows) #align category_theory.limits.wide_pushout CategoryTheory.Limits.widePushout namespace WidePullback variable {C : Type u} [Category.{v} C] {B : C} {objs : J → C} (arrows : ∀ j : J, objs j ⟶ B) variable [HasWidePullback B objs arrows] /-- The `j`-th projection from the pullback. -/ noncomputable abbrev π (j : J) : widePullback _ _ arrows ⟶ objs j := limit.π (WidePullbackShape.wideCospan _ _ _) (Option.some j) #align category_theory.limits.wide_pullback.π CategoryTheory.Limits.WidePullback.π /-- The unique map to the base from the pullback. -/ noncomputable abbrev base : widePullback _ _ arrows ⟶ B := limit.π (WidePullbackShape.wideCospan _ _ _) Option.none #align category_theory.limits.wide_pullback.base CategoryTheory.Limits.WidePullback.base @[reassoc (attr := simp)] theorem π_arrow (j : J) : π arrows j ≫ arrows _ = base arrows := by apply limit.w (WidePullbackShape.wideCospan _ _ _) (WidePullbackShape.Hom.term j) #align category_theory.limits.wide_pullback.π_arrow CategoryTheory.Limits.WidePullback.π_arrow variable {arrows} /-- Lift a collection of morphisms to a morphism to the pullback. -/ noncomputable abbrev lift {X : C} (f : X ⟶ B) (fs : ∀ j : J, X ⟶ objs j) (w : ∀ j, fs j ≫ arrows j = f) : X ⟶ widePullback _ _ arrows := limit.lift (WidePullbackShape.wideCospan _ _ _) (WidePullbackShape.mkCone f fs <| w) #align category_theory.limits.wide_pullback.lift CategoryTheory.Limits.WidePullback.lift variable (arrows) variable {X : C} (f : X ⟶ B) (fs : ∀ j : J, X ⟶ objs j) (w : ∀ j, fs j ≫ arrows j = f) -- Porting note (#10618): simp can prove this so removed simp attribute @[reassoc] theorem lift_π (j : J) : lift f fs w ≫ π arrows j = fs _ := by simp only [limit.lift_π, WidePullbackShape.mkCone_pt, WidePullbackShape.mkCone_π_app] #align category_theory.limits.wide_pullback.lift_π CategoryTheory.Limits.WidePullback.lift_π -- Porting note (#10618): simp can prove this so removed simp attribute @[reassoc] theorem lift_base : lift f fs w ≫ base arrows = f := by simp only [limit.lift_π, WidePullbackShape.mkCone_pt, WidePullbackShape.mkCone_π_app] #align category_theory.limits.wide_pullback.lift_base CategoryTheory.Limits.WidePullback.lift_base
Mathlib/CategoryTheory/Limits/Shapes/WidePullbacks.lean
368
376
theorem eq_lift_of_comp_eq (g : X ⟶ widePullback _ _ arrows) : (∀ j : J, g ≫ π arrows j = fs j) → g ≫ base arrows = f → g = lift f fs w := by
intro h1 h2 apply (limit.isLimit (WidePullbackShape.wideCospan B objs arrows)).uniq (WidePullbackShape.mkCone f fs <| w) rintro (_ | _) · apply h2 · apply h1
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Chris Hughes, Anne Baanen -/ import Mathlib.Data.Matrix.Block import Mathlib.Data.Matrix.Notation import Mathlib.Data.Matrix.RowCol import Mathlib.GroupTheory.GroupAction.Ring import Mathlib.GroupTheory.Perm.Fin import Mathlib.LinearAlgebra.Alternating.Basic #align_import linear_algebra.matrix.determinant from "leanprover-community/mathlib"@"c3019c79074b0619edb4b27553a91b2e82242395" /-! # Determinant of a matrix This file defines the determinant of a matrix, `Matrix.det`, and its essential properties. ## Main definitions - `Matrix.det`: the determinant of a square matrix, as a sum over permutations - `Matrix.detRowAlternating`: the determinant, as an `AlternatingMap` in the rows of the matrix ## Main results - `det_mul`: the determinant of `A * B` is the product of determinants - `det_zero_of_row_eq`: the determinant is zero if there is a repeated row - `det_block_diagonal`: the determinant of a block diagonal matrix is a product of the blocks' determinants ## Implementation notes It is possible to configure `simp` to compute determinants. See the file `test/matrix.lean` for some examples. -/ universe u v w z open Equiv Equiv.Perm Finset Function namespace Matrix open Matrix variable {m n : Type*} [DecidableEq n] [Fintype n] [DecidableEq m] [Fintype m] variable {R : Type v} [CommRing R] local notation "ε " σ:arg => ((sign σ : ℤ) : R) /-- `det` is an `AlternatingMap` in the rows of the matrix. -/ def detRowAlternating : (n → R) [⋀^n]→ₗ[R] R := MultilinearMap.alternatization ((MultilinearMap.mkPiAlgebra R n R).compLinearMap LinearMap.proj) #align matrix.det_row_alternating Matrix.detRowAlternating /-- The determinant of a matrix given by the Leibniz formula. -/ abbrev det (M : Matrix n n R) : R := detRowAlternating M #align matrix.det Matrix.det theorem det_apply (M : Matrix n n R) : M.det = ∑ σ : Perm n, Equiv.Perm.sign σ • ∏ i, M (σ i) i := MultilinearMap.alternatization_apply _ M #align matrix.det_apply Matrix.det_apply -- This is what the old definition was. We use it to avoid having to change the old proofs below theorem det_apply' (M : Matrix n n R) : M.det = ∑ σ : Perm n, ε σ * ∏ i, M (σ i) i := by simp [det_apply, Units.smul_def] #align matrix.det_apply' Matrix.det_apply' @[simp] theorem det_diagonal {d : n → R} : det (diagonal d) = ∏ i, d i := by rw [det_apply'] refine (Finset.sum_eq_single 1 ?_ ?_).trans ?_ · rintro σ - h2 cases' not_forall.1 (mt Equiv.ext h2) with x h3 convert mul_zero (ε σ) apply Finset.prod_eq_zero (mem_univ x) exact if_neg h3 · simp · simp #align matrix.det_diagonal Matrix.det_diagonal -- @[simp] -- Porting note (#10618): simp can prove this theorem det_zero (_ : Nonempty n) : det (0 : Matrix n n R) = 0 := (detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_zero #align matrix.det_zero Matrix.det_zero @[simp] theorem det_one : det (1 : Matrix n n R) = 1 := by rw [← diagonal_one]; simp [-diagonal_one] #align matrix.det_one Matrix.det_one theorem det_isEmpty [IsEmpty n] {A : Matrix n n R} : det A = 1 := by simp [det_apply] #align matrix.det_is_empty Matrix.det_isEmpty @[simp] theorem coe_det_isEmpty [IsEmpty n] : (det : Matrix n n R → R) = Function.const _ 1 := by ext exact det_isEmpty #align matrix.coe_det_is_empty Matrix.coe_det_isEmpty theorem det_eq_one_of_card_eq_zero {A : Matrix n n R} (h : Fintype.card n = 0) : det A = 1 := haveI : IsEmpty n := Fintype.card_eq_zero_iff.mp h det_isEmpty #align matrix.det_eq_one_of_card_eq_zero Matrix.det_eq_one_of_card_eq_zero /-- If `n` has only one element, the determinant of an `n` by `n` matrix is just that element. Although `Unique` implies `DecidableEq` and `Fintype`, the instances might not be syntactically equal. Thus, we need to fill in the args explicitly. -/ @[simp] theorem det_unique {n : Type*} [Unique n] [DecidableEq n] [Fintype n] (A : Matrix n n R) : det A = A default default := by simp [det_apply, univ_unique] #align matrix.det_unique Matrix.det_unique theorem det_eq_elem_of_subsingleton [Subsingleton n] (A : Matrix n n R) (k : n) : det A = A k k := by have := uniqueOfSubsingleton k convert det_unique A #align matrix.det_eq_elem_of_subsingleton Matrix.det_eq_elem_of_subsingleton theorem det_eq_elem_of_card_eq_one {A : Matrix n n R} (h : Fintype.card n = 1) (k : n) : det A = A k k := haveI : Subsingleton n := Fintype.card_le_one_iff_subsingleton.mp h.le det_eq_elem_of_subsingleton _ _ #align matrix.det_eq_elem_of_card_eq_one Matrix.det_eq_elem_of_card_eq_one theorem det_mul_aux {M N : Matrix n n R} {p : n → n} (H : ¬Bijective p) : (∑ σ : Perm n, ε σ * ∏ x, M (σ x) (p x) * N (p x) x) = 0 := by obtain ⟨i, j, hpij, hij⟩ : ∃ i j, p i = p j ∧ i ≠ j := by rw [← Finite.injective_iff_bijective, Injective] at H push_neg at H exact H exact sum_involution (fun σ _ => σ * Equiv.swap i j) (fun σ _ => by have : (∏ x, M (σ x) (p x)) = ∏ x, M ((σ * Equiv.swap i j) x) (p x) := Fintype.prod_equiv (swap i j) _ _ (by simp [apply_swap_eq_self hpij]) simp [this, sign_swap hij, -sign_swap', prod_mul_distrib]) (fun σ _ _ => (not_congr mul_swap_eq_iff).mpr hij) (fun _ _ => mem_univ _) fun σ _ => mul_swap_involutive i j σ #align matrix.det_mul_aux Matrix.det_mul_aux @[simp] theorem det_mul (M N : Matrix n n R) : det (M * N) = det M * det N := calc det (M * N) = ∑ p : n → n, ∑ σ : Perm n, ε σ * ∏ i, M (σ i) (p i) * N (p i) i := by simp only [det_apply', mul_apply, prod_univ_sum, mul_sum, Fintype.piFinset_univ] rw [Finset.sum_comm] _ = ∑ p ∈ (@univ (n → n) _).filter Bijective, ∑ σ : Perm n, ε σ * ∏ i, M (σ i) (p i) * N (p i) i := (Eq.symm <| sum_subset (filter_subset _ _) fun f _ hbij => det_mul_aux <| by simpa only [true_and_iff, mem_filter, mem_univ] using hbij) _ = ∑ τ : Perm n, ∑ σ : Perm n, ε σ * ∏ i, M (σ i) (τ i) * N (τ i) i := sum_bij (fun p h ↦ Equiv.ofBijective p (mem_filter.1 h).2) (fun _ _ ↦ mem_univ _) (fun _ _ _ _ h ↦ by injection h) (fun b _ ↦ ⟨b, mem_filter.2 ⟨mem_univ _, b.bijective⟩, coe_fn_injective rfl⟩) fun _ _ ↦ rfl _ = ∑ σ : Perm n, ∑ τ : Perm n, (∏ i, N (σ i) i) * ε τ * ∏ j, M (τ j) (σ j) := by simp only [mul_comm, mul_left_comm, prod_mul_distrib, mul_assoc] _ = ∑ σ : Perm n, ∑ τ : Perm n, (∏ i, N (σ i) i) * (ε σ * ε τ) * ∏ i, M (τ i) i := (sum_congr rfl fun σ _ => Fintype.sum_equiv (Equiv.mulRight σ⁻¹) _ _ fun τ => by have : (∏ j, M (τ j) (σ j)) = ∏ j, M ((τ * σ⁻¹) j) j := by rw [← (σ⁻¹ : _ ≃ _).prod_comp] simp only [Equiv.Perm.coe_mul, apply_inv_self, Function.comp_apply] have h : ε σ * ε (τ * σ⁻¹) = ε τ := calc ε σ * ε (τ * σ⁻¹) = ε (τ * σ⁻¹ * σ) := by rw [mul_comm, sign_mul (τ * σ⁻¹)] simp only [Int.cast_mul, Units.val_mul] _ = ε τ := by simp only [inv_mul_cancel_right] simp_rw [Equiv.coe_mulRight, h] simp only [this]) _ = det M * det N := by simp only [det_apply', Finset.mul_sum, mul_comm, mul_left_comm, mul_assoc] #align matrix.det_mul Matrix.det_mul /-- The determinant of a matrix, as a monoid homomorphism. -/ def detMonoidHom : Matrix n n R →* R where toFun := det map_one' := det_one map_mul' := det_mul #align matrix.det_monoid_hom Matrix.detMonoidHom @[simp] theorem coe_detMonoidHom : (detMonoidHom : Matrix n n R → R) = det := rfl #align matrix.coe_det_monoid_hom Matrix.coe_detMonoidHom /-- On square matrices, `mul_comm` applies under `det`. -/ theorem det_mul_comm (M N : Matrix m m R) : det (M * N) = det (N * M) := by rw [det_mul, det_mul, mul_comm] #align matrix.det_mul_comm Matrix.det_mul_comm /-- On square matrices, `mul_left_comm` applies under `det`. -/ theorem det_mul_left_comm (M N P : Matrix m m R) : det (M * (N * P)) = det (N * (M * P)) := by rw [← Matrix.mul_assoc, ← Matrix.mul_assoc, det_mul, det_mul_comm M N, ← det_mul] #align matrix.det_mul_left_comm Matrix.det_mul_left_comm /-- On square matrices, `mul_right_comm` applies under `det`. -/ theorem det_mul_right_comm (M N P : Matrix m m R) : det (M * N * P) = det (M * P * N) := by rw [Matrix.mul_assoc, Matrix.mul_assoc, det_mul, det_mul_comm N P, ← det_mul] #align matrix.det_mul_right_comm Matrix.det_mul_right_comm -- TODO(mathlib4#6607): fix elaboration so that the ascription isn't needed theorem det_units_conj (M : (Matrix m m R)ˣ) (N : Matrix m m R) : det ((M : Matrix _ _ _) * N * (↑M⁻¹ : Matrix _ _ _)) = det N := by rw [det_mul_right_comm, Units.mul_inv, one_mul] #align matrix.det_units_conj Matrix.det_units_conj -- TODO(mathlib4#6607): fix elaboration so that the ascription isn't needed theorem det_units_conj' (M : (Matrix m m R)ˣ) (N : Matrix m m R) : det ((↑M⁻¹ : Matrix _ _ _) * N * (↑M : Matrix _ _ _)) = det N := det_units_conj M⁻¹ N #align matrix.det_units_conj' Matrix.det_units_conj' /-- Transposing a matrix preserves the determinant. -/ @[simp] theorem det_transpose (M : Matrix n n R) : Mᵀ.det = M.det := by rw [det_apply', det_apply'] refine Fintype.sum_bijective _ inv_involutive.bijective _ _ ?_ intro σ rw [sign_inv] congr 1 apply Fintype.prod_equiv σ intros simp #align matrix.det_transpose Matrix.det_transpose /-- Permuting the columns changes the sign of the determinant. -/ theorem det_permute (σ : Perm n) (M : Matrix n n R) : (M.submatrix σ id).det = Perm.sign σ * M.det := ((detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_perm M σ).trans (by simp [Units.smul_def]) #align matrix.det_permute Matrix.det_permute /-- Permuting the rows changes the sign of the determinant. -/ theorem det_permute' (σ : Perm n) (M : Matrix n n R) : (M.submatrix id σ).det = Perm.sign σ * M.det := by rw [← det_transpose, transpose_submatrix, det_permute, det_transpose] /-- Permuting rows and columns with the same equivalence has no effect. -/ @[simp] theorem det_submatrix_equiv_self (e : n ≃ m) (A : Matrix m m R) : det (A.submatrix e e) = det A := by rw [det_apply', det_apply'] apply Fintype.sum_equiv (Equiv.permCongr e) intro σ rw [Equiv.Perm.sign_permCongr e σ] congr 1 apply Fintype.prod_equiv e intro i rw [Equiv.permCongr_apply, Equiv.symm_apply_apply, submatrix_apply] #align matrix.det_submatrix_equiv_self Matrix.det_submatrix_equiv_self /-- Reindexing both indices along the same equivalence preserves the determinant. For the `simp` version of this lemma, see `det_submatrix_equiv_self`; this one is unsuitable because `Matrix.reindex_apply` unfolds `reindex` first. -/ theorem det_reindex_self (e : m ≃ n) (A : Matrix m m R) : det (reindex e e A) = det A := det_submatrix_equiv_self e.symm A #align matrix.det_reindex_self Matrix.det_reindex_self theorem det_smul (A : Matrix n n R) (c : R) : det (c • A) = c ^ Fintype.card n * det A := calc det (c • A) = det ((diagonal fun _ => c) * A) := by rw [smul_eq_diagonal_mul] _ = det (diagonal fun _ => c) * det A := det_mul _ _ _ = c ^ Fintype.card n * det A := by simp [card_univ] #align matrix.det_smul Matrix.det_smul @[simp] theorem det_smul_of_tower {α} [Monoid α] [DistribMulAction α R] [IsScalarTower α R R] [SMulCommClass α R R] (c : α) (A : Matrix n n R) : det (c • A) = c ^ Fintype.card n • det A := by rw [← smul_one_smul R c A, det_smul, smul_pow, one_pow, smul_mul_assoc, one_mul] #align matrix.det_smul_of_tower Matrix.det_smul_of_tower theorem det_neg (A : Matrix n n R) : det (-A) = (-1) ^ Fintype.card n * det A := by rw [← det_smul, neg_one_smul] #align matrix.det_neg Matrix.det_neg /-- A variant of `Matrix.det_neg` with scalar multiplication by `Units ℤ` instead of multiplication by `R`. -/ theorem det_neg_eq_smul (A : Matrix n n R) : det (-A) = (-1 : Units ℤ) ^ Fintype.card n • det A := by rw [← det_smul_of_tower, Units.neg_smul, one_smul] #align matrix.det_neg_eq_smul Matrix.det_neg_eq_smul /-- Multiplying each row by a fixed `v i` multiplies the determinant by the product of the `v`s. -/ theorem det_mul_row (v : n → R) (A : Matrix n n R) : det (of fun i j => v j * A i j) = (∏ i, v i) * det A := calc det (of fun i j => v j * A i j) = det (A * diagonal v) := congr_arg det <| by ext simp [mul_comm] _ = (∏ i, v i) * det A := by rw [det_mul, det_diagonal, mul_comm] #align matrix.det_mul_row Matrix.det_mul_row /-- Multiplying each column by a fixed `v j` multiplies the determinant by the product of the `v`s. -/ theorem det_mul_column (v : n → R) (A : Matrix n n R) : det (of fun i j => v i * A i j) = (∏ i, v i) * det A := MultilinearMap.map_smul_univ _ v A #align matrix.det_mul_column Matrix.det_mul_column @[simp] theorem det_pow (M : Matrix m m R) (n : ℕ) : det (M ^ n) = det M ^ n := (detMonoidHom : Matrix m m R →* R).map_pow M n #align matrix.det_pow Matrix.det_pow section HomMap variable {S : Type w} [CommRing S] theorem _root_.RingHom.map_det (f : R →+* S) (M : Matrix n n R) : f M.det = Matrix.det (f.mapMatrix M) := by simp [Matrix.det_apply', map_sum f, map_prod f] #align ring_hom.map_det RingHom.map_det theorem _root_.RingEquiv.map_det (f : R ≃+* S) (M : Matrix n n R) : f M.det = Matrix.det (f.mapMatrix M) := f.toRingHom.map_det _ #align ring_equiv.map_det RingEquiv.map_det theorem _root_.AlgHom.map_det [Algebra R S] {T : Type z} [CommRing T] [Algebra R T] (f : S →ₐ[R] T) (M : Matrix n n S) : f M.det = Matrix.det (f.mapMatrix M) := f.toRingHom.map_det _ #align alg_hom.map_det AlgHom.map_det theorem _root_.AlgEquiv.map_det [Algebra R S] {T : Type z} [CommRing T] [Algebra R T] (f : S ≃ₐ[R] T) (M : Matrix n n S) : f M.det = Matrix.det (f.mapMatrix M) := f.toAlgHom.map_det _ #align alg_equiv.map_det AlgEquiv.map_det end HomMap @[simp] theorem det_conjTranspose [StarRing R] (M : Matrix m m R) : det Mᴴ = star (det M) := ((starRingEnd R).map_det _).symm.trans <| congr_arg star M.det_transpose #align matrix.det_conj_transpose Matrix.det_conjTranspose section DetZero /-! ### `det_zero` section Prove that a matrix with a repeated column has determinant equal to zero. -/ theorem det_eq_zero_of_row_eq_zero {A : Matrix n n R} (i : n) (h : ∀ j, A i j = 0) : det A = 0 := (detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_coord_zero i (funext h) #align matrix.det_eq_zero_of_row_eq_zero Matrix.det_eq_zero_of_row_eq_zero theorem det_eq_zero_of_column_eq_zero {A : Matrix n n R} (j : n) (h : ∀ i, A i j = 0) : det A = 0 := by rw [← det_transpose] exact det_eq_zero_of_row_eq_zero j h #align matrix.det_eq_zero_of_column_eq_zero Matrix.det_eq_zero_of_column_eq_zero variable {M : Matrix n n R} {i j : n} /-- If a matrix has a repeated row, the determinant will be zero. -/ theorem det_zero_of_row_eq (i_ne_j : i ≠ j) (hij : M i = M j) : M.det = 0 := (detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_eq_zero_of_eq M hij i_ne_j #align matrix.det_zero_of_row_eq Matrix.det_zero_of_row_eq /-- If a matrix has a repeated column, the determinant will be zero. -/ theorem det_zero_of_column_eq (i_ne_j : i ≠ j) (hij : ∀ k, M k i = M k j) : M.det = 0 := by rw [← det_transpose, det_zero_of_row_eq i_ne_j] exact funext hij #align matrix.det_zero_of_column_eq Matrix.det_zero_of_column_eq /-- If we repeat a row of a matrix, we get a matrix of determinant zero. -/ theorem det_updateRow_eq_zero (h : i ≠ j) : (M.updateRow j (M i)).det = 0 := det_zero_of_row_eq h (by simp [h]) /-- If we repeat a column of a matrix, we get a matrix of determinant zero. -/ theorem det_updateColumn_eq_zero (h : i ≠ j) : (M.updateColumn j (fun k ↦ M k i)).det = 0 := det_zero_of_column_eq h (by simp [h]) end DetZero theorem det_updateRow_add (M : Matrix n n R) (j : n) (u v : n → R) : det (updateRow M j <| u + v) = det (updateRow M j u) + det (updateRow M j v) := (detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_add M j u v #align matrix.det_update_row_add Matrix.det_updateRow_add theorem det_updateColumn_add (M : Matrix n n R) (j : n) (u v : n → R) : det (updateColumn M j <| u + v) = det (updateColumn M j u) + det (updateColumn M j v) := by rw [← det_transpose, ← updateRow_transpose, det_updateRow_add] simp [updateRow_transpose, det_transpose] #align matrix.det_update_column_add Matrix.det_updateColumn_add theorem det_updateRow_smul (M : Matrix n n R) (j : n) (s : R) (u : n → R) : det (updateRow M j <| s • u) = s * det (updateRow M j u) := (detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_smul M j s u #align matrix.det_update_row_smul Matrix.det_updateRow_smul theorem det_updateColumn_smul (M : Matrix n n R) (j : n) (s : R) (u : n → R) : det (updateColumn M j <| s • u) = s * det (updateColumn M j u) := by rw [← det_transpose, ← updateRow_transpose, det_updateRow_smul] simp [updateRow_transpose, det_transpose] #align matrix.det_update_column_smul Matrix.det_updateColumn_smul theorem det_updateRow_smul' (M : Matrix n n R) (j : n) (s : R) (u : n → R) : det (updateRow (s • M) j u) = s ^ (Fintype.card n - 1) * det (updateRow M j u) := MultilinearMap.map_update_smul _ M j s u #align matrix.det_update_row_smul' Matrix.det_updateRow_smul' theorem det_updateColumn_smul' (M : Matrix n n R) (j : n) (s : R) (u : n → R) : det (updateColumn (s • M) j u) = s ^ (Fintype.card n - 1) * det (updateColumn M j u) := by rw [← det_transpose, ← updateRow_transpose, transpose_smul, det_updateRow_smul'] simp [updateRow_transpose, det_transpose] #align matrix.det_update_column_smul' Matrix.det_updateColumn_smul' theorem det_updateRow_sum_aux (M : Matrix n n R) {j : n} (s : Finset n) (hj : j ∉ s) (c : n → R) (a : R) : (M.updateRow j (a • M j + ∑ k ∈ s, (c k) • M k)).det = a • M.det := by induction s using Finset.induction_on with | empty => rw [Finset.sum_empty, add_zero, smul_eq_mul, det_updateRow_smul, updateRow_eq_self] | @insert k _ hk h_ind => have h : k ≠ j := fun h ↦ (h ▸ hj) (Finset.mem_insert_self _ _) rw [Finset.sum_insert hk, add_comm ((c k) • M k), ← add_assoc, det_updateRow_add, det_updateRow_smul, det_updateRow_eq_zero h, mul_zero, add_zero, h_ind] exact fun h ↦ hj (Finset.mem_insert_of_mem h) /-- If we replace a row of a matrix by a linear combination of its rows, then the determinant is multiplied by the coefficient of that row. -/ theorem det_updateRow_sum (A : Matrix n n R) (j : n) (c : n → R) : (A.updateRow j (∑ k, (c k) • A k)).det = (c j) • A.det := by convert det_updateRow_sum_aux A (Finset.univ.erase j) (Finset.univ.not_mem_erase j) c (c j) rw [← Finset.univ.add_sum_erase _ (Finset.mem_univ j)] /-- If we replace a column of a matrix by a linear combination of its columns, then the determinant is multiplied by the coefficient of that column. -/ theorem det_updateColumn_sum (A : Matrix n n R) (j : n) (c : n → R) : (A.updateColumn j (fun k ↦ ∑ i, (c i) • A k i)).det = (c j) • A.det := by rw [← det_transpose, ← updateRow_transpose, ← det_transpose A] convert det_updateRow_sum A.transpose j c simp only [smul_eq_mul, Finset.sum_apply, Pi.smul_apply, transpose_apply] section DetEq /-! ### `det_eq` section Lemmas showing the determinant is invariant under a variety of operations. -/ theorem det_eq_of_eq_mul_det_one {A B : Matrix n n R} (C : Matrix n n R) (hC : det C = 1) (hA : A = B * C) : det A = det B := calc det A = det (B * C) := congr_arg _ hA _ = det B * det C := det_mul _ _ _ = det B := by rw [hC, mul_one] #align matrix.det_eq_of_eq_mul_det_one Matrix.det_eq_of_eq_mul_det_one theorem det_eq_of_eq_det_one_mul {A B : Matrix n n R} (C : Matrix n n R) (hC : det C = 1) (hA : A = C * B) : det A = det B := calc det A = det (C * B) := congr_arg _ hA _ = det C * det B := det_mul _ _ _ = det B := by rw [hC, one_mul] #align matrix.det_eq_of_eq_det_one_mul Matrix.det_eq_of_eq_det_one_mul theorem det_updateRow_add_self (A : Matrix n n R) {i j : n} (hij : i ≠ j) : det (updateRow A i (A i + A j)) = det A := by simp [det_updateRow_add, det_zero_of_row_eq hij (updateRow_self.trans (updateRow_ne hij.symm).symm)] #align matrix.det_update_row_add_self Matrix.det_updateRow_add_self theorem det_updateColumn_add_self (A : Matrix n n R) {i j : n} (hij : i ≠ j) : det (updateColumn A i fun k => A k i + A k j) = det A := by rw [← det_transpose, ← updateRow_transpose, ← det_transpose A] exact det_updateRow_add_self Aᵀ hij #align matrix.det_update_column_add_self Matrix.det_updateColumn_add_self theorem det_updateRow_add_smul_self (A : Matrix n n R) {i j : n} (hij : i ≠ j) (c : R) : det (updateRow A i (A i + c • A j)) = det A := by simp [det_updateRow_add, det_updateRow_smul, det_zero_of_row_eq hij (updateRow_self.trans (updateRow_ne hij.symm).symm)] #align matrix.det_update_row_add_smul_self Matrix.det_updateRow_add_smul_self theorem det_updateColumn_add_smul_self (A : Matrix n n R) {i j : n} (hij : i ≠ j) (c : R) : det (updateColumn A i fun k => A k i + c • A k j) = det A := by rw [← det_transpose, ← updateRow_transpose, ← det_transpose A] exact det_updateRow_add_smul_self Aᵀ hij c #align matrix.det_update_column_add_smul_self Matrix.det_updateColumn_add_smul_self theorem det_eq_of_forall_row_eq_smul_add_const_aux {A B : Matrix n n R} {s : Finset n} : ∀ (c : n → R) (_ : ∀ i, i ∉ s → c i = 0) (k : n) (_ : k ∉ s) (_: ∀ i j, A i j = B i j + c i * B k j), det A = det B := by induction s using Finset.induction_on generalizing B with | empty => rintro c hs k - A_eq have : ∀ i, c i = 0 := by intro i specialize hs i contrapose! hs simp [hs] congr ext i j rw [A_eq, this, zero_mul, add_zero] | @insert i s _hi ih => intro c hs k hk A_eq have hAi : A i = B i + c i • B k := funext (A_eq i) rw [@ih (updateRow B i (A i)) (Function.update c i 0), hAi, det_updateRow_add_smul_self] · exact mt (fun h => show k ∈ insert i s from h ▸ Finset.mem_insert_self _ _) hk · intro i' hi' rw [Function.update_apply] split_ifs with hi'i · rfl · exact hs i' fun h => hi' ((Finset.mem_insert.mp h).resolve_left hi'i) · exact k · exact fun h => hk (Finset.mem_insert_of_mem h) · intro i' j' rw [updateRow_apply, Function.update_apply] split_ifs with hi'i · simp [hi'i] rw [A_eq, updateRow_ne fun h : k = i => hk <| h ▸ Finset.mem_insert_self k s] #align matrix.det_eq_of_forall_row_eq_smul_add_const_aux Matrix.det_eq_of_forall_row_eq_smul_add_const_aux /-- If you add multiples of row `B k` to other rows, the determinant doesn't change. -/ theorem det_eq_of_forall_row_eq_smul_add_const {A B : Matrix n n R} (c : n → R) (k : n) (hk : c k = 0) (A_eq : ∀ i j, A i j = B i j + c i * B k j) : det A = det B := det_eq_of_forall_row_eq_smul_add_const_aux c (fun i => not_imp_comm.mp fun hi => Finset.mem_erase.mpr ⟨mt (fun h : i = k => show c i = 0 from h.symm ▸ hk) hi, Finset.mem_univ i⟩) k (Finset.not_mem_erase k Finset.univ) A_eq #align matrix.det_eq_of_forall_row_eq_smul_add_const Matrix.det_eq_of_forall_row_eq_smul_add_const theorem det_eq_of_forall_row_eq_smul_add_pred_aux {n : ℕ} (k : Fin (n + 1)) : ∀ (c : Fin n → R) (_hc : ∀ i : Fin n, k < i.succ → c i = 0) {M N : Matrix (Fin n.succ) (Fin n.succ) R} (_h0 : ∀ j, M 0 j = N 0 j) (_hsucc : ∀ (i : Fin n) (j), M i.succ j = N i.succ j + c i * M (Fin.castSucc i) j), det M = det N := by refine Fin.induction ?_ (fun k ih => ?_) k <;> intro c hc M N h0 hsucc · congr ext i j refine Fin.cases (h0 j) (fun i => ?_) i rw [hsucc, hc i (Fin.succ_pos _), zero_mul, add_zero] set M' := updateRow M k.succ (N k.succ) with hM' have hM : M = updateRow M' k.succ (M' k.succ + c k • M (Fin.castSucc k)) := by ext i j by_cases hi : i = k.succ · simp [hi, hM', hsucc, updateRow_self] rw [updateRow_ne hi, hM', updateRow_ne hi] have k_ne_succ : (Fin.castSucc k) ≠ k.succ := (Fin.castSucc_lt_succ k).ne have M_k : M (Fin.castSucc k) = M' (Fin.castSucc k) := (updateRow_ne k_ne_succ).symm rw [hM, M_k, det_updateRow_add_smul_self M' k_ne_succ.symm, ih (Function.update c k 0)] · intro i hi rw [Fin.lt_iff_val_lt_val, Fin.coe_castSucc, Fin.val_succ, Nat.lt_succ_iff] at hi rw [Function.update_apply] split_ifs with hik · rfl exact hc _ (Fin.succ_lt_succ_iff.mpr (lt_of_le_of_ne hi (Ne.symm hik))) · rwa [hM', updateRow_ne (Fin.succ_ne_zero _).symm] intro i j rw [Function.update_apply] split_ifs with hik · rw [zero_mul, add_zero, hM', hik, updateRow_self] rw [hM', updateRow_ne ((Fin.succ_injective _).ne hik), hsucc] by_cases hik2 : k < i · simp [hc i (Fin.succ_lt_succ_iff.mpr hik2)] rw [updateRow_ne] apply ne_of_lt rwa [Fin.lt_iff_val_lt_val, Fin.coe_castSucc, Fin.val_succ, Nat.lt_succ_iff, ← not_lt] #align matrix.det_eq_of_forall_row_eq_smul_add_pred_aux Matrix.det_eq_of_forall_row_eq_smul_add_pred_aux /-- If you add multiples of previous rows to the next row, the determinant doesn't change. -/ theorem det_eq_of_forall_row_eq_smul_add_pred {n : ℕ} {A B : Matrix (Fin (n + 1)) (Fin (n + 1)) R} (c : Fin n → R) (A_zero : ∀ j, A 0 j = B 0 j) (A_succ : ∀ (i : Fin n) (j), A i.succ j = B i.succ j + c i * A (Fin.castSucc i) j) : det A = det B := det_eq_of_forall_row_eq_smul_add_pred_aux (Fin.last _) c (fun _ hi => absurd hi (not_lt_of_ge (Fin.le_last _))) A_zero A_succ #align matrix.det_eq_of_forall_row_eq_smul_add_pred Matrix.det_eq_of_forall_row_eq_smul_add_pred /-- If you add multiples of previous columns to the next columns, the determinant doesn't change. -/ theorem det_eq_of_forall_col_eq_smul_add_pred {n : ℕ} {A B : Matrix (Fin (n + 1)) (Fin (n + 1)) R} (c : Fin n → R) (A_zero : ∀ i, A i 0 = B i 0) (A_succ : ∀ (i) (j : Fin n), A i j.succ = B i j.succ + c j * A i (Fin.castSucc j)) : det A = det B := by rw [← det_transpose A, ← det_transpose B] exact det_eq_of_forall_row_eq_smul_add_pred c A_zero fun i j => A_succ j i #align matrix.det_eq_of_forall_col_eq_smul_add_pred Matrix.det_eq_of_forall_col_eq_smul_add_pred end DetEq @[simp]
Mathlib/LinearAlgebra/Matrix/Determinant/Basic.lean
599
664
theorem det_blockDiagonal {o : Type*} [Fintype o] [DecidableEq o] (M : o → Matrix n n R) : (blockDiagonal M).det = ∏ k, (M k).det := by
-- Rewrite the determinants as a sum over permutations. simp_rw [det_apply'] -- The right hand side is a product of sums, rewrite it as a sum of products. rw [Finset.prod_sum] simp_rw [Finset.prod_attach_univ, Finset.univ_pi_univ] -- We claim that the only permutations contributing to the sum are those that -- preserve their second component. let preserving_snd : Finset (Equiv.Perm (n × o)) := Finset.univ.filter fun σ => ∀ x, (σ x).snd = x.snd have mem_preserving_snd : ∀ {σ : Equiv.Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ x, (σ x).snd = x.snd := fun {σ} => Finset.mem_filter.trans ⟨fun h => h.2, fun h => ⟨Finset.mem_univ _, h⟩⟩ rw [← Finset.sum_subset (Finset.subset_univ preserving_snd) _] -- And that these are in bijection with `o → Equiv.Perm m`. · refine (Finset.sum_bij (fun σ _ => prodCongrLeft fun k ↦ σ k (mem_univ k)) ?_ ?_ ?_ ?_).symm · intro σ _ rw [mem_preserving_snd] rintro ⟨-, x⟩ simp only [prodCongrLeft_apply] · intro σ _ σ' _ eq ext x hx k simp only at eq have : ∀ k x, prodCongrLeft (fun k => σ k (Finset.mem_univ _)) (k, x) = prodCongrLeft (fun k => σ' k (Finset.mem_univ _)) (k, x) := fun k x => by rw [eq] simp only [prodCongrLeft_apply, Prod.mk.inj_iff] at this exact (this k x).1 · intro σ hσ rw [mem_preserving_snd] at hσ have hσ' : ∀ x, (σ⁻¹ x).snd = x.snd := by intro x conv_rhs => rw [← Perm.apply_inv_self σ x, hσ] have mk_apply_eq : ∀ k x, ((σ (x, k)).fst, k) = σ (x, k) := by intro k x ext · simp only · simp only [hσ] have mk_inv_apply_eq : ∀ k x, ((σ⁻¹ (x, k)).fst, k) = σ⁻¹ (x, k) := by intro k x conv_lhs => rw [← Perm.apply_inv_self σ (x, k)] ext · simp only [apply_inv_self] · simp only [hσ'] refine ⟨fun k _ => ⟨fun x => (σ (x, k)).fst, fun x => (σ⁻¹ (x, k)).fst, ?_, ?_⟩, ?_, ?_⟩ · intro x simp only [mk_apply_eq, inv_apply_self] · intro x simp only [mk_inv_apply_eq, apply_inv_self] · apply Finset.mem_univ · ext ⟨k, x⟩ · simp only [coe_fn_mk, prodCongrLeft_apply] · simp only [prodCongrLeft_apply, hσ] · intro σ _ rw [Finset.prod_mul_distrib, ← Finset.univ_product_univ, Finset.prod_product_right] simp only [sign_prodCongrLeft, Units.coe_prod, Int.cast_prod, blockDiagonal_apply_eq, prodCongrLeft_apply] · intro σ _ hσ rw [mem_preserving_snd] at hσ obtain ⟨⟨k, x⟩, hkx⟩ := not_forall.mp hσ rw [Finset.prod_eq_zero (Finset.mem_univ (k, x)), mul_zero] rw [blockDiagonal_apply_ne] exact hkx
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Algebra.MonoidAlgebra.Degree import Mathlib.Algebra.Polynomial.Coeff import Mathlib.Algebra.Polynomial.Monomial import Mathlib.Data.Fintype.BigOperators import Mathlib.Data.Nat.WithBot import Mathlib.Data.Nat.Cast.WithTop import Mathlib.Data.Nat.SuccPred #align_import data.polynomial.degree.definitions from "leanprover-community/mathlib"@"808ea4ebfabeb599f21ec4ae87d6dc969597887f" /-! # Theory of univariate polynomials The definitions include `degree`, `Monic`, `leadingCoeff` Results include - `degree_mul` : The degree of the product is the sum of degrees - `leadingCoeff_add_of_degree_eq` and `leadingCoeff_add_of_degree_lt` : The leading_coefficient of a sum is determined by the leading coefficients and degrees -/ -- Porting note: `Mathlib.Data.Nat.Cast.WithTop` should be imported for `Nat.cast_withBot`. set_option linter.uppercaseLean3 false noncomputable section open Finsupp Finset open Polynomial namespace Polynomial universe u v variable {R : Type u} {S : Type v} {a b c d : R} {n m : ℕ} section Semiring variable [Semiring R] {p q r : R[X]} /-- `degree p` is the degree of the polynomial `p`, i.e. the largest `X`-exponent in `p`. `degree p = some n` when `p ≠ 0` and `n` is the highest power of `X` that appears in `p`, otherwise `degree 0 = ⊥`. -/ def degree (p : R[X]) : WithBot ℕ := p.support.max #align polynomial.degree Polynomial.degree theorem supDegree_eq_degree (p : R[X]) : p.toFinsupp.supDegree WithBot.some = p.degree := max_eq_sup_coe theorem degree_lt_wf : WellFounded fun p q : R[X] => degree p < degree q := InvImage.wf degree wellFounded_lt #align polynomial.degree_lt_wf Polynomial.degree_lt_wf instance : WellFoundedRelation R[X] := ⟨_, degree_lt_wf⟩ /-- `natDegree p` forces `degree p` to ℕ, by defining `natDegree 0 = 0`. -/ def natDegree (p : R[X]) : ℕ := (degree p).unbot' 0 #align polynomial.nat_degree Polynomial.natDegree /-- `leadingCoeff p` gives the coefficient of the highest power of `X` in `p`-/ def leadingCoeff (p : R[X]) : R := coeff p (natDegree p) #align polynomial.leading_coeff Polynomial.leadingCoeff /-- a polynomial is `Monic` if its leading coefficient is 1 -/ def Monic (p : R[X]) := leadingCoeff p = (1 : R) #align polynomial.monic Polynomial.Monic @[nontriviality] theorem monic_of_subsingleton [Subsingleton R] (p : R[X]) : Monic p := Subsingleton.elim _ _ #align polynomial.monic_of_subsingleton Polynomial.monic_of_subsingleton theorem Monic.def : Monic p ↔ leadingCoeff p = 1 := Iff.rfl #align polynomial.monic.def Polynomial.Monic.def instance Monic.decidable [DecidableEq R] : Decidable (Monic p) := by unfold Monic; infer_instance #align polynomial.monic.decidable Polynomial.Monic.decidable @[simp] theorem Monic.leadingCoeff {p : R[X]} (hp : p.Monic) : leadingCoeff p = 1 := hp #align polynomial.monic.leading_coeff Polynomial.Monic.leadingCoeff theorem Monic.coeff_natDegree {p : R[X]} (hp : p.Monic) : p.coeff p.natDegree = 1 := hp #align polynomial.monic.coeff_nat_degree Polynomial.Monic.coeff_natDegree @[simp] theorem degree_zero : degree (0 : R[X]) = ⊥ := rfl #align polynomial.degree_zero Polynomial.degree_zero @[simp] theorem natDegree_zero : natDegree (0 : R[X]) = 0 := rfl #align polynomial.nat_degree_zero Polynomial.natDegree_zero @[simp] theorem coeff_natDegree : coeff p (natDegree p) = leadingCoeff p := rfl #align polynomial.coeff_nat_degree Polynomial.coeff_natDegree @[simp] theorem degree_eq_bot : degree p = ⊥ ↔ p = 0 := ⟨fun h => support_eq_empty.1 (Finset.max_eq_bot.1 h), fun h => h.symm ▸ rfl⟩ #align polynomial.degree_eq_bot Polynomial.degree_eq_bot @[nontriviality] theorem degree_of_subsingleton [Subsingleton R] : degree p = ⊥ := by rw [Subsingleton.elim p 0, degree_zero] #align polynomial.degree_of_subsingleton Polynomial.degree_of_subsingleton @[nontriviality] theorem natDegree_of_subsingleton [Subsingleton R] : natDegree p = 0 := by rw [Subsingleton.elim p 0, natDegree_zero] #align polynomial.nat_degree_of_subsingleton Polynomial.natDegree_of_subsingleton theorem degree_eq_natDegree (hp : p ≠ 0) : degree p = (natDegree p : WithBot ℕ) := by let ⟨n, hn⟩ := not_forall.1 (mt Option.eq_none_iff_forall_not_mem.2 (mt degree_eq_bot.1 hp)) have hn : degree p = some n := Classical.not_not.1 hn rw [natDegree, hn]; rfl #align polynomial.degree_eq_nat_degree Polynomial.degree_eq_natDegree theorem supDegree_eq_natDegree (p : R[X]) : p.toFinsupp.supDegree id = p.natDegree := by obtain rfl|h := eq_or_ne p 0 · simp apply WithBot.coe_injective rw [← AddMonoidAlgebra.supDegree_withBot_some_comp, Function.comp_id, supDegree_eq_degree, degree_eq_natDegree h, Nat.cast_withBot] rwa [support_toFinsupp, nonempty_iff_ne_empty, Ne, support_eq_empty] theorem degree_eq_iff_natDegree_eq {p : R[X]} {n : ℕ} (hp : p ≠ 0) : p.degree = n ↔ p.natDegree = n := by rw [degree_eq_natDegree hp]; exact WithBot.coe_eq_coe #align polynomial.degree_eq_iff_nat_degree_eq Polynomial.degree_eq_iff_natDegree_eq theorem degree_eq_iff_natDegree_eq_of_pos {p : R[X]} {n : ℕ} (hn : 0 < n) : p.degree = n ↔ p.natDegree = n := by obtain rfl|h := eq_or_ne p 0 · simp [hn.ne] · exact degree_eq_iff_natDegree_eq h #align polynomial.degree_eq_iff_nat_degree_eq_of_pos Polynomial.degree_eq_iff_natDegree_eq_of_pos theorem natDegree_eq_of_degree_eq_some {p : R[X]} {n : ℕ} (h : degree p = n) : natDegree p = n := by -- Porting note: `Nat.cast_withBot` is required. rw [natDegree, h, Nat.cast_withBot, WithBot.unbot'_coe] #align polynomial.nat_degree_eq_of_degree_eq_some Polynomial.natDegree_eq_of_degree_eq_some theorem degree_ne_of_natDegree_ne {n : ℕ} : p.natDegree ≠ n → degree p ≠ n := mt natDegree_eq_of_degree_eq_some #align polynomial.degree_ne_of_nat_degree_ne Polynomial.degree_ne_of_natDegree_ne @[simp] theorem degree_le_natDegree : degree p ≤ natDegree p := WithBot.giUnbot'Bot.gc.le_u_l _ #align polynomial.degree_le_nat_degree Polynomial.degree_le_natDegree theorem natDegree_eq_of_degree_eq [Semiring S] {q : S[X]} (h : degree p = degree q) : natDegree p = natDegree q := by unfold natDegree; rw [h] #align polynomial.nat_degree_eq_of_degree_eq Polynomial.natDegree_eq_of_degree_eq theorem le_degree_of_ne_zero (h : coeff p n ≠ 0) : (n : WithBot ℕ) ≤ degree p := by rw [Nat.cast_withBot] exact Finset.le_sup (mem_support_iff.2 h) #align polynomial.le_degree_of_ne_zero Polynomial.le_degree_of_ne_zero theorem le_natDegree_of_ne_zero (h : coeff p n ≠ 0) : n ≤ natDegree p := by rw [← Nat.cast_le (α := WithBot ℕ), ← degree_eq_natDegree] · exact le_degree_of_ne_zero h · rintro rfl exact h rfl #align polynomial.le_nat_degree_of_ne_zero Polynomial.le_natDegree_of_ne_zero theorem le_natDegree_of_mem_supp (a : ℕ) : a ∈ p.support → a ≤ natDegree p := le_natDegree_of_ne_zero ∘ mem_support_iff.mp #align polynomial.le_nat_degree_of_mem_supp Polynomial.le_natDegree_of_mem_supp theorem degree_eq_of_le_of_coeff_ne_zero (pn : p.degree ≤ n) (p1 : p.coeff n ≠ 0) : p.degree = n := pn.antisymm (le_degree_of_ne_zero p1) #align polynomial.degree_eq_of_le_of_coeff_ne_zero Polynomial.degree_eq_of_le_of_coeff_ne_zero theorem natDegree_eq_of_le_of_coeff_ne_zero (pn : p.natDegree ≤ n) (p1 : p.coeff n ≠ 0) : p.natDegree = n := pn.antisymm (le_natDegree_of_ne_zero p1) #align polynomial.nat_degree_eq_of_le_of_coeff_ne_zero Polynomial.natDegree_eq_of_le_of_coeff_ne_zero theorem degree_mono [Semiring S] {f : R[X]} {g : S[X]} (h : f.support ⊆ g.support) : f.degree ≤ g.degree := Finset.sup_mono h #align polynomial.degree_mono Polynomial.degree_mono theorem supp_subset_range (h : natDegree p < m) : p.support ⊆ Finset.range m := fun _n hn => mem_range.2 <| (le_natDegree_of_mem_supp _ hn).trans_lt h #align polynomial.supp_subset_range Polynomial.supp_subset_range theorem supp_subset_range_natDegree_succ : p.support ⊆ Finset.range (natDegree p + 1) := supp_subset_range (Nat.lt_succ_self _) #align polynomial.supp_subset_range_nat_degree_succ Polynomial.supp_subset_range_natDegree_succ theorem degree_le_degree (h : coeff q (natDegree p) ≠ 0) : degree p ≤ degree q := by by_cases hp : p = 0 · rw [hp, degree_zero] exact bot_le · rw [degree_eq_natDegree hp] exact le_degree_of_ne_zero h #align polynomial.degree_le_degree Polynomial.degree_le_degree theorem natDegree_le_iff_degree_le {n : ℕ} : natDegree p ≤ n ↔ degree p ≤ n := WithBot.unbot'_le_iff (fun _ ↦ bot_le) #align polynomial.nat_degree_le_iff_degree_le Polynomial.natDegree_le_iff_degree_le theorem natDegree_lt_iff_degree_lt (hp : p ≠ 0) : p.natDegree < n ↔ p.degree < ↑n := WithBot.unbot'_lt_iff (absurd · (degree_eq_bot.not.mpr hp)) #align polynomial.nat_degree_lt_iff_degree_lt Polynomial.natDegree_lt_iff_degree_lt alias ⟨degree_le_of_natDegree_le, natDegree_le_of_degree_le⟩ := natDegree_le_iff_degree_le #align polynomial.degree_le_of_nat_degree_le Polynomial.degree_le_of_natDegree_le #align polynomial.nat_degree_le_of_degree_le Polynomial.natDegree_le_of_degree_le theorem natDegree_le_natDegree [Semiring S] {q : S[X]} (hpq : p.degree ≤ q.degree) : p.natDegree ≤ q.natDegree := WithBot.giUnbot'Bot.gc.monotone_l hpq #align polynomial.nat_degree_le_nat_degree Polynomial.natDegree_le_natDegree theorem natDegree_lt_natDegree {p q : R[X]} (hp : p ≠ 0) (hpq : p.degree < q.degree) : p.natDegree < q.natDegree := by by_cases hq : q = 0 · exact (not_lt_bot <| hq ▸ hpq).elim rwa [degree_eq_natDegree hp, degree_eq_natDegree hq, Nat.cast_lt] at hpq #align polynomial.nat_degree_lt_nat_degree Polynomial.natDegree_lt_natDegree @[simp] theorem degree_C (ha : a ≠ 0) : degree (C a) = (0 : WithBot ℕ) := by rw [degree, ← monomial_zero_left, support_monomial 0 ha, max_eq_sup_coe, sup_singleton, WithBot.coe_zero] #align polynomial.degree_C Polynomial.degree_C theorem degree_C_le : degree (C a) ≤ 0 := by by_cases h : a = 0 · rw [h, C_0] exact bot_le · rw [degree_C h] #align polynomial.degree_C_le Polynomial.degree_C_le theorem degree_C_lt : degree (C a) < 1 := degree_C_le.trans_lt <| WithBot.coe_lt_coe.mpr zero_lt_one #align polynomial.degree_C_lt Polynomial.degree_C_lt theorem degree_one_le : degree (1 : R[X]) ≤ (0 : WithBot ℕ) := by rw [← C_1]; exact degree_C_le #align polynomial.degree_one_le Polynomial.degree_one_le @[simp] theorem natDegree_C (a : R) : natDegree (C a) = 0 := by by_cases ha : a = 0 · have : C a = 0 := by rw [ha, C_0] rw [natDegree, degree_eq_bot.2 this, WithBot.unbot'_bot] · rw [natDegree, degree_C ha, WithBot.unbot_zero'] #align polynomial.nat_degree_C Polynomial.natDegree_C @[simp] theorem natDegree_one : natDegree (1 : R[X]) = 0 := natDegree_C 1 #align polynomial.nat_degree_one Polynomial.natDegree_one @[simp] theorem natDegree_natCast (n : ℕ) : natDegree (n : R[X]) = 0 := by simp only [← C_eq_natCast, natDegree_C] #align polynomial.nat_degree_nat_cast Polynomial.natDegree_natCast @[deprecated (since := "2024-04-17")] alias natDegree_nat_cast := natDegree_natCast theorem degree_natCast_le (n : ℕ) : degree (n : R[X]) ≤ 0 := degree_le_of_natDegree_le (by simp) @[deprecated (since := "2024-04-17")] alias degree_nat_cast_le := degree_natCast_le @[simp] theorem degree_monomial (n : ℕ) (ha : a ≠ 0) : degree (monomial n a) = n := by rw [degree, support_monomial n ha, max_singleton, Nat.cast_withBot] #align polynomial.degree_monomial Polynomial.degree_monomial @[simp] theorem degree_C_mul_X_pow (n : ℕ) (ha : a ≠ 0) : degree (C a * X ^ n) = n := by rw [C_mul_X_pow_eq_monomial, degree_monomial n ha] #align polynomial.degree_C_mul_X_pow Polynomial.degree_C_mul_X_pow theorem degree_C_mul_X (ha : a ≠ 0) : degree (C a * X) = 1 := by simpa only [pow_one] using degree_C_mul_X_pow 1 ha #align polynomial.degree_C_mul_X Polynomial.degree_C_mul_X theorem degree_monomial_le (n : ℕ) (a : R) : degree (monomial n a) ≤ n := letI := Classical.decEq R if h : a = 0 then by rw [h, (monomial n).map_zero, degree_zero]; exact bot_le else le_of_eq (degree_monomial n h) #align polynomial.degree_monomial_le Polynomial.degree_monomial_le theorem degree_C_mul_X_pow_le (n : ℕ) (a : R) : degree (C a * X ^ n) ≤ n := by rw [C_mul_X_pow_eq_monomial] apply degree_monomial_le #align polynomial.degree_C_mul_X_pow_le Polynomial.degree_C_mul_X_pow_le theorem degree_C_mul_X_le (a : R) : degree (C a * X) ≤ 1 := by simpa only [pow_one] using degree_C_mul_X_pow_le 1 a #align polynomial.degree_C_mul_X_le Polynomial.degree_C_mul_X_le @[simp] theorem natDegree_C_mul_X_pow (n : ℕ) (a : R) (ha : a ≠ 0) : natDegree (C a * X ^ n) = n := natDegree_eq_of_degree_eq_some (degree_C_mul_X_pow n ha) #align polynomial.nat_degree_C_mul_X_pow Polynomial.natDegree_C_mul_X_pow @[simp] theorem natDegree_C_mul_X (a : R) (ha : a ≠ 0) : natDegree (C a * X) = 1 := by simpa only [pow_one] using natDegree_C_mul_X_pow 1 a ha #align polynomial.nat_degree_C_mul_X Polynomial.natDegree_C_mul_X @[simp] theorem natDegree_monomial [DecidableEq R] (i : ℕ) (r : R) : natDegree (monomial i r) = if r = 0 then 0 else i := by split_ifs with hr · simp [hr] · rw [← C_mul_X_pow_eq_monomial, natDegree_C_mul_X_pow i r hr] #align polynomial.nat_degree_monomial Polynomial.natDegree_monomial theorem natDegree_monomial_le (a : R) {m : ℕ} : (monomial m a).natDegree ≤ m := by classical rw [Polynomial.natDegree_monomial] split_ifs exacts [Nat.zero_le _, le_rfl] #align polynomial.nat_degree_monomial_le Polynomial.natDegree_monomial_le theorem natDegree_monomial_eq (i : ℕ) {r : R} (r0 : r ≠ 0) : (monomial i r).natDegree = i := letI := Classical.decEq R Eq.trans (natDegree_monomial _ _) (if_neg r0) #align polynomial.nat_degree_monomial_eq Polynomial.natDegree_monomial_eq theorem coeff_eq_zero_of_degree_lt (h : degree p < n) : coeff p n = 0 := Classical.not_not.1 (mt le_degree_of_ne_zero (not_le_of_gt h)) #align polynomial.coeff_eq_zero_of_degree_lt Polynomial.coeff_eq_zero_of_degree_lt theorem coeff_eq_zero_of_natDegree_lt {p : R[X]} {n : ℕ} (h : p.natDegree < n) : p.coeff n = 0 := by apply coeff_eq_zero_of_degree_lt by_cases hp : p = 0 · subst hp exact WithBot.bot_lt_coe n · rwa [degree_eq_natDegree hp, Nat.cast_lt] #align polynomial.coeff_eq_zero_of_nat_degree_lt Polynomial.coeff_eq_zero_of_natDegree_lt theorem ext_iff_natDegree_le {p q : R[X]} {n : ℕ} (hp : p.natDegree ≤ n) (hq : q.natDegree ≤ n) : p = q ↔ ∀ i ≤ n, p.coeff i = q.coeff i := by refine Iff.trans Polynomial.ext_iff ?_ refine forall_congr' fun i => ⟨fun h _ => h, fun h => ?_⟩ refine (le_or_lt i n).elim h fun k => ?_ exact (coeff_eq_zero_of_natDegree_lt (hp.trans_lt k)).trans (coeff_eq_zero_of_natDegree_lt (hq.trans_lt k)).symm #align polynomial.ext_iff_nat_degree_le Polynomial.ext_iff_natDegree_le theorem ext_iff_degree_le {p q : R[X]} {n : ℕ} (hp : p.degree ≤ n) (hq : q.degree ≤ n) : p = q ↔ ∀ i ≤ n, p.coeff i = q.coeff i := ext_iff_natDegree_le (natDegree_le_of_degree_le hp) (natDegree_le_of_degree_le hq) #align polynomial.ext_iff_degree_le Polynomial.ext_iff_degree_le @[simp] theorem coeff_natDegree_succ_eq_zero {p : R[X]} : p.coeff (p.natDegree + 1) = 0 := coeff_eq_zero_of_natDegree_lt (lt_add_one _) #align polynomial.coeff_nat_degree_succ_eq_zero Polynomial.coeff_natDegree_succ_eq_zero -- We need the explicit `Decidable` argument here because an exotic one shows up in a moment! theorem ite_le_natDegree_coeff (p : R[X]) (n : ℕ) (I : Decidable (n < 1 + natDegree p)) : @ite _ (n < 1 + natDegree p) I (coeff p n) 0 = coeff p n := by split_ifs with h · rfl · exact (coeff_eq_zero_of_natDegree_lt (not_le.1 fun w => h (Nat.lt_one_add_iff.2 w))).symm #align polynomial.ite_le_nat_degree_coeff Polynomial.ite_le_natDegree_coeff theorem as_sum_support (p : R[X]) : p = ∑ i ∈ p.support, monomial i (p.coeff i) := (sum_monomial_eq p).symm #align polynomial.as_sum_support Polynomial.as_sum_support theorem as_sum_support_C_mul_X_pow (p : R[X]) : p = ∑ i ∈ p.support, C (p.coeff i) * X ^ i := _root_.trans p.as_sum_support <| by simp only [C_mul_X_pow_eq_monomial] #align polynomial.as_sum_support_C_mul_X_pow Polynomial.as_sum_support_C_mul_X_pow /-- We can reexpress a sum over `p.support` as a sum over `range n`, for any `n` satisfying `p.natDegree < n`. -/ theorem sum_over_range' [AddCommMonoid S] (p : R[X]) {f : ℕ → R → S} (h : ∀ n, f n 0 = 0) (n : ℕ) (w : p.natDegree < n) : p.sum f = ∑ a ∈ range n, f a (coeff p a) := by rcases p with ⟨⟩ have := supp_subset_range w simp only [Polynomial.sum, support, coeff, natDegree, degree] at this ⊢ exact Finsupp.sum_of_support_subset _ this _ fun n _hn => h n #align polynomial.sum_over_range' Polynomial.sum_over_range' /-- We can reexpress a sum over `p.support` as a sum over `range (p.natDegree + 1)`. -/ theorem sum_over_range [AddCommMonoid S] (p : R[X]) {f : ℕ → R → S} (h : ∀ n, f n 0 = 0) : p.sum f = ∑ a ∈ range (p.natDegree + 1), f a (coeff p a) := sum_over_range' p h (p.natDegree + 1) (lt_add_one _) #align polynomial.sum_over_range Polynomial.sum_over_range -- TODO this is essentially a duplicate of `sum_over_range`, and should be removed. theorem sum_fin [AddCommMonoid S] (f : ℕ → R → S) (hf : ∀ i, f i 0 = 0) {n : ℕ} {p : R[X]} (hn : p.degree < n) : (∑ i : Fin n, f i (p.coeff i)) = p.sum f := by by_cases hp : p = 0 · rw [hp, sum_zero_index, Finset.sum_eq_zero] intro i _ exact hf i rw [sum_over_range' _ hf n ((natDegree_lt_iff_degree_lt hp).mpr hn), Fin.sum_univ_eq_sum_range fun i => f i (p.coeff i)] #align polynomial.sum_fin Polynomial.sum_fin theorem as_sum_range' (p : R[X]) (n : ℕ) (w : p.natDegree < n) : p = ∑ i ∈ range n, monomial i (coeff p i) := p.sum_monomial_eq.symm.trans <| p.sum_over_range' monomial_zero_right _ w #align polynomial.as_sum_range' Polynomial.as_sum_range' theorem as_sum_range (p : R[X]) : p = ∑ i ∈ range (p.natDegree + 1), monomial i (coeff p i) := p.sum_monomial_eq.symm.trans <| p.sum_over_range <| monomial_zero_right #align polynomial.as_sum_range Polynomial.as_sum_range theorem as_sum_range_C_mul_X_pow (p : R[X]) : p = ∑ i ∈ range (p.natDegree + 1), C (coeff p i) * X ^ i := p.as_sum_range.trans <| by simp only [C_mul_X_pow_eq_monomial] #align polynomial.as_sum_range_C_mul_X_pow Polynomial.as_sum_range_C_mul_X_pow theorem coeff_ne_zero_of_eq_degree (hn : degree p = n) : coeff p n ≠ 0 := fun h => mem_support_iff.mp (mem_of_max hn) h #align polynomial.coeff_ne_zero_of_eq_degree Polynomial.coeff_ne_zero_of_eq_degree theorem eq_X_add_C_of_degree_le_one (h : degree p ≤ 1) : p = C (p.coeff 1) * X + C (p.coeff 0) := ext fun n => Nat.casesOn n (by simp) fun n => Nat.casesOn n (by simp [coeff_C]) fun m => by -- Porting note: `by decide` → `Iff.mpr ..` have : degree p < m.succ.succ := lt_of_le_of_lt h (Iff.mpr WithBot.coe_lt_coe <| Nat.succ_lt_succ <| Nat.zero_lt_succ m) simp [coeff_eq_zero_of_degree_lt this, coeff_C, Nat.succ_ne_zero, coeff_X, Nat.succ_inj', @eq_comm ℕ 0] #align polynomial.eq_X_add_C_of_degree_le_one Polynomial.eq_X_add_C_of_degree_le_one theorem eq_X_add_C_of_degree_eq_one (h : degree p = 1) : p = C p.leadingCoeff * X + C (p.coeff 0) := (eq_X_add_C_of_degree_le_one h.le).trans (by rw [← Nat.cast_one] at h; rw [leadingCoeff, natDegree_eq_of_degree_eq_some h]) #align polynomial.eq_X_add_C_of_degree_eq_one Polynomial.eq_X_add_C_of_degree_eq_one theorem eq_X_add_C_of_natDegree_le_one (h : natDegree p ≤ 1) : p = C (p.coeff 1) * X + C (p.coeff 0) := eq_X_add_C_of_degree_le_one <| degree_le_of_natDegree_le h #align polynomial.eq_X_add_C_of_nat_degree_le_one Polynomial.eq_X_add_C_of_natDegree_le_one theorem Monic.eq_X_add_C (hm : p.Monic) (hnd : p.natDegree = 1) : p = X + C (p.coeff 0) := by rw [← one_mul X, ← C_1, ← hm.coeff_natDegree, hnd, ← eq_X_add_C_of_natDegree_le_one hnd.le] #align polynomial.monic.eq_X_add_C Polynomial.Monic.eq_X_add_C theorem exists_eq_X_add_C_of_natDegree_le_one (h : natDegree p ≤ 1) : ∃ a b, p = C a * X + C b := ⟨p.coeff 1, p.coeff 0, eq_X_add_C_of_natDegree_le_one h⟩ #align polynomial.exists_eq_X_add_C_of_natDegree_le_one Polynomial.exists_eq_X_add_C_of_natDegree_le_one theorem degree_X_pow_le (n : ℕ) : degree (X ^ n : R[X]) ≤ n := by simpa only [C_1, one_mul] using degree_C_mul_X_pow_le n (1 : R) #align polynomial.degree_X_pow_le Polynomial.degree_X_pow_le theorem degree_X_le : degree (X : R[X]) ≤ 1 := degree_monomial_le _ _ #align polynomial.degree_X_le Polynomial.degree_X_le theorem natDegree_X_le : (X : R[X]).natDegree ≤ 1 := natDegree_le_of_degree_le degree_X_le #align polynomial.nat_degree_X_le Polynomial.natDegree_X_le theorem mem_support_C_mul_X_pow {n a : ℕ} {c : R} (h : a ∈ support (C c * X ^ n)) : a = n := mem_singleton.1 <| support_C_mul_X_pow' n c h #align polynomial.mem_support_C_mul_X_pow Polynomial.mem_support_C_mul_X_pow theorem card_support_C_mul_X_pow_le_one {c : R} {n : ℕ} : card (support (C c * X ^ n)) ≤ 1 := by rw [← card_singleton n] apply card_le_card (support_C_mul_X_pow' n c) #align polynomial.card_support_C_mul_X_pow_le_one Polynomial.card_support_C_mul_X_pow_le_one theorem card_supp_le_succ_natDegree (p : R[X]) : p.support.card ≤ p.natDegree + 1 := by rw [← Finset.card_range (p.natDegree + 1)] exact Finset.card_le_card supp_subset_range_natDegree_succ #align polynomial.card_supp_le_succ_nat_degree Polynomial.card_supp_le_succ_natDegree theorem le_degree_of_mem_supp (a : ℕ) : a ∈ p.support → ↑a ≤ degree p := le_degree_of_ne_zero ∘ mem_support_iff.mp #align polynomial.le_degree_of_mem_supp Polynomial.le_degree_of_mem_supp theorem nonempty_support_iff : p.support.Nonempty ↔ p ≠ 0 := by rw [Ne, nonempty_iff_ne_empty, Ne, ← support_eq_empty] #align polynomial.nonempty_support_iff Polynomial.nonempty_support_iff end Semiring section NonzeroSemiring variable [Semiring R] [Nontrivial R] {p q : R[X]} @[simp] theorem degree_one : degree (1 : R[X]) = (0 : WithBot ℕ) := degree_C one_ne_zero #align polynomial.degree_one Polynomial.degree_one @[simp] theorem degree_X : degree (X : R[X]) = 1 := degree_monomial _ one_ne_zero #align polynomial.degree_X Polynomial.degree_X @[simp] theorem natDegree_X : (X : R[X]).natDegree = 1 := natDegree_eq_of_degree_eq_some degree_X #align polynomial.nat_degree_X Polynomial.natDegree_X end NonzeroSemiring section Ring variable [Ring R] theorem coeff_mul_X_sub_C {p : R[X]} {r : R} {a : ℕ} : coeff (p * (X - C r)) (a + 1) = coeff p a - coeff p (a + 1) * r := by simp [mul_sub] #align polynomial.coeff_mul_X_sub_C Polynomial.coeff_mul_X_sub_C @[simp] theorem degree_neg (p : R[X]) : degree (-p) = degree p := by unfold degree; rw [support_neg] #align polynomial.degree_neg Polynomial.degree_neg theorem degree_neg_le_of_le {a : WithBot ℕ} {p : R[X]} (hp : degree p ≤ a) : degree (-p) ≤ a := p.degree_neg.le.trans hp @[simp] theorem natDegree_neg (p : R[X]) : natDegree (-p) = natDegree p := by simp [natDegree] #align polynomial.nat_degree_neg Polynomial.natDegree_neg theorem natDegree_neg_le_of_le {p : R[X]} (hp : natDegree p ≤ m) : natDegree (-p) ≤ m := (natDegree_neg p).le.trans hp @[simp] theorem natDegree_intCast (n : ℤ) : natDegree (n : R[X]) = 0 := by rw [← C_eq_intCast, natDegree_C] #align polynomial.nat_degree_intCast Polynomial.natDegree_intCast @[deprecated (since := "2024-04-17")] alias natDegree_int_cast := natDegree_intCast theorem degree_intCast_le (n : ℤ) : degree (n : R[X]) ≤ 0 := degree_le_of_natDegree_le (by simp) @[deprecated (since := "2024-04-17")] alias degree_int_cast_le := degree_intCast_le @[simp] theorem leadingCoeff_neg (p : R[X]) : (-p).leadingCoeff = -p.leadingCoeff := by rw [leadingCoeff, leadingCoeff, natDegree_neg, coeff_neg] #align polynomial.leading_coeff_neg Polynomial.leadingCoeff_neg end Ring section Semiring variable [Semiring R] {p : R[X]} /-- The second-highest coefficient, or 0 for constants -/ def nextCoeff (p : R[X]) : R := if p.natDegree = 0 then 0 else p.coeff (p.natDegree - 1) #align polynomial.next_coeff Polynomial.nextCoeff lemma nextCoeff_eq_zero : p.nextCoeff = 0 ↔ p.natDegree = 0 ∨ 0 < p.natDegree ∧ p.coeff (p.natDegree - 1) = 0 := by simp [nextCoeff, or_iff_not_imp_left, pos_iff_ne_zero]; aesop lemma nextCoeff_ne_zero : p.nextCoeff ≠ 0 ↔ p.natDegree ≠ 0 ∧ p.coeff (p.natDegree - 1) ≠ 0 := by simp [nextCoeff] @[simp] theorem nextCoeff_C_eq_zero (c : R) : nextCoeff (C c) = 0 := by rw [nextCoeff] simp #align polynomial.next_coeff_C_eq_zero Polynomial.nextCoeff_C_eq_zero theorem nextCoeff_of_natDegree_pos (hp : 0 < p.natDegree) : nextCoeff p = p.coeff (p.natDegree - 1) := by rw [nextCoeff, if_neg] contrapose! hp simpa #align polynomial.next_coeff_of_pos_nat_degree Polynomial.nextCoeff_of_natDegree_pos variable {p q : R[X]} {ι : Type*} theorem coeff_natDegree_eq_zero_of_degree_lt (h : degree p < degree q) : coeff p (natDegree q) = 0 := coeff_eq_zero_of_degree_lt (lt_of_lt_of_le h degree_le_natDegree) #align polynomial.coeff_nat_degree_eq_zero_of_degree_lt Polynomial.coeff_natDegree_eq_zero_of_degree_lt theorem ne_zero_of_degree_gt {n : WithBot ℕ} (h : n < degree p) : p ≠ 0 := mt degree_eq_bot.2 h.ne_bot #align polynomial.ne_zero_of_degree_gt Polynomial.ne_zero_of_degree_gt theorem ne_zero_of_degree_ge_degree (hpq : p.degree ≤ q.degree) (hp : p ≠ 0) : q ≠ 0 := Polynomial.ne_zero_of_degree_gt (lt_of_lt_of_le (bot_lt_iff_ne_bot.mpr (by rwa [Ne, Polynomial.degree_eq_bot])) hpq : q.degree > ⊥) #align polynomial.ne_zero_of_degree_ge_degree Polynomial.ne_zero_of_degree_ge_degree theorem ne_zero_of_natDegree_gt {n : ℕ} (h : n < natDegree p) : p ≠ 0 := fun H => by simp [H, Nat.not_lt_zero] at h #align polynomial.ne_zero_of_nat_degree_gt Polynomial.ne_zero_of_natDegree_gt theorem degree_lt_degree (h : natDegree p < natDegree q) : degree p < degree q := by by_cases hp : p = 0 · simp [hp] rw [bot_lt_iff_ne_bot] intro hq simp [hp, degree_eq_bot.mp hq, lt_irrefl] at h · rwa [degree_eq_natDegree hp, degree_eq_natDegree <| ne_zero_of_natDegree_gt h, Nat.cast_lt] #align polynomial.degree_lt_degree Polynomial.degree_lt_degree theorem natDegree_lt_natDegree_iff (hp : p ≠ 0) : natDegree p < natDegree q ↔ degree p < degree q := ⟨degree_lt_degree, fun h ↦ by have hq : q ≠ 0 := ne_zero_of_degree_gt h rwa [degree_eq_natDegree hp, degree_eq_natDegree hq, Nat.cast_lt] at h⟩ #align polynomial.nat_degree_lt_nat_degree_iff Polynomial.natDegree_lt_natDegree_iff theorem eq_C_of_degree_le_zero (h : degree p ≤ 0) : p = C (coeff p 0) := by ext (_ | n) · simp rw [coeff_C, if_neg (Nat.succ_ne_zero _), coeff_eq_zero_of_degree_lt] exact h.trans_lt (WithBot.coe_lt_coe.2 n.succ_pos) #align polynomial.eq_C_of_degree_le_zero Polynomial.eq_C_of_degree_le_zero theorem eq_C_of_degree_eq_zero (h : degree p = 0) : p = C (coeff p 0) := eq_C_of_degree_le_zero h.le #align polynomial.eq_C_of_degree_eq_zero Polynomial.eq_C_of_degree_eq_zero theorem degree_le_zero_iff : degree p ≤ 0 ↔ p = C (coeff p 0) := ⟨eq_C_of_degree_le_zero, fun h => h.symm ▸ degree_C_le⟩ #align polynomial.degree_le_zero_iff Polynomial.degree_le_zero_iff theorem degree_add_le (p q : R[X]) : degree (p + q) ≤ max (degree p) (degree q) := by simpa only [degree, ← support_toFinsupp, toFinsupp_add] using AddMonoidAlgebra.sup_support_add_le _ _ _ #align polynomial.degree_add_le Polynomial.degree_add_le theorem degree_add_le_of_degree_le {p q : R[X]} {n : ℕ} (hp : degree p ≤ n) (hq : degree q ≤ n) : degree (p + q) ≤ n := (degree_add_le p q).trans <| max_le hp hq #align polynomial.degree_add_le_of_degree_le Polynomial.degree_add_le_of_degree_le theorem degree_add_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) : degree (p + q) ≤ max a b := (p.degree_add_le q).trans <| max_le_max ‹_› ‹_› theorem natDegree_add_le (p q : R[X]) : natDegree (p + q) ≤ max (natDegree p) (natDegree q) := by cases' le_max_iff.1 (degree_add_le p q) with h h <;> simp [natDegree_le_natDegree h] #align polynomial.nat_degree_add_le Polynomial.natDegree_add_le theorem natDegree_add_le_of_degree_le {p q : R[X]} {n : ℕ} (hp : natDegree p ≤ n) (hq : natDegree q ≤ n) : natDegree (p + q) ≤ n := (natDegree_add_le p q).trans <| max_le hp hq #align polynomial.nat_degree_add_le_of_degree_le Polynomial.natDegree_add_le_of_degree_le theorem natDegree_add_le_of_le (hp : natDegree p ≤ m) (hq : natDegree q ≤ n) : natDegree (p + q) ≤ max m n := (p.natDegree_add_le q).trans <| max_le_max ‹_› ‹_› @[simp] theorem leadingCoeff_zero : leadingCoeff (0 : R[X]) = 0 := rfl #align polynomial.leading_coeff_zero Polynomial.leadingCoeff_zero @[simp] theorem leadingCoeff_eq_zero : leadingCoeff p = 0 ↔ p = 0 := ⟨fun h => Classical.by_contradiction fun hp => mt mem_support_iff.1 (Classical.not_not.2 h) (mem_of_max (degree_eq_natDegree hp)), fun h => h.symm ▸ leadingCoeff_zero⟩ #align polynomial.leading_coeff_eq_zero Polynomial.leadingCoeff_eq_zero theorem leadingCoeff_ne_zero : leadingCoeff p ≠ 0 ↔ p ≠ 0 := by rw [Ne, leadingCoeff_eq_zero] #align polynomial.leading_coeff_ne_zero Polynomial.leadingCoeff_ne_zero theorem leadingCoeff_eq_zero_iff_deg_eq_bot : leadingCoeff p = 0 ↔ degree p = ⊥ := by rw [leadingCoeff_eq_zero, degree_eq_bot] #align polynomial.leading_coeff_eq_zero_iff_deg_eq_bot Polynomial.leadingCoeff_eq_zero_iff_deg_eq_bot lemma natDegree_le_pred (hf : p.natDegree ≤ n) (hn : p.coeff n = 0) : p.natDegree ≤ n - 1 := by obtain _ | n := n · exact hf · refine (Nat.le_succ_iff_eq_or_le.1 hf).resolve_left fun h ↦ ?_ rw [← Nat.succ_eq_add_one, ← h, coeff_natDegree, leadingCoeff_eq_zero] at hn aesop theorem natDegree_mem_support_of_nonzero (H : p ≠ 0) : p.natDegree ∈ p.support := by rw [mem_support_iff] exact (not_congr leadingCoeff_eq_zero).mpr H #align polynomial.nat_degree_mem_support_of_nonzero Polynomial.natDegree_mem_support_of_nonzero theorem natDegree_eq_support_max' (h : p ≠ 0) : p.natDegree = p.support.max' (nonempty_support_iff.mpr h) := (le_max' _ _ <| natDegree_mem_support_of_nonzero h).antisymm <| max'_le _ _ _ le_natDegree_of_mem_supp #align polynomial.nat_degree_eq_support_max' Polynomial.natDegree_eq_support_max' theorem natDegree_C_mul_X_pow_le (a : R) (n : ℕ) : natDegree (C a * X ^ n) ≤ n := natDegree_le_iff_degree_le.2 <| degree_C_mul_X_pow_le _ _ #align polynomial.nat_degree_C_mul_X_pow_le Polynomial.natDegree_C_mul_X_pow_le theorem degree_add_eq_left_of_degree_lt (h : degree q < degree p) : degree (p + q) = degree p := le_antisymm (max_eq_left_of_lt h ▸ degree_add_le _ _) <| degree_le_degree <| by rw [coeff_add, coeff_natDegree_eq_zero_of_degree_lt h, add_zero] exact mt leadingCoeff_eq_zero.1 (ne_zero_of_degree_gt h) #align polynomial.degree_add_eq_left_of_degree_lt Polynomial.degree_add_eq_left_of_degree_lt theorem degree_add_eq_right_of_degree_lt (h : degree p < degree q) : degree (p + q) = degree q := by rw [add_comm, degree_add_eq_left_of_degree_lt h] #align polynomial.degree_add_eq_right_of_degree_lt Polynomial.degree_add_eq_right_of_degree_lt theorem natDegree_add_eq_left_of_natDegree_lt (h : natDegree q < natDegree p) : natDegree (p + q) = natDegree p := natDegree_eq_of_degree_eq (degree_add_eq_left_of_degree_lt (degree_lt_degree h)) #align polynomial.nat_degree_add_eq_left_of_nat_degree_lt Polynomial.natDegree_add_eq_left_of_natDegree_lt theorem natDegree_add_eq_right_of_natDegree_lt (h : natDegree p < natDegree q) : natDegree (p + q) = natDegree q := natDegree_eq_of_degree_eq (degree_add_eq_right_of_degree_lt (degree_lt_degree h)) #align polynomial.nat_degree_add_eq_right_of_nat_degree_lt Polynomial.natDegree_add_eq_right_of_natDegree_lt theorem degree_add_C (hp : 0 < degree p) : degree (p + C a) = degree p := add_comm (C a) p ▸ degree_add_eq_right_of_degree_lt <| lt_of_le_of_lt degree_C_le hp #align polynomial.degree_add_C Polynomial.degree_add_C @[simp] theorem natDegree_add_C {a : R} : (p + C a).natDegree = p.natDegree := by rcases eq_or_ne p 0 with rfl | hp · simp by_cases hpd : p.degree ≤ 0 · rw [eq_C_of_degree_le_zero hpd, ← C_add, natDegree_C, natDegree_C] · rw [not_le, degree_eq_natDegree hp, Nat.cast_pos, ← natDegree_C a] at hpd exact natDegree_add_eq_left_of_natDegree_lt hpd @[simp] theorem natDegree_C_add {a : R} : (C a + p).natDegree = p.natDegree := by simp [add_comm _ p] theorem degree_add_eq_of_leadingCoeff_add_ne_zero (h : leadingCoeff p + leadingCoeff q ≠ 0) : degree (p + q) = max p.degree q.degree := le_antisymm (degree_add_le _ _) <| match lt_trichotomy (degree p) (degree q) with | Or.inl hlt => by rw [degree_add_eq_right_of_degree_lt hlt, max_eq_right_of_lt hlt] | Or.inr (Or.inl HEq) => le_of_not_gt fun hlt : max (degree p) (degree q) > degree (p + q) => h <| show leadingCoeff p + leadingCoeff q = 0 by rw [HEq, max_self] at hlt rw [leadingCoeff, leadingCoeff, natDegree_eq_of_degree_eq HEq, ← coeff_add] exact coeff_natDegree_eq_zero_of_degree_lt hlt | Or.inr (Or.inr hlt) => by rw [degree_add_eq_left_of_degree_lt hlt, max_eq_left_of_lt hlt] #align polynomial.degree_add_eq_of_leading_coeff_add_ne_zero Polynomial.degree_add_eq_of_leadingCoeff_add_ne_zero lemma natDegree_eq_of_natDegree_add_lt_left (p q : R[X]) (H : natDegree (p + q) < natDegree p) : natDegree p = natDegree q := by by_contra h cases Nat.lt_or_lt_of_ne h with | inl h => exact lt_asymm h (by rwa [natDegree_add_eq_right_of_natDegree_lt h] at H) | inr h => rw [natDegree_add_eq_left_of_natDegree_lt h] at H exact LT.lt.false H lemma natDegree_eq_of_natDegree_add_lt_right (p q : R[X]) (H : natDegree (p + q) < natDegree q) : natDegree p = natDegree q := (natDegree_eq_of_natDegree_add_lt_left q p (add_comm p q ▸ H)).symm lemma natDegree_eq_of_natDegree_add_eq_zero (p q : R[X]) (H : natDegree (p + q) = 0) : natDegree p = natDegree q := by by_cases h₁ : natDegree p = 0; on_goal 1 => by_cases h₂ : natDegree q = 0 · exact h₁.trans h₂.symm · apply natDegree_eq_of_natDegree_add_lt_right; rwa [H, Nat.pos_iff_ne_zero] · apply natDegree_eq_of_natDegree_add_lt_left; rwa [H, Nat.pos_iff_ne_zero] theorem degree_erase_le (p : R[X]) (n : ℕ) : degree (p.erase n) ≤ degree p := by rcases p with ⟨p⟩ simp only [erase_def, degree, coeff, support] -- Porting note: simpler convert-free proof to be explicit about definition unfolding apply sup_mono rw [Finsupp.support_erase] apply Finset.erase_subset #align polynomial.degree_erase_le Polynomial.degree_erase_le theorem degree_erase_lt (hp : p ≠ 0) : degree (p.erase (natDegree p)) < degree p := by apply lt_of_le_of_ne (degree_erase_le _ _) rw [degree_eq_natDegree hp, degree, support_erase] exact fun h => not_mem_erase _ _ (mem_of_max h) #align polynomial.degree_erase_lt Polynomial.degree_erase_lt theorem degree_update_le (p : R[X]) (n : ℕ) (a : R) : degree (p.update n a) ≤ max (degree p) n := by classical rw [degree, support_update] split_ifs · exact (Finset.max_mono (erase_subset _ _)).trans (le_max_left _ _) · rw [max_insert, max_comm] exact le_rfl #align polynomial.degree_update_le Polynomial.degree_update_le theorem degree_sum_le (s : Finset ι) (f : ι → R[X]) : degree (∑ i ∈ s, f i) ≤ s.sup fun b => degree (f b) := Finset.cons_induction_on s (by simp only [sum_empty, sup_empty, degree_zero, le_refl]) fun a s has ih => calc degree (∑ i ∈ cons a s has, f i) ≤ max (degree (f a)) (degree (∑ i ∈ s, f i)) := by rw [Finset.sum_cons]; exact degree_add_le _ _ _ ≤ _ := by rw [sup_cons, sup_eq_max]; exact max_le_max le_rfl ih #align polynomial.degree_sum_le Polynomial.degree_sum_le theorem degree_mul_le (p q : R[X]) : degree (p * q) ≤ degree p + degree q := by simpa only [degree, ← support_toFinsupp, toFinsupp_mul] using AddMonoidAlgebra.sup_support_mul_le (WithBot.coe_add _ _).le _ _ #align polynomial.degree_mul_le Polynomial.degree_mul_le theorem degree_mul_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) : degree (p * q) ≤ a + b := (p.degree_mul_le _).trans <| add_le_add ‹_› ‹_› theorem degree_pow_le (p : R[X]) : ∀ n : ℕ, degree (p ^ n) ≤ n • degree p | 0 => by rw [pow_zero, zero_nsmul]; exact degree_one_le | n + 1 => calc degree (p ^ (n + 1)) ≤ degree (p ^ n) + degree p := by rw [pow_succ]; exact degree_mul_le _ _ _ ≤ _ := by rw [succ_nsmul]; exact add_le_add_right (degree_pow_le _ _) _ #align polynomial.degree_pow_le Polynomial.degree_pow_le theorem degree_pow_le_of_le {a : WithBot ℕ} (b : ℕ) (hp : degree p ≤ a) : degree (p ^ b) ≤ b * a := by induction b with | zero => simp [degree_one_le] | succ n hn => rw [Nat.cast_succ, add_mul, one_mul, pow_succ] exact degree_mul_le_of_le hn hp @[simp] theorem leadingCoeff_monomial (a : R) (n : ℕ) : leadingCoeff (monomial n a) = a := by classical by_cases ha : a = 0 · simp only [ha, (monomial n).map_zero, leadingCoeff_zero] · rw [leadingCoeff, natDegree_monomial, if_neg ha, coeff_monomial] simp #align polynomial.leading_coeff_monomial Polynomial.leadingCoeff_monomial theorem leadingCoeff_C_mul_X_pow (a : R) (n : ℕ) : leadingCoeff (C a * X ^ n) = a := by rw [C_mul_X_pow_eq_monomial, leadingCoeff_monomial] #align polynomial.leading_coeff_C_mul_X_pow Polynomial.leadingCoeff_C_mul_X_pow theorem leadingCoeff_C_mul_X (a : R) : leadingCoeff (C a * X) = a := by simpa only [pow_one] using leadingCoeff_C_mul_X_pow a 1 #align polynomial.leading_coeff_C_mul_X Polynomial.leadingCoeff_C_mul_X @[simp] theorem leadingCoeff_C (a : R) : leadingCoeff (C a) = a := leadingCoeff_monomial a 0 #align polynomial.leading_coeff_C Polynomial.leadingCoeff_C -- @[simp] -- Porting note (#10618): simp can prove this theorem leadingCoeff_X_pow (n : ℕ) : leadingCoeff ((X : R[X]) ^ n) = 1 := by simpa only [C_1, one_mul] using leadingCoeff_C_mul_X_pow (1 : R) n #align polynomial.leading_coeff_X_pow Polynomial.leadingCoeff_X_pow -- @[simp] -- Porting note (#10618): simp can prove this theorem leadingCoeff_X : leadingCoeff (X : R[X]) = 1 := by simpa only [pow_one] using @leadingCoeff_X_pow R _ 1 #align polynomial.leading_coeff_X Polynomial.leadingCoeff_X @[simp] theorem monic_X_pow (n : ℕ) : Monic (X ^ n : R[X]) := leadingCoeff_X_pow n #align polynomial.monic_X_pow Polynomial.monic_X_pow @[simp] theorem monic_X : Monic (X : R[X]) := leadingCoeff_X #align polynomial.monic_X Polynomial.monic_X -- @[simp] -- Porting note (#10618): simp can prove this theorem leadingCoeff_one : leadingCoeff (1 : R[X]) = 1 := leadingCoeff_C 1 #align polynomial.leading_coeff_one Polynomial.leadingCoeff_one @[simp] theorem monic_one : Monic (1 : R[X]) := leadingCoeff_C _ #align polynomial.monic_one Polynomial.monic_one theorem Monic.ne_zero {R : Type*} [Semiring R] [Nontrivial R] {p : R[X]} (hp : p.Monic) : p ≠ 0 := by rintro rfl simp [Monic] at hp #align polynomial.monic.ne_zero Polynomial.Monic.ne_zero theorem Monic.ne_zero_of_ne (h : (0 : R) ≠ 1) {p : R[X]} (hp : p.Monic) : p ≠ 0 := by nontriviality R exact hp.ne_zero #align polynomial.monic.ne_zero_of_ne Polynomial.Monic.ne_zero_of_ne theorem monic_of_natDegree_le_of_coeff_eq_one (n : ℕ) (pn : p.natDegree ≤ n) (p1 : p.coeff n = 1) : Monic p := by unfold Monic nontriviality refine (congr_arg _ <| natDegree_eq_of_le_of_coeff_ne_zero pn ?_).trans p1 exact ne_of_eq_of_ne p1 one_ne_zero #align polynomial.monic_of_nat_degree_le_of_coeff_eq_one Polynomial.monic_of_natDegree_le_of_coeff_eq_one theorem monic_of_degree_le_of_coeff_eq_one (n : ℕ) (pn : p.degree ≤ n) (p1 : p.coeff n = 1) : Monic p := monic_of_natDegree_le_of_coeff_eq_one n (natDegree_le_of_degree_le pn) p1 #align polynomial.monic_of_degree_le_of_coeff_eq_one Polynomial.monic_of_degree_le_of_coeff_eq_one theorem Monic.ne_zero_of_polynomial_ne {r} (hp : Monic p) (hne : q ≠ r) : p ≠ 0 := haveI := Nontrivial.of_polynomial_ne hne hp.ne_zero #align polynomial.monic.ne_zero_of_polynomial_ne Polynomial.Monic.ne_zero_of_polynomial_ne theorem leadingCoeff_add_of_degree_lt (h : degree p < degree q) : leadingCoeff (p + q) = leadingCoeff q := by have : coeff p (natDegree q) = 0 := coeff_natDegree_eq_zero_of_degree_lt h simp only [leadingCoeff, natDegree_eq_of_degree_eq (degree_add_eq_right_of_degree_lt h), this, coeff_add, zero_add] #align polynomial.leading_coeff_add_of_degree_lt Polynomial.leadingCoeff_add_of_degree_lt theorem leadingCoeff_add_of_degree_lt' (h : degree q < degree p) : leadingCoeff (p + q) = leadingCoeff p := by rw [add_comm] exact leadingCoeff_add_of_degree_lt h theorem leadingCoeff_add_of_degree_eq (h : degree p = degree q) (hlc : leadingCoeff p + leadingCoeff q ≠ 0) : leadingCoeff (p + q) = leadingCoeff p + leadingCoeff q := by have : natDegree (p + q) = natDegree p := by apply natDegree_eq_of_degree_eq rw [degree_add_eq_of_leadingCoeff_add_ne_zero hlc, h, max_self] simp only [leadingCoeff, this, natDegree_eq_of_degree_eq h, coeff_add] #align polynomial.leading_coeff_add_of_degree_eq Polynomial.leadingCoeff_add_of_degree_eq @[simp] theorem coeff_mul_degree_add_degree (p q : R[X]) : coeff (p * q) (natDegree p + natDegree q) = leadingCoeff p * leadingCoeff q := calc coeff (p * q) (natDegree p + natDegree q) = ∑ x ∈ antidiagonal (natDegree p + natDegree q), coeff p x.1 * coeff q x.2 := coeff_mul _ _ _ _ = coeff p (natDegree p) * coeff q (natDegree q) := by refine Finset.sum_eq_single (natDegree p, natDegree q) ?_ ?_ · rintro ⟨i, j⟩ h₁ h₂ rw [mem_antidiagonal] at h₁ by_cases H : natDegree p < i · rw [coeff_eq_zero_of_degree_lt (lt_of_le_of_lt degree_le_natDegree (WithBot.coe_lt_coe.2 H)), zero_mul] · rw [not_lt_iff_eq_or_lt] at H cases' H with H H · subst H rw [add_left_cancel_iff] at h₁ dsimp at h₁ subst h₁ exact (h₂ rfl).elim · suffices natDegree q < j by rw [coeff_eq_zero_of_degree_lt (lt_of_le_of_lt degree_le_natDegree (WithBot.coe_lt_coe.2 this)), mul_zero] by_contra! H' exact ne_of_lt (Nat.lt_of_lt_of_le (Nat.add_lt_add_right H j) (Nat.add_le_add_left H' _)) h₁ · intro H exfalso apply H rw [mem_antidiagonal] #align polynomial.coeff_mul_degree_add_degree Polynomial.coeff_mul_degree_add_degree theorem degree_mul' (h : leadingCoeff p * leadingCoeff q ≠ 0) : degree (p * q) = degree p + degree q := have hp : p ≠ 0 := by refine mt ?_ h; exact fun hp => by rw [hp, leadingCoeff_zero, zero_mul] have hq : q ≠ 0 := by refine mt ?_ h; exact fun hq => by rw [hq, leadingCoeff_zero, mul_zero] le_antisymm (degree_mul_le _ _) (by rw [degree_eq_natDegree hp, degree_eq_natDegree hq] refine le_degree_of_ne_zero (n := natDegree p + natDegree q) ?_ rwa [coeff_mul_degree_add_degree]) #align polynomial.degree_mul' Polynomial.degree_mul' theorem Monic.degree_mul (hq : Monic q) : degree (p * q) = degree p + degree q := letI := Classical.decEq R if hp : p = 0 then by simp [hp] else degree_mul' <| by rwa [hq.leadingCoeff, mul_one, Ne, leadingCoeff_eq_zero] #align polynomial.monic.degree_mul Polynomial.Monic.degree_mul theorem natDegree_mul' (h : leadingCoeff p * leadingCoeff q ≠ 0) : natDegree (p * q) = natDegree p + natDegree q := have hp : p ≠ 0 := mt leadingCoeff_eq_zero.2 fun h₁ => h <| by rw [h₁, zero_mul] have hq : q ≠ 0 := mt leadingCoeff_eq_zero.2 fun h₁ => h <| by rw [h₁, mul_zero] natDegree_eq_of_degree_eq_some <| by rw [degree_mul' h, Nat.cast_add, degree_eq_natDegree hp, degree_eq_natDegree hq] #align polynomial.nat_degree_mul' Polynomial.natDegree_mul' theorem leadingCoeff_mul' (h : leadingCoeff p * leadingCoeff q ≠ 0) : leadingCoeff (p * q) = leadingCoeff p * leadingCoeff q := by unfold leadingCoeff rw [natDegree_mul' h, coeff_mul_degree_add_degree] rfl #align polynomial.leading_coeff_mul' Polynomial.leadingCoeff_mul' theorem monomial_natDegree_leadingCoeff_eq_self (h : p.support.card ≤ 1) : monomial p.natDegree p.leadingCoeff = p := by classical rcases card_support_le_one_iff_monomial.1 h with ⟨n, a, rfl⟩ by_cases ha : a = 0 <;> simp [ha] #align polynomial.monomial_nat_degree_leading_coeff_eq_self Polynomial.monomial_natDegree_leadingCoeff_eq_self theorem C_mul_X_pow_eq_self (h : p.support.card ≤ 1) : C p.leadingCoeff * X ^ p.natDegree = p := by rw [C_mul_X_pow_eq_monomial, monomial_natDegree_leadingCoeff_eq_self h] #align polynomial.C_mul_X_pow_eq_self Polynomial.C_mul_X_pow_eq_self theorem leadingCoeff_pow' : leadingCoeff p ^ n ≠ 0 → leadingCoeff (p ^ n) = leadingCoeff p ^ n := Nat.recOn n (by simp) fun n ih h => by have h₁ : leadingCoeff p ^ n ≠ 0 := fun h₁ => h <| by rw [pow_succ, h₁, zero_mul] have h₂ : leadingCoeff p * leadingCoeff (p ^ n) ≠ 0 := by rwa [pow_succ', ← ih h₁] at h rw [pow_succ', pow_succ', leadingCoeff_mul' h₂, ih h₁] #align polynomial.leading_coeff_pow' Polynomial.leadingCoeff_pow' theorem degree_pow' : ∀ {n : ℕ}, leadingCoeff p ^ n ≠ 0 → degree (p ^ n) = n • degree p | 0 => fun h => by rw [pow_zero, ← C_1] at *; rw [degree_C h, zero_nsmul] | n + 1 => fun h => by have h₁ : leadingCoeff p ^ n ≠ 0 := fun h₁ => h <| by rw [pow_succ, h₁, zero_mul] have h₂ : leadingCoeff (p ^ n) * leadingCoeff p ≠ 0 := by rwa [pow_succ, ← leadingCoeff_pow' h₁] at h rw [pow_succ, degree_mul' h₂, succ_nsmul, degree_pow' h₁] #align polynomial.degree_pow' Polynomial.degree_pow' theorem natDegree_pow' {n : ℕ} (h : leadingCoeff p ^ n ≠ 0) : natDegree (p ^ n) = n * natDegree p := letI := Classical.decEq R if hp0 : p = 0 then if hn0 : n = 0 then by simp [*] else by rw [hp0, zero_pow hn0]; simp else have hpn : p ^ n ≠ 0 := fun hpn0 => by have h1 := h rw [← leadingCoeff_pow' h1, hpn0, leadingCoeff_zero] at h; exact h rfl Option.some_inj.1 <| show (natDegree (p ^ n) : WithBot ℕ) = (n * natDegree p : ℕ) by rw [← degree_eq_natDegree hpn, degree_pow' h, degree_eq_natDegree hp0]; simp #align polynomial.nat_degree_pow' Polynomial.natDegree_pow' theorem leadingCoeff_monic_mul {p q : R[X]} (hp : Monic p) : leadingCoeff (p * q) = leadingCoeff q := by rcases eq_or_ne q 0 with (rfl | H) · simp · rw [leadingCoeff_mul', hp.leadingCoeff, one_mul] rwa [hp.leadingCoeff, one_mul, Ne, leadingCoeff_eq_zero] #align polynomial.leading_coeff_monic_mul Polynomial.leadingCoeff_monic_mul theorem leadingCoeff_mul_monic {p q : R[X]} (hq : Monic q) : leadingCoeff (p * q) = leadingCoeff p := letI := Classical.decEq R Decidable.byCases (fun H : leadingCoeff p = 0 => by rw [H, leadingCoeff_eq_zero.1 H, zero_mul, leadingCoeff_zero]) fun H : leadingCoeff p ≠ 0 => by rw [leadingCoeff_mul', hq.leadingCoeff, mul_one] rwa [hq.leadingCoeff, mul_one] #align polynomial.leading_coeff_mul_monic Polynomial.leadingCoeff_mul_monic @[simp] theorem leadingCoeff_mul_X_pow {p : R[X]} {n : ℕ} : leadingCoeff (p * X ^ n) = leadingCoeff p := leadingCoeff_mul_monic (monic_X_pow n) #align polynomial.leading_coeff_mul_X_pow Polynomial.leadingCoeff_mul_X_pow @[simp] theorem leadingCoeff_mul_X {p : R[X]} : leadingCoeff (p * X) = leadingCoeff p := leadingCoeff_mul_monic monic_X #align polynomial.leading_coeff_mul_X Polynomial.leadingCoeff_mul_X theorem natDegree_mul_le {p q : R[X]} : natDegree (p * q) ≤ natDegree p + natDegree q := by apply natDegree_le_of_degree_le apply le_trans (degree_mul_le p q) rw [Nat.cast_add] apply add_le_add <;> apply degree_le_natDegree #align polynomial.nat_degree_mul_le Polynomial.natDegree_mul_le theorem natDegree_mul_le_of_le (hp : natDegree p ≤ m) (hg : natDegree q ≤ n) : natDegree (p * q) ≤ m + n := natDegree_mul_le.trans <| add_le_add ‹_› ‹_› theorem natDegree_pow_le {p : R[X]} {n : ℕ} : (p ^ n).natDegree ≤ n * p.natDegree := by induction' n with i hi · simp · rw [pow_succ, Nat.succ_mul] apply le_trans natDegree_mul_le exact add_le_add_right hi _ #align polynomial.nat_degree_pow_le Polynomial.natDegree_pow_le theorem natDegree_pow_le_of_le (n : ℕ) (hp : natDegree p ≤ m) : natDegree (p ^ n) ≤ n * m := natDegree_pow_le.trans (Nat.mul_le_mul le_rfl ‹_›) @[simp] theorem coeff_pow_mul_natDegree (p : R[X]) (n : ℕ) : (p ^ n).coeff (n * p.natDegree) = p.leadingCoeff ^ n := by induction' n with i hi · simp · rw [pow_succ, pow_succ, Nat.succ_mul] by_cases hp1 : p.leadingCoeff ^ i = 0 · rw [hp1, zero_mul] by_cases hp2 : p ^ i = 0 · rw [hp2, zero_mul, coeff_zero] · apply coeff_eq_zero_of_natDegree_lt have h1 : (p ^ i).natDegree < i * p.natDegree := by refine lt_of_le_of_ne natDegree_pow_le fun h => hp2 ?_ rw [← h, hp1] at hi exact leadingCoeff_eq_zero.mp hi calc (p ^ i * p).natDegree ≤ (p ^ i).natDegree + p.natDegree := natDegree_mul_le _ < i * p.natDegree + p.natDegree := add_lt_add_right h1 _ · rw [← natDegree_pow' hp1, ← leadingCoeff_pow' hp1] exact coeff_mul_degree_add_degree _ _ #align polynomial.coeff_pow_mul_nat_degree Polynomial.coeff_pow_mul_natDegree
Mathlib/Algebra/Polynomial/Degree/Definitions.lean
1,142
1,154
theorem coeff_mul_add_eq_of_natDegree_le {df dg : ℕ} {f g : R[X]} (hdf : natDegree f ≤ df) (hdg : natDegree g ≤ dg) : (f * g).coeff (df + dg) = f.coeff df * g.coeff dg := by
rw [coeff_mul, Finset.sum_eq_single_of_mem (df, dg)] · rw [mem_antidiagonal] rintro ⟨df', dg'⟩ hmem hne obtain h | hdf' := lt_or_le df df' · rw [coeff_eq_zero_of_natDegree_lt (hdf.trans_lt h), zero_mul] obtain h | hdg' := lt_or_le dg dg' · rw [coeff_eq_zero_of_natDegree_lt (hdg.trans_lt h), mul_zero] obtain ⟨rfl, rfl⟩ := (add_eq_add_iff_eq_and_eq hdf' hdg').mp (mem_antidiagonal.1 hmem) exact (hne rfl).elim
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot, Yury Kudryashov, Rémy Degenne -/ import Mathlib.Order.MinMax import Mathlib.Data.Set.Subsingleton import Mathlib.Tactic.Says #align_import data.set.intervals.basic from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c" /-! # Intervals In any preorder `α`, we define intervals (which on each side can be either infinite, open, or closed) using the following naming conventions: - `i`: infinite - `o`: open - `c`: closed Each interval has the name `I` + letter for left side + letter for right side. For instance, `Ioc a b` denotes the interval `(a, b]`. This file contains these definitions, and basic facts on inclusion, intersection, difference of intervals (where the precise statements may depend on the properties of the order, in particular for some statements it should be `LinearOrder` or `DenselyOrdered`). TODO: This is just the beginning; a lot of rules are missing -/ open Function open OrderDual (toDual ofDual) variable {α β : Type*} namespace Set section Preorder variable [Preorder α] {a a₁ a₂ b b₁ b₂ c x : α} /-- Left-open right-open interval -/ def Ioo (a b : α) := { x | a < x ∧ x < b } #align set.Ioo Set.Ioo /-- Left-closed right-open interval -/ def Ico (a b : α) := { x | a ≤ x ∧ x < b } #align set.Ico Set.Ico /-- Left-infinite right-open interval -/ def Iio (a : α) := { x | x < a } #align set.Iio Set.Iio /-- Left-closed right-closed interval -/ def Icc (a b : α) := { x | a ≤ x ∧ x ≤ b } #align set.Icc Set.Icc /-- Left-infinite right-closed interval -/ def Iic (b : α) := { x | x ≤ b } #align set.Iic Set.Iic /-- Left-open right-closed interval -/ def Ioc (a b : α) := { x | a < x ∧ x ≤ b } #align set.Ioc Set.Ioc /-- Left-closed right-infinite interval -/ def Ici (a : α) := { x | a ≤ x } #align set.Ici Set.Ici /-- Left-open right-infinite interval -/ def Ioi (a : α) := { x | a < x } #align set.Ioi Set.Ioi theorem Ioo_def (a b : α) : { x | a < x ∧ x < b } = Ioo a b := rfl #align set.Ioo_def Set.Ioo_def theorem Ico_def (a b : α) : { x | a ≤ x ∧ x < b } = Ico a b := rfl #align set.Ico_def Set.Ico_def theorem Iio_def (a : α) : { x | x < a } = Iio a := rfl #align set.Iio_def Set.Iio_def theorem Icc_def (a b : α) : { x | a ≤ x ∧ x ≤ b } = Icc a b := rfl #align set.Icc_def Set.Icc_def theorem Iic_def (b : α) : { x | x ≤ b } = Iic b := rfl #align set.Iic_def Set.Iic_def theorem Ioc_def (a b : α) : { x | a < x ∧ x ≤ b } = Ioc a b := rfl #align set.Ioc_def Set.Ioc_def theorem Ici_def (a : α) : { x | a ≤ x } = Ici a := rfl #align set.Ici_def Set.Ici_def theorem Ioi_def (a : α) : { x | a < x } = Ioi a := rfl #align set.Ioi_def Set.Ioi_def @[simp] theorem mem_Ioo : x ∈ Ioo a b ↔ a < x ∧ x < b := Iff.rfl #align set.mem_Ioo Set.mem_Ioo @[simp] theorem mem_Ico : x ∈ Ico a b ↔ a ≤ x ∧ x < b := Iff.rfl #align set.mem_Ico Set.mem_Ico @[simp] theorem mem_Iio : x ∈ Iio b ↔ x < b := Iff.rfl #align set.mem_Iio Set.mem_Iio @[simp] theorem mem_Icc : x ∈ Icc a b ↔ a ≤ x ∧ x ≤ b := Iff.rfl #align set.mem_Icc Set.mem_Icc @[simp] theorem mem_Iic : x ∈ Iic b ↔ x ≤ b := Iff.rfl #align set.mem_Iic Set.mem_Iic @[simp] theorem mem_Ioc : x ∈ Ioc a b ↔ a < x ∧ x ≤ b := Iff.rfl #align set.mem_Ioc Set.mem_Ioc @[simp] theorem mem_Ici : x ∈ Ici a ↔ a ≤ x := Iff.rfl #align set.mem_Ici Set.mem_Ici @[simp] theorem mem_Ioi : x ∈ Ioi a ↔ a < x := Iff.rfl #align set.mem_Ioi Set.mem_Ioi instance decidableMemIoo [Decidable (a < x ∧ x < b)] : Decidable (x ∈ Ioo a b) := by assumption #align set.decidable_mem_Ioo Set.decidableMemIoo instance decidableMemIco [Decidable (a ≤ x ∧ x < b)] : Decidable (x ∈ Ico a b) := by assumption #align set.decidable_mem_Ico Set.decidableMemIco instance decidableMemIio [Decidable (x < b)] : Decidable (x ∈ Iio b) := by assumption #align set.decidable_mem_Iio Set.decidableMemIio instance decidableMemIcc [Decidable (a ≤ x ∧ x ≤ b)] : Decidable (x ∈ Icc a b) := by assumption #align set.decidable_mem_Icc Set.decidableMemIcc instance decidableMemIic [Decidable (x ≤ b)] : Decidable (x ∈ Iic b) := by assumption #align set.decidable_mem_Iic Set.decidableMemIic instance decidableMemIoc [Decidable (a < x ∧ x ≤ b)] : Decidable (x ∈ Ioc a b) := by assumption #align set.decidable_mem_Ioc Set.decidableMemIoc instance decidableMemIci [Decidable (a ≤ x)] : Decidable (x ∈ Ici a) := by assumption #align set.decidable_mem_Ici Set.decidableMemIci instance decidableMemIoi [Decidable (a < x)] : Decidable (x ∈ Ioi a) := by assumption #align set.decidable_mem_Ioi Set.decidableMemIoi -- Porting note (#10618): `simp` can prove this -- @[simp] theorem left_mem_Ioo : a ∈ Ioo a b ↔ False := by simp [lt_irrefl] #align set.left_mem_Ioo Set.left_mem_Ioo -- Porting note (#10618): `simp` can prove this -- @[simp] theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp [le_refl] #align set.left_mem_Ico Set.left_mem_Ico -- Porting note (#10618): `simp` can prove this -- @[simp] theorem left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := by simp [le_refl] #align set.left_mem_Icc Set.left_mem_Icc -- Porting note (#10618): `simp` can prove this -- @[simp] theorem left_mem_Ioc : a ∈ Ioc a b ↔ False := by simp [lt_irrefl] #align set.left_mem_Ioc Set.left_mem_Ioc theorem left_mem_Ici : a ∈ Ici a := by simp #align set.left_mem_Ici Set.left_mem_Ici -- Porting note (#10618): `simp` can prove this -- @[simp] theorem right_mem_Ioo : b ∈ Ioo a b ↔ False := by simp [lt_irrefl] #align set.right_mem_Ioo Set.right_mem_Ioo -- Porting note (#10618): `simp` can prove this -- @[simp] theorem right_mem_Ico : b ∈ Ico a b ↔ False := by simp [lt_irrefl] #align set.right_mem_Ico Set.right_mem_Ico -- Porting note (#10618): `simp` can prove this -- @[simp] theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := by simp [le_refl] #align set.right_mem_Icc Set.right_mem_Icc -- Porting note (#10618): `simp` can prove this -- @[simp] theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp [le_refl] #align set.right_mem_Ioc Set.right_mem_Ioc theorem right_mem_Iic : a ∈ Iic a := by simp #align set.right_mem_Iic Set.right_mem_Iic @[simp] theorem dual_Ici : Ici (toDual a) = ofDual ⁻¹' Iic a := rfl #align set.dual_Ici Set.dual_Ici @[simp] theorem dual_Iic : Iic (toDual a) = ofDual ⁻¹' Ici a := rfl #align set.dual_Iic Set.dual_Iic @[simp] theorem dual_Ioi : Ioi (toDual a) = ofDual ⁻¹' Iio a := rfl #align set.dual_Ioi Set.dual_Ioi @[simp] theorem dual_Iio : Iio (toDual a) = ofDual ⁻¹' Ioi a := rfl #align set.dual_Iio Set.dual_Iio @[simp] theorem dual_Icc : Icc (toDual a) (toDual b) = ofDual ⁻¹' Icc b a := Set.ext fun _ => and_comm #align set.dual_Icc Set.dual_Icc @[simp] theorem dual_Ioc : Ioc (toDual a) (toDual b) = ofDual ⁻¹' Ico b a := Set.ext fun _ => and_comm #align set.dual_Ioc Set.dual_Ioc @[simp] theorem dual_Ico : Ico (toDual a) (toDual b) = ofDual ⁻¹' Ioc b a := Set.ext fun _ => and_comm #align set.dual_Ico Set.dual_Ico @[simp] theorem dual_Ioo : Ioo (toDual a) (toDual b) = ofDual ⁻¹' Ioo b a := Set.ext fun _ => and_comm #align set.dual_Ioo Set.dual_Ioo @[simp] theorem nonempty_Icc : (Icc a b).Nonempty ↔ a ≤ b := ⟨fun ⟨_, hx⟩ => hx.1.trans hx.2, fun h => ⟨a, left_mem_Icc.2 h⟩⟩ #align set.nonempty_Icc Set.nonempty_Icc @[simp] theorem nonempty_Ico : (Ico a b).Nonempty ↔ a < b := ⟨fun ⟨_, hx⟩ => hx.1.trans_lt hx.2, fun h => ⟨a, left_mem_Ico.2 h⟩⟩ #align set.nonempty_Ico Set.nonempty_Ico @[simp] theorem nonempty_Ioc : (Ioc a b).Nonempty ↔ a < b := ⟨fun ⟨_, hx⟩ => hx.1.trans_le hx.2, fun h => ⟨b, right_mem_Ioc.2 h⟩⟩ #align set.nonempty_Ioc Set.nonempty_Ioc @[simp] theorem nonempty_Ici : (Ici a).Nonempty := ⟨a, left_mem_Ici⟩ #align set.nonempty_Ici Set.nonempty_Ici @[simp] theorem nonempty_Iic : (Iic a).Nonempty := ⟨a, right_mem_Iic⟩ #align set.nonempty_Iic Set.nonempty_Iic @[simp] theorem nonempty_Ioo [DenselyOrdered α] : (Ioo a b).Nonempty ↔ a < b := ⟨fun ⟨_, ha, hb⟩ => ha.trans hb, exists_between⟩ #align set.nonempty_Ioo Set.nonempty_Ioo @[simp] theorem nonempty_Ioi [NoMaxOrder α] : (Ioi a).Nonempty := exists_gt a #align set.nonempty_Ioi Set.nonempty_Ioi @[simp] theorem nonempty_Iio [NoMinOrder α] : (Iio a).Nonempty := exists_lt a #align set.nonempty_Iio Set.nonempty_Iio theorem nonempty_Icc_subtype (h : a ≤ b) : Nonempty (Icc a b) := Nonempty.to_subtype (nonempty_Icc.mpr h) #align set.nonempty_Icc_subtype Set.nonempty_Icc_subtype theorem nonempty_Ico_subtype (h : a < b) : Nonempty (Ico a b) := Nonempty.to_subtype (nonempty_Ico.mpr h) #align set.nonempty_Ico_subtype Set.nonempty_Ico_subtype theorem nonempty_Ioc_subtype (h : a < b) : Nonempty (Ioc a b) := Nonempty.to_subtype (nonempty_Ioc.mpr h) #align set.nonempty_Ioc_subtype Set.nonempty_Ioc_subtype /-- An interval `Ici a` is nonempty. -/ instance nonempty_Ici_subtype : Nonempty (Ici a) := Nonempty.to_subtype nonempty_Ici #align set.nonempty_Ici_subtype Set.nonempty_Ici_subtype /-- An interval `Iic a` is nonempty. -/ instance nonempty_Iic_subtype : Nonempty (Iic a) := Nonempty.to_subtype nonempty_Iic #align set.nonempty_Iic_subtype Set.nonempty_Iic_subtype theorem nonempty_Ioo_subtype [DenselyOrdered α] (h : a < b) : Nonempty (Ioo a b) := Nonempty.to_subtype (nonempty_Ioo.mpr h) #align set.nonempty_Ioo_subtype Set.nonempty_Ioo_subtype /-- In an order without maximal elements, the intervals `Ioi` are nonempty. -/ instance nonempty_Ioi_subtype [NoMaxOrder α] : Nonempty (Ioi a) := Nonempty.to_subtype nonempty_Ioi #align set.nonempty_Ioi_subtype Set.nonempty_Ioi_subtype /-- In an order without minimal elements, the intervals `Iio` are nonempty. -/ instance nonempty_Iio_subtype [NoMinOrder α] : Nonempty (Iio a) := Nonempty.to_subtype nonempty_Iio #align set.nonempty_Iio_subtype Set.nonempty_Iio_subtype instance [NoMinOrder α] : NoMinOrder (Iio a) := ⟨fun a => let ⟨b, hb⟩ := exists_lt (a : α) ⟨⟨b, lt_trans hb a.2⟩, hb⟩⟩ instance [NoMinOrder α] : NoMinOrder (Iic a) := ⟨fun a => let ⟨b, hb⟩ := exists_lt (a : α) ⟨⟨b, hb.le.trans a.2⟩, hb⟩⟩ instance [NoMaxOrder α] : NoMaxOrder (Ioi a) := OrderDual.noMaxOrder (α := Iio (toDual a)) instance [NoMaxOrder α] : NoMaxOrder (Ici a) := OrderDual.noMaxOrder (α := Iic (toDual a)) @[simp] theorem Icc_eq_empty (h : ¬a ≤ b) : Icc a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans hb) #align set.Icc_eq_empty Set.Icc_eq_empty @[simp] theorem Ico_eq_empty (h : ¬a < b) : Ico a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans_lt hb) #align set.Ico_eq_empty Set.Ico_eq_empty @[simp] theorem Ioc_eq_empty (h : ¬a < b) : Ioc a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans_le hb) #align set.Ioc_eq_empty Set.Ioc_eq_empty @[simp] theorem Ioo_eq_empty (h : ¬a < b) : Ioo a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans hb) #align set.Ioo_eq_empty Set.Ioo_eq_empty @[simp] theorem Icc_eq_empty_of_lt (h : b < a) : Icc a b = ∅ := Icc_eq_empty h.not_le #align set.Icc_eq_empty_of_lt Set.Icc_eq_empty_of_lt @[simp] theorem Ico_eq_empty_of_le (h : b ≤ a) : Ico a b = ∅ := Ico_eq_empty h.not_lt #align set.Ico_eq_empty_of_le Set.Ico_eq_empty_of_le @[simp] theorem Ioc_eq_empty_of_le (h : b ≤ a) : Ioc a b = ∅ := Ioc_eq_empty h.not_lt #align set.Ioc_eq_empty_of_le Set.Ioc_eq_empty_of_le @[simp] theorem Ioo_eq_empty_of_le (h : b ≤ a) : Ioo a b = ∅ := Ioo_eq_empty h.not_lt #align set.Ioo_eq_empty_of_le Set.Ioo_eq_empty_of_le -- Porting note (#10618): `simp` can prove this -- @[simp] theorem Ico_self (a : α) : Ico a a = ∅ := Ico_eq_empty <| lt_irrefl _ #align set.Ico_self Set.Ico_self -- Porting note (#10618): `simp` can prove this -- @[simp] theorem Ioc_self (a : α) : Ioc a a = ∅ := Ioc_eq_empty <| lt_irrefl _ #align set.Ioc_self Set.Ioc_self -- Porting note (#10618): `simp` can prove this -- @[simp] theorem Ioo_self (a : α) : Ioo a a = ∅ := Ioo_eq_empty <| lt_irrefl _ #align set.Ioo_self Set.Ioo_self theorem Ici_subset_Ici : Ici a ⊆ Ici b ↔ b ≤ a := ⟨fun h => h <| left_mem_Ici, fun h _ hx => h.trans hx⟩ #align set.Ici_subset_Ici Set.Ici_subset_Ici @[gcongr] alias ⟨_, _root_.GCongr.Ici_subset_Ici_of_le⟩ := Ici_subset_Ici theorem Iic_subset_Iic : Iic a ⊆ Iic b ↔ a ≤ b := @Ici_subset_Ici αᵒᵈ _ _ _ #align set.Iic_subset_Iic Set.Iic_subset_Iic @[gcongr] alias ⟨_, _root_.GCongr.Iic_subset_Iic_of_le⟩ := Iic_subset_Iic theorem Ici_subset_Ioi : Ici a ⊆ Ioi b ↔ b < a := ⟨fun h => h left_mem_Ici, fun h _ hx => h.trans_le hx⟩ #align set.Ici_subset_Ioi Set.Ici_subset_Ioi theorem Iic_subset_Iio : Iic a ⊆ Iio b ↔ a < b := ⟨fun h => h right_mem_Iic, fun h _ hx => lt_of_le_of_lt hx h⟩ #align set.Iic_subset_Iio Set.Iic_subset_Iio @[gcongr] theorem Ioo_subset_Ioo (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans_lt hx₁, hx₂.trans_le h₂⟩ #align set.Ioo_subset_Ioo Set.Ioo_subset_Ioo @[gcongr] theorem Ioo_subset_Ioo_left (h : a₁ ≤ a₂) : Ioo a₂ b ⊆ Ioo a₁ b := Ioo_subset_Ioo h le_rfl #align set.Ioo_subset_Ioo_left Set.Ioo_subset_Ioo_left @[gcongr] theorem Ioo_subset_Ioo_right (h : b₁ ≤ b₂) : Ioo a b₁ ⊆ Ioo a b₂ := Ioo_subset_Ioo le_rfl h #align set.Ioo_subset_Ioo_right Set.Ioo_subset_Ioo_right @[gcongr] theorem Ico_subset_Ico (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ico a₁ b₁ ⊆ Ico a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans hx₁, hx₂.trans_le h₂⟩ #align set.Ico_subset_Ico Set.Ico_subset_Ico @[gcongr] theorem Ico_subset_Ico_left (h : a₁ ≤ a₂) : Ico a₂ b ⊆ Ico a₁ b := Ico_subset_Ico h le_rfl #align set.Ico_subset_Ico_left Set.Ico_subset_Ico_left @[gcongr] theorem Ico_subset_Ico_right (h : b₁ ≤ b₂) : Ico a b₁ ⊆ Ico a b₂ := Ico_subset_Ico le_rfl h #align set.Ico_subset_Ico_right Set.Ico_subset_Ico_right @[gcongr] theorem Icc_subset_Icc (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Icc a₁ b₁ ⊆ Icc a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans hx₁, le_trans hx₂ h₂⟩ #align set.Icc_subset_Icc Set.Icc_subset_Icc @[gcongr] theorem Icc_subset_Icc_left (h : a₁ ≤ a₂) : Icc a₂ b ⊆ Icc a₁ b := Icc_subset_Icc h le_rfl #align set.Icc_subset_Icc_left Set.Icc_subset_Icc_left @[gcongr] theorem Icc_subset_Icc_right (h : b₁ ≤ b₂) : Icc a b₁ ⊆ Icc a b₂ := Icc_subset_Icc le_rfl h #align set.Icc_subset_Icc_right Set.Icc_subset_Icc_right theorem Icc_subset_Ioo (ha : a₂ < a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ := fun _ hx => ⟨ha.trans_le hx.1, hx.2.trans_lt hb⟩ #align set.Icc_subset_Ioo Set.Icc_subset_Ioo theorem Icc_subset_Ici_self : Icc a b ⊆ Ici a := fun _ => And.left #align set.Icc_subset_Ici_self Set.Icc_subset_Ici_self theorem Icc_subset_Iic_self : Icc a b ⊆ Iic b := fun _ => And.right #align set.Icc_subset_Iic_self Set.Icc_subset_Iic_self theorem Ioc_subset_Iic_self : Ioc a b ⊆ Iic b := fun _ => And.right #align set.Ioc_subset_Iic_self Set.Ioc_subset_Iic_self @[gcongr] theorem Ioc_subset_Ioc (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans_lt hx₁, hx₂.trans h₂⟩ #align set.Ioc_subset_Ioc Set.Ioc_subset_Ioc @[gcongr] theorem Ioc_subset_Ioc_left (h : a₁ ≤ a₂) : Ioc a₂ b ⊆ Ioc a₁ b := Ioc_subset_Ioc h le_rfl #align set.Ioc_subset_Ioc_left Set.Ioc_subset_Ioc_left @[gcongr] theorem Ioc_subset_Ioc_right (h : b₁ ≤ b₂) : Ioc a b₁ ⊆ Ioc a b₂ := Ioc_subset_Ioc le_rfl h #align set.Ioc_subset_Ioc_right Set.Ioc_subset_Ioc_right theorem Ico_subset_Ioo_left (h₁ : a₁ < a₂) : Ico a₂ b ⊆ Ioo a₁ b := fun _ => And.imp_left h₁.trans_le #align set.Ico_subset_Ioo_left Set.Ico_subset_Ioo_left theorem Ioc_subset_Ioo_right (h : b₁ < b₂) : Ioc a b₁ ⊆ Ioo a b₂ := fun _ => And.imp_right fun h' => h'.trans_lt h #align set.Ioc_subset_Ioo_right Set.Ioc_subset_Ioo_right theorem Icc_subset_Ico_right (h₁ : b₁ < b₂) : Icc a b₁ ⊆ Ico a b₂ := fun _ => And.imp_right fun h₂ => h₂.trans_lt h₁ #align set.Icc_subset_Ico_right Set.Icc_subset_Ico_right theorem Ioo_subset_Ico_self : Ioo a b ⊆ Ico a b := fun _ => And.imp_left le_of_lt #align set.Ioo_subset_Ico_self Set.Ioo_subset_Ico_self theorem Ioo_subset_Ioc_self : Ioo a b ⊆ Ioc a b := fun _ => And.imp_right le_of_lt #align set.Ioo_subset_Ioc_self Set.Ioo_subset_Ioc_self theorem Ico_subset_Icc_self : Ico a b ⊆ Icc a b := fun _ => And.imp_right le_of_lt #align set.Ico_subset_Icc_self Set.Ico_subset_Icc_self theorem Ioc_subset_Icc_self : Ioc a b ⊆ Icc a b := fun _ => And.imp_left le_of_lt #align set.Ioc_subset_Icc_self Set.Ioc_subset_Icc_self theorem Ioo_subset_Icc_self : Ioo a b ⊆ Icc a b := Subset.trans Ioo_subset_Ico_self Ico_subset_Icc_self #align set.Ioo_subset_Icc_self Set.Ioo_subset_Icc_self theorem Ico_subset_Iio_self : Ico a b ⊆ Iio b := fun _ => And.right #align set.Ico_subset_Iio_self Set.Ico_subset_Iio_self theorem Ioo_subset_Iio_self : Ioo a b ⊆ Iio b := fun _ => And.right #align set.Ioo_subset_Iio_self Set.Ioo_subset_Iio_self theorem Ioc_subset_Ioi_self : Ioc a b ⊆ Ioi a := fun _ => And.left #align set.Ioc_subset_Ioi_self Set.Ioc_subset_Ioi_self theorem Ioo_subset_Ioi_self : Ioo a b ⊆ Ioi a := fun _ => And.left #align set.Ioo_subset_Ioi_self Set.Ioo_subset_Ioi_self theorem Ioi_subset_Ici_self : Ioi a ⊆ Ici a := fun _ hx => le_of_lt hx #align set.Ioi_subset_Ici_self Set.Ioi_subset_Ici_self theorem Iio_subset_Iic_self : Iio a ⊆ Iic a := fun _ hx => le_of_lt hx #align set.Iio_subset_Iic_self Set.Iio_subset_Iic_self theorem Ico_subset_Ici_self : Ico a b ⊆ Ici a := fun _ => And.left #align set.Ico_subset_Ici_self Set.Ico_subset_Ici_self theorem Ioi_ssubset_Ici_self : Ioi a ⊂ Ici a := ⟨Ioi_subset_Ici_self, fun h => lt_irrefl a (h le_rfl)⟩ #align set.Ioi_ssubset_Ici_self Set.Ioi_ssubset_Ici_self theorem Iio_ssubset_Iic_self : Iio a ⊂ Iic a := @Ioi_ssubset_Ici_self αᵒᵈ _ _ #align set.Iio_ssubset_Iic_self Set.Iio_ssubset_Iic_self theorem Icc_subset_Icc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Icc a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans hx, hx'.trans h'⟩⟩ #align set.Icc_subset_Icc_iff Set.Icc_subset_Icc_iff theorem Icc_subset_Ioo_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ < a₁ ∧ b₁ < b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans_le hx, hx'.trans_lt h'⟩⟩ #align set.Icc_subset_Ioo_iff Set.Icc_subset_Ioo_iff theorem Icc_subset_Ico_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ < b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans hx, hx'.trans_lt h'⟩⟩ #align set.Icc_subset_Ico_iff Set.Icc_subset_Ico_iff theorem Icc_subset_Ioc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioc a₂ b₂ ↔ a₂ < a₁ ∧ b₁ ≤ b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans_le hx, hx'.trans h'⟩⟩ #align set.Icc_subset_Ioc_iff Set.Icc_subset_Ioc_iff theorem Icc_subset_Iio_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Iio b₂ ↔ b₁ < b₂ := ⟨fun h => h ⟨h₁, le_rfl⟩, fun h _ ⟨_, hx'⟩ => hx'.trans_lt h⟩ #align set.Icc_subset_Iio_iff Set.Icc_subset_Iio_iff theorem Icc_subset_Ioi_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioi a₂ ↔ a₂ < a₁ := ⟨fun h => h ⟨le_rfl, h₁⟩, fun h _ ⟨hx, _⟩ => h.trans_le hx⟩ #align set.Icc_subset_Ioi_iff Set.Icc_subset_Ioi_iff theorem Icc_subset_Iic_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Iic b₂ ↔ b₁ ≤ b₂ := ⟨fun h => h ⟨h₁, le_rfl⟩, fun h _ ⟨_, hx'⟩ => hx'.trans h⟩ #align set.Icc_subset_Iic_iff Set.Icc_subset_Iic_iff theorem Icc_subset_Ici_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ici a₂ ↔ a₂ ≤ a₁ := ⟨fun h => h ⟨le_rfl, h₁⟩, fun h _ ⟨hx, _⟩ => h.trans hx⟩ #align set.Icc_subset_Ici_iff Set.Icc_subset_Ici_iff theorem Icc_ssubset_Icc_left (hI : a₂ ≤ b₂) (ha : a₂ < a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := (ssubset_iff_of_subset (Icc_subset_Icc (le_of_lt ha) hb)).mpr ⟨a₂, left_mem_Icc.mpr hI, not_and.mpr fun f _ => lt_irrefl a₂ (ha.trans_le f)⟩ #align set.Icc_ssubset_Icc_left Set.Icc_ssubset_Icc_left theorem Icc_ssubset_Icc_right (hI : a₂ ≤ b₂) (ha : a₂ ≤ a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := (ssubset_iff_of_subset (Icc_subset_Icc ha (le_of_lt hb))).mpr ⟨b₂, right_mem_Icc.mpr hI, fun f => lt_irrefl b₁ (hb.trans_le f.2)⟩ #align set.Icc_ssubset_Icc_right Set.Icc_ssubset_Icc_right /-- If `a ≤ b`, then `(b, +∞) ⊆ (a, +∞)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Ioi_subset_Ioi_iff`. -/ @[gcongr] theorem Ioi_subset_Ioi (h : a ≤ b) : Ioi b ⊆ Ioi a := fun _ hx => h.trans_lt hx #align set.Ioi_subset_Ioi Set.Ioi_subset_Ioi /-- If `a ≤ b`, then `(b, +∞) ⊆ [a, +∞)`. In preorders, this is just an implication. If you need the equivalence in dense linear orders, use `Ioi_subset_Ici_iff`. -/ theorem Ioi_subset_Ici (h : a ≤ b) : Ioi b ⊆ Ici a := Subset.trans (Ioi_subset_Ioi h) Ioi_subset_Ici_self #align set.Ioi_subset_Ici Set.Ioi_subset_Ici /-- If `a ≤ b`, then `(-∞, a) ⊆ (-∞, b)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Iio_subset_Iio_iff`. -/ @[gcongr] theorem Iio_subset_Iio (h : a ≤ b) : Iio a ⊆ Iio b := fun _ hx => lt_of_lt_of_le hx h #align set.Iio_subset_Iio Set.Iio_subset_Iio /-- If `a ≤ b`, then `(-∞, a) ⊆ (-∞, b]`. In preorders, this is just an implication. If you need the equivalence in dense linear orders, use `Iio_subset_Iic_iff`. -/ theorem Iio_subset_Iic (h : a ≤ b) : Iio a ⊆ Iic b := Subset.trans (Iio_subset_Iio h) Iio_subset_Iic_self #align set.Iio_subset_Iic Set.Iio_subset_Iic theorem Ici_inter_Iic : Ici a ∩ Iic b = Icc a b := rfl #align set.Ici_inter_Iic Set.Ici_inter_Iic theorem Ici_inter_Iio : Ici a ∩ Iio b = Ico a b := rfl #align set.Ici_inter_Iio Set.Ici_inter_Iio theorem Ioi_inter_Iic : Ioi a ∩ Iic b = Ioc a b := rfl #align set.Ioi_inter_Iic Set.Ioi_inter_Iic theorem Ioi_inter_Iio : Ioi a ∩ Iio b = Ioo a b := rfl #align set.Ioi_inter_Iio Set.Ioi_inter_Iio theorem Iic_inter_Ici : Iic a ∩ Ici b = Icc b a := inter_comm _ _ #align set.Iic_inter_Ici Set.Iic_inter_Ici theorem Iio_inter_Ici : Iio a ∩ Ici b = Ico b a := inter_comm _ _ #align set.Iio_inter_Ici Set.Iio_inter_Ici theorem Iic_inter_Ioi : Iic a ∩ Ioi b = Ioc b a := inter_comm _ _ #align set.Iic_inter_Ioi Set.Iic_inter_Ioi theorem Iio_inter_Ioi : Iio a ∩ Ioi b = Ioo b a := inter_comm _ _ #align set.Iio_inter_Ioi Set.Iio_inter_Ioi theorem mem_Icc_of_Ioo (h : x ∈ Ioo a b) : x ∈ Icc a b := Ioo_subset_Icc_self h #align set.mem_Icc_of_Ioo Set.mem_Icc_of_Ioo theorem mem_Ico_of_Ioo (h : x ∈ Ioo a b) : x ∈ Ico a b := Ioo_subset_Ico_self h #align set.mem_Ico_of_Ioo Set.mem_Ico_of_Ioo theorem mem_Ioc_of_Ioo (h : x ∈ Ioo a b) : x ∈ Ioc a b := Ioo_subset_Ioc_self h #align set.mem_Ioc_of_Ioo Set.mem_Ioc_of_Ioo theorem mem_Icc_of_Ico (h : x ∈ Ico a b) : x ∈ Icc a b := Ico_subset_Icc_self h #align set.mem_Icc_of_Ico Set.mem_Icc_of_Ico theorem mem_Icc_of_Ioc (h : x ∈ Ioc a b) : x ∈ Icc a b := Ioc_subset_Icc_self h #align set.mem_Icc_of_Ioc Set.mem_Icc_of_Ioc theorem mem_Ici_of_Ioi (h : x ∈ Ioi a) : x ∈ Ici a := Ioi_subset_Ici_self h #align set.mem_Ici_of_Ioi Set.mem_Ici_of_Ioi theorem mem_Iic_of_Iio (h : x ∈ Iio a) : x ∈ Iic a := Iio_subset_Iic_self h #align set.mem_Iic_of_Iio Set.mem_Iic_of_Iio theorem Icc_eq_empty_iff : Icc a b = ∅ ↔ ¬a ≤ b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Icc] #align set.Icc_eq_empty_iff Set.Icc_eq_empty_iff theorem Ico_eq_empty_iff : Ico a b = ∅ ↔ ¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ico] #align set.Ico_eq_empty_iff Set.Ico_eq_empty_iff theorem Ioc_eq_empty_iff : Ioc a b = ∅ ↔ ¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioc] #align set.Ioc_eq_empty_iff Set.Ioc_eq_empty_iff theorem Ioo_eq_empty_iff [DenselyOrdered α] : Ioo a b = ∅ ↔ ¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioo] #align set.Ioo_eq_empty_iff Set.Ioo_eq_empty_iff theorem _root_.IsTop.Iic_eq (h : IsTop a) : Iic a = univ := eq_univ_of_forall h #align is_top.Iic_eq IsTop.Iic_eq theorem _root_.IsBot.Ici_eq (h : IsBot a) : Ici a = univ := eq_univ_of_forall h #align is_bot.Ici_eq IsBot.Ici_eq theorem _root_.IsMax.Ioi_eq (h : IsMax a) : Ioi a = ∅ := eq_empty_of_subset_empty fun _ => h.not_lt #align is_max.Ioi_eq IsMax.Ioi_eq theorem _root_.IsMin.Iio_eq (h : IsMin a) : Iio a = ∅ := eq_empty_of_subset_empty fun _ => h.not_lt #align is_min.Iio_eq IsMin.Iio_eq theorem Iic_inter_Ioc_of_le (h : a ≤ c) : Iic a ∩ Ioc b c = Ioc b a := ext fun _ => ⟨fun H => ⟨H.2.1, H.1⟩, fun H => ⟨H.2, H.1, H.2.trans h⟩⟩ #align set.Iic_inter_Ioc_of_le Set.Iic_inter_Ioc_of_le theorem not_mem_Icc_of_lt (ha : c < a) : c ∉ Icc a b := fun h => ha.not_le h.1 #align set.not_mem_Icc_of_lt Set.not_mem_Icc_of_lt theorem not_mem_Icc_of_gt (hb : b < c) : c ∉ Icc a b := fun h => hb.not_le h.2 #align set.not_mem_Icc_of_gt Set.not_mem_Icc_of_gt theorem not_mem_Ico_of_lt (ha : c < a) : c ∉ Ico a b := fun h => ha.not_le h.1 #align set.not_mem_Ico_of_lt Set.not_mem_Ico_of_lt theorem not_mem_Ioc_of_gt (hb : b < c) : c ∉ Ioc a b := fun h => hb.not_le h.2 #align set.not_mem_Ioc_of_gt Set.not_mem_Ioc_of_gt -- Porting note (#10618): `simp` can prove this -- @[simp] theorem not_mem_Ioi_self : a ∉ Ioi a := lt_irrefl _ #align set.not_mem_Ioi_self Set.not_mem_Ioi_self -- Porting note (#10618): `simp` can prove this -- @[simp] theorem not_mem_Iio_self : b ∉ Iio b := lt_irrefl _ #align set.not_mem_Iio_self Set.not_mem_Iio_self theorem not_mem_Ioc_of_le (ha : c ≤ a) : c ∉ Ioc a b := fun h => lt_irrefl _ <| h.1.trans_le ha #align set.not_mem_Ioc_of_le Set.not_mem_Ioc_of_le theorem not_mem_Ico_of_ge (hb : b ≤ c) : c ∉ Ico a b := fun h => lt_irrefl _ <| h.2.trans_le hb #align set.not_mem_Ico_of_ge Set.not_mem_Ico_of_ge theorem not_mem_Ioo_of_le (ha : c ≤ a) : c ∉ Ioo a b := fun h => lt_irrefl _ <| h.1.trans_le ha #align set.not_mem_Ioo_of_le Set.not_mem_Ioo_of_le theorem not_mem_Ioo_of_ge (hb : b ≤ c) : c ∉ Ioo a b := fun h => lt_irrefl _ <| h.2.trans_le hb #align set.not_mem_Ioo_of_ge Set.not_mem_Ioo_of_ge end Preorder section PartialOrder variable [PartialOrder α] {a b c : α} @[simp] theorem Icc_self (a : α) : Icc a a = {a} := Set.ext <| by simp [Icc, le_antisymm_iff, and_comm] #align set.Icc_self Set.Icc_self instance instIccUnique : Unique (Set.Icc a a) where default := ⟨a, by simp⟩ uniq y := Subtype.ext <| by simpa using y.2 @[simp] theorem Icc_eq_singleton_iff : Icc a b = {c} ↔ a = c ∧ b = c := by refine ⟨fun h => ?_, ?_⟩ · have hab : a ≤ b := nonempty_Icc.1 (h.symm.subst <| singleton_nonempty c) exact ⟨eq_of_mem_singleton <| h.subst <| left_mem_Icc.2 hab, eq_of_mem_singleton <| h.subst <| right_mem_Icc.2 hab⟩ · rintro ⟨rfl, rfl⟩ exact Icc_self _ #align set.Icc_eq_singleton_iff Set.Icc_eq_singleton_iff lemma subsingleton_Icc_of_ge (hba : b ≤ a) : Set.Subsingleton (Icc a b) := fun _x ⟨hax, hxb⟩ _y ⟨hay, hyb⟩ ↦ le_antisymm (le_implies_le_of_le_of_le hxb hay hba) (le_implies_le_of_le_of_le hyb hax hba) #align set.subsingleton_Icc_of_ge Set.subsingleton_Icc_of_ge @[simp] lemma subsingleton_Icc_iff {α : Type*} [LinearOrder α] {a b : α} : Set.Subsingleton (Icc a b) ↔ b ≤ a := by refine ⟨fun h ↦ ?_, subsingleton_Icc_of_ge⟩ contrapose! h simp only [ge_iff_le, gt_iff_lt, not_subsingleton_iff] exact ⟨a, ⟨le_refl _, h.le⟩, b, ⟨h.le, le_refl _⟩, h.ne⟩ @[simp] theorem Icc_diff_left : Icc a b \ {a} = Ioc a b := ext fun x => by simp [lt_iff_le_and_ne, eq_comm, and_right_comm] #align set.Icc_diff_left Set.Icc_diff_left @[simp] theorem Icc_diff_right : Icc a b \ {b} = Ico a b := ext fun x => by simp [lt_iff_le_and_ne, and_assoc] #align set.Icc_diff_right Set.Icc_diff_right @[simp] theorem Ico_diff_left : Ico a b \ {a} = Ioo a b := ext fun x => by simp [and_right_comm, ← lt_iff_le_and_ne, eq_comm] #align set.Ico_diff_left Set.Ico_diff_left @[simp] theorem Ioc_diff_right : Ioc a b \ {b} = Ioo a b := ext fun x => by simp [and_assoc, ← lt_iff_le_and_ne] #align set.Ioc_diff_right Set.Ioc_diff_right @[simp] theorem Icc_diff_both : Icc a b \ {a, b} = Ioo a b := by rw [insert_eq, ← diff_diff, Icc_diff_left, Ioc_diff_right] #align set.Icc_diff_both Set.Icc_diff_both @[simp] theorem Ici_diff_left : Ici a \ {a} = Ioi a := ext fun x => by simp [lt_iff_le_and_ne, eq_comm] #align set.Ici_diff_left Set.Ici_diff_left @[simp] theorem Iic_diff_right : Iic a \ {a} = Iio a := ext fun x => by simp [lt_iff_le_and_ne] #align set.Iic_diff_right Set.Iic_diff_right @[simp] theorem Ico_diff_Ioo_same (h : a < b) : Ico a b \ Ioo a b = {a} := by rw [← Ico_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 <| left_mem_Ico.2 h)] #align set.Ico_diff_Ioo_same Set.Ico_diff_Ioo_same @[simp] theorem Ioc_diff_Ioo_same (h : a < b) : Ioc a b \ Ioo a b = {b} := by rw [← Ioc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 <| right_mem_Ioc.2 h)] #align set.Ioc_diff_Ioo_same Set.Ioc_diff_Ioo_same @[simp] theorem Icc_diff_Ico_same (h : a ≤ b) : Icc a b \ Ico a b = {b} := by rw [← Icc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 <| right_mem_Icc.2 h)] #align set.Icc_diff_Ico_same Set.Icc_diff_Ico_same @[simp] theorem Icc_diff_Ioc_same (h : a ≤ b) : Icc a b \ Ioc a b = {a} := by rw [← Icc_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 <| left_mem_Icc.2 h)] #align set.Icc_diff_Ioc_same Set.Icc_diff_Ioc_same @[simp]
Mathlib/Order/Interval/Set/Basic.lean
860
862
theorem Icc_diff_Ioo_same (h : a ≤ b) : Icc a b \ Ioo a b = {a, b} := by
rw [← Icc_diff_both, diff_diff_cancel_left] simp [insert_subset_iff, h]
/- Copyright (c) 2022 Benjamin Davidson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Benjamin Davidson, Devon Tuma, Eric Rodriguez, Oliver Nash -/ import Mathlib.Data.Set.Pointwise.Interval import Mathlib.Topology.Algebra.Field import Mathlib.Topology.Algebra.Order.Group #align_import topology.algebra.order.field from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd" /-! # Topologies on linear ordered fields In this file we prove that a linear ordered field with order topology has continuous multiplication and division (apart from zero in the denominator). We also prove theorems like `Filter.Tendsto.mul_atTop`: if `f` tends to a positive number and `g` tends to positive infinity, then `f * g` tends to positive infinity. -/ open Set Filter TopologicalSpace Function open scoped Pointwise Topology open OrderDual (toDual ofDual) /-- If a (possibly non-unital and/or non-associative) ring `R` admits a submultiplicative nonnegative norm `norm : R → 𝕜`, where `𝕜` is a linear ordered field, and the open balls `{ x | norm x < ε }`, `ε > 0`, form a basis of neighborhoods of zero, then `R` is a topological ring. -/ theorem TopologicalRing.of_norm {R 𝕜 : Type*} [NonUnitalNonAssocRing R] [LinearOrderedField 𝕜] [TopologicalSpace R] [TopologicalAddGroup R] (norm : R → 𝕜) (norm_nonneg : ∀ x, 0 ≤ norm x) (norm_mul_le : ∀ x y, norm (x * y) ≤ norm x * norm y) (nhds_basis : (𝓝 (0 : R)).HasBasis ((0 : 𝕜) < ·) (fun ε ↦ { x | norm x < ε })) : TopologicalRing R := by have h0 : ∀ f : R → R, ∀ c ≥ (0 : 𝕜), (∀ x, norm (f x) ≤ c * norm x) → Tendsto f (𝓝 0) (𝓝 0) := by refine fun f c c0 hf ↦ (nhds_basis.tendsto_iff nhds_basis).2 fun ε ε0 ↦ ?_ rcases exists_pos_mul_lt ε0 c with ⟨δ, δ0, hδ⟩ refine ⟨δ, δ0, fun x hx ↦ (hf _).trans_lt ?_⟩ exact (mul_le_mul_of_nonneg_left (le_of_lt hx) c0).trans_lt hδ apply TopologicalRing.of_addGroup_of_nhds_zero case hmul => refine ((nhds_basis.prod nhds_basis).tendsto_iff nhds_basis).2 fun ε ε0 ↦ ?_ refine ⟨(1, ε), ⟨one_pos, ε0⟩, fun (x, y) ⟨hx, hy⟩ => ?_⟩ simp only [sub_zero] at * calc norm (x * y) ≤ norm x * norm y := norm_mul_le _ _ _ < ε := mul_lt_of_le_one_of_lt_of_nonneg hx.le hy (norm_nonneg _) case hmul_left => exact fun x => h0 _ (norm x) (norm_nonneg _) (norm_mul_le x) case hmul_right => exact fun y => h0 (· * y) (norm y) (norm_nonneg y) fun x => (norm_mul_le x y).trans_eq (mul_comm _ _) variable {𝕜 α : Type*} [LinearOrderedField 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜] {l : Filter α} {f g : α → 𝕜} -- see Note [lower instance priority] instance (priority := 100) LinearOrderedField.topologicalRing : TopologicalRing 𝕜 := .of_norm abs abs_nonneg (fun _ _ ↦ (abs_mul _ _).le) <| by simpa using nhds_basis_abs_sub_lt (0 : 𝕜) /-- In a linearly ordered field with the order topology, if `f` tends to `Filter.atTop` and `g` tends to a positive constant `C` then `f * g` tends to `Filter.atTop`. -/ theorem Filter.Tendsto.atTop_mul {C : 𝕜} (hC : 0 < C) (hf : Tendsto f l atTop) (hg : Tendsto g l (𝓝 C)) : Tendsto (fun x => f x * g x) l atTop := by refine tendsto_atTop_mono' _ ?_ (hf.atTop_mul_const (half_pos hC)) filter_upwards [hg.eventually (lt_mem_nhds (half_lt_self hC)), hf.eventually_ge_atTop 0] with x hg hf using mul_le_mul_of_nonneg_left hg.le hf #align filter.tendsto.at_top_mul Filter.Tendsto.atTop_mul /-- In a linearly ordered field with the order topology, if `f` tends to a positive constant `C` and `g` tends to `Filter.atTop` then `f * g` tends to `Filter.atTop`. -/ theorem Filter.Tendsto.mul_atTop {C : 𝕜} (hC : 0 < C) (hf : Tendsto f l (𝓝 C)) (hg : Tendsto g l atTop) : Tendsto (fun x => f x * g x) l atTop := by simpa only [mul_comm] using hg.atTop_mul hC hf #align filter.tendsto.mul_at_top Filter.Tendsto.mul_atTop /-- In a linearly ordered field with the order topology, if `f` tends to `Filter.atTop` and `g` tends to a negative constant `C` then `f * g` tends to `Filter.atBot`. -/ theorem Filter.Tendsto.atTop_mul_neg {C : 𝕜} (hC : C < 0) (hf : Tendsto f l atTop) (hg : Tendsto g l (𝓝 C)) : Tendsto (fun x => f x * g x) l atBot := by have := hf.atTop_mul (neg_pos.2 hC) hg.neg simpa only [(· ∘ ·), neg_mul_eq_mul_neg, neg_neg] using tendsto_neg_atTop_atBot.comp this #align filter.tendsto.at_top_mul_neg Filter.Tendsto.atTop_mul_neg /-- In a linearly ordered field with the order topology, if `f` tends to a negative constant `C` and `g` tends to `Filter.atTop` then `f * g` tends to `Filter.atBot`. -/ theorem Filter.Tendsto.neg_mul_atTop {C : 𝕜} (hC : C < 0) (hf : Tendsto f l (𝓝 C)) (hg : Tendsto g l atTop) : Tendsto (fun x => f x * g x) l atBot := by simpa only [mul_comm] using hg.atTop_mul_neg hC hf #align filter.tendsto.neg_mul_at_top Filter.Tendsto.neg_mul_atTop /-- In a linearly ordered field with the order topology, if `f` tends to `Filter.atBot` and `g` tends to a positive constant `C` then `f * g` tends to `Filter.atBot`. -/ theorem Filter.Tendsto.atBot_mul {C : 𝕜} (hC : 0 < C) (hf : Tendsto f l atBot) (hg : Tendsto g l (𝓝 C)) : Tendsto (fun x => f x * g x) l atBot := by have := (tendsto_neg_atBot_atTop.comp hf).atTop_mul hC hg simpa [(· ∘ ·)] using tendsto_neg_atTop_atBot.comp this #align filter.tendsto.at_bot_mul Filter.Tendsto.atBot_mul /-- In a linearly ordered field with the order topology, if `f` tends to `Filter.atBot` and `g` tends to a negative constant `C` then `f * g` tends to `Filter.atTop`. -/ theorem Filter.Tendsto.atBot_mul_neg {C : 𝕜} (hC : C < 0) (hf : Tendsto f l atBot) (hg : Tendsto g l (𝓝 C)) : Tendsto (fun x => f x * g x) l atTop := by have := (tendsto_neg_atBot_atTop.comp hf).atTop_mul_neg hC hg simpa [(· ∘ ·)] using tendsto_neg_atBot_atTop.comp this #align filter.tendsto.at_bot_mul_neg Filter.Tendsto.atBot_mul_neg /-- In a linearly ordered field with the order topology, if `f` tends to a positive constant `C` and `g` tends to `Filter.atBot` then `f * g` tends to `Filter.atBot`. -/ theorem Filter.Tendsto.mul_atBot {C : 𝕜} (hC : 0 < C) (hf : Tendsto f l (𝓝 C)) (hg : Tendsto g l atBot) : Tendsto (fun x => f x * g x) l atBot := by simpa only [mul_comm] using hg.atBot_mul hC hf #align filter.tendsto.mul_at_bot Filter.Tendsto.mul_atBot /-- In a linearly ordered field with the order topology, if `f` tends to a negative constant `C` and `g` tends to `Filter.atBot` then `f * g` tends to `Filter.atTop`. -/ theorem Filter.Tendsto.neg_mul_atBot {C : 𝕜} (hC : C < 0) (hf : Tendsto f l (𝓝 C)) (hg : Tendsto g l atBot) : Tendsto (fun x => f x * g x) l atTop := by simpa only [mul_comm] using hg.atBot_mul_neg hC hf #align filter.tendsto.neg_mul_at_bot Filter.Tendsto.neg_mul_atBot @[simp] lemma inv_atTop₀ : (atTop : Filter 𝕜)⁻¹ = 𝓝[>] 0 := (((atTop_basis_Ioi' (0 : 𝕜)).map _).comp_surjective inv_surjective).eq_of_same_basis <| (nhdsWithin_Ioi_basis _).congr (by simp) fun a ha ↦ by simp [inv_Ioi (inv_pos.2 ha)] @[simp] lemma inv_nhdsWithin_Ioi_zero : (𝓝[>] (0 : 𝕜))⁻¹ = atTop := by rw [← inv_atTop₀, inv_inv] /-- The function `x ↦ x⁻¹` tends to `+∞` on the right of `0`. -/ theorem tendsto_inv_zero_atTop : Tendsto (fun x : 𝕜 => x⁻¹) (𝓝[>] (0 : 𝕜)) atTop := inv_nhdsWithin_Ioi_zero.le #align tendsto_inv_zero_at_top tendsto_inv_zero_atTop /-- The function `r ↦ r⁻¹` tends to `0` on the right as `r → +∞`. -/ theorem tendsto_inv_atTop_zero' : Tendsto (fun r : 𝕜 => r⁻¹) atTop (𝓝[>] (0 : 𝕜)) := inv_atTop₀.le #align tendsto_inv_at_top_zero' tendsto_inv_atTop_zero' theorem tendsto_inv_atTop_zero : Tendsto (fun r : 𝕜 => r⁻¹) atTop (𝓝 0) := tendsto_inv_atTop_zero'.mono_right inf_le_left #align tendsto_inv_at_top_zero tendsto_inv_atTop_zero theorem Filter.Tendsto.div_atTop {a : 𝕜} (h : Tendsto f l (𝓝 a)) (hg : Tendsto g l atTop) : Tendsto (fun x => f x / g x) l (𝓝 0) := by simp only [div_eq_mul_inv] exact mul_zero a ▸ h.mul (tendsto_inv_atTop_zero.comp hg) #align filter.tendsto.div_at_top Filter.Tendsto.div_atTop theorem Filter.Tendsto.inv_tendsto_atTop (h : Tendsto f l atTop) : Tendsto f⁻¹ l (𝓝 0) := tendsto_inv_atTop_zero.comp h #align filter.tendsto.inv_tendsto_at_top Filter.Tendsto.inv_tendsto_atTop theorem Filter.Tendsto.inv_tendsto_zero (h : Tendsto f l (𝓝[>] 0)) : Tendsto f⁻¹ l atTop := tendsto_inv_zero_atTop.comp h #align filter.tendsto.inv_tendsto_zero Filter.Tendsto.inv_tendsto_zero /-- The function `x^(-n)` tends to `0` at `+∞` for any positive natural `n`. A version for positive real powers exists as `tendsto_rpow_neg_atTop`. -/ theorem tendsto_pow_neg_atTop {n : ℕ} (hn : n ≠ 0) : Tendsto (fun x : 𝕜 => x ^ (-(n : ℤ))) atTop (𝓝 0) := by simpa only [zpow_neg, zpow_natCast] using (@tendsto_pow_atTop 𝕜 _ _ hn).inv_tendsto_atTop #align tendsto_pow_neg_at_top tendsto_pow_neg_atTop theorem tendsto_zpow_atTop_zero {n : ℤ} (hn : n < 0) : Tendsto (fun x : 𝕜 => x ^ n) atTop (𝓝 0) := by lift -n to ℕ using le_of_lt (neg_pos.mpr hn) with N h rw [← neg_pos, ← h, Nat.cast_pos] at hn simpa only [h, neg_neg] using tendsto_pow_neg_atTop hn.ne' #align tendsto_zpow_at_top_zero tendsto_zpow_atTop_zero theorem tendsto_const_mul_zpow_atTop_zero {n : ℤ} {c : 𝕜} (hn : n < 0) : Tendsto (fun x => c * x ^ n) atTop (𝓝 0) := mul_zero c ▸ Filter.Tendsto.const_mul c (tendsto_zpow_atTop_zero hn) #align tendsto_const_mul_zpow_at_top_zero tendsto_const_mul_zpow_atTop_zero theorem tendsto_const_mul_pow_nhds_iff' {n : ℕ} {c d : 𝕜} : Tendsto (fun x : 𝕜 => c * x ^ n) atTop (𝓝 d) ↔ (c = 0 ∨ n = 0) ∧ c = d := by rcases eq_or_ne n 0 with (rfl | hn) · simp [tendsto_const_nhds_iff] rcases lt_trichotomy c 0 with (hc | rfl | hc) · have := tendsto_const_mul_pow_atBot_iff.2 ⟨hn, hc⟩ simp [not_tendsto_nhds_of_tendsto_atBot this, hc.ne, hn] · simp [tendsto_const_nhds_iff] · have := tendsto_const_mul_pow_atTop_iff.2 ⟨hn, hc⟩ simp [not_tendsto_nhds_of_tendsto_atTop this, hc.ne', hn] #align tendsto_const_mul_pow_nhds_iff' tendsto_const_mul_pow_nhds_iff'
Mathlib/Topology/Algebra/Order/Field.lean
189
191
theorem tendsto_const_mul_pow_nhds_iff {n : ℕ} {c d : 𝕜} (hc : c ≠ 0) : Tendsto (fun x : 𝕜 => c * x ^ n) atTop (𝓝 d) ↔ n = 0 ∧ c = d := by
simp [tendsto_const_mul_pow_nhds_iff', hc]
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Order.CompleteLattice import Mathlib.Order.Cover import Mathlib.Order.Iterate import Mathlib.Order.WellFounded #align_import order.succ_pred.basic from "leanprover-community/mathlib"@"0111834459f5d7400215223ea95ae38a1265a907" /-! # Successor and predecessor This file defines successor and predecessor orders. `succ a`, the successor of an element `a : α` is the least element greater than `a`. `pred a` is the greatest element less than `a`. Typical examples include `ℕ`, `ℤ`, `ℕ+`, `Fin n`, but also `ENat`, the lexicographic order of a successor/predecessor order... ## Typeclasses * `SuccOrder`: Order equipped with a sensible successor function. * `PredOrder`: Order equipped with a sensible predecessor function. * `IsSuccArchimedean`: `SuccOrder` where `succ` iterated to an element gives all the greater ones. * `IsPredArchimedean`: `PredOrder` where `pred` iterated to an element gives all the smaller ones. ## Implementation notes Maximal elements don't have a sensible successor. Thus the naïve typeclass ```lean class NaiveSuccOrder (α : Type*) [Preorder α] := (succ : α → α) (succ_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b) (lt_succ_iff : ∀ {a b}, a < succ b ↔ a ≤ b) ``` can't apply to an `OrderTop` because plugging in `a = b = ⊤` into either of `succ_le_iff` and `lt_succ_iff` yields `⊤ < ⊤` (or more generally `m < m` for a maximal element `m`). The solution taken here is to remove the implications `≤ → <` and instead require that `a < succ a` for all non maximal elements (enforced by the combination of `le_succ` and the contrapositive of `max_of_succ_le`). The stricter condition of every element having a sensible successor can be obtained through the combination of `SuccOrder α` and `NoMaxOrder α`. ## TODO Is `GaloisConnection pred succ` always true? If not, we should introduce ```lean class SuccPredOrder (α : Type*) [Preorder α] extends SuccOrder α, PredOrder α := (pred_succ_gc : GaloisConnection (pred : α → α) succ) ``` `CovBy` should help here. -/ open Function OrderDual Set variable {α β : Type*} /-- Order equipped with a sensible successor function. -/ @[ext] class SuccOrder (α : Type*) [Preorder α] where /-- Successor function-/ succ : α → α /-- Proof of basic ordering with respect to `succ`-/ le_succ : ∀ a, a ≤ succ a /-- Proof of interaction between `succ` and maximal element-/ max_of_succ_le {a} : succ a ≤ a → IsMax a /-- Proof that `succ` satisfies ordering invariants between `LT` and `LE`-/ succ_le_of_lt {a b} : a < b → succ a ≤ b /-- Proof that `succ` satisfies ordering invariants between `LE` and `LT`-/ le_of_lt_succ {a b} : a < succ b → a ≤ b #align succ_order SuccOrder #align succ_order.ext_iff SuccOrder.ext_iff #align succ_order.ext SuccOrder.ext /-- Order equipped with a sensible predecessor function. -/ @[ext] class PredOrder (α : Type*) [Preorder α] where /-- Predecessor function-/ pred : α → α /-- Proof of basic ordering with respect to `pred`-/ pred_le : ∀ a, pred a ≤ a /-- Proof of interaction between `pred` and minimal element-/ min_of_le_pred {a} : a ≤ pred a → IsMin a /-- Proof that `pred` satisfies ordering invariants between `LT` and `LE`-/ le_pred_of_lt {a b} : a < b → a ≤ pred b /-- Proof that `pred` satisfies ordering invariants between `LE` and `LT`-/ le_of_pred_lt {a b} : pred a < b → a ≤ b #align pred_order PredOrder #align pred_order.ext PredOrder.ext #align pred_order.ext_iff PredOrder.ext_iff instance [Preorder α] [SuccOrder α] : PredOrder αᵒᵈ where pred := toDual ∘ SuccOrder.succ ∘ ofDual pred_le := by simp only [comp, OrderDual.forall, ofDual_toDual, toDual_le_toDual, SuccOrder.le_succ, implies_true] min_of_le_pred h := by apply SuccOrder.max_of_succ_le h le_pred_of_lt := by intro a b h; exact SuccOrder.succ_le_of_lt h le_of_pred_lt := SuccOrder.le_of_lt_succ instance [Preorder α] [PredOrder α] : SuccOrder αᵒᵈ where succ := toDual ∘ PredOrder.pred ∘ ofDual le_succ := by simp only [comp, OrderDual.forall, ofDual_toDual, toDual_le_toDual, PredOrder.pred_le, implies_true] max_of_succ_le h := by apply PredOrder.min_of_le_pred h succ_le_of_lt := by intro a b h; exact PredOrder.le_pred_of_lt h le_of_lt_succ := PredOrder.le_of_pred_lt section Preorder variable [Preorder α] /-- A constructor for `SuccOrder α` usable when `α` has no maximal element. -/ def SuccOrder.ofSuccLeIffOfLeLtSucc (succ : α → α) (hsucc_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b) (hle_of_lt_succ : ∀ {a b}, a < succ b → a ≤ b) : SuccOrder α := { succ le_succ := fun _ => (hsucc_le_iff.1 le_rfl).le max_of_succ_le := fun ha => (lt_irrefl _ <| hsucc_le_iff.1 ha).elim succ_le_of_lt := fun h => hsucc_le_iff.2 h le_of_lt_succ := fun h => hle_of_lt_succ h} #align succ_order.of_succ_le_iff_of_le_lt_succ SuccOrder.ofSuccLeIffOfLeLtSucc /-- A constructor for `PredOrder α` usable when `α` has no minimal element. -/ def PredOrder.ofLePredIffOfPredLePred (pred : α → α) (hle_pred_iff : ∀ {a b}, a ≤ pred b ↔ a < b) (hle_of_pred_lt : ∀ {a b}, pred a < b → a ≤ b) : PredOrder α := { pred pred_le := fun _ => (hle_pred_iff.1 le_rfl).le min_of_le_pred := fun ha => (lt_irrefl _ <| hle_pred_iff.1 ha).elim le_pred_of_lt := fun h => hle_pred_iff.2 h le_of_pred_lt := fun h => hle_of_pred_lt h } #align pred_order.of_le_pred_iff_of_pred_le_pred PredOrder.ofLePredIffOfPredLePred end Preorder section LinearOrder variable [LinearOrder α] /-- A constructor for `SuccOrder α` for `α` a linear order. -/ @[simps] def SuccOrder.ofCore (succ : α → α) (hn : ∀ {a}, ¬IsMax a → ∀ b, a < b ↔ succ a ≤ b) (hm : ∀ a, IsMax a → succ a = a) : SuccOrder α := { succ succ_le_of_lt := fun {a b} => by_cases (fun h hab => (hm a h).symm ▸ hab.le) fun h => (hn h b).mp le_succ := fun a => by_cases (fun h => (hm a h).symm.le) fun h => le_of_lt <| by simpa using (hn h a).not le_of_lt_succ := fun {a b} hab => by_cases (fun h => hm b h ▸ hab.le) fun h => by simpa [hab] using (hn h a).not max_of_succ_le := fun {a} => not_imp_not.mp fun h => by simpa using (hn h a).not } #align succ_order.of_core SuccOrder.ofCore #align succ_order.of_core_succ SuccOrder.ofCore_succ /-- A constructor for `PredOrder α` for `α` a linear order. -/ @[simps] def PredOrder.ofCore {α} [LinearOrder α] (pred : α → α) (hn : ∀ {a}, ¬IsMin a → ∀ b, b ≤ pred a ↔ b < a) (hm : ∀ a, IsMin a → pred a = a) : PredOrder α := { pred le_pred_of_lt := fun {a b} => by_cases (fun h hab => (hm b h).symm ▸ hab.le) fun h => (hn h a).mpr pred_le := fun a => by_cases (fun h => (hm a h).le) fun h => le_of_lt <| by simpa using (hn h a).not le_of_pred_lt := fun {a b} hab => by_cases (fun h => hm a h ▸ hab.le) fun h => by simpa [hab] using (hn h b).not min_of_le_pred := fun {a} => not_imp_not.mp fun h => by simpa using (hn h a).not } #align pred_order.of_core PredOrder.ofCore #align pred_order.of_core_pred PredOrder.ofCore_pred /-- A constructor for `SuccOrder α` usable when `α` is a linear order with no maximal element. -/ def SuccOrder.ofSuccLeIff (succ : α → α) (hsucc_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b) : SuccOrder α := { succ le_succ := fun _ => (hsucc_le_iff.1 le_rfl).le max_of_succ_le := fun ha => (lt_irrefl _ <| hsucc_le_iff.1 ha).elim succ_le_of_lt := fun h => hsucc_le_iff.2 h le_of_lt_succ := fun {_ _} h => le_of_not_lt ((not_congr hsucc_le_iff).1 h.not_le) } #align succ_order.of_succ_le_iff SuccOrder.ofSuccLeIff /-- A constructor for `PredOrder α` usable when `α` is a linear order with no minimal element. -/ def PredOrder.ofLePredIff (pred : α → α) (hle_pred_iff : ∀ {a b}, a ≤ pred b ↔ a < b) : PredOrder α := { pred pred_le := fun _ => (hle_pred_iff.1 le_rfl).le min_of_le_pred := fun ha => (lt_irrefl _ <| hle_pred_iff.1 ha).elim le_pred_of_lt := fun h => hle_pred_iff.2 h le_of_pred_lt := fun {_ _} h => le_of_not_lt ((not_congr hle_pred_iff).1 h.not_le) } #align pred_order.of_le_pred_iff PredOrder.ofLePredIff open scoped Classical variable (α) /-- A well-order is a `SuccOrder`. -/ noncomputable def SuccOrder.ofLinearWellFoundedLT [WellFoundedLT α] : SuccOrder α := ofCore (fun a ↦ if h : (Ioi a).Nonempty then wellFounded_lt.min _ h else a) (fun ha _ ↦ by rw [not_isMax_iff] at ha simp_rw [Set.Nonempty, mem_Ioi, dif_pos ha] exact ⟨(wellFounded_lt.min_le · ha), lt_of_lt_of_le (wellFounded_lt.min_mem _ ha)⟩) fun a ha ↦ dif_neg (not_not_intro ha <| not_isMax_iff.mpr ·) /-- A linear order with well-founded greater-than relation is a `PredOrder`. -/ noncomputable def PredOrder.ofLinearWellFoundedGT (α) [LinearOrder α] [WellFoundedGT α] : PredOrder α := letI := SuccOrder.ofLinearWellFoundedLT αᵒᵈ; inferInstanceAs (PredOrder αᵒᵈᵒᵈ) end LinearOrder /-! ### Successor order -/ namespace Order section Preorder variable [Preorder α] [SuccOrder α] {a b : α} /-- The successor of an element. If `a` is not maximal, then `succ a` is the least element greater than `a`. If `a` is maximal, then `succ a = a`. -/ def succ : α → α := SuccOrder.succ #align order.succ Order.succ theorem le_succ : ∀ a : α, a ≤ succ a := SuccOrder.le_succ #align order.le_succ Order.le_succ theorem max_of_succ_le {a : α} : succ a ≤ a → IsMax a := SuccOrder.max_of_succ_le #align order.max_of_succ_le Order.max_of_succ_le theorem succ_le_of_lt {a b : α} : a < b → succ a ≤ b := SuccOrder.succ_le_of_lt #align order.succ_le_of_lt Order.succ_le_of_lt theorem le_of_lt_succ {a b : α} : a < succ b → a ≤ b := SuccOrder.le_of_lt_succ #align order.le_of_lt_succ Order.le_of_lt_succ @[simp] theorem succ_le_iff_isMax : succ a ≤ a ↔ IsMax a := ⟨max_of_succ_le, fun h => h <| le_succ _⟩ #align order.succ_le_iff_is_max Order.succ_le_iff_isMax @[simp] theorem lt_succ_iff_not_isMax : a < succ a ↔ ¬IsMax a := ⟨not_isMax_of_lt, fun ha => (le_succ a).lt_of_not_le fun h => ha <| max_of_succ_le h⟩ #align order.lt_succ_iff_not_is_max Order.lt_succ_iff_not_isMax alias ⟨_, lt_succ_of_not_isMax⟩ := lt_succ_iff_not_isMax #align order.lt_succ_of_not_is_max Order.lt_succ_of_not_isMax theorem wcovBy_succ (a : α) : a ⩿ succ a := ⟨le_succ a, fun _ hb => (succ_le_of_lt hb).not_lt⟩ #align order.wcovby_succ Order.wcovBy_succ theorem covBy_succ_of_not_isMax (h : ¬IsMax a) : a ⋖ succ a := (wcovBy_succ a).covBy_of_lt <| lt_succ_of_not_isMax h #align order.covby_succ_of_not_is_max Order.covBy_succ_of_not_isMax theorem lt_succ_iff_of_not_isMax (ha : ¬IsMax a) : b < succ a ↔ b ≤ a := ⟨le_of_lt_succ, fun h => h.trans_lt <| lt_succ_of_not_isMax ha⟩ #align order.lt_succ_iff_of_not_is_max Order.lt_succ_iff_of_not_isMax theorem succ_le_iff_of_not_isMax (ha : ¬IsMax a) : succ a ≤ b ↔ a < b := ⟨(lt_succ_of_not_isMax ha).trans_le, succ_le_of_lt⟩ #align order.succ_le_iff_of_not_is_max Order.succ_le_iff_of_not_isMax lemma succ_lt_succ_of_not_isMax (h : a < b) (hb : ¬ IsMax b) : succ a < succ b := (lt_succ_iff_of_not_isMax hb).2 <| succ_le_of_lt h theorem succ_lt_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) : succ a < succ b ↔ a < b := by rw [lt_succ_iff_of_not_isMax hb, succ_le_iff_of_not_isMax ha] #align order.succ_lt_succ_iff_of_not_is_max Order.succ_lt_succ_iff_of_not_isMax theorem succ_le_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) : succ a ≤ succ b ↔ a ≤ b := by rw [succ_le_iff_of_not_isMax ha, lt_succ_iff_of_not_isMax hb] #align order.succ_le_succ_iff_of_not_is_max Order.succ_le_succ_iff_of_not_isMax @[simp, mono] theorem succ_le_succ (h : a ≤ b) : succ a ≤ succ b := by by_cases hb : IsMax b · by_cases hba : b ≤ a · exact (hb <| hba.trans <| le_succ _).trans (le_succ _) · exact succ_le_of_lt ((h.lt_of_not_le hba).trans_le <| le_succ b) · rwa [succ_le_iff_of_not_isMax fun ha => hb <| ha.mono h, lt_succ_iff_of_not_isMax hb] #align order.succ_le_succ Order.succ_le_succ theorem succ_mono : Monotone (succ : α → α) := fun _ _ => succ_le_succ #align order.succ_mono Order.succ_mono theorem le_succ_iterate (k : ℕ) (x : α) : x ≤ succ^[k] x := by conv_lhs => rw [(by simp only [Function.iterate_id, id] : x = id^[k] x)] exact Monotone.le_iterate_of_le succ_mono le_succ k x #align order.le_succ_iterate Order.le_succ_iterate theorem isMax_iterate_succ_of_eq_of_lt {n m : ℕ} (h_eq : succ^[n] a = succ^[m] a) (h_lt : n < m) : IsMax (succ^[n] a) := by refine max_of_succ_le (le_trans ?_ h_eq.symm.le) have : succ (succ^[n] a) = succ^[n + 1] a := by rw [Function.iterate_succ', comp] rw [this] have h_le : n + 1 ≤ m := Nat.succ_le_of_lt h_lt exact Monotone.monotone_iterate_of_le_map succ_mono (le_succ a) h_le #align order.is_max_iterate_succ_of_eq_of_lt Order.isMax_iterate_succ_of_eq_of_lt theorem isMax_iterate_succ_of_eq_of_ne {n m : ℕ} (h_eq : succ^[n] a = succ^[m] a) (h_ne : n ≠ m) : IsMax (succ^[n] a) := by rcases le_total n m with h | h · exact isMax_iterate_succ_of_eq_of_lt h_eq (lt_of_le_of_ne h h_ne) · rw [h_eq] exact isMax_iterate_succ_of_eq_of_lt h_eq.symm (lt_of_le_of_ne h h_ne.symm) #align order.is_max_iterate_succ_of_eq_of_ne Order.isMax_iterate_succ_of_eq_of_ne theorem Iio_succ_of_not_isMax (ha : ¬IsMax a) : Iio (succ a) = Iic a := Set.ext fun _ => lt_succ_iff_of_not_isMax ha #align order.Iio_succ_of_not_is_max Order.Iio_succ_of_not_isMax theorem Ici_succ_of_not_isMax (ha : ¬IsMax a) : Ici (succ a) = Ioi a := Set.ext fun _ => succ_le_iff_of_not_isMax ha #align order.Ici_succ_of_not_is_max Order.Ici_succ_of_not_isMax
Mathlib/Order/SuccPred/Basic.lean
331
332
theorem Ico_succ_right_of_not_isMax (hb : ¬IsMax b) : Ico a (succ b) = Icc a b := by
rw [← Ici_inter_Iio, Iio_succ_of_not_isMax hb, Ici_inter_Iic]
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Chris Hughes, Floris van Doorn, Yaël Dillies -/ import Mathlib.Data.Nat.Defs import Mathlib.Tactic.GCongr.Core import Mathlib.Tactic.Common import Mathlib.Tactic.Monotonicity.Attr #align_import data.nat.factorial.basic from "leanprover-community/mathlib"@"d012cd09a9b256d870751284dd6a29882b0be105" /-! # Factorial and variants This file defines the factorial, along with the ascending and descending variants. ## Main declarations * `Nat.factorial`: The factorial. * `Nat.ascFactorial`: The ascending factorial. It is the product of natural numbers from `n` to `n + k - 1`. * `Nat.descFactorial`: The descending factorial. It is the product of natural numbers from `n - k + 1` to `n`. -/ namespace Nat /-- `Nat.factorial n` is the factorial of `n`. -/ def factorial : ℕ → ℕ | 0 => 1 | succ n => succ n * factorial n #align nat.factorial Nat.factorial /-- factorial notation `n!` -/ scoped notation:10000 n "!" => Nat.factorial n section Factorial variable {m n : ℕ} @[simp] theorem factorial_zero : 0! = 1 := rfl #align nat.factorial_zero Nat.factorial_zero theorem factorial_succ (n : ℕ) : (n + 1)! = (n + 1) * n ! := rfl #align nat.factorial_succ Nat.factorial_succ @[simp] theorem factorial_one : 1! = 1 := rfl #align nat.factorial_one Nat.factorial_one @[simp] theorem factorial_two : 2! = 2 := rfl #align nat.factorial_two Nat.factorial_two theorem mul_factorial_pred (hn : 0 < n) : n * (n - 1)! = n ! := Nat.sub_add_cancel (Nat.succ_le_of_lt hn) ▸ rfl #align nat.mul_factorial_pred Nat.mul_factorial_pred theorem factorial_pos : ∀ n, 0 < n ! | 0 => Nat.zero_lt_one | succ n => Nat.mul_pos (succ_pos _) (factorial_pos n) #align nat.factorial_pos Nat.factorial_pos theorem factorial_ne_zero (n : ℕ) : n ! ≠ 0 := ne_of_gt (factorial_pos _) #align nat.factorial_ne_zero Nat.factorial_ne_zero theorem factorial_dvd_factorial {m n} (h : m ≤ n) : m ! ∣ n ! := by induction' h with n _ ih · exact Nat.dvd_refl _ · exact Nat.dvd_trans ih (Nat.dvd_mul_left _ _) #align nat.factorial_dvd_factorial Nat.factorial_dvd_factorial theorem dvd_factorial : ∀ {m n}, 0 < m → m ≤ n → m ∣ n ! | succ _, _, _, h => Nat.dvd_trans (Nat.dvd_mul_right _ _) (factorial_dvd_factorial h) #align nat.dvd_factorial Nat.dvd_factorial @[mono, gcongr] theorem factorial_le {m n} (h : m ≤ n) : m ! ≤ n ! := le_of_dvd (factorial_pos _) (factorial_dvd_factorial h) #align nat.factorial_le Nat.factorial_le theorem factorial_mul_pow_le_factorial : ∀ {m n : ℕ}, m ! * (m + 1) ^ n ≤ (m + n)! | m, 0 => by simp | m, n + 1 => by rw [← Nat.add_assoc, factorial_succ, Nat.mul_comm (_ + 1), Nat.pow_succ, ← Nat.mul_assoc] exact Nat.mul_le_mul factorial_mul_pow_le_factorial (succ_le_succ (le_add_right _ _)) #align nat.factorial_mul_pow_le_factorial Nat.factorial_mul_pow_le_factorial theorem factorial_lt (hn : 0 < n) : n ! < m ! ↔ n < m := by refine ⟨fun h => not_le.mp fun hmn => Nat.not_le_of_lt h (factorial_le hmn), fun h => ?_⟩ have : ∀ {n}, 0 < n → n ! < (n + 1)! := by intro k hk rw [factorial_succ, succ_mul, Nat.lt_add_left_iff_pos] exact Nat.mul_pos hk k.factorial_pos induction' h with k hnk ih generalizing hn · exact this hn · exact lt_trans (ih hn) $ this <| lt_trans hn <| lt_of_succ_le hnk #align nat.factorial_lt Nat.factorial_lt @[gcongr] lemma factorial_lt_of_lt {m n : ℕ} (hn : 0 < n) (h : n < m) : n ! < m ! := (factorial_lt hn).mpr h @[simp] lemma one_lt_factorial : 1 < n ! ↔ 1 < n := factorial_lt Nat.one_pos #align nat.one_lt_factorial Nat.one_lt_factorial @[simp] theorem factorial_eq_one : n ! = 1 ↔ n ≤ 1 := by constructor · intro h rw [← not_lt, ← one_lt_factorial, h] apply lt_irrefl · rintro (_|_|_) <;> rfl #align nat.factorial_eq_one Nat.factorial_eq_one theorem factorial_inj (hn : 1 < n) : n ! = m ! ↔ n = m := by refine ⟨fun h => ?_, congr_arg _⟩ obtain hnm | rfl | hnm := lt_trichotomy n m · rw [← factorial_lt <| lt_of_succ_lt hn, h] at hnm cases lt_irrefl _ hnm · rfl rw [← one_lt_factorial, h, one_lt_factorial] at hn rw [← factorial_lt <| lt_of_succ_lt hn, h] at hnm cases lt_irrefl _ hnm #align nat.factorial_inj Nat.factorial_inj theorem factorial_inj' (h : 1 < n ∨ 1 < m) : n ! = m ! ↔ n = m := by obtain hn|hm := h · exact factorial_inj hn · rw [eq_comm, factorial_inj hm, eq_comm] theorem self_le_factorial : ∀ n : ℕ, n ≤ n ! | 0 => Nat.zero_le _ | k + 1 => Nat.le_mul_of_pos_right _ (Nat.one_le_of_lt k.factorial_pos) #align nat.self_le_factorial Nat.self_le_factorial theorem lt_factorial_self {n : ℕ} (hi : 3 ≤ n) : n < n ! := by have : 0 < n := by omega have hn : 1 < pred n := le_pred_of_lt (succ_le_iff.mp hi) rw [← succ_pred_eq_of_pos ‹0 < n›, factorial_succ] exact (Nat.lt_mul_iff_one_lt_right (pred n).succ_pos).2 ((Nat.lt_of_lt_of_le hn (self_le_factorial _))) #align nat.lt_factorial_self Nat.lt_factorial_self theorem add_factorial_succ_lt_factorial_add_succ {i : ℕ} (n : ℕ) (hi : 2 ≤ i) : i + (n + 1)! < (i + n + 1)! := by rw [factorial_succ (i + _), Nat.add_mul, Nat.one_mul] have := (i + n).self_le_factorial refine Nat.add_lt_add_of_lt_of_le (Nat.lt_of_le_of_lt ?_ ((Nat.lt_mul_iff_one_lt_right ?_).2 ?_)) (factorial_le ?_) <;> omega #align nat.add_factorial_succ_lt_factorial_add_succ Nat.add_factorial_succ_lt_factorial_add_succ theorem add_factorial_lt_factorial_add {i n : ℕ} (hi : 2 ≤ i) (hn : 1 ≤ n) : i + n ! < (i + n)! := by cases hn · rw [factorial_one] exact lt_factorial_self (succ_le_succ hi) exact add_factorial_succ_lt_factorial_add_succ _ hi #align nat.add_factorial_lt_factorial_add Nat.add_factorial_lt_factorial_add theorem add_factorial_succ_le_factorial_add_succ (i : ℕ) (n : ℕ) : i + (n + 1)! ≤ (i + (n + 1))! := by cases (le_or_lt (2 : ℕ) i) · rw [← Nat.add_assoc] apply Nat.le_of_lt apply add_factorial_succ_lt_factorial_add_succ assumption · match i with | 0 => simp | 1 => rw [← Nat.add_assoc, factorial_succ (1 + n), Nat.add_mul, Nat.one_mul, Nat.add_comm 1 n, Nat.add_le_add_iff_right] exact Nat.mul_pos n.succ_pos n.succ.factorial_pos | succ (succ n) => contradiction #align nat.add_factorial_succ_le_factorial_add_succ Nat.add_factorial_succ_le_factorial_add_succ
Mathlib/Data/Nat/Factorial/Basic.lean
182
185
theorem add_factorial_le_factorial_add (i : ℕ) {n : ℕ} (n1 : 1 ≤ n) : i + n ! ≤ (i + n)! := by
cases' n1 with h · exact self_le_factorial _ exact add_factorial_succ_le_factorial_add_succ i h
/- Copyright (c) 2022 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Limits.Shapes.Pullbacks import Mathlib.CategoryTheory.Limits.Shapes.ZeroMorphisms import Mathlib.CategoryTheory.Limits.Constructions.BinaryProducts #align_import category_theory.limits.constructions.zero_objects from "leanprover-community/mathlib"@"52a270e2ea4e342c2587c106f8be904524214a4b" /-! # Limits involving zero objects Binary products and coproducts with a zero object always exist, and pullbacks/pushouts over a zero object are products/coproducts. -/ noncomputable section open CategoryTheory variable {C : Type*} [Category C] namespace CategoryTheory.Limits variable [HasZeroObject C] [HasZeroMorphisms C] open ZeroObject /-- The limit cone for the product with a zero object. -/ def binaryFanZeroLeft (X : C) : BinaryFan (0 : C) X := BinaryFan.mk 0 (𝟙 X) #align category_theory.limits.binary_fan_zero_left CategoryTheory.Limits.binaryFanZeroLeft /-- The limit cone for the product with a zero object is limiting. -/ def binaryFanZeroLeftIsLimit (X : C) : IsLimit (binaryFanZeroLeft X) := BinaryFan.isLimitMk (fun s => BinaryFan.snd s) (by aesop_cat) (by aesop_cat) (fun s m _ h₂ => by simpa using h₂) #align category_theory.limits.binary_fan_zero_left_is_limit CategoryTheory.Limits.binaryFanZeroLeftIsLimit instance hasBinaryProduct_zero_left (X : C) : HasBinaryProduct (0 : C) X := HasLimit.mk ⟨_, binaryFanZeroLeftIsLimit X⟩ #align category_theory.limits.has_binary_product_zero_left CategoryTheory.Limits.hasBinaryProduct_zero_left /-- A zero object is a left unit for categorical product. -/ def zeroProdIso (X : C) : (0 : C) ⨯ X ≅ X := limit.isoLimitCone ⟨_, binaryFanZeroLeftIsLimit X⟩ #align category_theory.limits.zero_prod_iso CategoryTheory.Limits.zeroProdIso @[simp] theorem zeroProdIso_hom (X : C) : (zeroProdIso X).hom = prod.snd := rfl #align category_theory.limits.zero_prod_iso_hom CategoryTheory.Limits.zeroProdIso_hom @[simp] theorem zeroProdIso_inv_snd (X : C) : (zeroProdIso X).inv ≫ prod.snd = 𝟙 X := by dsimp [zeroProdIso, binaryFanZeroLeft] simp #align category_theory.limits.zero_prod_iso_inv_snd CategoryTheory.Limits.zeroProdIso_inv_snd /-- The limit cone for the product with a zero object. -/ def binaryFanZeroRight (X : C) : BinaryFan X (0 : C) := BinaryFan.mk (𝟙 X) 0 #align category_theory.limits.binary_fan_zero_right CategoryTheory.Limits.binaryFanZeroRight /-- The limit cone for the product with a zero object is limiting. -/ def binaryFanZeroRightIsLimit (X : C) : IsLimit (binaryFanZeroRight X) := BinaryFan.isLimitMk (fun s => BinaryFan.fst s) (by aesop_cat) (by aesop_cat) (fun s m h₁ _ => by simpa using h₁) #align category_theory.limits.binary_fan_zero_right_is_limit CategoryTheory.Limits.binaryFanZeroRightIsLimit instance hasBinaryProduct_zero_right (X : C) : HasBinaryProduct X (0 : C) := HasLimit.mk ⟨_, binaryFanZeroRightIsLimit X⟩ #align category_theory.limits.has_binary_product_zero_right CategoryTheory.Limits.hasBinaryProduct_zero_right /-- A zero object is a right unit for categorical product. -/ def prodZeroIso (X : C) : X ⨯ (0 : C) ≅ X := limit.isoLimitCone ⟨_, binaryFanZeroRightIsLimit X⟩ #align category_theory.limits.prod_zero_iso CategoryTheory.Limits.prodZeroIso @[simp] theorem prodZeroIso_hom (X : C) : (prodZeroIso X).hom = prod.fst := rfl #align category_theory.limits.prod_zero_iso_hom CategoryTheory.Limits.prodZeroIso_hom @[simp] theorem prodZeroIso_iso_inv_snd (X : C) : (prodZeroIso X).inv ≫ prod.fst = 𝟙 X := by dsimp [prodZeroIso, binaryFanZeroRight] simp #align category_theory.limits.prod_zero_iso_iso_inv_snd CategoryTheory.Limits.prodZeroIso_iso_inv_snd /-- The colimit cocone for the coproduct with a zero object. -/ def binaryCofanZeroLeft (X : C) : BinaryCofan (0 : C) X := BinaryCofan.mk 0 (𝟙 X) #align category_theory.limits.binary_cofan_zero_left CategoryTheory.Limits.binaryCofanZeroLeft /-- The colimit cocone for the coproduct with a zero object is colimiting. -/ def binaryCofanZeroLeftIsColimit (X : C) : IsColimit (binaryCofanZeroLeft X) := BinaryCofan.isColimitMk (fun s => BinaryCofan.inr s) (by aesop_cat) (by aesop_cat) (fun s m _ h₂ => by simpa using h₂) #align category_theory.limits.binary_cofan_zero_left_is_colimit CategoryTheory.Limits.binaryCofanZeroLeftIsColimit instance hasBinaryCoproduct_zero_left (X : C) : HasBinaryCoproduct (0 : C) X := HasColimit.mk ⟨_, binaryCofanZeroLeftIsColimit X⟩ #align category_theory.limits.has_binary_coproduct_zero_left CategoryTheory.Limits.hasBinaryCoproduct_zero_left /-- A zero object is a left unit for categorical coproduct. -/ def zeroCoprodIso (X : C) : (0 : C) ⨿ X ≅ X := colimit.isoColimitCocone ⟨_, binaryCofanZeroLeftIsColimit X⟩ #align category_theory.limits.zero_coprod_iso CategoryTheory.Limits.zeroCoprodIso @[simp] theorem inr_zeroCoprodIso_hom (X : C) : coprod.inr ≫ (zeroCoprodIso X).hom = 𝟙 X := by dsimp [zeroCoprodIso, binaryCofanZeroLeft] simp #align category_theory.limits.inr_zero_coprod_iso_hom CategoryTheory.Limits.inr_zeroCoprodIso_hom @[simp] theorem zeroCoprodIso_inv (X : C) : (zeroCoprodIso X).inv = coprod.inr := rfl #align category_theory.limits.zero_coprod_iso_inv CategoryTheory.Limits.zeroCoprodIso_inv /-- The colimit cocone for the coproduct with a zero object. -/ def binaryCofanZeroRight (X : C) : BinaryCofan X (0 : C) := BinaryCofan.mk (𝟙 X) 0 #align category_theory.limits.binary_cofan_zero_right CategoryTheory.Limits.binaryCofanZeroRight /-- The colimit cocone for the coproduct with a zero object is colimiting. -/ def binaryCofanZeroRightIsColimit (X : C) : IsColimit (binaryCofanZeroRight X) := BinaryCofan.isColimitMk (fun s => BinaryCofan.inl s) (by aesop_cat) (by aesop_cat) (fun s m h₁ _ => by simpa using h₁) #align category_theory.limits.binary_cofan_zero_right_is_colimit CategoryTheory.Limits.binaryCofanZeroRightIsColimit instance hasBinaryCoproduct_zero_right (X : C) : HasBinaryCoproduct X (0 : C) := HasColimit.mk ⟨_, binaryCofanZeroRightIsColimit X⟩ #align category_theory.limits.has_binary_coproduct_zero_right CategoryTheory.Limits.hasBinaryCoproduct_zero_right /-- A zero object is a right unit for categorical coproduct. -/ def coprodZeroIso (X : C) : X ⨿ (0 : C) ≅ X := colimit.isoColimitCocone ⟨_, binaryCofanZeroRightIsColimit X⟩ #align category_theory.limits.coprod_zero_iso CategoryTheory.Limits.coprodZeroIso @[simp] theorem inr_coprodZeroIso_hom (X : C) : coprod.inl ≫ (coprodZeroIso X).hom = 𝟙 X := by dsimp [coprodZeroIso, binaryCofanZeroRight] simp #align category_theory.limits.inr_coprod_zeroiso_hom CategoryTheory.Limits.inr_coprodZeroIso_hom @[simp] theorem coprodZeroIso_inv (X : C) : (coprodZeroIso X).inv = coprod.inl := rfl #align category_theory.limits.coprod_zero_iso_inv CategoryTheory.Limits.coprodZeroIso_inv instance hasPullback_over_zero (X Y : C) [HasBinaryProduct X Y] : HasPullback (0 : X ⟶ 0) (0 : Y ⟶ 0) := HasLimit.mk ⟨_, isPullbackOfIsTerminalIsProduct _ _ _ _ HasZeroObject.zeroIsTerminal (prodIsProd X Y)⟩ #align category_theory.limits.has_pullback_over_zero CategoryTheory.Limits.hasPullback_over_zero /-- The pullback over the zero object is the product. -/ def pullbackZeroZeroIso (X Y : C) [HasBinaryProduct X Y] : pullback (0 : X ⟶ 0) (0 : Y ⟶ 0) ≅ X ⨯ Y := limit.isoLimitCone ⟨_, isPullbackOfIsTerminalIsProduct _ _ _ _ HasZeroObject.zeroIsTerminal (prodIsProd X Y)⟩ #align category_theory.limits.pullback_zero_zero_iso CategoryTheory.Limits.pullbackZeroZeroIso @[simp] theorem pullbackZeroZeroIso_inv_fst (X Y : C) [HasBinaryProduct X Y] : (pullbackZeroZeroIso X Y).inv ≫ pullback.fst = prod.fst := by dsimp [pullbackZeroZeroIso] simp #align category_theory.limits.pullback_zero_zero_iso_inv_fst CategoryTheory.Limits.pullbackZeroZeroIso_inv_fst @[simp] theorem pullbackZeroZeroIso_inv_snd (X Y : C) [HasBinaryProduct X Y] : (pullbackZeroZeroIso X Y).inv ≫ pullback.snd = prod.snd := by dsimp [pullbackZeroZeroIso] simp #align category_theory.limits.pullback_zero_zero_iso_inv_snd CategoryTheory.Limits.pullbackZeroZeroIso_inv_snd @[simp] theorem pullbackZeroZeroIso_hom_fst (X Y : C) [HasBinaryProduct X Y] : (pullbackZeroZeroIso X Y).hom ≫ prod.fst = pullback.fst := by simp [← Iso.eq_inv_comp] #align category_theory.limits.pullback_zero_zero_iso_hom_fst CategoryTheory.Limits.pullbackZeroZeroIso_hom_fst @[simp] theorem pullbackZeroZeroIso_hom_snd (X Y : C) [HasBinaryProduct X Y] : (pullbackZeroZeroIso X Y).hom ≫ prod.snd = pullback.snd := by simp [← Iso.eq_inv_comp] #align category_theory.limits.pullback_zero_zero_iso_hom_snd CategoryTheory.Limits.pullbackZeroZeroIso_hom_snd instance hasPushout_over_zero (X Y : C) [HasBinaryCoproduct X Y] : HasPushout (0 : 0 ⟶ X) (0 : 0 ⟶ Y) := HasColimit.mk ⟨_, isPushoutOfIsInitialIsCoproduct _ _ _ _ HasZeroObject.zeroIsInitial (coprodIsCoprod X Y)⟩ #align category_theory.limits.has_pushout_over_zero CategoryTheory.Limits.hasPushout_over_zero /-- The pushout over the zero object is the coproduct. -/ def pushoutZeroZeroIso (X Y : C) [HasBinaryCoproduct X Y] : pushout (0 : 0 ⟶ X) (0 : 0 ⟶ Y) ≅ X ⨿ Y := colimit.isoColimitCocone ⟨_, isPushoutOfIsInitialIsCoproduct _ _ _ _ HasZeroObject.zeroIsInitial (coprodIsCoprod X Y)⟩ #align category_theory.limits.pushout_zero_zero_iso CategoryTheory.Limits.pushoutZeroZeroIso @[simp] theorem inl_pushoutZeroZeroIso_hom (X Y : C) [HasBinaryCoproduct X Y] : pushout.inl ≫ (pushoutZeroZeroIso X Y).hom = coprod.inl := by dsimp [pushoutZeroZeroIso] simp #align category_theory.limits.inl_pushout_zero_zero_iso_hom CategoryTheory.Limits.inl_pushoutZeroZeroIso_hom @[simp] theorem inr_pushoutZeroZeroIso_hom (X Y : C) [HasBinaryCoproduct X Y] : pushout.inr ≫ (pushoutZeroZeroIso X Y).hom = coprod.inr := by dsimp [pushoutZeroZeroIso] simp #align category_theory.limits.inr_pushout_zero_zero_iso_hom CategoryTheory.Limits.inr_pushoutZeroZeroIso_hom @[simp]
Mathlib/CategoryTheory/Limits/Constructions/ZeroObjects.lean
221
222
theorem inl_pushoutZeroZeroIso_inv (X Y : C) [HasBinaryCoproduct X Y] : coprod.inl ≫ (pushoutZeroZeroIso X Y).inv = pushout.inl := by
simp [Iso.comp_inv_eq]
/- 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.LinearAlgebra.Finsupp import Mathlib.RingTheory.Ideal.Over import Mathlib.RingTheory.Ideal.Prod import Mathlib.RingTheory.Ideal.MinimalPrime import Mathlib.RingTheory.Localization.Away.Basic import Mathlib.RingTheory.Nilpotent.Lemmas import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.Sober #align_import algebraic_geometry.prime_spectrum.basic from "leanprover-community/mathlib"@"a7c017d750512a352b623b1824d75da5998457d0" /-! # Prime spectrum of a commutative (semi)ring The prime spectrum of a commutative (semi)ring is the type of all prime ideals. It is naturally endowed with a topology: the Zariski topology. (It is also naturally endowed with a sheaf of rings, which is constructed in `AlgebraicGeometry.StructureSheaf`.) ## Main definitions * `PrimeSpectrum R`: The prime spectrum of a commutative (semi)ring `R`, i.e., the set of all prime ideals of `R`. * `zeroLocus s`: The zero locus of a subset `s` of `R` is the subset of `PrimeSpectrum R` consisting of all prime ideals that contain `s`. * `vanishingIdeal t`: The vanishing ideal of a subset `t` of `PrimeSpectrum R` is the intersection of points in `t` (viewed as prime ideals). ## Conventions We denote subsets of (semi)rings with `s`, `s'`, etc... whereas we denote subsets of prime spectra with `t`, `t'`, etc... ## Inspiration/contributors The contents of this file draw inspiration from <https://github.com/ramonfmir/lean-scheme> which has contributions from Ramon Fernandez Mir, Kevin Buzzard, Kenny Lau, and Chris Hughes (on an earlier repository). -/ noncomputable section open scoped Classical universe u v variable (R : Type u) (S : Type v) /-- The prime spectrum of a commutative (semi)ring `R` is the type of all prime ideals of `R`. It is naturally endowed with a topology (the Zariski topology), and a sheaf of commutative rings (see `AlgebraicGeometry.StructureSheaf`). It is a fundamental building block in algebraic geometry. -/ @[ext] structure PrimeSpectrum [CommSemiring R] where asIdeal : Ideal R IsPrime : asIdeal.IsPrime #align prime_spectrum PrimeSpectrum attribute [instance] PrimeSpectrum.IsPrime namespace PrimeSpectrum section CommSemiRing variable [CommSemiring R] [CommSemiring S] variable {R S} instance [Nontrivial R] : Nonempty <| PrimeSpectrum R := let ⟨I, hI⟩ := Ideal.exists_maximal R ⟨⟨I, hI.isPrime⟩⟩ /-- The prime spectrum of the zero ring is empty. -/ instance [Subsingleton R] : IsEmpty (PrimeSpectrum R) := ⟨fun x ↦ x.IsPrime.ne_top <| SetLike.ext' <| Subsingleton.eq_univ_of_nonempty x.asIdeal.nonempty⟩ #noalign prime_spectrum.punit variable (R S) /-- The map from the direct sum of prime spectra to the prime spectrum of a direct product. -/ @[simp] def primeSpectrumProdOfSum : Sum (PrimeSpectrum R) (PrimeSpectrum S) → PrimeSpectrum (R × S) | Sum.inl ⟨I, _⟩ => ⟨Ideal.prod I ⊤, Ideal.isPrime_ideal_prod_top⟩ | Sum.inr ⟨J, _⟩ => ⟨Ideal.prod ⊤ J, Ideal.isPrime_ideal_prod_top'⟩ #align prime_spectrum.prime_spectrum_prod_of_sum PrimeSpectrum.primeSpectrumProdOfSum /-- The prime spectrum of `R × S` is in bijection with the disjoint unions of the prime spectrum of `R` and the prime spectrum of `S`. -/ noncomputable def primeSpectrumProd : PrimeSpectrum (R × S) ≃ Sum (PrimeSpectrum R) (PrimeSpectrum S) := Equiv.symm <| Equiv.ofBijective (primeSpectrumProdOfSum R S) (by constructor · rintro (⟨I, hI⟩ | ⟨J, hJ⟩) (⟨I', hI'⟩ | ⟨J', hJ'⟩) h <;> simp only [mk.injEq, Ideal.prod.ext_iff, primeSpectrumProdOfSum] at h · simp only [h] · exact False.elim (hI.ne_top h.left) · exact False.elim (hJ.ne_top h.right) · simp only [h] · rintro ⟨I, hI⟩ rcases (Ideal.ideal_prod_prime I).mp hI with (⟨p, ⟨hp, rfl⟩⟩ | ⟨p, ⟨hp, rfl⟩⟩) · exact ⟨Sum.inl ⟨p, hp⟩, rfl⟩ · exact ⟨Sum.inr ⟨p, hp⟩, rfl⟩) #align prime_spectrum.prime_spectrum_prod PrimeSpectrum.primeSpectrumProd variable {R S} @[simp] theorem primeSpectrumProd_symm_inl_asIdeal (x : PrimeSpectrum R) : ((primeSpectrumProd R S).symm <| Sum.inl x).asIdeal = Ideal.prod x.asIdeal ⊤ := by cases x rfl #align prime_spectrum.prime_spectrum_prod_symm_inl_as_ideal PrimeSpectrum.primeSpectrumProd_symm_inl_asIdeal @[simp] theorem primeSpectrumProd_symm_inr_asIdeal (x : PrimeSpectrum S) : ((primeSpectrumProd R S).symm <| Sum.inr x).asIdeal = Ideal.prod ⊤ x.asIdeal := by cases x rfl #align prime_spectrum.prime_spectrum_prod_symm_inr_as_ideal PrimeSpectrum.primeSpectrumProd_symm_inr_asIdeal /-- The zero locus of a set `s` of elements of a commutative (semi)ring `R` is the set of all prime ideals of the ring that contain the set `s`. An element `f` of `R` can be thought of as a dependent function on the prime spectrum of `R`. At a point `x` (a prime ideal) the function (i.e., element) `f` takes values in the quotient ring `R` modulo the prime ideal `x`. In this manner, `zeroLocus s` is exactly the subset of `PrimeSpectrum R` where all "functions" in `s` vanish simultaneously. -/ def zeroLocus (s : Set R) : Set (PrimeSpectrum R) := { x | s ⊆ x.asIdeal } #align prime_spectrum.zero_locus PrimeSpectrum.zeroLocus @[simp] theorem mem_zeroLocus (x : PrimeSpectrum R) (s : Set R) : x ∈ zeroLocus s ↔ s ⊆ x.asIdeal := Iff.rfl #align prime_spectrum.mem_zero_locus PrimeSpectrum.mem_zeroLocus @[simp] theorem zeroLocus_span (s : Set R) : zeroLocus (Ideal.span s : Set R) = zeroLocus s := by ext x exact (Submodule.gi R R).gc s x.asIdeal #align prime_spectrum.zero_locus_span PrimeSpectrum.zeroLocus_span /-- The vanishing ideal of a set `t` of points of the prime spectrum of a commutative ring `R` is the intersection of all the prime ideals in the set `t`. An element `f` of `R` can be thought of as a dependent function on the prime spectrum of `R`. At a point `x` (a prime ideal) the function (i.e., element) `f` takes values in the quotient ring `R` modulo the prime ideal `x`. In this manner, `vanishingIdeal t` is exactly the ideal of `R` consisting of all "functions" that vanish on all of `t`. -/ def vanishingIdeal (t : Set (PrimeSpectrum R)) : Ideal R := ⨅ (x : PrimeSpectrum R) (_ : x ∈ t), x.asIdeal #align prime_spectrum.vanishing_ideal PrimeSpectrum.vanishingIdeal theorem coe_vanishingIdeal (t : Set (PrimeSpectrum R)) : (vanishingIdeal t : Set R) = { f : R | ∀ x : PrimeSpectrum R, x ∈ t → f ∈ x.asIdeal } := by ext f rw [vanishingIdeal, SetLike.mem_coe, Submodule.mem_iInf] apply forall_congr'; intro x rw [Submodule.mem_iInf] #align prime_spectrum.coe_vanishing_ideal PrimeSpectrum.coe_vanishingIdeal theorem mem_vanishingIdeal (t : Set (PrimeSpectrum R)) (f : R) : f ∈ vanishingIdeal t ↔ ∀ x : PrimeSpectrum R, x ∈ t → f ∈ x.asIdeal := by rw [← SetLike.mem_coe, coe_vanishingIdeal, Set.mem_setOf_eq] #align prime_spectrum.mem_vanishing_ideal PrimeSpectrum.mem_vanishingIdeal @[simp] theorem vanishingIdeal_singleton (x : PrimeSpectrum R) : vanishingIdeal ({x} : Set (PrimeSpectrum R)) = x.asIdeal := by simp [vanishingIdeal] #align prime_spectrum.vanishing_ideal_singleton PrimeSpectrum.vanishingIdeal_singleton theorem subset_zeroLocus_iff_le_vanishingIdeal (t : Set (PrimeSpectrum R)) (I : Ideal R) : t ⊆ zeroLocus I ↔ I ≤ vanishingIdeal t := ⟨fun h _ k => (mem_vanishingIdeal _ _).mpr fun _ j => (mem_zeroLocus _ _).mpr (h j) k, fun h => fun x j => (mem_zeroLocus _ _).mpr (le_trans h fun _ h => ((mem_vanishingIdeal _ _).mp h) x j)⟩ #align prime_spectrum.subset_zero_locus_iff_le_vanishing_ideal PrimeSpectrum.subset_zeroLocus_iff_le_vanishingIdeal section Gc variable (R) /-- `zeroLocus` and `vanishingIdeal` form a galois connection. -/ theorem gc : @GaloisConnection (Ideal R) (Set (PrimeSpectrum R))ᵒᵈ _ _ (fun I => zeroLocus I) fun t => vanishingIdeal t := fun I t => subset_zeroLocus_iff_le_vanishingIdeal t I #align prime_spectrum.gc PrimeSpectrum.gc /-- `zeroLocus` and `vanishingIdeal` form a galois connection. -/ theorem gc_set : @GaloisConnection (Set R) (Set (PrimeSpectrum R))ᵒᵈ _ _ (fun s => zeroLocus s) fun t => vanishingIdeal t := by have ideal_gc : GaloisConnection Ideal.span _ := (Submodule.gi R R).gc simpa [zeroLocus_span, Function.comp] using ideal_gc.compose (gc R) #align prime_spectrum.gc_set PrimeSpectrum.gc_set theorem subset_zeroLocus_iff_subset_vanishingIdeal (t : Set (PrimeSpectrum R)) (s : Set R) : t ⊆ zeroLocus s ↔ s ⊆ vanishingIdeal t := (gc_set R) s t #align prime_spectrum.subset_zero_locus_iff_subset_vanishing_ideal PrimeSpectrum.subset_zeroLocus_iff_subset_vanishingIdeal end Gc theorem subset_vanishingIdeal_zeroLocus (s : Set R) : s ⊆ vanishingIdeal (zeroLocus s) := (gc_set R).le_u_l s #align prime_spectrum.subset_vanishing_ideal_zero_locus PrimeSpectrum.subset_vanishingIdeal_zeroLocus theorem le_vanishingIdeal_zeroLocus (I : Ideal R) : I ≤ vanishingIdeal (zeroLocus I) := (gc R).le_u_l I #align prime_spectrum.le_vanishing_ideal_zero_locus PrimeSpectrum.le_vanishingIdeal_zeroLocus @[simp] theorem vanishingIdeal_zeroLocus_eq_radical (I : Ideal R) : vanishingIdeal (zeroLocus (I : Set R)) = I.radical := Ideal.ext fun f => by rw [mem_vanishingIdeal, Ideal.radical_eq_sInf, Submodule.mem_sInf] exact ⟨fun h x hx => h ⟨x, hx.2⟩ hx.1, fun h x hx => h x.1 ⟨hx, x.2⟩⟩ #align prime_spectrum.vanishing_ideal_zero_locus_eq_radical PrimeSpectrum.vanishingIdeal_zeroLocus_eq_radical @[simp] theorem zeroLocus_radical (I : Ideal R) : zeroLocus (I.radical : Set R) = zeroLocus I := vanishingIdeal_zeroLocus_eq_radical I ▸ (gc R).l_u_l_eq_l I #align prime_spectrum.zero_locus_radical PrimeSpectrum.zeroLocus_radical theorem subset_zeroLocus_vanishingIdeal (t : Set (PrimeSpectrum R)) : t ⊆ zeroLocus (vanishingIdeal t) := (gc R).l_u_le t #align prime_spectrum.subset_zero_locus_vanishing_ideal PrimeSpectrum.subset_zeroLocus_vanishingIdeal theorem zeroLocus_anti_mono {s t : Set R} (h : s ⊆ t) : zeroLocus t ⊆ zeroLocus s := (gc_set R).monotone_l h #align prime_spectrum.zero_locus_anti_mono PrimeSpectrum.zeroLocus_anti_mono theorem zeroLocus_anti_mono_ideal {s t : Ideal R} (h : s ≤ t) : zeroLocus (t : Set R) ⊆ zeroLocus (s : Set R) := (gc R).monotone_l h #align prime_spectrum.zero_locus_anti_mono_ideal PrimeSpectrum.zeroLocus_anti_mono_ideal theorem vanishingIdeal_anti_mono {s t : Set (PrimeSpectrum R)} (h : s ⊆ t) : vanishingIdeal t ≤ vanishingIdeal s := (gc R).monotone_u h #align prime_spectrum.vanishing_ideal_anti_mono PrimeSpectrum.vanishingIdeal_anti_mono theorem zeroLocus_subset_zeroLocus_iff (I J : Ideal R) : zeroLocus (I : Set R) ⊆ zeroLocus (J : Set R) ↔ J ≤ I.radical := by rw [subset_zeroLocus_iff_le_vanishingIdeal, vanishingIdeal_zeroLocus_eq_radical] #align prime_spectrum.zero_locus_subset_zero_locus_iff PrimeSpectrum.zeroLocus_subset_zeroLocus_iff theorem zeroLocus_subset_zeroLocus_singleton_iff (f g : R) : zeroLocus ({f} : Set R) ⊆ zeroLocus {g} ↔ g ∈ (Ideal.span ({f} : Set R)).radical := by rw [← zeroLocus_span {f}, ← zeroLocus_span {g}, zeroLocus_subset_zeroLocus_iff, Ideal.span_le, Set.singleton_subset_iff, SetLike.mem_coe] #align prime_spectrum.zero_locus_subset_zero_locus_singleton_iff PrimeSpectrum.zeroLocus_subset_zeroLocus_singleton_iff theorem zeroLocus_bot : zeroLocus ((⊥ : Ideal R) : Set R) = Set.univ := (gc R).l_bot #align prime_spectrum.zero_locus_bot PrimeSpectrum.zeroLocus_bot @[simp] theorem zeroLocus_singleton_zero : zeroLocus ({0} : Set R) = Set.univ := zeroLocus_bot #align prime_spectrum.zero_locus_singleton_zero PrimeSpectrum.zeroLocus_singleton_zero @[simp] theorem zeroLocus_empty : zeroLocus (∅ : Set R) = Set.univ := (gc_set R).l_bot #align prime_spectrum.zero_locus_empty PrimeSpectrum.zeroLocus_empty @[simp] theorem vanishingIdeal_univ : vanishingIdeal (∅ : Set (PrimeSpectrum R)) = ⊤ := by simpa using (gc R).u_top #align prime_spectrum.vanishing_ideal_univ PrimeSpectrum.vanishingIdeal_univ theorem zeroLocus_empty_of_one_mem {s : Set R} (h : (1 : R) ∈ s) : zeroLocus s = ∅ := by rw [Set.eq_empty_iff_forall_not_mem] intro x hx rw [mem_zeroLocus] at hx have x_prime : x.asIdeal.IsPrime := by infer_instance have eq_top : x.asIdeal = ⊤ := by rw [Ideal.eq_top_iff_one] exact hx h apply x_prime.ne_top eq_top #align prime_spectrum.zero_locus_empty_of_one_mem PrimeSpectrum.zeroLocus_empty_of_one_mem @[simp] theorem zeroLocus_singleton_one : zeroLocus ({1} : Set R) = ∅ := zeroLocus_empty_of_one_mem (Set.mem_singleton (1 : R)) #align prime_spectrum.zero_locus_singleton_one PrimeSpectrum.zeroLocus_singleton_one theorem zeroLocus_empty_iff_eq_top {I : Ideal R} : zeroLocus (I : Set R) = ∅ ↔ I = ⊤ := by constructor · contrapose! intro h rcases Ideal.exists_le_maximal I h with ⟨M, hM, hIM⟩ exact ⟨⟨M, hM.isPrime⟩, hIM⟩ · rintro rfl apply zeroLocus_empty_of_one_mem trivial #align prime_spectrum.zero_locus_empty_iff_eq_top PrimeSpectrum.zeroLocus_empty_iff_eq_top @[simp] theorem zeroLocus_univ : zeroLocus (Set.univ : Set R) = ∅ := zeroLocus_empty_of_one_mem (Set.mem_univ 1) #align prime_spectrum.zero_locus_univ PrimeSpectrum.zeroLocus_univ theorem vanishingIdeal_eq_top_iff {s : Set (PrimeSpectrum R)} : vanishingIdeal s = ⊤ ↔ s = ∅ := by rw [← top_le_iff, ← subset_zeroLocus_iff_le_vanishingIdeal, Submodule.top_coe, zeroLocus_univ, Set.subset_empty_iff] #align prime_spectrum.vanishing_ideal_eq_top_iff PrimeSpectrum.vanishingIdeal_eq_top_iff theorem zeroLocus_sup (I J : Ideal R) : zeroLocus ((I ⊔ J : Ideal R) : Set R) = zeroLocus I ∩ zeroLocus J := (gc R).l_sup #align prime_spectrum.zero_locus_sup PrimeSpectrum.zeroLocus_sup theorem zeroLocus_union (s s' : Set R) : zeroLocus (s ∪ s') = zeroLocus s ∩ zeroLocus s' := (gc_set R).l_sup #align prime_spectrum.zero_locus_union PrimeSpectrum.zeroLocus_union theorem vanishingIdeal_union (t t' : Set (PrimeSpectrum R)) : vanishingIdeal (t ∪ t') = vanishingIdeal t ⊓ vanishingIdeal t' := (gc R).u_inf #align prime_spectrum.vanishing_ideal_union PrimeSpectrum.vanishingIdeal_union theorem zeroLocus_iSup {ι : Sort*} (I : ι → Ideal R) : zeroLocus ((⨆ i, I i : Ideal R) : Set R) = ⋂ i, zeroLocus (I i) := (gc R).l_iSup #align prime_spectrum.zero_locus_supr PrimeSpectrum.zeroLocus_iSup theorem zeroLocus_iUnion {ι : Sort*} (s : ι → Set R) : zeroLocus (⋃ i, s i) = ⋂ i, zeroLocus (s i) := (gc_set R).l_iSup #align prime_spectrum.zero_locus_Union PrimeSpectrum.zeroLocus_iUnion theorem zeroLocus_bUnion (s : Set (Set R)) : zeroLocus (⋃ s' ∈ s, s' : Set R) = ⋂ s' ∈ s, zeroLocus s' := by simp only [zeroLocus_iUnion] #align prime_spectrum.zero_locus_bUnion PrimeSpectrum.zeroLocus_bUnion theorem vanishingIdeal_iUnion {ι : Sort*} (t : ι → Set (PrimeSpectrum R)) : vanishingIdeal (⋃ i, t i) = ⨅ i, vanishingIdeal (t i) := (gc R).u_iInf #align prime_spectrum.vanishing_ideal_Union PrimeSpectrum.vanishingIdeal_iUnion theorem zeroLocus_inf (I J : Ideal R) : zeroLocus ((I ⊓ J : Ideal R) : Set R) = zeroLocus I ∪ zeroLocus J := Set.ext fun x => x.2.inf_le #align prime_spectrum.zero_locus_inf PrimeSpectrum.zeroLocus_inf theorem union_zeroLocus (s s' : Set R) : zeroLocus s ∪ zeroLocus s' = zeroLocus (Ideal.span s ⊓ Ideal.span s' : Ideal R) := by rw [zeroLocus_inf] simp #align prime_spectrum.union_zero_locus PrimeSpectrum.union_zeroLocus theorem zeroLocus_mul (I J : Ideal R) : zeroLocus ((I * J : Ideal R) : Set R) = zeroLocus I ∪ zeroLocus J := Set.ext fun x => x.2.mul_le #align prime_spectrum.zero_locus_mul PrimeSpectrum.zeroLocus_mul theorem zeroLocus_singleton_mul (f g : R) : zeroLocus ({f * g} : Set R) = zeroLocus {f} ∪ zeroLocus {g} := Set.ext fun x => by simpa using x.2.mul_mem_iff_mem_or_mem #align prime_spectrum.zero_locus_singleton_mul PrimeSpectrum.zeroLocus_singleton_mul @[simp] theorem zeroLocus_pow (I : Ideal R) {n : ℕ} (hn : n ≠ 0) : zeroLocus ((I ^ n : Ideal R) : Set R) = zeroLocus I := zeroLocus_radical (I ^ n) ▸ (I.radical_pow hn).symm ▸ zeroLocus_radical I #align prime_spectrum.zero_locus_pow PrimeSpectrum.zeroLocus_pow @[simp] theorem zeroLocus_singleton_pow (f : R) (n : ℕ) (hn : 0 < n) : zeroLocus ({f ^ n} : Set R) = zeroLocus {f} := Set.ext fun x => by simpa using x.2.pow_mem_iff_mem n hn #align prime_spectrum.zero_locus_singleton_pow PrimeSpectrum.zeroLocus_singleton_pow theorem sup_vanishingIdeal_le (t t' : Set (PrimeSpectrum R)) : vanishingIdeal t ⊔ vanishingIdeal t' ≤ vanishingIdeal (t ∩ t') := by intro r rw [Submodule.mem_sup, mem_vanishingIdeal] rintro ⟨f, hf, g, hg, rfl⟩ x ⟨hxt, hxt'⟩ rw [mem_vanishingIdeal] at hf hg apply Submodule.add_mem <;> solve_by_elim #align prime_spectrum.sup_vanishing_ideal_le PrimeSpectrum.sup_vanishingIdeal_le theorem mem_compl_zeroLocus_iff_not_mem {f : R} {I : PrimeSpectrum R} : I ∈ (zeroLocus {f} : Set (PrimeSpectrum R))ᶜ ↔ f ∉ I.asIdeal := by rw [Set.mem_compl_iff, mem_zeroLocus, Set.singleton_subset_iff]; rfl #align prime_spectrum.mem_compl_zero_locus_iff_not_mem PrimeSpectrum.mem_compl_zeroLocus_iff_not_mem /-- The Zariski topology on the prime spectrum of a commutative (semi)ring is defined via the closed sets of the topology: they are exactly those sets that are the zero locus of a subset of the ring. -/ instance zariskiTopology : TopologicalSpace (PrimeSpectrum R) := TopologicalSpace.ofClosed (Set.range PrimeSpectrum.zeroLocus) ⟨Set.univ, by simp⟩ (by intro Zs h rw [Set.sInter_eq_iInter] choose f hf using fun i : Zs => h i.prop simp only [← hf] exact ⟨_, zeroLocus_iUnion _⟩) (by rintro _ ⟨s, rfl⟩ _ ⟨t, rfl⟩ exact ⟨_, (union_zeroLocus s t).symm⟩) #align prime_spectrum.zariski_topology PrimeSpectrum.zariskiTopology theorem isOpen_iff (U : Set (PrimeSpectrum R)) : IsOpen U ↔ ∃ s, Uᶜ = zeroLocus s := by simp only [@eq_comm _ Uᶜ]; rfl #align prime_spectrum.is_open_iff PrimeSpectrum.isOpen_iff theorem isClosed_iff_zeroLocus (Z : Set (PrimeSpectrum R)) : IsClosed Z ↔ ∃ s, Z = zeroLocus s := by rw [← isOpen_compl_iff, isOpen_iff, compl_compl] #align prime_spectrum.is_closed_iff_zero_locus PrimeSpectrum.isClosed_iff_zeroLocus theorem isClosed_iff_zeroLocus_ideal (Z : Set (PrimeSpectrum R)) : IsClosed Z ↔ ∃ I : Ideal R, Z = zeroLocus I := (isClosed_iff_zeroLocus _).trans ⟨fun ⟨s, hs⟩ => ⟨_, (zeroLocus_span s).substr hs⟩, fun ⟨I, hI⟩ => ⟨I, hI⟩⟩ #align prime_spectrum.is_closed_iff_zero_locus_ideal PrimeSpectrum.isClosed_iff_zeroLocus_ideal theorem isClosed_iff_zeroLocus_radical_ideal (Z : Set (PrimeSpectrum R)) : IsClosed Z ↔ ∃ I : Ideal R, I.IsRadical ∧ Z = zeroLocus I := (isClosed_iff_zeroLocus_ideal _).trans ⟨fun ⟨I, hI⟩ => ⟨_, I.radical_isRadical, (zeroLocus_radical I).substr hI⟩, fun ⟨I, _, hI⟩ => ⟨I, hI⟩⟩ #align prime_spectrum.is_closed_iff_zero_locus_radical_ideal PrimeSpectrum.isClosed_iff_zeroLocus_radical_ideal theorem isClosed_zeroLocus (s : Set R) : IsClosed (zeroLocus s) := by rw [isClosed_iff_zeroLocus] exact ⟨s, rfl⟩ #align prime_spectrum.is_closed_zero_locus PrimeSpectrum.isClosed_zeroLocus theorem zeroLocus_vanishingIdeal_eq_closure (t : Set (PrimeSpectrum R)) : zeroLocus (vanishingIdeal t : Set R) = closure t := by rcases isClosed_iff_zeroLocus (closure t) |>.mp isClosed_closure with ⟨I, hI⟩ rw [subset_antisymm_iff, (isClosed_zeroLocus _).closure_subset_iff, hI, subset_zeroLocus_iff_subset_vanishingIdeal, (gc R).u_l_u_eq_u, ← subset_zeroLocus_iff_subset_vanishingIdeal, ← hI] exact ⟨subset_closure, subset_zeroLocus_vanishingIdeal t⟩ #align prime_spectrum.zero_locus_vanishing_ideal_eq_closure PrimeSpectrum.zeroLocus_vanishingIdeal_eq_closure theorem vanishingIdeal_closure (t : Set (PrimeSpectrum R)) : vanishingIdeal (closure t) = vanishingIdeal t := zeroLocus_vanishingIdeal_eq_closure t ▸ (gc R).u_l_u_eq_u t #align prime_spectrum.vanishing_ideal_closure PrimeSpectrum.vanishingIdeal_closure theorem closure_singleton (x) : closure ({x} : Set (PrimeSpectrum R)) = zeroLocus x.asIdeal := by rw [← zeroLocus_vanishingIdeal_eq_closure, vanishingIdeal_singleton] #align prime_spectrum.closure_singleton PrimeSpectrum.closure_singleton theorem isClosed_singleton_iff_isMaximal (x : PrimeSpectrum R) : IsClosed ({x} : Set (PrimeSpectrum R)) ↔ x.asIdeal.IsMaximal := by rw [← closure_subset_iff_isClosed, ← zeroLocus_vanishingIdeal_eq_closure, vanishingIdeal_singleton] constructor <;> intro H · rcases x.asIdeal.exists_le_maximal x.2.1 with ⟨m, hm, hxm⟩ exact (congr_arg asIdeal (@H ⟨m, hm.isPrime⟩ hxm)) ▸ hm · exact fun p hp ↦ PrimeSpectrum.ext _ _ (H.eq_of_le p.2.1 hp).symm #align prime_spectrum.is_closed_singleton_iff_is_maximal PrimeSpectrum.isClosed_singleton_iff_isMaximal theorem isRadical_vanishingIdeal (s : Set (PrimeSpectrum R)) : (vanishingIdeal s).IsRadical := by rw [← vanishingIdeal_closure, ← zeroLocus_vanishingIdeal_eq_closure, vanishingIdeal_zeroLocus_eq_radical] apply Ideal.radical_isRadical #align prime_spectrum.is_radical_vanishing_ideal PrimeSpectrum.isRadical_vanishingIdeal theorem vanishingIdeal_anti_mono_iff {s t : Set (PrimeSpectrum R)} (ht : IsClosed t) : s ⊆ t ↔ vanishingIdeal t ≤ vanishingIdeal s := ⟨vanishingIdeal_anti_mono, fun h => by rw [← ht.closure_subset_iff, ← ht.closure_eq] convert ← zeroLocus_anti_mono_ideal h <;> apply zeroLocus_vanishingIdeal_eq_closure⟩ #align prime_spectrum.vanishing_ideal_anti_mono_iff PrimeSpectrum.vanishingIdeal_anti_mono_iff theorem vanishingIdeal_strict_anti_mono_iff {s t : Set (PrimeSpectrum R)} (hs : IsClosed s) (ht : IsClosed t) : s ⊂ t ↔ vanishingIdeal t < vanishingIdeal s := by rw [Set.ssubset_def, vanishingIdeal_anti_mono_iff hs, vanishingIdeal_anti_mono_iff ht, lt_iff_le_not_le] #align prime_spectrum.vanishing_ideal_strict_anti_mono_iff PrimeSpectrum.vanishingIdeal_strict_anti_mono_iff /-- The antitone order embedding of closed subsets of `Spec R` into ideals of `R`. -/ def closedsEmbedding (R : Type*) [CommSemiring R] : (TopologicalSpace.Closeds <| PrimeSpectrum R)ᵒᵈ ↪o Ideal R := OrderEmbedding.ofMapLEIff (fun s => vanishingIdeal ↑(OrderDual.ofDual s)) fun s _ => (vanishingIdeal_anti_mono_iff s.2).symm #align prime_spectrum.closeds_embedding PrimeSpectrum.closedsEmbedding theorem t1Space_iff_isField [IsDomain R] : T1Space (PrimeSpectrum R) ↔ IsField R := by refine ⟨?_, fun h => ?_⟩ · intro h have hbot : Ideal.IsPrime (⊥ : Ideal R) := Ideal.bot_prime exact Classical.not_not.1 (mt (Ring.ne_bot_of_isMaximal_of_not_isField <| (isClosed_singleton_iff_isMaximal _).1 (T1Space.t1 ⟨⊥, hbot⟩)) (by aesop)) · refine ⟨fun x => (isClosed_singleton_iff_isMaximal x).2 ?_⟩ by_cases hx : x.asIdeal = ⊥ · letI := h.toSemifield exact hx.symm ▸ Ideal.bot_isMaximal · exact absurd h (Ring.not_isField_iff_exists_prime.2 ⟨x.asIdeal, ⟨hx, x.2⟩⟩) #align prime_spectrum.t1_space_iff_is_field PrimeSpectrum.t1Space_iff_isField local notation "Z(" a ")" => zeroLocus (a : Set R) theorem isIrreducible_zeroLocus_iff_of_radical (I : Ideal R) (hI : I.IsRadical) : IsIrreducible (zeroLocus (I : Set R)) ↔ I.IsPrime := by rw [Ideal.isPrime_iff, IsIrreducible] apply and_congr · rw [Set.nonempty_iff_ne_empty, Ne, zeroLocus_empty_iff_eq_top] · trans ∀ x y : Ideal R, Z(I) ⊆ Z(x) ∪ Z(y) → Z(I) ⊆ Z(x) ∨ Z(I) ⊆ Z(y) · simp_rw [isPreirreducible_iff_closed_union_closed, isClosed_iff_zeroLocus_ideal] constructor · rintro h x y exact h _ _ ⟨x, rfl⟩ ⟨y, rfl⟩ · rintro h _ _ ⟨x, rfl⟩ ⟨y, rfl⟩ exact h x y · simp_rw [← zeroLocus_inf, subset_zeroLocus_iff_le_vanishingIdeal, vanishingIdeal_zeroLocus_eq_radical, hI.radical] constructor · simp_rw [← SetLike.mem_coe, ← Set.singleton_subset_iff, ← Ideal.span_le, ← Ideal.span_singleton_mul_span_singleton] refine fun h x y h' => h _ _ ?_ rw [← hI.radical_le_iff] at h' ⊢ simpa only [Ideal.radical_inf, Ideal.radical_mul] using h' · simp_rw [or_iff_not_imp_left, SetLike.not_le_iff_exists] rintro h s t h' ⟨x, hx, hx'⟩ y hy exact h (h' ⟨Ideal.mul_mem_right _ _ hx, Ideal.mul_mem_left _ _ hy⟩) hx' #align prime_spectrum.is_irreducible_zero_locus_iff_of_radical PrimeSpectrum.isIrreducible_zeroLocus_iff_of_radical theorem isIrreducible_zeroLocus_iff (I : Ideal R) : IsIrreducible (zeroLocus (I : Set R)) ↔ I.radical.IsPrime := zeroLocus_radical I ▸ isIrreducible_zeroLocus_iff_of_radical _ I.radical_isRadical #align prime_spectrum.is_irreducible_zero_locus_iff PrimeSpectrum.isIrreducible_zeroLocus_iff theorem isIrreducible_iff_vanishingIdeal_isPrime {s : Set (PrimeSpectrum R)} : IsIrreducible s ↔ (vanishingIdeal s).IsPrime := by rw [← isIrreducible_iff_closure, ← zeroLocus_vanishingIdeal_eq_closure, isIrreducible_zeroLocus_iff_of_radical _ (isRadical_vanishingIdeal s)] #align prime_spectrum.is_irreducible_iff_vanishing_ideal_is_prime PrimeSpectrum.isIrreducible_iff_vanishingIdeal_isPrime lemma vanishingIdeal_isIrreducible : vanishingIdeal (R := R) '' {s | IsIrreducible s} = {P | P.IsPrime} := Set.ext fun I ↦ ⟨fun ⟨_, hs, e⟩ ↦ e ▸ isIrreducible_iff_vanishingIdeal_isPrime.mp hs, fun h ↦ ⟨zeroLocus I, (isIrreducible_zeroLocus_iff_of_radical _ h.isRadical).mpr h, (vanishingIdeal_zeroLocus_eq_radical I).trans h.radical⟩⟩ lemma vanishingIdeal_isClosed_isIrreducible : vanishingIdeal (R := R) '' {s | IsClosed s ∧ IsIrreducible s} = {P | P.IsPrime} := by refine (subset_antisymm ?_ ?_).trans vanishingIdeal_isIrreducible · exact Set.image_subset _ fun _ ↦ And.right rintro _ ⟨s, hs, rfl⟩ exact ⟨closure s, ⟨isClosed_closure, hs.closure⟩, vanishingIdeal_closure s⟩ instance irreducibleSpace [IsDomain R] : IrreducibleSpace (PrimeSpectrum R) := by rw [irreducibleSpace_def, Set.top_eq_univ, ← zeroLocus_bot, isIrreducible_zeroLocus_iff] simpa using Ideal.bot_prime instance quasiSober : QuasiSober (PrimeSpectrum R) := ⟨fun {S} h₁ h₂ => ⟨⟨_, isIrreducible_iff_vanishingIdeal_isPrime.1 h₁⟩, by rw [IsGenericPoint, closure_singleton, zeroLocus_vanishingIdeal_eq_closure, h₂.closure_eq]⟩⟩ /-- The prime spectrum of a commutative (semi)ring is a compact topological space. -/ instance compactSpace : CompactSpace (PrimeSpectrum R) := by refine compactSpace_of_finite_subfamily_closed fun S S_closed S_empty ↦ ?_ choose I hI using fun i ↦ (isClosed_iff_zeroLocus_ideal (S i)).mp (S_closed i) simp_rw [hI, ← zeroLocus_iSup, zeroLocus_empty_iff_eq_top, ← top_le_iff] at S_empty ⊢ exact Ideal.isCompactElement_top.exists_finset_of_le_iSup _ _ S_empty section Comap variable {S' : Type*} [CommSemiring S'] theorem preimage_comap_zeroLocus_aux (f : R →+* S) (s : Set R) : (fun y => ⟨Ideal.comap f y.asIdeal, inferInstance⟩ : PrimeSpectrum S → PrimeSpectrum R) ⁻¹' zeroLocus s = zeroLocus (f '' s) := by ext x simp only [mem_zeroLocus, Set.image_subset_iff, Set.mem_preimage, mem_zeroLocus, Ideal.coe_comap] #align prime_spectrum.preimage_comap_zero_locus_aux PrimeSpectrum.preimage_comap_zeroLocus_aux /-- The function between prime spectra of commutative (semi)rings induced by a ring homomorphism. This function is continuous. -/ def comap (f : R →+* S) : C(PrimeSpectrum S, PrimeSpectrum R) where toFun y := ⟨Ideal.comap f y.asIdeal, inferInstance⟩ continuous_toFun := by simp only [continuous_iff_isClosed, isClosed_iff_zeroLocus] rintro _ ⟨s, rfl⟩ exact ⟨_, preimage_comap_zeroLocus_aux f s⟩ #align prime_spectrum.comap PrimeSpectrum.comap variable (f : R →+* S) @[simp] theorem comap_asIdeal (y : PrimeSpectrum S) : (comap f y).asIdeal = Ideal.comap f y.asIdeal := rfl #align prime_spectrum.comap_as_ideal PrimeSpectrum.comap_asIdeal @[simp] theorem comap_id : comap (RingHom.id R) = ContinuousMap.id _ := by ext rfl #align prime_spectrum.comap_id PrimeSpectrum.comap_id @[simp] theorem comap_comp (f : R →+* S) (g : S →+* S') : comap (g.comp f) = (comap f).comp (comap g) := rfl #align prime_spectrum.comap_comp PrimeSpectrum.comap_comp theorem comap_comp_apply (f : R →+* S) (g : S →+* S') (x : PrimeSpectrum S') : PrimeSpectrum.comap (g.comp f) x = (PrimeSpectrum.comap f) (PrimeSpectrum.comap g x) := rfl #align prime_spectrum.comap_comp_apply PrimeSpectrum.comap_comp_apply @[simp] theorem preimage_comap_zeroLocus (s : Set R) : comap f ⁻¹' zeroLocus s = zeroLocus (f '' s) := preimage_comap_zeroLocus_aux f s #align prime_spectrum.preimage_comap_zero_locus PrimeSpectrum.preimage_comap_zeroLocus theorem comap_injective_of_surjective (f : R →+* S) (hf : Function.Surjective f) : Function.Injective (comap f) := fun x y h => PrimeSpectrum.ext _ _ (Ideal.comap_injective_of_surjective f hf (congr_arg PrimeSpectrum.asIdeal h : (comap f x).asIdeal = (comap f y).asIdeal)) #align prime_spectrum.comap_injective_of_surjective PrimeSpectrum.comap_injective_of_surjective variable (S) theorem localization_comap_inducing [Algebra R S] (M : Submonoid R) [IsLocalization M S] : Inducing (comap (algebraMap R S)) := by refine ⟨TopologicalSpace.ext_isClosed fun Z ↦ ?_⟩ simp_rw [isClosed_induced_iff, isClosed_iff_zeroLocus, @eq_comm _ _ (zeroLocus _), exists_exists_eq_and, preimage_comap_zeroLocus] constructor · rintro ⟨s, rfl⟩ refine ⟨(Ideal.span s).comap (algebraMap R S), ?_⟩ rw [← zeroLocus_span, ← zeroLocus_span s, ← Ideal.map, IsLocalization.map_comap M S] · rintro ⟨s, rfl⟩ exact ⟨_, rfl⟩ #align prime_spectrum.localization_comap_inducing PrimeSpectrum.localization_comap_inducing theorem localization_comap_injective [Algebra R S] (M : Submonoid R) [IsLocalization M S] : Function.Injective (comap (algebraMap R S)) := by intro p q h replace h := congr_arg (fun x : PrimeSpectrum R => Ideal.map (algebraMap R S) x.asIdeal) h dsimp only [comap, ContinuousMap.coe_mk] at h rw [IsLocalization.map_comap M S, IsLocalization.map_comap M S] at h ext1 exact h #align prime_spectrum.localization_comap_injective PrimeSpectrum.localization_comap_injective theorem localization_comap_embedding [Algebra R S] (M : Submonoid R) [IsLocalization M S] : Embedding (comap (algebraMap R S)) := ⟨localization_comap_inducing S M, localization_comap_injective S M⟩ #align prime_spectrum.localization_comap_embedding PrimeSpectrum.localization_comap_embedding theorem localization_comap_range [Algebra R S] (M : Submonoid R) [IsLocalization M S] : Set.range (comap (algebraMap R S)) = { p | Disjoint (M : Set R) p.asIdeal } := by ext x constructor · simp_rw [disjoint_iff_inf_le] rintro ⟨p, rfl⟩ x ⟨hx₁, hx₂⟩ exact (p.2.1 : ¬_) (p.asIdeal.eq_top_of_isUnit_mem hx₂ (IsLocalization.map_units S ⟨x, hx₁⟩)) · intro h use ⟨x.asIdeal.map (algebraMap R S), IsLocalization.isPrime_of_isPrime_disjoint M S _ x.2 h⟩ ext1 exact IsLocalization.comap_map_of_isPrime_disjoint M S _ x.2 h #align prime_spectrum.localization_comap_range PrimeSpectrum.localization_comap_range open Function RingHom theorem comap_inducing_of_surjective (hf : Surjective f) : Inducing (comap f) where induced := by set_option tactic.skipAssignedInstances false in simp_rw [TopologicalSpace.ext_iff, ← isClosed_compl_iff, ← @isClosed_compl_iff (PrimeSpectrum S) ((TopologicalSpace.induced (comap f) zariskiTopology)), isClosed_induced_iff, isClosed_iff_zeroLocus] refine fun s => ⟨fun ⟨F, hF⟩ => ⟨zeroLocus (f ⁻¹' F), ⟨f ⁻¹' F, rfl⟩, by rw [preimage_comap_zeroLocus, Function.Surjective.image_preimage hf, hF]⟩, ?_⟩ rintro ⟨-, ⟨F, rfl⟩, hF⟩ exact ⟨f '' F, hF.symm.trans (preimage_comap_zeroLocus f F)⟩ #align prime_spectrum.comap_inducing_of_surjective PrimeSpectrum.comap_inducing_of_surjective end Comap end CommSemiRing section SpecOfSurjective /-! The comap of a surjective ring homomorphism is a closed embedding between the prime spectra. -/ open Function RingHom variable [CommRing R] [CommRing S] variable (f : R →+* S) variable {R} theorem comap_singleton_isClosed_of_surjective (f : R →+* S) (hf : Function.Surjective f) (x : PrimeSpectrum S) (hx : IsClosed ({x} : Set (PrimeSpectrum S))) : IsClosed ({comap f x} : Set (PrimeSpectrum R)) := haveI : x.asIdeal.IsMaximal := (isClosed_singleton_iff_isMaximal x).1 hx (isClosed_singleton_iff_isMaximal _).2 (Ideal.comap_isMaximal_of_surjective f hf) #align prime_spectrum.comap_singleton_is_closed_of_surjective PrimeSpectrum.comap_singleton_isClosed_of_surjective theorem comap_singleton_isClosed_of_isIntegral (f : R →+* S) (hf : f.IsIntegral) (x : PrimeSpectrum S) (hx : IsClosed ({x} : Set (PrimeSpectrum S))) : IsClosed ({comap f x} : Set (PrimeSpectrum R)) := have := (isClosed_singleton_iff_isMaximal x).1 hx (isClosed_singleton_iff_isMaximal _).2 (Ideal.isMaximal_comap_of_isIntegral_of_isMaximal' f hf x.asIdeal) #align prime_spectrum.comap_singleton_is_closed_of_is_integral PrimeSpectrum.comap_singleton_isClosed_of_isIntegral
Mathlib/AlgebraicGeometry/PrimeSpectrum/Basic.lean
729
745
theorem image_comap_zeroLocus_eq_zeroLocus_comap (hf : Surjective f) (I : Ideal S) : comap f '' zeroLocus I = zeroLocus (I.comap f) := by
simp only [Set.ext_iff, Set.mem_image, mem_zeroLocus, SetLike.coe_subset_coe] refine fun p => ⟨?_, fun h_I_p => ?_⟩ · rintro ⟨p, hp, rfl⟩ a ha exact hp ha · have hp : ker f ≤ p.asIdeal := (Ideal.comap_mono bot_le).trans h_I_p refine ⟨⟨p.asIdeal.map f, Ideal.map_isPrime_of_surjective hf hp⟩, fun x hx => ?_, ?_⟩ · obtain ⟨x', rfl⟩ := hf x exact Ideal.mem_map_of_mem f (h_I_p hx) · ext x rw [comap_asIdeal, Ideal.mem_comap, Ideal.mem_map_iff_of_surjective f hf] refine ⟨?_, fun hx => ⟨x, hx, rfl⟩⟩ rintro ⟨x', hx', heq⟩ rw [← sub_sub_cancel x' x] refine p.asIdeal.sub_mem hx' (hp ?_) rwa [mem_ker, map_sub, sub_eq_zero]
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.Analysis.Calculus.ContDiff.Defs #align_import analysis.calculus.iterated_deriv from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # One-dimensional iterated derivatives We define the `n`-th derivative of a function `f : 𝕜 → F` as a function `iteratedDeriv n f : 𝕜 → F`, as well as a version on domains `iteratedDerivWithin n f s : 𝕜 → F`, and prove their basic properties. ## Main definitions and results Let `𝕜` be a nontrivially normed field, and `F` a normed vector space over `𝕜`. Let `f : 𝕜 → F`. * `iteratedDeriv n f` is the `n`-th derivative of `f`, seen as a function from `𝕜` to `F`. It is defined as the `n`-th Fréchet derivative (which is a multilinear map) applied to the vector `(1, ..., 1)`, to take advantage of all the existing framework, but we show that it coincides with the naive iterative definition. * `iteratedDeriv_eq_iterate` states that the `n`-th derivative of `f` is obtained by starting from `f` and differentiating it `n` times. * `iteratedDerivWithin n f s` is the `n`-th derivative of `f` within the domain `s`. It only behaves well when `s` has the unique derivative property. * `iteratedDerivWithin_eq_iterate` states that the `n`-th derivative of `f` in the domain `s` is obtained by starting from `f` and differentiating it `n` times within `s`. This only holds when `s` has the unique derivative property. ## Implementation details The results are deduced from the corresponding results for the more general (multilinear) iterated Fréchet derivative. For this, we write `iteratedDeriv n f` as the composition of `iteratedFDeriv 𝕜 n f` and a continuous linear equiv. As continuous linear equivs respect differentiability and commute with differentiation, this makes it possible to prove readily that the derivative of the `n`-th derivative is the `n+1`-th derivative in `iteratedDerivWithin_succ`, by translating the corresponding result `iteratedFDerivWithin_succ_apply_left` for the iterated Fréchet derivative. -/ noncomputable section open scoped Classical Topology open Filter Asymptotics Set variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] /-- The `n`-th iterated derivative of a function from `𝕜` to `F`, as a function from `𝕜` to `F`. -/ def iteratedDeriv (n : ℕ) (f : 𝕜 → F) (x : 𝕜) : F := (iteratedFDeriv 𝕜 n f x : (Fin n → 𝕜) → F) fun _ : Fin n => 1 #align iterated_deriv iteratedDeriv /-- The `n`-th iterated derivative of a function from `𝕜` to `F` within a set `s`, as a function from `𝕜` to `F`. -/ def iteratedDerivWithin (n : ℕ) (f : 𝕜 → F) (s : Set 𝕜) (x : 𝕜) : F := (iteratedFDerivWithin 𝕜 n f s x : (Fin n → 𝕜) → F) fun _ : Fin n => 1 #align iterated_deriv_within iteratedDerivWithin variable {n : ℕ} {f : 𝕜 → F} {s : Set 𝕜} {x : 𝕜} theorem iteratedDerivWithin_univ : iteratedDerivWithin n f univ = iteratedDeriv n f := by ext x rw [iteratedDerivWithin, iteratedDeriv, iteratedFDerivWithin_univ] #align iterated_deriv_within_univ iteratedDerivWithin_univ /-! ### Properties of the iterated derivative within a set -/ theorem iteratedDerivWithin_eq_iteratedFDerivWithin : iteratedDerivWithin n f s x = (iteratedFDerivWithin 𝕜 n f s x : (Fin n → 𝕜) → F) fun _ : Fin n => 1 := rfl #align iterated_deriv_within_eq_iterated_fderiv_within iteratedDerivWithin_eq_iteratedFDerivWithin /-- Write the iterated derivative as the composition of a continuous linear equiv and the iterated Fréchet derivative -/ theorem iteratedDerivWithin_eq_equiv_comp : iteratedDerivWithin n f s = (ContinuousMultilinearMap.piFieldEquiv 𝕜 (Fin n) F).symm ∘ iteratedFDerivWithin 𝕜 n f s := by ext x; rfl #align iterated_deriv_within_eq_equiv_comp iteratedDerivWithin_eq_equiv_comp /-- Write the iterated Fréchet derivative as the composition of a continuous linear equiv and the iterated derivative. -/ theorem iteratedFDerivWithin_eq_equiv_comp : iteratedFDerivWithin 𝕜 n f s = ContinuousMultilinearMap.piFieldEquiv 𝕜 (Fin n) F ∘ iteratedDerivWithin n f s := by rw [iteratedDerivWithin_eq_equiv_comp, ← Function.comp.assoc, LinearIsometryEquiv.self_comp_symm, Function.id_comp] #align iterated_fderiv_within_eq_equiv_comp iteratedFDerivWithin_eq_equiv_comp /-- The `n`-th Fréchet derivative applied to a vector `(m 0, ..., m (n-1))` is the derivative multiplied by the product of the `m i`s. -/ theorem iteratedFDerivWithin_apply_eq_iteratedDerivWithin_mul_prod {m : Fin n → 𝕜} : (iteratedFDerivWithin 𝕜 n f s x : (Fin n → 𝕜) → F) m = (∏ i, m i) • iteratedDerivWithin n f s x := by rw [iteratedDerivWithin_eq_iteratedFDerivWithin, ← ContinuousMultilinearMap.map_smul_univ] simp #align iterated_fderiv_within_apply_eq_iterated_deriv_within_mul_prod iteratedFDerivWithin_apply_eq_iteratedDerivWithin_mul_prod theorem norm_iteratedFDerivWithin_eq_norm_iteratedDerivWithin : ‖iteratedFDerivWithin 𝕜 n f s x‖ = ‖iteratedDerivWithin n f s x‖ := by rw [iteratedDerivWithin_eq_equiv_comp, Function.comp_apply, LinearIsometryEquiv.norm_map] #align norm_iterated_fderiv_within_eq_norm_iterated_deriv_within norm_iteratedFDerivWithin_eq_norm_iteratedDerivWithin @[simp] theorem iteratedDerivWithin_zero : iteratedDerivWithin 0 f s = f := by ext x simp [iteratedDerivWithin] #align iterated_deriv_within_zero iteratedDerivWithin_zero @[simp] theorem iteratedDerivWithin_one {x : 𝕜} (h : UniqueDiffWithinAt 𝕜 s x) : iteratedDerivWithin 1 f s x = derivWithin f s x := by simp only [iteratedDerivWithin, iteratedFDerivWithin_one_apply h]; rfl #align iterated_deriv_within_one iteratedDerivWithin_one /-- If the first `n` derivatives within a set of a function are continuous, and its first `n-1` derivatives are differentiable, then the function is `C^n`. This is not an equivalence in general, but this is an equivalence when the set has unique derivatives, see `contDiffOn_iff_continuousOn_differentiableOn_deriv`. -/ theorem contDiffOn_of_continuousOn_differentiableOn_deriv {n : ℕ∞} (Hcont : ∀ m : ℕ, (m : ℕ∞) ≤ n → ContinuousOn (fun x => iteratedDerivWithin m f s x) s) (Hdiff : ∀ m : ℕ, (m : ℕ∞) < n → DifferentiableOn 𝕜 (fun x => iteratedDerivWithin m f s x) s) : ContDiffOn 𝕜 n f s := by apply contDiffOn_of_continuousOn_differentiableOn · simpa only [iteratedFDerivWithin_eq_equiv_comp, LinearIsometryEquiv.comp_continuousOn_iff] · simpa only [iteratedFDerivWithin_eq_equiv_comp, LinearIsometryEquiv.comp_differentiableOn_iff] #align cont_diff_on_of_continuous_on_differentiable_on_deriv contDiffOn_of_continuousOn_differentiableOn_deriv /-- To check that a function is `n` times continuously differentiable, it suffices to check that its first `n` derivatives are differentiable. This is slightly too strong as the condition we require on the `n`-th derivative is differentiability instead of continuity, but it has the advantage of avoiding the discussion of continuity in the proof (and for `n = ∞` this is optimal). -/ theorem contDiffOn_of_differentiableOn_deriv {n : ℕ∞} (h : ∀ m : ℕ, (m : ℕ∞) ≤ n → DifferentiableOn 𝕜 (iteratedDerivWithin m f s) s) : ContDiffOn 𝕜 n f s := by apply contDiffOn_of_differentiableOn simpa only [iteratedFDerivWithin_eq_equiv_comp, LinearIsometryEquiv.comp_differentiableOn_iff] #align cont_diff_on_of_differentiable_on_deriv contDiffOn_of_differentiableOn_deriv /-- On a set with unique derivatives, a `C^n` function has derivatives up to `n` which are continuous. -/ theorem ContDiffOn.continuousOn_iteratedDerivWithin {n : ℕ∞} {m : ℕ} (h : ContDiffOn 𝕜 n f s) (hmn : (m : ℕ∞) ≤ n) (hs : UniqueDiffOn 𝕜 s) : ContinuousOn (iteratedDerivWithin m f s) s := by simpa only [iteratedDerivWithin_eq_equiv_comp, LinearIsometryEquiv.comp_continuousOn_iff] using h.continuousOn_iteratedFDerivWithin hmn hs #align cont_diff_on.continuous_on_iterated_deriv_within ContDiffOn.continuousOn_iteratedDerivWithin theorem ContDiffWithinAt.differentiableWithinAt_iteratedDerivWithin {n : ℕ∞} {m : ℕ} (h : ContDiffWithinAt 𝕜 n f s x) (hmn : (m : ℕ∞) < n) (hs : UniqueDiffOn 𝕜 (insert x s)) : DifferentiableWithinAt 𝕜 (iteratedDerivWithin m f s) s x := by simpa only [iteratedDerivWithin_eq_equiv_comp, LinearIsometryEquiv.comp_differentiableWithinAt_iff] using h.differentiableWithinAt_iteratedFDerivWithin hmn hs #align cont_diff_within_at.differentiable_within_at_iterated_deriv_within ContDiffWithinAt.differentiableWithinAt_iteratedDerivWithin /-- On a set with unique derivatives, a `C^n` function has derivatives less than `n` which are differentiable. -/ theorem ContDiffOn.differentiableOn_iteratedDerivWithin {n : ℕ∞} {m : ℕ} (h : ContDiffOn 𝕜 n f s) (hmn : (m : ℕ∞) < n) (hs : UniqueDiffOn 𝕜 s) : DifferentiableOn 𝕜 (iteratedDerivWithin m f s) s := fun x hx => (h x hx).differentiableWithinAt_iteratedDerivWithin hmn <| by rwa [insert_eq_of_mem hx] #align cont_diff_on.differentiable_on_iterated_deriv_within ContDiffOn.differentiableOn_iteratedDerivWithin /-- The property of being `C^n`, initially defined in terms of the Fréchet derivative, can be reformulated in terms of the one-dimensional derivative on sets with unique derivatives. -/ theorem contDiffOn_iff_continuousOn_differentiableOn_deriv {n : ℕ∞} (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 n f s ↔ (∀ m : ℕ, (m : ℕ∞) ≤ n → ContinuousOn (iteratedDerivWithin m f s) s) ∧ ∀ m : ℕ, (m : ℕ∞) < n → DifferentiableOn 𝕜 (iteratedDerivWithin m f s) s := by simp only [contDiffOn_iff_continuousOn_differentiableOn hs, iteratedFDerivWithin_eq_equiv_comp, LinearIsometryEquiv.comp_continuousOn_iff, LinearIsometryEquiv.comp_differentiableOn_iff] #align cont_diff_on_iff_continuous_on_differentiable_on_deriv contDiffOn_iff_continuousOn_differentiableOn_deriv /-- The `n+1`-th iterated derivative within a set with unique derivatives can be obtained by differentiating the `n`-th iterated derivative. -/ theorem iteratedDerivWithin_succ {x : 𝕜} (hxs : UniqueDiffWithinAt 𝕜 s x) : iteratedDerivWithin (n + 1) f s x = derivWithin (iteratedDerivWithin n f s) s x := by rw [iteratedDerivWithin_eq_iteratedFDerivWithin, iteratedFDerivWithin_succ_apply_left, iteratedFDerivWithin_eq_equiv_comp, LinearIsometryEquiv.comp_fderivWithin _ hxs, derivWithin] change ((ContinuousMultilinearMap.mkPiRing 𝕜 (Fin n) ((fderivWithin 𝕜 (iteratedDerivWithin n f s) s x : 𝕜 → F) 1) : (Fin n → 𝕜) → F) fun i : Fin n => 1) = (fderivWithin 𝕜 (iteratedDerivWithin n f s) s x : 𝕜 → F) 1 simp #align iterated_deriv_within_succ iteratedDerivWithin_succ /-- The `n`-th iterated derivative within a set with unique derivatives can be obtained by iterating `n` times the differentiation operation. -/ theorem iteratedDerivWithin_eq_iterate {x : 𝕜} (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : iteratedDerivWithin n f s x = (fun g : 𝕜 → F => derivWithin g s)^[n] f x := by induction' n with n IH generalizing x · simp · rw [iteratedDerivWithin_succ (hs x hx), Function.iterate_succ'] exact derivWithin_congr (fun y hy => IH hy) (IH hx) #align iterated_deriv_within_eq_iterate iteratedDerivWithin_eq_iterate /-- The `n+1`-th iterated derivative within a set with unique derivatives can be obtained by taking the `n`-th derivative of the derivative. -/ theorem iteratedDerivWithin_succ' {x : 𝕜} (hxs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : iteratedDerivWithin (n + 1) f s x = (iteratedDerivWithin n (derivWithin f s) s) x := by rw [iteratedDerivWithin_eq_iterate hxs hx, iteratedDerivWithin_eq_iterate hxs hx]; rfl #align iterated_deriv_within_succ' iteratedDerivWithin_succ' /-! ### Properties of the iterated derivative on the whole space -/ theorem iteratedDeriv_eq_iteratedFDeriv : iteratedDeriv n f x = (iteratedFDeriv 𝕜 n f x : (Fin n → 𝕜) → F) fun _ : Fin n => 1 := rfl #align iterated_deriv_eq_iterated_fderiv iteratedDeriv_eq_iteratedFDeriv /-- Write the iterated derivative as the composition of a continuous linear equiv and the iterated Fréchet derivative -/ theorem iteratedDeriv_eq_equiv_comp : iteratedDeriv n f = (ContinuousMultilinearMap.piFieldEquiv 𝕜 (Fin n) F).symm ∘ iteratedFDeriv 𝕜 n f := by ext x; rfl #align iterated_deriv_eq_equiv_comp iteratedDeriv_eq_equiv_comp /-- Write the iterated Fréchet derivative as the composition of a continuous linear equiv and the iterated derivative. -/ theorem iteratedFDeriv_eq_equiv_comp : iteratedFDeriv 𝕜 n f = ContinuousMultilinearMap.piFieldEquiv 𝕜 (Fin n) F ∘ iteratedDeriv n f := by rw [iteratedDeriv_eq_equiv_comp, ← Function.comp.assoc, LinearIsometryEquiv.self_comp_symm, Function.id_comp] #align iterated_fderiv_eq_equiv_comp iteratedFDeriv_eq_equiv_comp /-- The `n`-th Fréchet derivative applied to a vector `(m 0, ..., m (n-1))` is the derivative multiplied by the product of the `m i`s. -/ theorem iteratedFDeriv_apply_eq_iteratedDeriv_mul_prod {m : Fin n → 𝕜} : (iteratedFDeriv 𝕜 n f x : (Fin n → 𝕜) → F) m = (∏ i, m i) • iteratedDeriv n f x := by rw [iteratedDeriv_eq_iteratedFDeriv, ← ContinuousMultilinearMap.map_smul_univ]; simp #align iterated_fderiv_apply_eq_iterated_deriv_mul_prod iteratedFDeriv_apply_eq_iteratedDeriv_mul_prod theorem norm_iteratedFDeriv_eq_norm_iteratedDeriv : ‖iteratedFDeriv 𝕜 n f x‖ = ‖iteratedDeriv n f x‖ := by rw [iteratedDeriv_eq_equiv_comp, Function.comp_apply, LinearIsometryEquiv.norm_map] #align norm_iterated_fderiv_eq_norm_iterated_deriv norm_iteratedFDeriv_eq_norm_iteratedDeriv @[simp] theorem iteratedDeriv_zero : iteratedDeriv 0 f = f := by ext x; simp [iteratedDeriv] #align iterated_deriv_zero iteratedDeriv_zero @[simp] theorem iteratedDeriv_one : iteratedDeriv 1 f = deriv f := by ext x; simp [iteratedDeriv]; rfl #align iterated_deriv_one iteratedDeriv_one /-- The property of being `C^n`, initially defined in terms of the Fréchet derivative, can be reformulated in terms of the one-dimensional derivative. -/ theorem contDiff_iff_iteratedDeriv {n : ℕ∞} : ContDiff 𝕜 n f ↔ (∀ m : ℕ, (m : ℕ∞) ≤ n → Continuous (iteratedDeriv m f)) ∧ ∀ m : ℕ, (m : ℕ∞) < n → Differentiable 𝕜 (iteratedDeriv m f) := by simp only [contDiff_iff_continuous_differentiable, iteratedFDeriv_eq_equiv_comp, LinearIsometryEquiv.comp_continuous_iff, LinearIsometryEquiv.comp_differentiable_iff] #align cont_diff_iff_iterated_deriv contDiff_iff_iteratedDeriv /-- To check that a function is `n` times continuously differentiable, it suffices to check that its first `n` derivatives are differentiable. This is slightly too strong as the condition we require on the `n`-th derivative is differentiability instead of continuity, but it has the advantage of avoiding the discussion of continuity in the proof (and for `n = ∞` this is optimal). -/ theorem contDiff_of_differentiable_iteratedDeriv {n : ℕ∞} (h : ∀ m : ℕ, (m : ℕ∞) ≤ n → Differentiable 𝕜 (iteratedDeriv m f)) : ContDiff 𝕜 n f := contDiff_iff_iteratedDeriv.2 ⟨fun m hm => (h m hm).continuous, fun m hm => h m (le_of_lt hm)⟩ #align cont_diff_of_differentiable_iterated_deriv contDiff_of_differentiable_iteratedDeriv theorem ContDiff.continuous_iteratedDeriv {n : ℕ∞} (m : ℕ) (h : ContDiff 𝕜 n f) (hmn : (m : ℕ∞) ≤ n) : Continuous (iteratedDeriv m f) := (contDiff_iff_iteratedDeriv.1 h).1 m hmn #align cont_diff.continuous_iterated_deriv ContDiff.continuous_iteratedDeriv theorem ContDiff.differentiable_iteratedDeriv {n : ℕ∞} (m : ℕ) (h : ContDiff 𝕜 n f) (hmn : (m : ℕ∞) < n) : Differentiable 𝕜 (iteratedDeriv m f) := (contDiff_iff_iteratedDeriv.1 h).2 m hmn #align cont_diff.differentiable_iterated_deriv ContDiff.differentiable_iteratedDeriv /-- The `n+1`-th iterated derivative can be obtained by differentiating the `n`-th iterated derivative. -/ theorem iteratedDeriv_succ : iteratedDeriv (n + 1) f = deriv (iteratedDeriv n f) := by ext x rw [← iteratedDerivWithin_univ, ← iteratedDerivWithin_univ, ← derivWithin_univ] exact iteratedDerivWithin_succ uniqueDiffWithinAt_univ #align iterated_deriv_succ iteratedDeriv_succ /-- The `n`-th iterated derivative can be obtained by iterating `n` times the differentiation operation. -/
Mathlib/Analysis/Calculus/IteratedDeriv/Defs.lean
293
297
theorem iteratedDeriv_eq_iterate : iteratedDeriv n f = deriv^[n] f := by
ext x rw [← iteratedDerivWithin_univ] convert iteratedDerivWithin_eq_iterate uniqueDiffOn_univ (F := F) (mem_univ x) simp [derivWithin_univ]
/- 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.Geometry.Euclidean.Angle.Oriented.Affine import Mathlib.Geometry.Euclidean.Angle.Unoriented.RightAngle #align_import geometry.euclidean.angle.oriented.right_angle from "leanprover-community/mathlib"@"46b633fd842bef9469441c0209906f6dddd2b4f5" /-! # Oriented angles in right-angled triangles. This file proves basic geometrical results about distances and oriented angles in (possibly degenerate) right-angled triangles in real inner product spaces and Euclidean affine spaces. -/ noncomputable section open scoped EuclideanGeometry open scoped Real open scoped RealInnerProductSpace namespace Orientation open FiniteDimensional variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] variable [hd2 : Fact (finrank ℝ V = 2)] (o : Orientation ℝ V (Fin 2)) /-- An angle in a right-angled triangle expressed using `arccos`. -/ theorem oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle x (x + y) = Real.arccos (‖x‖ / ‖x + y‖) := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, InnerProductGeometry.angle_add_eq_arccos_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)] #align orientation.oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two Orientation.oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arccos`. -/ theorem oangle_add_left_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle (x + y) y = Real.arccos (‖y‖ / ‖x + y‖) := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two h #align orientation.oangle_add_left_eq_arccos_of_oangle_eq_pi_div_two Orientation.oangle_add_left_eq_arccos_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arcsin`. -/ theorem oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle x (x + y) = Real.arcsin (‖y‖ / ‖x + y‖) := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, InnerProductGeometry.angle_add_eq_arcsin_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))] #align orientation.oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two Orientation.oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arcsin`. -/ theorem oangle_add_left_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle (x + y) y = Real.arcsin (‖x‖ / ‖x + y‖) := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two h #align orientation.oangle_add_left_eq_arcsin_of_oangle_eq_pi_div_two Orientation.oangle_add_left_eq_arcsin_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arctan`. -/ theorem oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle x (x + y) = Real.arctan (‖y‖ / ‖x‖) := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, InnerProductGeometry.angle_add_eq_arctan_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (o.left_ne_zero_of_oangle_eq_pi_div_two h)] #align orientation.oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two Orientation.oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arctan`. -/ theorem oangle_add_left_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle (x + y) y = Real.arctan (‖x‖ / ‖y‖) := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two h #align orientation.oangle_add_left_eq_arctan_of_oangle_eq_pi_div_two Orientation.oangle_add_left_eq_arctan_of_oangle_eq_pi_div_two /-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/ theorem cos_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle x (x + y)) = ‖x‖ / ‖x + y‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe, InnerProductGeometry.cos_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)] #align orientation.cos_oangle_add_right_of_oangle_eq_pi_div_two Orientation.cos_oangle_add_right_of_oangle_eq_pi_div_two /-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/ theorem cos_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle (x + y) y) = ‖y‖ / ‖x + y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).cos_oangle_add_right_of_oangle_eq_pi_div_two h #align orientation.cos_oangle_add_left_of_oangle_eq_pi_div_two Orientation.cos_oangle_add_left_of_oangle_eq_pi_div_two /-- The sine of an angle in a right-angled triangle as a ratio of sides. -/ theorem sin_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle x (x + y)) = ‖y‖ / ‖x + y‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe, InnerProductGeometry.sin_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))] #align orientation.sin_oangle_add_right_of_oangle_eq_pi_div_two Orientation.sin_oangle_add_right_of_oangle_eq_pi_div_two /-- The sine of an angle in a right-angled triangle as a ratio of sides. -/ theorem sin_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle (x + y) y) = ‖x‖ / ‖x + y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).sin_oangle_add_right_of_oangle_eq_pi_div_two h #align orientation.sin_oangle_add_left_of_oangle_eq_pi_div_two Orientation.sin_oangle_add_left_of_oangle_eq_pi_div_two /-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/ theorem tan_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle x (x + y)) = ‖y‖ / ‖x‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe, InnerProductGeometry.tan_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)] #align orientation.tan_oangle_add_right_of_oangle_eq_pi_div_two Orientation.tan_oangle_add_right_of_oangle_eq_pi_div_two /-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/ theorem tan_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle (x + y) y) = ‖x‖ / ‖y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).tan_oangle_add_right_of_oangle_eq_pi_div_two h #align orientation.tan_oangle_add_left_of_oangle_eq_pi_div_two Orientation.tan_oangle_add_left_of_oangle_eq_pi_div_two /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side. -/ theorem cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle x (x + y)) * ‖x + y‖ = ‖x‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe, InnerProductGeometry.cos_angle_add_mul_norm_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)] #align orientation.cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two Orientation.cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side. -/ theorem cos_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle (x + y) y) * ‖x + y‖ = ‖y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h #align orientation.cos_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two Orientation.cos_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side. -/ theorem sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle x (x + y)) * ‖x + y‖ = ‖y‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe, InnerProductGeometry.sin_angle_add_mul_norm_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)] #align orientation.sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two Orientation.sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side. -/ theorem sin_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle (x + y) y) * ‖x + y‖ = ‖x‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h #align orientation.sin_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two Orientation.sin_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side. -/ theorem tan_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle x (x + y)) * ‖x‖ = ‖y‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe, InnerProductGeometry.tan_angle_add_mul_norm_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))] #align orientation.tan_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two Orientation.tan_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side. -/ theorem tan_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle (x + y) y) * ‖y‖ = ‖x‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).tan_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h #align orientation.tan_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two Orientation.tan_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse. -/ theorem norm_div_cos_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.cos (o.oangle x (x + y)) = ‖x + y‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe, InnerProductGeometry.norm_div_cos_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))] #align orientation.norm_div_cos_oangle_add_right_of_oangle_eq_pi_div_two Orientation.norm_div_cos_oangle_add_right_of_oangle_eq_pi_div_two /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse. -/ theorem norm_div_cos_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.cos (o.oangle (x + y) y) = ‖x + y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).norm_div_cos_oangle_add_right_of_oangle_eq_pi_div_two h #align orientation.norm_div_cos_oangle_add_left_of_oangle_eq_pi_div_two Orientation.norm_div_cos_oangle_add_left_of_oangle_eq_pi_div_two /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse. -/ theorem norm_div_sin_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.sin (o.oangle x (x + y)) = ‖x + y‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe, InnerProductGeometry.norm_div_sin_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (Or.inr (o.right_ne_zero_of_oangle_eq_pi_div_two h))] #align orientation.norm_div_sin_oangle_add_right_of_oangle_eq_pi_div_two Orientation.norm_div_sin_oangle_add_right_of_oangle_eq_pi_div_two /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse. -/ theorem norm_div_sin_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.sin (o.oangle (x + y) y) = ‖x + y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).norm_div_sin_oangle_add_right_of_oangle_eq_pi_div_two h #align orientation.norm_div_sin_oangle_add_left_of_oangle_eq_pi_div_two Orientation.norm_div_sin_oangle_add_left_of_oangle_eq_pi_div_two /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side. -/ theorem norm_div_tan_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.tan (o.oangle x (x + y)) = ‖x‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe, InnerProductGeometry.norm_div_tan_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (Or.inr (o.right_ne_zero_of_oangle_eq_pi_div_two h))] #align orientation.norm_div_tan_oangle_add_right_of_oangle_eq_pi_div_two Orientation.norm_div_tan_oangle_add_right_of_oangle_eq_pi_div_two /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side. -/ theorem norm_div_tan_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.tan (o.oangle (x + y) y) = ‖y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).norm_div_tan_oangle_add_right_of_oangle_eq_pi_div_two h #align orientation.norm_div_tan_oangle_add_left_of_oangle_eq_pi_div_two Orientation.norm_div_tan_oangle_add_left_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arccos`, version subtracting vectors. -/ theorem oangle_sub_right_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle y (y - x) = Real.arccos (‖y‖ / ‖y - x‖) := by have hs : (o.oangle y (y - x)).sign = 1 := by rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, InnerProductGeometry.angle_sub_eq_arccos_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)] #align orientation.oangle_sub_right_eq_arccos_of_oangle_eq_pi_div_two Orientation.oangle_sub_right_eq_arccos_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arccos`, version subtracting vectors. -/ theorem oangle_sub_left_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle (x - y) x = Real.arccos (‖x‖ / ‖x - y‖) := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ exact (-o).oangle_sub_right_eq_arccos_of_oangle_eq_pi_div_two h #align orientation.oangle_sub_left_eq_arccos_of_oangle_eq_pi_div_two Orientation.oangle_sub_left_eq_arccos_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arcsin`, version subtracting vectors. -/ theorem oangle_sub_right_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle y (y - x) = Real.arcsin (‖x‖ / ‖y - x‖) := by have hs : (o.oangle y (y - x)).sign = 1 := by rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, InnerProductGeometry.angle_sub_eq_arcsin_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h) (Or.inl (o.right_ne_zero_of_oangle_eq_pi_div_two h))] #align orientation.oangle_sub_right_eq_arcsin_of_oangle_eq_pi_div_two Orientation.oangle_sub_right_eq_arcsin_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arcsin`, version subtracting vectors. -/ theorem oangle_sub_left_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle (x - y) x = Real.arcsin (‖y‖ / ‖x - y‖) := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ exact (-o).oangle_sub_right_eq_arcsin_of_oangle_eq_pi_div_two h #align orientation.oangle_sub_left_eq_arcsin_of_oangle_eq_pi_div_two Orientation.oangle_sub_left_eq_arcsin_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arctan`, version subtracting vectors. -/ theorem oangle_sub_right_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle y (y - x) = Real.arctan (‖x‖ / ‖y‖) := by have hs : (o.oangle y (y - x)).sign = 1 := by rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, InnerProductGeometry.angle_sub_eq_arctan_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h) (o.right_ne_zero_of_oangle_eq_pi_div_two h)] #align orientation.oangle_sub_right_eq_arctan_of_oangle_eq_pi_div_two Orientation.oangle_sub_right_eq_arctan_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arctan`, version subtracting vectors. -/ theorem oangle_sub_left_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle (x - y) x = Real.arctan (‖y‖ / ‖x‖) := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ exact (-o).oangle_sub_right_eq_arctan_of_oangle_eq_pi_div_two h #align orientation.oangle_sub_left_eq_arctan_of_oangle_eq_pi_div_two Orientation.oangle_sub_left_eq_arctan_of_oangle_eq_pi_div_two /-- The cosine of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ theorem cos_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle y (y - x)) = ‖y‖ / ‖y - x‖ := by have hs : (o.oangle y (y - x)).sign = 1 := by rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe, InnerProductGeometry.cos_angle_sub_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)] #align orientation.cos_oangle_sub_right_of_oangle_eq_pi_div_two Orientation.cos_oangle_sub_right_of_oangle_eq_pi_div_two /-- The cosine of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ theorem cos_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle (x - y) x) = ‖x‖ / ‖x - y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ exact (-o).cos_oangle_sub_right_of_oangle_eq_pi_div_two h #align orientation.cos_oangle_sub_left_of_oangle_eq_pi_div_two Orientation.cos_oangle_sub_left_of_oangle_eq_pi_div_two /-- The sine of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ theorem sin_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle y (y - x)) = ‖x‖ / ‖y - x‖ := by have hs : (o.oangle y (y - x)).sign = 1 := by rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe, InnerProductGeometry.sin_angle_sub_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h) (Or.inl (o.right_ne_zero_of_oangle_eq_pi_div_two h))] #align orientation.sin_oangle_sub_right_of_oangle_eq_pi_div_two Orientation.sin_oangle_sub_right_of_oangle_eq_pi_div_two /-- The sine of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ theorem sin_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle (x - y) x) = ‖y‖ / ‖x - y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ exact (-o).sin_oangle_sub_right_of_oangle_eq_pi_div_two h #align orientation.sin_oangle_sub_left_of_oangle_eq_pi_div_two Orientation.sin_oangle_sub_left_of_oangle_eq_pi_div_two /-- The tangent of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ theorem tan_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle y (y - x)) = ‖x‖ / ‖y‖ := by have hs : (o.oangle y (y - x)).sign = 1 := by rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe, InnerProductGeometry.tan_angle_sub_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)] #align orientation.tan_oangle_sub_right_of_oangle_eq_pi_div_two Orientation.tan_oangle_sub_right_of_oangle_eq_pi_div_two /-- The tangent of an angle in a right-angled triangle as a ratio of sides, version subtracting vectors. -/ theorem tan_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle (x - y) x) = ‖y‖ / ‖x‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ exact (-o).tan_oangle_sub_right_of_oangle_eq_pi_div_two h #align orientation.tan_oangle_sub_left_of_oangle_eq_pi_div_two Orientation.tan_oangle_sub_left_of_oangle_eq_pi_div_two /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side, version subtracting vectors. -/ theorem cos_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle y (y - x)) * ‖y - x‖ = ‖y‖ := by have hs : (o.oangle y (y - x)).sign = 1 := by rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe, InnerProductGeometry.cos_angle_sub_mul_norm_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)] #align orientation.cos_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two Orientation.cos_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side, version subtracting vectors. -/ theorem cos_oangle_sub_left_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle (x - y) x) * ‖x - y‖ = ‖x‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ exact (-o).cos_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two h #align orientation.cos_oangle_sub_left_mul_norm_of_oangle_eq_pi_div_two Orientation.cos_oangle_sub_left_mul_norm_of_oangle_eq_pi_div_two /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side, version subtracting vectors. -/ theorem sin_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle y (y - x)) * ‖y - x‖ = ‖x‖ := by have hs : (o.oangle y (y - x)).sign = 1 := by rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe, InnerProductGeometry.sin_angle_sub_mul_norm_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)] #align orientation.sin_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two Orientation.sin_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side, version subtracting vectors. -/ theorem sin_oangle_sub_left_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle (x - y) x) * ‖x - y‖ = ‖y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ exact (-o).sin_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two h #align orientation.sin_oangle_sub_left_mul_norm_of_oangle_eq_pi_div_two Orientation.sin_oangle_sub_left_mul_norm_of_oangle_eq_pi_div_two /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side, version subtracting vectors. -/ theorem tan_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle y (y - x)) * ‖y‖ = ‖x‖ := by have hs : (o.oangle y (y - x)).sign = 1 := by rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe, InnerProductGeometry.tan_angle_sub_mul_norm_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h) (Or.inl (o.right_ne_zero_of_oangle_eq_pi_div_two h))] #align orientation.tan_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two Orientation.tan_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side, version subtracting vectors. -/ theorem tan_oangle_sub_left_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle (x - y) x) * ‖x‖ = ‖y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ exact (-o).tan_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two h #align orientation.tan_oangle_sub_left_mul_norm_of_oangle_eq_pi_div_two Orientation.tan_oangle_sub_left_mul_norm_of_oangle_eq_pi_div_two /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse, version subtracting vectors. -/ theorem norm_div_cos_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.cos (o.oangle y (y - x)) = ‖y - x‖ := by have hs : (o.oangle y (y - x)).sign = 1 := by rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe, InnerProductGeometry.norm_div_cos_angle_sub_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h) (Or.inl (o.right_ne_zero_of_oangle_eq_pi_div_two h))] #align orientation.norm_div_cos_oangle_sub_right_of_oangle_eq_pi_div_two Orientation.norm_div_cos_oangle_sub_right_of_oangle_eq_pi_div_two /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse, version subtracting vectors. -/ theorem norm_div_cos_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.cos (o.oangle (x - y) x) = ‖x - y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ exact (-o).norm_div_cos_oangle_sub_right_of_oangle_eq_pi_div_two h #align orientation.norm_div_cos_oangle_sub_left_of_oangle_eq_pi_div_two Orientation.norm_div_cos_oangle_sub_left_of_oangle_eq_pi_div_two /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse, version subtracting vectors. -/ theorem norm_div_sin_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.sin (o.oangle y (y - x)) = ‖y - x‖ := by have hs : (o.oangle y (y - x)).sign = 1 := by rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe, InnerProductGeometry.norm_div_sin_angle_sub_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h) (Or.inr (o.left_ne_zero_of_oangle_eq_pi_div_two h))] #align orientation.norm_div_sin_oangle_sub_right_of_oangle_eq_pi_div_two Orientation.norm_div_sin_oangle_sub_right_of_oangle_eq_pi_div_two /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse, version subtracting vectors. -/ theorem norm_div_sin_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.sin (o.oangle (x - y) x) = ‖x - y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ exact (-o).norm_div_sin_oangle_sub_right_of_oangle_eq_pi_div_two h #align orientation.norm_div_sin_oangle_sub_left_of_oangle_eq_pi_div_two Orientation.norm_div_sin_oangle_sub_left_of_oangle_eq_pi_div_two /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side, version subtracting vectors. -/ theorem norm_div_tan_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.tan (o.oangle y (y - x)) = ‖y‖ := by have hs : (o.oangle y (y - x)).sign = 1 := by rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe, InnerProductGeometry.norm_div_tan_angle_sub_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h) (Or.inr (o.left_ne_zero_of_oangle_eq_pi_div_two h))] #align orientation.norm_div_tan_oangle_sub_right_of_oangle_eq_pi_div_two Orientation.norm_div_tan_oangle_sub_right_of_oangle_eq_pi_div_two /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side, version subtracting vectors. -/ theorem norm_div_tan_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.tan (o.oangle (x - y) x) = ‖x‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ exact (-o).norm_div_tan_oangle_sub_right_of_oangle_eq_pi_div_two h #align orientation.norm_div_tan_oangle_sub_left_of_oangle_eq_pi_div_two Orientation.norm_div_tan_oangle_sub_left_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arctan`, where one side is a multiple of a rotation of another by `π / 2`. -/ theorem oangle_add_right_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) : o.oangle x (x + r • o.rotation (π / 2 : ℝ) x) = Real.arctan r := by rcases lt_trichotomy r 0 with (hr | rfl | hr) · have ha : o.oangle x (r • o.rotation (π / 2 : ℝ) x) = -(π / 2 : ℝ) := by rw [o.oangle_smul_right_of_neg _ _ hr, o.oangle_neg_right h, o.oangle_rotation_self_right h, ← sub_eq_zero, add_comm, sub_neg_eq_add, ← Real.Angle.coe_add, ← Real.Angle.coe_add, add_assoc, add_halves, ← two_mul, Real.Angle.coe_two_pi] simpa using h -- Porting note: if the type is not given in `neg_neg` then Lean "forgets" about the instance -- `Neg (Orientation ℝ V (Fin 2))` rw [← neg_inj, ← oangle_neg_orientation_eq_neg, @neg_neg Real.Angle] at ha rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj, oangle_rev, (-o).oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two ha, norm_smul, LinearIsometryEquiv.norm_map, mul_div_assoc, div_self (norm_ne_zero_iff.2 h), mul_one, Real.norm_eq_abs, abs_of_neg hr, Real.arctan_neg, Real.Angle.coe_neg, neg_neg] · rw [zero_smul, add_zero, oangle_self, Real.arctan_zero, Real.Angle.coe_zero] · have ha : o.oangle x (r • o.rotation (π / 2 : ℝ) x) = (π / 2 : ℝ) := by rw [o.oangle_smul_right_of_pos _ _ hr, o.oangle_rotation_self_right h] rw [o.oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two ha, norm_smul, LinearIsometryEquiv.norm_map, mul_div_assoc, div_self (norm_ne_zero_iff.2 h), mul_one, Real.norm_eq_abs, abs_of_pos hr] #align orientation.oangle_add_right_smul_rotation_pi_div_two Orientation.oangle_add_right_smul_rotation_pi_div_two /-- An angle in a right-angled triangle expressed using `arctan`, where one side is a multiple of a rotation of another by `π / 2`. -/ theorem oangle_add_left_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) : o.oangle (x + r • o.rotation (π / 2 : ℝ) x) (r • o.rotation (π / 2 : ℝ) x) = Real.arctan r⁻¹ := by by_cases hr : r = 0; · simp [hr] rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj, ← neg_neg ((π / 2 : ℝ) : Real.Angle), ← rotation_neg_orientation_eq_neg, add_comm] have hx : x = r⁻¹ • (-o).rotation (π / 2 : ℝ) (r • (-o).rotation (-(π / 2 : ℝ)) x) := by simp [hr] nth_rw 3 [hx] refine (-o).oangle_add_right_smul_rotation_pi_div_two ?_ _ simp [hr, h] #align orientation.oangle_add_left_smul_rotation_pi_div_two Orientation.oangle_add_left_smul_rotation_pi_div_two /-- The tangent of an angle in a right-angled triangle, where one side is a multiple of a rotation of another by `π / 2`. -/ theorem tan_oangle_add_right_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) : Real.Angle.tan (o.oangle x (x + r • o.rotation (π / 2 : ℝ) x)) = r := by rw [o.oangle_add_right_smul_rotation_pi_div_two h, Real.Angle.tan_coe, Real.tan_arctan] #align orientation.tan_oangle_add_right_smul_rotation_pi_div_two Orientation.tan_oangle_add_right_smul_rotation_pi_div_two /-- The tangent of an angle in a right-angled triangle, where one side is a multiple of a rotation of another by `π / 2`. -/ theorem tan_oangle_add_left_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) : Real.Angle.tan (o.oangle (x + r • o.rotation (π / 2 : ℝ) x) (r • o.rotation (π / 2 : ℝ) x)) = r⁻¹ := by rw [o.oangle_add_left_smul_rotation_pi_div_two h, Real.Angle.tan_coe, Real.tan_arctan] #align orientation.tan_oangle_add_left_smul_rotation_pi_div_two Orientation.tan_oangle_add_left_smul_rotation_pi_div_two /-- An angle in a right-angled triangle expressed using `arctan`, where one side is a multiple of a rotation of another by `π / 2`, version subtracting vectors. -/ theorem oangle_sub_right_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) : o.oangle (r • o.rotation (π / 2 : ℝ) x) (r • o.rotation (π / 2 : ℝ) x - x) = Real.arctan r⁻¹ := by by_cases hr : r = 0; · simp [hr] have hx : -x = r⁻¹ • o.rotation (π / 2 : ℝ) (r • o.rotation (π / 2 : ℝ) x) := by simp [hr, ← Real.Angle.coe_add] rw [sub_eq_add_neg, hx, o.oangle_add_right_smul_rotation_pi_div_two] simpa [hr] using h #align orientation.oangle_sub_right_smul_rotation_pi_div_two Orientation.oangle_sub_right_smul_rotation_pi_div_two /-- An angle in a right-angled triangle expressed using `arctan`, where one side is a multiple of a rotation of another by `π / 2`, version subtracting vectors. -/ theorem oangle_sub_left_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) : o.oangle (x - r • o.rotation (π / 2 : ℝ) x) x = Real.arctan r := by by_cases hr : r = 0; · simp [hr] have hx : x = r⁻¹ • o.rotation (π / 2 : ℝ) (-(r • o.rotation (π / 2 : ℝ) x)) := by simp [hr, ← Real.Angle.coe_add] rw [sub_eq_add_neg, add_comm] nth_rw 3 [hx] nth_rw 2 [hx] rw [o.oangle_add_left_smul_rotation_pi_div_two, inv_inv] simpa [hr] using h #align orientation.oangle_sub_left_smul_rotation_pi_div_two Orientation.oangle_sub_left_smul_rotation_pi_div_two end Orientation namespace EuclideanGeometry open FiniteDimensional variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] [hd2 : Fact (finrank ℝ V = 2)] [Module.Oriented ℝ V (Fin 2)] /-- An angle in a right-angled triangle expressed using `arccos`. -/ theorem oangle_right_eq_arccos_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : ∡ p₂ p₃ p₁ = Real.arccos (dist p₃ p₂ / dist p₁ p₃) := by have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, angle_eq_arccos_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)] #align euclidean_geometry.oangle_right_eq_arccos_of_oangle_eq_pi_div_two EuclideanGeometry.oangle_right_eq_arccos_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arccos`. -/ theorem oangle_left_eq_arccos_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : ∡ p₃ p₁ p₂ = Real.arccos (dist p₁ p₂ / dist p₁ p₃) := by have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, angle_eq_arccos_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h), dist_comm p₁ p₃] #align euclidean_geometry.oangle_left_eq_arccos_of_oangle_eq_pi_div_two EuclideanGeometry.oangle_left_eq_arccos_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arcsin`. -/ theorem oangle_right_eq_arcsin_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : ∡ p₂ p₃ p₁ = Real.arcsin (dist p₁ p₂ / dist p₁ p₃) := by have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, angle_eq_arcsin_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h) (Or.inl (left_ne_of_oangle_eq_pi_div_two h))] #align euclidean_geometry.oangle_right_eq_arcsin_of_oangle_eq_pi_div_two EuclideanGeometry.oangle_right_eq_arcsin_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arcsin`. -/ theorem oangle_left_eq_arcsin_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : ∡ p₃ p₁ p₂ = Real.arcsin (dist p₃ p₂ / dist p₁ p₃) := by have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, angle_eq_arcsin_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h) (Or.inr (left_ne_of_oangle_eq_pi_div_two h)), dist_comm p₁ p₃] #align euclidean_geometry.oangle_left_eq_arcsin_of_oangle_eq_pi_div_two EuclideanGeometry.oangle_left_eq_arcsin_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arctan`. -/ theorem oangle_right_eq_arctan_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : ∡ p₂ p₃ p₁ = Real.arctan (dist p₁ p₂ / dist p₃ p₂) := by have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, angle_eq_arctan_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h) (right_ne_of_oangle_eq_pi_div_two h)] #align euclidean_geometry.oangle_right_eq_arctan_of_oangle_eq_pi_div_two EuclideanGeometry.oangle_right_eq_arctan_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arctan`. -/ theorem oangle_left_eq_arctan_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : ∡ p₃ p₁ p₂ = Real.arctan (dist p₃ p₂ / dist p₁ p₂) := by have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, angle_eq_arctan_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h) (left_ne_of_oangle_eq_pi_div_two h)] #align euclidean_geometry.oangle_left_eq_arctan_of_oangle_eq_pi_div_two EuclideanGeometry.oangle_left_eq_arctan_of_oangle_eq_pi_div_two /-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/ theorem cos_oangle_right_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.cos (∡ p₂ p₃ p₁) = dist p₃ p₂ / dist p₁ p₃ := by have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe, cos_angle_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)] #align euclidean_geometry.cos_oangle_right_of_oangle_eq_pi_div_two EuclideanGeometry.cos_oangle_right_of_oangle_eq_pi_div_two /-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/ theorem cos_oangle_left_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.cos (∡ p₃ p₁ p₂) = dist p₁ p₂ / dist p₁ p₃ := by have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, Real.Angle.cos_coe, cos_angle_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h), dist_comm p₁ p₃] #align euclidean_geometry.cos_oangle_left_of_oangle_eq_pi_div_two EuclideanGeometry.cos_oangle_left_of_oangle_eq_pi_div_two /-- The sine of an angle in a right-angled triangle as a ratio of sides. -/ theorem sin_oangle_right_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.sin (∡ p₂ p₃ p₁) = dist p₁ p₂ / dist p₁ p₃ := by have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe, sin_angle_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h) (Or.inl (left_ne_of_oangle_eq_pi_div_two h))] #align euclidean_geometry.sin_oangle_right_of_oangle_eq_pi_div_two EuclideanGeometry.sin_oangle_right_of_oangle_eq_pi_div_two /-- The sine of an angle in a right-angled triangle as a ratio of sides. -/ theorem sin_oangle_left_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.sin (∡ p₃ p₁ p₂) = dist p₃ p₂ / dist p₁ p₃ := by have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, Real.Angle.sin_coe, sin_angle_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h) (Or.inr (left_ne_of_oangle_eq_pi_div_two h)), dist_comm p₁ p₃] #align euclidean_geometry.sin_oangle_left_of_oangle_eq_pi_div_two EuclideanGeometry.sin_oangle_left_of_oangle_eq_pi_div_two /-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/ theorem tan_oangle_right_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.tan (∡ p₂ p₃ p₁) = dist p₁ p₂ / dist p₃ p₂ := by have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe, tan_angle_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)] #align euclidean_geometry.tan_oangle_right_of_oangle_eq_pi_div_two EuclideanGeometry.tan_oangle_right_of_oangle_eq_pi_div_two /-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/ theorem tan_oangle_left_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.tan (∡ p₃ p₁ p₂) = dist p₃ p₂ / dist p₁ p₂ := by have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, Real.Angle.tan_coe, tan_angle_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h)] #align euclidean_geometry.tan_oangle_left_of_oangle_eq_pi_div_two EuclideanGeometry.tan_oangle_left_of_oangle_eq_pi_div_two /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side. -/ theorem cos_oangle_right_mul_dist_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.cos (∡ p₂ p₃ p₁) * dist p₁ p₃ = dist p₃ p₂ := by have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe, cos_angle_mul_dist_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)] #align euclidean_geometry.cos_oangle_right_mul_dist_of_oangle_eq_pi_div_two EuclideanGeometry.cos_oangle_right_mul_dist_of_oangle_eq_pi_div_two /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side. -/ theorem cos_oangle_left_mul_dist_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.cos (∡ p₃ p₁ p₂) * dist p₁ p₃ = dist p₁ p₂ := by have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm, Real.Angle.cos_coe, dist_comm p₁ p₃, cos_angle_mul_dist_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h)] #align euclidean_geometry.cos_oangle_left_mul_dist_of_oangle_eq_pi_div_two EuclideanGeometry.cos_oangle_left_mul_dist_of_oangle_eq_pi_div_two /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side. -/
Mathlib/Geometry/Euclidean/Angle/Oriented/RightAngle.lean
709
713
theorem sin_oangle_right_mul_dist_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : Real.Angle.sin (∡ p₂ p₃ p₁) * dist p₁ p₃ = dist p₁ p₂ := by
have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two] rw [oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe, sin_angle_mul_dist_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)]
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.CharP.Pi import Mathlib.Algebra.CharP.Quotient import Mathlib.Algebra.CharP.Subring import Mathlib.Algebra.Ring.Pi import Mathlib.Analysis.SpecialFunctions.Pow.NNReal import Mathlib.FieldTheory.Perfect import Mathlib.RingTheory.Localization.FractionRing import Mathlib.Algebra.Ring.Subring.Basic import Mathlib.RingTheory.Valuation.Integers #align_import ring_theory.perfection from "leanprover-community/mathlib"@"0b9eaaa7686280fad8cce467f5c3c57ee6ce77f8" /-! # Ring Perfection and Tilt In this file we define the perfection of a ring of characteristic p, and the tilt of a field given a valuation to `ℝ≥0`. ## TODO Define the valuation on the tilt, and define a characteristic predicate for the tilt. -/ universe u₁ u₂ u₃ u₄ open scoped NNReal /-- The perfection of a monoid `M`, defined to be the projective limit of `M` using the `p`-th power maps `M → M` indexed by the natural numbers, implemented as `{ f : ℕ → M | ∀ n, f (n + 1) ^ p = f n }`. -/ def Monoid.perfection (M : Type u₁) [CommMonoid M] (p : ℕ) : Submonoid (ℕ → M) where carrier := { f | ∀ n, f (n + 1) ^ p = f n } one_mem' _ := one_pow _ mul_mem' hf hg n := (mul_pow _ _ _).trans <| congr_arg₂ _ (hf n) (hg n) #align monoid.perfection Monoid.perfection /-- The perfection of a ring `R` with characteristic `p`, as a subsemiring, defined to be the projective limit of `R` using the Frobenius maps `R → R` indexed by the natural numbers, implemented as `{ f : ℕ → R | ∀ n, f (n + 1) ^ p = f n }`. -/ def Ring.perfectionSubsemiring (R : Type u₁) [CommSemiring R] (p : ℕ) [hp : Fact p.Prime] [CharP R p] : Subsemiring (ℕ → R) := { Monoid.perfection R p with zero_mem' := fun _ ↦ zero_pow hp.1.ne_zero add_mem' := fun hf hg n => (frobenius_add R p _ _).trans <| congr_arg₂ _ (hf n) (hg n) } #align ring.perfection_subsemiring Ring.perfectionSubsemiring /-- The perfection of a ring `R` with characteristic `p`, as a subring, defined to be the projective limit of `R` using the Frobenius maps `R → R` indexed by the natural numbers, implemented as `{ f : ℕ → R | ∀ n, f (n + 1) ^ p = f n }`. -/ def Ring.perfectionSubring (R : Type u₁) [CommRing R] (p : ℕ) [hp : Fact p.Prime] [CharP R p] : Subring (ℕ → R) := (Ring.perfectionSubsemiring R p).toSubring fun n => by simp_rw [← frobenius_def, Pi.neg_apply, Pi.one_apply, RingHom.map_neg, RingHom.map_one] #align ring.perfection_subring Ring.perfectionSubring /-- The perfection of a ring `R` with characteristic `p`, defined to be the projective limit of `R` using the Frobenius maps `R → R` indexed by the natural numbers, implemented as `{f : ℕ → R // ∀ n, f (n + 1) ^ p = f n}`. -/ def Ring.Perfection (R : Type u₁) [CommSemiring R] (p : ℕ) : Type u₁ := { f // ∀ n : ℕ, (f : ℕ → R) (n + 1) ^ p = f n } #align ring.perfection Ring.Perfection namespace Perfection variable (R : Type u₁) [CommSemiring R] (p : ℕ) [hp : Fact p.Prime] [CharP R p] instance commSemiring : CommSemiring (Ring.Perfection R p) := (Ring.perfectionSubsemiring R p).toCommSemiring #align perfection.ring.perfection.comm_semiring Perfection.commSemiring instance charP : CharP (Ring.Perfection R p) p := CharP.subsemiring (ℕ → R) p (Ring.perfectionSubsemiring R p) #align perfection.char_p Perfection.charP instance ring (R : Type u₁) [CommRing R] [CharP R p] : Ring (Ring.Perfection R p) := (Ring.perfectionSubring R p).toRing #align perfection.ring Perfection.ring instance commRing (R : Type u₁) [CommRing R] [CharP R p] : CommRing (Ring.Perfection R p) := (Ring.perfectionSubring R p).toCommRing #align perfection.comm_ring Perfection.commRing instance : Inhabited (Ring.Perfection R p) := ⟨0⟩ /-- The `n`-th coefficient of an element of the perfection. -/ def coeff (n : ℕ) : Ring.Perfection R p →+* R where toFun f := f.1 n map_one' := rfl map_mul' _ _ := rfl map_zero' := rfl map_add' _ _ := rfl #align perfection.coeff Perfection.coeff variable {R p} @[ext] theorem ext {f g : Ring.Perfection R p} (h : ∀ n, coeff R p n f = coeff R p n g) : f = g := Subtype.eq <| funext h #align perfection.ext Perfection.ext variable (R p) /-- The `p`-th root of an element of the perfection. -/ def pthRoot : Ring.Perfection R p →+* Ring.Perfection R p where toFun f := ⟨fun n => coeff R p (n + 1) f, fun _ => f.2 _⟩ map_one' := rfl map_mul' _ _ := rfl map_zero' := rfl map_add' _ _ := rfl #align perfection.pth_root Perfection.pthRoot variable {R p} @[simp] theorem coeff_mk (f : ℕ → R) (hf) (n : ℕ) : coeff R p n ⟨f, hf⟩ = f n := rfl #align perfection.coeff_mk Perfection.coeff_mk theorem coeff_pthRoot (f : Ring.Perfection R p) (n : ℕ) : coeff R p n (pthRoot R p f) = coeff R p (n + 1) f := rfl #align perfection.coeff_pth_root Perfection.coeff_pthRoot theorem coeff_pow_p (f : Ring.Perfection R p) (n : ℕ) : coeff R p (n + 1) (f ^ p) = coeff R p n f := by rw [RingHom.map_pow]; exact f.2 n #align perfection.coeff_pow_p Perfection.coeff_pow_p theorem coeff_pow_p' (f : Ring.Perfection R p) (n : ℕ) : coeff R p (n + 1) f ^ p = coeff R p n f := f.2 n #align perfection.coeff_pow_p' Perfection.coeff_pow_p' theorem coeff_frobenius (f : Ring.Perfection R p) (n : ℕ) : coeff R p (n + 1) (frobenius _ p f) = coeff R p n f := by apply coeff_pow_p f n #align perfection.coeff_frobenius Perfection.coeff_frobenius -- `coeff_pow_p f n` also works but is slow! theorem coeff_iterate_frobenius (f : Ring.Perfection R p) (n m : ℕ) : coeff R p (n + m) ((frobenius _ p)^[m] f) = coeff R p n f := Nat.recOn m rfl fun m ih => by erw [Function.iterate_succ_apply', coeff_frobenius, ih] #align perfection.coeff_iterate_frobenius Perfection.coeff_iterate_frobenius theorem coeff_iterate_frobenius' (f : Ring.Perfection R p) (n m : ℕ) (hmn : m ≤ n) : coeff R p n ((frobenius _ p)^[m] f) = coeff R p (n - m) f := Eq.symm <| (coeff_iterate_frobenius _ _ m).symm.trans <| (tsub_add_cancel_of_le hmn).symm ▸ rfl #align perfection.coeff_iterate_frobenius' Perfection.coeff_iterate_frobenius' theorem pthRoot_frobenius : (pthRoot R p).comp (frobenius _ p) = RingHom.id _ := RingHom.ext fun x => ext fun n => by rw [RingHom.comp_apply, RingHom.id_apply, coeff_pthRoot, coeff_frobenius] #align perfection.pth_root_frobenius Perfection.pthRoot_frobenius theorem frobenius_pthRoot : (frobenius _ p).comp (pthRoot R p) = RingHom.id _ := RingHom.ext fun x => ext fun n => by rw [RingHom.comp_apply, RingHom.id_apply, RingHom.map_frobenius, coeff_pthRoot, ← @RingHom.map_frobenius (Ring.Perfection R p) _ R, coeff_frobenius] #align perfection.frobenius_pth_root Perfection.frobenius_pthRoot theorem coeff_add_ne_zero {f : Ring.Perfection R p} {n : ℕ} (hfn : coeff R p n f ≠ 0) (k : ℕ) : coeff R p (n + k) f ≠ 0 := Nat.recOn k hfn fun k ih h => ih <| by erw [← coeff_pow_p, RingHom.map_pow, h, zero_pow hp.1.ne_zero] #align perfection.coeff_add_ne_zero Perfection.coeff_add_ne_zero theorem coeff_ne_zero_of_le {f : Ring.Perfection R p} {m n : ℕ} (hfm : coeff R p m f ≠ 0) (hmn : m ≤ n) : coeff R p n f ≠ 0 := let ⟨k, hk⟩ := Nat.exists_eq_add_of_le hmn hk.symm ▸ coeff_add_ne_zero hfm k #align perfection.coeff_ne_zero_of_le Perfection.coeff_ne_zero_of_le variable (R p) instance perfectRing : PerfectRing (Ring.Perfection R p) p where bijective_frobenius := Function.bijective_iff_has_inverse.mpr ⟨pthRoot R p, DFunLike.congr_fun <| @frobenius_pthRoot R _ p _ _, DFunLike.congr_fun <| @pthRoot_frobenius R _ p _ _⟩ #align perfection.perfect_ring Perfection.perfectRing /-- Given rings `R` and `S` of characteristic `p`, with `R` being perfect, any homomorphism `R →+* S` can be lifted to a homomorphism `R →+* Perfection S p`. -/ @[simps] noncomputable def lift (R : Type u₁) [CommSemiring R] [CharP R p] [PerfectRing R p] (S : Type u₂) [CommSemiring S] [CharP S p] : (R →+* S) ≃ (R →+* Ring.Perfection S p) where toFun f := { toFun := fun r => ⟨fun n => f (((frobeniusEquiv R p).symm : R →+* R)^[n] r), fun n => by erw [← f.map_pow, Function.iterate_succ_apply', frobeniusEquiv_symm_pow_p]⟩ map_one' := ext fun n => (congr_arg f <| iterate_map_one _ _).trans f.map_one map_mul' := fun x y => ext fun n => (congr_arg f <| iterate_map_mul _ _ _ _).trans <| f.map_mul _ _ map_zero' := ext fun n => (congr_arg f <| iterate_map_zero _ _).trans f.map_zero map_add' := fun x y => ext fun n => (congr_arg f <| iterate_map_add _ _ _ _).trans <| f.map_add _ _ } invFun := RingHom.comp <| coeff S p 0 left_inv f := RingHom.ext fun r => rfl right_inv f := RingHom.ext fun r => ext fun n => show coeff S p 0 (f (((frobeniusEquiv R p).symm)^[n] r)) = coeff S p n (f r) by rw [← coeff_iterate_frobenius _ 0 n, zero_add, ← RingHom.map_iterate_frobenius, Function.RightInverse.iterate (frobenius_apply_frobeniusEquiv_symm R p) n] theorem hom_ext {R : Type u₁} [CommSemiring R] [CharP R p] [PerfectRing R p] {S : Type u₂} [CommSemiring S] [CharP S p] {f g : R →+* Ring.Perfection S p} (hfg : ∀ x, coeff S p 0 (f x) = coeff S p 0 (g x)) : f = g := (lift p R S).symm.injective <| RingHom.ext hfg #align perfection.hom_ext Perfection.hom_ext variable {R} {S : Type u₂} [CommSemiring S] [CharP S p] /-- A ring homomorphism `R →+* S` induces `Perfection R p →+* Perfection S p`. -/ @[simps] def map (φ : R →+* S) : Ring.Perfection R p →+* Ring.Perfection S p where toFun f := ⟨fun n => φ (coeff R p n f), fun n => by rw [← φ.map_pow, coeff_pow_p']⟩ map_one' := Subtype.eq <| funext fun _ => φ.map_one map_mul' f g := Subtype.eq <| funext fun n => φ.map_mul _ _ map_zero' := Subtype.eq <| funext fun _ => φ.map_zero map_add' f g := Subtype.eq <| funext fun n => φ.map_add _ _ #align perfection.map Perfection.map theorem coeff_map (φ : R →+* S) (f : Ring.Perfection R p) (n : ℕ) : coeff S p n (map p φ f) = φ (coeff R p n f) := rfl #align perfection.coeff_map Perfection.coeff_map end Perfection /-- A perfection map to a ring of characteristic `p` is a map that is isomorphic to its perfection. -/ -- @[nolint has_nonempty_instance] -- Porting note(#5171): This linter does not exist yet. structure PerfectionMap (p : ℕ) [Fact p.Prime] {R : Type u₁} [CommSemiring R] [CharP R p] {P : Type u₂} [CommSemiring P] [CharP P p] [PerfectRing P p] (π : P →+* R) : Prop where injective : ∀ ⦃x y : P⦄, (∀ n, π (((frobeniusEquiv P p).symm)^[n] x) = π (((frobeniusEquiv P p).symm)^[n] y)) → x = y surjective : ∀ f : ℕ → R, (∀ n, f (n + 1) ^ p = f n) → ∃ x : P, ∀ n, π (((frobeniusEquiv P p).symm)^[n] x) = f n #align perfection_map PerfectionMap namespace PerfectionMap variable {p : ℕ} [Fact p.Prime] variable {R : Type u₁} [CommSemiring R] [CharP R p] variable {P : Type u₃} [CommSemiring P] [CharP P p] [PerfectRing P p] /-- Create a `PerfectionMap` from an isomorphism to the perfection. -/ @[simps] theorem mk' {f : P →+* R} (g : P ≃+* Ring.Perfection R p) (hfg : Perfection.lift p P R f = g) : PerfectionMap p f := { injective := fun x y hxy => g.injective <| (RingHom.ext_iff.1 hfg x).symm.trans <| Eq.symm <| (RingHom.ext_iff.1 hfg y).symm.trans <| Perfection.ext fun n => (hxy n).symm surjective := fun y hy => let ⟨x, hx⟩ := g.surjective ⟨y, hy⟩ ⟨x, fun n => show Perfection.coeff R p n (Perfection.lift p P R f x) = Perfection.coeff R p n ⟨y, hy⟩ by simp [hfg, hx]⟩ } #align perfection_map.mk' PerfectionMap.mk' variable (p R P) /-- The canonical perfection map from the perfection of a ring. -/ theorem of : PerfectionMap p (Perfection.coeff R p 0) := mk' (RingEquiv.refl _) <| (Equiv.apply_eq_iff_eq_symm_apply _).2 rfl #align perfection_map.of PerfectionMap.of /-- For a perfect ring, it itself is the perfection. -/ theorem id [PerfectRing R p] : PerfectionMap p (RingHom.id R) := { injective := fun x y hxy => hxy 0 surjective := fun f hf => ⟨f 0, fun n => show ((frobeniusEquiv R p).symm)^[n] (f 0) = f n from Nat.recOn n rfl fun n ih => injective_pow_p R p <| by rw [Function.iterate_succ_apply', frobeniusEquiv_symm_pow_p, ih, hf]⟩ } #align perfection_map.id PerfectionMap.id variable {p R P} /-- A perfection map induces an isomorphism to the perfection. -/ noncomputable def equiv {π : P →+* R} (m : PerfectionMap p π) : P ≃+* Ring.Perfection R p := RingEquiv.ofBijective (Perfection.lift p P R π) ⟨fun _ _ hxy => m.injective fun n => (congr_arg (Perfection.coeff R p n) hxy : _), fun f => let ⟨x, hx⟩ := m.surjective f.1 f.2 ⟨x, Perfection.ext <| hx⟩⟩ #align perfection_map.equiv PerfectionMap.equiv theorem equiv_apply {π : P →+* R} (m : PerfectionMap p π) (x : P) : m.equiv x = Perfection.lift p P R π x := rfl #align perfection_map.equiv_apply PerfectionMap.equiv_apply theorem comp_equiv {π : P →+* R} (m : PerfectionMap p π) (x : P) : Perfection.coeff R p 0 (m.equiv x) = π x := rfl #align perfection_map.comp_equiv PerfectionMap.comp_equiv theorem comp_equiv' {π : P →+* R} (m : PerfectionMap p π) : (Perfection.coeff R p 0).comp ↑m.equiv = π := RingHom.ext fun _ => rfl #align perfection_map.comp_equiv' PerfectionMap.comp_equiv' theorem comp_symm_equiv {π : P →+* R} (m : PerfectionMap p π) (f : Ring.Perfection R p) : π (m.equiv.symm f) = Perfection.coeff R p 0 f := (m.comp_equiv _).symm.trans <| congr_arg _ <| m.equiv.apply_symm_apply f #align perfection_map.comp_symm_equiv PerfectionMap.comp_symm_equiv theorem comp_symm_equiv' {π : P →+* R} (m : PerfectionMap p π) : π.comp ↑m.equiv.symm = Perfection.coeff R p 0 := RingHom.ext m.comp_symm_equiv #align perfection_map.comp_symm_equiv' PerfectionMap.comp_symm_equiv' variable (p R P) /-- Given rings `R` and `S` of characteristic `p`, with `R` being perfect, any homomorphism `R →+* S` can be lifted to a homomorphism `R →+* P`, where `P` is any perfection of `S`. -/ @[simps] noncomputable def lift [PerfectRing R p] (S : Type u₂) [CommSemiring S] [CharP S p] (P : Type u₃) [CommSemiring P] [CharP P p] [PerfectRing P p] (π : P →+* S) (m : PerfectionMap p π) : (R →+* S) ≃ (R →+* P) where toFun f := RingHom.comp ↑m.equiv.symm <| Perfection.lift p R S f invFun f := π.comp f left_inv f := by simp_rw [← RingHom.comp_assoc, comp_symm_equiv'] exact (Perfection.lift p R S).symm_apply_apply f right_inv f := by exact RingHom.ext fun x => m.equiv.injective <| (m.equiv.apply_symm_apply _).trans <| show Perfection.lift p R S (π.comp f) x = RingHom.comp (↑m.equiv) f x from RingHom.ext_iff.1 (by rw [Equiv.apply_eq_iff_eq_symm_apply]; rfl) _ #align perfection_map.lift PerfectionMap.lift variable {R p} theorem hom_ext [PerfectRing R p] {S : Type u₂} [CommSemiring S] [CharP S p] {P : Type u₃} [CommSemiring P] [CharP P p] [PerfectRing P p] (π : P →+* S) (m : PerfectionMap p π) {f g : R →+* P} (hfg : ∀ x, π (f x) = π (g x)) : f = g := (lift p R S P π m).symm.injective <| RingHom.ext hfg #align perfection_map.hom_ext PerfectionMap.hom_ext variable {P} (p) variable {S : Type u₂} [CommSemiring S] [CharP S p] variable {Q : Type u₄} [CommSemiring Q] [CharP Q p] [PerfectRing Q p] /-- A ring homomorphism `R →+* S` induces `P →+* Q`, a map of the respective perfections. -/ @[nolint unusedArguments] noncomputable def map {π : P →+* R} (_ : PerfectionMap p π) {σ : Q →+* S} (n : PerfectionMap p σ) (φ : R →+* S) : P →+* Q := lift p P S Q σ n <| φ.comp π #align perfection_map.map PerfectionMap.map theorem comp_map {π : P →+* R} (m : PerfectionMap p π) {σ : Q →+* S} (n : PerfectionMap p σ) (φ : R →+* S) : σ.comp (map p m n φ) = φ.comp π := (lift p P S Q σ n).symm_apply_apply _ #align perfection_map.comp_map PerfectionMap.comp_map theorem map_map {π : P →+* R} (m : PerfectionMap p π) {σ : Q →+* S} (n : PerfectionMap p σ) (φ : R →+* S) (x : P) : σ (map p m n φ x) = φ (π x) := RingHom.ext_iff.1 (comp_map p m n φ) x #align perfection_map.map_map PerfectionMap.map_map theorem map_eq_map (φ : R →+* S) : map p (of p R) (of p S) φ = Perfection.map p φ := hom_ext _ (of p S) fun f => by rw [map_map, Perfection.coeff_map] #align perfection_map.map_eq_map PerfectionMap.map_eq_map end PerfectionMap section Perfectoid variable (K : Type u₁) [Field K] (v : Valuation K ℝ≥0) variable (O : Type u₂) [CommRing O] [Algebra O K] (hv : v.Integers O) variable (p : ℕ) -- Porting note: Specified all arguments explicitly /-- `O/(p)` for `O`, ring of integers of `K`. -/ @[nolint unusedArguments] -- Porting note(#5171): removed `nolint has_nonempty_instance` def ModP (K : Type u₁) [Field K] (v : Valuation K ℝ≥0) (O : Type u₂) [CommRing O] [Algebra O K] (_ : v.Integers O) (p : ℕ) := O ⧸ (Ideal.span {(p : O)} : Ideal O) #align mod_p ModP variable [hp : Fact p.Prime] [hvp : Fact (v p ≠ 1)] namespace ModP instance commRing : CommRing (ModP K v O hv p) := Ideal.Quotient.commRing (Ideal.span {(p : O)} : Ideal O) instance charP : CharP (ModP K v O hv p) p := CharP.quotient O p <| mt hv.one_of_isUnit <| (map_natCast (algebraMap O K) p).symm ▸ hvp.1 instance : Nontrivial (ModP K v O hv p) := CharP.nontrivial_of_char_ne_one hp.1.ne_one section Classical attribute [local instance] Classical.dec /-- For a field `K` with valuation `v : K → ℝ≥0` and ring of integers `O`, a function `O/(p) → ℝ≥0` that sends `0` to `0` and `x + (p)` to `v(x)` as long as `x ∉ (p)`. -/ noncomputable def preVal (x : ModP K v O hv p) : ℝ≥0 := if x = 0 then 0 else v (algebraMap O K x.out') #align mod_p.pre_val ModP.preVal variable {K v O hv p}
Mathlib/RingTheory/Perfection.lean
406
413
theorem preVal_mk {x : O} (hx : (Ideal.Quotient.mk _ x : ModP K v O hv p) ≠ 0) : preVal K v O hv p (Ideal.Quotient.mk _ x) = v (algebraMap O K x) := by
obtain ⟨r, hr⟩ : ∃ (a : O), a * (p : O) = (Quotient.mk'' x).out' - x := Ideal.mem_span_singleton'.1 <| Ideal.Quotient.eq.1 <| Quotient.sound' <| Quotient.mk_out' _ refine (if_neg hx).trans (v.map_eq_of_sub_lt <| lt_of_not_le ?_) erw [← RingHom.map_sub, ← hr, hv.le_iff_dvd] exact fun hprx => hx (Ideal.Quotient.eq_zero_iff_mem.2 <| Ideal.mem_span_singleton.2 <| dvd_of_mul_left_dvd hprx)
/- 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} 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 _ #align measure_theory.adapted.is_stopping_time_crossing MeasureTheory.Adapted.isStoppingTime_crossing theorem Adapted.isStoppingTime_upperCrossingTime (hf : Adapted ℱ f) : IsStoppingTime ℱ (upperCrossingTime a b f N n) := hf.isStoppingTime_crossing.1 #align measure_theory.adapted.is_stopping_time_upper_crossing_time MeasureTheory.Adapted.isStoppingTime_upperCrossingTime theorem Adapted.isStoppingTime_lowerCrossingTime (hf : Adapted ℱ f) : IsStoppingTime ℱ (lowerCrossingTime a b f N n) := hf.isStoppingTime_crossing.2 #align measure_theory.adapted.is_stopping_time_lower_crossing_time MeasureTheory.Adapted.isStoppingTime_lowerCrossingTime /-- `upcrossingStrat a b f N n` is 1 if `n` is between a consecutive pair of lower and upper crossings and is 0 otherwise. `upcrossingStrat` is shifted by one index so that it is adapted rather than predictable. -/ noncomputable def upcrossingStrat (a b : ℝ) (f : ℕ → Ω → ℝ) (N n : ℕ) (ω : Ω) : ℝ := ∑ k ∈ Finset.range N, (Set.Ico (lowerCrossingTime a b f N k ω) (upperCrossingTime a b f N (k + 1) ω)).indicator 1 n #align measure_theory.upcrossing_strat MeasureTheory.upcrossingStrat theorem upcrossingStrat_nonneg : 0 ≤ upcrossingStrat a b f N n ω := Finset.sum_nonneg fun _ _ => Set.indicator_nonneg (fun _ _ => zero_le_one) _ #align measure_theory.upcrossing_strat_nonneg MeasureTheory.upcrossingStrat_nonneg theorem upcrossingStrat_le_one : upcrossingStrat a b f N n ω ≤ 1 := by rw [upcrossingStrat, ← Finset.indicator_biUnion_apply] · exact Set.indicator_le_self' (fun _ _ => zero_le_one) _ intro i _ j _ hij simp only [Set.Ico_disjoint_Ico] obtain hij' | hij' := lt_or_gt_of_ne hij · rw [min_eq_left (upperCrossingTime_mono (Nat.succ_le_succ hij'.le) : upperCrossingTime a b f N _ ω ≤ upperCrossingTime a b f N _ ω), max_eq_right (lowerCrossingTime_mono hij'.le : lowerCrossingTime a b f N _ _ ≤ lowerCrossingTime _ _ _ _ _ _)] refine le_trans upperCrossingTime_le_lowerCrossingTime (lowerCrossingTime_mono (Nat.succ_le_of_lt hij')) · rw [gt_iff_lt] at hij' rw [min_eq_right (upperCrossingTime_mono (Nat.succ_le_succ hij'.le) : upperCrossingTime a b f N _ ω ≤ upperCrossingTime a b f N _ ω), max_eq_left (lowerCrossingTime_mono hij'.le : lowerCrossingTime a b f N _ _ ≤ lowerCrossingTime _ _ _ _ _ _)] refine le_trans upperCrossingTime_le_lowerCrossingTime (lowerCrossingTime_mono (Nat.succ_le_of_lt hij')) #align measure_theory.upcrossing_strat_le_one MeasureTheory.upcrossingStrat_le_one theorem Adapted.upcrossingStrat_adapted (hf : Adapted ℱ f) : Adapted ℱ (upcrossingStrat a b f N) := by intro n change StronglyMeasurable[ℱ n] fun ω => ∑ k ∈ Finset.range N, ({n | lowerCrossingTime a b f N k ω ≤ n} ∩ {n | n < upperCrossingTime a b f N (k + 1) ω}).indicator 1 n refine Finset.stronglyMeasurable_sum _ fun i _ => stronglyMeasurable_const.indicator ((hf.isStoppingTime_lowerCrossingTime n).inter ?_) simp_rw [← not_le] exact (hf.isStoppingTime_upperCrossingTime n).compl #align measure_theory.adapted.upcrossing_strat_adapted MeasureTheory.Adapted.upcrossingStrat_adapted theorem Submartingale.sum_upcrossingStrat_mul [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (a b : ℝ) (N : ℕ) : Submartingale (fun n : ℕ => ∑ k ∈ Finset.range n, upcrossingStrat a b f N k * (f (k + 1) - f k)) ℱ μ := hf.sum_mul_sub hf.adapted.upcrossingStrat_adapted (fun _ _ => upcrossingStrat_le_one) fun _ _ => upcrossingStrat_nonneg #align measure_theory.submartingale.sum_upcrossing_strat_mul MeasureTheory.Submartingale.sum_upcrossingStrat_mul theorem Submartingale.sum_sub_upcrossingStrat_mul [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (a b : ℝ) (N : ℕ) : Submartingale (fun n : ℕ => ∑ k ∈ Finset.range n, (1 - upcrossingStrat a b f N k) * (f (k + 1) - f k)) ℱ μ := by refine hf.sum_mul_sub (fun n => (adapted_const ℱ 1 n).sub (hf.adapted.upcrossingStrat_adapted n)) (?_ : ∀ n ω, (1 - upcrossingStrat a b f N n) ω ≤ 1) ?_ · exact fun n ω => sub_le_self _ upcrossingStrat_nonneg · intro n ω simp [upcrossingStrat_le_one] #align measure_theory.submartingale.sum_sub_upcrossing_strat_mul MeasureTheory.Submartingale.sum_sub_upcrossingStrat_mul theorem Submartingale.sum_mul_upcrossingStrat_le [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) : μ[∑ k ∈ Finset.range n, upcrossingStrat a b f N k * (f (k + 1) - f k)] ≤ μ[f n] - μ[f 0] := by have h₁ : (0 : ℝ) ≤ μ[∑ k ∈ Finset.range n, (1 - upcrossingStrat a b f N k) * (f (k + 1) - f k)] := by have := (hf.sum_sub_upcrossingStrat_mul a b N).setIntegral_le (zero_le n) MeasurableSet.univ rw [integral_univ, integral_univ] at this refine le_trans ?_ this simp only [Finset.range_zero, Finset.sum_empty, integral_zero', le_refl] have h₂ : μ[∑ k ∈ Finset.range n, (1 - upcrossingStrat a b f N k) * (f (k + 1) - f k)] = μ[∑ k ∈ Finset.range n, (f (k + 1) - f k)] - μ[∑ k ∈ Finset.range n, upcrossingStrat a b f N k * (f (k + 1) - f k)] := by simp only [sub_mul, one_mul, Finset.sum_sub_distrib, Pi.sub_apply, Finset.sum_apply, Pi.mul_apply] refine integral_sub (Integrable.sub (integrable_finset_sum _ fun i _ => hf.integrable _) (integrable_finset_sum _ fun i _ => hf.integrable _)) ?_ convert (hf.sum_upcrossingStrat_mul a b N).integrable n using 1 ext; simp rw [h₂, sub_nonneg] at h₁ refine le_trans h₁ ?_ simp_rw [Finset.sum_range_sub, integral_sub' (hf.integrable _) (hf.integrable _), le_refl] #align measure_theory.submartingale.sum_mul_upcrossing_strat_le MeasureTheory.Submartingale.sum_mul_upcrossingStrat_le /-- The number of upcrossings (strictly) before time `N`. -/ noncomputable def upcrossingsBefore [Preorder ι] [OrderBot ι] [InfSet ι] (a b : ℝ) (f : ι → Ω → ℝ) (N : ι) (ω : Ω) : ℕ := sSup {n | upperCrossingTime a b f N n ω < N} #align measure_theory.upcrossings_before MeasureTheory.upcrossingsBefore @[simp] theorem upcrossingsBefore_bot [Preorder ι] [OrderBot ι] [InfSet ι] {a b : ℝ} {f : ι → Ω → ℝ} {ω : Ω} : upcrossingsBefore a b f ⊥ ω = ⊥ := by simp [upcrossingsBefore] #align measure_theory.upcrossings_before_bot MeasureTheory.upcrossingsBefore_bot theorem upcrossingsBefore_zero : upcrossingsBefore a b f 0 ω = 0 := by simp [upcrossingsBefore] #align measure_theory.upcrossings_before_zero MeasureTheory.upcrossingsBefore_zero @[simp] theorem upcrossingsBefore_zero' : upcrossingsBefore a b f 0 = 0 := by ext ω; exact upcrossingsBefore_zero #align measure_theory.upcrossings_before_zero' MeasureTheory.upcrossingsBefore_zero' theorem upperCrossingTime_lt_of_le_upcrossingsBefore (hN : 0 < N) (hab : a < b) (hn : n ≤ upcrossingsBefore a b f N ω) : upperCrossingTime a b f N n ω < N := haveI : upperCrossingTime a b f N (upcrossingsBefore a b f N ω) ω < N := (upperCrossingTime_lt_nonempty hN).csSup_mem ((OrderBot.bddBelow _).finite_of_bddAbove (upperCrossingTime_lt_bddAbove hab)) lt_of_le_of_lt (upperCrossingTime_mono hn) this #align measure_theory.upper_crossing_time_lt_of_le_upcrossings_before MeasureTheory.upperCrossingTime_lt_of_le_upcrossingsBefore theorem upperCrossingTime_eq_of_upcrossingsBefore_lt (hab : a < b) (hn : upcrossingsBefore a b f N ω < n) : upperCrossingTime a b f N n ω = N := by refine le_antisymm upperCrossingTime_le (not_lt.1 ?_) convert not_mem_of_csSup_lt hn (upperCrossingTime_lt_bddAbove hab) #align measure_theory.upper_crossing_time_eq_of_upcrossings_before_lt MeasureTheory.upperCrossingTime_eq_of_upcrossingsBefore_lt theorem upcrossingsBefore_le (f : ℕ → Ω → ℝ) (ω : Ω) (hab : a < b) : upcrossingsBefore a b f N ω ≤ N := by by_cases hN : N = 0 · subst hN rw [upcrossingsBefore_zero] · refine csSup_le ⟨0, zero_lt_iff.2 hN⟩ fun n (hn : _ < N) => ?_ by_contra hnN exact hn.ne (upperCrossingTime_eq_of_bound_le hab (not_le.1 hnN).le) #align measure_theory.upcrossings_before_le MeasureTheory.upcrossingsBefore_le theorem crossing_eq_crossing_of_lowerCrossingTime_lt {M : ℕ} (hNM : N ≤ M) (h : lowerCrossingTime a b f N n ω < N) : upperCrossingTime a b f M n ω = upperCrossingTime a b f N n ω ∧ lowerCrossingTime a b f M n ω = lowerCrossingTime a b f N n ω := by have h' : upperCrossingTime a b f N n ω < N := lt_of_le_of_lt upperCrossingTime_le_lowerCrossingTime h induction' n with k ih · simp only [Nat.zero_eq, upperCrossingTime_zero, bot_eq_zero', eq_self_iff_true, lowerCrossingTime_zero, true_and_iff, eq_comm] refine hitting_eq_hitting_of_exists hNM ?_ rw [lowerCrossingTime, hitting_lt_iff] at h · obtain ⟨j, hj₁, hj₂⟩ := h exact ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩ · exact le_rfl · specialize ih (lt_of_le_of_lt (lowerCrossingTime_mono (Nat.le_succ _)) h) (lt_of_le_of_lt (upperCrossingTime_mono (Nat.le_succ _)) h') have : upperCrossingTime a b f M k.succ ω = upperCrossingTime a b f N k.succ ω := by rw [upperCrossingTime_succ_eq, hitting_lt_iff] at h' · simp only [upperCrossingTime_succ_eq] obtain ⟨j, hj₁, hj₂⟩ := h' rw [eq_comm, ih.2] exact hitting_eq_hitting_of_exists hNM ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩ · exact le_rfl refine ⟨this, ?_⟩ simp only [lowerCrossingTime, eq_comm, this, Nat.succ_eq_add_one] refine hitting_eq_hitting_of_exists hNM ?_ rw [lowerCrossingTime, hitting_lt_iff _ le_rfl] at h obtain ⟨j, hj₁, hj₂⟩ := h exact ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩ #align measure_theory.crossing_eq_crossing_of_lower_crossing_time_lt MeasureTheory.crossing_eq_crossing_of_lowerCrossingTime_lt theorem crossing_eq_crossing_of_upperCrossingTime_lt {M : ℕ} (hNM : N ≤ M) (h : upperCrossingTime a b f N (n + 1) ω < N) : upperCrossingTime a b f M (n + 1) ω = upperCrossingTime a b f N (n + 1) ω ∧ lowerCrossingTime a b f M n ω = lowerCrossingTime a b f N n ω := by have := (crossing_eq_crossing_of_lowerCrossingTime_lt hNM (lt_of_le_of_lt lowerCrossingTime_le_upperCrossingTime_succ h)).2 refine ⟨?_, this⟩ rw [upperCrossingTime_succ_eq, upperCrossingTime_succ_eq, eq_comm, this] refine hitting_eq_hitting_of_exists hNM ?_ rw [upperCrossingTime_succ_eq, hitting_lt_iff] at h · obtain ⟨j, hj₁, hj₂⟩ := h exact ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hj₂⟩ · exact le_rfl #align measure_theory.crossing_eq_crossing_of_upper_crossing_time_lt MeasureTheory.crossing_eq_crossing_of_upperCrossingTime_lt theorem upperCrossingTime_eq_upperCrossingTime_of_lt {M : ℕ} (hNM : N ≤ M) (h : upperCrossingTime a b f N n ω < N) : upperCrossingTime a b f M n ω = upperCrossingTime a b f N n ω := by cases n · simp · exact (crossing_eq_crossing_of_upperCrossingTime_lt hNM h).1 #align measure_theory.upper_crossing_time_eq_upper_crossing_time_of_lt MeasureTheory.upperCrossingTime_eq_upperCrossingTime_of_lt theorem upcrossingsBefore_mono (hab : a < b) : Monotone fun N ω => upcrossingsBefore a b f N ω := by intro N M hNM ω simp only [upcrossingsBefore] by_cases hemp : {n : ℕ | upperCrossingTime a b f N n ω < N}.Nonempty · refine csSup_le_csSup (upperCrossingTime_lt_bddAbove hab) hemp fun n hn => ?_ rw [Set.mem_setOf_eq, upperCrossingTime_eq_upperCrossingTime_of_lt hNM hn] exact lt_of_lt_of_le hn hNM · rw [Set.not_nonempty_iff_eq_empty] at hemp simp [hemp, csSup_empty, bot_eq_zero', zero_le'] #align measure_theory.upcrossings_before_mono MeasureTheory.upcrossingsBefore_mono theorem upcrossingsBefore_lt_of_exists_upcrossing (hab : a < b) {N₁ N₂ : ℕ} (hN₁ : N ≤ N₁) (hN₁' : f N₁ ω < a) (hN₂ : N₁ ≤ N₂) (hN₂' : b < f N₂ ω) : upcrossingsBefore a b f N ω < upcrossingsBefore a b f (N₂ + 1) ω := by refine lt_of_lt_of_le (Nat.lt_succ_self _) (le_csSup (upperCrossingTime_lt_bddAbove hab) ?_) rw [Set.mem_setOf_eq, upperCrossingTime_succ_eq, hitting_lt_iff _ le_rfl] refine ⟨N₂, ⟨?_, Nat.lt_succ_self _⟩, hN₂'.le⟩ rw [lowerCrossingTime, hitting_le_iff_of_lt _ (Nat.lt_succ_self _)] refine ⟨N₁, ⟨le_trans ?_ hN₁, hN₂⟩, hN₁'.le⟩ by_cases hN : 0 < N · have : upperCrossingTime a b f N (upcrossingsBefore a b f N ω) ω < N := Nat.sSup_mem (upperCrossingTime_lt_nonempty hN) (upperCrossingTime_lt_bddAbove hab) rw [upperCrossingTime_eq_upperCrossingTime_of_lt (hN₁.trans (hN₂.trans <| Nat.le_succ _)) this] exact this.le · rw [not_lt, Nat.le_zero] at hN rw [hN, upcrossingsBefore_zero, upperCrossingTime_zero] rfl #align measure_theory.upcrossings_before_lt_of_exists_upcrossing MeasureTheory.upcrossingsBefore_lt_of_exists_upcrossing theorem lowerCrossingTime_lt_of_lt_upcrossingsBefore (hN : 0 < N) (hab : a < b) (hn : n < upcrossingsBefore a b f N ω) : lowerCrossingTime a b f N n ω < N := lt_of_le_of_lt lowerCrossingTime_le_upperCrossingTime_succ (upperCrossingTime_lt_of_le_upcrossingsBefore hN hab hn) #align measure_theory.lower_crossing_time_lt_of_lt_upcrossings_before MeasureTheory.lowerCrossingTime_lt_of_lt_upcrossingsBefore theorem le_sub_of_le_upcrossingsBefore (hN : 0 < N) (hab : a < b) (hn : n < upcrossingsBefore a b f N ω) : b - a ≤ stoppedValue f (upperCrossingTime a b f N (n + 1)) ω - stoppedValue f (lowerCrossingTime a b f N n) ω := sub_le_sub (stoppedValue_upperCrossingTime (upperCrossingTime_lt_of_le_upcrossingsBefore hN hab hn).ne) (stoppedValue_lowerCrossingTime (lowerCrossingTime_lt_of_lt_upcrossingsBefore hN hab hn).ne) #align measure_theory.le_sub_of_le_upcrossings_before MeasureTheory.le_sub_of_le_upcrossingsBefore theorem sub_eq_zero_of_upcrossingsBefore_lt (hab : a < b) (hn : upcrossingsBefore a b f N ω < n) : stoppedValue f (upperCrossingTime a b f N (n + 1)) ω - stoppedValue f (lowerCrossingTime a b f N n) ω = 0 := by have : N ≤ upperCrossingTime a b f N n ω := by rw [upcrossingsBefore] at hn rw [← not_lt] exact fun h => not_le.2 hn (le_csSup (upperCrossingTime_lt_bddAbove hab) h) simp [stoppedValue, upperCrossingTime_stabilize' (Nat.le_succ n) this, lowerCrossingTime_stabilize' le_rfl (le_trans this upperCrossingTime_le_lowerCrossingTime)] #align measure_theory.sub_eq_zero_of_upcrossings_before_lt MeasureTheory.sub_eq_zero_of_upcrossingsBefore_lt theorem mul_upcrossingsBefore_le (hf : a ≤ f N ω) (hab : a < b) : (b - a) * upcrossingsBefore a b f N ω ≤ ∑ k ∈ Finset.range N, upcrossingStrat a b f N k ω * (f (k + 1) - f k) ω := by classical by_cases hN : N = 0 · simp [hN] simp_rw [upcrossingStrat, Finset.sum_mul, ← Set.indicator_mul_left _ _ (fun x ↦ (f (x + 1) - f x) ω), Pi.one_apply, Pi.sub_apply, one_mul] rw [Finset.sum_comm] have h₁ : ∀ k, ∑ n ∈ Finset.range N, (Set.Ico (lowerCrossingTime a b f N k ω) (upperCrossingTime a b f N (k + 1) ω)).indicator (fun m => f (m + 1) ω - f m ω) n = stoppedValue f (upperCrossingTime a b f N (k + 1)) ω - stoppedValue f (lowerCrossingTime a b f N k) ω := by intro k rw [Finset.sum_indicator_eq_sum_filter, (_ : Finset.filter (fun i => i ∈ Set.Ico (lowerCrossingTime a b f N k ω) (upperCrossingTime a b f N (k + 1) ω)) (Finset.range N) = Finset.Ico (lowerCrossingTime a b f N k ω) (upperCrossingTime a b f N (k + 1) ω)), Finset.sum_Ico_eq_add_neg _ lowerCrossingTime_le_upperCrossingTime_succ, Finset.sum_range_sub fun n => f n ω, Finset.sum_range_sub fun n => f n ω, neg_sub, sub_add_sub_cancel] · rfl · ext i simp only [Set.mem_Ico, Finset.mem_filter, Finset.mem_range, Finset.mem_Ico, and_iff_right_iff_imp, and_imp] exact fun _ h => lt_of_lt_of_le h upperCrossingTime_le simp_rw [h₁] have h₂ : ∑ _k ∈ Finset.range (upcrossingsBefore a b f N ω), (b - a) ≤ ∑ k ∈ Finset.range N, (stoppedValue f (upperCrossingTime a b f N (k + 1)) ω - stoppedValue f (lowerCrossingTime a b f N k) ω) := by calc ∑ _k ∈ Finset.range (upcrossingsBefore a b f N ω), (b - a) ≤ ∑ k ∈ Finset.range (upcrossingsBefore a b f N ω), (stoppedValue f (upperCrossingTime a b f N (k + 1)) ω - stoppedValue f (lowerCrossingTime a b f N k) ω) := by refine Finset.sum_le_sum fun i hi => le_sub_of_le_upcrossingsBefore (zero_lt_iff.2 hN) hab ?_ rwa [Finset.mem_range] at hi _ ≤ ∑ k ∈ Finset.range N, (stoppedValue f (upperCrossingTime a b f N (k + 1)) ω - stoppedValue f (lowerCrossingTime a b f N k) ω) := by refine Finset.sum_le_sum_of_subset_of_nonneg (Finset.range_subset.2 (upcrossingsBefore_le f ω hab)) fun i _ hi => ?_ by_cases hi' : i = upcrossingsBefore a b f N ω · subst hi' simp only [stoppedValue] rw [upperCrossingTime_eq_of_upcrossingsBefore_lt hab (Nat.lt_succ_self _)] by_cases heq : lowerCrossingTime a b f N (upcrossingsBefore a b f N ω) ω = N · rw [heq, sub_self] · rw [sub_nonneg] exact le_trans (stoppedValue_lowerCrossingTime heq) hf · rw [sub_eq_zero_of_upcrossingsBefore_lt hab] rw [Finset.mem_range, not_lt] at hi exact lt_of_le_of_ne hi (Ne.symm hi') refine le_trans ?_ h₂ rw [Finset.sum_const, Finset.card_range, nsmul_eq_mul, mul_comm] #align measure_theory.mul_upcrossings_before_le MeasureTheory.mul_upcrossingsBefore_le theorem integral_mul_upcrossingsBefore_le_integral [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hfN : ∀ ω, a ≤ f N ω) (hfzero : 0 ≤ f 0) (hab : a < b) : (b - a) * μ[upcrossingsBefore a b f N] ≤ μ[f N] := calc (b - a) * μ[upcrossingsBefore a b f N] ≤ μ[∑ k ∈ Finset.range N, upcrossingStrat a b f N k * (f (k + 1) - f k)] := by rw [← integral_mul_left] refine integral_mono_of_nonneg ?_ ((hf.sum_upcrossingStrat_mul a b N).integrable N) ?_ · exact eventually_of_forall fun ω => mul_nonneg (sub_nonneg.2 hab.le) (Nat.cast_nonneg _) · filter_upwards with ω simpa using mul_upcrossingsBefore_le (hfN ω) hab _ ≤ μ[f N] - μ[f 0] := hf.sum_mul_upcrossingStrat_le _ ≤ μ[f N] := (sub_le_self_iff _).2 (integral_nonneg hfzero) #align measure_theory.integral_mul_upcrossings_before_le_integral MeasureTheory.integral_mul_upcrossingsBefore_le_integral theorem crossing_pos_eq (hab : a < b) : upperCrossingTime 0 (b - a) (fun n ω => (f n ω - a)⁺) N n = upperCrossingTime a b f N n ∧ lowerCrossingTime 0 (b - a) (fun n ω => (f n ω - a)⁺) N n = lowerCrossingTime a b f N n := by have hab' : 0 < b - a := sub_pos.2 hab have hf : ∀ ω i, b - a ≤ (f i ω - a)⁺ ↔ b ≤ f i ω := by intro i ω refine ⟨fun h => ?_, fun h => ?_⟩ · rwa [← sub_le_sub_iff_right a, ← posPart_eq_of_posPart_pos (lt_of_lt_of_le hab' h)] · rw [← sub_le_sub_iff_right a] at h rwa [posPart_eq_self.2 (le_trans hab'.le h)] have hf' (ω i) : (f i ω - a)⁺ ≤ 0 ↔ f i ω ≤ a := by rw [posPart_nonpos, sub_nonpos] induction' n with k ih · refine ⟨rfl, ?_⟩ #adaptation_note /-- nightly-2024-03-16: simp was simp (config := { unfoldPartialApp := true }) only [lowerCrossingTime_zero, hitting, Set.mem_Icc, Set.mem_Iic, Nat.zero_eq] -/ simp (config := { unfoldPartialApp := true }) only [lowerCrossingTime_zero, hitting_def, Set.mem_Icc, Set.mem_Iic, Nat.zero_eq] ext ω split_ifs with h₁ h₂ h₂ · simp_rw [hf'] · simp_rw [Set.mem_Iic, ← hf' _ _] at h₂ exact False.elim (h₂ h₁) · simp_rw [Set.mem_Iic, hf' _ _] at h₁ exact False.elim (h₁ h₂) · rfl · have : upperCrossingTime 0 (b - a) (fun n ω => (f n ω - a)⁺) N (k + 1) = upperCrossingTime a b f N (k + 1) := by ext ω simp only [upperCrossingTime_succ_eq, ← ih.2, hitting, Set.mem_Ici, tsub_le_iff_right] split_ifs with h₁ h₂ h₂ · simp_rw [← sub_le_iff_le_add, hf ω] · refine False.elim (h₂ ?_) simp_all only [Set.mem_Ici, not_true_eq_false] · refine False.elim (h₁ ?_) simp_all only [Set.mem_Ici] · rfl refine ⟨this, ?_⟩ ext ω simp only [lowerCrossingTime, this, hitting, Set.mem_Iic] split_ifs with h₁ h₂ h₂ · simp_rw [hf' ω] · refine False.elim (h₂ ?_) simp_all only [Set.mem_Iic, not_true_eq_false] · refine False.elim (h₁ ?_) simp_all only [Set.mem_Iic] · rfl #align measure_theory.crossing_pos_eq MeasureTheory.crossing_pos_eq theorem upcrossingsBefore_pos_eq (hab : a < b) : upcrossingsBefore 0 (b - a) (fun n ω => (f n ω - a)⁺) N ω = upcrossingsBefore a b f N ω := by simp_rw [upcrossingsBefore, (crossing_pos_eq hab).1] #align measure_theory.upcrossings_before_pos_eq MeasureTheory.upcrossingsBefore_pos_eq theorem mul_integral_upcrossingsBefore_le_integral_pos_part_aux [IsFiniteMeasure μ] (hf : Submartingale f ℱ μ) (hab : a < b) : (b - a) * μ[upcrossingsBefore a b f N] ≤ μ[fun ω => (f N ω - a)⁺] := by refine le_trans (le_of_eq ?_) (integral_mul_upcrossingsBefore_le_integral (hf.sub_martingale (martingale_const _ _ _)).pos (fun ω => posPart_nonneg _) (fun ω => posPart_nonneg _) (sub_pos.2 hab)) simp_rw [sub_zero, ← upcrossingsBefore_pos_eq hab] rfl #align measure_theory.mul_integral_upcrossings_before_le_integral_pos_part_aux MeasureTheory.mul_integral_upcrossingsBefore_le_integral_pos_part_aux /-- **Doob's upcrossing estimate**: given a real valued discrete submartingale `f` and real values `a` and `b`, we have `(b - a) * 𝔼[upcrossingsBefore a b f N] ≤ 𝔼[(f N - a)⁺]` where `upcrossingsBefore a b f N` is the number of times the process `f` crossed from below `a` to above `b` before the time `N`. -/ theorem Submartingale.mul_integral_upcrossingsBefore_le_integral_pos_part [IsFiniteMeasure μ] (a b : ℝ) (hf : Submartingale f ℱ μ) (N : ℕ) : (b - a) * μ[upcrossingsBefore a b f N] ≤ μ[fun ω => (f N ω - a)⁺] := by by_cases hab : a < b · exact mul_integral_upcrossingsBefore_le_integral_pos_part_aux hf hab · rw [not_lt, ← sub_nonpos] at hab exact le_trans (mul_nonpos_of_nonpos_of_nonneg hab (by positivity)) (integral_nonneg fun ω => posPart_nonneg _) #align measure_theory.submartingale.mul_integral_upcrossings_before_le_integral_pos_part MeasureTheory.Submartingale.mul_integral_upcrossingsBefore_le_integral_pos_part /-! ### Variant of the upcrossing estimate Now, we would like to prove a variant of the upcrossing estimate obtained by taking the supremum over $N$ of the original upcrossing estimate. Namely, we want the inequality $$ (b - a) \sup_N \mathbb{E}[U_N(a, b)] \le \sup_N \mathbb{E}[f_N]. $$ This inequality is central for the martingale convergence theorem as it provides a uniform bound for the upcrossings. We note that on top of taking the supremum on both sides of the inequality, we had also used the monotone convergence theorem on the left hand side to take the supremum outside of the integral. To do this, we need to make sure $U_N(a, b)$ is measurable and integrable. Integrability is easy to check as $U_N(a, b) ≤ N$ and so it suffices to show measurability. Indeed, by noting that $$ U_N(a, b) = \sum_{i = 1}^N \mathbf{1}_{\{U_N(a, b) < N\}} $$ $U_N(a, b)$ is measurable as $\{U_N(a, b) < N\}$ is a measurable set since $U_N(a, b)$ is a stopping time. -/
Mathlib/Probability/Martingale/Upcrossing.lean
778
801
theorem upcrossingsBefore_eq_sum (hab : a < b) : upcrossingsBefore a b f N ω = ∑ i ∈ Finset.Ico 1 (N + 1), {n | upperCrossingTime a b f N n ω < N}.indicator 1 i := by
by_cases hN : N = 0 · simp [hN] rw [← Finset.sum_Ico_consecutive _ (Nat.succ_le_succ zero_le') (Nat.succ_le_succ (upcrossingsBefore_le f ω hab))] have h₁ : ∀ k ∈ Finset.Ico 1 (upcrossingsBefore a b f N ω + 1), {n : ℕ | upperCrossingTime a b f N n ω < N}.indicator 1 k = 1 := by rintro k hk rw [Finset.mem_Ico] at hk rw [Set.indicator_of_mem] · rfl · exact upperCrossingTime_lt_of_le_upcrossingsBefore (zero_lt_iff.2 hN) hab (Nat.lt_succ_iff.1 hk.2) have h₂ : ∀ k ∈ Finset.Ico (upcrossingsBefore a b f N ω + 1) (N + 1), {n : ℕ | upperCrossingTime a b f N n ω < N}.indicator 1 k = 0 := by rintro k hk rw [Finset.mem_Ico, Nat.succ_le_iff] at hk rw [Set.indicator_of_not_mem] simp only [Set.mem_setOf_eq, not_lt] exact (upperCrossingTime_eq_of_upcrossingsBefore_lt hab hk.1).symm.le rw [Finset.sum_congr rfl h₁, Finset.sum_congr rfl h₂, Finset.sum_const, Finset.sum_const, smul_eq_mul, mul_one, smul_eq_mul, mul_zero, Nat.card_Ico, Nat.add_succ_sub_one, add_zero, add_zero]
/- 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.Geometry.Euclidean.Sphere.Basic import Mathlib.LinearAlgebra.AffineSpace.FiniteDimensional import Mathlib.Tactic.DeriveFintype #align_import geometry.euclidean.circumcenter from "leanprover-community/mathlib"@"2de9c37fa71dde2f1c6feff19876dd6a7b1519f0" /-! # Circumcenter and circumradius This file proves some lemmas on points equidistant from a set of points, and defines the circumradius and circumcenter of a simplex. There are also some definitions for use in calculations where it is convenient to work with affine combinations of vertices together with the circumcenter. ## Main definitions * `circumcenter` and `circumradius` are the circumcenter and circumradius of a simplex. ## References * https://en.wikipedia.org/wiki/Circumscribed_circle -/ noncomputable section open scoped Classical open RealInnerProductSpace namespace EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] open AffineSubspace /-- `p` is equidistant from two points in `s` if and only if its `orthogonalProjection` is. -/ theorem dist_eq_iff_dist_orthogonalProjection_eq {s : AffineSubspace ℝ P} [Nonempty s] [HasOrthogonalProjection s.direction] {p1 p2 : P} (p3 : P) (hp1 : p1 ∈ s) (hp2 : p2 ∈ s) : dist p1 p3 = dist p2 p3 ↔ dist p1 (orthogonalProjection s p3) = dist p2 (orthogonalProjection s p3) := by rw [← mul_self_inj_of_nonneg dist_nonneg dist_nonneg, ← mul_self_inj_of_nonneg dist_nonneg dist_nonneg, dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq p3 hp1, dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq p3 hp2] simp #align euclidean_geometry.dist_eq_iff_dist_orthogonal_projection_eq EuclideanGeometry.dist_eq_iff_dist_orthogonalProjection_eq /-- `p` is equidistant from a set of points in `s` if and only if its `orthogonalProjection` is. -/ theorem dist_set_eq_iff_dist_orthogonalProjection_eq {s : AffineSubspace ℝ P} [Nonempty s] [HasOrthogonalProjection s.direction] {ps : Set P} (hps : ps ⊆ s) (p : P) : (Set.Pairwise ps fun p1 p2 => dist p1 p = dist p2 p) ↔ Set.Pairwise ps fun p1 p2 => dist p1 (orthogonalProjection s p) = dist p2 (orthogonalProjection s p) := ⟨fun h _ hp1 _ hp2 hne => (dist_eq_iff_dist_orthogonalProjection_eq p (hps hp1) (hps hp2)).1 (h hp1 hp2 hne), fun h _ hp1 _ hp2 hne => (dist_eq_iff_dist_orthogonalProjection_eq p (hps hp1) (hps hp2)).2 (h hp1 hp2 hne)⟩ #align euclidean_geometry.dist_set_eq_iff_dist_orthogonal_projection_eq EuclideanGeometry.dist_set_eq_iff_dist_orthogonalProjection_eq /-- There exists `r` such that `p` has distance `r` from all the points of a set of points in `s` if and only if there exists (possibly different) `r` such that its `orthogonalProjection` has that distance from all the points in that set. -/ theorem exists_dist_eq_iff_exists_dist_orthogonalProjection_eq {s : AffineSubspace ℝ P} [Nonempty s] [HasOrthogonalProjection s.direction] {ps : Set P} (hps : ps ⊆ s) (p : P) : (∃ r, ∀ p1 ∈ ps, dist p1 p = r) ↔ ∃ r, ∀ p1 ∈ ps, dist p1 ↑(orthogonalProjection s p) = r := by have h := dist_set_eq_iff_dist_orthogonalProjection_eq hps p simp_rw [Set.pairwise_eq_iff_exists_eq] at h exact h #align euclidean_geometry.exists_dist_eq_iff_exists_dist_orthogonal_projection_eq EuclideanGeometry.exists_dist_eq_iff_exists_dist_orthogonalProjection_eq /-- The induction step for the existence and uniqueness of the circumcenter. Given a nonempty set of points in a nonempty affine subspace whose direction is complete, such that there is a unique (circumcenter, circumradius) pair for those points in that subspace, and a point `p` not in that subspace, there is a unique (circumcenter, circumradius) pair for the set with `p` added, in the span of the subspace with `p` added. -/ theorem existsUnique_dist_eq_of_insert {s : AffineSubspace ℝ P} [HasOrthogonalProjection s.direction] {ps : Set P} (hnps : ps.Nonempty) {p : P} (hps : ps ⊆ s) (hp : p ∉ s) (hu : ∃! cs : Sphere P, cs.center ∈ s ∧ ps ⊆ (cs : Set P)) : ∃! cs₂ : Sphere P, cs₂.center ∈ affineSpan ℝ (insert p (s : Set P)) ∧ insert p ps ⊆ (cs₂ : Set P) := by haveI : Nonempty s := Set.Nonempty.to_subtype (hnps.mono hps) rcases hu with ⟨⟨cc, cr⟩, ⟨hcc, hcr⟩, hcccru⟩ simp only at hcc hcr hcccru let x := dist cc (orthogonalProjection s p) let y := dist p (orthogonalProjection s p) have hy0 : y ≠ 0 := dist_orthogonalProjection_ne_zero_of_not_mem hp let ycc₂ := (x * x + y * y - cr * cr) / (2 * y) let cc₂ := (ycc₂ / y) • (p -ᵥ orthogonalProjection s p : V) +ᵥ cc let cr₂ := √(cr * cr + ycc₂ * ycc₂) use ⟨cc₂, cr₂⟩ simp (config := { zeta := false, proj := false }) only have hpo : p = (1 : ℝ) • (p -ᵥ orthogonalProjection s p : V) +ᵥ (orthogonalProjection s p : P) := by simp constructor · constructor · refine vadd_mem_of_mem_direction ?_ (mem_affineSpan ℝ (Set.mem_insert_of_mem _ hcc)) rw [direction_affineSpan] exact Submodule.smul_mem _ _ (vsub_mem_vectorSpan ℝ (Set.mem_insert _ _) (Set.mem_insert_of_mem _ (orthogonalProjection_mem _))) · intro p1 hp1 rw [Sphere.mem_coe, mem_sphere, ← mul_self_inj_of_nonneg dist_nonneg (Real.sqrt_nonneg _), Real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _))] cases' hp1 with hp1 hp1 · rw [hp1] rw [hpo, dist_sq_smul_orthogonal_vadd_smul_orthogonal_vadd (orthogonalProjection_mem p) hcc _ _ (vsub_orthogonalProjection_mem_direction_orthogonal s p), ← dist_eq_norm_vsub V p, dist_comm _ cc] field_simp [ycc₂, hy0] ring · rw [dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq _ (hps hp1), orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ hcc, Subtype.coe_mk, dist_of_mem_subset_mk_sphere hp1 hcr, dist_eq_norm_vsub V cc₂ cc, vadd_vsub, norm_smul, ← dist_eq_norm_vsub V, Real.norm_eq_abs, abs_div, abs_of_nonneg dist_nonneg, div_mul_cancel₀ _ hy0, abs_mul_abs_self] · rintro ⟨cc₃, cr₃⟩ ⟨hcc₃, hcr₃⟩ simp only at hcc₃ hcr₃ obtain ⟨t₃, cc₃', hcc₃', hcc₃''⟩ : ∃ r : ℝ, ∃ p0 ∈ s, cc₃ = r • (p -ᵥ ↑((orthogonalProjection s) p)) +ᵥ p0 := by rwa [mem_affineSpan_insert_iff (orthogonalProjection_mem p)] at hcc₃ have hcr₃' : ∃ r, ∀ p1 ∈ ps, dist p1 cc₃ = r := ⟨cr₃, fun p1 hp1 => dist_of_mem_subset_mk_sphere (Set.mem_insert_of_mem _ hp1) hcr₃⟩ rw [exists_dist_eq_iff_exists_dist_orthogonalProjection_eq hps cc₃, hcc₃'', orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ hcc₃'] at hcr₃' cases' hcr₃' with cr₃' hcr₃' have hu := hcccru ⟨cc₃', cr₃'⟩ simp only at hu replace hu := hu ⟨hcc₃', hcr₃'⟩ -- Porting note: was -- cases' hu with hucc hucr -- substs hucc hucr cases' hu have hcr₃val : cr₃ = √(cr * cr + t₃ * y * (t₃ * y)) := by cases' hnps with p0 hp0 have h' : ↑(⟨cc, hcc₃'⟩ : s) = cc := rfl rw [← dist_of_mem_subset_mk_sphere (Set.mem_insert_of_mem _ hp0) hcr₃, hcc₃'', ← mul_self_inj_of_nonneg dist_nonneg (Real.sqrt_nonneg _), Real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)), dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq _ (hps hp0), orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ hcc₃', h', dist_of_mem_subset_mk_sphere hp0 hcr, dist_eq_norm_vsub V _ cc, vadd_vsub, norm_smul, ← dist_eq_norm_vsub V p, Real.norm_eq_abs, ← mul_assoc, mul_comm _ |t₃|, ← mul_assoc, abs_mul_abs_self] ring replace hcr₃ := dist_of_mem_subset_mk_sphere (Set.mem_insert _ _) hcr₃ rw [hpo, hcc₃'', hcr₃val, ← mul_self_inj_of_nonneg dist_nonneg (Real.sqrt_nonneg _), dist_sq_smul_orthogonal_vadd_smul_orthogonal_vadd (orthogonalProjection_mem p) hcc₃' _ _ (vsub_orthogonalProjection_mem_direction_orthogonal s p), dist_comm, ← dist_eq_norm_vsub V p, Real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _))] at hcr₃ change x * x + _ * (y * y) = _ at hcr₃ rw [show x * x + (1 - t₃) * (1 - t₃) * (y * y) = x * x + y * y - 2 * y * (t₃ * y) + t₃ * y * (t₃ * y) by ring, add_left_inj] at hcr₃ have ht₃ : t₃ = ycc₂ / y := by field_simp [ycc₂, ← hcr₃, hy0] subst ht₃ change cc₃ = cc₂ at hcc₃'' congr rw [hcr₃val] congr 2 field_simp [hy0] #align euclidean_geometry.exists_unique_dist_eq_of_insert EuclideanGeometry.existsUnique_dist_eq_of_insert /-- Given a finite nonempty affinely independent family of points, there is a unique (circumcenter, circumradius) pair for those points in the affine subspace they span. -/ theorem _root_.AffineIndependent.existsUnique_dist_eq {ι : Type*} [hne : Nonempty ι] [Finite ι] {p : ι → P} (ha : AffineIndependent ℝ p) : ∃! cs : Sphere P, cs.center ∈ affineSpan ℝ (Set.range p) ∧ Set.range p ⊆ (cs : Set P) := by cases nonempty_fintype ι induction' hn : Fintype.card ι with m hm generalizing ι · exfalso have h := Fintype.card_pos_iff.2 hne rw [hn] at h exact lt_irrefl 0 h · cases' m with m · rw [Fintype.card_eq_one_iff] at hn cases' hn with i hi haveI : Unique ι := ⟨⟨i⟩, hi⟩ use ⟨p i, 0⟩ simp only [Set.range_unique, AffineSubspace.mem_affineSpan_singleton] constructor · simp_rw [hi default, Set.singleton_subset_iff] exact ⟨⟨⟩, by simp only [Metric.sphere_zero, Set.mem_singleton_iff]⟩ · rintro ⟨cc, cr⟩ simp only rintro ⟨rfl, hdist⟩ simp? [Set.singleton_subset_iff] at hdist says simp only [Set.singleton_subset_iff, Metric.mem_sphere, dist_self] at hdist rw [hi default, hdist] · have i := hne.some let ι2 := { x // x ≠ i } have hc : Fintype.card ι2 = m + 1 := by rw [Fintype.card_of_subtype (Finset.univ.filter fun x => x ≠ i)] · rw [Finset.filter_not] -- Porting note: removed `simp_rw [eq_comm]` and used `filter_eq'` instead of `filter_eq` rw [Finset.filter_eq' _ i, if_pos (Finset.mem_univ _), Finset.card_sdiff (Finset.subset_univ _), Finset.card_singleton, Finset.card_univ, hn] simp · simp haveI : Nonempty ι2 := Fintype.card_pos_iff.1 (hc.symm ▸ Nat.zero_lt_succ _) have ha2 : AffineIndependent ℝ fun i2 : ι2 => p i2 := ha.subtype _ replace hm := hm ha2 _ hc have hr : Set.range p = insert (p i) (Set.range fun i2 : ι2 => p i2) := by change _ = insert _ (Set.range fun i2 : { x | x ≠ i } => p i2) rw [← Set.image_eq_range, ← Set.image_univ, ← Set.image_insert_eq] congr with j simp [Classical.em] rw [hr, ← affineSpan_insert_affineSpan] refine existsUnique_dist_eq_of_insert (Set.range_nonempty _) (subset_spanPoints ℝ _) ?_ hm convert ha.not_mem_affineSpan_diff i Set.univ change (Set.range fun i2 : { x | x ≠ i } => p i2) = _ rw [← Set.image_eq_range] congr with j simp #align affine_independent.exists_unique_dist_eq AffineIndependent.existsUnique_dist_eq end EuclideanGeometry namespace Affine namespace Simplex open Finset AffineSubspace EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- The circumsphere of a simplex. -/ def circumsphere {n : ℕ} (s : Simplex ℝ P n) : Sphere P := s.independent.existsUnique_dist_eq.choose #align affine.simplex.circumsphere Affine.Simplex.circumsphere /-- The property satisfied by the circumsphere. -/ theorem circumsphere_unique_dist_eq {n : ℕ} (s : Simplex ℝ P n) : (s.circumsphere.center ∈ affineSpan ℝ (Set.range s.points) ∧ Set.range s.points ⊆ s.circumsphere) ∧ ∀ cs : Sphere P, cs.center ∈ affineSpan ℝ (Set.range s.points) ∧ Set.range s.points ⊆ cs → cs = s.circumsphere := s.independent.existsUnique_dist_eq.choose_spec #align affine.simplex.circumsphere_unique_dist_eq Affine.Simplex.circumsphere_unique_dist_eq /-- The circumcenter of a simplex. -/ def circumcenter {n : ℕ} (s : Simplex ℝ P n) : P := s.circumsphere.center #align affine.simplex.circumcenter Affine.Simplex.circumcenter /-- The circumradius of a simplex. -/ def circumradius {n : ℕ} (s : Simplex ℝ P n) : ℝ := s.circumsphere.radius #align affine.simplex.circumradius Affine.Simplex.circumradius /-- The center of the circumsphere is the circumcenter. -/ @[simp] theorem circumsphere_center {n : ℕ} (s : Simplex ℝ P n) : s.circumsphere.center = s.circumcenter := rfl #align affine.simplex.circumsphere_center Affine.Simplex.circumsphere_center /-- The radius of the circumsphere is the circumradius. -/ @[simp] theorem circumsphere_radius {n : ℕ} (s : Simplex ℝ P n) : s.circumsphere.radius = s.circumradius := rfl #align affine.simplex.circumsphere_radius Affine.Simplex.circumsphere_radius /-- The circumcenter lies in the affine span. -/ theorem circumcenter_mem_affineSpan {n : ℕ} (s : Simplex ℝ P n) : s.circumcenter ∈ affineSpan ℝ (Set.range s.points) := s.circumsphere_unique_dist_eq.1.1 #align affine.simplex.circumcenter_mem_affine_span Affine.Simplex.circumcenter_mem_affineSpan /-- All points have distance from the circumcenter equal to the circumradius. -/ @[simp] theorem dist_circumcenter_eq_circumradius {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : dist (s.points i) s.circumcenter = s.circumradius := dist_of_mem_subset_sphere (Set.mem_range_self _) s.circumsphere_unique_dist_eq.1.2 #align affine.simplex.dist_circumcenter_eq_circumradius Affine.Simplex.dist_circumcenter_eq_circumradius /-- All points lie in the circumsphere. -/ theorem mem_circumsphere {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : s.points i ∈ s.circumsphere := s.dist_circumcenter_eq_circumradius i #align affine.simplex.mem_circumsphere Affine.Simplex.mem_circumsphere /-- All points have distance to the circumcenter equal to the circumradius. -/ @[simp] theorem dist_circumcenter_eq_circumradius' {n : ℕ} (s : Simplex ℝ P n) : ∀ i, dist s.circumcenter (s.points i) = s.circumradius := by intro i rw [dist_comm] exact dist_circumcenter_eq_circumradius _ _ #align affine.simplex.dist_circumcenter_eq_circumradius' Affine.Simplex.dist_circumcenter_eq_circumradius' /-- Given a point in the affine span from which all the points are equidistant, that point is the circumcenter. -/ theorem eq_circumcenter_of_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P} (hp : p ∈ affineSpan ℝ (Set.range s.points)) {r : ℝ} (hr : ∀ i, dist (s.points i) p = r) : p = s.circumcenter := by have h := s.circumsphere_unique_dist_eq.2 ⟨p, r⟩ simp only [hp, hr, forall_const, eq_self_iff_true, subset_sphere, Sphere.ext_iff, Set.forall_mem_range, mem_sphere, true_and] at h -- Porting note: added the next three lines (`simp` less powerful) rw [subset_sphere (s := ⟨p, r⟩)] at h simp only [hp, hr, forall_const, eq_self_iff_true, subset_sphere, Sphere.ext_iff, Set.forall_mem_range, mem_sphere, true_and] at h exact h.1 #align affine.simplex.eq_circumcenter_of_dist_eq Affine.Simplex.eq_circumcenter_of_dist_eq /-- Given a point in the affine span from which all the points are equidistant, that distance is the circumradius. -/ theorem eq_circumradius_of_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P} (hp : p ∈ affineSpan ℝ (Set.range s.points)) {r : ℝ} (hr : ∀ i, dist (s.points i) p = r) : r = s.circumradius := by have h := s.circumsphere_unique_dist_eq.2 ⟨p, r⟩ simp only [hp, hr, forall_const, eq_self_iff_true, subset_sphere, Sphere.ext_iff, Set.forall_mem_range, mem_sphere, true_and_iff] at h -- Porting note: added the next three lines (`simp` less powerful) rw [subset_sphere (s := ⟨p, r⟩)] at h simp only [hp, hr, forall_const, eq_self_iff_true, subset_sphere, Sphere.ext_iff, Set.forall_mem_range, mem_sphere, true_and_iff] at h exact h.2 #align affine.simplex.eq_circumradius_of_dist_eq Affine.Simplex.eq_circumradius_of_dist_eq /-- The circumradius is non-negative. -/ theorem circumradius_nonneg {n : ℕ} (s : Simplex ℝ P n) : 0 ≤ s.circumradius := s.dist_circumcenter_eq_circumradius 0 ▸ dist_nonneg #align affine.simplex.circumradius_nonneg Affine.Simplex.circumradius_nonneg /-- The circumradius of a simplex with at least two points is positive. -/ theorem circumradius_pos {n : ℕ} (s : Simplex ℝ P (n + 1)) : 0 < s.circumradius := by refine lt_of_le_of_ne s.circumradius_nonneg ?_ intro h have hr := s.dist_circumcenter_eq_circumradius simp_rw [← h, dist_eq_zero] at hr have h01 := s.independent.injective.ne (by simp : (0 : Fin (n + 2)) ≠ 1) simp [hr] at h01 #align affine.simplex.circumradius_pos Affine.Simplex.circumradius_pos /-- The circumcenter of a 0-simplex equals its unique point. -/ theorem circumcenter_eq_point (s : Simplex ℝ P 0) (i : Fin 1) : s.circumcenter = s.points i := by have h := s.circumcenter_mem_affineSpan have : Unique (Fin 1) := ⟨⟨0, by decide⟩, fun a => by simp only [Fin.eq_zero]⟩ simp only [Set.range_unique, AffineSubspace.mem_affineSpan_singleton] at h rw [h] congr simp only [eq_iff_true_of_subsingleton] #align affine.simplex.circumcenter_eq_point Affine.Simplex.circumcenter_eq_point /-- The circumcenter of a 1-simplex equals its centroid. -/ theorem circumcenter_eq_centroid (s : Simplex ℝ P 1) : s.circumcenter = Finset.univ.centroid ℝ s.points := by have hr : Set.Pairwise Set.univ fun i j : Fin 2 => dist (s.points i) (Finset.univ.centroid ℝ s.points) = dist (s.points j) (Finset.univ.centroid ℝ s.points) := by intro i hi j hj hij rw [Finset.centroid_pair_fin, dist_eq_norm_vsub V (s.points i), dist_eq_norm_vsub V (s.points j), vsub_vadd_eq_vsub_sub, vsub_vadd_eq_vsub_sub, ← one_smul ℝ (s.points i -ᵥ s.points 0), ← one_smul ℝ (s.points j -ᵥ s.points 0)] fin_cases i <;> fin_cases j <;> simp [-one_smul, ← sub_smul] <;> norm_num rw [Set.pairwise_eq_iff_exists_eq] at hr cases' hr with r hr exact (s.eq_circumcenter_of_dist_eq (centroid_mem_affineSpan_of_card_eq_add_one ℝ _ (Finset.card_fin 2)) fun i => hr i (Set.mem_univ _)).symm #align affine.simplex.circumcenter_eq_centroid Affine.Simplex.circumcenter_eq_centroid /-- Reindexing a simplex along an `Equiv` of index types does not change the circumsphere. -/ @[simp] theorem circumsphere_reindex {m n : ℕ} (s : Simplex ℝ P m) (e : Fin (m + 1) ≃ Fin (n + 1)) : (s.reindex e).circumsphere = s.circumsphere := by refine s.circumsphere_unique_dist_eq.2 _ ⟨?_, ?_⟩ <;> rw [← s.reindex_range_points e] · exact (s.reindex e).circumsphere_unique_dist_eq.1.1 · exact (s.reindex e).circumsphere_unique_dist_eq.1.2 #align affine.simplex.circumsphere_reindex Affine.Simplex.circumsphere_reindex /-- Reindexing a simplex along an `Equiv` of index types does not change the circumcenter. -/ @[simp] theorem circumcenter_reindex {m n : ℕ} (s : Simplex ℝ P m) (e : Fin (m + 1) ≃ Fin (n + 1)) : (s.reindex e).circumcenter = s.circumcenter := by simp_rw [circumcenter, circumsphere_reindex] #align affine.simplex.circumcenter_reindex Affine.Simplex.circumcenter_reindex /-- Reindexing a simplex along an `Equiv` of index types does not change the circumradius. -/ @[simp] theorem circumradius_reindex {m n : ℕ} (s : Simplex ℝ P m) (e : Fin (m + 1) ≃ Fin (n + 1)) : (s.reindex e).circumradius = s.circumradius := by simp_rw [circumradius, circumsphere_reindex] #align affine.simplex.circumradius_reindex Affine.Simplex.circumradius_reindex attribute [local instance] AffineSubspace.toAddTorsor /-- The orthogonal projection of a point `p` onto the hyperplane spanned by the simplex's points. -/ def orthogonalProjectionSpan {n : ℕ} (s : Simplex ℝ P n) : P →ᵃ[ℝ] affineSpan ℝ (Set.range s.points) := orthogonalProjection (affineSpan ℝ (Set.range s.points)) #align affine.simplex.orthogonal_projection_span Affine.Simplex.orthogonalProjectionSpan /-- Adding a vector to a point in the given subspace, then taking the orthogonal projection, produces the original point if the vector is a multiple of the result of subtracting a point's orthogonal projection from that point. -/ theorem orthogonalProjection_vadd_smul_vsub_orthogonalProjection {n : ℕ} (s : Simplex ℝ P n) {p1 : P} (p2 : P) (r : ℝ) (hp : p1 ∈ affineSpan ℝ (Set.range s.points)) : s.orthogonalProjectionSpan (r • (p2 -ᵥ s.orthogonalProjectionSpan p2 : V) +ᵥ p1) = ⟨p1, hp⟩ := EuclideanGeometry.orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ _ #align affine.simplex.orthogonal_projection_vadd_smul_vsub_orthogonal_projection Affine.Simplex.orthogonalProjection_vadd_smul_vsub_orthogonalProjection theorem coe_orthogonalProjection_vadd_smul_vsub_orthogonalProjection {n : ℕ} {r₁ : ℝ} (s : Simplex ℝ P n) {p p₁o : P} (hp₁o : p₁o ∈ affineSpan ℝ (Set.range s.points)) : ↑(s.orthogonalProjectionSpan (r₁ • (p -ᵥ ↑(s.orthogonalProjectionSpan p)) +ᵥ p₁o)) = p₁o := congrArg ((↑) : _ → P) (orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ _ hp₁o) #align affine.simplex.coe_orthogonal_projection_vadd_smul_vsub_orthogonal_projection Affine.Simplex.coe_orthogonalProjection_vadd_smul_vsub_orthogonalProjection theorem dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq {n : ℕ} (s : Simplex ℝ P n) {p1 : P} (p2 : P) (hp1 : p1 ∈ affineSpan ℝ (Set.range s.points)) : dist p1 p2 * dist p1 p2 = dist p1 (s.orthogonalProjectionSpan p2) * dist p1 (s.orthogonalProjectionSpan p2) + dist p2 (s.orthogonalProjectionSpan p2) * dist p2 (s.orthogonalProjectionSpan p2) := by rw [PseudoMetricSpace.dist_comm p2 _, dist_eq_norm_vsub V p1 _, dist_eq_norm_vsub V p1 _, dist_eq_norm_vsub V _ p2, ← vsub_add_vsub_cancel p1 (s.orthogonalProjectionSpan p2) p2, norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero] exact Submodule.inner_right_of_mem_orthogonal (vsub_orthogonalProjection_mem_direction p2 hp1) (orthogonalProjection_vsub_mem_direction_orthogonal _ p2) #align affine.simplex.dist_sq_eq_dist_orthogonal_projection_sq_add_dist_orthogonal_projection_sq Affine.Simplex.dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq theorem dist_circumcenter_sq_eq_sq_sub_circumradius {n : ℕ} {r : ℝ} (s : Simplex ℝ P n) {p₁ : P} (h₁ : ∀ i : Fin (n + 1), dist (s.points i) p₁ = r) (h₁' : ↑(s.orthogonalProjectionSpan p₁) = s.circumcenter) (h : s.points 0 ∈ affineSpan ℝ (Set.range s.points)) : dist p₁ s.circumcenter * dist p₁ s.circumcenter = r * r - s.circumradius * s.circumradius := by rw [dist_comm, ← h₁ 0, s.dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq p₁ h] simp only [h₁', dist_comm p₁, add_sub_cancel_left, Simplex.dist_circumcenter_eq_circumradius] #align affine.simplex.dist_circumcenter_sq_eq_sq_sub_circumradius Affine.Simplex.dist_circumcenter_sq_eq_sq_sub_circumradius /-- If there exists a distance that a point has from all vertices of a simplex, the orthogonal projection of that point onto the subspace spanned by that simplex is its circumcenter. -/ theorem orthogonalProjection_eq_circumcenter_of_exists_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P} (hr : ∃ r, ∀ i, dist (s.points i) p = r) : ↑(s.orthogonalProjectionSpan p) = s.circumcenter := by change ∃ r : ℝ, ∀ i, (fun x => dist x p = r) (s.points i) at hr have hr : ∃ (r : ℝ), ∀ (a : P), a ∈ Set.range (fun (i : Fin (n + 1)) => s.points i) → dist a p = r := by cases' hr with r hr use r refine Set.forall_mem_range.mpr ?_ exact hr rw [exists_dist_eq_iff_exists_dist_orthogonalProjection_eq (subset_affineSpan ℝ _) p] at hr cases' hr with r hr exact s.eq_circumcenter_of_dist_eq (orthogonalProjection_mem p) fun i => hr _ (Set.mem_range_self i) #align affine.simplex.orthogonal_projection_eq_circumcenter_of_exists_dist_eq Affine.Simplex.orthogonalProjection_eq_circumcenter_of_exists_dist_eq /-- If a point has the same distance from all vertices of a simplex, the orthogonal projection of that point onto the subspace spanned by that simplex is its circumcenter. -/ theorem orthogonalProjection_eq_circumcenter_of_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P} {r : ℝ} (hr : ∀ i, dist (s.points i) p = r) : ↑(s.orthogonalProjectionSpan p) = s.circumcenter := s.orthogonalProjection_eq_circumcenter_of_exists_dist_eq ⟨r, hr⟩ #align affine.simplex.orthogonal_projection_eq_circumcenter_of_dist_eq Affine.Simplex.orthogonalProjection_eq_circumcenter_of_dist_eq /-- The orthogonal projection of the circumcenter onto a face is the circumcenter of that face. -/ theorem orthogonalProjection_circumcenter {n : ℕ} (s : Simplex ℝ P n) {fs : Finset (Fin (n + 1))} {m : ℕ} (h : fs.card = m + 1) : ↑((s.face h).orthogonalProjectionSpan s.circumcenter) = (s.face h).circumcenter := haveI hr : ∃ r, ∀ i, dist ((s.face h).points i) s.circumcenter = r := by use s.circumradius simp [face_points] orthogonalProjection_eq_circumcenter_of_exists_dist_eq _ hr #align affine.simplex.orthogonal_projection_circumcenter Affine.Simplex.orthogonalProjection_circumcenter /-- Two simplices with the same points have the same circumcenter. -/ theorem circumcenter_eq_of_range_eq {n : ℕ} {s₁ s₂ : Simplex ℝ P n} (h : Set.range s₁.points = Set.range s₂.points) : s₁.circumcenter = s₂.circumcenter := by have hs : s₁.circumcenter ∈ affineSpan ℝ (Set.range s₂.points) := h ▸ s₁.circumcenter_mem_affineSpan have hr : ∀ i, dist (s₂.points i) s₁.circumcenter = s₁.circumradius := by intro i have hi : s₂.points i ∈ Set.range s₂.points := Set.mem_range_self _ rw [← h, Set.mem_range] at hi rcases hi with ⟨j, hj⟩ rw [← hj, s₁.dist_circumcenter_eq_circumradius j] exact s₂.eq_circumcenter_of_dist_eq hs hr #align affine.simplex.circumcenter_eq_of_range_eq Affine.Simplex.circumcenter_eq_of_range_eq /-- An index type for the vertices of a simplex plus its circumcenter. This is for use in calculations where it is convenient to work with affine combinations of vertices together with the circumcenter. (An equivalent form sometimes used in the literature is placing the circumcenter at the origin and working with vectors for the vertices.) -/ inductive PointsWithCircumcenterIndex (n : ℕ) | pointIndex : Fin (n + 1) → PointsWithCircumcenterIndex n | circumcenterIndex : PointsWithCircumcenterIndex n deriving Fintype #align affine.simplex.points_with_circumcenter_index Affine.Simplex.PointsWithCircumcenterIndex open PointsWithCircumcenterIndex instance pointsWithCircumcenterIndexInhabited (n : ℕ) : Inhabited (PointsWithCircumcenterIndex n) := ⟨circumcenterIndex⟩ #align affine.simplex.points_with_circumcenter_index_inhabited Affine.Simplex.pointsWithCircumcenterIndexInhabited /-- `pointIndex` as an embedding. -/ def pointIndexEmbedding (n : ℕ) : Fin (n + 1) ↪ PointsWithCircumcenterIndex n := ⟨fun i => pointIndex i, fun _ _ h => by injection h⟩ #align affine.simplex.point_index_embedding Affine.Simplex.pointIndexEmbedding /-- The sum of a function over `PointsWithCircumcenterIndex`. -/ theorem sum_pointsWithCircumcenter {α : Type*} [AddCommMonoid α] {n : ℕ} (f : PointsWithCircumcenterIndex n → α) : ∑ i, f i = (∑ i : Fin (n + 1), f (pointIndex i)) + f circumcenterIndex := by have h : univ = insert circumcenterIndex (univ.map (pointIndexEmbedding n)) := by ext x refine ⟨fun h => ?_, fun _ => mem_univ _⟩ cases' x with i · exact mem_insert_of_mem (mem_map_of_mem _ (mem_univ i)) · exact mem_insert_self _ _ change _ = (∑ i, f (pointIndexEmbedding n i)) + _ rw [add_comm, h, ← sum_map, sum_insert] simp_rw [Finset.mem_map, not_exists] rintro x ⟨_, h⟩ injection h #align affine.simplex.sum_points_with_circumcenter Affine.Simplex.sum_pointsWithCircumcenter /-- The vertices of a simplex plus its circumcenter. -/ def pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P n) : PointsWithCircumcenterIndex n → P | pointIndex i => s.points i | circumcenterIndex => s.circumcenter #align affine.simplex.points_with_circumcenter Affine.Simplex.pointsWithCircumcenter /-- `pointsWithCircumcenter`, applied to a `pointIndex` value, equals `points` applied to that value. -/ @[simp] theorem pointsWithCircumcenter_point {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : s.pointsWithCircumcenter (pointIndex i) = s.points i := rfl #align affine.simplex.points_with_circumcenter_point Affine.Simplex.pointsWithCircumcenter_point /-- `pointsWithCircumcenter`, applied to `circumcenterIndex`, equals the circumcenter. -/ @[simp] theorem pointsWithCircumcenter_eq_circumcenter {n : ℕ} (s : Simplex ℝ P n) : s.pointsWithCircumcenter circumcenterIndex = s.circumcenter := rfl #align affine.simplex.points_with_circumcenter_eq_circumcenter Affine.Simplex.pointsWithCircumcenter_eq_circumcenter /-- The weights for a single vertex of a simplex, in terms of `pointsWithCircumcenter`. -/ def pointWeightsWithCircumcenter {n : ℕ} (i : Fin (n + 1)) : PointsWithCircumcenterIndex n → ℝ | pointIndex j => if j = i then 1 else 0 | circumcenterIndex => 0 #align affine.simplex.point_weights_with_circumcenter Affine.Simplex.pointWeightsWithCircumcenter /-- `point_weights_with_circumcenter` sums to 1. -/ @[simp] theorem sum_pointWeightsWithCircumcenter {n : ℕ} (i : Fin (n + 1)) : ∑ j, pointWeightsWithCircumcenter i j = 1 := by convert sum_ite_eq' univ (pointIndex i) (Function.const _ (1 : ℝ)) with j · cases j <;> simp [pointWeightsWithCircumcenter] · simp #align affine.simplex.sum_point_weights_with_circumcenter Affine.Simplex.sum_pointWeightsWithCircumcenter /-- A single vertex, in terms of `pointsWithCircumcenter`. -/ theorem point_eq_affineCombination_of_pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : s.points i = (univ : Finset (PointsWithCircumcenterIndex n)).affineCombination ℝ s.pointsWithCircumcenter (pointWeightsWithCircumcenter i) := by rw [← pointsWithCircumcenter_point] symm refine affineCombination_of_eq_one_of_eq_zero _ _ _ (mem_univ _) (by simp [pointWeightsWithCircumcenter]) ?_ intro i hi hn cases i · have h : _ ≠ i := fun h => hn (h ▸ rfl) simp [pointWeightsWithCircumcenter, h] · rfl #align affine.simplex.point_eq_affine_combination_of_points_with_circumcenter Affine.Simplex.point_eq_affineCombination_of_pointsWithCircumcenter /-- The weights for the centroid of some vertices of a simplex, in terms of `pointsWithCircumcenter`. -/ def centroidWeightsWithCircumcenter {n : ℕ} (fs : Finset (Fin (n + 1))) : PointsWithCircumcenterIndex n → ℝ | pointIndex i => if i ∈ fs then (card fs : ℝ)⁻¹ else 0 | circumcenterIndex => 0 #align affine.simplex.centroid_weights_with_circumcenter Affine.Simplex.centroidWeightsWithCircumcenter /-- `centroidWeightsWithCircumcenter` sums to 1, if the `Finset` is nonempty. -/ @[simp] theorem sum_centroidWeightsWithCircumcenter {n : ℕ} {fs : Finset (Fin (n + 1))} (h : fs.Nonempty) : ∑ i, centroidWeightsWithCircumcenter fs i = 1 := by simp_rw [sum_pointsWithCircumcenter, centroidWeightsWithCircumcenter, add_zero, ← fs.sum_centroidWeights_eq_one_of_nonempty ℝ h, ← sum_indicator_subset _ fs.subset_univ] rcongr #align affine.simplex.sum_centroid_weights_with_circumcenter Affine.Simplex.sum_centroidWeightsWithCircumcenter /-- The centroid of some vertices of a simplex, in terms of `pointsWithCircumcenter`. -/ theorem centroid_eq_affineCombination_of_pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P n) (fs : Finset (Fin (n + 1))) : fs.centroid ℝ s.points = (univ : Finset (PointsWithCircumcenterIndex n)).affineCombination ℝ s.pointsWithCircumcenter (centroidWeightsWithCircumcenter fs) := by simp_rw [centroid_def, affineCombination_apply, weightedVSubOfPoint_apply, sum_pointsWithCircumcenter, centroidWeightsWithCircumcenter, pointsWithCircumcenter_point, zero_smul, add_zero, centroidWeights, ← sum_indicator_subset_of_eq_zero (Function.const (Fin (n + 1)) (card fs : ℝ)⁻¹) (fun i wi => wi • (s.points i -ᵥ Classical.choice AddTorsor.nonempty)) fs.subset_univ fun _ => zero_smul ℝ _, Set.indicator_apply] congr #align affine.simplex.centroid_eq_affine_combination_of_points_with_circumcenter Affine.Simplex.centroid_eq_affineCombination_of_pointsWithCircumcenter /-- The weights for the circumcenter of a simplex, in terms of `pointsWithCircumcenter`. -/ def circumcenterWeightsWithCircumcenter (n : ℕ) : PointsWithCircumcenterIndex n → ℝ | pointIndex _ => 0 | circumcenterIndex => 1 #align affine.simplex.circumcenter_weights_with_circumcenter Affine.Simplex.circumcenterWeightsWithCircumcenter /-- `circumcenterWeightsWithCircumcenter` sums to 1. -/ @[simp] theorem sum_circumcenterWeightsWithCircumcenter (n : ℕ) : ∑ i, circumcenterWeightsWithCircumcenter n i = 1 := by convert sum_ite_eq' univ circumcenterIndex (Function.const _ (1 : ℝ)) with j · cases j <;> simp [circumcenterWeightsWithCircumcenter] · simp #align affine.simplex.sum_circumcenter_weights_with_circumcenter Affine.Simplex.sum_circumcenterWeightsWithCircumcenter /-- The circumcenter of a simplex, in terms of `pointsWithCircumcenter`. -/ theorem circumcenter_eq_affineCombination_of_pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P n) : s.circumcenter = (univ : Finset (PointsWithCircumcenterIndex n)).affineCombination ℝ s.pointsWithCircumcenter (circumcenterWeightsWithCircumcenter n) := by rw [← pointsWithCircumcenter_eq_circumcenter] symm refine affineCombination_of_eq_one_of_eq_zero _ _ _ (mem_univ _) rfl ?_ rintro ⟨i⟩ _ hn <;> tauto #align affine.simplex.circumcenter_eq_affine_combination_of_points_with_circumcenter Affine.Simplex.circumcenter_eq_affineCombination_of_pointsWithCircumcenter /-- The weights for the reflection of the circumcenter in an edge of a simplex. This definition is only valid with `i₁ ≠ i₂`. -/ def reflectionCircumcenterWeightsWithCircumcenter {n : ℕ} (i₁ i₂ : Fin (n + 1)) : PointsWithCircumcenterIndex n → ℝ | pointIndex i => if i = i₁ ∨ i = i₂ then 1 else 0 | circumcenterIndex => -1 #align affine.simplex.reflection_circumcenter_weights_with_circumcenter Affine.Simplex.reflectionCircumcenterWeightsWithCircumcenter /-- `reflectionCircumcenterWeightsWithCircumcenter` sums to 1. -/ @[simp] theorem sum_reflectionCircumcenterWeightsWithCircumcenter {n : ℕ} {i₁ i₂ : Fin (n + 1)} (h : i₁ ≠ i₂) : ∑ i, reflectionCircumcenterWeightsWithCircumcenter i₁ i₂ i = 1 := by simp_rw [sum_pointsWithCircumcenter, reflectionCircumcenterWeightsWithCircumcenter, sum_ite, sum_const, filter_or, filter_eq'] rw [card_union_of_disjoint] · set_option simprocs false in simp · simpa only [if_true, mem_univ, disjoint_singleton] using h #align affine.simplex.sum_reflection_circumcenter_weights_with_circumcenter Affine.Simplex.sum_reflectionCircumcenterWeightsWithCircumcenter /-- The reflection of the circumcenter of a simplex in an edge, in terms of `pointsWithCircumcenter`. -/ theorem reflection_circumcenter_eq_affineCombination_of_pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P n) {i₁ i₂ : Fin (n + 1)} (h : i₁ ≠ i₂) : reflection (affineSpan ℝ (s.points '' {i₁, i₂})) s.circumcenter = (univ : Finset (PointsWithCircumcenterIndex n)).affineCombination ℝ s.pointsWithCircumcenter (reflectionCircumcenterWeightsWithCircumcenter i₁ i₂) := by have hc : card ({i₁, i₂} : Finset (Fin (n + 1))) = 2 := by simp [h] -- Making the next line a separate definition helps the elaborator: set W : AffineSubspace ℝ P := affineSpan ℝ (s.points '' {i₁, i₂}) have h_faces : (orthogonalProjection W s.circumcenter : P) = ↑((s.face hc).orthogonalProjectionSpan s.circumcenter) := by apply eq_orthogonalProjection_of_eq_subspace simp rw [EuclideanGeometry.reflection_apply, h_faces, s.orthogonalProjection_circumcenter hc, circumcenter_eq_centroid, s.face_centroid_eq_centroid hc, centroid_eq_affineCombination_of_pointsWithCircumcenter, circumcenter_eq_affineCombination_of_pointsWithCircumcenter, ← @vsub_eq_zero_iff_eq V, affineCombination_vsub, weightedVSub_vadd_affineCombination, affineCombination_vsub, weightedVSub_apply, sum_pointsWithCircumcenter] simp_rw [Pi.sub_apply, Pi.add_apply, Pi.sub_apply, sub_smul, add_smul, sub_smul, centroidWeightsWithCircumcenter, circumcenterWeightsWithCircumcenter, reflectionCircumcenterWeightsWithCircumcenter, ite_smul, zero_smul, sub_zero, apply_ite₂ (· + ·), add_zero, ← add_smul, hc, zero_sub, neg_smul, sub_self, add_zero] -- Porting note: was `convert sum_const_zero` rw [← sum_const_zero] congr norm_num #align affine.simplex.reflection_circumcenter_eq_affine_combination_of_points_with_circumcenter Affine.Simplex.reflection_circumcenter_eq_affineCombination_of_pointsWithCircumcenter end Simplex end Affine namespace EuclideanGeometry open Affine AffineSubspace FiniteDimensional variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- Given a nonempty affine subspace, whose direction is complete, that contains a set of points, those points are cospherical if and only if they are equidistant from some point in that subspace. -/
Mathlib/Geometry/Euclidean/Circumcenter.lean
728
735
theorem cospherical_iff_exists_mem_of_complete {s : AffineSubspace ℝ P} {ps : Set P} (h : ps ⊆ s) [Nonempty s] [HasOrthogonalProjection s.direction] : Cospherical ps ↔ ∃ center ∈ s, ∃ radius : ℝ, ∀ p ∈ ps, dist p center = radius := by
constructor · rintro ⟨c, hcr⟩ rw [exists_dist_eq_iff_exists_dist_orthogonalProjection_eq h c] at hcr exact ⟨orthogonalProjection s c, orthogonalProjection_mem _, hcr⟩ · exact fun ⟨c, _, hd⟩ => ⟨c, hd⟩
/- Copyright (c) 2019 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Nat.Choose.Basic import Mathlib.Data.List.Perm import Mathlib.Data.List.Range #align_import data.list.sublists from "leanprover-community/mathlib"@"ccad6d5093bd2f5c6ca621fc74674cce51355af6" /-! # sublists `List.Sublists` gives a list of all (not necessarily contiguous) sublists of a list. This file contains basic results on this function. -/ /- Porting note: various auxiliary definitions such as `sublists'_aux` were left out of the port because they were only used to prove properties of `sublists`, and these proofs have changed. -/ universe u v w variable {α : Type u} {β : Type v} {γ : Type w} open Nat namespace List /-! ### sublists -/ @[simp] theorem sublists'_nil : sublists' (@nil α) = [[]] := rfl #align list.sublists'_nil List.sublists'_nil @[simp] theorem sublists'_singleton (a : α) : sublists' [a] = [[], [a]] := rfl #align list.sublists'_singleton List.sublists'_singleton #noalign list.map_sublists'_aux #noalign list.sublists'_aux_append #noalign list.sublists'_aux_eq_sublists' -- Porting note: Not the same as `sublists'_aux` from Lean3 /-- Auxiliary helper definition for `sublists'` -/ def sublists'Aux (a : α) (r₁ r₂ : List (List α)) : List (List α) := r₁.foldl (init := r₂) fun r l => r ++ [a :: l] #align list.sublists'_aux List.sublists'Aux theorem sublists'Aux_eq_array_foldl (a : α) : ∀ (r₁ r₂ : List (List α)), sublists'Aux a r₁ r₂ = ((r₁.toArray).foldl (init := r₂.toArray) (fun r l => r.push (a :: l))).toList := by intro r₁ r₂ rw [sublists'Aux, Array.foldl_eq_foldl_data] have := List.foldl_hom Array.toList (fun r l => r.push (a :: l)) (fun r l => r ++ [a :: l]) r₁ r₂.toArray (by simp) simpa using this theorem sublists'_eq_sublists'Aux (l : List α) : sublists' l = l.foldr (fun a r => sublists'Aux a r r) [[]] := by simp only [sublists', sublists'Aux_eq_array_foldl] rw [← List.foldr_hom Array.toList] · rfl · intros _ _; congr <;> simp theorem sublists'Aux_eq_map (a : α) (r₁ : List (List α)) : ∀ (r₂ : List (List α)), sublists'Aux a r₁ r₂ = r₂ ++ map (cons a) r₁ := List.reverseRecOn r₁ (fun _ => by simp [sublists'Aux]) fun r₁ l ih r₂ => by rw [map_append, map_singleton, ← append_assoc, ← ih, sublists'Aux, foldl_append, foldl] simp [sublists'Aux] -- Porting note: simp can prove `sublists'_singleton` @[simp 900] theorem sublists'_cons (a : α) (l : List α) : sublists' (a :: l) = sublists' l ++ map (cons a) (sublists' l) := by simp [sublists'_eq_sublists'Aux, foldr_cons, sublists'Aux_eq_map] #align list.sublists'_cons List.sublists'_cons @[simp]
Mathlib/Data/List/Sublists.lean
82
93
theorem mem_sublists' {s t : List α} : s ∈ sublists' t ↔ s <+ t := by
induction' t with a t IH generalizing s · simp only [sublists'_nil, mem_singleton] exact ⟨fun h => by rw [h], eq_nil_of_sublist_nil⟩ simp only [sublists'_cons, mem_append, IH, mem_map] constructor <;> intro h · rcases h with (h | ⟨s, h, rfl⟩) · exact sublist_cons_of_sublist _ h · exact h.cons_cons _ · cases' h with _ _ _ h s _ _ h · exact Or.inl h · exact Or.inr ⟨s, h, rfl⟩
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Chris Hughes -/ import Mathlib.Algebra.Associated import Mathlib.Algebra.BigOperators.Group.Finset import Mathlib.Algebra.SMulWithZero import Mathlib.Data.Nat.PartENat import Mathlib.Tactic.Linarith #align_import ring_theory.multiplicity from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3" /-! # Multiplicity of a divisor For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves several basic results on it. ## Main definitions * `multiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers `n`. * `multiplicity.Finite a b`: a predicate denoting that the multiplicity of `a` in `b` is finite. -/ variable {α β : Type*} open Nat Part /-- `multiplicity a b` returns the largest natural number `n` such that `a ^ n ∣ b`, as a `PartENat` or natural with infinity. If `∀ n, a ^ n ∣ b`, then it returns `⊤`-/ def multiplicity [Monoid α] [DecidableRel ((· ∣ ·) : α → α → Prop)] (a b : α) : PartENat := PartENat.find fun n => ¬a ^ (n + 1) ∣ b #align multiplicity multiplicity namespace multiplicity section Monoid variable [Monoid α] [Monoid β] /-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/ abbrev Finite (a b : α) : Prop := ∃ n : ℕ, ¬a ^ (n + 1) ∣ b #align multiplicity.finite multiplicity.Finite theorem finite_iff_dom [DecidableRel ((· ∣ ·) : α → α → Prop)] {a b : α} : Finite a b ↔ (multiplicity a b).Dom := Iff.rfl #align multiplicity.finite_iff_dom multiplicity.finite_iff_dom theorem finite_def {a b : α} : Finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b := Iff.rfl #align multiplicity.finite_def multiplicity.finite_def theorem not_dvd_one_of_finite_one_right {a : α} : Finite a 1 → ¬a ∣ 1 := fun ⟨n, hn⟩ ⟨d, hd⟩ => hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩ #align multiplicity.not_dvd_one_of_finite_one_right multiplicity.not_dvd_one_of_finite_one_right @[norm_cast] theorem Int.natCast_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := by apply Part.ext' · rw [← @finite_iff_dom ℕ, @finite_def ℕ, ← @finite_iff_dom ℤ, @finite_def ℤ] norm_cast · intro h1 h2 apply _root_.le_antisymm <;> · apply Nat.find_mono norm_cast simp #align multiplicity.int.coe_nat_multiplicity multiplicity.Int.natCast_multiplicity @[deprecated (since := "2024-04-05")] alias Int.coe_nat_multiplicity := Int.natCast_multiplicity theorem not_finite_iff_forall {a b : α} : ¬Finite a b ↔ ∀ n : ℕ, a ^ n ∣ b := ⟨fun h n => Nat.casesOn n (by rw [_root_.pow_zero] exact one_dvd _) (by simpa [Finite, Classical.not_not] using h), by simp [Finite, multiplicity, Classical.not_not]; tauto⟩ #align multiplicity.not_finite_iff_forall multiplicity.not_finite_iff_forall theorem not_unit_of_finite {a b : α} (h : Finite a b) : ¬IsUnit a := let ⟨n, hn⟩ := h hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1) #align multiplicity.not_unit_of_finite multiplicity.not_unit_of_finite theorem finite_of_finite_mul_right {a b c : α} : Finite a (b * c) → Finite a b := fun ⟨n, hn⟩ => ⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩ #align multiplicity.finite_of_finite_mul_right multiplicity.finite_of_finite_mul_right variable [DecidableRel ((· ∣ ·) : α → α → Prop)] [DecidableRel ((· ∣ ·) : β → β → Prop)] theorem pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} : (k : PartENat) ≤ multiplicity a b → a ^ k ∣ b := by rw [← PartENat.some_eq_natCast] exact Nat.casesOn k (fun _ => by rw [_root_.pow_zero] exact one_dvd _) fun k ⟨_, h₂⟩ => by_contradiction fun hk => Nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk #align multiplicity.pow_dvd_of_le_multiplicity multiplicity.pow_dvd_of_le_multiplicity theorem pow_multiplicity_dvd {a b : α} (h : Finite a b) : a ^ get (multiplicity a b) h ∣ b := pow_dvd_of_le_multiplicity (by rw [PartENat.natCast_get]) #align multiplicity.pow_multiplicity_dvd multiplicity.pow_multiplicity_dvd theorem is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := fun h => by rw [PartENat.lt_coe_iff] at hm; exact Nat.find_spec hm.fst ((pow_dvd_pow _ hm.snd).trans h) #align multiplicity.is_greatest multiplicity.is_greatest theorem is_greatest' {a b : α} {m : ℕ} (h : Finite a b) (hm : get (multiplicity a b) h < m) : ¬a ^ m ∣ b := is_greatest (by rwa [← PartENat.coe_lt_coe, PartENat.natCast_get] at hm) #align multiplicity.is_greatest' multiplicity.is_greatest' theorem pos_of_dvd {a b : α} (hfin : Finite a b) (hdiv : a ∣ b) : 0 < (multiplicity a b).get hfin := by refine zero_lt_iff.2 fun h => ?_ simpa [hdiv] using is_greatest' hfin (lt_one_iff.mpr h) #align multiplicity.pos_of_dvd multiplicity.pos_of_dvd theorem unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) : (k : PartENat) = multiplicity a b := le_antisymm (le_of_not_gt fun hk' => is_greatest hk' hk) <| by have : Finite a b := ⟨k, hsucc⟩ rw [PartENat.le_coe_iff] exact ⟨this, Nat.find_min' _ hsucc⟩ #align multiplicity.unique multiplicity.unique
Mathlib/RingTheory/Multiplicity.lean
137
139
theorem unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) : k = get (multiplicity a b) ⟨k, hsucc⟩ := by
rw [← PartENat.natCast_inj, PartENat.natCast_get, unique hk hsucc]
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Yakov Pechersky -/ import Mathlib.Data.List.Nodup import Mathlib.Data.List.Zip import Mathlib.Data.Nat.Defs import Mathlib.Data.List.Infix #align_import data.list.rotate from "leanprover-community/mathlib"@"f694c7dead66f5d4c80f446c796a5aad14707f0e" /-! # List rotation This file proves basic results about `List.rotate`, the list rotation. ## Main declarations * `List.IsRotated l₁ l₂`: States that `l₁` is a rotated version of `l₂`. * `List.cyclicPermutations l`: The list of all cyclic permutants of `l`, up to the length of `l`. ## Tags rotated, rotation, permutation, cycle -/ universe u variable {α : Type u} open Nat Function namespace List theorem rotate_mod (l : List α) (n : ℕ) : l.rotate (n % l.length) = l.rotate n := by simp [rotate] #align list.rotate_mod List.rotate_mod @[simp] theorem rotate_nil (n : ℕ) : ([] : List α).rotate n = [] := by simp [rotate] #align list.rotate_nil List.rotate_nil @[simp] theorem rotate_zero (l : List α) : l.rotate 0 = l := by simp [rotate] #align list.rotate_zero List.rotate_zero -- Porting note: removing simp, simp can prove it theorem rotate'_nil (n : ℕ) : ([] : List α).rotate' n = [] := by cases n <;> rfl #align list.rotate'_nil List.rotate'_nil @[simp] theorem rotate'_zero (l : List α) : l.rotate' 0 = l := by cases l <;> rfl #align list.rotate'_zero List.rotate'_zero theorem rotate'_cons_succ (l : List α) (a : α) (n : ℕ) : (a :: l : List α).rotate' n.succ = (l ++ [a]).rotate' n := by simp [rotate'] #align list.rotate'_cons_succ List.rotate'_cons_succ @[simp] theorem length_rotate' : ∀ (l : List α) (n : ℕ), (l.rotate' n).length = l.length | [], _ => by simp | a :: l, 0 => rfl | a :: l, n + 1 => by rw [List.rotate', length_rotate' (l ++ [a]) n]; simp #align list.length_rotate' List.length_rotate' theorem rotate'_eq_drop_append_take : ∀ {l : List α} {n : ℕ}, n ≤ l.length → l.rotate' n = l.drop n ++ l.take n | [], n, h => by simp [drop_append_of_le_length h] | l, 0, h => by simp [take_append_of_le_length h] | a :: l, n + 1, h => by have hnl : n ≤ l.length := le_of_succ_le_succ h have hnl' : n ≤ (l ++ [a]).length := by rw [length_append, length_cons, List.length]; exact le_of_succ_le h rw [rotate'_cons_succ, rotate'_eq_drop_append_take hnl', drop, take, drop_append_of_le_length hnl, take_append_of_le_length hnl]; simp #align list.rotate'_eq_drop_append_take List.rotate'_eq_drop_append_take theorem rotate'_rotate' : ∀ (l : List α) (n m : ℕ), (l.rotate' n).rotate' m = l.rotate' (n + m) | a :: l, 0, m => by simp | [], n, m => by simp | a :: l, n + 1, m => by rw [rotate'_cons_succ, rotate'_rotate' _ n, Nat.add_right_comm, ← rotate'_cons_succ, Nat.succ_eq_add_one] #align list.rotate'_rotate' List.rotate'_rotate' @[simp] theorem rotate'_length (l : List α) : rotate' l l.length = l := by rw [rotate'_eq_drop_append_take le_rfl]; simp #align list.rotate'_length List.rotate'_length @[simp] theorem rotate'_length_mul (l : List α) : ∀ n : ℕ, l.rotate' (l.length * n) = l | 0 => by simp | n + 1 => calc l.rotate' (l.length * (n + 1)) = (l.rotate' (l.length * n)).rotate' (l.rotate' (l.length * n)).length := by simp [-rotate'_length, Nat.mul_succ, rotate'_rotate'] _ = l := by rw [rotate'_length, rotate'_length_mul l n] #align list.rotate'_length_mul List.rotate'_length_mul theorem rotate'_mod (l : List α) (n : ℕ) : l.rotate' (n % l.length) = l.rotate' n := calc l.rotate' (n % l.length) = (l.rotate' (n % l.length)).rotate' ((l.rotate' (n % l.length)).length * (n / l.length)) := by rw [rotate'_length_mul] _ = l.rotate' n := by rw [rotate'_rotate', length_rotate', Nat.mod_add_div] #align list.rotate'_mod List.rotate'_mod theorem rotate_eq_rotate' (l : List α) (n : ℕ) : l.rotate n = l.rotate' n := if h : l.length = 0 then by simp_all [length_eq_zero] else by rw [← rotate'_mod, rotate'_eq_drop_append_take (le_of_lt (Nat.mod_lt _ (Nat.pos_of_ne_zero h)))]; simp [rotate] #align list.rotate_eq_rotate' List.rotate_eq_rotate' theorem rotate_cons_succ (l : List α) (a : α) (n : ℕ) : (a :: l : List α).rotate (n + 1) = (l ++ [a]).rotate n := by rw [rotate_eq_rotate', rotate_eq_rotate', rotate'_cons_succ] #align list.rotate_cons_succ List.rotate_cons_succ @[simp] theorem mem_rotate : ∀ {l : List α} {a : α} {n : ℕ}, a ∈ l.rotate n ↔ a ∈ l | [], _, n => by simp | a :: l, _, 0 => by simp | a :: l, _, n + 1 => by simp [rotate_cons_succ, mem_rotate, or_comm] #align list.mem_rotate List.mem_rotate @[simp] theorem length_rotate (l : List α) (n : ℕ) : (l.rotate n).length = l.length := by rw [rotate_eq_rotate', length_rotate'] #align list.length_rotate List.length_rotate @[simp] theorem rotate_replicate (a : α) (n : ℕ) (k : ℕ) : (replicate n a).rotate k = replicate n a := eq_replicate.2 ⟨by rw [length_rotate, length_replicate], fun b hb => eq_of_mem_replicate <| mem_rotate.1 hb⟩ #align list.rotate_replicate List.rotate_replicate theorem rotate_eq_drop_append_take {l : List α} {n : ℕ} : n ≤ l.length → l.rotate n = l.drop n ++ l.take n := by rw [rotate_eq_rotate']; exact rotate'_eq_drop_append_take #align list.rotate_eq_drop_append_take List.rotate_eq_drop_append_take theorem rotate_eq_drop_append_take_mod {l : List α} {n : ℕ} : l.rotate n = l.drop (n % l.length) ++ l.take (n % l.length) := by rcases l.length.zero_le.eq_or_lt with hl | hl · simp [eq_nil_of_length_eq_zero hl.symm] rw [← rotate_eq_drop_append_take (n.mod_lt hl).le, rotate_mod] #align list.rotate_eq_drop_append_take_mod List.rotate_eq_drop_append_take_mod @[simp] theorem rotate_append_length_eq (l l' : List α) : (l ++ l').rotate l.length = l' ++ l := by rw [rotate_eq_rotate'] induction l generalizing l' · simp · simp_all [rotate'] #align list.rotate_append_length_eq List.rotate_append_length_eq theorem rotate_rotate (l : List α) (n m : ℕ) : (l.rotate n).rotate m = l.rotate (n + m) := by rw [rotate_eq_rotate', rotate_eq_rotate', rotate_eq_rotate', rotate'_rotate'] #align list.rotate_rotate List.rotate_rotate @[simp] theorem rotate_length (l : List α) : rotate l l.length = l := by rw [rotate_eq_rotate', rotate'_length] #align list.rotate_length List.rotate_length @[simp] theorem rotate_length_mul (l : List α) (n : ℕ) : l.rotate (l.length * n) = l := by rw [rotate_eq_rotate', rotate'_length_mul] #align list.rotate_length_mul List.rotate_length_mul theorem rotate_perm (l : List α) (n : ℕ) : l.rotate n ~ l := by rw [rotate_eq_rotate'] induction' n with n hn generalizing l · simp · cases' l with hd tl · simp · rw [rotate'_cons_succ] exact (hn _).trans (perm_append_singleton _ _) #align list.rotate_perm List.rotate_perm @[simp] theorem nodup_rotate {l : List α} {n : ℕ} : Nodup (l.rotate n) ↔ Nodup l := (rotate_perm l n).nodup_iff #align list.nodup_rotate List.nodup_rotate @[simp] theorem rotate_eq_nil_iff {l : List α} {n : ℕ} : l.rotate n = [] ↔ l = [] := by induction' n with n hn generalizing l · simp · cases' l with hd tl · simp · simp [rotate_cons_succ, hn] #align list.rotate_eq_nil_iff List.rotate_eq_nil_iff @[simp] theorem nil_eq_rotate_iff {l : List α} {n : ℕ} : [] = l.rotate n ↔ [] = l := by rw [eq_comm, rotate_eq_nil_iff, eq_comm] #align list.nil_eq_rotate_iff List.nil_eq_rotate_iff @[simp] theorem rotate_singleton (x : α) (n : ℕ) : [x].rotate n = [x] := rotate_replicate x 1 n #align list.rotate_singleton List.rotate_singleton theorem zipWith_rotate_distrib {β γ : Type*} (f : α → β → γ) (l : List α) (l' : List β) (n : ℕ) (h : l.length = l'.length) : (zipWith f l l').rotate n = zipWith f (l.rotate n) (l'.rotate n) := by rw [rotate_eq_drop_append_take_mod, rotate_eq_drop_append_take_mod, rotate_eq_drop_append_take_mod, h, zipWith_append, ← zipWith_distrib_drop, ← zipWith_distrib_take, List.length_zipWith, h, min_self] rw [length_drop, length_drop, h] #align list.zip_with_rotate_distrib List.zipWith_rotate_distrib attribute [local simp] rotate_cons_succ -- Porting note: removing @[simp], simp can prove it theorem zipWith_rotate_one {β : Type*} (f : α → α → β) (x y : α) (l : List α) : zipWith f (x :: y :: l) ((x :: y :: l).rotate 1) = f x y :: zipWith f (y :: l) (l ++ [x]) := by simp #align list.zip_with_rotate_one List.zipWith_rotate_one theorem get?_rotate {l : List α} {n m : ℕ} (hml : m < l.length) : (l.rotate n).get? m = l.get? ((m + n) % l.length) := by rw [rotate_eq_drop_append_take_mod] rcases lt_or_le m (l.drop (n % l.length)).length with hm | hm · rw [get?_append hm, get?_drop, ← add_mod_mod] rw [length_drop, Nat.lt_sub_iff_add_lt] at hm rw [mod_eq_of_lt hm, Nat.add_comm] · have hlt : n % length l < length l := mod_lt _ (m.zero_le.trans_lt hml) rw [get?_append_right hm, get?_take, length_drop] · congr 1 rw [length_drop] at hm have hm' := Nat.sub_le_iff_le_add'.1 hm have : n % length l + m - length l < length l := by rw [Nat.sub_lt_iff_lt_add' hm'] exact Nat.add_lt_add hlt hml conv_rhs => rw [Nat.add_comm m, ← mod_add_mod, mod_eq_sub_mod hm', mod_eq_of_lt this] rw [← Nat.add_right_inj, ← Nat.add_sub_assoc, Nat.add_sub_sub_cancel, Nat.add_sub_cancel', Nat.add_comm] exacts [hm', hlt.le, hm] · rwa [Nat.sub_lt_iff_lt_add hm, length_drop, Nat.sub_add_cancel hlt.le] #align list.nth_rotate List.get?_rotate -- Porting note (#10756): new lemma theorem get_rotate (l : List α) (n : ℕ) (k : Fin (l.rotate n).length) : (l.rotate n).get k = l.get ⟨(k + n) % l.length, mod_lt _ (length_rotate l n ▸ k.1.zero_le.trans_lt k.2)⟩ := by rw [← Option.some_inj, ← get?_eq_get, ← get?_eq_get, get?_rotate] exact k.2.trans_eq (length_rotate _ _) theorem head?_rotate {l : List α} {n : ℕ} (h : n < l.length) : head? (l.rotate n) = l.get? n := by rw [← get?_zero, get?_rotate (n.zero_le.trans_lt h), Nat.zero_add, Nat.mod_eq_of_lt h] #align list.head'_rotate List.head?_rotate -- Porting note: moved down from its original location below `get_rotate` so that the -- non-deprecated lemma does not use the deprecated version set_option linter.deprecated false in @[deprecated get_rotate (since := "2023-01-13")] theorem nthLe_rotate (l : List α) (n k : ℕ) (hk : k < (l.rotate n).length) : (l.rotate n).nthLe k hk = l.nthLe ((k + n) % l.length) (mod_lt _ (length_rotate l n ▸ k.zero_le.trans_lt hk)) := get_rotate l n ⟨k, hk⟩ #align list.nth_le_rotate List.nthLe_rotate set_option linter.deprecated false in theorem nthLe_rotate_one (l : List α) (k : ℕ) (hk : k < (l.rotate 1).length) : (l.rotate 1).nthLe k hk = l.nthLe ((k + 1) % l.length) (mod_lt _ (length_rotate l 1 ▸ k.zero_le.trans_lt hk)) := nthLe_rotate l 1 k hk #align list.nth_le_rotate_one List.nthLe_rotate_one -- Porting note (#10756): new lemma /-- A version of `List.get_rotate` that represents `List.get l` in terms of `List.get (List.rotate l n)`, not vice versa. Can be used instead of rewriting `List.get_rotate` from right to left. -/ theorem get_eq_get_rotate (l : List α) (n : ℕ) (k : Fin l.length) : l.get k = (l.rotate n).get ⟨(l.length - n % l.length + k) % l.length, (Nat.mod_lt _ (k.1.zero_le.trans_lt k.2)).trans_eq (length_rotate _ _).symm⟩ := by rw [get_rotate] refine congr_arg l.get (Fin.eq_of_val_eq ?_) simp only [mod_add_mod] rw [← add_mod_mod, Nat.add_right_comm, Nat.sub_add_cancel, add_mod_left, mod_eq_of_lt] exacts [k.2, (mod_lt _ (k.1.zero_le.trans_lt k.2)).le] set_option linter.deprecated false in /-- A variant of `List.nthLe_rotate` useful for rewrites from right to left. -/ @[deprecated get_eq_get_rotate] theorem nthLe_rotate' (l : List α) (n k : ℕ) (hk : k < l.length) : (l.rotate n).nthLe ((l.length - n % l.length + k) % l.length) ((Nat.mod_lt _ (k.zero_le.trans_lt hk)).trans_le (length_rotate _ _).ge) = l.nthLe k hk := (get_eq_get_rotate l n ⟨k, hk⟩).symm #align list.nth_le_rotate' List.nthLe_rotate' theorem rotate_eq_self_iff_eq_replicate [hα : Nonempty α] : ∀ {l : List α}, (∀ n, l.rotate n = l) ↔ ∃ a, l = replicate l.length a | [] => by simp | a :: l => ⟨fun h => ⟨a, ext_get (length_replicate _ _).symm fun n h₁ h₂ => by rw [get_replicate, ← Option.some_inj, ← get?_eq_get, ← head?_rotate h₁, h, head?_cons]⟩, fun ⟨b, hb⟩ n => by rw [hb, rotate_replicate]⟩ #align list.rotate_eq_self_iff_eq_replicate List.rotate_eq_self_iff_eq_replicate theorem rotate_one_eq_self_iff_eq_replicate [Nonempty α] {l : List α} : l.rotate 1 = l ↔ ∃ a : α, l = List.replicate l.length a := ⟨fun h => rotate_eq_self_iff_eq_replicate.mp fun n => Nat.rec l.rotate_zero (fun n hn => by rwa [Nat.succ_eq_add_one, ← l.rotate_rotate, hn]) n, fun h => rotate_eq_self_iff_eq_replicate.mpr h 1⟩ #align list.rotate_one_eq_self_iff_eq_replicate List.rotate_one_eq_self_iff_eq_replicate theorem rotate_injective (n : ℕ) : Function.Injective fun l : List α => l.rotate n := by rintro l l' (h : l.rotate n = l'.rotate n) have hle : l.length = l'.length := (l.length_rotate n).symm.trans (h.symm ▸ l'.length_rotate n) rw [rotate_eq_drop_append_take_mod, rotate_eq_drop_append_take_mod] at h obtain ⟨hd, ht⟩ := append_inj h (by simp_all) rw [← take_append_drop _ l, ht, hd, take_append_drop] #align list.rotate_injective List.rotate_injective @[simp] theorem rotate_eq_rotate {l l' : List α} {n : ℕ} : l.rotate n = l'.rotate n ↔ l = l' := (rotate_injective n).eq_iff #align list.rotate_eq_rotate List.rotate_eq_rotate theorem rotate_eq_iff {l l' : List α} {n : ℕ} : l.rotate n = l' ↔ l = l'.rotate (l'.length - n % l'.length) := by rw [← @rotate_eq_rotate _ l _ n, rotate_rotate, ← rotate_mod l', add_mod] rcases l'.length.zero_le.eq_or_lt with hl | hl · rw [eq_nil_of_length_eq_zero hl.symm, rotate_nil] · rcases (Nat.zero_le (n % l'.length)).eq_or_lt with hn | hn · simp [← hn] · rw [mod_eq_of_lt (Nat.sub_lt hl hn), Nat.sub_add_cancel, mod_self, rotate_zero] exact (Nat.mod_lt _ hl).le #align list.rotate_eq_iff List.rotate_eq_iff @[simp] theorem rotate_eq_singleton_iff {l : List α} {n : ℕ} {x : α} : l.rotate n = [x] ↔ l = [x] := by rw [rotate_eq_iff, rotate_singleton] #align list.rotate_eq_singleton_iff List.rotate_eq_singleton_iff @[simp] theorem singleton_eq_rotate_iff {l : List α} {n : ℕ} {x : α} : [x] = l.rotate n ↔ [x] = l := by rw [eq_comm, rotate_eq_singleton_iff, eq_comm] #align list.singleton_eq_rotate_iff List.singleton_eq_rotate_iff theorem reverse_rotate (l : List α) (n : ℕ) : (l.rotate n).reverse = l.reverse.rotate (l.length - n % l.length) := by rw [← length_reverse l, ← rotate_eq_iff] induction' n with n hn generalizing l · simp · cases' l with hd tl · simp · rw [rotate_cons_succ, ← rotate_rotate, hn] simp #align list.reverse_rotate List.reverse_rotate theorem rotate_reverse (l : List α) (n : ℕ) : l.reverse.rotate n = (l.rotate (l.length - n % l.length)).reverse := by rw [← reverse_reverse l] simp_rw [reverse_rotate, reverse_reverse, rotate_eq_iff, rotate_rotate, length_rotate, length_reverse] rw [← length_reverse l] let k := n % l.reverse.length cases' hk' : k with k' · simp_all! [k, length_reverse, ← rotate_rotate] · cases' l with x l · simp · rw [Nat.mod_eq_of_lt, Nat.sub_add_cancel, rotate_length] · exact Nat.sub_le _ _ · exact Nat.sub_lt (by simp) (by simp_all! [k]) #align list.rotate_reverse List.rotate_reverse theorem map_rotate {β : Type*} (f : α → β) (l : List α) (n : ℕ) : map f (l.rotate n) = (map f l).rotate n := by induction' n with n hn IH generalizing l · simp · cases' l with hd tl · simp · simp [hn] #align list.map_rotate List.map_rotate theorem Nodup.rotate_congr {l : List α} (hl : l.Nodup) (hn : l ≠ []) (i j : ℕ) (h : l.rotate i = l.rotate j) : i % l.length = j % l.length := by rw [← rotate_mod l i, ← rotate_mod l j] at h simpa only [head?_rotate, mod_lt, length_pos_of_ne_nil hn, get?_eq_get, Option.some_inj, hl.get_inj_iff, Fin.ext_iff] using congr_arg head? h #align list.nodup.rotate_congr List.Nodup.rotate_congr theorem Nodup.rotate_congr_iff {l : List α} (hl : l.Nodup) {i j : ℕ} : l.rotate i = l.rotate j ↔ i % l.length = j % l.length ∨ l = [] := by rcases eq_or_ne l [] with rfl | hn · simp · simp only [hn, or_false] refine ⟨hl.rotate_congr hn _ _, fun h ↦ ?_⟩ rw [← rotate_mod, h, rotate_mod] theorem Nodup.rotate_eq_self_iff {l : List α} (hl : l.Nodup) {n : ℕ} : l.rotate n = l ↔ n % l.length = 0 ∨ l = [] := by rw [← zero_mod, ← hl.rotate_congr_iff, rotate_zero] #align list.nodup.rotate_eq_self_iff List.Nodup.rotate_eq_self_iff section IsRotated variable (l l' : List α) /-- `IsRotated l₁ l₂` or `l₁ ~r l₂` asserts that `l₁` and `l₂` are cyclic permutations of each other. This is defined by claiming that `∃ n, l.rotate n = l'`. -/ def IsRotated : Prop := ∃ n, l.rotate n = l' #align list.is_rotated List.IsRotated @[inherit_doc List.IsRotated] infixr:1000 " ~r " => IsRotated variable {l l'} @[refl] theorem IsRotated.refl (l : List α) : l ~r l := ⟨0, by simp⟩ #align list.is_rotated.refl List.IsRotated.refl @[symm] theorem IsRotated.symm (h : l ~r l') : l' ~r l := by obtain ⟨n, rfl⟩ := h cases' l with hd tl · exists 0 · use (hd :: tl).length * n - n rw [rotate_rotate, Nat.add_sub_cancel', rotate_length_mul] exact Nat.le_mul_of_pos_left _ (by simp) #align list.is_rotated.symm List.IsRotated.symm theorem isRotated_comm : l ~r l' ↔ l' ~r l := ⟨IsRotated.symm, IsRotated.symm⟩ #align list.is_rotated_comm List.isRotated_comm @[simp] protected theorem IsRotated.forall (l : List α) (n : ℕ) : l.rotate n ~r l := IsRotated.symm ⟨n, rfl⟩ #align list.is_rotated.forall List.IsRotated.forall @[trans] theorem IsRotated.trans : ∀ {l l' l'' : List α}, l ~r l' → l' ~r l'' → l ~r l'' | _, _, _, ⟨n, rfl⟩, ⟨m, rfl⟩ => ⟨n + m, by rw [rotate_rotate]⟩ #align list.is_rotated.trans List.IsRotated.trans theorem IsRotated.eqv : Equivalence (@IsRotated α) := Equivalence.mk IsRotated.refl IsRotated.symm IsRotated.trans #align list.is_rotated.eqv List.IsRotated.eqv /-- The relation `List.IsRotated l l'` forms a `Setoid` of cycles. -/ def IsRotated.setoid (α : Type*) : Setoid (List α) where r := IsRotated iseqv := IsRotated.eqv #align list.is_rotated.setoid List.IsRotated.setoid theorem IsRotated.perm (h : l ~r l') : l ~ l' := Exists.elim h fun _ hl => hl ▸ (rotate_perm _ _).symm #align list.is_rotated.perm List.IsRotated.perm theorem IsRotated.nodup_iff (h : l ~r l') : Nodup l ↔ Nodup l' := h.perm.nodup_iff #align list.is_rotated.nodup_iff List.IsRotated.nodup_iff theorem IsRotated.mem_iff (h : l ~r l') {a : α} : a ∈ l ↔ a ∈ l' := h.perm.mem_iff #align list.is_rotated.mem_iff List.IsRotated.mem_iff @[simp] theorem isRotated_nil_iff : l ~r [] ↔ l = [] := ⟨fun ⟨n, hn⟩ => by simpa using hn, fun h => h ▸ by rfl⟩ #align list.is_rotated_nil_iff List.isRotated_nil_iff @[simp] theorem isRotated_nil_iff' : [] ~r l ↔ [] = l := by rw [isRotated_comm, isRotated_nil_iff, eq_comm] #align list.is_rotated_nil_iff' List.isRotated_nil_iff' @[simp] theorem isRotated_singleton_iff {x : α} : l ~r [x] ↔ l = [x] := ⟨fun ⟨n, hn⟩ => by simpa using hn, fun h => h ▸ by rfl⟩ #align list.is_rotated_singleton_iff List.isRotated_singleton_iff @[simp] theorem isRotated_singleton_iff' {x : α} : [x] ~r l ↔ [x] = l := by rw [isRotated_comm, isRotated_singleton_iff, eq_comm] #align list.is_rotated_singleton_iff' List.isRotated_singleton_iff' theorem isRotated_concat (hd : α) (tl : List α) : (tl ++ [hd]) ~r (hd :: tl) := IsRotated.symm ⟨1, by simp⟩ #align list.is_rotated_concat List.isRotated_concat theorem isRotated_append : (l ++ l') ~r (l' ++ l) := ⟨l.length, by simp⟩ #align list.is_rotated_append List.isRotated_append theorem IsRotated.reverse (h : l ~r l') : l.reverse ~r l'.reverse := by obtain ⟨n, rfl⟩ := h exact ⟨_, (reverse_rotate _ _).symm⟩ #align list.is_rotated.reverse List.IsRotated.reverse theorem isRotated_reverse_comm_iff : l.reverse ~r l' ↔ l ~r l'.reverse := by constructor <;> · intro h simpa using h.reverse #align list.is_rotated_reverse_comm_iff List.isRotated_reverse_comm_iff @[simp] theorem isRotated_reverse_iff : l.reverse ~r l'.reverse ↔ l ~r l' := by simp [isRotated_reverse_comm_iff] #align list.is_rotated_reverse_iff List.isRotated_reverse_iff theorem isRotated_iff_mod : l ~r l' ↔ ∃ n ≤ l.length, l.rotate n = l' := by refine ⟨fun h => ?_, fun ⟨n, _, h⟩ => ⟨n, h⟩⟩ obtain ⟨n, rfl⟩ := h cases' l with hd tl · simp · refine ⟨n % (hd :: tl).length, ?_, rotate_mod _ _⟩ refine (Nat.mod_lt _ ?_).le simp #align list.is_rotated_iff_mod List.isRotated_iff_mod theorem isRotated_iff_mem_map_range : l ~r l' ↔ l' ∈ (List.range (l.length + 1)).map l.rotate := by simp_rw [mem_map, mem_range, isRotated_iff_mod] exact ⟨fun ⟨n, hn, h⟩ => ⟨n, Nat.lt_succ_of_le hn, h⟩, fun ⟨n, hn, h⟩ => ⟨n, Nat.le_of_lt_succ hn, h⟩⟩ #align list.is_rotated_iff_mem_map_range List.isRotated_iff_mem_map_range -- Porting note: @[congr] only works for equality. -- @[congr] theorem IsRotated.map {β : Type*} {l₁ l₂ : List α} (h : l₁ ~r l₂) (f : α → β) : map f l₁ ~r map f l₂ := by obtain ⟨n, rfl⟩ := h rw [map_rotate] use n #align list.is_rotated.map List.IsRotated.map /-- List of all cyclic permutations of `l`. The `cyclicPermutations` of a nonempty list `l` will always contain `List.length l` elements. This implies that under certain conditions, there are duplicates in `List.cyclicPermutations l`. The `n`th entry is equal to `l.rotate n`, proven in `List.get_cyclicPermutations`. The proof that every cyclic permutant of `l` is in the list is `List.mem_cyclicPermutations_iff`. cyclicPermutations [1, 2, 3, 2, 4] = [[1, 2, 3, 2, 4], [2, 3, 2, 4, 1], [3, 2, 4, 1, 2], [2, 4, 1, 2, 3], [4, 1, 2, 3, 2]] -/ def cyclicPermutations : List α → List (List α) | [] => [[]] | l@(_ :: _) => dropLast (zipWith (· ++ ·) (tails l) (inits l)) #align list.cyclic_permutations List.cyclicPermutations @[simp] theorem cyclicPermutations_nil : cyclicPermutations ([] : List α) = [[]] := rfl #align list.cyclic_permutations_nil List.cyclicPermutations_nil theorem cyclicPermutations_cons (x : α) (l : List α) : cyclicPermutations (x :: l) = dropLast (zipWith (· ++ ·) (tails (x :: l)) (inits (x :: l))) := rfl #align list.cyclic_permutations_cons List.cyclicPermutations_cons theorem cyclicPermutations_of_ne_nil (l : List α) (h : l ≠ []) : cyclicPermutations l = dropLast (zipWith (· ++ ·) (tails l) (inits l)) := by obtain ⟨hd, tl, rfl⟩ := exists_cons_of_ne_nil h exact cyclicPermutations_cons _ _ #align list.cyclic_permutations_of_ne_nil List.cyclicPermutations_of_ne_nil theorem length_cyclicPermutations_cons (x : α) (l : List α) : length (cyclicPermutations (x :: l)) = length l + 1 := by simp [cyclicPermutations_cons] #align list.length_cyclic_permutations_cons List.length_cyclicPermutations_cons @[simp]
Mathlib/Data/List/Rotate.lean
577
578
theorem length_cyclicPermutations_of_ne_nil (l : List α) (h : l ≠ []) : length (cyclicPermutations l) = length l := by
simp [cyclicPermutations_of_ne_nil _ h]
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Minchao Wu -/ import Mathlib.Order.BoundedOrder #align_import data.prod.lex from "leanprover-community/mathlib"@"70d50ecfd4900dd6d328da39ab7ebd516abe4025" /-! # Lexicographic order This file defines the lexicographic relation for pairs of orders, partial orders and linear orders. ## Main declarations * `Prod.Lex.<pre/partial/linear>Order`: Instances lifting the orders on `α` and `β` to `α ×ₗ β`. ## Notation * `α ×ₗ β`: `α × β` equipped with the lexicographic order ## See also Related files are: * `Data.Finset.CoLex`: Colexicographic order on finite sets. * `Data.List.Lex`: Lexicographic order on lists. * `Data.Pi.Lex`: Lexicographic order on `Πₗ i, α i`. * `Data.PSigma.Order`: Lexicographic order on `Σ' i, α i`. * `Data.Sigma.Order`: Lexicographic order on `Σ i, α i`. -/ variable {α β γ : Type*} namespace Prod.Lex @[inherit_doc] notation:35 α " ×ₗ " β:34 => Lex (Prod α β) instance decidableEq (α β : Type*) [DecidableEq α] [DecidableEq β] : DecidableEq (α ×ₗ β) := instDecidableEqProd #align prod.lex.decidable_eq Prod.Lex.decidableEq instance inhabited (α β : Type*) [Inhabited α] [Inhabited β] : Inhabited (α ×ₗ β) := instInhabitedProd #align prod.lex.inhabited Prod.Lex.inhabited /-- Dictionary / lexicographic ordering on pairs. -/ instance instLE (α β : Type*) [LT α] [LE β] : LE (α ×ₗ β) where le := Prod.Lex (· < ·) (· ≤ ·) #align prod.lex.has_le Prod.Lex.instLE instance instLT (α β : Type*) [LT α] [LT β] : LT (α ×ₗ β) where lt := Prod.Lex (· < ·) (· < ·) #align prod.lex.has_lt Prod.Lex.instLT theorem le_iff [LT α] [LE β] (a b : α × β) : toLex a ≤ toLex b ↔ a.1 < b.1 ∨ a.1 = b.1 ∧ a.2 ≤ b.2 := Prod.lex_def (· < ·) (· ≤ ·) #align prod.lex.le_iff Prod.Lex.le_iff theorem lt_iff [LT α] [LT β] (a b : α × β) : toLex a < toLex b ↔ a.1 < b.1 ∨ a.1 = b.1 ∧ a.2 < b.2 := Prod.lex_def (· < ·) (· < ·) #align prod.lex.lt_iff Prod.Lex.lt_iff example (x : α) (y : β) : toLex (x, y) = toLex (x, y) := rfl /-- Dictionary / lexicographic preorder for pairs. -/ instance preorder (α β : Type*) [Preorder α] [Preorder β] : Preorder (α ×ₗ β) := { Prod.Lex.instLE α β, Prod.Lex.instLT α β with le_refl := refl_of <| Prod.Lex _ _, le_trans := fun _ _ _ => trans_of <| Prod.Lex _ _, lt_iff_le_not_le := fun x₁ x₂ => match x₁, x₂ with | (a₁, b₁), (a₂, b₂) => by constructor · rintro (⟨_, _, hlt⟩ | ⟨_, hlt⟩) · constructor · exact left _ _ hlt · rintro ⟨⟩ · apply lt_asymm hlt; assumption · exact lt_irrefl _ hlt · constructor · right rw [lt_iff_le_not_le] at hlt exact hlt.1 · rintro ⟨⟩ · apply lt_irrefl a₁ assumption · rw [lt_iff_le_not_le] at hlt apply hlt.2 assumption · rintro ⟨⟨⟩, h₂r⟩ · left assumption · right rw [lt_iff_le_not_le] constructor · assumption · intro h apply h₂r right exact h } #align prod.lex.preorder Prod.Lex.preorder theorem monotone_fst [Preorder α] [LE β] (t c : α ×ₗ β) (h : t ≤ c) : (ofLex t).1 ≤ (ofLex c).1 := by cases (Prod.Lex.le_iff t c).mp h with | inl h' => exact h'.le | inr h' => exact h'.1.le section Preorder variable [PartialOrder α] [Preorder β]
Mathlib/Data/Prod/Lex.lean
115
119
theorem toLex_mono : Monotone (toLex : α × β → α ×ₗ β) := by
rintro ⟨a₁, b₁⟩ ⟨a₂, b₂⟩ ⟨ha, hb⟩ obtain rfl | ha : a₁ = a₂ ∨ _ := ha.eq_or_lt · exact right _ hb · exact left _ _ ha
/- Copyright (c) 2019 Neil Strickland. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Neil Strickland -/ import Mathlib.Algebra.BigOperators.Intervals import Mathlib.Algebra.BigOperators.Ring import Mathlib.Algebra.Order.BigOperators.Ring.Finset import Mathlib.Algebra.Order.Field.Basic import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Algebra.Ring.Opposite import Mathlib.Tactic.Abel #align_import algebra.geom_sum from "leanprover-community/mathlib"@"f7fc89d5d5ff1db2d1242c7bb0e9062ce47ef47c" /-! # Partial sums of geometric series This file determines the values of the geometric series $\sum_{i=0}^{n-1} x^i$ and $\sum_{i=0}^{n-1} x^i y^{n-1-i}$ and variants thereof. We also provide some bounds on the "geometric" sum of `a/b^i` where `a b : ℕ`. ## Main statements * `geom_sum_Ico` proves that $\sum_{i=m}^{n-1} x^i=\frac{x^n-x^m}{x-1}$ in a division ring. * `geom_sum₂_Ico` proves that $\sum_{i=m}^{n-1} x^iy^{n - 1 - i}=\frac{x^n-y^{n-m}x^m}{x-y}$ in a field. Several variants are recorded, generalising in particular to the case of a noncommutative ring in which `x` and `y` commute. Even versions not using division or subtraction, valid in each semiring, are recorded. -/ -- Porting note: corrected type in the description of `geom_sum₂_Ico` (in the doc string only). universe u variable {α : Type u} open Finset MulOpposite section Semiring variable [Semiring α] theorem geom_sum_succ {x : α} {n : ℕ} : ∑ i ∈ range (n + 1), x ^ i = (x * ∑ i ∈ range n, x ^ i) + 1 := by simp only [mul_sum, ← pow_succ', sum_range_succ', pow_zero] #align geom_sum_succ geom_sum_succ theorem geom_sum_succ' {x : α} {n : ℕ} : ∑ i ∈ range (n + 1), x ^ i = x ^ n + ∑ i ∈ range n, x ^ i := (sum_range_succ _ _).trans (add_comm _ _) #align geom_sum_succ' geom_sum_succ' theorem geom_sum_zero (x : α) : ∑ i ∈ range 0, x ^ i = 0 := rfl #align geom_sum_zero geom_sum_zero theorem geom_sum_one (x : α) : ∑ i ∈ range 1, x ^ i = 1 := by simp [geom_sum_succ'] #align geom_sum_one geom_sum_one @[simp] theorem geom_sum_two {x : α} : ∑ i ∈ range 2, x ^ i = x + 1 := by simp [geom_sum_succ'] #align geom_sum_two geom_sum_two @[simp] theorem zero_geom_sum : ∀ {n}, ∑ i ∈ range n, (0 : α) ^ i = if n = 0 then 0 else 1 | 0 => by simp | 1 => by simp | n + 2 => by rw [geom_sum_succ'] simp [zero_geom_sum] #align zero_geom_sum zero_geom_sum theorem one_geom_sum (n : ℕ) : ∑ i ∈ range n, (1 : α) ^ i = n := by simp #align one_geom_sum one_geom_sum -- porting note (#10618): simp can prove this -- @[simp] theorem op_geom_sum (x : α) (n : ℕ) : op (∑ i ∈ range n, x ^ i) = ∑ i ∈ range n, op x ^ i := by simp #align op_geom_sum op_geom_sum -- Porting note: linter suggested to change left hand side @[simp] theorem op_geom_sum₂ (x y : α) (n : ℕ) : ∑ i ∈ range n, op y ^ (n - 1 - i) * op x ^ i = ∑ i ∈ range n, op y ^ i * op x ^ (n - 1 - i) := by rw [← sum_range_reflect] refine sum_congr rfl fun j j_in => ?_ rw [mem_range, Nat.lt_iff_add_one_le] at j_in congr apply tsub_tsub_cancel_of_le exact le_tsub_of_add_le_right j_in #align op_geom_sum₂ op_geom_sum₂ theorem geom_sum₂_with_one (x : α) (n : ℕ) : ∑ i ∈ range n, x ^ i * 1 ^ (n - 1 - i) = ∑ i ∈ range n, x ^ i := sum_congr rfl fun i _ => by rw [one_pow, mul_one] #align geom_sum₂_with_one geom_sum₂_with_one /-- $x^n-y^n = (x-y) \sum x^ky^{n-1-k}$ reformulated without `-` signs. -/ protected theorem Commute.geom_sum₂_mul_add {x y : α} (h : Commute x y) (n : ℕ) : (∑ i ∈ range n, (x + y) ^ i * y ^ (n - 1 - i)) * x + y ^ n = (x + y) ^ n := by let f : ℕ → ℕ → α := fun m i : ℕ => (x + y) ^ i * y ^ (m - 1 - i) -- Porting note: adding `hf` here, because below in two places `dsimp [f]` didn't work have hf : ∀ m i : ℕ, f m i = (x + y) ^ i * y ^ (m - 1 - i) := by simp only [ge_iff_le, tsub_le_iff_right, forall_const] change (∑ i ∈ range n, (f n) i) * x + y ^ n = (x + y) ^ n induction' n with n ih · rw [range_zero, sum_empty, zero_mul, zero_add, pow_zero, pow_zero] · have f_last : f (n + 1) n = (x + y) ^ n := by rw [hf, ← tsub_add_eq_tsub_tsub, Nat.add_comm, tsub_self, pow_zero, mul_one] have f_succ : ∀ i, i ∈ range n → f (n + 1) i = y * f n i := fun i hi => by rw [hf] have : Commute y ((x + y) ^ i) := (h.symm.add_right (Commute.refl y)).pow_right i rw [← mul_assoc, this.eq, mul_assoc, ← pow_succ' y (n - 1 - i)] congr 2 rw [add_tsub_cancel_right, ← tsub_add_eq_tsub_tsub, add_comm 1 i] have : i + 1 + (n - (i + 1)) = n := add_tsub_cancel_of_le (mem_range.mp hi) rw [add_comm (i + 1)] at this rw [← this, add_tsub_cancel_right, add_comm i 1, ← add_assoc, add_tsub_cancel_right] rw [pow_succ' (x + y), add_mul, sum_range_succ_comm, add_mul, f_last, add_assoc] rw [(((Commute.refl x).add_right h).pow_right n).eq] congr 1 rw [sum_congr rfl f_succ, ← mul_sum, pow_succ' y, mul_assoc, ← mul_add y, ih] #align commute.geom_sum₂_mul_add Commute.geom_sum₂_mul_add end Semiring @[simp] theorem neg_one_geom_sum [Ring α] {n : ℕ} : ∑ i ∈ range n, (-1 : α) ^ i = if Even n then 0 else 1 := by induction' n with k hk · simp · simp only [geom_sum_succ', Nat.even_add_one, hk] split_ifs with h · rw [h.neg_one_pow, add_zero] · rw [(Nat.odd_iff_not_even.2 h).neg_one_pow, neg_add_self] #align neg_one_geom_sum neg_one_geom_sum theorem geom_sum₂_self {α : Type*} [CommRing α] (x : α) (n : ℕ) : ∑ i ∈ range n, x ^ i * x ^ (n - 1 - i) = n * x ^ (n - 1) := calc ∑ i ∈ Finset.range n, x ^ i * x ^ (n - 1 - i) = ∑ i ∈ Finset.range n, x ^ (i + (n - 1 - i)) := by simp_rw [← pow_add] _ = ∑ _i ∈ Finset.range n, x ^ (n - 1) := Finset.sum_congr rfl fun i hi => congr_arg _ <| add_tsub_cancel_of_le <| Nat.le_sub_one_of_lt <| Finset.mem_range.1 hi _ = (Finset.range n).card • x ^ (n - 1) := Finset.sum_const _ _ = n * x ^ (n - 1) := by rw [Finset.card_range, nsmul_eq_mul] #align geom_sum₂_self geom_sum₂_self /-- $x^n-y^n = (x-y) \sum x^ky^{n-1-k}$ reformulated without `-` signs. -/ theorem geom_sum₂_mul_add [CommSemiring α] (x y : α) (n : ℕ) : (∑ i ∈ range n, (x + y) ^ i * y ^ (n - 1 - i)) * x + y ^ n = (x + y) ^ n := (Commute.all x y).geom_sum₂_mul_add n #align geom_sum₂_mul_add geom_sum₂_mul_add theorem geom_sum_mul_add [Semiring α] (x : α) (n : ℕ) : (∑ i ∈ range n, (x + 1) ^ i) * x + 1 = (x + 1) ^ n := by have := (Commute.one_right x).geom_sum₂_mul_add n rw [one_pow, geom_sum₂_with_one] at this exact this #align geom_sum_mul_add geom_sum_mul_add protected theorem Commute.geom_sum₂_mul [Ring α] {x y : α} (h : Commute x y) (n : ℕ) : (∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) * (x - y) = x ^ n - y ^ n := by have := (h.sub_left (Commute.refl y)).geom_sum₂_mul_add n rw [sub_add_cancel] at this rw [← this, add_sub_cancel_right] #align commute.geom_sum₂_mul Commute.geom_sum₂_mul theorem Commute.mul_neg_geom_sum₂ [Ring α] {x y : α} (h : Commute x y) (n : ℕ) : ((y - x) * ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) = y ^ n - x ^ n := by apply op_injective simp only [op_mul, op_sub, op_geom_sum₂, op_pow] simp [(Commute.op h.symm).geom_sum₂_mul n] #align commute.mul_neg_geom_sum₂ Commute.mul_neg_geom_sum₂ theorem Commute.mul_geom_sum₂ [Ring α] {x y : α} (h : Commute x y) (n : ℕ) : ((x - y) * ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) = x ^ n - y ^ n := by rw [← neg_sub (y ^ n), ← h.mul_neg_geom_sum₂, ← neg_mul, neg_sub] #align commute.mul_geom_sum₂ Commute.mul_geom_sum₂ theorem geom_sum₂_mul [CommRing α] (x y : α) (n : ℕ) : (∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) * (x - y) = x ^ n - y ^ n := (Commute.all x y).geom_sum₂_mul n #align geom_sum₂_mul geom_sum₂_mul theorem Commute.sub_dvd_pow_sub_pow [Ring α] {x y : α} (h : Commute x y) (n : ℕ) : x - y ∣ x ^ n - y ^ n := Dvd.intro _ <| h.mul_geom_sum₂ _ theorem sub_dvd_pow_sub_pow [CommRing α] (x y : α) (n : ℕ) : x - y ∣ x ^ n - y ^ n := (Commute.all x y).sub_dvd_pow_sub_pow n #align sub_dvd_pow_sub_pow sub_dvd_pow_sub_pow theorem one_sub_dvd_one_sub_pow [Ring α] (x : α) (n : ℕ) : 1 - x ∣ 1 - x ^ n := by conv_rhs => rw [← one_pow n] exact (Commute.one_left x).sub_dvd_pow_sub_pow n theorem sub_one_dvd_pow_sub_one [Ring α] (x : α) (n : ℕ) : x - 1 ∣ x ^ n - 1 := by conv_rhs => rw [← one_pow n] exact (Commute.one_right x).sub_dvd_pow_sub_pow n theorem nat_sub_dvd_pow_sub_pow (x y n : ℕ) : x - y ∣ x ^ n - y ^ n := by rcases le_or_lt y x with h | h · have : y ^ n ≤ x ^ n := Nat.pow_le_pow_left h _ exact mod_cast sub_dvd_pow_sub_pow (x : ℤ) (↑y) n · have : x ^ n ≤ y ^ n := Nat.pow_le_pow_left h.le _ exact (Nat.sub_eq_zero_of_le this).symm ▸ dvd_zero (x - y) #align nat_sub_dvd_pow_sub_pow nat_sub_dvd_pow_sub_pow theorem Odd.add_dvd_pow_add_pow [CommRing α] (x y : α) {n : ℕ} (h : Odd n) : x + y ∣ x ^ n + y ^ n := by have h₁ := geom_sum₂_mul x (-y) n rw [Odd.neg_pow h y, sub_neg_eq_add, sub_neg_eq_add] at h₁ exact Dvd.intro_left _ h₁ #align odd.add_dvd_pow_add_pow Odd.add_dvd_pow_add_pow theorem Odd.nat_add_dvd_pow_add_pow (x y : ℕ) {n : ℕ} (h : Odd n) : x + y ∣ x ^ n + y ^ n := mod_cast Odd.add_dvd_pow_add_pow (x : ℤ) (↑y) h #align odd.nat_add_dvd_pow_add_pow Odd.nat_add_dvd_pow_add_pow theorem geom_sum_mul [Ring α] (x : α) (n : ℕ) : (∑ i ∈ range n, x ^ i) * (x - 1) = x ^ n - 1 := by have := (Commute.one_right x).geom_sum₂_mul n rw [one_pow, geom_sum₂_with_one] at this exact this #align geom_sum_mul geom_sum_mul theorem mul_geom_sum [Ring α] (x : α) (n : ℕ) : ((x - 1) * ∑ i ∈ range n, x ^ i) = x ^ n - 1 := op_injective <| by simpa using geom_sum_mul (op x) n #align mul_geom_sum mul_geom_sum theorem geom_sum_mul_neg [Ring α] (x : α) (n : ℕ) : (∑ i ∈ range n, x ^ i) * (1 - x) = 1 - x ^ n := by have := congr_arg Neg.neg (geom_sum_mul x n) rw [neg_sub, ← mul_neg, neg_sub] at this exact this #align geom_sum_mul_neg geom_sum_mul_neg theorem mul_neg_geom_sum [Ring α] (x : α) (n : ℕ) : ((1 - x) * ∑ i ∈ range n, x ^ i) = 1 - x ^ n := op_injective <| by simpa using geom_sum_mul_neg (op x) n #align mul_neg_geom_sum mul_neg_geom_sum protected theorem Commute.geom_sum₂_comm {α : Type u} [Semiring α] {x y : α} (n : ℕ) (h : Commute x y) : ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i) = ∑ i ∈ range n, y ^ i * x ^ (n - 1 - i) := by cases n; · simp simp only [Nat.succ_eq_add_one, Nat.add_sub_cancel] rw [← Finset.sum_flip] refine Finset.sum_congr rfl fun i hi => ?_ simpa [Nat.sub_sub_self (Nat.succ_le_succ_iff.mp (Finset.mem_range.mp hi))] using h.pow_pow _ _ #align commute.geom_sum₂_comm Commute.geom_sum₂_comm theorem geom_sum₂_comm {α : Type u} [CommSemiring α] (x y : α) (n : ℕ) : ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i) = ∑ i ∈ range n, y ^ i * x ^ (n - 1 - i) := (Commute.all x y).geom_sum₂_comm n #align geom_sum₂_comm geom_sum₂_comm protected theorem Commute.geom_sum₂ [DivisionRing α] {x y : α} (h' : Commute x y) (h : x ≠ y) (n : ℕ) : ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i) = (x ^ n - y ^ n) / (x - y) := by have : x - y ≠ 0 := by simp_all [sub_eq_iff_eq_add] rw [← h'.geom_sum₂_mul, mul_div_cancel_right₀ _ this] #align commute.geom_sum₂ Commute.geom_sum₂ theorem geom₂_sum [Field α] {x y : α} (h : x ≠ y) (n : ℕ) : ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i) = (x ^ n - y ^ n) / (x - y) := (Commute.all x y).geom_sum₂ h n #align geom₂_sum geom₂_sum theorem geom_sum_eq [DivisionRing α] {x : α} (h : x ≠ 1) (n : ℕ) : ∑ i ∈ range n, x ^ i = (x ^ n - 1) / (x - 1) := by have : x - 1 ≠ 0 := by simp_all [sub_eq_iff_eq_add] rw [← geom_sum_mul, mul_div_cancel_right₀ _ this] #align geom_sum_eq geom_sum_eq protected theorem Commute.mul_geom_sum₂_Ico [Ring α] {x y : α} (h : Commute x y) {m n : ℕ} (hmn : m ≤ n) : ((x - y) * ∑ i ∈ Finset.Ico m n, x ^ i * y ^ (n - 1 - i)) = x ^ n - x ^ m * y ^ (n - m) := by rw [sum_Ico_eq_sub _ hmn] have : ∑ k ∈ range m, x ^ k * y ^ (n - 1 - k) = ∑ k ∈ range m, x ^ k * (y ^ (n - m) * y ^ (m - 1 - k)) := by refine sum_congr rfl fun j j_in => ?_ rw [← pow_add] congr rw [mem_range, Nat.lt_iff_add_one_le, add_comm] at j_in have h' : n - m + (m - (1 + j)) = n - (1 + j) := tsub_add_tsub_cancel hmn j_in rw [← tsub_add_eq_tsub_tsub m, h', ← tsub_add_eq_tsub_tsub] rw [this] simp_rw [pow_mul_comm y (n - m) _] simp_rw [← mul_assoc] rw [← sum_mul, mul_sub, h.mul_geom_sum₂, ← mul_assoc, h.mul_geom_sum₂, sub_mul, ← pow_add, add_tsub_cancel_of_le hmn, sub_sub_sub_cancel_right (x ^ n) (x ^ m * y ^ (n - m)) (y ^ n)] #align commute.mul_geom_sum₂_Ico Commute.mul_geom_sum₂_Ico protected theorem Commute.geom_sum₂_succ_eq {α : Type u} [Ring α] {x y : α} (h : Commute x y) {n : ℕ} : ∑ i ∈ range (n + 1), x ^ i * y ^ (n - i) = x ^ n + y * ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i) := by simp_rw [mul_sum, sum_range_succ_comm, tsub_self, pow_zero, mul_one, add_right_inj, ← mul_assoc, (h.symm.pow_right _).eq, mul_assoc, ← pow_succ'] refine sum_congr rfl fun i hi => ?_ suffices n - 1 - i + 1 = n - i by rw [this] cases' n with n · exact absurd (List.mem_range.mp hi) i.not_lt_zero · rw [tsub_add_eq_add_tsub (Nat.le_sub_one_of_lt (List.mem_range.mp hi)), tsub_add_cancel_of_le (Nat.succ_le_iff.mpr n.succ_pos)] #align commute.geom_sum₂_succ_eq Commute.geom_sum₂_succ_eq theorem geom_sum₂_succ_eq {α : Type u} [CommRing α] (x y : α) {n : ℕ} : ∑ i ∈ range (n + 1), x ^ i * y ^ (n - i) = x ^ n + y * ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i) := (Commute.all x y).geom_sum₂_succ_eq #align geom_sum₂_succ_eq geom_sum₂_succ_eq theorem mul_geom_sum₂_Ico [CommRing α] (x y : α) {m n : ℕ} (hmn : m ≤ n) : ((x - y) * ∑ i ∈ Finset.Ico m n, x ^ i * y ^ (n - 1 - i)) = x ^ n - x ^ m * y ^ (n - m) := (Commute.all x y).mul_geom_sum₂_Ico hmn #align mul_geom_sum₂_Ico mul_geom_sum₂_Ico protected theorem Commute.geom_sum₂_Ico_mul [Ring α] {x y : α} (h : Commute x y) {m n : ℕ} (hmn : m ≤ n) : (∑ i ∈ Finset.Ico m n, x ^ i * y ^ (n - 1 - i)) * (x - y) = x ^ n - y ^ (n - m) * x ^ m := by apply op_injective simp only [op_sub, op_mul, op_pow, op_sum] have : (∑ k ∈ Ico m n, MulOpposite.op y ^ (n - 1 - k) * MulOpposite.op x ^ k) = ∑ k ∈ Ico m n, MulOpposite.op x ^ k * MulOpposite.op y ^ (n - 1 - k) := by refine sum_congr rfl fun k _ => ?_ have hp := Commute.pow_pow (Commute.op h.symm) (n - 1 - k) k simpa [Commute, SemiconjBy] using hp simp only [this] -- Porting note: gives deterministic timeout without this intermediate `have` convert (Commute.op h).mul_geom_sum₂_Ico hmn #align commute.geom_sum₂_Ico_mul Commute.geom_sum₂_Ico_mul theorem geom_sum_Ico_mul [Ring α] (x : α) {m n : ℕ} (hmn : m ≤ n) : (∑ i ∈ Finset.Ico m n, x ^ i) * (x - 1) = x ^ n - x ^ m := by rw [sum_Ico_eq_sub _ hmn, sub_mul, geom_sum_mul, geom_sum_mul, sub_sub_sub_cancel_right] #align geom_sum_Ico_mul geom_sum_Ico_mul theorem geom_sum_Ico_mul_neg [Ring α] (x : α) {m n : ℕ} (hmn : m ≤ n) : (∑ i ∈ Finset.Ico m n, x ^ i) * (1 - x) = x ^ m - x ^ n := by rw [sum_Ico_eq_sub _ hmn, sub_mul, geom_sum_mul_neg, geom_sum_mul_neg, sub_sub_sub_cancel_left] #align geom_sum_Ico_mul_neg geom_sum_Ico_mul_neg protected theorem Commute.geom_sum₂_Ico [DivisionRing α] {x y : α} (h : Commute x y) (hxy : x ≠ y) {m n : ℕ} (hmn : m ≤ n) : (∑ i ∈ Finset.Ico m n, x ^ i * y ^ (n - 1 - i)) = (x ^ n - y ^ (n - m) * x ^ m) / (x - y) := by have : x - y ≠ 0 := by simp_all [sub_eq_iff_eq_add] rw [← h.geom_sum₂_Ico_mul hmn, mul_div_cancel_right₀ _ this] #align commute.geom_sum₂_Ico Commute.geom_sum₂_Ico theorem geom_sum₂_Ico [Field α] {x y : α} (hxy : x ≠ y) {m n : ℕ} (hmn : m ≤ n) : (∑ i ∈ Finset.Ico m n, x ^ i * y ^ (n - 1 - i)) = (x ^ n - y ^ (n - m) * x ^ m) / (x - y) := (Commute.all x y).geom_sum₂_Ico hxy hmn #align geom_sum₂_Ico geom_sum₂_Ico theorem geom_sum_Ico [DivisionRing α] {x : α} (hx : x ≠ 1) {m n : ℕ} (hmn : m ≤ n) : ∑ i ∈ Finset.Ico m n, x ^ i = (x ^ n - x ^ m) / (x - 1) := by simp only [sum_Ico_eq_sub _ hmn, geom_sum_eq hx, div_sub_div_same, sub_sub_sub_cancel_right] #align geom_sum_Ico geom_sum_Ico theorem geom_sum_Ico' [DivisionRing α] {x : α} (hx : x ≠ 1) {m n : ℕ} (hmn : m ≤ n) : ∑ i ∈ Finset.Ico m n, x ^ i = (x ^ m - x ^ n) / (1 - x) := by simp only [geom_sum_Ico hx hmn] convert neg_div_neg_eq (x ^ m - x ^ n) (1 - x) using 2 <;> abel #align geom_sum_Ico' geom_sum_Ico'
Mathlib/Algebra/GeomSum.lean
375
384
theorem geom_sum_Ico_le_of_lt_one [LinearOrderedField α] {x : α} (hx : 0 ≤ x) (h'x : x < 1) {m n : ℕ} : ∑ i ∈ Ico m n, x ^ i ≤ x ^ m / (1 - x) := by
rcases le_or_lt m n with (hmn | hmn) · rw [geom_sum_Ico' h'x.ne hmn] apply div_le_div (pow_nonneg hx _) _ (sub_pos.2 h'x) le_rfl simpa using pow_nonneg hx _ · rw [Ico_eq_empty, sum_empty] · apply div_nonneg (pow_nonneg hx _) simpa using h'x.le · simpa using hmn.le
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Aaron Anderson, Yakov Pechersky -/ import Mathlib.Algebra.Group.Commute.Basic import Mathlib.Data.Fintype.Card import Mathlib.GroupTheory.Perm.Basic #align_import group_theory.perm.support from "leanprover-community/mathlib"@"9003f28797c0664a49e4179487267c494477d853" /-! # support of a permutation ## Main definitions In the following, `f g : Equiv.Perm α`. * `Equiv.Perm.Disjoint`: two permutations `f` and `g` are `Disjoint` if every element is fixed either by `f`, or by `g`. Equivalently, `f` and `g` are `Disjoint` iff their `support` are disjoint. * `Equiv.Perm.IsSwap`: `f = swap x y` for `x ≠ y`. * `Equiv.Perm.support`: the elements `x : α` that are not fixed by `f`. Assume `α` is a Fintype: * `Equiv.Perm.fixed_point_card_lt_of_ne_one f` says that `f` has strictly less than `Fintype.card α - 1` fixed points, unless `f = 1`. (Equivalently, `f.support` has at least 2 elements.) -/ open Equiv Finset namespace Equiv.Perm variable {α : Type*} section Disjoint /-- Two permutations `f` and `g` are `Disjoint` if their supports are disjoint, i.e., every element is fixed either by `f`, or by `g`. -/ def Disjoint (f g : Perm α) := ∀ x, f x = x ∨ g x = x #align equiv.perm.disjoint Equiv.Perm.Disjoint variable {f g h : Perm α} @[symm] theorem Disjoint.symm : Disjoint f g → Disjoint g f := by simp only [Disjoint, or_comm, imp_self] #align equiv.perm.disjoint.symm Equiv.Perm.Disjoint.symm theorem Disjoint.symmetric : Symmetric (@Disjoint α) := fun _ _ => Disjoint.symm #align equiv.perm.disjoint.symmetric Equiv.Perm.Disjoint.symmetric instance : IsSymm (Perm α) Disjoint := ⟨Disjoint.symmetric⟩ theorem disjoint_comm : Disjoint f g ↔ Disjoint g f := ⟨Disjoint.symm, Disjoint.symm⟩ #align equiv.perm.disjoint_comm Equiv.Perm.disjoint_comm theorem Disjoint.commute (h : Disjoint f g) : Commute f g := Equiv.ext fun x => (h x).elim (fun hf => (h (g x)).elim (fun hg => by simp [mul_apply, hf, hg]) fun hg => by simp [mul_apply, hf, g.injective hg]) fun hg => (h (f x)).elim (fun hf => by simp [mul_apply, f.injective hf, hg]) fun hf => by simp [mul_apply, hf, hg] #align equiv.perm.disjoint.commute Equiv.Perm.Disjoint.commute @[simp] theorem disjoint_one_left (f : Perm α) : Disjoint 1 f := fun _ => Or.inl rfl #align equiv.perm.disjoint_one_left Equiv.Perm.disjoint_one_left @[simp] theorem disjoint_one_right (f : Perm α) : Disjoint f 1 := fun _ => Or.inr rfl #align equiv.perm.disjoint_one_right Equiv.Perm.disjoint_one_right theorem disjoint_iff_eq_or_eq : Disjoint f g ↔ ∀ x : α, f x = x ∨ g x = x := Iff.rfl #align equiv.perm.disjoint_iff_eq_or_eq Equiv.Perm.disjoint_iff_eq_or_eq @[simp] theorem disjoint_refl_iff : Disjoint f f ↔ f = 1 := by refine ⟨fun h => ?_, fun h => h.symm ▸ disjoint_one_left 1⟩ ext x cases' h x with hx hx <;> simp [hx] #align equiv.perm.disjoint_refl_iff Equiv.Perm.disjoint_refl_iff theorem Disjoint.inv_left (h : Disjoint f g) : Disjoint f⁻¹ g := by intro x rw [inv_eq_iff_eq, eq_comm] exact h x #align equiv.perm.disjoint.inv_left Equiv.Perm.Disjoint.inv_left theorem Disjoint.inv_right (h : Disjoint f g) : Disjoint f g⁻¹ := h.symm.inv_left.symm #align equiv.perm.disjoint.inv_right Equiv.Perm.Disjoint.inv_right @[simp] theorem disjoint_inv_left_iff : Disjoint f⁻¹ g ↔ Disjoint f g := by refine ⟨fun h => ?_, Disjoint.inv_left⟩ convert h.inv_left #align equiv.perm.disjoint_inv_left_iff Equiv.Perm.disjoint_inv_left_iff @[simp] theorem disjoint_inv_right_iff : Disjoint f g⁻¹ ↔ Disjoint f g := by rw [disjoint_comm, disjoint_inv_left_iff, disjoint_comm] #align equiv.perm.disjoint_inv_right_iff Equiv.Perm.disjoint_inv_right_iff theorem Disjoint.mul_left (H1 : Disjoint f h) (H2 : Disjoint g h) : Disjoint (f * g) h := fun x => by cases H1 x <;> cases H2 x <;> simp [*] #align equiv.perm.disjoint.mul_left Equiv.Perm.Disjoint.mul_left theorem Disjoint.mul_right (H1 : Disjoint f g) (H2 : Disjoint f h) : Disjoint f (g * h) := by rw [disjoint_comm] exact H1.symm.mul_left H2.symm #align equiv.perm.disjoint.mul_right Equiv.Perm.Disjoint.mul_right -- Porting note (#11215): TODO: make it `@[simp]` theorem disjoint_conj (h : Perm α) : Disjoint (h * f * h⁻¹) (h * g * h⁻¹) ↔ Disjoint f g := (h⁻¹).forall_congr fun {_} ↦ by simp only [mul_apply, eq_inv_iff_eq] theorem Disjoint.conj (H : Disjoint f g) (h : Perm α) : Disjoint (h * f * h⁻¹) (h * g * h⁻¹) := (disjoint_conj h).2 H theorem disjoint_prod_right (l : List (Perm α)) (h : ∀ g ∈ l, Disjoint f g) : Disjoint f l.prod := by induction' l with g l ih · exact disjoint_one_right _ · rw [List.prod_cons] exact (h _ (List.mem_cons_self _ _)).mul_right (ih fun g hg => h g (List.mem_cons_of_mem _ hg)) #align equiv.perm.disjoint_prod_right Equiv.Perm.disjoint_prod_right open scoped List in theorem disjoint_prod_perm {l₁ l₂ : List (Perm α)} (hl : l₁.Pairwise Disjoint) (hp : l₁ ~ l₂) : l₁.prod = l₂.prod := hp.prod_eq' <| hl.imp Disjoint.commute #align equiv.perm.disjoint_prod_perm Equiv.Perm.disjoint_prod_perm theorem nodup_of_pairwise_disjoint {l : List (Perm α)} (h1 : (1 : Perm α) ∉ l) (h2 : l.Pairwise Disjoint) : l.Nodup := by refine List.Pairwise.imp_of_mem ?_ h2 intro τ σ h_mem _ h_disjoint _ subst τ suffices (σ : Perm α) = 1 by rw [this] at h_mem exact h1 h_mem exact ext fun a => or_self_iff.mp (h_disjoint a) #align equiv.perm.nodup_of_pairwise_disjoint Equiv.Perm.nodup_of_pairwise_disjoint theorem pow_apply_eq_self_of_apply_eq_self {x : α} (hfx : f x = x) : ∀ n : ℕ, (f ^ n) x = x | 0 => rfl | n + 1 => by rw [pow_succ, mul_apply, hfx, pow_apply_eq_self_of_apply_eq_self hfx n] #align equiv.perm.pow_apply_eq_self_of_apply_eq_self Equiv.Perm.pow_apply_eq_self_of_apply_eq_self theorem zpow_apply_eq_self_of_apply_eq_self {x : α} (hfx : f x = x) : ∀ n : ℤ, (f ^ n) x = x | (n : ℕ) => pow_apply_eq_self_of_apply_eq_self hfx n | Int.negSucc n => by rw [zpow_negSucc, inv_eq_iff_eq, pow_apply_eq_self_of_apply_eq_self hfx] #align equiv.perm.zpow_apply_eq_self_of_apply_eq_self Equiv.Perm.zpow_apply_eq_self_of_apply_eq_self theorem pow_apply_eq_of_apply_apply_eq_self {x : α} (hffx : f (f x) = x) : ∀ n : ℕ, (f ^ n) x = x ∨ (f ^ n) x = f x | 0 => Or.inl rfl | n + 1 => (pow_apply_eq_of_apply_apply_eq_self hffx n).elim (fun h => Or.inr (by rw [pow_succ', mul_apply, h])) fun h => Or.inl (by rw [pow_succ', mul_apply, h, hffx]) #align equiv.perm.pow_apply_eq_of_apply_apply_eq_self Equiv.Perm.pow_apply_eq_of_apply_apply_eq_self theorem zpow_apply_eq_of_apply_apply_eq_self {x : α} (hffx : f (f x) = x) : ∀ i : ℤ, (f ^ i) x = x ∨ (f ^ i) x = f x | (n : ℕ) => pow_apply_eq_of_apply_apply_eq_self hffx n | Int.negSucc n => by rw [zpow_negSucc, inv_eq_iff_eq, ← f.injective.eq_iff, ← mul_apply, ← pow_succ', eq_comm, inv_eq_iff_eq, ← mul_apply, ← pow_succ, @eq_comm _ x, or_comm] exact pow_apply_eq_of_apply_apply_eq_self hffx _ #align equiv.perm.zpow_apply_eq_of_apply_apply_eq_self Equiv.Perm.zpow_apply_eq_of_apply_apply_eq_self theorem Disjoint.mul_apply_eq_iff {σ τ : Perm α} (hστ : Disjoint σ τ) {a : α} : (σ * τ) a = a ↔ σ a = a ∧ τ a = a := by refine ⟨fun h => ?_, fun h => by rw [mul_apply, h.2, h.1]⟩ cases' hστ a with hσ hτ · exact ⟨hσ, σ.injective (h.trans hσ.symm)⟩ · exact ⟨(congr_arg σ hτ).symm.trans h, hτ⟩ #align equiv.perm.disjoint.mul_apply_eq_iff Equiv.Perm.Disjoint.mul_apply_eq_iff theorem Disjoint.mul_eq_one_iff {σ τ : Perm α} (hστ : Disjoint σ τ) : σ * τ = 1 ↔ σ = 1 ∧ τ = 1 := by simp_rw [ext_iff, one_apply, hστ.mul_apply_eq_iff, forall_and] #align equiv.perm.disjoint.mul_eq_one_iff Equiv.Perm.Disjoint.mul_eq_one_iff theorem Disjoint.zpow_disjoint_zpow {σ τ : Perm α} (hστ : Disjoint σ τ) (m n : ℤ) : Disjoint (σ ^ m) (τ ^ n) := fun x => Or.imp (fun h => zpow_apply_eq_self_of_apply_eq_self h m) (fun h => zpow_apply_eq_self_of_apply_eq_self h n) (hστ x) #align equiv.perm.disjoint.zpow_disjoint_zpow Equiv.Perm.Disjoint.zpow_disjoint_zpow theorem Disjoint.pow_disjoint_pow {σ τ : Perm α} (hστ : Disjoint σ τ) (m n : ℕ) : Disjoint (σ ^ m) (τ ^ n) := hστ.zpow_disjoint_zpow m n #align equiv.perm.disjoint.pow_disjoint_pow Equiv.Perm.Disjoint.pow_disjoint_pow end Disjoint section IsSwap variable [DecidableEq α] /-- `f.IsSwap` indicates that the permutation `f` is a transposition of two elements. -/ def IsSwap (f : Perm α) : Prop := ∃ x y, x ≠ y ∧ f = swap x y #align equiv.perm.is_swap Equiv.Perm.IsSwap @[simp] theorem ofSubtype_swap_eq {p : α → Prop} [DecidablePred p] (x y : Subtype p) : ofSubtype (Equiv.swap x y) = Equiv.swap ↑x ↑y := Equiv.ext fun z => by by_cases hz : p z · rw [swap_apply_def, ofSubtype_apply_of_mem _ hz] split_ifs with hzx hzy · simp_rw [hzx, Subtype.coe_eta, swap_apply_left] · simp_rw [hzy, Subtype.coe_eta, swap_apply_right] · rw [swap_apply_of_ne_of_ne] <;> simp [Subtype.ext_iff, *] · rw [ofSubtype_apply_of_not_mem _ hz, swap_apply_of_ne_of_ne] · intro h apply hz rw [h] exact Subtype.prop x intro h apply hz rw [h] exact Subtype.prop y #align equiv.perm.of_subtype_swap_eq Equiv.Perm.ofSubtype_swap_eq theorem IsSwap.of_subtype_isSwap {p : α → Prop} [DecidablePred p] {f : Perm (Subtype p)} (h : f.IsSwap) : (ofSubtype f).IsSwap := let ⟨⟨x, hx⟩, ⟨y, hy⟩, hxy⟩ := h ⟨x, y, by simp only [Ne, Subtype.ext_iff] at hxy exact hxy.1, by rw [hxy.2, ofSubtype_swap_eq]⟩ #align equiv.perm.is_swap.of_subtype_is_swap Equiv.Perm.IsSwap.of_subtype_isSwap theorem ne_and_ne_of_swap_mul_apply_ne_self {f : Perm α} {x y : α} (hy : (swap x (f x) * f) y ≠ y) : f y ≠ y ∧ y ≠ x := by simp only [swap_apply_def, mul_apply, f.injective.eq_iff] at * by_cases h : f y = x · constructor <;> intro <;> simp_all only [if_true, eq_self_iff_true, not_true, Ne] · split_ifs at hy with h h <;> try { simp [*] at * } #align equiv.perm.ne_and_ne_of_swap_mul_apply_ne_self Equiv.Perm.ne_and_ne_of_swap_mul_apply_ne_self end IsSwap section support section Set variable (p q : Perm α) theorem set_support_inv_eq : { x | p⁻¹ x ≠ x } = { x | p x ≠ x } := by ext x simp only [Set.mem_setOf_eq, Ne] rw [inv_def, symm_apply_eq, eq_comm] #align equiv.perm.set_support_inv_eq Equiv.Perm.set_support_inv_eq theorem set_support_apply_mem {p : Perm α} {a : α} : p a ∈ { x | p x ≠ x } ↔ a ∈ { x | p x ≠ x } := by simp #align equiv.perm.set_support_apply_mem Equiv.Perm.set_support_apply_mem theorem set_support_zpow_subset (n : ℤ) : { x | (p ^ n) x ≠ x } ⊆ { x | p x ≠ x } := by intro x simp only [Set.mem_setOf_eq, Ne] intro hx H simp [zpow_apply_eq_self_of_apply_eq_self H] at hx #align equiv.perm.set_support_zpow_subset Equiv.Perm.set_support_zpow_subset theorem set_support_mul_subset : { x | (p * q) x ≠ x } ⊆ { x | p x ≠ x } ∪ { x | q x ≠ x } := by intro x simp only [Perm.coe_mul, Function.comp_apply, Ne, Set.mem_union, Set.mem_setOf_eq] by_cases hq : q x = x <;> simp [hq] #align equiv.perm.set_support_mul_subset Equiv.Perm.set_support_mul_subset end Set variable [DecidableEq α] [Fintype α] {f g : Perm α} /-- The `Finset` of nonfixed points of a permutation. -/ def support (f : Perm α) : Finset α := univ.filter fun x => f x ≠ x #align equiv.perm.support Equiv.Perm.support @[simp] theorem mem_support {x : α} : x ∈ f.support ↔ f x ≠ x := by rw [support, mem_filter, and_iff_right (mem_univ x)] #align equiv.perm.mem_support Equiv.Perm.mem_support theorem not_mem_support {x : α} : x ∉ f.support ↔ f x = x := by simp #align equiv.perm.not_mem_support Equiv.Perm.not_mem_support theorem coe_support_eq_set_support (f : Perm α) : (f.support : Set α) = { x | f x ≠ x } := by ext simp #align equiv.perm.coe_support_eq_set_support Equiv.Perm.coe_support_eq_set_support @[simp]
Mathlib/GroupTheory/Perm/Support.lean
310
312
theorem support_eq_empty_iff {σ : Perm α} : σ.support = ∅ ↔ σ = 1 := by
simp_rw [Finset.ext_iff, mem_support, Finset.not_mem_empty, iff_false_iff, not_not, Equiv.Perm.ext_iff, one_apply]
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Algebra.Polynomial.Degree.Definitions import Mathlib.Algebra.Polynomial.Induction #align_import data.polynomial.eval from "leanprover-community/mathlib"@"728baa2f54e6062c5879a3e397ac6bac323e506f" /-! # Theory of univariate polynomials The main defs here are `eval₂`, `eval`, and `map`. We give several lemmas about their interaction with each other and with module operations. -/ set_option linter.uppercaseLean3 false noncomputable section open Finset AddMonoidAlgebra open Polynomial namespace Polynomial universe u v w y variable {R : Type u} {S : Type v} {T : Type w} {ι : Type y} {a b : R} {m n : ℕ} section Semiring variable [Semiring R] {p q r : R[X]} section variable [Semiring S] variable (f : R →+* S) (x : S) /-- Evaluate a polynomial `p` given a ring hom `f` from the scalar ring to the target and a value `x` for the variable in the target -/ irreducible_def eval₂ (p : R[X]) : S := p.sum fun e a => f a * x ^ e #align polynomial.eval₂ Polynomial.eval₂ theorem eval₂_eq_sum {f : R →+* S} {x : S} : p.eval₂ f x = p.sum fun e a => f a * x ^ e := by rw [eval₂_def] #align polynomial.eval₂_eq_sum Polynomial.eval₂_eq_sum theorem eval₂_congr {R S : Type*} [Semiring R] [Semiring S] {f g : R →+* S} {s t : S} {φ ψ : R[X]} : f = g → s = t → φ = ψ → eval₂ f s φ = eval₂ g t ψ := by rintro rfl rfl rfl; rfl #align polynomial.eval₂_congr Polynomial.eval₂_congr @[simp] theorem eval₂_at_zero : p.eval₂ f 0 = f (coeff p 0) := by simp (config := { contextual := true }) only [eval₂_eq_sum, zero_pow_eq, mul_ite, mul_zero, mul_one, sum, Classical.not_not, mem_support_iff, sum_ite_eq', ite_eq_left_iff, RingHom.map_zero, imp_true_iff, eq_self_iff_true] #align polynomial.eval₂_at_zero Polynomial.eval₂_at_zero @[simp] theorem eval₂_zero : (0 : R[X]).eval₂ f x = 0 := by simp [eval₂_eq_sum] #align polynomial.eval₂_zero Polynomial.eval₂_zero @[simp] theorem eval₂_C : (C a).eval₂ f x = f a := by simp [eval₂_eq_sum] #align polynomial.eval₂_C Polynomial.eval₂_C @[simp] theorem eval₂_X : X.eval₂ f x = x := by simp [eval₂_eq_sum] #align polynomial.eval₂_X Polynomial.eval₂_X @[simp] theorem eval₂_monomial {n : ℕ} {r : R} : (monomial n r).eval₂ f x = f r * x ^ n := by simp [eval₂_eq_sum] #align polynomial.eval₂_monomial Polynomial.eval₂_monomial @[simp] theorem eval₂_X_pow {n : ℕ} : (X ^ n).eval₂ f x = x ^ n := by rw [X_pow_eq_monomial] convert eval₂_monomial f x (n := n) (r := 1) simp #align polynomial.eval₂_X_pow Polynomial.eval₂_X_pow @[simp] theorem eval₂_add : (p + q).eval₂ f x = p.eval₂ f x + q.eval₂ f x := by simp only [eval₂_eq_sum] apply sum_add_index <;> simp [add_mul] #align polynomial.eval₂_add Polynomial.eval₂_add @[simp] theorem eval₂_one : (1 : R[X]).eval₂ f x = 1 := by rw [← C_1, eval₂_C, f.map_one] #align polynomial.eval₂_one Polynomial.eval₂_one set_option linter.deprecated false in @[simp] theorem eval₂_bit0 : (bit0 p).eval₂ f x = bit0 (p.eval₂ f x) := by rw [bit0, eval₂_add, bit0] #align polynomial.eval₂_bit0 Polynomial.eval₂_bit0 set_option linter.deprecated false in @[simp]
Mathlib/Algebra/Polynomial/Eval.lean
105
106
theorem eval₂_bit1 : (bit1 p).eval₂ f x = bit1 (p.eval₂ f x) := by
rw [bit1, eval₂_add, eval₂_bit0, eval₂_one, bit1]
/- 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.Basic import Mathlib.Topology.Algebra.UniformGroup /-! # Infinite sums and products in topological groups Lemmas on topological sums in groups (as opposed to monoids). -/ noncomputable section open Filter Finset Function open scoped Topology variable {α β γ δ : Type*} section TopologicalGroup variable [CommGroup α] [TopologicalSpace α] [TopologicalGroup α] variable {f g : β → α} {a a₁ a₂ : α} -- `by simpa using` speeds up elaboration. Why? @[to_additive] theorem HasProd.inv (h : HasProd f a) : HasProd (fun b ↦ (f b)⁻¹) a⁻¹ := by simpa only using h.map (MonoidHom.id α)⁻¹ continuous_inv #align has_sum.neg HasSum.neg @[to_additive] theorem Multipliable.inv (hf : Multipliable f) : Multipliable fun b ↦ (f b)⁻¹ := hf.hasProd.inv.multipliable #align summable.neg Summable.neg @[to_additive] theorem Multipliable.of_inv (hf : Multipliable fun b ↦ (f b)⁻¹) : Multipliable f := by simpa only [inv_inv] using hf.inv #align summable.of_neg Summable.of_neg @[to_additive] theorem multipliable_inv_iff : (Multipliable fun b ↦ (f b)⁻¹) ↔ Multipliable f := ⟨Multipliable.of_inv, Multipliable.inv⟩ #align summable_neg_iff summable_neg_iff @[to_additive] theorem HasProd.div (hf : HasProd f a₁) (hg : HasProd g a₂) : HasProd (fun b ↦ f b / g b) (a₁ / a₂) := by simp only [div_eq_mul_inv] exact hf.mul hg.inv #align has_sum.sub HasSum.sub @[to_additive] theorem Multipliable.div (hf : Multipliable f) (hg : Multipliable g) : Multipliable fun b ↦ f b / g b := (hf.hasProd.div hg.hasProd).multipliable #align summable.sub Summable.sub @[to_additive] theorem Multipliable.trans_div (hg : Multipliable g) (hfg : Multipliable fun b ↦ f b / g b) : Multipliable f := by simpa only [div_mul_cancel] using hfg.mul hg #align summable.trans_sub Summable.trans_sub @[to_additive] theorem multipliable_iff_of_multipliable_div (hfg : Multipliable fun b ↦ f b / g b) : Multipliable f ↔ Multipliable g := ⟨fun hf ↦ hf.trans_div <| by simpa only [inv_div] using hfg.inv, fun hg ↦ hg.trans_div hfg⟩ #align summable_iff_of_summable_sub summable_iff_of_summable_sub @[to_additive] theorem HasProd.update (hf : HasProd f a₁) (b : β) [DecidableEq β] (a : α) : HasProd (update f b a) (a / f b * a₁) := by convert (hasProd_ite_eq b (a / f b)).mul hf with b' by_cases h : b' = b · rw [h, update_same] simp [eq_self_iff_true, if_true, sub_add_cancel] · simp only [h, update_noteq, if_false, Ne, one_mul, not_false_iff] #align has_sum.update HasSum.update @[to_additive] theorem Multipliable.update (hf : Multipliable f) (b : β) [DecidableEq β] (a : α) : Multipliable (update f b a) := (hf.hasProd.update b a).multipliable #align summable.update Summable.update @[to_additive] theorem HasProd.hasProd_compl_iff {s : Set β} (hf : HasProd (f ∘ (↑) : s → α) a₁) : HasProd (f ∘ (↑) : ↑sᶜ → α) a₂ ↔ HasProd f (a₁ * a₂) := by refine ⟨fun h ↦ hf.mul_compl h, fun h ↦ ?_⟩ rw [hasProd_subtype_iff_mulIndicator] at hf ⊢ rw [Set.mulIndicator_compl] simpa only [div_eq_mul_inv, mul_inv_cancel_comm] using h.div hf #align has_sum.has_sum_compl_iff HasSum.hasSum_compl_iff @[to_additive] theorem HasProd.hasProd_iff_compl {s : Set β} (hf : HasProd (f ∘ (↑) : s → α) a₁) : HasProd f a₂ ↔ HasProd (f ∘ (↑) : ↑sᶜ → α) (a₂ / a₁) := Iff.symm <| hf.hasProd_compl_iff.trans <| by rw [mul_div_cancel] #align has_sum.has_sum_iff_compl HasSum.hasSum_iff_compl @[to_additive] theorem Multipliable.multipliable_compl_iff {s : Set β} (hf : Multipliable (f ∘ (↑) : s → α)) : Multipliable (f ∘ (↑) : ↑sᶜ → α) ↔ Multipliable f where mp := fun ⟨_, ha⟩ ↦ (hf.hasProd.hasProd_compl_iff.1 ha).multipliable mpr := fun ⟨_, ha⟩ ↦ (hf.hasProd.hasProd_iff_compl.1 ha).multipliable #align summable.summable_compl_iff Summable.summable_compl_iff @[to_additive] protected theorem Finset.hasProd_compl_iff (s : Finset β) : HasProd (fun x : { x // x ∉ s } ↦ f x) a ↔ HasProd f (a * ∏ i ∈ s, f i) := (s.hasProd f).hasProd_compl_iff.trans <| by rw [mul_comm] #align finset.has_sum_compl_iff Finset.hasSum_compl_iff @[to_additive] protected theorem Finset.hasProd_iff_compl (s : Finset β) : HasProd f a ↔ HasProd (fun x : { x // x ∉ s } ↦ f x) (a / ∏ i ∈ s, f i) := (s.hasProd f).hasProd_iff_compl #align finset.has_sum_iff_compl Finset.hasSum_iff_compl @[to_additive] protected theorem Finset.multipliable_compl_iff (s : Finset β) : (Multipliable fun x : { x // x ∉ s } ↦ f x) ↔ Multipliable f := (s.multipliable f).multipliable_compl_iff #align finset.summable_compl_iff Finset.summable_compl_iff @[to_additive] theorem Set.Finite.multipliable_compl_iff {s : Set β} (hs : s.Finite) : Multipliable (f ∘ (↑) : ↑sᶜ → α) ↔ Multipliable f := (hs.multipliable f).multipliable_compl_iff #align set.finite.summable_compl_iff Set.Finite.summable_compl_iff @[to_additive]
Mathlib/Topology/Algebra/InfiniteSum/Group.lean
137
142
theorem hasProd_ite_div_hasProd [DecidableEq β] (hf : HasProd f a) (b : β) : HasProd (fun n ↦ ite (n = b) 1 (f n)) (a / f b) := by
convert hf.update b 1 using 1 · ext n rw [Function.update_apply] · rw [div_mul_eq_mul_div, one_mul]
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor import Mathlib.CategoryTheory.Monoidal.Functor #align_import category_theory.monoidal.preadditive from "leanprover-community/mathlib"@"986c4d5761f938b2e1c43c01f001b6d9d88c2055" /-! # Preadditive monoidal categories A monoidal category is `MonoidalPreadditive` if it is preadditive and tensor product of morphisms is linear in both factors. -/ noncomputable section open scoped Classical namespace CategoryTheory open CategoryTheory.Limits open CategoryTheory.MonoidalCategory variable (C : Type*) [Category C] [Preadditive C] [MonoidalCategory C] /-- A category is `MonoidalPreadditive` if tensoring is additive in both factors. Note we don't `extend Preadditive C` here, as `Abelian C` already extends it, and we'll need to have both typeclasses sometimes. -/ class MonoidalPreadditive : Prop where whiskerLeft_zero : ∀ {X Y Z : C}, X ◁ (0 : Y ⟶ Z) = 0 := by aesop_cat zero_whiskerRight : ∀ {X Y Z : C}, (0 : Y ⟶ Z) ▷ X = 0 := by aesop_cat whiskerLeft_add : ∀ {X Y Z : C} (f g : Y ⟶ Z), X ◁ (f + g) = X ◁ f + X ◁ g := by aesop_cat add_whiskerRight : ∀ {X Y Z : C} (f g : Y ⟶ Z), (f + g) ▷ X = f ▷ X + g ▷ X := by aesop_cat #align category_theory.monoidal_preadditive CategoryTheory.MonoidalPreadditive attribute [simp] MonoidalPreadditive.whiskerLeft_zero MonoidalPreadditive.zero_whiskerRight attribute [simp] MonoidalPreadditive.whiskerLeft_add MonoidalPreadditive.add_whiskerRight variable {C} variable [MonoidalPreadditive C] namespace MonoidalPreadditive -- The priority setting will not be needed when we replace `𝟙 X ⊗ f` by `X ◁ f`. @[simp (low)] theorem tensor_zero {W X Y Z : C} (f : W ⟶ X) : f ⊗ (0 : Y ⟶ Z) = 0 := by simp [tensorHom_def] -- The priority setting will not be needed when we replace `f ⊗ 𝟙 X` by `f ▷ X`. @[simp (low)] theorem zero_tensor {W X Y Z : C} (f : Y ⟶ Z) : (0 : W ⟶ X) ⊗ f = 0 := by simp [tensorHom_def] theorem tensor_add {W X Y Z : C} (f : W ⟶ X) (g h : Y ⟶ Z) : f ⊗ (g + h) = f ⊗ g + f ⊗ h := by simp [tensorHom_def] theorem add_tensor {W X Y Z : C} (f g : W ⟶ X) (h : Y ⟶ Z) : (f + g) ⊗ h = f ⊗ h + g ⊗ h := by simp [tensorHom_def] end MonoidalPreadditive instance tensorLeft_additive (X : C) : (tensorLeft X).Additive where #align category_theory.tensor_left_additive CategoryTheory.tensorLeft_additive instance tensorRight_additive (X : C) : (tensorRight X).Additive where #align category_theory.tensor_right_additive CategoryTheory.tensorRight_additive instance tensoringLeft_additive (X : C) : ((tensoringLeft C).obj X).Additive where #align category_theory.tensoring_left_additive CategoryTheory.tensoringLeft_additive instance tensoringRight_additive (X : C) : ((tensoringRight C).obj X).Additive where #align category_theory.tensoring_right_additive CategoryTheory.tensoringRight_additive /-- A faithful additive monoidal functor to a monoidal preadditive category ensures that the domain is monoidal preadditive. -/ theorem monoidalPreadditive_of_faithful {D} [Category D] [Preadditive D] [MonoidalCategory D] (F : MonoidalFunctor D C) [F.Faithful] [F.Additive] : MonoidalPreadditive D := { whiskerLeft_zero := by intros apply F.toFunctor.map_injective simp [F.map_whiskerLeft] zero_whiskerRight := by intros apply F.toFunctor.map_injective simp [F.map_whiskerRight] whiskerLeft_add := by intros apply F.toFunctor.map_injective simp only [F.map_whiskerLeft, Functor.map_add, Preadditive.comp_add, Preadditive.add_comp, MonoidalPreadditive.whiskerLeft_add] add_whiskerRight := by intros apply F.toFunctor.map_injective simp only [F.map_whiskerRight, Functor.map_add, Preadditive.comp_add, Preadditive.add_comp, MonoidalPreadditive.add_whiskerRight] } #align category_theory.monoidal_preadditive_of_faithful CategoryTheory.monoidalPreadditive_of_faithful theorem whiskerLeft_sum (P : C) {Q R : C} {J : Type*} (s : Finset J) (g : J → (Q ⟶ R)) : P ◁ ∑ j ∈ s, g j = ∑ j ∈ s, P ◁ g j := map_sum ((tensoringLeft C).obj P).mapAddHom g s theorem sum_whiskerRight {Q R : C} {J : Type*} (s : Finset J) (g : J → (Q ⟶ R)) (P : C) : (∑ j ∈ s, g j) ▷ P = ∑ j ∈ s, g j ▷ P := map_sum ((tensoringRight C).obj P).mapAddHom g s theorem tensor_sum {P Q R S : C} {J : Type*} (s : Finset J) (f : P ⟶ Q) (g : J → (R ⟶ S)) : (f ⊗ ∑ j ∈ s, g j) = ∑ j ∈ s, f ⊗ g j := by simp only [tensorHom_def, whiskerLeft_sum, Preadditive.comp_sum] #align category_theory.tensor_sum CategoryTheory.tensor_sum theorem sum_tensor {P Q R S : C} {J : Type*} (s : Finset J) (f : P ⟶ Q) (g : J → (R ⟶ S)) : (∑ j ∈ s, g j) ⊗ f = ∑ j ∈ s, g j ⊗ f := by simp only [tensorHom_def, sum_whiskerRight, Preadditive.sum_comp] #align category_theory.sum_tensor CategoryTheory.sum_tensor -- In a closed monoidal category, this would hold because -- `tensorLeft X` is a left adjoint and hence preserves all colimits. -- In any case it is true in any preadditive category. instance (X : C) : PreservesFiniteBiproducts (tensorLeft X) where preserves {J} := { preserves := fun {f} => { preserves := fun {b} i => isBilimitOfTotal _ (by dsimp simp_rw [← id_tensorHom] simp only [← tensor_comp, Category.comp_id, ← tensor_sum, ← tensor_id, IsBilimit.total i]) } } instance (X : C) : PreservesFiniteBiproducts (tensorRight X) where preserves {J} := { preserves := fun {f} => { preserves := fun {b} i => isBilimitOfTotal _ (by dsimp simp_rw [← tensorHom_id] simp only [← tensor_comp, Category.comp_id, ← sum_tensor, ← tensor_id, IsBilimit.total i]) } } variable [HasFiniteBiproducts C] /-- The isomorphism showing how tensor product on the left distributes over direct sums. -/ def leftDistributor {J : Type} [Fintype J] (X : C) (f : J → C) : X ⊗ ⨁ f ≅ ⨁ fun j => X ⊗ f j := (tensorLeft X).mapBiproduct f #align category_theory.left_distributor CategoryTheory.leftDistributor theorem leftDistributor_hom {J : Type} [Fintype J] (X : C) (f : J → C) : (leftDistributor X f).hom = ∑ j : J, (X ◁ biproduct.π f j) ≫ biproduct.ι (fun j => X ⊗ f j) j := by ext dsimp [leftDistributor, Functor.mapBiproduct, Functor.mapBicone] erw [biproduct.lift_π] simp only [Preadditive.sum_comp, Category.assoc, biproduct.ι_π, comp_dite, comp_zero, Finset.sum_dite_eq', Finset.mem_univ, ite_true, eqToHom_refl, Category.comp_id] #align category_theory.left_distributor_hom CategoryTheory.leftDistributor_hom theorem leftDistributor_inv {J : Type} [Fintype J] (X : C) (f : J → C) : (leftDistributor X f).inv = ∑ j : J, biproduct.π _ j ≫ (X ◁ biproduct.ι f j) := by ext dsimp [leftDistributor, Functor.mapBiproduct, Functor.mapBicone] simp only [Preadditive.comp_sum, biproduct.ι_π_assoc, dite_comp, zero_comp, Finset.sum_dite_eq, Finset.mem_univ, ite_true, eqToHom_refl, Category.id_comp, biproduct.ι_desc] #align category_theory.left_distributor_inv CategoryTheory.leftDistributor_inv @[reassoc (attr := simp)] theorem leftDistributor_hom_comp_biproduct_π {J : Type} [Fintype J] (X : C) (f : J → C) (j : J) : (leftDistributor X f).hom ≫ biproduct.π _ j = X ◁ biproduct.π _ j := by simp [leftDistributor_hom, Preadditive.sum_comp, biproduct.ι_π, comp_dite] @[reassoc (attr := simp)] theorem biproduct_ι_comp_leftDistributor_hom {J : Type} [Fintype J] (X : C) (f : J → C) (j : J) : (X ◁ biproduct.ι _ j) ≫ (leftDistributor X f).hom = biproduct.ι (fun j => X ⊗ f j) j := by simp [leftDistributor_hom, Preadditive.comp_sum, ← MonoidalCategory.whiskerLeft_comp_assoc, biproduct.ι_π, whiskerLeft_dite, dite_comp] @[reassoc (attr := simp)]
Mathlib/CategoryTheory/Monoidal/Preadditive.lean
182
185
theorem leftDistributor_inv_comp_biproduct_π {J : Type} [Fintype J] (X : C) (f : J → C) (j : J) : (leftDistributor X f).inv ≫ (X ◁ biproduct.π _ j) = biproduct.π _ j := by
simp [leftDistributor_inv, Preadditive.sum_comp, ← MonoidalCategory.whiskerLeft_comp, biproduct.ι_π, whiskerLeft_dite, comp_dite]
/- Copyright (c) 2024 Judith Ludwig, Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Judith Ludwig, Christian Merten -/ import Mathlib.RingTheory.AdicCompletion.Basic import Mathlib.RingTheory.AdicCompletion.Algebra import Mathlib.Algebra.DirectSum.Basic /-! # Functoriality of adic completions In this file we establish functorial properties of the adic completion. ## Main definitions - `LinearMap.adicCauchy I f`: the linear map on `I`-adic cauchy sequences induced by `f` - `LinearMap.adicCompletion I f`: the linear map on `I`-adic completions induced by `f` ## Main results - `sumEquivOfFintype`: adic completion commutes with finite sums - `piEquivOfFintype`: adic completion commutes with finite products -/ variable {R : Type*} [CommRing R] (I : Ideal R) variable {M : Type*} [AddCommGroup M] [Module R M] variable {N : Type*} [AddCommGroup N] [Module R N] variable {P : Type*} [AddCommGroup P] [Module R P] variable {T : Type*} [AddCommGroup T] [Module (AdicCompletion I R) T] namespace LinearMap /-- `R`-linear version of `reduceModIdeal`. -/ private def reduceModIdealAux (f : M →ₗ[R] N) : M ⧸ (I • ⊤ : Submodule R M) →ₗ[R] N ⧸ (I • ⊤ : Submodule R N) := Submodule.mapQ (I • ⊤ : Submodule R M) (I • ⊤ : Submodule R N) f (fun x hx ↦ by refine Submodule.smul_induction_on hx (fun r hr x _ ↦ ?_) (fun x y hx hy ↦ ?_) · simp [Submodule.smul_mem_smul hr Submodule.mem_top] · simp [Submodule.add_mem _ hx hy]) @[local simp] private theorem reduceModIdealAux_apply (f : M →ₗ[R] N) (x : M) : (f.reduceModIdealAux I) (Submodule.Quotient.mk (p := (I • ⊤ : Submodule R M)) x) = Submodule.Quotient.mk (p := (I • ⊤ : Submodule R N)) (f x) := rfl /-- The induced linear map on the quotients mod `I • ⊤`. -/ def reduceModIdeal (f : M →ₗ[R] N) : M ⧸ (I • ⊤ : Submodule R M) →ₗ[R ⧸ I] N ⧸ (I • ⊤ : Submodule R N) where toFun := f.reduceModIdealAux I map_add' := by simp map_smul' r x := by refine Quotient.inductionOn' r (fun r ↦ ?_) refine Quotient.inductionOn' x (fun x ↦ ?_) simp only [Submodule.Quotient.mk''_eq_mk, Ideal.Quotient.mk_eq_mk, Module.Quotient.mk_smul_mk, Submodule.Quotient.mk_smul, LinearMapClass.map_smul, reduceModIdealAux_apply] rfl @[simp] theorem reduceModIdeal_apply (f : M →ₗ[R] N) (x : M) : (f.reduceModIdeal I) (Submodule.Quotient.mk (p := (I • ⊤ : Submodule R M)) x) = Submodule.Quotient.mk (p := (I • ⊤ : Submodule R N)) (f x) := rfl end LinearMap namespace AdicCompletion open LinearMap theorem transitionMap_comp_reduceModIdeal (f : M →ₗ[R] N) {m n : ℕ} (hmn : m ≤ n) : transitionMap I N hmn ∘ₗ f.reduceModIdeal (I ^ n) = (f.reduceModIdeal (I ^ m) : _ →ₗ[R] _) ∘ₗ transitionMap I M hmn := by ext x simp namespace AdicCauchySequence /-- A linear map induces a linear map on adic cauchy sequences. -/ @[simps] def map (f : M →ₗ[R] N) : AdicCauchySequence I M →ₗ[R] AdicCauchySequence I N where toFun a := ⟨fun n ↦ f (a n), fun {m n} hmn ↦ by have hm : Submodule.map f (I ^ m • ⊤ : Submodule R M) ≤ (I ^ m • ⊤ : Submodule R N) := by rw [Submodule.map_smul''] exact smul_mono_right _ le_top apply SModEq.mono hm apply SModEq.map (a.property hmn) f⟩ map_add' a b := by ext n; simp map_smul' r a := by ext n; simp variable (M) in @[simp] theorem map_id : map I (LinearMap.id (M := M)) = LinearMap.id := rfl theorem map_comp (f : M →ₗ[R] N) (g : N →ₗ[R] P) : map I g ∘ₗ map I f = map I (g ∘ₗ f) := rfl theorem map_comp_apply (f : M →ₗ[R] N) (g : N →ₗ[R] P) (a : AdicCauchySequence I M) : map I g (map I f a) = map I (g ∘ₗ f) a := rfl end AdicCauchySequence /-- `R`-linear version of `adicCompletion`. -/ private def adicCompletionAux (f : M →ₗ[R] N) : AdicCompletion I M →ₗ[R] AdicCompletion I N := AdicCompletion.lift I (fun n ↦ reduceModIdeal (I ^ n) f ∘ₗ AdicCompletion.eval I M n) (fun {m n} hmn ↦ by rw [← comp_assoc, AdicCompletion.transitionMap_comp_reduceModIdeal, comp_assoc, transitionMap_comp_eval]) @[local simp] private theorem adicCompletionAux_val_apply (f : M →ₗ[R] N) {n : ℕ} (x : AdicCompletion I M) : (adicCompletionAux I f x).val n = f.reduceModIdeal (I ^ n) (x.val n) := rfl /-- A linear map induces a map on adic completions. -/ def map (f : M →ₗ[R] N) : AdicCompletion I M →ₗ[AdicCompletion I R] AdicCompletion I N where toFun := adicCompletionAux I f map_add' := by aesop map_smul' r x := by ext n simp only [adicCompletionAux_val_apply, smul_eval, smul_eq_mul, RingHom.id_apply] rw [val_smul_eq_evalₐ_smul, val_smul_eq_evalₐ_smul, map_smul] @[simp] theorem map_val_apply (f : M →ₗ[R] N) {n : ℕ} (x : AdicCompletion I M) : (map I f x).val n = f.reduceModIdeal (I ^ n) (x.val n) := rfl /-- Equality of maps out of an adic completion can be checked on Cauchy sequences. -/ theorem map_ext {f g : AdicCompletion I M → N} (h : ∀ (a : AdicCauchySequence I M), f (AdicCompletion.mk I M a) = g (AdicCompletion.mk I M a)) : f = g := by ext x apply induction_on I M x (fun a ↦ h a) /-- Equality of linear maps out of an adic completion can be checked on Cauchy sequences. -/ @[ext] theorem map_ext' {f g : AdicCompletion I M →ₗ[AdicCompletion I R] T} (h : ∀ (a : AdicCauchySequence I M), f (AdicCompletion.mk I M a) = g (AdicCompletion.mk I M a)) : f = g := by ext x apply induction_on I M x (fun a ↦ h a) /-- Equality of linear maps out of an adic completion can be checked on Cauchy sequences. -/ @[ext] theorem map_ext'' {f g : AdicCompletion I M →ₗ[R] N} (h : f.comp (AdicCompletion.mk I M) = g.comp (AdicCompletion.mk I M)) : f = g := by ext x apply induction_on I M x (fun a ↦ LinearMap.ext_iff.mp h a) variable (M) in @[simp] theorem map_id : map I (LinearMap.id (M := M)) = LinearMap.id (R := AdicCompletion I R) (M := AdicCompletion I M) := by ext a n simp theorem map_comp (f : M →ₗ[R] N) (g : N →ₗ[R] P) : map I g ∘ₗ map I f = map I (g ∘ₗ f) := by ext simp theorem map_comp_apply (f : M →ₗ[R] N) (g : N →ₗ[R] P) (x : AdicCompletion I M) : map I g (map I f x) = map I (g ∘ₗ f) x := by show (map I g ∘ₗ map I f) x = map I (g ∘ₗ f) x rw [map_comp] @[simp] theorem map_mk (f : M →ₗ[R] N) (a : AdicCauchySequence I M) : map I f (AdicCompletion.mk I M a) = AdicCompletion.mk I N (AdicCauchySequence.map I f a) := rfl @[simp] theorem val_sum {α : Type*} (s : Finset α) (f : α → AdicCompletion I M) (n : ℕ) : (Finset.sum s f).val n = Finset.sum s (fun a ↦ (f a).val n) := by change (Submodule.subtype (AdicCompletion.submodule I M) _) n = _ rw [map_sum, Finset.sum_apply, Submodule.coeSubtype] /-- A linear equiv induces a linear equiv on adic completions. -/ def congr (f : M ≃ₗ[R] N) : AdicCompletion I M ≃ₗ[AdicCompletion I R] AdicCompletion I N := LinearEquiv.ofLinear (map I f) (map I f.symm) (by simp [map_comp]) (by simp [map_comp]) @[simp] theorem congr_apply (f : M ≃ₗ[R] N) (x : AdicCompletion I M) : congr I f x = map I f x := rfl @[simp] theorem congr_symm_apply (f : M ≃ₗ[R] N) (x : AdicCompletion I N) : (congr I f).symm x = map I f.symm x := rfl section Families /-! ### Adic completion in families In this section we consider a family `M : ι → Type*` of `R`-modules. Purely from the formal properties of adic completions we obtain two canonical maps - `AdicCompleiton I (∀ j, M j) →ₗ[R] ∀ j, AdicCompletion I (M j)` - `(⨁ j, (AdicCompletion I (M j))) →ₗ[R] AdicCompletion I (⨁ j, M j)` If `ι` is finite, both are isomorphisms and, modulo the equivalence `⨁ j, (AdicCompletion I (M j)` and `∀ j, AdicCompletion I (M j)`, inverse to each other. -/ variable {ι : Type*} [DecidableEq ι] (M : ι → Type*) [∀ i, AddCommGroup (M i)] [∀ i, Module R (M i)] section Pi /-- The canonical map from the adic completion of the product to the product of the adic completions. -/ @[simps!] def pi : AdicCompletion I (∀ j, M j) →ₗ[AdicCompletion I R] ∀ j, AdicCompletion I (M j) := LinearMap.pi (fun j ↦ map I (LinearMap.proj j)) end Pi section Sum open DirectSum /-- The canonical map from the sum of the adic completions to the adic completion of the sum. -/ def sum : (⨁ j, (AdicCompletion I (M j))) →ₗ[AdicCompletion I R] AdicCompletion I (⨁ j, M j) := toModule (AdicCompletion I R) ι (AdicCompletion I (⨁ j, M j)) (fun j ↦ map I (lof R ι M j)) @[simp] theorem sum_lof (j : ι) (x : AdicCompletion I (M j)) : sum I M ((DirectSum.lof (AdicCompletion I R) ι (fun i ↦ AdicCompletion I (M i)) j) x) = map I (lof R ι M j) x := by simp [sum] @[simp] theorem sum_of (j : ι) (x : AdicCompletion I (M j)) : sum I M ((DirectSum.of (fun i ↦ AdicCompletion I (M i)) j) x) = map I (lof R ι M j) x := by rw [← lof_eq_of R] apply sum_lof variable [Fintype ι] /-- If `ι` is finite, we use the equivalence of sum and product to obtain an inverse for `AdicCompletion.sum` from `AdicCompletion.pi`. -/ def sumInv : AdicCompletion I (⨁ j, M j) →ₗ[AdicCompletion I R] (⨁ j, (AdicCompletion I (M j))) := letI f := map I (linearEquivFunOnFintype R ι M) letI g := linearEquivFunOnFintype (AdicCompletion I R) ι (fun j ↦ AdicCompletion I (M j)) g.symm.toLinearMap ∘ₗ pi I M ∘ₗ f @[simp] theorem component_sumInv (x : AdicCompletion I (⨁ j, M j)) (j : ι) : component (AdicCompletion I R) ι _ j (sumInv I M x) = map I (component R ι _ j) x := by apply induction_on I _ x (fun x ↦ ?_) rfl @[simp] theorem sumInv_apply (x : AdicCompletion I (⨁ j, M j)) (j : ι) : (sumInv I M x) j = map I (component R ι _ j) x := by apply induction_on I _ x (fun x ↦ ?_) rfl theorem sumInv_comp_sum : sumInv I M ∘ₗ sum I M = LinearMap.id := by ext j x apply DirectSum.ext (AdicCompletion I R) (fun i ↦ ?_) ext n simp only [LinearMap.coe_comp, Function.comp_apply, sum_lof, map_mk, component_sumInv, mk_apply_coe, AdicCauchySequence.map_apply_coe, Submodule.mkQ_apply, LinearMap.id_comp] rw [DirectSum.component.of, DirectSum.component.of] split · next h => subst h; simp · simp theorem sum_comp_sumInv : sum I M ∘ₗ sumInv I M = LinearMap.id := by ext f n simp only [LinearMap.coe_comp, Function.comp_apply, LinearMap.id_coe, id_eq, mk_apply_coe, Submodule.mkQ_apply] rw [← DirectSum.sum_univ_of _ (((sumInv I M) ((AdicCompletion.mk I (⨁ (j : ι), M j)) f)))] simp only [sumInv_apply, map_mk, map_sum, sum_of, val_sum, mk_apply_coe, AdicCauchySequence.map_apply_coe, Submodule.mkQ_apply] simp only [← Submodule.mkQ_apply, ← map_sum] erw [DirectSum.sum_univ_of] /-- If `ι` is finite, `sum` has `sumInv` as inverse. -/ def sumEquivOfFintype : (⨁ j, (AdicCompletion I (M j))) ≃ₗ[AdicCompletion I R] AdicCompletion I (⨁ j, M j) := LinearEquiv.ofLinear (sum I M) (sumInv I M) (sum_comp_sumInv I M) (sumInv_comp_sum I M) @[simp] theorem sumEquivOfFintype_apply (x : ⨁ j, (AdicCompletion I (M j))) : sumEquivOfFintype I M x = sum I M x := rfl @[simp] theorem sumEquivOfFintype_symm_apply (x : AdicCompletion I (⨁ j, M j)) : (sumEquivOfFintype I M).symm x = sumInv I M x := rfl end Sum section Pi open DirectSum variable [Fintype ι] /-- If `ι` is finite, `pi` is a linear equiv. -/ def piEquivOfFintype : AdicCompletion I (∀ j, M j) ≃ₗ[AdicCompletion I R] ∀ j, AdicCompletion I (M j) := letI f := (congr I (linearEquivFunOnFintype R ι M)).symm letI g := (linearEquivFunOnFintype (AdicCompletion I R) ι (fun j ↦ AdicCompletion I (M j))) f.trans ((sumEquivOfFintype I M).symm.trans g) @[simp] theorem piEquivOfFintype_apply (x : AdicCompletion I (∀ j, M j)) : piEquivOfFintype I M x = pi I M x := by simp [piEquivOfFintype, sumInv, map_comp_apply] /-- Adic completion of `R^n` is `(AdicCompletion I R)^n`. -/ def piEquivFin (n : ℕ) : AdicCompletion I (Fin n → R) ≃ₗ[AdicCompletion I R] Fin n → AdicCompletion I R := piEquivOfFintype I (ι := Fin n) (fun _ : Fin n ↦ R) @[simp]
Mathlib/RingTheory/AdicCompletion/Functoriality.lean
344
346
theorem piEquivFin_apply (n : ℕ) (x : AdicCompletion I (Fin n → R)) : piEquivFin I n x = pi I (fun _ : Fin n ↦ R) x := by
simp only [piEquivFin, piEquivOfFintype_apply]
/- 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"]
Mathlib/Topology/Algebra/InfiniteSum/NatInt.lean
174
179
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]
/- Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Analysis.Convex.Topology import Mathlib.Analysis.NormedSpace.Pointwise import Mathlib.Analysis.Seminorm import Mathlib.Analysis.LocallyConvex.Bounded import Mathlib.Analysis.RCLike.Basic #align_import analysis.convex.gauge from "leanprover-community/mathlib"@"373b03b5b9d0486534edbe94747f23cb3712f93d" /-! # The Minkowski functional This file defines the Minkowski functional, aka gauge. The Minkowski functional of a set `s` is the function which associates each point to how much you need to scale `s` for `x` to be inside it. When `s` is symmetric, convex and absorbent, its gauge is a seminorm. Reciprocally, any seminorm arises as the gauge of some set, namely its unit ball. This induces the equivalence of seminorms and locally convex topological vector spaces. ## Main declarations For a real vector space, * `gauge`: Aka Minkowski functional. `gauge s x` is the least (actually, an infimum) `r` such that `x ∈ r • s`. * `gaugeSeminorm`: The Minkowski functional as a seminorm, when `s` is symmetric, convex and absorbent. ## References * [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966] ## Tags Minkowski functional, gauge -/ open NormedField Set open scoped Pointwise Topology NNReal noncomputable section variable {𝕜 E F : Type*} section AddCommGroup variable [AddCommGroup E] [Module ℝ E] /-- The Minkowski functional. Given a set `s` in a real vector space, `gauge s` is the functional which sends `x : E` to the smallest `r : ℝ` such that `x` is in `s` scaled by `r`. -/ def gauge (s : Set E) (x : E) : ℝ := sInf { r : ℝ | 0 < r ∧ x ∈ r • s } #align gauge gauge variable {s t : Set E} {x : E} {a : ℝ} theorem gauge_def : gauge s x = sInf ({ r ∈ Set.Ioi (0 : ℝ) | x ∈ r • s }) := rfl #align gauge_def gauge_def /-- An alternative definition of the gauge using scalar multiplication on the element rather than on the set. -/ theorem gauge_def' : gauge s x = sInf {r ∈ Set.Ioi (0 : ℝ) | r⁻¹ • x ∈ s} := by congrm sInf {r | ?_} exact and_congr_right fun hr => mem_smul_set_iff_inv_smul_mem₀ hr.ne' _ _ #align gauge_def' gauge_def' private theorem gauge_set_bddBelow : BddBelow { r : ℝ | 0 < r ∧ x ∈ r • s } := ⟨0, fun _ hr => hr.1.le⟩ /-- If the given subset is `Absorbent` then the set we take an infimum over in `gauge` is nonempty, which is useful for proving many properties about the gauge. -/ theorem Absorbent.gauge_set_nonempty (absorbs : Absorbent ℝ s) : { r : ℝ | 0 < r ∧ x ∈ r • s }.Nonempty := let ⟨r, hr₁, hr₂⟩ := (absorbs x).exists_pos ⟨r, hr₁, hr₂ r (Real.norm_of_nonneg hr₁.le).ge rfl⟩ #align absorbent.gauge_set_nonempty Absorbent.gauge_set_nonempty theorem gauge_mono (hs : Absorbent ℝ s) (h : s ⊆ t) : gauge t ≤ gauge s := fun _ => csInf_le_csInf gauge_set_bddBelow hs.gauge_set_nonempty fun _ hr => ⟨hr.1, smul_set_mono h hr.2⟩ #align gauge_mono gauge_mono theorem exists_lt_of_gauge_lt (absorbs : Absorbent ℝ s) (h : gauge s x < a) : ∃ b, 0 < b ∧ b < a ∧ x ∈ b • s := by obtain ⟨b, ⟨hb, hx⟩, hba⟩ := exists_lt_of_csInf_lt absorbs.gauge_set_nonempty h exact ⟨b, hb, hba, hx⟩ #align exists_lt_of_gauge_lt exists_lt_of_gauge_lt /-- The gauge evaluated at `0` is always zero (mathematically this requires `0` to be in the set `s` but, the real infimum of the empty set in Lean being defined as `0`, it holds unconditionally). -/ @[simp] theorem gauge_zero : gauge s 0 = 0 := by rw [gauge_def'] by_cases h : (0 : E) ∈ s · simp only [smul_zero, sep_true, h, csInf_Ioi] · simp only [smul_zero, sep_false, h, Real.sInf_empty] #align gauge_zero gauge_zero @[simp] theorem gauge_zero' : gauge (0 : Set E) = 0 := by ext x rw [gauge_def'] obtain rfl | hx := eq_or_ne x 0 · simp only [csInf_Ioi, mem_zero, Pi.zero_apply, eq_self_iff_true, sep_true, smul_zero] · simp only [mem_zero, Pi.zero_apply, inv_eq_zero, smul_eq_zero] convert Real.sInf_empty exact eq_empty_iff_forall_not_mem.2 fun r hr => hr.2.elim (ne_of_gt hr.1) hx #align gauge_zero' gauge_zero' @[simp] theorem gauge_empty : gauge (∅ : Set E) = 0 := by ext simp only [gauge_def', Real.sInf_empty, mem_empty_iff_false, Pi.zero_apply, sep_false] #align gauge_empty gauge_empty theorem gauge_of_subset_zero (h : s ⊆ 0) : gauge s = 0 := by obtain rfl | rfl := subset_singleton_iff_eq.1 h exacts [gauge_empty, gauge_zero'] #align gauge_of_subset_zero gauge_of_subset_zero /-- The gauge is always nonnegative. -/ theorem gauge_nonneg (x : E) : 0 ≤ gauge s x := Real.sInf_nonneg _ fun _ hx => hx.1.le #align gauge_nonneg gauge_nonneg theorem gauge_neg (symmetric : ∀ x ∈ s, -x ∈ s) (x : E) : gauge s (-x) = gauge s x := by have : ∀ x, -x ∈ s ↔ x ∈ s := fun x => ⟨fun h => by simpa using symmetric _ h, symmetric x⟩ simp_rw [gauge_def', smul_neg, this] #align gauge_neg gauge_neg theorem gauge_neg_set_neg (x : E) : gauge (-s) (-x) = gauge s x := by simp_rw [gauge_def', smul_neg, neg_mem_neg] #align gauge_neg_set_neg gauge_neg_set_neg theorem gauge_neg_set_eq_gauge_neg (x : E) : gauge (-s) x = gauge s (-x) := by rw [← gauge_neg_set_neg, neg_neg] #align gauge_neg_set_eq_gauge_neg gauge_neg_set_eq_gauge_neg theorem gauge_le_of_mem (ha : 0 ≤ a) (hx : x ∈ a • s) : gauge s x ≤ a := by obtain rfl | ha' := ha.eq_or_lt · rw [mem_singleton_iff.1 (zero_smul_set_subset _ hx), gauge_zero] · exact csInf_le gauge_set_bddBelow ⟨ha', hx⟩ #align gauge_le_of_mem gauge_le_of_mem theorem gauge_le_eq (hs₁ : Convex ℝ s) (hs₀ : (0 : E) ∈ s) (hs₂ : Absorbent ℝ s) (ha : 0 ≤ a) : { x | gauge s x ≤ a } = ⋂ (r : ℝ) (_ : a < r), r • s := by ext x simp_rw [Set.mem_iInter, Set.mem_setOf_eq] refine ⟨fun h r hr => ?_, fun h => le_of_forall_pos_lt_add fun ε hε => ?_⟩ · have hr' := ha.trans_lt hr rw [mem_smul_set_iff_inv_smul_mem₀ hr'.ne'] obtain ⟨δ, δ_pos, hδr, hδ⟩ := exists_lt_of_gauge_lt hs₂ (h.trans_lt hr) suffices (r⁻¹ * δ) • δ⁻¹ • x ∈ s by rwa [smul_smul, mul_inv_cancel_right₀ δ_pos.ne'] at this rw [mem_smul_set_iff_inv_smul_mem₀ δ_pos.ne'] at hδ refine hs₁.smul_mem_of_zero_mem hs₀ hδ ⟨by positivity, ?_⟩ rw [inv_mul_le_iff hr', mul_one] exact hδr.le · have hε' := (lt_add_iff_pos_right a).2 (half_pos hε) exact (gauge_le_of_mem (ha.trans hε'.le) <| h _ hε').trans_lt (add_lt_add_left (half_lt_self hε) _) #align gauge_le_eq gauge_le_eq theorem gauge_lt_eq' (absorbs : Absorbent ℝ s) (a : ℝ) : { x | gauge s x < a } = ⋃ (r : ℝ) (_ : 0 < r) (_ : r < a), r • s := by ext simp_rw [mem_setOf, mem_iUnion, exists_prop] exact ⟨exists_lt_of_gauge_lt absorbs, fun ⟨r, hr₀, hr₁, hx⟩ => (gauge_le_of_mem hr₀.le hx).trans_lt hr₁⟩ #align gauge_lt_eq' gauge_lt_eq' theorem gauge_lt_eq (absorbs : Absorbent ℝ s) (a : ℝ) : { x | gauge s x < a } = ⋃ r ∈ Set.Ioo 0 (a : ℝ), r • s := by ext simp_rw [mem_setOf, mem_iUnion, exists_prop, mem_Ioo, and_assoc] exact ⟨exists_lt_of_gauge_lt absorbs, fun ⟨r, hr₀, hr₁, hx⟩ => (gauge_le_of_mem hr₀.le hx).trans_lt hr₁⟩ #align gauge_lt_eq gauge_lt_eq theorem mem_openSegment_of_gauge_lt_one (absorbs : Absorbent ℝ s) (hgauge : gauge s x < 1) : ∃ y ∈ s, x ∈ openSegment ℝ 0 y := by rcases exists_lt_of_gauge_lt absorbs hgauge with ⟨r, hr₀, hr₁, y, hy, rfl⟩ refine ⟨y, hy, 1 - r, r, ?_⟩ simp [*] theorem gauge_lt_one_subset_self (hs : Convex ℝ s) (h₀ : (0 : E) ∈ s) (absorbs : Absorbent ℝ s) : { x | gauge s x < 1 } ⊆ s := fun _x hx ↦ let ⟨_y, hys, hx⟩ := mem_openSegment_of_gauge_lt_one absorbs hx hs.openSegment_subset h₀ hys hx #align gauge_lt_one_subset_self gauge_lt_one_subset_self theorem gauge_le_one_of_mem {x : E} (hx : x ∈ s) : gauge s x ≤ 1 := gauge_le_of_mem zero_le_one <| by rwa [one_smul] #align gauge_le_one_of_mem gauge_le_one_of_mem /-- Gauge is subadditive. -/ theorem gauge_add_le (hs : Convex ℝ s) (absorbs : Absorbent ℝ s) (x y : E) : gauge s (x + y) ≤ gauge s x + gauge s y := by refine le_of_forall_pos_lt_add fun ε hε => ?_ obtain ⟨a, ha, ha', x, hx, rfl⟩ := exists_lt_of_gauge_lt absorbs (lt_add_of_pos_right (gauge s x) (half_pos hε)) obtain ⟨b, hb, hb', y, hy, rfl⟩ := exists_lt_of_gauge_lt absorbs (lt_add_of_pos_right (gauge s y) (half_pos hε)) calc gauge s (a • x + b • y) ≤ a + b := gauge_le_of_mem (by positivity) <| by rw [hs.add_smul ha.le hb.le] exact add_mem_add (smul_mem_smul_set hx) (smul_mem_smul_set hy) _ < gauge s (a • x) + gauge s (b • y) + ε := by linarith #align gauge_add_le gauge_add_le theorem self_subset_gauge_le_one : s ⊆ { x | gauge s x ≤ 1 } := fun _ => gauge_le_one_of_mem #align self_subset_gauge_le_one self_subset_gauge_le_one theorem Convex.gauge_le (hs : Convex ℝ s) (h₀ : (0 : E) ∈ s) (absorbs : Absorbent ℝ s) (a : ℝ) : Convex ℝ { x | gauge s x ≤ a } := by by_cases ha : 0 ≤ a · rw [gauge_le_eq hs h₀ absorbs ha] exact convex_iInter fun i => convex_iInter fun _ => hs.smul _ · -- Porting note: `convert` needed help convert convex_empty (𝕜 := ℝ) (E := E) exact eq_empty_iff_forall_not_mem.2 fun x hx => ha <| (gauge_nonneg _).trans hx #align convex.gauge_le Convex.gauge_le theorem Balanced.starConvex (hs : Balanced ℝ s) : StarConvex ℝ 0 s := starConvex_zero_iff.2 fun x hx a ha₀ ha₁ => hs _ (by rwa [Real.norm_of_nonneg ha₀]) (smul_mem_smul_set hx) #align balanced.star_convex Balanced.starConvex theorem le_gauge_of_not_mem (hs₀ : StarConvex ℝ 0 s) (hs₂ : Absorbs ℝ s {x}) (hx : x ∉ a • s) : a ≤ gauge s x := by rw [starConvex_zero_iff] at hs₀ obtain ⟨r, hr, h⟩ := hs₂.exists_pos refine le_csInf ⟨r, hr, singleton_subset_iff.1 <| h _ (Real.norm_of_nonneg hr.le).ge⟩ ?_ rintro b ⟨hb, x, hx', rfl⟩ refine not_lt.1 fun hba => hx ?_ have ha := hb.trans hba refine ⟨(a⁻¹ * b) • x, hs₀ hx' (by positivity) ?_, ?_⟩ · rw [← div_eq_inv_mul] exact div_le_one_of_le hba.le ha.le · dsimp only rw [← mul_smul, mul_inv_cancel_left₀ ha.ne'] #align le_gauge_of_not_mem le_gauge_of_not_mem theorem one_le_gauge_of_not_mem (hs₁ : StarConvex ℝ 0 s) (hs₂ : Absorbs ℝ s {x}) (hx : x ∉ s) : 1 ≤ gauge s x := le_gauge_of_not_mem hs₁ hs₂ <| by rwa [one_smul] #align one_le_gauge_of_not_mem one_le_gauge_of_not_mem section LinearOrderedField variable {α : Type*} [LinearOrderedField α] [MulActionWithZero α ℝ] [OrderedSMul α ℝ]
Mathlib/Analysis/Convex/Gauge.lean
257
279
theorem gauge_smul_of_nonneg [MulActionWithZero α E] [IsScalarTower α ℝ (Set E)] {s : Set E} {a : α} (ha : 0 ≤ a) (x : E) : gauge s (a • x) = a • gauge s x := by
obtain rfl | ha' := ha.eq_or_lt · rw [zero_smul, gauge_zero, zero_smul] rw [gauge_def', gauge_def', ← Real.sInf_smul_of_nonneg ha] congr 1 ext r simp_rw [Set.mem_smul_set, Set.mem_sep_iff] constructor · rintro ⟨hr, hx⟩ simp_rw [mem_Ioi] at hr ⊢ rw [← mem_smul_set_iff_inv_smul_mem₀ hr.ne'] at hx have := smul_pos (inv_pos.2 ha') hr refine ⟨a⁻¹ • r, ⟨this, ?_⟩, smul_inv_smul₀ ha'.ne' _⟩ rwa [← mem_smul_set_iff_inv_smul_mem₀ this.ne', smul_assoc, mem_smul_set_iff_inv_smul_mem₀ (inv_ne_zero ha'.ne'), inv_inv] · rintro ⟨r, ⟨hr, hx⟩, rfl⟩ rw [mem_Ioi] at hr ⊢ rw [← mem_smul_set_iff_inv_smul_mem₀ hr.ne'] at hx have := smul_pos ha' hr refine ⟨this, ?_⟩ rw [← mem_smul_set_iff_inv_smul_mem₀ this.ne', smul_assoc] exact smul_mem_smul_set hx
/- 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.Algebra.DirectSum.Module import Mathlib.Analysis.Complex.Basic import Mathlib.Analysis.Convex.Uniform import Mathlib.Analysis.NormedSpace.Completion import Mathlib.Analysis.NormedSpace.BoundedLinearMaps #align_import analysis.inner_product_space.basic from "leanprover-community/mathlib"@"3f655f5297b030a87d641ad4e825af8d9679eb0b" /-! # Inner product space This file defines inner product spaces and proves the basic properties. We do not formally define Hilbert spaces, but they can be obtained using the set of assumptions `[NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [CompleteSpace E]`. An inner product space is a vector space endowed with an inner product. It generalizes the notion of dot product in `ℝ^n` and provides the means of defining the length of a vector and the angle between two vectors. In particular vectors `x` and `y` are orthogonal if their inner product equals zero. We define both the real and complex cases at the same time using the `RCLike` typeclass. This file proves general results on inner product spaces. For the specific construction of an inner product structure on `n → 𝕜` for `𝕜 = ℝ` or `ℂ`, see `EuclideanSpace` in `Analysis.InnerProductSpace.PiL2`. ## Main results - We define the class `InnerProductSpace 𝕜 E` extending `NormedSpace 𝕜 E` with a number of basic properties, most notably the Cauchy-Schwarz inequality. Here `𝕜` is understood to be either `ℝ` or `ℂ`, through the `RCLike` typeclass. - We show that the inner product is continuous, `continuous_inner`, and bundle it as the continuous sesquilinear map `innerSL` (see also `innerₛₗ` for the non-continuous version). - We define `Orthonormal`, a predicate on a function `v : ι → E`, and prove the existence of a maximal orthonormal set, `exists_maximal_orthonormal`. Bessel's inequality, `Orthonormal.tsum_inner_products_le`, states that given an orthonormal set `v` and a vector `x`, the sum of the norm-squares of the inner products `⟪v i, x⟫` is no more than the norm-square of `x`. For the existence of orthonormal bases, Hilbert bases, etc., see the file `Analysis.InnerProductSpace.projection`. ## Notation We globally denote the real and complex inner products by `⟪·, ·⟫_ℝ` and `⟪·, ·⟫_ℂ` respectively. We also provide two notation namespaces: `RealInnerProductSpace`, `ComplexInnerProductSpace`, which respectively introduce the plain notation `⟪·, ·⟫` for the real and complex inner product. ## Implementation notes We choose the convention that inner products are conjugate linear in the first argument and linear in the second. ## Tags inner product space, Hilbert space, norm ## References * [Clément & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*] * [Clément & Martin, *A Coq formal proof of the Lax–Milgram theorem*] The Coq code is available at the following address: <http://www.lri.fr/~sboldo/elfic/index.html> -/ noncomputable section open RCLike Real Filter open Topology ComplexConjugate open LinearMap (BilinForm) variable {𝕜 E F : Type*} [RCLike 𝕜] /-- Syntactic typeclass for types endowed with an inner product -/ class Inner (𝕜 E : Type*) where /-- The inner product function. -/ inner : E → E → 𝕜 #align has_inner Inner export Inner (inner) /-- The inner product with values in `𝕜`. -/ notation3:max "⟪" x ", " y "⟫_" 𝕜:max => @inner 𝕜 _ _ x y section Notations /-- The inner product with values in `ℝ`. -/ scoped[RealInnerProductSpace] notation "⟪" x ", " y "⟫" => @inner ℝ _ _ x y /-- The inner product with values in `ℂ`. -/ scoped[ComplexInnerProductSpace] notation "⟪" x ", " y "⟫" => @inner ℂ _ _ x y end Notations /-- An inner product space is a vector space with an additional operation called inner product. The norm could be derived from the inner product, instead we require the existence of a norm and the fact that `‖x‖^2 = re ⟪x, x⟫` to be able to put instances on `𝕂` or product spaces. To construct a norm from an inner product, see `InnerProductSpace.ofCore`. -/ class InnerProductSpace (𝕜 : Type*) (E : Type*) [RCLike 𝕜] [NormedAddCommGroup E] extends NormedSpace 𝕜 E, Inner 𝕜 E where /-- The inner product induces the norm. -/ norm_sq_eq_inner : ∀ x : E, ‖x‖ ^ 2 = re (inner x x) /-- The inner product is *hermitian*, taking the `conj` swaps the arguments. -/ conj_symm : ∀ x y, conj (inner y x) = inner x y /-- The inner product is additive in the first coordinate. -/ add_left : ∀ x y z, inner (x + y) z = inner x z + inner y z /-- The inner product is conjugate linear in the first coordinate. -/ smul_left : ∀ x y r, inner (r • x) y = conj r * inner x y #align inner_product_space InnerProductSpace /-! ### Constructing a normed space structure from an inner product In the definition of an inner product space, we require the existence of a norm, which is equal (but maybe not defeq) to the square root of the scalar product. This makes it possible to put an inner product space structure on spaces with a preexisting norm (for instance `ℝ`), with good properties. However, sometimes, one would like to define the norm starting only from a well-behaved scalar product. This is what we implement in this paragraph, starting from a structure `InnerProductSpace.Core` stating that we have a nice scalar product. Our goal here is not to develop a whole theory with all the supporting API, as this will be done below for `InnerProductSpace`. Instead, we implement the bare minimum to go as directly as possible to the construction of the norm and the proof of the triangular inequality. Warning: Do not use this `Core` structure if the space you are interested in already has a norm instance defined on it, otherwise this will create a second non-defeq norm instance! -/ /-- A structure requiring that a scalar product is positive definite and symmetric, from which one can construct an `InnerProductSpace` instance in `InnerProductSpace.ofCore`. -/ -- @[nolint HasNonemptyInstance] porting note: I don't think we have this linter anymore structure InnerProductSpace.Core (𝕜 : Type*) (F : Type*) [RCLike 𝕜] [AddCommGroup F] [Module 𝕜 F] extends Inner 𝕜 F where /-- The inner product is *hermitian*, taking the `conj` swaps the arguments. -/ conj_symm : ∀ x y, conj (inner y x) = inner x y /-- The inner product is positive (semi)definite. -/ nonneg_re : ∀ x, 0 ≤ re (inner x x) /-- The inner product is positive definite. -/ definite : ∀ x, inner x x = 0 → x = 0 /-- The inner product is additive in the first coordinate. -/ add_left : ∀ x y z, inner (x + y) z = inner x z + inner y z /-- The inner product is conjugate linear in the first coordinate. -/ smul_left : ∀ x y r, inner (r • x) y = conj r * inner x y #align inner_product_space.core InnerProductSpace.Core /- We set `InnerProductSpace.Core` to be a class as we will use it as such in the construction of the normed space structure that it produces. However, all the instances we will use will be local to this proof. -/ attribute [class] InnerProductSpace.Core /-- Define `InnerProductSpace.Core` from `InnerProductSpace`. Defined to reuse lemmas about `InnerProductSpace.Core` for `InnerProductSpace`s. Note that the `Norm` instance provided by `InnerProductSpace.Core.norm` is propositionally but not definitionally equal to the original norm. -/ def InnerProductSpace.toCore [NormedAddCommGroup E] [c : InnerProductSpace 𝕜 E] : InnerProductSpace.Core 𝕜 E := { c with nonneg_re := fun x => by rw [← InnerProductSpace.norm_sq_eq_inner] apply sq_nonneg definite := fun x hx => norm_eq_zero.1 <| pow_eq_zero (n := 2) <| by rw [InnerProductSpace.norm_sq_eq_inner (𝕜 := 𝕜) x, hx, map_zero] } #align inner_product_space.to_core InnerProductSpace.toCore namespace InnerProductSpace.Core variable [AddCommGroup F] [Module 𝕜 F] [c : InnerProductSpace.Core 𝕜 F] local notation "⟪" x ", " y "⟫" => @inner 𝕜 F _ x y local notation "normSqK" => @RCLike.normSq 𝕜 _ local notation "reK" => @RCLike.re 𝕜 _ local notation "ext_iff" => @RCLike.ext_iff 𝕜 _ local postfix:90 "†" => starRingEnd _ /-- Inner product defined by the `InnerProductSpace.Core` structure. We can't reuse `InnerProductSpace.Core.toInner` because it takes `InnerProductSpace.Core` as an explicit argument. -/ def toInner' : Inner 𝕜 F := c.toInner #align inner_product_space.core.to_has_inner' InnerProductSpace.Core.toInner' attribute [local instance] toInner' /-- The norm squared function for `InnerProductSpace.Core` structure. -/ def normSq (x : F) := reK ⟪x, x⟫ #align inner_product_space.core.norm_sq InnerProductSpace.Core.normSq local notation "normSqF" => @normSq 𝕜 F _ _ _ _ theorem inner_conj_symm (x y : F) : ⟪y, x⟫† = ⟪x, y⟫ := c.conj_symm x y #align inner_product_space.core.inner_conj_symm InnerProductSpace.Core.inner_conj_symm theorem inner_self_nonneg {x : F} : 0 ≤ re ⟪x, x⟫ := c.nonneg_re _ #align inner_product_space.core.inner_self_nonneg InnerProductSpace.Core.inner_self_nonneg theorem inner_self_im (x : F) : im ⟪x, x⟫ = 0 := by rw [← @ofReal_inj 𝕜, im_eq_conj_sub] simp [inner_conj_symm] #align inner_product_space.core.inner_self_im InnerProductSpace.Core.inner_self_im theorem inner_add_left (x y z : F) : ⟪x + y, z⟫ = ⟪x, z⟫ + ⟪y, z⟫ := c.add_left _ _ _ #align inner_product_space.core.inner_add_left InnerProductSpace.Core.inner_add_left theorem inner_add_right (x y z : F) : ⟪x, y + z⟫ = ⟪x, y⟫ + ⟪x, z⟫ := by rw [← inner_conj_symm, inner_add_left, RingHom.map_add]; simp only [inner_conj_symm] #align inner_product_space.core.inner_add_right InnerProductSpace.Core.inner_add_right theorem ofReal_normSq_eq_inner_self (x : F) : (normSqF x : 𝕜) = ⟪x, x⟫ := by rw [ext_iff] exact ⟨by simp only [ofReal_re]; rfl, by simp only [inner_self_im, ofReal_im]⟩ #align inner_product_space.core.coe_norm_sq_eq_inner_self InnerProductSpace.Core.ofReal_normSq_eq_inner_self theorem inner_re_symm (x y : F) : re ⟪x, y⟫ = re ⟪y, x⟫ := by rw [← inner_conj_symm, conj_re] #align inner_product_space.core.inner_re_symm InnerProductSpace.Core.inner_re_symm theorem inner_im_symm (x y : F) : im ⟪x, y⟫ = -im ⟪y, x⟫ := by rw [← inner_conj_symm, conj_im] #align inner_product_space.core.inner_im_symm InnerProductSpace.Core.inner_im_symm theorem inner_smul_left (x y : F) {r : 𝕜} : ⟪r • x, y⟫ = r† * ⟪x, y⟫ := c.smul_left _ _ _ #align inner_product_space.core.inner_smul_left InnerProductSpace.Core.inner_smul_left theorem inner_smul_right (x y : F) {r : 𝕜} : ⟪x, r • y⟫ = r * ⟪x, y⟫ := by rw [← inner_conj_symm, inner_smul_left]; simp only [conj_conj, inner_conj_symm, RingHom.map_mul] #align inner_product_space.core.inner_smul_right InnerProductSpace.Core.inner_smul_right theorem inner_zero_left (x : F) : ⟪0, x⟫ = 0 := by rw [← zero_smul 𝕜 (0 : F), inner_smul_left]; simp only [zero_mul, RingHom.map_zero] #align inner_product_space.core.inner_zero_left InnerProductSpace.Core.inner_zero_left theorem inner_zero_right (x : F) : ⟪x, 0⟫ = 0 := by rw [← inner_conj_symm, inner_zero_left]; simp only [RingHom.map_zero] #align inner_product_space.core.inner_zero_right InnerProductSpace.Core.inner_zero_right theorem inner_self_eq_zero {x : F} : ⟪x, x⟫ = 0 ↔ x = 0 := ⟨c.definite _, by rintro rfl exact inner_zero_left _⟩ #align inner_product_space.core.inner_self_eq_zero InnerProductSpace.Core.inner_self_eq_zero theorem normSq_eq_zero {x : F} : normSqF x = 0 ↔ x = 0 := Iff.trans (by simp only [normSq, ext_iff, map_zero, inner_self_im, eq_self_iff_true, and_true_iff]) (@inner_self_eq_zero 𝕜 _ _ _ _ _ x) #align inner_product_space.core.norm_sq_eq_zero InnerProductSpace.Core.normSq_eq_zero theorem inner_self_ne_zero {x : F} : ⟪x, x⟫ ≠ 0 ↔ x ≠ 0 := inner_self_eq_zero.not #align inner_product_space.core.inner_self_ne_zero InnerProductSpace.Core.inner_self_ne_zero theorem inner_self_ofReal_re (x : F) : (re ⟪x, x⟫ : 𝕜) = ⟪x, x⟫ := by norm_num [ext_iff, inner_self_im] set_option linter.uppercaseLean3 false in #align inner_product_space.core.inner_self_re_to_K InnerProductSpace.Core.inner_self_ofReal_re theorem norm_inner_symm (x y : F) : ‖⟪x, y⟫‖ = ‖⟪y, x⟫‖ := by rw [← inner_conj_symm, norm_conj] #align inner_product_space.core.norm_inner_symm InnerProductSpace.Core.norm_inner_symm theorem inner_neg_left (x y : F) : ⟪-x, y⟫ = -⟪x, y⟫ := by rw [← neg_one_smul 𝕜 x, inner_smul_left] simp #align inner_product_space.core.inner_neg_left InnerProductSpace.Core.inner_neg_left theorem inner_neg_right (x y : F) : ⟪x, -y⟫ = -⟪x, y⟫ := by rw [← inner_conj_symm, inner_neg_left]; simp only [RingHom.map_neg, inner_conj_symm] #align inner_product_space.core.inner_neg_right InnerProductSpace.Core.inner_neg_right theorem inner_sub_left (x y z : F) : ⟪x - y, z⟫ = ⟪x, z⟫ - ⟪y, z⟫ := by simp [sub_eq_add_neg, inner_add_left, inner_neg_left] #align inner_product_space.core.inner_sub_left InnerProductSpace.Core.inner_sub_left theorem inner_sub_right (x y z : F) : ⟪x, y - z⟫ = ⟪x, y⟫ - ⟪x, z⟫ := by simp [sub_eq_add_neg, inner_add_right, inner_neg_right] #align inner_product_space.core.inner_sub_right InnerProductSpace.Core.inner_sub_right theorem inner_mul_symm_re_eq_norm (x y : F) : re (⟪x, y⟫ * ⟪y, x⟫) = ‖⟪x, y⟫ * ⟪y, x⟫‖ := by rw [← inner_conj_symm, mul_comm] exact re_eq_norm_of_mul_conj (inner y x) #align inner_product_space.core.inner_mul_symm_re_eq_norm InnerProductSpace.Core.inner_mul_symm_re_eq_norm /-- Expand `inner (x + y) (x + y)` -/ theorem inner_add_add_self (x y : F) : ⟪x + y, x + y⟫ = ⟪x, x⟫ + ⟪x, y⟫ + ⟪y, x⟫ + ⟪y, y⟫ := by simp only [inner_add_left, inner_add_right]; ring #align inner_product_space.core.inner_add_add_self InnerProductSpace.Core.inner_add_add_self -- Expand `inner (x - y) (x - y)` theorem inner_sub_sub_self (x y : F) : ⟪x - y, x - y⟫ = ⟪x, x⟫ - ⟪x, y⟫ - ⟪y, x⟫ + ⟪y, y⟫ := by simp only [inner_sub_left, inner_sub_right]; ring #align inner_product_space.core.inner_sub_sub_self InnerProductSpace.Core.inner_sub_sub_self /-- An auxiliary equality useful to prove the **Cauchy–Schwarz inequality**: the square of the norm of `⟪x, y⟫ • x - ⟪x, x⟫ • y` is equal to `‖x‖ ^ 2 * (‖x‖ ^ 2 * ‖y‖ ^ 2 - ‖⟪x, y⟫‖ ^ 2)`. We use `InnerProductSpace.ofCore.normSq x` etc (defeq to `is_R_or_C.re ⟪x, x⟫`) instead of `‖x‖ ^ 2` etc to avoid extra rewrites when applying it to an `InnerProductSpace`. -/ theorem cauchy_schwarz_aux (x y : F) : normSqF (⟪x, y⟫ • x - ⟪x, x⟫ • y) = normSqF x * (normSqF x * normSqF y - ‖⟪x, y⟫‖ ^ 2) := by rw [← @ofReal_inj 𝕜, ofReal_normSq_eq_inner_self] simp only [inner_sub_sub_self, inner_smul_left, inner_smul_right, conj_ofReal, mul_sub, ← ofReal_normSq_eq_inner_self x, ← ofReal_normSq_eq_inner_self y] rw [← mul_assoc, mul_conj, RCLike.conj_mul, mul_left_comm, ← inner_conj_symm y, mul_conj] push_cast ring #align inner_product_space.core.cauchy_schwarz_aux InnerProductSpace.Core.cauchy_schwarz_aux /-- **Cauchy–Schwarz inequality**. We need this for the `Core` structure to prove the triangle inequality below when showing the core is a normed group. -/ theorem inner_mul_inner_self_le (x y : F) : ‖⟪x, y⟫‖ * ‖⟪y, x⟫‖ ≤ re ⟪x, x⟫ * re ⟪y, y⟫ := by rcases eq_or_ne x 0 with (rfl | hx) · simpa only [inner_zero_left, map_zero, zero_mul, norm_zero] using le_rfl · have hx' : 0 < normSqF x := inner_self_nonneg.lt_of_ne' (mt normSq_eq_zero.1 hx) rw [← sub_nonneg, ← mul_nonneg_iff_right_nonneg_of_pos hx', ← normSq, ← normSq, norm_inner_symm y, ← sq, ← cauchy_schwarz_aux] exact inner_self_nonneg #align inner_product_space.core.inner_mul_inner_self_le InnerProductSpace.Core.inner_mul_inner_self_le /-- Norm constructed from an `InnerProductSpace.Core` structure, defined to be the square root of the scalar product. -/ def toNorm : Norm F where norm x := √(re ⟪x, x⟫) #align inner_product_space.core.to_has_norm InnerProductSpace.Core.toNorm attribute [local instance] toNorm theorem norm_eq_sqrt_inner (x : F) : ‖x‖ = √(re ⟪x, x⟫) := rfl #align inner_product_space.core.norm_eq_sqrt_inner InnerProductSpace.Core.norm_eq_sqrt_inner theorem inner_self_eq_norm_mul_norm (x : F) : re ⟪x, x⟫ = ‖x‖ * ‖x‖ := by rw [norm_eq_sqrt_inner, ← sqrt_mul inner_self_nonneg (re ⟪x, x⟫), sqrt_mul_self inner_self_nonneg] #align inner_product_space.core.inner_self_eq_norm_mul_norm InnerProductSpace.Core.inner_self_eq_norm_mul_norm theorem sqrt_normSq_eq_norm (x : F) : √(normSqF x) = ‖x‖ := rfl #align inner_product_space.core.sqrt_norm_sq_eq_norm InnerProductSpace.Core.sqrt_normSq_eq_norm /-- Cauchy–Schwarz inequality with norm -/ theorem norm_inner_le_norm (x y : F) : ‖⟪x, y⟫‖ ≤ ‖x‖ * ‖y‖ := nonneg_le_nonneg_of_sq_le_sq (mul_nonneg (sqrt_nonneg _) (sqrt_nonneg _)) <| calc ‖⟪x, y⟫‖ * ‖⟪x, y⟫‖ = ‖⟪x, y⟫‖ * ‖⟪y, x⟫‖ := by rw [norm_inner_symm] _ ≤ re ⟪x, x⟫ * re ⟪y, y⟫ := inner_mul_inner_self_le x y _ = ‖x‖ * ‖y‖ * (‖x‖ * ‖y‖) := by simp only [inner_self_eq_norm_mul_norm]; ring #align inner_product_space.core.norm_inner_le_norm InnerProductSpace.Core.norm_inner_le_norm /-- Normed group structure constructed from an `InnerProductSpace.Core` structure -/ def toNormedAddCommGroup : NormedAddCommGroup F := AddGroupNorm.toNormedAddCommGroup { toFun := fun x => √(re ⟪x, x⟫) map_zero' := by simp only [sqrt_zero, inner_zero_right, map_zero] neg' := fun x => by simp only [inner_neg_left, neg_neg, inner_neg_right] add_le' := fun x y => by have h₁ : ‖⟪x, y⟫‖ ≤ ‖x‖ * ‖y‖ := norm_inner_le_norm _ _ have h₂ : re ⟪x, y⟫ ≤ ‖⟪x, y⟫‖ := re_le_norm _ have h₃ : re ⟪x, y⟫ ≤ ‖x‖ * ‖y‖ := h₂.trans h₁ have h₄ : re ⟪y, x⟫ ≤ ‖x‖ * ‖y‖ := by rwa [← inner_conj_symm, conj_re] have : ‖x + y‖ * ‖x + y‖ ≤ (‖x‖ + ‖y‖) * (‖x‖ + ‖y‖) := by simp only [← inner_self_eq_norm_mul_norm, inner_add_add_self, mul_add, mul_comm, map_add] linarith exact nonneg_le_nonneg_of_sq_le_sq (add_nonneg (sqrt_nonneg _) (sqrt_nonneg _)) this eq_zero_of_map_eq_zero' := fun x hx => normSq_eq_zero.1 <| (sqrt_eq_zero inner_self_nonneg).1 hx } #align inner_product_space.core.to_normed_add_comm_group InnerProductSpace.Core.toNormedAddCommGroup attribute [local instance] toNormedAddCommGroup /-- Normed space structure constructed from an `InnerProductSpace.Core` structure -/ def toNormedSpace : NormedSpace 𝕜 F where norm_smul_le r x := by rw [norm_eq_sqrt_inner, inner_smul_left, inner_smul_right, ← mul_assoc] rw [RCLike.conj_mul, ← ofReal_pow, re_ofReal_mul, sqrt_mul, ← ofReal_normSq_eq_inner_self, ofReal_re] · simp [sqrt_normSq_eq_norm, RCLike.sqrt_normSq_eq_norm] · positivity #align inner_product_space.core.to_normed_space InnerProductSpace.Core.toNormedSpace end InnerProductSpace.Core section attribute [local instance] InnerProductSpace.Core.toNormedAddCommGroup /-- Given an `InnerProductSpace.Core` structure on a space, one can use it to turn the space into an inner product space. The `NormedAddCommGroup` structure is expected to already be defined with `InnerProductSpace.ofCore.toNormedAddCommGroup`. -/ def InnerProductSpace.ofCore [AddCommGroup F] [Module 𝕜 F] (c : InnerProductSpace.Core 𝕜 F) : InnerProductSpace 𝕜 F := letI : NormedSpace 𝕜 F := @InnerProductSpace.Core.toNormedSpace 𝕜 F _ _ _ c { c with norm_sq_eq_inner := fun x => by have h₁ : ‖x‖ ^ 2 = √(re (c.inner x x)) ^ 2 := rfl have h₂ : 0 ≤ re (c.inner x x) := InnerProductSpace.Core.inner_self_nonneg simp [h₁, sq_sqrt, h₂] } #align inner_product_space.of_core InnerProductSpace.ofCore end /-! ### Properties of inner product spaces -/ variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] variable [NormedAddCommGroup F] [InnerProductSpace ℝ F] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y local notation "IK" => @RCLike.I 𝕜 _ local postfix:90 "†" => starRingEnd _ export InnerProductSpace (norm_sq_eq_inner) section BasicProperties @[simp] theorem inner_conj_symm (x y : E) : ⟪y, x⟫† = ⟪x, y⟫ := InnerProductSpace.conj_symm _ _ #align inner_conj_symm inner_conj_symm theorem real_inner_comm (x y : F) : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := @inner_conj_symm ℝ _ _ _ _ x y #align real_inner_comm real_inner_comm theorem inner_eq_zero_symm {x y : E} : ⟪x, y⟫ = 0 ↔ ⟪y, x⟫ = 0 := by rw [← inner_conj_symm] exact star_eq_zero #align inner_eq_zero_symm inner_eq_zero_symm @[simp] theorem inner_self_im (x : E) : im ⟪x, x⟫ = 0 := by rw [← @ofReal_inj 𝕜, im_eq_conj_sub]; simp #align inner_self_im inner_self_im theorem inner_add_left (x y z : E) : ⟪x + y, z⟫ = ⟪x, z⟫ + ⟪y, z⟫ := InnerProductSpace.add_left _ _ _ #align inner_add_left inner_add_left theorem inner_add_right (x y z : E) : ⟪x, y + z⟫ = ⟪x, y⟫ + ⟪x, z⟫ := by rw [← inner_conj_symm, inner_add_left, RingHom.map_add] simp only [inner_conj_symm] #align inner_add_right inner_add_right theorem inner_re_symm (x y : E) : re ⟪x, y⟫ = re ⟪y, x⟫ := by rw [← inner_conj_symm, conj_re] #align inner_re_symm inner_re_symm theorem inner_im_symm (x y : E) : im ⟪x, y⟫ = -im ⟪y, x⟫ := by rw [← inner_conj_symm, conj_im] #align inner_im_symm inner_im_symm theorem inner_smul_left (x y : E) (r : 𝕜) : ⟪r • x, y⟫ = r† * ⟪x, y⟫ := InnerProductSpace.smul_left _ _ _ #align inner_smul_left inner_smul_left theorem real_inner_smul_left (x y : F) (r : ℝ) : ⟪r • x, y⟫_ℝ = r * ⟪x, y⟫_ℝ := inner_smul_left _ _ _ #align real_inner_smul_left real_inner_smul_left theorem inner_smul_real_left (x y : E) (r : ℝ) : ⟪(r : 𝕜) • x, y⟫ = r • ⟪x, y⟫ := by rw [inner_smul_left, conj_ofReal, Algebra.smul_def] rfl #align inner_smul_real_left inner_smul_real_left theorem inner_smul_right (x y : E) (r : 𝕜) : ⟪x, r • y⟫ = r * ⟪x, y⟫ := by rw [← inner_conj_symm, inner_smul_left, RingHom.map_mul, conj_conj, inner_conj_symm] #align inner_smul_right inner_smul_right theorem real_inner_smul_right (x y : F) (r : ℝ) : ⟪x, r • y⟫_ℝ = r * ⟪x, y⟫_ℝ := inner_smul_right _ _ _ #align real_inner_smul_right real_inner_smul_right theorem inner_smul_real_right (x y : E) (r : ℝ) : ⟪x, (r : 𝕜) • y⟫ = r • ⟪x, y⟫ := by rw [inner_smul_right, Algebra.smul_def] rfl #align inner_smul_real_right inner_smul_real_right /-- The inner product as a sesquilinear form. Note that in the case `𝕜 = ℝ` this is a bilinear form. -/ @[simps!] def sesqFormOfInner : E →ₗ[𝕜] E →ₗ⋆[𝕜] 𝕜 := LinearMap.mk₂'ₛₗ (RingHom.id 𝕜) (starRingEnd _) (fun x y => ⟪y, x⟫) (fun _x _y _z => inner_add_right _ _ _) (fun _r _x _y => inner_smul_right _ _ _) (fun _x _y _z => inner_add_left _ _ _) fun _r _x _y => inner_smul_left _ _ _ #align sesq_form_of_inner sesqFormOfInner /-- The real inner product as a bilinear form. Note that unlike `sesqFormOfInner`, this does not reverse the order of the arguments. -/ @[simps!] def bilinFormOfRealInner : BilinForm ℝ F := sesqFormOfInner.flip #align bilin_form_of_real_inner bilinFormOfRealInner /-- An inner product with a sum on the left. -/ theorem sum_inner {ι : Type*} (s : Finset ι) (f : ι → E) (x : E) : ⟪∑ i ∈ s, f i, x⟫ = ∑ i ∈ s, ⟪f i, x⟫ := map_sum (sesqFormOfInner (𝕜 := 𝕜) (E := E) x) _ _ #align sum_inner sum_inner /-- An inner product with a sum on the right. -/ theorem inner_sum {ι : Type*} (s : Finset ι) (f : ι → E) (x : E) : ⟪x, ∑ i ∈ s, f i⟫ = ∑ i ∈ s, ⟪x, f i⟫ := map_sum (LinearMap.flip sesqFormOfInner x) _ _ #align inner_sum inner_sum /-- An inner product with a sum on the left, `Finsupp` version. -/ theorem Finsupp.sum_inner {ι : Type*} (l : ι →₀ 𝕜) (v : ι → E) (x : E) : ⟪l.sum fun (i : ι) (a : 𝕜) => a • v i, x⟫ = l.sum fun (i : ι) (a : 𝕜) => conj a • ⟪v i, x⟫ := by convert _root_.sum_inner (𝕜 := 𝕜) l.support (fun a => l a • v a) x simp only [inner_smul_left, Finsupp.sum, smul_eq_mul] #align finsupp.sum_inner Finsupp.sum_inner /-- An inner product with a sum on the right, `Finsupp` version. -/ theorem Finsupp.inner_sum {ι : Type*} (l : ι →₀ 𝕜) (v : ι → E) (x : E) : ⟪x, l.sum fun (i : ι) (a : 𝕜) => a • v i⟫ = l.sum fun (i : ι) (a : 𝕜) => a • ⟪x, v i⟫ := by convert _root_.inner_sum (𝕜 := 𝕜) l.support (fun a => l a • v a) x simp only [inner_smul_right, Finsupp.sum, smul_eq_mul] #align finsupp.inner_sum Finsupp.inner_sum theorem DFinsupp.sum_inner {ι : Type*} [DecidableEq ι] {α : ι → Type*} [∀ i, AddZeroClass (α i)] [∀ (i) (x : α i), Decidable (x ≠ 0)] (f : ∀ i, α i → E) (l : Π₀ i, α i) (x : E) : ⟪l.sum f, x⟫ = l.sum fun i a => ⟪f i a, x⟫ := by simp (config := { contextual := true }) only [DFinsupp.sum, _root_.sum_inner, smul_eq_mul] #align dfinsupp.sum_inner DFinsupp.sum_inner theorem DFinsupp.inner_sum {ι : Type*} [DecidableEq ι] {α : ι → Type*} [∀ i, AddZeroClass (α i)] [∀ (i) (x : α i), Decidable (x ≠ 0)] (f : ∀ i, α i → E) (l : Π₀ i, α i) (x : E) : ⟪x, l.sum f⟫ = l.sum fun i a => ⟪x, f i a⟫ := by simp (config := { contextual := true }) only [DFinsupp.sum, _root_.inner_sum, smul_eq_mul] #align dfinsupp.inner_sum DFinsupp.inner_sum @[simp] theorem inner_zero_left (x : E) : ⟪0, x⟫ = 0 := by rw [← zero_smul 𝕜 (0 : E), inner_smul_left, RingHom.map_zero, zero_mul] #align inner_zero_left inner_zero_left theorem inner_re_zero_left (x : E) : re ⟪0, x⟫ = 0 := by simp only [inner_zero_left, AddMonoidHom.map_zero] #align inner_re_zero_left inner_re_zero_left @[simp] theorem inner_zero_right (x : E) : ⟪x, 0⟫ = 0 := by rw [← inner_conj_symm, inner_zero_left, RingHom.map_zero] #align inner_zero_right inner_zero_right theorem inner_re_zero_right (x : E) : re ⟪x, 0⟫ = 0 := by simp only [inner_zero_right, AddMonoidHom.map_zero] #align inner_re_zero_right inner_re_zero_right theorem inner_self_nonneg {x : E} : 0 ≤ re ⟪x, x⟫ := InnerProductSpace.toCore.nonneg_re x #align inner_self_nonneg inner_self_nonneg theorem real_inner_self_nonneg {x : F} : 0 ≤ ⟪x, x⟫_ℝ := @inner_self_nonneg ℝ F _ _ _ x #align real_inner_self_nonneg real_inner_self_nonneg @[simp] theorem inner_self_ofReal_re (x : E) : (re ⟪x, x⟫ : 𝕜) = ⟪x, x⟫ := ((RCLike.is_real_TFAE (⟪x, x⟫ : 𝕜)).out 2 3).2 (inner_self_im _) set_option linter.uppercaseLean3 false in #align inner_self_re_to_K inner_self_ofReal_re theorem inner_self_eq_norm_sq_to_K (x : E) : ⟪x, x⟫ = (‖x‖ : 𝕜) ^ 2 := by rw [← inner_self_ofReal_re, ← norm_sq_eq_inner, ofReal_pow] set_option linter.uppercaseLean3 false in #align inner_self_eq_norm_sq_to_K inner_self_eq_norm_sq_to_K theorem inner_self_re_eq_norm (x : E) : re ⟪x, x⟫ = ‖⟪x, x⟫‖ := by conv_rhs => rw [← inner_self_ofReal_re] symm exact norm_of_nonneg inner_self_nonneg #align inner_self_re_eq_norm inner_self_re_eq_norm theorem inner_self_ofReal_norm (x : E) : (‖⟪x, x⟫‖ : 𝕜) = ⟪x, x⟫ := by rw [← inner_self_re_eq_norm] exact inner_self_ofReal_re _ set_option linter.uppercaseLean3 false in #align inner_self_norm_to_K inner_self_ofReal_norm theorem real_inner_self_abs (x : F) : |⟪x, x⟫_ℝ| = ⟪x, x⟫_ℝ := @inner_self_ofReal_norm ℝ F _ _ _ x #align real_inner_self_abs real_inner_self_abs @[simp] theorem inner_self_eq_zero {x : E} : ⟪x, x⟫ = 0 ↔ x = 0 := by rw [inner_self_eq_norm_sq_to_K, sq_eq_zero_iff, ofReal_eq_zero, norm_eq_zero] #align inner_self_eq_zero inner_self_eq_zero theorem inner_self_ne_zero {x : E} : ⟪x, x⟫ ≠ 0 ↔ x ≠ 0 := inner_self_eq_zero.not #align inner_self_ne_zero inner_self_ne_zero @[simp] theorem inner_self_nonpos {x : E} : re ⟪x, x⟫ ≤ 0 ↔ x = 0 := by rw [← norm_sq_eq_inner, (sq_nonneg _).le_iff_eq, sq_eq_zero_iff, norm_eq_zero] #align inner_self_nonpos inner_self_nonpos theorem real_inner_self_nonpos {x : F} : ⟪x, x⟫_ℝ ≤ 0 ↔ x = 0 := @inner_self_nonpos ℝ F _ _ _ x #align real_inner_self_nonpos real_inner_self_nonpos theorem norm_inner_symm (x y : E) : ‖⟪x, y⟫‖ = ‖⟪y, x⟫‖ := by rw [← inner_conj_symm, norm_conj] #align norm_inner_symm norm_inner_symm @[simp] theorem inner_neg_left (x y : E) : ⟪-x, y⟫ = -⟪x, y⟫ := by rw [← neg_one_smul 𝕜 x, inner_smul_left] simp #align inner_neg_left inner_neg_left @[simp] theorem inner_neg_right (x y : E) : ⟪x, -y⟫ = -⟪x, y⟫ := by rw [← inner_conj_symm, inner_neg_left]; simp only [RingHom.map_neg, inner_conj_symm] #align inner_neg_right inner_neg_right theorem inner_neg_neg (x y : E) : ⟪-x, -y⟫ = ⟪x, y⟫ := by simp #align inner_neg_neg inner_neg_neg -- Porting note: removed `simp` because it can prove it using `inner_conj_symm` theorem inner_self_conj (x : E) : ⟪x, x⟫† = ⟪x, x⟫ := inner_conj_symm _ _ #align inner_self_conj inner_self_conj theorem inner_sub_left (x y z : E) : ⟪x - y, z⟫ = ⟪x, z⟫ - ⟪y, z⟫ := by simp [sub_eq_add_neg, inner_add_left] #align inner_sub_left inner_sub_left theorem inner_sub_right (x y z : E) : ⟪x, y - z⟫ = ⟪x, y⟫ - ⟪x, z⟫ := by simp [sub_eq_add_neg, inner_add_right] #align inner_sub_right inner_sub_right theorem inner_mul_symm_re_eq_norm (x y : E) : re (⟪x, y⟫ * ⟪y, x⟫) = ‖⟪x, y⟫ * ⟪y, x⟫‖ := by rw [← inner_conj_symm, mul_comm] exact re_eq_norm_of_mul_conj (inner y x) #align inner_mul_symm_re_eq_norm inner_mul_symm_re_eq_norm /-- Expand `⟪x + y, x + y⟫` -/ theorem inner_add_add_self (x y : E) : ⟪x + y, x + y⟫ = ⟪x, x⟫ + ⟪x, y⟫ + ⟪y, x⟫ + ⟪y, y⟫ := by simp only [inner_add_left, inner_add_right]; ring #align inner_add_add_self inner_add_add_self /-- Expand `⟪x + y, x + y⟫_ℝ` -/ theorem real_inner_add_add_self (x y : F) : ⟪x + y, x + y⟫_ℝ = ⟪x, x⟫_ℝ + 2 * ⟪x, y⟫_ℝ + ⟪y, y⟫_ℝ := by have : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [← inner_conj_symm]; rfl simp only [inner_add_add_self, this, add_left_inj] ring #align real_inner_add_add_self real_inner_add_add_self -- Expand `⟪x - y, x - y⟫` theorem inner_sub_sub_self (x y : E) : ⟪x - y, x - y⟫ = ⟪x, x⟫ - ⟪x, y⟫ - ⟪y, x⟫ + ⟪y, y⟫ := by simp only [inner_sub_left, inner_sub_right]; ring #align inner_sub_sub_self inner_sub_sub_self /-- Expand `⟪x - y, x - y⟫_ℝ` -/ theorem real_inner_sub_sub_self (x y : F) : ⟪x - y, x - y⟫_ℝ = ⟪x, x⟫_ℝ - 2 * ⟪x, y⟫_ℝ + ⟪y, y⟫_ℝ := by have : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [← inner_conj_symm]; rfl simp only [inner_sub_sub_self, this, add_left_inj] ring #align real_inner_sub_sub_self real_inner_sub_sub_self variable (𝕜) theorem ext_inner_left {x y : E} (h : ∀ v, ⟪v, x⟫ = ⟪v, y⟫) : x = y := by rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜, inner_sub_right, sub_eq_zero, h (x - y)] #align ext_inner_left ext_inner_left theorem ext_inner_right {x y : E} (h : ∀ v, ⟪x, v⟫ = ⟪y, v⟫) : x = y := by rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜, inner_sub_left, sub_eq_zero, h (x - y)] #align ext_inner_right ext_inner_right variable {𝕜} /-- Parallelogram law -/ theorem parallelogram_law {x y : E} : ⟪x + y, x + y⟫ + ⟪x - y, x - y⟫ = 2 * (⟪x, x⟫ + ⟪y, y⟫) := by simp only [inner_add_add_self, inner_sub_sub_self] ring #align parallelogram_law parallelogram_law /-- **Cauchy–Schwarz inequality**. -/ theorem inner_mul_inner_self_le (x y : E) : ‖⟪x, y⟫‖ * ‖⟪y, x⟫‖ ≤ re ⟪x, x⟫ * re ⟪y, y⟫ := letI c : InnerProductSpace.Core 𝕜 E := InnerProductSpace.toCore InnerProductSpace.Core.inner_mul_inner_self_le x y #align inner_mul_inner_self_le inner_mul_inner_self_le /-- Cauchy–Schwarz inequality for real inner products. -/ theorem real_inner_mul_inner_self_le (x y : F) : ⟪x, y⟫_ℝ * ⟪x, y⟫_ℝ ≤ ⟪x, x⟫_ℝ * ⟪y, y⟫_ℝ := calc ⟪x, y⟫_ℝ * ⟪x, y⟫_ℝ ≤ ‖⟪x, y⟫_ℝ‖ * ‖⟪y, x⟫_ℝ‖ := by rw [real_inner_comm y, ← norm_mul] exact le_abs_self _ _ ≤ ⟪x, x⟫_ℝ * ⟪y, y⟫_ℝ := @inner_mul_inner_self_le ℝ _ _ _ _ x y #align real_inner_mul_inner_self_le real_inner_mul_inner_self_le /-- A family of vectors is linearly independent if they are nonzero and orthogonal. -/ theorem linearIndependent_of_ne_zero_of_inner_eq_zero {ι : Type*} {v : ι → E} (hz : ∀ i, v i ≠ 0) (ho : Pairwise fun i j => ⟪v i, v j⟫ = 0) : LinearIndependent 𝕜 v := by rw [linearIndependent_iff'] intro s g hg i hi have h' : g i * inner (v i) (v i) = inner (v i) (∑ j ∈ s, g j • v j) := by rw [inner_sum] symm convert Finset.sum_eq_single (β := 𝕜) i ?_ ?_ · rw [inner_smul_right] · intro j _hj hji rw [inner_smul_right, ho hji.symm, mul_zero] · exact fun h => False.elim (h hi) simpa [hg, hz] using h' #align linear_independent_of_ne_zero_of_inner_eq_zero linearIndependent_of_ne_zero_of_inner_eq_zero end BasicProperties section OrthonormalSets variable {ι : Type*} (𝕜) /-- An orthonormal set of vectors in an `InnerProductSpace` -/ def Orthonormal (v : ι → E) : Prop := (∀ i, ‖v i‖ = 1) ∧ Pairwise fun i j => ⟪v i, v j⟫ = 0 #align orthonormal Orthonormal variable {𝕜} /-- `if ... then ... else` characterization of an indexed set of vectors being orthonormal. (Inner product equals Kronecker delta.) -/ theorem orthonormal_iff_ite [DecidableEq ι] {v : ι → E} : Orthonormal 𝕜 v ↔ ∀ i j, ⟪v i, v j⟫ = if i = j then (1 : 𝕜) else (0 : 𝕜) := by constructor · intro hv i j split_ifs with h · simp [h, inner_self_eq_norm_sq_to_K, hv.1] · exact hv.2 h · intro h constructor · intro i have h' : ‖v i‖ ^ 2 = 1 ^ 2 := by simp [@norm_sq_eq_inner 𝕜, h i i] have h₁ : 0 ≤ ‖v i‖ := norm_nonneg _ have h₂ : (0 : ℝ) ≤ 1 := zero_le_one rwa [sq_eq_sq h₁ h₂] at h' · intro i j hij simpa [hij] using h i j #align orthonormal_iff_ite orthonormal_iff_ite /-- `if ... then ... else` characterization of a set of vectors being orthonormal. (Inner product equals Kronecker delta.) -/ theorem orthonormal_subtype_iff_ite [DecidableEq E] {s : Set E} : Orthonormal 𝕜 (Subtype.val : s → E) ↔ ∀ v ∈ s, ∀ w ∈ s, ⟪v, w⟫ = if v = w then 1 else 0 := by rw [orthonormal_iff_ite] constructor · intro h v hv w hw convert h ⟨v, hv⟩ ⟨w, hw⟩ using 1 simp · rintro h ⟨v, hv⟩ ⟨w, hw⟩ convert h v hv w hw using 1 simp #align orthonormal_subtype_iff_ite orthonormal_subtype_iff_ite /-- The inner product of a linear combination of a set of orthonormal vectors with one of those vectors picks out the coefficient of that vector. -/
Mathlib/Analysis/InnerProductSpace/Basic.lean
776
779
theorem Orthonormal.inner_right_finsupp {v : ι → E} (hv : Orthonormal 𝕜 v) (l : ι →₀ 𝕜) (i : ι) : ⟪v i, Finsupp.total ι E 𝕜 v l⟫ = l i := by
classical simpa [Finsupp.total_apply, Finsupp.inner_sum, orthonormal_iff_ite.mp hv] using Eq.symm
/- Copyright (c) 2018 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot -/ import Mathlib.Topology.Algebra.Ring.Basic import Mathlib.RingTheory.Ideal.Quotient #align_import topology.algebra.ring.ideal from "leanprover-community/mathlib"@"9a59dcb7a2d06bf55da57b9030169219980660cd" /-! # Ideals and quotients of topological rings In this file we define `Ideal.closure` to be the topological closure of an ideal in a topological ring. We also define a `TopologicalSpace` structure on the quotient of a topological ring by an ideal and prove that the quotient is a topological ring. -/ section Ring variable {R : Type*} [TopologicalSpace R] [Ring R] [TopologicalRing R] /-- The closure of an ideal in a topological ring as an ideal. -/ protected def Ideal.closure (I : Ideal R) : Ideal R := { AddSubmonoid.topologicalClosure I.toAddSubmonoid with carrier := closure I smul_mem' := fun c _ hx => map_mem_closure (mulLeft_continuous _) hx fun _ => I.mul_mem_left c } #align ideal.closure Ideal.closure @[simp] theorem Ideal.coe_closure (I : Ideal R) : (I.closure : Set R) = closure I := rfl #align ideal.coe_closure Ideal.coe_closure -- Porting note: removed `@[simp]` because we make the instance argument explicit since otherwise -- it causes timeouts as `simp` tries and fails to generated an `IsClosed` instance. -- we also `alignₓ` because of the change in argument type -- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/!4.234852.20heartbeats.20of.20the.20linter theorem Ideal.closure_eq_of_isClosed (I : Ideal R) (hI : IsClosed (I : Set R)) : I.closure = I := SetLike.ext' hI.closure_eq #align ideal.closure_eq_of_is_closed Ideal.closure_eq_of_isClosedₓ end Ring section CommRing variable {R : Type*} [TopologicalSpace R] [CommRing R] (N : Ideal R) open Ideal.Quotient instance topologicalRingQuotientTopology : TopologicalSpace (R ⧸ N) := instTopologicalSpaceQuotient #align topological_ring_quotient_topology topologicalRingQuotientTopology -- note for the reader: in the following, `mk` is `Ideal.Quotient.mk`, the canonical map `R → R/I`. variable [TopologicalRing R]
Mathlib/Topology/Algebra/Ring/Ideal.lean
61
65
theorem QuotientRing.isOpenMap_coe : IsOpenMap (mk N) := by
intro s s_op change IsOpen (mk N ⁻¹' (mk N '' s)) rw [quotient_ring_saturate] exact isOpen_iUnion fun ⟨n, _⟩ => isOpenMap_add_left n s s_op
/- Copyright (c) 2019 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.Algebra.Order.Ring.Int import Mathlib.Algebra.Ring.Rat #align_import data.rat.order from "leanprover-community/mathlib"@"a59dad53320b73ef180174aae867addd707ef00e" /-! # The rational numbers form a linear ordered field This file constructs the order on `ℚ` and proves that `ℚ` is a discrete, linearly ordered commutative ring. `ℚ` is in fact a linearly ordered field, but this fact is located in `Data.Rat.Field` instead of here because we need the order on `ℚ` to define `ℚ≥0`, which we itself need to define `Field`. ## Tags rat, rationals, field, ℚ, numerator, denominator, num, denom, order, ordering -/ assert_not_exists Field assert_not_exists Finset assert_not_exists Set.Icc assert_not_exists GaloisConnection namespace Rat variable {a b c p q : ℚ} @[simp] lemma divInt_nonneg_iff_of_pos_right {a b : ℤ} (hb : 0 < b) : 0 ≤ a /. b ↔ 0 ≤ a := by cases' hab : a /. b with n d hd hnd rw [mk'_eq_divInt, divInt_eq_iff hb.ne' (mod_cast hd)] at hab rw [← num_nonneg, ← mul_nonneg_iff_of_pos_right hb, ← hab, mul_nonneg_iff_of_pos_right (mod_cast Nat.pos_of_ne_zero hd)] #align rat.mk_nonneg Rat.divInt_nonneg_iff_of_pos_right @[simp] lemma divInt_nonneg {a b : ℤ} (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a /. b := by obtain rfl | hb := hb.eq_or_lt · simp rfl rwa [divInt_nonneg_iff_of_pos_right hb] @[simp] lemma mkRat_nonneg {a : ℤ} (ha : 0 ≤ a) (b : ℕ) : 0 ≤ mkRat a b := by simpa using divInt_nonneg ha (Int.natCast_nonneg _) theorem ofScientific_nonneg (m : ℕ) (s : Bool) (e : ℕ) : 0 ≤ Rat.ofScientific m s e := by rw [Rat.ofScientific] cases s · rw [if_neg (by decide)] refine num_nonneg.mp ?_ rw [num_natCast] exact Int.natCast_nonneg _ · rw [if_pos rfl, normalize_eq_mkRat] exact Rat.mkRat_nonneg (Int.natCast_nonneg _) _ instance _root_.NNRatCast.toOfScientific {K} [NNRatCast K] : OfScientific K where ofScientific (m : ℕ) (b : Bool) (d : ℕ) := NNRat.cast ⟨Rat.ofScientific m b d, ofScientific_nonneg m b d⟩ /-- Casting a scientific literal via `ℚ≥0` is the same as casting directly. -/ @[simp, norm_cast] theorem _root_.NNRat.cast_ofScientific {K} [NNRatCast K] (m : ℕ) (s : Bool) (e : ℕ) : (OfScientific.ofScientific m s e : ℚ≥0) = (OfScientific.ofScientific m s e : K) := rfl protected lemma add_nonneg : 0 ≤ a → 0 ≤ b → 0 ≤ a + b := numDenCasesOn' a fun n₁ d₁ h₁ ↦ numDenCasesOn' b fun n₂ d₂ h₂ ↦ by have d₁0 : 0 < (d₁ : ℤ) := mod_cast Nat.pos_of_ne_zero h₁ have d₂0 : 0 < (d₂ : ℤ) := mod_cast Nat.pos_of_ne_zero h₂ simp only [d₁0, d₂0, h₁, h₂, mul_pos, divInt_nonneg_iff_of_pos_right, divInt_add_divInt, Ne, Nat.cast_eq_zero, not_false_iff] intro n₁0 n₂0 apply add_nonneg <;> apply mul_nonneg <;> · first |assumption|apply Int.ofNat_zero_le #align rat.nonneg_add Rat.add_nonneg protected lemma mul_nonneg : 0 ≤ a → 0 ≤ b → 0 ≤ a * b := numDenCasesOn' a fun n₁ d₁ h₁ => numDenCasesOn' b fun n₂ d₂ h₂ => by have d₁0 : 0 < (d₁ : ℤ) := mod_cast Nat.pos_of_ne_zero h₁ have d₂0 : 0 < (d₂ : ℤ) := mod_cast Nat.pos_of_ne_zero h₂ simp only [d₁0, d₂0, mul_pos, divInt_nonneg_iff_of_pos_right, divInt_mul_divInt _ _ d₁0.ne' d₂0.ne'] apply mul_nonneg #align rat.nonneg_mul Rat.mul_nonneg #align rat.mul_nonneg Rat.mul_nonneg -- Porting note (#11215): TODO can this be shortened? protected theorem le_iff_sub_nonneg (a b : ℚ) : a ≤ b ↔ 0 ≤ b - a := numDenCasesOn'' a fun na da ha hared => numDenCasesOn'' b fun nb db hb hbred => by change Rat.blt _ _ = false ↔ _ unfold Rat.blt simp only [Bool.and_eq_true, decide_eq_true_eq, Bool.ite_eq_false_distrib, decide_eq_false_iff_not, not_lt, ite_eq_left_iff, not_and, not_le, ← num_nonneg] split_ifs with h h' · rw [Rat.sub_def] simp only [false_iff, not_le] simp only [normalize_eq] apply Int.ediv_neg' · rw [sub_neg] apply lt_of_lt_of_le · apply mul_neg_of_neg_of_pos h.1 rwa [Int.natCast_pos, Nat.pos_iff_ne_zero] · apply mul_nonneg h.2 (Int.natCast_nonneg _) · simp only [Int.natCast_pos, Nat.pos_iff_ne_zero] exact Nat.gcd_ne_zero_right (Nat.mul_ne_zero hb ha) · simp only [divInt_ofNat, ← zero_iff_num_zero, mkRat_eq_zero hb] at h' simp [h'] · simp only [Rat.sub_def, normalize_eq] refine ⟨fun H => ?_, fun H _ => ?_⟩ · refine Int.ediv_nonneg ?_ (Int.natCast_nonneg _) rw [sub_nonneg] push_neg at h obtain hb|hb := Ne.lt_or_lt h' · apply H intro H' exact (hb.trans H').false.elim · obtain ha|ha := le_or_lt na 0 · apply le_trans <| mul_nonpos_of_nonpos_of_nonneg ha (Int.natCast_nonneg _) exact mul_nonneg hb.le (Int.natCast_nonneg _) · exact H (fun _ => ha) · rw [← sub_nonneg] contrapose! H apply Int.ediv_neg' H simp only [Int.natCast_pos, Nat.pos_iff_ne_zero] exact Nat.gcd_ne_zero_right (Nat.mul_ne_zero hb ha) protected lemma divInt_le_divInt {a b c d : ℤ} (b0 : 0 < b) (d0 : 0 < d) : a /. b ≤ c /. d ↔ a * d ≤ c * b := by rw [Rat.le_iff_sub_nonneg, ← sub_nonneg (α := ℤ)] simp [sub_eq_add_neg, ne_of_gt b0, ne_of_gt d0, mul_pos d0 b0] #align rat.le_def Rat.divInt_le_divInt protected lemma le_total : a ≤ b ∨ b ≤ a := by simpa only [← Rat.le_iff_sub_nonneg, neg_sub] using Rat.nonneg_total (b - a) #align rat.le_total Rat.le_total protected theorem not_le {a b : ℚ} : ¬a ≤ b ↔ b < a := (Bool.not_eq_false _).to_iff instance linearOrder : LinearOrder ℚ where le_refl a := by rw [Rat.le_iff_sub_nonneg, ← num_nonneg]; simp le_trans a b c hab hbc := by rw [Rat.le_iff_sub_nonneg] at hab hbc have := Rat.add_nonneg hab hbc simp_rw [sub_eq_add_neg, add_left_comm (b + -a) c (-b), add_comm (b + -a) (-b), add_left_comm (-b) b (-a), add_comm (-b) (-a), add_neg_cancel_comm_assoc, ← sub_eq_add_neg] at this rwa [Rat.le_iff_sub_nonneg] le_antisymm a b hab hba := by rw [Rat.le_iff_sub_nonneg] at hab hba rw [sub_eq_add_neg] at hba rw [← neg_sub, sub_eq_add_neg] at hab have := eq_neg_of_add_eq_zero_left (Rat.nonneg_antisymm hba hab) rwa [neg_neg] at this le_total _ _ := Rat.le_total decidableEq := inferInstance decidableLE := inferInstance decidableLT := inferInstance lt_iff_le_not_le _ _ := by rw [← Rat.not_le, and_iff_right_of_imp Rat.le_total.resolve_left] #align rat.le_refl le_refl #align rat.le_antisymm le_antisymm #align rat.le_trans le_trans /-! ### Extra instances to short-circuit type class resolution These also prevent non-computable instances being used to construct these instances non-computably. -/ instance instDistribLattice : DistribLattice ℚ := inferInstance instance instLattice : Lattice ℚ := inferInstance instance instSemilatticeInf : SemilatticeInf ℚ := inferInstance instance instSemilatticeSup : SemilatticeSup ℚ := inferInstance instance instInf : Inf ℚ := inferInstance instance instSup : Sup ℚ := inferInstance instance instPartialOrder : PartialOrder ℚ := inferInstance instance instPreorder : Preorder ℚ := inferInstance /-! ### Miscellaneous lemmas -/ protected lemma le_def : p ≤ q ↔ p.num * q.den ≤ q.num * p.den := by rw [← num_divInt_den q, ← num_divInt_den p] conv_rhs => simp only [num_divInt_den] exact Rat.divInt_le_divInt (mod_cast p.pos) (mod_cast q.pos) #align rat.le_def' Rat.le_def protected lemma lt_def : p < q ↔ p.num * q.den < q.num * p.den := by rw [lt_iff_le_and_ne, Rat.le_def] suffices p ≠ q ↔ p.num * q.den ≠ q.num * p.den by constructor <;> intro h · exact lt_iff_le_and_ne.mpr ⟨h.left, this.mp h.right⟩ · have tmp := lt_iff_le_and_ne.mp h exact ⟨tmp.left, this.mpr tmp.right⟩ exact not_iff_not.mpr eq_iff_mul_eq_mul #align rat.lt_def Rat.lt_def #noalign rat.nonneg_iff_zero_le protected theorem add_le_add_left {a b c : ℚ} : c + a ≤ c + b ↔ a ≤ b := by rw [Rat.le_iff_sub_nonneg, add_sub_add_left_eq_sub, ← Rat.le_iff_sub_nonneg] #align rat.add_le_add_left Rat.add_le_add_left instance instLinearOrderedCommRing : LinearOrderedCommRing ℚ where __ := Rat.linearOrder __ := Rat.commRing zero_le_one := by decide add_le_add_left := fun a b ab c => Rat.add_le_add_left.2 ab mul_pos a b ha hb := (Rat.mul_nonneg ha.le hb.le).lt_of_ne' (mul_ne_zero ha.ne' hb.ne') -- Extra instances to short-circuit type class resolution instance : LinearOrderedRing ℚ := by infer_instance instance : OrderedRing ℚ := by infer_instance instance : LinearOrderedSemiring ℚ := by infer_instance instance : OrderedSemiring ℚ := by infer_instance instance : LinearOrderedAddCommGroup ℚ := by infer_instance instance : OrderedAddCommGroup ℚ := by infer_instance instance : OrderedCancelAddCommMonoid ℚ := by infer_instance instance : OrderedAddCommMonoid ℚ := by infer_instance @[simp] lemma num_nonpos {a : ℚ} : a.num ≤ 0 ↔ a ≤ 0 := by simpa using @num_nonneg (-a) @[simp] lemma num_pos {a : ℚ} : 0 < a.num ↔ 0 < a := lt_iff_lt_of_le_iff_le num_nonpos #align rat.num_pos_iff_pos Rat.num_pos @[simp] lemma num_neg {a : ℚ} : a.num < 0 ↔ a < 0 := lt_iff_lt_of_le_iff_le num_nonneg @[deprecated (since := "2024-02-16")] alias num_nonneg_iff_zero_le := num_nonneg @[deprecated (since := "2024-02-16")] alias num_pos_iff_pos := num_pos
Mathlib/Algebra/Order/Ring/Rat.lean
240
246
theorem div_lt_div_iff_mul_lt_mul {a b c d : ℤ} (b_pos : 0 < b) (d_pos : 0 < d) : (a : ℚ) / b < c / d ↔ a * d < c * b := by
simp only [lt_iff_le_not_le] apply and_congr · simp [div_def', Rat.divInt_le_divInt b_pos d_pos] · apply not_congr simp [div_def', Rat.divInt_le_divInt d_pos b_pos]
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Yury Kudryashov -/ import Mathlib.Analysis.Normed.Group.InfiniteSum import Mathlib.Analysis.Normed.MulAction import Mathlib.Topology.Algebra.Order.LiminfLimsup import Mathlib.Topology.PartialHomeomorph #align_import analysis.asymptotics.asymptotics from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Asymptotics We introduce these relations: * `IsBigOWith c l f g` : "f is big O of g along l with constant c"; * `f =O[l] g` : "f is big O of g along l"; * `f =o[l] g` : "f is little o of g along l". Here `l` is any filter on the domain of `f` and `g`, which are assumed to be the same. The codomains of `f` and `g` do not need to be the same; all that is needed that there is a norm associated with these types, and it is the norm that is compared asymptotically. The relation `IsBigOWith c` is introduced to factor out common algebraic arguments in the proofs of similar properties of `IsBigO` and `IsLittleO`. Usually proofs outside of this file should use `IsBigO` instead. Often the ranges of `f` and `g` will be the real numbers, in which case the norm is the absolute value. In general, we have `f =O[l] g ↔ (fun x ↦ ‖f x‖) =O[l] (fun x ↦ ‖g x‖)`, and similarly for `IsLittleO`. But our setup allows us to use the notions e.g. with functions to the integers, rationals, complex numbers, or any normed vector space without mentioning the norm explicitly. If `f` and `g` are functions to a normed field like the reals or complex numbers and `g` is always nonzero, we have `f =o[l] g ↔ Tendsto (fun x ↦ f x / (g x)) l (𝓝 0)`. In fact, the right-to-left direction holds without the hypothesis on `g`, and in the other direction it suffices to assume that `f` is zero wherever `g` is. (This generalization is useful in defining the Fréchet derivative.) -/ open Filter Set open scoped Classical open Topology Filter NNReal namespace Asymptotics set_option linter.uppercaseLean3 false variable {α : Type*} {β : Type*} {E : Type*} {F : Type*} {G : Type*} {E' : Type*} {F' : Type*} {G' : Type*} {E'' : Type*} {F'' : Type*} {G'' : Type*} {E''' : Type*} {R : Type*} {R' : Type*} {𝕜 : Type*} {𝕜' : Type*} variable [Norm E] [Norm F] [Norm G] variable [SeminormedAddCommGroup E'] [SeminormedAddCommGroup F'] [SeminormedAddCommGroup G'] [NormedAddCommGroup E''] [NormedAddCommGroup F''] [NormedAddCommGroup G''] [SeminormedRing R] [SeminormedAddGroup E'''] [SeminormedRing R'] variable [NormedDivisionRing 𝕜] [NormedDivisionRing 𝕜'] variable {c c' c₁ c₂ : ℝ} {f : α → E} {g : α → F} {k : α → G} variable {f' : α → E'} {g' : α → F'} {k' : α → G'} variable {f'' : α → E''} {g'' : α → F''} {k'' : α → G''} variable {l l' : Filter α} section Defs /-! ### Definitions -/ /-- This version of the Landau notation `IsBigOWith C l f g` where `f` and `g` are two functions on a type `α` and `l` is a filter on `α`, means that eventually for `l`, `‖f‖` is bounded by `C * ‖g‖`. In other words, `‖f‖ / ‖g‖` is eventually bounded by `C`, modulo division by zero issues that are avoided by this definition. Probably you want to use `IsBigO` instead of this relation. -/ irreducible_def IsBigOWith (c : ℝ) (l : Filter α) (f : α → E) (g : α → F) : Prop := ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ #align asymptotics.is_O_with Asymptotics.IsBigOWith /-- Definition of `IsBigOWith`. We record it in a lemma as `IsBigOWith` is irreducible. -/ theorem isBigOWith_iff : IsBigOWith c l f g ↔ ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := by rw [IsBigOWith_def] #align asymptotics.is_O_with_iff Asymptotics.isBigOWith_iff alias ⟨IsBigOWith.bound, IsBigOWith.of_bound⟩ := isBigOWith_iff #align asymptotics.is_O_with.bound Asymptotics.IsBigOWith.bound #align asymptotics.is_O_with.of_bound Asymptotics.IsBigOWith.of_bound /-- The Landau notation `f =O[l] g` where `f` and `g` are two functions on a type `α` and `l` is a filter on `α`, means that eventually for `l`, `‖f‖` is bounded by a constant multiple of `‖g‖`. In other words, `‖f‖ / ‖g‖` is eventually bounded, modulo division by zero issues that are avoided by this definition. -/ irreducible_def IsBigO (l : Filter α) (f : α → E) (g : α → F) : Prop := ∃ c : ℝ, IsBigOWith c l f g #align asymptotics.is_O Asymptotics.IsBigO @[inherit_doc] notation:100 f " =O[" l "] " g:100 => IsBigO l f g /-- Definition of `IsBigO` in terms of `IsBigOWith`. We record it in a lemma as `IsBigO` is irreducible. -/ theorem isBigO_iff_isBigOWith : f =O[l] g ↔ ∃ c : ℝ, IsBigOWith c l f g := by rw [IsBigO_def] #align asymptotics.is_O_iff_is_O_with Asymptotics.isBigO_iff_isBigOWith /-- Definition of `IsBigO` in terms of filters. -/ theorem isBigO_iff : f =O[l] g ↔ ∃ c : ℝ, ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := by simp only [IsBigO_def, IsBigOWith_def] #align asymptotics.is_O_iff Asymptotics.isBigO_iff /-- Definition of `IsBigO` in terms of filters, with a positive constant. -/ theorem isBigO_iff' {g : α → E'''} : f =O[l] g ↔ ∃ c > 0, ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := by refine ⟨fun h => ?mp, fun h => ?mpr⟩ case mp => rw [isBigO_iff] at h obtain ⟨c, hc⟩ := h refine ⟨max c 1, zero_lt_one.trans_le (le_max_right _ _), ?_⟩ filter_upwards [hc] with x hx apply hx.trans gcongr exact le_max_left _ _ case mpr => rw [isBigO_iff] obtain ⟨c, ⟨_, hc⟩⟩ := h exact ⟨c, hc⟩ /-- Definition of `IsBigO` in terms of filters, with the constant in the lower bound. -/ theorem isBigO_iff'' {g : α → E'''} : f =O[l] g ↔ ∃ c > 0, ∀ᶠ x in l, c * ‖f x‖ ≤ ‖g x‖ := by refine ⟨fun h => ?mp, fun h => ?mpr⟩ case mp => rw [isBigO_iff'] at h obtain ⟨c, ⟨hc_pos, hc⟩⟩ := h refine ⟨c⁻¹, ⟨by positivity, ?_⟩⟩ filter_upwards [hc] with x hx rwa [inv_mul_le_iff (by positivity)] case mpr => rw [isBigO_iff'] obtain ⟨c, ⟨hc_pos, hc⟩⟩ := h refine ⟨c⁻¹, ⟨by positivity, ?_⟩⟩ filter_upwards [hc] with x hx rwa [← inv_inv c, inv_mul_le_iff (by positivity)] at hx theorem IsBigO.of_bound (c : ℝ) (h : ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖) : f =O[l] g := isBigO_iff.2 ⟨c, h⟩ #align asymptotics.is_O.of_bound Asymptotics.IsBigO.of_bound theorem IsBigO.of_bound' (h : ∀ᶠ x in l, ‖f x‖ ≤ ‖g x‖) : f =O[l] g := IsBigO.of_bound 1 <| by simp_rw [one_mul] exact h #align asymptotics.is_O.of_bound' Asymptotics.IsBigO.of_bound' theorem IsBigO.bound : f =O[l] g → ∃ c : ℝ, ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := isBigO_iff.1 #align asymptotics.is_O.bound Asymptotics.IsBigO.bound /-- The Landau notation `f =o[l] g` where `f` and `g` are two functions on a type `α` and `l` is a filter on `α`, means that eventually for `l`, `‖f‖` is bounded by an arbitrarily small constant multiple of `‖g‖`. In other words, `‖f‖ / ‖g‖` tends to `0` along `l`, modulo division by zero issues that are avoided by this definition. -/ irreducible_def IsLittleO (l : Filter α) (f : α → E) (g : α → F) : Prop := ∀ ⦃c : ℝ⦄, 0 < c → IsBigOWith c l f g #align asymptotics.is_o Asymptotics.IsLittleO @[inherit_doc] notation:100 f " =o[" l "] " g:100 => IsLittleO l f g /-- Definition of `IsLittleO` in terms of `IsBigOWith`. -/ theorem isLittleO_iff_forall_isBigOWith : f =o[l] g ↔ ∀ ⦃c : ℝ⦄, 0 < c → IsBigOWith c l f g := by rw [IsLittleO_def] #align asymptotics.is_o_iff_forall_is_O_with Asymptotics.isLittleO_iff_forall_isBigOWith alias ⟨IsLittleO.forall_isBigOWith, IsLittleO.of_isBigOWith⟩ := isLittleO_iff_forall_isBigOWith #align asymptotics.is_o.forall_is_O_with Asymptotics.IsLittleO.forall_isBigOWith #align asymptotics.is_o.of_is_O_with Asymptotics.IsLittleO.of_isBigOWith /-- Definition of `IsLittleO` in terms of filters. -/ theorem isLittleO_iff : f =o[l] g ↔ ∀ ⦃c : ℝ⦄, 0 < c → ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := by simp only [IsLittleO_def, IsBigOWith_def] #align asymptotics.is_o_iff Asymptotics.isLittleO_iff alias ⟨IsLittleO.bound, IsLittleO.of_bound⟩ := isLittleO_iff #align asymptotics.is_o.bound Asymptotics.IsLittleO.bound #align asymptotics.is_o.of_bound Asymptotics.IsLittleO.of_bound theorem IsLittleO.def (h : f =o[l] g) (hc : 0 < c) : ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := isLittleO_iff.1 h hc #align asymptotics.is_o.def Asymptotics.IsLittleO.def theorem IsLittleO.def' (h : f =o[l] g) (hc : 0 < c) : IsBigOWith c l f g := isBigOWith_iff.2 <| isLittleO_iff.1 h hc #align asymptotics.is_o.def' Asymptotics.IsLittleO.def' theorem IsLittleO.eventuallyLE (h : f =o[l] g) : ∀ᶠ x in l, ‖f x‖ ≤ ‖g x‖ := by simpa using h.def zero_lt_one end Defs /-! ### Conversions -/ theorem IsBigOWith.isBigO (h : IsBigOWith c l f g) : f =O[l] g := by rw [IsBigO_def]; exact ⟨c, h⟩ #align asymptotics.is_O_with.is_O Asymptotics.IsBigOWith.isBigO theorem IsLittleO.isBigOWith (hgf : f =o[l] g) : IsBigOWith 1 l f g := hgf.def' zero_lt_one #align asymptotics.is_o.is_O_with Asymptotics.IsLittleO.isBigOWith theorem IsLittleO.isBigO (hgf : f =o[l] g) : f =O[l] g := hgf.isBigOWith.isBigO #align asymptotics.is_o.is_O Asymptotics.IsLittleO.isBigO theorem IsBigO.isBigOWith : f =O[l] g → ∃ c : ℝ, IsBigOWith c l f g := isBigO_iff_isBigOWith.1 #align asymptotics.is_O.is_O_with Asymptotics.IsBigO.isBigOWith theorem IsBigOWith.weaken (h : IsBigOWith c l f g') (hc : c ≤ c') : IsBigOWith c' l f g' := IsBigOWith.of_bound <| mem_of_superset h.bound fun x hx => calc ‖f x‖ ≤ c * ‖g' x‖ := hx _ ≤ _ := by gcongr #align asymptotics.is_O_with.weaken Asymptotics.IsBigOWith.weaken theorem IsBigOWith.exists_pos (h : IsBigOWith c l f g') : ∃ c' > 0, IsBigOWith c' l f g' := ⟨max c 1, lt_of_lt_of_le zero_lt_one (le_max_right c 1), h.weaken <| le_max_left c 1⟩ #align asymptotics.is_O_with.exists_pos Asymptotics.IsBigOWith.exists_pos theorem IsBigO.exists_pos (h : f =O[l] g') : ∃ c > 0, IsBigOWith c l f g' := let ⟨_c, hc⟩ := h.isBigOWith hc.exists_pos #align asymptotics.is_O.exists_pos Asymptotics.IsBigO.exists_pos theorem IsBigOWith.exists_nonneg (h : IsBigOWith c l f g') : ∃ c' ≥ 0, IsBigOWith c' l f g' := let ⟨c, cpos, hc⟩ := h.exists_pos ⟨c, le_of_lt cpos, hc⟩ #align asymptotics.is_O_with.exists_nonneg Asymptotics.IsBigOWith.exists_nonneg theorem IsBigO.exists_nonneg (h : f =O[l] g') : ∃ c ≥ 0, IsBigOWith c l f g' := let ⟨_c, hc⟩ := h.isBigOWith hc.exists_nonneg #align asymptotics.is_O.exists_nonneg Asymptotics.IsBigO.exists_nonneg /-- `f = O(g)` if and only if `IsBigOWith c f g` for all sufficiently large `c`. -/ theorem isBigO_iff_eventually_isBigOWith : f =O[l] g' ↔ ∀ᶠ c in atTop, IsBigOWith c l f g' := isBigO_iff_isBigOWith.trans ⟨fun ⟨c, hc⟩ => mem_atTop_sets.2 ⟨c, fun _c' hc' => hc.weaken hc'⟩, fun h => h.exists⟩ #align asymptotics.is_O_iff_eventually_is_O_with Asymptotics.isBigO_iff_eventually_isBigOWith /-- `f = O(g)` if and only if `∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖` for all sufficiently large `c`. -/ theorem isBigO_iff_eventually : f =O[l] g' ↔ ∀ᶠ c in atTop, ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g' x‖ := isBigO_iff_eventually_isBigOWith.trans <| by simp only [IsBigOWith_def] #align asymptotics.is_O_iff_eventually Asymptotics.isBigO_iff_eventually theorem IsBigO.exists_mem_basis {ι} {p : ι → Prop} {s : ι → Set α} (h : f =O[l] g') (hb : l.HasBasis p s) : ∃ c > 0, ∃ i : ι, p i ∧ ∀ x ∈ s i, ‖f x‖ ≤ c * ‖g' x‖ := flip Exists.imp h.exists_pos fun c h => by simpa only [isBigOWith_iff, hb.eventually_iff, exists_prop] using h #align asymptotics.is_O.exists_mem_basis Asymptotics.IsBigO.exists_mem_basis theorem isBigOWith_inv (hc : 0 < c) : IsBigOWith c⁻¹ l f g ↔ ∀ᶠ x in l, c * ‖f x‖ ≤ ‖g x‖ := by simp only [IsBigOWith_def, ← div_eq_inv_mul, le_div_iff' hc] #align asymptotics.is_O_with_inv Asymptotics.isBigOWith_inv -- We prove this lemma with strange assumptions to get two lemmas below automatically theorem isLittleO_iff_nat_mul_le_aux (h₀ : (∀ x, 0 ≤ ‖f x‖) ∨ ∀ x, 0 ≤ ‖g x‖) : f =o[l] g ↔ ∀ n : ℕ, ∀ᶠ x in l, ↑n * ‖f x‖ ≤ ‖g x‖ := by constructor · rintro H (_ | n) · refine (H.def one_pos).mono fun x h₀' => ?_ rw [Nat.cast_zero, zero_mul] refine h₀.elim (fun hf => (hf x).trans ?_) fun hg => hg x rwa [one_mul] at h₀' · have : (0 : ℝ) < n.succ := Nat.cast_pos.2 n.succ_pos exact (isBigOWith_inv this).1 (H.def' <| inv_pos.2 this) · refine fun H => isLittleO_iff.2 fun ε ε0 => ?_ rcases exists_nat_gt ε⁻¹ with ⟨n, hn⟩ have hn₀ : (0 : ℝ) < n := (inv_pos.2 ε0).trans hn refine ((isBigOWith_inv hn₀).2 (H n)).bound.mono fun x hfg => ?_ refine hfg.trans (mul_le_mul_of_nonneg_right (inv_le_of_inv_le ε0 hn.le) ?_) refine h₀.elim (fun hf => nonneg_of_mul_nonneg_right ((hf x).trans hfg) ?_) fun h => h x exact inv_pos.2 hn₀ #align asymptotics.is_o_iff_nat_mul_le_aux Asymptotics.isLittleO_iff_nat_mul_le_aux theorem isLittleO_iff_nat_mul_le : f =o[l] g' ↔ ∀ n : ℕ, ∀ᶠ x in l, ↑n * ‖f x‖ ≤ ‖g' x‖ := isLittleO_iff_nat_mul_le_aux (Or.inr fun _x => norm_nonneg _) #align asymptotics.is_o_iff_nat_mul_le Asymptotics.isLittleO_iff_nat_mul_le theorem isLittleO_iff_nat_mul_le' : f' =o[l] g ↔ ∀ n : ℕ, ∀ᶠ x in l, ↑n * ‖f' x‖ ≤ ‖g x‖ := isLittleO_iff_nat_mul_le_aux (Or.inl fun _x => norm_nonneg _) #align asymptotics.is_o_iff_nat_mul_le' Asymptotics.isLittleO_iff_nat_mul_le' /-! ### Subsingleton -/ @[nontriviality] theorem isLittleO_of_subsingleton [Subsingleton E'] : f' =o[l] g' := IsLittleO.of_bound fun c hc => by simp [Subsingleton.elim (f' _) 0, mul_nonneg hc.le] #align asymptotics.is_o_of_subsingleton Asymptotics.isLittleO_of_subsingleton @[nontriviality] theorem isBigO_of_subsingleton [Subsingleton E'] : f' =O[l] g' := isLittleO_of_subsingleton.isBigO #align asymptotics.is_O_of_subsingleton Asymptotics.isBigO_of_subsingleton section congr variable {f₁ f₂ : α → E} {g₁ g₂ : α → F} /-! ### Congruence -/ theorem isBigOWith_congr (hc : c₁ = c₂) (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : IsBigOWith c₁ l f₁ g₁ ↔ IsBigOWith c₂ l f₂ g₂ := by simp only [IsBigOWith_def] subst c₂ apply Filter.eventually_congr filter_upwards [hf, hg] with _ e₁ e₂ rw [e₁, e₂] #align asymptotics.is_O_with_congr Asymptotics.isBigOWith_congr theorem IsBigOWith.congr' (h : IsBigOWith c₁ l f₁ g₁) (hc : c₁ = c₂) (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : IsBigOWith c₂ l f₂ g₂ := (isBigOWith_congr hc hf hg).mp h #align asymptotics.is_O_with.congr' Asymptotics.IsBigOWith.congr' theorem IsBigOWith.congr (h : IsBigOWith c₁ l f₁ g₁) (hc : c₁ = c₂) (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) : IsBigOWith c₂ l f₂ g₂ := h.congr' hc (univ_mem' hf) (univ_mem' hg) #align asymptotics.is_O_with.congr Asymptotics.IsBigOWith.congr theorem IsBigOWith.congr_left (h : IsBigOWith c l f₁ g) (hf : ∀ x, f₁ x = f₂ x) : IsBigOWith c l f₂ g := h.congr rfl hf fun _ => rfl #align asymptotics.is_O_with.congr_left Asymptotics.IsBigOWith.congr_left theorem IsBigOWith.congr_right (h : IsBigOWith c l f g₁) (hg : ∀ x, g₁ x = g₂ x) : IsBigOWith c l f g₂ := h.congr rfl (fun _ => rfl) hg #align asymptotics.is_O_with.congr_right Asymptotics.IsBigOWith.congr_right theorem IsBigOWith.congr_const (h : IsBigOWith c₁ l f g) (hc : c₁ = c₂) : IsBigOWith c₂ l f g := h.congr hc (fun _ => rfl) fun _ => rfl #align asymptotics.is_O_with.congr_const Asymptotics.IsBigOWith.congr_const theorem isBigO_congr (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : f₁ =O[l] g₁ ↔ f₂ =O[l] g₂ := by simp only [IsBigO_def] exact exists_congr fun c => isBigOWith_congr rfl hf hg #align asymptotics.is_O_congr Asymptotics.isBigO_congr theorem IsBigO.congr' (h : f₁ =O[l] g₁) (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : f₂ =O[l] g₂ := (isBigO_congr hf hg).mp h #align asymptotics.is_O.congr' Asymptotics.IsBigO.congr' theorem IsBigO.congr (h : f₁ =O[l] g₁) (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) : f₂ =O[l] g₂ := h.congr' (univ_mem' hf) (univ_mem' hg) #align asymptotics.is_O.congr Asymptotics.IsBigO.congr theorem IsBigO.congr_left (h : f₁ =O[l] g) (hf : ∀ x, f₁ x = f₂ x) : f₂ =O[l] g := h.congr hf fun _ => rfl #align asymptotics.is_O.congr_left Asymptotics.IsBigO.congr_left theorem IsBigO.congr_right (h : f =O[l] g₁) (hg : ∀ x, g₁ x = g₂ x) : f =O[l] g₂ := h.congr (fun _ => rfl) hg #align asymptotics.is_O.congr_right Asymptotics.IsBigO.congr_right theorem isLittleO_congr (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : f₁ =o[l] g₁ ↔ f₂ =o[l] g₂ := by simp only [IsLittleO_def] exact forall₂_congr fun c _hc => isBigOWith_congr (Eq.refl c) hf hg #align asymptotics.is_o_congr Asymptotics.isLittleO_congr theorem IsLittleO.congr' (h : f₁ =o[l] g₁) (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : f₂ =o[l] g₂ := (isLittleO_congr hf hg).mp h #align asymptotics.is_o.congr' Asymptotics.IsLittleO.congr' theorem IsLittleO.congr (h : f₁ =o[l] g₁) (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) : f₂ =o[l] g₂ := h.congr' (univ_mem' hf) (univ_mem' hg) #align asymptotics.is_o.congr Asymptotics.IsLittleO.congr theorem IsLittleO.congr_left (h : f₁ =o[l] g) (hf : ∀ x, f₁ x = f₂ x) : f₂ =o[l] g := h.congr hf fun _ => rfl #align asymptotics.is_o.congr_left Asymptotics.IsLittleO.congr_left theorem IsLittleO.congr_right (h : f =o[l] g₁) (hg : ∀ x, g₁ x = g₂ x) : f =o[l] g₂ := h.congr (fun _ => rfl) hg #align asymptotics.is_o.congr_right Asymptotics.IsLittleO.congr_right @[trans] theorem _root_.Filter.EventuallyEq.trans_isBigO {f₁ f₂ : α → E} {g : α → F} (hf : f₁ =ᶠ[l] f₂) (h : f₂ =O[l] g) : f₁ =O[l] g := h.congr' hf.symm EventuallyEq.rfl #align filter.eventually_eq.trans_is_O Filter.EventuallyEq.trans_isBigO instance transEventuallyEqIsBigO : @Trans (α → E) (α → E) (α → F) (· =ᶠ[l] ·) (· =O[l] ·) (· =O[l] ·) where trans := Filter.EventuallyEq.trans_isBigO @[trans] theorem _root_.Filter.EventuallyEq.trans_isLittleO {f₁ f₂ : α → E} {g : α → F} (hf : f₁ =ᶠ[l] f₂) (h : f₂ =o[l] g) : f₁ =o[l] g := h.congr' hf.symm EventuallyEq.rfl #align filter.eventually_eq.trans_is_o Filter.EventuallyEq.trans_isLittleO instance transEventuallyEqIsLittleO : @Trans (α → E) (α → E) (α → F) (· =ᶠ[l] ·) (· =o[l] ·) (· =o[l] ·) where trans := Filter.EventuallyEq.trans_isLittleO @[trans] theorem IsBigO.trans_eventuallyEq {f : α → E} {g₁ g₂ : α → F} (h : f =O[l] g₁) (hg : g₁ =ᶠ[l] g₂) : f =O[l] g₂ := h.congr' EventuallyEq.rfl hg #align asymptotics.is_O.trans_eventually_eq Asymptotics.IsBigO.trans_eventuallyEq instance transIsBigOEventuallyEq : @Trans (α → E) (α → F) (α → F) (· =O[l] ·) (· =ᶠ[l] ·) (· =O[l] ·) where trans := IsBigO.trans_eventuallyEq @[trans] theorem IsLittleO.trans_eventuallyEq {f : α → E} {g₁ g₂ : α → F} (h : f =o[l] g₁) (hg : g₁ =ᶠ[l] g₂) : f =o[l] g₂ := h.congr' EventuallyEq.rfl hg #align asymptotics.is_o.trans_eventually_eq Asymptotics.IsLittleO.trans_eventuallyEq instance transIsLittleOEventuallyEq : @Trans (α → E) (α → F) (α → F) (· =o[l] ·) (· =ᶠ[l] ·) (· =o[l] ·) where trans := IsLittleO.trans_eventuallyEq end congr /-! ### Filter operations and transitivity -/ theorem IsBigOWith.comp_tendsto (hcfg : IsBigOWith c l f g) {k : β → α} {l' : Filter β} (hk : Tendsto k l' l) : IsBigOWith c l' (f ∘ k) (g ∘ k) := IsBigOWith.of_bound <| hk hcfg.bound #align asymptotics.is_O_with.comp_tendsto Asymptotics.IsBigOWith.comp_tendsto theorem IsBigO.comp_tendsto (hfg : f =O[l] g) {k : β → α} {l' : Filter β} (hk : Tendsto k l' l) : (f ∘ k) =O[l'] (g ∘ k) := isBigO_iff_isBigOWith.2 <| hfg.isBigOWith.imp fun _c h => h.comp_tendsto hk #align asymptotics.is_O.comp_tendsto Asymptotics.IsBigO.comp_tendsto theorem IsLittleO.comp_tendsto (hfg : f =o[l] g) {k : β → α} {l' : Filter β} (hk : Tendsto k l' l) : (f ∘ k) =o[l'] (g ∘ k) := IsLittleO.of_isBigOWith fun _c cpos => (hfg.forall_isBigOWith cpos).comp_tendsto hk #align asymptotics.is_o.comp_tendsto Asymptotics.IsLittleO.comp_tendsto @[simp] theorem isBigOWith_map {k : β → α} {l : Filter β} : IsBigOWith c (map k l) f g ↔ IsBigOWith c l (f ∘ k) (g ∘ k) := by simp only [IsBigOWith_def] exact eventually_map #align asymptotics.is_O_with_map Asymptotics.isBigOWith_map @[simp] theorem isBigO_map {k : β → α} {l : Filter β} : f =O[map k l] g ↔ (f ∘ k) =O[l] (g ∘ k) := by simp only [IsBigO_def, isBigOWith_map] #align asymptotics.is_O_map Asymptotics.isBigO_map @[simp] theorem isLittleO_map {k : β → α} {l : Filter β} : f =o[map k l] g ↔ (f ∘ k) =o[l] (g ∘ k) := by simp only [IsLittleO_def, isBigOWith_map] #align asymptotics.is_o_map Asymptotics.isLittleO_map theorem IsBigOWith.mono (h : IsBigOWith c l' f g) (hl : l ≤ l') : IsBigOWith c l f g := IsBigOWith.of_bound <| hl h.bound #align asymptotics.is_O_with.mono Asymptotics.IsBigOWith.mono theorem IsBigO.mono (h : f =O[l'] g) (hl : l ≤ l') : f =O[l] g := isBigO_iff_isBigOWith.2 <| h.isBigOWith.imp fun _c h => h.mono hl #align asymptotics.is_O.mono Asymptotics.IsBigO.mono theorem IsLittleO.mono (h : f =o[l'] g) (hl : l ≤ l') : f =o[l] g := IsLittleO.of_isBigOWith fun _c cpos => (h.forall_isBigOWith cpos).mono hl #align asymptotics.is_o.mono Asymptotics.IsLittleO.mono theorem IsBigOWith.trans (hfg : IsBigOWith c l f g) (hgk : IsBigOWith c' l g k) (hc : 0 ≤ c) : IsBigOWith (c * c') l f k := by simp only [IsBigOWith_def] at * filter_upwards [hfg, hgk] with x hx hx' calc ‖f x‖ ≤ c * ‖g x‖ := hx _ ≤ c * (c' * ‖k x‖) := by gcongr _ = c * c' * ‖k x‖ := (mul_assoc _ _ _).symm #align asymptotics.is_O_with.trans Asymptotics.IsBigOWith.trans @[trans] theorem IsBigO.trans {f : α → E} {g : α → F'} {k : α → G} (hfg : f =O[l] g) (hgk : g =O[l] k) : f =O[l] k := let ⟨_c, cnonneg, hc⟩ := hfg.exists_nonneg let ⟨_c', hc'⟩ := hgk.isBigOWith (hc.trans hc' cnonneg).isBigO #align asymptotics.is_O.trans Asymptotics.IsBigO.trans instance transIsBigOIsBigO : @Trans (α → E) (α → F') (α → G) (· =O[l] ·) (· =O[l] ·) (· =O[l] ·) where trans := IsBigO.trans theorem IsLittleO.trans_isBigOWith (hfg : f =o[l] g) (hgk : IsBigOWith c l g k) (hc : 0 < c) : f =o[l] k := by simp only [IsLittleO_def] at * intro c' c'pos have : 0 < c' / c := div_pos c'pos hc exact ((hfg this).trans hgk this.le).congr_const (div_mul_cancel₀ _ hc.ne') #align asymptotics.is_o.trans_is_O_with Asymptotics.IsLittleO.trans_isBigOWith @[trans] theorem IsLittleO.trans_isBigO {f : α → E} {g : α → F} {k : α → G'} (hfg : f =o[l] g) (hgk : g =O[l] k) : f =o[l] k := let ⟨_c, cpos, hc⟩ := hgk.exists_pos hfg.trans_isBigOWith hc cpos #align asymptotics.is_o.trans_is_O Asymptotics.IsLittleO.trans_isBigO instance transIsLittleOIsBigO : @Trans (α → E) (α → F) (α → G') (· =o[l] ·) (· =O[l] ·) (· =o[l] ·) where trans := IsLittleO.trans_isBigO theorem IsBigOWith.trans_isLittleO (hfg : IsBigOWith c l f g) (hgk : g =o[l] k) (hc : 0 < c) : f =o[l] k := by simp only [IsLittleO_def] at * intro c' c'pos have : 0 < c' / c := div_pos c'pos hc exact (hfg.trans (hgk this) hc.le).congr_const (mul_div_cancel₀ _ hc.ne') #align asymptotics.is_O_with.trans_is_o Asymptotics.IsBigOWith.trans_isLittleO @[trans] theorem IsBigO.trans_isLittleO {f : α → E} {g : α → F'} {k : α → G} (hfg : f =O[l] g) (hgk : g =o[l] k) : f =o[l] k := let ⟨_c, cpos, hc⟩ := hfg.exists_pos hc.trans_isLittleO hgk cpos #align asymptotics.is_O.trans_is_o Asymptotics.IsBigO.trans_isLittleO instance transIsBigOIsLittleO : @Trans (α → E) (α → F') (α → G) (· =O[l] ·) (· =o[l] ·) (· =o[l] ·) where trans := IsBigO.trans_isLittleO @[trans] theorem IsLittleO.trans {f : α → E} {g : α → F} {k : α → G} (hfg : f =o[l] g) (hgk : g =o[l] k) : f =o[l] k := hfg.trans_isBigOWith hgk.isBigOWith one_pos #align asymptotics.is_o.trans Asymptotics.IsLittleO.trans instance transIsLittleOIsLittleO : @Trans (α → E) (α → F) (α → G) (· =o[l] ·) (· =o[l] ·) (· =o[l] ·) where trans := IsLittleO.trans theorem _root_.Filter.Eventually.trans_isBigO {f : α → E} {g : α → F'} {k : α → G} (hfg : ∀ᶠ x in l, ‖f x‖ ≤ ‖g x‖) (hgk : g =O[l] k) : f =O[l] k := (IsBigO.of_bound' hfg).trans hgk #align filter.eventually.trans_is_O Filter.Eventually.trans_isBigO theorem _root_.Filter.Eventually.isBigO {f : α → E} {g : α → ℝ} {l : Filter α} (hfg : ∀ᶠ x in l, ‖f x‖ ≤ g x) : f =O[l] g := IsBigO.of_bound' <| hfg.mono fun _x hx => hx.trans <| Real.le_norm_self _ #align filter.eventually.is_O Filter.Eventually.isBigO section variable (l) theorem isBigOWith_of_le' (hfg : ∀ x, ‖f x‖ ≤ c * ‖g x‖) : IsBigOWith c l f g := IsBigOWith.of_bound <| univ_mem' hfg #align asymptotics.is_O_with_of_le' Asymptotics.isBigOWith_of_le' theorem isBigOWith_of_le (hfg : ∀ x, ‖f x‖ ≤ ‖g x‖) : IsBigOWith 1 l f g := isBigOWith_of_le' l fun x => by rw [one_mul] exact hfg x #align asymptotics.is_O_with_of_le Asymptotics.isBigOWith_of_le theorem isBigO_of_le' (hfg : ∀ x, ‖f x‖ ≤ c * ‖g x‖) : f =O[l] g := (isBigOWith_of_le' l hfg).isBigO #align asymptotics.is_O_of_le' Asymptotics.isBigO_of_le' theorem isBigO_of_le (hfg : ∀ x, ‖f x‖ ≤ ‖g x‖) : f =O[l] g := (isBigOWith_of_le l hfg).isBigO #align asymptotics.is_O_of_le Asymptotics.isBigO_of_le end theorem isBigOWith_refl (f : α → E) (l : Filter α) : IsBigOWith 1 l f f := isBigOWith_of_le l fun _ => le_rfl #align asymptotics.is_O_with_refl Asymptotics.isBigOWith_refl theorem isBigO_refl (f : α → E) (l : Filter α) : f =O[l] f := (isBigOWith_refl f l).isBigO #align asymptotics.is_O_refl Asymptotics.isBigO_refl theorem _root_.Filter.EventuallyEq.isBigO {f₁ f₂ : α → E} (hf : f₁ =ᶠ[l] f₂) : f₁ =O[l] f₂ := hf.trans_isBigO (isBigO_refl _ _) theorem IsBigOWith.trans_le (hfg : IsBigOWith c l f g) (hgk : ∀ x, ‖g x‖ ≤ ‖k x‖) (hc : 0 ≤ c) : IsBigOWith c l f k := (hfg.trans (isBigOWith_of_le l hgk) hc).congr_const <| mul_one c #align asymptotics.is_O_with.trans_le Asymptotics.IsBigOWith.trans_le theorem IsBigO.trans_le (hfg : f =O[l] g') (hgk : ∀ x, ‖g' x‖ ≤ ‖k x‖) : f =O[l] k := hfg.trans (isBigO_of_le l hgk) #align asymptotics.is_O.trans_le Asymptotics.IsBigO.trans_le theorem IsLittleO.trans_le (hfg : f =o[l] g) (hgk : ∀ x, ‖g x‖ ≤ ‖k x‖) : f =o[l] k := hfg.trans_isBigOWith (isBigOWith_of_le _ hgk) zero_lt_one #align asymptotics.is_o.trans_le Asymptotics.IsLittleO.trans_le theorem isLittleO_irrefl' (h : ∃ᶠ x in l, ‖f' x‖ ≠ 0) : ¬f' =o[l] f' := by intro ho rcases ((ho.bound one_half_pos).and_frequently h).exists with ⟨x, hle, hne⟩ rw [one_div, ← div_eq_inv_mul] at hle exact (half_lt_self (lt_of_le_of_ne (norm_nonneg _) hne.symm)).not_le hle #align asymptotics.is_o_irrefl' Asymptotics.isLittleO_irrefl' theorem isLittleO_irrefl (h : ∃ᶠ x in l, f'' x ≠ 0) : ¬f'' =o[l] f'' := isLittleO_irrefl' <| h.mono fun _x => norm_ne_zero_iff.mpr #align asymptotics.is_o_irrefl Asymptotics.isLittleO_irrefl theorem IsBigO.not_isLittleO (h : f'' =O[l] g') (hf : ∃ᶠ x in l, f'' x ≠ 0) : ¬g' =o[l] f'' := fun h' => isLittleO_irrefl hf (h.trans_isLittleO h') #align asymptotics.is_O.not_is_o Asymptotics.IsBigO.not_isLittleO theorem IsLittleO.not_isBigO (h : f'' =o[l] g') (hf : ∃ᶠ x in l, f'' x ≠ 0) : ¬g' =O[l] f'' := fun h' => isLittleO_irrefl hf (h.trans_isBigO h') #align asymptotics.is_o.not_is_O Asymptotics.IsLittleO.not_isBigO section Bot variable (c f g) @[simp] theorem isBigOWith_bot : IsBigOWith c ⊥ f g := IsBigOWith.of_bound <| trivial #align asymptotics.is_O_with_bot Asymptotics.isBigOWith_bot @[simp] theorem isBigO_bot : f =O[⊥] g := (isBigOWith_bot 1 f g).isBigO #align asymptotics.is_O_bot Asymptotics.isBigO_bot @[simp] theorem isLittleO_bot : f =o[⊥] g := IsLittleO.of_isBigOWith fun c _ => isBigOWith_bot c f g #align asymptotics.is_o_bot Asymptotics.isLittleO_bot end Bot @[simp] theorem isBigOWith_pure {x} : IsBigOWith c (pure x) f g ↔ ‖f x‖ ≤ c * ‖g x‖ := isBigOWith_iff #align asymptotics.is_O_with_pure Asymptotics.isBigOWith_pure theorem IsBigOWith.sup (h : IsBigOWith c l f g) (h' : IsBigOWith c l' f g) : IsBigOWith c (l ⊔ l') f g := IsBigOWith.of_bound <| mem_sup.2 ⟨h.bound, h'.bound⟩ #align asymptotics.is_O_with.sup Asymptotics.IsBigOWith.sup theorem IsBigOWith.sup' (h : IsBigOWith c l f g') (h' : IsBigOWith c' l' f g') : IsBigOWith (max c c') (l ⊔ l') f g' := IsBigOWith.of_bound <| mem_sup.2 ⟨(h.weaken <| le_max_left c c').bound, (h'.weaken <| le_max_right c c').bound⟩ #align asymptotics.is_O_with.sup' Asymptotics.IsBigOWith.sup' theorem IsBigO.sup (h : f =O[l] g') (h' : f =O[l'] g') : f =O[l ⊔ l'] g' := let ⟨_c, hc⟩ := h.isBigOWith let ⟨_c', hc'⟩ := h'.isBigOWith (hc.sup' hc').isBigO #align asymptotics.is_O.sup Asymptotics.IsBigO.sup theorem IsLittleO.sup (h : f =o[l] g) (h' : f =o[l'] g) : f =o[l ⊔ l'] g := IsLittleO.of_isBigOWith fun _c cpos => (h.forall_isBigOWith cpos).sup (h'.forall_isBigOWith cpos) #align asymptotics.is_o.sup Asymptotics.IsLittleO.sup @[simp] theorem isBigO_sup : f =O[l ⊔ l'] g' ↔ f =O[l] g' ∧ f =O[l'] g' := ⟨fun h => ⟨h.mono le_sup_left, h.mono le_sup_right⟩, fun h => h.1.sup h.2⟩ #align asymptotics.is_O_sup Asymptotics.isBigO_sup @[simp] theorem isLittleO_sup : f =o[l ⊔ l'] g ↔ f =o[l] g ∧ f =o[l'] g := ⟨fun h => ⟨h.mono le_sup_left, h.mono le_sup_right⟩, fun h => h.1.sup h.2⟩ #align asymptotics.is_o_sup Asymptotics.isLittleO_sup theorem isBigOWith_insert [TopologicalSpace α] {x : α} {s : Set α} {C : ℝ} {g : α → E} {g' : α → F} (h : ‖g x‖ ≤ C * ‖g' x‖) : IsBigOWith C (𝓝[insert x s] x) g g' ↔ IsBigOWith C (𝓝[s] x) g g' := by simp_rw [IsBigOWith_def, nhdsWithin_insert, eventually_sup, eventually_pure, h, true_and_iff] #align asymptotics.is_O_with_insert Asymptotics.isBigOWith_insert protected theorem IsBigOWith.insert [TopologicalSpace α] {x : α} {s : Set α} {C : ℝ} {g : α → E} {g' : α → F} (h1 : IsBigOWith C (𝓝[s] x) g g') (h2 : ‖g x‖ ≤ C * ‖g' x‖) : IsBigOWith C (𝓝[insert x s] x) g g' := (isBigOWith_insert h2).mpr h1 #align asymptotics.is_O_with.insert Asymptotics.IsBigOWith.insert theorem isLittleO_insert [TopologicalSpace α] {x : α} {s : Set α} {g : α → E'} {g' : α → F'} (h : g x = 0) : g =o[𝓝[insert x s] x] g' ↔ g =o[𝓝[s] x] g' := by simp_rw [IsLittleO_def] refine forall_congr' fun c => forall_congr' fun hc => ?_ rw [isBigOWith_insert] rw [h, norm_zero] exact mul_nonneg hc.le (norm_nonneg _) #align asymptotics.is_o_insert Asymptotics.isLittleO_insert protected theorem IsLittleO.insert [TopologicalSpace α] {x : α} {s : Set α} {g : α → E'} {g' : α → F'} (h1 : g =o[𝓝[s] x] g') (h2 : g x = 0) : g =o[𝓝[insert x s] x] g' := (isLittleO_insert h2).mpr h1 #align asymptotics.is_o.insert Asymptotics.IsLittleO.insert /-! ### Simplification : norm, abs -/ section NormAbs variable {u v : α → ℝ} @[simp] theorem isBigOWith_norm_right : (IsBigOWith c l f fun x => ‖g' x‖) ↔ IsBigOWith c l f g' := by simp only [IsBigOWith_def, norm_norm] #align asymptotics.is_O_with_norm_right Asymptotics.isBigOWith_norm_right @[simp] theorem isBigOWith_abs_right : (IsBigOWith c l f fun x => |u x|) ↔ IsBigOWith c l f u := @isBigOWith_norm_right _ _ _ _ _ _ f u l #align asymptotics.is_O_with_abs_right Asymptotics.isBigOWith_abs_right alias ⟨IsBigOWith.of_norm_right, IsBigOWith.norm_right⟩ := isBigOWith_norm_right #align asymptotics.is_O_with.of_norm_right Asymptotics.IsBigOWith.of_norm_right #align asymptotics.is_O_with.norm_right Asymptotics.IsBigOWith.norm_right alias ⟨IsBigOWith.of_abs_right, IsBigOWith.abs_right⟩ := isBigOWith_abs_right #align asymptotics.is_O_with.of_abs_right Asymptotics.IsBigOWith.of_abs_right #align asymptotics.is_O_with.abs_right Asymptotics.IsBigOWith.abs_right @[simp] theorem isBigO_norm_right : (f =O[l] fun x => ‖g' x‖) ↔ f =O[l] g' := by simp only [IsBigO_def] exact exists_congr fun _ => isBigOWith_norm_right #align asymptotics.is_O_norm_right Asymptotics.isBigO_norm_right @[simp] theorem isBigO_abs_right : (f =O[l] fun x => |u x|) ↔ f =O[l] u := @isBigO_norm_right _ _ ℝ _ _ _ _ _ #align asymptotics.is_O_abs_right Asymptotics.isBigO_abs_right alias ⟨IsBigO.of_norm_right, IsBigO.norm_right⟩ := isBigO_norm_right #align asymptotics.is_O.of_norm_right Asymptotics.IsBigO.of_norm_right #align asymptotics.is_O.norm_right Asymptotics.IsBigO.norm_right alias ⟨IsBigO.of_abs_right, IsBigO.abs_right⟩ := isBigO_abs_right #align asymptotics.is_O.of_abs_right Asymptotics.IsBigO.of_abs_right #align asymptotics.is_O.abs_right Asymptotics.IsBigO.abs_right @[simp] theorem isLittleO_norm_right : (f =o[l] fun x => ‖g' x‖) ↔ f =o[l] g' := by simp only [IsLittleO_def] exact forall₂_congr fun _ _ => isBigOWith_norm_right #align asymptotics.is_o_norm_right Asymptotics.isLittleO_norm_right @[simp] theorem isLittleO_abs_right : (f =o[l] fun x => |u x|) ↔ f =o[l] u := @isLittleO_norm_right _ _ ℝ _ _ _ _ _ #align asymptotics.is_o_abs_right Asymptotics.isLittleO_abs_right alias ⟨IsLittleO.of_norm_right, IsLittleO.norm_right⟩ := isLittleO_norm_right #align asymptotics.is_o.of_norm_right Asymptotics.IsLittleO.of_norm_right #align asymptotics.is_o.norm_right Asymptotics.IsLittleO.norm_right alias ⟨IsLittleO.of_abs_right, IsLittleO.abs_right⟩ := isLittleO_abs_right #align asymptotics.is_o.of_abs_right Asymptotics.IsLittleO.of_abs_right #align asymptotics.is_o.abs_right Asymptotics.IsLittleO.abs_right @[simp] theorem isBigOWith_norm_left : IsBigOWith c l (fun x => ‖f' x‖) g ↔ IsBigOWith c l f' g := by simp only [IsBigOWith_def, norm_norm] #align asymptotics.is_O_with_norm_left Asymptotics.isBigOWith_norm_left @[simp] theorem isBigOWith_abs_left : IsBigOWith c l (fun x => |u x|) g ↔ IsBigOWith c l u g := @isBigOWith_norm_left _ _ _ _ _ _ g u l #align asymptotics.is_O_with_abs_left Asymptotics.isBigOWith_abs_left alias ⟨IsBigOWith.of_norm_left, IsBigOWith.norm_left⟩ := isBigOWith_norm_left #align asymptotics.is_O_with.of_norm_left Asymptotics.IsBigOWith.of_norm_left #align asymptotics.is_O_with.norm_left Asymptotics.IsBigOWith.norm_left alias ⟨IsBigOWith.of_abs_left, IsBigOWith.abs_left⟩ := isBigOWith_abs_left #align asymptotics.is_O_with.of_abs_left Asymptotics.IsBigOWith.of_abs_left #align asymptotics.is_O_with.abs_left Asymptotics.IsBigOWith.abs_left @[simp] theorem isBigO_norm_left : (fun x => ‖f' x‖) =O[l] g ↔ f' =O[l] g := by simp only [IsBigO_def] exact exists_congr fun _ => isBigOWith_norm_left #align asymptotics.is_O_norm_left Asymptotics.isBigO_norm_left @[simp] theorem isBigO_abs_left : (fun x => |u x|) =O[l] g ↔ u =O[l] g := @isBigO_norm_left _ _ _ _ _ g u l #align asymptotics.is_O_abs_left Asymptotics.isBigO_abs_left alias ⟨IsBigO.of_norm_left, IsBigO.norm_left⟩ := isBigO_norm_left #align asymptotics.is_O.of_norm_left Asymptotics.IsBigO.of_norm_left #align asymptotics.is_O.norm_left Asymptotics.IsBigO.norm_left alias ⟨IsBigO.of_abs_left, IsBigO.abs_left⟩ := isBigO_abs_left #align asymptotics.is_O.of_abs_left Asymptotics.IsBigO.of_abs_left #align asymptotics.is_O.abs_left Asymptotics.IsBigO.abs_left @[simp] theorem isLittleO_norm_left : (fun x => ‖f' x‖) =o[l] g ↔ f' =o[l] g := by simp only [IsLittleO_def] exact forall₂_congr fun _ _ => isBigOWith_norm_left #align asymptotics.is_o_norm_left Asymptotics.isLittleO_norm_left @[simp] theorem isLittleO_abs_left : (fun x => |u x|) =o[l] g ↔ u =o[l] g := @isLittleO_norm_left _ _ _ _ _ g u l #align asymptotics.is_o_abs_left Asymptotics.isLittleO_abs_left alias ⟨IsLittleO.of_norm_left, IsLittleO.norm_left⟩ := isLittleO_norm_left #align asymptotics.is_o.of_norm_left Asymptotics.IsLittleO.of_norm_left #align asymptotics.is_o.norm_left Asymptotics.IsLittleO.norm_left alias ⟨IsLittleO.of_abs_left, IsLittleO.abs_left⟩ := isLittleO_abs_left #align asymptotics.is_o.of_abs_left Asymptotics.IsLittleO.of_abs_left #align asymptotics.is_o.abs_left Asymptotics.IsLittleO.abs_left theorem isBigOWith_norm_norm : (IsBigOWith c l (fun x => ‖f' x‖) fun x => ‖g' x‖) ↔ IsBigOWith c l f' g' := isBigOWith_norm_left.trans isBigOWith_norm_right #align asymptotics.is_O_with_norm_norm Asymptotics.isBigOWith_norm_norm theorem isBigOWith_abs_abs : (IsBigOWith c l (fun x => |u x|) fun x => |v x|) ↔ IsBigOWith c l u v := isBigOWith_abs_left.trans isBigOWith_abs_right #align asymptotics.is_O_with_abs_abs Asymptotics.isBigOWith_abs_abs alias ⟨IsBigOWith.of_norm_norm, IsBigOWith.norm_norm⟩ := isBigOWith_norm_norm #align asymptotics.is_O_with.of_norm_norm Asymptotics.IsBigOWith.of_norm_norm #align asymptotics.is_O_with.norm_norm Asymptotics.IsBigOWith.norm_norm alias ⟨IsBigOWith.of_abs_abs, IsBigOWith.abs_abs⟩ := isBigOWith_abs_abs #align asymptotics.is_O_with.of_abs_abs Asymptotics.IsBigOWith.of_abs_abs #align asymptotics.is_O_with.abs_abs Asymptotics.IsBigOWith.abs_abs theorem isBigO_norm_norm : ((fun x => ‖f' x‖) =O[l] fun x => ‖g' x‖) ↔ f' =O[l] g' := isBigO_norm_left.trans isBigO_norm_right #align asymptotics.is_O_norm_norm Asymptotics.isBigO_norm_norm theorem isBigO_abs_abs : ((fun x => |u x|) =O[l] fun x => |v x|) ↔ u =O[l] v := isBigO_abs_left.trans isBigO_abs_right #align asymptotics.is_O_abs_abs Asymptotics.isBigO_abs_abs alias ⟨IsBigO.of_norm_norm, IsBigO.norm_norm⟩ := isBigO_norm_norm #align asymptotics.is_O.of_norm_norm Asymptotics.IsBigO.of_norm_norm #align asymptotics.is_O.norm_norm Asymptotics.IsBigO.norm_norm alias ⟨IsBigO.of_abs_abs, IsBigO.abs_abs⟩ := isBigO_abs_abs #align asymptotics.is_O.of_abs_abs Asymptotics.IsBigO.of_abs_abs #align asymptotics.is_O.abs_abs Asymptotics.IsBigO.abs_abs theorem isLittleO_norm_norm : ((fun x => ‖f' x‖) =o[l] fun x => ‖g' x‖) ↔ f' =o[l] g' := isLittleO_norm_left.trans isLittleO_norm_right #align asymptotics.is_o_norm_norm Asymptotics.isLittleO_norm_norm theorem isLittleO_abs_abs : ((fun x => |u x|) =o[l] fun x => |v x|) ↔ u =o[l] v := isLittleO_abs_left.trans isLittleO_abs_right #align asymptotics.is_o_abs_abs Asymptotics.isLittleO_abs_abs alias ⟨IsLittleO.of_norm_norm, IsLittleO.norm_norm⟩ := isLittleO_norm_norm #align asymptotics.is_o.of_norm_norm Asymptotics.IsLittleO.of_norm_norm #align asymptotics.is_o.norm_norm Asymptotics.IsLittleO.norm_norm alias ⟨IsLittleO.of_abs_abs, IsLittleO.abs_abs⟩ := isLittleO_abs_abs #align asymptotics.is_o.of_abs_abs Asymptotics.IsLittleO.of_abs_abs #align asymptotics.is_o.abs_abs Asymptotics.IsLittleO.abs_abs end NormAbs /-! ### Simplification: negate -/ @[simp] theorem isBigOWith_neg_right : (IsBigOWith c l f fun x => -g' x) ↔ IsBigOWith c l f g' := by simp only [IsBigOWith_def, norm_neg] #align asymptotics.is_O_with_neg_right Asymptotics.isBigOWith_neg_right alias ⟨IsBigOWith.of_neg_right, IsBigOWith.neg_right⟩ := isBigOWith_neg_right #align asymptotics.is_O_with.of_neg_right Asymptotics.IsBigOWith.of_neg_right #align asymptotics.is_O_with.neg_right Asymptotics.IsBigOWith.neg_right @[simp] theorem isBigO_neg_right : (f =O[l] fun x => -g' x) ↔ f =O[l] g' := by simp only [IsBigO_def] exact exists_congr fun _ => isBigOWith_neg_right #align asymptotics.is_O_neg_right Asymptotics.isBigO_neg_right alias ⟨IsBigO.of_neg_right, IsBigO.neg_right⟩ := isBigO_neg_right #align asymptotics.is_O.of_neg_right Asymptotics.IsBigO.of_neg_right #align asymptotics.is_O.neg_right Asymptotics.IsBigO.neg_right @[simp] theorem isLittleO_neg_right : (f =o[l] fun x => -g' x) ↔ f =o[l] g' := by simp only [IsLittleO_def] exact forall₂_congr fun _ _ => isBigOWith_neg_right #align asymptotics.is_o_neg_right Asymptotics.isLittleO_neg_right alias ⟨IsLittleO.of_neg_right, IsLittleO.neg_right⟩ := isLittleO_neg_right #align asymptotics.is_o.of_neg_right Asymptotics.IsLittleO.of_neg_right #align asymptotics.is_o.neg_right Asymptotics.IsLittleO.neg_right @[simp] theorem isBigOWith_neg_left : IsBigOWith c l (fun x => -f' x) g ↔ IsBigOWith c l f' g := by simp only [IsBigOWith_def, norm_neg] #align asymptotics.is_O_with_neg_left Asymptotics.isBigOWith_neg_left alias ⟨IsBigOWith.of_neg_left, IsBigOWith.neg_left⟩ := isBigOWith_neg_left #align asymptotics.is_O_with.of_neg_left Asymptotics.IsBigOWith.of_neg_left #align asymptotics.is_O_with.neg_left Asymptotics.IsBigOWith.neg_left @[simp] theorem isBigO_neg_left : (fun x => -f' x) =O[l] g ↔ f' =O[l] g := by simp only [IsBigO_def] exact exists_congr fun _ => isBigOWith_neg_left #align asymptotics.is_O_neg_left Asymptotics.isBigO_neg_left alias ⟨IsBigO.of_neg_left, IsBigO.neg_left⟩ := isBigO_neg_left #align asymptotics.is_O.of_neg_left Asymptotics.IsBigO.of_neg_left #align asymptotics.is_O.neg_left Asymptotics.IsBigO.neg_left @[simp] theorem isLittleO_neg_left : (fun x => -f' x) =o[l] g ↔ f' =o[l] g := by simp only [IsLittleO_def] exact forall₂_congr fun _ _ => isBigOWith_neg_left #align asymptotics.is_o_neg_left Asymptotics.isLittleO_neg_left alias ⟨IsLittleO.of_neg_left, IsLittleO.neg_left⟩ := isLittleO_neg_left #align asymptotics.is_o.of_neg_left Asymptotics.IsLittleO.of_neg_left #align asymptotics.is_o.neg_left Asymptotics.IsLittleO.neg_left /-! ### Product of functions (right) -/ theorem isBigOWith_fst_prod : IsBigOWith 1 l f' fun x => (f' x, g' x) := isBigOWith_of_le l fun _x => le_max_left _ _ #align asymptotics.is_O_with_fst_prod Asymptotics.isBigOWith_fst_prod theorem isBigOWith_snd_prod : IsBigOWith 1 l g' fun x => (f' x, g' x) := isBigOWith_of_le l fun _x => le_max_right _ _ #align asymptotics.is_O_with_snd_prod Asymptotics.isBigOWith_snd_prod theorem isBigO_fst_prod : f' =O[l] fun x => (f' x, g' x) := isBigOWith_fst_prod.isBigO #align asymptotics.is_O_fst_prod Asymptotics.isBigO_fst_prod theorem isBigO_snd_prod : g' =O[l] fun x => (f' x, g' x) := isBigOWith_snd_prod.isBigO #align asymptotics.is_O_snd_prod Asymptotics.isBigO_snd_prod theorem isBigO_fst_prod' {f' : α → E' × F'} : (fun x => (f' x).1) =O[l] f' := by simpa [IsBigO_def, IsBigOWith_def] using isBigO_fst_prod (E' := E') (F' := F') #align asymptotics.is_O_fst_prod' Asymptotics.isBigO_fst_prod' theorem isBigO_snd_prod' {f' : α → E' × F'} : (fun x => (f' x).2) =O[l] f' := by simpa [IsBigO_def, IsBigOWith_def] using isBigO_snd_prod (E' := E') (F' := F') #align asymptotics.is_O_snd_prod' Asymptotics.isBigO_snd_prod' section variable (f' k') theorem IsBigOWith.prod_rightl (h : IsBigOWith c l f g') (hc : 0 ≤ c) : IsBigOWith c l f fun x => (g' x, k' x) := (h.trans isBigOWith_fst_prod hc).congr_const (mul_one c) #align asymptotics.is_O_with.prod_rightl Asymptotics.IsBigOWith.prod_rightl theorem IsBigO.prod_rightl (h : f =O[l] g') : f =O[l] fun x => (g' x, k' x) := let ⟨_c, cnonneg, hc⟩ := h.exists_nonneg (hc.prod_rightl k' cnonneg).isBigO #align asymptotics.is_O.prod_rightl Asymptotics.IsBigO.prod_rightl theorem IsLittleO.prod_rightl (h : f =o[l] g') : f =o[l] fun x => (g' x, k' x) := IsLittleO.of_isBigOWith fun _c cpos => (h.forall_isBigOWith cpos).prod_rightl k' cpos.le #align asymptotics.is_o.prod_rightl Asymptotics.IsLittleO.prod_rightl theorem IsBigOWith.prod_rightr (h : IsBigOWith c l f g') (hc : 0 ≤ c) : IsBigOWith c l f fun x => (f' x, g' x) := (h.trans isBigOWith_snd_prod hc).congr_const (mul_one c) #align asymptotics.is_O_with.prod_rightr Asymptotics.IsBigOWith.prod_rightr theorem IsBigO.prod_rightr (h : f =O[l] g') : f =O[l] fun x => (f' x, g' x) := let ⟨_c, cnonneg, hc⟩ := h.exists_nonneg (hc.prod_rightr f' cnonneg).isBigO #align asymptotics.is_O.prod_rightr Asymptotics.IsBigO.prod_rightr theorem IsLittleO.prod_rightr (h : f =o[l] g') : f =o[l] fun x => (f' x, g' x) := IsLittleO.of_isBigOWith fun _c cpos => (h.forall_isBigOWith cpos).prod_rightr f' cpos.le #align asymptotics.is_o.prod_rightr Asymptotics.IsLittleO.prod_rightr end theorem IsBigOWith.prod_left_same (hf : IsBigOWith c l f' k') (hg : IsBigOWith c l g' k') : IsBigOWith c l (fun x => (f' x, g' x)) k' := by rw [isBigOWith_iff] at *; filter_upwards [hf, hg] with x using max_le #align asymptotics.is_O_with.prod_left_same Asymptotics.IsBigOWith.prod_left_same theorem IsBigOWith.prod_left (hf : IsBigOWith c l f' k') (hg : IsBigOWith c' l g' k') : IsBigOWith (max c c') l (fun x => (f' x, g' x)) k' := (hf.weaken <| le_max_left c c').prod_left_same (hg.weaken <| le_max_right c c') #align asymptotics.is_O_with.prod_left Asymptotics.IsBigOWith.prod_left theorem IsBigOWith.prod_left_fst (h : IsBigOWith c l (fun x => (f' x, g' x)) k') : IsBigOWith c l f' k' := (isBigOWith_fst_prod.trans h zero_le_one).congr_const <| one_mul c #align asymptotics.is_O_with.prod_left_fst Asymptotics.IsBigOWith.prod_left_fst theorem IsBigOWith.prod_left_snd (h : IsBigOWith c l (fun x => (f' x, g' x)) k') : IsBigOWith c l g' k' := (isBigOWith_snd_prod.trans h zero_le_one).congr_const <| one_mul c #align asymptotics.is_O_with.prod_left_snd Asymptotics.IsBigOWith.prod_left_snd theorem isBigOWith_prod_left : IsBigOWith c l (fun x => (f' x, g' x)) k' ↔ IsBigOWith c l f' k' ∧ IsBigOWith c l g' k' := ⟨fun h => ⟨h.prod_left_fst, h.prod_left_snd⟩, fun h => h.1.prod_left_same h.2⟩ #align asymptotics.is_O_with_prod_left Asymptotics.isBigOWith_prod_left theorem IsBigO.prod_left (hf : f' =O[l] k') (hg : g' =O[l] k') : (fun x => (f' x, g' x)) =O[l] k' := let ⟨_c, hf⟩ := hf.isBigOWith let ⟨_c', hg⟩ := hg.isBigOWith (hf.prod_left hg).isBigO #align asymptotics.is_O.prod_left Asymptotics.IsBigO.prod_left theorem IsBigO.prod_left_fst : (fun x => (f' x, g' x)) =O[l] k' → f' =O[l] k' := IsBigO.trans isBigO_fst_prod #align asymptotics.is_O.prod_left_fst Asymptotics.IsBigO.prod_left_fst theorem IsBigO.prod_left_snd : (fun x => (f' x, g' x)) =O[l] k' → g' =O[l] k' := IsBigO.trans isBigO_snd_prod #align asymptotics.is_O.prod_left_snd Asymptotics.IsBigO.prod_left_snd @[simp] theorem isBigO_prod_left : (fun x => (f' x, g' x)) =O[l] k' ↔ f' =O[l] k' ∧ g' =O[l] k' := ⟨fun h => ⟨h.prod_left_fst, h.prod_left_snd⟩, fun h => h.1.prod_left h.2⟩ #align asymptotics.is_O_prod_left Asymptotics.isBigO_prod_left theorem IsLittleO.prod_left (hf : f' =o[l] k') (hg : g' =o[l] k') : (fun x => (f' x, g' x)) =o[l] k' := IsLittleO.of_isBigOWith fun _c hc => (hf.forall_isBigOWith hc).prod_left_same (hg.forall_isBigOWith hc) #align asymptotics.is_o.prod_left Asymptotics.IsLittleO.prod_left theorem IsLittleO.prod_left_fst : (fun x => (f' x, g' x)) =o[l] k' → f' =o[l] k' := IsBigO.trans_isLittleO isBigO_fst_prod #align asymptotics.is_o.prod_left_fst Asymptotics.IsLittleO.prod_left_fst theorem IsLittleO.prod_left_snd : (fun x => (f' x, g' x)) =o[l] k' → g' =o[l] k' := IsBigO.trans_isLittleO isBigO_snd_prod #align asymptotics.is_o.prod_left_snd Asymptotics.IsLittleO.prod_left_snd @[simp] theorem isLittleO_prod_left : (fun x => (f' x, g' x)) =o[l] k' ↔ f' =o[l] k' ∧ g' =o[l] k' := ⟨fun h => ⟨h.prod_left_fst, h.prod_left_snd⟩, fun h => h.1.prod_left h.2⟩ #align asymptotics.is_o_prod_left Asymptotics.isLittleO_prod_left theorem IsBigOWith.eq_zero_imp (h : IsBigOWith c l f'' g'') : ∀ᶠ x in l, g'' x = 0 → f'' x = 0 := Eventually.mono h.bound fun x hx hg => norm_le_zero_iff.1 <| by simpa [hg] using hx #align asymptotics.is_O_with.eq_zero_imp Asymptotics.IsBigOWith.eq_zero_imp theorem IsBigO.eq_zero_imp (h : f'' =O[l] g'') : ∀ᶠ x in l, g'' x = 0 → f'' x = 0 := let ⟨_C, hC⟩ := h.isBigOWith hC.eq_zero_imp #align asymptotics.is_O.eq_zero_imp Asymptotics.IsBigO.eq_zero_imp /-! ### Addition and subtraction -/ section add_sub variable {f₁ f₂ : α → E'} {g₁ g₂ : α → F'} theorem IsBigOWith.add (h₁ : IsBigOWith c₁ l f₁ g) (h₂ : IsBigOWith c₂ l f₂ g) : IsBigOWith (c₁ + c₂) l (fun x => f₁ x + f₂ x) g := by rw [IsBigOWith_def] at * filter_upwards [h₁, h₂] with x hx₁ hx₂ using calc ‖f₁ x + f₂ x‖ ≤ c₁ * ‖g x‖ + c₂ * ‖g x‖ := norm_add_le_of_le hx₁ hx₂ _ = (c₁ + c₂) * ‖g x‖ := (add_mul _ _ _).symm #align asymptotics.is_O_with.add Asymptotics.IsBigOWith.add theorem IsBigO.add (h₁ : f₁ =O[l] g) (h₂ : f₂ =O[l] g) : (fun x => f₁ x + f₂ x) =O[l] g := let ⟨_c₁, hc₁⟩ := h₁.isBigOWith let ⟨_c₂, hc₂⟩ := h₂.isBigOWith (hc₁.add hc₂).isBigO #align asymptotics.is_O.add Asymptotics.IsBigO.add theorem IsLittleO.add (h₁ : f₁ =o[l] g) (h₂ : f₂ =o[l] g) : (fun x => f₁ x + f₂ x) =o[l] g := IsLittleO.of_isBigOWith fun c cpos => ((h₁.forall_isBigOWith <| half_pos cpos).add (h₂.forall_isBigOWith <| half_pos cpos)).congr_const (add_halves c) #align asymptotics.is_o.add Asymptotics.IsLittleO.add theorem IsLittleO.add_add (h₁ : f₁ =o[l] g₁) (h₂ : f₂ =o[l] g₂) : (fun x => f₁ x + f₂ x) =o[l] fun x => ‖g₁ x‖ + ‖g₂ x‖ := by refine (h₁.trans_le fun x => ?_).add (h₂.trans_le ?_) <;> simp [abs_of_nonneg, add_nonneg] #align asymptotics.is_o.add_add Asymptotics.IsLittleO.add_add theorem IsBigO.add_isLittleO (h₁ : f₁ =O[l] g) (h₂ : f₂ =o[l] g) : (fun x => f₁ x + f₂ x) =O[l] g := h₁.add h₂.isBigO #align asymptotics.is_O.add_is_o Asymptotics.IsBigO.add_isLittleO theorem IsLittleO.add_isBigO (h₁ : f₁ =o[l] g) (h₂ : f₂ =O[l] g) : (fun x => f₁ x + f₂ x) =O[l] g := h₁.isBigO.add h₂ #align asymptotics.is_o.add_is_O Asymptotics.IsLittleO.add_isBigO theorem IsBigOWith.add_isLittleO (h₁ : IsBigOWith c₁ l f₁ g) (h₂ : f₂ =o[l] g) (hc : c₁ < c₂) : IsBigOWith c₂ l (fun x => f₁ x + f₂ x) g := (h₁.add (h₂.forall_isBigOWith (sub_pos.2 hc))).congr_const (add_sub_cancel _ _) #align asymptotics.is_O_with.add_is_o Asymptotics.IsBigOWith.add_isLittleO theorem IsLittleO.add_isBigOWith (h₁ : f₁ =o[l] g) (h₂ : IsBigOWith c₁ l f₂ g) (hc : c₁ < c₂) : IsBigOWith c₂ l (fun x => f₁ x + f₂ x) g := (h₂.add_isLittleO h₁ hc).congr_left fun _ => add_comm _ _ #align asymptotics.is_o.add_is_O_with Asymptotics.IsLittleO.add_isBigOWith theorem IsBigOWith.sub (h₁ : IsBigOWith c₁ l f₁ g) (h₂ : IsBigOWith c₂ l f₂ g) : IsBigOWith (c₁ + c₂) l (fun x => f₁ x - f₂ x) g := by simpa only [sub_eq_add_neg] using h₁.add h₂.neg_left #align asymptotics.is_O_with.sub Asymptotics.IsBigOWith.sub theorem IsBigOWith.sub_isLittleO (h₁ : IsBigOWith c₁ l f₁ g) (h₂ : f₂ =o[l] g) (hc : c₁ < c₂) : IsBigOWith c₂ l (fun x => f₁ x - f₂ x) g := by simpa only [sub_eq_add_neg] using h₁.add_isLittleO h₂.neg_left hc #align asymptotics.is_O_with.sub_is_o Asymptotics.IsBigOWith.sub_isLittleO theorem IsBigO.sub (h₁ : f₁ =O[l] g) (h₂ : f₂ =O[l] g) : (fun x => f₁ x - f₂ x) =O[l] g := by simpa only [sub_eq_add_neg] using h₁.add h₂.neg_left #align asymptotics.is_O.sub Asymptotics.IsBigO.sub theorem IsLittleO.sub (h₁ : f₁ =o[l] g) (h₂ : f₂ =o[l] g) : (fun x => f₁ x - f₂ x) =o[l] g := by simpa only [sub_eq_add_neg] using h₁.add h₂.neg_left #align asymptotics.is_o.sub Asymptotics.IsLittleO.sub end add_sub /-! ### Lemmas about `IsBigO (f₁ - f₂) g l` / `IsLittleO (f₁ - f₂) g l` treated as a binary relation -/ section IsBigOOAsRel variable {f₁ f₂ f₃ : α → E'} theorem IsBigOWith.symm (h : IsBigOWith c l (fun x => f₁ x - f₂ x) g) : IsBigOWith c l (fun x => f₂ x - f₁ x) g := h.neg_left.congr_left fun _x => neg_sub _ _ #align asymptotics.is_O_with.symm Asymptotics.IsBigOWith.symm theorem isBigOWith_comm : IsBigOWith c l (fun x => f₁ x - f₂ x) g ↔ IsBigOWith c l (fun x => f₂ x - f₁ x) g := ⟨IsBigOWith.symm, IsBigOWith.symm⟩ #align asymptotics.is_O_with_comm Asymptotics.isBigOWith_comm theorem IsBigO.symm (h : (fun x => f₁ x - f₂ x) =O[l] g) : (fun x => f₂ x - f₁ x) =O[l] g := h.neg_left.congr_left fun _x => neg_sub _ _ #align asymptotics.is_O.symm Asymptotics.IsBigO.symm theorem isBigO_comm : (fun x => f₁ x - f₂ x) =O[l] g ↔ (fun x => f₂ x - f₁ x) =O[l] g := ⟨IsBigO.symm, IsBigO.symm⟩ #align asymptotics.is_O_comm Asymptotics.isBigO_comm theorem IsLittleO.symm (h : (fun x => f₁ x - f₂ x) =o[l] g) : (fun x => f₂ x - f₁ x) =o[l] g := by simpa only [neg_sub] using h.neg_left #align asymptotics.is_o.symm Asymptotics.IsLittleO.symm theorem isLittleO_comm : (fun x => f₁ x - f₂ x) =o[l] g ↔ (fun x => f₂ x - f₁ x) =o[l] g := ⟨IsLittleO.symm, IsLittleO.symm⟩ #align asymptotics.is_o_comm Asymptotics.isLittleO_comm theorem IsBigOWith.triangle (h₁ : IsBigOWith c l (fun x => f₁ x - f₂ x) g) (h₂ : IsBigOWith c' l (fun x => f₂ x - f₃ x) g) : IsBigOWith (c + c') l (fun x => f₁ x - f₃ x) g := (h₁.add h₂).congr_left fun _x => sub_add_sub_cancel _ _ _ #align asymptotics.is_O_with.triangle Asymptotics.IsBigOWith.triangle theorem IsBigO.triangle (h₁ : (fun x => f₁ x - f₂ x) =O[l] g) (h₂ : (fun x => f₂ x - f₃ x) =O[l] g) : (fun x => f₁ x - f₃ x) =O[l] g := (h₁.add h₂).congr_left fun _x => sub_add_sub_cancel _ _ _ #align asymptotics.is_O.triangle Asymptotics.IsBigO.triangle theorem IsLittleO.triangle (h₁ : (fun x => f₁ x - f₂ x) =o[l] g) (h₂ : (fun x => f₂ x - f₃ x) =o[l] g) : (fun x => f₁ x - f₃ x) =o[l] g := (h₁.add h₂).congr_left fun _x => sub_add_sub_cancel _ _ _ #align asymptotics.is_o.triangle Asymptotics.IsLittleO.triangle theorem IsBigO.congr_of_sub (h : (fun x => f₁ x - f₂ x) =O[l] g) : f₁ =O[l] g ↔ f₂ =O[l] g := ⟨fun h' => (h'.sub h).congr_left fun _x => sub_sub_cancel _ _, fun h' => (h.add h').congr_left fun _x => sub_add_cancel _ _⟩ #align asymptotics.is_O.congr_of_sub Asymptotics.IsBigO.congr_of_sub theorem IsLittleO.congr_of_sub (h : (fun x => f₁ x - f₂ x) =o[l] g) : f₁ =o[l] g ↔ f₂ =o[l] g := ⟨fun h' => (h'.sub h).congr_left fun _x => sub_sub_cancel _ _, fun h' => (h.add h').congr_left fun _x => sub_add_cancel _ _⟩ #align asymptotics.is_o.congr_of_sub Asymptotics.IsLittleO.congr_of_sub end IsBigOOAsRel /-! ### Zero, one, and other constants -/ section ZeroConst variable (g g' l) theorem isLittleO_zero : (fun _x => (0 : E')) =o[l] g' := IsLittleO.of_bound fun c hc => univ_mem' fun x => by simpa using mul_nonneg hc.le (norm_nonneg <| g' x) #align asymptotics.is_o_zero Asymptotics.isLittleO_zero theorem isBigOWith_zero (hc : 0 ≤ c) : IsBigOWith c l (fun _x => (0 : E')) g' := IsBigOWith.of_bound <| univ_mem' fun x => by simpa using mul_nonneg hc (norm_nonneg <| g' x) #align asymptotics.is_O_with_zero Asymptotics.isBigOWith_zero theorem isBigOWith_zero' : IsBigOWith 0 l (fun _x => (0 : E')) g := IsBigOWith.of_bound <| univ_mem' fun x => by simp #align asymptotics.is_O_with_zero' Asymptotics.isBigOWith_zero' theorem isBigO_zero : (fun _x => (0 : E')) =O[l] g := isBigO_iff_isBigOWith.2 ⟨0, isBigOWith_zero' _ _⟩ #align asymptotics.is_O_zero Asymptotics.isBigO_zero theorem isBigO_refl_left : (fun x => f' x - f' x) =O[l] g' := (isBigO_zero g' l).congr_left fun _x => (sub_self _).symm #align asymptotics.is_O_refl_left Asymptotics.isBigO_refl_left theorem isLittleO_refl_left : (fun x => f' x - f' x) =o[l] g' := (isLittleO_zero g' l).congr_left fun _x => (sub_self _).symm #align asymptotics.is_o_refl_left Asymptotics.isLittleO_refl_left variable {g g' l} @[simp] theorem isBigOWith_zero_right_iff : (IsBigOWith c l f'' fun _x => (0 : F')) ↔ f'' =ᶠ[l] 0 := by simp only [IsBigOWith_def, exists_prop, true_and_iff, norm_zero, mul_zero, norm_le_zero_iff, EventuallyEq, Pi.zero_apply] #align asymptotics.is_O_with_zero_right_iff Asymptotics.isBigOWith_zero_right_iff @[simp] theorem isBigO_zero_right_iff : (f'' =O[l] fun _x => (0 : F')) ↔ f'' =ᶠ[l] 0 := ⟨fun h => let ⟨_c, hc⟩ := h.isBigOWith isBigOWith_zero_right_iff.1 hc, fun h => (isBigOWith_zero_right_iff.2 h : IsBigOWith 1 _ _ _).isBigO⟩ #align asymptotics.is_O_zero_right_iff Asymptotics.isBigO_zero_right_iff @[simp] theorem isLittleO_zero_right_iff : (f'' =o[l] fun _x => (0 : F')) ↔ f'' =ᶠ[l] 0 := ⟨fun h => isBigO_zero_right_iff.1 h.isBigO, fun h => IsLittleO.of_isBigOWith fun _c _hc => isBigOWith_zero_right_iff.2 h⟩ #align asymptotics.is_o_zero_right_iff Asymptotics.isLittleO_zero_right_iff theorem isBigOWith_const_const (c : E) {c' : F''} (hc' : c' ≠ 0) (l : Filter α) : IsBigOWith (‖c‖ / ‖c'‖) l (fun _x : α => c) fun _x => c' := by simp only [IsBigOWith_def] apply univ_mem' intro x rw [mem_setOf, div_mul_cancel₀ _ (norm_ne_zero_iff.mpr hc')] #align asymptotics.is_O_with_const_const Asymptotics.isBigOWith_const_const theorem isBigO_const_const (c : E) {c' : F''} (hc' : c' ≠ 0) (l : Filter α) : (fun _x : α => c) =O[l] fun _x => c' := (isBigOWith_const_const c hc' l).isBigO #align asymptotics.is_O_const_const Asymptotics.isBigO_const_const @[simp] theorem isBigO_const_const_iff {c : E''} {c' : F''} (l : Filter α) [l.NeBot] : ((fun _x : α => c) =O[l] fun _x => c') ↔ c' = 0 → c = 0 := by rcases eq_or_ne c' 0 with (rfl | hc') · simp [EventuallyEq] · simp [hc', isBigO_const_const _ hc'] #align asymptotics.is_O_const_const_iff Asymptotics.isBigO_const_const_iff @[simp] theorem isBigO_pure {x} : f'' =O[pure x] g'' ↔ g'' x = 0 → f'' x = 0 := calc f'' =O[pure x] g'' ↔ (fun _y : α => f'' x) =O[pure x] fun _ => g'' x := isBigO_congr rfl rfl _ ↔ g'' x = 0 → f'' x = 0 := isBigO_const_const_iff _ #align asymptotics.is_O_pure Asymptotics.isBigO_pure end ZeroConst @[simp] theorem isBigOWith_principal {s : Set α} : IsBigOWith c (𝓟 s) f g ↔ ∀ x ∈ s, ‖f x‖ ≤ c * ‖g x‖ := by rw [IsBigOWith_def, eventually_principal] #align asymptotics.is_O_with_principal Asymptotics.isBigOWith_principal theorem isBigO_principal {s : Set α} : f =O[𝓟 s] g ↔ ∃ c, ∀ x ∈ s, ‖f x‖ ≤ c * ‖g x‖ := by simp_rw [isBigO_iff, eventually_principal] #align asymptotics.is_O_principal Asymptotics.isBigO_principal @[simp] theorem isLittleO_principal {s : Set α} : f'' =o[𝓟 s] g' ↔ ∀ x ∈ s, f'' x = 0 := by refine ⟨fun h x hx ↦ norm_le_zero_iff.1 ?_, fun h ↦ ?_⟩ · simp only [isLittleO_iff, isBigOWith_principal] at h have : Tendsto (fun c : ℝ => c * ‖g' x‖) (𝓝[>] 0) (𝓝 0) := ((continuous_id.mul continuous_const).tendsto' _ _ (zero_mul _)).mono_left inf_le_left apply le_of_tendsto_of_tendsto tendsto_const_nhds this apply eventually_nhdsWithin_iff.2 (eventually_of_forall (fun c hc ↦ ?_)) exact eventually_principal.1 (h hc) x hx · apply (isLittleO_zero g' _).congr' ?_ EventuallyEq.rfl exact fun x hx ↦ (h x hx).symm @[simp] theorem isBigOWith_top : IsBigOWith c ⊤ f g ↔ ∀ x, ‖f x‖ ≤ c * ‖g x‖ := by rw [IsBigOWith_def, eventually_top] #align asymptotics.is_O_with_top Asymptotics.isBigOWith_top @[simp] theorem isBigO_top : f =O[⊤] g ↔ ∃ C, ∀ x, ‖f x‖ ≤ C * ‖g x‖ := by simp_rw [isBigO_iff, eventually_top] #align asymptotics.is_O_top Asymptotics.isBigO_top @[simp] theorem isLittleO_top : f'' =o[⊤] g' ↔ ∀ x, f'' x = 0 := by simp only [← principal_univ, isLittleO_principal, mem_univ, forall_true_left] #align asymptotics.is_o_top Asymptotics.isLittleO_top section variable (F) variable [One F] [NormOneClass F] theorem isBigOWith_const_one (c : E) (l : Filter α) : IsBigOWith ‖c‖ l (fun _x : α => c) fun _x => (1 : F) := by simp [isBigOWith_iff] #align asymptotics.is_O_with_const_one Asymptotics.isBigOWith_const_one theorem isBigO_const_one (c : E) (l : Filter α) : (fun _x : α => c) =O[l] fun _x => (1 : F) := (isBigOWith_const_one F c l).isBigO #align asymptotics.is_O_const_one Asymptotics.isBigO_const_one theorem isLittleO_const_iff_isLittleO_one {c : F''} (hc : c ≠ 0) : (f =o[l] fun _x => c) ↔ f =o[l] fun _x => (1 : F) := ⟨fun h => h.trans_isBigOWith (isBigOWith_const_one _ _ _) (norm_pos_iff.2 hc), fun h => h.trans_isBigO <| isBigO_const_const _ hc _⟩ #align asymptotics.is_o_const_iff_is_o_one Asymptotics.isLittleO_const_iff_isLittleO_one @[simp] theorem isLittleO_one_iff : f' =o[l] (fun _x => 1 : α → F) ↔ Tendsto f' l (𝓝 0) := by simp only [isLittleO_iff, norm_one, mul_one, Metric.nhds_basis_closedBall.tendsto_right_iff, Metric.mem_closedBall, dist_zero_right] #align asymptotics.is_o_one_iff Asymptotics.isLittleO_one_iff @[simp] theorem isBigO_one_iff : f =O[l] (fun _x => 1 : α → F) ↔ IsBoundedUnder (· ≤ ·) l fun x => ‖f x‖ := by simp only [isBigO_iff, norm_one, mul_one, IsBoundedUnder, IsBounded, eventually_map] #align asymptotics.is_O_one_iff Asymptotics.isBigO_one_iff alias ⟨_, _root_.Filter.IsBoundedUnder.isBigO_one⟩ := isBigO_one_iff #align filter.is_bounded_under.is_O_one Filter.IsBoundedUnder.isBigO_one @[simp] theorem isLittleO_one_left_iff : (fun _x => 1 : α → F) =o[l] f ↔ Tendsto (fun x => ‖f x‖) l atTop := calc (fun _x => 1 : α → F) =o[l] f ↔ ∀ n : ℕ, ∀ᶠ x in l, ↑n * ‖(1 : F)‖ ≤ ‖f x‖ := isLittleO_iff_nat_mul_le_aux <| Or.inl fun _x => by simp only [norm_one, zero_le_one] _ ↔ ∀ n : ℕ, True → ∀ᶠ x in l, ‖f x‖ ∈ Ici (n : ℝ) := by simp only [norm_one, mul_one, true_imp_iff, mem_Ici] _ ↔ Tendsto (fun x => ‖f x‖) l atTop := atTop_hasCountableBasis_of_archimedean.1.tendsto_right_iff.symm #align asymptotics.is_o_one_left_iff Asymptotics.isLittleO_one_left_iff theorem _root_.Filter.Tendsto.isBigO_one {c : E'} (h : Tendsto f' l (𝓝 c)) : f' =O[l] (fun _x => 1 : α → F) := h.norm.isBoundedUnder_le.isBigO_one F #align filter.tendsto.is_O_one Filter.Tendsto.isBigO_one theorem IsBigO.trans_tendsto_nhds (hfg : f =O[l] g') {y : F'} (hg : Tendsto g' l (𝓝 y)) : f =O[l] (fun _x => 1 : α → F) := hfg.trans <| hg.isBigO_one F #align asymptotics.is_O.trans_tendsto_nhds Asymptotics.IsBigO.trans_tendsto_nhds /-- The condition `f = O[𝓝[≠] a] 1` is equivalent to `f = O[𝓝 a] 1`. -/ lemma isBigO_one_nhds_ne_iff [TopologicalSpace α] {a : α} : f =O[𝓝[≠] a] (fun _ ↦ 1 : α → F) ↔ f =O[𝓝 a] (fun _ ↦ 1 : α → F) := by refine ⟨fun h ↦ ?_, fun h ↦ h.mono nhdsWithin_le_nhds⟩ simp only [isBigO_one_iff, IsBoundedUnder, IsBounded, eventually_map] at h ⊢ obtain ⟨c, hc⟩ := h use max c ‖f a‖ filter_upwards [eventually_nhdsWithin_iff.mp hc] with b hb rcases eq_or_ne b a with rfl | hb' · apply le_max_right · exact (hb hb').trans (le_max_left ..) end theorem isLittleO_const_iff {c : F''} (hc : c ≠ 0) : (f'' =o[l] fun _x => c) ↔ Tendsto f'' l (𝓝 0) := (isLittleO_const_iff_isLittleO_one ℝ hc).trans (isLittleO_one_iff _) #align asymptotics.is_o_const_iff Asymptotics.isLittleO_const_iff theorem isLittleO_id_const {c : F''} (hc : c ≠ 0) : (fun x : E'' => x) =o[𝓝 0] fun _x => c := (isLittleO_const_iff hc).mpr (continuous_id.tendsto 0) #align asymptotics.is_o_id_const Asymptotics.isLittleO_id_const theorem _root_.Filter.IsBoundedUnder.isBigO_const (h : IsBoundedUnder (· ≤ ·) l (norm ∘ f)) {c : F''} (hc : c ≠ 0) : f =O[l] fun _x => c := (h.isBigO_one ℝ).trans (isBigO_const_const _ hc _) #align filter.is_bounded_under.is_O_const Filter.IsBoundedUnder.isBigO_const theorem isBigO_const_of_tendsto {y : E''} (h : Tendsto f'' l (𝓝 y)) {c : F''} (hc : c ≠ 0) : f'' =O[l] fun _x => c := h.norm.isBoundedUnder_le.isBigO_const hc #align asymptotics.is_O_const_of_tendsto Asymptotics.isBigO_const_of_tendsto theorem IsBigO.isBoundedUnder_le {c : F} (h : f =O[l] fun _x => c) : IsBoundedUnder (· ≤ ·) l (norm ∘ f) := let ⟨c', hc'⟩ := h.bound ⟨c' * ‖c‖, eventually_map.2 hc'⟩ #align asymptotics.is_O.is_bounded_under_le Asymptotics.IsBigO.isBoundedUnder_le theorem isBigO_const_of_ne {c : F''} (hc : c ≠ 0) : (f =O[l] fun _x => c) ↔ IsBoundedUnder (· ≤ ·) l (norm ∘ f) := ⟨fun h => h.isBoundedUnder_le, fun h => h.isBigO_const hc⟩ #align asymptotics.is_O_const_of_ne Asymptotics.isBigO_const_of_ne theorem isBigO_const_iff {c : F''} : (f'' =O[l] fun _x => c) ↔ (c = 0 → f'' =ᶠ[l] 0) ∧ IsBoundedUnder (· ≤ ·) l fun x => ‖f'' x‖ := by refine ⟨fun h => ⟨fun hc => isBigO_zero_right_iff.1 (by rwa [← hc]), h.isBoundedUnder_le⟩, ?_⟩ rintro ⟨hcf, hf⟩ rcases eq_or_ne c 0 with (hc | hc) exacts [(hcf hc).trans_isBigO (isBigO_zero _ _), hf.isBigO_const hc] #align asymptotics.is_O_const_iff Asymptotics.isBigO_const_iff theorem isBigO_iff_isBoundedUnder_le_div (h : ∀ᶠ x in l, g'' x ≠ 0) : f =O[l] g'' ↔ IsBoundedUnder (· ≤ ·) l fun x => ‖f x‖ / ‖g'' x‖ := by simp only [isBigO_iff, IsBoundedUnder, IsBounded, eventually_map] exact exists_congr fun c => eventually_congr <| h.mono fun x hx => (div_le_iff <| norm_pos_iff.2 hx).symm #align asymptotics.is_O_iff_is_bounded_under_le_div Asymptotics.isBigO_iff_isBoundedUnder_le_div /-- `(fun x ↦ c) =O[l] f` if and only if `f` is bounded away from zero. -/ theorem isBigO_const_left_iff_pos_le_norm {c : E''} (hc : c ≠ 0) : (fun _x => c) =O[l] f' ↔ ∃ b, 0 < b ∧ ∀ᶠ x in l, b ≤ ‖f' x‖ := by constructor · intro h rcases h.exists_pos with ⟨C, hC₀, hC⟩ refine ⟨‖c‖ / C, div_pos (norm_pos_iff.2 hc) hC₀, ?_⟩ exact hC.bound.mono fun x => (div_le_iff' hC₀).2 · rintro ⟨b, hb₀, hb⟩ refine IsBigO.of_bound (‖c‖ / b) (hb.mono fun x hx => ?_) rw [div_mul_eq_mul_div, mul_div_assoc] exact le_mul_of_one_le_right (norm_nonneg _) ((one_le_div hb₀).2 hx) #align asymptotics.is_O_const_left_iff_pos_le_norm Asymptotics.isBigO_const_left_iff_pos_le_norm theorem IsBigO.trans_tendsto (hfg : f'' =O[l] g'') (hg : Tendsto g'' l (𝓝 0)) : Tendsto f'' l (𝓝 0) := (isLittleO_one_iff ℝ).1 <| hfg.trans_isLittleO <| (isLittleO_one_iff ℝ).2 hg #align asymptotics.is_O.trans_tendsto Asymptotics.IsBigO.trans_tendsto theorem IsLittleO.trans_tendsto (hfg : f'' =o[l] g'') (hg : Tendsto g'' l (𝓝 0)) : Tendsto f'' l (𝓝 0) := hfg.isBigO.trans_tendsto hg #align asymptotics.is_o.trans_tendsto Asymptotics.IsLittleO.trans_tendsto /-! ### Multiplication by a constant -/ theorem isBigOWith_const_mul_self (c : R) (f : α → R) (l : Filter α) : IsBigOWith ‖c‖ l (fun x => c * f x) f := isBigOWith_of_le' _ fun _x => norm_mul_le _ _ #align asymptotics.is_O_with_const_mul_self Asymptotics.isBigOWith_const_mul_self theorem isBigO_const_mul_self (c : R) (f : α → R) (l : Filter α) : (fun x => c * f x) =O[l] f := (isBigOWith_const_mul_self c f l).isBigO #align asymptotics.is_O_const_mul_self Asymptotics.isBigO_const_mul_self theorem IsBigOWith.const_mul_left {f : α → R} (h : IsBigOWith c l f g) (c' : R) : IsBigOWith (‖c'‖ * c) l (fun x => c' * f x) g := (isBigOWith_const_mul_self c' f l).trans h (norm_nonneg c') #align asymptotics.is_O_with.const_mul_left Asymptotics.IsBigOWith.const_mul_left theorem IsBigO.const_mul_left {f : α → R} (h : f =O[l] g) (c' : R) : (fun x => c' * f x) =O[l] g := let ⟨_c, hc⟩ := h.isBigOWith (hc.const_mul_left c').isBigO #align asymptotics.is_O.const_mul_left Asymptotics.IsBigO.const_mul_left theorem isBigOWith_self_const_mul' (u : Rˣ) (f : α → R) (l : Filter α) : IsBigOWith ‖(↑u⁻¹ : R)‖ l f fun x => ↑u * f x := (isBigOWith_const_mul_self ↑u⁻¹ (fun x ↦ ↑u * f x) l).congr_left fun x ↦ u.inv_mul_cancel_left (f x) #align asymptotics.is_O_with_self_const_mul' Asymptotics.isBigOWith_self_const_mul' theorem isBigOWith_self_const_mul (c : 𝕜) (hc : c ≠ 0) (f : α → 𝕜) (l : Filter α) : IsBigOWith ‖c‖⁻¹ l f fun x => c * f x := (isBigOWith_self_const_mul' (Units.mk0 c hc) f l).congr_const <| norm_inv c #align asymptotics.is_O_with_self_const_mul Asymptotics.isBigOWith_self_const_mul theorem isBigO_self_const_mul' {c : R} (hc : IsUnit c) (f : α → R) (l : Filter α) : f =O[l] fun x => c * f x := let ⟨u, hu⟩ := hc hu ▸ (isBigOWith_self_const_mul' u f l).isBigO #align asymptotics.is_O_self_const_mul' Asymptotics.isBigO_self_const_mul' theorem isBigO_self_const_mul (c : 𝕜) (hc : c ≠ 0) (f : α → 𝕜) (l : Filter α) : f =O[l] fun x => c * f x := isBigO_self_const_mul' (IsUnit.mk0 c hc) f l #align asymptotics.is_O_self_const_mul Asymptotics.isBigO_self_const_mul theorem isBigO_const_mul_left_iff' {f : α → R} {c : R} (hc : IsUnit c) : (fun x => c * f x) =O[l] g ↔ f =O[l] g := ⟨(isBigO_self_const_mul' hc f l).trans, fun h => h.const_mul_left c⟩ #align asymptotics.is_O_const_mul_left_iff' Asymptotics.isBigO_const_mul_left_iff' theorem isBigO_const_mul_left_iff {f : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : (fun x => c * f x) =O[l] g ↔ f =O[l] g := isBigO_const_mul_left_iff' <| IsUnit.mk0 c hc #align asymptotics.is_O_const_mul_left_iff Asymptotics.isBigO_const_mul_left_iff theorem IsLittleO.const_mul_left {f : α → R} (h : f =o[l] g) (c : R) : (fun x => c * f x) =o[l] g := (isBigO_const_mul_self c f l).trans_isLittleO h #align asymptotics.is_o.const_mul_left Asymptotics.IsLittleO.const_mul_left theorem isLittleO_const_mul_left_iff' {f : α → R} {c : R} (hc : IsUnit c) : (fun x => c * f x) =o[l] g ↔ f =o[l] g := ⟨(isBigO_self_const_mul' hc f l).trans_isLittleO, fun h => h.const_mul_left c⟩ #align asymptotics.is_o_const_mul_left_iff' Asymptotics.isLittleO_const_mul_left_iff' theorem isLittleO_const_mul_left_iff {f : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : (fun x => c * f x) =o[l] g ↔ f =o[l] g := isLittleO_const_mul_left_iff' <| IsUnit.mk0 c hc #align asymptotics.is_o_const_mul_left_iff Asymptotics.isLittleO_const_mul_left_iff theorem IsBigOWith.of_const_mul_right {g : α → R} {c : R} (hc' : 0 ≤ c') (h : IsBigOWith c' l f fun x => c * g x) : IsBigOWith (c' * ‖c‖) l f g := h.trans (isBigOWith_const_mul_self c g l) hc' #align asymptotics.is_O_with.of_const_mul_right Asymptotics.IsBigOWith.of_const_mul_right theorem IsBigO.of_const_mul_right {g : α → R} {c : R} (h : f =O[l] fun x => c * g x) : f =O[l] g := let ⟨_c, cnonneg, hc⟩ := h.exists_nonneg (hc.of_const_mul_right cnonneg).isBigO #align asymptotics.is_O.of_const_mul_right Asymptotics.IsBigO.of_const_mul_right theorem IsBigOWith.const_mul_right' {g : α → R} {u : Rˣ} {c' : ℝ} (hc' : 0 ≤ c') (h : IsBigOWith c' l f g) : IsBigOWith (c' * ‖(↑u⁻¹ : R)‖) l f fun x => ↑u * g x := h.trans (isBigOWith_self_const_mul' _ _ _) hc' #align asymptotics.is_O_with.const_mul_right' Asymptotics.IsBigOWith.const_mul_right' theorem IsBigOWith.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) {c' : ℝ} (hc' : 0 ≤ c') (h : IsBigOWith c' l f g) : IsBigOWith (c' * ‖c‖⁻¹) l f fun x => c * g x := h.trans (isBigOWith_self_const_mul c hc g l) hc' #align asymptotics.is_O_with.const_mul_right Asymptotics.IsBigOWith.const_mul_right theorem IsBigO.const_mul_right' {g : α → R} {c : R} (hc : IsUnit c) (h : f =O[l] g) : f =O[l] fun x => c * g x := h.trans (isBigO_self_const_mul' hc g l) #align asymptotics.is_O.const_mul_right' Asymptotics.IsBigO.const_mul_right' theorem IsBigO.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) (h : f =O[l] g) : f =O[l] fun x => c * g x := h.const_mul_right' <| IsUnit.mk0 c hc #align asymptotics.is_O.const_mul_right Asymptotics.IsBigO.const_mul_right theorem isBigO_const_mul_right_iff' {g : α → R} {c : R} (hc : IsUnit c) : (f =O[l] fun x => c * g x) ↔ f =O[l] g := ⟨fun h => h.of_const_mul_right, fun h => h.const_mul_right' hc⟩ #align asymptotics.is_O_const_mul_right_iff' Asymptotics.isBigO_const_mul_right_iff' theorem isBigO_const_mul_right_iff {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : (f =O[l] fun x => c * g x) ↔ f =O[l] g := isBigO_const_mul_right_iff' <| IsUnit.mk0 c hc #align asymptotics.is_O_const_mul_right_iff Asymptotics.isBigO_const_mul_right_iff theorem IsLittleO.of_const_mul_right {g : α → R} {c : R} (h : f =o[l] fun x => c * g x) : f =o[l] g := h.trans_isBigO (isBigO_const_mul_self c g l) #align asymptotics.is_o.of_const_mul_right Asymptotics.IsLittleO.of_const_mul_right theorem IsLittleO.const_mul_right' {g : α → R} {c : R} (hc : IsUnit c) (h : f =o[l] g) : f =o[l] fun x => c * g x := h.trans_isBigO (isBigO_self_const_mul' hc g l) #align asymptotics.is_o.const_mul_right' Asymptotics.IsLittleO.const_mul_right' theorem IsLittleO.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) (h : f =o[l] g) : f =o[l] fun x => c * g x := h.const_mul_right' <| IsUnit.mk0 c hc #align asymptotics.is_o.const_mul_right Asymptotics.IsLittleO.const_mul_right theorem isLittleO_const_mul_right_iff' {g : α → R} {c : R} (hc : IsUnit c) : (f =o[l] fun x => c * g x) ↔ f =o[l] g := ⟨fun h => h.of_const_mul_right, fun h => h.const_mul_right' hc⟩ #align asymptotics.is_o_const_mul_right_iff' Asymptotics.isLittleO_const_mul_right_iff' theorem isLittleO_const_mul_right_iff {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : (f =o[l] fun x => c * g x) ↔ f =o[l] g := isLittleO_const_mul_right_iff' <| IsUnit.mk0 c hc #align asymptotics.is_o_const_mul_right_iff Asymptotics.isLittleO_const_mul_right_iff /-! ### Multiplication -/ theorem IsBigOWith.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} {c₁ c₂ : ℝ} (h₁ : IsBigOWith c₁ l f₁ g₁) (h₂ : IsBigOWith c₂ l f₂ g₂) : IsBigOWith (c₁ * c₂) l (fun x => f₁ x * f₂ x) fun x => g₁ x * g₂ x := by simp only [IsBigOWith_def] at * filter_upwards [h₁, h₂] with _ hx₁ hx₂ apply le_trans (norm_mul_le _ _) convert mul_le_mul hx₁ hx₂ (norm_nonneg _) (le_trans (norm_nonneg _) hx₁) using 1 rw [norm_mul, mul_mul_mul_comm] #align asymptotics.is_O_with.mul Asymptotics.IsBigOWith.mul theorem IsBigO.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : f₁ =O[l] g₁) (h₂ : f₂ =O[l] g₂) : (fun x => f₁ x * f₂ x) =O[l] fun x => g₁ x * g₂ x := let ⟨_c, hc⟩ := h₁.isBigOWith let ⟨_c', hc'⟩ := h₂.isBigOWith (hc.mul hc').isBigO #align asymptotics.is_O.mul Asymptotics.IsBigO.mul theorem IsBigO.mul_isLittleO {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : f₁ =O[l] g₁) (h₂ : f₂ =o[l] g₂) : (fun x => f₁ x * f₂ x) =o[l] fun x => g₁ x * g₂ x := by simp only [IsLittleO_def] at * intro c cpos rcases h₁.exists_pos with ⟨c', c'pos, hc'⟩ exact (hc'.mul (h₂ (div_pos cpos c'pos))).congr_const (mul_div_cancel₀ _ (ne_of_gt c'pos)) #align asymptotics.is_O.mul_is_o Asymptotics.IsBigO.mul_isLittleO theorem IsLittleO.mul_isBigO {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : f₁ =o[l] g₁) (h₂ : f₂ =O[l] g₂) : (fun x => f₁ x * f₂ x) =o[l] fun x => g₁ x * g₂ x := by simp only [IsLittleO_def] at * intro c cpos rcases h₂.exists_pos with ⟨c', c'pos, hc'⟩ exact ((h₁ (div_pos cpos c'pos)).mul hc').congr_const (div_mul_cancel₀ _ (ne_of_gt c'pos)) #align asymptotics.is_o.mul_is_O Asymptotics.IsLittleO.mul_isBigO theorem IsLittleO.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : f₁ =o[l] g₁) (h₂ : f₂ =o[l] g₂) : (fun x => f₁ x * f₂ x) =o[l] fun x => g₁ x * g₂ x := h₁.mul_isBigO h₂.isBigO #align asymptotics.is_o.mul Asymptotics.IsLittleO.mul theorem IsBigOWith.pow' {f : α → R} {g : α → 𝕜} (h : IsBigOWith c l f g) : ∀ n : ℕ, IsBigOWith (Nat.casesOn n ‖(1 : R)‖ fun n => c ^ (n + 1)) l (fun x => f x ^ n) fun x => g x ^ n | 0 => by simpa using isBigOWith_const_const (1 : R) (one_ne_zero' 𝕜) l | 1 => by simpa | n + 2 => by simpa [pow_succ] using (IsBigOWith.pow' h (n + 1)).mul h #align asymptotics.is_O_with.pow' Asymptotics.IsBigOWith.pow' theorem IsBigOWith.pow [NormOneClass R] {f : α → R} {g : α → 𝕜} (h : IsBigOWith c l f g) : ∀ n : ℕ, IsBigOWith (c ^ n) l (fun x => f x ^ n) fun x => g x ^ n | 0 => by simpa using h.pow' 0 | n + 1 => h.pow' (n + 1) #align asymptotics.is_O_with.pow Asymptotics.IsBigOWith.pow theorem IsBigOWith.of_pow {n : ℕ} {f : α → 𝕜} {g : α → R} (h : IsBigOWith c l (f ^ n) (g ^ n)) (hn : n ≠ 0) (hc : c ≤ c' ^ n) (hc' : 0 ≤ c') : IsBigOWith c' l f g := IsBigOWith.of_bound <| (h.weaken hc).bound.mono fun x hx ↦ le_of_pow_le_pow_left hn (by positivity) <| calc ‖f x‖ ^ n = ‖f x ^ n‖ := (norm_pow _ _).symm _ ≤ c' ^ n * ‖g x ^ n‖ := hx _ ≤ c' ^ n * ‖g x‖ ^ n := by gcongr; exact norm_pow_le' _ hn.bot_lt _ = (c' * ‖g x‖) ^ n := (mul_pow _ _ _).symm #align asymptotics.is_O_with.of_pow Asymptotics.IsBigOWith.of_pow theorem IsBigO.pow {f : α → R} {g : α → 𝕜} (h : f =O[l] g) (n : ℕ) : (fun x => f x ^ n) =O[l] fun x => g x ^ n := let ⟨_C, hC⟩ := h.isBigOWith isBigO_iff_isBigOWith.2 ⟨_, hC.pow' n⟩ #align asymptotics.is_O.pow Asymptotics.IsBigO.pow theorem IsBigO.of_pow {f : α → 𝕜} {g : α → R} {n : ℕ} (hn : n ≠ 0) (h : (f ^ n) =O[l] (g ^ n)) : f =O[l] g := by rcases h.exists_pos with ⟨C, _hC₀, hC⟩ obtain ⟨c : ℝ, hc₀ : 0 ≤ c, hc : C ≤ c ^ n⟩ := ((eventually_ge_atTop _).and <| (tendsto_pow_atTop hn).eventually_ge_atTop C).exists exact (hC.of_pow hn hc hc₀).isBigO #align asymptotics.is_O.of_pow Asymptotics.IsBigO.of_pow theorem IsLittleO.pow {f : α → R} {g : α → 𝕜} (h : f =o[l] g) {n : ℕ} (hn : 0 < n) : (fun x => f x ^ n) =o[l] fun x => g x ^ n := by obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hn.ne'; clear hn induction' n with n ihn · simpa only [Nat.zero_eq, ← Nat.one_eq_succ_zero, pow_one] · convert ihn.mul h <;> simp [pow_succ] #align asymptotics.is_o.pow Asymptotics.IsLittleO.pow theorem IsLittleO.of_pow {f : α → 𝕜} {g : α → R} {n : ℕ} (h : (f ^ n) =o[l] (g ^ n)) (hn : n ≠ 0) : f =o[l] g := IsLittleO.of_isBigOWith fun _c hc => (h.def' <| pow_pos hc _).of_pow hn le_rfl hc.le #align asymptotics.is_o.of_pow Asymptotics.IsLittleO.of_pow /-! ### Inverse -/ theorem IsBigOWith.inv_rev {f : α → 𝕜} {g : α → 𝕜'} (h : IsBigOWith c l f g) (h₀ : ∀ᶠ x in l, f x = 0 → g x = 0) : IsBigOWith c l (fun x => (g x)⁻¹) fun x => (f x)⁻¹ := by refine IsBigOWith.of_bound (h.bound.mp (h₀.mono fun x h₀ hle => ?_)) rcases eq_or_ne (f x) 0 with hx | hx · simp only [hx, h₀ hx, inv_zero, norm_zero, mul_zero, le_rfl] · have hc : 0 < c := pos_of_mul_pos_left ((norm_pos_iff.2 hx).trans_le hle) (norm_nonneg _) replace hle := inv_le_inv_of_le (norm_pos_iff.2 hx) hle simpa only [norm_inv, mul_inv, ← div_eq_inv_mul, div_le_iff hc] using hle #align asymptotics.is_O_with.inv_rev Asymptotics.IsBigOWith.inv_rev theorem IsBigO.inv_rev {f : α → 𝕜} {g : α → 𝕜'} (h : f =O[l] g) (h₀ : ∀ᶠ x in l, f x = 0 → g x = 0) : (fun x => (g x)⁻¹) =O[l] fun x => (f x)⁻¹ := let ⟨_c, hc⟩ := h.isBigOWith (hc.inv_rev h₀).isBigO #align asymptotics.is_O.inv_rev Asymptotics.IsBigO.inv_rev theorem IsLittleO.inv_rev {f : α → 𝕜} {g : α → 𝕜'} (h : f =o[l] g) (h₀ : ∀ᶠ x in l, f x = 0 → g x = 0) : (fun x => (g x)⁻¹) =o[l] fun x => (f x)⁻¹ := IsLittleO.of_isBigOWith fun _c hc => (h.def' hc).inv_rev h₀ #align asymptotics.is_o.inv_rev Asymptotics.IsLittleO.inv_rev /-! ### Scalar multiplication -/ section SMulConst variable [Module R E'] [BoundedSMul R E'] theorem IsBigOWith.const_smul_self (c' : R) : IsBigOWith (‖c'‖) l (fun x => c' • f' x) f' := isBigOWith_of_le' _ fun _ => norm_smul_le _ _ theorem IsBigO.const_smul_self (c' : R) : (fun x => c' • f' x) =O[l] f' := (IsBigOWith.const_smul_self _).isBigO theorem IsBigOWith.const_smul_left (h : IsBigOWith c l f' g) (c' : R) : IsBigOWith (‖c'‖ * c) l (fun x => c' • f' x) g := .trans (.const_smul_self _) h (norm_nonneg _) theorem IsBigO.const_smul_left (h : f' =O[l] g) (c : R) : (c • f') =O[l] g := let ⟨_b, hb⟩ := h.isBigOWith (hb.const_smul_left _).isBigO #align asymptotics.is_O.const_smul_left Asymptotics.IsBigO.const_smul_left theorem IsLittleO.const_smul_left (h : f' =o[l] g) (c : R) : (c • f') =o[l] g := (IsBigO.const_smul_self _).trans_isLittleO h #align asymptotics.is_o.const_smul_left Asymptotics.IsLittleO.const_smul_left variable [Module 𝕜 E'] [BoundedSMul 𝕜 E'] theorem isBigO_const_smul_left {c : 𝕜} (hc : c ≠ 0) : (fun x => c • f' x) =O[l] g ↔ f' =O[l] g := by have cne0 : ‖c‖ ≠ 0 := norm_ne_zero_iff.mpr hc rw [← isBigO_norm_left] simp only [norm_smul] rw [isBigO_const_mul_left_iff cne0, isBigO_norm_left] #align asymptotics.is_O_const_smul_left Asymptotics.isBigO_const_smul_left theorem isLittleO_const_smul_left {c : 𝕜} (hc : c ≠ 0) : (fun x => c • f' x) =o[l] g ↔ f' =o[l] g := by have cne0 : ‖c‖ ≠ 0 := norm_ne_zero_iff.mpr hc rw [← isLittleO_norm_left] simp only [norm_smul] rw [isLittleO_const_mul_left_iff cne0, isLittleO_norm_left] #align asymptotics.is_o_const_smul_left Asymptotics.isLittleO_const_smul_left theorem isBigO_const_smul_right {c : 𝕜} (hc : c ≠ 0) : (f =O[l] fun x => c • f' x) ↔ f =O[l] f' := by have cne0 : ‖c‖ ≠ 0 := norm_ne_zero_iff.mpr hc rw [← isBigO_norm_right] simp only [norm_smul] rw [isBigO_const_mul_right_iff cne0, isBigO_norm_right] #align asymptotics.is_O_const_smul_right Asymptotics.isBigO_const_smul_right theorem isLittleO_const_smul_right {c : 𝕜} (hc : c ≠ 0) : (f =o[l] fun x => c • f' x) ↔ f =o[l] f' := by have cne0 : ‖c‖ ≠ 0 := norm_ne_zero_iff.mpr hc rw [← isLittleO_norm_right] simp only [norm_smul] rw [isLittleO_const_mul_right_iff cne0, isLittleO_norm_right] #align asymptotics.is_o_const_smul_right Asymptotics.isLittleO_const_smul_right end SMulConst section SMul variable [Module R E'] [BoundedSMul R E'] [Module 𝕜' F'] [BoundedSMul 𝕜' F'] variable {k₁ : α → R} {k₂ : α → 𝕜'} theorem IsBigOWith.smul (h₁ : IsBigOWith c l k₁ k₂) (h₂ : IsBigOWith c' l f' g') : IsBigOWith (c * c') l (fun x => k₁ x • f' x) fun x => k₂ x • g' x := by simp only [IsBigOWith_def] at * filter_upwards [h₁, h₂] with _ hx₁ hx₂ apply le_trans (norm_smul_le _ _) convert mul_le_mul hx₁ hx₂ (norm_nonneg _) (le_trans (norm_nonneg _) hx₁) using 1 rw [norm_smul, mul_mul_mul_comm] #align asymptotics.is_O_with.smul Asymptotics.IsBigOWith.smul theorem IsBigO.smul (h₁ : k₁ =O[l] k₂) (h₂ : f' =O[l] g') : (fun x => k₁ x • f' x) =O[l] fun x => k₂ x • g' x := by obtain ⟨c₁, h₁⟩ := h₁.isBigOWith obtain ⟨c₂, h₂⟩ := h₂.isBigOWith exact (h₁.smul h₂).isBigO #align asymptotics.is_O.smul Asymptotics.IsBigO.smul theorem IsBigO.smul_isLittleO (h₁ : k₁ =O[l] k₂) (h₂ : f' =o[l] g') : (fun x => k₁ x • f' x) =o[l] fun x => k₂ x • g' x := by simp only [IsLittleO_def] at * intro c cpos rcases h₁.exists_pos with ⟨c', c'pos, hc'⟩ exact (hc'.smul (h₂ (div_pos cpos c'pos))).congr_const (mul_div_cancel₀ _ (ne_of_gt c'pos)) #align asymptotics.is_O.smul_is_o Asymptotics.IsBigO.smul_isLittleO theorem IsLittleO.smul_isBigO (h₁ : k₁ =o[l] k₂) (h₂ : f' =O[l] g') : (fun x => k₁ x • f' x) =o[l] fun x => k₂ x • g' x := by simp only [IsLittleO_def] at * intro c cpos rcases h₂.exists_pos with ⟨c', c'pos, hc'⟩ exact ((h₁ (div_pos cpos c'pos)).smul hc').congr_const (div_mul_cancel₀ _ (ne_of_gt c'pos)) #align asymptotics.is_o.smul_is_O Asymptotics.IsLittleO.smul_isBigO theorem IsLittleO.smul (h₁ : k₁ =o[l] k₂) (h₂ : f' =o[l] g') : (fun x => k₁ x • f' x) =o[l] fun x => k₂ x • g' x := h₁.smul_isBigO h₂.isBigO #align asymptotics.is_o.smul Asymptotics.IsLittleO.smul end SMul /-! ### Sum -/ section Sum variable {ι : Type*} {A : ι → α → E'} {C : ι → ℝ} {s : Finset ι} theorem IsBigOWith.sum (h : ∀ i ∈ s, IsBigOWith (C i) l (A i) g) : IsBigOWith (∑ i ∈ s, C i) l (fun x => ∑ i ∈ s, A i x) g := by induction' s using Finset.induction_on with i s is IH · simp only [isBigOWith_zero', Finset.sum_empty, forall_true_iff] · simp only [is, Finset.sum_insert, not_false_iff] exact (h _ (Finset.mem_insert_self i s)).add (IH fun j hj => h _ (Finset.mem_insert_of_mem hj)) #align asymptotics.is_O_with.sum Asymptotics.IsBigOWith.sum theorem IsBigO.sum (h : ∀ i ∈ s, A i =O[l] g) : (fun x => ∑ i ∈ s, A i x) =O[l] g := by simp only [IsBigO_def] at * choose! C hC using h exact ⟨_, IsBigOWith.sum hC⟩ #align asymptotics.is_O.sum Asymptotics.IsBigO.sum theorem IsLittleO.sum (h : ∀ i ∈ s, A i =o[l] g') : (fun x => ∑ i ∈ s, A i x) =o[l] g' := by induction' s using Finset.induction_on with i s is IH · simp only [isLittleO_zero, Finset.sum_empty, forall_true_iff] · simp only [is, Finset.sum_insert, not_false_iff] exact (h _ (Finset.mem_insert_self i s)).add (IH fun j hj => h _ (Finset.mem_insert_of_mem hj)) #align asymptotics.is_o.sum Asymptotics.IsLittleO.sum end Sum /-! ### Relation between `f = o(g)` and `f / g → 0` -/ theorem IsLittleO.tendsto_div_nhds_zero {f g : α → 𝕜} (h : f =o[l] g) : Tendsto (fun x => f x / g x) l (𝓝 0) := (isLittleO_one_iff 𝕜).mp <| by calc (fun x => f x / g x) =o[l] fun x => g x / g x := by simpa only [div_eq_mul_inv] using h.mul_isBigO (isBigO_refl _ _) _ =O[l] fun _x => (1 : 𝕜) := isBigO_of_le _ fun x => by simp [div_self_le_one] #align asymptotics.is_o.tendsto_div_nhds_zero Asymptotics.IsLittleO.tendsto_div_nhds_zero theorem IsLittleO.tendsto_inv_smul_nhds_zero [Module 𝕜 E'] [BoundedSMul 𝕜 E'] {f : α → E'} {g : α → 𝕜} {l : Filter α} (h : f =o[l] g) : Tendsto (fun x => (g x)⁻¹ • f x) l (𝓝 0) := by simpa only [div_eq_inv_mul, ← norm_inv, ← norm_smul, ← tendsto_zero_iff_norm_tendsto_zero] using h.norm_norm.tendsto_div_nhds_zero #align asymptotics.is_o.tendsto_inv_smul_nhds_zero Asymptotics.IsLittleO.tendsto_inv_smul_nhds_zero theorem isLittleO_iff_tendsto' {f g : α → 𝕜} (hgf : ∀ᶠ x in l, g x = 0 → f x = 0) : f =o[l] g ↔ Tendsto (fun x => f x / g x) l (𝓝 0) := ⟨IsLittleO.tendsto_div_nhds_zero, fun h => (((isLittleO_one_iff _).mpr h).mul_isBigO (isBigO_refl g l)).congr' (hgf.mono fun _x => div_mul_cancel_of_imp) (eventually_of_forall fun _x => one_mul _)⟩ #align asymptotics.is_o_iff_tendsto' Asymptotics.isLittleO_iff_tendsto' theorem isLittleO_iff_tendsto {f g : α → 𝕜} (hgf : ∀ x, g x = 0 → f x = 0) : f =o[l] g ↔ Tendsto (fun x => f x / g x) l (𝓝 0) := isLittleO_iff_tendsto' (eventually_of_forall hgf) #align asymptotics.is_o_iff_tendsto Asymptotics.isLittleO_iff_tendsto alias ⟨_, isLittleO_of_tendsto'⟩ := isLittleO_iff_tendsto' #align asymptotics.is_o_of_tendsto' Asymptotics.isLittleO_of_tendsto' alias ⟨_, isLittleO_of_tendsto⟩ := isLittleO_iff_tendsto #align asymptotics.is_o_of_tendsto Asymptotics.isLittleO_of_tendsto theorem isLittleO_const_left_of_ne {c : E''} (hc : c ≠ 0) : (fun _x => c) =o[l] g ↔ Tendsto (fun x => ‖g x‖) l atTop := by simp only [← isLittleO_one_left_iff ℝ] exact ⟨(isBigO_const_const (1 : ℝ) hc l).trans_isLittleO, (isBigO_const_one ℝ c l).trans_isLittleO⟩ #align asymptotics.is_o_const_left_of_ne Asymptotics.isLittleO_const_left_of_ne @[simp] theorem isLittleO_const_left {c : E''} : (fun _x => c) =o[l] g'' ↔ c = 0 ∨ Tendsto (norm ∘ g'') l atTop := by rcases eq_or_ne c 0 with (rfl | hc) · simp only [isLittleO_zero, eq_self_iff_true, true_or_iff] · simp only [hc, false_or_iff, isLittleO_const_left_of_ne hc]; rfl #align asymptotics.is_o_const_left Asymptotics.isLittleO_const_left @[simp 1001] -- Porting note: increase priority so that this triggers before `isLittleO_const_left` theorem isLittleO_const_const_iff [NeBot l] {d : E''} {c : F''} : ((fun _x => d) =o[l] fun _x => c) ↔ d = 0 := by have : ¬Tendsto (Function.const α ‖c‖) l atTop := not_tendsto_atTop_of_tendsto_nhds tendsto_const_nhds simp only [isLittleO_const_left, or_iff_left_iff_imp] exact fun h => (this h).elim #align asymptotics.is_o_const_const_iff Asymptotics.isLittleO_const_const_iff @[simp] theorem isLittleO_pure {x} : f'' =o[pure x] g'' ↔ f'' x = 0 := calc f'' =o[pure x] g'' ↔ (fun _y : α => f'' x) =o[pure x] fun _ => g'' x := isLittleO_congr rfl rfl _ ↔ f'' x = 0 := isLittleO_const_const_iff #align asymptotics.is_o_pure Asymptotics.isLittleO_pure theorem isLittleO_const_id_cobounded (c : F'') : (fun _ => c) =o[Bornology.cobounded E''] id := isLittleO_const_left.2 <| .inr tendsto_norm_cobounded_atTop #align asymptotics.is_o_const_id_comap_norm_at_top Asymptotics.isLittleO_const_id_cobounded theorem isLittleO_const_id_atTop (c : E'') : (fun _x : ℝ => c) =o[atTop] id := isLittleO_const_left.2 <| Or.inr tendsto_abs_atTop_atTop #align asymptotics.is_o_const_id_at_top Asymptotics.isLittleO_const_id_atTop theorem isLittleO_const_id_atBot (c : E'') : (fun _x : ℝ => c) =o[atBot] id := isLittleO_const_left.2 <| Or.inr tendsto_abs_atBot_atTop #align asymptotics.is_o_const_id_at_bot Asymptotics.isLittleO_const_id_atBot /-! ### Eventually (u / v) * v = u If `u` and `v` are linked by an `IsBigOWith` relation, then we eventually have `(u / v) * v = u`, even if `v` vanishes. -/ section EventuallyMulDivCancel variable {u v : α → 𝕜} theorem IsBigOWith.eventually_mul_div_cancel (h : IsBigOWith c l u v) : u / v * v =ᶠ[l] u := Eventually.mono h.bound fun y hy => div_mul_cancel_of_imp fun hv => by simpa [hv] using hy #align asymptotics.is_O_with.eventually_mul_div_cancel Asymptotics.IsBigOWith.eventually_mul_div_cancel /-- If `u = O(v)` along `l`, then `(u / v) * v = u` eventually at `l`. -/ theorem IsBigO.eventually_mul_div_cancel (h : u =O[l] v) : u / v * v =ᶠ[l] u := let ⟨_c, hc⟩ := h.isBigOWith hc.eventually_mul_div_cancel #align asymptotics.is_O.eventually_mul_div_cancel Asymptotics.IsBigO.eventually_mul_div_cancel /-- If `u = o(v)` along `l`, then `(u / v) * v = u` eventually at `l`. -/ theorem IsLittleO.eventually_mul_div_cancel (h : u =o[l] v) : u / v * v =ᶠ[l] u := (h.forall_isBigOWith zero_lt_one).eventually_mul_div_cancel #align asymptotics.is_o.eventually_mul_div_cancel Asymptotics.IsLittleO.eventually_mul_div_cancel end EventuallyMulDivCancel /-! ### Equivalent definitions of the form `∃ φ, u =ᶠ[l] φ * v` in a `NormedField`. -/ section ExistsMulEq variable {u v : α → 𝕜} /-- If `‖φ‖` is eventually bounded by `c`, and `u =ᶠ[l] φ * v`, then we have `IsBigOWith c u v l`. This does not require any assumptions on `c`, which is why we keep this version along with `IsBigOWith_iff_exists_eq_mul`. -/ theorem isBigOWith_of_eq_mul {u v : α → R} (φ : α → R) (hφ : ∀ᶠ x in l, ‖φ x‖ ≤ c) (h : u =ᶠ[l] φ * v) : IsBigOWith c l u v := by simp only [IsBigOWith_def] refine h.symm.rw (fun x a => ‖a‖ ≤ c * ‖v x‖) (hφ.mono fun x hx => ?_) simp only [Pi.mul_apply] refine (norm_mul_le _ _).trans ?_ gcongr #align asymptotics.is_O_with_of_eq_mul Asymptotics.isBigOWith_of_eq_mul theorem isBigOWith_iff_exists_eq_mul (hc : 0 ≤ c) : IsBigOWith c l u v ↔ ∃ φ : α → 𝕜, (∀ᶠ x in l, ‖φ x‖ ≤ c) ∧ u =ᶠ[l] φ * v := by constructor · intro h use fun x => u x / v x refine ⟨Eventually.mono h.bound fun y hy => ?_, h.eventually_mul_div_cancel.symm⟩ simpa using div_le_of_nonneg_of_le_mul (norm_nonneg _) hc hy · rintro ⟨φ, hφ, h⟩ exact isBigOWith_of_eq_mul φ hφ h #align asymptotics.is_O_with_iff_exists_eq_mul Asymptotics.isBigOWith_iff_exists_eq_mul theorem IsBigOWith.exists_eq_mul (h : IsBigOWith c l u v) (hc : 0 ≤ c) : ∃ φ : α → 𝕜, (∀ᶠ x in l, ‖φ x‖ ≤ c) ∧ u =ᶠ[l] φ * v := (isBigOWith_iff_exists_eq_mul hc).mp h #align asymptotics.is_O_with.exists_eq_mul Asymptotics.IsBigOWith.exists_eq_mul theorem isBigO_iff_exists_eq_mul : u =O[l] v ↔ ∃ φ : α → 𝕜, l.IsBoundedUnder (· ≤ ·) (norm ∘ φ) ∧ u =ᶠ[l] φ * v := by constructor · rintro h rcases h.exists_nonneg with ⟨c, hnnc, hc⟩ rcases hc.exists_eq_mul hnnc with ⟨φ, hφ, huvφ⟩ exact ⟨φ, ⟨c, hφ⟩, huvφ⟩ · rintro ⟨φ, ⟨c, hφ⟩, huvφ⟩ exact isBigO_iff_isBigOWith.2 ⟨c, isBigOWith_of_eq_mul φ hφ huvφ⟩ #align asymptotics.is_O_iff_exists_eq_mul Asymptotics.isBigO_iff_exists_eq_mul alias ⟨IsBigO.exists_eq_mul, _⟩ := isBigO_iff_exists_eq_mul #align asymptotics.is_O.exists_eq_mul Asymptotics.IsBigO.exists_eq_mul theorem isLittleO_iff_exists_eq_mul : u =o[l] v ↔ ∃ φ : α → 𝕜, Tendsto φ l (𝓝 0) ∧ u =ᶠ[l] φ * v := by constructor · exact fun h => ⟨fun x => u x / v x, h.tendsto_div_nhds_zero, h.eventually_mul_div_cancel.symm⟩ · simp only [IsLittleO_def] rintro ⟨φ, hφ, huvφ⟩ c hpos rw [NormedAddCommGroup.tendsto_nhds_zero] at hφ exact isBigOWith_of_eq_mul _ ((hφ c hpos).mono fun x => le_of_lt) huvφ #align asymptotics.is_o_iff_exists_eq_mul Asymptotics.isLittleO_iff_exists_eq_mul alias ⟨IsLittleO.exists_eq_mul, _⟩ := isLittleO_iff_exists_eq_mul #align asymptotics.is_o.exists_eq_mul Asymptotics.IsLittleO.exists_eq_mul end ExistsMulEq /-! ### Miscellaneous lemmas -/ theorem div_isBoundedUnder_of_isBigO {α : Type*} {l : Filter α} {f g : α → 𝕜} (h : f =O[l] g) : IsBoundedUnder (· ≤ ·) l fun x => ‖f x / g x‖ := by obtain ⟨c, h₀, hc⟩ := h.exists_nonneg refine ⟨c, eventually_map.2 (hc.bound.mono fun x hx => ?_)⟩ rw [norm_div] exact div_le_of_nonneg_of_le_mul (norm_nonneg _) h₀ hx #align asymptotics.div_is_bounded_under_of_is_O Asymptotics.div_isBoundedUnder_of_isBigO theorem isBigO_iff_div_isBoundedUnder {α : Type*} {l : Filter α} {f g : α → 𝕜} (hgf : ∀ᶠ x in l, g x = 0 → f x = 0) : f =O[l] g ↔ IsBoundedUnder (· ≤ ·) l fun x => ‖f x / g x‖ := by refine ⟨div_isBoundedUnder_of_isBigO, fun h => ?_⟩ obtain ⟨c, hc⟩ := h simp only [eventually_map, norm_div] at hc refine IsBigO.of_bound c (hc.mp <| hgf.mono fun x hx₁ hx₂ => ?_) by_cases hgx : g x = 0 · simp [hx₁ hgx, hgx] · exact (div_le_iff (norm_pos_iff.2 hgx)).mp hx₂ #align asymptotics.is_O_iff_div_is_bounded_under Asymptotics.isBigO_iff_div_isBoundedUnder theorem isBigO_of_div_tendsto_nhds {α : Type*} {l : Filter α} {f g : α → 𝕜} (hgf : ∀ᶠ x in l, g x = 0 → f x = 0) (c : 𝕜) (H : Filter.Tendsto (f / g) l (𝓝 c)) : f =O[l] g := (isBigO_iff_div_isBoundedUnder hgf).2 <| H.norm.isBoundedUnder_le #align asymptotics.is_O_of_div_tendsto_nhds Asymptotics.isBigO_of_div_tendsto_nhds theorem IsLittleO.tendsto_zero_of_tendsto {α E 𝕜 : Type*} [NormedAddCommGroup E] [NormedField 𝕜] {u : α → E} {v : α → 𝕜} {l : Filter α} {y : 𝕜} (huv : u =o[l] v) (hv : Tendsto v l (𝓝 y)) : Tendsto u l (𝓝 0) := by suffices h : u =o[l] fun _x => (1 : 𝕜) by rwa [isLittleO_one_iff] at h exact huv.trans_isBigO (hv.isBigO_one 𝕜) #align asymptotics.is_o.tendsto_zero_of_tendsto Asymptotics.IsLittleO.tendsto_zero_of_tendsto
Mathlib/Analysis/Asymptotics/Asymptotics.lean
2,079
2,084
theorem isLittleO_pow_pow {m n : ℕ} (h : m < n) : (fun x : 𝕜 => x ^ n) =o[𝓝 0] fun x => x ^ m := by
rcases lt_iff_exists_add.1 h with ⟨p, hp0 : 0 < p, rfl⟩ suffices (fun x : 𝕜 => x ^ m * x ^ p) =o[𝓝 0] fun x => x ^ m * 1 ^ p by simpa only [pow_add, one_pow, mul_one] exact IsBigO.mul_isLittleO (isBigO_refl _ _) (IsLittleO.pow ((isLittleO_one_iff _).2 tendsto_id) hp0)
/- 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.Sigma.Basic import Mathlib.Algebra.Order.Ring.Nat #align_import set_theory.lists from "leanprover-community/mathlib"@"497d1e06409995dd8ec95301fa8d8f3480187f4c" /-! # A computable model of ZFA without infinity In this file we define finite hereditary lists. This is useful for calculations in naive set theory. We distinguish two kinds of ZFA lists: * Atoms. Directly correspond to an element of the original type. * Proper ZFA lists. Can be thought of (but aren't implemented) as a list of ZFA lists (not necessarily proper). For example, `Lists ℕ` contains stuff like `23`, `[]`, `[37]`, `[1, [[2], 3], 4]`. ## Implementation note As we want to be able to append both atoms and proper ZFA lists to proper ZFA lists, it's handy that atoms and proper ZFA lists belong to the same type, even though atoms of `α` could be modelled as `α` directly. But we don't want to be able to append anything to atoms. This calls for a two-steps definition of ZFA lists: * First, define ZFA prelists as atoms and proper ZFA prelists. Those proper ZFA prelists are defined by inductive appending of (not necessarily proper) ZFA lists. * Second, define ZFA lists by rubbing out the distinction between atoms and proper lists. ## Main declarations * `Lists' α false`: Atoms as ZFA prelists. Basically a copy of `α`. * `Lists' α true`: Proper ZFA prelists. Defined inductively from the empty ZFA prelist (`Lists'.nil`) and from appending a ZFA prelist to a proper ZFA prelist (`Lists'.cons a l`). * `Lists α`: ZFA lists. Sum of the atoms and proper ZFA prelists. * `Finsets α`: ZFA sets. Defined as `Lists` quotiented by `Lists.Equiv`, the extensional equivalence. -/ variable {α : Type*} /-- Prelists, helper type to define `Lists`. `Lists' α false` are the "atoms", a copy of `α`. `Lists' α true` are the "proper" ZFA prelists, inductively defined from the empty ZFA prelist and from appending a ZFA prelist to a proper ZFA prelist. It is made so that you can't append anything to an atom while having only one appending function for appending both atoms and proper ZFC prelists to a proper ZFA prelist. -/ inductive Lists'.{u} (α : Type u) : Bool → Type u | atom : α → Lists' α false | nil : Lists' α true | cons' {b} : Lists' α b → Lists' α true → Lists' α true deriving DecidableEq #align lists' Lists' compile_inductive% Lists' /-- Hereditarily finite list, aka ZFA list. A ZFA list is either an "atom" (`b = false`), corresponding to an element of `α`, or a "proper" ZFA list, inductively defined from the empty ZFA list and from appending a ZFA list to a proper ZFA list. -/ def Lists (α : Type*) := Σb, Lists' α b #align lists Lists namespace Lists' instance [Inhabited α] : ∀ b, Inhabited (Lists' α b) | true => ⟨nil⟩ | false => ⟨atom default⟩ /-- Appending a ZFA list to a proper ZFA prelist. -/ def cons : Lists α → Lists' α true → Lists' α true | ⟨_, a⟩, l => cons' a l #align lists'.cons Lists'.cons /-- Converts a ZFA prelist to a `List` of ZFA lists. Atoms are sent to `[]`. -/ @[simp] def toList : ∀ {b}, Lists' α b → List (Lists α) | _, atom _ => [] | _, nil => [] | _, cons' a l => ⟨_, a⟩ :: l.toList #align lists'.to_list Lists'.toList -- Porting note (#10618): removed @[simp] -- simp can prove this: by simp only [@Lists'.toList, @Sigma.eta] theorem toList_cons (a : Lists α) (l) : toList (cons a l) = a :: l.toList := by simp #align lists'.to_list_cons Lists'.toList_cons /-- Converts a `List` of ZFA lists to a proper ZFA prelist. -/ @[simp] def ofList : List (Lists α) → Lists' α true | [] => nil | a :: l => cons a (ofList l) #align lists'.of_list Lists'.ofList @[simp]
Mathlib/SetTheory/Lists.lean
99
99
theorem to_ofList (l : List (Lists α)) : toList (ofList l) = l := by
induction l <;> simp [*]
/- Copyright (c) 2022 Yuyang Zhao. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yuyang Zhao -/ import Mathlib.Algebra.Order.Floor import Mathlib.Data.Nat.Prime /-! # Existence of a sufficiently large prime for which `a * c ^ p / (p - 1)! < 1` This is a technical result used in the proof of the Lindemann-Weierstrass theorem. -/ namespace FloorRing open scoped Nat variable {K : Type*}
Mathlib/Algebra/Order/Floor/Prime.lean
22
34
theorem exists_prime_mul_pow_lt_factorial [LinearOrderedRing K] [FloorRing K] (n : ℕ) (a c : K) : ∃ p > n, p.Prime ∧ a * c ^ p < (p - 1)! := by
obtain ⟨p, pn, pp, h⟩ := n.exists_prime_mul_pow_lt_factorial ⌈|a|⌉.natAbs ⌈|c|⌉.natAbs use p, pn, pp calc a * c ^ p _ ≤ |a * c ^ p| := le_abs_self _ _ ≤ ⌈|a|⌉ * (⌈|c|⌉ : K) ^ p := ?_ _ = ↑(Int.natAbs ⌈|a|⌉ * Int.natAbs ⌈|c|⌉ ^ p) := ?_ _ < ↑(p - 1)! := Nat.cast_lt.mpr h · rw [abs_mul, abs_pow] gcongr <;> try first | positivity | apply Int.le_ceil · simp_rw [Nat.cast_mul, Nat.cast_pow, Int.cast_natAbs, abs_eq_self.mpr (Int.ceil_nonneg (abs_nonneg (_ : K)))]
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Eric Wieser -/ import Mathlib.Algebra.Algebra.Defs import Mathlib.GroupTheory.GroupAction.BigOperators import Mathlib.LinearAlgebra.Prod #align_import algebra.triv_sq_zero_ext from "leanprover-community/mathlib"@"ce7e9d53d4bbc38065db3b595cd5bd73c323bc1d" /-! # Trivial Square-Zero Extension Given a ring `R` together with an `(R, R)`-bimodule `M`, the trivial square-zero extension of `M` over `R` is defined to be the `R`-algebra `R ⊕ M` with multiplication given by `(r₁ + m₁) * (r₂ + m₂) = r₁ r₂ + r₁ m₂ + m₁ r₂`. It is a square-zero extension because `M^2 = 0`. Note that expressing this requires bimodules; we write these in general for a not-necessarily-commutative `R` as: ```lean variable {R M : Type*} [Semiring R] [AddCommMonoid M] variable [Module R M] [Module Rᵐᵒᵖ M] [SMulCommClass R Rᵐᵒᵖ M] ``` If we instead work with a commutative `R'` acting symmetrically on `M`, we write ```lean variable {R' M : Type*} [CommSemiring R'] [AddCommMonoid M] variable [Module R' M] [Module R'ᵐᵒᵖ M] [IsCentralScalar R' M] ``` noting that in this context `IsCentralScalar R' M` implies `SMulCommClass R' R'ᵐᵒᵖ M`. Many of the later results in this file are only stated for the commutative `R'` for simplicity. ## Main definitions * `TrivSqZeroExt.inl`, `TrivSqZeroExt.inr`: the canonical inclusions into `TrivSqZeroExt R M`. * `TrivSqZeroExt.fst`, `TrivSqZeroExt.snd`: the canonical projections from `TrivSqZeroExt R M`. * `triv_sq_zero_ext.algebra`: the associated `R`-algebra structure. * `TrivSqZeroExt.lift`: the universal property of the trivial square-zero extension; algebra morphisms `TrivSqZeroExt R M →ₐ[S] A` are uniquely defined by an algebra morphism `f : R →ₐ[S] A` on `R` and a linear map `g : M →ₗ[S] A` on `M` such that: * `g x * g y = 0`: the elements of `M` continue to square to zero. * `g (r •> x) = f r * g x` and `g (x <• r) = g x * f r`: left and right actions are preserved by `g`. * `TrivSqZeroExt.lift`: the universal property of the trivial square-zero extension; algebra morphisms `TrivSqZeroExt R M →ₐ[R] A` are uniquely defined by linear maps `M →ₗ[R] A` for which the product of any two elements in the range is zero. -/ universe u v w /-- "Trivial Square-Zero Extension". Given a module `M` over a ring `R`, the trivial square-zero extension of `M` over `R` is defined to be the `R`-algebra `R × M` with multiplication given by `(r₁ + m₁) * (r₂ + m₂) = r₁ r₂ + r₁ m₂ + r₂ m₁`. It is a square-zero extension because `M^2 = 0`. -/ def TrivSqZeroExt (R : Type u) (M : Type v) := R × M #align triv_sq_zero_ext TrivSqZeroExt local notation "tsze" => TrivSqZeroExt open scoped RightActions namespace TrivSqZeroExt open MulOpposite section Basic variable {R : Type u} {M : Type v} /-- The canonical inclusion `R → TrivSqZeroExt R M`. -/ def inl [Zero M] (r : R) : tsze R M := (r, 0) #align triv_sq_zero_ext.inl TrivSqZeroExt.inl /-- The canonical inclusion `M → TrivSqZeroExt R M`. -/ def inr [Zero R] (m : M) : tsze R M := (0, m) #align triv_sq_zero_ext.inr TrivSqZeroExt.inr /-- The canonical projection `TrivSqZeroExt R M → R`. -/ def fst (x : tsze R M) : R := x.1 #align triv_sq_zero_ext.fst TrivSqZeroExt.fst /-- The canonical projection `TrivSqZeroExt R M → M`. -/ def snd (x : tsze R M) : M := x.2 #align triv_sq_zero_ext.snd TrivSqZeroExt.snd @[simp] theorem fst_mk (r : R) (m : M) : fst (r, m) = r := rfl #align triv_sq_zero_ext.fst_mk TrivSqZeroExt.fst_mk @[simp] theorem snd_mk (r : R) (m : M) : snd (r, m) = m := rfl #align triv_sq_zero_ext.snd_mk TrivSqZeroExt.snd_mk @[ext] theorem ext {x y : tsze R M} (h1 : x.fst = y.fst) (h2 : x.snd = y.snd) : x = y := Prod.ext h1 h2 #align triv_sq_zero_ext.ext TrivSqZeroExt.ext section variable (M) @[simp] theorem fst_inl [Zero M] (r : R) : (inl r : tsze R M).fst = r := rfl #align triv_sq_zero_ext.fst_inl TrivSqZeroExt.fst_inl @[simp] theorem snd_inl [Zero M] (r : R) : (inl r : tsze R M).snd = 0 := rfl #align triv_sq_zero_ext.snd_inl TrivSqZeroExt.snd_inl @[simp] theorem fst_comp_inl [Zero M] : fst ∘ (inl : R → tsze R M) = id := rfl #align triv_sq_zero_ext.fst_comp_inl TrivSqZeroExt.fst_comp_inl @[simp] theorem snd_comp_inl [Zero M] : snd ∘ (inl : R → tsze R M) = 0 := rfl #align triv_sq_zero_ext.snd_comp_inl TrivSqZeroExt.snd_comp_inl end section variable (R) @[simp] theorem fst_inr [Zero R] (m : M) : (inr m : tsze R M).fst = 0 := rfl #align triv_sq_zero_ext.fst_inr TrivSqZeroExt.fst_inr @[simp] theorem snd_inr [Zero R] (m : M) : (inr m : tsze R M).snd = m := rfl #align triv_sq_zero_ext.snd_inr TrivSqZeroExt.snd_inr @[simp] theorem fst_comp_inr [Zero R] : fst ∘ (inr : M → tsze R M) = 0 := rfl #align triv_sq_zero_ext.fst_comp_inr TrivSqZeroExt.fst_comp_inr @[simp] theorem snd_comp_inr [Zero R] : snd ∘ (inr : M → tsze R M) = id := rfl #align triv_sq_zero_ext.snd_comp_inr TrivSqZeroExt.snd_comp_inr end theorem inl_injective [Zero M] : Function.Injective (inl : R → tsze R M) := Function.LeftInverse.injective <| fst_inl _ #align triv_sq_zero_ext.inl_injective TrivSqZeroExt.inl_injective theorem inr_injective [Zero R] : Function.Injective (inr : M → tsze R M) := Function.LeftInverse.injective <| snd_inr _ #align triv_sq_zero_ext.inr_injective TrivSqZeroExt.inr_injective end Basic /-! ### Structures inherited from `Prod` Additive operators and scalar multiplication operate elementwise. -/ section Additive variable {T : Type*} {S : Type*} {R : Type u} {M : Type v} instance inhabited [Inhabited R] [Inhabited M] : Inhabited (tsze R M) := instInhabitedProd instance zero [Zero R] [Zero M] : Zero (tsze R M) := Prod.instZero instance add [Add R] [Add M] : Add (tsze R M) := Prod.instAdd instance sub [Sub R] [Sub M] : Sub (tsze R M) := Prod.instSub instance neg [Neg R] [Neg M] : Neg (tsze R M) := Prod.instNeg instance addSemigroup [AddSemigroup R] [AddSemigroup M] : AddSemigroup (tsze R M) := Prod.instAddSemigroup instance addZeroClass [AddZeroClass R] [AddZeroClass M] : AddZeroClass (tsze R M) := Prod.instAddZeroClass instance addMonoid [AddMonoid R] [AddMonoid M] : AddMonoid (tsze R M) := Prod.instAddMonoid instance addGroup [AddGroup R] [AddGroup M] : AddGroup (tsze R M) := Prod.instAddGroup instance addCommSemigroup [AddCommSemigroup R] [AddCommSemigroup M] : AddCommSemigroup (tsze R M) := Prod.instAddCommSemigroup instance addCommMonoid [AddCommMonoid R] [AddCommMonoid M] : AddCommMonoid (tsze R M) := Prod.instAddCommMonoid instance addCommGroup [AddCommGroup R] [AddCommGroup M] : AddCommGroup (tsze R M) := Prod.instAddCommGroup instance smul [SMul S R] [SMul S M] : SMul S (tsze R M) := Prod.smul instance isScalarTower [SMul T R] [SMul T M] [SMul S R] [SMul S M] [SMul T S] [IsScalarTower T S R] [IsScalarTower T S M] : IsScalarTower T S (tsze R M) := Prod.isScalarTower instance smulCommClass [SMul T R] [SMul T M] [SMul S R] [SMul S M] [SMulCommClass T S R] [SMulCommClass T S M] : SMulCommClass T S (tsze R M) := Prod.smulCommClass instance isCentralScalar [SMul S R] [SMul S M] [SMul Sᵐᵒᵖ R] [SMul Sᵐᵒᵖ M] [IsCentralScalar S R] [IsCentralScalar S M] : IsCentralScalar S (tsze R M) := Prod.isCentralScalar instance mulAction [Monoid S] [MulAction S R] [MulAction S M] : MulAction S (tsze R M) := Prod.mulAction instance distribMulAction [Monoid S] [AddMonoid R] [AddMonoid M] [DistribMulAction S R] [DistribMulAction S M] : DistribMulAction S (tsze R M) := Prod.distribMulAction instance module [Semiring S] [AddCommMonoid R] [AddCommMonoid M] [Module S R] [Module S M] : Module S (tsze R M) := Prod.instModule @[simp] theorem fst_zero [Zero R] [Zero M] : (0 : tsze R M).fst = 0 := rfl #align triv_sq_zero_ext.fst_zero TrivSqZeroExt.fst_zero @[simp] theorem snd_zero [Zero R] [Zero M] : (0 : tsze R M).snd = 0 := rfl #align triv_sq_zero_ext.snd_zero TrivSqZeroExt.snd_zero @[simp] theorem fst_add [Add R] [Add M] (x₁ x₂ : tsze R M) : (x₁ + x₂).fst = x₁.fst + x₂.fst := rfl #align triv_sq_zero_ext.fst_add TrivSqZeroExt.fst_add @[simp] theorem snd_add [Add R] [Add M] (x₁ x₂ : tsze R M) : (x₁ + x₂).snd = x₁.snd + x₂.snd := rfl #align triv_sq_zero_ext.snd_add TrivSqZeroExt.snd_add @[simp] theorem fst_neg [Neg R] [Neg M] (x : tsze R M) : (-x).fst = -x.fst := rfl #align triv_sq_zero_ext.fst_neg TrivSqZeroExt.fst_neg @[simp] theorem snd_neg [Neg R] [Neg M] (x : tsze R M) : (-x).snd = -x.snd := rfl #align triv_sq_zero_ext.snd_neg TrivSqZeroExt.snd_neg @[simp] theorem fst_sub [Sub R] [Sub M] (x₁ x₂ : tsze R M) : (x₁ - x₂).fst = x₁.fst - x₂.fst := rfl #align triv_sq_zero_ext.fst_sub TrivSqZeroExt.fst_sub @[simp] theorem snd_sub [Sub R] [Sub M] (x₁ x₂ : tsze R M) : (x₁ - x₂).snd = x₁.snd - x₂.snd := rfl #align triv_sq_zero_ext.snd_sub TrivSqZeroExt.snd_sub @[simp] theorem fst_smul [SMul S R] [SMul S M] (s : S) (x : tsze R M) : (s • x).fst = s • x.fst := rfl #align triv_sq_zero_ext.fst_smul TrivSqZeroExt.fst_smul @[simp] theorem snd_smul [SMul S R] [SMul S M] (s : S) (x : tsze R M) : (s • x).snd = s • x.snd := rfl #align triv_sq_zero_ext.snd_smul TrivSqZeroExt.snd_smul theorem fst_sum {ι} [AddCommMonoid R] [AddCommMonoid M] (s : Finset ι) (f : ι → tsze R M) : (∑ i ∈ s, f i).fst = ∑ i ∈ s, (f i).fst := Prod.fst_sum #align triv_sq_zero_ext.fst_sum TrivSqZeroExt.fst_sum theorem snd_sum {ι} [AddCommMonoid R] [AddCommMonoid M] (s : Finset ι) (f : ι → tsze R M) : (∑ i ∈ s, f i).snd = ∑ i ∈ s, (f i).snd := Prod.snd_sum #align triv_sq_zero_ext.snd_sum TrivSqZeroExt.snd_sum section variable (M) @[simp] theorem inl_zero [Zero R] [Zero M] : (inl 0 : tsze R M) = 0 := rfl #align triv_sq_zero_ext.inl_zero TrivSqZeroExt.inl_zero @[simp] theorem inl_add [Add R] [AddZeroClass M] (r₁ r₂ : R) : (inl (r₁ + r₂) : tsze R M) = inl r₁ + inl r₂ := ext rfl (add_zero 0).symm #align triv_sq_zero_ext.inl_add TrivSqZeroExt.inl_add @[simp] theorem inl_neg [Neg R] [SubNegZeroMonoid M] (r : R) : (inl (-r) : tsze R M) = -inl r := ext rfl neg_zero.symm #align triv_sq_zero_ext.inl_neg TrivSqZeroExt.inl_neg @[simp] theorem inl_sub [Sub R] [SubNegZeroMonoid M] (r₁ r₂ : R) : (inl (r₁ - r₂) : tsze R M) = inl r₁ - inl r₂ := ext rfl (sub_zero _).symm #align triv_sq_zero_ext.inl_sub TrivSqZeroExt.inl_sub @[simp] theorem inl_smul [Monoid S] [AddMonoid M] [SMul S R] [DistribMulAction S M] (s : S) (r : R) : (inl (s • r) : tsze R M) = s • inl r := ext rfl (smul_zero s).symm #align triv_sq_zero_ext.inl_smul TrivSqZeroExt.inl_smul theorem inl_sum {ι} [AddCommMonoid R] [AddCommMonoid M] (s : Finset ι) (f : ι → R) : (inl (∑ i ∈ s, f i) : tsze R M) = ∑ i ∈ s, inl (f i) := map_sum (LinearMap.inl ℕ _ _) _ _ #align triv_sq_zero_ext.inl_sum TrivSqZeroExt.inl_sum end section variable (R) @[simp] theorem inr_zero [Zero R] [Zero M] : (inr 0 : tsze R M) = 0 := rfl #align triv_sq_zero_ext.inr_zero TrivSqZeroExt.inr_zero @[simp] theorem inr_add [AddZeroClass R] [AddZeroClass M] (m₁ m₂ : M) : (inr (m₁ + m₂) : tsze R M) = inr m₁ + inr m₂ := ext (add_zero 0).symm rfl #align triv_sq_zero_ext.inr_add TrivSqZeroExt.inr_add @[simp] theorem inr_neg [SubNegZeroMonoid R] [Neg M] (m : M) : (inr (-m) : tsze R M) = -inr m := ext neg_zero.symm rfl #align triv_sq_zero_ext.inr_neg TrivSqZeroExt.inr_neg @[simp] theorem inr_sub [SubNegZeroMonoid R] [Sub M] (m₁ m₂ : M) : (inr (m₁ - m₂) : tsze R M) = inr m₁ - inr m₂ := ext (sub_zero _).symm rfl #align triv_sq_zero_ext.inr_sub TrivSqZeroExt.inr_sub @[simp] theorem inr_smul [Zero R] [Zero S] [SMulWithZero S R] [SMul S M] (r : S) (m : M) : (inr (r • m) : tsze R M) = r • inr m := ext (smul_zero _).symm rfl #align triv_sq_zero_ext.inr_smul TrivSqZeroExt.inr_smul theorem inr_sum {ι} [AddCommMonoid R] [AddCommMonoid M] (s : Finset ι) (f : ι → M) : (inr (∑ i ∈ s, f i) : tsze R M) = ∑ i ∈ s, inr (f i) := map_sum (LinearMap.inr ℕ _ _) _ _ #align triv_sq_zero_ext.inr_sum TrivSqZeroExt.inr_sum end theorem inl_fst_add_inr_snd_eq [AddZeroClass R] [AddZeroClass M] (x : tsze R M) : inl x.fst + inr x.snd = x := ext (add_zero x.1) (zero_add x.2) #align triv_sq_zero_ext.inl_fst_add_inr_snd_eq TrivSqZeroExt.inl_fst_add_inr_snd_eq /-- To show a property hold on all `TrivSqZeroExt R M` it suffices to show it holds on terms of the form `inl r + inr m`. -/ @[elab_as_elim, induction_eliminator, cases_eliminator] theorem ind {R M} [AddZeroClass R] [AddZeroClass M] {P : TrivSqZeroExt R M → Prop} (inl_add_inr : ∀ r m, P (inl r + inr m)) (x) : P x := inl_fst_add_inr_snd_eq x ▸ inl_add_inr x.1 x.2 #align triv_sq_zero_ext.ind TrivSqZeroExt.ind /-- This cannot be marked `@[ext]` as it ends up being used instead of `LinearMap.prod_ext` when working with `R × M`. -/ theorem linearMap_ext {N} [Semiring S] [AddCommMonoid R] [AddCommMonoid M] [AddCommMonoid N] [Module S R] [Module S M] [Module S N] ⦃f g : tsze R M →ₗ[S] N⦄ (hl : ∀ r, f (inl r) = g (inl r)) (hr : ∀ m, f (inr m) = g (inr m)) : f = g := LinearMap.prod_ext (LinearMap.ext hl) (LinearMap.ext hr) #align triv_sq_zero_ext.linear_map_ext TrivSqZeroExt.linearMap_ext variable (R M) /-- The canonical `R`-linear inclusion `M → TrivSqZeroExt R M`. -/ @[simps apply] def inrHom [Semiring R] [AddCommMonoid M] [Module R M] : M →ₗ[R] tsze R M := { LinearMap.inr R R M with toFun := inr } #align triv_sq_zero_ext.inr_hom TrivSqZeroExt.inrHom /-- The canonical `R`-linear projection `TrivSqZeroExt R M → M`. -/ @[simps apply] def sndHom [Semiring R] [AddCommMonoid M] [Module R M] : tsze R M →ₗ[R] M := { LinearMap.snd _ _ _ with toFun := snd } #align triv_sq_zero_ext.snd_hom TrivSqZeroExt.sndHom end Additive /-! ### Multiplicative structure -/ section Mul variable {R : Type u} {M : Type v} instance one [One R] [Zero M] : One (tsze R M) := ⟨(1, 0)⟩ instance mul [Mul R] [Add M] [SMul R M] [SMul Rᵐᵒᵖ M] : Mul (tsze R M) := ⟨fun x y => (x.1 * y.1, x.1 •> y.2 + x.2 <• y.1)⟩ @[simp] theorem fst_one [One R] [Zero M] : (1 : tsze R M).fst = 1 := rfl #align triv_sq_zero_ext.fst_one TrivSqZeroExt.fst_one @[simp] theorem snd_one [One R] [Zero M] : (1 : tsze R M).snd = 0 := rfl #align triv_sq_zero_ext.snd_one TrivSqZeroExt.snd_one @[simp] theorem fst_mul [Mul R] [Add M] [SMul R M] [SMul Rᵐᵒᵖ M] (x₁ x₂ : tsze R M) : (x₁ * x₂).fst = x₁.fst * x₂.fst := rfl #align triv_sq_zero_ext.fst_mul TrivSqZeroExt.fst_mul @[simp] theorem snd_mul [Mul R] [Add M] [SMul R M] [SMul Rᵐᵒᵖ M] (x₁ x₂ : tsze R M) : (x₁ * x₂).snd = x₁.fst •> x₂.snd + x₁.snd <• x₂.fst := rfl #align triv_sq_zero_ext.snd_mul TrivSqZeroExt.snd_mul section variable (M) @[simp] theorem inl_one [One R] [Zero M] : (inl 1 : tsze R M) = 1 := rfl #align triv_sq_zero_ext.inl_one TrivSqZeroExt.inl_one @[simp] theorem inl_mul [Monoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M] (r₁ r₂ : R) : (inl (r₁ * r₂) : tsze R M) = inl r₁ * inl r₂ := ext rfl <| show (0 : M) = r₁ •> (0 : M) + (0 : M) <• r₂ by rw [smul_zero, zero_add, smul_zero] #align triv_sq_zero_ext.inl_mul TrivSqZeroExt.inl_mul theorem inl_mul_inl [Monoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M] (r₁ r₂ : R) : (inl r₁ * inl r₂ : tsze R M) = inl (r₁ * r₂) := (inl_mul M r₁ r₂).symm #align triv_sq_zero_ext.inl_mul_inl TrivSqZeroExt.inl_mul_inl end section variable (R) @[simp] theorem inr_mul_inr [Semiring R] [AddCommMonoid M] [Module R M] [Module Rᵐᵒᵖ M] (m₁ m₂ : M) : (inr m₁ * inr m₂ : tsze R M) = 0 := ext (mul_zero _) <| show (0 : R) •> m₂ + m₁ <• (0 : R) = 0 by rw [zero_smul, zero_add, op_zero, zero_smul] #align triv_sq_zero_ext.inr_mul_inr TrivSqZeroExt.inr_mul_inr end theorem inl_mul_inr [Semiring R] [AddCommMonoid M] [Module R M] [Module Rᵐᵒᵖ M] (r : R) (m : M) : (inl r * inr m : tsze R M) = inr (r • m) := ext (mul_zero r) <| show r • m + (0 : Rᵐᵒᵖ) • (0 : M) = r • m by rw [smul_zero, add_zero] #align triv_sq_zero_ext.inl_mul_inr TrivSqZeroExt.inl_mul_inr theorem inr_mul_inl [Semiring R] [AddCommMonoid M] [Module R M] [Module Rᵐᵒᵖ M] (r : R) (m : M) : (inr m * inl r : tsze R M) = inr (m <• r) := ext (zero_mul r) <| show (0 : R) •> (0 : M) + m <• r = m <• r by rw [smul_zero, zero_add] #align triv_sq_zero_ext.inr_mul_inl TrivSqZeroExt.inr_mul_inl theorem inl_mul_eq_smul [Semiring R] [AddCommMonoid M] [Module R M] [Module Rᵐᵒᵖ M] (r : R) (x : tsze R M) : inl r * x = r •> x := ext rfl (by dsimp; rw [smul_zero, add_zero]) theorem mul_inl_eq_op_smul [Semiring R] [AddCommMonoid M] [Module R M] [Module Rᵐᵒᵖ M] (x : tsze R M) (r : R) : x * inl r = x <• r := ext rfl (by dsimp; rw [smul_zero, zero_add]) instance mulOneClass [Monoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M] : MulOneClass (tsze R M) := { TrivSqZeroExt.one, TrivSqZeroExt.mul with one_mul := fun x => ext (one_mul x.1) <| show (1 : R) •> x.2 + (0 : M) <• x.1 = x.2 by rw [one_smul, smul_zero, add_zero] mul_one := fun x => ext (mul_one x.1) <| show x.1 • (0 : M) + x.2 <• (1 : R) = x.2 by rw [smul_zero, zero_add, op_one, one_smul] } instance addMonoidWithOne [AddMonoidWithOne R] [AddMonoid M] : AddMonoidWithOne (tsze R M) := { TrivSqZeroExt.addMonoid, TrivSqZeroExt.one with natCast := fun n => inl n natCast_zero := by simp [Nat.cast] natCast_succ := fun _ => by ext <;> simp [Nat.cast] } @[simp] theorem fst_natCast [AddMonoidWithOne R] [AddMonoid M] (n : ℕ) : (n : tsze R M).fst = n := rfl #align triv_sq_zero_ext.fst_nat_cast TrivSqZeroExt.fst_natCast @[deprecated (since := "2024-04-17")] alias fst_nat_cast := fst_natCast @[simp] theorem snd_natCast [AddMonoidWithOne R] [AddMonoid M] (n : ℕ) : (n : tsze R M).snd = 0 := rfl #align triv_sq_zero_ext.snd_nat_cast TrivSqZeroExt.snd_natCast @[deprecated (since := "2024-04-17")] alias snd_nat_cast := snd_natCast @[simp] theorem inl_natCast [AddMonoidWithOne R] [AddMonoid M] (n : ℕ) : (inl n : tsze R M) = n := rfl #align triv_sq_zero_ext.inl_nat_cast TrivSqZeroExt.inl_natCast @[deprecated (since := "2024-04-17")] alias inl_nat_cast := inl_natCast instance addGroupWithOne [AddGroupWithOne R] [AddGroup M] : AddGroupWithOne (tsze R M) := { TrivSqZeroExt.addGroup, TrivSqZeroExt.addMonoidWithOne with intCast := fun z => inl z intCast_ofNat := fun _n => ext (Int.cast_natCast _) rfl intCast_negSucc := fun _n => ext (Int.cast_negSucc _) neg_zero.symm } @[simp] theorem fst_intCast [AddGroupWithOne R] [AddGroup M] (z : ℤ) : (z : tsze R M).fst = z := rfl #align triv_sq_zero_ext.fst_int_cast TrivSqZeroExt.fst_intCast @[deprecated (since := "2024-04-17")] alias fst_int_cast := fst_intCast @[simp] theorem snd_intCast [AddGroupWithOne R] [AddGroup M] (z : ℤ) : (z : tsze R M).snd = 0 := rfl #align triv_sq_zero_ext.snd_int_cast TrivSqZeroExt.snd_intCast @[deprecated (since := "2024-04-17")] alias snd_int_cast := snd_intCast @[simp] theorem inl_intCast [AddGroupWithOne R] [AddGroup M] (z : ℤ) : (inl z : tsze R M) = z := rfl #align triv_sq_zero_ext.inl_int_cast TrivSqZeroExt.inl_intCast @[deprecated (since := "2024-04-17")] alias inl_int_cast := inl_intCast instance nonAssocSemiring [Semiring R] [AddCommMonoid M] [Module R M] [Module Rᵐᵒᵖ M] : NonAssocSemiring (tsze R M) := { TrivSqZeroExt.addMonoidWithOne, TrivSqZeroExt.mulOneClass, TrivSqZeroExt.addCommMonoid with zero_mul := fun x => ext (zero_mul x.1) <| show (0 : R) •> x.2 + (0 : M) <• x.1 = 0 by rw [zero_smul, zero_add, smul_zero] mul_zero := fun x => ext (mul_zero x.1) <| show x.1 • (0 : M) + (0 : Rᵐᵒᵖ) • x.2 = 0 by rw [smul_zero, zero_add, zero_smul] left_distrib := fun x₁ x₂ x₃ => ext (mul_add x₁.1 x₂.1 x₃.1) <| show x₁.1 •> (x₂.2 + x₃.2) + x₁.2 <• (x₂.1 + x₃.1) = x₁.1 •> x₂.2 + x₁.2 <• x₂.1 + (x₁.1 •> x₃.2 + x₁.2 <• x₃.1) by simp_rw [smul_add, MulOpposite.op_add, add_smul, add_add_add_comm] right_distrib := fun x₁ x₂ x₃ => ext (add_mul x₁.1 x₂.1 x₃.1) <| show (x₁.1 + x₂.1) •> x₃.2 + (x₁.2 + x₂.2) <• x₃.1 = x₁.1 •> x₃.2 + x₁.2 <• x₃.1 + (x₂.1 •> x₃.2 + x₂.2 <• x₃.1) by simp_rw [add_smul, smul_add, add_add_add_comm] } instance nonAssocRing [Ring R] [AddCommGroup M] [Module R M] [Module Rᵐᵒᵖ M] : NonAssocRing (tsze R M) := { TrivSqZeroExt.addGroupWithOne, TrivSqZeroExt.nonAssocSemiring with } /-- In the general non-commutative case, the power operator is $$\begin{align} (r + m)^n &= r^n + r^{n-1}m + r^{n-2}mr + \cdots + rmr^{n-2} + mr^{n-1} \\ & =r^n + \sum_{i = 0}^{n - 1} r^{(n - 1) - i} m r^{i} \end{align}$$ In the commutative case this becomes the simpler $(r + m)^n = r^n + nr^{n-1}m$. -/ instance [Monoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M] : Pow (tsze R M) ℕ := ⟨fun x n => ⟨x.fst ^ n, ((List.range n).map fun i => x.fst ^ (n.pred - i) •> x.snd <• x.fst ^ i).sum⟩⟩ @[simp] theorem fst_pow [Monoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M] (x : tsze R M) (n : ℕ) : fst (x ^ n) = x.fst ^ n := rfl #align triv_sq_zero_ext.fst_pow TrivSqZeroExt.fst_pow theorem snd_pow_eq_sum [Monoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M] (x : tsze R M) (n : ℕ) : snd (x ^ n) = ((List.range n).map fun i => x.fst ^ (n.pred - i) •> x.snd <• x.fst ^ i).sum := rfl #align triv_sq_zero_ext.snd_pow_eq_sum TrivSqZeroExt.snd_pow_eq_sum theorem snd_pow_of_smul_comm [Monoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M] [SMulCommClass R Rᵐᵒᵖ M] (x : tsze R M) (n : ℕ) (h : x.snd <• x.fst = x.fst •> x.snd) : snd (x ^ n) = n • x.fst ^ n.pred •> x.snd := by simp_rw [snd_pow_eq_sum, ← smul_comm (_ : R) (_ : Rᵐᵒᵖ), aux, smul_smul, ← pow_add] match n with | 0 => rw [Nat.pred_zero, pow_zero, List.range_zero, zero_smul, List.map_nil, List.sum_nil] | (Nat.succ n) => simp_rw [Nat.pred_succ] refine (List.sum_eq_card_nsmul _ (x.fst ^ n • x.snd) ?_).trans ?_ · rintro m hm simp_rw [List.mem_map, List.mem_range] at hm obtain ⟨i, hi, rfl⟩ := hm rw [tsub_add_cancel_of_le (Nat.lt_succ_iff.mp hi)] · rw [List.length_map, List.length_range] where aux : ∀ n : ℕ, x.snd <• x.fst ^ n = x.fst ^ n •> x.snd := by intro n induction' n with n ih · simp · rw [pow_succ, op_mul, mul_smul, mul_smul, ← h, smul_comm (_ : R) (op x.fst) x.snd, ih] #align triv_sq_zero_ext.snd_pow_of_smul_comm TrivSqZeroExt.snd_pow_of_smul_comm theorem snd_pow_of_smul_comm' [Monoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M] [SMulCommClass R Rᵐᵒᵖ M] (x : tsze R M) (n : ℕ) (h : x.snd <• x.fst = x.fst •> x.snd) : snd (x ^ n) = n • (x.snd <• x.fst ^ n.pred) := by rw [snd_pow_of_smul_comm _ _ h, snd_pow_of_smul_comm.aux _ h] @[simp] theorem snd_pow [CommMonoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M] [IsCentralScalar R M] (x : tsze R M) (n : ℕ) : snd (x ^ n) = n • x.fst ^ n.pred • x.snd := snd_pow_of_smul_comm _ _ (op_smul_eq_smul _ _) #align triv_sq_zero_ext.snd_pow TrivSqZeroExt.snd_pow @[simp] theorem inl_pow [Monoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M] (r : R) (n : ℕ) : (inl r ^ n : tsze R M) = inl (r ^ n) := ext rfl <| by simp [snd_pow_eq_sum] #align triv_sq_zero_ext.inl_pow TrivSqZeroExt.inl_pow instance monoid [Monoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M] [SMulCommClass R Rᵐᵒᵖ M] : Monoid (tsze R M) := { TrivSqZeroExt.mulOneClass with mul_assoc := fun x y z => ext (mul_assoc x.1 y.1 z.1) <| show (x.1 * y.1) •> z.2 + (x.1 •> y.2 + x.2 <• y.1) <• z.1 = x.1 •> (y.1 •> z.2 + y.2 <• z.1) + x.2 <• (y.1 * z.1) by simp_rw [smul_add, ← mul_smul, add_assoc, smul_comm, op_mul] npow := fun n x => x ^ n npow_zero := fun x => ext (pow_zero x.fst) (by simp [snd_pow_eq_sum]) npow_succ := fun n x => ext (pow_succ _ _) (by simp_rw [snd_mul, snd_pow_eq_sum, Nat.pred_succ] cases n · simp [List.range_succ] rw [List.sum_range_succ'] simp only [pow_zero, op_one, tsub_zero, one_smul, Nat.succ_sub_succ_eq_sub, fst_pow, Nat.pred_succ, List.smul_sum, List.map_map, Function.comp] simp_rw [← smul_comm (_ : R) (_ : Rᵐᵒᵖ), smul_smul, pow_succ] rfl) } theorem fst_list_prod [Monoid R] [AddMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M] [SMulCommClass R Rᵐᵒᵖ M] (l : List (tsze R M)) : l.prod.fst = (l.map fst).prod := map_list_prod ({ toFun := fst, map_one' := fst_one, map_mul' := fst_mul } : tsze R M →* R) _ #align triv_sq_zero_ext.fst_list_prod TrivSqZeroExt.fst_list_prod instance semiring [Semiring R] [AddCommMonoid M] [Module R M] [Module Rᵐᵒᵖ M] [SMulCommClass R Rᵐᵒᵖ M] : Semiring (tsze R M) := { TrivSqZeroExt.monoid, TrivSqZeroExt.nonAssocSemiring with } /-- The second element of a product $\prod_{i=0}^n (r_i + m_i)$ is a sum of terms of the form $r_0\cdots r_{i-1}m_ir_{i+1}\cdots r_n$. -/ theorem snd_list_prod [Semiring R] [AddCommMonoid M] [Module R M] [Module Rᵐᵒᵖ M] [SMulCommClass R Rᵐᵒᵖ M] (l : List (tsze R M)) : l.prod.snd = (l.enum.map fun x : ℕ × tsze R M => ((l.map fst).take x.1).prod •> x.snd.snd <• ((l.map fst).drop x.1.succ).prod).sum := by induction' l with x xs ih · simp · rw [List.enum_cons, ← List.map_fst_add_enum_eq_enumFrom] simp_rw [List.map_cons, List.map_map, Function.comp, Prod.map_snd, Prod.map_fst, id, List.take_zero, List.take_cons, List.prod_nil, List.prod_cons, snd_mul, one_smul, List.drop, mul_smul, List.sum_cons, fst_list_prod, ih, List.smul_sum, List.map_map, ← smul_comm (_ : R) (_ : Rᵐᵒᵖ)] exact add_comm _ _ #align triv_sq_zero_ext.snd_list_prod TrivSqZeroExt.snd_list_prod instance ring [Ring R] [AddCommGroup M] [Module R M] [Module Rᵐᵒᵖ M] [SMulCommClass R Rᵐᵒᵖ M] : Ring (tsze R M) := { TrivSqZeroExt.semiring, TrivSqZeroExt.nonAssocRing with } instance commMonoid [CommMonoid R] [AddCommMonoid M] [DistribMulAction R M] [DistribMulAction Rᵐᵒᵖ M] [IsCentralScalar R M] : CommMonoid (tsze R M) := { TrivSqZeroExt.monoid with mul_comm := fun x₁ x₂ => ext (mul_comm x₁.1 x₂.1) <| show x₁.1 •> x₂.2 + x₁.2 <• x₂.1 = x₂.1 •> x₁.2 + x₂.2 <• x₁.1 by rw [op_smul_eq_smul, op_smul_eq_smul, add_comm] } instance commSemiring [CommSemiring R] [AddCommMonoid M] [Module R M] [Module Rᵐᵒᵖ M] [IsCentralScalar R M] : CommSemiring (tsze R M) := { TrivSqZeroExt.commMonoid, TrivSqZeroExt.nonAssocSemiring with } instance commRing [CommRing R] [AddCommGroup M] [Module R M] [Module Rᵐᵒᵖ M] [IsCentralScalar R M] : CommRing (tsze R M) := { TrivSqZeroExt.nonAssocRing, TrivSqZeroExt.commSemiring with } variable (R M) /-- The canonical inclusion of rings `R → TrivSqZeroExt R M`. -/ @[simps apply] def inlHom [Semiring R] [AddCommMonoid M] [Module R M] [Module Rᵐᵒᵖ M] : R →+* tsze R M where toFun := inl map_one' := inl_one M map_mul' := inl_mul M map_zero' := inl_zero M map_add' := inl_add M #align triv_sq_zero_ext.inl_hom TrivSqZeroExt.inlHom end Mul section Inv variable {R : Type u} {M : Type v} variable [Neg M] [Inv R] [SMul Rᵐᵒᵖ M] [SMul R M] /-- Inversion of the trivial-square-zero extension, sending $r + m$ to $r^{-1} - r^{-1}mr^{-1}$. -/ instance instInv : Inv (tsze R M) := ⟨fun b => (b.1⁻¹, -(b.1⁻¹ •> b.2 <• b.1⁻¹))⟩ @[simp] theorem fst_inv (x : tsze R M) : fst x⁻¹ = (fst x)⁻¹ := rfl @[simp] theorem snd_inv (x : tsze R M) : snd x⁻¹ = -((fst x)⁻¹ •> snd x <• (fst x)⁻¹) := rfl end Inv section DivisionSemiring variable {R : Type u} {M : Type v} variable [DivisionSemiring R] [AddCommGroup M] [Module Rᵐᵒᵖ M] [Module R M] [SMulCommClass R Rᵐᵒᵖ M] protected theorem inv_inl (r : R) : (inl r)⁻¹ = (inl (r⁻¹ : R) : tsze R M) := by ext · rw [fst_inv, fst_inl, fst_inl] · rw [snd_inv, fst_inl, snd_inl, snd_inl, smul_zero, smul_zero, neg_zero] @[simp] theorem inv_inr (m : M) : (inr m)⁻¹ = (0 : tsze R M) := by ext · rw [fst_inv, fst_inr, fst_zero, inv_zero] · rw [snd_inv, snd_inr, fst_inr, inv_zero, op_zero, zero_smul, snd_zero, neg_zero] @[simp] protected theorem inv_zero : (0 : tsze R M)⁻¹ = (0 : tsze R M) := by rw [← inl_zero, TrivSqZeroExt.inv_inl, inv_zero] @[simp] protected theorem inv_one : (1 : tsze R M)⁻¹ = (1 : tsze R M) := by rw [← inl_one, TrivSqZeroExt.inv_inl, inv_one] protected theorem mul_inv_cancel {x : tsze R M} (hx : fst x ≠ 0) : x * x⁻¹ = 1 := by ext · rw [fst_mul, fst_inv, fst_one, mul_inv_cancel hx] · rw [snd_mul, snd_inv, snd_one, smul_neg, smul_comm, smul_smul, mul_inv_cancel hx, one_smul, fst_inv, add_left_neg] protected theorem inv_mul_cancel {x : tsze R M} (hx : fst x ≠ 0) : x⁻¹ * x = 1 := by ext · rw [fst_mul, fst_inv, inv_mul_cancel hx, fst_one] · rw [snd_mul, snd_inv, snd_one, smul_neg, op_smul_op_smul, inv_mul_cancel hx, op_one, one_smul, fst_inv, add_right_neg] protected theorem mul_inv_rev (a b : tsze R M) : (a * b)⁻¹ = b⁻¹ * a⁻¹ := by ext · rw [fst_inv, fst_mul, fst_mul, mul_inv_rev, fst_inv, fst_inv] · simp only [snd_inv, snd_mul, fst_mul, fst_inv] simp only [neg_smul, smul_neg, smul_add] simp_rw [mul_inv_rev, smul_comm (_ : R), op_smul_op_smul, smul_smul, add_comm, neg_add] obtain ha0 | ha := eq_or_ne (fst a) 0 · simp [ha0] obtain hb0 | hb := eq_or_ne (fst b) 0 · simp [hb0] rw [inv_mul_cancel_right₀ ha, mul_inv_cancel_left₀ hb] protected theorem inv_inv {x : tsze R M} (hx : fst x ≠ 0) : x⁻¹⁻¹ = x := -- adapted from `Matrix.nonsing_inv_nonsing_inv` calc x⁻¹⁻¹ = 1 * x⁻¹⁻¹ := by rw [one_mul] _ = x * x⁻¹ * x⁻¹⁻¹ := by rw [TrivSqZeroExt.mul_inv_cancel hx] _ = x := by rw [mul_assoc, TrivSqZeroExt.mul_inv_cancel, mul_one] rw [fst_inv] apply inv_ne_zero hx end DivisionSemiring section DivisionRing variable {R : Type u} {M : Type v} variable [DivisionRing R] [AddCommGroup M] [Module Rᵐᵒᵖ M] [Module R M] [SMulCommClass R Rᵐᵒᵖ M] protected theorem inv_neg {x : tsze R M} : (-x)⁻¹ = -(x⁻¹) := by ext <;> simp [inv_neg] end DivisionRing section Algebra variable (S : Type*) (R R' : Type u) (M : Type v) variable [CommSemiring S] [Semiring R] [CommSemiring R'] [AddCommMonoid M] variable [Algebra S R] [Algebra S R'] [Module S M] variable [Module R M] [Module Rᵐᵒᵖ M] [SMulCommClass R Rᵐᵒᵖ M] variable [IsScalarTower S R M] [IsScalarTower S Rᵐᵒᵖ M] variable [Module R' M] [Module R'ᵐᵒᵖ M] [IsCentralScalar R' M] [IsScalarTower S R' M] instance algebra' : Algebra S (tsze R M) := { (TrivSqZeroExt.inlHom R M).comp (algebraMap S R) with smul := (· • ·) commutes' := fun s x => ext (Algebra.commutes _ _) <| show algebraMap S R s •> x.snd + (0 : M) <• x.fst = x.fst •> (0 : M) + x.snd <• algebraMap S R s by rw [smul_zero, smul_zero, add_zero, zero_add] rw [Algebra.algebraMap_eq_smul_one, MulOpposite.op_smul, op_one, smul_assoc, one_smul, smul_assoc, one_smul] smul_def' := fun s x => ext (Algebra.smul_def _ _) <| show s • x.snd = algebraMap S R s •> x.snd + (0 : M) <• x.fst by rw [smul_zero, add_zero, algebraMap_smul] } #align triv_sq_zero_ext.algebra' TrivSqZeroExt.algebra' -- shortcut instance for the common case instance : Algebra R' (tsze R' M) := TrivSqZeroExt.algebra' _ _ _ theorem algebraMap_eq_inl : ⇑(algebraMap R' (tsze R' M)) = inl := rfl #align triv_sq_zero_ext.algebra_map_eq_inl TrivSqZeroExt.algebraMap_eq_inl theorem algebraMap_eq_inlHom : algebraMap R' (tsze R' M) = inlHom R' M := rfl #align triv_sq_zero_ext.algebra_map_eq_inl_hom TrivSqZeroExt.algebraMap_eq_inlHom theorem algebraMap_eq_inl' (s : S) : algebraMap S (tsze R M) s = inl (algebraMap S R s) := rfl #align triv_sq_zero_ext.algebra_map_eq_inl' TrivSqZeroExt.algebraMap_eq_inl' /-- The canonical `S`-algebra projection `TrivSqZeroExt R M → R`. -/ @[simps] def fstHom : tsze R M →ₐ[S] R where toFun := fst map_one' := fst_one map_mul' := fst_mul map_zero' := fst_zero (M := M) map_add' := fst_add commutes' _r := fst_inl M _ #align triv_sq_zero_ext.fst_hom TrivSqZeroExt.fstHom /-- The canonical `S`-algebra inclusion `R → TrivSqZeroExt R M`. -/ @[simps] def inlAlgHom : R →ₐ[S] tsze R M where toFun := inl map_one' := inl_one _ map_mul' := inl_mul _ map_zero' := inl_zero (M := M) map_add' := inl_add _ commutes' _r := (algebraMap_eq_inl' _ _ _ _).symm variable {R R' S M} theorem algHom_ext {A} [Semiring A] [Algebra R' A] ⦃f g : tsze R' M →ₐ[R'] A⦄ (h : ∀ m, f (inr m) = g (inr m)) : f = g := AlgHom.toLinearMap_injective <| linearMap_ext (fun _r => (f.commutes _).trans (g.commutes _).symm) h #align triv_sq_zero_ext.alg_hom_ext TrivSqZeroExt.algHom_ext @[ext] theorem algHom_ext' {A} [Semiring A] [Algebra S A] ⦃f g : tsze R M →ₐ[S] A⦄ (hinl : f.comp (inlAlgHom S R M) = g.comp (inlAlgHom S R M)) (hinr : f.toLinearMap.comp (inrHom R M |>.restrictScalars S) = g.toLinearMap.comp (inrHom R M |>.restrictScalars S)) : f = g := AlgHom.toLinearMap_injective <| linearMap_ext (AlgHom.congr_fun hinl) (LinearMap.congr_fun hinr) #align triv_sq_zero_ext.alg_hom_ext' TrivSqZeroExt.algHom_ext' variable {A : Type*} [Semiring A] [Algebra S A] [Algebra R' A] /-- Assemble an algebra morphism `TrivSqZeroExt R M →ₐ[S] A` from separate morphisms on `R` and `M`. Namely, we require that for an algebra morphism `f : R →ₐ[S] A` and a linear map `g : M →ₗ[S] A`, we have: * `g x * g y = 0`: the elements of `M` continue to square to zero. * `g (r •> x) = f r * g x` and `g (x <• r) = g x * f r`: scalar multiplication on the left and right is sent to left- and right- multiplication by the image under `f`. See `TrivSqZeroExt.liftEquiv` for this as an equiv; namely that any such algebra morphism can be factored in this way. When `R` is commutative, this can be invoked with `f = Algebra.ofId R A`, which satisfies `hfg` and `hgf`. This version is captured as an equiv by `TrivSqZeroExt.liftEquivOfComm`. -/ def lift (f : R →ₐ[S] A) (g : M →ₗ[S] A) (hg : ∀ x y, g x * g y = 0) (hfg : ∀ r x, g (r •> x) = f r * g x) (hgf : ∀ r x, g (x <• r) = g x * f r) : tsze R M →ₐ[S] A := AlgHom.ofLinearMap ((f.comp <| fstHom S R M).toLinearMap + g ∘ₗ (sndHom R M |>.restrictScalars S)) (show f 1 + g (0 : M) = 1 by rw [map_zero, map_one, add_zero]) (TrivSqZeroExt.ind fun r₁ m₁ => TrivSqZeroExt.ind fun r₂ m₂ => by dsimp simp only [add_zero, zero_add, add_mul, mul_add, smul_mul_smul, hg, smul_zero, op_smul_eq_smul] rw [← AlgHom.map_mul, LinearMap.map_add, add_comm (g _), add_assoc, hfg, hgf]) #align triv_sq_zero_ext.lift_aux TrivSqZeroExt.lift theorem lift_def (f : R →ₐ[S] A) (g : M →ₗ[S] A) (hg : ∀ x y, g x * g y = 0) (hfg : ∀ r x, g (r • x) = f r * g x) (hgf : ∀ r x, g (op r • x) = g x * f r) (x : tsze R M) : lift f g hg hfg hgf x = f x.fst + g x.snd := rfl @[simp] theorem lift_apply_inl (f : R →ₐ[S] A) (g : M →ₗ[S] A) (hg : ∀ x y, g x * g y = 0) (hfg : ∀ r x, g (r •> x) = f r * g x) (hgf : ∀ r x, g (x <• r) = g x * f r) (r : R) : lift f g hg hfg hgf (inl r) = f r := show f r + g 0 = f r by rw [map_zero, add_zero] @[simp] theorem lift_apply_inr (f : R →ₐ[S] A) (g : M →ₗ[S] A) (hg : ∀ x y, g x * g y = 0) (hfg : ∀ r x, g (r •> x) = f r * g x) (hgf : ∀ r x, g (x <• r) = g x * f r) (m : M) : lift f g hg hfg hgf (inr m) = g m := show f 0 + g m = g m by rw [map_zero, zero_add] #align triv_sq_zero_ext.lift_aux_apply_inr TrivSqZeroExt.lift_apply_inr @[simp] theorem lift_comp_inlHom (f : R →ₐ[S] A) (g : M →ₗ[S] A) (hg : ∀ x y, g x * g y = 0) (hfg : ∀ r x, g (r •> x) = f r * g x) (hgf : ∀ r x, g (x <• r) = g x * f r) : (lift f g hg hfg hgf).comp (inlAlgHom S R M) = f := AlgHom.ext <| lift_apply_inl f g hg hfg hgf @[simp] theorem lift_comp_inrHom (f : R →ₐ[S] A) (g : M →ₗ[S] A) (hg : ∀ x y, g x * g y = 0) (hfg : ∀ r x, g (r •> x) = f r * g x) (hgf : ∀ r x, g (x <• r) = g x * f r) : (lift f g hg hfg hgf).toLinearMap.comp (inrHom R M |>.restrictScalars S) = g := LinearMap.ext <| lift_apply_inr f g hg hfg hgf #align triv_sq_zero_ext.lift_aux_comp_inr_hom TrivSqZeroExt.lift_comp_inrHom /-- When applied to `inr` and `inl` themselves, `lift` is the identity. -/ @[simp] theorem lift_inlAlgHom_inrHom : lift (inlAlgHom _ _ _) (inrHom R M |>.restrictScalars S) (inr_mul_inr R) (fun _ _ => (inl_mul_inr _ _).symm) (fun _ _ => (inr_mul_inl _ _).symm) = AlgHom.id S (tsze R M) := algHom_ext' (lift_comp_inlHom _ _ _ _ _) (lift_comp_inrHom _ _ _ _ _) #align triv_sq_zero_ext.lift_aux_inr_hom TrivSqZeroExt.lift_inlAlgHom_inrHomₓ /-- A universal property of the trivial square-zero extension, providing a unique `TrivSqZeroExt R M →ₐ[R] A` for every pair of maps `f : R →ₐ[S] A` and `g : M →ₗ[S] A`, where the range of `g` has no non-zero products, and scaling the input to `g` on the left or right amounts to a corresponding multiplication by `f` in the output. This isomorphism is named to match the very similar `Complex.lift`. -/ @[simps! apply symm_apply_coe] def liftEquiv : {fg : (R →ₐ[S] A) × (M →ₗ[S] A) // (∀ x y, fg.2 x * fg.2 y = 0) ∧ (∀ r x, fg.2 (r •> x) = fg.1 r * fg.2 x) ∧ (∀ r x, fg.2 (x <• r) = fg.2 x * fg.1 r)} ≃ (tsze R M →ₐ[S] A) where toFun fg := lift fg.val.1 fg.val.2 fg.prop.1 fg.prop.2.1 fg.prop.2.2 invFun F := ⟨(F.comp (inlAlgHom _ _ _), F.toLinearMap ∘ₗ (inrHom _ _ |>.restrictScalars _)), (fun _x _y => (F.map_mul _ _).symm.trans <| (F.congr_arg <| inr_mul_inr _ _ _).trans F.map_zero), (fun _r _x => (F.congr_arg (inl_mul_inr _ _).symm).trans (F.map_mul _ _)), (fun _r _x => (F.congr_arg (inr_mul_inl _ _).symm).trans (F.map_mul _ _))⟩ left_inv _f := Subtype.ext <| Prod.ext (lift_comp_inlHom _ _ _ _ _) (lift_comp_inrHom _ _ _ _ _) right_inv _F := algHom_ext' (lift_comp_inlHom _ _ _ _ _) (lift_comp_inrHom _ _ _ _ _) /-- A simplified version of `TrivSqZeroExt.liftEquiv` for the commutative case. -/ @[simps! apply symm_apply_coe] def liftEquivOfComm : { f : M →ₗ[R'] A // ∀ x y, f x * f y = 0 } ≃ (tsze R' M →ₐ[R'] A) := by refine Equiv.trans ?_ liftEquiv exact { toFun := fun f => ⟨(Algebra.ofId _ _, f.val), f.prop, fun r x => by simp [Algebra.smul_def, Algebra.ofId_apply], fun r x => by simp [Algebra.smul_def, Algebra.ofId_apply, Algebra.commutes]⟩ invFun := fun fg => ⟨fg.val.2, fg.prop.1⟩ left_inv := fun f => rfl right_inv := fun fg => Subtype.ext <| Prod.ext (AlgHom.toLinearMap_injective <| LinearMap.ext_ring <| by simp) rfl } #align triv_sq_zero_ext.lift TrivSqZeroExt.liftEquiv section map variable {N P : Type*} [AddCommMonoid N] [Module R' N] [Module R'ᵐᵒᵖ N] [IsCentralScalar R' N] [AddCommMonoid P] [Module R' P] [Module R'ᵐᵒᵖ P] [IsCentralScalar R' P] /-- Functoriality of `TrivSqZeroExt` when the ring is commutative: a linear map `f : M →ₗ[R'] N` induces a morphism of `R'`-algebras from `TrivSqZeroExt R' M` to `TrivSqZeroExt R' N`. Note that we cannot neatly state the non-commutative case, as we do not have morphisms of bimodules. -/ def map (f : M →ₗ[R'] N) : TrivSqZeroExt R' M →ₐ[R'] TrivSqZeroExt R' N := liftEquivOfComm ⟨inrHom R' N ∘ₗ f, fun _ _ => inr_mul_inr _ _ _⟩ @[simp] theorem map_inl (f : M →ₗ[R'] N) (r : R') : map f (inl r) = inl r := by rw [map, liftEquivOfComm_apply, lift_apply_inl, Algebra.ofId_apply, algebraMap_eq_inl] @[simp] theorem map_inr (f : M →ₗ[R'] N) (x : M) : map f (inr x) = inr (f x) := by rw [map, liftEquivOfComm_apply, lift_apply_inr, LinearMap.comp_apply, inrHom_apply] @[simp] theorem fst_map (f : M →ₗ[R'] N) (x : TrivSqZeroExt R' M) : fst (map f x) = fst x := by simp [map, lift_def, Algebra.ofId_apply, algebraMap_eq_inl] @[simp]
Mathlib/Algebra/TrivSqZeroExt.lean
1,074
1,075
theorem snd_map (f : M →ₗ[R'] N) (x : TrivSqZeroExt R' M) : snd (map f x) = f (snd x) := by
simp [map, lift_def, Algebra.ofId_apply, algebraMap_eq_inl]
/- Copyright (c) 2020 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.Algebra.NeZero import Mathlib.Algebra.Polynomial.BigOperators import Mathlib.Algebra.Polynomial.Lifts import Mathlib.Algebra.Polynomial.Splits import Mathlib.RingTheory.RootsOfUnity.Complex import Mathlib.NumberTheory.ArithmeticFunction import Mathlib.RingTheory.RootsOfUnity.Basic import Mathlib.FieldTheory.RatFunc.AsPolynomial #align_import ring_theory.polynomial.cyclotomic.basic from "leanprover-community/mathlib"@"7fdeecc0d03cd40f7a165e6cf00a4d2286db599f" /-! # Cyclotomic polynomials. For `n : ℕ` and an integral domain `R`, we define a modified version of the `n`-th cyclotomic polynomial with coefficients in `R`, denoted `cyclotomic' n R`, as `∏ (X - μ)`, where `μ` varies over the primitive `n`th roots of unity. If there is a primitive `n`th root of unity in `R` then this the standard definition. We then define the standard cyclotomic polynomial `cyclotomic n R` with coefficients in any ring `R`. ## Main definition * `cyclotomic n R` : the `n`-th cyclotomic polynomial with coefficients in `R`. ## Main results * `Polynomial.degree_cyclotomic` : The degree of `cyclotomic n` is `totient n`. * `Polynomial.prod_cyclotomic_eq_X_pow_sub_one` : `X ^ n - 1 = ∏ (cyclotomic i)`, where `i` divides `n`. * `Polynomial.cyclotomic_eq_prod_X_pow_sub_one_pow_moebius` : The Möbius inversion formula for `cyclotomic n R` over an abstract fraction field for `R[X]`. ## Implementation details Our definition of `cyclotomic' n R` makes sense in any integral domain `R`, but the interesting results hold if there is a primitive `n`-th root of unity in `R`. In particular, our definition is not the standard one unless there is a primitive `n`th root of unity in `R`. For example, `cyclotomic' 3 ℤ = 1`, since there are no primitive cube roots of unity in `ℤ`. The main example is `R = ℂ`, we decided to work in general since the difficulties are essentially the same. To get the standard cyclotomic polynomials, we use `unique_int_coeff_of_cycl`, with `R = ℂ`, to get a polynomial with integer coefficients and then we map it to `R[X]`, for any ring `R`. -/ open scoped Polynomial noncomputable section universe u namespace Polynomial section Cyclotomic' section IsDomain variable {R : Type*} [CommRing R] [IsDomain R] /-- The modified `n`-th cyclotomic polynomial with coefficients in `R`, it is the usual cyclotomic polynomial if there is a primitive `n`-th root of unity in `R`. -/ def cyclotomic' (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : R[X] := ∏ μ ∈ primitiveRoots n R, (X - C μ) #align polynomial.cyclotomic' Polynomial.cyclotomic' /-- The zeroth modified cyclotomic polyomial is `1`. -/ @[simp] theorem cyclotomic'_zero (R : Type*) [CommRing R] [IsDomain R] : cyclotomic' 0 R = 1 := by simp only [cyclotomic', Finset.prod_empty, primitiveRoots_zero] #align polynomial.cyclotomic'_zero Polynomial.cyclotomic'_zero /-- The first modified cyclotomic polyomial is `X - 1`. -/ @[simp] theorem cyclotomic'_one (R : Type*) [CommRing R] [IsDomain R] : cyclotomic' 1 R = X - 1 := by simp only [cyclotomic', Finset.prod_singleton, RingHom.map_one, IsPrimitiveRoot.primitiveRoots_one] #align polynomial.cyclotomic'_one Polynomial.cyclotomic'_one /-- The second modified cyclotomic polyomial is `X + 1` if the characteristic of `R` is not `2`. -/ @[simp] theorem cyclotomic'_two (R : Type*) [CommRing R] [IsDomain R] (p : ℕ) [CharP R p] (hp : p ≠ 2) : cyclotomic' 2 R = X + 1 := by rw [cyclotomic'] have prim_root_two : primitiveRoots 2 R = {(-1 : R)} := by simp only [Finset.eq_singleton_iff_unique_mem, mem_primitiveRoots two_pos] exact ⟨IsPrimitiveRoot.neg_one p hp, fun x => IsPrimitiveRoot.eq_neg_one_of_two_right⟩ simp only [prim_root_two, Finset.prod_singleton, RingHom.map_neg, RingHom.map_one, sub_neg_eq_add] #align polynomial.cyclotomic'_two Polynomial.cyclotomic'_two /-- `cyclotomic' n R` is monic. -/ theorem cyclotomic'.monic (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : (cyclotomic' n R).Monic := monic_prod_of_monic _ _ fun _ _ => monic_X_sub_C _ #align polynomial.cyclotomic'.monic Polynomial.cyclotomic'.monic /-- `cyclotomic' n R` is different from `0`. -/ theorem cyclotomic'_ne_zero (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : cyclotomic' n R ≠ 0 := (cyclotomic'.monic n R).ne_zero #align polynomial.cyclotomic'_ne_zero Polynomial.cyclotomic'_ne_zero /-- The natural degree of `cyclotomic' n R` is `totient n` if there is a primitive root of unity in `R`. -/ theorem natDegree_cyclotomic' {ζ : R} {n : ℕ} (h : IsPrimitiveRoot ζ n) : (cyclotomic' n R).natDegree = Nat.totient n := by rw [cyclotomic'] rw [natDegree_prod (primitiveRoots n R) fun z : R => X - C z] · simp only [IsPrimitiveRoot.card_primitiveRoots h, mul_one, natDegree_X_sub_C, Nat.cast_id, Finset.sum_const, nsmul_eq_mul] intro z _ exact X_sub_C_ne_zero z #align polynomial.nat_degree_cyclotomic' Polynomial.natDegree_cyclotomic' /-- The degree of `cyclotomic' n R` is `totient n` if there is a primitive root of unity in `R`. -/ theorem degree_cyclotomic' {ζ : R} {n : ℕ} (h : IsPrimitiveRoot ζ n) : (cyclotomic' n R).degree = Nat.totient n := by simp only [degree_eq_natDegree (cyclotomic'_ne_zero n R), natDegree_cyclotomic' h] #align polynomial.degree_cyclotomic' Polynomial.degree_cyclotomic' /-- The roots of `cyclotomic' n R` are the primitive `n`-th roots of unity. -/ theorem roots_of_cyclotomic (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : (cyclotomic' n R).roots = (primitiveRoots n R).val := by rw [cyclotomic']; exact roots_prod_X_sub_C (primitiveRoots n R) #align polynomial.roots_of_cyclotomic Polynomial.roots_of_cyclotomic /-- If there is a primitive `n`th root of unity in `K`, then `X ^ n - 1 = ∏ (X - μ)`, where `μ` varies over the `n`-th roots of unity. -/ theorem X_pow_sub_one_eq_prod {ζ : R} {n : ℕ} (hpos : 0 < n) (h : IsPrimitiveRoot ζ n) : X ^ n - 1 = ∏ ζ ∈ nthRootsFinset n R, (X - C ζ) := by classical rw [nthRootsFinset, ← Multiset.toFinset_eq (IsPrimitiveRoot.nthRoots_one_nodup h)] simp only [Finset.prod_mk, RingHom.map_one] rw [nthRoots] have hmonic : (X ^ n - C (1 : R)).Monic := monic_X_pow_sub_C (1 : R) (ne_of_lt hpos).symm symm apply prod_multiset_X_sub_C_of_monic_of_roots_card_eq hmonic rw [@natDegree_X_pow_sub_C R _ _ n 1, ← nthRoots] exact IsPrimitiveRoot.card_nthRoots_one h set_option linter.uppercaseLean3 false in #align polynomial.X_pow_sub_one_eq_prod Polynomial.X_pow_sub_one_eq_prod end IsDomain section Field variable {K : Type*} [Field K] /-- `cyclotomic' n K` splits. -/ theorem cyclotomic'_splits (n : ℕ) : Splits (RingHom.id K) (cyclotomic' n K) := by apply splits_prod (RingHom.id K) intro z _ simp only [splits_X_sub_C (RingHom.id K)] #align polynomial.cyclotomic'_splits Polynomial.cyclotomic'_splits /-- If there is a primitive `n`-th root of unity in `K`, then `X ^ n - 1` splits. -/ theorem X_pow_sub_one_splits {ζ : K} {n : ℕ} (h : IsPrimitiveRoot ζ n) : Splits (RingHom.id K) (X ^ n - C (1 : K)) := by rw [splits_iff_card_roots, ← nthRoots, IsPrimitiveRoot.card_nthRoots_one h, natDegree_X_pow_sub_C] set_option linter.uppercaseLean3 false in #align polynomial.X_pow_sub_one_splits Polynomial.X_pow_sub_one_splits /-- If there is a primitive `n`-th root of unity in `K`, then `∏ i ∈ Nat.divisors n, cyclotomic' i K = X ^ n - 1`. -/ theorem prod_cyclotomic'_eq_X_pow_sub_one {K : Type*} [CommRing K] [IsDomain K] {ζ : K} {n : ℕ} (hpos : 0 < n) (h : IsPrimitiveRoot ζ n) : ∏ i ∈ Nat.divisors n, cyclotomic' i K = X ^ n - 1 := by classical have hd : (n.divisors : Set ℕ).PairwiseDisjoint fun k => primitiveRoots k K := fun x _ y _ hne => IsPrimitiveRoot.disjoint hne simp only [X_pow_sub_one_eq_prod hpos h, cyclotomic', ← Finset.prod_biUnion hd, h.nthRoots_one_eq_biUnion_primitiveRoots] set_option linter.uppercaseLean3 false in #align polynomial.prod_cyclotomic'_eq_X_pow_sub_one Polynomial.prod_cyclotomic'_eq_X_pow_sub_one /-- If there is a primitive `n`-th root of unity in `K`, then `cyclotomic' n K = (X ^ k - 1) /ₘ (∏ i ∈ Nat.properDivisors k, cyclotomic' i K)`. -/ theorem cyclotomic'_eq_X_pow_sub_one_div {K : Type*} [CommRing K] [IsDomain K] {ζ : K} {n : ℕ} (hpos : 0 < n) (h : IsPrimitiveRoot ζ n) : cyclotomic' n K = (X ^ n - 1) /ₘ ∏ i ∈ Nat.properDivisors n, cyclotomic' i K := by rw [← prod_cyclotomic'_eq_X_pow_sub_one hpos h, ← Nat.cons_self_properDivisors hpos.ne', Finset.prod_cons] have prod_monic : (∏ i ∈ Nat.properDivisors n, cyclotomic' i K).Monic := by apply monic_prod_of_monic intro i _ exact cyclotomic'.monic i K rw [(div_modByMonic_unique (cyclotomic' n K) 0 prod_monic _).1] simp only [degree_zero, zero_add] refine ⟨by rw [mul_comm], ?_⟩ rw [bot_lt_iff_ne_bot] intro h exact Monic.ne_zero prod_monic (degree_eq_bot.1 h) set_option linter.uppercaseLean3 false in #align polynomial.cyclotomic'_eq_X_pow_sub_one_div Polynomial.cyclotomic'_eq_X_pow_sub_one_div /-- If there is a primitive `n`-th root of unity in `K`, then `cyclotomic' n K` comes from a monic polynomial with integer coefficients. -/ theorem int_coeff_of_cyclotomic' {K : Type*} [CommRing K] [IsDomain K] {ζ : K} {n : ℕ} (h : IsPrimitiveRoot ζ n) : ∃ P : ℤ[X], map (Int.castRingHom K) P = cyclotomic' n K ∧ P.degree = (cyclotomic' n K).degree ∧ P.Monic := by refine lifts_and_degree_eq_and_monic ?_ (cyclotomic'.monic n K) induction' n using Nat.strong_induction_on with k ihk generalizing ζ rcases k.eq_zero_or_pos with (rfl | hpos) · use 1 simp only [cyclotomic'_zero, coe_mapRingHom, Polynomial.map_one] let B : K[X] := ∏ i ∈ Nat.properDivisors k, cyclotomic' i K have Bmo : B.Monic := by apply monic_prod_of_monic intro i _ exact cyclotomic'.monic i K have Bint : B ∈ lifts (Int.castRingHom K) := by refine Subsemiring.prod_mem (lifts (Int.castRingHom K)) ?_ intro x hx have xsmall := (Nat.mem_properDivisors.1 hx).2 obtain ⟨d, hd⟩ := (Nat.mem_properDivisors.1 hx).1 rw [mul_comm] at hd exact ihk x xsmall (h.pow hpos hd) replace Bint := lifts_and_degree_eq_and_monic Bint Bmo obtain ⟨B₁, hB₁, _, hB₁mo⟩ := Bint let Q₁ : ℤ[X] := (X ^ k - 1) /ₘ B₁ have huniq : 0 + B * cyclotomic' k K = X ^ k - 1 ∧ (0 : K[X]).degree < B.degree := by constructor · rw [zero_add, mul_comm, ← prod_cyclotomic'_eq_X_pow_sub_one hpos h, ← Nat.cons_self_properDivisors hpos.ne', Finset.prod_cons] · simpa only [degree_zero, bot_lt_iff_ne_bot, Ne, degree_eq_bot] using Bmo.ne_zero replace huniq := div_modByMonic_unique (cyclotomic' k K) (0 : K[X]) Bmo huniq simp only [lifts, RingHom.mem_rangeS] use Q₁ rw [coe_mapRingHom, map_divByMonic (Int.castRingHom K) hB₁mo, hB₁, ← huniq.1] simp #align polynomial.int_coeff_of_cyclotomic' Polynomial.int_coeff_of_cyclotomic' /-- If `K` is of characteristic `0` and there is a primitive `n`-th root of unity in `K`, then `cyclotomic n K` comes from a unique polynomial with integer coefficients. -/ theorem unique_int_coeff_of_cycl {K : Type*} [CommRing K] [IsDomain K] [CharZero K] {ζ : K} {n : ℕ+} (h : IsPrimitiveRoot ζ n) : ∃! P : ℤ[X], map (Int.castRingHom K) P = cyclotomic' n K := by obtain ⟨P, hP⟩ := int_coeff_of_cyclotomic' h refine ⟨P, hP.1, fun Q hQ => ?_⟩ apply map_injective (Int.castRingHom K) Int.cast_injective rw [hP.1, hQ] #align polynomial.unique_int_coeff_of_cycl Polynomial.unique_int_coeff_of_cycl end Field end Cyclotomic' section Cyclotomic /-- The `n`-th cyclotomic polynomial with coefficients in `R`. -/ def cyclotomic (n : ℕ) (R : Type*) [Ring R] : R[X] := if h : n = 0 then 1 else map (Int.castRingHom R) (int_coeff_of_cyclotomic' (Complex.isPrimitiveRoot_exp n h)).choose #align polynomial.cyclotomic Polynomial.cyclotomic theorem int_cyclotomic_rw {n : ℕ} (h : n ≠ 0) : cyclotomic n ℤ = (int_coeff_of_cyclotomic' (Complex.isPrimitiveRoot_exp n h)).choose := by simp only [cyclotomic, h, dif_neg, not_false_iff] ext i simp only [coeff_map, Int.cast_id, eq_intCast] #align polynomial.int_cyclotomic_rw Polynomial.int_cyclotomic_rw /-- `cyclotomic n R` comes from `cyclotomic n ℤ`. -/ theorem map_cyclotomic_int (n : ℕ) (R : Type*) [Ring R] : map (Int.castRingHom R) (cyclotomic n ℤ) = cyclotomic n R := by by_cases hzero : n = 0 · simp only [hzero, cyclotomic, dif_pos, Polynomial.map_one] simp [cyclotomic, hzero] #align polynomial.map_cyclotomic_int Polynomial.map_cyclotomic_int theorem int_cyclotomic_spec (n : ℕ) : map (Int.castRingHom ℂ) (cyclotomic n ℤ) = cyclotomic' n ℂ ∧ (cyclotomic n ℤ).degree = (cyclotomic' n ℂ).degree ∧ (cyclotomic n ℤ).Monic := by by_cases hzero : n = 0 · simp only [hzero, cyclotomic, degree_one, monic_one, cyclotomic'_zero, dif_pos, eq_self_iff_true, Polynomial.map_one, and_self_iff] rw [int_cyclotomic_rw hzero] exact (int_coeff_of_cyclotomic' (Complex.isPrimitiveRoot_exp n hzero)).choose_spec #align polynomial.int_cyclotomic_spec Polynomial.int_cyclotomic_spec theorem int_cyclotomic_unique {n : ℕ} {P : ℤ[X]} (h : map (Int.castRingHom ℂ) P = cyclotomic' n ℂ) : P = cyclotomic n ℤ := by apply map_injective (Int.castRingHom ℂ) Int.cast_injective rw [h, (int_cyclotomic_spec n).1] #align polynomial.int_cyclotomic_unique Polynomial.int_cyclotomic_unique /-- The definition of `cyclotomic n R` commutes with any ring homomorphism. -/ @[simp] theorem map_cyclotomic (n : ℕ) {R S : Type*} [Ring R] [Ring S] (f : R →+* S) : map f (cyclotomic n R) = cyclotomic n S := by rw [← map_cyclotomic_int n R, ← map_cyclotomic_int n S, map_map] have : Subsingleton (ℤ →+* S) := inferInstance congr! #align polynomial.map_cyclotomic Polynomial.map_cyclotomic theorem cyclotomic.eval_apply {R S : Type*} (q : R) (n : ℕ) [Ring R] [Ring S] (f : R →+* S) : eval (f q) (cyclotomic n S) = f (eval q (cyclotomic n R)) := by rw [← map_cyclotomic n f, eval_map, eval₂_at_apply] #align polynomial.cyclotomic.eval_apply Polynomial.cyclotomic.eval_apply /-- The zeroth cyclotomic polyomial is `1`. -/ @[simp] theorem cyclotomic_zero (R : Type*) [Ring R] : cyclotomic 0 R = 1 := by simp only [cyclotomic, dif_pos] #align polynomial.cyclotomic_zero Polynomial.cyclotomic_zero /-- The first cyclotomic polyomial is `X - 1`. -/ @[simp] theorem cyclotomic_one (R : Type*) [Ring R] : cyclotomic 1 R = X - 1 := by have hspec : map (Int.castRingHom ℂ) (X - 1) = cyclotomic' 1 ℂ := by simp only [cyclotomic'_one, PNat.one_coe, map_X, Polynomial.map_one, Polynomial.map_sub] symm rw [← map_cyclotomic_int, ← int_cyclotomic_unique hspec] simp only [map_X, Polynomial.map_one, Polynomial.map_sub] #align polynomial.cyclotomic_one Polynomial.cyclotomic_one /-- `cyclotomic n` is monic. -/ theorem cyclotomic.monic (n : ℕ) (R : Type*) [Ring R] : (cyclotomic n R).Monic := by rw [← map_cyclotomic_int] exact (int_cyclotomic_spec n).2.2.map _ #align polynomial.cyclotomic.monic Polynomial.cyclotomic.monic /-- `cyclotomic n` is primitive. -/ theorem cyclotomic.isPrimitive (n : ℕ) (R : Type*) [CommRing R] : (cyclotomic n R).IsPrimitive := (cyclotomic.monic n R).isPrimitive #align polynomial.cyclotomic.is_primitive Polynomial.cyclotomic.isPrimitive /-- `cyclotomic n R` is different from `0`. -/ theorem cyclotomic_ne_zero (n : ℕ) (R : Type*) [Ring R] [Nontrivial R] : cyclotomic n R ≠ 0 := (cyclotomic.monic n R).ne_zero #align polynomial.cyclotomic_ne_zero Polynomial.cyclotomic_ne_zero /-- The degree of `cyclotomic n` is `totient n`. -/ theorem degree_cyclotomic (n : ℕ) (R : Type*) [Ring R] [Nontrivial R] : (cyclotomic n R).degree = Nat.totient n := by rw [← map_cyclotomic_int] rw [degree_map_eq_of_leadingCoeff_ne_zero (Int.castRingHom R) _] · cases' n with k · simp only [cyclotomic, degree_one, dif_pos, Nat.totient_zero, CharP.cast_eq_zero] rw [← degree_cyclotomic' (Complex.isPrimitiveRoot_exp k.succ (Nat.succ_ne_zero k))] exact (int_cyclotomic_spec k.succ).2.1 simp only [(int_cyclotomic_spec n).right.right, eq_intCast, Monic.leadingCoeff, Int.cast_one, Ne, not_false_iff, one_ne_zero] #align polynomial.degree_cyclotomic Polynomial.degree_cyclotomic /-- The natural degree of `cyclotomic n` is `totient n`. -/ theorem natDegree_cyclotomic (n : ℕ) (R : Type*) [Ring R] [Nontrivial R] : (cyclotomic n R).natDegree = Nat.totient n := by rw [natDegree, degree_cyclotomic]; norm_cast #align polynomial.nat_degree_cyclotomic Polynomial.natDegree_cyclotomic /-- The degree of `cyclotomic n R` is positive. -/ theorem degree_cyclotomic_pos (n : ℕ) (R : Type*) (hpos : 0 < n) [Ring R] [Nontrivial R] : 0 < (cyclotomic n R).degree := by rwa [degree_cyclotomic n R, Nat.cast_pos, Nat.totient_pos] #align polynomial.degree_cyclotomic_pos Polynomial.degree_cyclotomic_pos open Finset /-- `∏ i ∈ Nat.divisors n, cyclotomic i R = X ^ n - 1`. -/ theorem prod_cyclotomic_eq_X_pow_sub_one {n : ℕ} (hpos : 0 < n) (R : Type*) [CommRing R] : ∏ i ∈ Nat.divisors n, cyclotomic i R = X ^ n - 1 := by have integer : ∏ i ∈ Nat.divisors n, cyclotomic i ℤ = X ^ n - 1 := by apply map_injective (Int.castRingHom ℂ) Int.cast_injective simp only [Polynomial.map_prod, int_cyclotomic_spec, Polynomial.map_pow, map_X, Polynomial.map_one, Polynomial.map_sub] exact prod_cyclotomic'_eq_X_pow_sub_one hpos (Complex.isPrimitiveRoot_exp n hpos.ne') simpa only [Polynomial.map_prod, map_cyclotomic_int, Polynomial.map_sub, Polynomial.map_one, Polynomial.map_pow, Polynomial.map_X] using congr_arg (map (Int.castRingHom R)) integer set_option linter.uppercaseLean3 false in #align polynomial.prod_cyclotomic_eq_X_pow_sub_one Polynomial.prod_cyclotomic_eq_X_pow_sub_one theorem cyclotomic.dvd_X_pow_sub_one (n : ℕ) (R : Type*) [Ring R] : cyclotomic n R ∣ X ^ n - 1 := by suffices cyclotomic n ℤ ∣ X ^ n - 1 by simpa only [map_cyclotomic_int, Polynomial.map_sub, Polynomial.map_one, Polynomial.map_pow, Polynomial.map_X] using map_dvd (Int.castRingHom R) this rcases n.eq_zero_or_pos with (rfl | hn) · simp rw [← prod_cyclotomic_eq_X_pow_sub_one hn] exact Finset.dvd_prod_of_mem _ (n.mem_divisors_self hn.ne') set_option linter.uppercaseLean3 false in #align polynomial.cyclotomic.dvd_X_pow_sub_one Polynomial.cyclotomic.dvd_X_pow_sub_one theorem prod_cyclotomic_eq_geom_sum {n : ℕ} (h : 0 < n) (R) [CommRing R] : ∏ i ∈ n.divisors.erase 1, cyclotomic i R = ∑ i ∈ Finset.range n, X ^ i := by suffices (∏ i ∈ n.divisors.erase 1, cyclotomic i ℤ) = ∑ i ∈ Finset.range n, X ^ i by simpa only [Polynomial.map_prod, map_cyclotomic_int, Polynomial.map_sum, Polynomial.map_pow, Polynomial.map_X] using congr_arg (map (Int.castRingHom R)) this rw [← mul_left_inj' (cyclotomic_ne_zero 1 ℤ), prod_erase_mul _ _ (Nat.one_mem_divisors.2 h.ne'), cyclotomic_one, geom_sum_mul, prod_cyclotomic_eq_X_pow_sub_one h] #align polynomial.prod_cyclotomic_eq_geom_sum Polynomial.prod_cyclotomic_eq_geom_sum /-- If `p` is prime, then `cyclotomic p R = ∑ i ∈ range p, X ^ i`. -/ theorem cyclotomic_prime (R : Type*) [Ring R] (p : ℕ) [hp : Fact p.Prime] : cyclotomic p R = ∑ i ∈ Finset.range p, X ^ i := by suffices cyclotomic p ℤ = ∑ i ∈ range p, X ^ i by simpa only [map_cyclotomic_int, Polynomial.map_sum, Polynomial.map_pow, Polynomial.map_X] using congr_arg (map (Int.castRingHom R)) this rw [← prod_cyclotomic_eq_geom_sum hp.out.pos, hp.out.divisors, erase_insert (mem_singleton.not.2 hp.out.ne_one.symm), prod_singleton] #align polynomial.cyclotomic_prime Polynomial.cyclotomic_prime theorem cyclotomic_prime_mul_X_sub_one (R : Type*) [Ring R] (p : ℕ) [hn : Fact (Nat.Prime p)] : cyclotomic p R * (X - 1) = X ^ p - 1 := by rw [cyclotomic_prime, geom_sum_mul] set_option linter.uppercaseLean3 false in #align polynomial.cyclotomic_prime_mul_X_sub_one Polynomial.cyclotomic_prime_mul_X_sub_one @[simp] theorem cyclotomic_two (R : Type*) [Ring R] : cyclotomic 2 R = X + 1 := by simp [cyclotomic_prime] #align polynomial.cyclotomic_two Polynomial.cyclotomic_two @[simp] theorem cyclotomic_three (R : Type*) [Ring R] : cyclotomic 3 R = X ^ 2 + X + 1 := by simp [cyclotomic_prime, sum_range_succ'] #align polynomial.cyclotomic_three Polynomial.cyclotomic_three theorem cyclotomic_dvd_geom_sum_of_dvd (R) [Ring R] {d n : ℕ} (hdn : d ∣ n) (hd : d ≠ 1) : cyclotomic d R ∣ ∑ i ∈ Finset.range n, X ^ i := by suffices cyclotomic d ℤ ∣ ∑ i ∈ Finset.range n, X ^ i by simpa only [map_cyclotomic_int, Polynomial.map_sum, Polynomial.map_pow, Polynomial.map_X] using map_dvd (Int.castRingHom R) this rcases n.eq_zero_or_pos with (rfl | hn) · simp rw [← prod_cyclotomic_eq_geom_sum hn] apply Finset.dvd_prod_of_mem simp [hd, hdn, hn.ne'] #align polynomial.cyclotomic_dvd_geom_sum_of_dvd Polynomial.cyclotomic_dvd_geom_sum_of_dvd theorem X_pow_sub_one_mul_prod_cyclotomic_eq_X_pow_sub_one_of_dvd (R) [CommRing R] {d n : ℕ} (h : d ∈ n.properDivisors) : ((X ^ d - 1) * ∏ x ∈ n.divisors \ d.divisors, cyclotomic x R) = X ^ n - 1 := by obtain ⟨hd, hdn⟩ := Nat.mem_properDivisors.mp h have h0n : 0 < n := pos_of_gt hdn have h0d : 0 < d := Nat.pos_of_dvd_of_pos hd h0n rw [← prod_cyclotomic_eq_X_pow_sub_one h0d, ← prod_cyclotomic_eq_X_pow_sub_one h0n, mul_comm, Finset.prod_sdiff (Nat.divisors_subset_of_dvd h0n.ne' hd)] set_option linter.uppercaseLean3 false in #align polynomial.X_pow_sub_one_mul_prod_cyclotomic_eq_X_pow_sub_one_of_dvd Polynomial.X_pow_sub_one_mul_prod_cyclotomic_eq_X_pow_sub_one_of_dvd theorem X_pow_sub_one_mul_cyclotomic_dvd_X_pow_sub_one_of_dvd (R) [CommRing R] {d n : ℕ} (h : d ∈ n.properDivisors) : (X ^ d - 1) * cyclotomic n R ∣ X ^ n - 1 := by have hdn := (Nat.mem_properDivisors.mp h).2 use ∏ x ∈ n.properDivisors \ d.divisors, cyclotomic x R symm convert X_pow_sub_one_mul_prod_cyclotomic_eq_X_pow_sub_one_of_dvd R h using 1 rw [mul_assoc] congr 1 rw [← Nat.insert_self_properDivisors hdn.ne_bot, insert_sdiff_of_not_mem, prod_insert] · exact Finset.not_mem_sdiff_of_not_mem_left Nat.properDivisors.not_self_mem · exact fun hk => hdn.not_le <| Nat.divisor_le hk set_option linter.uppercaseLean3 false in #align polynomial.X_pow_sub_one_mul_cyclotomic_dvd_X_pow_sub_one_of_dvd Polynomial.X_pow_sub_one_mul_cyclotomic_dvd_X_pow_sub_one_of_dvd section ArithmeticFunction open ArithmeticFunction open scoped ArithmeticFunction /-- `cyclotomic n R` can be expressed as a product in a fraction field of `R[X]` using Möbius inversion. -/ theorem cyclotomic_eq_prod_X_pow_sub_one_pow_moebius {n : ℕ} (R : Type*) [CommRing R] [IsDomain R] : algebraMap _ (RatFunc R) (cyclotomic n R) = ∏ i ∈ n.divisorsAntidiagonal, algebraMap R[X] _ (X ^ i.snd - 1) ^ μ i.fst := by rcases n.eq_zero_or_pos with (rfl | hpos) · simp have h : ∀ n : ℕ, 0 < n → (∏ i ∈ Nat.divisors n, algebraMap _ (RatFunc R) (cyclotomic i R)) = algebraMap _ _ (X ^ n - 1 : R[X]) := by intro n hn rw [← prod_cyclotomic_eq_X_pow_sub_one hn R, map_prod] rw [(prod_eq_iff_prod_pow_moebius_eq_of_nonzero (fun n hn => _) fun n hn => _).1 h n hpos] <;> simp_rw [Ne, IsFractionRing.to_map_eq_zero_iff] · simp [cyclotomic_ne_zero] · intro n hn apply Monic.ne_zero apply monic_X_pow_sub_C _ (ne_of_gt hn) set_option linter.uppercaseLean3 false in #align polynomial.cyclotomic_eq_prod_X_pow_sub_one_pow_moebius Polynomial.cyclotomic_eq_prod_X_pow_sub_one_pow_moebius end ArithmeticFunction /-- We have `cyclotomic n R = (X ^ k - 1) /ₘ (∏ i ∈ Nat.properDivisors k, cyclotomic i K)`. -/ theorem cyclotomic_eq_X_pow_sub_one_div {R : Type*} [CommRing R] {n : ℕ} (hpos : 0 < n) : cyclotomic n R = (X ^ n - 1) /ₘ ∏ i ∈ Nat.properDivisors n, cyclotomic i R := by nontriviality R rw [← prod_cyclotomic_eq_X_pow_sub_one hpos, ← Nat.cons_self_properDivisors hpos.ne', Finset.prod_cons] have prod_monic : (∏ i ∈ Nat.properDivisors n, cyclotomic i R).Monic := by apply monic_prod_of_monic intro i _ exact cyclotomic.monic i R rw [(div_modByMonic_unique (cyclotomic n R) 0 prod_monic _).1] simp only [degree_zero, zero_add] constructor · rw [mul_comm] rw [bot_lt_iff_ne_bot] intro h exact Monic.ne_zero prod_monic (degree_eq_bot.1 h) set_option linter.uppercaseLean3 false in #align polynomial.cyclotomic_eq_X_pow_sub_one_div Polynomial.cyclotomic_eq_X_pow_sub_one_div /-- If `m` is a proper divisor of `n`, then `X ^ m - 1` divides `∏ i ∈ Nat.properDivisors n, cyclotomic i R`. -/ theorem X_pow_sub_one_dvd_prod_cyclotomic (R : Type*) [CommRing R] {n m : ℕ} (hpos : 0 < n) (hm : m ∣ n) (hdiff : m ≠ n) : X ^ m - 1 ∣ ∏ i ∈ Nat.properDivisors n, cyclotomic i R := by replace hm := Nat.mem_properDivisors.2 ⟨hm, lt_of_le_of_ne (Nat.divisor_le (Nat.mem_divisors.2 ⟨hm, hpos.ne'⟩)) hdiff⟩ rw [← Finset.sdiff_union_of_subset (Nat.divisors_subset_properDivisors (ne_of_lt hpos).symm (Nat.mem_properDivisors.1 hm).1 (ne_of_lt (Nat.mem_properDivisors.1 hm).2)), Finset.prod_union Finset.sdiff_disjoint, prod_cyclotomic_eq_X_pow_sub_one (Nat.pos_of_mem_properDivisors hm)] exact ⟨∏ x ∈ n.properDivisors \ m.divisors, cyclotomic x R, by rw [mul_comm]⟩ set_option linter.uppercaseLean3 false in #align polynomial.X_pow_sub_one_dvd_prod_cyclotomic Polynomial.X_pow_sub_one_dvd_prod_cyclotomic /-- If there is a primitive `n`-th root of unity in `K`, then `cyclotomic n K = ∏ μ ∈ primitiveRoots n K, (X - C μ)`. ∈ particular, `cyclotomic n K = cyclotomic' n K` -/ theorem cyclotomic_eq_prod_X_sub_primitiveRoots {K : Type*} [CommRing K] [IsDomain K] {ζ : K} {n : ℕ} (hz : IsPrimitiveRoot ζ n) : cyclotomic n K = ∏ μ ∈ primitiveRoots n K, (X - C μ) := by rw [← cyclotomic'] induction' n using Nat.strong_induction_on with k hk generalizing ζ obtain hzero | hpos := k.eq_zero_or_pos · simp only [hzero, cyclotomic'_zero, cyclotomic_zero] have h : ∀ i ∈ k.properDivisors, cyclotomic i K = cyclotomic' i K := by intro i hi obtain ⟨d, hd⟩ := (Nat.mem_properDivisors.1 hi).1 rw [mul_comm] at hd exact hk i (Nat.mem_properDivisors.1 hi).2 (IsPrimitiveRoot.pow hpos hz hd) rw [@cyclotomic_eq_X_pow_sub_one_div _ _ _ hpos, cyclotomic'_eq_X_pow_sub_one_div hpos hz, Finset.prod_congr (refl k.properDivisors) h] set_option linter.uppercaseLean3 false in #align polynomial.cyclotomic_eq_prod_X_sub_primitive_roots Polynomial.cyclotomic_eq_prod_X_sub_primitiveRoots theorem eq_cyclotomic_iff {R : Type*} [CommRing R] {n : ℕ} (hpos : 0 < n) (P : R[X]) : P = cyclotomic n R ↔ (P * ∏ i ∈ Nat.properDivisors n, Polynomial.cyclotomic i R) = X ^ n - 1 := by nontriviality R refine ⟨fun hcycl => ?_, fun hP => ?_⟩ · rw [hcycl, ← prod_cyclotomic_eq_X_pow_sub_one hpos R, ← Nat.cons_self_properDivisors hpos.ne', Finset.prod_cons] · have prod_monic : (∏ i ∈ Nat.properDivisors n, cyclotomic i R).Monic := by apply monic_prod_of_monic intro i _ exact cyclotomic.monic i R rw [@cyclotomic_eq_X_pow_sub_one_div R _ _ hpos, (div_modByMonic_unique P 0 prod_monic _).1] refine ⟨by rwa [zero_add, mul_comm], ?_⟩ rw [degree_zero, bot_lt_iff_ne_bot] intro h exact Monic.ne_zero prod_monic (degree_eq_bot.1 h) #align polynomial.eq_cyclotomic_iff Polynomial.eq_cyclotomic_iff /-- If `p ^ k` is a prime power, then `cyclotomic (p ^ (n + 1)) R = ∑ i ∈ range p, (X ^ (p ^ n)) ^ i`. -/ theorem cyclotomic_prime_pow_eq_geom_sum {R : Type*} [CommRing R] {p n : ℕ} (hp : p.Prime) : cyclotomic (p ^ (n + 1)) R = ∑ i ∈ Finset.range p, (X ^ p ^ n) ^ i := by have : ∀ m, (cyclotomic (p ^ (m + 1)) R = ∑ i ∈ Finset.range p, (X ^ p ^ m) ^ i) ↔ ((∑ i ∈ Finset.range p, (X ^ p ^ m) ^ i) * ∏ x ∈ Finset.range (m + 1), cyclotomic (p ^ x) R) = X ^ p ^ (m + 1) - 1 := by intro m have := eq_cyclotomic_iff (R := R) (P := ∑ i ∈ range p, (X ^ p ^ m) ^ i) (pow_pos hp.pos (m + 1)) rw [eq_comm] at this rw [this, Nat.prod_properDivisors_prime_pow hp] induction' n with n_n n_ih · haveI := Fact.mk hp; simp [cyclotomic_prime] rw [((eq_cyclotomic_iff (pow_pos hp.pos (n_n + 1 + 1)) _).mpr _).symm] rw [Nat.prod_properDivisors_prime_pow hp, Finset.prod_range_succ, n_ih] rw [this] at n_ih rw [mul_comm _ (∑ i ∈ _, _), n_ih, geom_sum_mul, sub_left_inj, ← pow_mul] simp only [pow_add, pow_one] #align polynomial.cyclotomic_prime_pow_eq_geom_sum Polynomial.cyclotomic_prime_pow_eq_geom_sum theorem cyclotomic_prime_pow_mul_X_pow_sub_one (R : Type*) [CommRing R] (p k : ℕ) [hn : Fact (Nat.Prime p)] : cyclotomic (p ^ (k + 1)) R * (X ^ p ^ k - 1) = X ^ p ^ (k + 1) - 1 := by rw [cyclotomic_prime_pow_eq_geom_sum hn.out, geom_sum_mul, ← pow_mul, pow_succ, mul_comm] set_option linter.uppercaseLean3 false in #align polynomial.cyclotomic_prime_pow_mul_X_pow_sub_one Polynomial.cyclotomic_prime_pow_mul_X_pow_sub_one /-- The constant term of `cyclotomic n R` is `1` if `2 ≤ n`. -/ theorem cyclotomic_coeff_zero (R : Type*) [CommRing R] {n : ℕ} (hn : 1 < n) : (cyclotomic n R).coeff 0 = 1 := by induction' n using Nat.strong_induction_on with n hi have hprod : (∏ i ∈ Nat.properDivisors n, (Polynomial.cyclotomic i R).coeff 0) = -1 := by rw [← Finset.insert_erase (Nat.one_mem_properDivisors_iff_one_lt.2 (lt_of_lt_of_le one_lt_two hn)), Finset.prod_insert (Finset.not_mem_erase 1 _), cyclotomic_one R] have hleq : ∀ j ∈ n.properDivisors.erase 1, 2 ≤ j := by intro j hj apply Nat.succ_le_of_lt exact (Ne.le_iff_lt (Finset.mem_erase.1 hj).1.symm).mp (Nat.succ_le_of_lt (Nat.pos_of_mem_properDivisors (Finset.mem_erase.1 hj).2)) have hcongr : ∀ j ∈ n.properDivisors.erase 1, (cyclotomic j R).coeff 0 = 1 := by intro j hj exact hi j (Nat.mem_properDivisors.1 (Finset.mem_erase.1 hj).2).2 (hleq j hj) have hrw : (∏ x ∈ n.properDivisors.erase 1, (cyclotomic x R).coeff 0) = 1 := by rw [Finset.prod_congr (refl (n.properDivisors.erase 1)) hcongr] simp only [Finset.prod_const_one] simp only [hrw, mul_one, zero_sub, coeff_one_zero, coeff_X_zero, coeff_sub] have heq : (X ^ n - 1 : R[X]).coeff 0 = -(cyclotomic n R).coeff 0 := by rw [← prod_cyclotomic_eq_X_pow_sub_one (zero_le_one.trans_lt hn), ← Nat.cons_self_properDivisors hn.ne_bot, Finset.prod_cons, mul_coeff_zero, coeff_zero_prod, hprod, mul_neg, mul_one] have hzero : (X ^ n - 1 : R[X]).coeff 0 = (-1 : R) := by rw [coeff_zero_eq_eval_zero _] simp only [zero_pow (by positivity : n ≠ 0), eval_X, eval_one, zero_sub, eval_pow, eval_sub] rw [hzero] at heq exact neg_inj.mp (Eq.symm heq) #align polynomial.cyclotomic_coeff_zero Polynomial.cyclotomic_coeff_zero /-- If `(a : ℕ)` is a root of `cyclotomic n (ZMod p)`, where `p` is a prime, then `a` and `p` are coprime. -/ theorem coprime_of_root_cyclotomic {n : ℕ} (hpos : 0 < n) {p : ℕ} [hprime : Fact p.Prime] {a : ℕ} (hroot : IsRoot (cyclotomic n (ZMod p)) (Nat.castRingHom (ZMod p) a)) : a.Coprime p := by apply Nat.Coprime.symm rw [hprime.1.coprime_iff_not_dvd] intro h replace h := (ZMod.natCast_zmod_eq_zero_iff_dvd a p).2 h rw [IsRoot.def, eq_natCast, h, ← coeff_zero_eq_eval_zero] at hroot by_cases hone : n = 1 · simp only [hone, cyclotomic_one, zero_sub, coeff_one_zero, coeff_X_zero, neg_eq_zero, one_ne_zero, coeff_sub] at hroot rw [cyclotomic_coeff_zero (ZMod p) (Nat.succ_le_of_lt (lt_of_le_of_ne (Nat.succ_le_of_lt hpos) (Ne.symm hone)))] at hroot exact one_ne_zero hroot #align polynomial.coprime_of_root_cyclotomic Polynomial.coprime_of_root_cyclotomic end Cyclotomic section Order /-- If `(a : ℕ)` is a root of `cyclotomic n (ZMod p)`, then the multiplicative order of `a` modulo `p` divides `n`. -/
Mathlib/RingTheory/Polynomial/Cyclotomic/Basic.lean
640
650
theorem orderOf_root_cyclotomic_dvd {n : ℕ} (hpos : 0 < n) {p : ℕ} [Fact p.Prime] {a : ℕ} (hroot : IsRoot (cyclotomic n (ZMod p)) (Nat.castRingHom (ZMod p) a)) : orderOf (ZMod.unitOfCoprime a (coprime_of_root_cyclotomic hpos hroot)) ∣ n := by
apply orderOf_dvd_of_pow_eq_one suffices hpow : eval (Nat.castRingHom (ZMod p) a) (X ^ n - 1 : (ZMod p)[X]) = 0 by simp only [eval_X, eval_one, eval_pow, eval_sub, eq_natCast] at hpow apply Units.val_eq_one.1 simp only [sub_eq_zero.mp hpow, ZMod.coe_unitOfCoprime, Units.val_pow_eq_pow_val] rw [IsRoot.def] at hroot rw [← prod_cyclotomic_eq_X_pow_sub_one hpos (ZMod p), ← Nat.cons_self_properDivisors hpos.ne', Finset.prod_cons, eval_mul, hroot, zero_mul]
/- 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.LinearAlgebra.Finsupp import Mathlib.RingTheory.Ideal.Over import Mathlib.RingTheory.Ideal.Prod import Mathlib.RingTheory.Ideal.MinimalPrime import Mathlib.RingTheory.Localization.Away.Basic import Mathlib.RingTheory.Nilpotent.Lemmas import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.Sober #align_import algebraic_geometry.prime_spectrum.basic from "leanprover-community/mathlib"@"a7c017d750512a352b623b1824d75da5998457d0" /-! # Prime spectrum of a commutative (semi)ring The prime spectrum of a commutative (semi)ring is the type of all prime ideals. It is naturally endowed with a topology: the Zariski topology. (It is also naturally endowed with a sheaf of rings, which is constructed in `AlgebraicGeometry.StructureSheaf`.) ## Main definitions * `PrimeSpectrum R`: The prime spectrum of a commutative (semi)ring `R`, i.e., the set of all prime ideals of `R`. * `zeroLocus s`: The zero locus of a subset `s` of `R` is the subset of `PrimeSpectrum R` consisting of all prime ideals that contain `s`. * `vanishingIdeal t`: The vanishing ideal of a subset `t` of `PrimeSpectrum R` is the intersection of points in `t` (viewed as prime ideals). ## Conventions We denote subsets of (semi)rings with `s`, `s'`, etc... whereas we denote subsets of prime spectra with `t`, `t'`, etc... ## Inspiration/contributors The contents of this file draw inspiration from <https://github.com/ramonfmir/lean-scheme> which has contributions from Ramon Fernandez Mir, Kevin Buzzard, Kenny Lau, and Chris Hughes (on an earlier repository). -/ noncomputable section open scoped Classical universe u v variable (R : Type u) (S : Type v) /-- The prime spectrum of a commutative (semi)ring `R` is the type of all prime ideals of `R`. It is naturally endowed with a topology (the Zariski topology), and a sheaf of commutative rings (see `AlgebraicGeometry.StructureSheaf`). It is a fundamental building block in algebraic geometry. -/ @[ext] structure PrimeSpectrum [CommSemiring R] where asIdeal : Ideal R IsPrime : asIdeal.IsPrime #align prime_spectrum PrimeSpectrum attribute [instance] PrimeSpectrum.IsPrime namespace PrimeSpectrum section CommSemiRing variable [CommSemiring R] [CommSemiring S] variable {R S} instance [Nontrivial R] : Nonempty <| PrimeSpectrum R := let ⟨I, hI⟩ := Ideal.exists_maximal R ⟨⟨I, hI.isPrime⟩⟩ /-- The prime spectrum of the zero ring is empty. -/ instance [Subsingleton R] : IsEmpty (PrimeSpectrum R) := ⟨fun x ↦ x.IsPrime.ne_top <| SetLike.ext' <| Subsingleton.eq_univ_of_nonempty x.asIdeal.nonempty⟩ #noalign prime_spectrum.punit variable (R S) /-- The map from the direct sum of prime spectra to the prime spectrum of a direct product. -/ @[simp] def primeSpectrumProdOfSum : Sum (PrimeSpectrum R) (PrimeSpectrum S) → PrimeSpectrum (R × S) | Sum.inl ⟨I, _⟩ => ⟨Ideal.prod I ⊤, Ideal.isPrime_ideal_prod_top⟩ | Sum.inr ⟨J, _⟩ => ⟨Ideal.prod ⊤ J, Ideal.isPrime_ideal_prod_top'⟩ #align prime_spectrum.prime_spectrum_prod_of_sum PrimeSpectrum.primeSpectrumProdOfSum /-- The prime spectrum of `R × S` is in bijection with the disjoint unions of the prime spectrum of `R` and the prime spectrum of `S`. -/ noncomputable def primeSpectrumProd : PrimeSpectrum (R × S) ≃ Sum (PrimeSpectrum R) (PrimeSpectrum S) := Equiv.symm <| Equiv.ofBijective (primeSpectrumProdOfSum R S) (by constructor · rintro (⟨I, hI⟩ | ⟨J, hJ⟩) (⟨I', hI'⟩ | ⟨J', hJ'⟩) h <;> simp only [mk.injEq, Ideal.prod.ext_iff, primeSpectrumProdOfSum] at h · simp only [h] · exact False.elim (hI.ne_top h.left) · exact False.elim (hJ.ne_top h.right) · simp only [h] · rintro ⟨I, hI⟩ rcases (Ideal.ideal_prod_prime I).mp hI with (⟨p, ⟨hp, rfl⟩⟩ | ⟨p, ⟨hp, rfl⟩⟩) · exact ⟨Sum.inl ⟨p, hp⟩, rfl⟩ · exact ⟨Sum.inr ⟨p, hp⟩, rfl⟩) #align prime_spectrum.prime_spectrum_prod PrimeSpectrum.primeSpectrumProd variable {R S} @[simp] theorem primeSpectrumProd_symm_inl_asIdeal (x : PrimeSpectrum R) : ((primeSpectrumProd R S).symm <| Sum.inl x).asIdeal = Ideal.prod x.asIdeal ⊤ := by cases x rfl #align prime_spectrum.prime_spectrum_prod_symm_inl_as_ideal PrimeSpectrum.primeSpectrumProd_symm_inl_asIdeal @[simp] theorem primeSpectrumProd_symm_inr_asIdeal (x : PrimeSpectrum S) : ((primeSpectrumProd R S).symm <| Sum.inr x).asIdeal = Ideal.prod ⊤ x.asIdeal := by cases x rfl #align prime_spectrum.prime_spectrum_prod_symm_inr_as_ideal PrimeSpectrum.primeSpectrumProd_symm_inr_asIdeal /-- The zero locus of a set `s` of elements of a commutative (semi)ring `R` is the set of all prime ideals of the ring that contain the set `s`. An element `f` of `R` can be thought of as a dependent function on the prime spectrum of `R`. At a point `x` (a prime ideal) the function (i.e., element) `f` takes values in the quotient ring `R` modulo the prime ideal `x`. In this manner, `zeroLocus s` is exactly the subset of `PrimeSpectrum R` where all "functions" in `s` vanish simultaneously. -/ def zeroLocus (s : Set R) : Set (PrimeSpectrum R) := { x | s ⊆ x.asIdeal } #align prime_spectrum.zero_locus PrimeSpectrum.zeroLocus @[simp] theorem mem_zeroLocus (x : PrimeSpectrum R) (s : Set R) : x ∈ zeroLocus s ↔ s ⊆ x.asIdeal := Iff.rfl #align prime_spectrum.mem_zero_locus PrimeSpectrum.mem_zeroLocus @[simp] theorem zeroLocus_span (s : Set R) : zeroLocus (Ideal.span s : Set R) = zeroLocus s := by ext x exact (Submodule.gi R R).gc s x.asIdeal #align prime_spectrum.zero_locus_span PrimeSpectrum.zeroLocus_span /-- The vanishing ideal of a set `t` of points of the prime spectrum of a commutative ring `R` is the intersection of all the prime ideals in the set `t`. An element `f` of `R` can be thought of as a dependent function on the prime spectrum of `R`. At a point `x` (a prime ideal) the function (i.e., element) `f` takes values in the quotient ring `R` modulo the prime ideal `x`. In this manner, `vanishingIdeal t` is exactly the ideal of `R` consisting of all "functions" that vanish on all of `t`. -/ def vanishingIdeal (t : Set (PrimeSpectrum R)) : Ideal R := ⨅ (x : PrimeSpectrum R) (_ : x ∈ t), x.asIdeal #align prime_spectrum.vanishing_ideal PrimeSpectrum.vanishingIdeal theorem coe_vanishingIdeal (t : Set (PrimeSpectrum R)) : (vanishingIdeal t : Set R) = { f : R | ∀ x : PrimeSpectrum R, x ∈ t → f ∈ x.asIdeal } := by ext f rw [vanishingIdeal, SetLike.mem_coe, Submodule.mem_iInf] apply forall_congr'; intro x rw [Submodule.mem_iInf] #align prime_spectrum.coe_vanishing_ideal PrimeSpectrum.coe_vanishingIdeal theorem mem_vanishingIdeal (t : Set (PrimeSpectrum R)) (f : R) : f ∈ vanishingIdeal t ↔ ∀ x : PrimeSpectrum R, x ∈ t → f ∈ x.asIdeal := by rw [← SetLike.mem_coe, coe_vanishingIdeal, Set.mem_setOf_eq] #align prime_spectrum.mem_vanishing_ideal PrimeSpectrum.mem_vanishingIdeal @[simp] theorem vanishingIdeal_singleton (x : PrimeSpectrum R) : vanishingIdeal ({x} : Set (PrimeSpectrum R)) = x.asIdeal := by simp [vanishingIdeal] #align prime_spectrum.vanishing_ideal_singleton PrimeSpectrum.vanishingIdeal_singleton theorem subset_zeroLocus_iff_le_vanishingIdeal (t : Set (PrimeSpectrum R)) (I : Ideal R) : t ⊆ zeroLocus I ↔ I ≤ vanishingIdeal t := ⟨fun h _ k => (mem_vanishingIdeal _ _).mpr fun _ j => (mem_zeroLocus _ _).mpr (h j) k, fun h => fun x j => (mem_zeroLocus _ _).mpr (le_trans h fun _ h => ((mem_vanishingIdeal _ _).mp h) x j)⟩ #align prime_spectrum.subset_zero_locus_iff_le_vanishing_ideal PrimeSpectrum.subset_zeroLocus_iff_le_vanishingIdeal section Gc variable (R) /-- `zeroLocus` and `vanishingIdeal` form a galois connection. -/ theorem gc : @GaloisConnection (Ideal R) (Set (PrimeSpectrum R))ᵒᵈ _ _ (fun I => zeroLocus I) fun t => vanishingIdeal t := fun I t => subset_zeroLocus_iff_le_vanishingIdeal t I #align prime_spectrum.gc PrimeSpectrum.gc /-- `zeroLocus` and `vanishingIdeal` form a galois connection. -/ theorem gc_set : @GaloisConnection (Set R) (Set (PrimeSpectrum R))ᵒᵈ _ _ (fun s => zeroLocus s) fun t => vanishingIdeal t := by have ideal_gc : GaloisConnection Ideal.span _ := (Submodule.gi R R).gc simpa [zeroLocus_span, Function.comp] using ideal_gc.compose (gc R) #align prime_spectrum.gc_set PrimeSpectrum.gc_set theorem subset_zeroLocus_iff_subset_vanishingIdeal (t : Set (PrimeSpectrum R)) (s : Set R) : t ⊆ zeroLocus s ↔ s ⊆ vanishingIdeal t := (gc_set R) s t #align prime_spectrum.subset_zero_locus_iff_subset_vanishing_ideal PrimeSpectrum.subset_zeroLocus_iff_subset_vanishingIdeal end Gc theorem subset_vanishingIdeal_zeroLocus (s : Set R) : s ⊆ vanishingIdeal (zeroLocus s) := (gc_set R).le_u_l s #align prime_spectrum.subset_vanishing_ideal_zero_locus PrimeSpectrum.subset_vanishingIdeal_zeroLocus theorem le_vanishingIdeal_zeroLocus (I : Ideal R) : I ≤ vanishingIdeal (zeroLocus I) := (gc R).le_u_l I #align prime_spectrum.le_vanishing_ideal_zero_locus PrimeSpectrum.le_vanishingIdeal_zeroLocus @[simp] theorem vanishingIdeal_zeroLocus_eq_radical (I : Ideal R) : vanishingIdeal (zeroLocus (I : Set R)) = I.radical := Ideal.ext fun f => by rw [mem_vanishingIdeal, Ideal.radical_eq_sInf, Submodule.mem_sInf] exact ⟨fun h x hx => h ⟨x, hx.2⟩ hx.1, fun h x hx => h x.1 ⟨hx, x.2⟩⟩ #align prime_spectrum.vanishing_ideal_zero_locus_eq_radical PrimeSpectrum.vanishingIdeal_zeroLocus_eq_radical @[simp] theorem zeroLocus_radical (I : Ideal R) : zeroLocus (I.radical : Set R) = zeroLocus I := vanishingIdeal_zeroLocus_eq_radical I ▸ (gc R).l_u_l_eq_l I #align prime_spectrum.zero_locus_radical PrimeSpectrum.zeroLocus_radical theorem subset_zeroLocus_vanishingIdeal (t : Set (PrimeSpectrum R)) : t ⊆ zeroLocus (vanishingIdeal t) := (gc R).l_u_le t #align prime_spectrum.subset_zero_locus_vanishing_ideal PrimeSpectrum.subset_zeroLocus_vanishingIdeal theorem zeroLocus_anti_mono {s t : Set R} (h : s ⊆ t) : zeroLocus t ⊆ zeroLocus s := (gc_set R).monotone_l h #align prime_spectrum.zero_locus_anti_mono PrimeSpectrum.zeroLocus_anti_mono theorem zeroLocus_anti_mono_ideal {s t : Ideal R} (h : s ≤ t) : zeroLocus (t : Set R) ⊆ zeroLocus (s : Set R) := (gc R).monotone_l h #align prime_spectrum.zero_locus_anti_mono_ideal PrimeSpectrum.zeroLocus_anti_mono_ideal theorem vanishingIdeal_anti_mono {s t : Set (PrimeSpectrum R)} (h : s ⊆ t) : vanishingIdeal t ≤ vanishingIdeal s := (gc R).monotone_u h #align prime_spectrum.vanishing_ideal_anti_mono PrimeSpectrum.vanishingIdeal_anti_mono theorem zeroLocus_subset_zeroLocus_iff (I J : Ideal R) : zeroLocus (I : Set R) ⊆ zeroLocus (J : Set R) ↔ J ≤ I.radical := by rw [subset_zeroLocus_iff_le_vanishingIdeal, vanishingIdeal_zeroLocus_eq_radical] #align prime_spectrum.zero_locus_subset_zero_locus_iff PrimeSpectrum.zeroLocus_subset_zeroLocus_iff theorem zeroLocus_subset_zeroLocus_singleton_iff (f g : R) : zeroLocus ({f} : Set R) ⊆ zeroLocus {g} ↔ g ∈ (Ideal.span ({f} : Set R)).radical := by rw [← zeroLocus_span {f}, ← zeroLocus_span {g}, zeroLocus_subset_zeroLocus_iff, Ideal.span_le, Set.singleton_subset_iff, SetLike.mem_coe] #align prime_spectrum.zero_locus_subset_zero_locus_singleton_iff PrimeSpectrum.zeroLocus_subset_zeroLocus_singleton_iff theorem zeroLocus_bot : zeroLocus ((⊥ : Ideal R) : Set R) = Set.univ := (gc R).l_bot #align prime_spectrum.zero_locus_bot PrimeSpectrum.zeroLocus_bot @[simp] theorem zeroLocus_singleton_zero : zeroLocus ({0} : Set R) = Set.univ := zeroLocus_bot #align prime_spectrum.zero_locus_singleton_zero PrimeSpectrum.zeroLocus_singleton_zero @[simp] theorem zeroLocus_empty : zeroLocus (∅ : Set R) = Set.univ := (gc_set R).l_bot #align prime_spectrum.zero_locus_empty PrimeSpectrum.zeroLocus_empty @[simp] theorem vanishingIdeal_univ : vanishingIdeal (∅ : Set (PrimeSpectrum R)) = ⊤ := by simpa using (gc R).u_top #align prime_spectrum.vanishing_ideal_univ PrimeSpectrum.vanishingIdeal_univ theorem zeroLocus_empty_of_one_mem {s : Set R} (h : (1 : R) ∈ s) : zeroLocus s = ∅ := by rw [Set.eq_empty_iff_forall_not_mem] intro x hx rw [mem_zeroLocus] at hx have x_prime : x.asIdeal.IsPrime := by infer_instance have eq_top : x.asIdeal = ⊤ := by rw [Ideal.eq_top_iff_one] exact hx h apply x_prime.ne_top eq_top #align prime_spectrum.zero_locus_empty_of_one_mem PrimeSpectrum.zeroLocus_empty_of_one_mem @[simp] theorem zeroLocus_singleton_one : zeroLocus ({1} : Set R) = ∅ := zeroLocus_empty_of_one_mem (Set.mem_singleton (1 : R)) #align prime_spectrum.zero_locus_singleton_one PrimeSpectrum.zeroLocus_singleton_one theorem zeroLocus_empty_iff_eq_top {I : Ideal R} : zeroLocus (I : Set R) = ∅ ↔ I = ⊤ := by constructor · contrapose! intro h rcases Ideal.exists_le_maximal I h with ⟨M, hM, hIM⟩ exact ⟨⟨M, hM.isPrime⟩, hIM⟩ · rintro rfl apply zeroLocus_empty_of_one_mem trivial #align prime_spectrum.zero_locus_empty_iff_eq_top PrimeSpectrum.zeroLocus_empty_iff_eq_top @[simp] theorem zeroLocus_univ : zeroLocus (Set.univ : Set R) = ∅ := zeroLocus_empty_of_one_mem (Set.mem_univ 1) #align prime_spectrum.zero_locus_univ PrimeSpectrum.zeroLocus_univ theorem vanishingIdeal_eq_top_iff {s : Set (PrimeSpectrum R)} : vanishingIdeal s = ⊤ ↔ s = ∅ := by rw [← top_le_iff, ← subset_zeroLocus_iff_le_vanishingIdeal, Submodule.top_coe, zeroLocus_univ, Set.subset_empty_iff] #align prime_spectrum.vanishing_ideal_eq_top_iff PrimeSpectrum.vanishingIdeal_eq_top_iff theorem zeroLocus_sup (I J : Ideal R) : zeroLocus ((I ⊔ J : Ideal R) : Set R) = zeroLocus I ∩ zeroLocus J := (gc R).l_sup #align prime_spectrum.zero_locus_sup PrimeSpectrum.zeroLocus_sup theorem zeroLocus_union (s s' : Set R) : zeroLocus (s ∪ s') = zeroLocus s ∩ zeroLocus s' := (gc_set R).l_sup #align prime_spectrum.zero_locus_union PrimeSpectrum.zeroLocus_union theorem vanishingIdeal_union (t t' : Set (PrimeSpectrum R)) : vanishingIdeal (t ∪ t') = vanishingIdeal t ⊓ vanishingIdeal t' := (gc R).u_inf #align prime_spectrum.vanishing_ideal_union PrimeSpectrum.vanishingIdeal_union theorem zeroLocus_iSup {ι : Sort*} (I : ι → Ideal R) : zeroLocus ((⨆ i, I i : Ideal R) : Set R) = ⋂ i, zeroLocus (I i) := (gc R).l_iSup #align prime_spectrum.zero_locus_supr PrimeSpectrum.zeroLocus_iSup theorem zeroLocus_iUnion {ι : Sort*} (s : ι → Set R) : zeroLocus (⋃ i, s i) = ⋂ i, zeroLocus (s i) := (gc_set R).l_iSup #align prime_spectrum.zero_locus_Union PrimeSpectrum.zeroLocus_iUnion theorem zeroLocus_bUnion (s : Set (Set R)) : zeroLocus (⋃ s' ∈ s, s' : Set R) = ⋂ s' ∈ s, zeroLocus s' := by simp only [zeroLocus_iUnion] #align prime_spectrum.zero_locus_bUnion PrimeSpectrum.zeroLocus_bUnion theorem vanishingIdeal_iUnion {ι : Sort*} (t : ι → Set (PrimeSpectrum R)) : vanishingIdeal (⋃ i, t i) = ⨅ i, vanishingIdeal (t i) := (gc R).u_iInf #align prime_spectrum.vanishing_ideal_Union PrimeSpectrum.vanishingIdeal_iUnion theorem zeroLocus_inf (I J : Ideal R) : zeroLocus ((I ⊓ J : Ideal R) : Set R) = zeroLocus I ∪ zeroLocus J := Set.ext fun x => x.2.inf_le #align prime_spectrum.zero_locus_inf PrimeSpectrum.zeroLocus_inf theorem union_zeroLocus (s s' : Set R) : zeroLocus s ∪ zeroLocus s' = zeroLocus (Ideal.span s ⊓ Ideal.span s' : Ideal R) := by rw [zeroLocus_inf] simp #align prime_spectrum.union_zero_locus PrimeSpectrum.union_zeroLocus theorem zeroLocus_mul (I J : Ideal R) : zeroLocus ((I * J : Ideal R) : Set R) = zeroLocus I ∪ zeroLocus J := Set.ext fun x => x.2.mul_le #align prime_spectrum.zero_locus_mul PrimeSpectrum.zeroLocus_mul theorem zeroLocus_singleton_mul (f g : R) : zeroLocus ({f * g} : Set R) = zeroLocus {f} ∪ zeroLocus {g} := Set.ext fun x => by simpa using x.2.mul_mem_iff_mem_or_mem #align prime_spectrum.zero_locus_singleton_mul PrimeSpectrum.zeroLocus_singleton_mul @[simp] theorem zeroLocus_pow (I : Ideal R) {n : ℕ} (hn : n ≠ 0) : zeroLocus ((I ^ n : Ideal R) : Set R) = zeroLocus I := zeroLocus_radical (I ^ n) ▸ (I.radical_pow hn).symm ▸ zeroLocus_radical I #align prime_spectrum.zero_locus_pow PrimeSpectrum.zeroLocus_pow @[simp] theorem zeroLocus_singleton_pow (f : R) (n : ℕ) (hn : 0 < n) : zeroLocus ({f ^ n} : Set R) = zeroLocus {f} := Set.ext fun x => by simpa using x.2.pow_mem_iff_mem n hn #align prime_spectrum.zero_locus_singleton_pow PrimeSpectrum.zeroLocus_singleton_pow theorem sup_vanishingIdeal_le (t t' : Set (PrimeSpectrum R)) : vanishingIdeal t ⊔ vanishingIdeal t' ≤ vanishingIdeal (t ∩ t') := by intro r rw [Submodule.mem_sup, mem_vanishingIdeal] rintro ⟨f, hf, g, hg, rfl⟩ x ⟨hxt, hxt'⟩ rw [mem_vanishingIdeal] at hf hg apply Submodule.add_mem <;> solve_by_elim #align prime_spectrum.sup_vanishing_ideal_le PrimeSpectrum.sup_vanishingIdeal_le theorem mem_compl_zeroLocus_iff_not_mem {f : R} {I : PrimeSpectrum R} : I ∈ (zeroLocus {f} : Set (PrimeSpectrum R))ᶜ ↔ f ∉ I.asIdeal := by rw [Set.mem_compl_iff, mem_zeroLocus, Set.singleton_subset_iff]; rfl #align prime_spectrum.mem_compl_zero_locus_iff_not_mem PrimeSpectrum.mem_compl_zeroLocus_iff_not_mem /-- The Zariski topology on the prime spectrum of a commutative (semi)ring is defined via the closed sets of the topology: they are exactly those sets that are the zero locus of a subset of the ring. -/ instance zariskiTopology : TopologicalSpace (PrimeSpectrum R) := TopologicalSpace.ofClosed (Set.range PrimeSpectrum.zeroLocus) ⟨Set.univ, by simp⟩ (by intro Zs h rw [Set.sInter_eq_iInter] choose f hf using fun i : Zs => h i.prop simp only [← hf] exact ⟨_, zeroLocus_iUnion _⟩) (by rintro _ ⟨s, rfl⟩ _ ⟨t, rfl⟩ exact ⟨_, (union_zeroLocus s t).symm⟩) #align prime_spectrum.zariski_topology PrimeSpectrum.zariskiTopology theorem isOpen_iff (U : Set (PrimeSpectrum R)) : IsOpen U ↔ ∃ s, Uᶜ = zeroLocus s := by simp only [@eq_comm _ Uᶜ]; rfl #align prime_spectrum.is_open_iff PrimeSpectrum.isOpen_iff theorem isClosed_iff_zeroLocus (Z : Set (PrimeSpectrum R)) : IsClosed Z ↔ ∃ s, Z = zeroLocus s := by rw [← isOpen_compl_iff, isOpen_iff, compl_compl] #align prime_spectrum.is_closed_iff_zero_locus PrimeSpectrum.isClosed_iff_zeroLocus theorem isClosed_iff_zeroLocus_ideal (Z : Set (PrimeSpectrum R)) : IsClosed Z ↔ ∃ I : Ideal R, Z = zeroLocus I := (isClosed_iff_zeroLocus _).trans ⟨fun ⟨s, hs⟩ => ⟨_, (zeroLocus_span s).substr hs⟩, fun ⟨I, hI⟩ => ⟨I, hI⟩⟩ #align prime_spectrum.is_closed_iff_zero_locus_ideal PrimeSpectrum.isClosed_iff_zeroLocus_ideal theorem isClosed_iff_zeroLocus_radical_ideal (Z : Set (PrimeSpectrum R)) : IsClosed Z ↔ ∃ I : Ideal R, I.IsRadical ∧ Z = zeroLocus I := (isClosed_iff_zeroLocus_ideal _).trans ⟨fun ⟨I, hI⟩ => ⟨_, I.radical_isRadical, (zeroLocus_radical I).substr hI⟩, fun ⟨I, _, hI⟩ => ⟨I, hI⟩⟩ #align prime_spectrum.is_closed_iff_zero_locus_radical_ideal PrimeSpectrum.isClosed_iff_zeroLocus_radical_ideal theorem isClosed_zeroLocus (s : Set R) : IsClosed (zeroLocus s) := by rw [isClosed_iff_zeroLocus] exact ⟨s, rfl⟩ #align prime_spectrum.is_closed_zero_locus PrimeSpectrum.isClosed_zeroLocus theorem zeroLocus_vanishingIdeal_eq_closure (t : Set (PrimeSpectrum R)) : zeroLocus (vanishingIdeal t : Set R) = closure t := by rcases isClosed_iff_zeroLocus (closure t) |>.mp isClosed_closure with ⟨I, hI⟩ rw [subset_antisymm_iff, (isClosed_zeroLocus _).closure_subset_iff, hI, subset_zeroLocus_iff_subset_vanishingIdeal, (gc R).u_l_u_eq_u, ← subset_zeroLocus_iff_subset_vanishingIdeal, ← hI] exact ⟨subset_closure, subset_zeroLocus_vanishingIdeal t⟩ #align prime_spectrum.zero_locus_vanishing_ideal_eq_closure PrimeSpectrum.zeroLocus_vanishingIdeal_eq_closure theorem vanishingIdeal_closure (t : Set (PrimeSpectrum R)) : vanishingIdeal (closure t) = vanishingIdeal t := zeroLocus_vanishingIdeal_eq_closure t ▸ (gc R).u_l_u_eq_u t #align prime_spectrum.vanishing_ideal_closure PrimeSpectrum.vanishingIdeal_closure theorem closure_singleton (x) : closure ({x} : Set (PrimeSpectrum R)) = zeroLocus x.asIdeal := by rw [← zeroLocus_vanishingIdeal_eq_closure, vanishingIdeal_singleton] #align prime_spectrum.closure_singleton PrimeSpectrum.closure_singleton theorem isClosed_singleton_iff_isMaximal (x : PrimeSpectrum R) : IsClosed ({x} : Set (PrimeSpectrum R)) ↔ x.asIdeal.IsMaximal := by rw [← closure_subset_iff_isClosed, ← zeroLocus_vanishingIdeal_eq_closure, vanishingIdeal_singleton] constructor <;> intro H · rcases x.asIdeal.exists_le_maximal x.2.1 with ⟨m, hm, hxm⟩ exact (congr_arg asIdeal (@H ⟨m, hm.isPrime⟩ hxm)) ▸ hm · exact fun p hp ↦ PrimeSpectrum.ext _ _ (H.eq_of_le p.2.1 hp).symm #align prime_spectrum.is_closed_singleton_iff_is_maximal PrimeSpectrum.isClosed_singleton_iff_isMaximal theorem isRadical_vanishingIdeal (s : Set (PrimeSpectrum R)) : (vanishingIdeal s).IsRadical := by rw [← vanishingIdeal_closure, ← zeroLocus_vanishingIdeal_eq_closure, vanishingIdeal_zeroLocus_eq_radical] apply Ideal.radical_isRadical #align prime_spectrum.is_radical_vanishing_ideal PrimeSpectrum.isRadical_vanishingIdeal theorem vanishingIdeal_anti_mono_iff {s t : Set (PrimeSpectrum R)} (ht : IsClosed t) : s ⊆ t ↔ vanishingIdeal t ≤ vanishingIdeal s := ⟨vanishingIdeal_anti_mono, fun h => by rw [← ht.closure_subset_iff, ← ht.closure_eq] convert ← zeroLocus_anti_mono_ideal h <;> apply zeroLocus_vanishingIdeal_eq_closure⟩ #align prime_spectrum.vanishing_ideal_anti_mono_iff PrimeSpectrum.vanishingIdeal_anti_mono_iff theorem vanishingIdeal_strict_anti_mono_iff {s t : Set (PrimeSpectrum R)} (hs : IsClosed s) (ht : IsClosed t) : s ⊂ t ↔ vanishingIdeal t < vanishingIdeal s := by rw [Set.ssubset_def, vanishingIdeal_anti_mono_iff hs, vanishingIdeal_anti_mono_iff ht, lt_iff_le_not_le] #align prime_spectrum.vanishing_ideal_strict_anti_mono_iff PrimeSpectrum.vanishingIdeal_strict_anti_mono_iff /-- The antitone order embedding of closed subsets of `Spec R` into ideals of `R`. -/ def closedsEmbedding (R : Type*) [CommSemiring R] : (TopologicalSpace.Closeds <| PrimeSpectrum R)ᵒᵈ ↪o Ideal R := OrderEmbedding.ofMapLEIff (fun s => vanishingIdeal ↑(OrderDual.ofDual s)) fun s _ => (vanishingIdeal_anti_mono_iff s.2).symm #align prime_spectrum.closeds_embedding PrimeSpectrum.closedsEmbedding theorem t1Space_iff_isField [IsDomain R] : T1Space (PrimeSpectrum R) ↔ IsField R := by refine ⟨?_, fun h => ?_⟩ · intro h have hbot : Ideal.IsPrime (⊥ : Ideal R) := Ideal.bot_prime exact Classical.not_not.1 (mt (Ring.ne_bot_of_isMaximal_of_not_isField <| (isClosed_singleton_iff_isMaximal _).1 (T1Space.t1 ⟨⊥, hbot⟩)) (by aesop)) · refine ⟨fun x => (isClosed_singleton_iff_isMaximal x).2 ?_⟩ by_cases hx : x.asIdeal = ⊥ · letI := h.toSemifield exact hx.symm ▸ Ideal.bot_isMaximal · exact absurd h (Ring.not_isField_iff_exists_prime.2 ⟨x.asIdeal, ⟨hx, x.2⟩⟩) #align prime_spectrum.t1_space_iff_is_field PrimeSpectrum.t1Space_iff_isField local notation "Z(" a ")" => zeroLocus (a : Set R) theorem isIrreducible_zeroLocus_iff_of_radical (I : Ideal R) (hI : I.IsRadical) : IsIrreducible (zeroLocus (I : Set R)) ↔ I.IsPrime := by rw [Ideal.isPrime_iff, IsIrreducible] apply and_congr · rw [Set.nonempty_iff_ne_empty, Ne, zeroLocus_empty_iff_eq_top] · trans ∀ x y : Ideal R, Z(I) ⊆ Z(x) ∪ Z(y) → Z(I) ⊆ Z(x) ∨ Z(I) ⊆ Z(y) · simp_rw [isPreirreducible_iff_closed_union_closed, isClosed_iff_zeroLocus_ideal] constructor · rintro h x y exact h _ _ ⟨x, rfl⟩ ⟨y, rfl⟩ · rintro h _ _ ⟨x, rfl⟩ ⟨y, rfl⟩ exact h x y · simp_rw [← zeroLocus_inf, subset_zeroLocus_iff_le_vanishingIdeal, vanishingIdeal_zeroLocus_eq_radical, hI.radical] constructor · simp_rw [← SetLike.mem_coe, ← Set.singleton_subset_iff, ← Ideal.span_le, ← Ideal.span_singleton_mul_span_singleton] refine fun h x y h' => h _ _ ?_ rw [← hI.radical_le_iff] at h' ⊢ simpa only [Ideal.radical_inf, Ideal.radical_mul] using h' · simp_rw [or_iff_not_imp_left, SetLike.not_le_iff_exists] rintro h s t h' ⟨x, hx, hx'⟩ y hy exact h (h' ⟨Ideal.mul_mem_right _ _ hx, Ideal.mul_mem_left _ _ hy⟩) hx' #align prime_spectrum.is_irreducible_zero_locus_iff_of_radical PrimeSpectrum.isIrreducible_zeroLocus_iff_of_radical theorem isIrreducible_zeroLocus_iff (I : Ideal R) : IsIrreducible (zeroLocus (I : Set R)) ↔ I.radical.IsPrime := zeroLocus_radical I ▸ isIrreducible_zeroLocus_iff_of_radical _ I.radical_isRadical #align prime_spectrum.is_irreducible_zero_locus_iff PrimeSpectrum.isIrreducible_zeroLocus_iff theorem isIrreducible_iff_vanishingIdeal_isPrime {s : Set (PrimeSpectrum R)} : IsIrreducible s ↔ (vanishingIdeal s).IsPrime := by rw [← isIrreducible_iff_closure, ← zeroLocus_vanishingIdeal_eq_closure, isIrreducible_zeroLocus_iff_of_radical _ (isRadical_vanishingIdeal s)] #align prime_spectrum.is_irreducible_iff_vanishing_ideal_is_prime PrimeSpectrum.isIrreducible_iff_vanishingIdeal_isPrime lemma vanishingIdeal_isIrreducible : vanishingIdeal (R := R) '' {s | IsIrreducible s} = {P | P.IsPrime} := Set.ext fun I ↦ ⟨fun ⟨_, hs, e⟩ ↦ e ▸ isIrreducible_iff_vanishingIdeal_isPrime.mp hs, fun h ↦ ⟨zeroLocus I, (isIrreducible_zeroLocus_iff_of_radical _ h.isRadical).mpr h, (vanishingIdeal_zeroLocus_eq_radical I).trans h.radical⟩⟩ lemma vanishingIdeal_isClosed_isIrreducible : vanishingIdeal (R := R) '' {s | IsClosed s ∧ IsIrreducible s} = {P | P.IsPrime} := by refine (subset_antisymm ?_ ?_).trans vanishingIdeal_isIrreducible · exact Set.image_subset _ fun _ ↦ And.right rintro _ ⟨s, hs, rfl⟩ exact ⟨closure s, ⟨isClosed_closure, hs.closure⟩, vanishingIdeal_closure s⟩ instance irreducibleSpace [IsDomain R] : IrreducibleSpace (PrimeSpectrum R) := by rw [irreducibleSpace_def, Set.top_eq_univ, ← zeroLocus_bot, isIrreducible_zeroLocus_iff] simpa using Ideal.bot_prime instance quasiSober : QuasiSober (PrimeSpectrum R) := ⟨fun {S} h₁ h₂ => ⟨⟨_, isIrreducible_iff_vanishingIdeal_isPrime.1 h₁⟩, by rw [IsGenericPoint, closure_singleton, zeroLocus_vanishingIdeal_eq_closure, h₂.closure_eq]⟩⟩ /-- The prime spectrum of a commutative (semi)ring is a compact topological space. -/ instance compactSpace : CompactSpace (PrimeSpectrum R) := by refine compactSpace_of_finite_subfamily_closed fun S S_closed S_empty ↦ ?_ choose I hI using fun i ↦ (isClosed_iff_zeroLocus_ideal (S i)).mp (S_closed i) simp_rw [hI, ← zeroLocus_iSup, zeroLocus_empty_iff_eq_top, ← top_le_iff] at S_empty ⊢ exact Ideal.isCompactElement_top.exists_finset_of_le_iSup _ _ S_empty section Comap variable {S' : Type*} [CommSemiring S'] theorem preimage_comap_zeroLocus_aux (f : R →+* S) (s : Set R) : (fun y => ⟨Ideal.comap f y.asIdeal, inferInstance⟩ : PrimeSpectrum S → PrimeSpectrum R) ⁻¹' zeroLocus s = zeroLocus (f '' s) := by ext x simp only [mem_zeroLocus, Set.image_subset_iff, Set.mem_preimage, mem_zeroLocus, Ideal.coe_comap] #align prime_spectrum.preimage_comap_zero_locus_aux PrimeSpectrum.preimage_comap_zeroLocus_aux /-- The function between prime spectra of commutative (semi)rings induced by a ring homomorphism. This function is continuous. -/ def comap (f : R →+* S) : C(PrimeSpectrum S, PrimeSpectrum R) where toFun y := ⟨Ideal.comap f y.asIdeal, inferInstance⟩ continuous_toFun := by simp only [continuous_iff_isClosed, isClosed_iff_zeroLocus] rintro _ ⟨s, rfl⟩ exact ⟨_, preimage_comap_zeroLocus_aux f s⟩ #align prime_spectrum.comap PrimeSpectrum.comap variable (f : R →+* S) @[simp] theorem comap_asIdeal (y : PrimeSpectrum S) : (comap f y).asIdeal = Ideal.comap f y.asIdeal := rfl #align prime_spectrum.comap_as_ideal PrimeSpectrum.comap_asIdeal @[simp] theorem comap_id : comap (RingHom.id R) = ContinuousMap.id _ := by ext rfl #align prime_spectrum.comap_id PrimeSpectrum.comap_id @[simp] theorem comap_comp (f : R →+* S) (g : S →+* S') : comap (g.comp f) = (comap f).comp (comap g) := rfl #align prime_spectrum.comap_comp PrimeSpectrum.comap_comp theorem comap_comp_apply (f : R →+* S) (g : S →+* S') (x : PrimeSpectrum S') : PrimeSpectrum.comap (g.comp f) x = (PrimeSpectrum.comap f) (PrimeSpectrum.comap g x) := rfl #align prime_spectrum.comap_comp_apply PrimeSpectrum.comap_comp_apply @[simp] theorem preimage_comap_zeroLocus (s : Set R) : comap f ⁻¹' zeroLocus s = zeroLocus (f '' s) := preimage_comap_zeroLocus_aux f s #align prime_spectrum.preimage_comap_zero_locus PrimeSpectrum.preimage_comap_zeroLocus theorem comap_injective_of_surjective (f : R →+* S) (hf : Function.Surjective f) : Function.Injective (comap f) := fun x y h => PrimeSpectrum.ext _ _ (Ideal.comap_injective_of_surjective f hf (congr_arg PrimeSpectrum.asIdeal h : (comap f x).asIdeal = (comap f y).asIdeal)) #align prime_spectrum.comap_injective_of_surjective PrimeSpectrum.comap_injective_of_surjective variable (S) theorem localization_comap_inducing [Algebra R S] (M : Submonoid R) [IsLocalization M S] : Inducing (comap (algebraMap R S)) := by refine ⟨TopologicalSpace.ext_isClosed fun Z ↦ ?_⟩ simp_rw [isClosed_induced_iff, isClosed_iff_zeroLocus, @eq_comm _ _ (zeroLocus _), exists_exists_eq_and, preimage_comap_zeroLocus] constructor · rintro ⟨s, rfl⟩ refine ⟨(Ideal.span s).comap (algebraMap R S), ?_⟩ rw [← zeroLocus_span, ← zeroLocus_span s, ← Ideal.map, IsLocalization.map_comap M S] · rintro ⟨s, rfl⟩ exact ⟨_, rfl⟩ #align prime_spectrum.localization_comap_inducing PrimeSpectrum.localization_comap_inducing theorem localization_comap_injective [Algebra R S] (M : Submonoid R) [IsLocalization M S] : Function.Injective (comap (algebraMap R S)) := by intro p q h replace h := congr_arg (fun x : PrimeSpectrum R => Ideal.map (algebraMap R S) x.asIdeal) h dsimp only [comap, ContinuousMap.coe_mk] at h rw [IsLocalization.map_comap M S, IsLocalization.map_comap M S] at h ext1 exact h #align prime_spectrum.localization_comap_injective PrimeSpectrum.localization_comap_injective theorem localization_comap_embedding [Algebra R S] (M : Submonoid R) [IsLocalization M S] : Embedding (comap (algebraMap R S)) := ⟨localization_comap_inducing S M, localization_comap_injective S M⟩ #align prime_spectrum.localization_comap_embedding PrimeSpectrum.localization_comap_embedding theorem localization_comap_range [Algebra R S] (M : Submonoid R) [IsLocalization M S] : Set.range (comap (algebraMap R S)) = { p | Disjoint (M : Set R) p.asIdeal } := by ext x constructor · simp_rw [disjoint_iff_inf_le] rintro ⟨p, rfl⟩ x ⟨hx₁, hx₂⟩ exact (p.2.1 : ¬_) (p.asIdeal.eq_top_of_isUnit_mem hx₂ (IsLocalization.map_units S ⟨x, hx₁⟩)) · intro h use ⟨x.asIdeal.map (algebraMap R S), IsLocalization.isPrime_of_isPrime_disjoint M S _ x.2 h⟩ ext1 exact IsLocalization.comap_map_of_isPrime_disjoint M S _ x.2 h #align prime_spectrum.localization_comap_range PrimeSpectrum.localization_comap_range open Function RingHom theorem comap_inducing_of_surjective (hf : Surjective f) : Inducing (comap f) where induced := by set_option tactic.skipAssignedInstances false in simp_rw [TopologicalSpace.ext_iff, ← isClosed_compl_iff, ← @isClosed_compl_iff (PrimeSpectrum S) ((TopologicalSpace.induced (comap f) zariskiTopology)), isClosed_induced_iff, isClosed_iff_zeroLocus] refine fun s => ⟨fun ⟨F, hF⟩ => ⟨zeroLocus (f ⁻¹' F), ⟨f ⁻¹' F, rfl⟩, by rw [preimage_comap_zeroLocus, Function.Surjective.image_preimage hf, hF]⟩, ?_⟩ rintro ⟨-, ⟨F, rfl⟩, hF⟩ exact ⟨f '' F, hF.symm.trans (preimage_comap_zeroLocus f F)⟩ #align prime_spectrum.comap_inducing_of_surjective PrimeSpectrum.comap_inducing_of_surjective end Comap end CommSemiRing section SpecOfSurjective /-! The comap of a surjective ring homomorphism is a closed embedding between the prime spectra. -/ open Function RingHom variable [CommRing R] [CommRing S] variable (f : R →+* S) variable {R} theorem comap_singleton_isClosed_of_surjective (f : R →+* S) (hf : Function.Surjective f) (x : PrimeSpectrum S) (hx : IsClosed ({x} : Set (PrimeSpectrum S))) : IsClosed ({comap f x} : Set (PrimeSpectrum R)) := haveI : x.asIdeal.IsMaximal := (isClosed_singleton_iff_isMaximal x).1 hx (isClosed_singleton_iff_isMaximal _).2 (Ideal.comap_isMaximal_of_surjective f hf) #align prime_spectrum.comap_singleton_is_closed_of_surjective PrimeSpectrum.comap_singleton_isClosed_of_surjective theorem comap_singleton_isClosed_of_isIntegral (f : R →+* S) (hf : f.IsIntegral) (x : PrimeSpectrum S) (hx : IsClosed ({x} : Set (PrimeSpectrum S))) : IsClosed ({comap f x} : Set (PrimeSpectrum R)) := have := (isClosed_singleton_iff_isMaximal x).1 hx (isClosed_singleton_iff_isMaximal _).2 (Ideal.isMaximal_comap_of_isIntegral_of_isMaximal' f hf x.asIdeal) #align prime_spectrum.comap_singleton_is_closed_of_is_integral PrimeSpectrum.comap_singleton_isClosed_of_isIntegral theorem image_comap_zeroLocus_eq_zeroLocus_comap (hf : Surjective f) (I : Ideal S) : comap f '' zeroLocus I = zeroLocus (I.comap f) := by simp only [Set.ext_iff, Set.mem_image, mem_zeroLocus, SetLike.coe_subset_coe] refine fun p => ⟨?_, fun h_I_p => ?_⟩ · rintro ⟨p, hp, rfl⟩ a ha exact hp ha · have hp : ker f ≤ p.asIdeal := (Ideal.comap_mono bot_le).trans h_I_p refine ⟨⟨p.asIdeal.map f, Ideal.map_isPrime_of_surjective hf hp⟩, fun x hx => ?_, ?_⟩ · obtain ⟨x', rfl⟩ := hf x exact Ideal.mem_map_of_mem f (h_I_p hx) · ext x rw [comap_asIdeal, Ideal.mem_comap, Ideal.mem_map_iff_of_surjective f hf] refine ⟨?_, fun hx => ⟨x, hx, rfl⟩⟩ rintro ⟨x', hx', heq⟩ rw [← sub_sub_cancel x' x] refine p.asIdeal.sub_mem hx' (hp ?_) rwa [mem_ker, map_sub, sub_eq_zero] #align prime_spectrum.image_comap_zero_locus_eq_zero_locus_comap PrimeSpectrum.image_comap_zeroLocus_eq_zeroLocus_comap theorem range_comap_of_surjective (hf : Surjective f) : Set.range (comap f) = zeroLocus (ker f) := by rw [← Set.image_univ] convert image_comap_zeroLocus_eq_zeroLocus_comap _ _ hf _ rw [zeroLocus_bot] #align prime_spectrum.range_comap_of_surjective PrimeSpectrum.range_comap_of_surjective theorem isClosed_range_comap_of_surjective (hf : Surjective f) : IsClosed (Set.range (comap f)) := by rw [range_comap_of_surjective _ f hf] exact isClosed_zeroLocus _ #align prime_spectrum.is_closed_range_comap_of_surjective PrimeSpectrum.isClosed_range_comap_of_surjective theorem closedEmbedding_comap_of_surjective (hf : Surjective f) : ClosedEmbedding (comap f) := { induced := (comap_inducing_of_surjective S f hf).induced inj := comap_injective_of_surjective f hf isClosed_range := isClosed_range_comap_of_surjective S f hf } #align prime_spectrum.closed_embedding_comap_of_surjective PrimeSpectrum.closedEmbedding_comap_of_surjective end SpecOfSurjective section CommSemiRing variable [CommSemiring R] [CommSemiring S] variable {R S} section BasicOpen /-- `basicOpen r` is the open subset containing all prime ideals not containing `r`. -/ def basicOpen (r : R) : TopologicalSpace.Opens (PrimeSpectrum R) where carrier := { x | r ∉ x.asIdeal } is_open' := ⟨{r}, Set.ext fun _ => Set.singleton_subset_iff.trans <| Classical.not_not.symm⟩ #align prime_spectrum.basic_open PrimeSpectrum.basicOpen @[simp] theorem mem_basicOpen (f : R) (x : PrimeSpectrum R) : x ∈ basicOpen f ↔ f ∉ x.asIdeal := Iff.rfl #align prime_spectrum.mem_basic_open PrimeSpectrum.mem_basicOpen theorem isOpen_basicOpen {a : R} : IsOpen (basicOpen a : Set (PrimeSpectrum R)) := (basicOpen a).isOpen #align prime_spectrum.is_open_basic_open PrimeSpectrum.isOpen_basicOpen @[simp] theorem basicOpen_eq_zeroLocus_compl (r : R) : (basicOpen r : Set (PrimeSpectrum R)) = (zeroLocus {r})ᶜ := Set.ext fun x => by simp only [SetLike.mem_coe, mem_basicOpen, Set.mem_compl_iff, mem_zeroLocus, Set.singleton_subset_iff] #align prime_spectrum.basic_open_eq_zero_locus_compl PrimeSpectrum.basicOpen_eq_zeroLocus_compl @[simp] theorem basicOpen_one : basicOpen (1 : R) = ⊤ := TopologicalSpace.Opens.ext <| by simp #align prime_spectrum.basic_open_one PrimeSpectrum.basicOpen_one @[simp] theorem basicOpen_zero : basicOpen (0 : R) = ⊥ := TopologicalSpace.Opens.ext <| by simp #align prime_spectrum.basic_open_zero PrimeSpectrum.basicOpen_zero theorem basicOpen_le_basicOpen_iff (f g : R) : basicOpen f ≤ basicOpen g ↔ f ∈ (Ideal.span ({g} : Set R)).radical := by rw [← SetLike.coe_subset_coe, basicOpen_eq_zeroLocus_compl, basicOpen_eq_zeroLocus_compl, Set.compl_subset_compl, zeroLocus_subset_zeroLocus_singleton_iff] #align prime_spectrum.basic_open_le_basic_open_iff PrimeSpectrum.basicOpen_le_basicOpen_iff theorem basicOpen_mul (f g : R) : basicOpen (f * g) = basicOpen f ⊓ basicOpen g := TopologicalSpace.Opens.ext <| by simp [zeroLocus_singleton_mul] #align prime_spectrum.basic_open_mul PrimeSpectrum.basicOpen_mul theorem basicOpen_mul_le_left (f g : R) : basicOpen (f * g) ≤ basicOpen f := by rw [basicOpen_mul f g] exact inf_le_left #align prime_spectrum.basic_open_mul_le_left PrimeSpectrum.basicOpen_mul_le_left theorem basicOpen_mul_le_right (f g : R) : basicOpen (f * g) ≤ basicOpen g := by rw [basicOpen_mul f g] exact inf_le_right #align prime_spectrum.basic_open_mul_le_right PrimeSpectrum.basicOpen_mul_le_right @[simp] theorem basicOpen_pow (f : R) (n : ℕ) (hn : 0 < n) : basicOpen (f ^ n) = basicOpen f := TopologicalSpace.Opens.ext <| by simpa using zeroLocus_singleton_pow f n hn #align prime_spectrum.basic_open_pow PrimeSpectrum.basicOpen_pow theorem isTopologicalBasis_basic_opens : TopologicalSpace.IsTopologicalBasis (Set.range fun r : R => (basicOpen r : Set (PrimeSpectrum R))) := by apply TopologicalSpace.isTopologicalBasis_of_isOpen_of_nhds · rintro _ ⟨r, rfl⟩ exact isOpen_basicOpen · rintro p U hp ⟨s, hs⟩ rw [← compl_compl U, Set.mem_compl_iff, ← hs, mem_zeroLocus, Set.not_subset] at hp obtain ⟨f, hfs, hfp⟩ := hp refine ⟨basicOpen f, ⟨f, rfl⟩, hfp, ?_⟩ rw [← Set.compl_subset_compl, ← hs, basicOpen_eq_zeroLocus_compl, compl_compl] exact zeroLocus_anti_mono (Set.singleton_subset_iff.mpr hfs) #align prime_spectrum.is_topological_basis_basic_opens PrimeSpectrum.isTopologicalBasis_basic_opens
Mathlib/AlgebraicGeometry/PrimeSpectrum/Basic.lean
847
851
theorem isBasis_basic_opens : TopologicalSpace.Opens.IsBasis (Set.range (@basicOpen R _)) := by
unfold TopologicalSpace.Opens.IsBasis convert isTopologicalBasis_basic_opens (R := R) rw [← Set.range_comp] rfl
/- 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.ModEq import Mathlib.Algebra.Module.Defs import Mathlib.Algebra.Order.Archimedean import Mathlib.Algebra.Periodic import Mathlib.Data.Int.SuccPred import Mathlib.GroupTheory.QuotientGroup import Mathlib.Order.Circular import Mathlib.Data.List.TFAE import Mathlib.Data.Set.Lattice #align_import algebra.order.to_interval_mod from "leanprover-community/mathlib"@"213b0cff7bc5ab6696ee07cceec80829ce42efec" /-! # Reducing to an interval modulo its length This file defines operations that reduce a number (in an `Archimedean` `LinearOrderedAddCommGroup`) to a number in a given interval, modulo the length of that interval. ## Main definitions * `toIcoDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ico a (a + p)`. * `toIcoMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ico a (a + p)`. * `toIocDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ioc a (a + p)`. * `toIocMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ioc a (a + p)`. -/ noncomputable section section LinearOrderedAddCommGroup variable {α : Type*} [LinearOrderedAddCommGroup α] [hα : Archimedean α] {p : α} (hp : 0 < p) {a b c : α} {n : ℤ} /-- The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ico a (a + p)`. -/ def toIcoDiv (a b : α) : ℤ := (existsUnique_sub_zsmul_mem_Ico hp b a).choose #align to_Ico_div toIcoDiv theorem sub_toIcoDiv_zsmul_mem_Ico (a b : α) : b - toIcoDiv hp a b • p ∈ Set.Ico a (a + p) := (existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.1 #align sub_to_Ico_div_zsmul_mem_Ico sub_toIcoDiv_zsmul_mem_Ico theorem toIcoDiv_eq_of_sub_zsmul_mem_Ico (h : b - n • p ∈ Set.Ico a (a + p)) : toIcoDiv hp a b = n := ((existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.2 _ h).symm #align to_Ico_div_eq_of_sub_zsmul_mem_Ico toIcoDiv_eq_of_sub_zsmul_mem_Ico /-- The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ioc a (a + p)`. -/ def toIocDiv (a b : α) : ℤ := (existsUnique_sub_zsmul_mem_Ioc hp b a).choose #align to_Ioc_div toIocDiv theorem sub_toIocDiv_zsmul_mem_Ioc (a b : α) : b - toIocDiv hp a b • p ∈ Set.Ioc a (a + p) := (existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.1 #align sub_to_Ioc_div_zsmul_mem_Ioc sub_toIocDiv_zsmul_mem_Ioc theorem toIocDiv_eq_of_sub_zsmul_mem_Ioc (h : b - n • p ∈ Set.Ioc a (a + p)) : toIocDiv hp a b = n := ((existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.2 _ h).symm #align to_Ioc_div_eq_of_sub_zsmul_mem_Ioc toIocDiv_eq_of_sub_zsmul_mem_Ioc /-- Reduce `b` to the interval `Ico a (a + p)`. -/ def toIcoMod (a b : α) : α := b - toIcoDiv hp a b • p #align to_Ico_mod toIcoMod /-- Reduce `b` to the interval `Ioc a (a + p)`. -/ def toIocMod (a b : α) : α := b - toIocDiv hp a b • p #align to_Ioc_mod toIocMod theorem toIcoMod_mem_Ico (a b : α) : toIcoMod hp a b ∈ Set.Ico a (a + p) := sub_toIcoDiv_zsmul_mem_Ico hp a b #align to_Ico_mod_mem_Ico toIcoMod_mem_Ico theorem toIcoMod_mem_Ico' (b : α) : toIcoMod hp 0 b ∈ Set.Ico 0 p := by convert toIcoMod_mem_Ico hp 0 b exact (zero_add p).symm #align to_Ico_mod_mem_Ico' toIcoMod_mem_Ico' theorem toIocMod_mem_Ioc (a b : α) : toIocMod hp a b ∈ Set.Ioc a (a + p) := sub_toIocDiv_zsmul_mem_Ioc hp a b #align to_Ioc_mod_mem_Ioc toIocMod_mem_Ioc theorem left_le_toIcoMod (a b : α) : a ≤ toIcoMod hp a b := (Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).1 #align left_le_to_Ico_mod left_le_toIcoMod theorem left_lt_toIocMod (a b : α) : a < toIocMod hp a b := (Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).1 #align left_lt_to_Ioc_mod left_lt_toIocMod theorem toIcoMod_lt_right (a b : α) : toIcoMod hp a b < a + p := (Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).2 #align to_Ico_mod_lt_right toIcoMod_lt_right theorem toIocMod_le_right (a b : α) : toIocMod hp a b ≤ a + p := (Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).2 #align to_Ioc_mod_le_right toIocMod_le_right @[simp] theorem self_sub_toIcoDiv_zsmul (a b : α) : b - toIcoDiv hp a b • p = toIcoMod hp a b := rfl #align self_sub_to_Ico_div_zsmul self_sub_toIcoDiv_zsmul @[simp] theorem self_sub_toIocDiv_zsmul (a b : α) : b - toIocDiv hp a b • p = toIocMod hp a b := rfl #align self_sub_to_Ioc_div_zsmul self_sub_toIocDiv_zsmul @[simp] theorem toIcoDiv_zsmul_sub_self (a b : α) : toIcoDiv hp a b • p - b = -toIcoMod hp a b := by rw [toIcoMod, neg_sub] #align to_Ico_div_zsmul_sub_self toIcoDiv_zsmul_sub_self @[simp] theorem toIocDiv_zsmul_sub_self (a b : α) : toIocDiv hp a b • p - b = -toIocMod hp a b := by rw [toIocMod, neg_sub] #align to_Ioc_div_zsmul_sub_self toIocDiv_zsmul_sub_self @[simp] theorem toIcoMod_sub_self (a b : α) : toIcoMod hp a b - b = -toIcoDiv hp a b • p := by rw [toIcoMod, sub_sub_cancel_left, neg_smul] #align to_Ico_mod_sub_self toIcoMod_sub_self @[simp] theorem toIocMod_sub_self (a b : α) : toIocMod hp a b - b = -toIocDiv hp a b • p := by rw [toIocMod, sub_sub_cancel_left, neg_smul] #align to_Ioc_mod_sub_self toIocMod_sub_self @[simp] theorem self_sub_toIcoMod (a b : α) : b - toIcoMod hp a b = toIcoDiv hp a b • p := by rw [toIcoMod, sub_sub_cancel] #align self_sub_to_Ico_mod self_sub_toIcoMod @[simp] theorem self_sub_toIocMod (a b : α) : b - toIocMod hp a b = toIocDiv hp a b • p := by rw [toIocMod, sub_sub_cancel] #align self_sub_to_Ioc_mod self_sub_toIocMod @[simp] theorem toIcoMod_add_toIcoDiv_zsmul (a b : α) : toIcoMod hp a b + toIcoDiv hp a b • p = b := by rw [toIcoMod, sub_add_cancel] #align to_Ico_mod_add_to_Ico_div_zsmul toIcoMod_add_toIcoDiv_zsmul @[simp]
Mathlib/Algebra/Order/ToIntervalMod.lean
158
159
theorem toIocMod_add_toIocDiv_zsmul (a b : α) : toIocMod hp a b + toIocDiv hp a b • p = b := by
rw [toIocMod, sub_add_cancel]
/- Copyright (c) 2021 Rémy Degenne. 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.Function.SimpleFuncDenseLp #align_import measure_theory.integral.set_to_l1 from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Extension of a linear function from indicators to L1 Let `T : Set α → E →L[ℝ] F` be additive for measurable sets with finite measure, in the sense that for `s, t` two such sets, `s ∩ t = ∅ → T (s ∪ t) = T s + T t`. `T` is akin to a bilinear map on `Set α × E`, or a linear map on indicator functions. This file constructs an extension of `T` to integrable simple functions, which are finite sums of indicators of measurable sets with finite measure, then to integrable functions, which are limits of integrable simple functions. The main result is a continuous linear map `(α →₁[μ] E) →L[ℝ] F`. This extension process is used to define the Bochner integral in the `MeasureTheory.Integral.Bochner` file and the conditional expectation of an integrable function in `MeasureTheory.Function.ConditionalExpectation`. ## Main Definitions - `FinMeasAdditive μ T`: the property that `T` is additive on measurable sets with finite measure. For two such sets, `s ∩ t = ∅ → T (s ∪ t) = T s + T t`. - `DominatedFinMeasAdditive μ T C`: `FinMeasAdditive μ T ∧ ∀ s, ‖T s‖ ≤ C * (μ s).toReal`. This is the property needed to perform the extension from indicators to L1. - `setToL1 (hT : DominatedFinMeasAdditive μ T C) : (α →₁[μ] E) →L[ℝ] F`: the extension of `T` from indicators to L1. - `setToFun μ T (hT : DominatedFinMeasAdditive μ T C) (f : α → E) : F`: a version of the extension which applies to functions (with value 0 if the function is not integrable). ## Properties For most properties of `setToFun`, we provide two lemmas. One version uses hypotheses valid on all sets, like `T = T'`, and a second version which uses a primed name uses hypotheses on measurable sets with finite measure, like `∀ s, MeasurableSet s → μ s < ∞ → T s = T' s`. The lemmas listed here don't show all hypotheses. Refer to the actual lemmas for details. Linearity: - `setToFun_zero_left : setToFun μ 0 hT f = 0` - `setToFun_add_left : setToFun μ (T + T') _ f = setToFun μ T hT f + setToFun μ T' hT' f` - `setToFun_smul_left : setToFun μ (fun s ↦ c • (T s)) (hT.smul c) f = c • setToFun μ T hT f` - `setToFun_zero : setToFun μ T hT (0 : α → E) = 0` - `setToFun_neg : setToFun μ T hT (-f) = - setToFun μ T hT f` If `f` and `g` are integrable: - `setToFun_add : setToFun μ T hT (f + g) = setToFun μ T hT f + setToFun μ T hT g` - `setToFun_sub : setToFun μ T hT (f - g) = setToFun μ T hT f - setToFun μ T hT g` If `T` is verifies `∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x`: - `setToFun_smul : setToFun μ T hT (c • f) = c • setToFun μ T hT f` Other: - `setToFun_congr_ae (h : f =ᵐ[μ] g) : setToFun μ T hT f = setToFun μ T hT g` - `setToFun_measure_zero (h : μ = 0) : setToFun μ T hT f = 0` If the space is a `NormedLatticeAddCommGroup` and `T` is such that `0 ≤ T s x` for `0 ≤ x`, we also prove order-related properties: - `setToFun_mono_left (h : ∀ s x, T s x ≤ T' s x) : setToFun μ T hT f ≤ setToFun μ T' hT' f` - `setToFun_nonneg (hf : 0 ≤ᵐ[μ] f) : 0 ≤ setToFun μ T hT f` - `setToFun_mono (hfg : f ≤ᵐ[μ] g) : setToFun μ T hT f ≤ setToFun μ T hT g` ## Implementation notes The starting object `T : Set α → E →L[ℝ] F` matters only through its restriction on measurable sets with finite measure. Its value on other sets is ignored. -/ noncomputable section open scoped Classical Topology NNReal ENNReal MeasureTheory Pointwise open Set Filter TopologicalSpace ENNReal EMetric namespace MeasureTheory variable {α E F F' G 𝕜 : Type*} {p : ℝ≥0∞} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] [NormedAddCommGroup F'] [NormedSpace ℝ F'] [NormedAddCommGroup G] {m : MeasurableSpace α} {μ : Measure α} local infixr:25 " →ₛ " => SimpleFunc open Finset section FinMeasAdditive /-- A set function is `FinMeasAdditive` if its value on the union of two disjoint measurable sets with finite measure is the sum of its values on each set. -/ def FinMeasAdditive {β} [AddMonoid β] {_ : MeasurableSpace α} (μ : Measure α) (T : Set α → β) : Prop := ∀ s t, MeasurableSet s → MeasurableSet t → μ s ≠ ∞ → μ t ≠ ∞ → s ∩ t = ∅ → T (s ∪ t) = T s + T t #align measure_theory.fin_meas_additive MeasureTheory.FinMeasAdditive namespace FinMeasAdditive variable {β : Type*} [AddCommMonoid β] {T T' : Set α → β} theorem zero : FinMeasAdditive μ (0 : Set α → β) := fun s t _ _ _ _ _ => by simp #align measure_theory.fin_meas_additive.zero MeasureTheory.FinMeasAdditive.zero theorem add (hT : FinMeasAdditive μ T) (hT' : FinMeasAdditive μ T') : FinMeasAdditive μ (T + T') := by intro s t hs ht hμs hμt hst simp only [hT s t hs ht hμs hμt hst, hT' s t hs ht hμs hμt hst, Pi.add_apply] abel #align measure_theory.fin_meas_additive.add MeasureTheory.FinMeasAdditive.add theorem smul [Monoid 𝕜] [DistribMulAction 𝕜 β] (hT : FinMeasAdditive μ T) (c : 𝕜) : FinMeasAdditive μ fun s => c • T s := fun s t hs ht hμs hμt hst => by simp [hT s t hs ht hμs hμt hst] #align measure_theory.fin_meas_additive.smul MeasureTheory.FinMeasAdditive.smul theorem of_eq_top_imp_eq_top {μ' : Measure α} (h : ∀ s, MeasurableSet s → μ s = ∞ → μ' s = ∞) (hT : FinMeasAdditive μ T) : FinMeasAdditive μ' T := fun s t hs ht hμ's hμ't hst => hT s t hs ht (mt (h s hs) hμ's) (mt (h t ht) hμ't) hst #align measure_theory.fin_meas_additive.of_eq_top_imp_eq_top MeasureTheory.FinMeasAdditive.of_eq_top_imp_eq_top theorem of_smul_measure (c : ℝ≥0∞) (hc_ne_top : c ≠ ∞) (hT : FinMeasAdditive (c • μ) T) : FinMeasAdditive μ T := by refine of_eq_top_imp_eq_top (fun s _ hμs => ?_) hT rw [Measure.smul_apply, smul_eq_mul, ENNReal.mul_eq_top] at hμs simp only [hc_ne_top, or_false_iff, Ne, false_and_iff] at hμs exact hμs.2 #align measure_theory.fin_meas_additive.of_smul_measure MeasureTheory.FinMeasAdditive.of_smul_measure theorem smul_measure (c : ℝ≥0∞) (hc_ne_zero : c ≠ 0) (hT : FinMeasAdditive μ T) : FinMeasAdditive (c • μ) T := by refine of_eq_top_imp_eq_top (fun s _ hμs => ?_) hT rw [Measure.smul_apply, smul_eq_mul, ENNReal.mul_eq_top] simp only [hc_ne_zero, true_and_iff, Ne, not_false_iff] exact Or.inl hμs #align measure_theory.fin_meas_additive.smul_measure MeasureTheory.FinMeasAdditive.smul_measure theorem smul_measure_iff (c : ℝ≥0∞) (hc_ne_zero : c ≠ 0) (hc_ne_top : c ≠ ∞) : FinMeasAdditive (c • μ) T ↔ FinMeasAdditive μ T := ⟨fun hT => of_smul_measure c hc_ne_top hT, fun hT => smul_measure c hc_ne_zero hT⟩ #align measure_theory.fin_meas_additive.smul_measure_iff MeasureTheory.FinMeasAdditive.smul_measure_iff theorem map_empty_eq_zero {β} [AddCancelMonoid β] {T : Set α → β} (hT : FinMeasAdditive μ T) : T ∅ = 0 := by have h_empty : μ ∅ ≠ ∞ := (measure_empty.le.trans_lt ENNReal.coe_lt_top).ne specialize hT ∅ ∅ MeasurableSet.empty MeasurableSet.empty h_empty h_empty (Set.inter_empty ∅) rw [Set.union_empty] at hT nth_rw 1 [← add_zero (T ∅)] at hT exact (add_left_cancel hT).symm #align measure_theory.fin_meas_additive.map_empty_eq_zero MeasureTheory.FinMeasAdditive.map_empty_eq_zero theorem map_iUnion_fin_meas_set_eq_sum (T : Set α → β) (T_empty : T ∅ = 0) (h_add : FinMeasAdditive μ T) {ι} (S : ι → Set α) (sι : Finset ι) (hS_meas : ∀ i, MeasurableSet (S i)) (hSp : ∀ i ∈ sι, μ (S i) ≠ ∞) (h_disj : ∀ᵉ (i ∈ sι) (j ∈ sι), i ≠ j → Disjoint (S i) (S j)) : T (⋃ i ∈ sι, S i) = ∑ i ∈ sι, T (S i) := by revert hSp h_disj refine Finset.induction_on sι ?_ ?_ · simp only [Finset.not_mem_empty, IsEmpty.forall_iff, iUnion_false, iUnion_empty, sum_empty, forall₂_true_iff, imp_true_iff, forall_true_left, not_false_iff, T_empty] intro a s has h hps h_disj rw [Finset.sum_insert has, ← h] swap; · exact fun i hi => hps i (Finset.mem_insert_of_mem hi) swap; · exact fun i hi j hj hij => h_disj i (Finset.mem_insert_of_mem hi) j (Finset.mem_insert_of_mem hj) hij rw [← h_add (S a) (⋃ i ∈ s, S i) (hS_meas a) (measurableSet_biUnion _ fun i _ => hS_meas i) (hps a (Finset.mem_insert_self a s))] · congr; convert Finset.iSup_insert a s S · exact ((measure_biUnion_finset_le _ _).trans_lt <| ENNReal.sum_lt_top fun i hi => hps i <| Finset.mem_insert_of_mem hi).ne · simp_rw [Set.inter_iUnion] refine iUnion_eq_empty.mpr fun i => iUnion_eq_empty.mpr fun hi => ?_ rw [← Set.disjoint_iff_inter_eq_empty] refine h_disj a (Finset.mem_insert_self a s) i (Finset.mem_insert_of_mem hi) fun hai => ?_ rw [← hai] at hi exact has hi #align measure_theory.fin_meas_additive.map_Union_fin_meas_set_eq_sum MeasureTheory.FinMeasAdditive.map_iUnion_fin_meas_set_eq_sum end FinMeasAdditive /-- A `FinMeasAdditive` set function whose norm on every set is less than the measure of the set (up to a multiplicative constant). -/ def DominatedFinMeasAdditive {β} [SeminormedAddCommGroup β] {_ : MeasurableSpace α} (μ : Measure α) (T : Set α → β) (C : ℝ) : Prop := FinMeasAdditive μ T ∧ ∀ s, MeasurableSet s → μ s < ∞ → ‖T s‖ ≤ C * (μ s).toReal #align measure_theory.dominated_fin_meas_additive MeasureTheory.DominatedFinMeasAdditive namespace DominatedFinMeasAdditive variable {β : Type*} [SeminormedAddCommGroup β] {T T' : Set α → β} {C C' : ℝ} theorem zero {m : MeasurableSpace α} (μ : Measure α) (hC : 0 ≤ C) : DominatedFinMeasAdditive μ (0 : Set α → β) C := by refine ⟨FinMeasAdditive.zero, fun s _ _ => ?_⟩ rw [Pi.zero_apply, norm_zero] exact mul_nonneg hC toReal_nonneg #align measure_theory.dominated_fin_meas_additive.zero MeasureTheory.DominatedFinMeasAdditive.zero theorem eq_zero_of_measure_zero {β : Type*} [NormedAddCommGroup β] {T : Set α → β} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C) {s : Set α} (hs : MeasurableSet s) (hs_zero : μ s = 0) : T s = 0 := by refine norm_eq_zero.mp ?_ refine ((hT.2 s hs (by simp [hs_zero])).trans (le_of_eq ?_)).antisymm (norm_nonneg _) rw [hs_zero, ENNReal.zero_toReal, mul_zero] #align measure_theory.dominated_fin_meas_additive.eq_zero_of_measure_zero MeasureTheory.DominatedFinMeasAdditive.eq_zero_of_measure_zero theorem eq_zero {β : Type*} [NormedAddCommGroup β] {T : Set α → β} {C : ℝ} {m : MeasurableSpace α} (hT : DominatedFinMeasAdditive (0 : Measure α) T C) {s : Set α} (hs : MeasurableSet s) : T s = 0 := eq_zero_of_measure_zero hT hs (by simp only [Measure.coe_zero, Pi.zero_apply]) #align measure_theory.dominated_fin_meas_additive.eq_zero MeasureTheory.DominatedFinMeasAdditive.eq_zero theorem add (hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') : DominatedFinMeasAdditive μ (T + T') (C + C') := by refine ⟨hT.1.add hT'.1, fun s hs hμs => ?_⟩ rw [Pi.add_apply, add_mul] exact (norm_add_le _ _).trans (add_le_add (hT.2 s hs hμs) (hT'.2 s hs hμs)) #align measure_theory.dominated_fin_meas_additive.add MeasureTheory.DominatedFinMeasAdditive.add theorem smul [NormedField 𝕜] [NormedSpace 𝕜 β] (hT : DominatedFinMeasAdditive μ T C) (c : 𝕜) : DominatedFinMeasAdditive μ (fun s => c • T s) (‖c‖ * C) := by refine ⟨hT.1.smul c, fun s hs hμs => ?_⟩ dsimp only rw [norm_smul, mul_assoc] exact mul_le_mul le_rfl (hT.2 s hs hμs) (norm_nonneg _) (norm_nonneg _) #align measure_theory.dominated_fin_meas_additive.smul MeasureTheory.DominatedFinMeasAdditive.smul
Mathlib/MeasureTheory/Integral/SetToL1.lean
231
238
theorem of_measure_le {μ' : Measure α} (h : μ ≤ μ') (hT : DominatedFinMeasAdditive μ T C) (hC : 0 ≤ C) : DominatedFinMeasAdditive μ' T C := by
have h' : ∀ s, μ s = ∞ → μ' s = ∞ := fun s hs ↦ top_unique <| hs.symm.trans_le (h _) refine ⟨hT.1.of_eq_top_imp_eq_top fun s _ ↦ h' s, fun s hs hμ's ↦ ?_⟩ have hμs : μ s < ∞ := (h s).trans_lt hμ's calc ‖T s‖ ≤ C * (μ s).toReal := hT.2 s hs hμs _ ≤ C * (μ' s).toReal := by gcongr; exacts [hμ's.ne, h _]
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Abelian.Basic #align_import category_theory.idempotents.basic from "leanprover-community/mathlib"@"3a061790136d13594ec10c7c90d202335ac5d854" /-! # Idempotent complete categories In this file, we define the notion of idempotent complete categories (also known as Karoubian categories, or pseudoabelian in the case of preadditive categories). ## Main definitions - `IsIdempotentComplete C` expresses that `C` is idempotent complete, i.e. all idempotents in `C` split. Other characterisations of idempotent completeness are given by `isIdempotentComplete_iff_hasEqualizer_of_id_and_idempotent` and `isIdempotentComplete_iff_idempotents_have_kernels`. - `isIdempotentComplete_of_abelian` expresses that abelian categories are idempotent complete. - `isIdempotentComplete_iff_ofEquivalence` expresses that if two categories `C` and `D` are equivalent, then `C` is idempotent complete iff `D` is. - `isIdempotentComplete_iff_opposite` expresses that `Cᵒᵖ` is idempotent complete iff `C` is. ## References * [Stacks: Karoubian categories] https://stacks.math.columbia.edu/tag/09SF -/ open CategoryTheory open CategoryTheory.Category open CategoryTheory.Limits open CategoryTheory.Preadditive open Opposite namespace CategoryTheory variable (C : Type*) [Category C] /-- A category is idempotent complete iff all idempotent endomorphisms `p` split as a composition `p = e ≫ i` with `i ≫ e = 𝟙 _` -/ class IsIdempotentComplete : Prop where /-- A category is idempotent complete iff all idempotent endomorphisms `p` split as a composition `p = e ≫ i` with `i ≫ e = 𝟙 _` -/ idempotents_split : ∀ (X : C) (p : X ⟶ X), p ≫ p = p → ∃ (Y : C) (i : Y ⟶ X) (e : X ⟶ Y), i ≫ e = 𝟙 Y ∧ e ≫ i = p #align category_theory.is_idempotent_complete CategoryTheory.IsIdempotentComplete namespace Idempotents /-- A category is idempotent complete iff for all idempotent endomorphisms, the equalizer of the identity and this idempotent exists. -/ theorem isIdempotentComplete_iff_hasEqualizer_of_id_and_idempotent : IsIdempotentComplete C ↔ ∀ (X : C) (p : X ⟶ X), p ≫ p = p → HasEqualizer (𝟙 X) p := by constructor · intro intro X p hp rcases IsIdempotentComplete.idempotents_split X p hp with ⟨Y, i, e, ⟨h₁, h₂⟩⟩ exact ⟨Nonempty.intro { cone := Fork.ofι i (show i ≫ 𝟙 X = i ≫ p by rw [comp_id, ← h₂, ← assoc, h₁, id_comp]) isLimit := by apply Fork.IsLimit.mk' intro s refine ⟨s.ι ≫ e, ?_⟩ constructor · erw [assoc, h₂, ← Limits.Fork.condition s, comp_id] · intro m hm rw [Fork.ι_ofι] at hm rw [← hm] simp only [← hm, assoc, h₁] exact (comp_id m).symm }⟩ · intro h refine ⟨?_⟩ intro X p hp haveI : HasEqualizer (𝟙 X) p := h X p hp refine ⟨equalizer (𝟙 X) p, equalizer.ι (𝟙 X) p, equalizer.lift p (show p ≫ 𝟙 X = p ≫ p by rw [hp, comp_id]), ?_, equalizer.lift_ι _ _⟩ ext simp only [assoc, limit.lift_π, Eq.ndrec, id_eq, eq_mpr_eq_cast, Fork.ofι_pt, Fork.ofι_π_app, id_comp] rw [← equalizer.condition, comp_id] #align category_theory.idempotents.is_idempotent_complete_iff_has_equalizer_of_id_and_idempotent CategoryTheory.Idempotents.isIdempotentComplete_iff_hasEqualizer_of_id_and_idempotent variable {C} /-- In a preadditive category, when `p : X ⟶ X` is idempotent, then `𝟙 X - p` is also idempotent. -/
Mathlib/CategoryTheory/Idempotents/Basic.lean
99
101
theorem idem_of_id_sub_idem [Preadditive C] {X : C} (p : X ⟶ X) (hp : p ≫ p = p) : (𝟙 _ - p) ≫ (𝟙 _ - p) = 𝟙 _ - p := by
simp only [comp_sub, sub_comp, id_comp, comp_id, hp, sub_self, sub_zero]
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Yury Kudryashov -/ import Mathlib.Analysis.Normed.Group.InfiniteSum import Mathlib.Analysis.Normed.MulAction import Mathlib.Topology.Algebra.Order.LiminfLimsup import Mathlib.Topology.PartialHomeomorph #align_import analysis.asymptotics.asymptotics from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Asymptotics We introduce these relations: * `IsBigOWith c l f g` : "f is big O of g along l with constant c"; * `f =O[l] g` : "f is big O of g along l"; * `f =o[l] g` : "f is little o of g along l". Here `l` is any filter on the domain of `f` and `g`, which are assumed to be the same. The codomains of `f` and `g` do not need to be the same; all that is needed that there is a norm associated with these types, and it is the norm that is compared asymptotically. The relation `IsBigOWith c` is introduced to factor out common algebraic arguments in the proofs of similar properties of `IsBigO` and `IsLittleO`. Usually proofs outside of this file should use `IsBigO` instead. Often the ranges of `f` and `g` will be the real numbers, in which case the norm is the absolute value. In general, we have `f =O[l] g ↔ (fun x ↦ ‖f x‖) =O[l] (fun x ↦ ‖g x‖)`, and similarly for `IsLittleO`. But our setup allows us to use the notions e.g. with functions to the integers, rationals, complex numbers, or any normed vector space without mentioning the norm explicitly. If `f` and `g` are functions to a normed field like the reals or complex numbers and `g` is always nonzero, we have `f =o[l] g ↔ Tendsto (fun x ↦ f x / (g x)) l (𝓝 0)`. In fact, the right-to-left direction holds without the hypothesis on `g`, and in the other direction it suffices to assume that `f` is zero wherever `g` is. (This generalization is useful in defining the Fréchet derivative.) -/ open Filter Set open scoped Classical open Topology Filter NNReal namespace Asymptotics set_option linter.uppercaseLean3 false variable {α : Type*} {β : Type*} {E : Type*} {F : Type*} {G : Type*} {E' : Type*} {F' : Type*} {G' : Type*} {E'' : Type*} {F'' : Type*} {G'' : Type*} {E''' : Type*} {R : Type*} {R' : Type*} {𝕜 : Type*} {𝕜' : Type*} variable [Norm E] [Norm F] [Norm G] variable [SeminormedAddCommGroup E'] [SeminormedAddCommGroup F'] [SeminormedAddCommGroup G'] [NormedAddCommGroup E''] [NormedAddCommGroup F''] [NormedAddCommGroup G''] [SeminormedRing R] [SeminormedAddGroup E'''] [SeminormedRing R'] variable [NormedDivisionRing 𝕜] [NormedDivisionRing 𝕜'] variable {c c' c₁ c₂ : ℝ} {f : α → E} {g : α → F} {k : α → G} variable {f' : α → E'} {g' : α → F'} {k' : α → G'} variable {f'' : α → E''} {g'' : α → F''} {k'' : α → G''} variable {l l' : Filter α} section Defs /-! ### Definitions -/ /-- This version of the Landau notation `IsBigOWith C l f g` where `f` and `g` are two functions on a type `α` and `l` is a filter on `α`, means that eventually for `l`, `‖f‖` is bounded by `C * ‖g‖`. In other words, `‖f‖ / ‖g‖` is eventually bounded by `C`, modulo division by zero issues that are avoided by this definition. Probably you want to use `IsBigO` instead of this relation. -/ irreducible_def IsBigOWith (c : ℝ) (l : Filter α) (f : α → E) (g : α → F) : Prop := ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ #align asymptotics.is_O_with Asymptotics.IsBigOWith /-- Definition of `IsBigOWith`. We record it in a lemma as `IsBigOWith` is irreducible. -/ theorem isBigOWith_iff : IsBigOWith c l f g ↔ ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := by rw [IsBigOWith_def] #align asymptotics.is_O_with_iff Asymptotics.isBigOWith_iff alias ⟨IsBigOWith.bound, IsBigOWith.of_bound⟩ := isBigOWith_iff #align asymptotics.is_O_with.bound Asymptotics.IsBigOWith.bound #align asymptotics.is_O_with.of_bound Asymptotics.IsBigOWith.of_bound /-- The Landau notation `f =O[l] g` where `f` and `g` are two functions on a type `α` and `l` is a filter on `α`, means that eventually for `l`, `‖f‖` is bounded by a constant multiple of `‖g‖`. In other words, `‖f‖ / ‖g‖` is eventually bounded, modulo division by zero issues that are avoided by this definition. -/ irreducible_def IsBigO (l : Filter α) (f : α → E) (g : α → F) : Prop := ∃ c : ℝ, IsBigOWith c l f g #align asymptotics.is_O Asymptotics.IsBigO @[inherit_doc] notation:100 f " =O[" l "] " g:100 => IsBigO l f g /-- Definition of `IsBigO` in terms of `IsBigOWith`. We record it in a lemma as `IsBigO` is irreducible. -/ theorem isBigO_iff_isBigOWith : f =O[l] g ↔ ∃ c : ℝ, IsBigOWith c l f g := by rw [IsBigO_def] #align asymptotics.is_O_iff_is_O_with Asymptotics.isBigO_iff_isBigOWith /-- Definition of `IsBigO` in terms of filters. -/ theorem isBigO_iff : f =O[l] g ↔ ∃ c : ℝ, ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := by simp only [IsBigO_def, IsBigOWith_def] #align asymptotics.is_O_iff Asymptotics.isBigO_iff /-- Definition of `IsBigO` in terms of filters, with a positive constant. -/ theorem isBigO_iff' {g : α → E'''} : f =O[l] g ↔ ∃ c > 0, ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := by refine ⟨fun h => ?mp, fun h => ?mpr⟩ case mp => rw [isBigO_iff] at h obtain ⟨c, hc⟩ := h refine ⟨max c 1, zero_lt_one.trans_le (le_max_right _ _), ?_⟩ filter_upwards [hc] with x hx apply hx.trans gcongr exact le_max_left _ _ case mpr => rw [isBigO_iff] obtain ⟨c, ⟨_, hc⟩⟩ := h exact ⟨c, hc⟩ /-- Definition of `IsBigO` in terms of filters, with the constant in the lower bound. -/ theorem isBigO_iff'' {g : α → E'''} : f =O[l] g ↔ ∃ c > 0, ∀ᶠ x in l, c * ‖f x‖ ≤ ‖g x‖ := by refine ⟨fun h => ?mp, fun h => ?mpr⟩ case mp => rw [isBigO_iff'] at h obtain ⟨c, ⟨hc_pos, hc⟩⟩ := h refine ⟨c⁻¹, ⟨by positivity, ?_⟩⟩ filter_upwards [hc] with x hx rwa [inv_mul_le_iff (by positivity)] case mpr => rw [isBigO_iff'] obtain ⟨c, ⟨hc_pos, hc⟩⟩ := h refine ⟨c⁻¹, ⟨by positivity, ?_⟩⟩ filter_upwards [hc] with x hx rwa [← inv_inv c, inv_mul_le_iff (by positivity)] at hx theorem IsBigO.of_bound (c : ℝ) (h : ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖) : f =O[l] g := isBigO_iff.2 ⟨c, h⟩ #align asymptotics.is_O.of_bound Asymptotics.IsBigO.of_bound theorem IsBigO.of_bound' (h : ∀ᶠ x in l, ‖f x‖ ≤ ‖g x‖) : f =O[l] g := IsBigO.of_bound 1 <| by simp_rw [one_mul] exact h #align asymptotics.is_O.of_bound' Asymptotics.IsBigO.of_bound' theorem IsBigO.bound : f =O[l] g → ∃ c : ℝ, ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := isBigO_iff.1 #align asymptotics.is_O.bound Asymptotics.IsBigO.bound /-- The Landau notation `f =o[l] g` where `f` and `g` are two functions on a type `α` and `l` is a filter on `α`, means that eventually for `l`, `‖f‖` is bounded by an arbitrarily small constant multiple of `‖g‖`. In other words, `‖f‖ / ‖g‖` tends to `0` along `l`, modulo division by zero issues that are avoided by this definition. -/ irreducible_def IsLittleO (l : Filter α) (f : α → E) (g : α → F) : Prop := ∀ ⦃c : ℝ⦄, 0 < c → IsBigOWith c l f g #align asymptotics.is_o Asymptotics.IsLittleO @[inherit_doc] notation:100 f " =o[" l "] " g:100 => IsLittleO l f g /-- Definition of `IsLittleO` in terms of `IsBigOWith`. -/ theorem isLittleO_iff_forall_isBigOWith : f =o[l] g ↔ ∀ ⦃c : ℝ⦄, 0 < c → IsBigOWith c l f g := by rw [IsLittleO_def] #align asymptotics.is_o_iff_forall_is_O_with Asymptotics.isLittleO_iff_forall_isBigOWith alias ⟨IsLittleO.forall_isBigOWith, IsLittleO.of_isBigOWith⟩ := isLittleO_iff_forall_isBigOWith #align asymptotics.is_o.forall_is_O_with Asymptotics.IsLittleO.forall_isBigOWith #align asymptotics.is_o.of_is_O_with Asymptotics.IsLittleO.of_isBigOWith /-- Definition of `IsLittleO` in terms of filters. -/ theorem isLittleO_iff : f =o[l] g ↔ ∀ ⦃c : ℝ⦄, 0 < c → ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := by simp only [IsLittleO_def, IsBigOWith_def] #align asymptotics.is_o_iff Asymptotics.isLittleO_iff alias ⟨IsLittleO.bound, IsLittleO.of_bound⟩ := isLittleO_iff #align asymptotics.is_o.bound Asymptotics.IsLittleO.bound #align asymptotics.is_o.of_bound Asymptotics.IsLittleO.of_bound theorem IsLittleO.def (h : f =o[l] g) (hc : 0 < c) : ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖ := isLittleO_iff.1 h hc #align asymptotics.is_o.def Asymptotics.IsLittleO.def theorem IsLittleO.def' (h : f =o[l] g) (hc : 0 < c) : IsBigOWith c l f g := isBigOWith_iff.2 <| isLittleO_iff.1 h hc #align asymptotics.is_o.def' Asymptotics.IsLittleO.def' theorem IsLittleO.eventuallyLE (h : f =o[l] g) : ∀ᶠ x in l, ‖f x‖ ≤ ‖g x‖ := by simpa using h.def zero_lt_one end Defs /-! ### Conversions -/ theorem IsBigOWith.isBigO (h : IsBigOWith c l f g) : f =O[l] g := by rw [IsBigO_def]; exact ⟨c, h⟩ #align asymptotics.is_O_with.is_O Asymptotics.IsBigOWith.isBigO theorem IsLittleO.isBigOWith (hgf : f =o[l] g) : IsBigOWith 1 l f g := hgf.def' zero_lt_one #align asymptotics.is_o.is_O_with Asymptotics.IsLittleO.isBigOWith theorem IsLittleO.isBigO (hgf : f =o[l] g) : f =O[l] g := hgf.isBigOWith.isBigO #align asymptotics.is_o.is_O Asymptotics.IsLittleO.isBigO theorem IsBigO.isBigOWith : f =O[l] g → ∃ c : ℝ, IsBigOWith c l f g := isBigO_iff_isBigOWith.1 #align asymptotics.is_O.is_O_with Asymptotics.IsBigO.isBigOWith theorem IsBigOWith.weaken (h : IsBigOWith c l f g') (hc : c ≤ c') : IsBigOWith c' l f g' := IsBigOWith.of_bound <| mem_of_superset h.bound fun x hx => calc ‖f x‖ ≤ c * ‖g' x‖ := hx _ ≤ _ := by gcongr #align asymptotics.is_O_with.weaken Asymptotics.IsBigOWith.weaken theorem IsBigOWith.exists_pos (h : IsBigOWith c l f g') : ∃ c' > 0, IsBigOWith c' l f g' := ⟨max c 1, lt_of_lt_of_le zero_lt_one (le_max_right c 1), h.weaken <| le_max_left c 1⟩ #align asymptotics.is_O_with.exists_pos Asymptotics.IsBigOWith.exists_pos theorem IsBigO.exists_pos (h : f =O[l] g') : ∃ c > 0, IsBigOWith c l f g' := let ⟨_c, hc⟩ := h.isBigOWith hc.exists_pos #align asymptotics.is_O.exists_pos Asymptotics.IsBigO.exists_pos theorem IsBigOWith.exists_nonneg (h : IsBigOWith c l f g') : ∃ c' ≥ 0, IsBigOWith c' l f g' := let ⟨c, cpos, hc⟩ := h.exists_pos ⟨c, le_of_lt cpos, hc⟩ #align asymptotics.is_O_with.exists_nonneg Asymptotics.IsBigOWith.exists_nonneg theorem IsBigO.exists_nonneg (h : f =O[l] g') : ∃ c ≥ 0, IsBigOWith c l f g' := let ⟨_c, hc⟩ := h.isBigOWith hc.exists_nonneg #align asymptotics.is_O.exists_nonneg Asymptotics.IsBigO.exists_nonneg /-- `f = O(g)` if and only if `IsBigOWith c f g` for all sufficiently large `c`. -/ theorem isBigO_iff_eventually_isBigOWith : f =O[l] g' ↔ ∀ᶠ c in atTop, IsBigOWith c l f g' := isBigO_iff_isBigOWith.trans ⟨fun ⟨c, hc⟩ => mem_atTop_sets.2 ⟨c, fun _c' hc' => hc.weaken hc'⟩, fun h => h.exists⟩ #align asymptotics.is_O_iff_eventually_is_O_with Asymptotics.isBigO_iff_eventually_isBigOWith /-- `f = O(g)` if and only if `∀ᶠ x in l, ‖f x‖ ≤ c * ‖g x‖` for all sufficiently large `c`. -/ theorem isBigO_iff_eventually : f =O[l] g' ↔ ∀ᶠ c in atTop, ∀ᶠ x in l, ‖f x‖ ≤ c * ‖g' x‖ := isBigO_iff_eventually_isBigOWith.trans <| by simp only [IsBigOWith_def] #align asymptotics.is_O_iff_eventually Asymptotics.isBigO_iff_eventually theorem IsBigO.exists_mem_basis {ι} {p : ι → Prop} {s : ι → Set α} (h : f =O[l] g') (hb : l.HasBasis p s) : ∃ c > 0, ∃ i : ι, p i ∧ ∀ x ∈ s i, ‖f x‖ ≤ c * ‖g' x‖ := flip Exists.imp h.exists_pos fun c h => by simpa only [isBigOWith_iff, hb.eventually_iff, exists_prop] using h #align asymptotics.is_O.exists_mem_basis Asymptotics.IsBigO.exists_mem_basis theorem isBigOWith_inv (hc : 0 < c) : IsBigOWith c⁻¹ l f g ↔ ∀ᶠ x in l, c * ‖f x‖ ≤ ‖g x‖ := by simp only [IsBigOWith_def, ← div_eq_inv_mul, le_div_iff' hc] #align asymptotics.is_O_with_inv Asymptotics.isBigOWith_inv -- We prove this lemma with strange assumptions to get two lemmas below automatically theorem isLittleO_iff_nat_mul_le_aux (h₀ : (∀ x, 0 ≤ ‖f x‖) ∨ ∀ x, 0 ≤ ‖g x‖) : f =o[l] g ↔ ∀ n : ℕ, ∀ᶠ x in l, ↑n * ‖f x‖ ≤ ‖g x‖ := by constructor · rintro H (_ | n) · refine (H.def one_pos).mono fun x h₀' => ?_ rw [Nat.cast_zero, zero_mul] refine h₀.elim (fun hf => (hf x).trans ?_) fun hg => hg x rwa [one_mul] at h₀' · have : (0 : ℝ) < n.succ := Nat.cast_pos.2 n.succ_pos exact (isBigOWith_inv this).1 (H.def' <| inv_pos.2 this) · refine fun H => isLittleO_iff.2 fun ε ε0 => ?_ rcases exists_nat_gt ε⁻¹ with ⟨n, hn⟩ have hn₀ : (0 : ℝ) < n := (inv_pos.2 ε0).trans hn refine ((isBigOWith_inv hn₀).2 (H n)).bound.mono fun x hfg => ?_ refine hfg.trans (mul_le_mul_of_nonneg_right (inv_le_of_inv_le ε0 hn.le) ?_) refine h₀.elim (fun hf => nonneg_of_mul_nonneg_right ((hf x).trans hfg) ?_) fun h => h x exact inv_pos.2 hn₀ #align asymptotics.is_o_iff_nat_mul_le_aux Asymptotics.isLittleO_iff_nat_mul_le_aux theorem isLittleO_iff_nat_mul_le : f =o[l] g' ↔ ∀ n : ℕ, ∀ᶠ x in l, ↑n * ‖f x‖ ≤ ‖g' x‖ := isLittleO_iff_nat_mul_le_aux (Or.inr fun _x => norm_nonneg _) #align asymptotics.is_o_iff_nat_mul_le Asymptotics.isLittleO_iff_nat_mul_le theorem isLittleO_iff_nat_mul_le' : f' =o[l] g ↔ ∀ n : ℕ, ∀ᶠ x in l, ↑n * ‖f' x‖ ≤ ‖g x‖ := isLittleO_iff_nat_mul_le_aux (Or.inl fun _x => norm_nonneg _) #align asymptotics.is_o_iff_nat_mul_le' Asymptotics.isLittleO_iff_nat_mul_le' /-! ### Subsingleton -/ @[nontriviality] theorem isLittleO_of_subsingleton [Subsingleton E'] : f' =o[l] g' := IsLittleO.of_bound fun c hc => by simp [Subsingleton.elim (f' _) 0, mul_nonneg hc.le] #align asymptotics.is_o_of_subsingleton Asymptotics.isLittleO_of_subsingleton @[nontriviality] theorem isBigO_of_subsingleton [Subsingleton E'] : f' =O[l] g' := isLittleO_of_subsingleton.isBigO #align asymptotics.is_O_of_subsingleton Asymptotics.isBigO_of_subsingleton section congr variable {f₁ f₂ : α → E} {g₁ g₂ : α → F} /-! ### Congruence -/ theorem isBigOWith_congr (hc : c₁ = c₂) (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : IsBigOWith c₁ l f₁ g₁ ↔ IsBigOWith c₂ l f₂ g₂ := by simp only [IsBigOWith_def] subst c₂ apply Filter.eventually_congr filter_upwards [hf, hg] with _ e₁ e₂ rw [e₁, e₂] #align asymptotics.is_O_with_congr Asymptotics.isBigOWith_congr theorem IsBigOWith.congr' (h : IsBigOWith c₁ l f₁ g₁) (hc : c₁ = c₂) (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : IsBigOWith c₂ l f₂ g₂ := (isBigOWith_congr hc hf hg).mp h #align asymptotics.is_O_with.congr' Asymptotics.IsBigOWith.congr' theorem IsBigOWith.congr (h : IsBigOWith c₁ l f₁ g₁) (hc : c₁ = c₂) (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) : IsBigOWith c₂ l f₂ g₂ := h.congr' hc (univ_mem' hf) (univ_mem' hg) #align asymptotics.is_O_with.congr Asymptotics.IsBigOWith.congr theorem IsBigOWith.congr_left (h : IsBigOWith c l f₁ g) (hf : ∀ x, f₁ x = f₂ x) : IsBigOWith c l f₂ g := h.congr rfl hf fun _ => rfl #align asymptotics.is_O_with.congr_left Asymptotics.IsBigOWith.congr_left theorem IsBigOWith.congr_right (h : IsBigOWith c l f g₁) (hg : ∀ x, g₁ x = g₂ x) : IsBigOWith c l f g₂ := h.congr rfl (fun _ => rfl) hg #align asymptotics.is_O_with.congr_right Asymptotics.IsBigOWith.congr_right theorem IsBigOWith.congr_const (h : IsBigOWith c₁ l f g) (hc : c₁ = c₂) : IsBigOWith c₂ l f g := h.congr hc (fun _ => rfl) fun _ => rfl #align asymptotics.is_O_with.congr_const Asymptotics.IsBigOWith.congr_const theorem isBigO_congr (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : f₁ =O[l] g₁ ↔ f₂ =O[l] g₂ := by simp only [IsBigO_def] exact exists_congr fun c => isBigOWith_congr rfl hf hg #align asymptotics.is_O_congr Asymptotics.isBigO_congr theorem IsBigO.congr' (h : f₁ =O[l] g₁) (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : f₂ =O[l] g₂ := (isBigO_congr hf hg).mp h #align asymptotics.is_O.congr' Asymptotics.IsBigO.congr' theorem IsBigO.congr (h : f₁ =O[l] g₁) (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) : f₂ =O[l] g₂ := h.congr' (univ_mem' hf) (univ_mem' hg) #align asymptotics.is_O.congr Asymptotics.IsBigO.congr theorem IsBigO.congr_left (h : f₁ =O[l] g) (hf : ∀ x, f₁ x = f₂ x) : f₂ =O[l] g := h.congr hf fun _ => rfl #align asymptotics.is_O.congr_left Asymptotics.IsBigO.congr_left theorem IsBigO.congr_right (h : f =O[l] g₁) (hg : ∀ x, g₁ x = g₂ x) : f =O[l] g₂ := h.congr (fun _ => rfl) hg #align asymptotics.is_O.congr_right Asymptotics.IsBigO.congr_right theorem isLittleO_congr (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : f₁ =o[l] g₁ ↔ f₂ =o[l] g₂ := by simp only [IsLittleO_def] exact forall₂_congr fun c _hc => isBigOWith_congr (Eq.refl c) hf hg #align asymptotics.is_o_congr Asymptotics.isLittleO_congr theorem IsLittleO.congr' (h : f₁ =o[l] g₁) (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) : f₂ =o[l] g₂ := (isLittleO_congr hf hg).mp h #align asymptotics.is_o.congr' Asymptotics.IsLittleO.congr' theorem IsLittleO.congr (h : f₁ =o[l] g₁) (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) : f₂ =o[l] g₂ := h.congr' (univ_mem' hf) (univ_mem' hg) #align asymptotics.is_o.congr Asymptotics.IsLittleO.congr theorem IsLittleO.congr_left (h : f₁ =o[l] g) (hf : ∀ x, f₁ x = f₂ x) : f₂ =o[l] g := h.congr hf fun _ => rfl #align asymptotics.is_o.congr_left Asymptotics.IsLittleO.congr_left theorem IsLittleO.congr_right (h : f =o[l] g₁) (hg : ∀ x, g₁ x = g₂ x) : f =o[l] g₂ := h.congr (fun _ => rfl) hg #align asymptotics.is_o.congr_right Asymptotics.IsLittleO.congr_right @[trans] theorem _root_.Filter.EventuallyEq.trans_isBigO {f₁ f₂ : α → E} {g : α → F} (hf : f₁ =ᶠ[l] f₂) (h : f₂ =O[l] g) : f₁ =O[l] g := h.congr' hf.symm EventuallyEq.rfl #align filter.eventually_eq.trans_is_O Filter.EventuallyEq.trans_isBigO instance transEventuallyEqIsBigO : @Trans (α → E) (α → E) (α → F) (· =ᶠ[l] ·) (· =O[l] ·) (· =O[l] ·) where trans := Filter.EventuallyEq.trans_isBigO @[trans] theorem _root_.Filter.EventuallyEq.trans_isLittleO {f₁ f₂ : α → E} {g : α → F} (hf : f₁ =ᶠ[l] f₂) (h : f₂ =o[l] g) : f₁ =o[l] g := h.congr' hf.symm EventuallyEq.rfl #align filter.eventually_eq.trans_is_o Filter.EventuallyEq.trans_isLittleO instance transEventuallyEqIsLittleO : @Trans (α → E) (α → E) (α → F) (· =ᶠ[l] ·) (· =o[l] ·) (· =o[l] ·) where trans := Filter.EventuallyEq.trans_isLittleO @[trans] theorem IsBigO.trans_eventuallyEq {f : α → E} {g₁ g₂ : α → F} (h : f =O[l] g₁) (hg : g₁ =ᶠ[l] g₂) : f =O[l] g₂ := h.congr' EventuallyEq.rfl hg #align asymptotics.is_O.trans_eventually_eq Asymptotics.IsBigO.trans_eventuallyEq instance transIsBigOEventuallyEq : @Trans (α → E) (α → F) (α → F) (· =O[l] ·) (· =ᶠ[l] ·) (· =O[l] ·) where trans := IsBigO.trans_eventuallyEq @[trans] theorem IsLittleO.trans_eventuallyEq {f : α → E} {g₁ g₂ : α → F} (h : f =o[l] g₁) (hg : g₁ =ᶠ[l] g₂) : f =o[l] g₂ := h.congr' EventuallyEq.rfl hg #align asymptotics.is_o.trans_eventually_eq Asymptotics.IsLittleO.trans_eventuallyEq instance transIsLittleOEventuallyEq : @Trans (α → E) (α → F) (α → F) (· =o[l] ·) (· =ᶠ[l] ·) (· =o[l] ·) where trans := IsLittleO.trans_eventuallyEq end congr /-! ### Filter operations and transitivity -/ theorem IsBigOWith.comp_tendsto (hcfg : IsBigOWith c l f g) {k : β → α} {l' : Filter β} (hk : Tendsto k l' l) : IsBigOWith c l' (f ∘ k) (g ∘ k) := IsBigOWith.of_bound <| hk hcfg.bound #align asymptotics.is_O_with.comp_tendsto Asymptotics.IsBigOWith.comp_tendsto theorem IsBigO.comp_tendsto (hfg : f =O[l] g) {k : β → α} {l' : Filter β} (hk : Tendsto k l' l) : (f ∘ k) =O[l'] (g ∘ k) := isBigO_iff_isBigOWith.2 <| hfg.isBigOWith.imp fun _c h => h.comp_tendsto hk #align asymptotics.is_O.comp_tendsto Asymptotics.IsBigO.comp_tendsto theorem IsLittleO.comp_tendsto (hfg : f =o[l] g) {k : β → α} {l' : Filter β} (hk : Tendsto k l' l) : (f ∘ k) =o[l'] (g ∘ k) := IsLittleO.of_isBigOWith fun _c cpos => (hfg.forall_isBigOWith cpos).comp_tendsto hk #align asymptotics.is_o.comp_tendsto Asymptotics.IsLittleO.comp_tendsto @[simp] theorem isBigOWith_map {k : β → α} {l : Filter β} : IsBigOWith c (map k l) f g ↔ IsBigOWith c l (f ∘ k) (g ∘ k) := by simp only [IsBigOWith_def] exact eventually_map #align asymptotics.is_O_with_map Asymptotics.isBigOWith_map @[simp] theorem isBigO_map {k : β → α} {l : Filter β} : f =O[map k l] g ↔ (f ∘ k) =O[l] (g ∘ k) := by simp only [IsBigO_def, isBigOWith_map] #align asymptotics.is_O_map Asymptotics.isBigO_map @[simp] theorem isLittleO_map {k : β → α} {l : Filter β} : f =o[map k l] g ↔ (f ∘ k) =o[l] (g ∘ k) := by simp only [IsLittleO_def, isBigOWith_map] #align asymptotics.is_o_map Asymptotics.isLittleO_map theorem IsBigOWith.mono (h : IsBigOWith c l' f g) (hl : l ≤ l') : IsBigOWith c l f g := IsBigOWith.of_bound <| hl h.bound #align asymptotics.is_O_with.mono Asymptotics.IsBigOWith.mono theorem IsBigO.mono (h : f =O[l'] g) (hl : l ≤ l') : f =O[l] g := isBigO_iff_isBigOWith.2 <| h.isBigOWith.imp fun _c h => h.mono hl #align asymptotics.is_O.mono Asymptotics.IsBigO.mono theorem IsLittleO.mono (h : f =o[l'] g) (hl : l ≤ l') : f =o[l] g := IsLittleO.of_isBigOWith fun _c cpos => (h.forall_isBigOWith cpos).mono hl #align asymptotics.is_o.mono Asymptotics.IsLittleO.mono theorem IsBigOWith.trans (hfg : IsBigOWith c l f g) (hgk : IsBigOWith c' l g k) (hc : 0 ≤ c) : IsBigOWith (c * c') l f k := by simp only [IsBigOWith_def] at * filter_upwards [hfg, hgk] with x hx hx' calc ‖f x‖ ≤ c * ‖g x‖ := hx _ ≤ c * (c' * ‖k x‖) := by gcongr _ = c * c' * ‖k x‖ := (mul_assoc _ _ _).symm #align asymptotics.is_O_with.trans Asymptotics.IsBigOWith.trans @[trans] theorem IsBigO.trans {f : α → E} {g : α → F'} {k : α → G} (hfg : f =O[l] g) (hgk : g =O[l] k) : f =O[l] k := let ⟨_c, cnonneg, hc⟩ := hfg.exists_nonneg let ⟨_c', hc'⟩ := hgk.isBigOWith (hc.trans hc' cnonneg).isBigO #align asymptotics.is_O.trans Asymptotics.IsBigO.trans instance transIsBigOIsBigO : @Trans (α → E) (α → F') (α → G) (· =O[l] ·) (· =O[l] ·) (· =O[l] ·) where trans := IsBigO.trans theorem IsLittleO.trans_isBigOWith (hfg : f =o[l] g) (hgk : IsBigOWith c l g k) (hc : 0 < c) : f =o[l] k := by simp only [IsLittleO_def] at * intro c' c'pos have : 0 < c' / c := div_pos c'pos hc exact ((hfg this).trans hgk this.le).congr_const (div_mul_cancel₀ _ hc.ne') #align asymptotics.is_o.trans_is_O_with Asymptotics.IsLittleO.trans_isBigOWith @[trans] theorem IsLittleO.trans_isBigO {f : α → E} {g : α → F} {k : α → G'} (hfg : f =o[l] g) (hgk : g =O[l] k) : f =o[l] k := let ⟨_c, cpos, hc⟩ := hgk.exists_pos hfg.trans_isBigOWith hc cpos #align asymptotics.is_o.trans_is_O Asymptotics.IsLittleO.trans_isBigO instance transIsLittleOIsBigO : @Trans (α → E) (α → F) (α → G') (· =o[l] ·) (· =O[l] ·) (· =o[l] ·) where trans := IsLittleO.trans_isBigO theorem IsBigOWith.trans_isLittleO (hfg : IsBigOWith c l f g) (hgk : g =o[l] k) (hc : 0 < c) : f =o[l] k := by simp only [IsLittleO_def] at * intro c' c'pos have : 0 < c' / c := div_pos c'pos hc exact (hfg.trans (hgk this) hc.le).congr_const (mul_div_cancel₀ _ hc.ne') #align asymptotics.is_O_with.trans_is_o Asymptotics.IsBigOWith.trans_isLittleO @[trans] theorem IsBigO.trans_isLittleO {f : α → E} {g : α → F'} {k : α → G} (hfg : f =O[l] g) (hgk : g =o[l] k) : f =o[l] k := let ⟨_c, cpos, hc⟩ := hfg.exists_pos hc.trans_isLittleO hgk cpos #align asymptotics.is_O.trans_is_o Asymptotics.IsBigO.trans_isLittleO instance transIsBigOIsLittleO : @Trans (α → E) (α → F') (α → G) (· =O[l] ·) (· =o[l] ·) (· =o[l] ·) where trans := IsBigO.trans_isLittleO @[trans] theorem IsLittleO.trans {f : α → E} {g : α → F} {k : α → G} (hfg : f =o[l] g) (hgk : g =o[l] k) : f =o[l] k := hfg.trans_isBigOWith hgk.isBigOWith one_pos #align asymptotics.is_o.trans Asymptotics.IsLittleO.trans instance transIsLittleOIsLittleO : @Trans (α → E) (α → F) (α → G) (· =o[l] ·) (· =o[l] ·) (· =o[l] ·) where trans := IsLittleO.trans theorem _root_.Filter.Eventually.trans_isBigO {f : α → E} {g : α → F'} {k : α → G} (hfg : ∀ᶠ x in l, ‖f x‖ ≤ ‖g x‖) (hgk : g =O[l] k) : f =O[l] k := (IsBigO.of_bound' hfg).trans hgk #align filter.eventually.trans_is_O Filter.Eventually.trans_isBigO theorem _root_.Filter.Eventually.isBigO {f : α → E} {g : α → ℝ} {l : Filter α} (hfg : ∀ᶠ x in l, ‖f x‖ ≤ g x) : f =O[l] g := IsBigO.of_bound' <| hfg.mono fun _x hx => hx.trans <| Real.le_norm_self _ #align filter.eventually.is_O Filter.Eventually.isBigO section variable (l) theorem isBigOWith_of_le' (hfg : ∀ x, ‖f x‖ ≤ c * ‖g x‖) : IsBigOWith c l f g := IsBigOWith.of_bound <| univ_mem' hfg #align asymptotics.is_O_with_of_le' Asymptotics.isBigOWith_of_le' theorem isBigOWith_of_le (hfg : ∀ x, ‖f x‖ ≤ ‖g x‖) : IsBigOWith 1 l f g := isBigOWith_of_le' l fun x => by rw [one_mul] exact hfg x #align asymptotics.is_O_with_of_le Asymptotics.isBigOWith_of_le theorem isBigO_of_le' (hfg : ∀ x, ‖f x‖ ≤ c * ‖g x‖) : f =O[l] g := (isBigOWith_of_le' l hfg).isBigO #align asymptotics.is_O_of_le' Asymptotics.isBigO_of_le' theorem isBigO_of_le (hfg : ∀ x, ‖f x‖ ≤ ‖g x‖) : f =O[l] g := (isBigOWith_of_le l hfg).isBigO #align asymptotics.is_O_of_le Asymptotics.isBigO_of_le end theorem isBigOWith_refl (f : α → E) (l : Filter α) : IsBigOWith 1 l f f := isBigOWith_of_le l fun _ => le_rfl #align asymptotics.is_O_with_refl Asymptotics.isBigOWith_refl theorem isBigO_refl (f : α → E) (l : Filter α) : f =O[l] f := (isBigOWith_refl f l).isBigO #align asymptotics.is_O_refl Asymptotics.isBigO_refl theorem _root_.Filter.EventuallyEq.isBigO {f₁ f₂ : α → E} (hf : f₁ =ᶠ[l] f₂) : f₁ =O[l] f₂ := hf.trans_isBigO (isBigO_refl _ _) theorem IsBigOWith.trans_le (hfg : IsBigOWith c l f g) (hgk : ∀ x, ‖g x‖ ≤ ‖k x‖) (hc : 0 ≤ c) : IsBigOWith c l f k := (hfg.trans (isBigOWith_of_le l hgk) hc).congr_const <| mul_one c #align asymptotics.is_O_with.trans_le Asymptotics.IsBigOWith.trans_le theorem IsBigO.trans_le (hfg : f =O[l] g') (hgk : ∀ x, ‖g' x‖ ≤ ‖k x‖) : f =O[l] k := hfg.trans (isBigO_of_le l hgk) #align asymptotics.is_O.trans_le Asymptotics.IsBigO.trans_le theorem IsLittleO.trans_le (hfg : f =o[l] g) (hgk : ∀ x, ‖g x‖ ≤ ‖k x‖) : f =o[l] k := hfg.trans_isBigOWith (isBigOWith_of_le _ hgk) zero_lt_one #align asymptotics.is_o.trans_le Asymptotics.IsLittleO.trans_le theorem isLittleO_irrefl' (h : ∃ᶠ x in l, ‖f' x‖ ≠ 0) : ¬f' =o[l] f' := by intro ho rcases ((ho.bound one_half_pos).and_frequently h).exists with ⟨x, hle, hne⟩ rw [one_div, ← div_eq_inv_mul] at hle exact (half_lt_self (lt_of_le_of_ne (norm_nonneg _) hne.symm)).not_le hle #align asymptotics.is_o_irrefl' Asymptotics.isLittleO_irrefl' theorem isLittleO_irrefl (h : ∃ᶠ x in l, f'' x ≠ 0) : ¬f'' =o[l] f'' := isLittleO_irrefl' <| h.mono fun _x => norm_ne_zero_iff.mpr #align asymptotics.is_o_irrefl Asymptotics.isLittleO_irrefl theorem IsBigO.not_isLittleO (h : f'' =O[l] g') (hf : ∃ᶠ x in l, f'' x ≠ 0) : ¬g' =o[l] f'' := fun h' => isLittleO_irrefl hf (h.trans_isLittleO h') #align asymptotics.is_O.not_is_o Asymptotics.IsBigO.not_isLittleO theorem IsLittleO.not_isBigO (h : f'' =o[l] g') (hf : ∃ᶠ x in l, f'' x ≠ 0) : ¬g' =O[l] f'' := fun h' => isLittleO_irrefl hf (h.trans_isBigO h') #align asymptotics.is_o.not_is_O Asymptotics.IsLittleO.not_isBigO section Bot variable (c f g) @[simp] theorem isBigOWith_bot : IsBigOWith c ⊥ f g := IsBigOWith.of_bound <| trivial #align asymptotics.is_O_with_bot Asymptotics.isBigOWith_bot @[simp] theorem isBigO_bot : f =O[⊥] g := (isBigOWith_bot 1 f g).isBigO #align asymptotics.is_O_bot Asymptotics.isBigO_bot @[simp] theorem isLittleO_bot : f =o[⊥] g := IsLittleO.of_isBigOWith fun c _ => isBigOWith_bot c f g #align asymptotics.is_o_bot Asymptotics.isLittleO_bot end Bot @[simp] theorem isBigOWith_pure {x} : IsBigOWith c (pure x) f g ↔ ‖f x‖ ≤ c * ‖g x‖ := isBigOWith_iff #align asymptotics.is_O_with_pure Asymptotics.isBigOWith_pure theorem IsBigOWith.sup (h : IsBigOWith c l f g) (h' : IsBigOWith c l' f g) : IsBigOWith c (l ⊔ l') f g := IsBigOWith.of_bound <| mem_sup.2 ⟨h.bound, h'.bound⟩ #align asymptotics.is_O_with.sup Asymptotics.IsBigOWith.sup theorem IsBigOWith.sup' (h : IsBigOWith c l f g') (h' : IsBigOWith c' l' f g') : IsBigOWith (max c c') (l ⊔ l') f g' := IsBigOWith.of_bound <| mem_sup.2 ⟨(h.weaken <| le_max_left c c').bound, (h'.weaken <| le_max_right c c').bound⟩ #align asymptotics.is_O_with.sup' Asymptotics.IsBigOWith.sup' theorem IsBigO.sup (h : f =O[l] g') (h' : f =O[l'] g') : f =O[l ⊔ l'] g' := let ⟨_c, hc⟩ := h.isBigOWith let ⟨_c', hc'⟩ := h'.isBigOWith (hc.sup' hc').isBigO #align asymptotics.is_O.sup Asymptotics.IsBigO.sup theorem IsLittleO.sup (h : f =o[l] g) (h' : f =o[l'] g) : f =o[l ⊔ l'] g := IsLittleO.of_isBigOWith fun _c cpos => (h.forall_isBigOWith cpos).sup (h'.forall_isBigOWith cpos) #align asymptotics.is_o.sup Asymptotics.IsLittleO.sup @[simp] theorem isBigO_sup : f =O[l ⊔ l'] g' ↔ f =O[l] g' ∧ f =O[l'] g' := ⟨fun h => ⟨h.mono le_sup_left, h.mono le_sup_right⟩, fun h => h.1.sup h.2⟩ #align asymptotics.is_O_sup Asymptotics.isBigO_sup @[simp] theorem isLittleO_sup : f =o[l ⊔ l'] g ↔ f =o[l] g ∧ f =o[l'] g := ⟨fun h => ⟨h.mono le_sup_left, h.mono le_sup_right⟩, fun h => h.1.sup h.2⟩ #align asymptotics.is_o_sup Asymptotics.isLittleO_sup theorem isBigOWith_insert [TopologicalSpace α] {x : α} {s : Set α} {C : ℝ} {g : α → E} {g' : α → F} (h : ‖g x‖ ≤ C * ‖g' x‖) : IsBigOWith C (𝓝[insert x s] x) g g' ↔ IsBigOWith C (𝓝[s] x) g g' := by simp_rw [IsBigOWith_def, nhdsWithin_insert, eventually_sup, eventually_pure, h, true_and_iff] #align asymptotics.is_O_with_insert Asymptotics.isBigOWith_insert protected theorem IsBigOWith.insert [TopologicalSpace α] {x : α} {s : Set α} {C : ℝ} {g : α → E} {g' : α → F} (h1 : IsBigOWith C (𝓝[s] x) g g') (h2 : ‖g x‖ ≤ C * ‖g' x‖) : IsBigOWith C (𝓝[insert x s] x) g g' := (isBigOWith_insert h2).mpr h1 #align asymptotics.is_O_with.insert Asymptotics.IsBigOWith.insert theorem isLittleO_insert [TopologicalSpace α] {x : α} {s : Set α} {g : α → E'} {g' : α → F'} (h : g x = 0) : g =o[𝓝[insert x s] x] g' ↔ g =o[𝓝[s] x] g' := by simp_rw [IsLittleO_def] refine forall_congr' fun c => forall_congr' fun hc => ?_ rw [isBigOWith_insert] rw [h, norm_zero] exact mul_nonneg hc.le (norm_nonneg _) #align asymptotics.is_o_insert Asymptotics.isLittleO_insert protected theorem IsLittleO.insert [TopologicalSpace α] {x : α} {s : Set α} {g : α → E'} {g' : α → F'} (h1 : g =o[𝓝[s] x] g') (h2 : g x = 0) : g =o[𝓝[insert x s] x] g' := (isLittleO_insert h2).mpr h1 #align asymptotics.is_o.insert Asymptotics.IsLittleO.insert /-! ### Simplification : norm, abs -/ section NormAbs variable {u v : α → ℝ} @[simp] theorem isBigOWith_norm_right : (IsBigOWith c l f fun x => ‖g' x‖) ↔ IsBigOWith c l f g' := by simp only [IsBigOWith_def, norm_norm] #align asymptotics.is_O_with_norm_right Asymptotics.isBigOWith_norm_right @[simp] theorem isBigOWith_abs_right : (IsBigOWith c l f fun x => |u x|) ↔ IsBigOWith c l f u := @isBigOWith_norm_right _ _ _ _ _ _ f u l #align asymptotics.is_O_with_abs_right Asymptotics.isBigOWith_abs_right alias ⟨IsBigOWith.of_norm_right, IsBigOWith.norm_right⟩ := isBigOWith_norm_right #align asymptotics.is_O_with.of_norm_right Asymptotics.IsBigOWith.of_norm_right #align asymptotics.is_O_with.norm_right Asymptotics.IsBigOWith.norm_right alias ⟨IsBigOWith.of_abs_right, IsBigOWith.abs_right⟩ := isBigOWith_abs_right #align asymptotics.is_O_with.of_abs_right Asymptotics.IsBigOWith.of_abs_right #align asymptotics.is_O_with.abs_right Asymptotics.IsBigOWith.abs_right @[simp] theorem isBigO_norm_right : (f =O[l] fun x => ‖g' x‖) ↔ f =O[l] g' := by simp only [IsBigO_def] exact exists_congr fun _ => isBigOWith_norm_right #align asymptotics.is_O_norm_right Asymptotics.isBigO_norm_right @[simp] theorem isBigO_abs_right : (f =O[l] fun x => |u x|) ↔ f =O[l] u := @isBigO_norm_right _ _ ℝ _ _ _ _ _ #align asymptotics.is_O_abs_right Asymptotics.isBigO_abs_right alias ⟨IsBigO.of_norm_right, IsBigO.norm_right⟩ := isBigO_norm_right #align asymptotics.is_O.of_norm_right Asymptotics.IsBigO.of_norm_right #align asymptotics.is_O.norm_right Asymptotics.IsBigO.norm_right alias ⟨IsBigO.of_abs_right, IsBigO.abs_right⟩ := isBigO_abs_right #align asymptotics.is_O.of_abs_right Asymptotics.IsBigO.of_abs_right #align asymptotics.is_O.abs_right Asymptotics.IsBigO.abs_right @[simp] theorem isLittleO_norm_right : (f =o[l] fun x => ‖g' x‖) ↔ f =o[l] g' := by simp only [IsLittleO_def] exact forall₂_congr fun _ _ => isBigOWith_norm_right #align asymptotics.is_o_norm_right Asymptotics.isLittleO_norm_right @[simp] theorem isLittleO_abs_right : (f =o[l] fun x => |u x|) ↔ f =o[l] u := @isLittleO_norm_right _ _ ℝ _ _ _ _ _ #align asymptotics.is_o_abs_right Asymptotics.isLittleO_abs_right alias ⟨IsLittleO.of_norm_right, IsLittleO.norm_right⟩ := isLittleO_norm_right #align asymptotics.is_o.of_norm_right Asymptotics.IsLittleO.of_norm_right #align asymptotics.is_o.norm_right Asymptotics.IsLittleO.norm_right alias ⟨IsLittleO.of_abs_right, IsLittleO.abs_right⟩ := isLittleO_abs_right #align asymptotics.is_o.of_abs_right Asymptotics.IsLittleO.of_abs_right #align asymptotics.is_o.abs_right Asymptotics.IsLittleO.abs_right @[simp] theorem isBigOWith_norm_left : IsBigOWith c l (fun x => ‖f' x‖) g ↔ IsBigOWith c l f' g := by simp only [IsBigOWith_def, norm_norm] #align asymptotics.is_O_with_norm_left Asymptotics.isBigOWith_norm_left @[simp] theorem isBigOWith_abs_left : IsBigOWith c l (fun x => |u x|) g ↔ IsBigOWith c l u g := @isBigOWith_norm_left _ _ _ _ _ _ g u l #align asymptotics.is_O_with_abs_left Asymptotics.isBigOWith_abs_left alias ⟨IsBigOWith.of_norm_left, IsBigOWith.norm_left⟩ := isBigOWith_norm_left #align asymptotics.is_O_with.of_norm_left Asymptotics.IsBigOWith.of_norm_left #align asymptotics.is_O_with.norm_left Asymptotics.IsBigOWith.norm_left alias ⟨IsBigOWith.of_abs_left, IsBigOWith.abs_left⟩ := isBigOWith_abs_left #align asymptotics.is_O_with.of_abs_left Asymptotics.IsBigOWith.of_abs_left #align asymptotics.is_O_with.abs_left Asymptotics.IsBigOWith.abs_left @[simp] theorem isBigO_norm_left : (fun x => ‖f' x‖) =O[l] g ↔ f' =O[l] g := by simp only [IsBigO_def] exact exists_congr fun _ => isBigOWith_norm_left #align asymptotics.is_O_norm_left Asymptotics.isBigO_norm_left @[simp] theorem isBigO_abs_left : (fun x => |u x|) =O[l] g ↔ u =O[l] g := @isBigO_norm_left _ _ _ _ _ g u l #align asymptotics.is_O_abs_left Asymptotics.isBigO_abs_left alias ⟨IsBigO.of_norm_left, IsBigO.norm_left⟩ := isBigO_norm_left #align asymptotics.is_O.of_norm_left Asymptotics.IsBigO.of_norm_left #align asymptotics.is_O.norm_left Asymptotics.IsBigO.norm_left alias ⟨IsBigO.of_abs_left, IsBigO.abs_left⟩ := isBigO_abs_left #align asymptotics.is_O.of_abs_left Asymptotics.IsBigO.of_abs_left #align asymptotics.is_O.abs_left Asymptotics.IsBigO.abs_left @[simp] theorem isLittleO_norm_left : (fun x => ‖f' x‖) =o[l] g ↔ f' =o[l] g := by simp only [IsLittleO_def] exact forall₂_congr fun _ _ => isBigOWith_norm_left #align asymptotics.is_o_norm_left Asymptotics.isLittleO_norm_left @[simp] theorem isLittleO_abs_left : (fun x => |u x|) =o[l] g ↔ u =o[l] g := @isLittleO_norm_left _ _ _ _ _ g u l #align asymptotics.is_o_abs_left Asymptotics.isLittleO_abs_left alias ⟨IsLittleO.of_norm_left, IsLittleO.norm_left⟩ := isLittleO_norm_left #align asymptotics.is_o.of_norm_left Asymptotics.IsLittleO.of_norm_left #align asymptotics.is_o.norm_left Asymptotics.IsLittleO.norm_left alias ⟨IsLittleO.of_abs_left, IsLittleO.abs_left⟩ := isLittleO_abs_left #align asymptotics.is_o.of_abs_left Asymptotics.IsLittleO.of_abs_left #align asymptotics.is_o.abs_left Asymptotics.IsLittleO.abs_left theorem isBigOWith_norm_norm : (IsBigOWith c l (fun x => ‖f' x‖) fun x => ‖g' x‖) ↔ IsBigOWith c l f' g' := isBigOWith_norm_left.trans isBigOWith_norm_right #align asymptotics.is_O_with_norm_norm Asymptotics.isBigOWith_norm_norm theorem isBigOWith_abs_abs : (IsBigOWith c l (fun x => |u x|) fun x => |v x|) ↔ IsBigOWith c l u v := isBigOWith_abs_left.trans isBigOWith_abs_right #align asymptotics.is_O_with_abs_abs Asymptotics.isBigOWith_abs_abs alias ⟨IsBigOWith.of_norm_norm, IsBigOWith.norm_norm⟩ := isBigOWith_norm_norm #align asymptotics.is_O_with.of_norm_norm Asymptotics.IsBigOWith.of_norm_norm #align asymptotics.is_O_with.norm_norm Asymptotics.IsBigOWith.norm_norm alias ⟨IsBigOWith.of_abs_abs, IsBigOWith.abs_abs⟩ := isBigOWith_abs_abs #align asymptotics.is_O_with.of_abs_abs Asymptotics.IsBigOWith.of_abs_abs #align asymptotics.is_O_with.abs_abs Asymptotics.IsBigOWith.abs_abs theorem isBigO_norm_norm : ((fun x => ‖f' x‖) =O[l] fun x => ‖g' x‖) ↔ f' =O[l] g' := isBigO_norm_left.trans isBigO_norm_right #align asymptotics.is_O_norm_norm Asymptotics.isBigO_norm_norm theorem isBigO_abs_abs : ((fun x => |u x|) =O[l] fun x => |v x|) ↔ u =O[l] v := isBigO_abs_left.trans isBigO_abs_right #align asymptotics.is_O_abs_abs Asymptotics.isBigO_abs_abs alias ⟨IsBigO.of_norm_norm, IsBigO.norm_norm⟩ := isBigO_norm_norm #align asymptotics.is_O.of_norm_norm Asymptotics.IsBigO.of_norm_norm #align asymptotics.is_O.norm_norm Asymptotics.IsBigO.norm_norm alias ⟨IsBigO.of_abs_abs, IsBigO.abs_abs⟩ := isBigO_abs_abs #align asymptotics.is_O.of_abs_abs Asymptotics.IsBigO.of_abs_abs #align asymptotics.is_O.abs_abs Asymptotics.IsBigO.abs_abs theorem isLittleO_norm_norm : ((fun x => ‖f' x‖) =o[l] fun x => ‖g' x‖) ↔ f' =o[l] g' := isLittleO_norm_left.trans isLittleO_norm_right #align asymptotics.is_o_norm_norm Asymptotics.isLittleO_norm_norm theorem isLittleO_abs_abs : ((fun x => |u x|) =o[l] fun x => |v x|) ↔ u =o[l] v := isLittleO_abs_left.trans isLittleO_abs_right #align asymptotics.is_o_abs_abs Asymptotics.isLittleO_abs_abs alias ⟨IsLittleO.of_norm_norm, IsLittleO.norm_norm⟩ := isLittleO_norm_norm #align asymptotics.is_o.of_norm_norm Asymptotics.IsLittleO.of_norm_norm #align asymptotics.is_o.norm_norm Asymptotics.IsLittleO.norm_norm alias ⟨IsLittleO.of_abs_abs, IsLittleO.abs_abs⟩ := isLittleO_abs_abs #align asymptotics.is_o.of_abs_abs Asymptotics.IsLittleO.of_abs_abs #align asymptotics.is_o.abs_abs Asymptotics.IsLittleO.abs_abs end NormAbs /-! ### Simplification: negate -/ @[simp] theorem isBigOWith_neg_right : (IsBigOWith c l f fun x => -g' x) ↔ IsBigOWith c l f g' := by simp only [IsBigOWith_def, norm_neg] #align asymptotics.is_O_with_neg_right Asymptotics.isBigOWith_neg_right alias ⟨IsBigOWith.of_neg_right, IsBigOWith.neg_right⟩ := isBigOWith_neg_right #align asymptotics.is_O_with.of_neg_right Asymptotics.IsBigOWith.of_neg_right #align asymptotics.is_O_with.neg_right Asymptotics.IsBigOWith.neg_right @[simp] theorem isBigO_neg_right : (f =O[l] fun x => -g' x) ↔ f =O[l] g' := by simp only [IsBigO_def] exact exists_congr fun _ => isBigOWith_neg_right #align asymptotics.is_O_neg_right Asymptotics.isBigO_neg_right alias ⟨IsBigO.of_neg_right, IsBigO.neg_right⟩ := isBigO_neg_right #align asymptotics.is_O.of_neg_right Asymptotics.IsBigO.of_neg_right #align asymptotics.is_O.neg_right Asymptotics.IsBigO.neg_right @[simp] theorem isLittleO_neg_right : (f =o[l] fun x => -g' x) ↔ f =o[l] g' := by simp only [IsLittleO_def] exact forall₂_congr fun _ _ => isBigOWith_neg_right #align asymptotics.is_o_neg_right Asymptotics.isLittleO_neg_right alias ⟨IsLittleO.of_neg_right, IsLittleO.neg_right⟩ := isLittleO_neg_right #align asymptotics.is_o.of_neg_right Asymptotics.IsLittleO.of_neg_right #align asymptotics.is_o.neg_right Asymptotics.IsLittleO.neg_right @[simp] theorem isBigOWith_neg_left : IsBigOWith c l (fun x => -f' x) g ↔ IsBigOWith c l f' g := by simp only [IsBigOWith_def, norm_neg] #align asymptotics.is_O_with_neg_left Asymptotics.isBigOWith_neg_left alias ⟨IsBigOWith.of_neg_left, IsBigOWith.neg_left⟩ := isBigOWith_neg_left #align asymptotics.is_O_with.of_neg_left Asymptotics.IsBigOWith.of_neg_left #align asymptotics.is_O_with.neg_left Asymptotics.IsBigOWith.neg_left @[simp] theorem isBigO_neg_left : (fun x => -f' x) =O[l] g ↔ f' =O[l] g := by simp only [IsBigO_def] exact exists_congr fun _ => isBigOWith_neg_left #align asymptotics.is_O_neg_left Asymptotics.isBigO_neg_left alias ⟨IsBigO.of_neg_left, IsBigO.neg_left⟩ := isBigO_neg_left #align asymptotics.is_O.of_neg_left Asymptotics.IsBigO.of_neg_left #align asymptotics.is_O.neg_left Asymptotics.IsBigO.neg_left @[simp] theorem isLittleO_neg_left : (fun x => -f' x) =o[l] g ↔ f' =o[l] g := by simp only [IsLittleO_def] exact forall₂_congr fun _ _ => isBigOWith_neg_left #align asymptotics.is_o_neg_left Asymptotics.isLittleO_neg_left alias ⟨IsLittleO.of_neg_left, IsLittleO.neg_left⟩ := isLittleO_neg_left #align asymptotics.is_o.of_neg_left Asymptotics.IsLittleO.of_neg_left #align asymptotics.is_o.neg_left Asymptotics.IsLittleO.neg_left /-! ### Product of functions (right) -/ theorem isBigOWith_fst_prod : IsBigOWith 1 l f' fun x => (f' x, g' x) := isBigOWith_of_le l fun _x => le_max_left _ _ #align asymptotics.is_O_with_fst_prod Asymptotics.isBigOWith_fst_prod theorem isBigOWith_snd_prod : IsBigOWith 1 l g' fun x => (f' x, g' x) := isBigOWith_of_le l fun _x => le_max_right _ _ #align asymptotics.is_O_with_snd_prod Asymptotics.isBigOWith_snd_prod theorem isBigO_fst_prod : f' =O[l] fun x => (f' x, g' x) := isBigOWith_fst_prod.isBigO #align asymptotics.is_O_fst_prod Asymptotics.isBigO_fst_prod theorem isBigO_snd_prod : g' =O[l] fun x => (f' x, g' x) := isBigOWith_snd_prod.isBigO #align asymptotics.is_O_snd_prod Asymptotics.isBigO_snd_prod theorem isBigO_fst_prod' {f' : α → E' × F'} : (fun x => (f' x).1) =O[l] f' := by simpa [IsBigO_def, IsBigOWith_def] using isBigO_fst_prod (E' := E') (F' := F') #align asymptotics.is_O_fst_prod' Asymptotics.isBigO_fst_prod' theorem isBigO_snd_prod' {f' : α → E' × F'} : (fun x => (f' x).2) =O[l] f' := by simpa [IsBigO_def, IsBigOWith_def] using isBigO_snd_prod (E' := E') (F' := F') #align asymptotics.is_O_snd_prod' Asymptotics.isBigO_snd_prod' section variable (f' k') theorem IsBigOWith.prod_rightl (h : IsBigOWith c l f g') (hc : 0 ≤ c) : IsBigOWith c l f fun x => (g' x, k' x) := (h.trans isBigOWith_fst_prod hc).congr_const (mul_one c) #align asymptotics.is_O_with.prod_rightl Asymptotics.IsBigOWith.prod_rightl theorem IsBigO.prod_rightl (h : f =O[l] g') : f =O[l] fun x => (g' x, k' x) := let ⟨_c, cnonneg, hc⟩ := h.exists_nonneg (hc.prod_rightl k' cnonneg).isBigO #align asymptotics.is_O.prod_rightl Asymptotics.IsBigO.prod_rightl theorem IsLittleO.prod_rightl (h : f =o[l] g') : f =o[l] fun x => (g' x, k' x) := IsLittleO.of_isBigOWith fun _c cpos => (h.forall_isBigOWith cpos).prod_rightl k' cpos.le #align asymptotics.is_o.prod_rightl Asymptotics.IsLittleO.prod_rightl theorem IsBigOWith.prod_rightr (h : IsBigOWith c l f g') (hc : 0 ≤ c) : IsBigOWith c l f fun x => (f' x, g' x) := (h.trans isBigOWith_snd_prod hc).congr_const (mul_one c) #align asymptotics.is_O_with.prod_rightr Asymptotics.IsBigOWith.prod_rightr theorem IsBigO.prod_rightr (h : f =O[l] g') : f =O[l] fun x => (f' x, g' x) := let ⟨_c, cnonneg, hc⟩ := h.exists_nonneg (hc.prod_rightr f' cnonneg).isBigO #align asymptotics.is_O.prod_rightr Asymptotics.IsBigO.prod_rightr theorem IsLittleO.prod_rightr (h : f =o[l] g') : f =o[l] fun x => (f' x, g' x) := IsLittleO.of_isBigOWith fun _c cpos => (h.forall_isBigOWith cpos).prod_rightr f' cpos.le #align asymptotics.is_o.prod_rightr Asymptotics.IsLittleO.prod_rightr end theorem IsBigOWith.prod_left_same (hf : IsBigOWith c l f' k') (hg : IsBigOWith c l g' k') : IsBigOWith c l (fun x => (f' x, g' x)) k' := by rw [isBigOWith_iff] at *; filter_upwards [hf, hg] with x using max_le #align asymptotics.is_O_with.prod_left_same Asymptotics.IsBigOWith.prod_left_same theorem IsBigOWith.prod_left (hf : IsBigOWith c l f' k') (hg : IsBigOWith c' l g' k') : IsBigOWith (max c c') l (fun x => (f' x, g' x)) k' := (hf.weaken <| le_max_left c c').prod_left_same (hg.weaken <| le_max_right c c') #align asymptotics.is_O_with.prod_left Asymptotics.IsBigOWith.prod_left theorem IsBigOWith.prod_left_fst (h : IsBigOWith c l (fun x => (f' x, g' x)) k') : IsBigOWith c l f' k' := (isBigOWith_fst_prod.trans h zero_le_one).congr_const <| one_mul c #align asymptotics.is_O_with.prod_left_fst Asymptotics.IsBigOWith.prod_left_fst theorem IsBigOWith.prod_left_snd (h : IsBigOWith c l (fun x => (f' x, g' x)) k') : IsBigOWith c l g' k' := (isBigOWith_snd_prod.trans h zero_le_one).congr_const <| one_mul c #align asymptotics.is_O_with.prod_left_snd Asymptotics.IsBigOWith.prod_left_snd theorem isBigOWith_prod_left : IsBigOWith c l (fun x => (f' x, g' x)) k' ↔ IsBigOWith c l f' k' ∧ IsBigOWith c l g' k' := ⟨fun h => ⟨h.prod_left_fst, h.prod_left_snd⟩, fun h => h.1.prod_left_same h.2⟩ #align asymptotics.is_O_with_prod_left Asymptotics.isBigOWith_prod_left theorem IsBigO.prod_left (hf : f' =O[l] k') (hg : g' =O[l] k') : (fun x => (f' x, g' x)) =O[l] k' := let ⟨_c, hf⟩ := hf.isBigOWith let ⟨_c', hg⟩ := hg.isBigOWith (hf.prod_left hg).isBigO #align asymptotics.is_O.prod_left Asymptotics.IsBigO.prod_left theorem IsBigO.prod_left_fst : (fun x => (f' x, g' x)) =O[l] k' → f' =O[l] k' := IsBigO.trans isBigO_fst_prod #align asymptotics.is_O.prod_left_fst Asymptotics.IsBigO.prod_left_fst theorem IsBigO.prod_left_snd : (fun x => (f' x, g' x)) =O[l] k' → g' =O[l] k' := IsBigO.trans isBigO_snd_prod #align asymptotics.is_O.prod_left_snd Asymptotics.IsBigO.prod_left_snd @[simp] theorem isBigO_prod_left : (fun x => (f' x, g' x)) =O[l] k' ↔ f' =O[l] k' ∧ g' =O[l] k' := ⟨fun h => ⟨h.prod_left_fst, h.prod_left_snd⟩, fun h => h.1.prod_left h.2⟩ #align asymptotics.is_O_prod_left Asymptotics.isBigO_prod_left theorem IsLittleO.prod_left (hf : f' =o[l] k') (hg : g' =o[l] k') : (fun x => (f' x, g' x)) =o[l] k' := IsLittleO.of_isBigOWith fun _c hc => (hf.forall_isBigOWith hc).prod_left_same (hg.forall_isBigOWith hc) #align asymptotics.is_o.prod_left Asymptotics.IsLittleO.prod_left theorem IsLittleO.prod_left_fst : (fun x => (f' x, g' x)) =o[l] k' → f' =o[l] k' := IsBigO.trans_isLittleO isBigO_fst_prod #align asymptotics.is_o.prod_left_fst Asymptotics.IsLittleO.prod_left_fst theorem IsLittleO.prod_left_snd : (fun x => (f' x, g' x)) =o[l] k' → g' =o[l] k' := IsBigO.trans_isLittleO isBigO_snd_prod #align asymptotics.is_o.prod_left_snd Asymptotics.IsLittleO.prod_left_snd @[simp] theorem isLittleO_prod_left : (fun x => (f' x, g' x)) =o[l] k' ↔ f' =o[l] k' ∧ g' =o[l] k' := ⟨fun h => ⟨h.prod_left_fst, h.prod_left_snd⟩, fun h => h.1.prod_left h.2⟩ #align asymptotics.is_o_prod_left Asymptotics.isLittleO_prod_left theorem IsBigOWith.eq_zero_imp (h : IsBigOWith c l f'' g'') : ∀ᶠ x in l, g'' x = 0 → f'' x = 0 := Eventually.mono h.bound fun x hx hg => norm_le_zero_iff.1 <| by simpa [hg] using hx #align asymptotics.is_O_with.eq_zero_imp Asymptotics.IsBigOWith.eq_zero_imp theorem IsBigO.eq_zero_imp (h : f'' =O[l] g'') : ∀ᶠ x in l, g'' x = 0 → f'' x = 0 := let ⟨_C, hC⟩ := h.isBigOWith hC.eq_zero_imp #align asymptotics.is_O.eq_zero_imp Asymptotics.IsBigO.eq_zero_imp /-! ### Addition and subtraction -/ section add_sub variable {f₁ f₂ : α → E'} {g₁ g₂ : α → F'} theorem IsBigOWith.add (h₁ : IsBigOWith c₁ l f₁ g) (h₂ : IsBigOWith c₂ l f₂ g) : IsBigOWith (c₁ + c₂) l (fun x => f₁ x + f₂ x) g := by rw [IsBigOWith_def] at * filter_upwards [h₁, h₂] with x hx₁ hx₂ using calc ‖f₁ x + f₂ x‖ ≤ c₁ * ‖g x‖ + c₂ * ‖g x‖ := norm_add_le_of_le hx₁ hx₂ _ = (c₁ + c₂) * ‖g x‖ := (add_mul _ _ _).symm #align asymptotics.is_O_with.add Asymptotics.IsBigOWith.add theorem IsBigO.add (h₁ : f₁ =O[l] g) (h₂ : f₂ =O[l] g) : (fun x => f₁ x + f₂ x) =O[l] g := let ⟨_c₁, hc₁⟩ := h₁.isBigOWith let ⟨_c₂, hc₂⟩ := h₂.isBigOWith (hc₁.add hc₂).isBigO #align asymptotics.is_O.add Asymptotics.IsBigO.add theorem IsLittleO.add (h₁ : f₁ =o[l] g) (h₂ : f₂ =o[l] g) : (fun x => f₁ x + f₂ x) =o[l] g := IsLittleO.of_isBigOWith fun c cpos => ((h₁.forall_isBigOWith <| half_pos cpos).add (h₂.forall_isBigOWith <| half_pos cpos)).congr_const (add_halves c) #align asymptotics.is_o.add Asymptotics.IsLittleO.add theorem IsLittleO.add_add (h₁ : f₁ =o[l] g₁) (h₂ : f₂ =o[l] g₂) : (fun x => f₁ x + f₂ x) =o[l] fun x => ‖g₁ x‖ + ‖g₂ x‖ := by refine (h₁.trans_le fun x => ?_).add (h₂.trans_le ?_) <;> simp [abs_of_nonneg, add_nonneg] #align asymptotics.is_o.add_add Asymptotics.IsLittleO.add_add theorem IsBigO.add_isLittleO (h₁ : f₁ =O[l] g) (h₂ : f₂ =o[l] g) : (fun x => f₁ x + f₂ x) =O[l] g := h₁.add h₂.isBigO #align asymptotics.is_O.add_is_o Asymptotics.IsBigO.add_isLittleO theorem IsLittleO.add_isBigO (h₁ : f₁ =o[l] g) (h₂ : f₂ =O[l] g) : (fun x => f₁ x + f₂ x) =O[l] g := h₁.isBigO.add h₂ #align asymptotics.is_o.add_is_O Asymptotics.IsLittleO.add_isBigO theorem IsBigOWith.add_isLittleO (h₁ : IsBigOWith c₁ l f₁ g) (h₂ : f₂ =o[l] g) (hc : c₁ < c₂) : IsBigOWith c₂ l (fun x => f₁ x + f₂ x) g := (h₁.add (h₂.forall_isBigOWith (sub_pos.2 hc))).congr_const (add_sub_cancel _ _) #align asymptotics.is_O_with.add_is_o Asymptotics.IsBigOWith.add_isLittleO theorem IsLittleO.add_isBigOWith (h₁ : f₁ =o[l] g) (h₂ : IsBigOWith c₁ l f₂ g) (hc : c₁ < c₂) : IsBigOWith c₂ l (fun x => f₁ x + f₂ x) g := (h₂.add_isLittleO h₁ hc).congr_left fun _ => add_comm _ _ #align asymptotics.is_o.add_is_O_with Asymptotics.IsLittleO.add_isBigOWith theorem IsBigOWith.sub (h₁ : IsBigOWith c₁ l f₁ g) (h₂ : IsBigOWith c₂ l f₂ g) : IsBigOWith (c₁ + c₂) l (fun x => f₁ x - f₂ x) g := by simpa only [sub_eq_add_neg] using h₁.add h₂.neg_left #align asymptotics.is_O_with.sub Asymptotics.IsBigOWith.sub theorem IsBigOWith.sub_isLittleO (h₁ : IsBigOWith c₁ l f₁ g) (h₂ : f₂ =o[l] g) (hc : c₁ < c₂) : IsBigOWith c₂ l (fun x => f₁ x - f₂ x) g := by simpa only [sub_eq_add_neg] using h₁.add_isLittleO h₂.neg_left hc #align asymptotics.is_O_with.sub_is_o Asymptotics.IsBigOWith.sub_isLittleO theorem IsBigO.sub (h₁ : f₁ =O[l] g) (h₂ : f₂ =O[l] g) : (fun x => f₁ x - f₂ x) =O[l] g := by simpa only [sub_eq_add_neg] using h₁.add h₂.neg_left #align asymptotics.is_O.sub Asymptotics.IsBigO.sub theorem IsLittleO.sub (h₁ : f₁ =o[l] g) (h₂ : f₂ =o[l] g) : (fun x => f₁ x - f₂ x) =o[l] g := by simpa only [sub_eq_add_neg] using h₁.add h₂.neg_left #align asymptotics.is_o.sub Asymptotics.IsLittleO.sub end add_sub /-! ### Lemmas about `IsBigO (f₁ - f₂) g l` / `IsLittleO (f₁ - f₂) g l` treated as a binary relation -/ section IsBigOOAsRel variable {f₁ f₂ f₃ : α → E'} theorem IsBigOWith.symm (h : IsBigOWith c l (fun x => f₁ x - f₂ x) g) : IsBigOWith c l (fun x => f₂ x - f₁ x) g := h.neg_left.congr_left fun _x => neg_sub _ _ #align asymptotics.is_O_with.symm Asymptotics.IsBigOWith.symm theorem isBigOWith_comm : IsBigOWith c l (fun x => f₁ x - f₂ x) g ↔ IsBigOWith c l (fun x => f₂ x - f₁ x) g := ⟨IsBigOWith.symm, IsBigOWith.symm⟩ #align asymptotics.is_O_with_comm Asymptotics.isBigOWith_comm theorem IsBigO.symm (h : (fun x => f₁ x - f₂ x) =O[l] g) : (fun x => f₂ x - f₁ x) =O[l] g := h.neg_left.congr_left fun _x => neg_sub _ _ #align asymptotics.is_O.symm Asymptotics.IsBigO.symm theorem isBigO_comm : (fun x => f₁ x - f₂ x) =O[l] g ↔ (fun x => f₂ x - f₁ x) =O[l] g := ⟨IsBigO.symm, IsBigO.symm⟩ #align asymptotics.is_O_comm Asymptotics.isBigO_comm theorem IsLittleO.symm (h : (fun x => f₁ x - f₂ x) =o[l] g) : (fun x => f₂ x - f₁ x) =o[l] g := by simpa only [neg_sub] using h.neg_left #align asymptotics.is_o.symm Asymptotics.IsLittleO.symm theorem isLittleO_comm : (fun x => f₁ x - f₂ x) =o[l] g ↔ (fun x => f₂ x - f₁ x) =o[l] g := ⟨IsLittleO.symm, IsLittleO.symm⟩ #align asymptotics.is_o_comm Asymptotics.isLittleO_comm theorem IsBigOWith.triangle (h₁ : IsBigOWith c l (fun x => f₁ x - f₂ x) g) (h₂ : IsBigOWith c' l (fun x => f₂ x - f₃ x) g) : IsBigOWith (c + c') l (fun x => f₁ x - f₃ x) g := (h₁.add h₂).congr_left fun _x => sub_add_sub_cancel _ _ _ #align asymptotics.is_O_with.triangle Asymptotics.IsBigOWith.triangle theorem IsBigO.triangle (h₁ : (fun x => f₁ x - f₂ x) =O[l] g) (h₂ : (fun x => f₂ x - f₃ x) =O[l] g) : (fun x => f₁ x - f₃ x) =O[l] g := (h₁.add h₂).congr_left fun _x => sub_add_sub_cancel _ _ _ #align asymptotics.is_O.triangle Asymptotics.IsBigO.triangle theorem IsLittleO.triangle (h₁ : (fun x => f₁ x - f₂ x) =o[l] g) (h₂ : (fun x => f₂ x - f₃ x) =o[l] g) : (fun x => f₁ x - f₃ x) =o[l] g := (h₁.add h₂).congr_left fun _x => sub_add_sub_cancel _ _ _ #align asymptotics.is_o.triangle Asymptotics.IsLittleO.triangle theorem IsBigO.congr_of_sub (h : (fun x => f₁ x - f₂ x) =O[l] g) : f₁ =O[l] g ↔ f₂ =O[l] g := ⟨fun h' => (h'.sub h).congr_left fun _x => sub_sub_cancel _ _, fun h' => (h.add h').congr_left fun _x => sub_add_cancel _ _⟩ #align asymptotics.is_O.congr_of_sub Asymptotics.IsBigO.congr_of_sub theorem IsLittleO.congr_of_sub (h : (fun x => f₁ x - f₂ x) =o[l] g) : f₁ =o[l] g ↔ f₂ =o[l] g := ⟨fun h' => (h'.sub h).congr_left fun _x => sub_sub_cancel _ _, fun h' => (h.add h').congr_left fun _x => sub_add_cancel _ _⟩ #align asymptotics.is_o.congr_of_sub Asymptotics.IsLittleO.congr_of_sub end IsBigOOAsRel /-! ### Zero, one, and other constants -/ section ZeroConst variable (g g' l) theorem isLittleO_zero : (fun _x => (0 : E')) =o[l] g' := IsLittleO.of_bound fun c hc => univ_mem' fun x => by simpa using mul_nonneg hc.le (norm_nonneg <| g' x) #align asymptotics.is_o_zero Asymptotics.isLittleO_zero theorem isBigOWith_zero (hc : 0 ≤ c) : IsBigOWith c l (fun _x => (0 : E')) g' := IsBigOWith.of_bound <| univ_mem' fun x => by simpa using mul_nonneg hc (norm_nonneg <| g' x) #align asymptotics.is_O_with_zero Asymptotics.isBigOWith_zero theorem isBigOWith_zero' : IsBigOWith 0 l (fun _x => (0 : E')) g := IsBigOWith.of_bound <| univ_mem' fun x => by simp #align asymptotics.is_O_with_zero' Asymptotics.isBigOWith_zero' theorem isBigO_zero : (fun _x => (0 : E')) =O[l] g := isBigO_iff_isBigOWith.2 ⟨0, isBigOWith_zero' _ _⟩ #align asymptotics.is_O_zero Asymptotics.isBigO_zero theorem isBigO_refl_left : (fun x => f' x - f' x) =O[l] g' := (isBigO_zero g' l).congr_left fun _x => (sub_self _).symm #align asymptotics.is_O_refl_left Asymptotics.isBigO_refl_left theorem isLittleO_refl_left : (fun x => f' x - f' x) =o[l] g' := (isLittleO_zero g' l).congr_left fun _x => (sub_self _).symm #align asymptotics.is_o_refl_left Asymptotics.isLittleO_refl_left variable {g g' l} @[simp] theorem isBigOWith_zero_right_iff : (IsBigOWith c l f'' fun _x => (0 : F')) ↔ f'' =ᶠ[l] 0 := by simp only [IsBigOWith_def, exists_prop, true_and_iff, norm_zero, mul_zero, norm_le_zero_iff, EventuallyEq, Pi.zero_apply] #align asymptotics.is_O_with_zero_right_iff Asymptotics.isBigOWith_zero_right_iff @[simp] theorem isBigO_zero_right_iff : (f'' =O[l] fun _x => (0 : F')) ↔ f'' =ᶠ[l] 0 := ⟨fun h => let ⟨_c, hc⟩ := h.isBigOWith isBigOWith_zero_right_iff.1 hc, fun h => (isBigOWith_zero_right_iff.2 h : IsBigOWith 1 _ _ _).isBigO⟩ #align asymptotics.is_O_zero_right_iff Asymptotics.isBigO_zero_right_iff @[simp] theorem isLittleO_zero_right_iff : (f'' =o[l] fun _x => (0 : F')) ↔ f'' =ᶠ[l] 0 := ⟨fun h => isBigO_zero_right_iff.1 h.isBigO, fun h => IsLittleO.of_isBigOWith fun _c _hc => isBigOWith_zero_right_iff.2 h⟩ #align asymptotics.is_o_zero_right_iff Asymptotics.isLittleO_zero_right_iff theorem isBigOWith_const_const (c : E) {c' : F''} (hc' : c' ≠ 0) (l : Filter α) : IsBigOWith (‖c‖ / ‖c'‖) l (fun _x : α => c) fun _x => c' := by simp only [IsBigOWith_def] apply univ_mem' intro x rw [mem_setOf, div_mul_cancel₀ _ (norm_ne_zero_iff.mpr hc')] #align asymptotics.is_O_with_const_const Asymptotics.isBigOWith_const_const theorem isBigO_const_const (c : E) {c' : F''} (hc' : c' ≠ 0) (l : Filter α) : (fun _x : α => c) =O[l] fun _x => c' := (isBigOWith_const_const c hc' l).isBigO #align asymptotics.is_O_const_const Asymptotics.isBigO_const_const @[simp] theorem isBigO_const_const_iff {c : E''} {c' : F''} (l : Filter α) [l.NeBot] : ((fun _x : α => c) =O[l] fun _x => c') ↔ c' = 0 → c = 0 := by rcases eq_or_ne c' 0 with (rfl | hc') · simp [EventuallyEq] · simp [hc', isBigO_const_const _ hc'] #align asymptotics.is_O_const_const_iff Asymptotics.isBigO_const_const_iff @[simp] theorem isBigO_pure {x} : f'' =O[pure x] g'' ↔ g'' x = 0 → f'' x = 0 := calc f'' =O[pure x] g'' ↔ (fun _y : α => f'' x) =O[pure x] fun _ => g'' x := isBigO_congr rfl rfl _ ↔ g'' x = 0 → f'' x = 0 := isBigO_const_const_iff _ #align asymptotics.is_O_pure Asymptotics.isBigO_pure end ZeroConst @[simp] theorem isBigOWith_principal {s : Set α} : IsBigOWith c (𝓟 s) f g ↔ ∀ x ∈ s, ‖f x‖ ≤ c * ‖g x‖ := by rw [IsBigOWith_def, eventually_principal] #align asymptotics.is_O_with_principal Asymptotics.isBigOWith_principal theorem isBigO_principal {s : Set α} : f =O[𝓟 s] g ↔ ∃ c, ∀ x ∈ s, ‖f x‖ ≤ c * ‖g x‖ := by simp_rw [isBigO_iff, eventually_principal] #align asymptotics.is_O_principal Asymptotics.isBigO_principal @[simp] theorem isLittleO_principal {s : Set α} : f'' =o[𝓟 s] g' ↔ ∀ x ∈ s, f'' x = 0 := by refine ⟨fun h x hx ↦ norm_le_zero_iff.1 ?_, fun h ↦ ?_⟩ · simp only [isLittleO_iff, isBigOWith_principal] at h have : Tendsto (fun c : ℝ => c * ‖g' x‖) (𝓝[>] 0) (𝓝 0) := ((continuous_id.mul continuous_const).tendsto' _ _ (zero_mul _)).mono_left inf_le_left apply le_of_tendsto_of_tendsto tendsto_const_nhds this apply eventually_nhdsWithin_iff.2 (eventually_of_forall (fun c hc ↦ ?_)) exact eventually_principal.1 (h hc) x hx · apply (isLittleO_zero g' _).congr' ?_ EventuallyEq.rfl exact fun x hx ↦ (h x hx).symm @[simp] theorem isBigOWith_top : IsBigOWith c ⊤ f g ↔ ∀ x, ‖f x‖ ≤ c * ‖g x‖ := by rw [IsBigOWith_def, eventually_top] #align asymptotics.is_O_with_top Asymptotics.isBigOWith_top @[simp] theorem isBigO_top : f =O[⊤] g ↔ ∃ C, ∀ x, ‖f x‖ ≤ C * ‖g x‖ := by simp_rw [isBigO_iff, eventually_top] #align asymptotics.is_O_top Asymptotics.isBigO_top @[simp] theorem isLittleO_top : f'' =o[⊤] g' ↔ ∀ x, f'' x = 0 := by simp only [← principal_univ, isLittleO_principal, mem_univ, forall_true_left] #align asymptotics.is_o_top Asymptotics.isLittleO_top section variable (F) variable [One F] [NormOneClass F] theorem isBigOWith_const_one (c : E) (l : Filter α) : IsBigOWith ‖c‖ l (fun _x : α => c) fun _x => (1 : F) := by simp [isBigOWith_iff] #align asymptotics.is_O_with_const_one Asymptotics.isBigOWith_const_one theorem isBigO_const_one (c : E) (l : Filter α) : (fun _x : α => c) =O[l] fun _x => (1 : F) := (isBigOWith_const_one F c l).isBigO #align asymptotics.is_O_const_one Asymptotics.isBigO_const_one theorem isLittleO_const_iff_isLittleO_one {c : F''} (hc : c ≠ 0) : (f =o[l] fun _x => c) ↔ f =o[l] fun _x => (1 : F) := ⟨fun h => h.trans_isBigOWith (isBigOWith_const_one _ _ _) (norm_pos_iff.2 hc), fun h => h.trans_isBigO <| isBigO_const_const _ hc _⟩ #align asymptotics.is_o_const_iff_is_o_one Asymptotics.isLittleO_const_iff_isLittleO_one @[simp] theorem isLittleO_one_iff : f' =o[l] (fun _x => 1 : α → F) ↔ Tendsto f' l (𝓝 0) := by simp only [isLittleO_iff, norm_one, mul_one, Metric.nhds_basis_closedBall.tendsto_right_iff, Metric.mem_closedBall, dist_zero_right] #align asymptotics.is_o_one_iff Asymptotics.isLittleO_one_iff @[simp] theorem isBigO_one_iff : f =O[l] (fun _x => 1 : α → F) ↔ IsBoundedUnder (· ≤ ·) l fun x => ‖f x‖ := by simp only [isBigO_iff, norm_one, mul_one, IsBoundedUnder, IsBounded, eventually_map] #align asymptotics.is_O_one_iff Asymptotics.isBigO_one_iff alias ⟨_, _root_.Filter.IsBoundedUnder.isBigO_one⟩ := isBigO_one_iff #align filter.is_bounded_under.is_O_one Filter.IsBoundedUnder.isBigO_one @[simp] theorem isLittleO_one_left_iff : (fun _x => 1 : α → F) =o[l] f ↔ Tendsto (fun x => ‖f x‖) l atTop := calc (fun _x => 1 : α → F) =o[l] f ↔ ∀ n : ℕ, ∀ᶠ x in l, ↑n * ‖(1 : F)‖ ≤ ‖f x‖ := isLittleO_iff_nat_mul_le_aux <| Or.inl fun _x => by simp only [norm_one, zero_le_one] _ ↔ ∀ n : ℕ, True → ∀ᶠ x in l, ‖f x‖ ∈ Ici (n : ℝ) := by simp only [norm_one, mul_one, true_imp_iff, mem_Ici] _ ↔ Tendsto (fun x => ‖f x‖) l atTop := atTop_hasCountableBasis_of_archimedean.1.tendsto_right_iff.symm #align asymptotics.is_o_one_left_iff Asymptotics.isLittleO_one_left_iff theorem _root_.Filter.Tendsto.isBigO_one {c : E'} (h : Tendsto f' l (𝓝 c)) : f' =O[l] (fun _x => 1 : α → F) := h.norm.isBoundedUnder_le.isBigO_one F #align filter.tendsto.is_O_one Filter.Tendsto.isBigO_one theorem IsBigO.trans_tendsto_nhds (hfg : f =O[l] g') {y : F'} (hg : Tendsto g' l (𝓝 y)) : f =O[l] (fun _x => 1 : α → F) := hfg.trans <| hg.isBigO_one F #align asymptotics.is_O.trans_tendsto_nhds Asymptotics.IsBigO.trans_tendsto_nhds /-- The condition `f = O[𝓝[≠] a] 1` is equivalent to `f = O[𝓝 a] 1`. -/ lemma isBigO_one_nhds_ne_iff [TopologicalSpace α] {a : α} : f =O[𝓝[≠] a] (fun _ ↦ 1 : α → F) ↔ f =O[𝓝 a] (fun _ ↦ 1 : α → F) := by refine ⟨fun h ↦ ?_, fun h ↦ h.mono nhdsWithin_le_nhds⟩ simp only [isBigO_one_iff, IsBoundedUnder, IsBounded, eventually_map] at h ⊢ obtain ⟨c, hc⟩ := h use max c ‖f a‖ filter_upwards [eventually_nhdsWithin_iff.mp hc] with b hb rcases eq_or_ne b a with rfl | hb' · apply le_max_right · exact (hb hb').trans (le_max_left ..) end theorem isLittleO_const_iff {c : F''} (hc : c ≠ 0) : (f'' =o[l] fun _x => c) ↔ Tendsto f'' l (𝓝 0) := (isLittleO_const_iff_isLittleO_one ℝ hc).trans (isLittleO_one_iff _) #align asymptotics.is_o_const_iff Asymptotics.isLittleO_const_iff theorem isLittleO_id_const {c : F''} (hc : c ≠ 0) : (fun x : E'' => x) =o[𝓝 0] fun _x => c := (isLittleO_const_iff hc).mpr (continuous_id.tendsto 0) #align asymptotics.is_o_id_const Asymptotics.isLittleO_id_const theorem _root_.Filter.IsBoundedUnder.isBigO_const (h : IsBoundedUnder (· ≤ ·) l (norm ∘ f)) {c : F''} (hc : c ≠ 0) : f =O[l] fun _x => c := (h.isBigO_one ℝ).trans (isBigO_const_const _ hc _) #align filter.is_bounded_under.is_O_const Filter.IsBoundedUnder.isBigO_const theorem isBigO_const_of_tendsto {y : E''} (h : Tendsto f'' l (𝓝 y)) {c : F''} (hc : c ≠ 0) : f'' =O[l] fun _x => c := h.norm.isBoundedUnder_le.isBigO_const hc #align asymptotics.is_O_const_of_tendsto Asymptotics.isBigO_const_of_tendsto theorem IsBigO.isBoundedUnder_le {c : F} (h : f =O[l] fun _x => c) : IsBoundedUnder (· ≤ ·) l (norm ∘ f) := let ⟨c', hc'⟩ := h.bound ⟨c' * ‖c‖, eventually_map.2 hc'⟩ #align asymptotics.is_O.is_bounded_under_le Asymptotics.IsBigO.isBoundedUnder_le theorem isBigO_const_of_ne {c : F''} (hc : c ≠ 0) : (f =O[l] fun _x => c) ↔ IsBoundedUnder (· ≤ ·) l (norm ∘ f) := ⟨fun h => h.isBoundedUnder_le, fun h => h.isBigO_const hc⟩ #align asymptotics.is_O_const_of_ne Asymptotics.isBigO_const_of_ne theorem isBigO_const_iff {c : F''} : (f'' =O[l] fun _x => c) ↔ (c = 0 → f'' =ᶠ[l] 0) ∧ IsBoundedUnder (· ≤ ·) l fun x => ‖f'' x‖ := by refine ⟨fun h => ⟨fun hc => isBigO_zero_right_iff.1 (by rwa [← hc]), h.isBoundedUnder_le⟩, ?_⟩ rintro ⟨hcf, hf⟩ rcases eq_or_ne c 0 with (hc | hc) exacts [(hcf hc).trans_isBigO (isBigO_zero _ _), hf.isBigO_const hc] #align asymptotics.is_O_const_iff Asymptotics.isBigO_const_iff theorem isBigO_iff_isBoundedUnder_le_div (h : ∀ᶠ x in l, g'' x ≠ 0) : f =O[l] g'' ↔ IsBoundedUnder (· ≤ ·) l fun x => ‖f x‖ / ‖g'' x‖ := by simp only [isBigO_iff, IsBoundedUnder, IsBounded, eventually_map] exact exists_congr fun c => eventually_congr <| h.mono fun x hx => (div_le_iff <| norm_pos_iff.2 hx).symm #align asymptotics.is_O_iff_is_bounded_under_le_div Asymptotics.isBigO_iff_isBoundedUnder_le_div /-- `(fun x ↦ c) =O[l] f` if and only if `f` is bounded away from zero. -/ theorem isBigO_const_left_iff_pos_le_norm {c : E''} (hc : c ≠ 0) : (fun _x => c) =O[l] f' ↔ ∃ b, 0 < b ∧ ∀ᶠ x in l, b ≤ ‖f' x‖ := by constructor · intro h rcases h.exists_pos with ⟨C, hC₀, hC⟩ refine ⟨‖c‖ / C, div_pos (norm_pos_iff.2 hc) hC₀, ?_⟩ exact hC.bound.mono fun x => (div_le_iff' hC₀).2 · rintro ⟨b, hb₀, hb⟩ refine IsBigO.of_bound (‖c‖ / b) (hb.mono fun x hx => ?_) rw [div_mul_eq_mul_div, mul_div_assoc] exact le_mul_of_one_le_right (norm_nonneg _) ((one_le_div hb₀).2 hx) #align asymptotics.is_O_const_left_iff_pos_le_norm Asymptotics.isBigO_const_left_iff_pos_le_norm theorem IsBigO.trans_tendsto (hfg : f'' =O[l] g'') (hg : Tendsto g'' l (𝓝 0)) : Tendsto f'' l (𝓝 0) := (isLittleO_one_iff ℝ).1 <| hfg.trans_isLittleO <| (isLittleO_one_iff ℝ).2 hg #align asymptotics.is_O.trans_tendsto Asymptotics.IsBigO.trans_tendsto theorem IsLittleO.trans_tendsto (hfg : f'' =o[l] g'') (hg : Tendsto g'' l (𝓝 0)) : Tendsto f'' l (𝓝 0) := hfg.isBigO.trans_tendsto hg #align asymptotics.is_o.trans_tendsto Asymptotics.IsLittleO.trans_tendsto /-! ### Multiplication by a constant -/ theorem isBigOWith_const_mul_self (c : R) (f : α → R) (l : Filter α) : IsBigOWith ‖c‖ l (fun x => c * f x) f := isBigOWith_of_le' _ fun _x => norm_mul_le _ _ #align asymptotics.is_O_with_const_mul_self Asymptotics.isBigOWith_const_mul_self theorem isBigO_const_mul_self (c : R) (f : α → R) (l : Filter α) : (fun x => c * f x) =O[l] f := (isBigOWith_const_mul_self c f l).isBigO #align asymptotics.is_O_const_mul_self Asymptotics.isBigO_const_mul_self theorem IsBigOWith.const_mul_left {f : α → R} (h : IsBigOWith c l f g) (c' : R) : IsBigOWith (‖c'‖ * c) l (fun x => c' * f x) g := (isBigOWith_const_mul_self c' f l).trans h (norm_nonneg c') #align asymptotics.is_O_with.const_mul_left Asymptotics.IsBigOWith.const_mul_left theorem IsBigO.const_mul_left {f : α → R} (h : f =O[l] g) (c' : R) : (fun x => c' * f x) =O[l] g := let ⟨_c, hc⟩ := h.isBigOWith (hc.const_mul_left c').isBigO #align asymptotics.is_O.const_mul_left Asymptotics.IsBigO.const_mul_left theorem isBigOWith_self_const_mul' (u : Rˣ) (f : α → R) (l : Filter α) : IsBigOWith ‖(↑u⁻¹ : R)‖ l f fun x => ↑u * f x := (isBigOWith_const_mul_self ↑u⁻¹ (fun x ↦ ↑u * f x) l).congr_left fun x ↦ u.inv_mul_cancel_left (f x) #align asymptotics.is_O_with_self_const_mul' Asymptotics.isBigOWith_self_const_mul' theorem isBigOWith_self_const_mul (c : 𝕜) (hc : c ≠ 0) (f : α → 𝕜) (l : Filter α) : IsBigOWith ‖c‖⁻¹ l f fun x => c * f x := (isBigOWith_self_const_mul' (Units.mk0 c hc) f l).congr_const <| norm_inv c #align asymptotics.is_O_with_self_const_mul Asymptotics.isBigOWith_self_const_mul theorem isBigO_self_const_mul' {c : R} (hc : IsUnit c) (f : α → R) (l : Filter α) : f =O[l] fun x => c * f x := let ⟨u, hu⟩ := hc hu ▸ (isBigOWith_self_const_mul' u f l).isBigO #align asymptotics.is_O_self_const_mul' Asymptotics.isBigO_self_const_mul' theorem isBigO_self_const_mul (c : 𝕜) (hc : c ≠ 0) (f : α → 𝕜) (l : Filter α) : f =O[l] fun x => c * f x := isBigO_self_const_mul' (IsUnit.mk0 c hc) f l #align asymptotics.is_O_self_const_mul Asymptotics.isBigO_self_const_mul theorem isBigO_const_mul_left_iff' {f : α → R} {c : R} (hc : IsUnit c) : (fun x => c * f x) =O[l] g ↔ f =O[l] g := ⟨(isBigO_self_const_mul' hc f l).trans, fun h => h.const_mul_left c⟩ #align asymptotics.is_O_const_mul_left_iff' Asymptotics.isBigO_const_mul_left_iff' theorem isBigO_const_mul_left_iff {f : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : (fun x => c * f x) =O[l] g ↔ f =O[l] g := isBigO_const_mul_left_iff' <| IsUnit.mk0 c hc #align asymptotics.is_O_const_mul_left_iff Asymptotics.isBigO_const_mul_left_iff theorem IsLittleO.const_mul_left {f : α → R} (h : f =o[l] g) (c : R) : (fun x => c * f x) =o[l] g := (isBigO_const_mul_self c f l).trans_isLittleO h #align asymptotics.is_o.const_mul_left Asymptotics.IsLittleO.const_mul_left theorem isLittleO_const_mul_left_iff' {f : α → R} {c : R} (hc : IsUnit c) : (fun x => c * f x) =o[l] g ↔ f =o[l] g := ⟨(isBigO_self_const_mul' hc f l).trans_isLittleO, fun h => h.const_mul_left c⟩ #align asymptotics.is_o_const_mul_left_iff' Asymptotics.isLittleO_const_mul_left_iff' theorem isLittleO_const_mul_left_iff {f : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : (fun x => c * f x) =o[l] g ↔ f =o[l] g := isLittleO_const_mul_left_iff' <| IsUnit.mk0 c hc #align asymptotics.is_o_const_mul_left_iff Asymptotics.isLittleO_const_mul_left_iff theorem IsBigOWith.of_const_mul_right {g : α → R} {c : R} (hc' : 0 ≤ c') (h : IsBigOWith c' l f fun x => c * g x) : IsBigOWith (c' * ‖c‖) l f g := h.trans (isBigOWith_const_mul_self c g l) hc' #align asymptotics.is_O_with.of_const_mul_right Asymptotics.IsBigOWith.of_const_mul_right theorem IsBigO.of_const_mul_right {g : α → R} {c : R} (h : f =O[l] fun x => c * g x) : f =O[l] g := let ⟨_c, cnonneg, hc⟩ := h.exists_nonneg (hc.of_const_mul_right cnonneg).isBigO #align asymptotics.is_O.of_const_mul_right Asymptotics.IsBigO.of_const_mul_right theorem IsBigOWith.const_mul_right' {g : α → R} {u : Rˣ} {c' : ℝ} (hc' : 0 ≤ c') (h : IsBigOWith c' l f g) : IsBigOWith (c' * ‖(↑u⁻¹ : R)‖) l f fun x => ↑u * g x := h.trans (isBigOWith_self_const_mul' _ _ _) hc' #align asymptotics.is_O_with.const_mul_right' Asymptotics.IsBigOWith.const_mul_right' theorem IsBigOWith.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) {c' : ℝ} (hc' : 0 ≤ c') (h : IsBigOWith c' l f g) : IsBigOWith (c' * ‖c‖⁻¹) l f fun x => c * g x := h.trans (isBigOWith_self_const_mul c hc g l) hc' #align asymptotics.is_O_with.const_mul_right Asymptotics.IsBigOWith.const_mul_right theorem IsBigO.const_mul_right' {g : α → R} {c : R} (hc : IsUnit c) (h : f =O[l] g) : f =O[l] fun x => c * g x := h.trans (isBigO_self_const_mul' hc g l) #align asymptotics.is_O.const_mul_right' Asymptotics.IsBigO.const_mul_right' theorem IsBigO.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) (h : f =O[l] g) : f =O[l] fun x => c * g x := h.const_mul_right' <| IsUnit.mk0 c hc #align asymptotics.is_O.const_mul_right Asymptotics.IsBigO.const_mul_right theorem isBigO_const_mul_right_iff' {g : α → R} {c : R} (hc : IsUnit c) : (f =O[l] fun x => c * g x) ↔ f =O[l] g := ⟨fun h => h.of_const_mul_right, fun h => h.const_mul_right' hc⟩ #align asymptotics.is_O_const_mul_right_iff' Asymptotics.isBigO_const_mul_right_iff' theorem isBigO_const_mul_right_iff {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : (f =O[l] fun x => c * g x) ↔ f =O[l] g := isBigO_const_mul_right_iff' <| IsUnit.mk0 c hc #align asymptotics.is_O_const_mul_right_iff Asymptotics.isBigO_const_mul_right_iff theorem IsLittleO.of_const_mul_right {g : α → R} {c : R} (h : f =o[l] fun x => c * g x) : f =o[l] g := h.trans_isBigO (isBigO_const_mul_self c g l) #align asymptotics.is_o.of_const_mul_right Asymptotics.IsLittleO.of_const_mul_right theorem IsLittleO.const_mul_right' {g : α → R} {c : R} (hc : IsUnit c) (h : f =o[l] g) : f =o[l] fun x => c * g x := h.trans_isBigO (isBigO_self_const_mul' hc g l) #align asymptotics.is_o.const_mul_right' Asymptotics.IsLittleO.const_mul_right' theorem IsLittleO.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) (h : f =o[l] g) : f =o[l] fun x => c * g x := h.const_mul_right' <| IsUnit.mk0 c hc #align asymptotics.is_o.const_mul_right Asymptotics.IsLittleO.const_mul_right theorem isLittleO_const_mul_right_iff' {g : α → R} {c : R} (hc : IsUnit c) : (f =o[l] fun x => c * g x) ↔ f =o[l] g := ⟨fun h => h.of_const_mul_right, fun h => h.const_mul_right' hc⟩ #align asymptotics.is_o_const_mul_right_iff' Asymptotics.isLittleO_const_mul_right_iff' theorem isLittleO_const_mul_right_iff {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) : (f =o[l] fun x => c * g x) ↔ f =o[l] g := isLittleO_const_mul_right_iff' <| IsUnit.mk0 c hc #align asymptotics.is_o_const_mul_right_iff Asymptotics.isLittleO_const_mul_right_iff /-! ### Multiplication -/ theorem IsBigOWith.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} {c₁ c₂ : ℝ} (h₁ : IsBigOWith c₁ l f₁ g₁) (h₂ : IsBigOWith c₂ l f₂ g₂) : IsBigOWith (c₁ * c₂) l (fun x => f₁ x * f₂ x) fun x => g₁ x * g₂ x := by simp only [IsBigOWith_def] at * filter_upwards [h₁, h₂] with _ hx₁ hx₂ apply le_trans (norm_mul_le _ _) convert mul_le_mul hx₁ hx₂ (norm_nonneg _) (le_trans (norm_nonneg _) hx₁) using 1 rw [norm_mul, mul_mul_mul_comm] #align asymptotics.is_O_with.mul Asymptotics.IsBigOWith.mul theorem IsBigO.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : f₁ =O[l] g₁) (h₂ : f₂ =O[l] g₂) : (fun x => f₁ x * f₂ x) =O[l] fun x => g₁ x * g₂ x := let ⟨_c, hc⟩ := h₁.isBigOWith let ⟨_c', hc'⟩ := h₂.isBigOWith (hc.mul hc').isBigO #align asymptotics.is_O.mul Asymptotics.IsBigO.mul theorem IsBigO.mul_isLittleO {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : f₁ =O[l] g₁) (h₂ : f₂ =o[l] g₂) : (fun x => f₁ x * f₂ x) =o[l] fun x => g₁ x * g₂ x := by simp only [IsLittleO_def] at * intro c cpos rcases h₁.exists_pos with ⟨c', c'pos, hc'⟩ exact (hc'.mul (h₂ (div_pos cpos c'pos))).congr_const (mul_div_cancel₀ _ (ne_of_gt c'pos)) #align asymptotics.is_O.mul_is_o Asymptotics.IsBigO.mul_isLittleO theorem IsLittleO.mul_isBigO {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : f₁ =o[l] g₁) (h₂ : f₂ =O[l] g₂) : (fun x => f₁ x * f₂ x) =o[l] fun x => g₁ x * g₂ x := by simp only [IsLittleO_def] at * intro c cpos rcases h₂.exists_pos with ⟨c', c'pos, hc'⟩ exact ((h₁ (div_pos cpos c'pos)).mul hc').congr_const (div_mul_cancel₀ _ (ne_of_gt c'pos)) #align asymptotics.is_o.mul_is_O Asymptotics.IsLittleO.mul_isBigO theorem IsLittleO.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : f₁ =o[l] g₁) (h₂ : f₂ =o[l] g₂) : (fun x => f₁ x * f₂ x) =o[l] fun x => g₁ x * g₂ x := h₁.mul_isBigO h₂.isBigO #align asymptotics.is_o.mul Asymptotics.IsLittleO.mul theorem IsBigOWith.pow' {f : α → R} {g : α → 𝕜} (h : IsBigOWith c l f g) : ∀ n : ℕ, IsBigOWith (Nat.casesOn n ‖(1 : R)‖ fun n => c ^ (n + 1)) l (fun x => f x ^ n) fun x => g x ^ n | 0 => by simpa using isBigOWith_const_const (1 : R) (one_ne_zero' 𝕜) l | 1 => by simpa | n + 2 => by simpa [pow_succ] using (IsBigOWith.pow' h (n + 1)).mul h #align asymptotics.is_O_with.pow' Asymptotics.IsBigOWith.pow' theorem IsBigOWith.pow [NormOneClass R] {f : α → R} {g : α → 𝕜} (h : IsBigOWith c l f g) : ∀ n : ℕ, IsBigOWith (c ^ n) l (fun x => f x ^ n) fun x => g x ^ n | 0 => by simpa using h.pow' 0 | n + 1 => h.pow' (n + 1) #align asymptotics.is_O_with.pow Asymptotics.IsBigOWith.pow theorem IsBigOWith.of_pow {n : ℕ} {f : α → 𝕜} {g : α → R} (h : IsBigOWith c l (f ^ n) (g ^ n)) (hn : n ≠ 0) (hc : c ≤ c' ^ n) (hc' : 0 ≤ c') : IsBigOWith c' l f g := IsBigOWith.of_bound <| (h.weaken hc).bound.mono fun x hx ↦ le_of_pow_le_pow_left hn (by positivity) <| calc ‖f x‖ ^ n = ‖f x ^ n‖ := (norm_pow _ _).symm _ ≤ c' ^ n * ‖g x ^ n‖ := hx _ ≤ c' ^ n * ‖g x‖ ^ n := by gcongr; exact norm_pow_le' _ hn.bot_lt _ = (c' * ‖g x‖) ^ n := (mul_pow _ _ _).symm #align asymptotics.is_O_with.of_pow Asymptotics.IsBigOWith.of_pow theorem IsBigO.pow {f : α → R} {g : α → 𝕜} (h : f =O[l] g) (n : ℕ) : (fun x => f x ^ n) =O[l] fun x => g x ^ n := let ⟨_C, hC⟩ := h.isBigOWith isBigO_iff_isBigOWith.2 ⟨_, hC.pow' n⟩ #align asymptotics.is_O.pow Asymptotics.IsBigO.pow theorem IsBigO.of_pow {f : α → 𝕜} {g : α → R} {n : ℕ} (hn : n ≠ 0) (h : (f ^ n) =O[l] (g ^ n)) : f =O[l] g := by rcases h.exists_pos with ⟨C, _hC₀, hC⟩ obtain ⟨c : ℝ, hc₀ : 0 ≤ c, hc : C ≤ c ^ n⟩ := ((eventually_ge_atTop _).and <| (tendsto_pow_atTop hn).eventually_ge_atTop C).exists exact (hC.of_pow hn hc hc₀).isBigO #align asymptotics.is_O.of_pow Asymptotics.IsBigO.of_pow theorem IsLittleO.pow {f : α → R} {g : α → 𝕜} (h : f =o[l] g) {n : ℕ} (hn : 0 < n) : (fun x => f x ^ n) =o[l] fun x => g x ^ n := by obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hn.ne'; clear hn induction' n with n ihn · simpa only [Nat.zero_eq, ← Nat.one_eq_succ_zero, pow_one] · convert ihn.mul h <;> simp [pow_succ] #align asymptotics.is_o.pow Asymptotics.IsLittleO.pow theorem IsLittleO.of_pow {f : α → 𝕜} {g : α → R} {n : ℕ} (h : (f ^ n) =o[l] (g ^ n)) (hn : n ≠ 0) : f =o[l] g := IsLittleO.of_isBigOWith fun _c hc => (h.def' <| pow_pos hc _).of_pow hn le_rfl hc.le #align asymptotics.is_o.of_pow Asymptotics.IsLittleO.of_pow /-! ### Inverse -/ theorem IsBigOWith.inv_rev {f : α → 𝕜} {g : α → 𝕜'} (h : IsBigOWith c l f g) (h₀ : ∀ᶠ x in l, f x = 0 → g x = 0) : IsBigOWith c l (fun x => (g x)⁻¹) fun x => (f x)⁻¹ := by refine IsBigOWith.of_bound (h.bound.mp (h₀.mono fun x h₀ hle => ?_)) rcases eq_or_ne (f x) 0 with hx | hx · simp only [hx, h₀ hx, inv_zero, norm_zero, mul_zero, le_rfl] · have hc : 0 < c := pos_of_mul_pos_left ((norm_pos_iff.2 hx).trans_le hle) (norm_nonneg _) replace hle := inv_le_inv_of_le (norm_pos_iff.2 hx) hle simpa only [norm_inv, mul_inv, ← div_eq_inv_mul, div_le_iff hc] using hle #align asymptotics.is_O_with.inv_rev Asymptotics.IsBigOWith.inv_rev theorem IsBigO.inv_rev {f : α → 𝕜} {g : α → 𝕜'} (h : f =O[l] g) (h₀ : ∀ᶠ x in l, f x = 0 → g x = 0) : (fun x => (g x)⁻¹) =O[l] fun x => (f x)⁻¹ := let ⟨_c, hc⟩ := h.isBigOWith (hc.inv_rev h₀).isBigO #align asymptotics.is_O.inv_rev Asymptotics.IsBigO.inv_rev theorem IsLittleO.inv_rev {f : α → 𝕜} {g : α → 𝕜'} (h : f =o[l] g) (h₀ : ∀ᶠ x in l, f x = 0 → g x = 0) : (fun x => (g x)⁻¹) =o[l] fun x => (f x)⁻¹ := IsLittleO.of_isBigOWith fun _c hc => (h.def' hc).inv_rev h₀ #align asymptotics.is_o.inv_rev Asymptotics.IsLittleO.inv_rev /-! ### Scalar multiplication -/ section SMulConst variable [Module R E'] [BoundedSMul R E'] theorem IsBigOWith.const_smul_self (c' : R) : IsBigOWith (‖c'‖) l (fun x => c' • f' x) f' := isBigOWith_of_le' _ fun _ => norm_smul_le _ _ theorem IsBigO.const_smul_self (c' : R) : (fun x => c' • f' x) =O[l] f' := (IsBigOWith.const_smul_self _).isBigO theorem IsBigOWith.const_smul_left (h : IsBigOWith c l f' g) (c' : R) : IsBigOWith (‖c'‖ * c) l (fun x => c' • f' x) g := .trans (.const_smul_self _) h (norm_nonneg _) theorem IsBigO.const_smul_left (h : f' =O[l] g) (c : R) : (c • f') =O[l] g := let ⟨_b, hb⟩ := h.isBigOWith (hb.const_smul_left _).isBigO #align asymptotics.is_O.const_smul_left Asymptotics.IsBigO.const_smul_left theorem IsLittleO.const_smul_left (h : f' =o[l] g) (c : R) : (c • f') =o[l] g := (IsBigO.const_smul_self _).trans_isLittleO h #align asymptotics.is_o.const_smul_left Asymptotics.IsLittleO.const_smul_left variable [Module 𝕜 E'] [BoundedSMul 𝕜 E'] theorem isBigO_const_smul_left {c : 𝕜} (hc : c ≠ 0) : (fun x => c • f' x) =O[l] g ↔ f' =O[l] g := by have cne0 : ‖c‖ ≠ 0 := norm_ne_zero_iff.mpr hc rw [← isBigO_norm_left] simp only [norm_smul] rw [isBigO_const_mul_left_iff cne0, isBigO_norm_left] #align asymptotics.is_O_const_smul_left Asymptotics.isBigO_const_smul_left theorem isLittleO_const_smul_left {c : 𝕜} (hc : c ≠ 0) : (fun x => c • f' x) =o[l] g ↔ f' =o[l] g := by have cne0 : ‖c‖ ≠ 0 := norm_ne_zero_iff.mpr hc rw [← isLittleO_norm_left] simp only [norm_smul] rw [isLittleO_const_mul_left_iff cne0, isLittleO_norm_left] #align asymptotics.is_o_const_smul_left Asymptotics.isLittleO_const_smul_left theorem isBigO_const_smul_right {c : 𝕜} (hc : c ≠ 0) : (f =O[l] fun x => c • f' x) ↔ f =O[l] f' := by have cne0 : ‖c‖ ≠ 0 := norm_ne_zero_iff.mpr hc rw [← isBigO_norm_right] simp only [norm_smul] rw [isBigO_const_mul_right_iff cne0, isBigO_norm_right] #align asymptotics.is_O_const_smul_right Asymptotics.isBigO_const_smul_right theorem isLittleO_const_smul_right {c : 𝕜} (hc : c ≠ 0) : (f =o[l] fun x => c • f' x) ↔ f =o[l] f' := by have cne0 : ‖c‖ ≠ 0 := norm_ne_zero_iff.mpr hc rw [← isLittleO_norm_right] simp only [norm_smul] rw [isLittleO_const_mul_right_iff cne0, isLittleO_norm_right] #align asymptotics.is_o_const_smul_right Asymptotics.isLittleO_const_smul_right end SMulConst section SMul variable [Module R E'] [BoundedSMul R E'] [Module 𝕜' F'] [BoundedSMul 𝕜' F'] variable {k₁ : α → R} {k₂ : α → 𝕜'} theorem IsBigOWith.smul (h₁ : IsBigOWith c l k₁ k₂) (h₂ : IsBigOWith c' l f' g') : IsBigOWith (c * c') l (fun x => k₁ x • f' x) fun x => k₂ x • g' x := by simp only [IsBigOWith_def] at * filter_upwards [h₁, h₂] with _ hx₁ hx₂ apply le_trans (norm_smul_le _ _) convert mul_le_mul hx₁ hx₂ (norm_nonneg _) (le_trans (norm_nonneg _) hx₁) using 1 rw [norm_smul, mul_mul_mul_comm] #align asymptotics.is_O_with.smul Asymptotics.IsBigOWith.smul theorem IsBigO.smul (h₁ : k₁ =O[l] k₂) (h₂ : f' =O[l] g') : (fun x => k₁ x • f' x) =O[l] fun x => k₂ x • g' x := by obtain ⟨c₁, h₁⟩ := h₁.isBigOWith obtain ⟨c₂, h₂⟩ := h₂.isBigOWith exact (h₁.smul h₂).isBigO #align asymptotics.is_O.smul Asymptotics.IsBigO.smul theorem IsBigO.smul_isLittleO (h₁ : k₁ =O[l] k₂) (h₂ : f' =o[l] g') : (fun x => k₁ x • f' x) =o[l] fun x => k₂ x • g' x := by simp only [IsLittleO_def] at * intro c cpos rcases h₁.exists_pos with ⟨c', c'pos, hc'⟩ exact (hc'.smul (h₂ (div_pos cpos c'pos))).congr_const (mul_div_cancel₀ _ (ne_of_gt c'pos)) #align asymptotics.is_O.smul_is_o Asymptotics.IsBigO.smul_isLittleO theorem IsLittleO.smul_isBigO (h₁ : k₁ =o[l] k₂) (h₂ : f' =O[l] g') : (fun x => k₁ x • f' x) =o[l] fun x => k₂ x • g' x := by simp only [IsLittleO_def] at * intro c cpos rcases h₂.exists_pos with ⟨c', c'pos, hc'⟩ exact ((h₁ (div_pos cpos c'pos)).smul hc').congr_const (div_mul_cancel₀ _ (ne_of_gt c'pos)) #align asymptotics.is_o.smul_is_O Asymptotics.IsLittleO.smul_isBigO theorem IsLittleO.smul (h₁ : k₁ =o[l] k₂) (h₂ : f' =o[l] g') : (fun x => k₁ x • f' x) =o[l] fun x => k₂ x • g' x := h₁.smul_isBigO h₂.isBigO #align asymptotics.is_o.smul Asymptotics.IsLittleO.smul end SMul /-! ### Sum -/ section Sum variable {ι : Type*} {A : ι → α → E'} {C : ι → ℝ} {s : Finset ι} theorem IsBigOWith.sum (h : ∀ i ∈ s, IsBigOWith (C i) l (A i) g) : IsBigOWith (∑ i ∈ s, C i) l (fun x => ∑ i ∈ s, A i x) g := by induction' s using Finset.induction_on with i s is IH · simp only [isBigOWith_zero', Finset.sum_empty, forall_true_iff] · simp only [is, Finset.sum_insert, not_false_iff] exact (h _ (Finset.mem_insert_self i s)).add (IH fun j hj => h _ (Finset.mem_insert_of_mem hj)) #align asymptotics.is_O_with.sum Asymptotics.IsBigOWith.sum theorem IsBigO.sum (h : ∀ i ∈ s, A i =O[l] g) : (fun x => ∑ i ∈ s, A i x) =O[l] g := by simp only [IsBigO_def] at * choose! C hC using h exact ⟨_, IsBigOWith.sum hC⟩ #align asymptotics.is_O.sum Asymptotics.IsBigO.sum theorem IsLittleO.sum (h : ∀ i ∈ s, A i =o[l] g') : (fun x => ∑ i ∈ s, A i x) =o[l] g' := by induction' s using Finset.induction_on with i s is IH · simp only [isLittleO_zero, Finset.sum_empty, forall_true_iff] · simp only [is, Finset.sum_insert, not_false_iff] exact (h _ (Finset.mem_insert_self i s)).add (IH fun j hj => h _ (Finset.mem_insert_of_mem hj)) #align asymptotics.is_o.sum Asymptotics.IsLittleO.sum end Sum /-! ### Relation between `f = o(g)` and `f / g → 0` -/ theorem IsLittleO.tendsto_div_nhds_zero {f g : α → 𝕜} (h : f =o[l] g) : Tendsto (fun x => f x / g x) l (𝓝 0) := (isLittleO_one_iff 𝕜).mp <| by calc (fun x => f x / g x) =o[l] fun x => g x / g x := by simpa only [div_eq_mul_inv] using h.mul_isBigO (isBigO_refl _ _) _ =O[l] fun _x => (1 : 𝕜) := isBigO_of_le _ fun x => by simp [div_self_le_one] #align asymptotics.is_o.tendsto_div_nhds_zero Asymptotics.IsLittleO.tendsto_div_nhds_zero theorem IsLittleO.tendsto_inv_smul_nhds_zero [Module 𝕜 E'] [BoundedSMul 𝕜 E'] {f : α → E'} {g : α → 𝕜} {l : Filter α} (h : f =o[l] g) : Tendsto (fun x => (g x)⁻¹ • f x) l (𝓝 0) := by simpa only [div_eq_inv_mul, ← norm_inv, ← norm_smul, ← tendsto_zero_iff_norm_tendsto_zero] using h.norm_norm.tendsto_div_nhds_zero #align asymptotics.is_o.tendsto_inv_smul_nhds_zero Asymptotics.IsLittleO.tendsto_inv_smul_nhds_zero theorem isLittleO_iff_tendsto' {f g : α → 𝕜} (hgf : ∀ᶠ x in l, g x = 0 → f x = 0) : f =o[l] g ↔ Tendsto (fun x => f x / g x) l (𝓝 0) := ⟨IsLittleO.tendsto_div_nhds_zero, fun h => (((isLittleO_one_iff _).mpr h).mul_isBigO (isBigO_refl g l)).congr' (hgf.mono fun _x => div_mul_cancel_of_imp) (eventually_of_forall fun _x => one_mul _)⟩ #align asymptotics.is_o_iff_tendsto' Asymptotics.isLittleO_iff_tendsto' theorem isLittleO_iff_tendsto {f g : α → 𝕜} (hgf : ∀ x, g x = 0 → f x = 0) : f =o[l] g ↔ Tendsto (fun x => f x / g x) l (𝓝 0) := isLittleO_iff_tendsto' (eventually_of_forall hgf) #align asymptotics.is_o_iff_tendsto Asymptotics.isLittleO_iff_tendsto alias ⟨_, isLittleO_of_tendsto'⟩ := isLittleO_iff_tendsto' #align asymptotics.is_o_of_tendsto' Asymptotics.isLittleO_of_tendsto' alias ⟨_, isLittleO_of_tendsto⟩ := isLittleO_iff_tendsto #align asymptotics.is_o_of_tendsto Asymptotics.isLittleO_of_tendsto theorem isLittleO_const_left_of_ne {c : E''} (hc : c ≠ 0) : (fun _x => c) =o[l] g ↔ Tendsto (fun x => ‖g x‖) l atTop := by simp only [← isLittleO_one_left_iff ℝ] exact ⟨(isBigO_const_const (1 : ℝ) hc l).trans_isLittleO, (isBigO_const_one ℝ c l).trans_isLittleO⟩ #align asymptotics.is_o_const_left_of_ne Asymptotics.isLittleO_const_left_of_ne @[simp] theorem isLittleO_const_left {c : E''} : (fun _x => c) =o[l] g'' ↔ c = 0 ∨ Tendsto (norm ∘ g'') l atTop := by rcases eq_or_ne c 0 with (rfl | hc) · simp only [isLittleO_zero, eq_self_iff_true, true_or_iff] · simp only [hc, false_or_iff, isLittleO_const_left_of_ne hc]; rfl #align asymptotics.is_o_const_left Asymptotics.isLittleO_const_left @[simp 1001] -- Porting note: increase priority so that this triggers before `isLittleO_const_left` theorem isLittleO_const_const_iff [NeBot l] {d : E''} {c : F''} : ((fun _x => d) =o[l] fun _x => c) ↔ d = 0 := by have : ¬Tendsto (Function.const α ‖c‖) l atTop := not_tendsto_atTop_of_tendsto_nhds tendsto_const_nhds simp only [isLittleO_const_left, or_iff_left_iff_imp] exact fun h => (this h).elim #align asymptotics.is_o_const_const_iff Asymptotics.isLittleO_const_const_iff @[simp] theorem isLittleO_pure {x} : f'' =o[pure x] g'' ↔ f'' x = 0 := calc f'' =o[pure x] g'' ↔ (fun _y : α => f'' x) =o[pure x] fun _ => g'' x := isLittleO_congr rfl rfl _ ↔ f'' x = 0 := isLittleO_const_const_iff #align asymptotics.is_o_pure Asymptotics.isLittleO_pure theorem isLittleO_const_id_cobounded (c : F'') : (fun _ => c) =o[Bornology.cobounded E''] id := isLittleO_const_left.2 <| .inr tendsto_norm_cobounded_atTop #align asymptotics.is_o_const_id_comap_norm_at_top Asymptotics.isLittleO_const_id_cobounded theorem isLittleO_const_id_atTop (c : E'') : (fun _x : ℝ => c) =o[atTop] id := isLittleO_const_left.2 <| Or.inr tendsto_abs_atTop_atTop #align asymptotics.is_o_const_id_at_top Asymptotics.isLittleO_const_id_atTop theorem isLittleO_const_id_atBot (c : E'') : (fun _x : ℝ => c) =o[atBot] id := isLittleO_const_left.2 <| Or.inr tendsto_abs_atBot_atTop #align asymptotics.is_o_const_id_at_bot Asymptotics.isLittleO_const_id_atBot /-! ### Eventually (u / v) * v = u If `u` and `v` are linked by an `IsBigOWith` relation, then we eventually have `(u / v) * v = u`, even if `v` vanishes. -/ section EventuallyMulDivCancel variable {u v : α → 𝕜} theorem IsBigOWith.eventually_mul_div_cancel (h : IsBigOWith c l u v) : u / v * v =ᶠ[l] u := Eventually.mono h.bound fun y hy => div_mul_cancel_of_imp fun hv => by simpa [hv] using hy #align asymptotics.is_O_with.eventually_mul_div_cancel Asymptotics.IsBigOWith.eventually_mul_div_cancel /-- If `u = O(v)` along `l`, then `(u / v) * v = u` eventually at `l`. -/ theorem IsBigO.eventually_mul_div_cancel (h : u =O[l] v) : u / v * v =ᶠ[l] u := let ⟨_c, hc⟩ := h.isBigOWith hc.eventually_mul_div_cancel #align asymptotics.is_O.eventually_mul_div_cancel Asymptotics.IsBigO.eventually_mul_div_cancel /-- If `u = o(v)` along `l`, then `(u / v) * v = u` eventually at `l`. -/ theorem IsLittleO.eventually_mul_div_cancel (h : u =o[l] v) : u / v * v =ᶠ[l] u := (h.forall_isBigOWith zero_lt_one).eventually_mul_div_cancel #align asymptotics.is_o.eventually_mul_div_cancel Asymptotics.IsLittleO.eventually_mul_div_cancel end EventuallyMulDivCancel /-! ### Equivalent definitions of the form `∃ φ, u =ᶠ[l] φ * v` in a `NormedField`. -/ section ExistsMulEq variable {u v : α → 𝕜} /-- If `‖φ‖` is eventually bounded by `c`, and `u =ᶠ[l] φ * v`, then we have `IsBigOWith c u v l`. This does not require any assumptions on `c`, which is why we keep this version along with `IsBigOWith_iff_exists_eq_mul`. -/ theorem isBigOWith_of_eq_mul {u v : α → R} (φ : α → R) (hφ : ∀ᶠ x in l, ‖φ x‖ ≤ c) (h : u =ᶠ[l] φ * v) : IsBigOWith c l u v := by simp only [IsBigOWith_def] refine h.symm.rw (fun x a => ‖a‖ ≤ c * ‖v x‖) (hφ.mono fun x hx => ?_) simp only [Pi.mul_apply] refine (norm_mul_le _ _).trans ?_ gcongr #align asymptotics.is_O_with_of_eq_mul Asymptotics.isBigOWith_of_eq_mul theorem isBigOWith_iff_exists_eq_mul (hc : 0 ≤ c) : IsBigOWith c l u v ↔ ∃ φ : α → 𝕜, (∀ᶠ x in l, ‖φ x‖ ≤ c) ∧ u =ᶠ[l] φ * v := by constructor · intro h use fun x => u x / v x refine ⟨Eventually.mono h.bound fun y hy => ?_, h.eventually_mul_div_cancel.symm⟩ simpa using div_le_of_nonneg_of_le_mul (norm_nonneg _) hc hy · rintro ⟨φ, hφ, h⟩ exact isBigOWith_of_eq_mul φ hφ h #align asymptotics.is_O_with_iff_exists_eq_mul Asymptotics.isBigOWith_iff_exists_eq_mul theorem IsBigOWith.exists_eq_mul (h : IsBigOWith c l u v) (hc : 0 ≤ c) : ∃ φ : α → 𝕜, (∀ᶠ x in l, ‖φ x‖ ≤ c) ∧ u =ᶠ[l] φ * v := (isBigOWith_iff_exists_eq_mul hc).mp h #align asymptotics.is_O_with.exists_eq_mul Asymptotics.IsBigOWith.exists_eq_mul theorem isBigO_iff_exists_eq_mul : u =O[l] v ↔ ∃ φ : α → 𝕜, l.IsBoundedUnder (· ≤ ·) (norm ∘ φ) ∧ u =ᶠ[l] φ * v := by constructor · rintro h rcases h.exists_nonneg with ⟨c, hnnc, hc⟩ rcases hc.exists_eq_mul hnnc with ⟨φ, hφ, huvφ⟩ exact ⟨φ, ⟨c, hφ⟩, huvφ⟩ · rintro ⟨φ, ⟨c, hφ⟩, huvφ⟩ exact isBigO_iff_isBigOWith.2 ⟨c, isBigOWith_of_eq_mul φ hφ huvφ⟩ #align asymptotics.is_O_iff_exists_eq_mul Asymptotics.isBigO_iff_exists_eq_mul alias ⟨IsBigO.exists_eq_mul, _⟩ := isBigO_iff_exists_eq_mul #align asymptotics.is_O.exists_eq_mul Asymptotics.IsBigO.exists_eq_mul theorem isLittleO_iff_exists_eq_mul : u =o[l] v ↔ ∃ φ : α → 𝕜, Tendsto φ l (𝓝 0) ∧ u =ᶠ[l] φ * v := by constructor · exact fun h => ⟨fun x => u x / v x, h.tendsto_div_nhds_zero, h.eventually_mul_div_cancel.symm⟩ · simp only [IsLittleO_def] rintro ⟨φ, hφ, huvφ⟩ c hpos rw [NormedAddCommGroup.tendsto_nhds_zero] at hφ exact isBigOWith_of_eq_mul _ ((hφ c hpos).mono fun x => le_of_lt) huvφ #align asymptotics.is_o_iff_exists_eq_mul Asymptotics.isLittleO_iff_exists_eq_mul alias ⟨IsLittleO.exists_eq_mul, _⟩ := isLittleO_iff_exists_eq_mul #align asymptotics.is_o.exists_eq_mul Asymptotics.IsLittleO.exists_eq_mul end ExistsMulEq /-! ### Miscellaneous lemmas -/ theorem div_isBoundedUnder_of_isBigO {α : Type*} {l : Filter α} {f g : α → 𝕜} (h : f =O[l] g) : IsBoundedUnder (· ≤ ·) l fun x => ‖f x / g x‖ := by obtain ⟨c, h₀, hc⟩ := h.exists_nonneg refine ⟨c, eventually_map.2 (hc.bound.mono fun x hx => ?_)⟩ rw [norm_div] exact div_le_of_nonneg_of_le_mul (norm_nonneg _) h₀ hx #align asymptotics.div_is_bounded_under_of_is_O Asymptotics.div_isBoundedUnder_of_isBigO theorem isBigO_iff_div_isBoundedUnder {α : Type*} {l : Filter α} {f g : α → 𝕜} (hgf : ∀ᶠ x in l, g x = 0 → f x = 0) : f =O[l] g ↔ IsBoundedUnder (· ≤ ·) l fun x => ‖f x / g x‖ := by refine ⟨div_isBoundedUnder_of_isBigO, fun h => ?_⟩ obtain ⟨c, hc⟩ := h simp only [eventually_map, norm_div] at hc refine IsBigO.of_bound c (hc.mp <| hgf.mono fun x hx₁ hx₂ => ?_) by_cases hgx : g x = 0 · simp [hx₁ hgx, hgx] · exact (div_le_iff (norm_pos_iff.2 hgx)).mp hx₂ #align asymptotics.is_O_iff_div_is_bounded_under Asymptotics.isBigO_iff_div_isBoundedUnder theorem isBigO_of_div_tendsto_nhds {α : Type*} {l : Filter α} {f g : α → 𝕜} (hgf : ∀ᶠ x in l, g x = 0 → f x = 0) (c : 𝕜) (H : Filter.Tendsto (f / g) l (𝓝 c)) : f =O[l] g := (isBigO_iff_div_isBoundedUnder hgf).2 <| H.norm.isBoundedUnder_le #align asymptotics.is_O_of_div_tendsto_nhds Asymptotics.isBigO_of_div_tendsto_nhds theorem IsLittleO.tendsto_zero_of_tendsto {α E 𝕜 : Type*} [NormedAddCommGroup E] [NormedField 𝕜] {u : α → E} {v : α → 𝕜} {l : Filter α} {y : 𝕜} (huv : u =o[l] v) (hv : Tendsto v l (𝓝 y)) : Tendsto u l (𝓝 0) := by suffices h : u =o[l] fun _x => (1 : 𝕜) by rwa [isLittleO_one_iff] at h exact huv.trans_isBigO (hv.isBigO_one 𝕜) #align asymptotics.is_o.tendsto_zero_of_tendsto Asymptotics.IsLittleO.tendsto_zero_of_tendsto theorem isLittleO_pow_pow {m n : ℕ} (h : m < n) : (fun x : 𝕜 => x ^ n) =o[𝓝 0] fun x => x ^ m := by rcases lt_iff_exists_add.1 h with ⟨p, hp0 : 0 < p, rfl⟩ suffices (fun x : 𝕜 => x ^ m * x ^ p) =o[𝓝 0] fun x => x ^ m * 1 ^ p by simpa only [pow_add, one_pow, mul_one] exact IsBigO.mul_isLittleO (isBigO_refl _ _) (IsLittleO.pow ((isLittleO_one_iff _).2 tendsto_id) hp0) #align asymptotics.is_o_pow_pow Asymptotics.isLittleO_pow_pow theorem isLittleO_norm_pow_norm_pow {m n : ℕ} (h : m < n) : (fun x : E' => ‖x‖ ^ n) =o[𝓝 0] fun x => ‖x‖ ^ m := (isLittleO_pow_pow h).comp_tendsto tendsto_norm_zero #align asymptotics.is_o_norm_pow_norm_pow Asymptotics.isLittleO_norm_pow_norm_pow theorem isLittleO_pow_id {n : ℕ} (h : 1 < n) : (fun x : 𝕜 => x ^ n) =o[𝓝 0] fun x => x := by convert isLittleO_pow_pow h (𝕜 := 𝕜) simp only [pow_one] #align asymptotics.is_o_pow_id Asymptotics.isLittleO_pow_id theorem isLittleO_norm_pow_id {n : ℕ} (h : 1 < n) : (fun x : E' => ‖x‖ ^ n) =o[𝓝 0] fun x => x := by have := @isLittleO_norm_pow_norm_pow E' _ _ _ h simp only [pow_one] at this exact isLittleO_norm_right.mp this #align asymptotics.is_o_norm_pow_id Asymptotics.isLittleO_norm_pow_id theorem IsBigO.eq_zero_of_norm_pow_within {f : E'' → F''} {s : Set E''} {x₀ : E''} {n : ℕ} (h : f =O[𝓝[s] x₀] fun x => ‖x - x₀‖ ^ n) (hx₀ : x₀ ∈ s) (hn : n ≠ 0) : f x₀ = 0 := mem_of_mem_nhdsWithin hx₀ h.eq_zero_imp <| by simp_rw [sub_self, norm_zero, zero_pow hn] #align asymptotics.is_O.eq_zero_of_norm_pow_within Asymptotics.IsBigO.eq_zero_of_norm_pow_within theorem IsBigO.eq_zero_of_norm_pow {f : E'' → F''} {x₀ : E''} {n : ℕ} (h : f =O[𝓝 x₀] fun x => ‖x - x₀‖ ^ n) (hn : n ≠ 0) : f x₀ = 0 := by rw [← nhdsWithin_univ] at h exact h.eq_zero_of_norm_pow_within (mem_univ _) hn #align asymptotics.is_O.eq_zero_of_norm_pow Asymptotics.IsBigO.eq_zero_of_norm_pow theorem isLittleO_pow_sub_pow_sub (x₀ : E') {n m : ℕ} (h : n < m) : (fun x => ‖x - x₀‖ ^ m) =o[𝓝 x₀] fun x => ‖x - x₀‖ ^ n := haveI : Tendsto (fun x => ‖x - x₀‖) (𝓝 x₀) (𝓝 0) := by apply tendsto_norm_zero.comp rw [← sub_self x₀] exact tendsto_id.sub tendsto_const_nhds (isLittleO_pow_pow h).comp_tendsto this #align asymptotics.is_o_pow_sub_pow_sub Asymptotics.isLittleO_pow_sub_pow_sub theorem isLittleO_pow_sub_sub (x₀ : E') {m : ℕ} (h : 1 < m) : (fun x => ‖x - x₀‖ ^ m) =o[𝓝 x₀] fun x => x - x₀ := by simpa only [isLittleO_norm_right, pow_one] using isLittleO_pow_sub_pow_sub x₀ h #align asymptotics.is_o_pow_sub_sub Asymptotics.isLittleO_pow_sub_sub theorem IsBigOWith.right_le_sub_of_lt_one {f₁ f₂ : α → E'} (h : IsBigOWith c l f₁ f₂) (hc : c < 1) : IsBigOWith (1 / (1 - c)) l f₂ fun x => f₂ x - f₁ x := IsBigOWith.of_bound <| mem_of_superset h.bound fun x hx => by simp only [mem_setOf_eq] at hx ⊢ rw [mul_comm, one_div, ← div_eq_mul_inv, _root_.le_div_iff, mul_sub, mul_one, mul_comm] · exact le_trans (sub_le_sub_left hx _) (norm_sub_norm_le _ _) · exact sub_pos.2 hc #align asymptotics.is_O_with.right_le_sub_of_lt_1 Asymptotics.IsBigOWith.right_le_sub_of_lt_one theorem IsBigOWith.right_le_add_of_lt_one {f₁ f₂ : α → E'} (h : IsBigOWith c l f₁ f₂) (hc : c < 1) : IsBigOWith (1 / (1 - c)) l f₂ fun x => f₁ x + f₂ x := (h.neg_right.right_le_sub_of_lt_one hc).neg_right.of_neg_left.congr rfl (fun x ↦ rfl) fun x ↦ by rw [neg_sub, sub_neg_eq_add] #align asymptotics.is_O_with.right_le_add_of_lt_1 Asymptotics.IsBigOWith.right_le_add_of_lt_one -- 2024-01-31 @[deprecated] alias IsBigOWith.right_le_sub_of_lt_1 := IsBigOWith.right_le_sub_of_lt_one @[deprecated] alias IsBigOWith.right_le_add_of_lt_1 := IsBigOWith.right_le_add_of_lt_one theorem IsLittleO.right_isBigO_sub {f₁ f₂ : α → E'} (h : f₁ =o[l] f₂) : f₂ =O[l] fun x => f₂ x - f₁ x := ((h.def' one_half_pos).right_le_sub_of_lt_one one_half_lt_one).isBigO #align asymptotics.is_o.right_is_O_sub Asymptotics.IsLittleO.right_isBigO_sub theorem IsLittleO.right_isBigO_add {f₁ f₂ : α → E'} (h : f₁ =o[l] f₂) : f₂ =O[l] fun x => f₁ x + f₂ x := ((h.def' one_half_pos).right_le_add_of_lt_one one_half_lt_one).isBigO #align asymptotics.is_o.right_is_O_add Asymptotics.IsLittleO.right_isBigO_add theorem IsLittleO.right_isBigO_add' {f₁ f₂ : α → E'} (h : f₁ =o[l] f₂) : f₂ =O[l] (f₂ + f₁) := add_comm f₁ f₂ ▸ h.right_isBigO_add /-- If `f x = O(g x)` along `cofinite`, then there exists a positive constant `C` such that `‖f x‖ ≤ C * ‖g x‖` whenever `g x ≠ 0`. -/ theorem bound_of_isBigO_cofinite (h : f =O[cofinite] g'') : ∃ C > 0, ∀ ⦃x⦄, g'' x ≠ 0 → ‖f x‖ ≤ C * ‖g'' x‖ := by rcases h.exists_pos with ⟨C, C₀, hC⟩ rw [IsBigOWith_def, eventually_cofinite] at hC rcases (hC.toFinset.image fun x => ‖f x‖ / ‖g'' x‖).exists_le with ⟨C', hC'⟩ have : ∀ x, C * ‖g'' x‖ < ‖f x‖ → ‖f x‖ / ‖g'' x‖ ≤ C' := by simpa using hC' refine ⟨max C C', lt_max_iff.2 (Or.inl C₀), fun x h₀ => ?_⟩ rw [max_mul_of_nonneg _ _ (norm_nonneg _), le_max_iff, or_iff_not_imp_left, not_le] exact fun hx => (div_le_iff (norm_pos_iff.2 h₀)).1 (this _ hx) #align asymptotics.bound_of_is_O_cofinite Asymptotics.bound_of_isBigO_cofinite theorem isBigO_cofinite_iff (h : ∀ x, g'' x = 0 → f'' x = 0) : f'' =O[cofinite] g'' ↔ ∃ C, ∀ x, ‖f'' x‖ ≤ C * ‖g'' x‖ := ⟨fun h' => let ⟨C, _C₀, hC⟩ := bound_of_isBigO_cofinite h' ⟨C, fun x => if hx : g'' x = 0 then by simp [h _ hx, hx] else hC hx⟩, fun h => (isBigO_top.2 h).mono le_top⟩ #align asymptotics.is_O_cofinite_iff Asymptotics.isBigO_cofinite_iff theorem bound_of_isBigO_nat_atTop {f : ℕ → E} {g'' : ℕ → E''} (h : f =O[atTop] g'') : ∃ C > 0, ∀ ⦃x⦄, g'' x ≠ 0 → ‖f x‖ ≤ C * ‖g'' x‖ := bound_of_isBigO_cofinite <| by rwa [Nat.cofinite_eq_atTop] #align asymptotics.bound_of_is_O_nat_at_top Asymptotics.bound_of_isBigO_nat_atTop theorem isBigO_nat_atTop_iff {f : ℕ → E''} {g : ℕ → F''} (h : ∀ x, g x = 0 → f x = 0) : f =O[atTop] g ↔ ∃ C, ∀ x, ‖f x‖ ≤ C * ‖g x‖ := by rw [← Nat.cofinite_eq_atTop, isBigO_cofinite_iff h] #align asymptotics.is_O_nat_at_top_iff Asymptotics.isBigO_nat_atTop_iff theorem isBigO_one_nat_atTop_iff {f : ℕ → E''} : f =O[atTop] (fun _n => 1 : ℕ → ℝ) ↔ ∃ C, ∀ n, ‖f n‖ ≤ C := Iff.trans (isBigO_nat_atTop_iff fun n h => (one_ne_zero h).elim) <| by simp only [norm_one, mul_one] #align asymptotics.is_O_one_nat_at_top_iff Asymptotics.isBigO_one_nat_atTop_iff theorem isBigOWith_pi {ι : Type*} [Fintype ι] {E' : ι → Type*} [∀ i, NormedAddCommGroup (E' i)] {f : α → ∀ i, E' i} {C : ℝ} (hC : 0 ≤ C) : IsBigOWith C l f g' ↔ ∀ i, IsBigOWith C l (fun x => f x i) g' := by have : ∀ x, 0 ≤ C * ‖g' x‖ := fun x => mul_nonneg hC (norm_nonneg _) simp only [isBigOWith_iff, pi_norm_le_iff_of_nonneg (this _), eventually_all] #align asymptotics.is_O_with_pi Asymptotics.isBigOWith_pi @[simp]
Mathlib/Analysis/Asymptotics/Asymptotics.lean
2,208
2,211
theorem isBigO_pi {ι : Type*} [Fintype ι] {E' : ι → Type*} [∀ i, NormedAddCommGroup (E' i)] {f : α → ∀ i, E' i} : f =O[l] g' ↔ ∀ i, (fun x => f x i) =O[l] g' := by
simp only [isBigO_iff_eventually_isBigOWith, ← eventually_all] exact eventually_congr (eventually_atTop.2 ⟨0, fun c => isBigOWith_pi⟩)
/- Copyright (c) 2022 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Analysis.Complex.CauchyIntegral import Mathlib.Analysis.NormedSpace.Completion import Mathlib.Analysis.NormedSpace.Extr import Mathlib.Topology.Order.ExtrClosure #align_import analysis.complex.abs_max from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Maximum modulus principle In this file we prove several versions of the maximum modulus principle. There are several statements that can be called "the maximum modulus principle" for maps between normed complex spaces. They differ by assumptions on the domain (any space, a nontrivial space, a finite dimensional space), assumptions on the codomain (any space, a strictly convex space), and by conclusion (either equality of norms or of the values of the function). ## Main results ### Theorems for any codomain Consider a function `f : E → F` that is complex differentiable on a set `s`, is continuous on its closure, and `‖f x‖` has a maximum on `s` at `c`. We prove the following theorems. - `Complex.norm_eqOn_closedBall_of_isMaxOn`: if `s = Metric.ball c r`, then `‖f x‖ = ‖f c‖` for any `x` from the corresponding closed ball; - `Complex.norm_eq_norm_of_isMaxOn_of_ball_subset`: if `Metric.ball c (dist w c) ⊆ s`, then `‖f w‖ = ‖f c‖`; - `Complex.norm_eqOn_of_isPreconnected_of_isMaxOn`: if `U` is an open (pre)connected set, `f` is complex differentiable on `U`, and `‖f x‖` has a maximum on `U` at `c ∈ U`, then `‖f x‖ = ‖f c‖` for all `x ∈ U`; - `Complex.norm_eqOn_closure_of_isPreconnected_of_isMaxOn`: if `s` is open and (pre)connected and `c ∈ s`, then `‖f x‖ = ‖f c‖` for all `x ∈ closure s`; - `Complex.norm_eventually_eq_of_isLocalMax`: if `f` is complex differentiable in a neighborhood of `c` and `‖f x‖` has a local maximum at `c`, then `‖f x‖` is locally a constant in a neighborhood of `c`. ### Theorems for a strictly convex codomain If the codomain `F` is a strictly convex space, then in the lemmas from the previous section we can prove `f w = f c` instead of `‖f w‖ = ‖f c‖`, see `Complex.eqOn_of_isPreconnected_of_isMaxOn_norm`, `Complex.eqOn_closure_of_isPreconnected_of_isMaxOn_norm`, `Complex.eq_of_isMaxOn_of_ball_subset`, `Complex.eqOn_closedBall_of_isMaxOn_norm`, and `Complex.eventually_eq_of_isLocalMax_norm`. ### Values on the frontier Finally, we prove some corollaries that relate the (norm of the) values of a function on a set to its values on the frontier of the set. All these lemmas assume that `E` is a nontrivial space. In this section `f g : E → F` are functions that are complex differentiable on a bounded set `s` and are continuous on its closure. We prove the following theorems. - `Complex.exists_mem_frontier_isMaxOn_norm`: If `E` is a finite dimensional space and `s` is a nonempty bounded set, then there exists a point `z ∈ frontier s` such that `(‖f ·‖)` takes it maximum value on `closure s` at `z`. - `Complex.norm_le_of_forall_mem_frontier_norm_le`: if `‖f z‖ ≤ C` for all `z ∈ frontier s`, then `‖f z‖ ≤ C` for all `z ∈ s`; note that this theorem does not require `E` to be a finite dimensional space. - `Complex.eqOn_closure_of_eqOn_frontier`: if `f x = g x` on the frontier of `s`, then `f x = g x` on `closure s`; - `Complex.eqOn_of_eqOn_frontier`: if `f x = g x` on the frontier of `s`, then `f x = g x` on `s`. ## Tags maximum modulus principle, complex analysis -/ open TopologicalSpace Metric Set Filter Asymptotics Function MeasureTheory AffineMap Bornology open scoped Topology Filter NNReal Real universe u v w variable {E : Type u} [NormedAddCommGroup E] [NormedSpace ℂ E] {F : Type v} [NormedAddCommGroup F] [NormedSpace ℂ F] local postfix:100 "̂" => UniformSpace.Completion namespace Complex /-! ### Auxiliary lemmas We split the proof into a series of lemmas. First we prove the principle for a function `f : ℂ → F` with an additional assumption that `F` is a complete space, then drop unneeded assumptions one by one. The lemmas with names `*_auxₙ` are considered to be private and should not be used outside of this file. -/ theorem norm_max_aux₁ [CompleteSpace F] {f : ℂ → F} {z w : ℂ} (hd : DiffContOnCl ℂ f (ball z (dist w z))) (hz : IsMaxOn (norm ∘ f) (closedBall z (dist w z)) z) : ‖f w‖ = ‖f z‖ := by -- Consider a circle of radius `r = dist w z`. set r : ℝ := dist w z have hw : w ∈ closedBall z r := mem_closedBall.2 le_rfl -- Assume the converse. Since `‖f w‖ ≤ ‖f z‖`, we have `‖f w‖ < ‖f z‖`. refine (isMaxOn_iff.1 hz _ hw).antisymm (not_lt.1 ?_) rintro hw_lt : ‖f w‖ < ‖f z‖ have hr : 0 < r := dist_pos.2 (ne_of_apply_ne (norm ∘ f) hw_lt.ne) -- Due to Cauchy integral formula, it suffices to prove the following inequality. suffices ‖∮ ζ in C(z, r), (ζ - z)⁻¹ • f ζ‖ < 2 * π * ‖f z‖ by refine this.ne ?_ have A : (∮ ζ in C(z, r), (ζ - z)⁻¹ • f ζ) = (2 * π * I : ℂ) • f z := hd.circleIntegral_sub_inv_smul (mem_ball_self hr) simp [A, norm_smul, Real.pi_pos.le] suffices ‖∮ ζ in C(z, r), (ζ - z)⁻¹ • f ζ‖ < 2 * π * r * (‖f z‖ / r) by rwa [mul_assoc, mul_div_cancel₀ _ hr.ne'] at this /- This inequality is true because `‖(ζ - z)⁻¹ • f ζ‖ ≤ ‖f z‖ / r` for all `ζ` on the circle and this inequality is strict at `ζ = w`. -/ have hsub : sphere z r ⊆ closedBall z r := sphere_subset_closedBall refine circleIntegral.norm_integral_lt_of_norm_le_const_of_lt hr ?_ ?_ ⟨w, rfl, ?_⟩ · show ContinuousOn (fun ζ : ℂ => (ζ - z)⁻¹ • f ζ) (sphere z r) refine ((continuousOn_id.sub continuousOn_const).inv₀ ?_).smul (hd.continuousOn_ball.mono hsub) exact fun ζ hζ => sub_ne_zero.2 (ne_of_mem_sphere hζ hr.ne') · show ∀ ζ ∈ sphere z r, ‖(ζ - z)⁻¹ • f ζ‖ ≤ ‖f z‖ / r rintro ζ (hζ : abs (ζ - z) = r) rw [le_div_iff hr, norm_smul, norm_inv, norm_eq_abs, hζ, mul_comm, mul_inv_cancel_left₀ hr.ne'] exact hz (hsub hζ) show ‖(w - z)⁻¹ • f w‖ < ‖f z‖ / r rw [norm_smul, norm_inv, norm_eq_abs, ← div_eq_inv_mul] exact (div_lt_div_right hr).2 hw_lt #align complex.norm_max_aux₁ Complex.norm_max_aux₁ /-! Now we drop the assumption `CompleteSpace F` by embedding `F` into its completion. -/ theorem norm_max_aux₂ {f : ℂ → F} {z w : ℂ} (hd : DiffContOnCl ℂ f (ball z (dist w z))) (hz : IsMaxOn (norm ∘ f) (closedBall z (dist w z)) z) : ‖f w‖ = ‖f z‖ := by set e : F →L[ℂ] F̂ := UniformSpace.Completion.toComplL have he : ∀ x, ‖e x‖ = ‖x‖ := UniformSpace.Completion.norm_coe replace hz : IsMaxOn (norm ∘ e ∘ f) (closedBall z (dist w z)) z := by simpa only [IsMaxOn, (· ∘ ·), he] using hz simpa only [he, (· ∘ ·)] using norm_max_aux₁ (e.differentiable.comp_diffContOnCl hd) hz #align complex.norm_max_aux₂ Complex.norm_max_aux₂ /-! Then we replace the assumption `IsMaxOn (norm ∘ f) (Metric.closedBall z r) z` with a seemingly weaker assumption `IsMaxOn (norm ∘ f) (Metric.ball z r) z`. -/ theorem norm_max_aux₃ {f : ℂ → F} {z w : ℂ} {r : ℝ} (hr : dist w z = r) (hd : DiffContOnCl ℂ f (ball z r)) (hz : IsMaxOn (norm ∘ f) (ball z r) z) : ‖f w‖ = ‖f z‖ := by subst r rcases eq_or_ne w z with (rfl | hne); · rfl rw [← dist_ne_zero] at hne exact norm_max_aux₂ hd (closure_ball z hne ▸ hz.closure hd.continuousOn.norm) #align complex.norm_max_aux₃ Complex.norm_max_aux₃ /-! ### Maximum modulus principle for any codomain If we do not assume that the codomain is a strictly convex space, then we can only claim that the **norm** `‖f x‖` is locally constant. -/ /-! Finally, we generalize the theorem from a disk in `ℂ` to a closed ball in any normed space. -/ /-- **Maximum modulus principle** on a closed ball: if `f : E → F` is continuous on a closed ball, is complex differentiable on the corresponding open ball, and the norm `‖f w‖` takes its maximum value on the open ball at its center, then the norm `‖f w‖` is constant on the closed ball. -/ theorem norm_eqOn_closedBall_of_isMaxOn {f : E → F} {z : E} {r : ℝ} (hd : DiffContOnCl ℂ f (ball z r)) (hz : IsMaxOn (norm ∘ f) (ball z r) z) : EqOn (norm ∘ f) (const E ‖f z‖) (closedBall z r) := by intro w hw rw [mem_closedBall, dist_comm] at hw rcases eq_or_ne z w with (rfl | hne); · rfl set e := (lineMap z w : ℂ → E) have hde : Differentiable ℂ e := (differentiable_id.smul_const (w - z)).add_const z suffices ‖(f ∘ e) (1 : ℂ)‖ = ‖(f ∘ e) (0 : ℂ)‖ by simpa [e] have hr : dist (1 : ℂ) 0 = 1 := by simp have hball : MapsTo e (ball 0 1) (ball z r) := by refine ((lipschitzWith_lineMap z w).mapsTo_ball (mt nndist_eq_zero.1 hne) 0 1).mono Subset.rfl ?_ simpa only [lineMap_apply_zero, mul_one, coe_nndist] using ball_subset_ball hw exact norm_max_aux₃ hr (hd.comp hde.diffContOnCl hball) (hz.comp_mapsTo hball (lineMap_apply_zero z w)) #align complex.norm_eq_on_closed_ball_of_is_max_on Complex.norm_eqOn_closedBall_of_isMaxOn /-- **Maximum modulus principle**: if `f : E → F` is complex differentiable on a set `s`, the norm of `f` takes it maximum on `s` at `z`, and `w` is a point such that the closed ball with center `z` and radius `dist w z` is included in `s`, then `‖f w‖ = ‖f z‖`. -/ theorem norm_eq_norm_of_isMaxOn_of_ball_subset {f : E → F} {s : Set E} {z w : E} (hd : DiffContOnCl ℂ f s) (hz : IsMaxOn (norm ∘ f) s z) (hsub : ball z (dist w z) ⊆ s) : ‖f w‖ = ‖f z‖ := norm_eqOn_closedBall_of_isMaxOn (hd.mono hsub) (hz.on_subset hsub) (mem_closedBall.2 le_rfl) #align complex.norm_eq_norm_of_is_max_on_of_ball_subset Complex.norm_eq_norm_of_isMaxOn_of_ball_subset /-- **Maximum modulus principle**: if `f : E → F` is complex differentiable in a neighborhood of `c` and the norm `‖f z‖` has a local maximum at `c`, then `‖f z‖` is locally constant in a neighborhood of `c`. -/ theorem norm_eventually_eq_of_isLocalMax {f : E → F} {c : E} (hd : ∀ᶠ z in 𝓝 c, DifferentiableAt ℂ f z) (hc : IsLocalMax (norm ∘ f) c) : ∀ᶠ y in 𝓝 c, ‖f y‖ = ‖f c‖ := by rcases nhds_basis_closedBall.eventually_iff.1 (hd.and hc) with ⟨r, hr₀, hr⟩ exact nhds_basis_closedBall.eventually_iff.2 ⟨r, hr₀, norm_eqOn_closedBall_of_isMaxOn (DifferentiableOn.diffContOnCl fun x hx => (hr <| closure_ball_subset_closedBall hx).1.differentiableWithinAt) fun x hx => (hr <| ball_subset_closedBall hx).2⟩ #align complex.norm_eventually_eq_of_is_local_max Complex.norm_eventually_eq_of_isLocalMax theorem isOpen_setOf_mem_nhds_and_isMaxOn_norm {f : E → F} {s : Set E} (hd : DifferentiableOn ℂ f s) : IsOpen {z | s ∈ 𝓝 z ∧ IsMaxOn (norm ∘ f) s z} := by refine isOpen_iff_mem_nhds.2 fun z hz => (eventually_eventually_nhds.2 hz.1).and ?_ replace hd : ∀ᶠ w in 𝓝 z, DifferentiableAt ℂ f w := hd.eventually_differentiableAt hz.1 exact (norm_eventually_eq_of_isLocalMax hd <| hz.2.isLocalMax hz.1).mono fun x hx y hy => le_trans (hz.2 hy).out hx.ge #align complex.is_open_set_of_mem_nhds_and_is_max_on_norm Complex.isOpen_setOf_mem_nhds_and_isMaxOn_norm /-- **Maximum modulus principle** on a connected set. Let `U` be a (pre)connected open set in a complex normed space. Let `f : E → F` be a function that is complex differentiable on `U`. Suppose that `‖f x‖` takes its maximum value on `U` at `c ∈ U`. Then `‖f x‖ = ‖f c‖` for all `x ∈ U`. -/ theorem norm_eqOn_of_isPreconnected_of_isMaxOn {f : E → F} {U : Set E} {c : E} (hc : IsPreconnected U) (ho : IsOpen U) (hd : DifferentiableOn ℂ f U) (hcU : c ∈ U) (hm : IsMaxOn (norm ∘ f) U c) : EqOn (norm ∘ f) (const E ‖f c‖) U := by set V := U ∩ {z | IsMaxOn (norm ∘ f) U z} have hV : ∀ x ∈ V, ‖f x‖ = ‖f c‖ := fun x hx => le_antisymm (hm hx.1) (hx.2 hcU) suffices U ⊆ V from fun x hx => hV x (this hx) have hVo : IsOpen V := by simpa only [ho.mem_nhds_iff, setOf_and, setOf_mem_eq] using isOpen_setOf_mem_nhds_and_isMaxOn_norm hd have hVne : (U ∩ V).Nonempty := ⟨c, hcU, hcU, hm⟩ set W := U ∩ {z | ‖f z‖ ≠ ‖f c‖} have hWo : IsOpen W := hd.continuousOn.norm.isOpen_inter_preimage ho isOpen_ne have hdVW : Disjoint V W := disjoint_left.mpr fun x hxV hxW => hxW.2 (hV x hxV) have hUVW : U ⊆ V ∪ W := fun x hx => (eq_or_ne ‖f x‖ ‖f c‖).imp (fun h => ⟨hx, fun y hy => (hm hy).out.trans_eq h.symm⟩) (And.intro hx) exact hc.subset_left_of_subset_union hVo hWo hdVW hUVW hVne #align complex.norm_eq_on_of_is_preconnected_of_is_max_on Complex.norm_eqOn_of_isPreconnected_of_isMaxOn /-- **Maximum modulus principle** on a connected set. Let `U` be a (pre)connected open set in a complex normed space. Let `f : E → F` be a function that is complex differentiable on `U` and is continuous on its closure. Suppose that `‖f x‖` takes its maximum value on `U` at `c ∈ U`. Then `‖f x‖ = ‖f c‖` for all `x ∈ closure U`. -/ theorem norm_eqOn_closure_of_isPreconnected_of_isMaxOn {f : E → F} {U : Set E} {c : E} (hc : IsPreconnected U) (ho : IsOpen U) (hd : DiffContOnCl ℂ f U) (hcU : c ∈ U) (hm : IsMaxOn (norm ∘ f) U c) : EqOn (norm ∘ f) (const E ‖f c‖) (closure U) := (norm_eqOn_of_isPreconnected_of_isMaxOn hc ho hd.differentiableOn hcU hm).of_subset_closure hd.continuousOn.norm continuousOn_const subset_closure Subset.rfl #align complex.norm_eq_on_closure_of_is_preconnected_of_is_max_on Complex.norm_eqOn_closure_of_isPreconnected_of_isMaxOn section StrictConvex /-! ### The case of a strictly convex codomain If the codomain `F` is a strictly convex space, then we can claim equalities like `f w = f z` instead of `‖f w‖ = ‖f z‖`. Instead of repeating the proof starting with lemmas about integrals, we apply a corresponding lemma above twice: for `f` and for `(f · + f c)`. Then we have `‖f w‖ = ‖f z‖` and `‖f w + f z‖ = ‖f z + f z‖`, thus `‖f w + f z‖ = ‖f w‖ + ‖f z‖`. This is only possible if `f w = f z`, see `eq_of_norm_eq_of_norm_add_eq`. -/ variable [StrictConvexSpace ℝ F] /-- **Maximum modulus principle** on a connected set. Let `U` be a (pre)connected open set in a complex normed space. Let `f : E → F` be a function that is complex differentiable on `U`. Suppose that `‖f x‖` takes its maximum value on `U` at `c ∈ U`. Then `f x = f c` for all `x ∈ U`. TODO: change assumption from `IsMaxOn` to `IsLocalMax`. -/ theorem eqOn_of_isPreconnected_of_isMaxOn_norm {f : E → F} {U : Set E} {c : E} (hc : IsPreconnected U) (ho : IsOpen U) (hd : DifferentiableOn ℂ f U) (hcU : c ∈ U) (hm : IsMaxOn (norm ∘ f) U c) : EqOn f (const E (f c)) U := fun x hx => have H₁ : ‖f x‖ = ‖f c‖ := norm_eqOn_of_isPreconnected_of_isMaxOn hc ho hd hcU hm hx have H₂ : ‖f x + f c‖ = ‖f c + f c‖ := norm_eqOn_of_isPreconnected_of_isMaxOn hc ho (hd.add_const _) hcU hm.norm_add_self hx eq_of_norm_eq_of_norm_add_eq H₁ <| by simp only [H₂, SameRay.rfl.norm_add, H₁, Function.const] #align complex.eq_on_of_is_preconnected_of_is_max_on_norm Complex.eqOn_of_isPreconnected_of_isMaxOn_norm /-- **Maximum modulus principle** on a connected set. Let `U` be a (pre)connected open set in a complex normed space. Let `f : E → F` be a function that is complex differentiable on `U` and is continuous on its closure. Suppose that `‖f x‖` takes its maximum value on `U` at `c ∈ U`. Then `f x = f c` for all `x ∈ closure U`. -/ theorem eqOn_closure_of_isPreconnected_of_isMaxOn_norm {f : E → F} {U : Set E} {c : E} (hc : IsPreconnected U) (ho : IsOpen U) (hd : DiffContOnCl ℂ f U) (hcU : c ∈ U) (hm : IsMaxOn (norm ∘ f) U c) : EqOn f (const E (f c)) (closure U) := (eqOn_of_isPreconnected_of_isMaxOn_norm hc ho hd.differentiableOn hcU hm).of_subset_closure hd.continuousOn continuousOn_const subset_closure Subset.rfl #align complex.eq_on_closure_of_is_preconnected_of_is_max_on_norm Complex.eqOn_closure_of_isPreconnected_of_isMaxOn_norm /-- **Maximum modulus principle**. Let `f : E → F` be a function between complex normed spaces. Suppose that the codomain `F` is a strictly convex space, `f` is complex differentiable on a set `s`, `f` is continuous on the closure of `s`, the norm of `f` takes it maximum on `s` at `z`, and `w` is a point such that the closed ball with center `z` and radius `dist w z` is included in `s`, then `f w = f z`. -/ theorem eq_of_isMaxOn_of_ball_subset {f : E → F} {s : Set E} {z w : E} (hd : DiffContOnCl ℂ f s) (hz : IsMaxOn (norm ∘ f) s z) (hsub : ball z (dist w z) ⊆ s) : f w = f z := have H₁ : ‖f w‖ = ‖f z‖ := norm_eq_norm_of_isMaxOn_of_ball_subset hd hz hsub have H₂ : ‖f w + f z‖ = ‖f z + f z‖ := norm_eq_norm_of_isMaxOn_of_ball_subset (hd.add_const _) hz.norm_add_self hsub eq_of_norm_eq_of_norm_add_eq H₁ <| by simp only [H₂, SameRay.rfl.norm_add, H₁] #align complex.eq_of_is_max_on_of_ball_subset Complex.eq_of_isMaxOn_of_ball_subset /-- **Maximum modulus principle** on a closed ball. Suppose that a function `f : E → F` from a normed complex space to a strictly convex normed complex space has the following properties: - it is continuous on a closed ball `Metric.closedBall z r`, - it is complex differentiable on the corresponding open ball; - the norm `‖f w‖` takes its maximum value on the open ball at its center. Then `f` is a constant on the closed ball. -/ theorem eqOn_closedBall_of_isMaxOn_norm {f : E → F} {z : E} {r : ℝ} (hd : DiffContOnCl ℂ f (ball z r)) (hz : IsMaxOn (norm ∘ f) (ball z r) z) : EqOn f (const E (f z)) (closedBall z r) := fun _x hx => eq_of_isMaxOn_of_ball_subset hd hz <| ball_subset_ball hx #align complex.eq_on_closed_ball_of_is_max_on_norm Complex.eqOn_closedBall_of_isMaxOn_norm /-- **Maximum modulus principle**: if `f : E → F` is complex differentiable in a neighborhood of `c` and the norm `‖f z‖` has a local maximum at `c`, then `f` is locally constant in a neighborhood of `c`. -/ theorem eventually_eq_of_isLocalMax_norm {f : E → F} {c : E} (hd : ∀ᶠ z in 𝓝 c, DifferentiableAt ℂ f z) (hc : IsLocalMax (norm ∘ f) c) : ∀ᶠ y in 𝓝 c, f y = f c := by rcases nhds_basis_closedBall.eventually_iff.1 (hd.and hc) with ⟨r, hr₀, hr⟩ exact nhds_basis_closedBall.eventually_iff.2 ⟨r, hr₀, eqOn_closedBall_of_isMaxOn_norm (DifferentiableOn.diffContOnCl fun x hx => (hr <| closure_ball_subset_closedBall hx).1.differentiableWithinAt) fun x hx => (hr <| ball_subset_closedBall hx).2⟩ #align complex.eventually_eq_of_is_local_max_norm Complex.eventually_eq_of_isLocalMax_norm theorem eventually_eq_or_eq_zero_of_isLocalMin_norm {f : E → ℂ} {c : E} (hf : ∀ᶠ z in 𝓝 c, DifferentiableAt ℂ f z) (hc : IsLocalMin (norm ∘ f) c) : (∀ᶠ z in 𝓝 c, f z = f c) ∨ f c = 0 := by refine or_iff_not_imp_right.mpr fun h => ?_ have h1 : ∀ᶠ z in 𝓝 c, f z ≠ 0 := hf.self_of_nhds.continuousAt.eventually_ne h have h2 : IsLocalMax (norm ∘ f)⁻¹ c := hc.inv (h1.mono fun z => norm_pos_iff.mpr) have h3 : IsLocalMax (norm ∘ f⁻¹) c := by refine h2.congr (eventually_of_forall ?_); simp have h4 : ∀ᶠ z in 𝓝 c, DifferentiableAt ℂ f⁻¹ z := by filter_upwards [hf, h1] with z h using h.inv filter_upwards [eventually_eq_of_isLocalMax_norm h4 h3] with z using inv_inj.mp #align complex.eventually_eq_or_eq_zero_of_is_local_min_norm Complex.eventually_eq_or_eq_zero_of_isLocalMin_norm end StrictConvex /-! ### Maximum on a set vs maximum on its frontier In this section we prove corollaries of the maximum modulus principle that relate the values of a function on a set to its values on the frontier of this set. -/ variable [Nontrivial E] /-- **Maximum modulus principle**: if `f : E → F` is complex differentiable on a nonempty bounded set `U` and is continuous on its closure, then there exists a point `z ∈ frontier U` such that `(‖f ·‖)` takes it maximum value on `closure U` at `z`. -/
Mathlib/Analysis/Complex/AbsMax.lean
369
382
theorem exists_mem_frontier_isMaxOn_norm [FiniteDimensional ℂ E] {f : E → F} {U : Set E} (hb : IsBounded U) (hne : U.Nonempty) (hd : DiffContOnCl ℂ f U) : ∃ z ∈ frontier U, IsMaxOn (norm ∘ f) (closure U) z := by
have hc : IsCompact (closure U) := hb.isCompact_closure obtain ⟨w, hwU, hle⟩ : ∃ w ∈ closure U, IsMaxOn (norm ∘ f) (closure U) w := hc.exists_isMaxOn hne.closure hd.continuousOn.norm rw [closure_eq_interior_union_frontier, mem_union] at hwU cases' hwU with hwU hwU; rotate_left; · exact ⟨w, hwU, hle⟩ have : interior U ≠ univ := ne_top_of_le_ne_top hc.ne_univ interior_subset_closure rcases exists_mem_frontier_infDist_compl_eq_dist hwU this with ⟨z, hzU, hzw⟩ refine ⟨z, frontier_interior_subset hzU, fun x hx => (hle hx).out.trans_eq ?_⟩ refine (norm_eq_norm_of_isMaxOn_of_ball_subset hd (hle.on_subset subset_closure) ?_).symm rw [dist_comm, ← hzw] exact ball_infDist_compl_subset.trans interior_subset
/- 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 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] end TransCmp instance [inst : OrientedCmp cmp] : OrientedCmp (flip cmp) where symm _ _ := inst.symm .. instance [inst : TransCmp cmp] : TransCmp (flip cmp) where le_trans h1 h2 := inst.le_trans h2 h1 /-- `BEqCmp cmp` asserts that `cmp x y = .eq` and `x == y` coincide. -/ class BEqCmp [BEq α] (cmp : α → α → Ordering) : Prop where /-- `cmp x y = .eq` holds iff `x == y` is true. -/ cmp_iff_beq : cmp x y = .eq ↔ x == y theorem BEqCmp.cmp_iff_eq [BEq α] [LawfulBEq α] [BEqCmp (α := α) cmp] : cmp x y = .eq ↔ x = y := by simp [BEqCmp.cmp_iff_beq] /-- `LTCmp cmp` asserts that `cmp x y = .lt` and `x < y` coincide. -/ class LTCmp [LT α] (cmp : α → α → Ordering) extends OrientedCmp cmp : Prop where /-- `cmp x y = .lt` holds iff `x < y` is true. -/ cmp_iff_lt : cmp x y = .lt ↔ x < y theorem LTCmp.cmp_iff_gt [LT α] [LTCmp (α := α) cmp] : cmp x y = .gt ↔ y < x := by rw [OrientedCmp.cmp_eq_gt, LTCmp.cmp_iff_lt] /-- `LECmp cmp` asserts that `cmp x y ≠ .gt` and `x ≤ y` coincide. -/ class LECmp [LE α] (cmp : α → α → Ordering) extends OrientedCmp cmp : Prop where /-- `cmp x y ≠ .gt` holds iff `x ≤ y` is true. -/ cmp_iff_le : cmp x y ≠ .gt ↔ x ≤ y theorem LECmp.cmp_iff_ge [LE α] [LECmp (α := α) cmp] : cmp x y ≠ .lt ↔ y ≤ x := by rw [← OrientedCmp.cmp_ne_gt, LECmp.cmp_iff_le] /-- `LawfulCmp cmp` asserts that the `LE`, `LT`, `BEq` instances are all coherent with each other and with `cmp`, describing a strict weak order (a linear order except for antisymmetry). -/ class LawfulCmp [LE α] [LT α] [BEq α] (cmp : α → α → Ordering) extends TransCmp cmp, BEqCmp cmp, LTCmp cmp, LECmp cmp : Prop /-- `OrientedOrd α` asserts that the `Ord` instance satisfies `OrientedCmp`. -/ abbrev OrientedOrd (α) [Ord α] := OrientedCmp (α := α) compare /-- `TransOrd α` asserts that the `Ord` instance satisfies `TransCmp`. -/ abbrev TransOrd (α) [Ord α] := TransCmp (α := α) compare /-- `BEqOrd α` asserts that the `Ord` and `BEq` instances are coherent via `BEqCmp`. -/ abbrev BEqOrd (α) [BEq α] [Ord α] := BEqCmp (α := α) compare /-- `LTOrd α` asserts that the `Ord` instance satisfies `LTCmp`. -/ abbrev LTOrd (α) [LT α] [Ord α] := LTCmp (α := α) compare /-- `LEOrd α` asserts that the `Ord` instance satisfies `LECmp`. -/ abbrev LEOrd (α) [LE α] [Ord α] := LECmp (α := α) compare /-- `LawfulOrd α` asserts that the `Ord` instance satisfies `LawfulCmp`. -/ abbrev LawfulOrd (α) [LE α] [LT α] [BEq α] [Ord α] := LawfulCmp (α := α) compare
.lake/packages/batteries/Batteries/Classes/Order.lean
163
166
theorem compareOfLessAndEq_eq_lt {x y : α} [LT α] [Decidable (x < y)] [DecidableEq α] : compareOfLessAndEq x y = .lt ↔ x < y := by
simp [compareOfLessAndEq] split <;> simp
/- 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.Order.BigOperators.Group.Finset import Mathlib.Data.Nat.Factors import Mathlib.Order.Interval.Finset.Nat #align_import number_theory.divisors from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3" /-! # Divisor Finsets This file defines sets of divisors of a natural number. This is particularly useful as background for defining Dirichlet convolution. ## Main Definitions Let `n : ℕ`. All of the following definitions are in the `Nat` namespace: * `divisors n` is the `Finset` of natural numbers that divide `n`. * `properDivisors n` is the `Finset` of natural numbers that divide `n`, other than `n`. * `divisorsAntidiagonal n` is the `Finset` of pairs `(x,y)` such that `x * y = n`. * `Perfect n` is true when `n` is positive and the sum of `properDivisors n` is `n`. ## Implementation details * `divisors 0`, `properDivisors 0`, and `divisorsAntidiagonal 0` are defined to be `∅`. ## Tags divisors, perfect numbers -/ open scoped Classical open Finset namespace Nat variable (n : ℕ) /-- `divisors n` is the `Finset` of divisors of `n`. As a special case, `divisors 0 = ∅`. -/ def divisors : Finset ℕ := Finset.filter (fun x : ℕ => x ∣ n) (Finset.Ico 1 (n + 1)) #align nat.divisors Nat.divisors /-- `properDivisors n` is the `Finset` of divisors of `n`, other than `n`. As a special case, `properDivisors 0 = ∅`. -/ def properDivisors : Finset ℕ := Finset.filter (fun x : ℕ => x ∣ n) (Finset.Ico 1 n) #align nat.proper_divisors Nat.properDivisors /-- `divisorsAntidiagonal n` is the `Finset` of pairs `(x,y)` such that `x * y = n`. As a special case, `divisorsAntidiagonal 0 = ∅`. -/ def divisorsAntidiagonal : Finset (ℕ × ℕ) := Finset.filter (fun x => x.fst * x.snd = n) (Ico 1 (n + 1) ×ˢ Ico 1 (n + 1)) #align nat.divisors_antidiagonal Nat.divisorsAntidiagonal variable {n} @[simp] theorem filter_dvd_eq_divisors (h : n ≠ 0) : (Finset.range n.succ).filter (· ∣ n) = n.divisors := by ext simp only [divisors, mem_filter, mem_range, mem_Ico, and_congr_left_iff, iff_and_self] exact fun ha _ => succ_le_iff.mpr (pos_of_dvd_of_pos ha h.bot_lt) #align nat.filter_dvd_eq_divisors Nat.filter_dvd_eq_divisors @[simp] theorem filter_dvd_eq_properDivisors (h : n ≠ 0) : (Finset.range n).filter (· ∣ n) = n.properDivisors := by ext simp only [properDivisors, mem_filter, mem_range, mem_Ico, and_congr_left_iff, iff_and_self] exact fun ha _ => succ_le_iff.mpr (pos_of_dvd_of_pos ha h.bot_lt) #align nat.filter_dvd_eq_proper_divisors Nat.filter_dvd_eq_properDivisors theorem properDivisors.not_self_mem : ¬n ∈ properDivisors n := by simp [properDivisors] #align nat.proper_divisors.not_self_mem Nat.properDivisors.not_self_mem @[simp] theorem mem_properDivisors {m : ℕ} : n ∈ properDivisors m ↔ n ∣ m ∧ n < m := by rcases eq_or_ne m 0 with (rfl | hm); · simp [properDivisors] simp only [and_comm, ← filter_dvd_eq_properDivisors hm, mem_filter, mem_range] #align nat.mem_proper_divisors Nat.mem_properDivisors theorem insert_self_properDivisors (h : n ≠ 0) : insert n (properDivisors n) = divisors n := by rw [divisors, properDivisors, Ico_succ_right_eq_insert_Ico (one_le_iff_ne_zero.2 h), Finset.filter_insert, if_pos (dvd_refl n)] #align nat.insert_self_proper_divisors Nat.insert_self_properDivisors theorem cons_self_properDivisors (h : n ≠ 0) : cons n (properDivisors n) properDivisors.not_self_mem = divisors n := by rw [cons_eq_insert, insert_self_properDivisors h] #align nat.cons_self_proper_divisors Nat.cons_self_properDivisors @[simp] theorem mem_divisors {m : ℕ} : n ∈ divisors m ↔ n ∣ m ∧ m ≠ 0 := by rcases eq_or_ne m 0 with (rfl | hm); · simp [divisors] simp only [hm, Ne, not_false_iff, and_true_iff, ← filter_dvd_eq_divisors hm, mem_filter, mem_range, and_iff_right_iff_imp, Nat.lt_succ_iff] exact le_of_dvd hm.bot_lt #align nat.mem_divisors Nat.mem_divisors theorem one_mem_divisors : 1 ∈ divisors n ↔ n ≠ 0 := by simp #align nat.one_mem_divisors Nat.one_mem_divisors theorem mem_divisors_self (n : ℕ) (h : n ≠ 0) : n ∈ n.divisors := mem_divisors.2 ⟨dvd_rfl, h⟩ #align nat.mem_divisors_self Nat.mem_divisors_self theorem dvd_of_mem_divisors {m : ℕ} (h : n ∈ divisors m) : n ∣ m := by cases m · apply dvd_zero · simp [mem_divisors.1 h] #align nat.dvd_of_mem_divisors Nat.dvd_of_mem_divisors @[simp]
Mathlib/NumberTheory/Divisors.lean
116
131
theorem mem_divisorsAntidiagonal {x : ℕ × ℕ} : x ∈ divisorsAntidiagonal n ↔ x.fst * x.snd = n ∧ n ≠ 0 := by
simp only [divisorsAntidiagonal, Finset.mem_Ico, Ne, Finset.mem_filter, Finset.mem_product] rw [and_comm] apply and_congr_right rintro rfl constructor <;> intro h · contrapose! h simp [h] · rw [Nat.lt_add_one_iff, Nat.lt_add_one_iff] rw [mul_eq_zero, not_or] at h simp only [succ_le_of_lt (Nat.pos_of_ne_zero h.1), succ_le_of_lt (Nat.pos_of_ne_zero h.2), true_and_iff] exact ⟨Nat.le_mul_of_pos_right _ (Nat.pos_of_ne_zero h.2), Nat.le_mul_of_pos_left _ (Nat.pos_of_ne_zero h.1)⟩
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Algebra.Polynomial.Reverse import Mathlib.Algebra.Regular.SMul #align_import data.polynomial.monic from "leanprover-community/mathlib"@"cbdf7b565832144d024caa5a550117c6df0204a5" /-! # Theory of monic polynomials We give several tools for proving that polynomials are monic, e.g. `Monic.mul`, `Monic.map`, `Monic.pow`. -/ noncomputable section open Finset open Polynomial namespace Polynomial universe u v y variable {R : Type u} {S : Type v} {a b : R} {m n : ℕ} {ι : Type y} section Semiring variable [Semiring R] {p q r : R[X]} theorem monic_zero_iff_subsingleton : Monic (0 : R[X]) ↔ Subsingleton R := subsingleton_iff_zero_eq_one #align polynomial.monic_zero_iff_subsingleton Polynomial.monic_zero_iff_subsingleton theorem not_monic_zero_iff : ¬Monic (0 : R[X]) ↔ (0 : R) ≠ 1 := (monic_zero_iff_subsingleton.trans subsingleton_iff_zero_eq_one.symm).not #align polynomial.not_monic_zero_iff Polynomial.not_monic_zero_iff theorem monic_zero_iff_subsingleton' : Monic (0 : R[X]) ↔ (∀ f g : R[X], f = g) ∧ ∀ a b : R, a = b := Polynomial.monic_zero_iff_subsingleton.trans ⟨by intro simp [eq_iff_true_of_subsingleton], fun h => subsingleton_iff.mpr h.2⟩ #align polynomial.monic_zero_iff_subsingleton' Polynomial.monic_zero_iff_subsingleton' theorem Monic.as_sum (hp : p.Monic) : p = X ^ p.natDegree + ∑ i ∈ range p.natDegree, C (p.coeff i) * X ^ i := by conv_lhs => rw [p.as_sum_range_C_mul_X_pow, sum_range_succ_comm] suffices C (p.coeff p.natDegree) = 1 by rw [this, one_mul] exact congr_arg C hp #align polynomial.monic.as_sum Polynomial.Monic.as_sum theorem ne_zero_of_ne_zero_of_monic (hp : p ≠ 0) (hq : Monic q) : q ≠ 0 := by rintro rfl rw [Monic.def, leadingCoeff_zero] at hq rw [← mul_one p, ← C_1, ← hq, C_0, mul_zero] at hp exact hp rfl #align polynomial.ne_zero_of_ne_zero_of_monic Polynomial.ne_zero_of_ne_zero_of_monic theorem Monic.map [Semiring S] (f : R →+* S) (hp : Monic p) : Monic (p.map f) := by unfold Monic nontriviality have : f p.leadingCoeff ≠ 0 := by rw [show _ = _ from hp, f.map_one] exact one_ne_zero rw [Polynomial.leadingCoeff, coeff_map] suffices p.coeff (p.map f).natDegree = 1 by simp [this] rwa [natDegree_eq_of_degree_eq (degree_map_eq_of_leadingCoeff_ne_zero f this)] #align polynomial.monic.map Polynomial.Monic.map theorem monic_C_mul_of_mul_leadingCoeff_eq_one {b : R} (hp : b * p.leadingCoeff = 1) : Monic (C b * p) := by unfold Monic nontriviality rw [leadingCoeff_mul' _] <;> simp [leadingCoeff_C b, hp] set_option linter.uppercaseLean3 false in #align polynomial.monic_C_mul_of_mul_leading_coeff_eq_one Polynomial.monic_C_mul_of_mul_leadingCoeff_eq_one theorem monic_mul_C_of_leadingCoeff_mul_eq_one {b : R} (hp : p.leadingCoeff * b = 1) : Monic (p * C b) := by unfold Monic nontriviality rw [leadingCoeff_mul' _] <;> simp [leadingCoeff_C b, hp] set_option linter.uppercaseLean3 false in #align polynomial.monic_mul_C_of_leading_coeff_mul_eq_one Polynomial.monic_mul_C_of_leadingCoeff_mul_eq_one theorem monic_of_degree_le (n : ℕ) (H1 : degree p ≤ n) (H2 : coeff p n = 1) : Monic p := Decidable.byCases (fun H : degree p < n => eq_of_zero_eq_one (H2 ▸ (coeff_eq_zero_of_degree_lt H).symm) _ _) fun H : ¬degree p < n => by rwa [Monic, Polynomial.leadingCoeff, natDegree, (lt_or_eq_of_le H1).resolve_left H] #align polynomial.monic_of_degree_le Polynomial.monic_of_degree_le theorem monic_X_pow_add {n : ℕ} (H : degree p ≤ n) : Monic (X ^ (n + 1) + p) := have H1 : degree p < (n + 1 : ℕ) := lt_of_le_of_lt H (WithBot.coe_lt_coe.2 (Nat.lt_succ_self n)) monic_of_degree_le (n + 1) (le_trans (degree_add_le _ _) (max_le (degree_X_pow_le _) (le_of_lt H1))) (by rw [coeff_add, coeff_X_pow, if_pos rfl, coeff_eq_zero_of_degree_lt H1, add_zero]) set_option linter.uppercaseLean3 false in #align polynomial.monic_X_pow_add Polynomial.monic_X_pow_add variable (a) in theorem monic_X_pow_add_C {n : ℕ} (h : n ≠ 0) : (X ^ n + C a).Monic := by obtain ⟨k, rfl⟩ := Nat.exists_eq_succ_of_ne_zero h exact monic_X_pow_add <| degree_C_le.trans Nat.WithBot.coe_nonneg theorem monic_X_add_C (x : R) : Monic (X + C x) := pow_one (X : R[X]) ▸ monic_X_pow_add_C x one_ne_zero set_option linter.uppercaseLean3 false in #align polynomial.monic_X_add_C Polynomial.monic_X_add_C theorem Monic.mul (hp : Monic p) (hq : Monic q) : Monic (p * q) := letI := Classical.decEq R if h0 : (0 : R) = 1 then haveI := subsingleton_of_zero_eq_one h0 Subsingleton.elim _ _ else by have : p.leadingCoeff * q.leadingCoeff ≠ 0 := by simp [Monic.def.1 hp, Monic.def.1 hq, Ne.symm h0] rw [Monic.def, leadingCoeff_mul' this, Monic.def.1 hp, Monic.def.1 hq, one_mul] #align polynomial.monic.mul Polynomial.Monic.mul theorem Monic.pow (hp : Monic p) : ∀ n : ℕ, Monic (p ^ n) | 0 => monic_one | n + 1 => by rw [pow_succ] exact (Monic.pow hp n).mul hp #align polynomial.monic.pow Polynomial.Monic.pow theorem Monic.add_of_left (hp : Monic p) (hpq : degree q < degree p) : Monic (p + q) := by rwa [Monic, add_comm, leadingCoeff_add_of_degree_lt hpq] #align polynomial.monic.add_of_left Polynomial.Monic.add_of_left theorem Monic.add_of_right (hq : Monic q) (hpq : degree p < degree q) : Monic (p + q) := by rwa [Monic, leadingCoeff_add_of_degree_lt hpq] #align polynomial.monic.add_of_right Polynomial.Monic.add_of_right theorem Monic.of_mul_monic_left (hp : p.Monic) (hpq : (p * q).Monic) : q.Monic := by contrapose! hpq rw [Monic.def] at hpq ⊢ rwa [leadingCoeff_monic_mul hp] #align polynomial.monic.of_mul_monic_left Polynomial.Monic.of_mul_monic_left theorem Monic.of_mul_monic_right (hq : q.Monic) (hpq : (p * q).Monic) : p.Monic := by contrapose! hpq rw [Monic.def] at hpq ⊢ rwa [leadingCoeff_mul_monic hq] #align polynomial.monic.of_mul_monic_right Polynomial.Monic.of_mul_monic_right namespace Monic @[simp] theorem natDegree_eq_zero_iff_eq_one (hp : p.Monic) : p.natDegree = 0 ↔ p = 1 := by constructor <;> intro h swap · rw [h] exact natDegree_one have : p = C (p.coeff 0) := by rw [← Polynomial.degree_le_zero_iff] rwa [Polynomial.natDegree_eq_zero_iff_degree_le_zero] at h rw [this] rw [← h, ← Polynomial.leadingCoeff, Monic.def.1 hp, C_1] #align polynomial.monic.nat_degree_eq_zero_iff_eq_one Polynomial.Monic.natDegree_eq_zero_iff_eq_one @[simp] theorem degree_le_zero_iff_eq_one (hp : p.Monic) : p.degree ≤ 0 ↔ p = 1 := by rw [← hp.natDegree_eq_zero_iff_eq_one, natDegree_eq_zero_iff_degree_le_zero] #align polynomial.monic.degree_le_zero_iff_eq_one Polynomial.Monic.degree_le_zero_iff_eq_one theorem natDegree_mul (hp : p.Monic) (hq : q.Monic) : (p * q).natDegree = p.natDegree + q.natDegree := by nontriviality R apply natDegree_mul' simp [hp.leadingCoeff, hq.leadingCoeff] #align polynomial.monic.nat_degree_mul Polynomial.Monic.natDegree_mul
Mathlib/Algebra/Polynomial/Monic.lean
182
187
theorem degree_mul_comm (hp : p.Monic) (q : R[X]) : (p * q).degree = (q * p).degree := by
by_cases h : q = 0 · simp [h] rw [degree_mul', hp.degree_mul] · exact add_comm _ _ · rwa [hp.leadingCoeff, one_mul, leadingCoeff_ne_zero]
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen -/ import Mathlib.LinearAlgebra.FiniteDimensional import Mathlib.LinearAlgebra.GeneralLinearGroup import Mathlib.LinearAlgebra.Matrix.Reindex import Mathlib.Tactic.FieldSimp import Mathlib.LinearAlgebra.Matrix.NonsingularInverse import Mathlib.LinearAlgebra.Matrix.Basis #align_import linear_algebra.determinant from "leanprover-community/mathlib"@"0c1d80f5a86b36c1db32e021e8d19ae7809d5b79" /-! # Determinant of families of vectors This file defines the determinant of an endomorphism, and of a family of vectors with respect to some basis. For the determinant of a matrix, see the file `LinearAlgebra.Matrix.Determinant`. ## Main definitions In the list below, and in all this file, `R` is a commutative ring (semiring is sometimes enough), `M` and its variations are `R`-modules, `ι`, `κ`, `n` and `m` are finite types used for indexing. * `Basis.det`: the determinant of a family of vectors with respect to a basis, as a multilinear map * `LinearMap.det`: the determinant of an endomorphism `f : End R M` as a multiplicative homomorphism (if `M` does not have a finite `R`-basis, the result is `1` instead) * `LinearEquiv.det`: the determinant of an isomorphism `f : M ≃ₗ[R] M` as a multiplicative homomorphism (if `M` does not have a finite `R`-basis, the result is `1` instead) ## Tags basis, det, determinant -/ noncomputable section open Matrix LinearMap Submodule Set Function universe u v w variable {R : Type*} [CommRing R] variable {M : Type*} [AddCommGroup M] [Module R M] variable {M' : Type*} [AddCommGroup M'] [Module R M'] variable {ι : Type*} [DecidableEq ι] [Fintype ι] variable (e : Basis ι R M) section Conjugate variable {A : Type*} [CommRing A] variable {m n : Type*} /-- If `R^m` and `R^n` are linearly equivalent, then `m` and `n` are also equivalent. -/ def equivOfPiLEquivPi {R : Type*} [Finite m] [Finite n] [CommRing R] [Nontrivial R] (e : (m → R) ≃ₗ[R] n → R) : m ≃ n := Basis.indexEquiv (Basis.ofEquivFun e.symm) (Pi.basisFun _ _) #align equiv_of_pi_lequiv_pi equivOfPiLEquivPi namespace Matrix variable [Fintype m] [Fintype n] /-- If `M` and `M'` are each other's inverse matrices, they are square matrices up to equivalence of types. -/ def indexEquivOfInv [Nontrivial A] [DecidableEq m] [DecidableEq n] {M : Matrix m n A} {M' : Matrix n m A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : m ≃ n := equivOfPiLEquivPi (toLin'OfInv hMM' hM'M) #align matrix.index_equiv_of_inv Matrix.indexEquivOfInv theorem det_comm [DecidableEq n] (M N : Matrix n n A) : det (M * N) = det (N * M) := by rw [det_mul, det_mul, mul_comm] #align matrix.det_comm Matrix.det_comm /-- If there exists a two-sided inverse `M'` for `M` (indexed differently), then `det (N * M) = det (M * N)`. -/ theorem det_comm' [DecidableEq m] [DecidableEq n] {M : Matrix n m A} {N : Matrix m n A} {M' : Matrix m n A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : det (M * N) = det (N * M) := by nontriviality A -- Although `m` and `n` are different a priori, we will show they have the same cardinality. -- This turns the problem into one for square matrices, which is easy. let e := indexEquivOfInv hMM' hM'M rw [← det_submatrix_equiv_self e, ← submatrix_mul_equiv _ _ _ (Equiv.refl n) _, det_comm, submatrix_mul_equiv, Equiv.coe_refl, submatrix_id_id] #align matrix.det_comm' Matrix.det_comm' /-- If `M'` is a two-sided inverse for `M` (indexed differently), `det (M * N * M') = det N`. See `Matrix.det_conj` and `Matrix.det_conj'` for the case when `M' = M⁻¹` or vice versa. -/ theorem det_conj_of_mul_eq_one [DecidableEq m] [DecidableEq n] {M : Matrix m n A} {M' : Matrix n m A} {N : Matrix n n A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : det (M * N * M') = det N := by rw [← det_comm' hM'M hMM', ← Matrix.mul_assoc, hM'M, Matrix.one_mul] #align matrix.det_conj_of_mul_eq_one Matrix.det_conj_of_mul_eq_one end Matrix end Conjugate namespace LinearMap /-! ### Determinant of a linear map -/ variable {A : Type*} [CommRing A] [Module A M] variable {κ : Type*} [Fintype κ] /-- The determinant of `LinearMap.toMatrix` does not depend on the choice of basis. -/ theorem det_toMatrix_eq_det_toMatrix [DecidableEq κ] (b : Basis ι A M) (c : Basis κ A M) (f : M →ₗ[A] M) : det (LinearMap.toMatrix b b f) = det (LinearMap.toMatrix c c f) := by rw [← linearMap_toMatrix_mul_basis_toMatrix c b c, ← basis_toMatrix_mul_linearMap_toMatrix b c b, Matrix.det_conj_of_mul_eq_one] <;> rw [Basis.toMatrix_mul_toMatrix, Basis.toMatrix_self] #align linear_map.det_to_matrix_eq_det_to_matrix LinearMap.det_toMatrix_eq_det_toMatrix /-- The determinant of an endomorphism given a basis. See `LinearMap.det` for a version that populates the basis non-computably. Although the `Trunc (Basis ι A M)` parameter makes it slightly more convenient to switch bases, there is no good way to generalize over universe parameters, so we can't fully state in `detAux`'s type that it does not depend on the choice of basis. Instead you can use the `detAux_def''` lemma, or avoid mentioning a basis at all using `LinearMap.det`. -/ irreducible_def detAux : Trunc (Basis ι A M) → (M →ₗ[A] M) →* A := Trunc.lift (fun b : Basis ι A M => detMonoidHom.comp (toMatrixAlgEquiv b : (M →ₗ[A] M) →* Matrix ι ι A)) fun b c => MonoidHom.ext <| det_toMatrix_eq_det_toMatrix b c #align linear_map.det_aux LinearMap.detAux /-- Unfold lemma for `detAux`. See also `detAux_def''` which allows you to vary the basis. -/ theorem detAux_def' (b : Basis ι A M) (f : M →ₗ[A] M) : LinearMap.detAux (Trunc.mk b) f = Matrix.det (LinearMap.toMatrix b b f) := by rw [detAux] rfl #align linear_map.det_aux_def LinearMap.detAux_def' theorem detAux_def'' {ι' : Type*} [Fintype ι'] [DecidableEq ι'] (tb : Trunc <| Basis ι A M) (b' : Basis ι' A M) (f : M →ₗ[A] M) : LinearMap.detAux tb f = Matrix.det (LinearMap.toMatrix b' b' f) := by induction tb using Trunc.induction_on with | h b => rw [detAux_def', det_toMatrix_eq_det_toMatrix b b'] #align linear_map.det_aux_def' LinearMap.detAux_def'' @[simp] theorem detAux_id (b : Trunc <| Basis ι A M) : LinearMap.detAux b LinearMap.id = 1 := (LinearMap.detAux b).map_one #align linear_map.det_aux_id LinearMap.detAux_id @[simp] theorem detAux_comp (b : Trunc <| Basis ι A M) (f g : M →ₗ[A] M) : LinearMap.detAux b (f.comp g) = LinearMap.detAux b f * LinearMap.detAux b g := (LinearMap.detAux b).map_mul f g #align linear_map.det_aux_comp LinearMap.detAux_comp section open scoped Classical in -- Discourage the elaborator from unfolding `det` and producing a huge term by marking it -- as irreducible. /-- The determinant of an endomorphism independent of basis. If there is no finite basis on `M`, the result is `1` instead. -/ protected irreducible_def det : (M →ₗ[A] M) →* A := if H : ∃ s : Finset M, Nonempty (Basis s A M) then LinearMap.detAux (Trunc.mk H.choose_spec.some) else 1 #align linear_map.det LinearMap.det open scoped Classical in theorem coe_det [DecidableEq M] : ⇑(LinearMap.det : (M →ₗ[A] M) →* A) = if H : ∃ s : Finset M, Nonempty (Basis s A M) then LinearMap.detAux (Trunc.mk H.choose_spec.some) else 1 := by ext rw [LinearMap.det_def] split_ifs · congr -- use the correct `DecidableEq` instance rfl #align linear_map.coe_det LinearMap.coe_det end -- Auxiliary lemma, the `simp` normal form goes in the other direction -- (using `LinearMap.det_toMatrix`) theorem det_eq_det_toMatrix_of_finset [DecidableEq M] {s : Finset M} (b : Basis s A M) (f : M →ₗ[A] M) : LinearMap.det f = Matrix.det (LinearMap.toMatrix b b f) := by have : ∃ s : Finset M, Nonempty (Basis s A M) := ⟨s, ⟨b⟩⟩ rw [LinearMap.coe_det, dif_pos, detAux_def'' _ b] <;> assumption #align linear_map.det_eq_det_to_matrix_of_finset LinearMap.det_eq_det_toMatrix_of_finset @[simp] theorem det_toMatrix (b : Basis ι A M) (f : M →ₗ[A] M) : Matrix.det (toMatrix b b f) = LinearMap.det f := by haveI := Classical.decEq M rw [det_eq_det_toMatrix_of_finset b.reindexFinsetRange] -- Porting note: moved out of `rw` due to error -- typeclass instance problem is stuck, it is often due to metavariables `DecidableEq ?m.628881` apply det_toMatrix_eq_det_toMatrix b #align linear_map.det_to_matrix LinearMap.det_toMatrix @[simp] theorem det_toMatrix' {ι : Type*} [Fintype ι] [DecidableEq ι] (f : (ι → A) →ₗ[A] ι → A) : Matrix.det (LinearMap.toMatrix' f) = LinearMap.det f := by simp [← toMatrix_eq_toMatrix'] #align linear_map.det_to_matrix' LinearMap.det_toMatrix' @[simp] theorem det_toLin (b : Basis ι R M) (f : Matrix ι ι R) : LinearMap.det (Matrix.toLin b b f) = f.det := by rw [← LinearMap.det_toMatrix b, LinearMap.toMatrix_toLin] #align linear_map.det_to_lin LinearMap.det_toLin @[simp] theorem det_toLin' (f : Matrix ι ι R) : LinearMap.det (Matrix.toLin' f) = Matrix.det f := by simp only [← toLin_eq_toLin', det_toLin] #align linear_map.det_to_lin' LinearMap.det_toLin' /-- To show `P (LinearMap.det f)` it suffices to consider `P (Matrix.det (toMatrix _ _ f))` and `P 1`. -/ -- @[elab_as_elim] -- Porting note: This attr can't be applied. theorem det_cases [DecidableEq M] {P : A → Prop} (f : M →ₗ[A] M) (hb : ∀ (s : Finset M) (b : Basis s A M), P (Matrix.det (toMatrix b b f))) (h1 : P 1) : P (LinearMap.det f) := by rw [LinearMap.det_def] split_ifs with h · convert hb _ h.choose_spec.some -- Porting note: was `apply det_aux_def'` convert detAux_def'' (Trunc.mk h.choose_spec.some) h.choose_spec.some f · exact h1 #align linear_map.det_cases LinearMap.det_cases @[simp] theorem det_comp (f g : M →ₗ[A] M) : LinearMap.det (f.comp g) = LinearMap.det f * LinearMap.det g := LinearMap.det.map_mul f g #align linear_map.det_comp LinearMap.det_comp @[simp] theorem det_id : LinearMap.det (LinearMap.id : M →ₗ[A] M) = 1 := LinearMap.det.map_one #align linear_map.det_id LinearMap.det_id /-- Multiplying a map by a scalar `c` multiplies its determinant by `c ^ dim M`. -/ @[simp] theorem det_smul {𝕜 : Type*} [Field 𝕜] {M : Type*} [AddCommGroup M] [Module 𝕜 M] (c : 𝕜) (f : M →ₗ[𝕜] M) : LinearMap.det (c • f) = c ^ FiniteDimensional.finrank 𝕜 M * LinearMap.det f := by by_cases H : ∃ s : Finset M, Nonempty (Basis s 𝕜 M) · have : FiniteDimensional 𝕜 M := by rcases H with ⟨s, ⟨hs⟩⟩ exact FiniteDimensional.of_fintype_basis hs simp only [← det_toMatrix (FiniteDimensional.finBasis 𝕜 M), LinearEquiv.map_smul, Fintype.card_fin, Matrix.det_smul] · classical have : FiniteDimensional.finrank 𝕜 M = 0 := finrank_eq_zero_of_not_exists_basis H simp [coe_det, H, this] #align linear_map.det_smul LinearMap.det_smul theorem det_zero' {ι : Type*} [Finite ι] [Nonempty ι] (b : Basis ι A M) : LinearMap.det (0 : M →ₗ[A] M) = 0 := by haveI := Classical.decEq ι cases nonempty_fintype ι rwa [← det_toMatrix b, LinearEquiv.map_zero, det_zero] #align linear_map.det_zero' LinearMap.det_zero' /-- In a finite-dimensional vector space, the zero map has determinant `1` in dimension `0`, and `0` otherwise. We give a formula that also works in infinite dimension, where we define the determinant to be `1`. -/ @[simp] theorem det_zero {𝕜 : Type*} [Field 𝕜] {M : Type*} [AddCommGroup M] [Module 𝕜 M] : LinearMap.det (0 : M →ₗ[𝕜] M) = (0 : 𝕜) ^ FiniteDimensional.finrank 𝕜 M := by simp only [← zero_smul 𝕜 (1 : M →ₗ[𝕜] M), det_smul, mul_one, MonoidHom.map_one] #align linear_map.det_zero LinearMap.det_zero theorem det_eq_one_of_subsingleton [Subsingleton M] (f : M →ₗ[R] M) : LinearMap.det (f : M →ₗ[R] M) = 1 := by have b : Basis (Fin 0) R M := Basis.empty M rw [← f.det_toMatrix b] exact Matrix.det_isEmpty #align linear_map.det_eq_one_of_subsingleton LinearMap.det_eq_one_of_subsingleton theorem det_eq_one_of_finrank_eq_zero {𝕜 : Type*} [Field 𝕜] {M : Type*} [AddCommGroup M] [Module 𝕜 M] (h : FiniteDimensional.finrank 𝕜 M = 0) (f : M →ₗ[𝕜] M) : LinearMap.det (f : M →ₗ[𝕜] M) = 1 := by classical refine @LinearMap.det_cases M _ 𝕜 _ _ _ (fun t => t = 1) f ?_ rfl intro s b have : IsEmpty s := by rw [← Fintype.card_eq_zero_iff] exact (FiniteDimensional.finrank_eq_card_basis b).symm.trans h exact Matrix.det_isEmpty #align linear_map.det_eq_one_of_finrank_eq_zero LinearMap.det_eq_one_of_finrank_eq_zero /-- Conjugating a linear map by a linear equiv does not change its determinant. -/ @[simp] theorem det_conj {N : Type*} [AddCommGroup N] [Module A N] (f : M →ₗ[A] M) (e : M ≃ₗ[A] N) : LinearMap.det ((e : M →ₗ[A] N) ∘ₗ f ∘ₗ (e.symm : N →ₗ[A] M)) = LinearMap.det f := by classical by_cases H : ∃ s : Finset M, Nonempty (Basis s A M) · rcases H with ⟨s, ⟨b⟩⟩ rw [← det_toMatrix b f, ← det_toMatrix (b.map e), toMatrix_comp (b.map e) b (b.map e), toMatrix_comp (b.map e) b b, ← Matrix.mul_assoc, Matrix.det_conj_of_mul_eq_one] · rw [← toMatrix_comp, LinearEquiv.comp_coe, e.symm_trans_self, LinearEquiv.refl_toLinearMap, toMatrix_id] · rw [← toMatrix_comp, LinearEquiv.comp_coe, e.self_trans_symm, LinearEquiv.refl_toLinearMap, toMatrix_id] · have H' : ¬∃ t : Finset N, Nonempty (Basis t A N) := by contrapose! H rcases H with ⟨s, ⟨b⟩⟩ exact ⟨_, ⟨(b.map e.symm).reindexFinsetRange⟩⟩ simp only [coe_det, H, H', MonoidHom.one_apply, dif_neg, not_false_eq_true] #align linear_map.det_conj LinearMap.det_conj /-- If a linear map is invertible, so is its determinant. -/ theorem isUnit_det {A : Type*} [CommRing A] [Module A M] (f : M →ₗ[A] M) (hf : IsUnit f) : IsUnit (LinearMap.det f) := by obtain ⟨g, hg⟩ : ∃ g, f.comp g = 1 := hf.exists_right_inv have : LinearMap.det f * LinearMap.det g = 1 := by simp only [← LinearMap.det_comp, hg, MonoidHom.map_one] exact isUnit_of_mul_eq_one _ _ this #align linear_map.is_unit_det LinearMap.isUnit_det /-- If a linear map has determinant different from `1`, then the space is finite-dimensional. -/ theorem finiteDimensional_of_det_ne_one {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] (f : M →ₗ[𝕜] M) (hf : LinearMap.det f ≠ 1) : FiniteDimensional 𝕜 M := by by_cases H : ∃ s : Finset M, Nonempty (Basis s 𝕜 M) · rcases H with ⟨s, ⟨hs⟩⟩ exact FiniteDimensional.of_fintype_basis hs · classical simp [LinearMap.coe_det, H] at hf #align linear_map.finite_dimensional_of_det_ne_one LinearMap.finiteDimensional_of_det_ne_one /-- If the determinant of a map vanishes, then the map is not onto. -/ theorem range_lt_top_of_det_eq_zero {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] {f : M →ₗ[𝕜] M} (hf : LinearMap.det f = 0) : LinearMap.range f < ⊤ := by have : FiniteDimensional 𝕜 M := by simp [f.finiteDimensional_of_det_ne_one, hf] contrapose hf simp only [lt_top_iff_ne_top, Classical.not_not, ← isUnit_iff_range_eq_top] at hf exact isUnit_iff_ne_zero.1 (f.isUnit_det hf) #align linear_map.range_lt_top_of_det_eq_zero LinearMap.range_lt_top_of_det_eq_zero /-- If the determinant of a map vanishes, then the map is not injective. -/ theorem bot_lt_ker_of_det_eq_zero {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] {f : M →ₗ[𝕜] M} (hf : LinearMap.det f = 0) : ⊥ < LinearMap.ker f := by have : FiniteDimensional 𝕜 M := by simp [f.finiteDimensional_of_det_ne_one, hf] contrapose hf simp only [bot_lt_iff_ne_bot, Classical.not_not, ← isUnit_iff_ker_eq_bot] at hf exact isUnit_iff_ne_zero.1 (f.isUnit_det hf) #align linear_map.bot_lt_ker_of_det_eq_zero LinearMap.bot_lt_ker_of_det_eq_zero end LinearMap namespace LinearEquiv /-- On a `LinearEquiv`, the domain of `LinearMap.det` can be promoted to `Rˣ`. -/ protected def det : (M ≃ₗ[R] M) →* Rˣ := (Units.map (LinearMap.det : (M →ₗ[R] M) →* R)).comp (LinearMap.GeneralLinearGroup.generalLinearEquiv R M).symm.toMonoidHom #align linear_equiv.det LinearEquiv.det @[simp] theorem coe_det (f : M ≃ₗ[R] M) : ↑(LinearEquiv.det f) = LinearMap.det (f : M →ₗ[R] M) := rfl #align linear_equiv.coe_det LinearEquiv.coe_det @[simp] theorem coe_inv_det (f : M ≃ₗ[R] M) : ↑(LinearEquiv.det f)⁻¹ = LinearMap.det (f.symm : M →ₗ[R] M) := rfl #align linear_equiv.coe_inv_det LinearEquiv.coe_inv_det @[simp] theorem det_refl : LinearEquiv.det (LinearEquiv.refl R M) = 1 := Units.ext <| LinearMap.det_id #align linear_equiv.det_refl LinearEquiv.det_refl @[simp] theorem det_trans (f g : M ≃ₗ[R] M) : LinearEquiv.det (f.trans g) = LinearEquiv.det g * LinearEquiv.det f := map_mul _ g f #align linear_equiv.det_trans LinearEquiv.det_trans @[simp, nolint simpNF] theorem det_symm (f : M ≃ₗ[R] M) : LinearEquiv.det f.symm = LinearEquiv.det f⁻¹ := map_inv _ f #align linear_equiv.det_symm LinearEquiv.det_symm /-- Conjugating a linear equiv by a linear equiv does not change its determinant. -/ @[simp] theorem det_conj (f : M ≃ₗ[R] M) (e : M ≃ₗ[R] M') : LinearEquiv.det ((e.symm.trans f).trans e) = LinearEquiv.det f := by rw [← Units.eq_iff, coe_det, coe_det, ← comp_coe, ← comp_coe, LinearMap.det_conj] #align linear_equiv.det_conj LinearEquiv.det_conj attribute [irreducible] LinearEquiv.det end LinearEquiv /-- The determinants of a `LinearEquiv` and its inverse multiply to 1. -/ @[simp] theorem LinearEquiv.det_mul_det_symm {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) : LinearMap.det (f : M →ₗ[A] M) * LinearMap.det (f.symm : M →ₗ[A] M) = 1 := by simp [← LinearMap.det_comp] #align linear_equiv.det_mul_det_symm LinearEquiv.det_mul_det_symm /-- The determinants of a `LinearEquiv` and its inverse multiply to 1. -/ @[simp] theorem LinearEquiv.det_symm_mul_det {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) : LinearMap.det (f.symm : M →ₗ[A] M) * LinearMap.det (f : M →ₗ[A] M) = 1 := by simp [← LinearMap.det_comp] #align linear_equiv.det_symm_mul_det LinearEquiv.det_symm_mul_det -- Cannot be stated using `LinearMap.det` because `f` is not an endomorphism.
Mathlib/LinearAlgebra/Determinant.lean
424
427
theorem LinearEquiv.isUnit_det (f : M ≃ₗ[R] M') (v : Basis ι R M) (v' : Basis ι R M') : IsUnit (LinearMap.toMatrix v v' f).det := by
apply isUnit_det_of_left_inverse simpa using (LinearMap.toMatrix_comp v v' v f.symm f).symm
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Yakov Pechersky -/ import Mathlib.Data.List.Nodup import Mathlib.Data.List.Zip import Mathlib.Data.Nat.Defs import Mathlib.Data.List.Infix #align_import data.list.rotate from "leanprover-community/mathlib"@"f694c7dead66f5d4c80f446c796a5aad14707f0e" /-! # List rotation This file proves basic results about `List.rotate`, the list rotation. ## Main declarations * `List.IsRotated l₁ l₂`: States that `l₁` is a rotated version of `l₂`. * `List.cyclicPermutations l`: The list of all cyclic permutants of `l`, up to the length of `l`. ## Tags rotated, rotation, permutation, cycle -/ universe u variable {α : Type u} open Nat Function namespace List theorem rotate_mod (l : List α) (n : ℕ) : l.rotate (n % l.length) = l.rotate n := by simp [rotate] #align list.rotate_mod List.rotate_mod @[simp] theorem rotate_nil (n : ℕ) : ([] : List α).rotate n = [] := by simp [rotate] #align list.rotate_nil List.rotate_nil @[simp] theorem rotate_zero (l : List α) : l.rotate 0 = l := by simp [rotate] #align list.rotate_zero List.rotate_zero -- Porting note: removing simp, simp can prove it
Mathlib/Data/List/Rotate.lean
49
49
theorem rotate'_nil (n : ℕ) : ([] : List α).rotate' n = [] := by
cases n <;> rfl
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel, Rémy Degenne, David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Pow.Complex import Qq #align_import analysis.special_functions.pow.real from "leanprover-community/mathlib"@"4fa54b337f7d52805480306db1b1439c741848c8" /-! # Power function on `ℝ` We construct the power functions `x ^ y`, where `x` and `y` are real numbers. -/ noncomputable section open scoped Classical open Real ComplexConjugate open Finset Set /- ## Definitions -/ namespace Real variable {x y z : ℝ} /-- The real power function `x ^ y`, defined as the real part of the complex power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`, one sets `0 ^ 0=1` and `0 ^ y=0` for `y ≠ 0`. For `x < 0`, the definition is somewhat arbitrary as it depends on the choice of a complex determination of the logarithm. With our conventions, it is equal to `exp (y log x) cos (π y)`. -/ noncomputable def rpow (x y : ℝ) := ((x : ℂ) ^ (y : ℂ)).re #align real.rpow Real.rpow noncomputable instance : Pow ℝ ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x y : ℝ) : rpow x y = x ^ y := rfl #align real.rpow_eq_pow Real.rpow_eq_pow theorem rpow_def (x y : ℝ) : x ^ y = ((x : ℂ) ^ (y : ℂ)).re := rfl #align real.rpow_def Real.rpow_def theorem rpow_def_of_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) := by simp only [rpow_def, Complex.cpow_def]; split_ifs <;> simp_all [(Complex.ofReal_log hx).symm, -Complex.ofReal_mul, -RCLike.ofReal_mul, (Complex.ofReal_mul _ _).symm, Complex.exp_ofReal_re, Complex.ofReal_eq_zero] #align real.rpow_def_of_nonneg Real.rpow_def_of_nonneg theorem rpow_def_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : x ^ y = exp (log x * y) := by rw [rpow_def_of_nonneg (le_of_lt hx), if_neg (ne_of_gt hx)] #align real.rpow_def_of_pos Real.rpow_def_of_pos theorem exp_mul (x y : ℝ) : exp (x * y) = exp x ^ y := by rw [rpow_def_of_pos (exp_pos _), log_exp] #align real.exp_mul Real.exp_mul @[simp, norm_cast] theorem rpow_intCast (x : ℝ) (n : ℤ) : x ^ (n : ℝ) = x ^ n := by simp only [rpow_def, ← Complex.ofReal_zpow, Complex.cpow_intCast, Complex.ofReal_intCast, Complex.ofReal_re] #align real.rpow_int_cast Real.rpow_intCast @[deprecated (since := "2024-04-17")] alias rpow_int_cast := rpow_intCast @[simp, norm_cast] theorem rpow_natCast (x : ℝ) (n : ℕ) : x ^ (n : ℝ) = x ^ n := by simpa using rpow_intCast x n #align real.rpow_nat_cast Real.rpow_natCast @[deprecated (since := "2024-04-17")] alias rpow_nat_cast := rpow_natCast @[simp] theorem exp_one_rpow (x : ℝ) : exp 1 ^ x = exp x := by rw [← exp_mul, one_mul] #align real.exp_one_rpow Real.exp_one_rpow @[simp] lemma exp_one_pow (n : ℕ) : exp 1 ^ n = exp n := by rw [← rpow_natCast, exp_one_rpow] theorem rpow_eq_zero_iff_of_nonneg (hx : 0 ≤ x) : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by simp only [rpow_def_of_nonneg hx] split_ifs <;> simp [*, exp_ne_zero] #align real.rpow_eq_zero_iff_of_nonneg Real.rpow_eq_zero_iff_of_nonneg @[simp] lemma rpow_eq_zero (hx : 0 ≤ x) (hy : y ≠ 0) : x ^ y = 0 ↔ x = 0 := by simp [rpow_eq_zero_iff_of_nonneg, *] @[simp] lemma rpow_ne_zero (hx : 0 ≤ x) (hy : y ≠ 0) : x ^ y ≠ 0 ↔ x ≠ 0 := Real.rpow_eq_zero hx hy |>.not open Real theorem rpow_def_of_neg {x : ℝ} (hx : x < 0) (y : ℝ) : x ^ y = exp (log x * y) * cos (y * π) := by rw [rpow_def, Complex.cpow_def, if_neg] · have : Complex.log x * y = ↑(log (-x) * y) + ↑(y * π) * Complex.I := by simp only [Complex.log, abs_of_neg hx, Complex.arg_ofReal_of_neg hx, Complex.abs_ofReal, Complex.ofReal_mul] ring rw [this, Complex.exp_add_mul_I, ← Complex.ofReal_exp, ← Complex.ofReal_cos, ← Complex.ofReal_sin, mul_add, ← Complex.ofReal_mul, ← mul_assoc, ← Complex.ofReal_mul, Complex.add_re, Complex.ofReal_re, Complex.mul_re, Complex.I_re, Complex.ofReal_im, Real.log_neg_eq_log] ring · rw [Complex.ofReal_eq_zero] exact ne_of_lt hx #align real.rpow_def_of_neg Real.rpow_def_of_neg theorem rpow_def_of_nonpos {x : ℝ} (hx : x ≤ 0) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) * cos (y * π) := by split_ifs with h <;> simp [rpow_def, *]; exact rpow_def_of_neg (lt_of_le_of_ne hx h) _ #align real.rpow_def_of_nonpos Real.rpow_def_of_nonpos theorem rpow_pos_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : 0 < x ^ y := by rw [rpow_def_of_pos hx]; apply exp_pos #align real.rpow_pos_of_pos Real.rpow_pos_of_pos @[simp] theorem rpow_zero (x : ℝ) : x ^ (0 : ℝ) = 1 := by simp [rpow_def] #align real.rpow_zero Real.rpow_zero theorem rpow_zero_pos (x : ℝ) : 0 < x ^ (0 : ℝ) := by simp @[simp] theorem zero_rpow {x : ℝ} (h : x ≠ 0) : (0 : ℝ) ^ x = 0 := by simp [rpow_def, *] #align real.zero_rpow Real.zero_rpow theorem zero_rpow_eq_iff {x : ℝ} {a : ℝ} : 0 ^ x = a ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by constructor · intro hyp simp only [rpow_def, Complex.ofReal_zero] at hyp by_cases h : x = 0 · subst h simp only [Complex.one_re, Complex.ofReal_zero, Complex.cpow_zero] at hyp exact Or.inr ⟨rfl, hyp.symm⟩ · rw [Complex.zero_cpow (Complex.ofReal_ne_zero.mpr h)] at hyp exact Or.inl ⟨h, hyp.symm⟩ · rintro (⟨h, rfl⟩ | ⟨rfl, rfl⟩) · exact zero_rpow h · exact rpow_zero _ #align real.zero_rpow_eq_iff Real.zero_rpow_eq_iff theorem eq_zero_rpow_iff {x : ℝ} {a : ℝ} : a = 0 ^ x ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by rw [← zero_rpow_eq_iff, eq_comm] #align real.eq_zero_rpow_iff Real.eq_zero_rpow_iff @[simp] theorem rpow_one (x : ℝ) : x ^ (1 : ℝ) = x := by simp [rpow_def] #align real.rpow_one Real.rpow_one @[simp] theorem one_rpow (x : ℝ) : (1 : ℝ) ^ x = 1 := by simp [rpow_def] #align real.one_rpow Real.one_rpow theorem zero_rpow_le_one (x : ℝ) : (0 : ℝ) ^ x ≤ 1 := by by_cases h : x = 0 <;> simp [h, zero_le_one] #align real.zero_rpow_le_one Real.zero_rpow_le_one theorem zero_rpow_nonneg (x : ℝ) : 0 ≤ (0 : ℝ) ^ x := by by_cases h : x = 0 <;> simp [h, zero_le_one] #align real.zero_rpow_nonneg Real.zero_rpow_nonneg theorem rpow_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : 0 ≤ x ^ y := by rw [rpow_def_of_nonneg hx]; split_ifs <;> simp only [zero_le_one, le_refl, le_of_lt (exp_pos _)] #align real.rpow_nonneg_of_nonneg Real.rpow_nonneg theorem abs_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≤ x) : |x ^ y| = |x| ^ y := by have h_rpow_nonneg : 0 ≤ x ^ y := Real.rpow_nonneg hx_nonneg _ rw [abs_eq_self.mpr hx_nonneg, abs_eq_self.mpr h_rpow_nonneg] #align real.abs_rpow_of_nonneg Real.abs_rpow_of_nonneg theorem abs_rpow_le_abs_rpow (x y : ℝ) : |x ^ y| ≤ |x| ^ y := by rcases le_or_lt 0 x with hx | hx · rw [abs_rpow_of_nonneg hx] · rw [abs_of_neg hx, rpow_def_of_neg hx, rpow_def_of_pos (neg_pos.2 hx), log_neg_eq_log, abs_mul, abs_of_pos (exp_pos _)] exact mul_le_of_le_one_right (exp_pos _).le (abs_cos_le_one _) #align real.abs_rpow_le_abs_rpow Real.abs_rpow_le_abs_rpow theorem abs_rpow_le_exp_log_mul (x y : ℝ) : |x ^ y| ≤ exp (log x * y) := by refine (abs_rpow_le_abs_rpow x y).trans ?_ by_cases hx : x = 0 · by_cases hy : y = 0 <;> simp [hx, hy, zero_le_one] · rw [rpow_def_of_pos (abs_pos.2 hx), log_abs] #align real.abs_rpow_le_exp_log_mul Real.abs_rpow_le_exp_log_mul theorem norm_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≤ x) : ‖x ^ y‖ = ‖x‖ ^ y := by simp_rw [Real.norm_eq_abs] exact abs_rpow_of_nonneg hx_nonneg #align real.norm_rpow_of_nonneg Real.norm_rpow_of_nonneg variable {w x y z : ℝ} theorem rpow_add (hx : 0 < x) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z := by simp only [rpow_def_of_pos hx, mul_add, exp_add] #align real.rpow_add Real.rpow_add theorem rpow_add' (hx : 0 ≤ x) (h : y + z ≠ 0) : x ^ (y + z) = x ^ y * x ^ z := by rcases hx.eq_or_lt with (rfl | pos) · rw [zero_rpow h, zero_eq_mul] have : y ≠ 0 ∨ z ≠ 0 := not_and_or.1 fun ⟨hy, hz⟩ => h <| hy.symm ▸ hz.symm ▸ zero_add 0 exact this.imp zero_rpow zero_rpow · exact rpow_add pos _ _ #align real.rpow_add' Real.rpow_add' /-- Variant of `Real.rpow_add'` that avoids having to prove `y + z = w` twice. -/ lemma rpow_of_add_eq (hx : 0 ≤ x) (hw : w ≠ 0) (h : y + z = w) : x ^ w = x ^ y * x ^ z := by rw [← h, rpow_add' hx]; rwa [h] theorem rpow_add_of_nonneg (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 ≤ z) : x ^ (y + z) = x ^ y * x ^ z := by rcases hy.eq_or_lt with (rfl | hy) · rw [zero_add, rpow_zero, one_mul] exact rpow_add' hx (ne_of_gt <| add_pos_of_pos_of_nonneg hy hz) #align real.rpow_add_of_nonneg Real.rpow_add_of_nonneg /-- For `0 ≤ x`, the only problematic case in the equality `x ^ y * x ^ z = x ^ (y + z)` is for `x = 0` and `y + z = 0`, where the right hand side is `1` while the left hand side can vanish. The inequality is always true, though, and given in this lemma. -/ theorem le_rpow_add {x : ℝ} (hx : 0 ≤ x) (y z : ℝ) : x ^ y * x ^ z ≤ x ^ (y + z) := by rcases le_iff_eq_or_lt.1 hx with (H | pos) · by_cases h : y + z = 0 · simp only [H.symm, h, rpow_zero] calc (0 : ℝ) ^ y * 0 ^ z ≤ 1 * 1 := mul_le_mul (zero_rpow_le_one y) (zero_rpow_le_one z) (zero_rpow_nonneg z) zero_le_one _ = 1 := by simp · simp [rpow_add', ← H, h] · simp [rpow_add pos] #align real.le_rpow_add Real.le_rpow_add theorem rpow_sum_of_pos {ι : Type*} {a : ℝ} (ha : 0 < a) (f : ι → ℝ) (s : Finset ι) : (a ^ ∑ x ∈ s, f x) = ∏ x ∈ s, a ^ f x := map_sum (⟨⟨fun (x : ℝ) => (a ^ x : ℝ), rpow_zero a⟩, rpow_add ha⟩ : ℝ →+ (Additive ℝ)) f s #align real.rpow_sum_of_pos Real.rpow_sum_of_pos theorem rpow_sum_of_nonneg {ι : Type*} {a : ℝ} (ha : 0 ≤ a) {s : Finset ι} {f : ι → ℝ} (h : ∀ x ∈ s, 0 ≤ f x) : (a ^ ∑ x ∈ s, f x) = ∏ x ∈ s, a ^ f x := by induction' s using Finset.cons_induction with i s hi ihs · rw [sum_empty, Finset.prod_empty, rpow_zero] · rw [forall_mem_cons] at h rw [sum_cons, prod_cons, ← ihs h.2, rpow_add_of_nonneg ha h.1 (sum_nonneg h.2)] #align real.rpow_sum_of_nonneg Real.rpow_sum_of_nonneg theorem rpow_neg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := by simp only [rpow_def_of_nonneg hx]; split_ifs <;> simp_all [exp_neg] #align real.rpow_neg Real.rpow_neg theorem rpow_sub {x : ℝ} (hx : 0 < x) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z := by simp only [sub_eq_add_neg, rpow_add hx, rpow_neg (le_of_lt hx), div_eq_mul_inv] #align real.rpow_sub Real.rpow_sub theorem rpow_sub' {x : ℝ} (hx : 0 ≤ x) {y z : ℝ} (h : y - z ≠ 0) : x ^ (y - z) = x ^ y / x ^ z := by simp only [sub_eq_add_neg] at h ⊢ simp only [rpow_add' hx h, rpow_neg hx, div_eq_mul_inv] #align real.rpow_sub' Real.rpow_sub' end Real /-! ## Comparing real and complex powers -/ namespace Complex theorem ofReal_cpow {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : ((x ^ y : ℝ) : ℂ) = (x : ℂ) ^ (y : ℂ) := by simp only [Real.rpow_def_of_nonneg hx, Complex.cpow_def, ofReal_eq_zero]; split_ifs <;> simp [Complex.ofReal_log hx] #align complex.of_real_cpow Complex.ofReal_cpow theorem ofReal_cpow_of_nonpos {x : ℝ} (hx : x ≤ 0) (y : ℂ) : (x : ℂ) ^ y = (-x : ℂ) ^ y * exp (π * I * y) := by rcases hx.eq_or_lt with (rfl | hlt) · rcases eq_or_ne y 0 with (rfl | hy) <;> simp [*] have hne : (x : ℂ) ≠ 0 := ofReal_ne_zero.mpr hlt.ne rw [cpow_def_of_ne_zero hne, cpow_def_of_ne_zero (neg_ne_zero.2 hne), ← exp_add, ← add_mul, log, log, abs.map_neg, arg_ofReal_of_neg hlt, ← ofReal_neg, arg_ofReal_of_nonneg (neg_nonneg.2 hx), ofReal_zero, zero_mul, add_zero] #align complex.of_real_cpow_of_nonpos Complex.ofReal_cpow_of_nonpos lemma cpow_ofReal (x : ℂ) (y : ℝ) : x ^ (y : ℂ) = ↑(abs x ^ y) * (Real.cos (arg x * y) + Real.sin (arg x * y) * I) := by rcases eq_or_ne x 0 with rfl | hx · simp [ofReal_cpow le_rfl] · rw [cpow_def_of_ne_zero hx, exp_eq_exp_re_mul_sin_add_cos, mul_comm (log x)] norm_cast rw [re_ofReal_mul, im_ofReal_mul, log_re, log_im, mul_comm y, mul_comm y, Real.exp_mul, Real.exp_log] rwa [abs.pos_iff] lemma cpow_ofReal_re (x : ℂ) (y : ℝ) : (x ^ (y : ℂ)).re = (abs x) ^ y * Real.cos (arg x * y) := by rw [cpow_ofReal]; generalize arg x * y = z; simp [Real.cos] lemma cpow_ofReal_im (x : ℂ) (y : ℝ) : (x ^ (y : ℂ)).im = (abs x) ^ y * Real.sin (arg x * y) := by rw [cpow_ofReal]; generalize arg x * y = z; simp [Real.sin] theorem abs_cpow_of_ne_zero {z : ℂ} (hz : z ≠ 0) (w : ℂ) : abs (z ^ w) = abs z ^ w.re / Real.exp (arg z * im w) := by rw [cpow_def_of_ne_zero hz, abs_exp, mul_re, log_re, log_im, Real.exp_sub, Real.rpow_def_of_pos (abs.pos hz)] #align complex.abs_cpow_of_ne_zero Complex.abs_cpow_of_ne_zero theorem abs_cpow_of_imp {z w : ℂ} (h : z = 0 → w.re = 0 → w = 0) : abs (z ^ w) = abs z ^ w.re / Real.exp (arg z * im w) := by rcases ne_or_eq z 0 with (hz | rfl) <;> [exact abs_cpow_of_ne_zero hz w; rw [map_zero]] rcases eq_or_ne w.re 0 with hw | hw · simp [hw, h rfl hw] · rw [Real.zero_rpow hw, zero_div, zero_cpow, map_zero] exact ne_of_apply_ne re hw #align complex.abs_cpow_of_imp Complex.abs_cpow_of_imp theorem abs_cpow_le (z w : ℂ) : abs (z ^ w) ≤ abs z ^ w.re / Real.exp (arg z * im w) := by by_cases h : z = 0 → w.re = 0 → w = 0 · exact (abs_cpow_of_imp h).le · push_neg at h simp [h] #align complex.abs_cpow_le Complex.abs_cpow_le @[simp] theorem abs_cpow_real (x : ℂ) (y : ℝ) : abs (x ^ (y : ℂ)) = Complex.abs x ^ y := by rw [abs_cpow_of_imp] <;> simp #align complex.abs_cpow_real Complex.abs_cpow_real @[simp] theorem abs_cpow_inv_nat (x : ℂ) (n : ℕ) : abs (x ^ (n⁻¹ : ℂ)) = Complex.abs x ^ (n⁻¹ : ℝ) := by rw [← abs_cpow_real]; simp [-abs_cpow_real] #align complex.abs_cpow_inv_nat Complex.abs_cpow_inv_nat theorem abs_cpow_eq_rpow_re_of_pos {x : ℝ} (hx : 0 < x) (y : ℂ) : abs (x ^ y) = x ^ y.re := by rw [abs_cpow_of_ne_zero (ofReal_ne_zero.mpr hx.ne'), arg_ofReal_of_nonneg hx.le, zero_mul, Real.exp_zero, div_one, abs_of_nonneg hx.le] #align complex.abs_cpow_eq_rpow_re_of_pos Complex.abs_cpow_eq_rpow_re_of_pos theorem abs_cpow_eq_rpow_re_of_nonneg {x : ℝ} (hx : 0 ≤ x) {y : ℂ} (hy : re y ≠ 0) : abs (x ^ y) = x ^ re y := by rw [abs_cpow_of_imp] <;> simp [*, arg_ofReal_of_nonneg, _root_.abs_of_nonneg] #align complex.abs_cpow_eq_rpow_re_of_nonneg Complex.abs_cpow_eq_rpow_re_of_nonneg lemma norm_natCast_cpow_of_re_ne_zero (n : ℕ) {s : ℂ} (hs : s.re ≠ 0) : ‖(n : ℂ) ^ s‖ = (n : ℝ) ^ (s.re) := by rw [norm_eq_abs, ← ofReal_natCast, abs_cpow_eq_rpow_re_of_nonneg n.cast_nonneg hs] lemma norm_natCast_cpow_of_pos {n : ℕ} (hn : 0 < n) (s : ℂ) : ‖(n : ℂ) ^ s‖ = (n : ℝ) ^ (s.re) := by rw [norm_eq_abs, ← ofReal_natCast, abs_cpow_eq_rpow_re_of_pos (Nat.cast_pos.mpr hn) _] lemma norm_natCast_cpow_pos_of_pos {n : ℕ} (hn : 0 < n) (s : ℂ) : 0 < ‖(n : ℂ) ^ s‖ := (norm_natCast_cpow_of_pos hn _).symm ▸ Real.rpow_pos_of_pos (Nat.cast_pos.mpr hn) _ theorem cpow_mul_ofReal_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) (z : ℂ) : (x : ℂ) ^ (↑y * z) = (↑(x ^ y) : ℂ) ^ z := by rw [cpow_mul, ofReal_cpow hx] · rw [← ofReal_log hx, ← ofReal_mul, ofReal_im, neg_lt_zero]; exact Real.pi_pos · rw [← ofReal_log hx, ← ofReal_mul, ofReal_im]; exact Real.pi_pos.le #align complex.cpow_mul_of_real_nonneg Complex.cpow_mul_ofReal_nonneg end Complex /-! ### Positivity extension -/ namespace Mathlib.Meta.Positivity open Lean Meta Qq /-- Extension for the `positivity` tactic: exponentiation by a real number is positive (namely 1) when the exponent is zero. The other cases are done in `evalRpow`. -/ @[positivity (_ : ℝ) ^ (0 : ℝ)] def evalRpowZero : PositivityExt where eval {u α} _ _ e := do match u, α, e with | 0, ~q(ℝ), ~q($a ^ (0 : ℝ)) => assertInstancesCommute pure (.positive q(Real.rpow_zero_pos $a)) | _, _, _ => throwError "not Real.rpow" /-- Extension for the `positivity` tactic: exponentiation by a real number is nonnegative when the base is nonnegative and positive when the base is positive. -/ @[positivity (_ : ℝ) ^ (_ : ℝ)] def evalRpow : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q($a ^ ($b : ℝ)) => let ra ← core q(inferInstance) q(inferInstance) a assertInstancesCommute match ra with | .positive pa => pure (.positive q(Real.rpow_pos_of_pos $pa $b)) | .nonnegative pa => pure (.nonnegative q(Real.rpow_nonneg $pa $b)) | _ => pure .none | _, _, _ => throwError "not Real.rpow" end Mathlib.Meta.Positivity /-! ## Further algebraic properties of `rpow` -/ namespace Real variable {x y z : ℝ} {n : ℕ} theorem rpow_mul {x : ℝ} (hx : 0 ≤ x) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := by rw [← Complex.ofReal_inj, Complex.ofReal_cpow (rpow_nonneg hx _), Complex.ofReal_cpow hx, Complex.ofReal_mul, Complex.cpow_mul, Complex.ofReal_cpow hx] <;> simp only [(Complex.ofReal_mul _ _).symm, (Complex.ofReal_log hx).symm, Complex.ofReal_im, neg_lt_zero, pi_pos, le_of_lt pi_pos] #align real.rpow_mul Real.rpow_mul theorem rpow_add_int {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℤ) : x ^ (y + n) = x ^ y * x ^ n := by rw [rpow_def, rpow_def, Complex.ofReal_add, Complex.cpow_add _ _ (Complex.ofReal_ne_zero.mpr hx), Complex.ofReal_intCast, Complex.cpow_intCast, ← Complex.ofReal_zpow, mul_comm, Complex.re_ofReal_mul, mul_comm] #align real.rpow_add_int Real.rpow_add_int theorem rpow_add_nat {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y + n) = x ^ y * x ^ n := by simpa using rpow_add_int hx y n #align real.rpow_add_nat Real.rpow_add_nat theorem rpow_sub_int {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y - n) = x ^ y / x ^ n := by simpa using rpow_add_int hx y (-n) #align real.rpow_sub_int Real.rpow_sub_int theorem rpow_sub_nat {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y - n) = x ^ y / x ^ n := by simpa using rpow_sub_int hx y n #align real.rpow_sub_nat Real.rpow_sub_nat lemma rpow_add_int' (hx : 0 ≤ x) {n : ℤ} (h : y + n ≠ 0) : x ^ (y + n) = x ^ y * x ^ n := by rw [rpow_add' hx h, rpow_intCast] lemma rpow_add_nat' (hx : 0 ≤ x) (h : y + n ≠ 0) : x ^ (y + n) = x ^ y * x ^ n := by rw [rpow_add' hx h, rpow_natCast] lemma rpow_sub_int' (hx : 0 ≤ x) {n : ℤ} (h : y - n ≠ 0) : x ^ (y - n) = x ^ y / x ^ n := by rw [rpow_sub' hx h, rpow_intCast] lemma rpow_sub_nat' (hx : 0 ≤ x) (h : y - n ≠ 0) : x ^ (y - n) = x ^ y / x ^ n := by rw [rpow_sub' hx h, rpow_natCast] theorem rpow_add_one {x : ℝ} (hx : x ≠ 0) (y : ℝ) : x ^ (y + 1) = x ^ y * x := by simpa using rpow_add_nat hx y 1 #align real.rpow_add_one Real.rpow_add_one theorem rpow_sub_one {x : ℝ} (hx : x ≠ 0) (y : ℝ) : x ^ (y - 1) = x ^ y / x := by simpa using rpow_sub_nat hx y 1 #align real.rpow_sub_one Real.rpow_sub_one lemma rpow_add_one' (hx : 0 ≤ x) (h : y + 1 ≠ 0) : x ^ (y + 1) = x ^ y * x := by rw [rpow_add' hx h, rpow_one] lemma rpow_one_add' (hx : 0 ≤ x) (h : 1 + y ≠ 0) : x ^ (1 + y) = x * x ^ y := by rw [rpow_add' hx h, rpow_one] lemma rpow_sub_one' (hx : 0 ≤ x) (h : y - 1 ≠ 0) : x ^ (y - 1) = x ^ y / x := by rw [rpow_sub' hx h, rpow_one] lemma rpow_one_sub' (hx : 0 ≤ x) (h : 1 - y ≠ 0) : x ^ (1 - y) = x / x ^ y := by rw [rpow_sub' hx h, rpow_one] @[simp] theorem rpow_two (x : ℝ) : x ^ (2 : ℝ) = x ^ 2 := by rw [← rpow_natCast] simp only [Nat.cast_ofNat] #align real.rpow_two Real.rpow_two theorem rpow_neg_one (x : ℝ) : x ^ (-1 : ℝ) = x⁻¹ := by suffices H : x ^ ((-1 : ℤ) : ℝ) = x⁻¹ by rwa [Int.cast_neg, Int.cast_one] at H simp only [rpow_intCast, zpow_one, zpow_neg] #align real.rpow_neg_one Real.rpow_neg_one theorem mul_rpow (hx : 0 ≤ x) (hy : 0 ≤ y) : (x * y) ^ z = x ^ z * y ^ z := by iterate 2 rw [Real.rpow_def_of_nonneg]; split_ifs with h_ifs <;> simp_all · rw [log_mul ‹_› ‹_›, add_mul, exp_add, rpow_def_of_pos (hy.lt_of_ne' ‹_›)] all_goals positivity #align real.mul_rpow Real.mul_rpow theorem inv_rpow (hx : 0 ≤ x) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := by simp only [← rpow_neg_one, ← rpow_mul hx, mul_comm] #align real.inv_rpow Real.inv_rpow theorem div_rpow (hx : 0 ≤ x) (hy : 0 ≤ y) (z : ℝ) : (x / y) ^ z = x ^ z / y ^ z := by simp only [div_eq_mul_inv, mul_rpow hx (inv_nonneg.2 hy), inv_rpow hy] #align real.div_rpow Real.div_rpow theorem log_rpow {x : ℝ} (hx : 0 < x) (y : ℝ) : log (x ^ y) = y * log x := by apply exp_injective rw [exp_log (rpow_pos_of_pos hx y), ← exp_log hx, mul_comm, rpow_def_of_pos (exp_pos (log x)) y] #align real.log_rpow Real.log_rpow theorem mul_log_eq_log_iff {x y z : ℝ} (hx : 0 < x) (hz : 0 < z) : y * log x = log z ↔ x ^ y = z := ⟨fun h ↦ log_injOn_pos (rpow_pos_of_pos hx _) hz <| log_rpow hx _ |>.trans h, by rintro rfl; rw [log_rpow hx]⟩ @[simp] lemma rpow_rpow_inv (hx : 0 ≤ x) (hy : y ≠ 0) : (x ^ y) ^ y⁻¹ = x := by rw [← rpow_mul hx, mul_inv_cancel hy, rpow_one] @[simp] lemma rpow_inv_rpow (hx : 0 ≤ x) (hy : y ≠ 0) : (x ^ y⁻¹) ^ y = x := by rw [← rpow_mul hx, inv_mul_cancel hy, rpow_one] theorem pow_rpow_inv_natCast (hx : 0 ≤ x) (hn : n ≠ 0) : (x ^ n) ^ (n⁻¹ : ℝ) = x := by have hn0 : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.2 hn rw [← rpow_natCast, ← rpow_mul hx, mul_inv_cancel hn0, rpow_one] #align real.pow_nat_rpow_nat_inv Real.pow_rpow_inv_natCast theorem rpow_inv_natCast_pow (hx : 0 ≤ x) (hn : n ≠ 0) : (x ^ (n⁻¹ : ℝ)) ^ n = x := by have hn0 : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.2 hn rw [← rpow_natCast, ← rpow_mul hx, inv_mul_cancel hn0, rpow_one] #align real.rpow_nat_inv_pow_nat Real.rpow_inv_natCast_pow lemma rpow_natCast_mul (hx : 0 ≤ x) (n : ℕ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by rw [rpow_mul hx, rpow_natCast] lemma rpow_mul_natCast (hx : 0 ≤ x) (y : ℝ) (n : ℕ) : x ^ (y * n) = (x ^ y) ^ n := by rw [rpow_mul hx, rpow_natCast] lemma rpow_intCast_mul (hx : 0 ≤ x) (n : ℤ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by rw [rpow_mul hx, rpow_intCast] lemma rpow_mul_intCast (hx : 0 ≤ x) (y : ℝ) (n : ℤ) : x ^ (y * n) = (x ^ y) ^ n := by rw [rpow_mul hx, rpow_intCast] /-! Note: lemmas about `(∏ i ∈ s, f i ^ r)` such as `Real.finset_prod_rpow` are proved in `Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean` instead. -/ /-! ## Order and monotonicity -/ @[gcongr] theorem rpow_lt_rpow (hx : 0 ≤ x) (hxy : x < y) (hz : 0 < z) : x ^ z < y ^ z := by rw [le_iff_eq_or_lt] at hx; cases' hx with hx hx · rw [← hx, zero_rpow (ne_of_gt hz)] exact rpow_pos_of_pos (by rwa [← hx] at hxy) _ · rw [rpow_def_of_pos hx, rpow_def_of_pos (lt_trans hx hxy), exp_lt_exp] exact mul_lt_mul_of_pos_right (log_lt_log hx hxy) hz #align real.rpow_lt_rpow Real.rpow_lt_rpow theorem strictMonoOn_rpow_Ici_of_exponent_pos {r : ℝ} (hr : 0 < r) : StrictMonoOn (fun (x : ℝ) => x ^ r) (Set.Ici 0) := fun _ ha _ _ hab => rpow_lt_rpow ha hab hr @[gcongr] theorem rpow_le_rpow {x y z : ℝ} (h : 0 ≤ x) (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x ^ z ≤ y ^ z := by rcases eq_or_lt_of_le h₁ with (rfl | h₁'); · rfl rcases eq_or_lt_of_le h₂ with (rfl | h₂'); · simp exact le_of_lt (rpow_lt_rpow h h₁' h₂') #align real.rpow_le_rpow Real.rpow_le_rpow theorem monotoneOn_rpow_Ici_of_exponent_nonneg {r : ℝ} (hr : 0 ≤ r) : MonotoneOn (fun (x : ℝ) => x ^ r) (Set.Ici 0) := fun _ ha _ _ hab => rpow_le_rpow ha hab hr lemma rpow_lt_rpow_of_neg (hx : 0 < x) (hxy : x < y) (hz : z < 0) : y ^ z < x ^ z := by have := hx.trans hxy rw [← inv_lt_inv, ← rpow_neg, ← rpow_neg] on_goal 1 => refine rpow_lt_rpow ?_ hxy (neg_pos.2 hz) all_goals positivity lemma rpow_le_rpow_of_nonpos (hx : 0 < x) (hxy : x ≤ y) (hz : z ≤ 0) : y ^ z ≤ x ^ z := by have := hx.trans_le hxy rw [← inv_le_inv, ← rpow_neg, ← rpow_neg] on_goal 1 => refine rpow_le_rpow ?_ hxy (neg_nonneg.2 hz) all_goals positivity theorem rpow_lt_rpow_iff (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z < y ^ z ↔ x < y := ⟨lt_imp_lt_of_le_imp_le fun h => rpow_le_rpow hy h (le_of_lt hz), fun h => rpow_lt_rpow hx h hz⟩ #align real.rpow_lt_rpow_iff Real.rpow_lt_rpow_iff theorem rpow_le_rpow_iff (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z ≤ y ^ z ↔ x ≤ y := le_iff_le_iff_lt_iff_lt.2 <| rpow_lt_rpow_iff hy hx hz #align real.rpow_le_rpow_iff Real.rpow_le_rpow_iff lemma rpow_lt_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z < y ^ z ↔ y < x := ⟨lt_imp_lt_of_le_imp_le fun h ↦ rpow_le_rpow_of_nonpos hx h hz.le, fun h ↦ rpow_lt_rpow_of_neg hy h hz⟩ lemma rpow_le_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z ≤ y ^ z ↔ y ≤ x := le_iff_le_iff_lt_iff_lt.2 <| rpow_lt_rpow_iff_of_neg hy hx hz lemma le_rpow_inv_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ≤ y ^ z⁻¹ ↔ x ^ z ≤ y := by rw [← rpow_le_rpow_iff hx _ hz, rpow_inv_rpow] <;> positivity lemma rpow_inv_le_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z⁻¹ ≤ y ↔ x ≤ y ^ z := by rw [← rpow_le_rpow_iff _ hy hz, rpow_inv_rpow] <;> positivity lemma lt_rpow_inv_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x < y ^ z⁻¹ ↔ x ^ z < y := lt_iff_lt_of_le_iff_le <| rpow_inv_le_iff_of_pos hy hx hz lemma rpow_inv_lt_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z⁻¹ < y ↔ x < y ^ z := lt_iff_lt_of_le_iff_le <| le_rpow_inv_iff_of_pos hy hx hz theorem le_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ≤ y ^ z⁻¹ ↔ y ≤ x ^ z := by rw [← rpow_le_rpow_iff_of_neg _ hx hz, rpow_inv_rpow _ hz.ne] <;> positivity #align real.le_rpow_inv_iff_of_neg Real.le_rpow_inv_iff_of_neg theorem lt_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x < y ^ z⁻¹ ↔ y < x ^ z := by rw [← rpow_lt_rpow_iff_of_neg _ hx hz, rpow_inv_rpow _ hz.ne] <;> positivity #align real.lt_rpow_inv_iff_of_neg Real.lt_rpow_inv_iff_of_neg theorem rpow_inv_lt_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ < y ↔ y ^ z < x := by rw [← rpow_lt_rpow_iff_of_neg hy _ hz, rpow_inv_rpow _ hz.ne] <;> positivity #align real.rpow_inv_lt_iff_of_neg Real.rpow_inv_lt_iff_of_neg theorem rpow_inv_le_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ ≤ y ↔ y ^ z ≤ x := by rw [← rpow_le_rpow_iff_of_neg hy _ hz, rpow_inv_rpow _ hz.ne] <;> positivity #align real.rpow_inv_le_iff_of_neg Real.rpow_inv_le_iff_of_neg theorem rpow_lt_rpow_of_exponent_lt (hx : 1 < x) (hyz : y < z) : x ^ y < x ^ z := by repeat' rw [rpow_def_of_pos (lt_trans zero_lt_one hx)] rw [exp_lt_exp]; exact mul_lt_mul_of_pos_left hyz (log_pos hx) #align real.rpow_lt_rpow_of_exponent_lt Real.rpow_lt_rpow_of_exponent_lt @[gcongr] theorem rpow_le_rpow_of_exponent_le (hx : 1 ≤ x) (hyz : y ≤ z) : x ^ y ≤ x ^ z := by repeat' rw [rpow_def_of_pos (lt_of_lt_of_le zero_lt_one hx)] rw [exp_le_exp]; exact mul_le_mul_of_nonneg_left hyz (log_nonneg hx) #align real.rpow_le_rpow_of_exponent_le Real.rpow_le_rpow_of_exponent_le theorem rpow_lt_rpow_of_exponent_neg {x y z : ℝ} (hy : 0 < y) (hxy : y < x) (hz : z < 0) : x ^ z < y ^ z := by have hx : 0 < x := hy.trans hxy rw [← neg_neg z, Real.rpow_neg (le_of_lt hx) (-z), Real.rpow_neg (le_of_lt hy) (-z), inv_lt_inv (rpow_pos_of_pos hx _) (rpow_pos_of_pos hy _)] exact Real.rpow_lt_rpow (by positivity) hxy <| neg_pos_of_neg hz theorem strictAntiOn_rpow_Ioi_of_exponent_neg {r : ℝ} (hr : r < 0) : StrictAntiOn (fun (x:ℝ) => x ^ r) (Set.Ioi 0) := fun _ ha _ _ hab => rpow_lt_rpow_of_exponent_neg ha hab hr theorem rpow_le_rpow_of_exponent_nonpos {x y : ℝ} (hy : 0 < y) (hxy : y ≤ x) (hz : z ≤ 0) : x ^ z ≤ y ^ z := by rcases ne_or_eq z 0 with hz_zero | rfl case inl => rcases ne_or_eq x y with hxy' | rfl case inl => exact le_of_lt <| rpow_lt_rpow_of_exponent_neg hy (Ne.lt_of_le (id (Ne.symm hxy')) hxy) (Ne.lt_of_le hz_zero hz) case inr => simp case inr => simp theorem antitoneOn_rpow_Ioi_of_exponent_nonpos {r : ℝ} (hr : r ≤ 0) : AntitoneOn (fun (x:ℝ) => x ^ r) (Set.Ioi 0) := fun _ ha _ _ hab => rpow_le_rpow_of_exponent_nonpos ha hab hr @[simp] theorem rpow_le_rpow_left_iff (hx : 1 < x) : x ^ y ≤ x ^ z ↔ y ≤ z := by have x_pos : 0 < x := lt_trans zero_lt_one hx rw [← log_le_log_iff (rpow_pos_of_pos x_pos y) (rpow_pos_of_pos x_pos z), log_rpow x_pos, log_rpow x_pos, mul_le_mul_right (log_pos hx)] #align real.rpow_le_rpow_left_iff Real.rpow_le_rpow_left_iff @[simp] theorem rpow_lt_rpow_left_iff (hx : 1 < x) : x ^ y < x ^ z ↔ y < z := by rw [lt_iff_not_le, rpow_le_rpow_left_iff hx, lt_iff_not_le] #align real.rpow_lt_rpow_left_iff Real.rpow_lt_rpow_left_iff theorem rpow_lt_rpow_of_exponent_gt (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) : x ^ y < x ^ z := by repeat' rw [rpow_def_of_pos hx0] rw [exp_lt_exp]; exact mul_lt_mul_of_neg_left hyz (log_neg hx0 hx1) #align real.rpow_lt_rpow_of_exponent_gt Real.rpow_lt_rpow_of_exponent_gt theorem rpow_le_rpow_of_exponent_ge (hx0 : 0 < x) (hx1 : x ≤ 1) (hyz : z ≤ y) : x ^ y ≤ x ^ z := by repeat' rw [rpow_def_of_pos hx0] rw [exp_le_exp]; exact mul_le_mul_of_nonpos_left hyz (log_nonpos (le_of_lt hx0) hx1) #align real.rpow_le_rpow_of_exponent_ge Real.rpow_le_rpow_of_exponent_ge @[simp] theorem rpow_le_rpow_left_iff_of_base_lt_one (hx0 : 0 < x) (hx1 : x < 1) : x ^ y ≤ x ^ z ↔ z ≤ y := by rw [← log_le_log_iff (rpow_pos_of_pos hx0 y) (rpow_pos_of_pos hx0 z), log_rpow hx0, log_rpow hx0, mul_le_mul_right_of_neg (log_neg hx0 hx1)] #align real.rpow_le_rpow_left_iff_of_base_lt_one Real.rpow_le_rpow_left_iff_of_base_lt_one @[simp] theorem rpow_lt_rpow_left_iff_of_base_lt_one (hx0 : 0 < x) (hx1 : x < 1) : x ^ y < x ^ z ↔ z < y := by rw [lt_iff_not_le, rpow_le_rpow_left_iff_of_base_lt_one hx0 hx1, lt_iff_not_le] #align real.rpow_lt_rpow_left_iff_of_base_lt_one Real.rpow_lt_rpow_left_iff_of_base_lt_one theorem rpow_lt_one {x z : ℝ} (hx1 : 0 ≤ x) (hx2 : x < 1) (hz : 0 < z) : x ^ z < 1 := by rw [← one_rpow z] exact rpow_lt_rpow hx1 hx2 hz #align real.rpow_lt_one Real.rpow_lt_one theorem rpow_le_one {x z : ℝ} (hx1 : 0 ≤ x) (hx2 : x ≤ 1) (hz : 0 ≤ z) : x ^ z ≤ 1 := by rw [← one_rpow z] exact rpow_le_rpow hx1 hx2 hz #align real.rpow_le_one Real.rpow_le_one
Mathlib/Analysis/SpecialFunctions/Pow/Real.lean
703
705
theorem rpow_lt_one_of_one_lt_of_neg {x z : ℝ} (hx : 1 < x) (hz : z < 0) : x ^ z < 1 := by
convert rpow_lt_rpow_of_exponent_lt hx hz exact (rpow_zero x).symm
/- Copyright (c) 2021 Thomas Browning. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning -/ import Mathlib.GroupTheory.Sylow import Mathlib.GroupTheory.Transfer #align_import group_theory.schur_zassenhaus from "leanprover-community/mathlib"@"d57133e49cf06508700ef69030cd099917e0f0de" /-! # The Schur-Zassenhaus Theorem In this file we prove the Schur-Zassenhaus theorem. ## Main results - `exists_right_complement'_of_coprime`: The **Schur-Zassenhaus** theorem: If `H : Subgroup G` is normal and has order coprime to its index, then there exists a subgroup `K` which is a (right) complement of `H`. - `exists_left_complement'_of_coprime`: The **Schur-Zassenhaus** theorem: If `H : Subgroup G` is normal and has order coprime to its index, then there exists a subgroup `K` which is a (left) complement of `H`. -/ namespace Subgroup section SchurZassenhausAbelian open MulOpposite MulAction Subgroup.leftTransversals MemLeftTransversals variable {G : Type*} [Group G] (H : Subgroup G) [IsCommutative H] [FiniteIndex H] (α β : leftTransversals (H : Set G)) /-- The quotient of the transversals of an abelian normal `N` by the `diff` relation. -/ def QuotientDiff := Quotient (Setoid.mk (fun α β => diff (MonoidHom.id H) α β = 1) ⟨fun α => diff_self (MonoidHom.id H) α, fun h => by rw [← diff_inv, h, inv_one], fun h h' => by rw [← diff_mul_diff, h, h', one_mul]⟩) #align subgroup.quotient_diff Subgroup.QuotientDiff instance : Inhabited H.QuotientDiff := by dsimp [QuotientDiff] -- Porting note: Added `dsimp` infer_instance theorem smul_diff_smul' [hH : Normal H] (g : Gᵐᵒᵖ) : diff (MonoidHom.id H) (g • α) (g • β) = ⟨g.unop⁻¹ * (diff (MonoidHom.id H) α β : H) * g.unop, hH.mem_comm ((congr_arg (· ∈ H) (mul_inv_cancel_left _ _)).mpr (SetLike.coe_mem _))⟩ := by letI := H.fintypeQuotientOfFiniteIndex let ϕ : H →* H := { toFun := fun h => ⟨g.unop⁻¹ * h * g.unop, hH.mem_comm ((congr_arg (· ∈ H) (mul_inv_cancel_left _ _)).mpr (SetLike.coe_mem _))⟩ map_one' := by rw [Subtype.ext_iff, coe_mk, coe_one, mul_one, inv_mul_self] map_mul' := fun h₁ h₂ => by simp only [Subtype.ext_iff, coe_mk, coe_mul, mul_assoc, mul_inv_cancel_left] } refine (Fintype.prod_equiv (MulAction.toPerm g).symm _ _ fun x ↦ ?_).trans (map_prod ϕ _ _).symm simp only [ϕ, smul_apply_eq_smul_apply_inv_smul, smul_eq_mul_unop, mul_inv_rev, mul_assoc, MonoidHom.id_apply, toPerm_symm_apply, MonoidHom.coe_mk, OneHom.coe_mk] #align subgroup.smul_diff_smul' Subgroup.smul_diff_smul' variable {H} [Normal H] noncomputable instance : MulAction G H.QuotientDiff where smul g := Quotient.map' (fun α => op g⁻¹ • α) fun α β h => Subtype.ext (by rwa [smul_diff_smul', coe_mk, coe_one, mul_eq_one_iff_eq_inv, mul_right_eq_self, ← coe_one, ← Subtype.ext_iff]) mul_smul g₁ g₂ q := Quotient.inductionOn' q fun T => congr_arg Quotient.mk'' (by rw [mul_inv_rev]; exact mul_smul (op g₁⁻¹) (op g₂⁻¹) T) one_smul q := Quotient.inductionOn' q fun T => congr_arg Quotient.mk'' (by rw [inv_one]; apply one_smul Gᵐᵒᵖ T) theorem smul_diff' (h : H) : diff (MonoidHom.id H) α (op (h : G) • β) = diff (MonoidHom.id H) α β * h ^ H.index := by letI := H.fintypeQuotientOfFiniteIndex rw [diff, diff, index_eq_card, ← Finset.card_univ, ← Finset.prod_const, ← Finset.prod_mul_distrib] refine Finset.prod_congr rfl fun q _ => ?_ simp_rw [Subtype.ext_iff, MonoidHom.id_apply, coe_mul, mul_assoc, mul_right_inj] rw [smul_apply_eq_smul_apply_inv_smul, smul_eq_mul_unop, MulOpposite.unop_op, mul_left_inj, ← Subtype.ext_iff, Equiv.apply_eq_iff_eq, inv_smul_eq_iff] exact self_eq_mul_right.mpr ((QuotientGroup.eq_one_iff _).mpr h.2) #align subgroup.smul_diff' Subgroup.smul_diff' theorem eq_one_of_smul_eq_one (hH : Nat.Coprime (Nat.card H) H.index) (α : H.QuotientDiff) (h : H) : h • α = α → h = 1 := Quotient.inductionOn' α fun α hα => (powCoprime hH).injective <| calc h ^ H.index = diff (MonoidHom.id H) (op ((h⁻¹ : H) : G) • α) α := by rw [← diff_inv, smul_diff', diff_self, one_mul, inv_pow, inv_inv] _ = 1 ^ H.index := (Quotient.exact' hα).trans (one_pow H.index).symm #align subgroup.eq_one_of_smul_eq_one Subgroup.eq_one_of_smul_eq_one theorem exists_smul_eq (hH : Nat.Coprime (Nat.card H) H.index) (α β : H.QuotientDiff) : ∃ h : H, h • α = β := Quotient.inductionOn' α (Quotient.inductionOn' β fun β α => Exists.imp (fun n => Quotient.sound') ⟨(powCoprime hH).symm (diff (MonoidHom.id H) β α), (diff_inv _ _ _).symm.trans (inv_eq_one.mpr ((smul_diff' β α ((powCoprime hH).symm (diff (MonoidHom.id H) β α))⁻¹).trans (by rw [inv_pow, ← powCoprime_apply hH, Equiv.apply_symm_apply, mul_inv_self])))⟩) #align subgroup.exists_smul_eq Subgroup.exists_smul_eq theorem isComplement'_stabilizer_of_coprime {α : H.QuotientDiff} (hH : Nat.Coprime (Nat.card H) H.index) : IsComplement' H (stabilizer G α) := isComplement'_stabilizer α (eq_one_of_smul_eq_one hH α) fun g => exists_smul_eq hH (g • α) α #align subgroup.is_complement'_stabilizer_of_coprime Subgroup.isComplement'_stabilizer_of_coprime /-- Do not use this lemma: It is made obsolete by `exists_right_complement'_of_coprime` -/ private theorem exists_right_complement'_of_coprime_aux (hH : Nat.Coprime (Nat.card H) H.index) : ∃ K : Subgroup G, IsComplement' H K := have ne : Nonempty (QuotientDiff H) := inferInstance ne.elim fun α => ⟨stabilizer G α, isComplement'_stabilizer_of_coprime hH⟩ end SchurZassenhausAbelian open scoped Classical universe u namespace SchurZassenhausInduction /-! ## Proof of the Schur-Zassenhaus theorem In this section, we prove the Schur-Zassenhaus theorem. The proof is by contradiction. We assume that `G` is a minimal counterexample to the theorem. -/ variable {G : Type u} [Group G] [Fintype G] {N : Subgroup G} [Normal N] (h1 : Nat.Coprime (Fintype.card N) N.index) (h2 : ∀ (G' : Type u) [Group G'] [Fintype G'], Fintype.card G' < Fintype.card G → ∀ {N' : Subgroup G'} [N'.Normal], Nat.Coprime (Fintype.card N') N'.index → ∃ H' : Subgroup G', IsComplement' N' H') (h3 : ∀ H : Subgroup G, ¬IsComplement' N H) /-! We will arrive at a contradiction via the following steps: * step 0: `N` (the normal Hall subgroup) is nontrivial. * step 1: If `K` is a subgroup of `G` with `K ⊔ N = ⊤`, then `K = ⊤`. * step 2: `N` is a minimal normal subgroup, phrased in terms of subgroups of `G`. * step 3: `N` is a minimal normal subgroup, phrased in terms of subgroups of `N`. * step 4: `p` (`min_fact (Fintype.card N)`) is prime (follows from step0). * step 5: `P` (a Sylow `p`-subgroup of `N`) is nontrivial. * step 6: `N` is a `p`-group (applies step 1 to the normalizer of `P` in `G`). * step 7: `N` is abelian (applies step 3 to the center of `N`). -/ /-- Do not use this lemma: It is made obsolete by `exists_right_complement'_of_coprime` -/ private theorem step0 : N ≠ ⊥ := by rintro rfl exact h3 ⊤ isComplement'_bot_top set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532 /-- Do not use this lemma: It is made obsolete by `exists_right_complement'_of_coprime` -/ private theorem step1 (K : Subgroup G) (hK : K ⊔ N = ⊤) : K = ⊤ := by contrapose! h3 have h4 : (N.comap K.subtype).index = N.index := by rw [← N.relindex_top_right, ← hK] exact (relindex_sup_right K N).symm have h5 : Fintype.card K < Fintype.card G := by rw [← K.index_mul_card] exact lt_mul_of_one_lt_left Fintype.card_pos (one_lt_index_of_ne_top h3) have h6 : Nat.Coprime (Fintype.card (N.comap K.subtype)) (N.comap K.subtype).index := by rw [h4] rw [← Nat.card_eq_fintype_card] at h1 ⊢ exact h1.coprime_dvd_left (card_comap_dvd_of_injective N K.subtype Subtype.coe_injective) obtain ⟨H, hH⟩ := h2 K h5 h6 replace hH : Fintype.card (H.map K.subtype) = N.index := by rw [← relindex_bot_left_eq_card, ← relindex_comap, MonoidHom.comap_bot, Subgroup.ker_subtype, relindex_bot_left, ← IsComplement'.index_eq_card (IsComplement'.symm hH), index_comap, subtype_range, ← relindex_sup_right, hK, relindex_top_right] have h7 : Fintype.card N * Fintype.card (H.map K.subtype) = Fintype.card G := by rw [hH, ← N.index_mul_card, mul_comm] have h8 : (Fintype.card N).Coprime (Fintype.card (H.map K.subtype)) := by rwa [hH] exact ⟨H.map K.subtype, isComplement'_of_coprime h7 h8⟩ /-- Do not use this lemma: It is made obsolete by `exists_right_complement'_of_coprime` -/ private theorem step2 (K : Subgroup G) [K.Normal] (hK : K ≤ N) : K = ⊥ ∨ K = N := by have : Function.Surjective (QuotientGroup.mk' K) := Quotient.surjective_Quotient_mk'' have h4 := step1 h1 h2 h3 contrapose! h4 have h5 : Fintype.card (G ⧸ K) < Fintype.card G := by rw [← index_eq_card, ← K.index_mul_card, ← Nat.card_eq_fintype_card] refine lt_mul_of_one_lt_right (Nat.pos_of_ne_zero index_ne_zero_of_finite) (K.one_lt_card_iff_ne_bot.mpr h4.1) have h6 : (Fintype.card (N.map (QuotientGroup.mk' K))).Coprime (N.map (QuotientGroup.mk' K)).index := by have index_map := N.index_map_eq this (by rwa [QuotientGroup.ker_mk']) have index_pos : 0 < N.index := Nat.pos_of_ne_zero index_ne_zero_of_finite rw [index_map] refine h1.coprime_dvd_left ?_ rw [← Nat.mul_dvd_mul_iff_left index_pos, index_mul_card, ← index_map, index_mul_card] simp only [← Nat.card_eq_fintype_card] exact K.card_quotient_dvd_card obtain ⟨H, hH⟩ := h2 (G ⧸ K) h5 h6 refine ⟨H.comap (QuotientGroup.mk' K), ?_, ?_⟩ · have key : (N.map (QuotientGroup.mk' K)).comap (QuotientGroup.mk' K) = N := by refine comap_map_eq_self ?_ rwa [QuotientGroup.ker_mk'] rwa [← key, comap_sup_eq, hH.symm.sup_eq_top, comap_top] · rw [← comap_top (QuotientGroup.mk' K)] intro hH' rw [comap_injective this hH', isComplement'_top_right, map_eq_bot_iff, QuotientGroup.ker_mk'] at hH exact h4.2 (le_antisymm hK hH) /-- Do not use this lemma: It is made obsolete by `exists_right_complement'_of_coprime` -/ private theorem step3 (K : Subgroup N) [(K.map N.subtype).Normal] : K = ⊥ ∨ K = ⊤ := by have key := step2 h1 h2 h3 (K.map N.subtype) (map_subtype_le K) rw [← map_bot N.subtype] at key conv at key => rhs rhs rw [← N.subtype_range, N.subtype.range_eq_map] have inj := map_injective N.subtype_injective rwa [inj.eq_iff, inj.eq_iff] at key /-- Do not use this lemma: It is made obsolete by `exists_right_complement'_of_coprime` -/ private theorem step4 : (Fintype.card N).minFac.Prime := by rw [← Nat.card_eq_fintype_card] exact Nat.minFac_prime (N.one_lt_card_iff_ne_bot.mpr (step0 h1 h3)).ne' /-- Do not use this lemma: It is made obsolete by `exists_right_complement'_of_coprime` -/ private theorem step5 {P : Sylow (Fintype.card N).minFac N} : P.1 ≠ ⊥ := haveI : Fact (Fintype.card N).minFac.Prime := ⟨step4 h1 h3⟩ P.ne_bot_of_dvd_card (Fintype.card N).minFac_dvd /-- Do not use this lemma: It is made obsolete by `exists_right_complement'_of_coprime` -/ private theorem step6 : IsPGroup (Fintype.card N).minFac N := by haveI : Fact (Fintype.card N).minFac.Prime := ⟨step4 h1 h3⟩ refine Sylow.nonempty.elim fun P => P.2.of_surjective P.1.subtype ?_ rw [← MonoidHom.range_top_iff_surjective, subtype_range] haveI : (P.1.map N.subtype).Normal := normalizer_eq_top.mp (step1 h1 h2 h3 (P.1.map N.subtype).normalizer P.normalizer_sup_eq_top) exact (step3 h1 h2 h3 P.1).resolve_left (step5 h1 h3) /-- Do not use this lemma: It is made obsolete by `exists_right_complement'_of_coprime` -/ theorem step7 : IsCommutative N := by haveI := N.bot_or_nontrivial.resolve_left (step0 h1 h3) haveI : Fact (Fintype.card N).minFac.Prime := ⟨step4 h1 h3⟩ exact ⟨⟨fun g h => ((eq_top_iff.mp ((step3 h1 h2 h3 (center N)).resolve_left (step6 h1 h2 h3).bot_lt_center.ne') (mem_top h)).comm g).symm⟩⟩ #align subgroup.schur_zassenhaus_induction.step7 Subgroup.SchurZassenhausInduction.step7 end SchurZassenhausInduction variable {n : ℕ} {G : Type u} [Group G] /-- Do not use this lemma: It is made obsolete by `exists_right_complement'_of_coprime` -/ private theorem exists_right_complement'_of_coprime_aux' [Fintype G] (hG : Fintype.card G = n) {N : Subgroup G} [N.Normal] (hN : Nat.Coprime (Fintype.card N) N.index) : ∃ H : Subgroup G, IsComplement' N H := by revert G apply Nat.strongInductionOn n rintro n ih G _ _ rfl N _ hN refine not_forall_not.mp fun h3 => ?_ haveI := SchurZassenhausInduction.step7 hN (fun G' _ _ hG' => by apply ih _ hG'; rfl) h3 rw [← Nat.card_eq_fintype_card] at hN exact not_exists_of_forall_not h3 (exists_right_complement'_of_coprime_aux hN) /-- **Schur-Zassenhaus** for normal subgroups: If `H : Subgroup G` is normal, and has order coprime to its index, then there exists a subgroup `K` which is a (right) complement of `H`. -/ theorem exists_right_complement'_of_coprime_of_fintype [Fintype G] {N : Subgroup G} [N.Normal] (hN : Nat.Coprime (Fintype.card N) N.index) : ∃ H : Subgroup G, IsComplement' N H := exists_right_complement'_of_coprime_aux' rfl hN #align subgroup.exists_right_complement'_of_coprime_of_fintype Subgroup.exists_right_complement'_of_coprime_of_fintype /-- **Schur-Zassenhaus** for normal subgroups: If `H : Subgroup G` is normal, and has order coprime to its index, then there exists a subgroup `K` which is a (right) complement of `H`. -/
Mathlib/GroupTheory/SchurZassenhaus.lean
287
304
theorem exists_right_complement'_of_coprime {N : Subgroup G} [N.Normal] (hN : Nat.Coprime (Nat.card N) N.index) : ∃ H : Subgroup G, IsComplement' N H := by
by_cases hN1 : Nat.card N = 0 · rw [hN1, Nat.coprime_zero_left, index_eq_one] at hN rw [hN] exact ⟨⊥, isComplement'_top_bot⟩ by_cases hN2 : N.index = 0 · rw [hN2, Nat.coprime_zero_right] at hN haveI := (Cardinal.toNat_eq_one_iff_unique.mp hN).1 rw [N.eq_bot_of_subsingleton] exact ⟨⊤, isComplement'_bot_top⟩ have hN3 : Nat.card G ≠ 0 := by rw [← N.card_mul_index] exact mul_ne_zero hN1 hN2 haveI := (Cardinal.lt_aleph0_iff_fintype.mp (lt_of_not_ge (mt Cardinal.toNat_apply_of_aleph0_le hN3))).some apply exists_right_complement'_of_coprime_of_fintype rwa [← Nat.card_eq_fintype_card]
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen -/ import Mathlib.Data.Matrix.Block import Mathlib.Data.Matrix.Notation import Mathlib.LinearAlgebra.StdBasis import Mathlib.RingTheory.AlgebraTower import Mathlib.Algebra.Algebra.Subalgebra.Tower #align_import linear_algebra.matrix.to_lin from "leanprover-community/mathlib"@"0e2aab2b0d521f060f62a14d2cf2e2c54e8491d6" /-! # Linear maps and matrices This file defines the maps to send matrices to a linear map, and to send linear maps between modules with a finite bases to matrices. This defines a linear equivalence between linear maps between finite-dimensional vector spaces and matrices indexed by the respective bases. ## Main definitions In the list below, and in all this file, `R` is a commutative ring (semiring is sometimes enough), `M` and its variations are `R`-modules, `ι`, `κ`, `n` and `m` are finite types used for indexing. * `LinearMap.toMatrix`: given bases `v₁ : ι → M₁` and `v₂ : κ → M₂`, the `R`-linear equivalence from `M₁ →ₗ[R] M₂` to `Matrix κ ι R` * `Matrix.toLin`: the inverse of `LinearMap.toMatrix` * `LinearMap.toMatrix'`: the `R`-linear equivalence from `(m → R) →ₗ[R] (n → R)` to `Matrix m n R` (with the standard basis on `m → R` and `n → R`) * `Matrix.toLin'`: the inverse of `LinearMap.toMatrix'` * `algEquivMatrix`: given a basis indexed by `n`, the `R`-algebra equivalence between `R`-endomorphisms of `M` and `Matrix n n R` ## Issues This file was originally written without attention to non-commutative rings, and so mostly only works in the commutative setting. This should be fixed. In particular, `Matrix.mulVec` gives us a linear equivalence `Matrix m n R ≃ₗ[R] (n → R) →ₗ[Rᵐᵒᵖ] (m → R)` while `Matrix.vecMul` gives us a linear equivalence `Matrix m n R ≃ₗ[Rᵐᵒᵖ] (m → R) →ₗ[R] (n → R)`. At present, the first equivalence is developed in detail but only for commutative rings (and we omit the distinction between `Rᵐᵒᵖ` and `R`), while the second equivalence is developed only in brief, but for not-necessarily-commutative rings. Naming is slightly inconsistent between the two developments. In the original (commutative) development `linear` is abbreviated to `lin`, although this is not consistent with the rest of mathlib. In the new (non-commutative) development `linear` is not abbreviated, and declarations use `_right` to indicate they use the right action of matrices on vectors (via `Matrix.vecMul`). When the two developments are made uniform, the names should be made uniform, too, by choosing between `linear` and `lin` consistently, and (presumably) adding `_left` where necessary. ## Tags linear_map, matrix, linear_equiv, diagonal, det, trace -/ noncomputable section open LinearMap Matrix Set Submodule section ToMatrixRight variable {R : Type*} [Semiring R] variable {l m n : Type*} /-- `Matrix.vecMul M` is a linear map. -/ def Matrix.vecMulLinear [Fintype m] (M : Matrix m n R) : (m → R) →ₗ[R] n → R where toFun x := x ᵥ* M map_add' _ _ := funext fun _ ↦ add_dotProduct _ _ _ map_smul' _ _ := funext fun _ ↦ smul_dotProduct _ _ _ #align matrix.vec_mul_linear Matrix.vecMulLinear @[simp] theorem Matrix.vecMulLinear_apply [Fintype m] (M : Matrix m n R) (x : m → R) : M.vecMulLinear x = x ᵥ* M := rfl theorem Matrix.coe_vecMulLinear [Fintype m] (M : Matrix m n R) : (M.vecMulLinear : _ → _) = M.vecMul := rfl variable [Fintype m] [DecidableEq m] @[simp] theorem Matrix.vecMul_stdBasis (M : Matrix m n R) (i j) : (LinearMap.stdBasis R (fun _ ↦ R) i 1 ᵥ* M) j = M i j := by have : (∑ i', (if i = i' then 1 else 0) * M i' j) = M i j := by simp_rw [boole_mul, Finset.sum_ite_eq, Finset.mem_univ, if_true] simp only [vecMul, dotProduct] convert this split_ifs with h <;> simp only [stdBasis_apply] · rw [h, Function.update_same] · rw [Function.update_noteq (Ne.symm h), Pi.zero_apply] #align matrix.vec_mul_std_basis Matrix.vecMul_stdBasis theorem range_vecMulLinear (M : Matrix m n R) : LinearMap.range M.vecMulLinear = span R (range M) := by letI := Classical.decEq m simp_rw [range_eq_map, ← iSup_range_stdBasis, Submodule.map_iSup, range_eq_map, ← Ideal.span_singleton_one, Ideal.span, Submodule.map_span, image_image, image_singleton, Matrix.vecMulLinear_apply, iSup_span, range_eq_iUnion, iUnion_singleton_eq_range, LinearMap.stdBasis, coe_single] unfold vecMul simp_rw [single_dotProduct, one_mul] theorem Matrix.vecMul_injective_iff {R : Type*} [CommRing R] {M : Matrix m n R} : Function.Injective M.vecMul ↔ LinearIndependent R (fun i ↦ M i) := by rw [← coe_vecMulLinear] simp only [← LinearMap.ker_eq_bot, Fintype.linearIndependent_iff, Submodule.eq_bot_iff, LinearMap.mem_ker, vecMulLinear_apply] refine ⟨fun h c h0 ↦ congr_fun <| h c ?_, fun h c h0 ↦ funext <| h c ?_⟩ · rw [← h0] ext i simp [vecMul, dotProduct] · rw [← h0] ext j simp [vecMul, dotProduct] /-- Linear maps `(m → R) →ₗ[R] (n → R)` are linearly equivalent over `Rᵐᵒᵖ` to `Matrix m n R`, by having matrices act by right multiplication. -/ def LinearMap.toMatrixRight' : ((m → R) →ₗ[R] n → R) ≃ₗ[Rᵐᵒᵖ] Matrix m n R where toFun f i j := f (stdBasis R (fun _ ↦ R) i 1) j invFun := Matrix.vecMulLinear right_inv M := by ext i j simp only [Matrix.vecMul_stdBasis, Matrix.vecMulLinear_apply] left_inv f := by apply (Pi.basisFun R m).ext intro j; ext i simp only [Pi.basisFun_apply, Matrix.vecMul_stdBasis, Matrix.vecMulLinear_apply] map_add' f g := by ext i j simp only [Pi.add_apply, LinearMap.add_apply, Matrix.add_apply] map_smul' c f := by ext i j simp only [Pi.smul_apply, LinearMap.smul_apply, RingHom.id_apply, Matrix.smul_apply] #align linear_map.to_matrix_right' LinearMap.toMatrixRight' /-- A `Matrix m n R` is linearly equivalent over `Rᵐᵒᵖ` to a linear map `(m → R) →ₗ[R] (n → R)`, by having matrices act by right multiplication. -/ abbrev Matrix.toLinearMapRight' : Matrix m n R ≃ₗ[Rᵐᵒᵖ] (m → R) →ₗ[R] n → R := LinearEquiv.symm LinearMap.toMatrixRight' #align matrix.to_linear_map_right' Matrix.toLinearMapRight' @[simp] theorem Matrix.toLinearMapRight'_apply (M : Matrix m n R) (v : m → R) : (Matrix.toLinearMapRight') M v = v ᵥ* M := rfl #align matrix.to_linear_map_right'_apply Matrix.toLinearMapRight'_apply @[simp] theorem Matrix.toLinearMapRight'_mul [Fintype l] [DecidableEq l] (M : Matrix l m R) (N : Matrix m n R) : Matrix.toLinearMapRight' (M * N) = (Matrix.toLinearMapRight' N).comp (Matrix.toLinearMapRight' M) := LinearMap.ext fun _x ↦ (vecMul_vecMul _ M N).symm #align matrix.to_linear_map_right'_mul Matrix.toLinearMapRight'_mul theorem Matrix.toLinearMapRight'_mul_apply [Fintype l] [DecidableEq l] (M : Matrix l m R) (N : Matrix m n R) (x) : Matrix.toLinearMapRight' (M * N) x = Matrix.toLinearMapRight' N (Matrix.toLinearMapRight' M x) := (vecMul_vecMul _ M N).symm #align matrix.to_linear_map_right'_mul_apply Matrix.toLinearMapRight'_mul_apply @[simp] theorem Matrix.toLinearMapRight'_one : Matrix.toLinearMapRight' (1 : Matrix m m R) = LinearMap.id := by ext simp [LinearMap.one_apply, stdBasis_apply] #align matrix.to_linear_map_right'_one Matrix.toLinearMapRight'_one /-- If `M` and `M'` are each other's inverse matrices, they provide an equivalence between `n → A` and `m → A` corresponding to `M.vecMul` and `M'.vecMul`. -/ @[simps] def Matrix.toLinearEquivRight'OfInv [Fintype n] [DecidableEq n] {M : Matrix m n R} {M' : Matrix n m R} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : (n → R) ≃ₗ[R] m → R := { LinearMap.toMatrixRight'.symm M' with toFun := Matrix.toLinearMapRight' M' invFun := Matrix.toLinearMapRight' M left_inv := fun x ↦ by rw [← Matrix.toLinearMapRight'_mul_apply, hM'M, Matrix.toLinearMapRight'_one, id_apply] right_inv := fun x ↦ by dsimp only -- Porting note: needed due to non-flat structures rw [← Matrix.toLinearMapRight'_mul_apply, hMM', Matrix.toLinearMapRight'_one, id_apply] } #align matrix.to_linear_equiv_right'_of_inv Matrix.toLinearEquivRight'OfInv end ToMatrixRight /-! From this point on, we only work with commutative rings, and fail to distinguish between `Rᵐᵒᵖ` and `R`. This should eventually be remedied. -/ section mulVec variable {R : Type*} [CommSemiring R] variable {k l m n : Type*} /-- `Matrix.mulVec M` is a linear map. -/ def Matrix.mulVecLin [Fintype n] (M : Matrix m n R) : (n → R) →ₗ[R] m → R where toFun := M.mulVec map_add' _ _ := funext fun _ ↦ dotProduct_add _ _ _ map_smul' _ _ := funext fun _ ↦ dotProduct_smul _ _ _ #align matrix.mul_vec_lin Matrix.mulVecLin theorem Matrix.coe_mulVecLin [Fintype n] (M : Matrix m n R) : (M.mulVecLin : _ → _) = M.mulVec := rfl @[simp] theorem Matrix.mulVecLin_apply [Fintype n] (M : Matrix m n R) (v : n → R) : M.mulVecLin v = M *ᵥ v := rfl #align matrix.mul_vec_lin_apply Matrix.mulVecLin_apply @[simp] theorem Matrix.mulVecLin_zero [Fintype n] : Matrix.mulVecLin (0 : Matrix m n R) = 0 := LinearMap.ext zero_mulVec #align matrix.mul_vec_lin_zero Matrix.mulVecLin_zero @[simp] theorem Matrix.mulVecLin_add [Fintype n] (M N : Matrix m n R) : (M + N).mulVecLin = M.mulVecLin + N.mulVecLin := LinearMap.ext fun _ ↦ add_mulVec _ _ _ #align matrix.mul_vec_lin_add Matrix.mulVecLin_add @[simp] theorem Matrix.mulVecLin_transpose [Fintype m] (M : Matrix m n R) : Mᵀ.mulVecLin = M.vecMulLinear := by ext; simp [mulVec_transpose] @[simp] theorem Matrix.vecMulLinear_transpose [Fintype n] (M : Matrix m n R) : Mᵀ.vecMulLinear = M.mulVecLin := by ext; simp [vecMul_transpose] theorem Matrix.mulVecLin_submatrix [Fintype n] [Fintype l] (f₁ : m → k) (e₂ : n ≃ l) (M : Matrix k l R) : (M.submatrix f₁ e₂).mulVecLin = funLeft R R f₁ ∘ₗ M.mulVecLin ∘ₗ funLeft _ _ e₂.symm := LinearMap.ext fun _ ↦ submatrix_mulVec_equiv _ _ _ _ #align matrix.mul_vec_lin_submatrix Matrix.mulVecLin_submatrix /-- A variant of `Matrix.mulVecLin_submatrix` that keeps around `LinearEquiv`s. -/ theorem Matrix.mulVecLin_reindex [Fintype n] [Fintype l] (e₁ : k ≃ m) (e₂ : l ≃ n) (M : Matrix k l R) : (reindex e₁ e₂ M).mulVecLin = ↑(LinearEquiv.funCongrLeft R R e₁.symm) ∘ₗ M.mulVecLin ∘ₗ ↑(LinearEquiv.funCongrLeft R R e₂) := Matrix.mulVecLin_submatrix _ _ _ #align matrix.mul_vec_lin_reindex Matrix.mulVecLin_reindex variable [Fintype n] @[simp] theorem Matrix.mulVecLin_one [DecidableEq n] : Matrix.mulVecLin (1 : Matrix n n R) = LinearMap.id := by ext; simp [Matrix.one_apply, Pi.single_apply] #align matrix.mul_vec_lin_one Matrix.mulVecLin_one @[simp] theorem Matrix.mulVecLin_mul [Fintype m] (M : Matrix l m R) (N : Matrix m n R) : Matrix.mulVecLin (M * N) = (Matrix.mulVecLin M).comp (Matrix.mulVecLin N) := LinearMap.ext fun _ ↦ (mulVec_mulVec _ _ _).symm #align matrix.mul_vec_lin_mul Matrix.mulVecLin_mul theorem Matrix.ker_mulVecLin_eq_bot_iff {M : Matrix m n R} : (LinearMap.ker M.mulVecLin) = ⊥ ↔ ∀ v, M *ᵥ v = 0 → v = 0 := by simp only [Submodule.eq_bot_iff, LinearMap.mem_ker, Matrix.mulVecLin_apply] #align matrix.ker_mul_vec_lin_eq_bot_iff Matrix.ker_mulVecLin_eq_bot_iff theorem Matrix.mulVec_stdBasis [DecidableEq n] (M : Matrix m n R) (i j) : (M *ᵥ LinearMap.stdBasis R (fun _ ↦ R) j 1) i = M i j := (congr_fun (Matrix.mulVec_single _ _ (1 : R)) i).trans <| mul_one _ #align matrix.mul_vec_std_basis Matrix.mulVec_stdBasis @[simp] theorem Matrix.mulVec_stdBasis_apply [DecidableEq n] (M : Matrix m n R) (j) : M *ᵥ LinearMap.stdBasis R (fun _ ↦ R) j 1 = Mᵀ j := funext fun i ↦ Matrix.mulVec_stdBasis M i j #align matrix.mul_vec_std_basis_apply Matrix.mulVec_stdBasis_apply theorem Matrix.range_mulVecLin (M : Matrix m n R) : LinearMap.range M.mulVecLin = span R (range Mᵀ) := by rw [← vecMulLinear_transpose, range_vecMulLinear] #align matrix.range_mul_vec_lin Matrix.range_mulVecLin theorem Matrix.mulVec_injective_iff {R : Type*} [CommRing R] {M : Matrix m n R} : Function.Injective M.mulVec ↔ LinearIndependent R (fun i ↦ Mᵀ i) := by change Function.Injective (fun x ↦ _) ↔ _ simp_rw [← M.vecMul_transpose, vecMul_injective_iff] end mulVec section ToMatrix' variable {R : Type*} [CommSemiring R] variable {k l m n : Type*} [DecidableEq n] [Fintype n] /-- Linear maps `(n → R) →ₗ[R] (m → R)` are linearly equivalent to `Matrix m n R`. -/ def LinearMap.toMatrix' : ((n → R) →ₗ[R] m → R) ≃ₗ[R] Matrix m n R where toFun f := of fun i j ↦ f (stdBasis R (fun _ ↦ R) j 1) i invFun := Matrix.mulVecLin right_inv M := by ext i j simp only [Matrix.mulVec_stdBasis, Matrix.mulVecLin_apply, of_apply] left_inv f := by apply (Pi.basisFun R n).ext intro j; ext i simp only [Pi.basisFun_apply, Matrix.mulVec_stdBasis, Matrix.mulVecLin_apply, of_apply] map_add' f g := by ext i j simp only [Pi.add_apply, LinearMap.add_apply, of_apply, Matrix.add_apply] map_smul' c f := by ext i j simp only [Pi.smul_apply, LinearMap.smul_apply, RingHom.id_apply, of_apply, Matrix.smul_apply] #align linear_map.to_matrix' LinearMap.toMatrix' /-- A `Matrix m n R` is linearly equivalent to a linear map `(n → R) →ₗ[R] (m → R)`. Note that the forward-direction does not require `DecidableEq` and is `Matrix.vecMulLin`. -/ def Matrix.toLin' : Matrix m n R ≃ₗ[R] (n → R) →ₗ[R] m → R := LinearMap.toMatrix'.symm #align matrix.to_lin' Matrix.toLin' theorem Matrix.toLin'_apply' (M : Matrix m n R) : Matrix.toLin' M = M.mulVecLin := rfl #align matrix.to_lin'_apply' Matrix.toLin'_apply' @[simp] theorem LinearMap.toMatrix'_symm : (LinearMap.toMatrix'.symm : Matrix m n R ≃ₗ[R] _) = Matrix.toLin' := rfl #align linear_map.to_matrix'_symm LinearMap.toMatrix'_symm @[simp] theorem Matrix.toLin'_symm : (Matrix.toLin'.symm : ((n → R) →ₗ[R] m → R) ≃ₗ[R] _) = LinearMap.toMatrix' := rfl #align matrix.to_lin'_symm Matrix.toLin'_symm @[simp] theorem LinearMap.toMatrix'_toLin' (M : Matrix m n R) : LinearMap.toMatrix' (Matrix.toLin' M) = M := LinearMap.toMatrix'.apply_symm_apply M #align linear_map.to_matrix'_to_lin' LinearMap.toMatrix'_toLin' @[simp] theorem Matrix.toLin'_toMatrix' (f : (n → R) →ₗ[R] m → R) : Matrix.toLin' (LinearMap.toMatrix' f) = f := Matrix.toLin'.apply_symm_apply f #align matrix.to_lin'_to_matrix' Matrix.toLin'_toMatrix' @[simp] theorem LinearMap.toMatrix'_apply (f : (n → R) →ₗ[R] m → R) (i j) : LinearMap.toMatrix' f i j = f (fun j' ↦ if j' = j then 1 else 0) i := by simp only [LinearMap.toMatrix', LinearEquiv.coe_mk, of_apply] refine congr_fun ?_ _ -- Porting note: `congr` didn't do this congr ext j' split_ifs with h · rw [h, stdBasis_same] apply stdBasis_ne _ _ _ _ h #align linear_map.to_matrix'_apply LinearMap.toMatrix'_apply @[simp] theorem Matrix.toLin'_apply (M : Matrix m n R) (v : n → R) : Matrix.toLin' M v = M *ᵥ v := rfl #align matrix.to_lin'_apply Matrix.toLin'_apply @[simp] theorem Matrix.toLin'_one : Matrix.toLin' (1 : Matrix n n R) = LinearMap.id := Matrix.mulVecLin_one #align matrix.to_lin'_one Matrix.toLin'_one @[simp] theorem LinearMap.toMatrix'_id : LinearMap.toMatrix' (LinearMap.id : (n → R) →ₗ[R] n → R) = 1 := by ext rw [Matrix.one_apply, LinearMap.toMatrix'_apply, id_apply] #align linear_map.to_matrix'_id LinearMap.toMatrix'_id @[simp] theorem LinearMap.toMatrix'_one : LinearMap.toMatrix' (1 : (n → R) →ₗ[R] n → R) = 1 := LinearMap.toMatrix'_id @[simp] theorem Matrix.toLin'_mul [Fintype m] [DecidableEq m] (M : Matrix l m R) (N : Matrix m n R) : Matrix.toLin' (M * N) = (Matrix.toLin' M).comp (Matrix.toLin' N) := Matrix.mulVecLin_mul _ _ #align matrix.to_lin'_mul Matrix.toLin'_mul @[simp] theorem Matrix.toLin'_submatrix [Fintype l] [DecidableEq l] (f₁ : m → k) (e₂ : n ≃ l) (M : Matrix k l R) : Matrix.toLin' (M.submatrix f₁ e₂) = funLeft R R f₁ ∘ₗ (Matrix.toLin' M) ∘ₗ funLeft _ _ e₂.symm := Matrix.mulVecLin_submatrix _ _ _ #align matrix.to_lin'_submatrix Matrix.toLin'_submatrix /-- A variant of `Matrix.toLin'_submatrix` that keeps around `LinearEquiv`s. -/ theorem Matrix.toLin'_reindex [Fintype l] [DecidableEq l] (e₁ : k ≃ m) (e₂ : l ≃ n) (M : Matrix k l R) : Matrix.toLin' (reindex e₁ e₂ M) = ↑(LinearEquiv.funCongrLeft R R e₁.symm) ∘ₗ (Matrix.toLin' M) ∘ₗ ↑(LinearEquiv.funCongrLeft R R e₂) := Matrix.mulVecLin_reindex _ _ _ #align matrix.to_lin'_reindex Matrix.toLin'_reindex /-- Shortcut lemma for `Matrix.toLin'_mul` and `LinearMap.comp_apply` -/ theorem Matrix.toLin'_mul_apply [Fintype m] [DecidableEq m] (M : Matrix l m R) (N : Matrix m n R) (x) : Matrix.toLin' (M * N) x = Matrix.toLin' M (Matrix.toLin' N x) := by rw [Matrix.toLin'_mul, LinearMap.comp_apply] #align matrix.to_lin'_mul_apply Matrix.toLin'_mul_apply theorem LinearMap.toMatrix'_comp [Fintype l] [DecidableEq l] (f : (n → R) →ₗ[R] m → R) (g : (l → R) →ₗ[R] n → R) : LinearMap.toMatrix' (f.comp g) = LinearMap.toMatrix' f * LinearMap.toMatrix' g := by suffices f.comp g = Matrix.toLin' (LinearMap.toMatrix' f * LinearMap.toMatrix' g) by rw [this, LinearMap.toMatrix'_toLin'] rw [Matrix.toLin'_mul, Matrix.toLin'_toMatrix', Matrix.toLin'_toMatrix'] #align linear_map.to_matrix'_comp LinearMap.toMatrix'_comp theorem LinearMap.toMatrix'_mul [Fintype m] [DecidableEq m] (f g : (m → R) →ₗ[R] m → R) : LinearMap.toMatrix' (f * g) = LinearMap.toMatrix' f * LinearMap.toMatrix' g := LinearMap.toMatrix'_comp f g #align linear_map.to_matrix'_mul LinearMap.toMatrix'_mul @[simp] theorem LinearMap.toMatrix'_algebraMap (x : R) : LinearMap.toMatrix' (algebraMap R (Module.End R (n → R)) x) = scalar n x := by simp [Module.algebraMap_end_eq_smul_id, smul_eq_diagonal_mul] #align linear_map.to_matrix'_algebra_map LinearMap.toMatrix'_algebraMap theorem Matrix.ker_toLin'_eq_bot_iff {M : Matrix n n R} : LinearMap.ker (Matrix.toLin' M) = ⊥ ↔ ∀ v, M *ᵥ v = 0 → v = 0 := Matrix.ker_mulVecLin_eq_bot_iff #align matrix.ker_to_lin'_eq_bot_iff Matrix.ker_toLin'_eq_bot_iff theorem Matrix.range_toLin' (M : Matrix m n R) : LinearMap.range (Matrix.toLin' M) = span R (range Mᵀ) := Matrix.range_mulVecLin _ #align matrix.range_to_lin' Matrix.range_toLin' /-- If `M` and `M'` are each other's inverse matrices, they provide an equivalence between `m → A` and `n → A` corresponding to `M.mulVec` and `M'.mulVec`. -/ @[simps] def Matrix.toLin'OfInv [Fintype m] [DecidableEq m] {M : Matrix m n R} {M' : Matrix n m R} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : (m → R) ≃ₗ[R] n → R := { Matrix.toLin' M' with toFun := Matrix.toLin' M' invFun := Matrix.toLin' M left_inv := fun x ↦ by rw [← Matrix.toLin'_mul_apply, hMM', Matrix.toLin'_one, id_apply] right_inv := fun x ↦ by simp only rw [← Matrix.toLin'_mul_apply, hM'M, Matrix.toLin'_one, id_apply] } #align matrix.to_lin'_of_inv Matrix.toLin'OfInv /-- Linear maps `(n → R) →ₗ[R] (n → R)` are algebra equivalent to `Matrix n n R`. -/ def LinearMap.toMatrixAlgEquiv' : ((n → R) →ₗ[R] n → R) ≃ₐ[R] Matrix n n R := AlgEquiv.ofLinearEquiv LinearMap.toMatrix' LinearMap.toMatrix'_one LinearMap.toMatrix'_mul #align linear_map.to_matrix_alg_equiv' LinearMap.toMatrixAlgEquiv' /-- A `Matrix n n R` is algebra equivalent to a linear map `(n → R) →ₗ[R] (n → R)`. -/ def Matrix.toLinAlgEquiv' : Matrix n n R ≃ₐ[R] (n → R) →ₗ[R] n → R := LinearMap.toMatrixAlgEquiv'.symm #align matrix.to_lin_alg_equiv' Matrix.toLinAlgEquiv' @[simp] theorem LinearMap.toMatrixAlgEquiv'_symm : (LinearMap.toMatrixAlgEquiv'.symm : Matrix n n R ≃ₐ[R] _) = Matrix.toLinAlgEquiv' := rfl #align linear_map.to_matrix_alg_equiv'_symm LinearMap.toMatrixAlgEquiv'_symm @[simp] theorem Matrix.toLinAlgEquiv'_symm : (Matrix.toLinAlgEquiv'.symm : ((n → R) →ₗ[R] n → R) ≃ₐ[R] _) = LinearMap.toMatrixAlgEquiv' := rfl #align matrix.to_lin_alg_equiv'_symm Matrix.toLinAlgEquiv'_symm @[simp] theorem LinearMap.toMatrixAlgEquiv'_toLinAlgEquiv' (M : Matrix n n R) : LinearMap.toMatrixAlgEquiv' (Matrix.toLinAlgEquiv' M) = M := LinearMap.toMatrixAlgEquiv'.apply_symm_apply M #align linear_map.to_matrix_alg_equiv'_to_lin_alg_equiv' LinearMap.toMatrixAlgEquiv'_toLinAlgEquiv' @[simp] theorem Matrix.toLinAlgEquiv'_toMatrixAlgEquiv' (f : (n → R) →ₗ[R] n → R) : Matrix.toLinAlgEquiv' (LinearMap.toMatrixAlgEquiv' f) = f := Matrix.toLinAlgEquiv'.apply_symm_apply f #align matrix.to_lin_alg_equiv'_to_matrix_alg_equiv' Matrix.toLinAlgEquiv'_toMatrixAlgEquiv' @[simp] theorem LinearMap.toMatrixAlgEquiv'_apply (f : (n → R) →ₗ[R] n → R) (i j) : LinearMap.toMatrixAlgEquiv' f i j = f (fun j' ↦ if j' = j then 1 else 0) i := by simp [LinearMap.toMatrixAlgEquiv'] #align linear_map.to_matrix_alg_equiv'_apply LinearMap.toMatrixAlgEquiv'_apply @[simp] theorem Matrix.toLinAlgEquiv'_apply (M : Matrix n n R) (v : n → R) : Matrix.toLinAlgEquiv' M v = M *ᵥ v := rfl #align matrix.to_lin_alg_equiv'_apply Matrix.toLinAlgEquiv'_apply -- Porting note: the simpNF linter rejects this, as `simp` already simplifies the lhs -- to `(1 : (n → R) →ₗ[R] n → R)`. -- @[simp] theorem Matrix.toLinAlgEquiv'_one : Matrix.toLinAlgEquiv' (1 : Matrix n n R) = LinearMap.id := Matrix.toLin'_one #align matrix.to_lin_alg_equiv'_one Matrix.toLinAlgEquiv'_one @[simp] theorem LinearMap.toMatrixAlgEquiv'_id : LinearMap.toMatrixAlgEquiv' (LinearMap.id : (n → R) →ₗ[R] n → R) = 1 := LinearMap.toMatrix'_id #align linear_map.to_matrix_alg_equiv'_id LinearMap.toMatrixAlgEquiv'_id #align matrix.to_lin_alg_equiv'_mul map_mulₓ theorem LinearMap.toMatrixAlgEquiv'_comp (f g : (n → R) →ₗ[R] n → R) : LinearMap.toMatrixAlgEquiv' (f.comp g) = LinearMap.toMatrixAlgEquiv' f * LinearMap.toMatrixAlgEquiv' g := LinearMap.toMatrix'_comp _ _ #align linear_map.to_matrix_alg_equiv'_comp LinearMap.toMatrixAlgEquiv'_comp theorem LinearMap.toMatrixAlgEquiv'_mul (f g : (n → R) →ₗ[R] n → R) : LinearMap.toMatrixAlgEquiv' (f * g) = LinearMap.toMatrixAlgEquiv' f * LinearMap.toMatrixAlgEquiv' g := LinearMap.toMatrixAlgEquiv'_comp f g #align linear_map.to_matrix_alg_equiv'_mul LinearMap.toMatrixAlgEquiv'_mul end ToMatrix' section ToMatrix section Finite variable {R : Type*} [CommSemiring R] variable {l m n : Type*} [Fintype n] [Finite m] [DecidableEq n] variable {M₁ M₂ : Type*} [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module R M₂] variable (v₁ : Basis n R M₁) (v₂ : Basis m R M₂) /-- Given bases of two modules `M₁` and `M₂` over a commutative ring `R`, we get a linear equivalence between linear maps `M₁ →ₗ M₂` and matrices over `R` indexed by the bases. -/ def LinearMap.toMatrix : (M₁ →ₗ[R] M₂) ≃ₗ[R] Matrix m n R := LinearEquiv.trans (LinearEquiv.arrowCongr v₁.equivFun v₂.equivFun) LinearMap.toMatrix' #align linear_map.to_matrix LinearMap.toMatrix /-- `LinearMap.toMatrix'` is a particular case of `LinearMap.toMatrix`, for the standard basis `Pi.basisFun R n`. -/ theorem LinearMap.toMatrix_eq_toMatrix' : LinearMap.toMatrix (Pi.basisFun R n) (Pi.basisFun R n) = LinearMap.toMatrix' := rfl #align linear_map.to_matrix_eq_to_matrix' LinearMap.toMatrix_eq_toMatrix' /-- Given bases of two modules `M₁` and `M₂` over a commutative ring `R`, we get a linear equivalence between matrices over `R` indexed by the bases and linear maps `M₁ →ₗ M₂`. -/ def Matrix.toLin : Matrix m n R ≃ₗ[R] M₁ →ₗ[R] M₂ := (LinearMap.toMatrix v₁ v₂).symm #align matrix.to_lin Matrix.toLin /-- `Matrix.toLin'` is a particular case of `Matrix.toLin`, for the standard basis `Pi.basisFun R n`. -/ theorem Matrix.toLin_eq_toLin' : Matrix.toLin (Pi.basisFun R n) (Pi.basisFun R m) = Matrix.toLin' := rfl #align matrix.to_lin_eq_to_lin' Matrix.toLin_eq_toLin' @[simp] theorem LinearMap.toMatrix_symm : (LinearMap.toMatrix v₁ v₂).symm = Matrix.toLin v₁ v₂ := rfl #align linear_map.to_matrix_symm LinearMap.toMatrix_symm @[simp] theorem Matrix.toLin_symm : (Matrix.toLin v₁ v₂).symm = LinearMap.toMatrix v₁ v₂ := rfl #align matrix.to_lin_symm Matrix.toLin_symm @[simp] theorem Matrix.toLin_toMatrix (f : M₁ →ₗ[R] M₂) : Matrix.toLin v₁ v₂ (LinearMap.toMatrix v₁ v₂ f) = f := by rw [← Matrix.toLin_symm, LinearEquiv.apply_symm_apply] #align matrix.to_lin_to_matrix Matrix.toLin_toMatrix @[simp] theorem LinearMap.toMatrix_toLin (M : Matrix m n R) : LinearMap.toMatrix v₁ v₂ (Matrix.toLin v₁ v₂ M) = M := by rw [← Matrix.toLin_symm, LinearEquiv.symm_apply_apply] #align linear_map.to_matrix_to_lin LinearMap.toMatrix_toLin theorem LinearMap.toMatrix_apply (f : M₁ →ₗ[R] M₂) (i : m) (j : n) : LinearMap.toMatrix v₁ v₂ f i j = v₂.repr (f (v₁ j)) i := by rw [LinearMap.toMatrix, LinearEquiv.trans_apply, LinearMap.toMatrix'_apply, LinearEquiv.arrowCongr_apply, Basis.equivFun_symm_apply, Finset.sum_eq_single j, if_pos rfl, one_smul, Basis.equivFun_apply] · intro j' _ hj' rw [if_neg hj', zero_smul] · intro hj have := Finset.mem_univ j contradiction #align linear_map.to_matrix_apply LinearMap.toMatrix_apply theorem LinearMap.toMatrix_transpose_apply (f : M₁ →ₗ[R] M₂) (j : n) : (LinearMap.toMatrix v₁ v₂ f)ᵀ j = v₂.repr (f (v₁ j)) := funext fun i ↦ f.toMatrix_apply _ _ i j #align linear_map.to_matrix_transpose_apply LinearMap.toMatrix_transpose_apply theorem LinearMap.toMatrix_apply' (f : M₁ →ₗ[R] M₂) (i : m) (j : n) : LinearMap.toMatrix v₁ v₂ f i j = v₂.repr (f (v₁ j)) i := LinearMap.toMatrix_apply v₁ v₂ f i j #align linear_map.to_matrix_apply' LinearMap.toMatrix_apply' theorem LinearMap.toMatrix_transpose_apply' (f : M₁ →ₗ[R] M₂) (j : n) : (LinearMap.toMatrix v₁ v₂ f)ᵀ j = v₂.repr (f (v₁ j)) := LinearMap.toMatrix_transpose_apply v₁ v₂ f j #align linear_map.to_matrix_transpose_apply' LinearMap.toMatrix_transpose_apply' /-- This will be a special case of `LinearMap.toMatrix_id_eq_basis_toMatrix`. -/ theorem LinearMap.toMatrix_id : LinearMap.toMatrix v₁ v₁ id = 1 := by ext i j simp [LinearMap.toMatrix_apply, Matrix.one_apply, Finsupp.single_apply, eq_comm] #align linear_map.to_matrix_id LinearMap.toMatrix_id @[simp] theorem LinearMap.toMatrix_one : LinearMap.toMatrix v₁ v₁ 1 = 1 := LinearMap.toMatrix_id v₁ #align linear_map.to_matrix_one LinearMap.toMatrix_one @[simp] theorem Matrix.toLin_one : Matrix.toLin v₁ v₁ 1 = LinearMap.id := by rw [← LinearMap.toMatrix_id v₁, Matrix.toLin_toMatrix] #align matrix.to_lin_one Matrix.toLin_one
Mathlib/LinearAlgebra/Matrix/ToLin.lean
636
640
theorem LinearMap.toMatrix_reindexRange [DecidableEq M₁] (f : M₁ →ₗ[R] M₂) (k : m) (i : n) : LinearMap.toMatrix v₁.reindexRange v₂.reindexRange f ⟨v₂ k, Set.mem_range_self k⟩ ⟨v₁ i, Set.mem_range_self i⟩ = LinearMap.toMatrix v₁ v₂ f k i := by
simp_rw [LinearMap.toMatrix_apply, Basis.reindexRange_self, Basis.reindexRange_repr]
/- 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.Algebra.Tower import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.Regular.Pow import Mathlib.Algebra.MonoidAlgebra.Support import Mathlib.Data.Finsupp.Antidiagonal import Mathlib.Order.SymmDiff import Mathlib.RingTheory.Adjoin.Basic #align_import data.mv_polynomial.basic from "leanprover-community/mathlib"@"c8734e8953e4b439147bd6f75c2163f6d27cdce6" /-! # Multivariate polynomials This file defines polynomial rings over a base ring (or even semiring), with variables from a general type `σ` (which could be infinite). ## Important definitions Let `R` be a commutative ring (or a semiring) and let `σ` be an arbitrary type. This file creates the type `MvPolynomial σ R`, which mathematicians might denote $R[X_i : i \in σ]$. It is the type of multivariate (a.k.a. multivariable) polynomials, with variables corresponding to the terms in `σ`, and coefficients in `R`. ### Notation In the definitions below, we use the following 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` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` ### Definitions * `MvPolynomial σ R` : the type of polynomials with variables of type `σ` and coefficients in the commutative semiring `R` * `monomial s a` : the monomial which mathematically would be denoted `a * X^s` * `C a` : the constant polynomial with value `a` * `X i` : the degree one monomial corresponding to i; mathematically this might be denoted `Xᵢ`. * `coeff s p` : the coefficient of `s` in `p`. * `eval₂ (f : R → S₁) (g : σ → S₁) p` : given a semiring homomorphism from `R` to another semiring `S₁`, and a map `σ → S₁`, evaluates `p` at this valuation, returning a term of type `S₁`. Note that `eval₂` can be made using `eval` and `map` (see below), and it has been suggested that sticking to `eval` and `map` might make the code less brittle. * `eval (g : σ → R) p` : given a map `σ → R`, evaluates `p` at this valuation, returning a term of type `R` * `map (f : R → S₁) p` : returns the multivariate polynomial obtained from `p` by the change of coefficient semiring corresponding to `f` ## Implementation notes Recall that if `Y` has a zero, then `X →₀ Y` is the type of functions from `X` to `Y` with finite support, i.e. such that only finitely many elements of `X` get sent to non-zero terms in `Y`. The definition of `MvPolynomial σ R` is `(σ →₀ ℕ) →₀ R`; here `σ →₀ ℕ` denotes the space of all monomials in the variables, and the function to `R` sends a monomial to its coefficient in the polynomial being represented. ## Tags polynomial, multivariate polynomial, multivariable polynomial -/ noncomputable section open Set Function Finsupp AddMonoidAlgebra open scoped Pointwise universe u v w x variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} /-- Multivariate polynomial, where `σ` is the index set of the variables and `R` is the coefficient ring -/ def MvPolynomial (σ : Type*) (R : Type*) [CommSemiring R] := AddMonoidAlgebra R (σ →₀ ℕ) #align mv_polynomial MvPolynomial namespace MvPolynomial -- Porting note: because of `MvPolynomial.C` and `MvPolynomial.X` this linter throws -- tons of warnings in this file, and it's easier to just disable them globally in the file set_option linter.uppercaseLean3 false variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {n m : σ} {s : σ →₀ ℕ} section CommSemiring section Instances instance decidableEqMvPolynomial [CommSemiring R] [DecidableEq σ] [DecidableEq R] : DecidableEq (MvPolynomial σ R) := Finsupp.instDecidableEq #align mv_polynomial.decidable_eq_mv_polynomial MvPolynomial.decidableEqMvPolynomial instance commSemiring [CommSemiring R] : CommSemiring (MvPolynomial σ R) := AddMonoidAlgebra.commSemiring instance inhabited [CommSemiring R] : Inhabited (MvPolynomial σ R) := ⟨0⟩ instance distribuMulAction [Monoid R] [CommSemiring S₁] [DistribMulAction R S₁] : DistribMulAction R (MvPolynomial σ S₁) := AddMonoidAlgebra.distribMulAction instance smulZeroClass [CommSemiring S₁] [SMulZeroClass R S₁] : SMulZeroClass R (MvPolynomial σ S₁) := AddMonoidAlgebra.smulZeroClass instance faithfulSMul [CommSemiring S₁] [SMulZeroClass R S₁] [FaithfulSMul R S₁] : FaithfulSMul R (MvPolynomial σ S₁) := AddMonoidAlgebra.faithfulSMul instance module [Semiring R] [CommSemiring S₁] [Module R S₁] : Module R (MvPolynomial σ S₁) := AddMonoidAlgebra.module instance isScalarTower [CommSemiring S₂] [SMul R S₁] [SMulZeroClass R S₂] [SMulZeroClass S₁ S₂] [IsScalarTower R S₁ S₂] : IsScalarTower R S₁ (MvPolynomial σ S₂) := AddMonoidAlgebra.isScalarTower instance smulCommClass [CommSemiring S₂] [SMulZeroClass R S₂] [SMulZeroClass S₁ S₂] [SMulCommClass R S₁ S₂] : SMulCommClass R S₁ (MvPolynomial σ S₂) := AddMonoidAlgebra.smulCommClass instance isCentralScalar [CommSemiring S₁] [SMulZeroClass R S₁] [SMulZeroClass Rᵐᵒᵖ S₁] [IsCentralScalar R S₁] : IsCentralScalar R (MvPolynomial σ S₁) := AddMonoidAlgebra.isCentralScalar instance algebra [CommSemiring R] [CommSemiring S₁] [Algebra R S₁] : Algebra R (MvPolynomial σ S₁) := AddMonoidAlgebra.algebra instance isScalarTower_right [CommSemiring S₁] [DistribSMul R S₁] [IsScalarTower R S₁ S₁] : IsScalarTower R (MvPolynomial σ S₁) (MvPolynomial σ S₁) := AddMonoidAlgebra.isScalarTower_self _ #align mv_polynomial.is_scalar_tower_right MvPolynomial.isScalarTower_right instance smulCommClass_right [CommSemiring S₁] [DistribSMul R S₁] [SMulCommClass R S₁ S₁] : SMulCommClass R (MvPolynomial σ S₁) (MvPolynomial σ S₁) := AddMonoidAlgebra.smulCommClass_self _ #align mv_polynomial.smul_comm_class_right MvPolynomial.smulCommClass_right /-- If `R` is a subsingleton, then `MvPolynomial σ R` has a unique element -/ instance unique [CommSemiring R] [Subsingleton R] : Unique (MvPolynomial σ R) := AddMonoidAlgebra.unique #align mv_polynomial.unique MvPolynomial.unique end Instances variable [CommSemiring R] [CommSemiring S₁] {p q : MvPolynomial σ R} /-- `monomial s a` is the monomial with coefficient `a` and exponents given by `s` -/ def monomial (s : σ →₀ ℕ) : R →ₗ[R] MvPolynomial σ R := lsingle s #align mv_polynomial.monomial MvPolynomial.monomial theorem single_eq_monomial (s : σ →₀ ℕ) (a : R) : Finsupp.single s a = monomial s a := rfl #align mv_polynomial.single_eq_monomial MvPolynomial.single_eq_monomial theorem mul_def : p * q = p.sum fun m a => q.sum fun n b => monomial (m + n) (a * b) := AddMonoidAlgebra.mul_def #align mv_polynomial.mul_def MvPolynomial.mul_def /-- `C a` is the constant polynomial with value `a` -/ def C : R →+* MvPolynomial σ R := { singleZeroRingHom with toFun := monomial 0 } #align mv_polynomial.C MvPolynomial.C variable (R σ) @[simp] theorem algebraMap_eq : algebraMap R (MvPolynomial σ R) = C := rfl #align mv_polynomial.algebra_map_eq MvPolynomial.algebraMap_eq variable {R σ} /-- `X n` is the degree `1` monomial $X_n$. -/ def X (n : σ) : MvPolynomial σ R := monomial (Finsupp.single n 1) 1 #align mv_polynomial.X MvPolynomial.X theorem monomial_left_injective {r : R} (hr : r ≠ 0) : Function.Injective fun s : σ →₀ ℕ => monomial s r := Finsupp.single_left_injective hr #align mv_polynomial.monomial_left_injective MvPolynomial.monomial_left_injective @[simp] theorem monomial_left_inj {s t : σ →₀ ℕ} {r : R} (hr : r ≠ 0) : monomial s r = monomial t r ↔ s = t := Finsupp.single_left_inj hr #align mv_polynomial.monomial_left_inj MvPolynomial.monomial_left_inj theorem C_apply : (C a : MvPolynomial σ R) = monomial 0 a := rfl #align mv_polynomial.C_apply MvPolynomial.C_apply -- Porting note (#10618): `simp` can prove this theorem C_0 : C 0 = (0 : MvPolynomial σ R) := map_zero _ #align mv_polynomial.C_0 MvPolynomial.C_0 -- Porting note (#10618): `simp` can prove this theorem C_1 : C 1 = (1 : MvPolynomial σ R) := rfl #align mv_polynomial.C_1 MvPolynomial.C_1 theorem C_mul_monomial : C a * monomial s a' = monomial s (a * a') := by -- Porting note: this `show` feels like defeq abuse, but I can't find the appropriate lemmas show AddMonoidAlgebra.single _ _ * AddMonoidAlgebra.single _ _ = AddMonoidAlgebra.single _ _ simp [C_apply, single_mul_single] #align mv_polynomial.C_mul_monomial MvPolynomial.C_mul_monomial -- Porting note (#10618): `simp` can prove this theorem C_add : (C (a + a') : MvPolynomial σ R) = C a + C a' := Finsupp.single_add _ _ _ #align mv_polynomial.C_add MvPolynomial.C_add -- Porting note (#10618): `simp` can prove this theorem C_mul : (C (a * a') : MvPolynomial σ R) = C a * C a' := C_mul_monomial.symm #align mv_polynomial.C_mul MvPolynomial.C_mul -- Porting note (#10618): `simp` can prove this theorem C_pow (a : R) (n : ℕ) : (C (a ^ n) : MvPolynomial σ R) = C a ^ n := map_pow _ _ _ #align mv_polynomial.C_pow MvPolynomial.C_pow theorem C_injective (σ : Type*) (R : Type*) [CommSemiring R] : Function.Injective (C : R → MvPolynomial σ R) := Finsupp.single_injective _ #align mv_polynomial.C_injective MvPolynomial.C_injective theorem C_surjective {R : Type*} [CommSemiring R] (σ : Type*) [IsEmpty σ] : Function.Surjective (C : R → MvPolynomial σ R) := by refine fun p => ⟨p.toFun 0, Finsupp.ext fun a => ?_⟩ simp only [C_apply, ← single_eq_monomial, (Finsupp.ext isEmptyElim (α := σ) : a = 0), single_eq_same] rfl #align mv_polynomial.C_surjective MvPolynomial.C_surjective @[simp] theorem C_inj {σ : Type*} (R : Type*) [CommSemiring R] (r s : R) : (C r : MvPolynomial σ R) = C s ↔ r = s := (C_injective σ R).eq_iff #align mv_polynomial.C_inj MvPolynomial.C_inj instance nontrivial_of_nontrivial (σ : Type*) (R : Type*) [CommSemiring R] [Nontrivial R] : Nontrivial (MvPolynomial σ R) := inferInstanceAs (Nontrivial <| AddMonoidAlgebra R (σ →₀ ℕ)) instance infinite_of_infinite (σ : Type*) (R : Type*) [CommSemiring R] [Infinite R] : Infinite (MvPolynomial σ R) := Infinite.of_injective C (C_injective _ _) #align mv_polynomial.infinite_of_infinite MvPolynomial.infinite_of_infinite instance infinite_of_nonempty (σ : Type*) (R : Type*) [Nonempty σ] [CommSemiring R] [Nontrivial R] : Infinite (MvPolynomial σ R) := Infinite.of_injective ((fun s : σ →₀ ℕ => monomial s 1) ∘ Finsupp.single (Classical.arbitrary σ)) <| (monomial_left_injective one_ne_zero).comp (Finsupp.single_injective _) #align mv_polynomial.infinite_of_nonempty MvPolynomial.infinite_of_nonempty theorem C_eq_coe_nat (n : ℕ) : (C ↑n : MvPolynomial σ R) = n := by induction n <;> simp [Nat.succ_eq_add_one, *] #align mv_polynomial.C_eq_coe_nat MvPolynomial.C_eq_coe_nat theorem C_mul' : MvPolynomial.C a * p = a • p := (Algebra.smul_def a p).symm #align mv_polynomial.C_mul' MvPolynomial.C_mul' theorem smul_eq_C_mul (p : MvPolynomial σ R) (a : R) : a • p = C a * p := C_mul'.symm #align mv_polynomial.smul_eq_C_mul MvPolynomial.smul_eq_C_mul theorem C_eq_smul_one : (C a : MvPolynomial σ R) = a • (1 : MvPolynomial σ R) := by rw [← C_mul', mul_one] #align mv_polynomial.C_eq_smul_one MvPolynomial.C_eq_smul_one theorem smul_monomial {S₁ : Type*} [SMulZeroClass S₁ R] (r : S₁) : r • monomial s a = monomial s (r • a) := Finsupp.smul_single _ _ _ #align mv_polynomial.smul_monomial MvPolynomial.smul_monomial theorem X_injective [Nontrivial R] : Function.Injective (X : σ → MvPolynomial σ R) := (monomial_left_injective one_ne_zero).comp (Finsupp.single_left_injective one_ne_zero) #align mv_polynomial.X_injective MvPolynomial.X_injective @[simp] theorem X_inj [Nontrivial R] (m n : σ) : X m = (X n : MvPolynomial σ R) ↔ m = n := X_injective.eq_iff #align mv_polynomial.X_inj MvPolynomial.X_inj theorem monomial_pow : monomial s a ^ e = monomial (e • s) (a ^ e) := AddMonoidAlgebra.single_pow e #align mv_polynomial.monomial_pow MvPolynomial.monomial_pow @[simp] theorem monomial_mul {s s' : σ →₀ ℕ} {a b : R} : monomial s a * monomial s' b = monomial (s + s') (a * b) := AddMonoidAlgebra.single_mul_single #align mv_polynomial.monomial_mul MvPolynomial.monomial_mul variable (σ R) /-- `fun s ↦ monomial s 1` as a homomorphism. -/ def monomialOneHom : Multiplicative (σ →₀ ℕ) →* MvPolynomial σ R := AddMonoidAlgebra.of _ _ #align mv_polynomial.monomial_one_hom MvPolynomial.monomialOneHom variable {σ R} @[simp] theorem monomialOneHom_apply : monomialOneHom R σ s = (monomial s 1 : MvPolynomial σ R) := rfl #align mv_polynomial.monomial_one_hom_apply MvPolynomial.monomialOneHom_apply theorem X_pow_eq_monomial : X n ^ e = monomial (Finsupp.single n e) (1 : R) := by simp [X, monomial_pow] #align mv_polynomial.X_pow_eq_monomial MvPolynomial.X_pow_eq_monomial theorem monomial_add_single : monomial (s + Finsupp.single n e) a = monomial s a * X n ^ e := by rw [X_pow_eq_monomial, monomial_mul, mul_one] #align mv_polynomial.monomial_add_single MvPolynomial.monomial_add_single theorem monomial_single_add : monomial (Finsupp.single n e + s) a = X n ^ e * monomial s a := by rw [X_pow_eq_monomial, monomial_mul, one_mul] #align mv_polynomial.monomial_single_add MvPolynomial.monomial_single_add theorem C_mul_X_pow_eq_monomial {s : σ} {a : R} {n : ℕ} : C a * X s ^ n = monomial (Finsupp.single s n) a := by rw [← zero_add (Finsupp.single s n), monomial_add_single, C_apply] #align mv_polynomial.C_mul_X_pow_eq_monomial MvPolynomial.C_mul_X_pow_eq_monomial theorem C_mul_X_eq_monomial {s : σ} {a : R} : C a * X s = monomial (Finsupp.single s 1) a := by rw [← C_mul_X_pow_eq_monomial, pow_one] #align mv_polynomial.C_mul_X_eq_monomial MvPolynomial.C_mul_X_eq_monomial -- Porting note (#10618): `simp` can prove this theorem monomial_zero {s : σ →₀ ℕ} : monomial s (0 : R) = 0 := Finsupp.single_zero _ #align mv_polynomial.monomial_zero MvPolynomial.monomial_zero @[simp] theorem monomial_zero' : (monomial (0 : σ →₀ ℕ) : R → MvPolynomial σ R) = C := rfl #align mv_polynomial.monomial_zero' MvPolynomial.monomial_zero' @[simp] theorem monomial_eq_zero {s : σ →₀ ℕ} {b : R} : monomial s b = 0 ↔ b = 0 := Finsupp.single_eq_zero #align mv_polynomial.monomial_eq_zero MvPolynomial.monomial_eq_zero @[simp] theorem sum_monomial_eq {A : Type*} [AddCommMonoid A] {u : σ →₀ ℕ} {r : R} {b : (σ →₀ ℕ) → R → A} (w : b u 0 = 0) : sum (monomial u r) b = b u r := Finsupp.sum_single_index w #align mv_polynomial.sum_monomial_eq MvPolynomial.sum_monomial_eq @[simp] theorem sum_C {A : Type*} [AddCommMonoid A] {b : (σ →₀ ℕ) → R → A} (w : b 0 0 = 0) : sum (C a) b = b 0 a := sum_monomial_eq w #align mv_polynomial.sum_C MvPolynomial.sum_C theorem monomial_sum_one {α : Type*} (s : Finset α) (f : α → σ →₀ ℕ) : (monomial (∑ i ∈ s, f i) 1 : MvPolynomial σ R) = ∏ i ∈ s, monomial (f i) 1 := map_prod (monomialOneHom R σ) (fun i => Multiplicative.ofAdd (f i)) s #align mv_polynomial.monomial_sum_one MvPolynomial.monomial_sum_one theorem monomial_sum_index {α : Type*} (s : Finset α) (f : α → σ →₀ ℕ) (a : R) : monomial (∑ i ∈ s, f i) a = C a * ∏ i ∈ s, monomial (f i) 1 := by rw [← monomial_sum_one, C_mul', ← (monomial _).map_smul, smul_eq_mul, mul_one] #align mv_polynomial.monomial_sum_index MvPolynomial.monomial_sum_index theorem monomial_finsupp_sum_index {α β : Type*} [Zero β] (f : α →₀ β) (g : α → β → σ →₀ ℕ) (a : R) : monomial (f.sum g) a = C a * f.prod fun a b => monomial (g a b) 1 := monomial_sum_index _ _ _ #align mv_polynomial.monomial_finsupp_sum_index MvPolynomial.monomial_finsupp_sum_index theorem monomial_eq_monomial_iff {α : Type*} (a₁ a₂ : α →₀ ℕ) (b₁ b₂ : R) : monomial a₁ b₁ = monomial a₂ b₂ ↔ a₁ = a₂ ∧ b₁ = b₂ ∨ b₁ = 0 ∧ b₂ = 0 := Finsupp.single_eq_single_iff _ _ _ _ #align mv_polynomial.monomial_eq_monomial_iff MvPolynomial.monomial_eq_monomial_iff theorem monomial_eq : monomial s a = C a * (s.prod fun n e => X n ^ e : MvPolynomial σ R) := by simp only [X_pow_eq_monomial, ← monomial_finsupp_sum_index, Finsupp.sum_single] #align mv_polynomial.monomial_eq MvPolynomial.monomial_eq @[simp] lemma prod_X_pow_eq_monomial : ∏ x ∈ s.support, X x ^ s x = monomial s (1 : R) := by simp only [monomial_eq, map_one, one_mul, Finsupp.prod] theorem induction_on_monomial {M : MvPolynomial σ R → Prop} (h_C : ∀ a, M (C a)) (h_X : ∀ p n, M p → M (p * X n)) : ∀ s a, M (monomial s a) := by intro s a apply @Finsupp.induction σ ℕ _ _ s · show M (monomial 0 a) exact h_C a · intro n e p _hpn _he ih have : ∀ e : ℕ, M (monomial p a * X n ^ e) := by intro e induction e with | zero => simp [ih] | succ e e_ih => simp [ih, pow_succ, (mul_assoc _ _ _).symm, h_X, e_ih] simp [add_comm, monomial_add_single, this] #align mv_polynomial.induction_on_monomial MvPolynomial.induction_on_monomial /-- Analog of `Polynomial.induction_on'`. To prove something about mv_polynomials, it suffices to show the condition is closed under taking sums, and it holds for monomials. -/ @[elab_as_elim] theorem induction_on' {P : MvPolynomial σ R → Prop} (p : MvPolynomial σ R) (h1 : ∀ (u : σ →₀ ℕ) (a : R), P (monomial u a)) (h2 : ∀ p q : MvPolynomial σ R, P p → P q → P (p + q)) : P p := Finsupp.induction p (suffices P (monomial 0 0) by rwa [monomial_zero] at this show P (monomial 0 0) from h1 0 0) fun a b f _ha _hb hPf => h2 _ _ (h1 _ _) hPf #align mv_polynomial.induction_on' MvPolynomial.induction_on' /-- Similar to `MvPolynomial.induction_on` but only a weak form of `h_add` is required. -/ theorem induction_on''' {M : MvPolynomial σ R → Prop} (p : MvPolynomial σ R) (h_C : ∀ a, M (C a)) (h_add_weak : ∀ (a : σ →₀ ℕ) (b : R) (f : (σ →₀ ℕ) →₀ R), a ∉ f.support → b ≠ 0 → M f → M ((show (σ →₀ ℕ) →₀ R from monomial a b) + f)) : M p := -- Porting note: I had to add the `show ... from ...` above, a type ascription was insufficient. Finsupp.induction p (C_0.rec <| h_C 0) h_add_weak #align mv_polynomial.induction_on''' MvPolynomial.induction_on''' /-- Similar to `MvPolynomial.induction_on` but only a yet weaker form of `h_add` is required. -/ theorem induction_on'' {M : MvPolynomial σ R → Prop} (p : MvPolynomial σ R) (h_C : ∀ a, M (C a)) (h_add_weak : ∀ (a : σ →₀ ℕ) (b : R) (f : (σ →₀ ℕ) →₀ R), a ∉ f.support → b ≠ 0 → M f → M (monomial a b) → M ((show (σ →₀ ℕ) →₀ R from monomial a b) + f)) (h_X : ∀ (p : MvPolynomial σ R) (n : σ), M p → M (p * MvPolynomial.X n)) : M p := -- Porting note: I had to add the `show ... from ...` above, a type ascription was insufficient. induction_on''' p h_C fun a b f ha hb hf => h_add_weak a b f ha hb hf <| induction_on_monomial h_C h_X a b #align mv_polynomial.induction_on'' MvPolynomial.induction_on'' /-- Analog of `Polynomial.induction_on`. -/ @[recursor 5] theorem induction_on {M : MvPolynomial σ R → Prop} (p : MvPolynomial σ R) (h_C : ∀ a, M (C a)) (h_add : ∀ p q, M p → M q → M (p + q)) (h_X : ∀ p n, M p → M (p * X n)) : M p := induction_on'' p h_C (fun a b f _ha _hb hf hm => h_add (monomial a b) f hm hf) h_X #align mv_polynomial.induction_on MvPolynomial.induction_on theorem ringHom_ext {A : Type*} [Semiring A] {f g : MvPolynomial σ R →+* A} (hC : ∀ r, f (C r) = g (C r)) (hX : ∀ i, f (X i) = g (X i)) : f = g := by refine AddMonoidAlgebra.ringHom_ext' ?_ ?_ -- Porting note: this has high priority, but Lean still chooses `RingHom.ext`, why? -- probably because of the type synonym · ext x exact hC _ · apply Finsupp.mulHom_ext'; intros x -- Porting note: `Finsupp.mulHom_ext'` needs to have increased priority apply MonoidHom.ext_mnat exact hX _ #align mv_polynomial.ring_hom_ext MvPolynomial.ringHom_ext /-- See note [partially-applied ext lemmas]. -/ @[ext 1100] theorem ringHom_ext' {A : Type*} [Semiring A] {f g : MvPolynomial σ R →+* A} (hC : f.comp C = g.comp C) (hX : ∀ i, f (X i) = g (X i)) : f = g := ringHom_ext (RingHom.ext_iff.1 hC) hX #align mv_polynomial.ring_hom_ext' MvPolynomial.ringHom_ext' theorem hom_eq_hom [Semiring S₂] (f g : MvPolynomial σ R →+* S₂) (hC : f.comp C = g.comp C) (hX : ∀ n : σ, f (X n) = g (X n)) (p : MvPolynomial σ R) : f p = g p := RingHom.congr_fun (ringHom_ext' hC hX) p #align mv_polynomial.hom_eq_hom MvPolynomial.hom_eq_hom theorem is_id (f : MvPolynomial σ R →+* MvPolynomial σ R) (hC : f.comp C = C) (hX : ∀ n : σ, f (X n) = X n) (p : MvPolynomial σ R) : f p = p := hom_eq_hom f (RingHom.id _) hC hX p #align mv_polynomial.is_id MvPolynomial.is_id @[ext 1100] theorem algHom_ext' {A B : Type*} [CommSemiring A] [CommSemiring B] [Algebra R A] [Algebra R B] {f g : MvPolynomial σ A →ₐ[R] B} (h₁ : f.comp (IsScalarTower.toAlgHom R A (MvPolynomial σ A)) = g.comp (IsScalarTower.toAlgHom R A (MvPolynomial σ A))) (h₂ : ∀ i, f (X i) = g (X i)) : f = g := AlgHom.coe_ringHom_injective (MvPolynomial.ringHom_ext' (congr_arg AlgHom.toRingHom h₁) h₂) #align mv_polynomial.alg_hom_ext' MvPolynomial.algHom_ext' @[ext 1200] theorem algHom_ext {A : Type*} [Semiring A] [Algebra R A] {f g : MvPolynomial σ R →ₐ[R] A} (hf : ∀ i : σ, f (X i) = g (X i)) : f = g := AddMonoidAlgebra.algHom_ext' (mulHom_ext' fun X : σ => MonoidHom.ext_mnat (hf X)) #align mv_polynomial.alg_hom_ext MvPolynomial.algHom_ext @[simp] theorem algHom_C {τ : Type*} (f : MvPolynomial σ R →ₐ[R] MvPolynomial τ R) (r : R) : f (C r) = C r := f.commutes r #align mv_polynomial.alg_hom_C MvPolynomial.algHom_C @[simp] theorem adjoin_range_X : Algebra.adjoin R (range (X : σ → MvPolynomial σ R)) = ⊤ := by set S := Algebra.adjoin R (range (X : σ → MvPolynomial σ R)) refine top_unique fun p hp => ?_; clear hp induction p using MvPolynomial.induction_on with | h_C => exact S.algebraMap_mem _ | h_add p q hp hq => exact S.add_mem hp hq | h_X p i hp => exact S.mul_mem hp (Algebra.subset_adjoin <| mem_range_self _) #align mv_polynomial.adjoin_range_X MvPolynomial.adjoin_range_X @[ext] theorem linearMap_ext {M : Type*} [AddCommMonoid M] [Module R M] {f g : MvPolynomial σ R →ₗ[R] M} (h : ∀ s, f ∘ₗ monomial s = g ∘ₗ monomial s) : f = g := Finsupp.lhom_ext' h #align mv_polynomial.linear_map_ext MvPolynomial.linearMap_ext section Support /-- The finite set of all `m : σ →₀ ℕ` such that `X^m` has a non-zero coefficient. -/ def support (p : MvPolynomial σ R) : Finset (σ →₀ ℕ) := Finsupp.support p #align mv_polynomial.support MvPolynomial.support theorem finsupp_support_eq_support (p : MvPolynomial σ R) : Finsupp.support p = p.support := rfl #align mv_polynomial.finsupp_support_eq_support MvPolynomial.finsupp_support_eq_support
Mathlib/Algebra/MvPolynomial/Basic.lean
539
542
theorem support_monomial [h : Decidable (a = 0)] : (monomial s a).support = if a = 0 then ∅ else {s} := by
rw [← Subsingleton.elim (Classical.decEq R a 0) h] rfl
/- 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, Simon Hudon, Mario Carneiro -/ import Aesop import Mathlib.Algebra.Group.Defs import Mathlib.Data.Nat.Defs import Mathlib.Data.Int.Defs import Mathlib.Logic.Function.Basic import Mathlib.Tactic.Cases import Mathlib.Tactic.SimpRw import Mathlib.Tactic.SplitIfs #align_import algebra.group.basic from "leanprover-community/mathlib"@"a07d750983b94c530ab69a726862c2ab6802b38c" /-! # Basic lemmas about semigroups, monoids, and groups This file lists various basic lemmas about semigroups, monoids, and groups. Most proofs are one-liners from the corresponding axioms. For the definitions of semigroups, monoids and groups, see `Algebra/Group/Defs.lean`. -/ assert_not_exists MonoidWithZero assert_not_exists DenselyOrdered open Function universe u variable {α β G M : Type*} section ite variable [Pow α β] @[to_additive (attr := simp) dite_smul] lemma pow_dite (p : Prop) [Decidable p] (a : α) (b : p → β) (c : ¬ p → β) : a ^ (if h : p then b h else c h) = if h : p then a ^ b h else a ^ c h := by split_ifs <;> rfl @[to_additive (attr := simp) smul_dite] lemma dite_pow (p : Prop) [Decidable p] (a : p → α) (b : ¬ p → α) (c : β) : (if h : p then a h else b h) ^ c = if h : p then a h ^ c else b h ^ c := by split_ifs <;> rfl @[to_additive (attr := simp) ite_smul] lemma pow_ite (p : Prop) [Decidable p] (a : α) (b c : β) : a ^ (if p then b else c) = if p then a ^ b else a ^ c := pow_dite _ _ _ _ @[to_additive (attr := simp) smul_ite] lemma ite_pow (p : Prop) [Decidable p] (a b : α) (c : β) : (if p then a else b) ^ c = if p then a ^ c else b ^ c := dite_pow _ _ _ _ set_option linter.existingAttributeWarning false in attribute [to_additive (attr := simp)] dite_smul smul_dite ite_smul smul_ite end ite section IsLeftCancelMul variable [Mul G] [IsLeftCancelMul G] @[to_additive] theorem mul_right_injective (a : G) : Injective (a * ·) := fun _ _ ↦ mul_left_cancel #align mul_right_injective mul_right_injective #align add_right_injective add_right_injective @[to_additive (attr := simp)] theorem mul_right_inj (a : G) {b c : G} : a * b = a * c ↔ b = c := (mul_right_injective a).eq_iff #align mul_right_inj mul_right_inj #align add_right_inj add_right_inj @[to_additive] theorem mul_ne_mul_right (a : G) {b c : G} : a * b ≠ a * c ↔ b ≠ c := (mul_right_injective a).ne_iff #align mul_ne_mul_right mul_ne_mul_right #align add_ne_add_right add_ne_add_right end IsLeftCancelMul section IsRightCancelMul variable [Mul G] [IsRightCancelMul G] @[to_additive] theorem mul_left_injective (a : G) : Function.Injective (· * a) := fun _ _ ↦ mul_right_cancel #align mul_left_injective mul_left_injective #align add_left_injective add_left_injective @[to_additive (attr := simp)] theorem mul_left_inj (a : G) {b c : G} : b * a = c * a ↔ b = c := (mul_left_injective a).eq_iff #align mul_left_inj mul_left_inj #align add_left_inj add_left_inj @[to_additive] theorem mul_ne_mul_left (a : G) {b c : G} : b * a ≠ c * a ↔ b ≠ c := (mul_left_injective a).ne_iff #align mul_ne_mul_left mul_ne_mul_left #align add_ne_add_left add_ne_add_left end IsRightCancelMul section Semigroup variable [Semigroup α] @[to_additive] instance Semigroup.to_isAssociative : Std.Associative (α := α) (· * ·) := ⟨mul_assoc⟩ #align semigroup.to_is_associative Semigroup.to_isAssociative #align add_semigroup.to_is_associative AddSemigroup.to_isAssociative /-- Composing two multiplications on the left by `y` then `x` is equal to a multiplication on the left by `x * y`. -/ @[to_additive (attr := simp) "Composing two additions on the left by `y` then `x` is equal to an addition on the left by `x + y`."] theorem comp_mul_left (x y : α) : (x * ·) ∘ (y * ·) = (x * y * ·) := by ext z simp [mul_assoc] #align comp_mul_left comp_mul_left #align comp_add_left comp_add_left /-- Composing two multiplications on the right by `y` and `x` is equal to a multiplication on the right by `y * x`. -/ @[to_additive (attr := simp) "Composing two additions on the right by `y` and `x` is equal to an addition on the right by `y + x`."] theorem comp_mul_right (x y : α) : (· * x) ∘ (· * y) = (· * (y * x)) := by ext z simp [mul_assoc] #align comp_mul_right comp_mul_right #align comp_add_right comp_add_right end Semigroup @[to_additive] instance CommMagma.to_isCommutative [CommMagma G] : Std.Commutative (α := G) (· * ·) := ⟨mul_comm⟩ #align comm_semigroup.to_is_commutative CommMagma.to_isCommutative #align add_comm_semigroup.to_is_commutative AddCommMagma.to_isCommutative section MulOneClass variable {M : Type u} [MulOneClass M] @[to_additive] theorem ite_mul_one {P : Prop} [Decidable P] {a b : M} : ite P (a * b) 1 = ite P a 1 * ite P b 1 := by by_cases h:P <;> simp [h] #align ite_mul_one ite_mul_one #align ite_add_zero ite_add_zero @[to_additive] theorem ite_one_mul {P : Prop} [Decidable P] {a b : M} : ite P 1 (a * b) = ite P 1 a * ite P 1 b := by by_cases h:P <;> simp [h] #align ite_one_mul ite_one_mul #align ite_zero_add ite_zero_add @[to_additive] theorem eq_one_iff_eq_one_of_mul_eq_one {a b : M} (h : a * b = 1) : a = 1 ↔ b = 1 := by constructor <;> (rintro rfl; simpa using h) #align eq_one_iff_eq_one_of_mul_eq_one eq_one_iff_eq_one_of_mul_eq_one #align eq_zero_iff_eq_zero_of_add_eq_zero eq_zero_iff_eq_zero_of_add_eq_zero @[to_additive] theorem one_mul_eq_id : ((1 : M) * ·) = id := funext one_mul #align one_mul_eq_id one_mul_eq_id #align zero_add_eq_id zero_add_eq_id @[to_additive] theorem mul_one_eq_id : (· * (1 : M)) = id := funext mul_one #align mul_one_eq_id mul_one_eq_id #align add_zero_eq_id add_zero_eq_id end MulOneClass section CommSemigroup variable [CommSemigroup G] @[to_additive] theorem mul_left_comm : ∀ a b c : G, a * (b * c) = b * (a * c) := left_comm Mul.mul mul_comm mul_assoc #align mul_left_comm mul_left_comm #align add_left_comm add_left_comm @[to_additive] theorem mul_right_comm : ∀ a b c : G, a * b * c = a * c * b := right_comm Mul.mul mul_comm mul_assoc #align mul_right_comm mul_right_comm #align add_right_comm add_right_comm @[to_additive] theorem mul_mul_mul_comm (a b c d : G) : a * b * (c * d) = a * c * (b * d) := by simp only [mul_left_comm, mul_assoc] #align mul_mul_mul_comm mul_mul_mul_comm #align add_add_add_comm add_add_add_comm @[to_additive] theorem mul_rotate (a b c : G) : a * b * c = b * c * a := by simp only [mul_left_comm, mul_comm] #align mul_rotate mul_rotate #align add_rotate add_rotate @[to_additive] theorem mul_rotate' (a b c : G) : a * (b * c) = b * (c * a) := by simp only [mul_left_comm, mul_comm] #align mul_rotate' mul_rotate' #align add_rotate' add_rotate' end CommSemigroup section AddCommSemigroup set_option linter.deprecated false variable {M : Type u} [AddCommSemigroup M] theorem bit0_add (a b : M) : bit0 (a + b) = bit0 a + bit0 b := add_add_add_comm _ _ _ _ #align bit0_add bit0_add theorem bit1_add [One M] (a b : M) : bit1 (a + b) = bit0 a + bit1 b := (congr_arg (· + (1 : M)) <| bit0_add a b : _).trans (add_assoc _ _ _) #align bit1_add bit1_add theorem bit1_add' [One M] (a b : M) : bit1 (a + b) = bit1 a + bit0 b := by rw [add_comm, bit1_add, add_comm] #align bit1_add' bit1_add' end AddCommSemigroup section AddMonoid set_option linter.deprecated false variable {M : Type u} [AddMonoid M] {a b c : M} @[simp] theorem bit0_zero : bit0 (0 : M) = 0 := add_zero _ #align bit0_zero bit0_zero @[simp] theorem bit1_zero [One M] : bit1 (0 : M) = 1 := by rw [bit1, bit0_zero, zero_add] #align bit1_zero bit1_zero end AddMonoid attribute [local simp] mul_assoc sub_eq_add_neg section Monoid variable [Monoid M] {a b c : M} {m n : ℕ} @[to_additive boole_nsmul] lemma pow_boole (P : Prop) [Decidable P] (a : M) : (a ^ if P then 1 else 0) = if P then a else 1 := by simp only [pow_ite, pow_one, pow_zero] #align pow_boole pow_boole @[to_additive nsmul_add_sub_nsmul] lemma pow_mul_pow_sub (a : M) (h : m ≤ n) : a ^ m * a ^ (n - m) = a ^ n := by rw [← pow_add, Nat.add_comm, Nat.sub_add_cancel h] #align pow_mul_pow_sub pow_mul_pow_sub #align nsmul_add_sub_nsmul nsmul_add_sub_nsmul @[to_additive sub_nsmul_nsmul_add] lemma pow_sub_mul_pow (a : M) (h : m ≤ n) : a ^ (n - m) * a ^ m = a ^ n := by rw [← pow_add, Nat.sub_add_cancel h] #align pow_sub_mul_pow pow_sub_mul_pow #align sub_nsmul_nsmul_add sub_nsmul_nsmul_add @[to_additive sub_one_nsmul_add] lemma mul_pow_sub_one (hn : n ≠ 0) (a : M) : a * a ^ (n - 1) = a ^ n := by rw [← pow_succ', Nat.sub_add_cancel $ Nat.one_le_iff_ne_zero.2 hn] @[to_additive add_sub_one_nsmul] lemma pow_sub_one_mul (hn : n ≠ 0) (a : M) : a ^ (n - 1) * a = a ^ n := by rw [← pow_succ, Nat.sub_add_cancel $ Nat.one_le_iff_ne_zero.2 hn] /-- If `x ^ n = 1`, then `x ^ m` is the same as `x ^ (m % n)` -/ @[to_additive nsmul_eq_mod_nsmul "If `n • x = 0`, then `m • x` is the same as `(m % n) • x`"] lemma pow_eq_pow_mod (m : ℕ) (ha : a ^ n = 1) : a ^ m = a ^ (m % n) := by calc a ^ m = a ^ (m % n + n * (m / n)) := by rw [Nat.mod_add_div] _ = a ^ (m % n) := by simp [pow_add, pow_mul, ha] #align pow_eq_pow_mod pow_eq_pow_mod #align nsmul_eq_mod_nsmul nsmul_eq_mod_nsmul @[to_additive] lemma pow_mul_pow_eq_one : ∀ n, a * b = 1 → a ^ n * b ^ n = 1 | 0, _ => by simp | n + 1, h => calc a ^ n.succ * b ^ n.succ = a ^ n * a * (b * b ^ n) := by rw [pow_succ, pow_succ'] _ = a ^ n * (a * b) * b ^ n := by simp only [mul_assoc] _ = 1 := by simp [h, pow_mul_pow_eq_one] #align pow_mul_pow_eq_one pow_mul_pow_eq_one #align nsmul_add_nsmul_eq_zero nsmul_add_nsmul_eq_zero end Monoid section CommMonoid variable [CommMonoid M] {x y z : M} @[to_additive] theorem inv_unique (hy : x * y = 1) (hz : x * z = 1) : y = z := left_inv_eq_right_inv (Trans.trans (mul_comm _ _) hy) hz #align inv_unique inv_unique #align neg_unique neg_unique @[to_additive nsmul_add] lemma mul_pow (a b : M) : ∀ n, (a * b) ^ n = a ^ n * b ^ n | 0 => by rw [pow_zero, pow_zero, pow_zero, one_mul] | n + 1 => by rw [pow_succ', pow_succ', pow_succ', mul_pow, mul_mul_mul_comm] #align mul_pow mul_pow #align nsmul_add nsmul_add end CommMonoid section LeftCancelMonoid variable {M : Type u} [LeftCancelMonoid M] {a b : M} @[to_additive (attr := simp)] theorem mul_right_eq_self : a * b = a ↔ b = 1 := calc a * b = a ↔ a * b = a * 1 := by rw [mul_one] _ ↔ b = 1 := mul_left_cancel_iff #align mul_right_eq_self mul_right_eq_self #align add_right_eq_self add_right_eq_self @[to_additive (attr := simp)] theorem self_eq_mul_right : a = a * b ↔ b = 1 := eq_comm.trans mul_right_eq_self #align self_eq_mul_right self_eq_mul_right #align self_eq_add_right self_eq_add_right @[to_additive] theorem mul_right_ne_self : a * b ≠ a ↔ b ≠ 1 := mul_right_eq_self.not #align mul_right_ne_self mul_right_ne_self #align add_right_ne_self add_right_ne_self @[to_additive] theorem self_ne_mul_right : a ≠ a * b ↔ b ≠ 1 := self_eq_mul_right.not #align self_ne_mul_right self_ne_mul_right #align self_ne_add_right self_ne_add_right end LeftCancelMonoid section RightCancelMonoid variable {M : Type u} [RightCancelMonoid M] {a b : M} @[to_additive (attr := simp)] theorem mul_left_eq_self : a * b = b ↔ a = 1 := calc a * b = b ↔ a * b = 1 * b := by rw [one_mul] _ ↔ a = 1 := mul_right_cancel_iff #align mul_left_eq_self mul_left_eq_self #align add_left_eq_self add_left_eq_self @[to_additive (attr := simp)] theorem self_eq_mul_left : b = a * b ↔ a = 1 := eq_comm.trans mul_left_eq_self #align self_eq_mul_left self_eq_mul_left #align self_eq_add_left self_eq_add_left @[to_additive] theorem mul_left_ne_self : a * b ≠ b ↔ a ≠ 1 := mul_left_eq_self.not #align mul_left_ne_self mul_left_ne_self #align add_left_ne_self add_left_ne_self @[to_additive] theorem self_ne_mul_left : b ≠ a * b ↔ a ≠ 1 := self_eq_mul_left.not #align self_ne_mul_left self_ne_mul_left #align self_ne_add_left self_ne_add_left end RightCancelMonoid section CancelCommMonoid variable [CancelCommMonoid α] {a b c d : α} @[to_additive] lemma eq_iff_eq_of_mul_eq_mul (h : a * b = c * d) : a = c ↔ b = d := by aesop @[to_additive] lemma ne_iff_ne_of_mul_eq_mul (h : a * b = c * d) : a ≠ c ↔ b ≠ d := by aesop end CancelCommMonoid section InvolutiveInv variable [InvolutiveInv G] {a b : G} @[to_additive (attr := simp)] theorem inv_involutive : Function.Involutive (Inv.inv : G → G) := inv_inv #align inv_involutive inv_involutive #align neg_involutive neg_involutive @[to_additive (attr := simp)] theorem inv_surjective : Function.Surjective (Inv.inv : G → G) := inv_involutive.surjective #align inv_surjective inv_surjective #align neg_surjective neg_surjective @[to_additive] theorem inv_injective : Function.Injective (Inv.inv : G → G) := inv_involutive.injective #align inv_injective inv_injective #align neg_injective neg_injective @[to_additive (attr := simp)] theorem inv_inj : a⁻¹ = b⁻¹ ↔ a = b := inv_injective.eq_iff #align inv_inj inv_inj #align neg_inj neg_inj @[to_additive] theorem inv_eq_iff_eq_inv : a⁻¹ = b ↔ a = b⁻¹ := ⟨fun h => h ▸ (inv_inv a).symm, fun h => h.symm ▸ inv_inv b⟩ #align inv_eq_iff_eq_inv inv_eq_iff_eq_inv #align neg_eq_iff_eq_neg neg_eq_iff_eq_neg variable (G) @[to_additive] theorem inv_comp_inv : Inv.inv ∘ Inv.inv = @id G := inv_involutive.comp_self #align inv_comp_inv inv_comp_inv #align neg_comp_neg neg_comp_neg @[to_additive] theorem leftInverse_inv : LeftInverse (fun a : G ↦ a⁻¹) fun a ↦ a⁻¹ := inv_inv #align left_inverse_inv leftInverse_inv #align left_inverse_neg leftInverse_neg @[to_additive] theorem rightInverse_inv : RightInverse (fun a : G ↦ a⁻¹) fun a ↦ a⁻¹ := inv_inv #align right_inverse_inv rightInverse_inv #align right_inverse_neg rightInverse_neg end InvolutiveInv section DivInvMonoid variable [DivInvMonoid G] {a b c : G} @[to_additive, field_simps] -- The attributes are out of order on purpose theorem inv_eq_one_div (x : G) : x⁻¹ = 1 / x := by rw [div_eq_mul_inv, one_mul] #align inv_eq_one_div inv_eq_one_div #align neg_eq_zero_sub neg_eq_zero_sub @[to_additive] theorem mul_one_div (x y : G) : x * (1 / y) = x / y := by rw [div_eq_mul_inv, one_mul, div_eq_mul_inv] #align mul_one_div mul_one_div #align add_zero_sub add_zero_sub @[to_additive] theorem mul_div_assoc (a b c : G) : a * b / c = a * (b / c) := by rw [div_eq_mul_inv, div_eq_mul_inv, mul_assoc _ _ _] #align mul_div_assoc mul_div_assoc #align add_sub_assoc add_sub_assoc @[to_additive, field_simps] -- The attributes are out of order on purpose theorem mul_div_assoc' (a b c : G) : a * (b / c) = a * b / c := (mul_div_assoc _ _ _).symm #align mul_div_assoc' mul_div_assoc' #align add_sub_assoc' add_sub_assoc' @[to_additive (attr := simp)] theorem one_div (a : G) : 1 / a = a⁻¹ := (inv_eq_one_div a).symm #align one_div one_div #align zero_sub zero_sub @[to_additive] theorem mul_div (a b c : G) : a * (b / c) = a * b / c := by simp only [mul_assoc, div_eq_mul_inv] #align mul_div mul_div #align add_sub add_sub @[to_additive] theorem div_eq_mul_one_div (a b : G) : a / b = a * (1 / b) := by rw [div_eq_mul_inv, one_div] #align div_eq_mul_one_div div_eq_mul_one_div #align sub_eq_add_zero_sub sub_eq_add_zero_sub end DivInvMonoid section DivInvOneMonoid variable [DivInvOneMonoid G] @[to_additive (attr := simp)] theorem div_one (a : G) : a / 1 = a := by simp [div_eq_mul_inv] #align div_one div_one #align sub_zero sub_zero @[to_additive] theorem one_div_one : (1 : G) / 1 = 1 := div_one _ #align one_div_one one_div_one #align zero_sub_zero zero_sub_zero end DivInvOneMonoid section DivisionMonoid variable [DivisionMonoid α] {a b c d : α} attribute [local simp] mul_assoc div_eq_mul_inv @[to_additive] theorem eq_inv_of_mul_eq_one_right (h : a * b = 1) : b = a⁻¹ := (inv_eq_of_mul_eq_one_right h).symm #align eq_inv_of_mul_eq_one_right eq_inv_of_mul_eq_one_right #align eq_neg_of_add_eq_zero_right eq_neg_of_add_eq_zero_right @[to_additive] theorem eq_one_div_of_mul_eq_one_left (h : b * a = 1) : b = 1 / a := by rw [eq_inv_of_mul_eq_one_left h, one_div] #align eq_one_div_of_mul_eq_one_left eq_one_div_of_mul_eq_one_left #align eq_zero_sub_of_add_eq_zero_left eq_zero_sub_of_add_eq_zero_left @[to_additive] theorem eq_one_div_of_mul_eq_one_right (h : a * b = 1) : b = 1 / a := by rw [eq_inv_of_mul_eq_one_right h, one_div] #align eq_one_div_of_mul_eq_one_right eq_one_div_of_mul_eq_one_right #align eq_zero_sub_of_add_eq_zero_right eq_zero_sub_of_add_eq_zero_right @[to_additive] theorem eq_of_div_eq_one (h : a / b = 1) : a = b := inv_injective <| inv_eq_of_mul_eq_one_right <| by rwa [← div_eq_mul_inv] #align eq_of_div_eq_one eq_of_div_eq_one #align eq_of_sub_eq_zero eq_of_sub_eq_zero lemma eq_of_inv_mul_eq_one (h : a⁻¹ * b = 1) : a = b := by simpa using eq_inv_of_mul_eq_one_left h lemma eq_of_mul_inv_eq_one (h : a * b⁻¹ = 1) : a = b := by simpa using eq_inv_of_mul_eq_one_left h @[to_additive] theorem div_ne_one_of_ne : a ≠ b → a / b ≠ 1 := mt eq_of_div_eq_one #align div_ne_one_of_ne div_ne_one_of_ne #align sub_ne_zero_of_ne sub_ne_zero_of_ne variable (a b c) @[to_additive] theorem one_div_mul_one_div_rev : 1 / a * (1 / b) = 1 / (b * a) := by simp #align one_div_mul_one_div_rev one_div_mul_one_div_rev #align zero_sub_add_zero_sub_rev zero_sub_add_zero_sub_rev @[to_additive] theorem inv_div_left : a⁻¹ / b = (b * a)⁻¹ := by simp #align inv_div_left inv_div_left #align neg_sub_left neg_sub_left @[to_additive (attr := simp)] theorem inv_div : (a / b)⁻¹ = b / a := by simp #align inv_div inv_div #align neg_sub neg_sub @[to_additive] theorem one_div_div : 1 / (a / b) = b / a := by simp #align one_div_div one_div_div #align zero_sub_sub zero_sub_sub @[to_additive] theorem one_div_one_div : 1 / (1 / a) = a := by simp #align one_div_one_div one_div_one_div #align zero_sub_zero_sub zero_sub_zero_sub @[to_additive] theorem div_eq_div_iff_comm : a / b = c / d ↔ b / a = d / c := inv_inj.symm.trans <| by simp only [inv_div] @[to_additive SubtractionMonoid.toSubNegZeroMonoid] instance (priority := 100) DivisionMonoid.toDivInvOneMonoid : DivInvOneMonoid α := { DivisionMonoid.toDivInvMonoid with inv_one := by simpa only [one_div, inv_inv] using (inv_div (1 : α) 1).symm } @[to_additive (attr := simp)] lemma inv_pow (a : α) : ∀ n : ℕ, a⁻¹ ^ n = (a ^ n)⁻¹ | 0 => by rw [pow_zero, pow_zero, inv_one] | n + 1 => by rw [pow_succ', pow_succ, inv_pow _ n, mul_inv_rev] #align inv_pow inv_pow #align neg_nsmul neg_nsmul -- the attributes are intentionally out of order. `smul_zero` proves `zsmul_zero`. @[to_additive zsmul_zero, simp] lemma one_zpow : ∀ n : ℤ, (1 : α) ^ n = 1 | (n : ℕ) => by rw [zpow_natCast, one_pow] | .negSucc n => by rw [zpow_negSucc, one_pow, inv_one] #align one_zpow one_zpow #align zsmul_zero zsmul_zero @[to_additive (attr := simp) neg_zsmul] lemma zpow_neg (a : α) : ∀ n : ℤ, a ^ (-n) = (a ^ n)⁻¹ | (n + 1 : ℕ) => DivInvMonoid.zpow_neg' _ _ | 0 => by change a ^ (0 : ℤ) = (a ^ (0 : ℤ))⁻¹ simp | Int.negSucc n => by rw [zpow_negSucc, inv_inv, ← zpow_natCast] rfl #align zpow_neg zpow_neg #align neg_zsmul neg_zsmul @[to_additive neg_one_zsmul_add] lemma mul_zpow_neg_one (a b : α) : (a * b) ^ (-1 : ℤ) = b ^ (-1 : ℤ) * a ^ (-1 : ℤ) := by simp only [zpow_neg, zpow_one, mul_inv_rev] #align mul_zpow_neg_one mul_zpow_neg_one #align neg_one_zsmul_add neg_one_zsmul_add @[to_additive zsmul_neg] lemma inv_zpow (a : α) : ∀ n : ℤ, a⁻¹ ^ n = (a ^ n)⁻¹ | (n : ℕ) => by rw [zpow_natCast, zpow_natCast, inv_pow] | .negSucc n => by rw [zpow_negSucc, zpow_negSucc, inv_pow] #align inv_zpow inv_zpow #align zsmul_neg zsmul_neg @[to_additive (attr := simp) zsmul_neg'] lemma inv_zpow' (a : α) (n : ℤ) : a⁻¹ ^ n = a ^ (-n) := by rw [inv_zpow, zpow_neg] #align inv_zpow' inv_zpow' #align zsmul_neg' zsmul_neg' @[to_additive nsmul_zero_sub] lemma one_div_pow (a : α) (n : ℕ) : (1 / a) ^ n = 1 / a ^ n := by simp only [one_div, inv_pow] #align one_div_pow one_div_pow #align nsmul_zero_sub nsmul_zero_sub @[to_additive zsmul_zero_sub] lemma one_div_zpow (a : α) (n : ℤ) : (1 / a) ^ n = 1 / a ^ n := by simp only [one_div, inv_zpow] #align one_div_zpow one_div_zpow #align zsmul_zero_sub zsmul_zero_sub variable {a b c} @[to_additive (attr := simp)] theorem inv_eq_one : a⁻¹ = 1 ↔ a = 1 := inv_injective.eq_iff' inv_one #align inv_eq_one inv_eq_one #align neg_eq_zero neg_eq_zero @[to_additive (attr := simp)] theorem one_eq_inv : 1 = a⁻¹ ↔ a = 1 := eq_comm.trans inv_eq_one #align one_eq_inv one_eq_inv #align zero_eq_neg zero_eq_neg @[to_additive] theorem inv_ne_one : a⁻¹ ≠ 1 ↔ a ≠ 1 := inv_eq_one.not #align inv_ne_one inv_ne_one #align neg_ne_zero neg_ne_zero @[to_additive] theorem eq_of_one_div_eq_one_div (h : 1 / a = 1 / b) : a = b := by rw [← one_div_one_div a, h, one_div_one_div] #align eq_of_one_div_eq_one_div eq_of_one_div_eq_one_div #align eq_of_zero_sub_eq_zero_sub eq_of_zero_sub_eq_zero_sub -- Note that `mul_zsmul` and `zpow_mul` have the primes swapped -- when additivised since their argument order, -- and therefore the more "natural" choice of lemma, is reversed. @[to_additive mul_zsmul'] lemma zpow_mul (a : α) : ∀ m n : ℤ, a ^ (m * n) = (a ^ m) ^ n | (m : ℕ), (n : ℕ) => by rw [zpow_natCast, zpow_natCast, ← pow_mul, ← zpow_natCast] rfl | (m : ℕ), .negSucc n => by rw [zpow_natCast, zpow_negSucc, ← pow_mul, Int.ofNat_mul_negSucc, zpow_neg, inv_inj, ← zpow_natCast] | .negSucc m, (n : ℕ) => by rw [zpow_natCast, zpow_negSucc, ← inv_pow, ← pow_mul, Int.negSucc_mul_ofNat, zpow_neg, inv_pow, inv_inj, ← zpow_natCast] | .negSucc m, .negSucc n => by rw [zpow_negSucc, zpow_negSucc, Int.negSucc_mul_negSucc, inv_pow, inv_inv, ← pow_mul, ← zpow_natCast] rfl #align zpow_mul zpow_mul #align mul_zsmul' mul_zsmul' @[to_additive mul_zsmul] lemma zpow_mul' (a : α) (m n : ℤ) : a ^ (m * n) = (a ^ n) ^ m := by rw [Int.mul_comm, zpow_mul] #align zpow_mul' zpow_mul' #align mul_zsmul mul_zsmul #noalign zpow_bit0 #noalign bit0_zsmul #noalign zpow_bit0' #noalign bit0_zsmul' #noalign zpow_bit1 #noalign bit1_zsmul variable (a b c) @[to_additive, field_simps] -- The attributes are out of order on purpose theorem div_div_eq_mul_div : a / (b / c) = a * c / b := by simp #align div_div_eq_mul_div div_div_eq_mul_div #align sub_sub_eq_add_sub sub_sub_eq_add_sub @[to_additive (attr := simp)] theorem div_inv_eq_mul : a / b⁻¹ = a * b := by simp #align div_inv_eq_mul div_inv_eq_mul #align sub_neg_eq_add sub_neg_eq_add @[to_additive] theorem div_mul_eq_div_div_swap : a / (b * c) = a / c / b := by simp only [mul_assoc, mul_inv_rev, div_eq_mul_inv] #align div_mul_eq_div_div_swap div_mul_eq_div_div_swap #align sub_add_eq_sub_sub_swap sub_add_eq_sub_sub_swap end DivisionMonoid section SubtractionMonoid set_option linter.deprecated false lemma bit0_neg [SubtractionMonoid α] (a : α) : bit0 (-a) = -bit0 a := (neg_add_rev _ _).symm #align bit0_neg bit0_neg end SubtractionMonoid section DivisionCommMonoid variable [DivisionCommMonoid α] (a b c d : α) attribute [local simp] mul_assoc mul_comm mul_left_comm div_eq_mul_inv @[to_additive neg_add] theorem mul_inv : (a * b)⁻¹ = a⁻¹ * b⁻¹ := by simp #align mul_inv mul_inv #align neg_add neg_add @[to_additive] theorem inv_div' : (a / b)⁻¹ = a⁻¹ / b⁻¹ := by simp #align inv_div' inv_div' #align neg_sub' neg_sub' @[to_additive] theorem div_eq_inv_mul : a / b = b⁻¹ * a := by simp #align div_eq_inv_mul div_eq_inv_mul #align sub_eq_neg_add sub_eq_neg_add @[to_additive] theorem inv_mul_eq_div : a⁻¹ * b = b / a := by simp #align inv_mul_eq_div inv_mul_eq_div #align neg_add_eq_sub neg_add_eq_sub @[to_additive] theorem inv_mul' : (a * b)⁻¹ = a⁻¹ / b := by simp #align inv_mul' inv_mul' #align neg_add' neg_add' @[to_additive] theorem inv_div_inv : a⁻¹ / b⁻¹ = b / a := by simp #align inv_div_inv inv_div_inv #align neg_sub_neg neg_sub_neg @[to_additive] theorem inv_inv_div_inv : (a⁻¹ / b⁻¹)⁻¹ = a / b := by simp #align inv_inv_div_inv inv_inv_div_inv #align neg_neg_sub_neg neg_neg_sub_neg @[to_additive] theorem one_div_mul_one_div : 1 / a * (1 / b) = 1 / (a * b) := by simp #align one_div_mul_one_div one_div_mul_one_div #align zero_sub_add_zero_sub zero_sub_add_zero_sub @[to_additive] theorem div_right_comm : a / b / c = a / c / b := by simp #align div_right_comm div_right_comm #align sub_right_comm sub_right_comm @[to_additive, field_simps] theorem div_div : a / b / c = a / (b * c) := by simp #align div_div div_div #align sub_sub sub_sub @[to_additive] theorem div_mul : a / b * c = a / (b / c) := by simp #align div_mul div_mul #align sub_add sub_add @[to_additive] theorem mul_div_left_comm : a * (b / c) = b * (a / c) := by simp #align mul_div_left_comm mul_div_left_comm #align add_sub_left_comm add_sub_left_comm @[to_additive] theorem mul_div_right_comm : a * b / c = a / c * b := by simp #align mul_div_right_comm mul_div_right_comm #align add_sub_right_comm add_sub_right_comm @[to_additive] theorem div_mul_eq_div_div : a / (b * c) = a / b / c := by simp #align div_mul_eq_div_div div_mul_eq_div_div #align sub_add_eq_sub_sub sub_add_eq_sub_sub @[to_additive, field_simps]
Mathlib/Algebra/Group/Basic.lean
796
796
theorem div_mul_eq_mul_div : a / b * c = a * c / b := by
simp
/- Copyright (c) 2018 Guy Leroy. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sangwoo Jo (aka Jason), Guy Leroy, Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.Group.Commute.Units import Mathlib.Algebra.Group.Int import Mathlib.Algebra.GroupWithZero.Semiconj import Mathlib.Data.Nat.GCD.Basic import Mathlib.Order.Bounds.Basic #align_import data.int.gcd from "leanprover-community/mathlib"@"47a1a73351de8dd6c8d3d32b569c8e434b03ca47" /-! # Extended GCD and divisibility over ℤ ## Main definitions * Given `x y : ℕ`, `xgcd x y` computes the pair of integers `(a, b)` such that `gcd x y = x * a + y * b`. `gcdA x y` and `gcdB x y` are defined to be `a` and `b`, respectively. ## Main statements * `gcd_eq_gcd_ab`: Bézout's lemma, given `x y : ℕ`, `gcd x y = x * gcdA x y + y * gcdB x y`. ## Tags Bézout's lemma, Bezout's lemma -/ /-! ### Extended Euclidean algorithm -/ namespace Nat /-- Helper function for the extended GCD algorithm (`Nat.xgcd`). -/ def xgcdAux : ℕ → ℤ → ℤ → ℕ → ℤ → ℤ → ℕ × ℤ × ℤ | 0, _, _, r', s', t' => (r', s', t') | succ k, s, t, r', s', t' => let q := r' / succ k xgcdAux (r' % succ k) (s' - q * s) (t' - q * t) (succ k) s t termination_by k => k decreasing_by exact mod_lt _ <| (succ_pos _).gt #align nat.xgcd_aux Nat.xgcdAux @[simp] theorem xgcd_zero_left {s t r' s' t'} : xgcdAux 0 s t r' s' t' = (r', s', t') := by simp [xgcdAux] #align nat.xgcd_zero_left Nat.xgcd_zero_left theorem xgcdAux_rec {r s t r' s' t'} (h : 0 < r) : xgcdAux r s t r' s' t' = xgcdAux (r' % r) (s' - r' / r * s) (t' - r' / r * t) r s t := by obtain ⟨r, rfl⟩ := Nat.exists_eq_succ_of_ne_zero h.ne' simp [xgcdAux] #align nat.xgcd_aux_rec Nat.xgcdAux_rec /-- Use the extended GCD algorithm to generate the `a` and `b` values satisfying `gcd x y = x * a + y * b`. -/ def xgcd (x y : ℕ) : ℤ × ℤ := (xgcdAux x 1 0 y 0 1).2 #align nat.xgcd Nat.xgcd /-- The extended GCD `a` value in the equation `gcd x y = x * a + y * b`. -/ def gcdA (x y : ℕ) : ℤ := (xgcd x y).1 #align nat.gcd_a Nat.gcdA /-- The extended GCD `b` value in the equation `gcd x y = x * a + y * b`. -/ def gcdB (x y : ℕ) : ℤ := (xgcd x y).2 #align nat.gcd_b Nat.gcdB @[simp] theorem gcdA_zero_left {s : ℕ} : gcdA 0 s = 0 := by unfold gcdA rw [xgcd, xgcd_zero_left] #align nat.gcd_a_zero_left Nat.gcdA_zero_left @[simp]
Mathlib/Data/Int/GCD.lean
80
82
theorem gcdB_zero_left {s : ℕ} : gcdB 0 s = 1 := by
unfold gcdB rw [xgcd, xgcd_zero_left]
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.NumberTheory.Zsqrtd.Basic import Mathlib.RingTheory.PrincipalIdealDomain import Mathlib.Data.Complex.Basic import Mathlib.Data.Real.Archimedean #align_import number_theory.zsqrtd.gaussian_int from "leanprover-community/mathlib"@"5b2fe80501ff327b9109fb09b7cc8c325cd0d7d9" /-! # Gaussian integers The Gaussian integers are complex integer, complex numbers whose real and imaginary parts are both integers. ## Main definitions The Euclidean domain structure on `ℤ[i]` is defined in this file. The homomorphism `GaussianInt.toComplex` into the complex numbers is also defined in this file. ## See also See `NumberTheory.Zsqrtd.QuadraticReciprocity` for: * `prime_iff_mod_four_eq_three_of_nat_prime`: A prime natural number is prime in `ℤ[i]` if and only if it is `3` mod `4` ## Notations This file uses the local notation `ℤ[i]` for `GaussianInt` ## Implementation notes Gaussian integers are implemented using the more general definition `Zsqrtd`, the type of integers adjoined a square root of `d`, in this case `-1`. The definition is reducible, so that properties and definitions about `Zsqrtd` can easily be used. -/ open Zsqrtd Complex open scoped ComplexConjugate /-- The Gaussian integers, defined as `ℤ√(-1)`. -/ abbrev GaussianInt : Type := Zsqrtd (-1) #align gaussian_int GaussianInt local notation "ℤ[i]" => GaussianInt namespace GaussianInt instance : Repr ℤ[i] := ⟨fun x _ => "⟨" ++ repr x.re ++ ", " ++ repr x.im ++ "⟩"⟩ instance instCommRing : CommRing ℤ[i] := Zsqrtd.commRing #align gaussian_int.comm_ring GaussianInt.instCommRing section attribute [-instance] Complex.instField -- Avoid making things noncomputable unnecessarily. /-- The embedding of the Gaussian integers into the complex numbers, as a ring homomorphism. -/ def toComplex : ℤ[i] →+* ℂ := Zsqrtd.lift ⟨I, by simp⟩ #align gaussian_int.to_complex GaussianInt.toComplex end instance : Coe ℤ[i] ℂ := ⟨toComplex⟩ theorem toComplex_def (x : ℤ[i]) : (x : ℂ) = x.re + x.im * I := rfl #align gaussian_int.to_complex_def GaussianInt.toComplex_def theorem toComplex_def' (x y : ℤ) : ((⟨x, y⟩ : ℤ[i]) : ℂ) = x + y * I := by simp [toComplex_def] #align gaussian_int.to_complex_def' GaussianInt.toComplex_def' theorem toComplex_def₂ (x : ℤ[i]) : (x : ℂ) = ⟨x.re, x.im⟩ := by apply Complex.ext <;> simp [toComplex_def] #align gaussian_int.to_complex_def₂ GaussianInt.toComplex_def₂ @[simp] theorem to_real_re (x : ℤ[i]) : ((x.re : ℤ) : ℝ) = (x : ℂ).re := by simp [toComplex_def] #align gaussian_int.to_real_re GaussianInt.to_real_re @[simp] theorem to_real_im (x : ℤ[i]) : ((x.im : ℤ) : ℝ) = (x : ℂ).im := by simp [toComplex_def] #align gaussian_int.to_real_im GaussianInt.to_real_im @[simp] theorem toComplex_re (x y : ℤ) : ((⟨x, y⟩ : ℤ[i]) : ℂ).re = x := by simp [toComplex_def] #align gaussian_int.to_complex_re GaussianInt.toComplex_re @[simp] theorem toComplex_im (x y : ℤ) : ((⟨x, y⟩ : ℤ[i]) : ℂ).im = y := by simp [toComplex_def] #align gaussian_int.to_complex_im GaussianInt.toComplex_im -- Porting note (#10618): @[simp] can prove this theorem toComplex_add (x y : ℤ[i]) : ((x + y : ℤ[i]) : ℂ) = x + y := toComplex.map_add _ _ #align gaussian_int.to_complex_add GaussianInt.toComplex_add -- Porting note (#10618): @[simp] can prove this theorem toComplex_mul (x y : ℤ[i]) : ((x * y : ℤ[i]) : ℂ) = x * y := toComplex.map_mul _ _ #align gaussian_int.to_complex_mul GaussianInt.toComplex_mul -- Porting note (#10618): @[simp] can prove this theorem toComplex_one : ((1 : ℤ[i]) : ℂ) = 1 := toComplex.map_one #align gaussian_int.to_complex_one GaussianInt.toComplex_one -- Porting note (#10618): @[simp] can prove this theorem toComplex_zero : ((0 : ℤ[i]) : ℂ) = 0 := toComplex.map_zero #align gaussian_int.to_complex_zero GaussianInt.toComplex_zero -- Porting note (#10618): @[simp] can prove this theorem toComplex_neg (x : ℤ[i]) : ((-x : ℤ[i]) : ℂ) = -x := toComplex.map_neg _ #align gaussian_int.to_complex_neg GaussianInt.toComplex_neg -- Porting note (#10618): @[simp] can prove this theorem toComplex_sub (x y : ℤ[i]) : ((x - y : ℤ[i]) : ℂ) = x - y := toComplex.map_sub _ _ #align gaussian_int.to_complex_sub GaussianInt.toComplex_sub @[simp] theorem toComplex_star (x : ℤ[i]) : ((star x : ℤ[i]) : ℂ) = conj (x : ℂ) := by rw [toComplex_def₂, toComplex_def₂] exact congr_arg₂ _ rfl (Int.cast_neg _) #align gaussian_int.to_complex_star GaussianInt.toComplex_star @[simp] theorem toComplex_inj {x y : ℤ[i]} : (x : ℂ) = y ↔ x = y := by cases x; cases y; simp [toComplex_def₂] #align gaussian_int.to_complex_inj GaussianInt.toComplex_inj lemma toComplex_injective : Function.Injective GaussianInt.toComplex := fun ⦃_ _⦄ ↦ toComplex_inj.mp @[simp] theorem toComplex_eq_zero {x : ℤ[i]} : (x : ℂ) = 0 ↔ x = 0 := by rw [← toComplex_zero, toComplex_inj] #align gaussian_int.to_complex_eq_zero GaussianInt.toComplex_eq_zero @[simp] theorem intCast_real_norm (x : ℤ[i]) : (x.norm : ℝ) = Complex.normSq (x : ℂ) := by rw [Zsqrtd.norm, normSq]; simp #align gaussian_int.nat_cast_real_norm GaussianInt.intCast_real_norm @[deprecated (since := "2024-04-17")] alias int_cast_real_norm := intCast_real_norm @[simp] theorem intCast_complex_norm (x : ℤ[i]) : (x.norm : ℂ) = Complex.normSq (x : ℂ) := by cases x; rw [Zsqrtd.norm, normSq]; simp #align gaussian_int.nat_cast_complex_norm GaussianInt.intCast_complex_norm @[deprecated (since := "2024-04-17")] alias int_cast_complex_norm := intCast_complex_norm theorem norm_nonneg (x : ℤ[i]) : 0 ≤ norm x := Zsqrtd.norm_nonneg (by norm_num) _ #align gaussian_int.norm_nonneg GaussianInt.norm_nonneg @[simp] theorem norm_eq_zero {x : ℤ[i]} : norm x = 0 ↔ x = 0 := by rw [← @Int.cast_inj ℝ _ _ _]; simp #align gaussian_int.norm_eq_zero GaussianInt.norm_eq_zero theorem norm_pos {x : ℤ[i]} : 0 < norm x ↔ x ≠ 0 := by rw [lt_iff_le_and_ne, Ne, eq_comm, norm_eq_zero]; simp [norm_nonneg] #align gaussian_int.norm_pos GaussianInt.norm_pos theorem abs_natCast_norm (x : ℤ[i]) : (x.norm.natAbs : ℤ) = x.norm := Int.natAbs_of_nonneg (norm_nonneg _) #align gaussian_int.abs_coe_nat_norm GaussianInt.abs_natCast_norm -- 2024-04-05 @[deprecated] alias abs_coe_nat_norm := abs_natCast_norm @[simp] theorem natCast_natAbs_norm {α : Type*} [Ring α] (x : ℤ[i]) : (x.norm.natAbs : α) = x.norm := by rw [← Int.cast_natCast, abs_natCast_norm] #align gaussian_int.nat_cast_nat_abs_norm GaussianInt.natCast_natAbs_norm @[deprecated (since := "2024-04-17")] alias nat_cast_natAbs_norm := natCast_natAbs_norm theorem natAbs_norm_eq (x : ℤ[i]) : x.norm.natAbs = x.re.natAbs * x.re.natAbs + x.im.natAbs * x.im.natAbs := Int.ofNat.inj <| by simp; simp [Zsqrtd.norm] #align gaussian_int.nat_abs_norm_eq GaussianInt.natAbs_norm_eq instance : Div ℤ[i] := ⟨fun x y => let n := (norm y : ℚ)⁻¹ let c := star y ⟨round ((x * c).re * n : ℚ), round ((x * c).im * n : ℚ)⟩⟩ theorem div_def (x y : ℤ[i]) : x / y = ⟨round ((x * star y).re / norm y : ℚ), round ((x * star y).im / norm y : ℚ)⟩ := show Zsqrtd.mk _ _ = _ by simp [div_eq_mul_inv] #align gaussian_int.div_def GaussianInt.div_def theorem toComplex_div_re (x y : ℤ[i]) : ((x / y : ℤ[i]) : ℂ).re = round (x / y : ℂ).re := by rw [div_def, ← @Rat.round_cast ℝ _ _] simp [-Rat.round_cast, mul_assoc, div_eq_mul_inv, mul_add, add_mul] #align gaussian_int.to_complex_div_re GaussianInt.toComplex_div_re theorem toComplex_div_im (x y : ℤ[i]) : ((x / y : ℤ[i]) : ℂ).im = round (x / y : ℂ).im := by rw [div_def, ← @Rat.round_cast ℝ _ _, ← @Rat.round_cast ℝ _ _] simp [-Rat.round_cast, mul_assoc, div_eq_mul_inv, mul_add, add_mul] #align gaussian_int.to_complex_div_im GaussianInt.toComplex_div_im theorem normSq_le_normSq_of_re_le_of_im_le {x y : ℂ} (hre : |x.re| ≤ |y.re|) (him : |x.im| ≤ |y.im|) : Complex.normSq x ≤ Complex.normSq y := by rw [normSq_apply, normSq_apply, ← _root_.abs_mul_self, _root_.abs_mul, ← _root_.abs_mul_self y.re, _root_.abs_mul y.re, ← _root_.abs_mul_self x.im, _root_.abs_mul x.im, ← _root_.abs_mul_self y.im, _root_.abs_mul y.im] exact add_le_add (mul_self_le_mul_self (abs_nonneg _) hre) (mul_self_le_mul_self (abs_nonneg _) him) #align gaussian_int.norm_sq_le_norm_sq_of_re_le_of_im_le GaussianInt.normSq_le_normSq_of_re_le_of_im_le theorem normSq_div_sub_div_lt_one (x y : ℤ[i]) : Complex.normSq ((x / y : ℂ) - ((x / y : ℤ[i]) : ℂ)) < 1 := calc Complex.normSq ((x / y : ℂ) - ((x / y : ℤ[i]) : ℂ)) _ = Complex.normSq ((x / y : ℂ).re - ((x / y : ℤ[i]) : ℂ).re + ((x / y : ℂ).im - ((x / y : ℤ[i]) : ℂ).im) * I : ℂ) := congr_arg _ <| by apply Complex.ext <;> simp _ ≤ Complex.normSq (1 / 2 + 1 / 2 * I) := by have : |(2⁻¹ : ℝ)| = 2⁻¹ := abs_of_nonneg (by norm_num) exact normSq_le_normSq_of_re_le_of_im_le (by rw [toComplex_div_re]; simp [normSq, this]; simpa using abs_sub_round (x / y : ℂ).re) (by rw [toComplex_div_im]; simp [normSq, this]; simpa using abs_sub_round (x / y : ℂ).im) _ < 1 := by simp [normSq]; norm_num #align gaussian_int.norm_sq_div_sub_div_lt_one GaussianInt.normSq_div_sub_div_lt_one instance : Mod ℤ[i] := ⟨fun x y => x - y * (x / y)⟩ theorem mod_def (x y : ℤ[i]) : x % y = x - y * (x / y) := rfl #align gaussian_int.mod_def GaussianInt.mod_def theorem norm_mod_lt (x : ℤ[i]) {y : ℤ[i]} (hy : y ≠ 0) : (x % y).norm < y.norm := have : (y : ℂ) ≠ 0 := by rwa [Ne, ← toComplex_zero, toComplex_inj] (@Int.cast_lt ℝ _ _ _ _).1 <| calc ↑(Zsqrtd.norm (x % y)) = Complex.normSq (x - y * (x / y : ℤ[i]) : ℂ) := by simp [mod_def] _ = Complex.normSq (y : ℂ) * Complex.normSq (x / y - (x / y : ℤ[i]) : ℂ) := by rw [← normSq_mul, mul_sub, mul_div_cancel₀ _ this] _ < Complex.normSq (y : ℂ) * 1 := (mul_lt_mul_of_pos_left (normSq_div_sub_div_lt_one _ _) (normSq_pos.2 this)) _ = Zsqrtd.norm y := by simp #align gaussian_int.norm_mod_lt GaussianInt.norm_mod_lt theorem natAbs_norm_mod_lt (x : ℤ[i]) {y : ℤ[i]} (hy : y ≠ 0) : (x % y).norm.natAbs < y.norm.natAbs := Int.ofNat_lt.1 (by simp [-Int.ofNat_lt, norm_mod_lt x hy]) #align gaussian_int.nat_abs_norm_mod_lt GaussianInt.natAbs_norm_mod_lt theorem norm_le_norm_mul_left (x : ℤ[i]) {y : ℤ[i]} (hy : y ≠ 0) : (norm x).natAbs ≤ (norm (x * y)).natAbs := by rw [Zsqrtd.norm_mul, Int.natAbs_mul] exact le_mul_of_one_le_right (Nat.zero_le _) (Int.ofNat_le.1 (by rw [abs_natCast_norm] exact Int.add_one_le_of_lt (norm_pos.2 hy))) #align gaussian_int.norm_le_norm_mul_left GaussianInt.norm_le_norm_mul_left instance instNontrivial : Nontrivial ℤ[i] := ⟨⟨0, 1, by decide⟩⟩ #align gaussian_int.nontrivial GaussianInt.instNontrivial instance : EuclideanDomain ℤ[i] := { GaussianInt.instCommRing, GaussianInt.instNontrivial with quotient := (· / ·) remainder := (· % ·) quotient_zero := by simp [div_def]; rfl quotient_mul_add_remainder_eq := fun _ _ => by simp [mod_def] r := _ r_wellFounded := (measure (Int.natAbs ∘ norm)).wf remainder_lt := natAbs_norm_mod_lt mul_left_not_lt := fun a b hb0 => not_lt_of_ge <| norm_le_norm_mul_left a hb0 } open PrincipalIdealRing
Mathlib/NumberTheory/Zsqrtd/GaussianInt.lean
297
312
theorem sq_add_sq_of_nat_prime_of_not_irreducible (p : ℕ) [hp : Fact p.Prime] (hpi : ¬Irreducible (p : ℤ[i])) : ∃ a b, a ^ 2 + b ^ 2 = p := have hpu : ¬IsUnit (p : ℤ[i]) := mt norm_eq_one_iff.2 <| by rw [norm_natCast, Int.natAbs_mul, mul_eq_one] exact fun h => (ne_of_lt hp.1.one_lt).symm h.1 have hab : ∃ a b, (p : ℤ[i]) = a * b ∧ ¬IsUnit a ∧ ¬IsUnit b := by
-- Porting note: was -- simpa [irreducible_iff, hpu, not_forall, not_or] using hpi simpa only [true_and, not_false_iff, exists_prop, irreducible_iff, hpu, not_forall, not_or] using hpi let ⟨a, b, hpab, hau, hbu⟩ := hab have hnap : (norm a).natAbs = p := ((hp.1.mul_eq_prime_sq_iff (mt norm_eq_one_iff.1 hau) (mt norm_eq_one_iff.1 hbu)).1 <| by rw [← Int.natCast_inj, Int.natCast_pow, sq, ← @norm_natCast (-1), hpab]; simp).1 ⟨a.re.natAbs, a.im.natAbs, by simpa [natAbs_norm_eq, sq] using hnap⟩
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Gabriel Ebner -/ import Mathlib.Init.Data.Nat.Lemmas import Mathlib.Data.Int.Cast.Defs import Mathlib.Algebra.Group.Basic #align_import data.int.cast.basic from "leanprover-community/mathlib"@"70d50ecfd4900dd6d328da39ab7ebd516abe4025" /-! # Cast of integers (additional theorems) This file proves additional properties about the *canonical* homomorphism from the integers into an additive group with a one (`Int.cast`). There is also `Data.Int.Cast.Lemmas`, which includes lemmas stated in terms of algebraic homomorphisms, and results involving the order structure of `ℤ`. By contrast, this file's only import beyond `Data.Int.Cast.Defs` is `Algebra.Group.Basic`. -/ universe u namespace Nat variable {R : Type u} [AddGroupWithOne R] @[simp, norm_cast] theorem cast_sub {m n} (h : m ≤ n) : ((n - m : ℕ) : R) = n - m := eq_sub_of_add_eq <| by rw [← cast_add, Nat.sub_add_cancel h] #align nat.cast_sub Nat.cast_subₓ -- `HasLiftT` appeared in the type signature @[simp, norm_cast] theorem cast_pred : ∀ {n}, 0 < n → ((n - 1 : ℕ) : R) = n - 1 | 0, h => by cases h | n + 1, _ => by rw [cast_succ, add_sub_cancel_right]; rfl #align nat.cast_pred Nat.cast_pred end Nat open Nat namespace Int variable {R : Type u} [AddGroupWithOne R] @[simp, norm_cast squash] theorem cast_negSucc (n : ℕ) : (-[n+1] : R) = -(n + 1 : ℕ) := AddGroupWithOne.intCast_negSucc n #align int.cast_neg_succ_of_nat Int.cast_negSuccₓ -- expected `n` to be implicit, and `HasLiftT` @[simp, norm_cast] theorem cast_zero : ((0 : ℤ) : R) = 0 := (AddGroupWithOne.intCast_ofNat 0).trans Nat.cast_zero #align int.cast_zero Int.cast_zeroₓ -- type had `HasLiftT` -- This lemma competes with `Int.ofNat_eq_natCast` to come later @[simp high, nolint simpNF, norm_cast] theorem cast_natCast (n : ℕ) : ((n : ℤ) : R) = n := AddGroupWithOne.intCast_ofNat _ #align int.cast_coe_nat Int.cast_natCastₓ -- expected `n` to be implicit, and `HasLiftT` #align int.cast_of_nat Int.cast_natCastₓ -- See note [no_index around OfNat.ofNat] @[simp, norm_cast] theorem cast_ofNat (n : ℕ) [n.AtLeastTwo] : ((no_index (OfNat.ofNat n) : ℤ) : R) = OfNat.ofNat n := by simpa only [OfNat.ofNat] using AddGroupWithOne.intCast_ofNat (R := R) n @[simp, norm_cast] theorem cast_one : ((1 : ℤ) : R) = 1 := by erw [cast_natCast, Nat.cast_one] #align int.cast_one Int.cast_oneₓ -- type had `HasLiftT` @[simp, norm_cast] theorem cast_neg : ∀ n, ((-n : ℤ) : R) = -n | (0 : ℕ) => by erw [cast_zero, neg_zero] | (n + 1 : ℕ) => by erw [cast_natCast, cast_negSucc] | -[n+1] => by erw [cast_natCast, cast_negSucc, neg_neg] #align int.cast_neg Int.cast_negₓ -- type had `HasLiftT` @[simp, norm_cast] theorem cast_subNatNat (m n) : ((Int.subNatNat m n : ℤ) : R) = m - n := by unfold subNatNat cases e : n - m · simp only [ofNat_eq_coe] simp [e, Nat.le_of_sub_eq_zero e] · rw [cast_negSucc, ← e, Nat.cast_sub <| _root_.le_of_lt <| Nat.lt_of_sub_eq_succ e, neg_sub] #align int.cast_sub_nat_nat Int.cast_subNatNatₓ -- type had `HasLiftT` #align int.neg_of_nat_eq Int.negOfNat_eq @[simp] theorem cast_negOfNat (n : ℕ) : ((negOfNat n : ℤ) : R) = -n := by simp [Int.cast_neg, negOfNat_eq] #align int.cast_neg_of_nat Int.cast_negOfNat @[simp, norm_cast] theorem cast_add : ∀ m n, ((m + n : ℤ) : R) = m + n | (m : ℕ), (n : ℕ) => by simp [-Int.natCast_add, ← Int.ofNat_add] | (m : ℕ), -[n+1] => by erw [cast_subNatNat, cast_natCast, cast_negSucc, sub_eq_add_neg] | -[m+1], (n : ℕ) => by erw [cast_subNatNat, cast_natCast, cast_negSucc, sub_eq_iff_eq_add, add_assoc, eq_neg_add_iff_add_eq, ← Nat.cast_add, ← Nat.cast_add, Nat.add_comm] | -[m+1], -[n+1] => show (-[m + n + 1+1] : R) = _ by rw [cast_negSucc, cast_negSucc, cast_negSucc, ← neg_add_rev, ← Nat.cast_add, Nat.add_right_comm m n 1, Nat.add_assoc, Nat.add_comm] #align int.cast_add Int.cast_addₓ -- type had `HasLiftT` @[simp, norm_cast] theorem cast_sub (m n) : ((m - n : ℤ) : R) = m - n := by simp [Int.sub_eq_add_neg, sub_eq_add_neg, Int.cast_neg, Int.cast_add] #align int.cast_sub Int.cast_subₓ -- type had `HasLiftT` section deprecated set_option linter.deprecated false @[norm_cast, deprecated] theorem cast_bit0 (n : ℤ) : ((bit0 n : ℤ) : R) = bit0 (n : R) := Int.cast_add _ _ #align int.cast_bit0 Int.cast_bit0 @[norm_cast, deprecated]
Mathlib/Data/Int/Cast/Basic.lean
137
138
theorem cast_bit1 (n : ℤ) : ((bit1 n : ℤ) : R) = bit1 (n : R) := by
rw [bit1, Int.cast_add, Int.cast_one, cast_bit0]; rfl
/- Copyright (c) 2020 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker, Devon Tuma -/ import Mathlib.Algebra.Polynomial.Roots import Mathlib.Analysis.Asymptotics.AsymptoticEquivalent import Mathlib.Analysis.Asymptotics.SpecificAsymptotics #align_import analysis.special_functions.polynomials from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Limits related to polynomial and rational functions This file proves basic facts about limits of polynomial and rationals functions. The main result is `eval_is_equivalent_at_top_eval_lead`, which states that for any polynomial `P` of degree `n` with leading coefficient `a`, the corresponding polynomial function is equivalent to `a * x^n` as `x` goes to +∞. We can then use this result to prove various limits for polynomial and rational functions, depending on the degrees and leading coefficients of the considered polynomials. -/ open Filter Finset Asymptotics open Asymptotics Polynomial Topology namespace Polynomial variable {𝕜 : Type*} [NormedLinearOrderedField 𝕜] (P Q : 𝕜[X]) theorem eventually_no_roots (hP : P ≠ 0) : ∀ᶠ x in atTop, ¬P.IsRoot x := atTop_le_cofinite <| (finite_setOf_isRoot hP).compl_mem_cofinite #align polynomial.eventually_no_roots Polynomial.eventually_no_roots variable [OrderTopology 𝕜] section PolynomialAtTop theorem isEquivalent_atTop_lead : (fun x => eval x P) ~[atTop] fun x => P.leadingCoeff * x ^ P.natDegree := by by_cases h : P = 0 · simp [h, IsEquivalent.refl] · simp only [Polynomial.eval_eq_sum_range, sum_range_succ] exact IsLittleO.add_isEquivalent (IsLittleO.sum fun i hi => IsLittleO.const_mul_left ((IsLittleO.const_mul_right fun hz => h <| leadingCoeff_eq_zero.mp hz) <| isLittleO_pow_pow_atTop_of_lt (mem_range.mp hi)) _) IsEquivalent.refl #align polynomial.is_equivalent_at_top_lead Polynomial.isEquivalent_atTop_lead theorem tendsto_atTop_of_leadingCoeff_nonneg (hdeg : 0 < P.degree) (hnng : 0 ≤ P.leadingCoeff) : Tendsto (fun x => eval x P) atTop atTop := P.isEquivalent_atTop_lead.symm.tendsto_atTop <| tendsto_const_mul_pow_atTop (natDegree_pos_iff_degree_pos.2 hdeg).ne' <| hnng.lt_of_ne' <| leadingCoeff_ne_zero.mpr <| ne_zero_of_degree_gt hdeg #align polynomial.tendsto_at_top_of_leading_coeff_nonneg Polynomial.tendsto_atTop_of_leadingCoeff_nonneg theorem tendsto_atTop_iff_leadingCoeff_nonneg : Tendsto (fun x => eval x P) atTop atTop ↔ 0 < P.degree ∧ 0 ≤ P.leadingCoeff := by refine ⟨fun h => ?_, fun h => tendsto_atTop_of_leadingCoeff_nonneg P h.1 h.2⟩ have : Tendsto (fun x => P.leadingCoeff * x ^ P.natDegree) atTop atTop := (isEquivalent_atTop_lead P).tendsto_atTop h rw [tendsto_const_mul_pow_atTop_iff, ← pos_iff_ne_zero, natDegree_pos_iff_degree_pos] at this exact ⟨this.1, this.2.le⟩ #align polynomial.tendsto_at_top_iff_leading_coeff_nonneg Polynomial.tendsto_atTop_iff_leadingCoeff_nonneg theorem tendsto_atBot_iff_leadingCoeff_nonpos : Tendsto (fun x => eval x P) atTop atBot ↔ 0 < P.degree ∧ P.leadingCoeff ≤ 0 := by simp only [← tendsto_neg_atTop_iff, ← eval_neg, tendsto_atTop_iff_leadingCoeff_nonneg, degree_neg, leadingCoeff_neg, neg_nonneg] #align polynomial.tendsto_at_bot_iff_leading_coeff_nonpos Polynomial.tendsto_atBot_iff_leadingCoeff_nonpos theorem tendsto_atBot_of_leadingCoeff_nonpos (hdeg : 0 < P.degree) (hnps : P.leadingCoeff ≤ 0) : Tendsto (fun x => eval x P) atTop atBot := P.tendsto_atBot_iff_leadingCoeff_nonpos.2 ⟨hdeg, hnps⟩ #align polynomial.tendsto_at_bot_of_leading_coeff_nonpos Polynomial.tendsto_atBot_of_leadingCoeff_nonpos theorem abs_tendsto_atTop (hdeg : 0 < P.degree) : Tendsto (fun x => abs <| eval x P) atTop atTop := by rcases le_total 0 P.leadingCoeff with hP | hP · exact tendsto_abs_atTop_atTop.comp (P.tendsto_atTop_of_leadingCoeff_nonneg hdeg hP) · exact tendsto_abs_atBot_atTop.comp (P.tendsto_atBot_of_leadingCoeff_nonpos hdeg hP) #align polynomial.abs_tendsto_at_top Polynomial.abs_tendsto_atTop theorem abs_isBoundedUnder_iff : (IsBoundedUnder (· ≤ ·) atTop fun x => |eval x P|) ↔ P.degree ≤ 0 := by refine ⟨fun h => ?_, fun h => ⟨|P.coeff 0|, eventually_map.mpr (eventually_of_forall (forall_imp (fun _ => le_of_eq) fun x => congr_arg abs <| _root_.trans (congr_arg (eval x) (eq_C_of_degree_le_zero h)) eval_C))⟩⟩ contrapose! h exact not_isBoundedUnder_of_tendsto_atTop (abs_tendsto_atTop P h) #align polynomial.abs_is_bounded_under_iff Polynomial.abs_isBoundedUnder_iff theorem abs_tendsto_atTop_iff : Tendsto (fun x => abs <| eval x P) atTop atTop ↔ 0 < P.degree := ⟨fun h => not_le.mp (mt (abs_isBoundedUnder_iff P).mpr (not_isBoundedUnder_of_tendsto_atTop h)), abs_tendsto_atTop P⟩ #align polynomial.abs_tendsto_at_top_iff Polynomial.abs_tendsto_atTop_iff theorem tendsto_nhds_iff {c : 𝕜} : Tendsto (fun x => eval x P) atTop (𝓝 c) ↔ P.leadingCoeff = c ∧ P.degree ≤ 0 := by refine ⟨fun h => ?_, fun h => ?_⟩ · have := P.isEquivalent_atTop_lead.tendsto_nhds h by_cases hP : P.leadingCoeff = 0 · simp only [hP, zero_mul, tendsto_const_nhds_iff] at this exact ⟨_root_.trans hP this, by simp [leadingCoeff_eq_zero.1 hP]⟩ · rw [tendsto_const_mul_pow_nhds_iff hP, natDegree_eq_zero_iff_degree_le_zero] at this exact this.symm · refine P.isEquivalent_atTop_lead.symm.tendsto_nhds ?_ have : P.natDegree = 0 := natDegree_eq_zero_iff_degree_le_zero.2 h.2 simp only [h.1, this, pow_zero, mul_one] exact tendsto_const_nhds #align polynomial.tendsto_nhds_iff Polynomial.tendsto_nhds_iff end PolynomialAtTop section PolynomialDivAtTop theorem isEquivalent_atTop_div : (fun x => eval x P / eval x Q) ~[atTop] fun x => P.leadingCoeff / Q.leadingCoeff * x ^ (P.natDegree - Q.natDegree : ℤ) := by by_cases hP : P = 0 · simp [hP, IsEquivalent.refl] by_cases hQ : Q = 0 · simp [hQ, IsEquivalent.refl] refine (P.isEquivalent_atTop_lead.symm.div Q.isEquivalent_atTop_lead.symm).symm.trans (EventuallyEq.isEquivalent ((eventually_gt_atTop 0).mono fun x hx => ?_)) simp [← div_mul_div_comm, hP, hQ, zpow_sub₀ hx.ne.symm] #align polynomial.is_equivalent_at_top_div Polynomial.isEquivalent_atTop_div theorem div_tendsto_zero_of_degree_lt (hdeg : P.degree < Q.degree) : Tendsto (fun x => eval x P / eval x Q) atTop (𝓝 0) := by by_cases hP : P = 0 · simp [hP, tendsto_const_nhds] rw [← natDegree_lt_natDegree_iff hP] at hdeg refine (isEquivalent_atTop_div P Q).symm.tendsto_nhds ?_ rw [← mul_zero] refine (tendsto_zpow_atTop_zero ?_).const_mul _ omega #align polynomial.div_tendsto_zero_of_degree_lt Polynomial.div_tendsto_zero_of_degree_lt theorem div_tendsto_zero_iff_degree_lt (hQ : Q ≠ 0) : Tendsto (fun x => eval x P / eval x Q) atTop (𝓝 0) ↔ P.degree < Q.degree := by refine ⟨fun h => ?_, div_tendsto_zero_of_degree_lt P Q⟩ by_cases hPQ : P.leadingCoeff / Q.leadingCoeff = 0 · simp only [div_eq_mul_inv, inv_eq_zero, mul_eq_zero] at hPQ cases' hPQ with hP0 hQ0 · rw [leadingCoeff_eq_zero.1 hP0, degree_zero] exact bot_lt_iff_ne_bot.2 fun hQ' => hQ (degree_eq_bot.1 hQ') · exact absurd (leadingCoeff_eq_zero.1 hQ0) hQ · have := (isEquivalent_atTop_div P Q).tendsto_nhds h rw [tendsto_const_mul_zpow_atTop_nhds_iff hPQ] at this cases' this with h h · exact absurd h.2 hPQ · rw [sub_lt_iff_lt_add, zero_add, Int.ofNat_lt] at h exact degree_lt_degree h.1 #align polynomial.div_tendsto_zero_iff_degree_lt Polynomial.div_tendsto_zero_iff_degree_lt theorem div_tendsto_leadingCoeff_div_of_degree_eq (hdeg : P.degree = Q.degree) : Tendsto (fun x => eval x P / eval x Q) atTop (𝓝 <| P.leadingCoeff / Q.leadingCoeff) := by refine (isEquivalent_atTop_div P Q).symm.tendsto_nhds ?_ rw [show (P.natDegree : ℤ) = Q.natDegree by simp [hdeg, natDegree]] simp [tendsto_const_nhds] #align polynomial.div_tendsto_leading_coeff_div_of_degree_eq Polynomial.div_tendsto_leadingCoeff_div_of_degree_eq theorem div_tendsto_atTop_of_degree_gt' (hdeg : Q.degree < P.degree) (hpos : 0 < P.leadingCoeff / Q.leadingCoeff) : Tendsto (fun x => eval x P / eval x Q) atTop atTop := by have hQ : Q ≠ 0 := fun h => by simp only [h, div_zero, leadingCoeff_zero] at hpos exact hpos.false rw [← natDegree_lt_natDegree_iff hQ] at hdeg refine (isEquivalent_atTop_div P Q).symm.tendsto_atTop ?_ apply Tendsto.const_mul_atTop hpos apply tendsto_zpow_atTop_atTop omega #align polynomial.div_tendsto_at_top_of_degree_gt' Polynomial.div_tendsto_atTop_of_degree_gt' theorem div_tendsto_atTop_of_degree_gt (hdeg : Q.degree < P.degree) (hQ : Q ≠ 0) (hnng : 0 ≤ P.leadingCoeff / Q.leadingCoeff) : Tendsto (fun x => eval x P / eval x Q) atTop atTop := have ratio_pos : 0 < P.leadingCoeff / Q.leadingCoeff := lt_of_le_of_ne hnng (div_ne_zero (fun h => ne_zero_of_degree_gt hdeg <| leadingCoeff_eq_zero.mp h) fun h => hQ <| leadingCoeff_eq_zero.mp h).symm div_tendsto_atTop_of_degree_gt' P Q hdeg ratio_pos #align polynomial.div_tendsto_at_top_of_degree_gt Polynomial.div_tendsto_atTop_of_degree_gt theorem div_tendsto_atBot_of_degree_gt' (hdeg : Q.degree < P.degree) (hneg : P.leadingCoeff / Q.leadingCoeff < 0) : Tendsto (fun x => eval x P / eval x Q) atTop atBot := by have hQ : Q ≠ 0 := fun h => by simp only [h, div_zero, leadingCoeff_zero] at hneg exact hneg.false rw [← natDegree_lt_natDegree_iff hQ] at hdeg refine (isEquivalent_atTop_div P Q).symm.tendsto_atBot ?_ apply Tendsto.const_mul_atTop_of_neg hneg apply tendsto_zpow_atTop_atTop omega #align polynomial.div_tendsto_at_bot_of_degree_gt' Polynomial.div_tendsto_atBot_of_degree_gt' theorem div_tendsto_atBot_of_degree_gt (hdeg : Q.degree < P.degree) (hQ : Q ≠ 0) (hnps : P.leadingCoeff / Q.leadingCoeff ≤ 0) : Tendsto (fun x => eval x P / eval x Q) atTop atBot := have ratio_neg : P.leadingCoeff / Q.leadingCoeff < 0 := lt_of_le_of_ne hnps (div_ne_zero (fun h => ne_zero_of_degree_gt hdeg <| leadingCoeff_eq_zero.mp h) fun h => hQ <| leadingCoeff_eq_zero.mp h) div_tendsto_atBot_of_degree_gt' P Q hdeg ratio_neg #align polynomial.div_tendsto_at_bot_of_degree_gt Polynomial.div_tendsto_atBot_of_degree_gt
Mathlib/Analysis/SpecialFunctions/Polynomials.lean
218
223
theorem abs_div_tendsto_atTop_of_degree_gt (hdeg : Q.degree < P.degree) (hQ : Q ≠ 0) : Tendsto (fun x => |eval x P / eval x Q|) atTop atTop := by
by_cases h : 0 ≤ P.leadingCoeff / Q.leadingCoeff · exact tendsto_abs_atTop_atTop.comp (P.div_tendsto_atTop_of_degree_gt Q hdeg hQ h) · push_neg at h exact tendsto_abs_atBot_atTop.comp (P.div_tendsto_atBot_of_degree_gt Q hdeg hQ h.le)
/- 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 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 #align filter.is_bounded_under.mono_le Filter.IsBoundedUnder.mono_le theorem IsBoundedUnder.mono_ge [Preorder β] {l : Filter α} {u v : α → β} (hu : IsBoundedUnder (· ≥ ·) l u) (hv : u ≤ᶠ[l] v) : IsBoundedUnder (· ≥ ·) l v := IsBoundedUnder.mono_le (β := βᵒᵈ) hu hv #align filter.is_bounded_under.mono_ge Filter.IsBoundedUnder.mono_ge theorem isBoundedUnder_const [IsRefl α r] {l : Filter β} {a : α} : IsBoundedUnder r l fun _ => a := ⟨a, eventually_map.2 <| eventually_of_forall fun _ => refl _⟩ #align filter.is_bounded_under_const Filter.isBoundedUnder_const theorem IsBounded.isBoundedUnder {q : β → β → Prop} {u : α → β} (hu : ∀ a₀ a₁, r a₀ a₁ → q (u a₀) (u a₁)) : f.IsBounded r → f.IsBoundedUnder q u | ⟨b, h⟩ => ⟨u b, show ∀ᶠ x in f, q (u x) (u b) from h.mono fun x => hu x b⟩ #align filter.is_bounded.is_bounded_under Filter.IsBounded.isBoundedUnder theorem IsBoundedUnder.comp {l : Filter γ} {q : β → β → Prop} {u : γ → α} {v : α → β} (hv : ∀ a₀ a₁, r a₀ a₁ → q (v a₀) (v a₁)) : l.IsBoundedUnder r u → l.IsBoundedUnder q (v ∘ u) | ⟨a, h⟩ => ⟨v a, show ∀ᶠ x in map u l, q (v x) (v a) from h.mono fun x => hv x a⟩ /-- A bounded above function `u` is in particular eventually bounded above. -/ lemma _root_.BddAbove.isBoundedUnder [Preorder α] {f : Filter β} {u : β → α} : BddAbove (Set.range u) → f.IsBoundedUnder (· ≤ ·) u | ⟨b, hb⟩ => isBoundedUnder_of ⟨b, by simpa [mem_upperBounds] using hb⟩ /-- A bounded below function `u` is in particular eventually bounded below. -/ lemma _root_.BddBelow.isBoundedUnder [Preorder α] {f : Filter β} {u : β → α} : BddBelow (Set.range u) → f.IsBoundedUnder (· ≥ ·) u | ⟨b, hb⟩ => isBoundedUnder_of ⟨b, by simpa [mem_lowerBounds] using hb⟩ theorem _root_.Monotone.isBoundedUnder_le_comp [Preorder α] [Preorder β] {l : Filter γ} {u : γ → α} {v : α → β} (hv : Monotone v) (hl : l.IsBoundedUnder (· ≤ ·) u) : l.IsBoundedUnder (· ≤ ·) (v ∘ u) := hl.comp hv theorem _root_.Monotone.isBoundedUnder_ge_comp [Preorder α] [Preorder β] {l : Filter γ} {u : γ → α} {v : α → β} (hv : Monotone v) (hl : l.IsBoundedUnder (· ≥ ·) u) : l.IsBoundedUnder (· ≥ ·) (v ∘ u) := hl.comp (swap hv) theorem _root_.Antitone.isBoundedUnder_le_comp [Preorder α] [Preorder β] {l : Filter γ} {u : γ → α} {v : α → β} (hv : Antitone v) (hl : l.IsBoundedUnder (· ≥ ·) u) : l.IsBoundedUnder (· ≤ ·) (v ∘ u) := hl.comp (swap hv) theorem _root_.Antitone.isBoundedUnder_ge_comp [Preorder α] [Preorder β] {l : Filter γ} {u : γ → α} {v : α → β} (hv : Antitone v) (hl : l.IsBoundedUnder (· ≤ ·) u) : l.IsBoundedUnder (· ≥ ·) (v ∘ u) := hl.comp hv theorem not_isBoundedUnder_of_tendsto_atTop [Preorder β] [NoMaxOrder β] {f : α → β} {l : Filter α} [l.NeBot] (hf : Tendsto f l atTop) : ¬IsBoundedUnder (· ≤ ·) l f := by rintro ⟨b, hb⟩ rw [eventually_map] at hb obtain ⟨b', h⟩ := exists_gt b have hb' := (tendsto_atTop.mp hf) b' have : { x : α | f x ≤ b } ∩ { x : α | b' ≤ f x } = ∅ := eq_empty_of_subset_empty fun x hx => (not_le_of_lt h) (le_trans hx.2 hx.1) exact (nonempty_of_mem (hb.and hb')).ne_empty this #align filter.not_is_bounded_under_of_tendsto_at_top Filter.not_isBoundedUnder_of_tendsto_atTop theorem not_isBoundedUnder_of_tendsto_atBot [Preorder β] [NoMinOrder β] {f : α → β} {l : Filter α} [l.NeBot] (hf : Tendsto f l atBot) : ¬IsBoundedUnder (· ≥ ·) l f := not_isBoundedUnder_of_tendsto_atTop (β := βᵒᵈ) hf #align filter.not_is_bounded_under_of_tendsto_at_bot Filter.not_isBoundedUnder_of_tendsto_atBot theorem IsBoundedUnder.bddAbove_range_of_cofinite [Preorder β] [IsDirected β (· ≤ ·)] {f : α → β} (hf : IsBoundedUnder (· ≤ ·) cofinite f) : BddAbove (range f) := by rcases hf with ⟨b, hb⟩ haveI : Nonempty β := ⟨b⟩ rw [← image_univ, ← union_compl_self { x | f x ≤ b }, image_union, bddAbove_union] exact ⟨⟨b, forall_mem_image.2 fun x => id⟩, (hb.image f).bddAbove⟩ #align filter.is_bounded_under.bdd_above_range_of_cofinite Filter.IsBoundedUnder.bddAbove_range_of_cofinite theorem IsBoundedUnder.bddBelow_range_of_cofinite [Preorder β] [IsDirected β (· ≥ ·)] {f : α → β} (hf : IsBoundedUnder (· ≥ ·) cofinite f) : BddBelow (range f) := IsBoundedUnder.bddAbove_range_of_cofinite (β := βᵒᵈ) hf #align filter.is_bounded_under.bdd_below_range_of_cofinite Filter.IsBoundedUnder.bddBelow_range_of_cofinite theorem IsBoundedUnder.bddAbove_range [Preorder β] [IsDirected β (· ≤ ·)] {f : ℕ → β} (hf : IsBoundedUnder (· ≤ ·) atTop f) : BddAbove (range f) := by rw [← Nat.cofinite_eq_atTop] at hf exact hf.bddAbove_range_of_cofinite #align filter.is_bounded_under.bdd_above_range Filter.IsBoundedUnder.bddAbove_range theorem IsBoundedUnder.bddBelow_range [Preorder β] [IsDirected β (· ≥ ·)] {f : ℕ → β} (hf : IsBoundedUnder (· ≥ ·) atTop f) : BddBelow (range f) := IsBoundedUnder.bddAbove_range (β := βᵒᵈ) hf #align filter.is_bounded_under.bdd_below_range Filter.IsBoundedUnder.bddBelow_range /-- `IsCobounded (≺) f` states that the filter `f` does not tend to infinity w.r.t. `≺`. This is also called frequently bounded. Will be usually instantiated with `≤` or `≥`. There is a subtlety in this definition: we want `f.IsCobounded` to hold for any `f` in the case of complete lattices. This will be relevant to deduce theorems on complete lattices from their versions on conditionally complete lattices with additional assumptions. We have to be careful in the edge case of the trivial filter containing the empty set: the other natural definition `¬ ∀ a, ∀ᶠ n in f, a ≤ n` would not work as well in this case. -/ def IsCobounded (r : α → α → Prop) (f : Filter α) := ∃ b, ∀ a, (∀ᶠ x in f, r x a) → r b a #align filter.is_cobounded Filter.IsCobounded /-- `IsCoboundedUnder (≺) f u` states that the image of the filter `f` under the map `u` does not tend to infinity w.r.t. `≺`. This is also called frequently bounded. Will be usually instantiated with `≤` or `≥`. -/ def IsCoboundedUnder (r : α → α → Prop) (f : Filter β) (u : β → α) := (map u f).IsCobounded r #align filter.is_cobounded_under Filter.IsCoboundedUnder /-- To check that a filter is frequently bounded, it suffices to have a witness which bounds `f` at some point for every admissible set. This is only an implication, as the other direction is wrong for the trivial filter. -/ theorem IsCobounded.mk [IsTrans α r] (a : α) (h : ∀ s ∈ f, ∃ x ∈ s, r a x) : f.IsCobounded r := ⟨a, fun _ s => let ⟨_, h₁, h₂⟩ := h _ s _root_.trans h₂ h₁⟩ #align filter.is_cobounded.mk Filter.IsCobounded.mk /-- A filter which is eventually bounded is in particular frequently bounded (in the opposite direction). At least if the filter is not trivial. -/ theorem IsBounded.isCobounded_flip [IsTrans α r] [NeBot f] : f.IsBounded r → f.IsCobounded (flip r) | ⟨a, ha⟩ => ⟨a, fun b hb => let ⟨_, rxa, rbx⟩ := (ha.and hb).exists show r b a from _root_.trans rbx rxa⟩ #align filter.is_bounded.is_cobounded_flip Filter.IsBounded.isCobounded_flip theorem IsBounded.isCobounded_ge [Preorder α] [NeBot f] (h : f.IsBounded (· ≤ ·)) : f.IsCobounded (· ≥ ·) := h.isCobounded_flip #align filter.is_bounded.is_cobounded_ge Filter.IsBounded.isCobounded_ge theorem IsBounded.isCobounded_le [Preorder α] [NeBot f] (h : f.IsBounded (· ≥ ·)) : f.IsCobounded (· ≤ ·) := h.isCobounded_flip #align filter.is_bounded.is_cobounded_le Filter.IsBounded.isCobounded_le theorem IsBoundedUnder.isCoboundedUnder_flip {l : Filter γ} [IsTrans α r] [NeBot l] (h : l.IsBoundedUnder r u) : l.IsCoboundedUnder (flip r) u := h.isCobounded_flip theorem IsBoundedUnder.isCoboundedUnder_le {u : γ → α} {l : Filter γ} [Preorder α] [NeBot l] (h : l.IsBoundedUnder (· ≥ ·) u) : l.IsCoboundedUnder (· ≤ ·) u := h.isCoboundedUnder_flip theorem IsBoundedUnder.isCoboundedUnder_ge {u : γ → α} {l : Filter γ} [Preorder α] [NeBot l] (h : l.IsBoundedUnder (· ≤ ·) u) : l.IsCoboundedUnder (· ≥ ·) u := h.isCoboundedUnder_flip lemma isCoboundedUnder_le_of_eventually_le [Preorder α] (l : Filter ι) [NeBot l] {f : ι → α} {x : α} (hf : ∀ᶠ i in l, x ≤ f i) : IsCoboundedUnder (· ≤ ·) l f := IsBoundedUnder.isCoboundedUnder_le ⟨x, hf⟩ lemma isCoboundedUnder_ge_of_eventually_le [Preorder α] (l : Filter ι) [NeBot l] {f : ι → α} {x : α} (hf : ∀ᶠ i in l, f i ≤ x) : IsCoboundedUnder (· ≥ ·) l f := IsBoundedUnder.isCoboundedUnder_ge ⟨x, hf⟩ lemma isCoboundedUnder_le_of_le [Preorder α] (l : Filter ι) [NeBot l] {f : ι → α} {x : α} (hf : ∀ i, x ≤ f i) : IsCoboundedUnder (· ≤ ·) l f := isCoboundedUnder_le_of_eventually_le l (eventually_of_forall hf) lemma isCoboundedUnder_ge_of_le [Preorder α] (l : Filter ι) [NeBot l] {f : ι → α} {x : α} (hf : ∀ i, f i ≤ x) : IsCoboundedUnder (· ≥ ·) l f := isCoboundedUnder_ge_of_eventually_le l (eventually_of_forall hf) theorem isCobounded_bot : IsCobounded r ⊥ ↔ ∃ b, ∀ x, r b x := by simp [IsCobounded] #align filter.is_cobounded_bot Filter.isCobounded_bot theorem isCobounded_top : IsCobounded r ⊤ ↔ Nonempty α := by simp (config := { contextual := true }) [IsCobounded, eq_univ_iff_forall, exists_true_iff_nonempty] #align filter.is_cobounded_top Filter.isCobounded_top theorem isCobounded_principal (s : Set α) : (𝓟 s).IsCobounded r ↔ ∃ b, ∀ a, (∀ x ∈ s, r x a) → r b a := by simp [IsCobounded, subset_def] #align filter.is_cobounded_principal Filter.isCobounded_principal theorem IsCobounded.mono (h : f ≤ g) : f.IsCobounded r → g.IsCobounded r | ⟨b, hb⟩ => ⟨b, fun a ha => hb a (h ha)⟩ #align filter.is_cobounded.mono Filter.IsCobounded.mono end Relation section Nonempty variable [Preorder α] [Nonempty α] {f : Filter β} {u : β → α} theorem isBounded_le_atBot : (atBot : Filter α).IsBounded (· ≤ ·) := ‹Nonempty α›.elim fun a => ⟨a, eventually_le_atBot _⟩ #align filter.is_bounded_le_at_bot Filter.isBounded_le_atBot theorem isBounded_ge_atTop : (atTop : Filter α).IsBounded (· ≥ ·) := ‹Nonempty α›.elim fun a => ⟨a, eventually_ge_atTop _⟩ #align filter.is_bounded_ge_at_top Filter.isBounded_ge_atTop theorem Tendsto.isBoundedUnder_le_atBot (h : Tendsto u f atBot) : f.IsBoundedUnder (· ≤ ·) u := isBounded_le_atBot.mono h #align filter.tendsto.is_bounded_under_le_at_bot Filter.Tendsto.isBoundedUnder_le_atBot theorem Tendsto.isBoundedUnder_ge_atTop (h : Tendsto u f atTop) : f.IsBoundedUnder (· ≥ ·) u := isBounded_ge_atTop.mono h #align filter.tendsto.is_bounded_under_ge_at_top Filter.Tendsto.isBoundedUnder_ge_atTop theorem bddAbove_range_of_tendsto_atTop_atBot [IsDirected α (· ≤ ·)] {u : ℕ → α} (hx : Tendsto u atTop atBot) : BddAbove (Set.range u) := hx.isBoundedUnder_le_atBot.bddAbove_range #align filter.bdd_above_range_of_tendsto_at_top_at_bot Filter.bddAbove_range_of_tendsto_atTop_atBot theorem bddBelow_range_of_tendsto_atTop_atTop [IsDirected α (· ≥ ·)] {u : ℕ → α} (hx : Tendsto u atTop atTop) : BddBelow (Set.range u) := hx.isBoundedUnder_ge_atTop.bddBelow_range #align filter.bdd_below_range_of_tendsto_at_top_at_top Filter.bddBelow_range_of_tendsto_atTop_atTop end Nonempty theorem isCobounded_le_of_bot [Preorder α] [OrderBot α] {f : Filter α} : f.IsCobounded (· ≤ ·) := ⟨⊥, fun _ _ => bot_le⟩ #align filter.is_cobounded_le_of_bot Filter.isCobounded_le_of_bot theorem isCobounded_ge_of_top [Preorder α] [OrderTop α] {f : Filter α} : f.IsCobounded (· ≥ ·) := ⟨⊤, fun _ _ => le_top⟩ #align filter.is_cobounded_ge_of_top Filter.isCobounded_ge_of_top theorem isBounded_le_of_top [Preorder α] [OrderTop α] {f : Filter α} : f.IsBounded (· ≤ ·) := ⟨⊤, eventually_of_forall fun _ => le_top⟩ #align filter.is_bounded_le_of_top Filter.isBounded_le_of_top theorem isBounded_ge_of_bot [Preorder α] [OrderBot α] {f : Filter α} : f.IsBounded (· ≥ ·) := ⟨⊥, eventually_of_forall fun _ => bot_le⟩ #align filter.is_bounded_ge_of_bot Filter.isBounded_ge_of_bot @[simp] theorem _root_.OrderIso.isBoundedUnder_le_comp [Preorder α] [Preorder β] (e : α ≃o β) {l : Filter γ} {u : γ → α} : (IsBoundedUnder (· ≤ ·) l fun x => e (u x)) ↔ IsBoundedUnder (· ≤ ·) l u := (Function.Surjective.exists e.surjective).trans <| exists_congr fun a => by simp only [eventually_map, e.le_iff_le] #align order_iso.is_bounded_under_le_comp OrderIso.isBoundedUnder_le_comp @[simp] theorem _root_.OrderIso.isBoundedUnder_ge_comp [Preorder α] [Preorder β] (e : α ≃o β) {l : Filter γ} {u : γ → α} : (IsBoundedUnder (· ≥ ·) l fun x => e (u x)) ↔ IsBoundedUnder (· ≥ ·) l u := OrderIso.isBoundedUnder_le_comp e.dual #align order_iso.is_bounded_under_ge_comp OrderIso.isBoundedUnder_ge_comp @[to_additive (attr := simp)] theorem isBoundedUnder_le_inv [OrderedCommGroup α] {l : Filter β} {u : β → α} : (IsBoundedUnder (· ≤ ·) l fun x => (u x)⁻¹) ↔ IsBoundedUnder (· ≥ ·) l u := (OrderIso.inv α).isBoundedUnder_ge_comp #align filter.is_bounded_under_le_inv Filter.isBoundedUnder_le_inv #align filter.is_bounded_under_le_neg Filter.isBoundedUnder_le_neg @[to_additive (attr := simp)] theorem isBoundedUnder_ge_inv [OrderedCommGroup α] {l : Filter β} {u : β → α} : (IsBoundedUnder (· ≥ ·) l fun x => (u x)⁻¹) ↔ IsBoundedUnder (· ≤ ·) l u := (OrderIso.inv α).isBoundedUnder_le_comp #align filter.is_bounded_under_ge_inv Filter.isBoundedUnder_ge_inv #align filter.is_bounded_under_ge_neg Filter.isBoundedUnder_ge_neg theorem IsBoundedUnder.sup [SemilatticeSup α] {f : Filter β} {u v : β → α} : f.IsBoundedUnder (· ≤ ·) u → f.IsBoundedUnder (· ≤ ·) v → f.IsBoundedUnder (· ≤ ·) fun a => u a ⊔ v a | ⟨bu, (hu : ∀ᶠ x in f, u x ≤ bu)⟩, ⟨bv, (hv : ∀ᶠ x in f, v x ≤ bv)⟩ => ⟨bu ⊔ bv, show ∀ᶠ x in f, u x ⊔ v x ≤ bu ⊔ bv by filter_upwards [hu, hv] with _ using sup_le_sup⟩ #align filter.is_bounded_under.sup Filter.IsBoundedUnder.sup @[simp] theorem isBoundedUnder_le_sup [SemilatticeSup α] {f : Filter β} {u v : β → α} : (f.IsBoundedUnder (· ≤ ·) fun a => u a ⊔ v a) ↔ f.IsBoundedUnder (· ≤ ·) u ∧ f.IsBoundedUnder (· ≤ ·) v := ⟨fun h => ⟨h.mono_le <| eventually_of_forall fun _ => le_sup_left, h.mono_le <| eventually_of_forall fun _ => le_sup_right⟩, fun h => h.1.sup h.2⟩ #align filter.is_bounded_under_le_sup Filter.isBoundedUnder_le_sup theorem IsBoundedUnder.inf [SemilatticeInf α] {f : Filter β} {u v : β → α} : f.IsBoundedUnder (· ≥ ·) u → f.IsBoundedUnder (· ≥ ·) v → f.IsBoundedUnder (· ≥ ·) fun a => u a ⊓ v a := IsBoundedUnder.sup (α := αᵒᵈ) #align filter.is_bounded_under.inf Filter.IsBoundedUnder.inf @[simp] theorem isBoundedUnder_ge_inf [SemilatticeInf α] {f : Filter β} {u v : β → α} : (f.IsBoundedUnder (· ≥ ·) fun a => u a ⊓ v a) ↔ f.IsBoundedUnder (· ≥ ·) u ∧ f.IsBoundedUnder (· ≥ ·) v := isBoundedUnder_le_sup (α := αᵒᵈ) #align filter.is_bounded_under_ge_inf Filter.isBoundedUnder_ge_inf theorem isBoundedUnder_le_abs [LinearOrderedAddCommGroup α] {f : Filter β} {u : β → α} : (f.IsBoundedUnder (· ≤ ·) fun a => |u a|) ↔ f.IsBoundedUnder (· ≤ ·) u ∧ f.IsBoundedUnder (· ≥ ·) u := isBoundedUnder_le_sup.trans <| and_congr Iff.rfl isBoundedUnder_le_neg #align filter.is_bounded_under_le_abs Filter.isBoundedUnder_le_abs /-- Filters are automatically bounded or cobounded in complete lattices. To use the same statements in complete and conditionally complete lattices but let automation fill automatically the boundedness proofs in complete lattices, we use the tactic `isBoundedDefault` in the statements, in the form `(hf : f.IsBounded (≥) := by isBoundedDefault)`. -/ macro "isBoundedDefault" : tactic => `(tactic| first | apply isCobounded_le_of_bot | apply isCobounded_ge_of_top | apply isBounded_le_of_top | apply isBounded_ge_of_bot) -- Porting note: The above is a lean 4 reconstruction of (note that applyc is not available (yet?)): -- unsafe def is_bounded_default : tactic Unit := -- tactic.applyc `` is_cobounded_le_of_bot <|> -- tactic.applyc `` is_cobounded_ge_of_top <|> -- tactic.applyc `` is_bounded_le_of_top <|> tactic.applyc `` is_bounded_ge_of_bot -- #align filter.is_bounded_default filter.IsBounded_default section ConditionallyCompleteLattice variable [ConditionallyCompleteLattice α] -- Porting note: Renamed from Limsup and Liminf to limsSup and limsInf /-- The `limsSup` of a filter `f` is the infimum of the `a` such that, eventually for `f`, holds `x ≤ a`. -/ def limsSup (f : Filter α) : α := sInf { a | ∀ᶠ n in f, n ≤ a } set_option linter.uppercaseLean3 false in #align filter.Limsup Filter.limsSup set_option linter.uppercaseLean3 false in /-- The `limsInf` of a filter `f` is the supremum of the `a` such that, eventually for `f`, holds `x ≥ a`. -/ def limsInf (f : Filter α) : α := sSup { a | ∀ᶠ n in f, a ≤ n } set_option linter.uppercaseLean3 false in #align filter.Liminf Filter.limsInf /-- The `limsup` of a function `u` along a filter `f` is the infimum of the `a` such that, eventually for `f`, holds `u x ≤ a`. -/ def limsup (u : β → α) (f : Filter β) : α := limsSup (map u f) #align filter.limsup Filter.limsup /-- The `liminf` of a function `u` along a filter `f` is the supremum of the `a` such that, eventually for `f`, holds `u x ≥ a`. -/ def liminf (u : β → α) (f : Filter β) : α := limsInf (map u f) #align filter.liminf Filter.liminf /-- The `blimsup` of a function `u` along a filter `f`, bounded by a predicate `p`, is the infimum of the `a` such that, eventually for `f`, `u x ≤ a` whenever `p x` holds. -/ def blimsup (u : β → α) (f : Filter β) (p : β → Prop) := sInf { a | ∀ᶠ x in f, p x → u x ≤ a } #align filter.blimsup Filter.blimsup /-- The `bliminf` of a function `u` along a filter `f`, bounded by a predicate `p`, is the supremum of the `a` such that, eventually for `f`, `a ≤ u x` whenever `p x` holds. -/ def bliminf (u : β → α) (f : Filter β) (p : β → Prop) := sSup { a | ∀ᶠ x in f, p x → a ≤ u x } #align filter.bliminf Filter.bliminf section variable {f : Filter β} {u : β → α} {p : β → Prop} theorem limsup_eq : limsup u f = sInf { a | ∀ᶠ n in f, u n ≤ a } := rfl #align filter.limsup_eq Filter.limsup_eq theorem liminf_eq : liminf u f = sSup { a | ∀ᶠ n in f, a ≤ u n } := rfl #align filter.liminf_eq Filter.liminf_eq theorem blimsup_eq : blimsup u f p = sInf { a | ∀ᶠ x in f, p x → u x ≤ a } := rfl #align filter.blimsup_eq Filter.blimsup_eq theorem bliminf_eq : bliminf u f p = sSup { a | ∀ᶠ x in f, p x → a ≤ u x } := rfl #align filter.bliminf_eq Filter.bliminf_eq lemma liminf_comp (u : β → α) (v : γ → β) (f : Filter γ) : liminf (u ∘ v) f = liminf u (map v f) := rfl lemma limsup_comp (u : β → α) (v : γ → β) (f : Filter γ) : limsup (u ∘ v) f = limsup u (map v f) := rfl end @[simp] theorem blimsup_true (f : Filter β) (u : β → α) : (blimsup u f fun _ => True) = limsup u f := by simp [blimsup_eq, limsup_eq] #align filter.blimsup_true Filter.blimsup_true @[simp] theorem bliminf_true (f : Filter β) (u : β → α) : (bliminf u f fun _ => True) = liminf u f := by simp [bliminf_eq, liminf_eq] #align filter.bliminf_true Filter.bliminf_true lemma blimsup_eq_limsup {f : Filter β} {u : β → α} {p : β → Prop} : blimsup u f p = limsup u (f ⊓ 𝓟 {x | p x}) := by simp only [blimsup_eq, limsup_eq, eventually_inf_principal, mem_setOf_eq] lemma bliminf_eq_liminf {f : Filter β} {u : β → α} {p : β → Prop} : bliminf u f p = liminf u (f ⊓ 𝓟 {x | p x}) := blimsup_eq_limsup (α := αᵒᵈ) theorem blimsup_eq_limsup_subtype {f : Filter β} {u : β → α} {p : β → Prop} : blimsup u f p = limsup (u ∘ ((↑) : { x | p x } → β)) (comap (↑) f) := by rw [blimsup_eq_limsup, limsup, limsup, ← map_map, map_comap_setCoe_val] #align filter.blimsup_eq_limsup_subtype Filter.blimsup_eq_limsup_subtype theorem bliminf_eq_liminf_subtype {f : Filter β} {u : β → α} {p : β → Prop} : bliminf u f p = liminf (u ∘ ((↑) : { x | p x } → β)) (comap (↑) f) := blimsup_eq_limsup_subtype (α := αᵒᵈ) #align filter.bliminf_eq_liminf_subtype Filter.bliminf_eq_liminf_subtype theorem limsSup_le_of_le {f : Filter α} {a} (hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault) (h : ∀ᶠ n in f, n ≤ a) : limsSup f ≤ a := csInf_le hf h set_option linter.uppercaseLean3 false in #align filter.Limsup_le_of_le Filter.limsSup_le_of_le theorem le_limsInf_of_le {f : Filter α} {a} (hf : f.IsCobounded (· ≥ ·) := by isBoundedDefault) (h : ∀ᶠ n in f, a ≤ n) : a ≤ limsInf f := le_csSup hf h set_option linter.uppercaseLean3 false in #align filter.le_Liminf_of_le Filter.le_limsInf_of_le theorem limsup_le_of_le {f : Filter β} {u : β → α} {a} (hf : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (h : ∀ᶠ n in f, u n ≤ a) : limsup u f ≤ a := csInf_le hf h #align filter.limsup_le_of_le Filter.limsSup_le_of_le theorem le_liminf_of_le {f : Filter β} {u : β → α} {a} (hf : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) (h : ∀ᶠ n in f, a ≤ u n) : a ≤ liminf u f := le_csSup hf h #align filter.le_liminf_of_le Filter.le_liminf_of_le theorem le_limsSup_of_le {f : Filter α} {a} (hf : f.IsBounded (· ≤ ·) := by isBoundedDefault) (h : ∀ b, (∀ᶠ n in f, n ≤ b) → a ≤ b) : a ≤ limsSup f := le_csInf hf h set_option linter.uppercaseLean3 false in #align filter.le_Limsup_of_le Filter.le_limsSup_of_le theorem limsInf_le_of_le {f : Filter α} {a} (hf : f.IsBounded (· ≥ ·) := by isBoundedDefault) (h : ∀ b, (∀ᶠ n in f, b ≤ n) → b ≤ a) : limsInf f ≤ a := csSup_le hf h set_option linter.uppercaseLean3 false in #align filter.Liminf_le_of_le Filter.limsInf_le_of_le theorem le_limsup_of_le {f : Filter β} {u : β → α} {a} (hf : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) (h : ∀ b, (∀ᶠ n in f, u n ≤ b) → a ≤ b) : a ≤ limsup u f := le_csInf hf h #align filter.le_limsup_of_le Filter.le_limsup_of_le theorem liminf_le_of_le {f : Filter β} {u : β → α} {a} (hf : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) (h : ∀ b, (∀ᶠ n in f, b ≤ u n) → b ≤ a) : liminf u f ≤ a := csSup_le hf h #align filter.liminf_le_of_le Filter.liminf_le_of_le theorem limsInf_le_limsSup {f : Filter α} [NeBot f] (h₁ : f.IsBounded (· ≤ ·) := by isBoundedDefault) (h₂ : f.IsBounded (· ≥ ·) := by isBoundedDefault): limsInf f ≤ limsSup f := liminf_le_of_le h₂ fun a₀ ha₀ => le_limsup_of_le h₁ fun a₁ ha₁ => show a₀ ≤ a₁ from let ⟨_, hb₀, hb₁⟩ := (ha₀.and ha₁).exists le_trans hb₀ hb₁ set_option linter.uppercaseLean3 false in #align filter.Liminf_le_Limsup Filter.limsInf_le_limsSup theorem liminf_le_limsup {f : Filter β} [NeBot f] {u : β → α} (h : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) (h' : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault): liminf u f ≤ limsup u f := limsInf_le_limsSup h h' #align filter.liminf_le_limsup Filter.liminf_le_limsup theorem limsSup_le_limsSup {f g : Filter α} (hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault) (hg : g.IsBounded (· ≤ ·) := by isBoundedDefault) (h : ∀ a, (∀ᶠ n in g, n ≤ a) → ∀ᶠ n in f, n ≤ a) : limsSup f ≤ limsSup g := csInf_le_csInf hf hg h set_option linter.uppercaseLean3 false in #align filter.Limsup_le_Limsup Filter.limsSup_le_limsSup theorem limsInf_le_limsInf {f g : Filter α} (hf : f.IsBounded (· ≥ ·) := by isBoundedDefault) (hg : g.IsCobounded (· ≥ ·) := by isBoundedDefault) (h : ∀ a, (∀ᶠ n in f, a ≤ n) → ∀ᶠ n in g, a ≤ n) : limsInf f ≤ limsInf g := csSup_le_csSup hg hf h set_option linter.uppercaseLean3 false in #align filter.Liminf_le_Liminf Filter.limsInf_le_limsInf theorem limsup_le_limsup {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β} (h : u ≤ᶠ[f] v) (hu : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (hv : f.IsBoundedUnder (· ≤ ·) v := by isBoundedDefault) : limsup u f ≤ limsup v f := limsSup_le_limsSup hu hv fun _ => h.trans #align filter.limsup_le_limsup Filter.limsup_le_limsup theorem liminf_le_liminf {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β} (h : ∀ᶠ a in f, u a ≤ v a) (hu : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) (hv : f.IsCoboundedUnder (· ≥ ·) v := by isBoundedDefault) : liminf u f ≤ liminf v f := limsup_le_limsup (β := βᵒᵈ) h hv hu #align filter.liminf_le_liminf Filter.liminf_le_liminf theorem limsSup_le_limsSup_of_le {f g : Filter α} (h : f ≤ g) (hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault) (hg : g.IsBounded (· ≤ ·) := by isBoundedDefault) : limsSup f ≤ limsSup g := limsSup_le_limsSup hf hg fun _ ha => h ha set_option linter.uppercaseLean3 false in #align filter.Limsup_le_Limsup_of_le Filter.limsSup_le_limsSup_of_le theorem limsInf_le_limsInf_of_le {f g : Filter α} (h : g ≤ f) (hf : f.IsBounded (· ≥ ·) := by isBoundedDefault) (hg : g.IsCobounded (· ≥ ·) := by isBoundedDefault) : limsInf f ≤ limsInf g := limsInf_le_limsInf hf hg fun _ ha => h ha set_option linter.uppercaseLean3 false in #align filter.Liminf_le_Liminf_of_le Filter.limsInf_le_limsInf_of_le theorem limsup_le_limsup_of_le {α β} [ConditionallyCompleteLattice β] {f g : Filter α} (h : f ≤ g) {u : α → β} (hf : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (hg : g.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) : limsup u f ≤ limsup u g := limsSup_le_limsSup_of_le (map_mono h) hf hg #align filter.limsup_le_limsup_of_le Filter.limsup_le_limsup_of_le theorem liminf_le_liminf_of_le {α β} [ConditionallyCompleteLattice β] {f g : Filter α} (h : g ≤ f) {u : α → β} (hf : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) (hg : g.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) : liminf u f ≤ liminf u g := limsInf_le_limsInf_of_le (map_mono h) hf hg #align filter.liminf_le_liminf_of_le Filter.liminf_le_liminf_of_le theorem limsSup_principal {s : Set α} (h : BddAbove s) (hs : s.Nonempty) : limsSup (𝓟 s) = sSup s := by simp only [limsSup, eventually_principal]; exact csInf_upper_bounds_eq_csSup h hs set_option linter.uppercaseLean3 false in #align filter.Limsup_principal Filter.limsSup_principal theorem limsInf_principal {s : Set α} (h : BddBelow s) (hs : s.Nonempty) : limsInf (𝓟 s) = sInf s := limsSup_principal (α := αᵒᵈ) h hs set_option linter.uppercaseLean3 false in #align filter.Liminf_principal Filter.limsInf_principal theorem limsup_congr {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β} (h : ∀ᶠ a in f, u a = v a) : limsup u f = limsup v f := by rw [limsup_eq] congr with b exact eventually_congr (h.mono fun x hx => by simp [hx]) #align filter.limsup_congr Filter.limsup_congr theorem blimsup_congr {f : Filter β} {u v : β → α} {p : β → Prop} (h : ∀ᶠ a in f, p a → u a = v a) : blimsup u f p = blimsup v f p := by simpa only [blimsup_eq_limsup] using limsup_congr <| eventually_inf_principal.2 h #align filter.blimsup_congr Filter.blimsup_congr theorem bliminf_congr {f : Filter β} {u v : β → α} {p : β → Prop} (h : ∀ᶠ a in f, p a → u a = v a) : bliminf u f p = bliminf v f p := blimsup_congr (α := αᵒᵈ) h #align filter.bliminf_congr Filter.bliminf_congr theorem liminf_congr {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β} (h : ∀ᶠ a in f, u a = v a) : liminf u f = liminf v f := limsup_congr (β := βᵒᵈ) h #align filter.liminf_congr Filter.liminf_congr @[simp] theorem limsup_const {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} [NeBot f] (b : β) : limsup (fun _ => b) f = b := by simpa only [limsup_eq, eventually_const] using csInf_Ici #align filter.limsup_const Filter.limsup_const @[simp] theorem liminf_const {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} [NeBot f] (b : β) : liminf (fun _ => b) f = b := limsup_const (β := βᵒᵈ) b #align filter.liminf_const Filter.liminf_const theorem HasBasis.liminf_eq_sSup_iUnion_iInter {ι ι' : Type*} {f : ι → α} {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) : liminf f v = sSup (⋃ (j : Subtype p), ⋂ (i : s j), Iic (f i)) := by simp_rw [liminf_eq, hv.eventually_iff] congr ext x simp only [mem_setOf_eq, iInter_coe_set, mem_iUnion, mem_iInter, mem_Iic, Subtype.exists, exists_prop] theorem HasBasis.liminf_eq_sSup_univ_of_empty {f : ι → α} {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) (i : ι') (hi : p i) (h'i : s i = ∅) : liminf f v = sSup univ := by simp [hv.eq_bot_iff.2 ⟨i, hi, h'i⟩, liminf_eq] theorem HasBasis.limsup_eq_sInf_iUnion_iInter {ι ι' : Type*} {f : ι → α} {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) : limsup f v = sInf (⋃ (j : Subtype p), ⋂ (i : s j), Ici (f i)) := HasBasis.liminf_eq_sSup_iUnion_iInter (α := αᵒᵈ) hv theorem HasBasis.limsup_eq_sInf_univ_of_empty {f : ι → α} {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) (i : ι') (hi : p i) (h'i : s i = ∅) : limsup f v = sInf univ := HasBasis.liminf_eq_sSup_univ_of_empty (α := αᵒᵈ) hv i hi h'i -- Porting note: simp_nf linter incorrectly says: lhs does not simplify when using simp on itself. @[simp, nolint simpNF] theorem liminf_nat_add (f : ℕ → α) (k : ℕ) : liminf (fun i => f (i + k)) atTop = liminf f atTop := by change liminf (f ∘ (· + k)) atTop = liminf f atTop rw [liminf, liminf, ← map_map, map_add_atTop_eq_nat] #align filter.liminf_nat_add Filter.liminf_nat_add -- Porting note: simp_nf linter incorrectly says: lhs does not simplify when using simp on itself. @[simp, nolint simpNF] theorem limsup_nat_add (f : ℕ → α) (k : ℕ) : limsup (fun i => f (i + k)) atTop = limsup f atTop := @liminf_nat_add αᵒᵈ _ f k #align filter.limsup_nat_add Filter.limsup_nat_add end ConditionallyCompleteLattice section CompleteLattice variable [CompleteLattice α] @[simp] theorem limsSup_bot : limsSup (⊥ : Filter α) = ⊥ := bot_unique <| sInf_le <| by simp set_option linter.uppercaseLean3 false in #align filter.Limsup_bot Filter.limsSup_bot @[simp] theorem limsup_bot (f : β → α) : limsup f ⊥ = ⊥ := by simp [limsup] @[simp] theorem limsInf_bot : limsInf (⊥ : Filter α) = ⊤ := top_unique <| le_sSup <| by simp set_option linter.uppercaseLean3 false in #align filter.Liminf_bot Filter.limsInf_bot @[simp] theorem liminf_bot (f : β → α) : liminf f ⊥ = ⊤ := by simp [liminf] @[simp] theorem limsSup_top : limsSup (⊤ : Filter α) = ⊤ := top_unique <| le_sInf <| by simp [eq_univ_iff_forall]; exact fun b hb => top_unique <| hb _ set_option linter.uppercaseLean3 false in #align filter.Limsup_top Filter.limsSup_top @[simp] theorem limsInf_top : limsInf (⊤ : Filter α) = ⊥ := bot_unique <| sSup_le <| by simp [eq_univ_iff_forall]; exact fun b hb => bot_unique <| hb _ set_option linter.uppercaseLean3 false in #align filter.Liminf_top Filter.limsInf_top @[simp] theorem blimsup_false {f : Filter β} {u : β → α} : (blimsup u f fun _ => False) = ⊥ := by simp [blimsup_eq] #align filter.blimsup_false Filter.blimsup_false @[simp] theorem bliminf_false {f : Filter β} {u : β → α} : (bliminf u f fun _ => False) = ⊤ := by simp [bliminf_eq] #align filter.bliminf_false Filter.bliminf_false /-- Same as limsup_const applied to `⊥` but without the `NeBot f` assumption -/ @[simp] theorem limsup_const_bot {f : Filter β} : limsup (fun _ : β => (⊥ : α)) f = (⊥ : α) := by rw [limsup_eq, eq_bot_iff] exact sInf_le (eventually_of_forall fun _ => le_rfl) #align filter.limsup_const_bot Filter.limsup_const_bot /-- Same as limsup_const applied to `⊤` but without the `NeBot f` assumption -/ @[simp] theorem liminf_const_top {f : Filter β} : liminf (fun _ : β => (⊤ : α)) f = (⊤ : α) := limsup_const_bot (α := αᵒᵈ) #align filter.liminf_const_top Filter.liminf_const_top theorem HasBasis.limsSup_eq_iInf_sSup {ι} {p : ι → Prop} {s} {f : Filter α} (h : f.HasBasis p s) : limsSup f = ⨅ (i) (_ : p i), sSup (s i) := le_antisymm (le_iInf₂ fun i hi => sInf_le <| h.eventually_iff.2 ⟨i, hi, fun _ => le_sSup⟩) (le_sInf fun _ ha => let ⟨_, hi, ha⟩ := h.eventually_iff.1 ha iInf₂_le_of_le _ hi <| sSup_le ha) set_option linter.uppercaseLean3 false in #align filter.has_basis.Limsup_eq_infi_Sup Filter.HasBasis.limsSup_eq_iInf_sSup theorem HasBasis.limsInf_eq_iSup_sInf {p : ι → Prop} {s : ι → Set α} {f : Filter α} (h : f.HasBasis p s) : limsInf f = ⨆ (i) (_ : p i), sInf (s i) := HasBasis.limsSup_eq_iInf_sSup (α := αᵒᵈ) h set_option linter.uppercaseLean3 false in #align filter.has_basis.Liminf_eq_supr_Inf Filter.HasBasis.limsInf_eq_iSup_sInf theorem limsSup_eq_iInf_sSup {f : Filter α} : limsSup f = ⨅ s ∈ f, sSup s := f.basis_sets.limsSup_eq_iInf_sSup set_option linter.uppercaseLean3 false in #align filter.Limsup_eq_infi_Sup Filter.limsSup_eq_iInf_sSup theorem limsInf_eq_iSup_sInf {f : Filter α} : limsInf f = ⨆ s ∈ f, sInf s := limsSup_eq_iInf_sSup (α := αᵒᵈ) set_option linter.uppercaseLean3 false in #align filter.Liminf_eq_supr_Inf Filter.limsInf_eq_iSup_sInf theorem limsup_le_iSup {f : Filter β} {u : β → α} : limsup u f ≤ ⨆ n, u n := limsup_le_of_le (by isBoundedDefault) (eventually_of_forall (le_iSup u)) #align filter.limsup_le_supr Filter.limsup_le_iSup theorem iInf_le_liminf {f : Filter β} {u : β → α} : ⨅ n, u n ≤ liminf u f := le_liminf_of_le (by isBoundedDefault) (eventually_of_forall (iInf_le u)) #align filter.infi_le_liminf Filter.iInf_le_liminf /-- In a complete lattice, the limsup of a function is the infimum over sets `s` in the filter of the supremum of the function over `s` -/ theorem limsup_eq_iInf_iSup {f : Filter β} {u : β → α} : limsup u f = ⨅ s ∈ f, ⨆ a ∈ s, u a := (f.basis_sets.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, id] #align filter.limsup_eq_infi_supr Filter.limsup_eq_iInf_iSup theorem limsup_eq_iInf_iSup_of_nat {u : ℕ → α} : limsup u atTop = ⨅ n : ℕ, ⨆ i ≥ n, u i := (atTop_basis.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, iInf_const]; rfl #align filter.limsup_eq_infi_supr_of_nat Filter.limsup_eq_iInf_iSup_of_nat theorem limsup_eq_iInf_iSup_of_nat' {u : ℕ → α} : limsup u atTop = ⨅ n : ℕ, ⨆ i : ℕ, u (i + n) := by simp only [limsup_eq_iInf_iSup_of_nat, iSup_ge_eq_iSup_nat_add] #align filter.limsup_eq_infi_supr_of_nat' Filter.limsup_eq_iInf_iSup_of_nat' theorem HasBasis.limsup_eq_iInf_iSup {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α} (h : f.HasBasis p s) : limsup u f = ⨅ (i) (_ : p i), ⨆ a ∈ s i, u a := (h.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, id] #align filter.has_basis.limsup_eq_infi_supr Filter.HasBasis.limsup_eq_iInf_iSup theorem blimsup_congr' {f : Filter β} {p q : β → Prop} {u : β → α} (h : ∀ᶠ x in f, u x ≠ ⊥ → (p x ↔ q x)) : blimsup u f p = blimsup u f q := by simp only [blimsup_eq] congr with a refine eventually_congr (h.mono fun b hb => ?_) rcases eq_or_ne (u b) ⊥ with hu | hu; · simp [hu] rw [hb hu] #align filter.blimsup_congr' Filter.blimsup_congr' theorem bliminf_congr' {f : Filter β} {p q : β → Prop} {u : β → α} (h : ∀ᶠ x in f, u x ≠ ⊤ → (p x ↔ q x)) : bliminf u f p = bliminf u f q := blimsup_congr' (α := αᵒᵈ) h #align filter.bliminf_congr' Filter.bliminf_congr' lemma HasBasis.blimsup_eq_iInf_iSup {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α} (hf : f.HasBasis p s) {q : β → Prop} : blimsup u f q = ⨅ (i) (_ : p i), ⨆ a ∈ s i, ⨆ (_ : q a), u a := by simp only [blimsup_eq_limsup, (hf.inf_principal _).limsup_eq_iInf_iSup, mem_inter_iff, iSup_and, mem_setOf_eq] theorem blimsup_eq_iInf_biSup {f : Filter β} {p : β → Prop} {u : β → α} : blimsup u f p = ⨅ s ∈ f, ⨆ (b) (_ : p b ∧ b ∈ s), u b := by simp only [f.basis_sets.blimsup_eq_iInf_iSup, iSup_and', id, and_comm] #align filter.blimsup_eq_infi_bsupr Filter.blimsup_eq_iInf_biSup theorem blimsup_eq_iInf_biSup_of_nat {p : ℕ → Prop} {u : ℕ → α} : blimsup u atTop p = ⨅ i, ⨆ (j) (_ : p j ∧ i ≤ j), u j := by simp only [atTop_basis.blimsup_eq_iInf_iSup, @and_comm (p _), iSup_and, mem_Ici, iInf_true] #align filter.blimsup_eq_infi_bsupr_of_nat Filter.blimsup_eq_iInf_biSup_of_nat /-- In a complete lattice, the liminf of a function is the infimum over sets `s` in the filter of the supremum of the function over `s` -/ theorem liminf_eq_iSup_iInf {f : Filter β} {u : β → α} : liminf u f = ⨆ s ∈ f, ⨅ a ∈ s, u a := limsup_eq_iInf_iSup (α := αᵒᵈ) #align filter.liminf_eq_supr_infi Filter.liminf_eq_iSup_iInf theorem liminf_eq_iSup_iInf_of_nat {u : ℕ → α} : liminf u atTop = ⨆ n : ℕ, ⨅ i ≥ n, u i := @limsup_eq_iInf_iSup_of_nat αᵒᵈ _ u #align filter.liminf_eq_supr_infi_of_nat Filter.liminf_eq_iSup_iInf_of_nat theorem liminf_eq_iSup_iInf_of_nat' {u : ℕ → α} : liminf u atTop = ⨆ n : ℕ, ⨅ i : ℕ, u (i + n) := @limsup_eq_iInf_iSup_of_nat' αᵒᵈ _ _ #align filter.liminf_eq_supr_infi_of_nat' Filter.liminf_eq_iSup_iInf_of_nat' theorem HasBasis.liminf_eq_iSup_iInf {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α} (h : f.HasBasis p s) : liminf u f = ⨆ (i) (_ : p i), ⨅ a ∈ s i, u a := HasBasis.limsup_eq_iInf_iSup (α := αᵒᵈ) h #align filter.has_basis.liminf_eq_supr_infi Filter.HasBasis.liminf_eq_iSup_iInf theorem bliminf_eq_iSup_biInf {f : Filter β} {p : β → Prop} {u : β → α} : bliminf u f p = ⨆ s ∈ f, ⨅ (b) (_ : p b ∧ b ∈ s), u b := @blimsup_eq_iInf_biSup αᵒᵈ β _ f p u #align filter.bliminf_eq_supr_binfi Filter.bliminf_eq_iSup_biInf theorem bliminf_eq_iSup_biInf_of_nat {p : ℕ → Prop} {u : ℕ → α} : bliminf u atTop p = ⨆ i, ⨅ (j) (_ : p j ∧ i ≤ j), u j := @blimsup_eq_iInf_biSup_of_nat αᵒᵈ _ p u #align filter.bliminf_eq_supr_binfi_of_nat Filter.bliminf_eq_iSup_biInf_of_nat theorem limsup_eq_sInf_sSup {ι R : Type*} (F : Filter ι) [CompleteLattice R] (a : ι → R) : limsup a F = sInf ((fun I => sSup (a '' I)) '' F.sets) := by apply le_antisymm · rw [limsup_eq] refine sInf_le_sInf fun x hx => ?_ rcases (mem_image _ F.sets x).mp hx with ⟨I, ⟨I_mem_F, hI⟩⟩ filter_upwards [I_mem_F] with i hi exact hI ▸ le_sSup (mem_image_of_mem _ hi) · refine le_sInf fun b hb => sInf_le_of_le (mem_image_of_mem _ hb) <| sSup_le ?_ rintro _ ⟨_, h, rfl⟩ exact h set_option linter.uppercaseLean3 false in #align filter.limsup_eq_Inf_Sup Filter.limsup_eq_sInf_sSup theorem liminf_eq_sSup_sInf {ι R : Type*} (F : Filter ι) [CompleteLattice R] (a : ι → R) : liminf a F = sSup ((fun I => sInf (a '' I)) '' F.sets) := @Filter.limsup_eq_sInf_sSup ι (OrderDual R) _ _ a set_option linter.uppercaseLean3 false in #align filter.liminf_eq_Sup_Inf Filter.liminf_eq_sSup_sInf theorem liminf_le_of_frequently_le' {α β} [CompleteLattice β] {f : Filter α} {u : α → β} {x : β} (h : ∃ᶠ a in f, u a ≤ x) : liminf u f ≤ x := by rw [liminf_eq] refine sSup_le fun b hb => ?_ have hbx : ∃ᶠ _ in f, b ≤ x := by revert h rw [← not_imp_not, not_frequently, not_frequently] exact fun h => hb.mp (h.mono fun a hbx hba hax => hbx (hba.trans hax)) exact hbx.exists.choose_spec #align filter.liminf_le_of_frequently_le' Filter.liminf_le_of_frequently_le' theorem le_limsup_of_frequently_le' {α β} [CompleteLattice β] {f : Filter α} {u : α → β} {x : β} (h : ∃ᶠ a in f, x ≤ u a) : x ≤ limsup u f := liminf_le_of_frequently_le' (β := βᵒᵈ) h #align filter.le_limsup_of_frequently_le' Filter.le_limsup_of_frequently_le' /-- If `f : α → α` is a morphism of complete lattices, then the limsup of its iterates of any `a : α` is a fixed point. -/ @[simp]
Mathlib/Order/LiminfLimsup.lean
953
962
theorem CompleteLatticeHom.apply_limsup_iterate (f : CompleteLatticeHom α α) (a : α) : f (limsup (fun n => f^[n] a) atTop) = limsup (fun n => f^[n] a) atTop := by
rw [limsup_eq_iInf_iSup_of_nat', map_iInf] simp_rw [_root_.map_iSup, ← Function.comp_apply (f := f), ← Function.iterate_succ' f, ← Nat.add_succ] conv_rhs => rw [iInf_split _ (0 < ·)] simp only [not_lt, Nat.le_zero, iInf_iInf_eq_left, add_zero, iInf_nat_gt_zero_eq, left_eq_inf] refine (iInf_le (fun i => ⨆ j, f^[j + (i + 1)] a) 0).trans ?_ simp only [zero_add, Function.comp_apply, iSup_le_iff] exact fun i => le_iSup (fun i => f^[i] a) (i + 1)
/- Copyright (c) 2023 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Geometry.Euclidean.Inversion.Basic import Mathlib.Geometry.Euclidean.PerpBisector /-! # Image of a hyperplane under inversion In this file we prove that the inversion with center `c` and radius `R ≠ 0` maps a sphere passing through the center to a hyperplane, and vice versa. More precisely, it maps a sphere with center `y ≠ c` and radius `dist y c` to the hyperplane `AffineSubspace.perpBisector c (EuclideanGeometry.inversion c R y)`. The exact statements are a little more complicated because `EuclideanGeometry.inversion c R` sends the center to itself, not to a point at infinity. We also prove that the inversion sends an affine subspace passing through the center to itself. ## Keywords inversion -/ open Metric Function AffineMap Set AffineSubspace open scoped Topology variable {V P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] {c x y : P} {R : ℝ} namespace EuclideanGeometry /-- The inversion with center `c` and radius `R` maps a sphere passing through the center to a hyperplane. -/ theorem inversion_mem_perpBisector_inversion_iff (hR : R ≠ 0) (hx : x ≠ c) (hy : y ≠ c) : inversion c R x ∈ perpBisector c (inversion c R y) ↔ dist x y = dist y c := by rw [mem_perpBisector_iff_dist_eq, dist_inversion_inversion hx hy, dist_inversion_center] have hx' := dist_ne_zero.2 hx have hy' := dist_ne_zero.2 hy field_simp [mul_assoc, mul_comm, hx, hx.symm, eq_comm] /-- The inversion with center `c` and radius `R` maps a sphere passing through the center to a hyperplane. -/ theorem inversion_mem_perpBisector_inversion_iff' (hR : R ≠ 0) (hy : y ≠ c) : inversion c R x ∈ perpBisector c (inversion c R y) ↔ dist x y = dist y c ∧ x ≠ c := by rcases eq_or_ne x c with rfl | hx · simp [*] · simp [inversion_mem_perpBisector_inversion_iff hR hx hy, hx] theorem preimage_inversion_perpBisector_inversion (hR : R ≠ 0) (hy : y ≠ c) : inversion c R ⁻¹' perpBisector c (inversion c R y) = sphere y (dist y c) \ {c} := Set.ext fun _ ↦ inversion_mem_perpBisector_inversion_iff' hR hy theorem preimage_inversion_perpBisector (hR : R ≠ 0) (hy : y ≠ c) : inversion c R ⁻¹' perpBisector c y = sphere (inversion c R y) (R ^ 2 / dist y c) \ {c} := by rw [← dist_inversion_center, ← preimage_inversion_perpBisector_inversion hR, inversion_inversion] <;> simp [*] theorem image_inversion_perpBisector (hR : R ≠ 0) (hy : y ≠ c) : inversion c R '' perpBisector c y = sphere (inversion c R y) (R ^ 2 / dist y c) \ {c} := by rw [image_eq_preimage_of_inverse (inversion_involutive _ hR) (inversion_involutive _ hR), preimage_inversion_perpBisector hR hy] theorem preimage_inversion_sphere_dist_center (hR : R ≠ 0) (hy : y ≠ c) : inversion c R ⁻¹' sphere y (dist y c) = insert c (perpBisector c (inversion c R y) : Set P) := by ext x rcases eq_or_ne x c with rfl | hx; · simp [dist_comm] rw [mem_preimage, mem_sphere, ← inversion_mem_perpBisector_inversion_iff hR] <;> simp [*]
Mathlib/Geometry/Euclidean/Inversion/ImageHyperplane.lean
73
76
theorem image_inversion_sphere_dist_center (hR : R ≠ 0) (hy : y ≠ c) : inversion c R '' sphere y (dist y c) = insert c (perpBisector c (inversion c R y) : Set P) := by
rw [image_eq_preimage_of_inverse (inversion_involutive _ hR) (inversion_involutive _ hR), preimage_inversion_sphere_dist_center hR hy]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Jeremy Avigad -/ import Mathlib.Order.Filter.Lift import Mathlib.Topology.Defs.Filter #align_import topology.basic from "leanprover-community/mathlib"@"e354e865255654389cc46e6032160238df2e0f40" /-! # Basic theory of topological spaces. The main definition is the type class `TopologicalSpace X` which endows a type `X` with a topology. Then `Set X` gets predicates `IsOpen`, `IsClosed` and functions `interior`, `closure` and `frontier`. Each point `x` of `X` gets a neighborhood filter `𝓝 x`. A filter `F` on `X` has `x` as a cluster point if `ClusterPt x F : 𝓝 x ⊓ F ≠ ⊥`. A map `f : α → X` clusters at `x` along `F : Filter α` if `MapClusterPt x F f : ClusterPt x (map f F)`. In particular the notion of cluster point of a sequence `u` is `MapClusterPt x atTop u`. For topological spaces `X` and `Y`, a function `f : X → Y` and a point `x : X`, `ContinuousAt f x` means `f` is continuous at `x`, and global continuity is `Continuous f`. There is also a version of continuity `PContinuous` for partially defined functions. ## Notation The following notation is introduced elsewhere and it heavily used in this file. * `𝓝 x`: the filter `nhds x` of neighborhoods of a point `x`; * `𝓟 s`: the principal filter of a set `s`; * `𝓝[s] x`: the filter `nhdsWithin x s` of neighborhoods of a point `x` within a set `s`; * `𝓝[≠] x`: the filter `nhdsWithin x {x}ᶜ` of punctured neighborhoods of `x`. ## Implementation notes Topology in mathlib heavily uses filters (even more than in Bourbaki). See explanations in <https://leanprover-community.github.io/theories/topology.html>. ## References * [N. Bourbaki, *General Topology*][bourbaki1966] * [I. M. James, *Topologies and Uniformities*][james1999] ## Tags topological space, interior, closure, frontier, neighborhood, continuity, continuous function -/ noncomputable section open Set Filter universe u v w x /-! ### Topological spaces -/ /-- A constructor for topologies by specifying the closed sets, and showing that they satisfy the appropriate conditions. -/ def TopologicalSpace.ofClosed {X : Type u} (T : Set (Set X)) (empty_mem : ∅ ∈ T) (sInter_mem : ∀ A, A ⊆ T → ⋂₀ A ∈ T) (union_mem : ∀ A, A ∈ T → ∀ B, B ∈ T → A ∪ B ∈ T) : TopologicalSpace X where IsOpen X := Xᶜ ∈ T isOpen_univ := by simp [empty_mem] isOpen_inter s t hs ht := by simpa only [compl_inter] using union_mem sᶜ hs tᶜ ht isOpen_sUnion s hs := by simp only [Set.compl_sUnion] exact sInter_mem (compl '' s) fun z ⟨y, hy, hz⟩ => hz ▸ hs y hy #align topological_space.of_closed TopologicalSpace.ofClosed section TopologicalSpace variable {X : Type u} {Y : Type v} {ι : Sort w} {α β : Type*} {x : X} {s s₁ s₂ t : Set X} {p p₁ p₂ : X → Prop} open Topology lemma isOpen_mk {p h₁ h₂ h₃} : IsOpen[⟨p, h₁, h₂, h₃⟩] s ↔ p s := Iff.rfl #align is_open_mk isOpen_mk @[ext] protected theorem TopologicalSpace.ext : ∀ {f g : TopologicalSpace X}, IsOpen[f] = IsOpen[g] → f = g | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl #align topological_space_eq TopologicalSpace.ext section variable [TopologicalSpace X] end protected theorem TopologicalSpace.ext_iff {t t' : TopologicalSpace X} : t = t' ↔ ∀ s, IsOpen[t] s ↔ IsOpen[t'] s := ⟨fun h s => h ▸ Iff.rfl, fun h => by ext; exact h _⟩ #align topological_space_eq_iff TopologicalSpace.ext_iff theorem isOpen_fold {t : TopologicalSpace X} : t.IsOpen s = IsOpen[t] s := rfl #align is_open_fold isOpen_fold variable [TopologicalSpace X] theorem isOpen_iUnion {f : ι → Set X} (h : ∀ i, IsOpen (f i)) : IsOpen (⋃ i, f i) := isOpen_sUnion (forall_mem_range.2 h) #align is_open_Union isOpen_iUnion theorem isOpen_biUnion {s : Set α} {f : α → Set X} (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋃ i ∈ s, f i) := isOpen_iUnion fun i => isOpen_iUnion fun hi => h i hi #align is_open_bUnion isOpen_biUnion theorem IsOpen.union (h₁ : IsOpen s₁) (h₂ : IsOpen s₂) : IsOpen (s₁ ∪ s₂) := by rw [union_eq_iUnion]; exact isOpen_iUnion (Bool.forall_bool.2 ⟨h₂, h₁⟩) #align is_open.union IsOpen.union lemma isOpen_iff_of_cover {f : α → Set X} (ho : ∀ i, IsOpen (f i)) (hU : (⋃ i, f i) = univ) : IsOpen s ↔ ∀ i, IsOpen (f i ∩ s) := by refine ⟨fun h i ↦ (ho i).inter h, fun h ↦ ?_⟩ rw [← s.inter_univ, inter_comm, ← hU, iUnion_inter] exact isOpen_iUnion fun i ↦ h i @[simp] theorem isOpen_empty : IsOpen (∅ : Set X) := by rw [← sUnion_empty]; exact isOpen_sUnion fun a => False.elim #align is_open_empty isOpen_empty theorem Set.Finite.isOpen_sInter {s : Set (Set X)} (hs : s.Finite) : (∀ t ∈ s, IsOpen t) → IsOpen (⋂₀ s) := Finite.induction_on hs (fun _ => by rw [sInter_empty]; exact isOpen_univ) fun _ _ ih h => by simp only [sInter_insert, forall_mem_insert] at h ⊢ exact h.1.inter (ih h.2) #align is_open_sInter Set.Finite.isOpen_sInter theorem Set.Finite.isOpen_biInter {s : Set α} {f : α → Set X} (hs : s.Finite) (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋂ i ∈ s, f i) := sInter_image f s ▸ (hs.image _).isOpen_sInter (forall_mem_image.2 h) #align is_open_bInter Set.Finite.isOpen_biInter theorem isOpen_iInter_of_finite [Finite ι] {s : ι → Set X} (h : ∀ i, IsOpen (s i)) : IsOpen (⋂ i, s i) := (finite_range _).isOpen_sInter (forall_mem_range.2 h) #align is_open_Inter isOpen_iInter_of_finite theorem isOpen_biInter_finset {s : Finset α} {f : α → Set X} (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋂ i ∈ s, f i) := s.finite_toSet.isOpen_biInter h #align is_open_bInter_finset isOpen_biInter_finset @[simp] -- Porting note: added `simp` theorem isOpen_const {p : Prop} : IsOpen { _x : X | p } := by by_cases p <;> simp [*] #align is_open_const isOpen_const theorem IsOpen.and : IsOpen { x | p₁ x } → IsOpen { x | p₂ x } → IsOpen { x | p₁ x ∧ p₂ x } := IsOpen.inter #align is_open.and IsOpen.and @[simp] theorem isOpen_compl_iff : IsOpen sᶜ ↔ IsClosed s := ⟨fun h => ⟨h⟩, fun h => h.isOpen_compl⟩ #align is_open_compl_iff isOpen_compl_iff
Mathlib/Topology/Basic.lean
164
167
theorem TopologicalSpace.ext_iff_isClosed {t₁ t₂ : TopologicalSpace X} : t₁ = t₂ ↔ ∀ s, IsClosed[t₁] s ↔ IsClosed[t₂] s := by
rw [TopologicalSpace.ext_iff, compl_surjective.forall] simp only [@isOpen_compl_iff _ _ t₁, @isOpen_compl_iff _ _ t₂]
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Moritz Doll -/ import Mathlib.LinearAlgebra.Prod #align_import linear_algebra.linear_pmap from "leanprover-community/mathlib"@"8b981918a93bc45a8600de608cde7944a80d92b9" /-! # Partially defined linear maps A `LinearPMap R E F` or `E →ₗ.[R] F` is a linear map from a submodule of `E` to `F`. We define a `SemilatticeInf` with `OrderBot` instance on this, and define three operations: * `mkSpanSingleton` defines a partial linear map defined on the span of a singleton. * `sup` takes two partial linear maps `f`, `g` that agree on the intersection of their domains, and returns the unique partial linear map on `f.domain ⊔ g.domain` that extends both `f` and `g`. * `sSup` takes a `DirectedOn (· ≤ ·)` set of partial linear maps, and returns the unique partial linear map on the `sSup` of their domains that extends all these maps. Moreover, we define * `LinearPMap.graph` is the graph of the partial linear map viewed as a submodule of `E × F`. Partially defined maps are currently used in `Mathlib` to prove Hahn-Banach theorem and its variations. Namely, `LinearPMap.sSup` implies that every chain of `LinearPMap`s is bounded above. They are also the basis for the theory of unbounded operators. -/ universe u v w /-- A `LinearPMap R E F` or `E →ₗ.[R] F` is a linear map from a submodule of `E` to `F`. -/ structure LinearPMap (R : Type u) [Ring R] (E : Type v) [AddCommGroup E] [Module R E] (F : Type w) [AddCommGroup F] [Module R F] where domain : Submodule R E toFun : domain →ₗ[R] F #align linear_pmap LinearPMap @[inherit_doc] notation:25 E " →ₗ.[" R:25 "] " F:0 => LinearPMap R E F variable {R : Type*} [Ring R] {E : Type*} [AddCommGroup E] [Module R E] {F : Type*} [AddCommGroup F] [Module R F] {G : Type*} [AddCommGroup G] [Module R G] namespace LinearPMap open Submodule -- Porting note: A new definition underlying a coercion `↑`. @[coe] def toFun' (f : E →ₗ.[R] F) : f.domain → F := f.toFun instance : CoeFun (E →ₗ.[R] F) fun f : E →ₗ.[R] F => f.domain → F := ⟨toFun'⟩ @[simp] theorem toFun_eq_coe (f : E →ₗ.[R] F) (x : f.domain) : f.toFun x = f x := rfl #align linear_pmap.to_fun_eq_coe LinearPMap.toFun_eq_coe @[ext] theorem ext {f g : E →ₗ.[R] F} (h : f.domain = g.domain) (h' : ∀ ⦃x : f.domain⦄ ⦃y : g.domain⦄ (_h : (x : E) = y), f x = g y) : f = g := by rcases f with ⟨f_dom, f⟩ rcases g with ⟨g_dom, g⟩ obtain rfl : f_dom = g_dom := h obtain rfl : f = g := LinearMap.ext fun x => h' rfl rfl #align linear_pmap.ext LinearPMap.ext @[simp] theorem map_zero (f : E →ₗ.[R] F) : f 0 = 0 := f.toFun.map_zero #align linear_pmap.map_zero LinearPMap.map_zero theorem ext_iff {f g : E →ₗ.[R] F} : f = g ↔ ∃ _domain_eq : f.domain = g.domain, ∀ ⦃x : f.domain⦄ ⦃y : g.domain⦄ (_h : (x : E) = y), f x = g y := ⟨fun EQ => EQ ▸ ⟨rfl, fun x y h => by congr exact mod_cast h⟩, fun ⟨deq, feq⟩ => ext deq feq⟩ #align linear_pmap.ext_iff LinearPMap.ext_iff theorem ext' {s : Submodule R E} {f g : s →ₗ[R] F} (h : f = g) : mk s f = mk s g := h ▸ rfl #align linear_pmap.ext' LinearPMap.ext' theorem map_add (f : E →ₗ.[R] F) (x y : f.domain) : f (x + y) = f x + f y := f.toFun.map_add x y #align linear_pmap.map_add LinearPMap.map_add theorem map_neg (f : E →ₗ.[R] F) (x : f.domain) : f (-x) = -f x := f.toFun.map_neg x #align linear_pmap.map_neg LinearPMap.map_neg theorem map_sub (f : E →ₗ.[R] F) (x y : f.domain) : f (x - y) = f x - f y := f.toFun.map_sub x y #align linear_pmap.map_sub LinearPMap.map_sub theorem map_smul (f : E →ₗ.[R] F) (c : R) (x : f.domain) : f (c • x) = c • f x := f.toFun.map_smul c x #align linear_pmap.map_smul LinearPMap.map_smul @[simp] theorem mk_apply (p : Submodule R E) (f : p →ₗ[R] F) (x : p) : mk p f x = f x := rfl #align linear_pmap.mk_apply LinearPMap.mk_apply /-- The unique `LinearPMap` on `R ∙ x` that sends `x` to `y`. This version works for modules over rings, and requires a proof of `∀ c, c • x = 0 → c • y = 0`. -/ noncomputable def mkSpanSingleton' (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) : E →ₗ.[R] F where domain := R ∙ x toFun := have H : ∀ c₁ c₂ : R, c₁ • x = c₂ • x → c₁ • y = c₂ • y := by intro c₁ c₂ h rw [← sub_eq_zero, ← sub_smul] at h ⊢ exact H _ h { toFun := fun z => Classical.choose (mem_span_singleton.1 z.prop) • y -- Porting note(#12129): additional beta reduction needed -- Porting note: Were `Classical.choose_spec (mem_span_singleton.1 _)`. map_add' := fun y z => by beta_reduce rw [← add_smul] apply H simp only [add_smul, sub_smul, fun w : R ∙ x => Classical.choose_spec (mem_span_singleton.1 w.prop)] apply coe_add map_smul' := fun c z => by beta_reduce rw [smul_smul] apply H simp only [mul_smul, fun w : R ∙ x => Classical.choose_spec (mem_span_singleton.1 w.prop)] apply coe_smul } #align linear_pmap.mk_span_singleton' LinearPMap.mkSpanSingleton' @[simp] theorem domain_mkSpanSingleton (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) : (mkSpanSingleton' x y H).domain = R ∙ x := rfl #align linear_pmap.domain_mk_span_singleton LinearPMap.domain_mkSpanSingleton @[simp] theorem mkSpanSingleton'_apply (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) (c : R) (h) : mkSpanSingleton' x y H ⟨c • x, h⟩ = c • y := by dsimp [mkSpanSingleton'] rw [← sub_eq_zero, ← sub_smul] apply H simp only [sub_smul, one_smul, sub_eq_zero] apply Classical.choose_spec (mem_span_singleton.1 h) #align linear_pmap.mk_span_singleton'_apply LinearPMap.mkSpanSingleton'_apply @[simp] theorem mkSpanSingleton'_apply_self (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) (h) : mkSpanSingleton' x y H ⟨x, h⟩ = y := by -- Porting note: A placeholder should be specified before `convert`. have := by refine mkSpanSingleton'_apply x y H 1 ?_; rwa [one_smul] convert this <;> rw [one_smul] #align linear_pmap.mk_span_singleton'_apply_self LinearPMap.mkSpanSingleton'_apply_self /-- The unique `LinearPMap` on `span R {x}` that sends a non-zero vector `x` to `y`. This version works for modules over division rings. -/ noncomputable abbrev mkSpanSingleton {K E F : Type*} [DivisionRing K] [AddCommGroup E] [Module K E] [AddCommGroup F] [Module K F] (x : E) (y : F) (hx : x ≠ 0) : E →ₗ.[K] F := mkSpanSingleton' x y fun c hc => (smul_eq_zero.1 hc).elim (fun hc => by rw [hc, zero_smul]) fun hx' => absurd hx' hx #align linear_pmap.mk_span_singleton LinearPMap.mkSpanSingleton theorem mkSpanSingleton_apply (K : Type*) {E F : Type*} [DivisionRing K] [AddCommGroup E] [Module K E] [AddCommGroup F] [Module K F] {x : E} (hx : x ≠ 0) (y : F) : mkSpanSingleton x y hx ⟨x, (Submodule.mem_span_singleton_self x : x ∈ Submodule.span K {x})⟩ = y := LinearPMap.mkSpanSingleton'_apply_self _ _ _ _ #align linear_pmap.mk_span_singleton_apply LinearPMap.mkSpanSingleton_apply /-- Projection to the first coordinate as a `LinearPMap` -/ protected def fst (p : Submodule R E) (p' : Submodule R F) : E × F →ₗ.[R] E where domain := p.prod p' toFun := (LinearMap.fst R E F).comp (p.prod p').subtype #align linear_pmap.fst LinearPMap.fst @[simp] theorem fst_apply (p : Submodule R E) (p' : Submodule R F) (x : p.prod p') : LinearPMap.fst p p' x = (x : E × F).1 := rfl #align linear_pmap.fst_apply LinearPMap.fst_apply /-- Projection to the second coordinate as a `LinearPMap` -/ protected def snd (p : Submodule R E) (p' : Submodule R F) : E × F →ₗ.[R] F where domain := p.prod p' toFun := (LinearMap.snd R E F).comp (p.prod p').subtype #align linear_pmap.snd LinearPMap.snd @[simp] theorem snd_apply (p : Submodule R E) (p' : Submodule R F) (x : p.prod p') : LinearPMap.snd p p' x = (x : E × F).2 := rfl #align linear_pmap.snd_apply LinearPMap.snd_apply instance le : LE (E →ₗ.[R] F) := ⟨fun f g => f.domain ≤ g.domain ∧ ∀ ⦃x : f.domain⦄ ⦃y : g.domain⦄ (_h : (x : E) = y), f x = g y⟩ #align linear_pmap.has_le LinearPMap.le theorem apply_comp_inclusion {T S : E →ₗ.[R] F} (h : T ≤ S) (x : T.domain) : T x = S (Submodule.inclusion h.1 x) := h.2 rfl #align linear_pmap.apply_comp_of_le LinearPMap.apply_comp_inclusion theorem exists_of_le {T S : E →ₗ.[R] F} (h : T ≤ S) (x : T.domain) : ∃ y : S.domain, (x : E) = y ∧ T x = S y := ⟨⟨x.1, h.1 x.2⟩, ⟨rfl, h.2 rfl⟩⟩ #align linear_pmap.exists_of_le LinearPMap.exists_of_le theorem eq_of_le_of_domain_eq {f g : E →ₗ.[R] F} (hle : f ≤ g) (heq : f.domain = g.domain) : f = g := ext heq hle.2 #align linear_pmap.eq_of_le_of_domain_eq LinearPMap.eq_of_le_of_domain_eq /-- Given two partial linear maps `f`, `g`, the set of points `x` such that both `f` and `g` are defined at `x` and `f x = g x` form a submodule. -/ def eqLocus (f g : E →ₗ.[R] F) : Submodule R E where carrier := { x | ∃ (hf : x ∈ f.domain) (hg : x ∈ g.domain), f ⟨x, hf⟩ = g ⟨x, hg⟩ } zero_mem' := ⟨zero_mem _, zero_mem _, f.map_zero.trans g.map_zero.symm⟩ add_mem' := fun {x y} ⟨hfx, hgx, hx⟩ ⟨hfy, hgy, hy⟩ => ⟨add_mem hfx hfy, add_mem hgx hgy, by erw [f.map_add ⟨x, hfx⟩ ⟨y, hfy⟩, g.map_add ⟨x, hgx⟩ ⟨y, hgy⟩, hx, hy]⟩ -- Porting note: `by rintro` is required, or error of a free variable happens. smul_mem' := by rintro c x ⟨hfx, hgx, hx⟩ exact ⟨smul_mem _ c hfx, smul_mem _ c hgx, by erw [f.map_smul c ⟨x, hfx⟩, g.map_smul c ⟨x, hgx⟩, hx]⟩ #align linear_pmap.eq_locus LinearPMap.eqLocus instance inf : Inf (E →ₗ.[R] F) := ⟨fun f g => ⟨f.eqLocus g, f.toFun.comp <| inclusion fun _x hx => hx.fst⟩⟩ #align linear_pmap.has_inf LinearPMap.inf instance bot : Bot (E →ₗ.[R] F) := ⟨⟨⊥, 0⟩⟩ #align linear_pmap.has_bot LinearPMap.bot instance inhabited : Inhabited (E →ₗ.[R] F) := ⟨⊥⟩ #align linear_pmap.inhabited LinearPMap.inhabited instance semilatticeInf : SemilatticeInf (E →ₗ.[R] F) where le := (· ≤ ·) le_refl f := ⟨le_refl f.domain, fun x y h => Subtype.eq h ▸ rfl⟩ le_trans := fun f g h ⟨fg_le, fg_eq⟩ ⟨gh_le, gh_eq⟩ => ⟨le_trans fg_le gh_le, fun x z hxz => have hxy : (x : E) = inclusion fg_le x := rfl (fg_eq hxy).trans (gh_eq <| hxy.symm.trans hxz)⟩ le_antisymm f g fg gf := eq_of_le_of_domain_eq fg (le_antisymm fg.1 gf.1) inf := (· ⊓ ·) -- Porting note: `by rintro` is required, or error of a metavariable happens. le_inf := by rintro f g h ⟨fg_le, fg_eq⟩ ⟨fh_le, fh_eq⟩ exact ⟨fun x hx => ⟨fg_le hx, fh_le hx, by -- Porting note: `[exact ⟨x, hx⟩, rfl, rfl]` → `[skip, exact ⟨x, hx⟩, skip] <;> rfl` convert (fg_eq _).symm.trans (fh_eq _) <;> [skip; exact ⟨x, hx⟩; skip] <;> rfl⟩, fun x ⟨y, yg, hy⟩ h => by apply fg_eq exact h⟩ inf_le_left f g := ⟨fun x hx => hx.fst, fun x y h => congr_arg f <| Subtype.eq <| h⟩ inf_le_right f g := ⟨fun x hx => hx.snd.fst, fun ⟨x, xf, xg, hx⟩ y h => hx.trans <| congr_arg g <| Subtype.eq <| h⟩ #align linear_pmap.semilattice_inf LinearPMap.semilatticeInf instance orderBot : OrderBot (E →ₗ.[R] F) where bot := ⊥ bot_le f := ⟨bot_le, fun x y h => by have hx : x = 0 := Subtype.eq ((mem_bot R).1 x.2) have hy : y = 0 := Subtype.eq (h.symm.trans (congr_arg _ hx)) rw [hx, hy, map_zero, map_zero]⟩ #align linear_pmap.order_bot LinearPMap.orderBot theorem le_of_eqLocus_ge {f g : E →ₗ.[R] F} (H : f.domain ≤ f.eqLocus g) : f ≤ g := suffices f ≤ f ⊓ g from le_trans this inf_le_right ⟨H, fun _x _y hxy => ((inf_le_left : f ⊓ g ≤ f).2 hxy.symm).symm⟩ #align linear_pmap.le_of_eq_locus_ge LinearPMap.le_of_eqLocus_ge theorem domain_mono : StrictMono (@domain R _ E _ _ F _ _) := fun _f _g hlt => lt_of_le_of_ne hlt.1.1 fun heq => ne_of_lt hlt <| eq_of_le_of_domain_eq (le_of_lt hlt) heq #align linear_pmap.domain_mono LinearPMap.domain_mono private theorem sup_aux (f g : E →ₗ.[R] F) (h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : ∃ fg : ↥(f.domain ⊔ g.domain) →ₗ[R] F, ∀ (x : f.domain) (y : g.domain) (z : ↥(f.domain ⊔ g.domain)), (x : E) + y = ↑z → fg z = f x + g y := by choose x hx y hy hxy using fun z : ↥(f.domain ⊔ g.domain) => mem_sup.1 z.prop set fg := fun z => f ⟨x z, hx z⟩ + g ⟨y z, hy z⟩ have fg_eq : ∀ (x' : f.domain) (y' : g.domain) (z' : ↥(f.domain ⊔ g.domain)) (_H : (x' : E) + y' = z'), fg z' = f x' + g y' := by intro x' y' z' H dsimp [fg] rw [add_comm, ← sub_eq_sub_iff_add_eq_add, eq_comm, ← map_sub, ← map_sub] apply h simp only [← eq_sub_iff_add_eq] at hxy simp only [AddSubgroupClass.coe_sub, coe_mk, coe_mk, hxy, ← sub_add, ← sub_sub, sub_self, zero_sub, ← H] apply neg_add_eq_sub use { toFun := fg, map_add' := ?_, map_smul' := ?_ }, fg_eq · rintro ⟨z₁, hz₁⟩ ⟨z₂, hz₂⟩ rw [← add_assoc, add_right_comm (f _), ← map_add, add_assoc, ← map_add] apply fg_eq simp only [coe_add, coe_mk, ← add_assoc] rw [add_right_comm (x _), hxy, add_assoc, hxy, coe_mk, coe_mk] · intro c z rw [smul_add, ← map_smul, ← map_smul] apply fg_eq simp only [coe_smul, coe_mk, ← smul_add, hxy, RingHom.id_apply] /-- Given two partial linear maps that agree on the intersection of their domains, `f.sup g h` is the unique partial linear map on `f.domain ⊔ g.domain` that agrees with `f` and `g`. -/ protected noncomputable def sup (f g : E →ₗ.[R] F) (h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : E →ₗ.[R] F := ⟨_, Classical.choose (sup_aux f g h)⟩ #align linear_pmap.sup LinearPMap.sup @[simp] theorem domain_sup (f g : E →ₗ.[R] F) (h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : (f.sup g h).domain = f.domain ⊔ g.domain := rfl #align linear_pmap.domain_sup LinearPMap.domain_sup theorem sup_apply {f g : E →ₗ.[R] F} (H : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) (x : f.domain) (y : g.domain) (z : ↥(f.domain ⊔ g.domain)) (hz : (↑x : E) + ↑y = ↑z) : f.sup g H z = f x + g y := Classical.choose_spec (sup_aux f g H) x y z hz #align linear_pmap.sup_apply LinearPMap.sup_apply protected theorem left_le_sup (f g : E →ₗ.[R] F) (h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : f ≤ f.sup g h := by refine ⟨le_sup_left, fun z₁ z₂ hz => ?_⟩ rw [← add_zero (f _), ← g.map_zero] refine (sup_apply h _ _ _ ?_).symm simpa #align linear_pmap.left_le_sup LinearPMap.left_le_sup protected theorem right_le_sup (f g : E →ₗ.[R] F) (h : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) : g ≤ f.sup g h := by refine ⟨le_sup_right, fun z₁ z₂ hz => ?_⟩ rw [← zero_add (g _), ← f.map_zero] refine (sup_apply h _ _ _ ?_).symm simpa #align linear_pmap.right_le_sup LinearPMap.right_le_sup protected theorem sup_le {f g h : E →ₗ.[R] F} (H : ∀ (x : f.domain) (y : g.domain), (x : E) = y → f x = g y) (fh : f ≤ h) (gh : g ≤ h) : f.sup g H ≤ h := have Hf : f ≤ f.sup g H ⊓ h := le_inf (f.left_le_sup g H) fh have Hg : g ≤ f.sup g H ⊓ h := le_inf (f.right_le_sup g H) gh le_of_eqLocus_ge <| sup_le Hf.1 Hg.1 #align linear_pmap.sup_le LinearPMap.sup_le /-- Hypothesis for `LinearPMap.sup` holds, if `f.domain` is disjoint with `g.domain`. -/ theorem sup_h_of_disjoint (f g : E →ₗ.[R] F) (h : Disjoint f.domain g.domain) (x : f.domain) (y : g.domain) (hxy : (x : E) = y) : f x = g y := by rw [disjoint_def] at h have hy : y = 0 := Subtype.eq (h y (hxy ▸ x.2) y.2) have hx : x = 0 := Subtype.eq (hxy.trans <| congr_arg _ hy) simp [*] #align linear_pmap.sup_h_of_disjoint LinearPMap.sup_h_of_disjoint /-! ### Algebraic operations -/ section Zero instance instZero : Zero (E →ₗ.[R] F) := ⟨⊤, 0⟩ @[simp] theorem zero_domain : (0 : E →ₗ.[R] F).domain = ⊤ := rfl @[simp] theorem zero_apply (x : (⊤ : Submodule R E)) : (0 : E →ₗ.[R] F) x = 0 := rfl end Zero section SMul variable {M N : Type*} [Monoid M] [DistribMulAction M F] [SMulCommClass R M F] variable [Monoid N] [DistribMulAction N F] [SMulCommClass R N F] instance instSMul : SMul M (E →ₗ.[R] F) := ⟨fun a f => { domain := f.domain toFun := a • f.toFun }⟩ #align linear_pmap.has_smul LinearPMap.instSMul @[simp] theorem smul_domain (a : M) (f : E →ₗ.[R] F) : (a • f).domain = f.domain := rfl #align linear_pmap.smul_domain LinearPMap.smul_domain theorem smul_apply (a : M) (f : E →ₗ.[R] F) (x : (a • f).domain) : (a • f) x = a • f x := rfl #align linear_pmap.smul_apply LinearPMap.smul_apply @[simp] theorem coe_smul (a : M) (f : E →ₗ.[R] F) : ⇑(a • f) = a • ⇑f := rfl #align linear_pmap.coe_smul LinearPMap.coe_smul instance instSMulCommClass [SMulCommClass M N F] : SMulCommClass M N (E →ₗ.[R] F) := ⟨fun a b f => ext' <| smul_comm a b f.toFun⟩ #align linear_pmap.smul_comm_class LinearPMap.instSMulCommClass instance instIsScalarTower [SMul M N] [IsScalarTower M N F] : IsScalarTower M N (E →ₗ.[R] F) := ⟨fun a b f => ext' <| smul_assoc a b f.toFun⟩ #align linear_pmap.is_scalar_tower LinearPMap.instIsScalarTower instance instMulAction : MulAction M (E →ₗ.[R] F) where smul := (· • ·) one_smul := fun ⟨_s, f⟩ => ext' <| one_smul M f mul_smul a b f := ext' <| mul_smul a b f.toFun #align linear_pmap.mul_action LinearPMap.instMulAction end SMul instance instNeg : Neg (E →ₗ.[R] F) := ⟨fun f => ⟨f.domain, -f.toFun⟩⟩ #align linear_pmap.has_neg LinearPMap.instNeg @[simp] theorem neg_domain (f : E →ₗ.[R] F) : (-f).domain = f.domain := rfl @[simp] theorem neg_apply (f : E →ₗ.[R] F) (x) : (-f) x = -f x := rfl #align linear_pmap.neg_apply LinearPMap.neg_apply instance instInvolutiveNeg : InvolutiveNeg (E →ₗ.[R] F) := ⟨fun f => by ext x y hxy · rfl · simp only [neg_apply, neg_neg] cases x congr⟩ section Add instance instAdd : Add (E →ₗ.[R] F) := ⟨fun f g => { domain := f.domain ⊓ g.domain toFun := f.toFun.comp (inclusion (inf_le_left : f.domain ⊓ g.domain ≤ _)) + g.toFun.comp (inclusion (inf_le_right : f.domain ⊓ g.domain ≤ _)) }⟩ theorem add_domain (f g : E →ₗ.[R] F) : (f + g).domain = f.domain ⊓ g.domain := rfl theorem add_apply (f g : E →ₗ.[R] F) (x : (f.domain ⊓ g.domain : Submodule R E)) : (f + g) x = f ⟨x, x.prop.1⟩ + g ⟨x, x.prop.2⟩ := rfl instance instAddSemigroup : AddSemigroup (E →ₗ.[R] F) := ⟨fun f g h => by ext x y hxy · simp only [add_domain, inf_assoc] · simp only [add_apply, hxy, add_assoc]⟩ instance instAddZeroClass : AddZeroClass (E →ₗ.[R] F) := ⟨fun f => by ext x y hxy · simp [add_domain] · simp only [add_apply, hxy, zero_apply, zero_add], fun f => by ext x y hxy · simp [add_domain] · simp only [add_apply, hxy, zero_apply, add_zero]⟩ instance instAddMonoid : AddMonoid (E →ₗ.[R] F) where zero_add f := by simp add_zero := by simp nsmul := nsmulRec instance instAddCommMonoid : AddCommMonoid (E →ₗ.[R] F) := ⟨fun f g => by ext x y hxy · simp only [add_domain, inf_comm] · simp only [add_apply, hxy, add_comm]⟩ end Add section VAdd instance instVAdd : VAdd (E →ₗ[R] F) (E →ₗ.[R] F) := ⟨fun f g => { domain := g.domain toFun := f.comp g.domain.subtype + g.toFun }⟩ #align linear_pmap.has_vadd LinearPMap.instVAdd @[simp] theorem vadd_domain (f : E →ₗ[R] F) (g : E →ₗ.[R] F) : (f +ᵥ g).domain = g.domain := rfl #align linear_pmap.vadd_domain LinearPMap.vadd_domain theorem vadd_apply (f : E →ₗ[R] F) (g : E →ₗ.[R] F) (x : (f +ᵥ g).domain) : (f +ᵥ g) x = f x + g x := rfl #align linear_pmap.vadd_apply LinearPMap.vadd_apply @[simp] theorem coe_vadd (f : E →ₗ[R] F) (g : E →ₗ.[R] F) : ⇑(f +ᵥ g) = ⇑(f.comp g.domain.subtype) + ⇑g := rfl #align linear_pmap.coe_vadd LinearPMap.coe_vadd instance instAddAction : AddAction (E →ₗ[R] F) (E →ₗ.[R] F) where vadd := (· +ᵥ ·) zero_vadd := fun ⟨_s, _f⟩ => ext' <| zero_add _ add_vadd := fun _f₁ _f₂ ⟨_s, _g⟩ => ext' <| LinearMap.ext fun _x => add_assoc _ _ _ #align linear_pmap.add_action LinearPMap.instAddAction end VAdd section Sub instance instSub : Sub (E →ₗ.[R] F) := ⟨fun f g => { domain := f.domain ⊓ g.domain toFun := f.toFun.comp (inclusion (inf_le_left : f.domain ⊓ g.domain ≤ _)) - g.toFun.comp (inclusion (inf_le_right : f.domain ⊓ g.domain ≤ _)) }⟩ theorem sub_domain (f g : E →ₗ.[R] F) : (f - g).domain = f.domain ⊓ g.domain := rfl theorem sub_apply (f g : E →ₗ.[R] F) (x : (f.domain ⊓ g.domain : Submodule R E)) : (f - g) x = f ⟨x, x.prop.1⟩ - g ⟨x, x.prop.2⟩ := rfl instance instSubtractionCommMonoid : SubtractionCommMonoid (E →ₗ.[R] F) where add_comm := add_comm sub_eq_add_neg f g := by ext x y h · rfl simp [sub_apply, add_apply, neg_apply, ← sub_eq_add_neg, h] neg_neg := neg_neg neg_add_rev f g := by ext x y h · simp [add_domain, sub_domain, neg_domain, And.comm] simp [sub_apply, add_apply, neg_apply, ← sub_eq_add_neg, h] neg_eq_of_add f g h' := by ext x y h · have : (0 : E →ₗ.[R] F).domain = ⊤ := zero_domain simp only [← h', add_domain, ge_iff_le, inf_eq_top_iff] at this rw [neg_domain, this.1, this.2] simp only [inf_coe, neg_domain, Eq.ndrec, Int.ofNat_eq_coe, neg_apply] rw [ext_iff] at h' rcases h' with ⟨hdom, h'⟩ rw [zero_domain] at hdom simp only [inf_coe, neg_domain, Eq.ndrec, Int.ofNat_eq_coe, zero_domain, top_coe, zero_apply, Subtype.forall, mem_top, forall_true_left, forall_eq'] at h' specialize h' x.1 (by simp [hdom]) simp only [inf_coe, neg_domain, Eq.ndrec, Int.ofNat_eq_coe, add_apply, Subtype.coe_eta, ← neg_eq_iff_add_eq_zero] at h' rw [h', h] zsmul := zsmulRec end Sub section variable {K : Type*} [DivisionRing K] [Module K E] [Module K F] /-- Extend a `LinearPMap` to `f.domain ⊔ K ∙ x`. -/ noncomputable def supSpanSingleton (f : E →ₗ.[K] F) (x : E) (y : F) (hx : x ∉ f.domain) : E →ₗ.[K] F := -- Porting note: `simpa [..]` → `simp [..]; exact ..` f.sup (mkSpanSingleton x y fun h₀ => hx <| h₀.symm ▸ f.domain.zero_mem) <| sup_h_of_disjoint _ _ <| by simp [disjoint_span_singleton]; exact fun h => False.elim <| hx h #align linear_pmap.sup_span_singleton LinearPMap.supSpanSingleton @[simp] theorem domain_supSpanSingleton (f : E →ₗ.[K] F) (x : E) (y : F) (hx : x ∉ f.domain) : (f.supSpanSingleton x y hx).domain = f.domain ⊔ K ∙ x := rfl #align linear_pmap.domain_sup_span_singleton LinearPMap.domain_supSpanSingleton @[simp, nolint simpNF] -- Porting note: Left-hand side does not simplify. theorem supSpanSingleton_apply_mk (f : E →ₗ.[K] F) (x : E) (y : F) (hx : x ∉ f.domain) (x' : E) (hx' : x' ∈ f.domain) (c : K) : f.supSpanSingleton x y hx ⟨x' + c • x, mem_sup.2 ⟨x', hx', _, mem_span_singleton.2 ⟨c, rfl⟩, rfl⟩⟩ = f ⟨x', hx'⟩ + c • y := by -- Porting note: `erw [..]; rfl; exact ..` → `erw [..]; exact ..; rfl` -- That is, the order of the side goals generated by `erw` changed. erw [sup_apply _ ⟨x', hx'⟩ ⟨c • x, _⟩, mkSpanSingleton'_apply] · exact mem_span_singleton.2 ⟨c, rfl⟩ · rfl #align linear_pmap.sup_span_singleton_apply_mk LinearPMap.supSpanSingleton_apply_mk end private theorem sSup_aux (c : Set (E →ₗ.[R] F)) (hc : DirectedOn (· ≤ ·) c) : ∃ f : ↥(sSup (domain '' c)) →ₗ[R] F, (⟨_, f⟩ : E →ₗ.[R] F) ∈ upperBounds c := by rcases c.eq_empty_or_nonempty with ceq | cne · subst c simp have hdir : DirectedOn (· ≤ ·) (domain '' c) := directedOn_image.2 (hc.mono @(domain_mono.monotone)) have P : ∀ x : ↥(sSup (domain '' c)), { p : c // (x : E) ∈ p.val.domain } := by rintro x apply Classical.indefiniteDescription have := (mem_sSup_of_directed (cne.image _) hdir).1 x.2 -- Porting note: + `← bex_def` rwa [Set.exists_mem_image, ← bex_def, SetCoe.exists'] at this set f : ↥(sSup (domain '' c)) → F := fun x => (P x).val.val ⟨x, (P x).property⟩ have f_eq : ∀ (p : c) (x : ↥(sSup (domain '' c))) (y : p.1.1) (_hxy : (x : E) = y), f x = p.1 y := by intro p x y hxy rcases hc (P x).1.1 (P x).1.2 p.1 p.2 with ⟨q, _hqc, hxq, hpq⟩ -- Porting note: `refine' ..; exacts [inclusion hpq.1 y, hxy, rfl]` -- → `refine' .. <;> [skip; exact inclusion hpq.1 y; rfl]; exact hxy` convert (hxq.2 _).trans (hpq.2 _).symm <;> [skip; exact inclusion hpq.1 y; rfl]; exact hxy use { toFun := f, map_add' := ?_, map_smul' := ?_ }, ?_ · intro x y rcases hc (P x).1.1 (P x).1.2 (P y).1.1 (P y).1.2 with ⟨p, hpc, hpx, hpy⟩ set x' := inclusion hpx.1 ⟨x, (P x).2⟩ set y' := inclusion hpy.1 ⟨y, (P y).2⟩ rw [f_eq ⟨p, hpc⟩ x x' rfl, f_eq ⟨p, hpc⟩ y y' rfl, f_eq ⟨p, hpc⟩ (x + y) (x' + y') rfl, map_add] · intro c x simp only [RingHom.id_apply] rw [f_eq (P x).1 (c • x) (c • ⟨x, (P x).2⟩) rfl, ← map_smul] · intro p hpc refine ⟨le_sSup <| Set.mem_image_of_mem domain hpc, fun x y hxy => Eq.symm ?_⟩ exact f_eq ⟨p, hpc⟩ _ _ hxy.symm protected noncomputable def sSup (c : Set (E →ₗ.[R] F)) (hc : DirectedOn (· ≤ ·) c) : E →ₗ.[R] F := ⟨_, Classical.choose <| sSup_aux c hc⟩ #align linear_pmap.Sup LinearPMap.sSup protected theorem le_sSup {c : Set (E →ₗ.[R] F)} (hc : DirectedOn (· ≤ ·) c) {f : E →ₗ.[R] F} (hf : f ∈ c) : f ≤ LinearPMap.sSup c hc := Classical.choose_spec (sSup_aux c hc) hf #align linear_pmap.le_Sup LinearPMap.le_sSup protected theorem sSup_le {c : Set (E →ₗ.[R] F)} (hc : DirectedOn (· ≤ ·) c) {g : E →ₗ.[R] F} (hg : ∀ f ∈ c, f ≤ g) : LinearPMap.sSup c hc ≤ g := le_of_eqLocus_ge <| sSup_le fun _ ⟨f, hf, Eq⟩ => Eq ▸ have : f ≤ LinearPMap.sSup c hc ⊓ g := le_inf (LinearPMap.le_sSup _ hf) (hg f hf) this.1 #align linear_pmap.Sup_le LinearPMap.sSup_le protected theorem sSup_apply {c : Set (E →ₗ.[R] F)} (hc : DirectedOn (· ≤ ·) c) {l : E →ₗ.[R] F} (hl : l ∈ c) (x : l.domain) : (LinearPMap.sSup c hc) ⟨x, (LinearPMap.le_sSup hc hl).1 x.2⟩ = l x := by symm apply (Classical.choose_spec (sSup_aux c hc) hl).2 rfl #align linear_pmap.Sup_apply LinearPMap.sSup_apply end LinearPMap namespace LinearMap /-- Restrict a linear map to a submodule, reinterpreting the result as a `LinearPMap`. -/ def toPMap (f : E →ₗ[R] F) (p : Submodule R E) : E →ₗ.[R] F := ⟨p, f.comp p.subtype⟩ #align linear_map.to_pmap LinearMap.toPMap @[simp] theorem toPMap_apply (f : E →ₗ[R] F) (p : Submodule R E) (x : p) : f.toPMap p x = f x := rfl #align linear_map.to_pmap_apply LinearMap.toPMap_apply @[simp] theorem toPMap_domain (f : E →ₗ[R] F) (p : Submodule R E) : (f.toPMap p).domain = p := rfl #align linear_map.to_pmap_domain LinearMap.toPMap_domain /-- Compose a linear map with a `LinearPMap` -/ def compPMap (g : F →ₗ[R] G) (f : E →ₗ.[R] F) : E →ₗ.[R] G where domain := f.domain toFun := g.comp f.toFun #align linear_map.comp_pmap LinearMap.compPMap @[simp] theorem compPMap_apply (g : F →ₗ[R] G) (f : E →ₗ.[R] F) (x) : g.compPMap f x = g (f x) := rfl #align linear_map.comp_pmap_apply LinearMap.compPMap_apply end LinearMap namespace LinearPMap /-- Restrict codomain of a `LinearPMap` -/ def codRestrict (f : E →ₗ.[R] F) (p : Submodule R F) (H : ∀ x, f x ∈ p) : E →ₗ.[R] p where domain := f.domain toFun := f.toFun.codRestrict p H #align linear_pmap.cod_restrict LinearPMap.codRestrict /-- Compose two `LinearPMap`s -/ def comp (g : F →ₗ.[R] G) (f : E →ₗ.[R] F) (H : ∀ x : f.domain, f x ∈ g.domain) : E →ₗ.[R] G := g.toFun.compPMap <| f.codRestrict _ H #align linear_pmap.comp LinearPMap.comp /-- `f.coprod g` is the partially defined linear map defined on `f.domain × g.domain`, and sending `p` to `f p.1 + g p.2`. -/ def coprod (f : E →ₗ.[R] G) (g : F →ₗ.[R] G) : E × F →ₗ.[R] G where domain := f.domain.prod g.domain toFun := -- Porting note: This is just -- `(f.comp (LinearPMap.fst f.domain g.domain) fun x => x.2.1).toFun +` -- ` (g.comp (LinearPMap.snd f.domain g.domain) fun x => x.2.2).toFun`, HAdd.hAdd (α := f.domain.prod g.domain →ₗ[R] G) (β := f.domain.prod g.domain →ₗ[R] G) (f.comp (LinearPMap.fst f.domain g.domain) fun x => x.2.1).toFun (g.comp (LinearPMap.snd f.domain g.domain) fun x => x.2.2).toFun #align linear_pmap.coprod LinearPMap.coprod @[simp] theorem coprod_apply (f : E →ₗ.[R] G) (g : F →ₗ.[R] G) (x) : f.coprod g x = f ⟨(x : E × F).1, x.2.1⟩ + g ⟨(x : E × F).2, x.2.2⟩ := rfl #align linear_pmap.coprod_apply LinearPMap.coprod_apply /-- Restrict a partially defined linear map to a submodule of `E` contained in `f.domain`. -/ def domRestrict (f : E →ₗ.[R] F) (S : Submodule R E) : E →ₗ.[R] F := ⟨S ⊓ f.domain, f.toFun.comp (Submodule.inclusion (by simp))⟩ #align linear_pmap.dom_restrict LinearPMap.domRestrict @[simp] theorem domRestrict_domain (f : E →ₗ.[R] F) {S : Submodule R E} : (f.domRestrict S).domain = S ⊓ f.domain := rfl #align linear_pmap.dom_restrict_domain LinearPMap.domRestrict_domain theorem domRestrict_apply {f : E →ₗ.[R] F} {S : Submodule R E} ⦃x : ↥(S ⊓ f.domain)⦄ ⦃y : f.domain⦄ (h : (x : E) = y) : f.domRestrict S x = f y := by have : Submodule.inclusion (by simp) x = y := by ext simp [h] rw [← this] exact LinearPMap.mk_apply _ _ _ #align linear_pmap.dom_restrict_apply LinearPMap.domRestrict_apply theorem domRestrict_le {f : E →ₗ.[R] F} {S : Submodule R E} : f.domRestrict S ≤ f := ⟨by simp, fun x y hxy => domRestrict_apply hxy⟩ #align linear_pmap.dom_restrict_le LinearPMap.domRestrict_le /-! ### Graph -/ section Graph /-- The graph of a `LinearPMap` viewed as a submodule on `E × F`. -/ def graph (f : E →ₗ.[R] F) : Submodule R (E × F) := f.toFun.graph.map (f.domain.subtype.prodMap (LinearMap.id : F →ₗ[R] F)) #align linear_pmap.graph LinearPMap.graph theorem mem_graph_iff' (f : E →ₗ.[R] F) {x : E × F} : x ∈ f.graph ↔ ∃ y : f.domain, (↑y, f y) = x := by simp [graph] #align linear_pmap.mem_graph_iff' LinearPMap.mem_graph_iff' @[simp] theorem mem_graph_iff (f : E →ₗ.[R] F) {x : E × F} : x ∈ f.graph ↔ ∃ y : f.domain, (↑y : E) = x.1 ∧ f y = x.2 := by cases x simp_rw [mem_graph_iff', Prod.mk.inj_iff] #align linear_pmap.mem_graph_iff LinearPMap.mem_graph_iff /-- The tuple `(x, f x)` is contained in the graph of `f`. -/ theorem mem_graph (f : E →ₗ.[R] F) (x : domain f) : ((x : E), f x) ∈ f.graph := by simp #align linear_pmap.mem_graph LinearPMap.mem_graph theorem graph_map_fst_eq_domain (f : E →ₗ.[R] F) : f.graph.map (LinearMap.fst R E F) = f.domain := by ext x simp only [Submodule.mem_map, mem_graph_iff, Subtype.exists, exists_and_left, exists_eq_left, LinearMap.fst_apply, Prod.exists, exists_and_right, exists_eq_right] constructor <;> intro h · rcases h with ⟨x, hx, _⟩ exact hx · use f ⟨x, h⟩ simp only [h, exists_const] theorem graph_map_snd_eq_range (f : E →ₗ.[R] F) : f.graph.map (LinearMap.snd R E F) = LinearMap.range f.toFun := by ext; simp variable {M : Type*} [Monoid M] [DistribMulAction M F] [SMulCommClass R M F] (y : M) /-- The graph of `z • f` as a pushforward. -/ theorem smul_graph (f : E →ₗ.[R] F) (z : M) : (z • f).graph = f.graph.map ((LinearMap.id : E →ₗ[R] E).prodMap (z • (LinearMap.id : F →ₗ[R] F))) := by ext x; cases' x with x_fst x_snd constructor <;> intro h · rw [mem_graph_iff] at h rcases h with ⟨y, hy, h⟩ rw [LinearPMap.smul_apply] at h rw [Submodule.mem_map] simp only [mem_graph_iff, LinearMap.prodMap_apply, LinearMap.id_coe, id, LinearMap.smul_apply, Prod.mk.inj_iff, Prod.exists, exists_exists_and_eq_and] use x_fst, y, hy rw [Submodule.mem_map] at h rcases h with ⟨x', hx', h⟩ cases x' simp only [LinearMap.prodMap_apply, LinearMap.id_coe, id, LinearMap.smul_apply, Prod.mk.inj_iff] at h rw [mem_graph_iff] at hx' ⊢ rcases hx' with ⟨y, hy, hx'⟩ use y rw [← h.1, ← h.2] simp [hy, hx'] #align linear_pmap.smul_graph LinearPMap.smul_graph /-- The graph of `-f` as a pushforward. -/ theorem neg_graph (f : E →ₗ.[R] F) : (-f).graph = f.graph.map ((LinearMap.id : E →ₗ[R] E).prodMap (-(LinearMap.id : F →ₗ[R] F))) := by ext x; cases' x with x_fst x_snd constructor <;> intro h · rw [mem_graph_iff] at h rcases h with ⟨y, hy, h⟩ rw [LinearPMap.neg_apply] at h rw [Submodule.mem_map] simp only [mem_graph_iff, LinearMap.prodMap_apply, LinearMap.id_coe, id, LinearMap.neg_apply, Prod.mk.inj_iff, Prod.exists, exists_exists_and_eq_and] use x_fst, y, hy rw [Submodule.mem_map] at h rcases h with ⟨x', hx', h⟩ cases x' simp only [LinearMap.prodMap_apply, LinearMap.id_coe, id, LinearMap.neg_apply, Prod.mk.inj_iff] at h rw [mem_graph_iff] at hx' ⊢ rcases hx' with ⟨y, hy, hx'⟩ use y rw [← h.1, ← h.2] simp [hy, hx'] #align linear_pmap.neg_graph LinearPMap.neg_graph theorem mem_graph_snd_inj (f : E →ₗ.[R] F) {x y : E} {x' y' : F} (hx : (x, x') ∈ f.graph) (hy : (y, y') ∈ f.graph) (hxy : x = y) : x' = y' := by rw [mem_graph_iff] at hx hy rcases hx with ⟨x'', hx1, hx2⟩ rcases hy with ⟨y'', hy1, hy2⟩ simp only at hx1 hx2 hy1 hy2 rw [← hx1, ← hy1, SetLike.coe_eq_coe] at hxy rw [← hx2, ← hy2, hxy] #align linear_pmap.mem_graph_snd_inj LinearPMap.mem_graph_snd_inj theorem mem_graph_snd_inj' (f : E →ₗ.[R] F) {x y : E × F} (hx : x ∈ f.graph) (hy : y ∈ f.graph) (hxy : x.1 = y.1) : x.2 = y.2 := by cases x cases y exact f.mem_graph_snd_inj hx hy hxy #align linear_pmap.mem_graph_snd_inj' LinearPMap.mem_graph_snd_inj' /-- The property that `f 0 = 0` in terms of the graph. -/ theorem graph_fst_eq_zero_snd (f : E →ₗ.[R] F) {x : E} {x' : F} (h : (x, x') ∈ f.graph) (hx : x = 0) : x' = 0 := f.mem_graph_snd_inj h f.graph.zero_mem hx #align linear_pmap.graph_fst_eq_zero_snd LinearPMap.graph_fst_eq_zero_snd theorem mem_domain_iff {f : E →ₗ.[R] F} {x : E} : x ∈ f.domain ↔ ∃ y : F, (x, y) ∈ f.graph := by constructor <;> intro h · use f ⟨x, h⟩ exact f.mem_graph ⟨x, h⟩ cases' h with y h rw [mem_graph_iff] at h cases' h with x' h simp only at h rw [← h.1] simp #align linear_pmap.mem_domain_iff LinearPMap.mem_domain_iff theorem mem_domain_of_mem_graph {f : E →ₗ.[R] F} {x : E} {y : F} (h : (x, y) ∈ f.graph) : x ∈ f.domain := by rw [mem_domain_iff] exact ⟨y, h⟩ #align linear_pmap.mem_domain_of_mem_graph LinearPMap.mem_domain_of_mem_graph theorem image_iff {f : E →ₗ.[R] F} {x : E} {y : F} (hx : x ∈ f.domain) : y = f ⟨x, hx⟩ ↔ (x, y) ∈ f.graph := by rw [mem_graph_iff] constructor <;> intro h · use ⟨x, hx⟩ simp [h] rcases h with ⟨⟨x', hx'⟩, ⟨h1, h2⟩⟩ simp only [Submodule.coe_mk] at h1 h2 simp only [← h2, h1] #align linear_pmap.image_iff LinearPMap.image_iff theorem mem_range_iff {f : E →ₗ.[R] F} {y : F} : y ∈ Set.range f ↔ ∃ x : E, (x, y) ∈ f.graph := by constructor <;> intro h · rw [Set.mem_range] at h rcases h with ⟨⟨x, hx⟩, h⟩ use x rw [← h] exact f.mem_graph ⟨x, hx⟩ cases' h with x h rw [mem_graph_iff] at h cases' h with x h rw [Set.mem_range] use x simp only at h rw [h.2] #align linear_pmap.mem_range_iff LinearPMap.mem_range_iff theorem mem_domain_iff_of_eq_graph {f g : E →ₗ.[R] F} (h : f.graph = g.graph) {x : E} : x ∈ f.domain ↔ x ∈ g.domain := by simp_rw [mem_domain_iff, h] #align linear_pmap.mem_domain_iff_of_eq_graph LinearPMap.mem_domain_iff_of_eq_graph theorem le_of_le_graph {f g : E →ₗ.[R] F} (h : f.graph ≤ g.graph) : f ≤ g := by constructor · intro x hx rw [mem_domain_iff] at hx ⊢ cases' hx with y hx use y exact h hx rintro ⟨x, hx⟩ ⟨y, hy⟩ hxy rw [image_iff] refine h ?_ simp only [Submodule.coe_mk] at hxy rw [hxy] at hx rw [← image_iff hx] simp [hxy] #align linear_pmap.le_of_le_graph LinearPMap.le_of_le_graph theorem le_graph_of_le {f g : E →ₗ.[R] F} (h : f ≤ g) : f.graph ≤ g.graph := by intro x hx rw [mem_graph_iff] at hx ⊢ cases' hx with y hx use ⟨y, h.1 y.2⟩ simp only [hx, Submodule.coe_mk, eq_self_iff_true, true_and_iff] convert hx.2 using 1 refine (h.2 ?_).symm simp only [hx.1, Submodule.coe_mk] #align linear_pmap.le_graph_of_le LinearPMap.le_graph_of_le theorem le_graph_iff {f g : E →ₗ.[R] F} : f.graph ≤ g.graph ↔ f ≤ g := ⟨le_of_le_graph, le_graph_of_le⟩ #align linear_pmap.le_graph_iff LinearPMap.le_graph_iff theorem eq_of_eq_graph {f g : E →ₗ.[R] F} (h : f.graph = g.graph) : f = g := by -- Porting note: `ext` → `refine ext ..` refine ext (Submodule.ext fun x => ?_) (fun x y h' => ?_) · exact mem_domain_iff_of_eq_graph h · exact (le_of_le_graph h.le).2 h' #align linear_pmap.eq_of_eq_graph LinearPMap.eq_of_eq_graph end Graph end LinearPMap namespace Submodule section SubmoduleToLinearPMap theorem existsUnique_from_graph {g : Submodule R (E × F)} (hg : ∀ {x : E × F} (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) {a : E} (ha : a ∈ g.map (LinearMap.fst R E F)) : ∃! b : F, (a, b) ∈ g := by refine exists_unique_of_exists_of_unique ?_ ?_ · convert ha simp intro y₁ y₂ hy₁ hy₂ have hy : ((0 : E), y₁ - y₂) ∈ g := by convert g.sub_mem hy₁ hy₂ exact (sub_self _).symm exact sub_eq_zero.mp (hg hy (by simp)) #align submodule.exists_unique_from_graph Submodule.existsUnique_from_graph /-- Auxiliary definition to unfold the existential quantifier. -/ noncomputable def valFromGraph {g : Submodule R (E × F)} (hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) {a : E} (ha : a ∈ g.map (LinearMap.fst R E F)) : F := (ExistsUnique.exists (existsUnique_from_graph @hg ha)).choose #align submodule.val_from_graph Submodule.valFromGraph theorem valFromGraph_mem {g : Submodule R (E × F)} (hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) {a : E} (ha : a ∈ g.map (LinearMap.fst R E F)) : (a, valFromGraph hg ha) ∈ g := (ExistsUnique.exists (existsUnique_from_graph @hg ha)).choose_spec #align submodule.val_from_graph_mem Submodule.valFromGraph_mem /-- Define a `LinearMap` from its graph. Helper definition for `LinearPMap`. -/ noncomputable def toLinearPMapAux (g : Submodule R (E × F)) (hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) : g.map (LinearMap.fst R E F) →ₗ[R] F where toFun := fun x => valFromGraph hg x.2 map_add' := fun v w => by have hadd := (g.map (LinearMap.fst R E F)).add_mem v.2 w.2 have hvw := valFromGraph_mem hg hadd have hvw' := g.add_mem (valFromGraph_mem hg v.2) (valFromGraph_mem hg w.2) rw [Prod.mk_add_mk] at hvw' exact (existsUnique_from_graph @hg hadd).unique hvw hvw' map_smul' := fun a v => by have hsmul := (g.map (LinearMap.fst R E F)).smul_mem a v.2 have hav := valFromGraph_mem hg hsmul have hav' := g.smul_mem a (valFromGraph_mem hg v.2) rw [Prod.smul_mk] at hav' exact (existsUnique_from_graph @hg hsmul).unique hav hav' open scoped Classical in /-- Define a `LinearPMap` from its graph. In the case that the submodule is not a graph of a `LinearPMap` then the underlying linear map is just the zero map. -/ noncomputable def toLinearPMap (g : Submodule R (E × F)) : E →ₗ.[R] F where domain := g.map (LinearMap.fst R E F) toFun := if hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0 then g.toLinearPMapAux hg else 0 #align submodule.to_linear_pmap Submodule.toLinearPMap theorem toLinearPMap_domain (g : Submodule R (E × F)) : g.toLinearPMap.domain = g.map (LinearMap.fst R E F) := rfl theorem toLinearPMap_apply_aux {g : Submodule R (E × F)} (hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) (x : g.map (LinearMap.fst R E F)) : g.toLinearPMap x = valFromGraph hg x.2 := by classical change (if hg : _ then g.toLinearPMapAux hg else 0) x = _ rw [dif_pos] · rfl · exact hg theorem mem_graph_toLinearPMap {g : Submodule R (E × F)} (hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) (x : g.map (LinearMap.fst R E F)) : (x.val, g.toLinearPMap x) ∈ g := by rw [toLinearPMap_apply_aux hg] exact valFromGraph_mem hg x.2 #align submodule.mem_graph_to_linear_pmap Submodule.mem_graph_toLinearPMap @[simp] theorem toLinearPMap_graph_eq (g : Submodule R (E × F)) (hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) : g.toLinearPMap.graph = g := by ext x constructor <;> intro hx · rw [LinearPMap.mem_graph_iff] at hx rcases hx with ⟨y, hx1, hx2⟩ convert g.mem_graph_toLinearPMap hg y using 1 exact Prod.ext hx1.symm hx2.symm rw [LinearPMap.mem_graph_iff] cases' x with x_fst x_snd have hx_fst : x_fst ∈ g.map (LinearMap.fst R E F) := by simp only [mem_map, LinearMap.fst_apply, Prod.exists, exists_and_right, exists_eq_right] exact ⟨x_snd, hx⟩ refine ⟨⟨x_fst, hx_fst⟩, Subtype.coe_mk x_fst hx_fst, ?_⟩ rw [toLinearPMap_apply_aux hg] exact (existsUnique_from_graph @hg hx_fst).unique (valFromGraph_mem hg hx_fst) hx #align submodule.to_linear_pmap_graph_eq Submodule.toLinearPMap_graph_eq theorem toLinearPMap_range (g : Submodule R (E × F)) (hg : ∀ (x : E × F) (_hx : x ∈ g) (_hx' : x.fst = 0), x.snd = 0) : LinearMap.range g.toLinearPMap.toFun = g.map (LinearMap.snd R E F) := by rwa [← LinearPMap.graph_map_snd_eq_range, toLinearPMap_graph_eq] end SubmoduleToLinearPMap end Submodule namespace LinearPMap section inverse /-- The inverse of a `LinearPMap`. -/ noncomputable def inverse (f : E →ₗ.[R] F) : F →ₗ.[R] E := (f.graph.map (LinearEquiv.prodComm R E F)).toLinearPMap variable {f : E →ₗ.[R] F}
Mathlib/LinearAlgebra/LinearPMap.lean
1,081
1,084
theorem inverse_domain : (inverse f).domain = LinearMap.range f.toFun := by
rw [inverse, Submodule.toLinearPMap_domain, ← graph_map_snd_eq_range, ← LinearEquiv.fst_comp_prodComm, Submodule.map_comp] rfl
/- Copyright (c) 2021 Arthur Paulino. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Arthur Paulino, Kyle Miller -/ import Mathlib.Combinatorics.SimpleGraph.Clique import Mathlib.Data.ENat.Lattice import Mathlib.Data.Nat.Lattice import Mathlib.Data.Setoid.Partition import Mathlib.Order.Antichain #align_import combinatorics.simple_graph.coloring from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a" /-! # Graph Coloring This module defines colorings of simple graphs (also known as proper colorings in the literature). A graph coloring is the attribution of "colors" to all of its vertices such that adjacent vertices have different colors. A coloring can be represented as a homomorphism into a complete graph, whose vertices represent the colors. ## Main definitions * `G.Coloring α` is the type of `α`-colorings of a simple graph `G`, with `α` being the set of available colors. The type is defined to be homomorphisms from `G` into the complete graph on `α`, and colorings have a coercion to `V → α`. * `G.Colorable n` is the proposition that `G` is `n`-colorable, which is whether there exists a coloring with at most *n* colors. * `G.chromaticNumber` is the minimal `n` such that `G` is `n`-colorable, or `⊤` if it cannot be colored with finitely many colors. (Cardinal-valued chromatic numbers are more niche, so we stick to `ℕ∞`.) We write `G.chromaticNumber ≠ ⊤` to mean a graph is colorable with finitely many colors. * `C.colorClass c` is the set of vertices colored by `c : α` in the coloring `C : G.Coloring α`. * `C.colorClasses` is the set containing all color classes. ## Todo: * Gather material from: * https://github.com/leanprover-community/mathlib/blob/simple_graph_matching/src/combinatorics/simple_graph/coloring.lean * https://github.com/kmill/lean-graphcoloring/blob/master/src/graph.lean * Trees * Planar graphs * Chromatic polynomials * develop API for partial colorings, likely as colorings of subgraphs (`H.coe.Coloring α`) -/ open Fintype Function universe u v namespace SimpleGraph variable {V : Type u} (G : SimpleGraph V) {n : ℕ} /-- An `α`-coloring of a simple graph `G` is a homomorphism of `G` into the complete graph on `α`. This is also known as a proper coloring. -/ abbrev Coloring (α : Type v) := G →g (⊤ : SimpleGraph α) #align simple_graph.coloring SimpleGraph.Coloring variable {G} {α β : Type*} (C : G.Coloring α) theorem Coloring.valid {v w : V} (h : G.Adj v w) : C v ≠ C w := C.map_rel h #align simple_graph.coloring.valid SimpleGraph.Coloring.valid /-- Construct a term of `SimpleGraph.Coloring` using a function that assigns vertices to colors and a proof that it is as proper coloring. (Note: this is a definitionally the constructor for `SimpleGraph.Hom`, but with a syntactically better proper coloring hypothesis.) -/ @[match_pattern] def Coloring.mk (color : V → α) (valid : ∀ {v w : V}, G.Adj v w → color v ≠ color w) : G.Coloring α := ⟨color, @valid⟩ #align simple_graph.coloring.mk SimpleGraph.Coloring.mk /-- The color class of a given color. -/ def Coloring.colorClass (c : α) : Set V := { v : V | C v = c } #align simple_graph.coloring.color_class SimpleGraph.Coloring.colorClass /-- The set containing all color classes. -/ def Coloring.colorClasses : Set (Set V) := (Setoid.ker C).classes #align simple_graph.coloring.color_classes SimpleGraph.Coloring.colorClasses theorem Coloring.mem_colorClass (v : V) : v ∈ C.colorClass (C v) := rfl #align simple_graph.coloring.mem_color_class SimpleGraph.Coloring.mem_colorClass theorem Coloring.colorClasses_isPartition : Setoid.IsPartition C.colorClasses := Setoid.isPartition_classes (Setoid.ker C) #align simple_graph.coloring.color_classes_is_partition SimpleGraph.Coloring.colorClasses_isPartition theorem Coloring.mem_colorClasses {v : V} : C.colorClass (C v) ∈ C.colorClasses := ⟨v, rfl⟩ #align simple_graph.coloring.mem_color_classes SimpleGraph.Coloring.mem_colorClasses theorem Coloring.colorClasses_finite [Finite α] : C.colorClasses.Finite := Setoid.finite_classes_ker _ #align simple_graph.coloring.color_classes_finite SimpleGraph.Coloring.colorClasses_finite theorem Coloring.card_colorClasses_le [Fintype α] [Fintype C.colorClasses] : Fintype.card C.colorClasses ≤ Fintype.card α := by simp [colorClasses] -- Porting note: brute force instance declaration `[Fintype (Setoid.classes (Setoid.ker C))]` haveI : Fintype (Setoid.classes (Setoid.ker C)) := by assumption convert Setoid.card_classes_ker_le C #align simple_graph.coloring.card_color_classes_le SimpleGraph.Coloring.card_colorClasses_le theorem Coloring.not_adj_of_mem_colorClass {c : α} {v w : V} (hv : v ∈ C.colorClass c) (hw : w ∈ C.colorClass c) : ¬G.Adj v w := fun h => C.valid h (Eq.trans hv (Eq.symm hw)) #align simple_graph.coloring.not_adj_of_mem_color_class SimpleGraph.Coloring.not_adj_of_mem_colorClass theorem Coloring.color_classes_independent (c : α) : IsAntichain G.Adj (C.colorClass c) := fun _ hv _ hw _ => C.not_adj_of_mem_colorClass hv hw #align simple_graph.coloring.color_classes_independent SimpleGraph.Coloring.color_classes_independent -- TODO make this computable noncomputable instance [Fintype V] [Fintype α] : Fintype (Coloring G α) := by classical change Fintype (RelHom G.Adj (⊤ : SimpleGraph α).Adj) apply Fintype.ofInjective _ RelHom.coe_fn_injective variable (G) /-- Whether a graph can be colored by at most `n` colors. -/ def Colorable (n : ℕ) : Prop := Nonempty (G.Coloring (Fin n)) #align simple_graph.colorable SimpleGraph.Colorable /-- The coloring of an empty graph. -/ def coloringOfIsEmpty [IsEmpty V] : G.Coloring α := Coloring.mk isEmptyElim fun {v} => isEmptyElim v #align simple_graph.coloring_of_is_empty SimpleGraph.coloringOfIsEmpty theorem colorable_of_isEmpty [IsEmpty V] (n : ℕ) : G.Colorable n := ⟨G.coloringOfIsEmpty⟩ #align simple_graph.colorable_of_is_empty SimpleGraph.colorable_of_isEmpty theorem isEmpty_of_colorable_zero (h : G.Colorable 0) : IsEmpty V := by constructor intro v obtain ⟨i, hi⟩ := h.some v exact Nat.not_lt_zero _ hi #align simple_graph.is_empty_of_colorable_zero SimpleGraph.isEmpty_of_colorable_zero /-- The "tautological" coloring of a graph, using the vertices of the graph as colors. -/ def selfColoring : G.Coloring V := Coloring.mk id fun {_ _} => G.ne_of_adj #align simple_graph.self_coloring SimpleGraph.selfColoring /-- The chromatic number of a graph is the minimal number of colors needed to color it. This is `⊤` (infinity) iff `G` isn't colorable with finitely many colors. If `G` is colorable, then `ENat.toNat G.chromaticNumber` is the `ℕ`-valued chromatic number. -/ noncomputable def chromaticNumber : ℕ∞ := ⨅ n ∈ setOf G.Colorable, (n : ℕ∞) #align simple_graph.chromatic_number SimpleGraph.chromaticNumber lemma chromaticNumber_eq_biInf {G : SimpleGraph V} : G.chromaticNumber = ⨅ n ∈ setOf G.Colorable, (n : ℕ∞) := rfl lemma chromaticNumber_eq_iInf {G : SimpleGraph V} : G.chromaticNumber = ⨅ n : {m | G.Colorable m}, (n : ℕ∞) := by rw [chromaticNumber, iInf_subtype] lemma Colorable.chromaticNumber_eq_sInf {G : SimpleGraph V} {n} (h : G.Colorable n) : G.chromaticNumber = sInf {n' : ℕ | G.Colorable n'} := by rw [ENat.coe_sInf, chromaticNumber] exact ⟨_, h⟩ /-- Given an embedding, there is an induced embedding of colorings. -/ def recolorOfEmbedding {α β : Type*} (f : α ↪ β) : G.Coloring α ↪ G.Coloring β where toFun C := (Embedding.completeGraph f).toHom.comp C inj' := by -- this was strangely painful; seems like missing lemmas about embeddings intro C C' h dsimp only at h ext v apply (Embedding.completeGraph f).inj' change ((Embedding.completeGraph f).toHom.comp C) v = _ rw [h] rfl #align simple_graph.recolor_of_embedding SimpleGraph.recolorOfEmbedding @[simp] lemma coe_recolorOfEmbedding (f : α ↪ β) : ⇑(G.recolorOfEmbedding f) = (Embedding.completeGraph f).toHom.comp := rfl /-- Given an equivalence, there is an induced equivalence between colorings. -/ def recolorOfEquiv {α β : Type*} (f : α ≃ β) : G.Coloring α ≃ G.Coloring β where toFun := G.recolorOfEmbedding f.toEmbedding invFun := G.recolorOfEmbedding f.symm.toEmbedding left_inv C := by ext v apply Equiv.symm_apply_apply right_inv C := by ext v apply Equiv.apply_symm_apply #align simple_graph.recolor_of_equiv SimpleGraph.recolorOfEquiv @[simp] lemma coe_recolorOfEquiv (f : α ≃ β) : ⇑(G.recolorOfEquiv f) = (Embedding.completeGraph f).toHom.comp := rfl /-- There is a noncomputable embedding of `α`-colorings to `β`-colorings if `β` has at least as large a cardinality as `α`. -/ noncomputable def recolorOfCardLE {α β : Type*} [Fintype α] [Fintype β] (hn : Fintype.card α ≤ Fintype.card β) : G.Coloring α ↪ G.Coloring β := G.recolorOfEmbedding <| (Function.Embedding.nonempty_of_card_le hn).some #align simple_graph.recolor_of_card_le SimpleGraph.recolorOfCardLE @[simp] lemma coe_recolorOfCardLE [Fintype α] [Fintype β] (hαβ : card α ≤ card β) : ⇑(G.recolorOfCardLE hαβ) = (Embedding.completeGraph (Embedding.nonempty_of_card_le hαβ).some).toHom.comp := rfl variable {G} theorem Colorable.mono {n m : ℕ} (h : n ≤ m) (hc : G.Colorable n) : G.Colorable m := ⟨G.recolorOfCardLE (by simp [h]) hc.some⟩ #align simple_graph.colorable.mono SimpleGraph.Colorable.mono theorem Coloring.colorable [Fintype α] (C : G.Coloring α) : G.Colorable (Fintype.card α) := ⟨G.recolorOfCardLE (by simp) C⟩ #align simple_graph.coloring.to_colorable SimpleGraph.Coloring.colorable theorem colorable_of_fintype (G : SimpleGraph V) [Fintype V] : G.Colorable (Fintype.card V) := G.selfColoring.colorable #align simple_graph.colorable_of_fintype SimpleGraph.colorable_of_fintype /-- Noncomputably get a coloring from colorability. -/ noncomputable def Colorable.toColoring [Fintype α] {n : ℕ} (hc : G.Colorable n) (hn : n ≤ Fintype.card α) : G.Coloring α := by rw [← Fintype.card_fin n] at hn exact G.recolorOfCardLE hn hc.some #align simple_graph.colorable.to_coloring SimpleGraph.Colorable.toColoring theorem Colorable.of_embedding {V' : Type*} {G' : SimpleGraph V'} (f : G ↪g G') {n : ℕ} (h : G'.Colorable n) : G.Colorable n := ⟨(h.toColoring (by simp)).comp f⟩ #align simple_graph.colorable.of_embedding SimpleGraph.Colorable.of_embedding theorem colorable_iff_exists_bdd_nat_coloring (n : ℕ) : G.Colorable n ↔ ∃ C : G.Coloring ℕ, ∀ v, C v < n := by constructor · rintro hc have C : G.Coloring (Fin n) := hc.toColoring (by simp) let f := Embedding.completeGraph (@Fin.valEmbedding n) use f.toHom.comp C intro v cases' C with color valid exact Fin.is_lt (color v) · rintro ⟨C, Cf⟩ refine ⟨Coloring.mk ?_ ?_⟩ · exact fun v => ⟨C v, Cf v⟩ · rintro v w hvw simp only [Fin.mk_eq_mk, Ne] exact C.valid hvw #align simple_graph.colorable_iff_exists_bdd_nat_coloring SimpleGraph.colorable_iff_exists_bdd_nat_coloring theorem colorable_set_nonempty_of_colorable {n : ℕ} (hc : G.Colorable n) : { n : ℕ | G.Colorable n }.Nonempty := ⟨n, hc⟩ #align simple_graph.colorable_set_nonempty_of_colorable SimpleGraph.colorable_set_nonempty_of_colorable theorem chromaticNumber_bddBelow : BddBelow { n : ℕ | G.Colorable n } := ⟨0, fun _ _ => zero_le _⟩ #align simple_graph.chromatic_number_bdd_below SimpleGraph.chromaticNumber_bddBelow theorem Colorable.chromaticNumber_le {n : ℕ} (hc : G.Colorable n) : G.chromaticNumber ≤ n := by rw [hc.chromaticNumber_eq_sInf] norm_cast apply csInf_le chromaticNumber_bddBelow exact hc #align simple_graph.chromatic_number_le_of_colorable SimpleGraph.Colorable.chromaticNumber_le theorem chromaticNumber_ne_top_iff_exists : G.chromaticNumber ≠ ⊤ ↔ ∃ n, G.Colorable n := by rw [chromaticNumber] convert_to ⨅ n : {m | G.Colorable m}, (n : ℕ∞) ≠ ⊤ ↔ _ · rw [iInf_subtype] rw [← lt_top_iff_ne_top, ENat.iInf_coe_lt_top] simp theorem chromaticNumber_le_iff_colorable {n : ℕ} : G.chromaticNumber ≤ n ↔ G.Colorable n := by refine ⟨fun h ↦ ?_, Colorable.chromaticNumber_le⟩ have : G.chromaticNumber ≠ ⊤ := (trans h (WithTop.coe_lt_top n)).ne rw [chromaticNumber_ne_top_iff_exists] at this obtain ⟨m, hm⟩ := this rw [hm.chromaticNumber_eq_sInf, Nat.cast_le] at h have := Nat.sInf_mem (⟨m, hm⟩ : {n' | G.Colorable n'}.Nonempty) rw [Set.mem_setOf_eq] at this exact this.mono h @[deprecated Colorable.chromaticNumber_le (since := "2024-03-21")] theorem chromaticNumber_le_card [Fintype α] (C : G.Coloring α) : G.chromaticNumber ≤ Fintype.card α := C.colorable.chromaticNumber_le #align simple_graph.chromatic_number_le_card SimpleGraph.chromaticNumber_le_card
Mathlib/Combinatorics/SimpleGraph/Coloring.lean
305
310
theorem colorable_chromaticNumber {m : ℕ} (hc : G.Colorable m) : G.Colorable (ENat.toNat G.chromaticNumber) := by
classical rw [hc.chromaticNumber_eq_sInf, Nat.sInf_def] · apply Nat.find_spec · exact colorable_set_nonempty_of_colorable hc
/- Copyright (c) 2022 Rémy Degenne, Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne, Kexing Ying -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.MeasureTheory.Function.Egorov import Mathlib.MeasureTheory.Function.LpSpace #align_import measure_theory.function.convergence_in_measure from "leanprover-community/mathlib"@"0b9eaaa7686280fad8cce467f5c3c57ee6ce77f8" /-! # Convergence in measure We define convergence in measure which is one of the many notions of convergence in probability. A sequence of functions `f` is said to converge in measure to some function `g` if for all `ε > 0`, the measure of the set `{x | ε ≤ dist (f i x) (g x)}` tends to 0 as `i` converges along some given filter `l`. Convergence in measure is most notably used in the formulation of the weak law of large numbers and is also useful in theorems such as the Vitali convergence theorem. This file provides some basic lemmas for working with convergence in measure and establishes some relations between convergence in measure and other notions of convergence. ## Main definitions * `MeasureTheory.TendstoInMeasure (μ : Measure α) (f : ι → α → E) (g : α → E)`: `f` converges in `μ`-measure to `g`. ## Main results * `MeasureTheory.tendstoInMeasure_of_tendsto_ae`: convergence almost everywhere in a finite measure space implies convergence in measure. * `MeasureTheory.TendstoInMeasure.exists_seq_tendsto_ae`: if `f` is a sequence of functions which converges in measure to `g`, then `f` has a subsequence which convergence almost everywhere to `g`. * `MeasureTheory.tendstoInMeasure_of_tendsto_snorm`: convergence in Lp implies convergence in measure. -/ open TopologicalSpace Filter open scoped NNReal ENNReal MeasureTheory Topology namespace MeasureTheory variable {α ι E : Type*} {m : MeasurableSpace α} {μ : Measure α} /-- A sequence of functions `f` is said to converge in measure to some function `g` if for all `ε > 0`, the measure of the set `{x | ε ≤ dist (f i x) (g x)}` tends to 0 as `i` converges along some given filter `l`. -/ def TendstoInMeasure [Dist E] {_ : MeasurableSpace α} (μ : Measure α) (f : ι → α → E) (l : Filter ι) (g : α → E) : Prop := ∀ ε, 0 < ε → Tendsto (fun i => μ { x | ε ≤ dist (f i x) (g x) }) l (𝓝 0) #align measure_theory.tendsto_in_measure MeasureTheory.TendstoInMeasure theorem tendstoInMeasure_iff_norm [SeminormedAddCommGroup E] {l : Filter ι} {f : ι → α → E} {g : α → E} : TendstoInMeasure μ f l g ↔ ∀ ε, 0 < ε → Tendsto (fun i => μ { x | ε ≤ ‖f i x - g x‖ }) l (𝓝 0) := by simp_rw [TendstoInMeasure, dist_eq_norm] #align measure_theory.tendsto_in_measure_iff_norm MeasureTheory.tendstoInMeasure_iff_norm namespace TendstoInMeasure variable [Dist E] {l : Filter ι} {f f' : ι → α → E} {g g' : α → E} protected theorem congr' (h_left : ∀ᶠ i in l, f i =ᵐ[μ] f' i) (h_right : g =ᵐ[μ] g') (h_tendsto : TendstoInMeasure μ f l g) : TendstoInMeasure μ f' l g' := by intro ε hε suffices (fun i => μ { x | ε ≤ dist (f' i x) (g' x) }) =ᶠ[l] fun i => μ { x | ε ≤ dist (f i x) (g x) } by rw [tendsto_congr' this] exact h_tendsto ε hε filter_upwards [h_left] with i h_ae_eq refine measure_congr ?_ filter_upwards [h_ae_eq, h_right] with x hxf hxg rw [eq_iff_iff] change ε ≤ dist (f' i x) (g' x) ↔ ε ≤ dist (f i x) (g x) rw [hxg, hxf] #align measure_theory.tendsto_in_measure.congr' MeasureTheory.TendstoInMeasure.congr' protected theorem congr (h_left : ∀ i, f i =ᵐ[μ] f' i) (h_right : g =ᵐ[μ] g') (h_tendsto : TendstoInMeasure μ f l g) : TendstoInMeasure μ f' l g' := TendstoInMeasure.congr' (eventually_of_forall h_left) h_right h_tendsto #align measure_theory.tendsto_in_measure.congr MeasureTheory.TendstoInMeasure.congr theorem congr_left (h : ∀ i, f i =ᵐ[μ] f' i) (h_tendsto : TendstoInMeasure μ f l g) : TendstoInMeasure μ f' l g := h_tendsto.congr h EventuallyEq.rfl #align measure_theory.tendsto_in_measure.congr_left MeasureTheory.TendstoInMeasure.congr_left theorem congr_right (h : g =ᵐ[μ] g') (h_tendsto : TendstoInMeasure μ f l g) : TendstoInMeasure μ f l g' := h_tendsto.congr (fun _ => EventuallyEq.rfl) h #align measure_theory.tendsto_in_measure.congr_right MeasureTheory.TendstoInMeasure.congr_right end TendstoInMeasure section ExistsSeqTendstoAe variable [MetricSpace E] variable {f : ℕ → α → E} {g : α → E} /-- Auxiliary lemma for `tendstoInMeasure_of_tendsto_ae`. -/ theorem tendstoInMeasure_of_tendsto_ae_of_stronglyMeasurable [IsFiniteMeasure μ] (hf : ∀ n, StronglyMeasurable (f n)) (hg : StronglyMeasurable g) (hfg : ∀ᵐ x ∂μ, Tendsto (fun n => f n x) atTop (𝓝 (g x))) : TendstoInMeasure μ f atTop g := by refine fun ε hε => ENNReal.tendsto_atTop_zero.mpr fun δ hδ => ?_ by_cases hδi : δ = ∞ · simp only [hδi, imp_true_iff, le_top, exists_const] lift δ to ℝ≥0 using hδi rw [gt_iff_lt, ENNReal.coe_pos, ← NNReal.coe_pos] at hδ obtain ⟨t, _, ht, hunif⟩ := tendstoUniformlyOn_of_ae_tendsto' hf hg hfg hδ rw [ENNReal.ofReal_coe_nnreal] at ht rw [Metric.tendstoUniformlyOn_iff] at hunif obtain ⟨N, hN⟩ := eventually_atTop.1 (hunif ε hε) refine ⟨N, fun n hn => ?_⟩ suffices { x : α | ε ≤ dist (f n x) (g x) } ⊆ t from (measure_mono this).trans ht rw [← Set.compl_subset_compl] intro x hx rw [Set.mem_compl_iff, Set.nmem_setOf_iff, dist_comm, not_le] exact hN n hn x hx #align measure_theory.tendsto_in_measure_of_tendsto_ae_of_strongly_measurable MeasureTheory.tendstoInMeasure_of_tendsto_ae_of_stronglyMeasurable /-- Convergence a.e. implies convergence in measure in a finite measure space. -/ theorem tendstoInMeasure_of_tendsto_ae [IsFiniteMeasure μ] (hf : ∀ n, AEStronglyMeasurable (f n) μ) (hfg : ∀ᵐ x ∂μ, Tendsto (fun n => f n x) atTop (𝓝 (g x))) : TendstoInMeasure μ f atTop g := by have hg : AEStronglyMeasurable g μ := aestronglyMeasurable_of_tendsto_ae _ hf hfg refine TendstoInMeasure.congr (fun i => (hf i).ae_eq_mk.symm) hg.ae_eq_mk.symm ?_ refine tendstoInMeasure_of_tendsto_ae_of_stronglyMeasurable (fun i => (hf i).stronglyMeasurable_mk) hg.stronglyMeasurable_mk ?_ have hf_eq_ae : ∀ᵐ x ∂μ, ∀ n, (hf n).mk (f n) x = f n x := ae_all_iff.mpr fun n => (hf n).ae_eq_mk.symm filter_upwards [hf_eq_ae, hg.ae_eq_mk, hfg] with x hxf hxg hxfg rw [← hxg, funext fun n => hxf n] exact hxfg #align measure_theory.tendsto_in_measure_of_tendsto_ae MeasureTheory.tendstoInMeasure_of_tendsto_ae namespace ExistsSeqTendstoAe theorem exists_nat_measure_lt_two_inv (hfg : TendstoInMeasure μ f atTop g) (n : ℕ) : ∃ N, ∀ m ≥ N, μ { x | (2 : ℝ)⁻¹ ^ n ≤ dist (f m x) (g x) } ≤ (2⁻¹ : ℝ≥0∞) ^ n := by specialize hfg ((2⁻¹ : ℝ) ^ n) (by simp only [Real.rpow_natCast, inv_pos, zero_lt_two, pow_pos]) rw [ENNReal.tendsto_atTop_zero] at hfg exact hfg ((2 : ℝ≥0∞)⁻¹ ^ n) (pos_iff_ne_zero.mpr fun h_zero => by simpa using pow_eq_zero h_zero) #align measure_theory.exists_seq_tendsto_ae.exists_nat_measure_lt_two_inv MeasureTheory.ExistsSeqTendstoAe.exists_nat_measure_lt_two_inv /-- Given a sequence of functions `f` which converges in measure to `g`, `seqTendstoAeSeqAux` is a sequence such that `∀ m ≥ seqTendstoAeSeqAux n, μ {x | 2⁻¹ ^ n ≤ dist (f m x) (g x)} ≤ 2⁻¹ ^ n`. -/ noncomputable def seqTendstoAeSeqAux (hfg : TendstoInMeasure μ f atTop g) (n : ℕ) := Classical.choose (exists_nat_measure_lt_two_inv hfg n) #align measure_theory.exists_seq_tendsto_ae.seq_tendsto_ae_seq_aux MeasureTheory.ExistsSeqTendstoAe.seqTendstoAeSeqAux /-- Transformation of `seqTendstoAeSeqAux` to makes sure it is strictly monotone. -/ noncomputable def seqTendstoAeSeq (hfg : TendstoInMeasure μ f atTop g) : ℕ → ℕ | 0 => seqTendstoAeSeqAux hfg 0 | n + 1 => max (seqTendstoAeSeqAux hfg (n + 1)) (seqTendstoAeSeq hfg n + 1) #align measure_theory.exists_seq_tendsto_ae.seq_tendsto_ae_seq MeasureTheory.ExistsSeqTendstoAe.seqTendstoAeSeq theorem seqTendstoAeSeq_succ (hfg : TendstoInMeasure μ f atTop g) {n : ℕ} : seqTendstoAeSeq hfg (n + 1) = max (seqTendstoAeSeqAux hfg (n + 1)) (seqTendstoAeSeq hfg n + 1) := by rw [seqTendstoAeSeq] #align measure_theory.exists_seq_tendsto_ae.seq_tendsto_ae_seq_succ MeasureTheory.ExistsSeqTendstoAe.seqTendstoAeSeq_succ theorem seqTendstoAeSeq_spec (hfg : TendstoInMeasure μ f atTop g) (n k : ℕ) (hn : seqTendstoAeSeq hfg n ≤ k) : μ { x | (2 : ℝ)⁻¹ ^ n ≤ dist (f k x) (g x) } ≤ (2 : ℝ≥0∞)⁻¹ ^ n := by cases n · exact Classical.choose_spec (exists_nat_measure_lt_two_inv hfg 0) k hn · exact Classical.choose_spec (exists_nat_measure_lt_two_inv hfg _) _ (le_trans (le_max_left _ _) hn) #align measure_theory.exists_seq_tendsto_ae.seq_tendsto_ae_seq_spec MeasureTheory.ExistsSeqTendstoAe.seqTendstoAeSeq_spec
Mathlib/MeasureTheory/Function/ConvergenceInMeasure.lean
178
182
theorem seqTendstoAeSeq_strictMono (hfg : TendstoInMeasure μ f atTop g) : StrictMono (seqTendstoAeSeq hfg) := by
refine strictMono_nat_of_lt_succ fun n => ?_ rw [seqTendstoAeSeq_succ] exact lt_of_lt_of_le (lt_add_one <| seqTendstoAeSeq hfg n) (le_max_right _ _)
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Init.Data.Ordering.Basic import Mathlib.Order.Synonym #align_import order.compare from "leanprover-community/mathlib"@"c4658a649d216f57e99621708b09dcb3dcccbd23" /-! # Comparison This file provides basic results about orderings and comparison in linear orders. ## Definitions * `CmpLE`: An `Ordering` from `≤`. * `Ordering.Compares`: Turns an `Ordering` into `<` and `=` propositions. * `linearOrderOfCompares`: Constructs a `LinearOrder` instance from the fact that any two elements that are not one strictly less than the other either way are equal. -/ variable {α β : Type*} /-- Like `cmp`, but uses a `≤` on the type instead of `<`. Given two elements `x` and `y`, returns a three-way comparison result `Ordering`. -/ def cmpLE {α} [LE α] [@DecidableRel α (· ≤ ·)] (x y : α) : Ordering := if x ≤ y then if y ≤ x then Ordering.eq else Ordering.lt else Ordering.gt #align cmp_le cmpLE theorem cmpLE_swap {α} [LE α] [IsTotal α (· ≤ ·)] [@DecidableRel α (· ≤ ·)] (x y : α) : (cmpLE x y).swap = cmpLE y x := by by_cases xy:x ≤ y <;> by_cases yx:y ≤ x <;> simp [cmpLE, *, Ordering.swap] cases not_or_of_not xy yx (total_of _ _ _) #align cmp_le_swap cmpLE_swap theorem cmpLE_eq_cmp {α} [Preorder α] [IsTotal α (· ≤ ·)] [@DecidableRel α (· ≤ ·)] [@DecidableRel α (· < ·)] (x y : α) : cmpLE x y = cmp x y := by by_cases xy:x ≤ y <;> by_cases yx:y ≤ x <;> simp [cmpLE, lt_iff_le_not_le, *, cmp, cmpUsing] cases not_or_of_not xy yx (total_of _ _ _) #align cmp_le_eq_cmp cmpLE_eq_cmp namespace Ordering /-- `Compares o a b` means that `a` and `b` have the ordering relation `o` between them, assuming that the relation `a < b` is defined. -/ -- Porting note: we have removed `@[simp]` here in favour of separate simp lemmas, -- otherwise this definition will unfold to a match. def Compares [LT α] : Ordering → α → α → Prop | lt, a, b => a < b | eq, a, b => a = b | gt, a, b => a > b #align ordering.compares Ordering.Compares @[simp] lemma compares_lt [LT α] (a b : α) : Compares lt a b = (a < b) := rfl @[simp] lemma compares_eq [LT α] (a b : α) : Compares eq a b = (a = b) := rfl @[simp] lemma compares_gt [LT α] (a b : α) : Compares gt a b = (a > b) := rfl theorem compares_swap [LT α] {a b : α} {o : Ordering} : o.swap.Compares a b ↔ o.Compares b a := by cases o · exact Iff.rfl · exact eq_comm · exact Iff.rfl #align ordering.compares_swap Ordering.compares_swap alias ⟨Compares.of_swap, Compares.swap⟩ := compares_swap #align ordering.compares.of_swap Ordering.Compares.of_swap #align ordering.compares.swap Ordering.Compares.swap theorem swap_eq_iff_eq_swap {o o' : Ordering} : o.swap = o' ↔ o = o'.swap := by rw [← swap_inj, swap_swap] #align ordering.swap_eq_iff_eq_swap Ordering.swap_eq_iff_eq_swap theorem Compares.eq_lt [Preorder α] : ∀ {o} {a b : α}, Compares o a b → (o = lt ↔ a < b) | lt, a, b, h => ⟨fun _ => h, fun _ => rfl⟩ | eq, a, b, h => ⟨fun h => by injection h, fun h' => (ne_of_lt h' h).elim⟩ | gt, a, b, h => ⟨fun h => by injection h, fun h' => (lt_asymm h h').elim⟩ #align ordering.compares.eq_lt Ordering.Compares.eq_lt theorem Compares.ne_lt [Preorder α] : ∀ {o} {a b : α}, Compares o a b → (o ≠ lt ↔ b ≤ a) | lt, a, b, h => ⟨absurd rfl, fun h' => (not_le_of_lt h h').elim⟩ | eq, a, b, h => ⟨fun _ => ge_of_eq h, fun _ h => by injection h⟩ | gt, a, b, h => ⟨fun _ => le_of_lt h, fun _ h => by injection h⟩ #align ordering.compares.ne_lt Ordering.Compares.ne_lt theorem Compares.eq_eq [Preorder α] : ∀ {o} {a b : α}, Compares o a b → (o = eq ↔ a = b) | lt, a, b, h => ⟨fun h => by injection h, fun h' => (ne_of_lt h h').elim⟩ | eq, a, b, h => ⟨fun _ => h, fun _ => rfl⟩ | gt, a, b, h => ⟨fun h => by injection h, fun h' => (ne_of_gt h h').elim⟩ #align ordering.compares.eq_eq Ordering.Compares.eq_eq theorem Compares.eq_gt [Preorder α] {o} {a b : α} (h : Compares o a b) : o = gt ↔ b < a := swap_eq_iff_eq_swap.symm.trans h.swap.eq_lt #align ordering.compares.eq_gt Ordering.Compares.eq_gt theorem Compares.ne_gt [Preorder α] {o} {a b : α} (h : Compares o a b) : o ≠ gt ↔ a ≤ b := (not_congr swap_eq_iff_eq_swap.symm).trans h.swap.ne_lt #align ordering.compares.ne_gt Ordering.Compares.ne_gt theorem Compares.le_total [Preorder α] {a b : α} : ∀ {o}, Compares o a b → a ≤ b ∨ b ≤ a | lt, h => Or.inl (le_of_lt h) | eq, h => Or.inl (le_of_eq h) | gt, h => Or.inr (le_of_lt h) #align ordering.compares.le_total Ordering.Compares.le_total theorem Compares.le_antisymm [Preorder α] {a b : α} : ∀ {o}, Compares o a b → a ≤ b → b ≤ a → a = b | lt, h, _, hba => (not_le_of_lt h hba).elim | eq, h, _, _ => h | gt, h, hab, _ => (not_le_of_lt h hab).elim #align ordering.compares.le_antisymm Ordering.Compares.le_antisymm theorem Compares.inj [Preorder α] {o₁} : ∀ {o₂} {a b : α}, Compares o₁ a b → Compares o₂ a b → o₁ = o₂ | lt, _, _, h₁, h₂ => h₁.eq_lt.2 h₂ | eq, _, _, h₁, h₂ => h₁.eq_eq.2 h₂ | gt, _, _, h₁, h₂ => h₁.eq_gt.2 h₂ #align ordering.compares.inj Ordering.Compares.inj -- Porting note: mathlib3 proof uses `change ... at hab` theorem compares_iff_of_compares_impl [LinearOrder α] [Preorder β] {a b : α} {a' b' : β} (h : ∀ {o}, Compares o a b → Compares o a' b') (o) : Compares o a b ↔ Compares o a' b' := by refine ⟨h, fun ho => ?_⟩ cases' lt_trichotomy a b with hab hab · have hab : Compares Ordering.lt a b := hab rwa [ho.inj (h hab)] · cases' hab with hab hab · have hab : Compares Ordering.eq a b := hab rwa [ho.inj (h hab)] · have hab : Compares Ordering.gt a b := hab rwa [ho.inj (h hab)] #align ordering.compares_iff_of_compares_impl Ordering.compares_iff_of_compares_impl theorem swap_orElse (o₁ o₂) : (orElse o₁ o₂).swap = orElse o₁.swap o₂.swap := by cases o₁ <;> rfl #align ordering.swap_or_else Ordering.swap_orElse theorem orElse_eq_lt (o₁ o₂) : orElse o₁ o₂ = lt ↔ o₁ = lt ∨ o₁ = eq ∧ o₂ = lt := by cases o₁ <;> cases o₂ <;> decide #align ordering.or_else_eq_lt Ordering.orElse_eq_lt end Ordering open Ordering OrderDual @[simp] theorem toDual_compares_toDual [LT α] {a b : α} {o : Ordering} : Compares o (toDual a) (toDual b) ↔ Compares o b a := by cases o exacts [Iff.rfl, eq_comm, Iff.rfl] #align to_dual_compares_to_dual toDual_compares_toDual @[simp] theorem ofDual_compares_ofDual [LT α] {a b : αᵒᵈ} {o : Ordering} : Compares o (ofDual a) (ofDual b) ↔ Compares o b a := by cases o exacts [Iff.rfl, eq_comm, Iff.rfl] #align of_dual_compares_of_dual ofDual_compares_ofDual
Mathlib/Order/Compare.lean
167
168
theorem cmp_compares [LinearOrder α] (a b : α) : (cmp a b).Compares a b := by
obtain h | h | h := lt_trichotomy a b <;> simp [cmp, cmpUsing, h, h.not_lt]
/- Copyright (c) 2019 Neil Strickland. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Neil Strickland -/ import Mathlib.Algebra.BigOperators.Intervals import Mathlib.Algebra.BigOperators.Ring import Mathlib.Algebra.Order.BigOperators.Ring.Finset import Mathlib.Algebra.Order.Field.Basic import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Algebra.Ring.Opposite import Mathlib.Tactic.Abel #align_import algebra.geom_sum from "leanprover-community/mathlib"@"f7fc89d5d5ff1db2d1242c7bb0e9062ce47ef47c" /-! # Partial sums of geometric series This file determines the values of the geometric series $\sum_{i=0}^{n-1} x^i$ and $\sum_{i=0}^{n-1} x^i y^{n-1-i}$ and variants thereof. We also provide some bounds on the "geometric" sum of `a/b^i` where `a b : ℕ`. ## Main statements * `geom_sum_Ico` proves that $\sum_{i=m}^{n-1} x^i=\frac{x^n-x^m}{x-1}$ in a division ring. * `geom_sum₂_Ico` proves that $\sum_{i=m}^{n-1} x^iy^{n - 1 - i}=\frac{x^n-y^{n-m}x^m}{x-y}$ in a field. Several variants are recorded, generalising in particular to the case of a noncommutative ring in which `x` and `y` commute. Even versions not using division or subtraction, valid in each semiring, are recorded. -/ -- Porting note: corrected type in the description of `geom_sum₂_Ico` (in the doc string only). universe u variable {α : Type u} open Finset MulOpposite section Semiring variable [Semiring α] theorem geom_sum_succ {x : α} {n : ℕ} : ∑ i ∈ range (n + 1), x ^ i = (x * ∑ i ∈ range n, x ^ i) + 1 := by simp only [mul_sum, ← pow_succ', sum_range_succ', pow_zero] #align geom_sum_succ geom_sum_succ theorem geom_sum_succ' {x : α} {n : ℕ} : ∑ i ∈ range (n + 1), x ^ i = x ^ n + ∑ i ∈ range n, x ^ i := (sum_range_succ _ _).trans (add_comm _ _) #align geom_sum_succ' geom_sum_succ' theorem geom_sum_zero (x : α) : ∑ i ∈ range 0, x ^ i = 0 := rfl #align geom_sum_zero geom_sum_zero theorem geom_sum_one (x : α) : ∑ i ∈ range 1, x ^ i = 1 := by simp [geom_sum_succ'] #align geom_sum_one geom_sum_one @[simp] theorem geom_sum_two {x : α} : ∑ i ∈ range 2, x ^ i = x + 1 := by simp [geom_sum_succ'] #align geom_sum_two geom_sum_two @[simp] theorem zero_geom_sum : ∀ {n}, ∑ i ∈ range n, (0 : α) ^ i = if n = 0 then 0 else 1 | 0 => by simp | 1 => by simp | n + 2 => by rw [geom_sum_succ'] simp [zero_geom_sum] #align zero_geom_sum zero_geom_sum theorem one_geom_sum (n : ℕ) : ∑ i ∈ range n, (1 : α) ^ i = n := by simp #align one_geom_sum one_geom_sum -- porting note (#10618): simp can prove this -- @[simp] theorem op_geom_sum (x : α) (n : ℕ) : op (∑ i ∈ range n, x ^ i) = ∑ i ∈ range n, op x ^ i := by simp #align op_geom_sum op_geom_sum -- Porting note: linter suggested to change left hand side @[simp] theorem op_geom_sum₂ (x y : α) (n : ℕ) : ∑ i ∈ range n, op y ^ (n - 1 - i) * op x ^ i = ∑ i ∈ range n, op y ^ i * op x ^ (n - 1 - i) := by rw [← sum_range_reflect] refine sum_congr rfl fun j j_in => ?_ rw [mem_range, Nat.lt_iff_add_one_le] at j_in congr apply tsub_tsub_cancel_of_le exact le_tsub_of_add_le_right j_in #align op_geom_sum₂ op_geom_sum₂ theorem geom_sum₂_with_one (x : α) (n : ℕ) : ∑ i ∈ range n, x ^ i * 1 ^ (n - 1 - i) = ∑ i ∈ range n, x ^ i := sum_congr rfl fun i _ => by rw [one_pow, mul_one] #align geom_sum₂_with_one geom_sum₂_with_one /-- $x^n-y^n = (x-y) \sum x^ky^{n-1-k}$ reformulated without `-` signs. -/ protected theorem Commute.geom_sum₂_mul_add {x y : α} (h : Commute x y) (n : ℕ) : (∑ i ∈ range n, (x + y) ^ i * y ^ (n - 1 - i)) * x + y ^ n = (x + y) ^ n := by let f : ℕ → ℕ → α := fun m i : ℕ => (x + y) ^ i * y ^ (m - 1 - i) -- Porting note: adding `hf` here, because below in two places `dsimp [f]` didn't work have hf : ∀ m i : ℕ, f m i = (x + y) ^ i * y ^ (m - 1 - i) := by simp only [ge_iff_le, tsub_le_iff_right, forall_const] change (∑ i ∈ range n, (f n) i) * x + y ^ n = (x + y) ^ n induction' n with n ih · rw [range_zero, sum_empty, zero_mul, zero_add, pow_zero, pow_zero] · have f_last : f (n + 1) n = (x + y) ^ n := by rw [hf, ← tsub_add_eq_tsub_tsub, Nat.add_comm, tsub_self, pow_zero, mul_one] have f_succ : ∀ i, i ∈ range n → f (n + 1) i = y * f n i := fun i hi => by rw [hf] have : Commute y ((x + y) ^ i) := (h.symm.add_right (Commute.refl y)).pow_right i rw [← mul_assoc, this.eq, mul_assoc, ← pow_succ' y (n - 1 - i)] congr 2 rw [add_tsub_cancel_right, ← tsub_add_eq_tsub_tsub, add_comm 1 i] have : i + 1 + (n - (i + 1)) = n := add_tsub_cancel_of_le (mem_range.mp hi) rw [add_comm (i + 1)] at this rw [← this, add_tsub_cancel_right, add_comm i 1, ← add_assoc, add_tsub_cancel_right] rw [pow_succ' (x + y), add_mul, sum_range_succ_comm, add_mul, f_last, add_assoc] rw [(((Commute.refl x).add_right h).pow_right n).eq] congr 1 rw [sum_congr rfl f_succ, ← mul_sum, pow_succ' y, mul_assoc, ← mul_add y, ih] #align commute.geom_sum₂_mul_add Commute.geom_sum₂_mul_add end Semiring @[simp] theorem neg_one_geom_sum [Ring α] {n : ℕ} : ∑ i ∈ range n, (-1 : α) ^ i = if Even n then 0 else 1 := by induction' n with k hk · simp · simp only [geom_sum_succ', Nat.even_add_one, hk] split_ifs with h · rw [h.neg_one_pow, add_zero] · rw [(Nat.odd_iff_not_even.2 h).neg_one_pow, neg_add_self] #align neg_one_geom_sum neg_one_geom_sum theorem geom_sum₂_self {α : Type*} [CommRing α] (x : α) (n : ℕ) : ∑ i ∈ range n, x ^ i * x ^ (n - 1 - i) = n * x ^ (n - 1) := calc ∑ i ∈ Finset.range n, x ^ i * x ^ (n - 1 - i) = ∑ i ∈ Finset.range n, x ^ (i + (n - 1 - i)) := by simp_rw [← pow_add] _ = ∑ _i ∈ Finset.range n, x ^ (n - 1) := Finset.sum_congr rfl fun i hi => congr_arg _ <| add_tsub_cancel_of_le <| Nat.le_sub_one_of_lt <| Finset.mem_range.1 hi _ = (Finset.range n).card • x ^ (n - 1) := Finset.sum_const _ _ = n * x ^ (n - 1) := by rw [Finset.card_range, nsmul_eq_mul] #align geom_sum₂_self geom_sum₂_self /-- $x^n-y^n = (x-y) \sum x^ky^{n-1-k}$ reformulated without `-` signs. -/ theorem geom_sum₂_mul_add [CommSemiring α] (x y : α) (n : ℕ) : (∑ i ∈ range n, (x + y) ^ i * y ^ (n - 1 - i)) * x + y ^ n = (x + y) ^ n := (Commute.all x y).geom_sum₂_mul_add n #align geom_sum₂_mul_add geom_sum₂_mul_add theorem geom_sum_mul_add [Semiring α] (x : α) (n : ℕ) : (∑ i ∈ range n, (x + 1) ^ i) * x + 1 = (x + 1) ^ n := by have := (Commute.one_right x).geom_sum₂_mul_add n rw [one_pow, geom_sum₂_with_one] at this exact this #align geom_sum_mul_add geom_sum_mul_add protected theorem Commute.geom_sum₂_mul [Ring α] {x y : α} (h : Commute x y) (n : ℕ) : (∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) * (x - y) = x ^ n - y ^ n := by have := (h.sub_left (Commute.refl y)).geom_sum₂_mul_add n rw [sub_add_cancel] at this rw [← this, add_sub_cancel_right] #align commute.geom_sum₂_mul Commute.geom_sum₂_mul
Mathlib/Algebra/GeomSum.lean
175
179
theorem Commute.mul_neg_geom_sum₂ [Ring α] {x y : α} (h : Commute x y) (n : ℕ) : ((y - x) * ∑ i ∈ range n, x ^ i * y ^ (n - 1 - i)) = y ^ n - x ^ n := by
apply op_injective simp only [op_mul, op_sub, op_geom_sum₂, op_pow] simp [(Commute.op h.symm).geom_sum₂_mul n]
/- Copyright (c) 2023 Peter Nelson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Peter Nelson -/ import Mathlib.SetTheory.Cardinal.Finite #align_import data.set.ncard from "leanprover-community/mathlib"@"74c2af38a828107941029b03839882c5c6f87a04" /-! # Noncomputable Set Cardinality We define the cardinality of set `s` as a term `Set.encard s : ℕ∞` and a term `Set.ncard s : ℕ`. The latter takes the junk value of zero if `s` is infinite. Both functions are noncomputable, and are defined in terms of `PartENat.card` (which takes a type as its argument); this file can be seen as an API for the same function in the special case where the type is a coercion of a `Set`, allowing for smoother interactions with the `Set` API. `Set.encard` never takes junk values, so is more mathematically natural than `Set.ncard`, even though it takes values in a less convenient type. It is probably the right choice in settings where one is concerned with the cardinalities of sets that may or may not be infinite. `Set.ncard` has a nicer codomain, but when using it, `Set.Finite` hypotheses are normally needed to make sure its values are meaningful. More generally, `Set.ncard` is intended to be used over the obvious alternative `Finset.card` when finiteness is 'propositional' rather than 'structural'. When working with sets that are finite by virtue of their definition, then `Finset.card` probably makes more sense. One setting where `Set.ncard` works nicely is in a type `α` with `[Finite α]`, where every set is automatically finite. In this setting, we use default arguments and a simple tactic so that finiteness goals are discharged automatically in `Set.ncard` theorems. ## Main Definitions * `Set.encard s` is the cardinality of the set `s` as an extended natural number, with value `⊤` if `s` is infinite. * `Set.ncard s` is the cardinality of the set `s` as a natural number, provided `s` is Finite. If `s` is Infinite, then `Set.ncard s = 0`. * `toFinite_tac` is a tactic that tries to synthesize a `Set.Finite s` argument with `Set.toFinite`. This will work for `s : Set α` where there is a `Finite α` instance. ## Implementation Notes The theorems in this file are very similar to those in `Data.Finset.Card`, but with `Set` operations instead of `Finset`. We first prove all the theorems for `Set.encard`, and then derive most of the `Set.ncard` results as a consequence. Things are done this way to avoid reliance on the `Finset` API for theorems about infinite sets, and to allow for a refactor that removes or modifies `Set.ncard` in the future. Nearly all the theorems for `Set.ncard` require finiteness of one or more of their arguments. We provide this assumption with a default argument of the form `(hs : s.Finite := by toFinite_tac)`, where `toFinite_tac` will find an `s.Finite` term in the cases where `s` is a set in a `Finite` type. Often, where there are two set arguments `s` and `t`, the finiteness of one follows from the other in the context of the theorem, in which case we only include the ones that are needed, and derive the other inside the proof. A few of the theorems, such as `ncard_union_le` do not require finiteness arguments; they are true by coincidence due to junk values. -/ namespace Set variable {α β : Type*} {s t : Set α} /-- The cardinality of a set as a term in `ℕ∞` -/ noncomputable def encard (s : Set α) : ℕ∞ := PartENat.withTopEquiv (PartENat.card s) @[simp] theorem encard_univ_coe (s : Set α) : encard (univ : Set s) = encard s := by rw [encard, encard, PartENat.card_congr (Equiv.Set.univ ↑s)] theorem encard_univ (α : Type*) : encard (univ : Set α) = PartENat.withTopEquiv (PartENat.card α) := by rw [encard, PartENat.card_congr (Equiv.Set.univ α)] theorem Finite.encard_eq_coe_toFinset_card (h : s.Finite) : s.encard = h.toFinset.card := by have := h.fintype rw [encard, PartENat.card_eq_coe_fintype_card, PartENat.withTopEquiv_natCast, toFinite_toFinset, toFinset_card] theorem encard_eq_coe_toFinset_card (s : Set α) [Fintype s] : encard s = s.toFinset.card := by have h := toFinite s rw [h.encard_eq_coe_toFinset_card, toFinite_toFinset] theorem encard_coe_eq_coe_finsetCard (s : Finset α) : encard (s : Set α) = s.card := by rw [Finite.encard_eq_coe_toFinset_card (Finset.finite_toSet s)]; simp theorem Infinite.encard_eq {s : Set α} (h : s.Infinite) : s.encard = ⊤ := by have := h.to_subtype rw [encard, ← PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply, PartENat.withTopEquiv_symm_top, PartENat.card_eq_top_of_infinite] @[simp] theorem encard_eq_zero : s.encard = 0 ↔ s = ∅ := by rw [encard, ← PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply, PartENat.withTopEquiv_symm_zero, PartENat.card_eq_zero_iff_empty, isEmpty_subtype, eq_empty_iff_forall_not_mem] @[simp] theorem encard_empty : (∅ : Set α).encard = 0 := by rw [encard_eq_zero] theorem nonempty_of_encard_ne_zero (h : s.encard ≠ 0) : s.Nonempty := by rwa [nonempty_iff_ne_empty, Ne, ← encard_eq_zero] theorem encard_ne_zero : s.encard ≠ 0 ↔ s.Nonempty := by rw [ne_eq, encard_eq_zero, nonempty_iff_ne_empty] @[simp] theorem encard_pos : 0 < s.encard ↔ s.Nonempty := by rw [pos_iff_ne_zero, encard_ne_zero] @[simp] theorem encard_singleton (e : α) : ({e} : Set α).encard = 1 := by rw [encard, ← PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply, PartENat.card_eq_coe_fintype_card, Fintype.card_ofSubsingleton, Nat.cast_one]; rfl theorem encard_union_eq (h : Disjoint s t) : (s ∪ t).encard = s.encard + t.encard := by classical have e := (Equiv.Set.union (by rwa [subset_empty_iff, ← disjoint_iff_inter_eq_empty])).symm simp [encard, ← PartENat.card_congr e, PartENat.card_sum, PartENat.withTopEquiv]
Mathlib/Data/Set/Card.lean
116
117
theorem encard_insert_of_not_mem {a : α} (has : a ∉ s) : (insert a s).encard = s.encard + 1 := by
rw [← union_singleton, encard_union_eq (by simpa), encard_singleton]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Kevin Buzzard, Yury Kudryashov, Frédéric Dupuis, Heather Macbeth -/ import Mathlib.Algebra.Module.Submodule.EqLocus import Mathlib.Algebra.Module.Submodule.RestrictScalars import Mathlib.Algebra.Ring.Idempotents import Mathlib.Data.Set.Pointwise.SMul import Mathlib.LinearAlgebra.Basic import Mathlib.Order.CompactlyGenerated.Basic import Mathlib.Order.OmegaCompletePartialOrder #align_import linear_algebra.span from "leanprover-community/mathlib"@"10878f6bf1dab863445907ab23fbfcefcb5845d0" /-! # The span of a set of vectors, as a submodule * `Submodule.span s` is defined to be the smallest submodule containing the set `s`. ## Notations * We introduce the notation `R ∙ v` for the span of a singleton, `Submodule.span R {v}`. This is `\span`, not the same as the scalar multiplication `•`/`\bub`. -/ variable {R R₂ K M M₂ V S : Type*} namespace Submodule open Function Set open Pointwise section AddCommMonoid variable [Semiring R] [AddCommMonoid M] [Module R M] variable {x : M} (p p' : Submodule R M) variable [Semiring R₂] {σ₁₂ : R →+* R₂} variable [AddCommMonoid M₂] [Module R₂ M₂] variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F σ₁₂ M M₂] section variable (R) /-- The span of a set `s ⊆ M` is the smallest submodule of M that contains `s`. -/ def span (s : Set M) : Submodule R M := sInf { p | s ⊆ p } #align submodule.span Submodule.span variable {R} -- Porting note: renamed field to `principal'` and added `principal` to fix explicit argument /-- An `R`-submodule of `M` is principal if it is generated by one element. -/ @[mk_iff] class IsPrincipal (S : Submodule R M) : Prop where principal' : ∃ a, S = span R {a} #align submodule.is_principal Submodule.IsPrincipal theorem IsPrincipal.principal (S : Submodule R M) [S.IsPrincipal] : ∃ a, S = span R {a} := Submodule.IsPrincipal.principal' #align submodule.is_principal.principal Submodule.IsPrincipal.principal end variable {s t : Set M} theorem mem_span : x ∈ span R s ↔ ∀ p : Submodule R M, s ⊆ p → x ∈ p := mem_iInter₂ #align submodule.mem_span Submodule.mem_span @[aesop safe 20 apply (rule_sets := [SetLike])] theorem subset_span : s ⊆ span R s := fun _ h => mem_span.2 fun _ hp => hp h #align submodule.subset_span Submodule.subset_span theorem span_le {p} : span R s ≤ p ↔ s ⊆ p := ⟨Subset.trans subset_span, fun ss _ h => mem_span.1 h _ ss⟩ #align submodule.span_le Submodule.span_le theorem span_mono (h : s ⊆ t) : span R s ≤ span R t := span_le.2 <| Subset.trans h subset_span #align submodule.span_mono Submodule.span_mono theorem span_monotone : Monotone (span R : Set M → Submodule R M) := fun _ _ => span_mono #align submodule.span_monotone Submodule.span_monotone theorem span_eq_of_le (h₁ : s ⊆ p) (h₂ : p ≤ span R s) : span R s = p := le_antisymm (span_le.2 h₁) h₂ #align submodule.span_eq_of_le Submodule.span_eq_of_le theorem span_eq : span R (p : Set M) = p := span_eq_of_le _ (Subset.refl _) subset_span #align submodule.span_eq Submodule.span_eq theorem span_eq_span (hs : s ⊆ span R t) (ht : t ⊆ span R s) : span R s = span R t := le_antisymm (span_le.2 hs) (span_le.2 ht) #align submodule.span_eq_span Submodule.span_eq_span /-- A version of `Submodule.span_eq` for subobjects closed under addition and scalar multiplication and containing zero. In general, this should not be used directly, but can be used to quickly generate proofs for specific types of subobjects. -/ lemma coe_span_eq_self [SetLike S M] [AddSubmonoidClass S M] [SMulMemClass S R M] (s : S) : (span R (s : Set M) : Set M) = s := by refine le_antisymm ?_ subset_span let s' : Submodule R M := { carrier := s add_mem' := add_mem zero_mem' := zero_mem _ smul_mem' := SMulMemClass.smul_mem } exact span_le (p := s') |>.mpr le_rfl /-- A version of `Submodule.span_eq` for when the span is by a smaller ring. -/ @[simp] theorem span_coe_eq_restrictScalars [Semiring S] [SMul S R] [Module S M] [IsScalarTower S R M] : span S (p : Set M) = p.restrictScalars S := span_eq (p.restrictScalars S) #align submodule.span_coe_eq_restrict_scalars Submodule.span_coe_eq_restrictScalars /-- A version of `Submodule.map_span_le` that does not require the `RingHomSurjective` assumption. -/ theorem image_span_subset (f : F) (s : Set M) (N : Submodule R₂ M₂) : f '' span R s ⊆ N ↔ ∀ m ∈ s, f m ∈ N := image_subset_iff.trans <| span_le (p := N.comap f) theorem image_span_subset_span (f : F) (s : Set M) : f '' span R s ⊆ span R₂ (f '' s) := (image_span_subset f s _).2 fun x hx ↦ subset_span ⟨x, hx, rfl⟩ theorem map_span [RingHomSurjective σ₁₂] (f : F) (s : Set M) : (span R s).map f = span R₂ (f '' s) := Eq.symm <| span_eq_of_le _ (Set.image_subset f subset_span) (image_span_subset_span f s) #align submodule.map_span Submodule.map_span alias _root_.LinearMap.map_span := Submodule.map_span #align linear_map.map_span LinearMap.map_span theorem map_span_le [RingHomSurjective σ₁₂] (f : F) (s : Set M) (N : Submodule R₂ M₂) : map f (span R s) ≤ N ↔ ∀ m ∈ s, f m ∈ N := image_span_subset f s N #align submodule.map_span_le Submodule.map_span_le alias _root_.LinearMap.map_span_le := Submodule.map_span_le #align linear_map.map_span_le LinearMap.map_span_le @[simp] theorem span_insert_zero : span R (insert (0 : M) s) = span R s := by refine le_antisymm ?_ (Submodule.span_mono (Set.subset_insert 0 s)) rw [span_le, Set.insert_subset_iff] exact ⟨by simp only [SetLike.mem_coe, Submodule.zero_mem], Submodule.subset_span⟩ #align submodule.span_insert_zero Submodule.span_insert_zero -- See also `span_preimage_eq` below. theorem span_preimage_le (f : F) (s : Set M₂) : span R (f ⁻¹' s) ≤ (span R₂ s).comap f := by rw [span_le, comap_coe] exact preimage_mono subset_span #align submodule.span_preimage_le Submodule.span_preimage_le alias _root_.LinearMap.span_preimage_le := Submodule.span_preimage_le #align linear_map.span_preimage_le LinearMap.span_preimage_le theorem closure_subset_span {s : Set M} : (AddSubmonoid.closure s : Set M) ⊆ span R s := (@AddSubmonoid.closure_le _ _ _ (span R s).toAddSubmonoid).mpr subset_span #align submodule.closure_subset_span Submodule.closure_subset_span theorem closure_le_toAddSubmonoid_span {s : Set M} : AddSubmonoid.closure s ≤ (span R s).toAddSubmonoid := closure_subset_span #align submodule.closure_le_to_add_submonoid_span Submodule.closure_le_toAddSubmonoid_span @[simp] theorem span_closure {s : Set M} : span R (AddSubmonoid.closure s : Set M) = span R s := le_antisymm (span_le.mpr closure_subset_span) (span_mono AddSubmonoid.subset_closure) #align submodule.span_closure Submodule.span_closure /-- An induction principle for span membership. If `p` holds for 0 and all elements of `s`, and is preserved under addition and scalar multiplication, then `p` holds for all elements of the span of `s`. -/ @[elab_as_elim] theorem span_induction {p : M → Prop} (h : x ∈ span R s) (mem : ∀ x ∈ s, p x) (zero : p 0) (add : ∀ x y, p x → p y → p (x + y)) (smul : ∀ (a : R) (x), p x → p (a • x)) : p x := ((@span_le (p := ⟨⟨⟨p, by intros x y; exact add x y⟩, zero⟩, smul⟩)) s).2 mem h #align submodule.span_induction Submodule.span_induction /-- An induction principle for span membership. This is a version of `Submodule.span_induction` for binary predicates. -/ theorem span_induction₂ {p : M → M → Prop} {a b : M} (ha : a ∈ Submodule.span R s) (hb : b ∈ Submodule.span R s) (mem_mem : ∀ x ∈ s, ∀ y ∈ s, p x y) (zero_left : ∀ y, p 0 y) (zero_right : ∀ x, p x 0) (add_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ + x₂) y) (add_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ + y₂)) (smul_left : ∀ (r : R) x y, p x y → p (r • x) y) (smul_right : ∀ (r : R) x y, p x y → p x (r • y)) : p a b := Submodule.span_induction ha (fun x hx => Submodule.span_induction hb (mem_mem x hx) (zero_right x) (add_right x) fun r => smul_right r x) (zero_left b) (fun x₁ x₂ => add_left x₁ x₂ b) fun r x => smul_left r x b /-- A dependent version of `Submodule.span_induction`. -/ @[elab_as_elim] theorem span_induction' {p : ∀ x, x ∈ span R s → Prop} (mem : ∀ (x) (h : x ∈ s), p x (subset_span h)) (zero : p 0 (Submodule.zero_mem _)) (add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (Submodule.add_mem _ ‹_› ‹_›)) (smul : ∀ (a : R) (x hx), p x hx → p (a • x) (Submodule.smul_mem _ _ ‹_›)) {x} (hx : x ∈ span R s) : p x hx := by refine Exists.elim ?_ fun (hx : x ∈ span R s) (hc : p x hx) => hc refine span_induction hx (fun m hm => ⟨subset_span hm, mem m hm⟩) ⟨zero_mem _, zero⟩ (fun x y hx hy => Exists.elim hx fun hx' hx => Exists.elim hy fun hy' hy => ⟨add_mem hx' hy', add _ _ _ _ hx hy⟩) fun r x hx => Exists.elim hx fun hx' hx => ⟨smul_mem _ _ hx', smul r _ _ hx⟩ #align submodule.span_induction' Submodule.span_induction' open AddSubmonoid in theorem span_eq_closure {s : Set M} : (span R s).toAddSubmonoid = closure (@univ R • s) := by refine le_antisymm (fun x hx ↦ span_induction hx (fun x hx ↦ subset_closure ⟨1, trivial, x, hx, one_smul R x⟩) (zero_mem _) (fun _ _ ↦ add_mem) fun r m hm ↦ closure_induction hm ?_ ?_ fun _ _ h h' ↦ ?_) (closure_le.2 ?_) · rintro _ ⟨r, -, m, hm, rfl⟩; exact smul_mem _ _ (subset_span hm) · rintro _ ⟨r', -, m, hm, rfl⟩; exact subset_closure ⟨r * r', trivial, m, hm, mul_smul r r' m⟩ · rw [smul_zero]; apply zero_mem · rw [smul_add]; exact add_mem h h' /-- A variant of `span_induction` that combines `∀ x ∈ s, p x` and `∀ r x, p x → p (r • x)` into a single condition `∀ r, ∀ x ∈ s, p (r • x)`, which can be easier to verify. -/ @[elab_as_elim] theorem closure_induction {p : M → Prop} (h : x ∈ span R s) (zero : p 0) (add : ∀ x y, p x → p y → p (x + y)) (smul_mem : ∀ r : R, ∀ x ∈ s, p (r • x)) : p x := by rw [← mem_toAddSubmonoid, span_eq_closure] at h refine AddSubmonoid.closure_induction h ?_ zero add rintro _ ⟨r, -, m, hm, rfl⟩ exact smul_mem r m hm /-- A dependent version of `Submodule.closure_induction`. -/ @[elab_as_elim] theorem closure_induction' {p : ∀ x, x ∈ span R s → Prop} (zero : p 0 (Submodule.zero_mem _)) (add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (Submodule.add_mem _ ‹_› ‹_›)) (smul_mem : ∀ (r x) (h : x ∈ s), p (r • x) (Submodule.smul_mem _ _ <| subset_span h)) {x} (hx : x ∈ span R s) : p x hx := by refine Exists.elim ?_ fun (hx : x ∈ span R s) (hc : p x hx) ↦ hc refine closure_induction hx ⟨zero_mem _, zero⟩ (fun x y hx hy ↦ Exists.elim hx fun hx' hx ↦ Exists.elim hy fun hy' hy ↦ ⟨add_mem hx' hy', add _ _ _ _ hx hy⟩) fun r x hx ↦ ⟨Submodule.smul_mem _ _ (subset_span hx), smul_mem r x hx⟩ @[simp] theorem span_span_coe_preimage : span R (((↑) : span R s → M) ⁻¹' s) = ⊤ := eq_top_iff.2 fun x ↦ Subtype.recOn x fun x hx _ ↦ by refine span_induction' (p := fun x hx ↦ (⟨x, hx⟩ : span R s) ∈ span R (Subtype.val ⁻¹' s)) (fun x' hx' ↦ subset_span hx') ?_ (fun x _ y _ ↦ ?_) (fun r x _ ↦ ?_) hx · exact zero_mem _ · exact add_mem · exact smul_mem _ _ #align submodule.span_span_coe_preimage Submodule.span_span_coe_preimage @[simp] lemma span_setOf_mem_eq_top : span R {x : span R s | (x : M) ∈ s} = ⊤ := span_span_coe_preimage theorem span_nat_eq_addSubmonoid_closure (s : Set M) : (span ℕ s).toAddSubmonoid = AddSubmonoid.closure s := by refine Eq.symm (AddSubmonoid.closure_eq_of_le subset_span ?_) apply (OrderIso.to_galoisConnection (AddSubmonoid.toNatSubmodule (M := M)).symm).l_le (a := span ℕ s) (b := AddSubmonoid.closure s) rw [span_le] exact AddSubmonoid.subset_closure #align submodule.span_nat_eq_add_submonoid_closure Submodule.span_nat_eq_addSubmonoid_closure @[simp] theorem span_nat_eq (s : AddSubmonoid M) : (span ℕ (s : Set M)).toAddSubmonoid = s := by rw [span_nat_eq_addSubmonoid_closure, s.closure_eq] #align submodule.span_nat_eq Submodule.span_nat_eq theorem span_int_eq_addSubgroup_closure {M : Type*} [AddCommGroup M] (s : Set M) : (span ℤ s).toAddSubgroup = AddSubgroup.closure s := Eq.symm <| AddSubgroup.closure_eq_of_le _ subset_span fun x hx => span_induction hx (fun x hx => AddSubgroup.subset_closure hx) (AddSubgroup.zero_mem _) (fun _ _ => AddSubgroup.add_mem _) fun _ _ _ => AddSubgroup.zsmul_mem _ ‹_› _ #align submodule.span_int_eq_add_subgroup_closure Submodule.span_int_eq_addSubgroup_closure @[simp] theorem span_int_eq {M : Type*} [AddCommGroup M] (s : AddSubgroup M) : (span ℤ (s : Set M)).toAddSubgroup = s := by rw [span_int_eq_addSubgroup_closure, s.closure_eq] #align submodule.span_int_eq Submodule.span_int_eq section variable (R M) /-- `span` forms a Galois insertion with the coercion from submodule to set. -/ protected def gi : GaloisInsertion (@span R M _ _ _) (↑) where choice s _ := span R s gc _ _ := span_le le_l_u _ := subset_span choice_eq _ _ := rfl #align submodule.gi Submodule.gi end @[simp] theorem span_empty : span R (∅ : Set M) = ⊥ := (Submodule.gi R M).gc.l_bot #align submodule.span_empty Submodule.span_empty @[simp] theorem span_univ : span R (univ : Set M) = ⊤ := eq_top_iff.2 <| SetLike.le_def.2 <| subset_span #align submodule.span_univ Submodule.span_univ theorem span_union (s t : Set M) : span R (s ∪ t) = span R s ⊔ span R t := (Submodule.gi R M).gc.l_sup #align submodule.span_union Submodule.span_union theorem span_iUnion {ι} (s : ι → Set M) : span R (⋃ i, s i) = ⨆ i, span R (s i) := (Submodule.gi R M).gc.l_iSup #align submodule.span_Union Submodule.span_iUnion /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem span_iUnion₂ {ι} {κ : ι → Sort*} (s : ∀ i, κ i → Set M) : span R (⋃ (i) (j), s i j) = ⨆ (i) (j), span R (s i j) := (Submodule.gi R M).gc.l_iSup₂ #align submodule.span_Union₂ Submodule.span_iUnion₂ theorem span_attach_biUnion [DecidableEq M] {α : Type*} (s : Finset α) (f : s → Finset M) : span R (s.attach.biUnion f : Set M) = ⨆ x, span R (f x) := by simp [span_iUnion] #align submodule.span_attach_bUnion Submodule.span_attach_biUnion theorem sup_span : p ⊔ span R s = span R (p ∪ s) := by rw [Submodule.span_union, p.span_eq] #align submodule.sup_span Submodule.sup_span theorem span_sup : span R s ⊔ p = span R (s ∪ p) := by rw [Submodule.span_union, p.span_eq] #align submodule.span_sup Submodule.span_sup notation:1000 /- Note that the character `∙` U+2219 used below is different from the scalar multiplication character `•` U+2022. -/ R " ∙ " x => span R (singleton x)
Mathlib/LinearAlgebra/Span.lean
347
348
theorem span_eq_iSup_of_singleton_spans (s : Set M) : span R s = ⨆ x ∈ s, R ∙ x := by
simp only [← span_iUnion, Set.biUnion_of_singleton s]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot, Yury Kudryashov, Rémy Degenne -/ import Mathlib.Algebra.Order.Group.Abs import Mathlib.Algebra.Order.Group.Basic import Mathlib.Algebra.Order.Group.OrderIso import Mathlib.Algebra.Order.Ring.Defs import Mathlib.Data.Int.Cast.Lemmas import Mathlib.Order.Interval.Set.Basic import Mathlib.Logic.Pairwise #align_import data.set.intervals.group from "leanprover-community/mathlib"@"c227d107bbada5d0d9d20287e3282c0a7f1651a0" /-! ### Lemmas about arithmetic operations and intervals. -/ variable {α : Type*} namespace Set section OrderedCommGroup variable [OrderedCommGroup α] {a b c d : α} /-! `inv_mem_Ixx_iff`, `sub_mem_Ixx_iff` -/ @[to_additive] theorem inv_mem_Icc_iff : a⁻¹ ∈ Set.Icc c d ↔ a ∈ Set.Icc d⁻¹ c⁻¹ := and_comm.trans <| and_congr inv_le' le_inv' #align set.inv_mem_Icc_iff Set.inv_mem_Icc_iff #align set.neg_mem_Icc_iff Set.neg_mem_Icc_iff @[to_additive] theorem inv_mem_Ico_iff : a⁻¹ ∈ Set.Ico c d ↔ a ∈ Set.Ioc d⁻¹ c⁻¹ := and_comm.trans <| and_congr inv_lt' le_inv' #align set.inv_mem_Ico_iff Set.inv_mem_Ico_iff #align set.neg_mem_Ico_iff Set.neg_mem_Ico_iff @[to_additive] theorem inv_mem_Ioc_iff : a⁻¹ ∈ Set.Ioc c d ↔ a ∈ Set.Ico d⁻¹ c⁻¹ := and_comm.trans <| and_congr inv_le' lt_inv' #align set.inv_mem_Ioc_iff Set.inv_mem_Ioc_iff #align set.neg_mem_Ioc_iff Set.neg_mem_Ioc_iff @[to_additive] theorem inv_mem_Ioo_iff : a⁻¹ ∈ Set.Ioo c d ↔ a ∈ Set.Ioo d⁻¹ c⁻¹ := and_comm.trans <| and_congr inv_lt' lt_inv' #align set.inv_mem_Ioo_iff Set.inv_mem_Ioo_iff #align set.neg_mem_Ioo_iff Set.neg_mem_Ioo_iff end OrderedCommGroup section OrderedAddCommGroup variable [OrderedAddCommGroup α] {a b c d : α} /-! `add_mem_Ixx_iff_left` -/ -- Porting note: instance search needs help `(α := α)` theorem add_mem_Icc_iff_left : a + b ∈ Set.Icc c d ↔ a ∈ Set.Icc (c - b) (d - b) := (and_congr (sub_le_iff_le_add (α := α)) (le_sub_iff_add_le (α := α))).symm #align set.add_mem_Icc_iff_left Set.add_mem_Icc_iff_left theorem add_mem_Ico_iff_left : a + b ∈ Set.Ico c d ↔ a ∈ Set.Ico (c - b) (d - b) := (and_congr (sub_le_iff_le_add (α := α)) (lt_sub_iff_add_lt (α := α))).symm #align set.add_mem_Ico_iff_left Set.add_mem_Ico_iff_left theorem add_mem_Ioc_iff_left : a + b ∈ Set.Ioc c d ↔ a ∈ Set.Ioc (c - b) (d - b) := (and_congr (sub_lt_iff_lt_add (α := α)) (le_sub_iff_add_le (α := α))).symm #align set.add_mem_Ioc_iff_left Set.add_mem_Ioc_iff_left theorem add_mem_Ioo_iff_left : a + b ∈ Set.Ioo c d ↔ a ∈ Set.Ioo (c - b) (d - b) := (and_congr (sub_lt_iff_lt_add (α := α)) (lt_sub_iff_add_lt (α := α))).symm #align set.add_mem_Ioo_iff_left Set.add_mem_Ioo_iff_left /-! `add_mem_Ixx_iff_right` -/ theorem add_mem_Icc_iff_right : a + b ∈ Set.Icc c d ↔ b ∈ Set.Icc (c - a) (d - a) := (and_congr sub_le_iff_le_add' le_sub_iff_add_le').symm #align set.add_mem_Icc_iff_right Set.add_mem_Icc_iff_right theorem add_mem_Ico_iff_right : a + b ∈ Set.Ico c d ↔ b ∈ Set.Ico (c - a) (d - a) := (and_congr sub_le_iff_le_add' lt_sub_iff_add_lt').symm #align set.add_mem_Ico_iff_right Set.add_mem_Ico_iff_right theorem add_mem_Ioc_iff_right : a + b ∈ Set.Ioc c d ↔ b ∈ Set.Ioc (c - a) (d - a) := (and_congr sub_lt_iff_lt_add' le_sub_iff_add_le').symm #align set.add_mem_Ioc_iff_right Set.add_mem_Ioc_iff_right theorem add_mem_Ioo_iff_right : a + b ∈ Set.Ioo c d ↔ b ∈ Set.Ioo (c - a) (d - a) := (and_congr sub_lt_iff_lt_add' lt_sub_iff_add_lt').symm #align set.add_mem_Ioo_iff_right Set.add_mem_Ioo_iff_right /-! `sub_mem_Ixx_iff_left` -/ theorem sub_mem_Icc_iff_left : a - b ∈ Set.Icc c d ↔ a ∈ Set.Icc (c + b) (d + b) := and_congr le_sub_iff_add_le sub_le_iff_le_add #align set.sub_mem_Icc_iff_left Set.sub_mem_Icc_iff_left theorem sub_mem_Ico_iff_left : a - b ∈ Set.Ico c d ↔ a ∈ Set.Ico (c + b) (d + b) := and_congr le_sub_iff_add_le sub_lt_iff_lt_add #align set.sub_mem_Ico_iff_left Set.sub_mem_Ico_iff_left theorem sub_mem_Ioc_iff_left : a - b ∈ Set.Ioc c d ↔ a ∈ Set.Ioc (c + b) (d + b) := and_congr lt_sub_iff_add_lt sub_le_iff_le_add #align set.sub_mem_Ioc_iff_left Set.sub_mem_Ioc_iff_left theorem sub_mem_Ioo_iff_left : a - b ∈ Set.Ioo c d ↔ a ∈ Set.Ioo (c + b) (d + b) := and_congr lt_sub_iff_add_lt sub_lt_iff_lt_add #align set.sub_mem_Ioo_iff_left Set.sub_mem_Ioo_iff_left /-! `sub_mem_Ixx_iff_right` -/ theorem sub_mem_Icc_iff_right : a - b ∈ Set.Icc c d ↔ b ∈ Set.Icc (a - d) (a - c) := and_comm.trans <| and_congr sub_le_comm le_sub_comm #align set.sub_mem_Icc_iff_right Set.sub_mem_Icc_iff_right theorem sub_mem_Ico_iff_right : a - b ∈ Set.Ico c d ↔ b ∈ Set.Ioc (a - d) (a - c) := and_comm.trans <| and_congr sub_lt_comm le_sub_comm #align set.sub_mem_Ico_iff_right Set.sub_mem_Ico_iff_right theorem sub_mem_Ioc_iff_right : a - b ∈ Set.Ioc c d ↔ b ∈ Set.Ico (a - d) (a - c) := and_comm.trans <| and_congr sub_le_comm lt_sub_comm #align set.sub_mem_Ioc_iff_right Set.sub_mem_Ioc_iff_right theorem sub_mem_Ioo_iff_right : a - b ∈ Set.Ioo c d ↔ b ∈ Set.Ioo (a - d) (a - c) := and_comm.trans <| and_congr sub_lt_comm lt_sub_comm #align set.sub_mem_Ioo_iff_right Set.sub_mem_Ioo_iff_right -- I think that symmetric intervals deserve attention and API: they arise all the time, -- for instance when considering metric balls in `ℝ`. theorem mem_Icc_iff_abs_le {R : Type*} [LinearOrderedAddCommGroup R] {x y z : R} : |x - y| ≤ z ↔ y ∈ Icc (x - z) (x + z) := abs_le.trans <| and_comm.trans <| and_congr sub_le_comm neg_le_sub_iff_le_add #align set.mem_Icc_iff_abs_le Set.mem_Icc_iff_abs_le end OrderedAddCommGroup section LinearOrderedAddCommGroup variable [LinearOrderedAddCommGroup α] /-- If we remove a smaller interval from a larger, the result is nonempty -/ theorem nonempty_Ico_sdiff {x dx y dy : α} (h : dy < dx) (hx : 0 < dx) : Nonempty ↑(Ico x (x + dx) \ Ico y (y + dy)) := by cases' lt_or_le x y with h' h' · use x simp [*, not_le.2 h'] · use max x (x + dy) simp [*, le_refl] #align set.nonempty_Ico_sdiff Set.nonempty_Ico_sdiff end LinearOrderedAddCommGroup /-! ### Lemmas about disjointness of translates of intervals -/ section PairwiseDisjoint section OrderedCommGroup variable [OrderedCommGroup α] (a b : α) @[to_additive] theorem pairwise_disjoint_Ioc_mul_zpow : Pairwise (Disjoint on fun n : ℤ => Ioc (a * b ^ n) (a * b ^ (n + 1))) := by simp (config := { unfoldPartialApp := true }) only [Function.onFun] simp_rw [Set.disjoint_iff] intro m n hmn x hx apply hmn have hb : 1 < b := by have : a * b ^ m < a * b ^ (m + 1) := hx.1.1.trans_le hx.1.2 rwa [mul_lt_mul_iff_left, ← mul_one (b ^ m), zpow_add_one, mul_lt_mul_iff_left] at this have i1 := hx.1.1.trans_le hx.2.2 have i2 := hx.2.1.trans_le hx.1.2 rw [mul_lt_mul_iff_left, zpow_lt_zpow_iff hb, Int.lt_add_one_iff] at i1 i2 exact le_antisymm i1 i2 #align set.pairwise_disjoint_Ioc_mul_zpow Set.pairwise_disjoint_Ioc_mul_zpow #align set.pairwise_disjoint_Ioc_add_zsmul Set.pairwise_disjoint_Ioc_add_zsmul @[to_additive] theorem pairwise_disjoint_Ico_mul_zpow : Pairwise (Disjoint on fun n : ℤ => Ico (a * b ^ n) (a * b ^ (n + 1))) := by simp (config := { unfoldPartialApp := true }) only [Function.onFun] simp_rw [Set.disjoint_iff] intro m n hmn x hx apply hmn have hb : 1 < b := by have : a * b ^ m < a * b ^ (m + 1) := hx.1.1.trans_lt hx.1.2 rwa [mul_lt_mul_iff_left, ← mul_one (b ^ m), zpow_add_one, mul_lt_mul_iff_left] at this have i1 := hx.1.1.trans_lt hx.2.2 have i2 := hx.2.1.trans_lt hx.1.2 rw [mul_lt_mul_iff_left, zpow_lt_zpow_iff hb, Int.lt_add_one_iff] at i1 i2 exact le_antisymm i1 i2 #align set.pairwise_disjoint_Ico_mul_zpow Set.pairwise_disjoint_Ico_mul_zpow #align set.pairwise_disjoint_Ico_add_zsmul Set.pairwise_disjoint_Ico_add_zsmul @[to_additive] theorem pairwise_disjoint_Ioo_mul_zpow : Pairwise (Disjoint on fun n : ℤ => Ioo (a * b ^ n) (a * b ^ (n + 1))) := fun _ _ hmn => (pairwise_disjoint_Ioc_mul_zpow a b hmn).mono Ioo_subset_Ioc_self Ioo_subset_Ioc_self #align set.pairwise_disjoint_Ioo_mul_zpow Set.pairwise_disjoint_Ioo_mul_zpow #align set.pairwise_disjoint_Ioo_add_zsmul Set.pairwise_disjoint_Ioo_add_zsmul @[to_additive] theorem pairwise_disjoint_Ioc_zpow : Pairwise (Disjoint on fun n : ℤ => Ioc (b ^ n) (b ^ (n + 1))) := by simpa only [one_mul] using pairwise_disjoint_Ioc_mul_zpow 1 b #align set.pairwise_disjoint_Ioc_zpow Set.pairwise_disjoint_Ioc_zpow #align set.pairwise_disjoint_Ioc_zsmul Set.pairwise_disjoint_Ioc_zsmul @[to_additive]
Mathlib/Algebra/Order/Interval/Set/Group.lean
219
221
theorem pairwise_disjoint_Ico_zpow : Pairwise (Disjoint on fun n : ℤ => Ico (b ^ n) (b ^ (n + 1))) := by
simpa only [one_mul] using pairwise_disjoint_Ico_mul_zpow 1 b